home *** CD-ROM | disk | FTP | other *** search
/ PC-Online 1996 May / PCOnline_05_1996.bin / linux / source / kernel-s / v1.2 / patch-1.005 / patch-1.2.8
Text File  |  1995-05-03  |  415KB  |  13,505 lines

  1. diff -u --recursive --new-file v1.2.7/linux/Makefile linux/Makefile
  2. --- v1.2.7/linux/Makefile    Sat Apr 29 12:42:20 1995
  3. +++ linux/Makefile    Tue May  2 08:18:15 1995
  4. @@ -1,6 +1,6 @@
  5.  VERSION = 1
  6.  PATCHLEVEL = 2
  7. -SUBLEVEL = 7
  8. +SUBLEVEL = 8
  9.  
  10.  ARCH = i386
  11.  
  12. diff -u --recursive --new-file v1.2.7/linux/arch/i386/kernel/vm86.c linux/arch/i386/kernel/vm86.c
  13. --- v1.2.7/linux/arch/i386/kernel/vm86.c    Wed Mar 29 06:52:56 1995
  14. +++ linux/arch/i386/kernel/vm86.c    Tue May  2 08:02:12 1995
  15. @@ -358,6 +358,14 @@
  16.              IP(regs) += 2;
  17.              set_vflags_long(popl(ssp, sp), regs);
  18.              return;
  19. +
  20. +        /* iretd */
  21. +        case 0xcf:
  22. +            SP(regs) += 12;
  23. +            IP(regs) = (unsigned short)popl(ssp, sp);
  24. +            regs->cs = (unsigned short)popl(ssp, sp);
  25. +            set_vflags_long(popl(ssp, sp), regs);
  26. +            return;
  27.          }
  28.  
  29.      /* pushf */
  30. diff -u --recursive --new-file v1.2.7/linux/drivers/block/README.sbpcd linux/drivers/block/README.sbpcd
  31. --- v1.2.7/linux/drivers/block/README.sbpcd    Wed Mar 29 06:52:57 1995
  32. +++ linux/drivers/block/README.sbpcd    Tue Apr 25 00:54:36 1995
  33. @@ -1,4 +1,4 @@
  34. -This README belongs to release 3.4 or newer of the SoundBlaster Pro
  35. +This README belongs to release 3.5 or newer of the SoundBlaster Pro
  36.  (Matsushita, Kotobuki, Panasonic, CreativeLabs, Longshine and soon TEAC, too)
  37.  CD-ROM driver for Linux.
  38.  
  39. @@ -16,28 +16,18 @@
  40.  an internal drive, and you can use it as an internal, too - f.e. plug it into
  41.  a soundcard).
  42.  
  43. -The quad-speed TEAC CD-55A drive uses the same interface types, but has a
  44. -totally different command and flow control scheme. Support is under
  45. -construction, but split: Greg Nowicki (nowicki@tardis.larc.nasa.gov)
  46. -cares about the separate driver "teaccd". Please, do not mail him merely for
  47. -asking "user questions" at the moment - the project is still a "baby".
  48. -
  49.  CreativeLabs has a new drive "CD-200". Support is under construction.
  50. -Detection should already work.
  51. -
  52. -Regarding CD200 support:
  53. -    Please, don't mail me about it if you are not a competent BETA tester 
  54. -            (if you are: mail!; I do not have such drives).
  55. -    Please, don't drop simple questions about the new drives in the
  56. -            newsgroups. Full support needs more or less time.
  57. -If you like to help, you can mail me the "SBPCD:..." messages, regarding the
  58. -new drives. But I mostly will not answer (just use) it.
  59. +Drive detection and playing audio should already work. I need qualified
  60. +feedback about the bugs within the data functions or a drive (I never saw
  61. +a CD200).
  62. +
  63. +The quad-speed TEAC CD-55A drive is supported. The routines may still be
  64. +a little bit buggy, but the data rate already reaches 500 kB/sec if you
  65. +set SBP_BUFFER_FRAMES to 64. The drive is able to deliver 600 kB/sec, so
  66. +this has to get a point of work.
  67.  
  68.  This driver is NOT for Mitsumi or Sony or Aztech or Philips or XXX drives,
  69.  and this driver is in no way usable for any new IDE ATAPI drive.
  70. -For Aztech CDA-268 drives (and for some Wearnes, Okano and Orchid drives),
  71. -Werner Zimmermann has done a driver which currently resides at ftp.gwdg.de
  72. -under /pub/linux/cdrom/drivers/aztech/.
  73.  
  74.  This driver will work with the soundcard interfaces (SB Pro, SB 16, Galaxy,
  75.  SoundFX, ...) and/or with the "no-sound" cards (Panasonic CI-101P, LaserMate,
  76. @@ -53,8 +43,8 @@
  77.  because the behavior of some sound card interfaces is different.
  78.  
  79.  The driver respects all known drive firmware releases - my old drive is a 2.11,
  80. -but it should work with "old" drives <2.01 ... >3.00 and with "new" drives
  81. -(which count the releases around 0.75 or 1.00).
  82. +but it should work with CR-52x drives <2.01 ... >3.00 and with CR-56x drives
  83. +<0.75 .. 5.00.
  84.  
  85.  Up to 4 drives per interface card, and up to 4 interface cards are supported.
  86.  All supported drive families can be mixed, but the CR-521 drives are 
  87. @@ -90,28 +80,30 @@
  88.  
  89.  With the CR-562 and CR-563 drives, the reading of audio frames is possible.
  90.  This is implemented by an IOCTL function which per default reads only up to
  91. -4 frames of 2352 bytes at once (configurable with the "READ_AUDIO" define).
  92. +4 frames of 2352 bytes at once (configurable with the "READ_AUDIO" define,
  93. +"55" is the maximum if you use sbpcd as a "module").
  94.  Reading the same frame a second time gives different data; the frame data 
  95.  start at a different position, but all read bytes are valid, and we always
  96.  read 98 consecutive chunks (of 24 Bytes) as a frame. Reading more than 1 frame
  97. -at once misses some chunks at each frame boundary.This lack has to get 
  98. -corrected by external, "higher level" software which reads the same frame 
  99. +at once possibly misses some chunks at each frame boundary. This lack has to
  100. +get corrected by external, "higher level" software which reads the same frame 
  101.  again and tries to find and eliminate overlapping chunks (24-byte-pieces).
  102.  
  103.  The transfer rate with reading audio (1-frame-pieces) is as slow as 32 kB/sec.
  104. -This could be better reading bigger chunks, but the "missing" chunks occur at
  105. -the beginning of each single frame.
  106. +This could be better reading bigger chunks, but the "missing" chunks possibly
  107. +occur at the beginning of each single frame.
  108.  The software interface possibly may change a bit the day the SCSI driver
  109.  supports it too.
  110.  
  111. -With the CR-562 and CR-563 drives, MultiSession is supported.
  112. +With all but the CR-52x drives, MultiSession is supported.
  113.  Photo CDs work (the "old" drives like CR-521 can access only the first
  114.  session of a photoCD).
  115.  At ftp.gwdg.de:/pub/linux/hpcdtoppm/ you will find Hadmut Danisch's package to
  116.  convert photo CD image files and Gerd Knorr's viewing utility.
  117.  
  118. -The transfer rate will reach 150 kB/sec with "old" drives and 300 kB/sec with
  119. -double-speed drives. XA (PhotoCD) disks with "old" drives give only 50 kB/sec.
  120. +The transfer rate will reach 150 kB/sec with "old" drives, 300 kB/sec with
  121. +double-speed drives, and about 500 kB/sec with quad speed drives.
  122. +XA (PhotoCD) disks with "old" drives give only 50 kB/sec.
  123.  
  124.  This release is part of the standard kernel and consists of
  125.  - this README file
  126. @@ -138,6 +130,7 @@
  127.            If you configure "SBPRO" wrong, the playing of audio CDs will work,
  128.            but you will not be able to mount a data CD.
  129.        a2. Tell the address of your CDROM_PORT (not of the sound port).
  130. +      a3. Set DISTRIBUTION to 0.
  131.     b. Additionally for 2.a1 and 2.a2, the setup may be done during
  132.        boot time (via the "kernel command line" or "LILO option"):
  133.            sbpcd=0x230,SoundBlaster
  134. @@ -145,7 +138,6 @@
  135.            sbpcd=0x320,LaserMate
  136.        or
  137.            sbpcd=0x330,SPEA
  138. -      (these strings are case sensitive!).
  139.        This is especially useful if you install a fresh distribution.
  140.  2. "cd /usr/src/linux" and do a "make config" and select "y" for Matsushita
  141.     CD-ROM support and for ISO9660 FileSystem support. If you do not have a
  142. @@ -198,11 +190,15 @@
  143.  "make config" of your kernel, you can build the "loadable module" sbpcd.o.
  144.  Read /usr/src/linux/README.modules on this.
  145.  
  146. -If sbpcd gets used as a module, the "audio copy" feature is disabled, and the
  147. -internal read-ahead buffer has a reduced size (the latter may affect throughput
  148. -a little bit under "slow" CPUs). Further, support of more than one interface
  149. +If sbpcd gets used as a module, the support of more than one interface
  150.  card (i.e. drives 4...15) is disabled.
  151.  
  152. +You can specify interface address and type with the "insmod" command like:
  153. + # insmod /usr/src/linux/modules/sbpcd.o sbpcd=0x340,0
  154. +or
  155. + # insmod /usr/src/linux/modules/sbpcd.o sbpcd=0x230,1
  156. +where the last number represents the SBPRO setting (no strings allowed here).
  157. +
  158.  
  159.  Things of interest:
  160.  -------------------
  161. @@ -215,7 +211,6 @@
  162.  
  163.  To reduce or increase the amount of kernel messages, edit sbpcd.c and play
  164.  with the "DBG_xxx" switches (initialization of the variable "sbpcd_debug").
  165. -This is the way to get rid of the initial warning message block, too.
  166.  
  167.  The driver uses the "variable BLOCK_SIZE" feature. To use it, you have to
  168.  specify "block=2048" as a mount option. Doing this will disable the direct
  169. @@ -229,120 +224,13 @@
  170.  
  171.  At the beginning of sbpcd.c, you will find some "#define"s (f.e. EJECT and
  172.  JUKEBOX). With that, you can configure the driver for some special things.
  173. -The following program disables the auto-eject feature during runtime:
  174. -
  175. -/*=================== begin program ========================================*/
  176. -/*
  177. - * set the "eject" switch (enable/disable auto-ejecting)
  178. - *
  179. - * (c) 1994 Eberhard Moenkeberg <emoenke@gwdg.de>
  180. - *          may be used & enhanced freely
  181. - *
  182. - * Disables or enables the auto-eject feature at run time.
  183. - * Works only if a CD is in the drive (just like the feature itself ;-) 
  184. - * Useful for a "quiet" shutdown or for weird audio player programs.
  185. - */
  186. -#define EJECT 0 /* 0: disable, 1: enable auto-ejecting */
  187. -
  188. -#include <stdio.h>
  189. -#include <sys/ioctl.h>
  190. -#include <linux/cdrom.h>
  191. -
  192. -static char arg=EJECT;
  193. -static int drive;
  194. -static int err;
  195. -
  196. -main(int argc, char *argv[])
  197. -{
  198. -/*
  199. - * open /dev/cdrom
  200. - */
  201. -  drive=open("/dev/cdrom", 0);
  202. -  if (drive<0)
  203. -    {
  204. -      fprintf(stderr, "can't open drive /dev/cdrom.\n");
  205. -      exit (-1);
  206. -    }
  207. -/*
  208. - * set EJECT_SW
  209. - */
  210. -  err=ioctl(drive, CDROMEJECT_SW, arg);
  211. -  if (err!=0)
  212. -    {
  213. -      fprintf(stderr, "can't set EJECT_SW (error %d).\n", err);
  214. -      exit (-1);
  215. -    }
  216. -  else
  217. -    fprintf(stdout, "EJECT_SW set to %d\n", arg);
  218. -}
  219. -/*===================== end program ========================================*/
  220. -
  221. -Jeff Tranter's "eject" utility can do this, too (and more) for you.
  222. +You can use the appended program "cdtester" to set the auto-eject feature
  223. +during runtime. Jeff Tranter's "eject" utility can do this, too (and more)
  224. +for you.
  225.  
  226.  There is a new ioctl CDROMMULTISESSION to obtain with a user program if
  227.  the CD is an XA disk and - if it is - where the last session starts. The
  228. -following example illustrates how to call it:
  229. -
  230. -/*=================== begin program ========================================*/
  231. -/*
  232. - * ask for multisession redirection info
  233. - *
  234. - * (c) 1994 Eberhard Moenkeberg <emoenke@gwdg.de>
  235. - *          may be used & enhanced freely
  236. - *
  237. - */
  238. -#include <stdio.h>
  239. -#include <sys/ioctl.h>
  240. -#include <linux/cdrom.h>
  241. -
  242. -static struct cdrom_multisession ms_info;
  243. -static int drive;
  244. -static int err;
  245. -
  246. -main(int argc, char *argv[])
  247. -{
  248. -/*
  249. - * open /dev/cdrom
  250. - */
  251. -  drive=open("/dev/cdrom", 0);
  252. -  if (drive<0)
  253. -    {
  254. -      fprintf(stderr, "can't open drive /dev/cdrom.\n");
  255. -      exit (-1);
  256. -    }
  257. -/*
  258. - * 
  259. - */
  260. -  ms_info.addr_format=CDROM_LBA;
  261. -  err=ioctl(drive, CDROMMULTISESSION, &ms_info);
  262. -  if (err!=0)
  263. -    {
  264. -      fprintf(stderr, "CDROMMULTISESSION(lba) returns error %d.\n", err);
  265. -      exit (-1);
  266. -    }
  267. -  else
  268. -    if (ms_info.xa_flag)
  269. -        fprintf(stdout, "lba: %d\n", ms_info.addr.lba);
  270. -    else
  271. -        fprintf(stdout, "not an XA disk.\n");
  272. -
  273. -  ms_info.addr_format=CDROM_MSF;
  274. -  err=ioctl(drive, CDROMMULTISESSION, &ms_info);
  275. -  if (err!=0)
  276. -    {
  277. -      fprintf(stderr, "CDROMMULTISESSION(msf) returns error %d.\n", err);
  278. -      exit (-1);
  279. -    }
  280. -  else
  281. -    if (ms_info.xa_flag)
  282. -        fprintf(stdout, "msf: %02d:%02d:%02d\n",
  283. -                 ms_info.addr.msf.minute,
  284. -                 ms_info.addr.msf.second,
  285. -                 ms_info.addr.msf.frame);
  286. -    else
  287. -        fprintf(stdout, "not an XA disk.\n");
  288. -}
  289. -/*===================== end program ========================================*/
  290. +"cdtester" program illustrates how to call it.
  291.  
  292.  
  293.  Auto-probing at boot time:
  294. @@ -354,7 +242,8 @@
  295.  SBPCD's auto-probing happens before the initialization of the net drivers.
  296.  Those "hazardous" addresses are excluded from auto-probing; the "kernel 
  297.  command line" feature has to be used during installation if you have your 
  298. -drive at those addresses.
  299. +drive at those addresses. The "module" version is allowed to probe at those
  300. +addresses, too.
  301.  
  302.  The auto-probing looks first at the configured address resp. the address
  303.  submitted by the kernel command line. With this, it is possible to use this
  304. @@ -382,7 +271,7 @@
  305.  without fearing NE2000 cards).
  306.  
  307.  To shorten the auto-probing list to a single entry, set DISTRIBUTION 0 within
  308. -sbpcd.c.
  309. +sbpcd.h.
  310.  
  311.  
  312.  Setting up address and interface type:
  313. @@ -569,3 +458,537 @@
  314.                           D-37083 Goettingen
  315.                           Germany
  316.  ---
  317. +
  318. +
  319. +Appendix -- the "cdtester" utility:
  320. +
  321. +/*
  322. + * cdtester.c -- test the audio functions of a CD driver
  323. + *
  324. + * (c) 1995 Eberhard Moenkeberg <emoenke@gwdg.de>
  325. + *          published under the GPL
  326. + *
  327. + *          made under heavy use of the "Tiny Audio CD Player"
  328. + *          from Werner Zimmermann <zimmerma@rz.fht-esslingen.de>
  329. + *          (see linux/drivers/block/README.aztcd)
  330. + */
  331. +#undef AZT_PRIVATE_IOCTLS /* not supported by every CDROM driver */
  332. +#define SBP_PRIVATE_IOCTLS /* not supported by every CDROM driver */
  333. +
  334. +#include <stdio.h>
  335. +#include <stdio.h>
  336. +#include <malloc.h>
  337. +#include <sys/ioctl.h>
  338. +#include <linux/cdrom.h>
  339. +
  340. +#ifdef AZT_PRIVATE_IOCTLS
  341. +#include <linux/aztcd.h>
  342. +#endif AZT_PRIVATE_IOCTLS
  343. +#ifdef SBP_PRIVATE_IOCTLS
  344. +#include <linux/sbpcd.h>
  345. +#include <linux/fs.h>
  346. +#endif SBP_PRIVATE_IOCTLS
  347. +
  348. +struct cdrom_tochdr hdr;
  349. +struct cdrom_tochdr tocHdr;
  350. +struct cdrom_tocentry TocEntry[101];
  351. +struct cdrom_tocentry entry;
  352. +struct cdrom_multisession ms_info;
  353. +struct cdrom_read_audio read_audio;
  354. +struct cdrom_ti ti;
  355. +struct cdrom_subchnl subchnl;
  356. +struct cdrom_msf msf;
  357. +struct cdrom_volctrl volctrl;
  358. +#ifdef AZT_PRIVATE_IOCTLS
  359. +union
  360. +{
  361. +    struct cdrom_msf msf;
  362. +    unsigned char buf[CD_FRAMESIZE_RAW];
  363. +} azt;
  364. +#endif AZT_PRIVATE_IOCTLS
  365. +int i, i1, i2, i3, j, k;
  366. +unsigned char sequence=0;
  367. +unsigned char command[80];
  368. +unsigned char first=1, last=1;
  369. +char *default_device="/dev/cdrom";
  370. +char dev[20];
  371. +char filename[20];
  372. +int drive;
  373. +int datafile;
  374. +int rc;
  375. +
  376. +void help(void)
  377. +{
  378. +    printf("Available Commands:\n");
  379. +    printf("STOP          s      EJECT        e       QUIT         q\n");
  380. +    printf("PLAY TRACK    t      PAUSE        p       RESUME       r\n");
  381. +    printf("NEXT TRACK    n      REPEAT LAST  l       HELP         h\n");
  382. +    printf("SUBCHANNEL_Q  c      TRACK INFO   i       PLAY AT      a\n");
  383. +    printf("READ          d      READ RAW     w       READ AUDIO   A\n");
  384. +    printf("MS-INFO       M      TOC          T       START        S\n");
  385. +    printf("SET EJECTSW   X      DEVICE       D       DEBUG        Y\n");
  386. +    printf("AUDIO_BUFSIZ  Z      RESET        R       BLKRASET     B\n");
  387. +    printf("SET VOLUME    v      GET VOLUME   V\n");
  388. +}
  389. +
  390. +/*
  391. + *  convert MSF number (3 bytes only) to Logical_Block_Address 
  392. + */
  393. +int msf2lba(u_char *msf)
  394. +{
  395. +    int i;
  396. +    
  397. +    i=(msf[0] * CD_SECS + msf[1]) * CD_FRAMES + msf[2] - CD_BLOCK_OFFSET;
  398. +    if (i<0) return (0);
  399. +    return (i);
  400. +}
  401. +/*
  402. + *  convert logical_block_address to m-s-f_number (3 bytes only)
  403. + */
  404. +void lba2msf(int lba, unsigned char *msf)
  405. +{
  406. +    lba += CD_BLOCK_OFFSET;
  407. +    msf[0] = lba / (CD_SECS*CD_FRAMES);
  408. +    lba %= CD_SECS*CD_FRAMES;
  409. +    msf[1] = lba / CD_FRAMES;
  410. +    msf[2] = lba % CD_FRAMES;
  411. +}
  412. +
  413. +int init_drive(char *dev)
  414. +{
  415. +    unsigned char msf_ent[3];
  416. +
  417. +    /*
  418. +     * open the device
  419. +     */
  420. +    drive=open(dev,0);
  421. +    if (drive<0) return (-1);
  422. +    /*
  423. +     * get TocHeader
  424. +     */
  425. +    printf("getting TocHeader...\n");
  426. +    rc=ioctl(drive,CDROMREADTOCHDR,&hdr);
  427. +    if (rc!=0)
  428. +    {
  429. +        printf("can't get TocHeader (error %d).\n",rc);
  430. +        return (-2);
  431. +    }
  432. +    else
  433. +        first=hdr.cdth_trk0;
  434. +        last=hdr.cdth_trk1;
  435. +        printf("TocHeader: %d %d\n",hdr.cdth_trk0,hdr.cdth_trk1);
  436. +    /*
  437. +     * get and display all TocEntries
  438. +     */
  439. +    printf("getting TocEntries...\n");
  440. +    for (i=1;i<=hdr.cdth_trk1+1;i++)
  441. +    {
  442. +        if (i!=hdr.cdth_trk1+1) TocEntry[i].cdte_track = i;
  443. +        else TocEntry[i].cdte_track = CDROM_LEADOUT;
  444. +        TocEntry[i].cdte_format = CDROM_LBA;
  445. +        rc=ioctl(drive,CDROMREADTOCENTRY,&TocEntry[i]);
  446. +        if (rc!=0)
  447. +        {
  448. +            printf("can't get TocEntry #%d (error %d).\n",i,rc);
  449. +        }
  450. +        else
  451. +        {
  452. +            lba2msf(TocEntry[i].cdte_addr.lba,&msf_ent[0]);
  453. +            if (TocEntry[i].cdte_track==CDROM_LEADOUT)
  454. +            {
  455. +                printf("TocEntry #%02X: %1X %1X %02d:%02d:%02d (lba: 0x%06X) %02X\n",
  456. +                       TocEntry[i].cdte_track,
  457. +                       TocEntry[i].cdte_adr,
  458. +                       TocEntry[i].cdte_ctrl,
  459. +                       msf_ent[0],
  460. +                       msf_ent[1],
  461. +                       msf_ent[2],
  462. +                       TocEntry[i].cdte_addr.lba,
  463. +                       TocEntry[i].cdte_datamode);
  464. +            }
  465. +            else
  466. +            {
  467. +                printf("TocEntry #%02d: %1X %1X %02d:%02d:%02d (lba: 0x%06X) %02X\n",
  468. +                       TocEntry[i].cdte_track,
  469. +                       TocEntry[i].cdte_adr,
  470. +                       TocEntry[i].cdte_ctrl,
  471. +                       msf_ent[0],
  472. +                       msf_ent[1],
  473. +                       msf_ent[2],
  474. +                       TocEntry[i].cdte_addr.lba,
  475. +                       TocEntry[i].cdte_datamode);
  476. +            }
  477. +        }
  478. +    }
  479. +    return (hdr.cdth_trk1); /* number of tracks */
  480. +}
  481. +
  482. +void display(int size,unsigned char *buffer)
  483. +{
  484. +    k=0;
  485. +    getchar();
  486. +    for (i=0;i<(size+1)/16;i++)
  487. +    {
  488. +        printf("%4d:",i*16);
  489. +        for (j=0;j<16;j++)
  490. +        {
  491. +            printf(" %02X",buffer[i*16+j]);
  492. +        }
  493. +        printf("  ");
  494. +        for (j=0;j<16;j++)
  495. +        {
  496. +            if (isalnum(buffer[i*16+j])) 
  497. +                printf("%c",buffer[i*16+j]);
  498. +            else
  499. +                printf(".");
  500. +        }
  501. +        printf("\n"); 
  502. +        k++;
  503. +        if (k>=20)
  504. +        {
  505. +            printf("press ENTER to continue\n");
  506. +            getchar();
  507. +            k=0;
  508. +        }
  509. +    } 
  510. +} 
  511. +
  512. +main(int argc, char *argv[])
  513. +{
  514. +    printf("\nTesting tool for a CDROM driver's audio functions V0.1\n");
  515. +    printf("(C) 1995 Eberhard Moenkeberg <emoenke@gwdg.de>\n");
  516. +    printf("initializing...\n");
  517. +    
  518. +    rc=init_drive(default_device);
  519. +    if (rc<0) printf("could not open %s (rc=%d).\n",default_device,rc);
  520. +    help();
  521. +    while (1)
  522. +    {
  523. +        printf("Give a one-letter command (h = help): ");
  524. +        scanf("%s",command);
  525. +        command[1]=0;
  526. +        switch (command[0])
  527. +        {
  528. +        case 'D':
  529. +            printf("device name (f.e. /dev/sbpcd3): ? ");
  530. +            scanf("%s",&dev);
  531. +            close(drive);
  532. +            rc=init_drive(dev);
  533. +            if (rc<0) printf("could not open %s (rc %d).\n",dev,rc);
  534. +            break;
  535. +        case 'e':
  536. +            rc=ioctl(drive,CDROMEJECT);
  537. +            if (rc<0) printf("CDROMEJECT: rc=%d.\n",rc);
  538. +            break;
  539. +        case 'p':
  540. +            rc=ioctl(drive,CDROMPAUSE);
  541. +            if (rc<0) printf("CDROMPAUSE: rc=%d.\n",rc);
  542. +            break;
  543. +        case 'r':
  544. +            rc=ioctl(drive,CDROMRESUME);
  545. +            if (rc<0) printf("CDROMRESUME: rc=%d.\n",rc);
  546. +            break;
  547. +        case 's':
  548. +            rc=ioctl(drive,CDROMSTOP);
  549. +            if (rc<0) printf("CDROMSTOP: rc=%d.\n",rc);
  550. +            break;
  551. +        case 'S':
  552. +            rc=ioctl(drive,CDROMSTART);
  553. +            if (rc<0) printf("CDROMSTART: rc=%d.\n",rc);
  554. +            break;
  555. +        case 't':
  556. +            rc=ioctl(drive,CDROMREADTOCHDR,&tocHdr);
  557. +            if (rc<0)
  558. +            {
  559. +                printf("CDROMREADTOCHDR: rc=%d.\n",rc);
  560. +                break;
  561. +            }
  562. +            first=tocHdr.cdth_trk0;
  563. +            last= tocHdr.cdth_trk1;
  564. +            if ((first==0)||(first>last))
  565. +            {
  566. +                printf ("--got invalid TOC data.\n");
  567. +            }
  568. +            else
  569. +            {
  570. +                printf("--enter track number(first=%d, last=%d): ",first,last);
  571. +                scanf("%d",&i1);
  572. +                ti.cdti_trk0=i1;
  573. +                if (ti.cdti_trk0<first) ti.cdti_trk0=first;
  574. +                if (ti.cdti_trk0>last) ti.cdti_trk0=last;
  575. +                ti.cdti_ind0=0;
  576. +                ti.cdti_trk1=last;
  577. +                ti.cdti_ind1=0;
  578. +                rc=ioctl(drive,CDROMSTOP);
  579. +                rc=ioctl(drive,CDROMPLAYTRKIND,&ti);
  580. +                if (rc<0) printf("CDROMPLAYTRKIND: rc=%d.\n",rc);
  581. +            }
  582. +            break;
  583. +        case 'n':
  584. +            rc=ioctl(drive,CDROMSTOP);
  585. +            if (++ti.cdti_trk0>last) ti.cdti_trk0=last;
  586. +            ti.cdti_ind0=0;
  587. +            ti.cdti_trk1=last;
  588. +            ti.cdti_ind1=0;
  589. +            rc=ioctl(drive,CDROMPLAYTRKIND,&ti);
  590. +            if (rc<0) printf("CDROMPLAYTRKIND: rc=%d.\n",rc);
  591. +            break;
  592. +        case 'l':
  593. +            rc=ioctl(drive,CDROMSTOP);
  594. +            if (--ti.cdti_trk0<first) ti.cdti_trk0=first;
  595. +            ti.cdti_ind0=0;
  596. +            ti.cdti_trk1=last;
  597. +            ti.cdti_ind1=0;
  598. +            rc=ioctl(drive,CDROMPLAYTRKIND,&ti);
  599. +            if (rc<0) printf("CDROMPLAYTRKIND: rc=%d.\n",rc);
  600. +            break;
  601. +        case 'c':
  602. +            subchnl.cdsc_format=CDROM_MSF;
  603. +            rc=ioctl(drive,CDROMSUBCHNL,&subchnl);
  604. +            if (rc<0) printf("CDROMSUBCHNL: rc=%d.\n",rc);
  605. +            else
  606. +            {
  607. +                printf("AudioStatus:%s  Track:%d  Mode:%d  MSF=%02d:%02d:%02d\n",
  608. +                       subchnl.cdsc_audiostatus==CDROM_AUDIO_PLAY ? "PLAYING":"NOT PLAYING",
  609. +                       subchnl.cdsc_trk,subchnl.cdsc_adr, 
  610. +                       subchnl.cdsc_absaddr.msf.minute,
  611. +                       subchnl.cdsc_absaddr.msf.second,
  612. +                       subchnl.cdsc_absaddr.msf.frame);
  613. +            }
  614. +            break;              
  615. +        case 'i':
  616. +            printf("Track No.: ");
  617. +            scanf("%d",&i1);
  618. +            entry.cdte_track=i1;
  619. +            if (entry.cdte_track<first) entry.cdte_track=first;
  620. +            if (entry.cdte_track>last)  entry.cdte_track=last;
  621. +            entry.cdte_format=CDROM_MSF;
  622. +            rc=ioctl(drive,CDROMREADTOCENTRY,&entry);
  623. +            if (rc<0) printf("CDROMREADTOCENTRY: rc=%d.\n",rc);
  624. +            else
  625. +            {
  626. +                printf("Mode %d Track, starts at %02d:%02d:%02d\n",
  627. +                       entry.cdte_adr,
  628. +                       entry.cdte_addr.msf.minute,
  629. +                       entry.cdte_addr.msf.second,
  630. +                       entry.cdte_addr.msf.frame);
  631. +            }
  632. +            break;
  633. +        case 'a':
  634. +            printf("Address (min:sec:frm)  ");
  635. +            scanf("%d:%d:%d",&i1,&i2,&i3);
  636. +            msf.cdmsf_min0=i1;
  637. +            msf.cdmsf_sec0=i2;
  638. +            msf.cdmsf_frame0=i3;
  639. +            if (msf.cdmsf_sec0>59) msf.cdmsf_sec0=59;
  640. +            if (msf.cdmsf_frame0>74) msf.cdmsf_frame0=74;
  641. +            lba2msf(TocEntry[last+1].cdte_addr.lba-1,&msf.cdmsf_min1);
  642. +            rc=ioctl(drive,CDROMSTOP);
  643. +            rc=ioctl(drive,CDROMPLAYMSF,&msf);
  644. +            if (rc<0) printf("CDROMPLAYMSF: rc=%d.\n",rc);
  645. +            break;
  646. +#ifdef AZT_PRIVATE_IOCTLS /*not supported by every CDROM driver*/
  647. +        case 'd':
  648. +            printf("Address (min:sec:frm)  ");
  649. +            scanf("%d:%d:%d",&i1,&i2,&i3);
  650. +            azt.msf.cdmsf_min0=i1;
  651. +            azt.msf.cdmsf_sec0=i2;
  652. +            azt.msf.cdmsf_frame0=i3;
  653. +            if (azt.msf.cdmsf_sec0>59) azt.msf.cdmsf_sec0=59;
  654. +            if (azt.msf.cdmsf_frame0>74) azt.msf.cdmsf_frame0=74;
  655. +            rc=ioctl(drive,CDROMREADMODE1,&azt.msf);
  656. +            if (rc<0) printf("CDROMREADMODE1: rc=%d.\n",rc);
  657. +            else display(CD_FRAMESIZE,azt.buf);
  658. +            break;
  659. +        case 'w':
  660. +            printf("Address (min:sec:frame)  ");
  661. +            scanf("%d:%d:%d",&i1,&i2,&i3);
  662. +            azt.msf.cdmsf_min0=i1;
  663. +            azt.msf.cdmsf_sec0=i2;
  664. +            azt.msf.cdmsf_frame0=i3;
  665. +            if (azt.msf.cdmsf_sec0>59) azt.msf.cdmsf_sec0=59;
  666. +            if (azt.msf.cdmsf_frame0>74) azt.msf.cdmsf_frame0=74;
  667. +            rc=ioctl(drive,CDROMREADMODE2,&azt.msf);
  668. +            if (rc<0) printf("CDROMREADMODE2: rc=%d.\n",rc);
  669. +            else display(CD_FRAMESIZE_RAW,azt.buf); /* currently only 2336 */
  670. +            break;  
  671. +#endif
  672. +        case 'v':
  673. +            printf("--Channel 0 (Left)  (0-255): ");
  674. +            scanf("%d",&i1);
  675. +            volctrl.channel0=i1;
  676. +            printf("--Channel 1 (Right) (0-255): ");
  677. +            scanf("%d",&i1);
  678. +            volctrl.channel1=i1;
  679. +            volctrl.channel2=0;
  680. +            volctrl.channel3=0;
  681. +            rc=ioctl(drive,CDROMVOLCTRL,&volctrl);
  682. +            if (rc<0) printf("CDROMVOLCTRL: rc=%d.\n",rc);
  683. +            break;  
  684. +        case 'q':
  685. +            close(drive);
  686. +            exit(0);
  687. +        case 'h':
  688. +            help();
  689. +            break;
  690. +        case 'T': /* display TOC entry - without involving the driver */
  691. +            scanf("%d",&i);
  692. +            if ((i<hdr.cdth_trk0)||(i>hdr.cdth_trk1))
  693. +                printf("invalid track number.\n");
  694. +            else
  695. +                printf("TocEntry %02d: adr=%01X ctrl=%01X msf=%02d:%02d:%02d mode=%02X\n",
  696. +                       TocEntry[i].cdte_track,
  697. +                       TocEntry[i].cdte_adr,
  698. +                       TocEntry[i].cdte_ctrl,
  699. +                       TocEntry[i].cdte_addr.msf.minute,
  700. +                       TocEntry[i].cdte_addr.msf.second,
  701. +                       TocEntry[i].cdte_addr.msf.frame,
  702. +                       TocEntry[i].cdte_datamode);
  703. +            break;
  704. +        case 'A': /* read audio data into file */
  705. +            printf("Address (min:sec:frm) ? ");
  706. +            scanf("%d:%d:%d",&i1,&i2,&i3);
  707. +            read_audio.addr.msf.minute=i1;
  708. +            read_audio.addr.msf.second=i2;
  709. +            read_audio.addr.msf.frame=i3;
  710. +            read_audio.addr_format=CDROM_MSF;
  711. +            printf("# of frames ? ");
  712. +            scanf("%d",&i1);
  713. +            read_audio.nframes=i1;
  714. +            k=read_audio.nframes*CD_FRAMESIZE_RAW;
  715. +            read_audio.buf=malloc(k);
  716. +            if (read_audio.buf==NULL)
  717. +            {
  718. +                printf("can't malloc %d bytes.\n",k);
  719. +                break;
  720. +            }
  721. +            sprintf(filename,"audio_%02d%02d%02d_%02d.%02d\0",
  722. +                read_audio.addr.msf.minute,
  723. +                read_audio.addr.msf.second,
  724. +                read_audio.addr.msf.frame,
  725. +                read_audio.nframes,
  726. +                ++sequence);
  727. +            datafile=creat(filename, 0755);
  728. +            if (datafile<0)
  729. +            {
  730. +                printf("can't open datafile %s.\n",filename);
  731. +                break;
  732. +            }
  733. +            rc=ioctl(drive,CDROMREADAUDIO,&read_audio);
  734. +            if (rc!=0)
  735. +            {
  736. +                printf("CDROMREADAUDIO: rc=%d.\n",rc);
  737. +            }
  738. +            else
  739. +            {
  740. +                rc=write(datafile,&read_audio.buf,k);
  741. +                if (rc!=k) printf("datafile I/O error (%d).\n",rc);
  742. +            }
  743. +            close(datafile);
  744. +            break;
  745. +        case 'X': /* set EJECT_SW (0: disable, 1: enable auto-ejecting) */
  746. +            scanf("%d",&i);
  747. +            rc=ioctl(drive,CDROMEJECT_SW,i);
  748. +            if (rc!=0)
  749. +                printf("CDROMEJECT_SW: rc=%d.\n",rc);
  750. +            else
  751. +                printf("EJECT_SW set to %d\n",i);
  752. +            break;
  753. +        case 'M': /* get the multisession redirection info */
  754. +            ms_info.addr_format=CDROM_LBA;
  755. +            rc=ioctl(drive,CDROMMULTISESSION,&ms_info);
  756. +            if (rc!=0)
  757. +            {
  758. +                printf("CDROMMULTISESSION(lba): rc=%d.\n",rc);
  759. +            }
  760. +            else
  761. +            {
  762. +                if (ms_info.xa_flag) printf("MultiSession offset (lba): %d (0x%06X)\n",ms_info.addr.lba,ms_info.addr.lba);
  763. +                else
  764. +                {
  765. +                    printf("this CD is not an XA disk.\n");
  766. +                    break;
  767. +                }
  768. +            }
  769. +            ms_info.addr_format=CDROM_MSF;
  770. +            rc=ioctl(drive,CDROMMULTISESSION,&ms_info);
  771. +            if (rc!=0)
  772. +            {
  773. +                printf("CDROMMULTISESSION(msf): rc=%d.\n",rc);
  774. +            }
  775. +            else
  776. +            {
  777. +                if (ms_info.xa_flag)
  778. +                    printf("MultiSession offset (msf): %02d:%02d:%02d (0x%02X%02X%02X)\n",
  779. +                           ms_info.addr.msf.minute,
  780. +                           ms_info.addr.msf.second,
  781. +                           ms_info.addr.msf.frame,
  782. +                           ms_info.addr.msf.minute,
  783. +                           ms_info.addr.msf.second,
  784. +                           ms_info.addr.msf.frame);
  785. +                else printf("this CD is not an XA disk.\n");
  786. +            }
  787. +            break;
  788. +#ifdef SBP_PRIVATE_IOCTLS
  789. +        case 'Y': /* set the driver's message level */
  790. +#if 0 /* not implemented yet */
  791. +            printf("enter switch name (f.e. DBG_CMD): ");
  792. +            scanf("%s",&dbg_switch);
  793. +            j=get_dbg_num(dbg_switch);
  794. +#else
  795. +            printf("enter DDIOCSDBG switch number: ");
  796. +            scanf("%d",&j);
  797. +#endif
  798. +            printf("enter 0 for \"off\", 1 for \"on\": ");
  799. +            scanf("%d",&i);
  800. +            if (i==0) j|=0x80;
  801. +            printf("calling \"ioctl(drive,DDIOCSDBG,%d)\"\n",j);
  802. +            rc=ioctl(drive,DDIOCSDBG,j);
  803. +            printf("DDIOCSDBG: rc=%d.\n",rc);
  804. +            break;
  805. +        case 'Z': /* set the audio buffer size */
  806. +            printf("# frames wanted: ? ");
  807. +            scanf("%d",&j);
  808. +            rc=ioctl(drive,CDROMAUDIOBUFSIZ,j);
  809. +            printf("%d frames granted.\n",rc);
  810. +            break;
  811. +        case 'V':
  812. +            rc=ioctl(drive,CDROMVOLREAD,&volctrl);
  813. +            if (rc<0) printf("CDROMVOLCTRL: rc=%d.\n",rc);
  814. +            printf("Volume: channel 0 (left) %d, channel 1 (right) %d\n",volctrl.channel0,volctrl.channel1);
  815. +            break;  
  816. +        case 'R':
  817. +            rc=ioctl(drive,CDROMRESET);
  818. +            if (rc<0) printf("CDROMRESET: rc=%d.\n",rc);
  819. +            break;
  820. +        case 'B': /* set the driver's (?) read ahead value */
  821. +            printf("enter read-ahead size: ? ");
  822. +            scanf("%d",&i);
  823. +            rc=ioctl(drive,BLKRASET,i);
  824. +            if (rc<0) printf("BLKRASET: rc=%d.\n",rc);
  825. +            break;
  826. +#endif SBP_PRIVATE_IOCTLS
  827. +        default:
  828. +            printf("unknown command: \"%s\".\n",command);
  829. +            break;
  830. +        }
  831. +    }
  832. +}
  833. +/*==========================================================================*/
  834. +/*
  835. + * Overrides for Emacs so that we follow Linus's tabbing style.
  836. + * Emacs will notice this stuff at the end of the file and automatically
  837. + * adjust the settings for this buffer only.  This must remain at the end
  838. + * of the file. 
  839. + * ---------------------------------------------------------------------------
  840. + * Local variables:
  841. + * c-indent-level: 8
  842. + * c-brace-imaginary-offset: 0
  843. + * c-brace-offset: -8
  844. + * c-argdecl-indent: 8
  845. + * c-label-offset: -8
  846. + * c-continued-statement-offset: 8
  847. + * c-continued-brace-offset: 0
  848. + * End:
  849. + */
  850. +
  851. diff -u --recursive --new-file v1.2.7/linux/drivers/block/sbpcd.c linux/drivers/block/sbpcd.c
  852. --- v1.2.7/linux/drivers/block/sbpcd.c    Wed Mar 29 06:52:57 1995
  853. +++ linux/drivers/block/sbpcd.c    Tue May  2 07:26:00 1995
  854. @@ -6,15 +6,12 @@
  855.   *            Panasonic CI-101P.
  856.   *            Also for the Longshine LCS-7260 drive.
  857.   *            Also for the IBM "External ISA CD-Rom" drive.
  858. - *            Still not for the CreativeLabs CD200 drive (but should work soon).
  859. - *            Not for the TEAC CD-55A drive (separate project now).
  860. + *            Also for the CreativeLabs CD200 drive (but I still need some
  861. + *            detailed bug reports).
  862. + *            Also for the TEAC CD-55A drive.
  863.   *            Not for Funai or Sanyo drives.
  864.   *
  865. - *  NOTE:     This is release 3.4.
  866. - *            It works with my SbPro & drive CR-521 V2.11 from 2/92
  867. - *            and with the CR-562-B V0.75 on a "naked" Panasonic
  868. - *            CI-101P interface. And vice versa. 
  869. - *  
  870. + *  NOTE:     This is release 3.6.
  871.   *
  872.   *  VERSION HISTORY
  873.   *
  874. @@ -31,8 +28,8 @@
  875.   *
  876.   *  0.4  use MAJOR 25 definitely.
  877.   *       Almost total re-design to support double-speed drives and
  878. - *       "naked" (no sound) interface cards.
  879. - *       Flow control should be exact now (tell me if not).
  880. + *       "naked" (no sound) interface cards ("LaserMate" interface type).
  881. + *       Flow control should be exact now.
  882.   *       Don't occupy the SbPro IRQ line (not needed either); will
  883.   *       live together with Hannu Savolainen's sndkit now.
  884.   *     Speeded up data transfer to 150 kB/sec, with help from Kai
  885. @@ -55,12 +52,12 @@
  886.   *       Formal redesign to add DDI debugging.
  887.   *       There are still flaws in IOCTL (workman with double speed drive).
  888.   *
  889. - *  1.0  Added support for all drive ids (0...3, no longer only 0)
  890. + *  1.0  Added support for all drive IDs (0...3, no longer only 0)
  891.   *       and up to 4 drives on one controller.
  892.   *       Added "#define MANY_SESSION" for "old" multi session CDs.
  893.   *
  894.   *  1.1  Do SpinUp for new drives, too.
  895. - *       Revised for clean compile under "old" kernels (pl9).
  896. + *       Revised for clean compile under "old" kernels (0.99pl9).
  897.   *
  898.   *  1.2  Found the "workman with double-speed drive" bug: use the driver's
  899.   *       audio_state, not what the drive is reporting with ReadSubQ.
  900. @@ -68,8 +65,8 @@
  901.   *  1.3  Minor cleanups.
  902.   *       Refinements regarding Workman.
  903.   *
  904. - *  1.4  Read XA disks (PhotoCDs) with "old" drives, too (but possibly only
  905. - *       the first session - I could not try a "multi-session" CD yet).
  906. + *  1.4  Read XA disks (PhotoCDs) with "old" drives, too (but only the first
  907. + *       session - no chance to fully access a "multi-session" CD).
  908.   *       This currently still is too slow (50 kB/sec) - but possibly
  909.   *       the old drives won't do it faster.
  910.   *       Implemented "door (un)lock" for new drives (still does not work
  911. @@ -123,7 +120,7 @@
  912.   *       Implemented "close tray" (done automatically during open).
  913.   *
  914.   *  2.4  Use different names for device registering.
  915. - *       
  916. + *
  917.   *  2.5  Added "#if EJECT" code (default: enabled) to automatically eject
  918.   *       the tray during last call to "sbpcd_release".
  919.   *       Added "#if JUKEBOX" code (default: disabled) to automatically eject
  920. @@ -132,11 +129,11 @@
  921.   *       SOUND_BASE (in sbpcd.h) accordingly (default: disabled).
  922.   *
  923.   *  2.6  Nothing new.  
  924. - *       
  925. + *
  926.   *  2.7  Added CDROMEJECT_SW ioctl to set the "EJECT" behavior on the fly:
  927.   *       0 disables, 1 enables auto-ejecting. Useful to keep the tray in
  928.   *       during shutdown.
  929. - *       
  930. + *
  931.   *  2.8  Added first support (still BETA, I need feedback or a drive) for
  932.   *       the Longshine LCS-7260 drives. They appear as double-speed drives
  933.   *       using the "old" command scheme, extended by tray control and door
  934. @@ -148,8 +145,8 @@
  935.   *       16..20).
  936.   *       Changed default of the "JUKEBOX" define. If you use this default,
  937.   *       your tray will eject if you try to mount without a disk in. Next
  938. - *       mount command will insert the tray - so, just insert a disk. ;-)
  939. - *       
  940. + *       mount command will insert the tray - so, just fill in a disk. ;-)
  941. + *
  942.   *  2.9  Fulfilled the Longshine LCS-7260 support; with great help and
  943.   *       experiments by Serge Robyns.
  944.   *       First attempts to support the TEAC CD-55A drives; but still not
  945. @@ -176,10 +173,10 @@
  946.   *       jumpered drive ID. This implies modifications to the /dev/sbpcd*
  947.   *       entries for some people, but will help the DAU (german TLA, english:
  948.   *       "newbie", maybe ;-) to install his "first" system from a CD.
  949. - *     
  950. + *
  951.   *  3.2  Still testing with CD200 and CD-55A drives.
  952.   *
  953. - *  3.3  Working with CD200 support. Maybe a simple read is already possible.
  954. + *  3.3  Working with CD200 support.
  955.   *
  956.   *  3.4  Auto-probing stops if an address of 0 is seen (to be entered with
  957.   *       the kernel command line).
  958. @@ -187,20 +184,40 @@
  959.   *       disabled, and the internal read ahead data buffer has a reduced size
  960.   *       of 4 kB; so, throughput may be reduced a little bit with slow CPUs.
  961.   *
  962. + *  3.5  Provisions to handle weird photoCDs which have an interrupted
  963. + *       "formatting" immediately after the last frames of some files: simply
  964. + *       never "read ahead" with MultiSession CDs. By this, CPU usage may be
  965. + *       increased with those CDs, and there may be a loss in speed.
  966. + *       Re-structured the messaging system.
  967. + *       The "loadable" version no longer has a limited READ_AUDIO buffer
  968. + *       size.
  969. + *       Removed "MANY_SESSION" handling for "old" multi session CDs.
  970. + *       Added "private" IOCTLs CDROMRESET and CDROMVOLREAD.
  971. + *       Started again to support the TEAC CD-55A drives, now that I found
  972. + *       the money for "my own" drive. ;-)
  973. + *       The TEAC CD-55A support is fairly working now.
  974. + *       I have measured that the drive "delivers" at 600 kB/sec (even with
  975. + *       bigger requests than the drive's 64 kB buffer can satisfy), but
  976. + *       the "real" rate does not exceed 520 kB/sec at the moment. 
  977. + *       Caused by the various changes to build in TEAC support, the timed
  978. + *       loops are de-optimized at the moment (less throughput with CR-52x
  979. + *       drives, and the TEAC will give speed only with SBP_BUFFER_FRAMES 64).
  980. + *
  981. + *  3.6  Fixed TEAC data read problems with SbPro interfaces.
  982. + *       Initial size of the READ_AUDIO buffer is 0. Can get set to any size
  983. + *       during runtime.
  984. + *
  985.   *  TODO
  986.   *
  987.   *     disk change detection
  988.   *     allow & synchronize multi-activity
  989.   *        (data + audio + ioctl + disk change, multiple drives)
  990. - *     implement multi-controller-support with a single driver
  991.   *     implement "read all subchannel data" (96 bytes per frame)
  992.   *
  993. - *
  994.   *     special thanks to Kai Makisara (kai.makisara@vtt.fi) for his fine
  995.   *     elaborated speed-up experiments (and the fabulous results!), for
  996.   *     the "push" towards load-free wait loops, and for the extensive mail
  997.   *     thread which brought additional hints and bug fixes.
  998. - * 
  999.   *
  1000.   *   Copyright (C) 1993, 1994, 1995  Eberhard Moenkeberg <emoenke@gwdg.de>
  1001.   *
  1002. @@ -232,10 +249,12 @@
  1003.  #ifdef MODULE
  1004.  #include <linux/module.h>
  1005.  #include <linux/version.h>
  1006. -#include <linux/malloc.h>
  1007.  #ifndef CONFIG_MODVERSIONS
  1008.  char kernel_version[]=UTS_RELEASE;
  1009.  #endif
  1010. +#else
  1011. +#define MOD_INC_USE_COUNT
  1012. +#define MOD_DEC_USE_COUNT
  1013.  #endif MODULE
  1014.  
  1015.  #include <linux/errno.h>
  1016. @@ -247,12 +266,12 @@
  1017.  #include <linux/cdrom.h>
  1018.  #include <linux/ioport.h>
  1019.  #include <linux/major.h> 
  1020. -#include <linux/sbpcd.h>
  1021.  #include <linux/string.h>
  1022.  #include <asm/system.h>
  1023.  #include <asm/io.h>
  1024.  #include <asm/segment.h>
  1025.  #include <stdarg.h>
  1026. +#include <linux/sbpcd.h>
  1027.  
  1028.  #if !(SBPCD_ISSUE-1)
  1029.  #define MAJOR_NR MATSUSHITA_CDROM_MAJOR
  1030. @@ -267,38 +286,9 @@
  1031.  #define MAJOR_NR MATSUSHITA_CDROM4_MAJOR /* fourth driver issue */
  1032.  #endif
  1033.  
  1034. -#ifdef MODULE
  1035. -#include "/usr/src/linux/drivers/block/blk.h"
  1036. -#else
  1037.  #include "blk.h"
  1038. -#define MOD_INC_USE_COUNT
  1039. -#define MOD_DEC_USE_COUNT
  1040. -#endif MODULE
  1041. -
  1042. -#define VERSION "3.4 Eberhard Moenkeberg <emoenke@gwdg.de>"
  1043. -
  1044. -/*
  1045. - *
  1046. - */
  1047. -#define READ_AUDIO 4 /* max. number of audio frames to read with one */
  1048. -                     /* request (allocates n* 2352 bytes kernel memory!) */
  1049. -#define JUKEBOX 1 /* tray control: eject tray if no disk is in */
  1050. -#define EJECT 1 /* tray control: eject tray after last use */
  1051. -#define LONG_TIMING 0 /* test against timeouts with "gold" CDs on CR-521 */
  1052. -#define MANY_SESSION 0 /* this will conflict with "true" multi-session! */
  1053. -#undef  FUTURE
  1054. -#define WORKMAN 1 /* some testing stuff to make it better */
  1055. -#define CDMKE /* makes timing independent of processor speed */
  1056. -
  1057. -#undef XA_TEST1
  1058. -#define XA_TEST2
  1059. -
  1060. -#define TEST_UPC 0
  1061. -#define SPEA_TEST 0
  1062. -#define PRINTK_BUG 0
  1063. -#define TEST_STI 0
  1064.  
  1065. -#define DISTRIBUTION 1 /* I use it with a 0 here */
  1066. +#define VERSION "v3.6-1 Eberhard Moenkeberg <emoenke@gwdg.de>"
  1067.  
  1068.  #if 0
  1069.  #define INLINE
  1070. @@ -328,11 +318,6 @@
  1071.  #define SBPCD_INIT(a,b) sbpcd4_init(a,b)
  1072.  #endif
  1073.  /*==========================================================================*/
  1074. -#if MANY_SESSION
  1075. -#undef LONG_TIMING
  1076. -#define LONG_TIMING 1
  1077. -#endif
  1078. -/*==========================================================================*/
  1079.  #if SBPCD_DIS_IRQ
  1080.  #define SBPCD_CLI cli()
  1081.  #define SBPCD_STI sti()
  1082. @@ -351,58 +336,58 @@
  1083.   * The possibly conflicting ethernet card addresses get NOT probed 
  1084.   * by default - to minimize the hang possibilities. 
  1085.   *
  1086. - * The SB Pro addresses get "mirrored" at 0x6xx - to avoid a type error,
  1087. - * the 0x2xx-addresses must get checked before 0x6xx.
  1088. + * The SB Pro addresses get "mirrored" at 0x6xx and some more locations - to
  1089. + * avoid a type error, the 0x2xx-addresses must get checked before 0x6xx.
  1090.   *
  1091.   * send mail to emoenke@gwdg.de if your interface card is not FULLY
  1092.   * represented here.
  1093.   */
  1094.  #if !(SBPCD_ISSUE-1)
  1095. -static int sbpcd_probe[] = 
  1096. +static int sbpcd[] = 
  1097.  {
  1098. -  CDROM_PORT, SBPRO, /* probe with user's setup first */
  1099. +    CDROM_PORT, SBPRO, /* probe with user's setup first */
  1100.  #if DISTRIBUTION
  1101. -  0x230, 1, /* Soundblaster Pro and 16 (default) */
  1102. -  0x300, 0, /* CI-101P (default), WDH-7001C (default),
  1103. -           Galaxy (default), Reveal (one default) */
  1104. -  0x250, 1, /* OmniCD default, Soundblaster Pro and 16 */
  1105. -  0x260, 1, /* OmniCD */
  1106. -  0x320, 0, /* Lasermate, CI-101P, WDH-7001C, Galaxy, Reveal (other default),
  1107. -               Longshine LCS-6853 (default) */
  1108. -  0x338, 0, /* Reveal Sound Wave 32 card model #SC600 */
  1109. -  0x340, 0, /* Mozart sound card (default), Lasermate, CI-101P */
  1110. -  0x360, 0, /* Lasermate, CI-101P */
  1111. -  0x270, 1, /* Soundblaster 16 */
  1112. -  0x670, 0, /* "sound card #9" */
  1113. -  0x690, 0, /* "sound card #9" */
  1114. -  0x330, 2, /* SPEA Media FX (default) */
  1115. -  0x320, 2, /* SPEA Media FX */
  1116. -  0x340, 2, /* SPEA Media FX */
  1117. -  0x634, 0, /* some newer sound cards */
  1118. -  0x638, 0, /* some newer sound cards */
  1119. -/* due to incomplete address decoding of the SbPro card, these must be last */
  1120. -  0x630, 0, /* "sound card #9" (default) */
  1121. -  0x650, 0, /* "sound card #9" */
  1122. +    0x230, 1, /* Soundblaster Pro and 16 (default) */
  1123. +    0x300, 0, /* CI-101P (default), WDH-7001C (default),
  1124. +             Galaxy (default), Reveal (one default) */
  1125. +    0x250, 1, /* OmniCD default, Soundblaster Pro and 16 */
  1126. +    0x260, 1, /* OmniCD */
  1127. +    0x320, 0, /* Lasermate, CI-101P, WDH-7001C, Galaxy, Reveal (other default),
  1128. +             Longshine LCS-6853 (default) */
  1129. +    0x338, 0, /* Reveal Sound Wave 32 card model #SC600 */
  1130. +    0x340, 0, /* Mozart sound card (default), Lasermate, CI-101P */
  1131. +    0x360, 0, /* Lasermate, CI-101P */
  1132. +    0x270, 1, /* Soundblaster 16 */
  1133. +    0x670, 0, /* "sound card #9" */
  1134. +    0x690, 0, /* "sound card #9" */
  1135. +    0x330, 2, /* SPEA Media FX (default) */
  1136. +    0x320, 2, /* SPEA Media FX */
  1137. +    0x340, 2, /* SPEA Media FX */
  1138. +    0x634, 0, /* some newer sound cards */
  1139. +    0x638, 0, /* some newer sound cards */
  1140. +    0x230, 1, /* some newer sound cards */
  1141. +    /* due to incomplete address decoding of the SbPro card, these must be last */
  1142. +    0x630, 0, /* "sound card #9" (default) */
  1143. +    0x650, 0, /* "sound card #9" */
  1144.  #ifdef MODULE
  1145. -/*
  1146. - * some "hazardous" locations (no harm with the loadable version)
  1147. - * (will stop the bus if a NE2000 ethernet card resides at offset -0x10)
  1148. - */
  1149. -  0x330, 0, /* Lasermate, CI-101P, WDH-7001C */
  1150. -  0x350, 0, /* Lasermate, CI-101P */
  1151. -  0x350, 2, /* SPEA Media FX */
  1152. -  0x370, 0, /* Lasermate, CI-101P */
  1153. -  0x290, 1, /* Soundblaster 16 */
  1154. -  0x310, 0, /* Lasermate, CI-101P, WDH-7001C */
  1155. +    /*
  1156. +     * some "hazardous" locations (no harm with the loadable version)
  1157. +     * (will stop the bus if a NE2000 ethernet card resides at offset -0x10)
  1158. +     */
  1159. +    0x330, 0, /* Lasermate, CI-101P, WDH-7001C */
  1160. +    0x350, 0, /* Lasermate, CI-101P */
  1161. +    0x350, 2, /* SPEA Media FX */
  1162. +    0x370, 0, /* Lasermate, CI-101P */
  1163. +    0x290, 1, /* Soundblaster 16 */
  1164. +    0x310, 0, /* Lasermate, CI-101P, WDH-7001C */
  1165.  #endif MODULE
  1166.  #endif DISTRIBUTION
  1167.  };
  1168.  #else
  1169. -static int sbpcd_probe[] = {CDROM_PORT, SBPRO}; /* probe with user's setup only */
  1170. +static int sbpcd[] = {CDROM_PORT, SBPRO}; /* probe with user's setup only */
  1171.  #endif
  1172.  
  1173. -#define NUM_PROBE  (sizeof(sbpcd_probe) / sizeof(int))
  1174. -
  1175. +#define NUM_PROBE  (sizeof(sbpcd) / sizeof(int))
  1176.  
  1177.  /*==========================================================================*/
  1178.  /*
  1179. @@ -425,9 +410,15 @@
  1180.  /*
  1181.   * the forward references:
  1182.   */
  1183. +static void sbp_sleep(u_int);
  1184. +static void mark_timeout_delay(u_long);
  1185. +static void mark_timeout_data(u_long);
  1186. +#if 0
  1187. +static void mark_timeout_audio(u_long);
  1188. +#endif
  1189.  static void sbp_read_cmd(void);
  1190.  static int sbp_data(void);
  1191. -static int cmd_out(int);
  1192. +static int cmd_out(void);
  1193.  static int DiskInfo(void);
  1194.  static int sbpcd_chk_disk_change(dev_t);
  1195.  
  1196. @@ -445,11 +436,11 @@
  1197.   * (1<<DBG_TOC)  tell TocEntry values
  1198.   * (1<<DBG_IOC)  ioctl trace
  1199.   * (1<<DBG_STA)  "ResponseStatus" trace
  1200. - * (1<<DBG_ERR)  "xx_ReadError" trace
  1201. + * (1<<DBG_ERR)  "cc_ReadError" trace
  1202.   * (1<<DBG_CMD)  "cmd_out" trace
  1203.   * (1<<DBG_WRN)  give explanation before auto-probing
  1204.   * (1<<DBG_MUL)  multi session code test
  1205. - * (1<<DBG_ID)   "drive_id != 0" test code
  1206. + * (1<<DBG_IDX)  "drive_id != 0" test code
  1207.   * (1<<DBG_IOX)  some special information
  1208.   * (1<<DBG_DID)  drive ID test
  1209.   * (1<<DBG_RES)  drive reset info
  1210. @@ -457,24 +448,24 @@
  1211.   * (1<<DBG_IOS)  ioctl trace: "subchannel"
  1212.   * (1<<DBG_IO2)  ioctl trace: general
  1213.   * (1<<DBG_UPC)  show UPC info
  1214. - * (1<<DBG_XA)   XA mode debugging
  1215. + * (1<<DBG_XA1)  XA mode debugging
  1216.   * (1<<DBG_LCK)  door (un)lock info
  1217. - * (1<<DBG_SQ)   dump SubQ frame
  1218. + * (1<<DBG_SQ1)   dump SubQ frame
  1219.   * (1<<DBG_AUD)  "read audio" debugging
  1220.   * (1<<DBG_SEQ)  Sequoia interface configuration trace
  1221.   * (1<<DBG_LCS)  Longshine LCS-7260 debugging trace
  1222.   * (1<<DBG_CD2)  MKE CD200 debugging trace
  1223. + * (1<<DBG_TEA)  TEAC CD-55A debugging trace
  1224. + * (1<<DBG_TE2)  TEAC CD-55A debugging trace, 2nd level
  1225.   * (1<<DBG_000)  unnecessary information
  1226.   */
  1227.  #if DISTRIBUTION
  1228. -static int sbpcd_debug =  (1<<DBG_INF) |
  1229. -                          (1<<DBG_WRN) |
  1230. -                          (1<<DBG_MUL);
  1231. +static int sbpcd_debug = (1<<DBG_INF);
  1232.  #else
  1233. -static int sbpcd_debug =  (1<<DBG_INF) |
  1234. -                          (1<<DBG_TOC) |
  1235. -                          (1<<DBG_MUL) |
  1236. -                          (1<<DBG_UPC);
  1237. +static int sbpcd_debug = ((1<<DBG_INF) |
  1238. +              (1<<DBG_TOC) |
  1239. +              (1<<DBG_MUL) |
  1240. +              (1<<DBG_UPC));
  1241.  #endif DISTRIBUTION
  1242.  
  1243.  static int sbpcd_ioaddr = CDROM_PORT;    /* default I/O base address */
  1244. @@ -493,12 +484,16 @@
  1245.  static struct cdrom_read_audio read_audio;
  1246.  static struct cdrom_multisession ms_info;
  1247.  
  1248. +static unsigned char msgnum=0;
  1249. +static char msgbuf[80];
  1250. +
  1251.  static char *str_sb = "SoundBlaster";
  1252.  static char *str_sb_l = "soundblaster";
  1253.  static char *str_lm = "LaserMate";
  1254.  static char *str_sp = "SPEA";
  1255.  static char *str_sp_l = "spea";
  1256.  char *type;
  1257. +
  1258.  #if !(SBPCD_ISSUE-1)
  1259.  static char *major_name="sbpcd";
  1260.  #endif
  1261. @@ -519,21 +514,17 @@
  1262.  #endif FUTURE
  1263.  
  1264.  /*==========================================================================*/
  1265. -#ifdef MODULE
  1266. -/* some restrictions for the "loadable" version */
  1267. -#define SBP_BUFFER_FRAMES 2 /* kmalloc() limit */
  1268. -#define SBP_BUFFER_AUDIO_FRAMES 0
  1269. -#else
  1270. -#define SBP_BUFFER_FRAMES 4 /* driver's own read_ahead, data mode */
  1271. -#define SBP_BUFFER_AUDIO_FRAMES READ_AUDIO /* buffer for read audio mode */
  1272. -#endif MODULE
  1273. +#define SBP_BUFFER_FRAMES 8 /* driver's own read_ahead, data mode */
  1274.  /*==========================================================================*/
  1275.  
  1276.  static u_char family0[]="MATSHITA"; /* MKE CR-52x */
  1277. -static u_char family1[]="CR-56"; /* MKE CR-56x */
  1278. -static u_char family2[]="CD200"; /* MKE CD200 */
  1279. +static u_char family1[]="CR-56";    /* MKE CR-56x */
  1280. +static u_char family2[]="CD200";    /* MKE CD200 */
  1281.  static u_char familyL[]="LCS-7260"; /* Longshine LCS-7260 */
  1282. +static u_char familyT[]="CD-55";    /* TEAC CD-55A */
  1283.  
  1284. +static u_int recursion=0; /* internal testing only */
  1285. +static u_int fatal_err=0; /* internal testing only */
  1286.  static u_int response_count=0;
  1287.  static u_int flags_cmd_out;
  1288.  static u_char cmd_type=0;
  1289. @@ -542,8 +533,13 @@
  1290.  static u_char xa_head_buf[CD_XA_HEAD];
  1291.  static u_char xa_tail_buf[CD_XA_TAIL];
  1292.  
  1293. +static u_long timeout;
  1294.  static u_char busy_data=0, busy_audio=0; /* true semaphores would be safer */
  1295. -static u_char timed_out=0;
  1296. +static volatile u_char timed_out_delay=0;
  1297. +static volatile u_char timed_out_data=0;
  1298. +#if 0
  1299. +static volatile u_char timed_out_audio=0;
  1300. +#endif
  1301.  static u_int datarate= 1000000;
  1302.  static u_int maxtim16=16000000;
  1303.  static u_int maxtim04= 4000000;
  1304. @@ -562,7 +558,7 @@
  1305.  /*==========================================================================*/
  1306.  
  1307.  static int ndrives=0;
  1308. -static u_char drv_pattern[4]={speed_auto,speed_auto,speed_auto,speed_auto};
  1309. +static u_char drv_pattern[NR_SBPCD]={speed_auto,speed_auto,speed_auto,speed_auto};
  1310.  static int sbpcd_blocksizes[NR_SBPCD] = {0, };
  1311.  
  1312.  /*==========================================================================*/
  1313. @@ -572,163 +568,211 @@
  1314.  static int d=0; /* DriveStruct index: drive number */
  1315.  
  1316.  static struct {
  1317. -  char drv_id; /* "jumpered" drive ID or -1 */
  1318. -  char drv_sel; /* drive select lines bits */
  1319. -
  1320. -  char drive_model[9];
  1321. -  u_char firmware_version[4];
  1322. -  char f_eject; /* auto-eject flag: 0 or 1 */
  1323. -  u_char *sbp_buf; /* Pointer to internal data buffer,
  1324. -                           space allocated during sbpcd_init() */
  1325. -  int sbp_first_frame;  /* First frame in buffer */
  1326. -  int sbp_last_frame;   /* Last frame in buffer  */
  1327. -  int sbp_read_frames;   /* Number of frames being read to buffer */
  1328. -  int sbp_current;       /* Frame being currently read */
  1329. -
  1330. -  u_char mode;           /* read_mode: READ_M1, READ_M2, READ_SC, READ_AU */
  1331. -  u_char *aud_buf;                  /* Pointer to audio data buffer,
  1332. -                                 space allocated during sbpcd_init() */
  1333. -  u_char drv_type;
  1334. -  u_char drv_options;
  1335. -  u_char status_byte;
  1336. -  u_char diskstate_flags;
  1337. -  u_char sense_byte;
  1338. -  
  1339. -  u_char CD_changed;
  1340. -  u_char open_count;
  1341. -  u_char error_byte;
  1342. -  
  1343. -  u_char f_multisession;
  1344. -  u_int lba_multi;
  1345. -  int first_session;
  1346. -  int last_session;
  1347. -  
  1348. -  u_char audio_state;
  1349. -  u_int pos_audio_start;
  1350. -  u_int pos_audio_end;
  1351. -  char vol_chan0;
  1352. -  u_char vol_ctrl0;
  1353. -  char vol_chan1;
  1354. -  u_char vol_ctrl1;
  1355. +    char drv_id;           /* "jumpered" drive ID or -1 */
  1356. +    char drv_sel;          /* drive select lines bits */
  1357. +    
  1358. +    char drive_model[9];
  1359. +    u_char firmware_version[4];
  1360. +    char f_eject;          /* auto-eject flag: 0 or 1 */
  1361. +    u_char *sbp_buf;       /* Pointer to internal data buffer,
  1362. +                  space allocated during sbpcd_init() */
  1363. +    u_int sbp_bufsiz;      /* size of sbp_buf (# of frames) */
  1364. +    int sbp_first_frame;   /* First frame in buffer */
  1365. +    int sbp_last_frame;    /* Last frame in buffer  */
  1366. +    int sbp_read_frames;   /* Number of frames being read to buffer */
  1367. +    int sbp_current;       /* Frame being currently read */
  1368. +    
  1369. +    u_char mode;           /* read_mode: READ_M1, READ_M2, READ_SC, READ_AU */
  1370. +    u_char *aud_buf;       /* Pointer to audio data buffer,
  1371. +                  space allocated during sbpcd_init() */
  1372. +    u_int sbp_audsiz;      /* size of aud_buf (# of raw frames) */
  1373. +    u_char drv_type;
  1374. +    u_char drv_options;
  1375. +    int status_bits;
  1376. +    u_char diskstate_flags;
  1377. +    u_char sense_byte;
  1378. +    
  1379. +    u_char CD_changed;
  1380. +    char open_count;
  1381. +    u_char error_byte;
  1382. +    
  1383. +    u_char f_multisession;
  1384. +    u_int lba_multi;
  1385. +    int first_session;
  1386. +    int last_session;
  1387. +    
  1388. +    u_char audio_state;
  1389. +    u_int pos_audio_start;
  1390. +    u_int pos_audio_end;
  1391. +    char vol_chan0;
  1392. +    u_char vol_ctrl0;
  1393. +    char vol_chan1;
  1394. +    u_char vol_ctrl1;
  1395.  #if 000 /* no supported drive has it */
  1396. -  char vol_chan2;
  1397. -  u_char vol_ctrl2;
  1398. -  char vol_chan3;
  1399. -  u_char vol_ctrl3;
  1400. +    char vol_chan2;
  1401. +    u_char vol_ctrl2;
  1402. +    char vol_chan3;
  1403. +    u_char vol_ctrl3;
  1404.  #endif 000
  1405. -  
  1406. -  u_char SubQ_ctl_adr;
  1407. -  u_char SubQ_trk;
  1408. -  u_char SubQ_pnt_idx;
  1409. -  u_int SubQ_run_tot;
  1410. -  u_int SubQ_run_trk;
  1411. -  u_char SubQ_whatisthis;
  1412. -  
  1413. -  u_char UPC_ctl_adr;
  1414. -  u_char UPC_buf[7];
  1415. -  
  1416. -  int CDsize_blk;
  1417. -  int frame_size;
  1418. -  int CDsize_frm;
  1419. -  
  1420. -  u_char xa_byte; /* 0x20: XA capabilities */
  1421. -  u_char n_first_track; /* binary */
  1422. -  u_char n_last_track; /* binary (not bcd), 0x01...0x63 */
  1423. -  u_int size_msf; /* time of whole CD, position of LeadOut track */
  1424. -  u_int size_blk;
  1425. -  
  1426. -  u_char TocEnt_nixbyte; /* em */
  1427. -  u_char TocEnt_ctl_adr;
  1428. -  u_char TocEnt_number;
  1429. -  u_char TocEnt_format; /* em */
  1430. -  u_int TocEnt_address;
  1431. -  u_char ored_ctl_adr; /* to detect if CDROM contains data tracks */
  1432. -  
  1433. -  struct {
  1434. -    u_char nixbyte; /* em */
  1435. -    u_char ctl_adr; /* 0x4x: data, 0x0x: audio */
  1436. -    u_char number;
  1437. -    u_char format; /* em */ /* 0x00: lba, 0x01: msf */
  1438. -    u_int address;
  1439. -  } TocBuffer[MAX_TRACKS+1]; /* last entry faked */ 
  1440. -  
  1441. -  int in_SpinUp;
  1442. -  
  1443. -} DriveStruct[NR_SBPCD];
  1444. +    u_char volume_control; /* TEAC on/off bits */
  1445. +    
  1446. +    u_char SubQ_ctl_adr;
  1447. +    u_char SubQ_trk;
  1448. +    u_char SubQ_pnt_idx;
  1449. +    u_int SubQ_run_tot;
  1450. +    u_int SubQ_run_trk;
  1451. +    u_char SubQ_whatisthis;
  1452. +    
  1453. +    u_char UPC_ctl_adr;
  1454. +    u_char UPC_buf[7];
  1455. +    
  1456. +    int CDsize_blk;
  1457. +    int frame_size;
  1458. +    int CDsize_frm;
  1459. +    
  1460. +    u_char xa_byte; /* 0x20: XA capabilities */
  1461. +    u_char n_first_track; /* binary */
  1462. +    u_char n_last_track; /* binary (not bcd), 0x01...0x63 */
  1463. +    u_int size_msf; /* time of whole CD, position of LeadOut track */
  1464. +    u_int size_blk;
  1465. +    
  1466. +    u_char TocEnt_nixbyte; /* em */
  1467. +    u_char TocEnt_ctl_adr;
  1468. +    u_char TocEnt_number;
  1469. +    u_char TocEnt_format; /* em */
  1470. +    u_int TocEnt_address;
  1471. +    u_char ored_ctl_adr; /* to detect if CDROM contains data tracks */
  1472. +    
  1473. +    struct {
  1474. +        u_char nixbyte; /* em */
  1475. +        u_char ctl_adr; /* 0x4x: data, 0x0x: audio */
  1476. +        u_char number;
  1477. +        u_char format; /* em */ /* 0x00: lba, 0x01: msf */
  1478. +        u_int address;
  1479. +    } TocBuffer[MAX_TRACKS+1]; /* last entry faked */ 
  1480. +    
  1481. +    int in_SpinUp; /* CR-52x test flag */
  1482. +    int n_bytes; /* TEAC awaited response count */
  1483. +    u_char error_state, b3, b4; /* TEAC command error state */
  1484. +    u_char f_drv_error; /* TEAC command error flag */
  1485. +    u_char speed_byte;
  1486. +    int frmsiz;
  1487. +    u_char f_XA; /* 1: XA */
  1488. +    u_char type_byte; /* 0, 1, 3 */
  1489. +    u_char mode_xb_6;
  1490. +    u_char mode_yb_7;
  1491. +    u_char mode_xb_8;
  1492. +    u_char delay;
  1493. +    
  1494. +} D_S[NR_SBPCD];
  1495.  
  1496.  /*
  1497.   * drive space ends here (needed separate for each unit)
  1498.   */
  1499.  /*==========================================================================*/
  1500. +#if 0
  1501. +unsigned long cli_sti; /* for saving the processor flags */
  1502. +#endif
  1503. +/*==========================================================================*/
  1504. +static struct timer_list delay_timer = { NULL, NULL, 0, 0, mark_timeout_delay};
  1505. +static struct timer_list data_timer = { NULL, NULL, 0, 0, mark_timeout_data};
  1506. +#if 0
  1507. +static struct timer_list audio_timer = { NULL, NULL, 0, 0, mark_timeout_audio};
  1508. +#endif
  1509.  /*==========================================================================*/
  1510.  /*
  1511.   * DDI interface
  1512.   */
  1513. -static void sbpcd_dprintf(int level, char *fmt, ...)
  1514. +static void msg(int level, char *fmt, ...)
  1515.  {
  1516. -  char buff[256];
  1517. -  va_list args;
  1518. -  extern int vsprintf(char *buf, const char *fmt, va_list args);
  1519. -
  1520. -  if (! (sbpcd_debug & (1 << level))) return;
  1521. -
  1522. -  va_start(args, fmt);
  1523. -  vsprintf(buff, fmt, args);
  1524. -  va_end(args);
  1525. -  printk(buff);
  1526. -#if PRINTK_BUG
  1527. -  sti(); /* to avoid possible "printk" bug */
  1528. -#endif
  1529. +    char buf[256];
  1530. +    va_list args;
  1531. +    extern int vsprintf(char *, const char *, va_list);
  1532. +    
  1533. +    if (!(sbpcd_debug&(1<<level))) return;
  1534. +    
  1535. +    msgnum++;
  1536. +    if (msgnum>99) msgnum=0;
  1537. +    sprintf(buf, "%s-%d [%02d]:  ", major_name, d, msgnum);
  1538. +    va_start(args, fmt);
  1539. +    vsprintf(&buf[15], fmt, args);
  1540. +    va_end(args);
  1541. +    printk(buf);
  1542. +    sbp_sleep(55); /* else messages get lost */
  1543. +    return;
  1544.  }
  1545. -
  1546. +/*==========================================================================*/
  1547.  /*
  1548.   * DDI interface: runtime trace bit pattern maintenance
  1549.   */
  1550.  static int sbpcd_dbg_ioctl(unsigned long arg, int level)
  1551.  {
  1552. -  int val;
  1553. -
  1554. -  val = get_fs_long((int *) arg);
  1555. -  switch(val)
  1556. -    {
  1557. -    case 0:    /* OFF */
  1558. -      sbpcd_debug = 0;
  1559. -      break;
  1560. -
  1561. -    default:
  1562. -      if (val >= 128) sbpcd_debug &= ~(1 << (val - 128));
  1563. -      else sbpcd_debug |= (1 << val);
  1564. -    }
  1565. -  return(0);
  1566. +    switch(arg)
  1567. +    {
  1568. +    case 0:    /* OFF */
  1569. +        sbpcd_debug = DBG_INF;
  1570. +        break;
  1571. +        
  1572. +    default:
  1573. +        if (arg>=128) sbpcd_debug &= ~(1<<(arg-128));
  1574. +        else sbpcd_debug |= (1<<arg);
  1575. +    }
  1576. +    return (arg);
  1577. +}
  1578. +/*==========================================================================*/
  1579. +static void mark_timeout_delay(u_long i)
  1580. +{
  1581. +    timed_out_delay=1;
  1582. +    msg(DBG_TIM,"delay timer expired.\n");
  1583. +}
  1584. +/*==========================================================================*/
  1585. +static void mark_timeout_data(u_long i)
  1586. +{
  1587. +    timed_out_data=1;
  1588. +    msg(DBG_TIM,"data timer expired.\n");
  1589.  }
  1590. -
  1591.  /*==========================================================================*/
  1592. +#if 0
  1593. +static void mark_timeout_audio(u_long i)
  1594. +{
  1595. +    timed_out_audio=1;
  1596. +    msg(DBG_TIM,"audio timer expired.\n");
  1597. +}
  1598. +#endif
  1599.  /*==========================================================================*/
  1600.  /*
  1601. - * Wait a little while (used for polling the drive).  If in initialization,
  1602. - * setting a timeout doesn't work, so just loop for a while.
  1603. + * Wait a little while (used for polling the drive).
  1604.   */
  1605. -static INLINE void sbp_sleep(u_int jifs)
  1606. +static void sbp_sleep(u_int time)
  1607.  {
  1608. -  sti();
  1609. -  current->state = TASK_INTERRUPTIBLE;
  1610. -  current->timeout = jiffies + jifs;
  1611. -  schedule();
  1612. -  sti();
  1613. +#ifndef MODULE
  1614. +    if (current == task[0]) 
  1615. +    {
  1616. +        del_timer(&delay_timer);
  1617. +        delay_timer.expires=time;
  1618. +        timed_out_delay=0;
  1619. +        add_timer(&delay_timer);
  1620. +        while (!timed_out_delay) ;
  1621. +        return;
  1622. +    }
  1623. +#endif MODULE
  1624. +    sti();
  1625. +    current->state = TASK_INTERRUPTIBLE;
  1626. +    current->timeout = jiffies + time;
  1627. +    schedule();
  1628. +    sti();
  1629.  }
  1630. -
  1631. -/*==========================================================================*/
  1632.  /*==========================================================================*/
  1633.  /*
  1634.   *  convert logical_block_address to m-s-f_number (3 bytes only)
  1635.   */
  1636.  static INLINE void lba2msf(int lba, u_char *msf)
  1637.  {
  1638. -  lba += CD_BLOCK_OFFSET;
  1639. -  msf[0] = lba / (CD_SECS*CD_FRAMES);
  1640. -  lba %= CD_SECS*CD_FRAMES;
  1641. -  msf[1] = lba / CD_FRAMES;
  1642. -  msf[2] = lba % CD_FRAMES;
  1643. +    lba += CD_BLOCK_OFFSET;
  1644. +    msf[0] = lba / (CD_SECS*CD_FRAMES);
  1645. +    lba %= CD_SECS*CD_FRAMES;
  1646. +    msf[1] = lba / CD_FRAMES;
  1647. +    msf[2] = lba % CD_FRAMES;
  1648.  }
  1649.  /*==========================================================================*/
  1650.  /*==========================================================================*/
  1651. @@ -737,56 +781,56 @@
  1652.   */
  1653.  static INLINE void bin2bcdx(u_char *p)  /* must work only up to 75 or 99 */
  1654.  {
  1655. -  *p=((*p/10)<<4)|(*p%10);
  1656. +    *p=((*p/10)<<4)|(*p%10);
  1657.  }
  1658.  /*==========================================================================*/
  1659.  static INLINE u_int blk2msf(u_int blk)
  1660.  {
  1661. -  MSF msf;
  1662. -  u_int mm;
  1663. -
  1664. -  msf.c[3] = 0;
  1665. -  msf.c[2] = (blk + CD_BLOCK_OFFSET) / (CD_SECS * CD_FRAMES);
  1666. -  mm = (blk + CD_BLOCK_OFFSET) % (CD_SECS * CD_FRAMES);
  1667. -  msf.c[1] = mm / CD_FRAMES;
  1668. -  msf.c[0] = mm % CD_FRAMES;
  1669. -  return (msf.n);
  1670. +    MSF msf;
  1671. +    u_int mm;
  1672. +    
  1673. +    msf.c[3] = 0;
  1674. +    msf.c[2] = (blk + CD_BLOCK_OFFSET) / (CD_SECS * CD_FRAMES);
  1675. +    mm = (blk + CD_BLOCK_OFFSET) % (CD_SECS * CD_FRAMES);
  1676. +    msf.c[1] = mm / CD_FRAMES;
  1677. +    msf.c[0] = mm % CD_FRAMES;
  1678. +    return (msf.n);
  1679.  }
  1680.  /*==========================================================================*/
  1681.  static INLINE u_int make16(u_char rh, u_char rl)
  1682.  {
  1683. -  return ((rh<<8)|rl);
  1684. +    return ((rh<<8)|rl);
  1685.  }
  1686.  /*==========================================================================*/
  1687.  static INLINE u_int make32(u_int rh, u_int rl)
  1688.  {
  1689. -  return ((rh<<16)|rl);
  1690. +    return ((rh<<16)|rl);
  1691.  }
  1692.  /*==========================================================================*/
  1693.  static INLINE u_char swap_nibbles(u_char i)
  1694.  {
  1695. -  return ((i<<4)|(i>>4));
  1696. +    return ((i<<4)|(i>>4));
  1697.  }
  1698.  /*==========================================================================*/
  1699.  static INLINE u_char byt2bcd(u_char i)
  1700.  {
  1701. -  return (((i/10)<<4)+i%10);
  1702. +    return (((i/10)<<4)+i%10);
  1703.  }
  1704.  /*==========================================================================*/
  1705.  static INLINE u_char bcd2bin(u_char bcd)
  1706.  {
  1707. -  return ((bcd>>4)*10+(bcd&0x0F));
  1708. +    return ((bcd>>4)*10+(bcd&0x0F));
  1709.  }
  1710.  /*==========================================================================*/
  1711.  static INLINE int msf2blk(int msfx)
  1712.  {
  1713. -  MSF msf;
  1714. -  int i;
  1715. -
  1716. -  msf.n=msfx;
  1717. -  i=(msf.c[2] * CD_SECS + msf.c[1]) * CD_FRAMES + msf.c[0] - CD_BLOCK_OFFSET;
  1718. -  if (i<0) return (0);
  1719. -  return (i);
  1720. +    MSF msf;
  1721. +    int i;
  1722. +    
  1723. +    msf.n=msfx;
  1724. +    i=(msf.c[2] * CD_SECS + msf.c[1]) * CD_FRAMES + msf.c[0] - CD_BLOCK_OFFSET;
  1725. +    if (i<0) return (0);
  1726. +    return (i);
  1727.  }
  1728.  /*==========================================================================*/
  1729.  /*
  1730. @@ -794,1869 +838,2578 @@
  1731.   */
  1732.  static INLINE int msf2lba(u_char *msf)
  1733.  {
  1734. -  int i;
  1735. -
  1736. -  i=(msf[0] * CD_SECS + msf[1]) * CD_FRAMES + msf[2] - CD_BLOCK_OFFSET;
  1737. -  if (i<0) return (0);
  1738. -  return (i);
  1739. +    int i;
  1740. +    
  1741. +    i=(msf[0] * CD_SECS + msf[1]) * CD_FRAMES + msf[2] - CD_BLOCK_OFFSET;
  1742. +    if (i<0) return (0);
  1743. +    return (i);
  1744.  }
  1745.  /*==========================================================================*/
  1746. -/* evaluate xx_ReadError code (still mysterious) */ 
  1747. +/* evaluate cc_ReadError code */ 
  1748.  static int sta2err(int sta)
  1749.  {
  1750. -  if (sta<=2) return (sta);
  1751. -  if (sta==0x05) return (-4); /* CRC error */
  1752. -  if (sta==0x06) return (-6); /* seek error */
  1753. -  if (sta==0x0d) return (-6); /* seek error */
  1754. -  if (sta==0x0e) return (-3); /* unknown command */
  1755. -  if (sta==0x14) return (-3); /* unknown command */
  1756. -  if (sta==0x0c) return (-11); /* read fault */
  1757. -  if (sta==0x0f) return (-11); /* read fault */
  1758. -  if (sta==0x10) return (-11); /* read fault */
  1759. -  if (sta>=0x16) return (-12); /* general failure */
  1760. -  DriveStruct[d].CD_changed=0xFF;
  1761. -  if (sta==0x11) return (-15); /* invalid disk change (LCS: removed) */
  1762. -  if (famL_drive)
  1763. -    if (sta==0x12) return (-15); /* invalid disk change (inserted) */
  1764. -  return (-2); /* drive not ready */
  1765. +    if (famT_drive)
  1766. +    {
  1767. +        if (sta==0x00) return (0);
  1768. +        if (sta==0x01) return (-604); /* CRC error */
  1769. +        if (sta==0x02) return (-602); /* drive not ready */
  1770. +        if (sta==0x03) return (-607); /* unknown media */
  1771. +        if (sta==0x04) return (-612); /* general failure */
  1772. +        if (sta==0x05) return (0);
  1773. +        if (sta==0x06) return (-615); /* invalid disk change */
  1774. +        if (sta==0x0b) return (-612); /* general failure */
  1775. +        if (sta==0xff) return (-612); /* general failure */
  1776. +        return (0);
  1777. +    }
  1778. +    else
  1779. +    {
  1780. +        if (sta<=2) return (sta);
  1781. +        if (sta==0x05) return (-604); /* CRC error */
  1782. +        if (sta==0x06) return (-606); /* seek error */
  1783. +        if (sta==0x0d) return (-606); /* seek error */
  1784. +        if (sta==0x0e) return (-603); /* unknown command */
  1785. +        if (sta==0x14) return (-603); /* unknown command */
  1786. +        if (sta==0x0c) return (-611); /* read fault */
  1787. +        if (sta==0x0f) return (-611); /* read fault */
  1788. +        if (sta==0x10) return (-611); /* read fault */
  1789. +        if (sta>=0x16) return (-612); /* general failure */
  1790. +        D_S[d].CD_changed=0xFF;
  1791. +        if (sta==0x11) return (-615); /* invalid disk change (LCS: removed) */
  1792. +        if (famL_drive)
  1793. +            if (sta==0x12) return (-615); /* invalid disk change (inserted) */
  1794. +        return (-602); /* drive not ready */
  1795. +    }
  1796.  }
  1797.  /*==========================================================================*/
  1798.  static INLINE void clr_cmdbuf(void)
  1799.  {
  1800. -  int i;
  1801. -
  1802. -  for (i=0;i<10;i++) drvcmd[i]=0;
  1803. -  cmd_type=0;
  1804. -}
  1805. -/*==========================================================================*/
  1806. -static void mark_timeout(unsigned long i)
  1807. -{
  1808. -  timed_out=1;
  1809. -  DPRINTF((DBG_TIM,"SBPCD: timer expired.\n"));
  1810. +    int i;
  1811. +    
  1812. +    for (i=0;i<10;i++) drvcmd[i]=0;
  1813. +    cmd_type=0;
  1814.  }
  1815.  /*==========================================================================*/
  1816. -static struct timer_list delay_timer = { NULL, NULL, 0, 0, mark_timeout};
  1817. -#if 0
  1818. -static struct timer_list data_timer = { NULL, NULL, 0, 0, mark_timeout};
  1819. -static struct timer_list audio_timer = { NULL, NULL, 0, 0, mark_timeout};
  1820. -#endif
  1821. -/*==========================================================================*/
  1822.  static void flush_status(void)
  1823.  {
  1824. -#ifdef CDMKE
  1825. -  int i;
  1826. -
  1827. +    int i;
  1828. +    
  1829.  #ifdef MODULE
  1830. -  sbp_sleep(150);
  1831. -  for (i=maxtim_data;i!=0;i--) inb(CDi_status);
  1832. +    sbp_sleep(150);
  1833. +    for (i=maxtim_data;i!=0;i--) inb(CDi_status);
  1834.  #else
  1835. -  if (current == task[0])
  1836. -    for (i=maxtim02;i!=0;i--) inb(CDi_status);
  1837. -  else 
  1838. -    {
  1839. -      sbp_sleep(150);
  1840. -      for (i=maxtim_data;i!=0;i--) inb(CDi_status);
  1841. -    }
  1842. +    if (current == task[0])
  1843. +        for (i=maxtim02;i!=0;i--) inb(CDi_status);
  1844. +    else 
  1845. +    {
  1846. +        sbp_sleep(150);
  1847. +        for (i=maxtim_data;i!=0;i--) inb(CDi_status);
  1848. +    }
  1849.  #endif MODULE
  1850. -#else
  1851. -  timed_out=0;
  1852. -#if 0
  1853. -  del_timer(&delay_timer);
  1854. -#endif
  1855. -  delay_timer.expires = 150;
  1856. -  add_timer(&delay_timer);
  1857. -  do { }
  1858. -  while (!timed_out);
  1859. -#if 0
  1860. -  del_timer(&delay_timer);
  1861. -#endif 0
  1862. -  inb(CDi_status);
  1863. -#endif CDMKE
  1864.  }
  1865.  /*==========================================================================*/
  1866.  static int CDi_stat_loop(void)
  1867.  {
  1868. -  int i,j;
  1869. -  u_long timeout;
  1870. -  
  1871. +    int i,j;
  1872. +    
  1873.  #ifdef MODULE
  1874. -    for(timeout = jiffies + 1000, i=maxtim_data; timeout > jiffies; )
  1875. -      {
  1876. -    for ( ;i!=0;i--)
  1877. -      {
  1878. -        j=inb(CDi_status);
  1879. -        if (!(j&s_not_data_ready)) return (j);
  1880. -        if (!(j&s_not_result_ready)) return (j);
  1881. -        if (fam0L_drive) if (j&s_attention) return (j);
  1882. -      }
  1883. -    sbp_sleep(1);
  1884. -    i = 1;
  1885. -      }
  1886. +    for(timeout = jiffies + 1000, i=maxtim_data; timeout > jiffies; )
  1887. +    {
  1888. +        for ( ;i!=0;i--)
  1889. +        {
  1890. +            j=inb(CDi_status);
  1891. +            if (!(j&s_not_data_ready)) return (j);
  1892. +            if (!(j&s_not_result_ready)) return (j);
  1893. +            if (fam0L_drive) if (j&s_attention) return (j);
  1894. +        }
  1895. +        sbp_sleep(1);
  1896. +        i = 1;
  1897. +    }
  1898.  #else
  1899. -  if (current == task[0])
  1900. -    for(i=maxtim16;i!=0;i--)
  1901. -      {
  1902. -    j=inb(CDi_status);
  1903. -        if (!(j&s_not_data_ready)) return (j);
  1904. -        if (!(j&s_not_result_ready)) return (j);
  1905. -        if (fam0L_drive) if (j&s_attention) return (j);
  1906. -      }
  1907. -  else
  1908. -    for(timeout = jiffies + 1000, i=maxtim_data; timeout > jiffies; )
  1909. -      {
  1910. -    for ( ;i!=0;i--)
  1911. -      {
  1912. -        j=inb(CDi_status);
  1913. -        if (!(j&s_not_data_ready)) return (j);
  1914. -        if (!(j&s_not_result_ready)) return (j);
  1915. -        if (fam0L_drive) if (j&s_attention) return (j);
  1916. -      }
  1917. -    sbp_sleep(1);
  1918. -    i = 1;
  1919. -      }
  1920. +    if (current == task[0])
  1921. +        for(i=maxtim16;i!=0;i--)
  1922. +        {
  1923. +            j=inb(CDi_status);
  1924. +            if (!(j&s_not_data_ready)) return (j);
  1925. +            if (!(j&s_not_result_ready)) return (j);
  1926. +            if (fam0L_drive) if (j&s_attention) return (j);
  1927. +        }
  1928. +    else
  1929. +        for(timeout = jiffies + 1000, i=maxtim_data; timeout > jiffies; )
  1930. +        {
  1931. +            for ( ;i!=0;i--)
  1932. +            {
  1933. +                j=inb(CDi_status);
  1934. +                if (!(j&s_not_data_ready)) return (j);
  1935. +                if (!(j&s_not_result_ready)) return (j);
  1936. +                if (fam0L_drive) if (j&s_attention) return (j);
  1937. +            }
  1938. +            sbp_sleep(1);
  1939. +            i = 1;
  1940. +        }
  1941.  #endif MODULE
  1942. -  DPRINTF((DBG_LCS,"SBPCD: CDi_stat_loop failed\n"));
  1943. -  return (-1);
  1944. +    msg(DBG_LCS,"CDi_stat_loop failed\n");
  1945. +    return (-1);
  1946. +}
  1947. +/*==========================================================================*/
  1948. +#if 00000
  1949. +/*==========================================================================*/
  1950. +static int tst_DataReady(void)
  1951. +{
  1952. +    int i;
  1953. +    
  1954. +    i=inb(CDi_status);
  1955. +    if (i&s_not_data_ready) return (0);
  1956. +    return (1);
  1957. +}
  1958. +/*==========================================================================*/
  1959. +static int tst_ResultReady(void)
  1960. +{
  1961. +    int i;
  1962. +    
  1963. +    i=inb(CDi_status);
  1964. +    if (i&s_not_result_ready) return (0);
  1965. +    return (1);
  1966. +}
  1967. +/*==========================================================================*/
  1968. +static int tst_Attention(void)
  1969. +{
  1970. +    int i;
  1971. +    
  1972. +    i=inb(CDi_status);
  1973. +    if (i&s_attention) return (1);
  1974. +    return (0);
  1975.  }
  1976.  /*==========================================================================*/
  1977. +#endif 00000
  1978. +/*==========================================================================*/
  1979.  static int ResponseInfo(void)
  1980.  {
  1981. -  int i,j, st=0;
  1982. -  u_long timeout;
  1983. -
  1984. -  DPRINTF((DBG_000,"SBPCD: ResponseInfo entered.\n"));
  1985. +    int i,j,st=0;
  1986. +    u_long timeout;
  1987. +    
  1988.  #ifdef MODULE
  1989. -  for (i=0, timeout = jiffies + 100; i < response_count; i++) 
  1990. -    {
  1991. -      for (j=maxtim_data; ; )
  1992. -    {
  1993. -      for ( ;j!=0;j-- )
  1994. -        {
  1995. -          st=inb(CDi_status);
  1996. -          if (!(st&s_not_result_ready)) break;
  1997. -        }
  1998. -      if (j != 0 || timeout <= jiffies) break;
  1999. -      sbp_sleep(0);
  2000. -      j = 1;
  2001. -    }
  2002. -      if (timeout <= jiffies) return (-1);
  2003. -      infobuf[i]=inb(CDi_info);
  2004. -    }
  2005. +    if (0)
  2006.  #else
  2007. -  if (current == task[0])
  2008. -    for (i=0;i<response_count;i++)
  2009. -      {
  2010. -    for (j=maxtim_8;j!=0;j--)
  2011. -      {
  2012. -        st=inb(CDi_status);
  2013. -        if (!(st&s_not_result_ready)) break;
  2014. -      }
  2015. -    if (j==0)
  2016. -      {
  2017. -        DPRINTF((DBG_SEQ,"SBPCD: ResponseInfo: not_result_ready (got %d of %d bytes).\n", i, response_count));
  2018. -        return (-1);
  2019. -      }
  2020. -    infobuf[i]=inb(CDi_info);
  2021. -      }
  2022. -  else 
  2023. -    {
  2024. -      for (i=0, timeout = jiffies + 100; i < response_count; i++) 
  2025. -    {
  2026. -      for (j=maxtim_data; ; )
  2027. -        {
  2028. -          for ( ;j!=0;j-- )
  2029. -        {
  2030. -          st=inb(CDi_status);
  2031. -          if (!(st&s_not_result_ready)) break;
  2032. -        }
  2033. -          if (j != 0 || timeout <= jiffies) break;
  2034. -          sbp_sleep(0);
  2035. -          j = 1;
  2036. -        }
  2037. -      if (timeout <= jiffies) return (-1);
  2038. -      infobuf[i]=inb(CDi_info);
  2039. -    }
  2040. -    }
  2041. +    if (current == task[0])
  2042.  #endif MODULE
  2043. -  DPRINTF((DBG_000,"SBPCD: ResponseInfo: done.\n"));
  2044. -  return (0);
  2045. +        for (i=0;i<response_count;i++)
  2046. +        {
  2047. +            for (j=maxtim_8;j!=0;j--)
  2048. +            {
  2049. +                st=inb(CDi_status);
  2050. +                if (!(st&s_not_result_ready)) break;
  2051. +            }
  2052. +            if (j==0) 
  2053. +            {
  2054. +                msg(DBG_SEQ,"ResponseInfo: not_result_ready (got %d of %d bytes).\n", i, response_count);
  2055. +                break;
  2056. +            }
  2057. +            infobuf[i]=inb(CDi_info);
  2058. +        }
  2059. +    else 
  2060. +    {
  2061. +        for (i=0,timeout=jiffies+100;i<response_count;i++) 
  2062. +        {
  2063. +            for (j=maxtim_data; ; )
  2064. +            {
  2065. +                for ( ;j!=0;j-- )
  2066. +                {
  2067. +                    st=inb(CDi_status);
  2068. +                    if (!(st&s_not_result_ready)) break;
  2069. +                }
  2070. +                if (j != 0 || timeout <= jiffies) break;
  2071. +                sbp_sleep(0);
  2072. +                j = 1;
  2073. +            }
  2074. +            if (timeout <= jiffies) break;
  2075. +            infobuf[i]=inb(CDi_info);
  2076. +        }
  2077. +    }
  2078. +    for (j=0;j<i;j++)
  2079. +        sprintf(&msgbuf[j*3]," %02X",infobuf[j]);
  2080. +    msgbuf[j*3]=0;
  2081. +    msg(DBG_CMD,"ResponseInfo:%s (%d,%d)\n",msgbuf,response_count,i);
  2082. +    st=response_count-i;
  2083. +    if (st>0) st=-st;
  2084. +    return (st);
  2085.  }
  2086.  /*==========================================================================*/
  2087.  static void EvaluateStatus(int st)
  2088.  {
  2089. -  DriveStruct[d].status_byte=0;
  2090. -  if (fam0_drive)
  2091. -    {
  2092. -      if (st&p_caddin_old) DriveStruct[d].status_byte |= p_door_closed|p_caddy_in;
  2093. -      if (st&p_spinning) DriveStruct[d].status_byte |= p_spinning;
  2094. -      if (st&p_check) DriveStruct[d].status_byte |= p_check;
  2095. -      if (st&p_busy_old) DriveStruct[d].status_byte |= p_busy_new;
  2096. -      if (st&p_disk_ok) DriveStruct[d].status_byte |= p_disk_ok;
  2097. -    }
  2098. -  else if (famL_drive)
  2099. -    {
  2100. -      if (st&p_caddin_old) DriveStruct[d].status_byte |= p_disk_ok|p_caddy_in;
  2101. -      if (st&p_spinning) DriveStruct[d].status_byte |= p_spinning;
  2102. -      if (st&p_check) DriveStruct[d].status_byte |= p_check;
  2103. -      if (st&p_busy_old) DriveStruct[d].status_byte |= p_busy_new;
  2104. -      if (st&p_lcs_door_closed) DriveStruct[d].status_byte |= p_door_closed;
  2105. -      if (st&p_lcs_door_locked) DriveStruct[d].status_byte |= p_door_locked;
  2106. -    }
  2107. -  else if (fam2_drive)
  2108. -    {
  2109. -      if (st&p2_check) DriveStruct[d].status_byte |= p1_check;
  2110. -      if (st&p2_door_closed) DriveStruct[d].status_byte |= p1_door_closed;
  2111. -      if (st&p2_disk_in) DriveStruct[d].status_byte |= p1_disk_in;
  2112. -      if (st&p2_busy1) DriveStruct[d].status_byte |= p1_busy;
  2113. -      if (st&p2_busy2) DriveStruct[d].status_byte |= p1_busy;
  2114. -      if (st&p2_spinning) DriveStruct[d].status_byte |= p1_spinning;
  2115. -      if (st&p2_door_locked) DriveStruct[d].status_byte |= p1_door_locked;
  2116. -      if (st&p2_disk_ok) DriveStruct[d].status_byte |= p1_disk_ok;
  2117. -    }
  2118. -  else if (fam1_drive) DriveStruct[d].status_byte=st;
  2119. -  return;
  2120. +    D_S[d].status_bits=0;
  2121. +    if (fam1_drive) D_S[d].status_bits=st|p_success;
  2122. +    else if (fam0_drive)
  2123. +    {
  2124. +        if (st&p_caddin_old) D_S[d].status_bits |= p_door_closed|p_caddy_in;
  2125. +        if (st&p_spinning) D_S[d].status_bits |= p_spinning;
  2126. +        if (st&p_check) D_S[d].status_bits |= p_check;
  2127. +         if (st&p_success_old) D_S[d].status_bits |= p_success;
  2128. +         if (st&p_busy_old) D_S[d].status_bits |= p_busy_new;
  2129. +        if (st&p_disk_ok) D_S[d].status_bits |= p_disk_ok;
  2130. +    }
  2131. +    else if (famL_drive)
  2132. +    {
  2133. +         D_S[d].status_bits |= p_success;
  2134. +        if (st&p_caddin_old) D_S[d].status_bits |= p_disk_ok|p_caddy_in;
  2135. +        if (st&p_spinning) D_S[d].status_bits |= p_spinning;
  2136. +        if (st&p_check) D_S[d].status_bits |= p_check;
  2137. +        if (st&p_busy_old) D_S[d].status_bits |= p_busy_new;
  2138. +        if (st&p_lcs_door_closed) D_S[d].status_bits |= p_door_closed;
  2139. +        if (st&p_lcs_door_locked) D_S[d].status_bits |= p_door_locked;
  2140. +    }
  2141. +    else if (fam2_drive)
  2142. +    {
  2143. +         D_S[d].status_bits |= p_success;
  2144. +        if (st&p2_check) D_S[d].status_bits |= p1_check;
  2145. +        if (st&p2_door_closed) D_S[d].status_bits |= p1_door_closed;
  2146. +        if (st&p2_disk_in) D_S[d].status_bits |= p1_disk_in;
  2147. +        if (st&p2_busy1) D_S[d].status_bits |= p1_busy;
  2148. +        if (st&p2_busy2) D_S[d].status_bits |= p1_busy;
  2149. +        if (st&p2_spinning) D_S[d].status_bits |= p1_spinning;
  2150. +        if (st&p2_door_locked) D_S[d].status_bits |= p1_door_locked;
  2151. +        if (st&p2_disk_ok) D_S[d].status_bits |= p1_disk_ok;
  2152. +    }
  2153. +    else if (famT_drive)
  2154. +    {
  2155. +        return; /* still needs to get coded */
  2156. +         D_S[d].status_bits |= p_success;
  2157. +        if (st&p2_check) D_S[d].status_bits |= p1_check;
  2158. +        if (st&p2_door_closed) D_S[d].status_bits |= p1_door_closed;
  2159. +        if (st&p2_disk_in) D_S[d].status_bits |= p1_disk_in;
  2160. +        if (st&p2_busy1) D_S[d].status_bits |= p1_busy;
  2161. +        if (st&p2_busy2) D_S[d].status_bits |= p1_busy;
  2162. +        if (st&p2_spinning) D_S[d].status_bits |= p1_spinning;
  2163. +        if (st&p2_door_locked) D_S[d].status_bits |= p1_door_locked;
  2164. +        if (st&p2_disk_ok) D_S[d].status_bits |= p1_disk_ok;
  2165. +    }
  2166. +    return;
  2167. +}
  2168. +/*==========================================================================*/
  2169. +static int get_state_T(void)
  2170. +{
  2171. +    int i;
  2172. +    
  2173. +    static int cmd_out_T(void);
  2174. +
  2175. +    msg(DBG_TE2,"doing get_state_T...\n");
  2176. +    clr_cmdbuf();
  2177. +    D_S[d].n_bytes=1;
  2178. +    drvcmd[0]=CMDT_STATUS;
  2179. +    i=cmd_out_T();
  2180. +    if (i>=0) i=infobuf[0];
  2181. +    else
  2182. +    {
  2183. +        msg(DBG_TEA,"get_state_T error %d\n", i);
  2184. +        return (i);
  2185. +    }
  2186. +    if (i>=0)
  2187. +        /* 2: closed, disk in */
  2188. +        D_S[d].status_bits=p1_door_closed|p1_disk_in|p1_spinning|p1_disk_ok;
  2189. +    else if (D_S[d].error_state==6)
  2190. +        /* 3: closed, disk in, changed ("06 xx xx") */
  2191. +        D_S[d].status_bits=p1_door_closed|p1_disk_in;
  2192. +    else if ((D_S[d].error_state!=2)||(D_S[d].b3!=0x3A)||(D_S[d].b4==0x00))
  2193. +    {
  2194. +        /* 1: closed, no disk ("xx yy zz"or "02 3A 00") */
  2195. +        D_S[d].status_bits=p1_door_closed;
  2196. +        D_S[d].open_count=0;
  2197. +    }
  2198. +    else if (D_S[d].b4==0x01)
  2199. +    {
  2200. +        /* 0: open ("02 3A 01") */
  2201. +        D_S[d].status_bits=0;
  2202. +        D_S[d].open_count=0;
  2203. +    }
  2204. +    else
  2205. +    {
  2206. +        /* 1: closed, no disk ("02 3A xx") */
  2207. +        D_S[d].status_bits=p1_door_closed;
  2208. +        D_S[d].open_count=0;
  2209. +    }
  2210. +    msg(DBG_TE2,"get_state_T done (%02X)...\n", D_S[d].status_bits);
  2211. +    return (D_S[d].status_bits);
  2212.  }
  2213.  /*==========================================================================*/
  2214.  static int ResponseStatus(void)
  2215.  {
  2216. -  int i,j;
  2217. -  u_long timeout;
  2218. -
  2219. -  DPRINTF((DBG_STA,"SBPCD: doing ResponseStatus...\n"));
  2220. +    int i,j;
  2221. +    u_long timeout;
  2222. +    
  2223. +    msg(DBG_STA,"doing ResponseStatus...\n");
  2224. +    if (famT_drive) return (get_state_T());
  2225.  #ifdef MODULE
  2226. -  if (flags_cmd_out & f_respo3) timeout = jiffies;
  2227. -  else if (flags_cmd_out & f_respo2) timeout = jiffies + 1600;
  2228. -  else timeout = jiffies + 400;
  2229. -  j=maxtim_8;
  2230. -  do
  2231. -    {
  2232. -      for ( ;j!=0;j--)
  2233. -    { 
  2234. -      i=inb(CDi_status);
  2235. -      if (!(i&s_not_result_ready)) break;
  2236. -    }
  2237. -      if (j != 0 || timeout <= jiffies) break;
  2238. -      sbp_sleep(0);
  2239. -      j = 1;
  2240. -    }
  2241. -  while (1);
  2242. +    if (0)
  2243.  #else
  2244. -  if (current == task[0])
  2245. -    {
  2246. -      if (flags_cmd_out & f_respo3) j = maxtim_8;
  2247. -      else if (flags_cmd_out&f_respo2) j=maxtim16;
  2248. -      else j=maxtim04;
  2249. -      for (;j!=0;j--)
  2250. +    if (current == task[0])
  2251. +#endif MODULE
  2252.      {
  2253. -      i=inb(CDi_status);
  2254. -      if (!(i&s_not_result_ready)) break;
  2255. +        if (flags_cmd_out & f_respo3) j = maxtim_8;
  2256. +        else if (flags_cmd_out&f_respo2) j=maxtim16;
  2257. +        else j=maxtim04;
  2258. +        for (;j!=0;j--)
  2259. +        {
  2260. +            i=inb(CDi_status);
  2261. +            if (!(i&s_not_result_ready)) break;
  2262. +        }
  2263.      }
  2264. -    }
  2265. -  else
  2266. -    {
  2267. -      if (flags_cmd_out & f_respo3) timeout = jiffies;
  2268. -      else if (flags_cmd_out & f_respo2) timeout = jiffies + 1600;
  2269. -      else timeout = jiffies + 400;
  2270. -      j=maxtim_8;
  2271. -      do
  2272. -    {
  2273. -      for ( ;j!=0;j--)
  2274. -        { 
  2275. -          i=inb(CDi_status);
  2276. -          if (!(i&s_not_result_ready)) break;
  2277. -        }
  2278. -      if (j != 0 || timeout <= jiffies) break;
  2279. -      sbp_sleep(0);
  2280. -      j = 1;
  2281. +    else
  2282. +    {
  2283. +        if (flags_cmd_out & f_respo3) timeout = jiffies;
  2284. +        else if (flags_cmd_out & f_respo2) timeout = jiffies + 1600;
  2285. +        else timeout = jiffies + 400;
  2286. +        j=maxtim_8;
  2287. +        do
  2288. +        {
  2289. +            for ( ;j!=0;j--)
  2290. +            { 
  2291. +                i=inb(CDi_status);
  2292. +                if (!(i&s_not_result_ready)) break;
  2293. +            }
  2294. +            if ((j!=0)||(timeout<jiffies)) break;
  2295. +            sbp_sleep(1);
  2296. +            j = 1;
  2297. +        }
  2298. +        while (1);
  2299.      }
  2300. -      while (1);
  2301. -    }
  2302. -#endif MODULE
  2303. -  if (j==0) 
  2304. -    { if ((flags_cmd_out & f_respo3) == 0)
  2305. -    DPRINTF((DBG_STA,"SBPCD: ResponseStatus: timeout.\n"));
  2306. -      DriveStruct[d].status_byte=0;
  2307. -      return (-1);
  2308. -    }
  2309. -  i=inb(CDi_info);
  2310. -  DPRINTF((DBG_STA,"SBPCD: ResponseStatus: response %2X.\n", i));
  2311. -  EvaluateStatus(i);
  2312. -  return (i);
  2313. -}
  2314. -/*==========================================================================*/
  2315. -static void xx_ReadStatus(void)
  2316. -{
  2317. -  int i;
  2318. -
  2319. -  DPRINTF((DBG_STA,"SBPCD: giving xx_ReadStatus command\n"));
  2320. -  SBPCD_CLI;
  2321. -  if (fam0L_drive) OUT(CDo_command,CMD0_STATUS);
  2322. -  else if (fam1_drive) OUT(CDo_command,CMD1_STATUS);
  2323. -  else if (fam2_drive) OUT(CDo_command,CMD2_STATUS);
  2324. -  if (!fam0L_drive) for (i=0;i<6;i++) OUT(CDo_command,0);
  2325. -  SBPCD_STI;
  2326. +    if (j==0) 
  2327. +    {
  2328. +        if ((flags_cmd_out & f_respo3) == 0)
  2329. +            msg(DBG_STA,"ResponseStatus: timeout.\n");
  2330. +        D_S[d].status_bits=0;
  2331. +        return (-401);
  2332. +    }
  2333. +    i=inb(CDi_info);
  2334. +    msg(DBG_STA,"ResponseStatus: response %02X.\n", i);
  2335. +    EvaluateStatus(i);
  2336. +#if 0
  2337. +    if (fam0_drive)
  2338. +#endif
  2339. +        msg(DBG_STA,"status_bits=%02X, i=%02X\n",D_S[d].status_bits,i);
  2340. +#if 1
  2341. +    return (D_S[d].status_bits);
  2342. +#else
  2343. +    return (i);
  2344. +#endif 0
  2345.  }
  2346.  /*==========================================================================*/
  2347. -static int xx_ReadError(void)
  2348. +static void cc_ReadStatus(void)
  2349.  {
  2350. -  int i;
  2351. -
  2352. -  clr_cmdbuf();
  2353. -  DPRINTF((DBG_ERR,"SBPCD: giving xx_ReadError command.\n"));
  2354. -  if (fam1_drive)
  2355. -    {
  2356. -      drvcmd[0]=CMD1_READ_ERR;
  2357. -      response_count=8;
  2358. -      flags_cmd_out=f_putcmd|f_ResponseStatus;
  2359. -    }
  2360. -  else if (fam0L_drive)
  2361. -    {
  2362. -      drvcmd[0]=CMD0_READ_ERR;
  2363. -      response_count=6;
  2364. -      if (famL_drive)
  2365. -    flags_cmd_out=f_putcmd;
  2366. -      else
  2367. -    flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus;
  2368. -    }
  2369. -  else if (fam2_drive)
  2370. -    {
  2371. -      drvcmd[0]=CMD2_READ_ERR;
  2372. -      response_count=6;
  2373. -      flags_cmd_out=f_putcmd;
  2374. -    }
  2375. -  i=cmd_out(7);
  2376. -  DriveStruct[d].error_byte=0;
  2377. -  DPRINTF((DBG_ERR,"SBPCD: xx_ReadError: cmd_out(82) returns %d (%02X)\n",i,i));
  2378. -  if (i<0) return (i);
  2379. -  if (fam0_drive) i=1;
  2380. -  else i=2;
  2381. -  DriveStruct[d].error_byte=infobuf[i];
  2382. -  DPRINTF((DBG_ERR,"SBPCD: xx_ReadError: infobuf[%d] is %d (%02X)\n",i,DriveStruct[d].error_byte,DriveStruct[d].error_byte));
  2383. -  i=sta2err(infobuf[i]);
  2384. -  return (i);
  2385. -}
  2386. -/*==========================================================================*/
  2387. -static int cmd_out(int len)
  2388. -{
  2389. -  int i=0;
  2390. -
  2391. -  if (flags_cmd_out&f_putcmd)
  2392. -    { 
  2393. -      DPRINTF((DBG_CMD,"SBPCD: cmd_out: put"));
  2394. -      for (i=0;i<len;i++) DPRINTF((DBG_CMD," %02X",drvcmd[i]));
  2395. -      DPRINTF((DBG_CMD,"\n"));
  2396. -
  2397. -      cli();
  2398. -      for (i=0;i<len;i++) OUT(CDo_command,drvcmd[i]);
  2399. -      sti();
  2400. -    }
  2401. -  if (response_count!=0)
  2402. -    {
  2403. -      if (cmd_type!=0)
  2404. -    {
  2405. -      if (sbpro_type==1) OUT(CDo_sel_i_d,1);
  2406. -      DPRINTF((DBG_INF,"SBPCD: misleaded to try ResponseData.\n"));
  2407. -      if (sbpro_type==1) OUT(CDo_sel_i_d,0);
  2408. -      return (-22);
  2409. +    int i;
  2410. +    
  2411. +    msg(DBG_STA,"giving cc_ReadStatus command\n");
  2412. +    if (famT_drive) return;
  2413. +    SBPCD_CLI;
  2414. +    if (fam0L_drive) OUT(CDo_command,CMD0_STATUS);
  2415. +    else if (fam1_drive) OUT(CDo_command,CMD1_STATUS);
  2416. +    else if (fam2_drive) OUT(CDo_command,CMD2_STATUS);
  2417. +    if (!fam0L_drive) for (i=0;i<6;i++) OUT(CDo_command,0);
  2418. +    SBPCD_STI;
  2419. +}
  2420. +/*==========================================================================*/
  2421. +static int cc_ReadError(void)
  2422. +{
  2423. +    int i;
  2424. +
  2425. +    clr_cmdbuf();
  2426. +    msg(DBG_ERR,"giving cc_ReadError command.\n");
  2427. +    if (fam1_drive)
  2428. +    {
  2429. +        drvcmd[0]=CMD1_READ_ERR;
  2430. +        response_count=8;
  2431. +        flags_cmd_out=f_putcmd|f_ResponseStatus;
  2432. +    }
  2433. +    else if (fam0L_drive)
  2434. +    {
  2435. +        drvcmd[0]=CMD0_READ_ERR;
  2436. +        response_count=6;
  2437. +        if (famL_drive)
  2438. +            flags_cmd_out=f_putcmd;
  2439. +        else
  2440. +            flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus;
  2441. +    }
  2442. +    else if (fam2_drive)
  2443. +    {
  2444. +        drvcmd[0]=CMD2_READ_ERR;
  2445. +        response_count=6;
  2446. +        flags_cmd_out=f_putcmd;
  2447. +    }
  2448. +    else if (famT_drive)
  2449. +    {
  2450. +        response_count=5;
  2451. +        drvcmd[0]=CMDT_READ_ERR;
  2452. +    }
  2453. +    i=cmd_out();
  2454. +    D_S[d].error_byte=0;
  2455. +    msg(DBG_ERR,"cc_ReadError: cmd_out(CMDx_READ_ERR) returns %d (%02X)\n",i,i);
  2456. +    if (i<0) return (i);
  2457. +    if (fam0_drive) i=1;
  2458. +    else i=2;
  2459. +    D_S[d].error_byte=infobuf[i];
  2460. +    msg(DBG_ERR,"cc_ReadError: infobuf[%d] is %d (%02X)\n",i,D_S[d].error_byte,D_S[d].error_byte);
  2461. +    i=sta2err(infobuf[i]);
  2462. +    return (i);
  2463. +}
  2464. +/*==========================================================================*/
  2465. +static int cmd_out_T(void)
  2466. +{
  2467. +#undef CMDT_TRIES
  2468. +#define CMDT_TRIES 100
  2469. +    
  2470. +    static int cc_DriveReset(void);
  2471. +    int i, j, l, ntries;
  2472. +    
  2473. +    D_S[d].error_state=0;
  2474. +    D_S[d].b3=0;
  2475. +    D_S[d].b4=0;
  2476. +    D_S[d].f_drv_error=0;
  2477. +    for (i=0;i<10;i++) sprintf(&msgbuf[i*3]," %02X",drvcmd[i]);
  2478. +    msgbuf[i*3]=0;
  2479. +    msg(DBG_CMD,"cmd_out_T:%s\n",msgbuf);
  2480. +
  2481. +    OUT(CDo_sel_i_d,0);
  2482. +    OUT(CDo_enable,D_S[d].drv_sel);
  2483. +    i=inb(CDi_status);
  2484. +    if (!(i&s_not_result_ready))
  2485. +    do
  2486. +    {
  2487. +        j=inb(CDi_info);
  2488. +        i=inb(CDi_status);
  2489. +        sbp_sleep(0);
  2490. +        msg(DBG_TEA,"cmd_out_T: spurious !s_not_result_ready. (%02X)\n", j);
  2491. +    }
  2492. +    while (!(i&s_not_result_ready));
  2493. +    cli();
  2494. +    for (i=0;i<10;i++) OUT(CDo_command,drvcmd[i]);
  2495. +    sti();
  2496. +    for (ntries=CMDT_TRIES;ntries>0;ntries--)
  2497. +    {
  2498. +        if (drvcmd[0]==CMDT_READ_VER) sbp_sleep(100);
  2499. +#if 1
  2500. +        OUT(CDo_sel_i_d,0);
  2501. +#endif
  2502. +        i=inb(CDi_status);
  2503. +        if (!(i&s_not_data_ready)) /* f.e. CMDT_DISKINFO */
  2504. +        {
  2505. +            OUT(CDo_sel_i_d,1);
  2506. +            if (drvcmd[0]==CMDT_READ) return (0); /* handled elsewhere */
  2507. +            if (drvcmd[0]==CMDT_DISKINFO)
  2508. +            {
  2509. +                l=0;
  2510. +                do
  2511. +                {
  2512. +                    infobuf[l++]=inb(CDi_data);
  2513. +                    i=inb(CDi_status);
  2514. +                }
  2515. +                while (!(i&s_not_data_ready));
  2516. +                for (j=0;j<l;j++) sprintf(&msgbuf[j*3]," %02X",infobuf[j]);
  2517. +                msgbuf[j*3]=0;
  2518. +                msg(DBG_CMD,"cmd_out_T data response:%s\n", msgbuf);
  2519. +            }
  2520. +            else
  2521. +            {
  2522. +                msg(DBG_TEA,"cmd_out_T: data response with cmd_%02X !!!!!!!!!!!!!!!!!!!!\n", drvcmd[0]);
  2523. +                j=0;
  2524. +                do
  2525. +                {
  2526. +                    i=inb(CDi_data);
  2527. +                    j++;
  2528. +                    i=inb(CDi_status);
  2529. +                }
  2530. +                while (!(i&s_not_data_ready));
  2531. +                msg(DBG_TEA,"cmd_out_T: data response: discarded %d bytes.\n", j);
  2532. +                fatal_err++;
  2533. +            }
  2534. +        }
  2535. +        i=inb(CDi_status);
  2536. +        if (!(i&s_not_result_ready))
  2537. +        {
  2538. +            OUT(CDo_sel_i_d,0);
  2539. +            l=0;
  2540. +            do
  2541. +            {
  2542. +                infobuf[l++]=inb(CDi_info);
  2543. +                i=inb(CDi_status);
  2544. +            }
  2545. +            while (!(i&s_not_result_ready));
  2546. +            for (j=0;j<l;j++) sprintf(&msgbuf[j*3]," %02X",infobuf[j]);
  2547. +            msgbuf[j*3]=0;
  2548. +            msg(DBG_CMD,"cmd_out_T info response:%s\n", msgbuf);
  2549. +            if (infobuf[0]!=0x02) return (l); /* info length */
  2550. +            do
  2551. +            {
  2552. +                ++recursion;
  2553. +                if (recursion>1) msg(DBG_TEA,"cmd_out_T READ_ERR recursion (%02X): %d !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n", drvcmd[0], recursion);
  2554. +                clr_cmdbuf();
  2555. +                drvcmd[0]=CMDT_READ_ERR;
  2556. +                j=cmd_out_T(); /* !!! recursive here !!! */
  2557. +                --recursion;
  2558. +                sbp_sleep(1);
  2559. +            }
  2560. +            while (j<0);
  2561. +            D_S[d].error_state=infobuf[2];
  2562. +            D_S[d].b3=infobuf[3];
  2563. +            D_S[d].b4=infobuf[4];
  2564. +            if (D_S[d].f_drv_error)
  2565. +            {
  2566. +                D_S[d].f_drv_error=0;
  2567. +                cc_DriveReset();
  2568. +                D_S[d].error_state=2;
  2569. +            }
  2570. +            return (-D_S[d].error_state-400);
  2571. +        }
  2572. +        if (drvcmd[0]==CMDT_READ) return (0); /* handled elsewhere */
  2573. +        sbp_sleep(1);
  2574. +        if (ntries>(CMDT_TRIES-50)) continue;
  2575. +        msg(DBG_TEA,"cmd_out_T: next CMDT_TRIES (%02X): %d.\n", drvcmd[0], ntries-1);
  2576. +    }
  2577. +    D_S[d].f_drv_error=1;
  2578. +    cc_DriveReset();
  2579. +    D_S[d].error_state=2;
  2580. +    return (-99);
  2581. +}
  2582. +/*==========================================================================*/
  2583. +static int cmd_out(void)
  2584. +{
  2585. +    int i=0;
  2586. +    
  2587. +    if (famT_drive) return(cmd_out_T());
  2588. +    
  2589. +    if (flags_cmd_out&f_putcmd)
  2590. +    { 
  2591. +        for (i=0;i<7;i++)
  2592. +            sprintf(&msgbuf[i*3], " %02X", drvcmd[i]);
  2593. +        msgbuf[i*3]=0;
  2594. +        msg(DBG_CMD,"cmd_out:%s\n", msgbuf);
  2595. +        cli();
  2596. +        for (i=0;i<7;i++) OUT(CDo_command,drvcmd[i]);
  2597. +        sti();
  2598.      }
  2599. -      else i=ResponseInfo();
  2600. -      if (i<0) return (-9);
  2601. -    }
  2602. -  if (DriveStruct[d].in_SpinUp != 0) DPRINTF((DBG_SPI,"SBPCD: to CDi_stat_loop.\n"));
  2603. -  if (flags_cmd_out&f_lopsta)
  2604. -    {
  2605. -      i=CDi_stat_loop();
  2606. -      if ((i<0)||!(i&s_attention)) return (-9);
  2607. -    }
  2608. -  if (!(flags_cmd_out&f_getsta)) goto LOC_229;
  2609. -  
  2610. -LOC_228:
  2611. -  if (DriveStruct[d].in_SpinUp != 0) DPRINTF((DBG_SPI,"SBPCD: to xx_ReadStatus.\n"));
  2612. -  xx_ReadStatus();
  2613. -
  2614. -LOC_229:
  2615. -  if (flags_cmd_out&f_ResponseStatus) 
  2616. -    {
  2617. -      if (DriveStruct[d].in_SpinUp != 0) DPRINTF((DBG_SPI,"SBPCD: to ResponseStatus.\n"));
  2618. -      i=ResponseStatus();
  2619. -                   /* builds status_byte, returns orig. status or p_busy_new */
  2620. -      if (i<0) return (-9);
  2621. -      if (flags_cmd_out&(f_bit1|f_wait_if_busy))
  2622. -    {
  2623. -      if (!st_check)
  2624. -        {
  2625. -          if (flags_cmd_out&f_bit1) if (i&p_success_old) goto LOC_232;
  2626. -          if (!(flags_cmd_out&f_wait_if_busy)) goto LOC_228;
  2627. -          if (!st_busy) goto LOC_228;
  2628. -        }
  2629. +    if (response_count!=0)
  2630. +    {
  2631. +        if (cmd_type!=0)
  2632. +        {
  2633. +            if (sbpro_type==1) OUT(CDo_sel_i_d,1);
  2634. +            msg(DBG_INF,"misleaded to try ResponseData.\n");
  2635. +            if (sbpro_type==1) OUT(CDo_sel_i_d,0);
  2636. +            return (-22);
  2637. +        }
  2638. +        else i=ResponseInfo();
  2639. +        if (i<0) return (i);
  2640.      }
  2641. -    }
  2642. -LOC_232:
  2643. -  if (!(flags_cmd_out&f_obey_p_check)) return (0);
  2644. -  if (!st_check) return (0);
  2645. -  if (DriveStruct[d].in_SpinUp != 0) DPRINTF((DBG_SPI,"SBPCD: to xx_ReadError.\n"));
  2646. -  i=xx_ReadError();
  2647. -  if (DriveStruct[d].in_SpinUp != 0) DPRINTF((DBG_SPI,"SBPCD: to cmd_out OK.\n"));
  2648. -  return (i);
  2649. -}
  2650. -/*==========================================================================*/
  2651. -static int xx_Seek(u_int pos, char f_blk_msf)
  2652. -{
  2653. -  int i;
  2654. -
  2655. -  clr_cmdbuf();
  2656. -  if (f_blk_msf>1) return (-3);
  2657. -  if (fam0_drive)
  2658. -    {
  2659. -      drvcmd[0]=CMD0_SEEK;
  2660. -      if (f_blk_msf==1) pos=msf2blk(pos);
  2661. -      drvcmd[2]=(pos>>16)&0x00FF;
  2662. -      drvcmd[3]=(pos>>8)&0x00FF;
  2663. -      drvcmd[4]=pos&0x00FF;
  2664. -      flags_cmd_out = f_putcmd | f_respo2 | f_lopsta | f_getsta |
  2665. -                      f_ResponseStatus | f_obey_p_check | f_bit1;
  2666. -    }
  2667. -  else if (fam1L_drive)
  2668. -    {
  2669. -      drvcmd[0]=CMD1_SEEK; /* same as CMD1_ and CMDL_ */
  2670. -      if (f_blk_msf==0) pos=blk2msf(pos);
  2671. -      drvcmd[1]=(pos>>16)&0x00FF;
  2672. -      drvcmd[2]=(pos>>8)&0x00FF;
  2673. -      drvcmd[3]=pos&0x00FF;
  2674. -      if (famL_drive)
  2675. -    flags_cmd_out=f_putcmd|f_respo2|f_lopsta|f_getsta|f_ResponseStatus|f_obey_p_check|f_bit1;
  2676. -      else
  2677. -    flags_cmd_out=f_putcmd|f_respo2|f_ResponseStatus|f_obey_p_check;
  2678. -    }
  2679. -  else if (fam2_drive)
  2680. -    {
  2681. -      drvcmd[0]=CMD2_SEEK;
  2682. -      if (f_blk_msf==0) pos=blk2msf(pos);
  2683. -      drvcmd[2]=(pos>>16)&0x00FF;
  2684. -      drvcmd[3]=(pos>>16)&0x00FF;
  2685. -      drvcmd[4]=(pos>>8)&0x00FF;
  2686. -      drvcmd[5]=pos&0x00FF;
  2687. -      flags_cmd_out=f_putcmd|f_ResponseStatus;
  2688. -    }
  2689. -  response_count=0;
  2690. -  i=cmd_out(7);
  2691. -  return (i);
  2692. -}
  2693. -/*==========================================================================*/
  2694. -static int xx_SpinUp(void)
  2695. -{
  2696. -  int i;
  2697. -
  2698. -  DPRINTF((DBG_SPI,"SBPCD: SpinUp.\n"));
  2699. -  DriveStruct[d].in_SpinUp = 1;
  2700. -  clr_cmdbuf();
  2701. -  if (fam0L_drive)
  2702. -    {
  2703. -      drvcmd[0]=CMD0_SPINUP;
  2704. -      flags_cmd_out=f_putcmd|f_respo2|f_lopsta|f_getsta|
  2705. -    f_ResponseStatus|f_obey_p_check|f_bit1;
  2706. -    }
  2707. -  else if (fam1_drive)
  2708. -    {
  2709. -      drvcmd[0]=CMD1_SPINUP;
  2710. -      flags_cmd_out=f_putcmd|f_respo2|f_ResponseStatus|f_obey_p_check;
  2711. -    }
  2712. -  else if (fam2_drive)
  2713. -    {
  2714. -      drvcmd[0]=CMD2_TRAY_CTL;
  2715. -      drvcmd[4]=0x01;
  2716. -      flags_cmd_out=f_putcmd|f_respo2|f_ResponseStatus|f_obey_p_check;
  2717. -    }
  2718. -  response_count=0;
  2719. -  i=cmd_out(7);
  2720. -  DriveStruct[d].in_SpinUp = 0;
  2721. -  return (i);
  2722. -}
  2723. -/*==========================================================================*/
  2724. -static int yy_SpinDown(void)
  2725. -{
  2726. -  int i;
  2727. -
  2728. -  if (fam0_drive) return (-3);
  2729. -  clr_cmdbuf();
  2730. -  response_count=0;
  2731. -  if (fam1_drive)
  2732. -    {
  2733. -      drvcmd[0]=CMD1_SPINDOWN;
  2734. -      flags_cmd_out=f_putcmd|f_respo2|f_ResponseStatus|f_obey_p_check;
  2735. -    }
  2736. -  else if (fam2_drive)
  2737. -    {
  2738. -      drvcmd[0]=CMD2_TRAY_CTL;
  2739. -      drvcmd[4]=0x02; /* "eject" */
  2740. -      flags_cmd_out=f_putcmd|f_ResponseStatus;
  2741. -    }
  2742. -  else if (famL_drive)
  2743. -    {
  2744. -      drvcmd[0]=CMDL_SPINDOWN;
  2745. -      drvcmd[1]=1;
  2746. -      flags_cmd_out=f_putcmd|f_respo2|f_lopsta|f_getsta|f_ResponseStatus|f_obey_p_check|f_bit1;
  2747. -    }
  2748. -  i=cmd_out(7);
  2749. -  return (i);
  2750. +    if (D_S[d].in_SpinUp) msg(DBG_SPI,"in_SpinUp: to CDi_stat_loop.\n");
  2751. +    if (flags_cmd_out&f_lopsta)
  2752. +    {
  2753. +        i=CDi_stat_loop();
  2754. +        if ((i<0)||!(i&s_attention)) return (-8);
  2755. +    }
  2756. +    if (!(flags_cmd_out&f_getsta)) goto LOC_229;
  2757. +    
  2758. + LOC_228:
  2759. +    if (D_S[d].in_SpinUp) msg(DBG_SPI,"in_SpinUp: to cc_ReadStatus.\n");
  2760. +    cc_ReadStatus();
  2761. +    
  2762. + LOC_229:
  2763. +    if (flags_cmd_out&f_ResponseStatus) 
  2764. +    {
  2765. +        if (D_S[d].in_SpinUp) msg(DBG_SPI,"in_SpinUp: to ResponseStatus.\n");
  2766. +        i=ResponseStatus();
  2767. +        /* builds status_bits, returns orig. status or p_busy_new */
  2768. +        if (i<0) return (-9);
  2769. +        if (flags_cmd_out&(f_bit1|f_wait_if_busy))
  2770. +        {
  2771. +            if (!st_check)
  2772. +            {
  2773. +                if ((flags_cmd_out&f_bit1)&&(i&p_success)) goto LOC_232;
  2774. +                if ((!(flags_cmd_out&f_wait_if_busy))||(!st_busy)) goto LOC_228;
  2775. +            }
  2776. +        }
  2777. +    }
  2778. + LOC_232:
  2779. +    if (!(flags_cmd_out&f_obey_p_check)) return (0);
  2780. +    if (!st_check) return (0);
  2781. +    if (D_S[d].in_SpinUp) msg(DBG_SPI,"in_SpinUp: to cc_ReadError.\n");
  2782. +    i=cc_ReadError();
  2783. +    if (D_S[d].in_SpinUp) msg(DBG_SPI,"in_SpinUp: to cmd_out OK.\n");
  2784. +    msg(DBG_000,"cmd_out: cc_ReadError=%d\n", i);
  2785. +    return (i);
  2786.  }
  2787.  /*==========================================================================*/
  2788. -static int yy_SetSpeed(u_char speed, u_char x1, u_char x2)
  2789. +static int cc_Seek(u_int pos, char f_blk_msf)
  2790.  {
  2791. -  int i;
  2792. -
  2793. -  if (fam0L_drive) return (-3);
  2794. +    int i;
  2795. +    
  2796.    clr_cmdbuf();
  2797. -  response_count=0;
  2798. -  if (fam1_drive)
  2799. -    {
  2800. -      drvcmd[0]=CMD1_SETMODE;
  2801. -      drvcmd[1]=0x03;
  2802. -      drvcmd[2]=speed;
  2803. -      drvcmd[3]=x1;
  2804. -      drvcmd[4]=x2;
  2805. -      flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
  2806. -    }
  2807. -  else if (fam2_drive)
  2808. -    {
  2809. -      drvcmd[0]=CMD2_SETSPEED;
  2810. -      if (speed&speed_auto)
  2811. +    if (f_blk_msf>1) return (-3);
  2812. +    if (fam0_drive)
  2813.      {
  2814. -      drvcmd[2]=0xFF;
  2815. -      drvcmd[3]=0xFF;
  2816. +        drvcmd[0]=CMD0_SEEK;
  2817. +        if (f_blk_msf==1) pos=msf2blk(pos);
  2818. +        drvcmd[2]=(pos>>16)&0x00FF;
  2819. +        drvcmd[3]=(pos>>8)&0x00FF;
  2820. +        drvcmd[4]=pos&0x00FF;
  2821. +        flags_cmd_out = f_putcmd | f_respo2 | f_lopsta | f_getsta |
  2822. +            f_ResponseStatus | f_obey_p_check | f_bit1;
  2823. +    }
  2824. +    else if (fam1L_drive)
  2825. +    {
  2826. +        drvcmd[0]=CMD1_SEEK; /* same as CMD1_ and CMDL_ */
  2827. +        if (f_blk_msf==0) pos=blk2msf(pos);
  2828. +        drvcmd[1]=(pos>>16)&0x00FF;
  2829. +        drvcmd[2]=(pos>>8)&0x00FF;
  2830. +        drvcmd[3]=pos&0x00FF;
  2831. +        if (famL_drive)
  2832. +            flags_cmd_out=f_putcmd|f_respo2|f_lopsta|f_getsta|f_ResponseStatus|f_obey_p_check|f_bit1;
  2833. +        else
  2834. +            flags_cmd_out=f_putcmd|f_respo2|f_ResponseStatus|f_obey_p_check;
  2835. +    }
  2836. +    else if (fam2_drive)
  2837. +    {
  2838. +        drvcmd[0]=CMD2_SEEK;
  2839. +        if (f_blk_msf==0) pos=blk2msf(pos);
  2840. +        drvcmd[2]=(pos>>24)&0x00FF;
  2841. +        drvcmd[3]=(pos>>16)&0x00FF;
  2842. +        drvcmd[4]=(pos>>8)&0x00FF;
  2843. +        drvcmd[5]=pos&0x00FF;
  2844. +        flags_cmd_out=f_putcmd|f_ResponseStatus;
  2845. +    }
  2846. +    else if (famT_drive)
  2847. +    {
  2848. +        drvcmd[0]=CMDT_SEEK;
  2849. +        if (f_blk_msf==1) pos=msf2blk(pos);
  2850. +        drvcmd[2]=(pos>>24)&0x00FF;
  2851. +        drvcmd[3]=(pos>>16)&0x00FF;
  2852. +        drvcmd[4]=(pos>>8)&0x00FF;
  2853. +        drvcmd[5]=pos&0x00FF;
  2854. +        D_S[d].n_bytes=1;
  2855. +    }
  2856. +    response_count=0;
  2857. +    i=cmd_out();
  2858. +    return (i);
  2859. +}
  2860. +/*==========================================================================*/
  2861. +static int cc_SpinUp(void)
  2862. +{
  2863. +    int i;
  2864. +    
  2865. +    msg(DBG_SPI,"SpinUp.\n");
  2866. +    D_S[d].in_SpinUp = 1;
  2867. +    clr_cmdbuf();
  2868. +    if (fam0L_drive)
  2869. +    {
  2870. +        drvcmd[0]=CMD0_SPINUP;
  2871. +        flags_cmd_out=f_putcmd|f_respo2|f_lopsta|f_getsta|
  2872. +            f_ResponseStatus|f_obey_p_check|f_bit1;
  2873. +    }
  2874. +    else if (fam1_drive)
  2875. +    {
  2876. +        drvcmd[0]=CMD1_SPINUP;
  2877. +        flags_cmd_out=f_putcmd|f_respo2|f_ResponseStatus|f_obey_p_check;
  2878. +    }
  2879. +    else if (fam2_drive)
  2880. +    {
  2881. +        drvcmd[0]=CMD2_TRAY_CTL;
  2882. +        drvcmd[4]=0x01; /* "spinup" */
  2883. +        flags_cmd_out=f_putcmd|f_respo2|f_ResponseStatus|f_obey_p_check;
  2884. +    }
  2885. +    else if (famT_drive)
  2886. +    {
  2887. +        drvcmd[0]=CMDT_TRAY_CTL;
  2888. +        drvcmd[4]=0x03; /* "insert", it hopefully spins the drive up */
  2889. +    }
  2890. +    response_count=0;
  2891. +    i=cmd_out();
  2892. +    D_S[d].in_SpinUp = 0;
  2893. +    return (i);
  2894. +}
  2895. +/*==========================================================================*/
  2896. +static int cc_SpinDown(void)
  2897. +{
  2898. +    int i;
  2899. +    
  2900. +    if (fam0_drive) return (0);
  2901. +    clr_cmdbuf();
  2902. +    response_count=0;
  2903. +    if (fam1_drive)
  2904. +    {
  2905. +        drvcmd[0]=CMD1_SPINDOWN;
  2906. +        flags_cmd_out=f_putcmd|f_respo2|f_ResponseStatus|f_obey_p_check;
  2907. +    }
  2908. +    else if (fam2_drive)
  2909. +    {
  2910. +        drvcmd[0]=CMD2_TRAY_CTL;
  2911. +        drvcmd[4]=0x02; /* "eject" */
  2912. +        flags_cmd_out=f_putcmd|f_ResponseStatus;
  2913. +    }
  2914. +    else if (famL_drive)
  2915. +    {
  2916. +        drvcmd[0]=CMDL_SPINDOWN;
  2917. +        drvcmd[1]=1;
  2918. +        flags_cmd_out=f_putcmd|f_respo2|f_lopsta|f_getsta|f_ResponseStatus|f_obey_p_check|f_bit1;
  2919. +    }
  2920. +    else if (famT_drive)
  2921. +    {
  2922. +        drvcmd[0]=CMDT_TRAY_CTL;
  2923. +        drvcmd[4]=0x02; /* "eject" */
  2924. +    }
  2925. +    i=cmd_out();
  2926. +    return (i);
  2927. +}
  2928. +/*==========================================================================*/
  2929. +static int cc_get_mode_T(void)
  2930. +{
  2931. +    int i;
  2932. +    
  2933. +    clr_cmdbuf();
  2934. +    response_count=10;
  2935. +    drvcmd[0]=CMDT_GETMODE;
  2936. +    drvcmd[4]=response_count;
  2937. +    i=cmd_out_T();
  2938. +    return (i);
  2939. +}
  2940. +/*==========================================================================*/
  2941. +static int cc_set_mode_T(void)
  2942. +{
  2943. +    int i;
  2944. +    
  2945. +    clr_cmdbuf();
  2946. +    response_count=1;
  2947. +    drvcmd[0]=CMDT_SETMODE;
  2948. +    drvcmd[1]=D_S[d].speed_byte;
  2949. +    drvcmd[2]=D_S[d].frmsiz>>8;
  2950. +    drvcmd[3]=D_S[d].frmsiz&0x0FF;
  2951. +    drvcmd[4]=D_S[d].f_XA; /* 1: XA */
  2952. +    drvcmd[5]=D_S[d].type_byte; /* 0, 1, 3 */
  2953. +    drvcmd[6]=D_S[d].mode_xb_6;
  2954. +    drvcmd[7]=D_S[d].mode_yb_7|D_S[d].volume_control;
  2955. +    drvcmd[8]=D_S[d].mode_xb_8;
  2956. +    drvcmd[9]=D_S[d].delay;
  2957. +    i=cmd_out_T();
  2958. +    return (i);
  2959. +}
  2960. +/*==========================================================================*/
  2961. +static int cc_prep_mode_T(void)
  2962. +{
  2963. +    int i, j;
  2964. +    
  2965. +    i=cc_get_mode_T();
  2966. +    if (i<0) return (i);
  2967. +    for (i=0;i<10;i++)
  2968. +        sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
  2969. +    msgbuf[i*3]=0;
  2970. +    msg(DBG_TEA,"CMDT_GETMODE:%s\n", msgbuf);
  2971. +    D_S[d].speed_byte=0x02; /* 0x02: auto quad, 0x82: quad, 0x81: double, 0x80: single */
  2972. +    D_S[d].frmsiz=make16(infobuf[2],infobuf[3]);
  2973. +    D_S[d].f_XA=infobuf[4];
  2974. +    if (D_S[d].f_XA==0) D_S[d].type_byte=0;
  2975. +    else D_S[d].type_byte=1;
  2976. +    D_S[d].mode_xb_6=infobuf[6];
  2977. +    D_S[d].mode_yb_7=1;
  2978. +    D_S[d].mode_xb_8=infobuf[8];
  2979. +    D_S[d].delay=0; /* 0, 1, 2, 3 */
  2980. +    j=cc_set_mode_T();
  2981. +    i=cc_get_mode_T();
  2982. +    for (i=0;i<10;i++)
  2983. +        sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
  2984. +    msgbuf[i*3]=0;
  2985. +    msg(DBG_TEA,"CMDT_GETMODE:%s\n", msgbuf);
  2986. +    return (j);
  2987. +}
  2988. +/*==========================================================================*/
  2989. +static int cc_SetSpeed(u_char speed, u_char x1, u_char x2)
  2990. +{
  2991. +    int i;
  2992. +    
  2993. +    if (fam0L_drive) return (-3);
  2994. +    clr_cmdbuf();
  2995. +    response_count=0;
  2996. +    if (fam1_drive)
  2997. +    {
  2998. +        drvcmd[0]=CMD1_SETMODE;
  2999. +        drvcmd[1]=0x03;
  3000. +        drvcmd[2]=speed;
  3001. +        drvcmd[3]=x1;
  3002. +        drvcmd[4]=x2;
  3003. +        flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
  3004.      }
  3005. -      else
  3006. +    else if (fam2_drive)
  3007.      {
  3008. -      drvcmd[2]=0;
  3009. -      drvcmd[3]=150;
  3010. +        drvcmd[0]=CMD2_SETSPEED;
  3011. +        if (speed&speed_auto)
  3012. +        {
  3013. +            drvcmd[2]=0xFF;
  3014. +            drvcmd[3]=0xFF;
  3015. +        }
  3016. +        else
  3017. +        {
  3018. +            drvcmd[2]=0;
  3019. +            drvcmd[3]=150;
  3020. +        }
  3021. +        flags_cmd_out=f_putcmd|f_ResponseStatus;
  3022.      }
  3023. -      flags_cmd_out=f_putcmd|f_ResponseStatus;
  3024. -    }
  3025. -  i=cmd_out(7);
  3026. -  return (i);
  3027. +    else if (famT_drive)
  3028. +    {
  3029. +        return (0);
  3030. +    }
  3031. +    i=cmd_out();
  3032. +    return (i);
  3033.  }
  3034.  /*==========================================================================*/
  3035. -static int xx_SetVolume(void)
  3036. +static int cc_SetVolume(void)
  3037.  {
  3038. -  int i;
  3039. -  u_char channel0,channel1,volume0,volume1;
  3040. -  u_char control0,value0,control1,value1;
  3041. -
  3042. -  DriveStruct[d].diskstate_flags &= ~volume_bit;
  3043. -  clr_cmdbuf();
  3044. -  channel0=DriveStruct[d].vol_chan0;
  3045. -  volume0=DriveStruct[d].vol_ctrl0;
  3046. -  channel1=control1=DriveStruct[d].vol_chan1;
  3047. -  volume1=value1=DriveStruct[d].vol_ctrl1;
  3048. -  control0=value0=0;
  3049. -
  3050. -  if (((DriveStruct[d].drv_options&audio_mono)!=0)&&(DriveStruct[d].drv_type>=drv_211))
  3051. -    {
  3052. -      if ((volume0!=0)&&(volume1==0))
  3053. +    int i;
  3054. +    u_char channel0,channel1,volume0,volume1;
  3055. +    u_char control0,value0,control1,value1;
  3056. +    
  3057. +    D_S[d].diskstate_flags &= ~volume_bit;
  3058. +    clr_cmdbuf();
  3059. +    channel0=D_S[d].vol_chan0;
  3060. +    volume0=D_S[d].vol_ctrl0;
  3061. +    channel1=control1=D_S[d].vol_chan1;
  3062. +    volume1=value1=D_S[d].vol_ctrl1;
  3063. +    control0=value0=0;
  3064. +    
  3065. +    if (((D_S[d].drv_options&audio_mono)!=0)&&(D_S[d].drv_type>=drv_211))
  3066.      {
  3067. -      volume1=volume0;
  3068. -      channel1=channel0;
  3069. +        if ((volume0!=0)&&(volume1==0))
  3070. +        {
  3071. +            volume1=volume0;
  3072. +            channel1=channel0;
  3073. +        }
  3074. +        else if ((volume0==0)&&(volume1!=0))
  3075. +        {
  3076. +            volume0=volume1;
  3077. +            channel0=channel1;
  3078. +        }
  3079.      }
  3080. -      else if ((volume0==0)&&(volume1!=0))
  3081. +    if (channel0>1)
  3082.      {
  3083. -      volume0=volume1;
  3084. -      channel0=channel1;
  3085. +        channel0=0;
  3086. +        volume0=0;
  3087.      }
  3088. -    }
  3089. -  if (channel0>1)
  3090. -    {
  3091. -      channel0=0;
  3092. -      volume0=0;
  3093. -    }
  3094. -  if (channel1>1)
  3095. -    {
  3096. -      channel1=1;
  3097. -      volume1=0;
  3098. -    }
  3099. -  
  3100. -  if (fam1_drive)
  3101. -    {
  3102. -      control0=channel0+1;
  3103. -      control1=channel1+1;
  3104. -      value0=(volume0>volume1)?volume0:volume1;
  3105. -      value1=value0;
  3106. -      if (volume0==0) control0=0;
  3107. -      if (volume1==0) control1=0;
  3108. -      drvcmd[0]=CMD1_SETMODE;
  3109. -      drvcmd[1]=0x05;
  3110. -      drvcmd[3]=control0;
  3111. -      drvcmd[4]=value0;
  3112. -      drvcmd[5]=control1;
  3113. -      drvcmd[6]=value1;
  3114. -      flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
  3115. -    }
  3116. -  else if (fam2_drive)
  3117. -    {
  3118. -      control0=channel0+1;
  3119. -      control1=channel1+1;
  3120. -      value0=(volume0>volume1)?volume0:volume1;
  3121. -      value1=value0;
  3122. -      if (volume0==0) control0=0;
  3123. -      if (volume1==0) control1=0;
  3124. -      drvcmd[0]=CMD2_SETMODE;
  3125. -      drvcmd[1]=0x0E;
  3126. -      drvcmd[3]=control0;
  3127. -      drvcmd[4]=value0;
  3128. -      drvcmd[5]=control1;
  3129. -      drvcmd[6]=value1;
  3130. -      flags_cmd_out=f_putcmd|f_ResponseStatus;
  3131. -    }
  3132. -  else if (famL_drive)
  3133. -    {
  3134. -      if ((volume0==0)||(channel0!=0)) control0 |= 0x80;
  3135. -      if ((volume1==0)||(channel1!=1)) control0 |= 0x40;
  3136. -      if (volume0|volume1) value0=0x80;
  3137. -      drvcmd[0]=CMDL_SETMODE;
  3138. -      drvcmd[1]=0x03;
  3139. -      drvcmd[4]=control0;
  3140. -      drvcmd[5]=value0;
  3141. -      flags_cmd_out=f_putcmd|f_lopsta|f_getsta|f_ResponseStatus|f_obey_p_check|f_bit1;
  3142. -    }
  3143. -  else if (fam0_drive) /* different firmware levels */
  3144. -    {
  3145. -      if (DriveStruct[d].drv_type>=drv_300)
  3146. -    {
  3147. -      control0=volume0&0xFC;
  3148. -      value0=volume1&0xFC;
  3149. -      if ((volume0!=0)&&(volume0<4)) control0 |= 0x04;
  3150. -      if ((volume1!=0)&&(volume1<4)) value0 |= 0x04;
  3151. -      if (channel0!=0) control0 |= 0x01;
  3152. -      if (channel1==1) value0 |= 0x01;
  3153. -    }
  3154. -      else
  3155. -    {
  3156. -      value0=(volume0>volume1)?volume0:volume1;
  3157. -      if (DriveStruct[d].drv_type<drv_211)
  3158. -        {
  3159. -          if (channel0!=0)
  3160. -        {
  3161. -          i=channel1;
  3162. -          channel1=channel0;
  3163. -          channel0=i;
  3164. -          i=volume1;
  3165. -          volume1=volume0;
  3166. -          volume0=i;
  3167. -        }
  3168. -          if (channel0==channel1)
  3169. -        {
  3170. -          if (channel0==0)
  3171. -            {
  3172. -              channel1=1;
  3173. -              volume1=0;
  3174. -              volume0=value0;
  3175. -            }
  3176. -          else
  3177. -            {
  3178. -              channel0=0;
  3179. -              volume0=0;
  3180. -              volume1=value0;
  3181. -            }
  3182. -        }
  3183. -        }
  3184. -
  3185. -      if ((volume0!=0)&&(volume1!=0))
  3186. -        {
  3187. -          if (volume0==0xFF) volume1=0xFF;
  3188. -          else if (volume1==0xFF) volume0=0xFF;
  3189. -        }
  3190. -      else if (DriveStruct[d].drv_type<drv_201) volume0=volume1=value0;
  3191. -
  3192. -      if (DriveStruct[d].drv_type>=drv_201)
  3193. -        {
  3194. -          if (volume0==0) control0 |= 0x80;
  3195. -          if (volume1==0) control0 |= 0x40;
  3196. -        }
  3197. -      if (DriveStruct[d].drv_type>=drv_211)
  3198. -        {
  3199. -          if (channel0!=0) control0 |= 0x20;
  3200. -          if (channel1!=1) control0 |= 0x10;
  3201. -        }
  3202. -    }
  3203. -      drvcmd[0]=CMD0_SETMODE;
  3204. -      drvcmd[1]=0x83;
  3205. -      drvcmd[4]=control0;
  3206. -      drvcmd[5]=value0;
  3207. -      flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
  3208. -    }
  3209. -  response_count=0;
  3210. -  i=cmd_out(7);
  3211. -  if (i>0) return (i);
  3212. -  DriveStruct[d].diskstate_flags |= volume_bit;
  3213. -  return (0);
  3214. +    if (channel1>1)
  3215. +    {
  3216. +        channel1=1;
  3217. +        volume1=0;
  3218. +    }
  3219. +    
  3220. +    if (fam1_drive)
  3221. +    {
  3222. +        control0=channel0+1;
  3223. +        control1=channel1+1;
  3224. +        value0=(volume0>volume1)?volume0:volume1;
  3225. +        value1=value0;
  3226. +        if (volume0==0) control0=0;
  3227. +        if (volume1==0) control1=0;
  3228. +        drvcmd[0]=CMD1_SETMODE;
  3229. +        drvcmd[1]=0x05;
  3230. +        drvcmd[3]=control0;
  3231. +        drvcmd[4]=value0;
  3232. +        drvcmd[5]=control1;
  3233. +        drvcmd[6]=value1;
  3234. +        flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
  3235. +    }
  3236. +    else if (fam2_drive)
  3237. +    {
  3238. +        control0=channel0+1;
  3239. +        control1=channel1+1;
  3240. +        value0=(volume0>volume1)?volume0:volume1;
  3241. +        value1=value0;
  3242. +        if (volume0==0) control0=0;
  3243. +        if (volume1==0) control1=0;
  3244. +        drvcmd[0]=CMD2_SETMODE;
  3245. +        drvcmd[1]=0x0E;
  3246. +        drvcmd[3]=control0;
  3247. +        drvcmd[4]=value0;
  3248. +        drvcmd[5]=control1;
  3249. +        drvcmd[6]=value1;
  3250. +        flags_cmd_out=f_putcmd|f_ResponseStatus;
  3251. +    }
  3252. +    else if (famL_drive)
  3253. +    {
  3254. +        if ((volume0==0)||(channel0!=0)) control0 |= 0x80;
  3255. +        if ((volume1==0)||(channel1!=1)) control0 |= 0x40;
  3256. +        if (volume0|volume1) value0=0x80;
  3257. +        drvcmd[0]=CMDL_SETMODE;
  3258. +        drvcmd[1]=0x03;
  3259. +        drvcmd[4]=control0;
  3260. +        drvcmd[5]=value0;
  3261. +        flags_cmd_out=f_putcmd|f_lopsta|f_getsta|f_ResponseStatus|f_obey_p_check|f_bit1;
  3262. +    }
  3263. +    else if (fam0_drive) /* different firmware levels */
  3264. +    {
  3265. +        if (D_S[d].drv_type>=drv_300)
  3266. +        {
  3267. +            control0=volume0&0xFC;
  3268. +            value0=volume1&0xFC;
  3269. +            if ((volume0!=0)&&(volume0<4)) control0 |= 0x04;
  3270. +            if ((volume1!=0)&&(volume1<4)) value0 |= 0x04;
  3271. +            if (channel0!=0) control0 |= 0x01;
  3272. +            if (channel1==1) value0 |= 0x01;
  3273. +        }
  3274. +        else
  3275. +        {
  3276. +            value0=(volume0>volume1)?volume0:volume1;
  3277. +            if (D_S[d].drv_type<drv_211)
  3278. +            {
  3279. +                if (channel0!=0)
  3280. +                {
  3281. +                    i=channel1;
  3282. +                    channel1=channel0;
  3283. +                    channel0=i;
  3284. +                    i=volume1;
  3285. +                    volume1=volume0;
  3286. +                    volume0=i;
  3287. +                }
  3288. +                if (channel0==channel1)
  3289. +                {
  3290. +                    if (channel0==0)
  3291. +                    {
  3292. +                        channel1=1;
  3293. +                        volume1=0;
  3294. +                        volume0=value0;
  3295. +                    }
  3296. +                    else
  3297. +                    {
  3298. +                        channel0=0;
  3299. +                        volume0=0;
  3300. +                        volume1=value0;
  3301. +                    }
  3302. +                }
  3303. +            }
  3304. +            
  3305. +            if ((volume0!=0)&&(volume1!=0))
  3306. +            {
  3307. +                if (volume0==0xFF) volume1=0xFF;
  3308. +                else if (volume1==0xFF) volume0=0xFF;
  3309. +            }
  3310. +            else if (D_S[d].drv_type<drv_201) volume0=volume1=value0;
  3311. +            
  3312. +            if (D_S[d].drv_type>=drv_201)
  3313. +            {
  3314. +                if (volume0==0) control0 |= 0x80;
  3315. +                if (volume1==0) control0 |= 0x40;
  3316. +            }
  3317. +            if (D_S[d].drv_type>=drv_211)
  3318. +            {
  3319. +                if (channel0!=0) control0 |= 0x20;
  3320. +                if (channel1!=1) control0 |= 0x10;
  3321. +            }
  3322. +        }
  3323. +        drvcmd[0]=CMD0_SETMODE;
  3324. +        drvcmd[1]=0x83;
  3325. +        drvcmd[4]=control0;
  3326. +        drvcmd[5]=value0;
  3327. +        flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
  3328. +    }
  3329. +    else if (famT_drive)
  3330. +    {
  3331. +        D_S[d].volume_control=0;
  3332. +        if (!volume0) D_S[d].volume_control|=0x10;
  3333. +        if (!volume1) D_S[d].volume_control|=0x20;
  3334. +        i=cc_prep_mode_T();
  3335. +        if (i<0) return (i);
  3336. +    }
  3337. +    if (!famT_drive)
  3338. +    {
  3339. +        response_count=0;
  3340. +        i=cmd_out();
  3341. +        if (i<0) return (i);
  3342. +    }
  3343. +    D_S[d].diskstate_flags |= volume_bit;
  3344. +    return (0);
  3345.  }
  3346.  /*==========================================================================*/
  3347.  static int GetStatus(void)
  3348.  {
  3349. -  int i;
  3350. -
  3351. -  flags_cmd_out=f_getsta|f_ResponseStatus|f_obey_p_check;
  3352. -  response_count=0;
  3353. -  cmd_type=0;
  3354. -  i=cmd_out(7);
  3355. -  return (i);
  3356. -}
  3357. -/*==========================================================================*/
  3358. -static int xy_DriveReset(void)
  3359. -{
  3360. -  int i;
  3361. -
  3362. -  DPRINTF((DBG_RES,"SBPCD: xy_DriveReset called.\n"));
  3363. -  clr_cmdbuf();
  3364. -  response_count=0;
  3365. -  if (fam0L_drive) OUT(CDo_reset,0x00);
  3366. -  else if (fam1_drive)
  3367. -    {
  3368. -      drvcmd[0]=CMD1_RESET;
  3369. -      flags_cmd_out=f_putcmd;
  3370. -      i=cmd_out(7);
  3371. -    }
  3372. -  else if (fam2_drive)
  3373. -    {
  3374. -      drvcmd[0]=CMD2_RESET;
  3375. -      flags_cmd_out=f_putcmd;
  3376. -      i=cmd_out(7);
  3377. -      OUT(CDo_reset,0x00);
  3378. -    }
  3379. -  if (famL_drive) sbp_sleep(500); /* wait 5 seconds */
  3380. -  else sbp_sleep(100); /* wait a second */
  3381. -  flush_status();
  3382. -  i=GetStatus();
  3383. -  if (i>=0) return -1;
  3384. -  if (DriveStruct[d].error_byte!=aud_12) return -1;
  3385. -  return (0);
  3386. +    int i;
  3387. +    
  3388. +    if (famT_drive) return (0);
  3389. +    flags_cmd_out=f_getsta|f_ResponseStatus|f_obey_p_check;
  3390. +    response_count=0;
  3391. +    cmd_type=0;
  3392. +    i=cmd_out();
  3393. +    return (i);
  3394. +}
  3395. +/*==========================================================================*/
  3396. +static int cc_DriveReset(void)
  3397. +{
  3398. +    int i;
  3399. +    
  3400. +    msg(DBG_RES,"cc_DriveReset called.\n");
  3401. +    clr_cmdbuf();
  3402. +    response_count=0;
  3403. +    if (fam0L_drive) OUT(CDo_reset,0x00);
  3404. +    else if (fam1_drive)
  3405. +    {
  3406. +        drvcmd[0]=CMD1_RESET;
  3407. +        flags_cmd_out=f_putcmd;
  3408. +        i=cmd_out();
  3409. +    }
  3410. +    else if (fam2_drive)
  3411. +    {
  3412. +        drvcmd[0]=CMD2_RESET;
  3413. +        flags_cmd_out=f_putcmd;
  3414. +        i=cmd_out();
  3415. +        OUT(CDo_reset,0x00);
  3416. +    }
  3417. +    else if (famT_drive)
  3418. +    {
  3419. +        OUT(CDo_sel_i_d,0);
  3420. +        OUT(CDo_enable,D_S[d].drv_sel);
  3421. +        OUT(CDo_command,CMDT_RESET);
  3422. +        for (i=1;i<10;i++) OUT(CDo_command,0);
  3423. +    }
  3424. +    if (fam0L_drive) sbp_sleep(500); /* wait 5 seconds */
  3425. +    else sbp_sleep(100); /* wait a second */
  3426. +#if 1
  3427. +    if (famT_drive)
  3428. +    {
  3429. +        msg(DBG_TEA, "================CMDT_RESET given=================.\n");
  3430. +        sbp_sleep(300);
  3431. +    }
  3432. +#endif 1
  3433. +    flush_status();
  3434. +    i=GetStatus();
  3435. +    if (i<0) return i;
  3436. +    if (!famT_drive)
  3437. +        if (D_S[d].error_byte!=aud_12) return -501;
  3438. +    return (0);
  3439.  }
  3440.  /*==========================================================================*/
  3441.  static int SetSpeed(void)
  3442.  {
  3443. -  int i, speed;
  3444. -
  3445. -  if (!(DriveStruct[d].drv_options&(speed_auto|speed_300|speed_150))) return (0);
  3446. -  speed=speed_auto;
  3447. -  if (!(DriveStruct[d].drv_options&speed_auto))
  3448. -    {
  3449. -      speed |= speed_300;
  3450. -      if (!(DriveStruct[d].drv_options&speed_300)) speed=0;
  3451. -    }
  3452. -  i=yy_SetSpeed(speed,0,0);
  3453. -  return (i);
  3454. +    int i, speed;
  3455. +    
  3456. +    if (!(D_S[d].drv_options&(speed_auto|speed_300|speed_150))) return (0);
  3457. +    speed=speed_auto;
  3458. +    if (!(D_S[d].drv_options&speed_auto))
  3459. +    {
  3460. +        speed |= speed_300;
  3461. +        if (!(D_S[d].drv_options&speed_300)) speed=0;
  3462. +    }
  3463. +    i=cc_SetSpeed(speed,0,0);
  3464. +    return (i);
  3465.  }
  3466.  /*==========================================================================*/
  3467.  static int DriveReset(void)
  3468.  {
  3469. -  int i;
  3470. -
  3471. -  i=xy_DriveReset();
  3472. -  if (i<0) return (-2);
  3473. -  do
  3474. -    {
  3475. -      i=GetStatus();
  3476. -      if ((i<0)&&(i!=-15)) return (-2); /* i!=-15 is from sta2err */
  3477. -      if (!st_caddy_in) break;
  3478. -    }
  3479. -  while (!st_diskok);
  3480. +    int i;
  3481. +    
  3482. +    i=cc_DriveReset();
  3483. +    if (i<0) return (-22);
  3484. +    do
  3485. +    {
  3486. +        i=GetStatus();
  3487. +        if ((i<0)&&(i!=-615)) return (-2); /* i!=-615 is from sta2err */
  3488. +        if (!st_caddy_in) break;
  3489. +        sbp_sleep(1);
  3490. +    }
  3491. +    while (!st_diskok);
  3492.  #if 000
  3493. -  DriveStruct[d].CD_changed=1;
  3494. +    D_S[d].CD_changed=1;
  3495.  #endif
  3496. -  if ((st_door_closed) && (st_caddy_in))
  3497. -    {
  3498. -      i=DiskInfo();
  3499. -      if (i<0) return (-2);
  3500. -    }
  3501. -  return (0);
  3502. +    if ((st_door_closed) && (st_caddy_in))
  3503. +    {
  3504. +        i=DiskInfo();
  3505. +        if (i<0) return (-23);
  3506. +    }
  3507. +    return (0);
  3508.  }
  3509.  /*==========================================================================*/
  3510. -static int xx_Pause_Resume(int pau_res)
  3511. +static int cc_PlayAudio(int pos_audio_start,int pos_audio_end)
  3512.  {
  3513. -  int i;
  3514. -
  3515. -  clr_cmdbuf();
  3516. -  response_count=0;
  3517. -  if (fam1_drive)
  3518. -    {
  3519. -      drvcmd[0]=CMD1_PAU_RES;
  3520. -      if (pau_res!=1) drvcmd[1]=0x80;
  3521. -      flags_cmd_out=f_putcmd|f_respo2|f_ResponseStatus|f_obey_p_check;
  3522. -    }
  3523. -  else if (fam2_drive)
  3524. -    {
  3525. -      drvcmd[0]=CMD2_PAU_RES;
  3526. -      if (pau_res!=1) drvcmd[2]=0x01;
  3527. -      flags_cmd_out=f_putcmd|f_ResponseStatus;
  3528. -    }
  3529. -  else if (fam0L_drive)
  3530. -    {
  3531. -      drvcmd[0]=CMD0_PAU_RES;
  3532. -      if (pau_res!=1) drvcmd[1]=0x80;
  3533. -      if (famL_drive)
  3534. -    flags_cmd_out=f_putcmd|f_respo2|f_lopsta|f_getsta|f_ResponseStatus|
  3535. -      f_obey_p_check|f_bit1;
  3536. -      else
  3537. -    flags_cmd_out=f_putcmd|f_respo2|f_lopsta|f_getsta|f_ResponseStatus|
  3538. -      f_obey_p_check;
  3539. -    }
  3540. -  i=cmd_out(7);
  3541. -  return (i);
  3542. +    int i, j, n;
  3543. +    
  3544. +    if (D_S[d].audio_state==audio_playing) return (-EINVAL);
  3545. +    clr_cmdbuf();
  3546. +    response_count=0;
  3547. +    if (famL_drive)
  3548. +    {
  3549. +        drvcmd[0]=CMDL_PLAY;
  3550. +        i=msf2blk(pos_audio_start);
  3551. +        n=msf2blk(pos_audio_end)+1-i;
  3552. +        drvcmd[1]=(i>>16)&0x00FF;
  3553. +        drvcmd[2]=(i>>8)&0x00FF;
  3554. +        drvcmd[3]=i&0x00FF;
  3555. +        drvcmd[4]=(n>>16)&0x00FF;
  3556. +        drvcmd[5]=(n>>8)&0x00FF;
  3557. +        drvcmd[6]=n&0x00FF;
  3558. +        flags_cmd_out = f_putcmd | f_respo2 | f_lopsta | f_getsta |
  3559. +            f_ResponseStatus | f_obey_p_check | f_wait_if_busy;
  3560. +    }
  3561. +    else
  3562. +    {
  3563. +        j=1;
  3564. +        if (fam1_drive)
  3565. +        {
  3566. +            drvcmd[0]=CMD1_PLAY_MSF;
  3567. +            flags_cmd_out = f_putcmd | f_respo2 | f_ResponseStatus |
  3568. +                f_obey_p_check | f_wait_if_busy;
  3569. +        }
  3570. +        else if (fam2_drive)
  3571. +        {
  3572. +            drvcmd[0]=CMD2_PLAY_MSF;
  3573. +            flags_cmd_out = f_putcmd | f_ResponseStatus;
  3574. +        }
  3575. +        else if (famT_drive)
  3576. +        {
  3577. +            drvcmd[0]=CMDT_PLAY_MSF;
  3578. +            j=3;
  3579. +            response_count=1;
  3580. +        }
  3581. +        else if (fam0_drive)
  3582. +        {
  3583. +            drvcmd[0]=CMD0_PLAY_MSF;
  3584. +            flags_cmd_out = f_putcmd | f_respo2 | f_lopsta | f_getsta |
  3585. +                f_ResponseStatus | f_obey_p_check | f_wait_if_busy;
  3586. +        }
  3587. +        drvcmd[j]=(pos_audio_start>>16)&0x00FF;
  3588. +        drvcmd[j+1]=(pos_audio_start>>8)&0x00FF;
  3589. +        drvcmd[j+2]=pos_audio_start&0x00FF;
  3590. +        drvcmd[j+3]=(pos_audio_end>>16)&0x00FF;
  3591. +        drvcmd[j+4]=(pos_audio_end>>8)&0x00FF;
  3592. +        drvcmd[j+5]=pos_audio_end&0x00FF;
  3593. +    }
  3594. +    i=cmd_out();
  3595. +    return (i);
  3596.  }
  3597.  /*==========================================================================*/
  3598. -static int yy_LockDoor(char lock)
  3599. +static int cc_Pause_Resume(int pau_res)
  3600.  {
  3601. -  int i;
  3602. -
  3603. -  if (fam0_drive) return (0);
  3604. -  DPRINTF((DBG_LCK,"SBPCD: yy_LockDoor: %d (drive %d)\n", lock, d));
  3605. -  DPRINTF((DBG_LCS,"SBPCD: p_door_locked bit %d before\n", st_door_locked));
  3606. -  clr_cmdbuf();
  3607. -  response_count=0;
  3608. -  if (fam1_drive)
  3609. -    {
  3610. -      drvcmd[0]=CMD1_LOCK_CTL;
  3611. -      if (lock==1) drvcmd[1]=0x01;
  3612. -      flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
  3613. -    }
  3614. -  else if (fam2_drive)
  3615. -    {
  3616. -      drvcmd[0]=CMD2_LOCK_CTL;
  3617. -      if (lock==1) drvcmd[4]=0x01;
  3618. -      flags_cmd_out=f_putcmd|f_ResponseStatus;
  3619. -    }
  3620. -  else if (famL_drive)
  3621. -    {
  3622. -      drvcmd[0]=CMDL_LOCK_CTL;
  3623. -      if (lock==1) drvcmd[1]=0x01;
  3624. -      flags_cmd_out=f_putcmd|f_respo2|f_lopsta|f_getsta|f_ResponseStatus|f_obey_p_check|f_bit1;
  3625. -    }
  3626. -  i=cmd_out(7);
  3627. -  DPRINTF((DBG_LCS,"SBPCD: p_door_locked bit %d after\n", st_door_locked));
  3628. -  return (i);
  3629. +    int i;
  3630. +    
  3631. +    clr_cmdbuf();
  3632. +    response_count=0;
  3633. +    if (fam1_drive)
  3634. +    {
  3635. +        drvcmd[0]=CMD1_PAU_RES;
  3636. +        if (pau_res!=1) drvcmd[1]=0x80;
  3637. +        flags_cmd_out=f_putcmd|f_respo2|f_ResponseStatus|f_obey_p_check;
  3638. +    }
  3639. +    else if (fam2_drive)
  3640. +    {
  3641. +        drvcmd[0]=CMD2_PAU_RES;
  3642. +        if (pau_res!=1) drvcmd[2]=0x01;
  3643. +        flags_cmd_out=f_putcmd|f_ResponseStatus;
  3644. +    }
  3645. +    else if (fam0L_drive)
  3646. +    {
  3647. +        drvcmd[0]=CMD0_PAU_RES;
  3648. +        if (pau_res!=1) drvcmd[1]=0x80;
  3649. +        if (famL_drive)
  3650. +            flags_cmd_out=f_putcmd|f_respo2|f_lopsta|f_getsta|f_ResponseStatus|
  3651. +                f_obey_p_check|f_bit1;
  3652. +        else
  3653. +            flags_cmd_out=f_putcmd|f_respo2|f_lopsta|f_getsta|f_ResponseStatus|
  3654. +                f_obey_p_check;
  3655. +    }
  3656. +    else if (famT_drive)
  3657. +    {
  3658. +        if (pau_res==3)    return (cc_PlayAudio(D_S[d].pos_audio_start,D_S[d].pos_audio_end));
  3659. +        else if (pau_res==1) drvcmd[0]=CMDT_PAUSE;
  3660. +        else return (-56);
  3661. +    }
  3662. +    i=cmd_out();
  3663. +    return (i);
  3664.  }
  3665.  /*==========================================================================*/
  3666. -static int yy_CloseTray(void)
  3667. +static int cc_LockDoor(char lock)
  3668.  {
  3669. -  int i;
  3670. -
  3671. -  if (fam0_drive) return (0);
  3672. -  DPRINTF((DBG_LCK,"SBPCD: yy_CloseTray (drive %d)\n", d));
  3673. -  DPRINTF((DBG_LCS,"SBPCD: p_door_closed bit %d before\n", st_door_closed));
  3674. -
  3675. -  clr_cmdbuf();
  3676. -  response_count=0;
  3677. -  if (fam1_drive)
  3678. -    {
  3679. -      drvcmd[0]=CMD1_TRAY_CTL;
  3680. -      flags_cmd_out=f_putcmd|f_respo2|f_ResponseStatus|f_obey_p_check;
  3681. -    }
  3682. -  else if (fam2_drive)
  3683. -    {
  3684. -      drvcmd[0]=CMD2_TRAY_CTL;
  3685. -      drvcmd[1]=0x01;
  3686. -      drvcmd[4]=0x03; /* "insert" */
  3687. -      flags_cmd_out=f_putcmd|f_ResponseStatus;
  3688. -    }
  3689. -  else if (famL_drive)
  3690. -    {
  3691. -      drvcmd[0]=CMDL_TRAY_CTL;
  3692. -      flags_cmd_out=f_putcmd|f_respo2|f_lopsta|f_getsta|
  3693. -     f_ResponseStatus|f_obey_p_check|f_bit1;
  3694. -    }
  3695. -  i=cmd_out(7);
  3696. -  DPRINTF((DBG_LCS,"SBPCD: p_door_closed bit %d after\n", st_door_closed));
  3697. -  return (i);
  3698. +    int i;
  3699. +    
  3700. +    if (fam0_drive) return (0);
  3701. +    msg(DBG_LCK,"cc_LockDoor: %d (drive %d)\n", lock, d);
  3702. +    msg(DBG_LCS,"p_door_locked bit %d before\n", st_door_locked);
  3703. +    clr_cmdbuf();
  3704. +    response_count=0;
  3705. +    if (fam1_drive)
  3706. +    {
  3707. +        drvcmd[0]=CMD1_LOCK_CTL;
  3708. +        if (lock==1) drvcmd[1]=0x01;
  3709. +        flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
  3710. +    }
  3711. +    else if (fam2_drive)
  3712. +    {
  3713. +        drvcmd[0]=CMD2_LOCK_CTL;
  3714. +        if (lock==1) drvcmd[4]=0x01;
  3715. +        flags_cmd_out=f_putcmd|f_ResponseStatus;
  3716. +    }
  3717. +    else if (famL_drive)
  3718. +    {
  3719. +        drvcmd[0]=CMDL_LOCK_CTL;
  3720. +        if (lock==1) drvcmd[1]=0x01;
  3721. +        flags_cmd_out=f_putcmd|f_respo2|f_lopsta|f_getsta|f_ResponseStatus|f_obey_p_check|f_bit1;
  3722. +    }
  3723. +    else if (famT_drive)
  3724. +    {
  3725. +        drvcmd[0]=CMDT_LOCK_CTL;
  3726. +        if (lock==1) drvcmd[4]=0x01;
  3727. +    }
  3728. +    i=cmd_out();
  3729. +    msg(DBG_LCS,"p_door_locked bit %d after\n", st_door_locked);
  3730. +    return (i);
  3731.  }
  3732.  /*==========================================================================*/
  3733. -static int xx_ReadSubQ(void)
  3734. +/*==========================================================================*/
  3735. +static int UnLockDoor(void)
  3736.  {
  3737. -  int i,j;
  3738. -
  3739. -  DriveStruct[d].diskstate_flags &= ~subq_bit;
  3740. -  for (j=255;j>0;j--)
  3741. -    {
  3742. -      clr_cmdbuf();
  3743. -      if (fam1_drive)
  3744. +    int i,j;
  3745. +    
  3746. +    j=20;
  3747. +    do
  3748.      {
  3749. -      drvcmd[0]=CMD1_READSUBQ;
  3750. -      flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
  3751. -      response_count=11;
  3752. +        i=cc_LockDoor(0);
  3753. +        --j;
  3754. +        sbp_sleep(1);
  3755.      }
  3756. -      else if (fam2_drive)
  3757. +    while ((i<0)&&(j));
  3758. +    if (i<0)
  3759.      {
  3760. -      drvcmd[0]=CMD2_READSUBQ;
  3761. -      drvcmd[1]=0x02;
  3762. -      drvcmd[3]=0x01;
  3763. -      flags_cmd_out=f_putcmd;
  3764. -      response_count=10;
  3765. +        cc_DriveReset();
  3766. +        return -84;
  3767.      }
  3768. -      else if (fam0L_drive)
  3769. +    return (0);
  3770. +}
  3771. +/*==========================================================================*/
  3772. +static int LockDoor(void)
  3773. +{
  3774. +    int i,j;
  3775. +    
  3776. +    j=20;
  3777. +    do
  3778.      {
  3779. -      drvcmd[0]=CMD0_READSUBQ;
  3780. -      drvcmd[1]=0x02;
  3781. -       if (famL_drive)
  3782. -         flags_cmd_out=f_putcmd;
  3783. -       else
  3784. -         flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
  3785. -      response_count=13;
  3786. +        i=cc_LockDoor(1);
  3787. +        --j;
  3788. +        sbp_sleep(1);
  3789.      }
  3790. -      i=cmd_out(7);
  3791. -      if (i<0) return (i);
  3792. -      DPRINTF((DBG_SQ,"SBPCD: xx_ReadSubQ:"));
  3793. -      for (i=0;i<response_count;i++)
  3794. +    while ((i<0)&&(j));
  3795. +    if (j==0) cc_DriveReset();
  3796. +    j=20;
  3797. +    do
  3798.      {
  3799. -      DPRINTF((DBG_SQ," %02X", infobuf[i]));
  3800. +        i=cc_LockDoor(1);
  3801. +        --j;
  3802. +        sbp_sleep(1);
  3803.      }
  3804. -      DPRINTF((DBG_SQ,"\n"));
  3805. -      if (infobuf[0]!=0) break;
  3806. -      if ((!st_spinning) || (j==1))
  3807. +    while ((i<0)&&(j));
  3808. +    return (i);
  3809. +}
  3810. +/*==========================================================================*/
  3811. +static int cc_CloseTray(void)
  3812. +{
  3813. +    int i;
  3814. +    
  3815. +    if (fam0_drive) return (0);
  3816. +    msg(DBG_LCK,"cc_CloseTray (drive %d)\n", d);
  3817. +    msg(DBG_LCS,"p_door_closed bit %d before\n", st_door_closed);
  3818. +    
  3819. +    clr_cmdbuf();
  3820. +    response_count=0;
  3821. +    if (fam1_drive)
  3822.      {
  3823. -      DriveStruct[d].SubQ_ctl_adr=DriveStruct[d].SubQ_trk=DriveStruct[d].SubQ_pnt_idx=DriveStruct[d].SubQ_whatisthis=0;
  3824. -      DriveStruct[d].SubQ_run_tot=DriveStruct[d].SubQ_run_trk=0;
  3825. -      return (0);
  3826. +        drvcmd[0]=CMD1_TRAY_CTL;
  3827. +        flags_cmd_out=f_putcmd|f_respo2|f_ResponseStatus|f_obey_p_check;
  3828.      }
  3829. -    }
  3830. -  DriveStruct[d].SubQ_ctl_adr=swap_nibbles(infobuf[1]);
  3831. -  DriveStruct[d].SubQ_trk=byt2bcd(infobuf[2]);
  3832. -  DriveStruct[d].SubQ_pnt_idx=byt2bcd(infobuf[3]);
  3833. -  i=4;
  3834. -  if (fam0L_drive) i=5;
  3835. -  DriveStruct[d].SubQ_run_tot=make32(make16(0,infobuf[i]),make16(infobuf[i+1],infobuf[i+2])); /* msf-bin */
  3836. -  i=7;
  3837. -  if (fam0L_drive) i=9;
  3838. -  DriveStruct[d].SubQ_run_trk=make32(make16(0,infobuf[i]),make16(infobuf[i+1],infobuf[i+2])); /* msf-bin */
  3839. -  DriveStruct[d].SubQ_whatisthis=infobuf[i+3];
  3840. -  DriveStruct[d].diskstate_flags |= subq_bit;
  3841. -  return (0);
  3842. +    else if (fam2_drive)
  3843. +    {
  3844. +        drvcmd[0]=CMD2_TRAY_CTL;
  3845. +        drvcmd[1]=0x01;
  3846. +        drvcmd[4]=0x03; /* "insert" */
  3847. +        flags_cmd_out=f_putcmd|f_ResponseStatus;
  3848. +    }
  3849. +    else if (famL_drive)
  3850. +    {
  3851. +        drvcmd[0]=CMDL_TRAY_CTL;
  3852. +        flags_cmd_out=f_putcmd|f_respo2|f_lopsta|f_getsta|
  3853. +            f_ResponseStatus|f_obey_p_check|f_bit1;
  3854. +    }
  3855. +    else if (famT_drive)
  3856. +    {
  3857. +        drvcmd[0]=CMDT_TRAY_CTL;
  3858. +        drvcmd[4]=0x03; /* "insert" */
  3859. +    }
  3860. +    i=cmd_out();
  3861. +    msg(DBG_LCS,"p_door_closed bit %d after\n", st_door_closed);
  3862. +    return (i);
  3863.  }
  3864.  /*==========================================================================*/
  3865. -static int xx_ModeSense(void)
  3866. +static int cc_ReadSubQ(void)
  3867.  {
  3868. -  int i;
  3869. -
  3870. -  if (fam2_drive) return (0);
  3871. -  DriveStruct[d].diskstate_flags &= ~frame_size_bit;
  3872. -  clr_cmdbuf();
  3873. -  if (fam1_drive)
  3874. -    {
  3875. -      drvcmd[0]=CMD1_GETMODE;
  3876. -      flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
  3877. -      response_count=5;
  3878. -    }
  3879. -  else if (fam0L_drive)
  3880. -    {
  3881. -      drvcmd[0]=CMD0_GETMODE;
  3882. -      if (famL_drive)
  3883. -    flags_cmd_out=f_putcmd;
  3884. -      else
  3885. -    flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
  3886. -      response_count=2;
  3887. -    }
  3888. -  i=cmd_out(7);
  3889. -  if (i<0) return (i);
  3890. -  i=0;
  3891. -  if (fam1_drive) DriveStruct[d].sense_byte=infobuf[i++];
  3892. -  else if (fam0L_drive) DriveStruct[d].sense_byte=0;
  3893. -  DriveStruct[d].frame_size=make16(infobuf[i],infobuf[i+1]);
  3894. -
  3895. -  DPRINTF((DBG_XA,"SBPCD: xx_ModeSense: "));
  3896. -  for (i=0;i<(fam1_drive?5:2);i++)
  3897. -    {
  3898. -      DPRINTF((DBG_XA,"%02X ", infobuf[i]));
  3899. -    }
  3900. -  DPRINTF((DBG_XA,"\n"));
  3901. +    int i,j;
  3902.  
  3903. -  DriveStruct[d].diskstate_flags |= frame_size_bit;
  3904. -  return (0);
  3905. +    D_S[d].diskstate_flags &= ~subq_bit;
  3906. +    for (j=255;j>0;j--)
  3907. +    {
  3908. +        clr_cmdbuf();
  3909. +        if (fam1_drive)
  3910. +        {
  3911. +            drvcmd[0]=CMD1_READSUBQ;
  3912. +            flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
  3913. +            response_count=11;
  3914. +        }
  3915. +        else if (fam2_drive)
  3916. +        {
  3917. +            drvcmd[0]=CMD2_READSUBQ;
  3918. +            drvcmd[1]=0x02;
  3919. +            drvcmd[3]=0x01;
  3920. +            flags_cmd_out=f_putcmd;
  3921. +            response_count=10;
  3922. +        }
  3923. +        else if (fam0L_drive)
  3924. +        {
  3925. +            drvcmd[0]=CMD0_READSUBQ;
  3926. +            drvcmd[1]=0x02;
  3927. +            if (famL_drive)
  3928. +                flags_cmd_out=f_putcmd;
  3929. +            else
  3930. +                flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
  3931. +            response_count=13;
  3932. +        }
  3933. +        else if (famT_drive)
  3934. +        {
  3935. +            response_count=12;
  3936. +            drvcmd[0]=CMDT_READSUBQ;
  3937. +            drvcmd[1]=0x02;
  3938. +            drvcmd[2]=0x40;
  3939. +            drvcmd[3]=0x01;
  3940. +            drvcmd[8]=response_count;
  3941. +        }
  3942. +        i=cmd_out();
  3943. +        if (i<0) return (i);
  3944. +        for (i=0;i<response_count;i++)
  3945. +        {
  3946. +            sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
  3947. +            msgbuf[i*3]=0;
  3948. +            msg(DBG_SQ1,"cc_ReadSubQ:%s\n", msgbuf);
  3949. +        }
  3950. +        if (famT_drive) break;
  3951. +        if (infobuf[0]!=0) break;
  3952. +        if ((!st_spinning) || (j==1))
  3953. +        {
  3954. +            D_S[d].SubQ_ctl_adr=D_S[d].SubQ_trk=D_S[d].SubQ_pnt_idx=D_S[d].SubQ_whatisthis=0;
  3955. +            D_S[d].SubQ_run_tot=D_S[d].SubQ_run_trk=0;
  3956. +            return (0);
  3957. +        }
  3958. +    }
  3959. +    if (famT_drive) D_S[d].SubQ_ctl_adr=infobuf[1];
  3960. +    else D_S[d].SubQ_ctl_adr=swap_nibbles(infobuf[1]);
  3961. +    D_S[d].SubQ_trk=byt2bcd(infobuf[2]);
  3962. +    D_S[d].SubQ_pnt_idx=byt2bcd(infobuf[3]);
  3963. +    if (fam0L_drive) i=5;
  3964. +    else if (fam12_drive) i=4;
  3965. +    else if (famT_drive) i=8;
  3966. +    D_S[d].SubQ_run_tot=make32(make16(0,infobuf[i]),make16(infobuf[i+1],infobuf[i+2])); /* msf-bin */
  3967. +    i=7;
  3968. +    if (fam0L_drive) i=9;
  3969. +    else if (fam12_drive) i=7;
  3970. +    else if (famT_drive) i=4;
  3971. +    D_S[d].SubQ_run_trk=make32(make16(0,infobuf[i]),make16(infobuf[i+1],infobuf[i+2])); /* msf-bin */
  3972. +    D_S[d].SubQ_whatisthis=infobuf[i+3];
  3973. +    D_S[d].diskstate_flags |= subq_bit;
  3974. +    return (0);
  3975. +}
  3976. +/*==========================================================================*/
  3977. +static int cc_ModeSense(void)
  3978. +{
  3979. +    int i;
  3980. +    
  3981. +    if (fam2_drive) return (0);
  3982. +    D_S[d].diskstate_flags &= ~frame_size_bit;
  3983. +    clr_cmdbuf();
  3984. +    if (fam1_drive)
  3985. +    {
  3986. +        response_count=5;
  3987. +        drvcmd[0]=CMD1_GETMODE;
  3988. +        flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
  3989. +    }
  3990. +    else if (fam0L_drive)
  3991. +    {
  3992. +        response_count=2;
  3993. +        drvcmd[0]=CMD0_GETMODE;
  3994. +        if (famL_drive) flags_cmd_out=f_putcmd;
  3995. +        else flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
  3996. +    }
  3997. +    else if (famT_drive)
  3998. +    {
  3999. +        response_count=10;
  4000. +        drvcmd[0]=CMDT_GETMODE;
  4001. +        drvcmd[4]=response_count;
  4002. +    }
  4003. +    i=cmd_out();
  4004. +    if (i<0) return (i);
  4005. +    i=0;
  4006. +    if (fam1_drive) D_S[d].sense_byte=infobuf[i++];
  4007. +    else if (fam0L_drive) D_S[d].sense_byte=0;
  4008. +    else if (famT_drive)
  4009. +    {
  4010. +        D_S[d].sense_byte=0;
  4011. +        if (infobuf[4]==0x01) D_S[d].xa_byte=0x20;
  4012. +        i=2;
  4013. +    }
  4014. +    D_S[d].frame_size=make16(infobuf[i],infobuf[i+1]);
  4015. +    for (i=0;i<response_count;i++)
  4016. +        sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
  4017. +    msgbuf[i*3]=0;
  4018. +    msg(DBG_XA1,"cc_ModeSense:%s\n", msgbuf);
  4019. +    
  4020. +    D_S[d].diskstate_flags |= frame_size_bit;
  4021. +    return (0);
  4022.  }
  4023.  /*==========================================================================*/
  4024.  /*==========================================================================*/
  4025. -static int xx_ModeSelect(int framesize)
  4026. +static int cc_ModeSelect(int framesize)
  4027.  {
  4028. -  int i;
  4029. -
  4030. -  if (fam2_drive) return (0);
  4031. -  DriveStruct[d].diskstate_flags &= ~frame_size_bit;
  4032. -  clr_cmdbuf();
  4033. -  DriveStruct[d].frame_size=framesize;
  4034. -  if (framesize==CD_FRAMESIZE_RAW) DriveStruct[d].sense_byte=0x82;
  4035. -  else DriveStruct[d].sense_byte=0x00;
  4036. -
  4037. -  DPRINTF((DBG_XA,"SBPCD: xx_ModeSelect: %02X %04X\n",
  4038. -       DriveStruct[d].sense_byte, DriveStruct[d].frame_size));
  4039. -
  4040. -  if (fam1_drive)
  4041. -    {
  4042. -      drvcmd[0]=CMD1_SETMODE;
  4043. -      drvcmd[1]=0x00;
  4044. -      drvcmd[2]=DriveStruct[d].sense_byte;
  4045. -      drvcmd[3]=(DriveStruct[d].frame_size>>8)&0xFF;
  4046. -      drvcmd[4]=DriveStruct[d].frame_size&0xFF;
  4047. -      flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
  4048. -    }
  4049. -  else if (fam0L_drive)
  4050. -    {
  4051. -      drvcmd[0]=CMD0_SETMODE;
  4052. -      drvcmd[1]=0x00;
  4053. -      drvcmd[2]=(DriveStruct[d].frame_size>>8)&0xFF;
  4054. -      drvcmd[3]=DriveStruct[d].frame_size&0xFF;
  4055. -      drvcmd[4]=0x00;
  4056. -      if(famL_drive)
  4057. -    flags_cmd_out=f_putcmd|f_lopsta|f_getsta|f_ResponseStatus|f_obey_p_check;
  4058. -      else
  4059. -    flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
  4060. -    }
  4061. -  response_count=0;
  4062. -  i=cmd_out(7);
  4063. -  if (i<0) return (i);
  4064. -  DriveStruct[d].diskstate_flags |= frame_size_bit;
  4065. -  return (0);
  4066. +    int i;
  4067. +    
  4068. +    if (fam2_drive) return (0);
  4069. +    D_S[d].diskstate_flags &= ~frame_size_bit;
  4070. +    clr_cmdbuf();
  4071. +    D_S[d].frame_size=framesize;
  4072. +    if (framesize==CD_FRAMESIZE_RAW) D_S[d].sense_byte=0x82;
  4073. +    else D_S[d].sense_byte=0x00;
  4074. +    
  4075. +    msg(DBG_XA1,"cc_ModeSelect: %02X %04X\n",
  4076. +        D_S[d].sense_byte, D_S[d].frame_size);
  4077. +    
  4078. +    if (fam1_drive)
  4079. +    {
  4080. +        drvcmd[0]=CMD1_SETMODE;
  4081. +        drvcmd[1]=0x00;
  4082. +        drvcmd[2]=D_S[d].sense_byte;
  4083. +        drvcmd[3]=(D_S[d].frame_size>>8)&0xFF;
  4084. +        drvcmd[4]=D_S[d].frame_size&0xFF;
  4085. +        flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
  4086. +    }
  4087. +    else if (fam0L_drive)
  4088. +    {
  4089. +        drvcmd[0]=CMD0_SETMODE;
  4090. +        drvcmd[1]=0x00;
  4091. +        drvcmd[2]=(D_S[d].frame_size>>8)&0xFF;
  4092. +        drvcmd[3]=D_S[d].frame_size&0xFF;
  4093. +        drvcmd[4]=0x00;
  4094. +        if(famL_drive)
  4095. +            flags_cmd_out=f_putcmd|f_lopsta|f_getsta|f_ResponseStatus|f_obey_p_check;
  4096. +        else
  4097. +            flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
  4098. +    }
  4099. +    else if (famT_drive)
  4100. +    {
  4101. +        return (-1);
  4102. +    }
  4103. +    response_count=0;
  4104. +    i=cmd_out();
  4105. +    if (i<0) return (i);
  4106. +    D_S[d].diskstate_flags |= frame_size_bit;
  4107. +    return (0);
  4108.  }
  4109.  /*==========================================================================*/
  4110. -#if 0000
  4111. -static int xx_TellVolume(void)
  4112. +static int cc_GetVolume(void)
  4113.  {
  4114. -  int i;
  4115. -  u_char switches;
  4116. -  u_char chan0,vol0,chan1,vol1;
  4117. -
  4118. -  DriveStruct[d].diskstate_flags &= ~volume_bit;
  4119. -  clr_cmdbuf();
  4120. -  if (fam1_drive)
  4121. -    {
  4122. -      drvcmd[0]=CMD1_GETMODE;
  4123. -      drvcmd[1]=0x05;
  4124. -      response_count=5;
  4125. -      flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
  4126. -    }
  4127. -  else if (fam2_drive)
  4128. -    {
  4129. -      drvcmd[0]=CMD2_GETMODE;
  4130. -      drvcmd[1]=0x0E;
  4131. -      response_count=5;
  4132. -      flags_cmd_out=f_putcmd;
  4133. -    }
  4134. -  else if (fam0L_drive)
  4135. -    {
  4136. -      drvcmd[0]=CMD0_GETMODE;
  4137. -      drvcmd[1]=0x03;
  4138. -      response_count=2;
  4139. -      if(famL_drive)
  4140. -    flags_cmd_out=f_putcmd;
  4141. -      else
  4142. -    flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
  4143. -    }
  4144. -  i=cmd_out(7);
  4145. -  if (i<0) return (i);
  4146. -  if (fam1_drive)
  4147. -    {
  4148. -      chan0=infobuf[1]&0x0F;
  4149. -      vol0=infobuf[2];
  4150. -      chan1=infobuf[3]&0x0F;
  4151. -      vol1=infobuf[4];
  4152. -      if (chan0==0)
  4153. -    {
  4154. -      chan0=1;
  4155. -      vol0=0;
  4156. +    int i;
  4157. +    u_char switches;
  4158. +    u_char chan0=0;
  4159. +    u_char vol0=0;
  4160. +    u_char chan1=1;
  4161. +    u_char vol1=0;
  4162. +    
  4163. +    D_S[d].diskstate_flags &= ~volume_bit;
  4164. +    clr_cmdbuf();
  4165. +    if (fam1_drive)
  4166. +    {
  4167. +        drvcmd[0]=CMD1_GETMODE;
  4168. +        drvcmd[1]=0x05;
  4169. +        response_count=5;
  4170. +        flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
  4171. +    }
  4172. +    else if (fam2_drive)
  4173. +    {
  4174. +        drvcmd[0]=CMD2_GETMODE;
  4175. +        drvcmd[1]=0x0E;
  4176. +        response_count=5;
  4177. +        flags_cmd_out=f_putcmd;
  4178. +    }
  4179. +    else if (fam0L_drive)
  4180. +    {
  4181. +        drvcmd[0]=CMD0_GETMODE;
  4182. +        drvcmd[1]=0x03;
  4183. +        response_count=2;
  4184. +        if(famL_drive)
  4185. +            flags_cmd_out=f_putcmd;
  4186. +        else
  4187. +            flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
  4188. +    }
  4189. +    else if (famT_drive)
  4190. +    {
  4191. +        i=cc_get_mode_T();
  4192. +        if (i<0) return (i);
  4193. +    }
  4194. +    if (!famT_drive)
  4195. +    {
  4196. +        i=cmd_out();
  4197. +        if (i<0) return (i);
  4198. +    }
  4199. +    if (fam1_drive)
  4200. +    {
  4201. +        chan0=infobuf[1]&0x0F;
  4202. +        vol0=infobuf[2];
  4203. +        chan1=infobuf[3]&0x0F;
  4204. +        vol1=infobuf[4];
  4205. +        if (chan0==0)
  4206. +        {
  4207. +            chan0=1;
  4208. +            vol0=0;
  4209. +        }
  4210. +        if (chan1==0)
  4211. +        {
  4212. +            chan1=2;
  4213. +            vol1=0;
  4214. +        }
  4215. +        chan0 >>= 1;
  4216. +        chan1 >>= 1;
  4217.      }
  4218. -      if (chan1==0)
  4219. +    else if (fam2_drive)
  4220.      {
  4221. -      chan1=2;
  4222. -      vol1=0;
  4223. +        chan0=infobuf[1];
  4224. +        vol0=infobuf[2];
  4225. +        chan1=infobuf[3];
  4226. +        vol1=infobuf[4];
  4227. +    }
  4228. +    else if (famL_drive)
  4229. +    {
  4230. +        chan0=0;
  4231. +        chan1=1;
  4232. +        vol0=vol1=infobuf[1];
  4233. +        switches=infobuf[0];
  4234. +        if ((switches&0x80)!=0) chan0=1;
  4235. +        if ((switches&0x40)!=0) chan1=0;
  4236. +    }
  4237. +    else if (fam0_drive) /* different firmware levels */
  4238. +    {
  4239. +        chan0=0;
  4240. +        chan1=1;
  4241. +        vol0=vol1=infobuf[1];
  4242. +        if (D_S[d].drv_type>=drv_201)
  4243. +        {
  4244. +            if (D_S[d].drv_type<drv_300)
  4245. +            {
  4246. +                switches=infobuf[0];
  4247. +                if ((switches&0x80)!=0) vol0=0;
  4248. +                if ((switches&0x40)!=0) vol1=0;
  4249. +                if (D_S[d].drv_type>=drv_211)
  4250. +                {
  4251. +                    if ((switches&0x20)!=0) chan0=1;
  4252. +                    if ((switches&0x10)!=0) chan1=0;
  4253. +                }
  4254. +            }
  4255. +            else
  4256. +            {
  4257. +                vol0=infobuf[0];
  4258. +                if ((vol0&0x01)!=0) chan0=1;
  4259. +                if ((vol1&0x01)==0) chan1=0;
  4260. +                vol0 &= 0xFC;
  4261. +                vol1 &= 0xFC;
  4262. +                if (vol0!=0) vol0 += 3;
  4263. +                if (vol1!=0) vol1 += 3;
  4264. +            }
  4265. +        }
  4266.      }
  4267. -      chan0 >>= 1;
  4268. -      chan1 >>= 1;
  4269. -    }
  4270. -  else if (fam2_drive)
  4271. -    {
  4272. -      chan0=infobuf[1];
  4273. -      vol0=infobuf[2];
  4274. -      chan1=infobuf[3];
  4275. -      vol1=infobuf[4];
  4276. -    }
  4277. -  else if (famL_drive)
  4278. -    {
  4279. -      chan0=0;
  4280. -      chan1=1;
  4281. -      vol0=vol1=infobuf[1];
  4282. -      switches=infobuf[0];
  4283. -      if ((switches&0x80)!=0) chan0=1;
  4284. -      if ((switches&0x40)!=0) chan1=0;
  4285. -    }
  4286. -  else if (fam0_drive) /* different firmware levels */
  4287. -    {
  4288. -      chan0=0;
  4289. -      chan1=1;
  4290. -      vol0=vol1=infobuf[1];
  4291. -      if (DriveStruct[d].drv_type>=drv_201)
  4292. -    {
  4293. -      if (DriveStruct[d].drv_type<drv_300)
  4294. -        {
  4295. -          switches=infobuf[0];
  4296. -          if ((switches&0x80)!=0) vol0=0;
  4297. -          if ((switches&0x40)!=0) vol1=0;
  4298. -          if (DriveStruct[d].drv_type>=drv_211)
  4299. -        {
  4300. -          if ((switches&0x20)!=0) chan0=1;
  4301. -          if ((switches&0x10)!=0) chan1=0;
  4302. -        }
  4303. -            }
  4304. -          else
  4305. -        {
  4306. -              vol0=infobuf[0];
  4307. -              if ((vol0&0x01)!=0) chan0=1;
  4308. -              if ((vol1&0x01)==0) chan1=0;
  4309. -              vol0 &= 0xFC;
  4310. -              vol1 &= 0xFC;
  4311. -              if (vol0!=0) vol0 += 3;
  4312. -              if (vol1!=0) vol1 += 3;
  4313. -            }
  4314. -        }
  4315. -    }
  4316. -  DriveStruct[d].vol_chan0=chan0;
  4317. -  DriveStruct[d].vol_ctrl0=vol0;
  4318. -  DriveStruct[d].vol_chan1=chan1;
  4319. -  DriveStruct[d].vol_ctrl1=vol1;
  4320. -  DriveStruct[d].vol_chan2=2;
  4321. -  DriveStruct[d].vol_ctrl2=0xFF;
  4322. -  DriveStruct[d].vol_chan3=3;
  4323. -  DriveStruct[d].vol_ctrl3=0xFF;
  4324. -  DriveStruct[d].diskstate_flags |= volume_bit;
  4325. -  return (0);
  4326. +    else if (famT_drive)
  4327. +    {
  4328. +        D_S[d].volume_control=infobuf[7];
  4329. +        chan0=0;
  4330. +        chan1=1;
  4331. +        if (D_S[d].volume_control&0x10) vol0=0;
  4332. +        else vol0=0xff;
  4333. +        if (D_S[d].volume_control&0x20) vol1=0;
  4334. +        else vol1=0xff;
  4335. +    }
  4336. +    D_S[d].vol_chan0=chan0;
  4337. +    D_S[d].vol_ctrl0=vol0;
  4338. +    D_S[d].vol_chan1=chan1;
  4339. +    D_S[d].vol_ctrl1=vol1;
  4340. +#if 000
  4341. +    D_S[d].vol_chan2=2;
  4342. +    D_S[d].vol_ctrl2=0xFF;
  4343. +    D_S[d].vol_chan3=3;
  4344. +    D_S[d].vol_ctrl3=0xFF;
  4345. +#endif 000
  4346. +    D_S[d].diskstate_flags |= volume_bit;
  4347. +    return (0);
  4348.  }
  4349. -#endif
  4350.  /*==========================================================================*/
  4351. -static int xx_ReadCapacity(void)
  4352. +static int cc_ReadCapacity(void)
  4353.  {
  4354. -  int i;
  4355. +    int i, j;
  4356. +    
  4357. +    if (famL_drive) return (0);
  4358. +    D_S[d].diskstate_flags &= ~cd_size_bit;
  4359. +    for (j=3;j>0;j--)
  4360. +    {
  4361. +        clr_cmdbuf();
  4362. +        if (fam1_drive)
  4363. +        {
  4364. +            drvcmd[0]=CMD1_CAPACITY;
  4365. +            response_count=5;
  4366. +            flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
  4367. +        }
  4368. +        else if (fam2_drive)
  4369. +        {
  4370. +            drvcmd[0]=CMD2_CAPACITY;
  4371. +            response_count=8;
  4372. +            flags_cmd_out=f_putcmd;
  4373. +        }
  4374. +        else if (fam0_drive)
  4375. +        {
  4376. +            drvcmd[0]=CMD0_CAPACITY;
  4377. +            response_count=5;
  4378. +            flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
  4379. +        }
  4380. +        else if (famT_drive)
  4381. +        {
  4382. +            response_count=12;
  4383. +            drvcmd[0]=CMDT_DISKINFO;
  4384. +            drvcmd[1]=0x02;
  4385. +            drvcmd[6]=CDROM_LEADOUT;
  4386. +            drvcmd[8]=response_count;
  4387. +            drvcmd[9]=0x00;
  4388. +        }
  4389. +        i=cmd_out();
  4390. +        if (i>=0) break;
  4391. +        msg(DBG_000,"cc_ReadCapacity: cmd_out: err %d\n", i);
  4392. +        cc_ReadError();
  4393. +    }
  4394. +    if (j==0) return (i);
  4395. +    if (fam1_drive) D_S[d].CDsize_frm=msf2blk(make32(make16(0,infobuf[0]),make16(infobuf[1],infobuf[2])))+CD_BLOCK_OFFSET;
  4396. +    else if (fam0_drive) D_S[d].CDsize_frm=make32(make16(0,infobuf[0]),make16(infobuf[1],infobuf[2]));
  4397. +    else if (fam2_drive) D_S[d].CDsize_frm=make32(make16(infobuf[0],infobuf[1]),make16(infobuf[2],infobuf[3]));
  4398. +    else if (famT_drive)
  4399. +    {
  4400. +        D_S[d].CDsize_frm=make32(make16(infobuf[8],infobuf[9]),make16(infobuf[10],infobuf[11]));
  4401. +        D_S[d].n_first_track=infobuf[2];
  4402. +        D_S[d].n_last_track=infobuf[3];
  4403.  
  4404. -  if (famL_drive) return (0);
  4405. -  DriveStruct[d].diskstate_flags &= ~cd_size_bit;
  4406. -  clr_cmdbuf();
  4407. -  if (fam1_drive)
  4408. -    {
  4409. -      drvcmd[0]=CMD1_CAPACITY;
  4410. -      response_count=5;
  4411. -      flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
  4412. -    }
  4413. -  else if (fam2_drive)
  4414. -    {
  4415. -      drvcmd[0]=CMD2_CAPACITY;
  4416. -      response_count=8;
  4417. -      flags_cmd_out=f_putcmd;
  4418. -    }
  4419. -  else if (fam0_drive)
  4420. -    {
  4421. -      drvcmd[0]=CMD0_CAPACITY;
  4422. -      response_count=5;
  4423. -      if(famL_drive)
  4424. -    flags_cmd_out=f_putcmd;
  4425. -      else
  4426. -    flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
  4427. -    }
  4428. -  i=cmd_out(7);
  4429. -  if (i<0) return (i);
  4430. -  if (fam1_drive) DriveStruct[d].CDsize_frm=msf2blk(make32(make16(0,infobuf[0]),make16(infobuf[1],infobuf[2])))+CD_BLOCK_OFFSET;
  4431. -  else if (fam0_drive) DriveStruct[d].CDsize_frm=make32(make16(0,infobuf[0]),make16(infobuf[1],infobuf[2]));
  4432. -  else if (fam2_drive) DriveStruct[d].CDsize_frm=make32(make16(infobuf[0],infobuf[1]),make16(infobuf[2],infobuf[3]));
  4433. -  DriveStruct[d].diskstate_flags |= cd_size_bit;
  4434. -  return (0);
  4435. +    }
  4436. +    D_S[d].diskstate_flags |= cd_size_bit;
  4437. +    msg(DBG_000,"cc_ReadCapacity: %d frames.\n", D_S[d].CDsize_frm);
  4438. +    return (0);
  4439.  }
  4440.  /*==========================================================================*/
  4441. -static int xx_ReadTocDescr(void)
  4442. +static int cc_ReadTocDescr(void)
  4443.  {
  4444. -  int i;
  4445. -
  4446. -  DriveStruct[d].diskstate_flags &= ~toc_bit;
  4447. -  clr_cmdbuf();
  4448. -  if (fam1_drive)
  4449. -    {
  4450. -      drvcmd[0]=CMD1_DISKINFO;
  4451. -      response_count=6;
  4452. -      flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
  4453. -    }
  4454. -  else if (fam0L_drive)
  4455. -    {
  4456. -      drvcmd[0]=CMD0_DISKINFO;
  4457. -      response_count=6;
  4458. -      if(famL_drive)
  4459. -    flags_cmd_out=f_putcmd;
  4460. -      else
  4461. -    flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
  4462. -    }
  4463. -  else if (fam2_drive)
  4464. -    {
  4465. -      /* possibly longer timeout periods necessary */
  4466. -      DriveStruct[d].f_multisession=0;
  4467. -      drvcmd[0]=CMD2_DISKINFO;
  4468. -      drvcmd[1]=0x02;
  4469. -      drvcmd[2]=0xAB;
  4470. -      drvcmd[3]=0xFF; /* session */
  4471. -      response_count=8;
  4472. -      flags_cmd_out=f_putcmd;
  4473. -    }
  4474. -  i=cmd_out(7);
  4475. -  if (i<0) return (i);
  4476. -  DriveStruct[d].xa_byte=infobuf[0];
  4477. -  if (fam2_drive)
  4478. -    {
  4479. -      DriveStruct[d].first_session=infobuf[1];
  4480. -      DriveStruct[d].last_session=infobuf[2];
  4481. -      DriveStruct[d].n_first_track=infobuf[3];
  4482. -      DriveStruct[d].n_last_track=infobuf[4];
  4483. -      if (DriveStruct[d].first_session!=DriveStruct[d].last_session)
  4484. -    {
  4485. -      DriveStruct[d].f_multisession=1;
  4486. -      DriveStruct[d].lba_multi=msf2blk(make32(make16(0,infobuf[5]),make16(infobuf[6],infobuf[7])));
  4487. -    }
  4488. +    int i;
  4489. +    
  4490. +    D_S[d].diskstate_flags &= ~toc_bit;
  4491. +    clr_cmdbuf();
  4492. +    if (fam1_drive)
  4493. +    {
  4494. +        drvcmd[0]=CMD1_DISKINFO;
  4495. +        response_count=6;
  4496. +        flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
  4497. +    }
  4498. +    else if (fam0L_drive)
  4499. +    {
  4500. +        drvcmd[0]=CMD0_DISKINFO;
  4501. +        response_count=6;
  4502. +        if(famL_drive)
  4503. +            flags_cmd_out=f_putcmd;
  4504. +        else
  4505. +            flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
  4506. +    }
  4507. +    else if (fam2_drive)
  4508. +    {
  4509. +        /* possibly longer timeout periods necessary */
  4510. +        D_S[d].f_multisession=0;
  4511. +        drvcmd[0]=CMD2_DISKINFO;
  4512. +        drvcmd[1]=0x02;
  4513. +        drvcmd[2]=0xAB;
  4514. +        drvcmd[3]=0xFF; /* session */
  4515. +        response_count=8;
  4516. +        flags_cmd_out=f_putcmd;
  4517. +    }
  4518. +    else if (famT_drive)
  4519. +    {
  4520. +        D_S[d].f_multisession=0;
  4521. +        response_count=12;
  4522. +        drvcmd[0]=CMDT_DISKINFO;
  4523. +        drvcmd[1]=0x02;
  4524. +        drvcmd[6]=CDROM_LEADOUT;
  4525. +        drvcmd[8]=response_count;
  4526. +        drvcmd[9]=0x00;
  4527. +    }
  4528. +    i=cmd_out();
  4529. +    if (i<0) return (i);
  4530. +    if ((fam1_drive)||(fam2_drive)||(famL_drive)||(fam0_drive))
  4531. +        D_S[d].xa_byte=infobuf[0];
  4532. +    if (fam2_drive)
  4533. +    {
  4534. +        D_S[d].first_session=infobuf[1];
  4535. +        D_S[d].last_session=infobuf[2];
  4536. +        D_S[d].n_first_track=infobuf[3];
  4537. +        D_S[d].n_last_track=infobuf[4];
  4538. +        if (D_S[d].first_session!=D_S[d].last_session)
  4539. +        {
  4540. +            D_S[d].f_multisession=1;
  4541. +            D_S[d].lba_multi=msf2blk(make32(make16(0,infobuf[5]),make16(infobuf[6],infobuf[7])));
  4542. +        }
  4543.  #if 0
  4544. -      if (DriveStruct[d].first_session!=DriveStruct[d].last_session)
  4545. -    {
  4546. -      if (DriveStruct[d].last_session<=20)
  4547. -        zwanzig=DriveStruct[d].last_session+1;
  4548. -      else zwanzig=20;
  4549. -      for (count=DriveStruct[d].first_session;count<zwanzig;count++)
  4550. -        {
  4551. -          drvcmd[0]=CMD2_DISKINFO;
  4552. -          drvcmd[1]=0x02;
  4553. -          drvcmd[2]=0xAB;
  4554. -          drvcmd[3]=count;
  4555. -          response_count=8;
  4556. -          flags_cmd_out=f_putcmd;
  4557. -          i=cmd_out(7);
  4558. -          if (i<0) return (i);
  4559. -          DriveStruct[d].msf_multi_n[count]=make32(make16(0,infobuf[5]),make16(infobuf[6],infobuf[7]));
  4560. -        }
  4561. -      DriveStruct[d].diskstate_flags |= multisession_bit;
  4562. -    }
  4563. -#endif
  4564. -      drvcmd[0]=CMD2_DISKINFO;
  4565. -      drvcmd[1]=0x02;
  4566. -      drvcmd[2]=0xAA;
  4567. -      drvcmd[3]=0xFF;
  4568. -      response_count=5;
  4569. -      flags_cmd_out=f_putcmd;
  4570. -      i=cmd_out(7);
  4571. -      if (i<0) return (i);
  4572. -      DriveStruct[d].size_msf=make32(make16(0,infobuf[2]),make16(infobuf[3],infobuf[4]));
  4573. -      DriveStruct[d].size_blk=msf2blk(DriveStruct[d].size_msf);
  4574. -    }
  4575. -  else
  4576. -    {
  4577. -      DriveStruct[d].n_first_track=infobuf[1];
  4578. -      DriveStruct[d].n_last_track=infobuf[2];
  4579. -      DriveStruct[d].size_msf=make32(make16(0,infobuf[3]),make16(infobuf[4],infobuf[5]));
  4580. -      DriveStruct[d].size_blk=msf2blk(DriveStruct[d].size_msf);
  4581. -      if (famL_drive) DriveStruct[d].CDsize_frm=DriveStruct[d].size_blk+1;
  4582. -    }
  4583. -  DriveStruct[d].diskstate_flags |= toc_bit;
  4584. -  DPRINTF((DBG_TOC,"SBPCD: TocDesc: %02X %02X %02X %08X\n",
  4585. -       DriveStruct[d].xa_byte,
  4586. -       DriveStruct[d].n_first_track,
  4587. -       DriveStruct[d].n_last_track,
  4588. -       DriveStruct[d].size_msf));
  4589. -  return (0);
  4590. +        if (D_S[d].first_session!=D_S[d].last_session)
  4591. +        {
  4592. +            if (D_S[d].last_session<=20)
  4593. +                zwanzig=D_S[d].last_session+1;
  4594. +            else zwanzig=20;
  4595. +            for (count=D_S[d].first_session;count<zwanzig;count++)
  4596. +            {
  4597. +                drvcmd[0]=CMD2_DISKINFO;
  4598. +                drvcmd[1]=0x02;
  4599. +                drvcmd[2]=0xAB;
  4600. +                drvcmd[3]=count;
  4601. +                response_count=8;
  4602. +                flags_cmd_out=f_putcmd;
  4603. +                i=cmd_out();
  4604. +                if (i<0) return (i);
  4605. +                D_S[d].msf_multi_n[count]=make32(make16(0,infobuf[5]),make16(infobuf[6],infobuf[7]));
  4606. +            }
  4607. +            D_S[d].diskstate_flags |= multisession_bit;
  4608. +        }
  4609. +#endif
  4610. +        drvcmd[0]=CMD2_DISKINFO;
  4611. +        drvcmd[1]=0x02;
  4612. +        drvcmd[2]=0xAA;
  4613. +        drvcmd[3]=0xFF;
  4614. +        response_count=5;
  4615. +        flags_cmd_out=f_putcmd;
  4616. +        i=cmd_out();
  4617. +        if (i<0) return (i);
  4618. +        D_S[d].size_msf=make32(make16(0,infobuf[2]),make16(infobuf[3],infobuf[4]));
  4619. +        D_S[d].size_blk=msf2blk(D_S[d].size_msf);
  4620. +    }
  4621. +    else if (famT_drive)
  4622. +    {
  4623. +        D_S[d].size_msf=make32(make16(infobuf[8],infobuf[9]),make16(infobuf[10],infobuf[11]));
  4624. +        D_S[d].size_blk=msf2blk(D_S[d].size_msf);
  4625. +        D_S[d].n_first_track=infobuf[2];
  4626. +        D_S[d].n_last_track=infobuf[3];
  4627. +    }
  4628. +    else
  4629. +    {
  4630. +        D_S[d].n_first_track=infobuf[1];
  4631. +        D_S[d].n_last_track=infobuf[2];
  4632. +        D_S[d].size_msf=make32(make16(0,infobuf[3]),make16(infobuf[4],infobuf[5]));
  4633. +        D_S[d].size_blk=msf2blk(D_S[d].size_msf);
  4634. +        if (famL_drive) D_S[d].CDsize_frm=D_S[d].size_blk+1;
  4635. +    }
  4636. +    D_S[d].diskstate_flags |= toc_bit;
  4637. +    msg(DBG_TOC,"TocDesc: %02X %02X %02X %08X\n",
  4638. +        D_S[d].xa_byte,
  4639. +        D_S[d].n_first_track,
  4640. +        D_S[d].n_last_track,
  4641. +        D_S[d].size_msf);
  4642. +    return (0);
  4643.  }
  4644.  /*==========================================================================*/
  4645. -static int xx_ReadTocEntry(int num)
  4646. +static int cc_ReadTocEntry(int num)
  4647.  {
  4648. -  int i;
  4649. -
  4650. -  clr_cmdbuf();
  4651. -  if (fam1_drive)
  4652. -    {
  4653. -      drvcmd[0]=CMD1_READTOC;
  4654. -      response_count=8;
  4655. -      flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
  4656. -    }
  4657. -  else if (fam2_drive)
  4658. -    {
  4659. -      /* possibly longer timeout periods necessary */
  4660. -      drvcmd[0]=CMD2_DISKINFO;
  4661. -      drvcmd[1]=0x02;
  4662. -      response_count=5;
  4663. -      flags_cmd_out=f_putcmd;
  4664. -    }
  4665. -  else if (fam0L_drive)
  4666. -    {
  4667. -      drvcmd[0]=CMD0_READTOC;
  4668. -      drvcmd[1]=0x02;
  4669. -      response_count=8;
  4670. -      if(famL_drive)
  4671. -    flags_cmd_out=f_putcmd;
  4672. -      else
  4673. +    int i;
  4674. +    
  4675. +    clr_cmdbuf();
  4676. +    if (fam1_drive)
  4677. +    {
  4678. +        drvcmd[0]=CMD1_READTOC;
  4679. +        drvcmd[2]=num;
  4680. +        response_count=8;
  4681. +        flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
  4682. +    }
  4683. +    else if (fam2_drive)
  4684. +    {
  4685. +        /* possibly longer timeout periods necessary */
  4686. +        drvcmd[0]=CMD2_DISKINFO;
  4687. +        drvcmd[1]=0x02;
  4688. +        drvcmd[2]=num;
  4689. +        response_count=5;
  4690. +        flags_cmd_out=f_putcmd;
  4691. +    }
  4692. +    else if (fam0L_drive)
  4693. +    {
  4694. +        drvcmd[0]=CMD0_READTOC;
  4695. +        drvcmd[1]=0x02;
  4696. +        drvcmd[2]=num;
  4697. +        response_count=8;
  4698. +        if(famL_drive)
  4699. +            flags_cmd_out=f_putcmd;
  4700. +        else
  4701.      flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
  4702. -    }
  4703. -  drvcmd[2]=num;
  4704. -  i=cmd_out(7);
  4705. -  if (i<0) return (i);
  4706. -  if (fam2_drive) i=0;
  4707. -  else
  4708. -    {
  4709. -      DriveStruct[d].TocEnt_nixbyte=infobuf[0];
  4710. -      i=1;
  4711. -    }
  4712. -  DriveStruct[d].TocEnt_ctl_adr=swap_nibbles(infobuf[i++]);
  4713. -  if (!(fam2_drive))
  4714. -    {
  4715. -      DriveStruct[d].TocEnt_number=infobuf[i++];
  4716. -      DriveStruct[d].TocEnt_format=infobuf[i];
  4717. -    }
  4718. -  if (fam1_drive) i=4;
  4719. -  else if (fam0L_drive) i=5;
  4720. -  else if (fam2_drive) i=2;
  4721. -  DriveStruct[d].TocEnt_address=make32(make16(0,infobuf[i]),
  4722. -                       make16(infobuf[i+1],infobuf[i+2]));
  4723. -  DPRINTF((DBG_TOC,"SBPCD: TocEntry: %02X %02X %02X %02X %08X\n",
  4724. -       DriveStruct[d].TocEnt_nixbyte, DriveStruct[d].TocEnt_ctl_adr,
  4725. -       DriveStruct[d].TocEnt_number, DriveStruct[d].TocEnt_format,
  4726. -       DriveStruct[d].TocEnt_address));
  4727. -  return (0);
  4728. +    }
  4729. +    else if (famT_drive)
  4730. +    {
  4731. +        response_count=12;
  4732. +        drvcmd[0]=CMDT_DISKINFO;
  4733. +        drvcmd[1]=0x02;
  4734. +        drvcmd[6]=num;
  4735. +        drvcmd[8]=response_count;
  4736. +        drvcmd[9]=0x00;
  4737. +    }
  4738. +    i=cmd_out();
  4739. +    if (i<0) return (i);
  4740. +    if ((fam1_drive)||(famL_drive)||(fam0_drive))
  4741. +    {
  4742. +        D_S[d].TocEnt_nixbyte=infobuf[0];
  4743. +        i=1;
  4744. +    }
  4745. +    else if (fam2_drive) i=0;
  4746. +    else if (famT_drive)
  4747. +    {
  4748. +        i=5;
  4749. +    }
  4750. +    D_S[d].TocEnt_ctl_adr=swap_nibbles(infobuf[i++]);
  4751. +    if ((fam1_drive)||(famL_drive)||(fam0_drive))
  4752. +    {
  4753. +        D_S[d].TocEnt_number=infobuf[i++];
  4754. +        D_S[d].TocEnt_format=infobuf[i];
  4755. +    }
  4756. +    else D_S[d].TocEnt_number=num;
  4757. +    if (fam1_drive) i=4;
  4758. +    else if (fam0L_drive) i=5;
  4759. +    else if (fam2_drive) i=2;
  4760. +    else if (famT_drive) i=9;
  4761. +    D_S[d].TocEnt_address=make32(make16(0,infobuf[i]),
  4762. +                     make16(infobuf[i+1],infobuf[i+2]));
  4763. +    msg(DBG_TOC,"TocEntry: %02X %02X %02X %02X %08X\n",
  4764. +        D_S[d].TocEnt_nixbyte, D_S[d].TocEnt_ctl_adr,
  4765. +        D_S[d].TocEnt_number, D_S[d].TocEnt_format,
  4766. +        D_S[d].TocEnt_address);
  4767. +    return (0);
  4768.  }
  4769.  /*==========================================================================*/
  4770. -static int xx_ReadPacket(void)
  4771. +static int cc_ReadPacket(void)
  4772.  {
  4773. -  int i;
  4774. -
  4775. -  clr_cmdbuf();
  4776. -  drvcmd[0]=CMD0_PACKET;
  4777. -  drvcmd[1]=response_count;
  4778. -  if(famL_drive)
  4779. -    flags_cmd_out=f_putcmd;
  4780. -  else if (fam01_drive)
  4781. -    flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
  4782. -  else if (fam2_drive) return (-1); /* not implemented yet */
  4783. -  i=cmd_out(7);
  4784. -  return (i);
  4785. +    int i;
  4786. +    
  4787. +    clr_cmdbuf();
  4788. +    drvcmd[0]=CMD0_PACKET;
  4789. +    drvcmd[1]=response_count;
  4790. +    if(famL_drive) flags_cmd_out=f_putcmd;
  4791. +    else if (fam01_drive)
  4792. +        flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
  4793. +    else if (fam2_drive) return (-1); /* not implemented yet */
  4794. +    else if (famT_drive)
  4795. +    {
  4796. +        return (-1);
  4797. +    }
  4798. +    i=cmd_out();
  4799. +    return (i);
  4800.  }
  4801.  /*==========================================================================*/
  4802.  static int convert_UPC(u_char *p)
  4803.  {
  4804. -  int i;
  4805. -
  4806. -  p++;
  4807. -  if (fam0L_drive) p[13]=0;
  4808. -  for (i=0;i<7;i++)
  4809. -    {
  4810. -      if (fam1_drive) DriveStruct[d].UPC_buf[i]=swap_nibbles(*p++);
  4811. -      else if (fam0L_drive)
  4812. -    {
  4813. -      DriveStruct[d].UPC_buf[i]=((*p++)<<4)&0xFF;
  4814. -      DriveStruct[d].UPC_buf[i] |= *p++;
  4815. -    }
  4816. -      else /* CD200 */
  4817. +    int i;
  4818. +    
  4819. +    p++;
  4820. +    if (fam0L_drive) p[13]=0;
  4821. +    for (i=0;i<7;i++)
  4822.      {
  4823. -      return (-1);
  4824. +        if (fam1_drive) D_S[d].UPC_buf[i]=swap_nibbles(*p++);
  4825. +        else if (fam0L_drive)
  4826. +        {
  4827. +            D_S[d].UPC_buf[i]=((*p++)<<4)&0xFF;
  4828. +            D_S[d].UPC_buf[i] |= *p++;
  4829. +        }
  4830. +        else if (famT_drive)
  4831. +        {
  4832. +            return (-1);
  4833. +        }
  4834. +        else /* CD200 */
  4835. +        {
  4836. +            return (-1);
  4837. +        }
  4838.      }
  4839. -    }
  4840. -  DriveStruct[d].UPC_buf[6] &= 0xF0;
  4841. -  return (0);
  4842. +    D_S[d].UPC_buf[6] &= 0xF0;
  4843. +    return (0);
  4844.  }
  4845.  /*==========================================================================*/
  4846. -static int xx_ReadUPC(void)
  4847. +static int cc_ReadUPC(void)
  4848.  {
  4849. -  int i;
  4850. +    int i;
  4851.  #if TEST_UPC
  4852. -  int block, checksum;
  4853. +    int block, checksum;
  4854.  #endif TEST_UPC
  4855. -
  4856. -  if (fam2_drive) return (0); /* not implemented yet */
  4857. -
  4858. -  DriveStruct[d].diskstate_flags &= ~upc_bit;
  4859. +    
  4860. +    if (fam2_drive) return (0); /* not implemented yet */
  4861. +    if (famT_drive)    return (0); /* not implemented yet */
  4862. +#if 1
  4863. +    if (fam0_drive) return (0); /* but it should work */
  4864. +#endif 1
  4865. +    
  4866. +    D_S[d].diskstate_flags &= ~upc_bit;
  4867.  #if TEST_UPC
  4868. -  for (block=CD_BLOCK_OFFSET+1;block<CD_BLOCK_OFFSET+200;block++)
  4869. -    {
  4870. -#endif TEST_UPC
  4871. -      clr_cmdbuf();
  4872. -      if (fam1_drive)
  4873. +    for (block=CD_BLOCK_OFFSET+1;block<CD_BLOCK_OFFSET+200;block++)
  4874.      {
  4875. -      drvcmd[0]=CMD1_READ_UPC;
  4876. +#endif TEST_UPC
  4877. +        clr_cmdbuf();
  4878. +        if (fam1_drive)
  4879. +        {
  4880. +            drvcmd[0]=CMD1_READ_UPC;
  4881.  #if TEST_UPC
  4882. -      drvcmd[1]=(block>>16)&0xFF;
  4883. -      drvcmd[2]=(block>>8)&0xFF;
  4884. -      drvcmd[3]=block&0xFF;
  4885. +            drvcmd[1]=(block>>16)&0xFF;
  4886. +            drvcmd[2]=(block>>8)&0xFF;
  4887. +            drvcmd[3]=block&0xFF;
  4888.  #endif TEST_UPC
  4889. -      response_count=8;
  4890. -      flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
  4891. -    }
  4892. -      else if (fam0L_drive)
  4893. -    {
  4894. -      drvcmd[0]=CMD0_READ_UPC;
  4895. +            response_count=8;
  4896. +            flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
  4897. +        }
  4898. +        else if (fam0L_drive)
  4899. +        {
  4900. +            drvcmd[0]=CMD0_READ_UPC;
  4901.  #if TEST_UPC
  4902. -      drvcmd[2]=(block>>16)&0xFF;
  4903. -      drvcmd[3]=(block>>8)&0xFF;
  4904. -      drvcmd[4]=block&0xFF;
  4905. +            drvcmd[2]=(block>>16)&0xFF;
  4906. +            drvcmd[3]=(block>>8)&0xFF;
  4907. +            drvcmd[4]=block&0xFF;
  4908.  #endif TEST_UPC
  4909. -      response_count=0;
  4910. -      flags_cmd_out=f_putcmd|f_lopsta|f_getsta|f_ResponseStatus|f_obey_p_check|f_bit1;
  4911. -    }
  4912. -      else /* CD200 */
  4913. -    {
  4914. -      return (-1);
  4915. -    }
  4916. -      i=cmd_out(7);
  4917. -      if (i<0) return (i);
  4918. -      if (fam0L_drive)
  4919. -    {
  4920. -      response_count=16;
  4921. -       if (famL_drive) flags_cmd_out=f_putcmd;
  4922. -      i=xx_ReadPacket();
  4923. -      if (i<0) return (i);
  4924. -    }
  4925. +            response_count=0;
  4926. +            flags_cmd_out=f_putcmd|f_lopsta|f_getsta|f_ResponseStatus|f_obey_p_check|f_bit1;
  4927. +        }
  4928. +        else if (fam2_drive)
  4929. +        {
  4930. +            return (-1);
  4931. +        }
  4932. +        else if (famT_drive)
  4933. +        {
  4934. +            return (-1);
  4935. +        }
  4936. +        i=cmd_out();
  4937. +        if (i<0)
  4938. +        {
  4939. +            msg(DBG_000,"cc_ReadUPC cmd_out: err %d\n", i);
  4940. +            return (i);
  4941. +        }
  4942. +        if (fam0L_drive)
  4943. +        {
  4944. +            response_count=16;
  4945. +            if (famL_drive) flags_cmd_out=f_putcmd;
  4946. +            i=cc_ReadPacket();
  4947. +            if (i<0)
  4948. +            {
  4949. +                msg(DBG_000,"cc_ReadUPC ReadPacket: err %d\n", i);
  4950. +                return (i);
  4951. +            }
  4952. +        }
  4953.  #if TEST_UPC
  4954. -      checksum=0;
  4955. +        checksum=0;
  4956.  #endif TEST_UPC
  4957. -      DPRINTF((DBG_UPC,"SBPCD: UPC info: "));
  4958. -      for (i=0;i<(fam1_drive?8:16);i++)
  4959. -    {
  4960. +        for (i=0;i<(fam1_drive?8:16);i++)
  4961. +        {
  4962.  #if TEST_UPC
  4963. -      checksum |= infobuf[i];
  4964. +            checksum |= infobuf[i];
  4965.  #endif TEST_UPC
  4966. -      DPRINTF((DBG_UPC,"%02X ", infobuf[i]));
  4967. -    }
  4968. -      DPRINTF((DBG_UPC,"\n"));
  4969. +            sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
  4970. +        }
  4971. +        msgbuf[i*3]=0;
  4972. +        msg(DBG_UPC,"UPC info:%s\n", msgbuf);
  4973.  #if TEST_UPC
  4974. -      if ((checksum&0x7F)!=0) break;
  4975. -    }
  4976. +        if ((checksum&0x7F)!=0) break;
  4977. +    }
  4978.  #endif TEST_UPC
  4979. -  DriveStruct[d].UPC_ctl_adr=0;
  4980. -  if (fam1_drive) i=0;
  4981. -  else i=2;
  4982. -  if ((infobuf[i]&0x80)!=0)
  4983. -    {
  4984. -      convert_UPC(&infobuf[i]);
  4985. -      DriveStruct[d].UPC_ctl_adr = (DriveStruct[d].TocEnt_ctl_adr & 0xF0) | 0x02;
  4986. -    }
  4987. -
  4988. -  DPRINTF((DBG_UPC,"SBPCD: UPC code: "));
  4989. -  DPRINTF((DBG_UPC,"(%02X) ", DriveStruct[d].UPC_ctl_adr));
  4990. -  for (i=0;i<7;i++)
  4991. -    {
  4992. -      DPRINTF((DBG_UPC,"%02X ", DriveStruct[d].UPC_buf[i]));
  4993. -    }
  4994. -  DPRINTF((DBG_UPC,"\n"));
  4995. -
  4996. -  DriveStruct[d].diskstate_flags |= upc_bit;
  4997. -  return (0);
  4998. +    D_S[d].UPC_ctl_adr=0;
  4999. +    if (fam1_drive) i=0;
  5000. +    else i=2;
  5001. +    if ((infobuf[i]&0x80)!=0)
  5002. +    {
  5003. +        convert_UPC(&infobuf[i]);
  5004. +        D_S[d].UPC_ctl_adr = (D_S[d].TocEnt_ctl_adr & 0xF0) | 0x02;
  5005. +    }
  5006. +    for (i=0;i<7;i++)
  5007. +        sprintf(&msgbuf[i*3], " %02X", D_S[d].UPC_buf[i]);
  5008. +    sprintf(&msgbuf[i*3], " (%02X)", D_S[d].UPC_ctl_adr);
  5009. +    msgbuf[i*3+5]=0;
  5010. +    msg(DBG_UPC,"UPC code:%s\n", msgbuf);
  5011. +    D_S[d].diskstate_flags |= upc_bit;
  5012. +    return (0);
  5013.  }
  5014.  /*==========================================================================*/
  5015. -static int yy_CheckMultiSession(void)
  5016. +static int cc_CheckMultiSession(void)
  5017.  {
  5018. -  int i;
  5019. -
  5020. -  if (fam2_drive) return (0);
  5021. -  DriveStruct[d].f_multisession=0;
  5022. -  DriveStruct[d].lba_multi=0;
  5023. -  if (fam0_drive) return (0);
  5024. -  clr_cmdbuf();
  5025. -  if (fam1_drive)
  5026. -    {
  5027. -      drvcmd[0]=CMD1_MULTISESS;
  5028. -      response_count=6;
  5029. -      flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
  5030. -      i=cmd_out(7);
  5031. -      if (i<0) return (i);
  5032. -      if ((infobuf[0]&0x80)!=0)
  5033. -    {
  5034. -      DriveStruct[d].f_multisession=1;
  5035. -      DriveStruct[d].lba_multi=msf2blk(make32(make16(0,infobuf[1]),
  5036. -                          make16(infobuf[2],infobuf[3])));
  5037. -      DPRINTF((DBG_MUL,"SBPCD: MultiSession CD detected: %02X %02X %02X %02X %02X %02X (%d)\n",
  5038. -           infobuf[0], infobuf[1], infobuf[2],
  5039. -           infobuf[3], infobuf[4], infobuf[5],
  5040. -           DriveStruct[d].lba_multi));
  5041. +    int i;
  5042. +    
  5043. +    if (fam2_drive) return (0);
  5044. +    D_S[d].f_multisession=0;
  5045. +    D_S[d].lba_multi=0;
  5046. +    if (fam0_drive) return (0);
  5047. +    clr_cmdbuf();
  5048. +    if (fam1_drive)
  5049. +    {
  5050. +        drvcmd[0]=CMD1_MULTISESS;
  5051. +        response_count=6;
  5052. +        flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
  5053. +        i=cmd_out();
  5054. +        if (i<0) return (i);
  5055. +        if ((infobuf[0]&0x80)!=0)
  5056. +        {
  5057. +            D_S[d].f_multisession=1;
  5058. +            D_S[d].lba_multi=msf2blk(make32(make16(0,infobuf[1]),
  5059. +                            make16(infobuf[2],infobuf[3])));
  5060. +        }
  5061.      }
  5062. -    }
  5063. -  else if (famL_drive)
  5064. -    {
  5065. -      drvcmd[0]=CMDL_MULTISESS;
  5066. -      drvcmd[1]=3;
  5067. -      drvcmd[2]=1;
  5068. -      response_count=8;
  5069. -      flags_cmd_out=f_putcmd;
  5070. -      i=cmd_out(7);
  5071. -      if (i<0) return (i);
  5072. -      DriveStruct[d].lba_multi=msf2blk(make32(make16(0,infobuf[5]),
  5073. -                          make16(infobuf[6],infobuf[7])));
  5074. -      DPRINTF((DBG_MUL,"SBPCD: MultiSession Info: %02X %02X %02X %02X %02X %02X %02X %02X (%d)\n",
  5075. -           infobuf[0], infobuf[1], infobuf[2], infobuf[3],
  5076. -           infobuf[4], infobuf[5], infobuf[6], infobuf[7],
  5077. -           DriveStruct[d].lba_multi));
  5078. -      if (DriveStruct[d].lba_multi>200)
  5079. +    else if (famL_drive)
  5080. +    {
  5081. +        drvcmd[0]=CMDL_MULTISESS;
  5082. +        drvcmd[1]=3;
  5083. +        drvcmd[2]=1;
  5084. +        response_count=8;
  5085. +        flags_cmd_out=f_putcmd;
  5086. +        i=cmd_out();
  5087. +        if (i<0) return (i);
  5088. +        D_S[d].lba_multi=msf2blk(make32(make16(0,infobuf[5]),
  5089. +                        make16(infobuf[6],infobuf[7])));
  5090. +    }
  5091. +    else if (famT_drive)
  5092. +    {
  5093. +        response_count=12;
  5094. +        drvcmd[0]=CMDT_DISKINFO;
  5095. +        drvcmd[1]=0x02;
  5096. +        drvcmd[6]=0;
  5097. +        drvcmd[8]=response_count;
  5098. +        drvcmd[9]=0x40;
  5099. +        i=cmd_out();
  5100. +        if (i<0) return (i);
  5101. +        D_S[d].lba_multi=msf2blk(make32(make16(0,infobuf[9]),make16(infobuf[10],infobuf[11])));
  5102. +    }
  5103. +    for (i=0;i<response_count;i++)
  5104. +        sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
  5105. +    msgbuf[i*3]=0;
  5106. +    msg(DBG_MUL,"MultiSession Info:%s (%d)\n", msgbuf, D_S[d].lba_multi);
  5107. +    if (D_S[d].lba_multi>200)
  5108.      {
  5109. -      DPRINTF((DBG_MUL,"SBPCD: MultiSession base: %06X\n", DriveStruct[d].lba_multi));
  5110. -      DriveStruct[d].f_multisession=1;
  5111. +        D_S[d].f_multisession=1;
  5112. +        msg(DBG_MUL,"MultiSession base: %06X\n", D_S[d].lba_multi);
  5113.      }
  5114. -    }
  5115. -  return (0);
  5116. +    return (0);
  5117.  }
  5118.  /*==========================================================================*/
  5119.  #if FUTURE
  5120. -static int yy_SubChanInfo(int frame, int count, u_char *buffer)
  5121. -/* "frame" is a RED BOOK (msf-bin) address */
  5122. +static int cc_SubChanInfo(int frame, int count, u_char *buffer)
  5123. +    /* "frame" is a RED BOOK (msf-bin) address */
  5124.  {
  5125. -  int i;
  5126. -
  5127. -  if (fam0L_drive) return (-ENOSYS); /* drive firmware lacks it */
  5128. +    int i;
  5129. +    
  5130. +    if (fam0L_drive) return (-ENOSYS); /* drive firmware lacks it */
  5131. +    if (famT_drive)
  5132. +    {
  5133. +        return (-1);
  5134. +    }
  5135.  #if 0
  5136. -  if (DriveStruct[d].audio_state!=audio_playing) return (-ENODATA);
  5137. +    if (D_S[d].audio_state!=audio_playing) return (-ENODATA);
  5138.  #endif
  5139. -  clr_cmdbuf();
  5140. -  drvcmd[0]=CMD1_SUBCHANINF;
  5141. -  drvcmd[1]=(frame>>16)&0xFF;
  5142. -  drvcmd[2]=(frame>>8)&0xFF;
  5143. -  drvcmd[3]=frame&0xFF;
  5144. -  drvcmd[5]=(count>>8)&0xFF;
  5145. -  drvcmd[6]=count&0xFF;
  5146. -  flags_cmd_out=f_putcmd|f_respo2|f_ResponseStatus|f_obey_p_check;
  5147. -  cmd_type=READ_SC;
  5148. -  DriveStruct[d].frame_size=CD_FRAMESIZE_SUB;
  5149. -  i=cmd_out(7); /* which buffer to use? */
  5150. -  return (i);
  5151. +    clr_cmdbuf();
  5152. +    drvcmd[0]=CMD1_SUBCHANINF;
  5153. +    drvcmd[1]=(frame>>16)&0xFF;
  5154. +    drvcmd[2]=(frame>>8)&0xFF;
  5155. +    drvcmd[3]=frame&0xFF;
  5156. +    drvcmd[5]=(count>>8)&0xFF;
  5157. +    drvcmd[6]=count&0xFF;
  5158. +    flags_cmd_out=f_putcmd|f_respo2|f_ResponseStatus|f_obey_p_check;
  5159. +    cmd_type=READ_SC;
  5160. +    D_S[d].frame_size=CD_FRAMESIZE_SUB;
  5161. +    i=cmd_out(); /* which buffer to use? */
  5162. +    return (i);
  5163.  }
  5164.  #endif FUTURE
  5165.  /*==========================================================================*/
  5166.  static void check_datarate(void)
  5167.  {
  5168. -#ifdef CDMKE
  5169. -  int i=0;
  5170. -
  5171. -  DPRINTF((DBG_IOX,"SBPCD: check_datarate entered.\n"));
  5172. -  datarate=0;
  5173. +    int i=0;
  5174. +    
  5175. +    msg(DBG_IOX,"check_datarate entered.\n");
  5176. +    datarate=0;
  5177.  #if TEST_STI
  5178. -  for (i=0;i<=1000;i++) printk(".");
  5179. +    for (i=0;i<=1000;i++) printk(".");
  5180.  #endif
  5181. -  /* set a timer to make (timed_out!=0) after 1.1 seconds */
  5182. -#if 0
  5183. -  del_timer(&delay_timer);
  5184. +    /* set a timer to make (timed_out_delay!=0) after 1.1 seconds */
  5185. +#if 1
  5186. +    del_timer(&delay_timer);
  5187.  #endif
  5188. -  delay_timer.expires = 110;
  5189. -  timed_out=0;
  5190. -  add_timer(&delay_timer);
  5191. -  DPRINTF((DBG_TIM,"SBPCD: timer started (110).\n"));
  5192. -  do
  5193. -    {
  5194. -      i=inb(CDi_status);
  5195. -      datarate++;
  5196. -#if 00000
  5197. -      if (datarate>0x0FFFFFFF) break;
  5198. +    delay_timer.expires=110;
  5199. +    timed_out_delay=0;
  5200. +    add_timer(&delay_timer);
  5201. +    msg(DBG_TIM,"delay timer started (110).\n");
  5202. +    do
  5203. +    {
  5204. +        i=inb(CDi_status);
  5205. +        datarate++;
  5206. +#if 1
  5207. +        if (datarate>0x6FFFFFFF) break;
  5208.  #endif 00000
  5209. -    }
  5210. -  while (!timed_out); /* originally looping for 1.1 seconds */
  5211. -#if 0
  5212. -  del_timer(&delay_timer);
  5213. -#endif 0
  5214. -  DPRINTF((DBG_TIM,"SBPCD: datarate: %d\n", datarate));
  5215. -  if (datarate<65536) datarate=65536;
  5216. -
  5217. -  maxtim16=datarate*16;
  5218. -  maxtim04=datarate*4;
  5219. -  maxtim02=datarate*2;
  5220. -  maxtim_8=datarate/32;
  5221. +    }
  5222. +    while (!timed_out_delay);
  5223. +    del_timer(&delay_timer);
  5224. +    msg(DBG_TIM,"datarate: %04X\n", datarate);
  5225. +    if (datarate<65536) datarate=65536;
  5226. +    maxtim16=datarate*16;
  5227. +    maxtim04=datarate*4;
  5228. +    maxtim02=datarate*2;
  5229. +    maxtim_8=datarate/32;
  5230.  #if LONG_TIMING
  5231. -  maxtim_data=datarate/100;
  5232. +    maxtim_data=datarate/100;
  5233.  #else
  5234. -  maxtim_data=datarate/300;
  5235. +    maxtim_data=datarate/300;
  5236.  #endif LONG_TIMING
  5237. -  DPRINTF((DBG_TIM,"SBPCD: maxtim_8 %d, maxtim_data %d.\n",
  5238. -       maxtim_8, maxtim_data));
  5239. -#endif CDMKE
  5240. +    msg(DBG_TIM,"maxtim_8 %d, maxtim_data %d.\n",
  5241. +        maxtim_8, maxtim_data);
  5242.  }
  5243.  /*==========================================================================*/
  5244. -#ifdef CD200
  5245. -
  5246.  #if 0
  5247. -
  5248. -static int xx_ReadVersion(int fam)
  5249. -{
  5250. -  int i;
  5251. -
  5252. -  clr_cmdbuf();
  5253. -  clear_response_buffer(13);
  5254. -  if (fam==1)
  5255. -    {
  5256. -      drvcmd[0]=CMD0_READ_VER; /* same as CMD1_ and CMDL_ */
  5257. -      response_count=13;
  5258. -      i=do_cmd(f_putcmd|f_lopsta|f_getsta|f_ResponseStatus);
  5259. -    }
  5260. -  else if (fam==2)
  5261. -    {
  5262. -      drvcmd[0]=CMD2_READ_VER;
  5263. -      response_count=12;
  5264. -      i=do_cmd(f_putcmd);
  5265. -    }
  5266. -  else return (-1);
  5267. -  return (i);
  5268. -}
  5269. -
  5270. -static int yy_ReadError(int fam)
  5271. +static int c2_ReadError(int fam)
  5272.  {
  5273. -  int i;
  5274. -
  5275. -  clr_cmdbuf();
  5276. -  response_count=9;
  5277. -  clr_respo_buf(9);
  5278. -  if (fam==1)
  5279. -    {
  5280. -      drvcmd[0]=CMD0_READ_ERR; /* same as CMD1_ and CMDL_ */
  5281. -      i=do_cmd(f_putcmd|f_lopsta|f_getsta|f_ResponseStatus);
  5282. -    }
  5283. -  else if (fam==2)
  5284. -    {
  5285. -      drvcmd[0]=CMD2_READ_ERR;
  5286. -      i=do_cmd(f_putcmd);
  5287. -    }
  5288. -  else return (-1);
  5289. -  return (i);
  5290. +    int i;
  5291. +    
  5292. +    clr_cmdbuf();
  5293. +    response_count=9;
  5294. +    clr_respo_buf(9);
  5295. +    if (fam==1)
  5296. +    {
  5297. +        drvcmd[0]=CMD0_READ_ERR; /* same as CMD1_ and CMDL_ */
  5298. +        i=do_cmd(f_putcmd|f_lopsta|f_getsta|f_ResponseStatus);
  5299. +    }
  5300. +    else if (fam==2)
  5301. +    {
  5302. +        drvcmd[0]=CMD2_READ_ERR;
  5303. +        i=do_cmd(f_putcmd);
  5304. +    }
  5305. +    else return (-1);
  5306. +    return (i);
  5307.  }
  5308.  #endif
  5309. -
  5310. -#endif CD200
  5311.  /*==========================================================================*/
  5312.  static void ask_mail(void)
  5313.  {
  5314. -  int i;
  5315. -
  5316. -  printk("SBPCD: please mail the following lines to emoenke@gwdg.de:\n");
  5317. -  printk("SBPCD: address %03X, type %s, drive ID %d\n", CDo_command, type, DriveStruct[d].drv_id);
  5318. -  printk("SBPCD: infobuf = \"");
  5319. -  for (i=0;i<12;i++) printk("%02X ",infobuf[i]);
  5320. -  printk("\"\nSBPCD: infobuf = \"");
  5321. -  for (i=0;i<12;i++) printk("%c",infobuf[i]);
  5322. -  printk("\"\n");
  5323. +    int i;
  5324. +    
  5325. +    msg(DBG_INF, "please mail the following lines to emoenke@gwdg.de:\n");
  5326. +    msg(DBG_INF, "%s\n", VERSION);
  5327. +    msg(DBG_INF, "address %03X, type %s, drive %s (ID %d)\n",
  5328. +        CDo_command, type, D_S[d].drive_model, D_S[d].drv_id);
  5329. +    for (i=0;i<12;i++)
  5330. +        sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
  5331. +    msgbuf[i*3]=0;
  5332. +    msg(DBG_INF,"infobuf =%s\n", msgbuf);
  5333. +    for (i=0;i<12;i++)
  5334. +        sprintf(&msgbuf[i*3], " %c ", infobuf[i]);
  5335. +    msgbuf[i*3]=0;
  5336. +    msg(DBG_INF,"infobuf =%s\n", msgbuf);
  5337.  }
  5338.  /*==========================================================================*/
  5339.  static int check_version(void)
  5340.  {
  5341. -  int i, j;
  5342. -  u_char lcs_firm[][4]={"A4F4","A E1"};
  5343. -
  5344. -  DPRINTF((DBG_INI,"SBPCD: check_version entered.\n"));
  5345. -  DriveStruct[d].drv_type=0;
  5346. -
  5347. -  /* check for CD200 */
  5348. -  clr_cmdbuf();
  5349. -  drvcmd[0]=CMD2_READ_ERR;
  5350. -  response_count=9;
  5351. -  flags_cmd_out=f_putcmd;
  5352. -  i=cmd_out(7);
  5353. -  if (i<0) DPRINTF((DBG_INI,"SBPCD: CMD2_READERR returns %d (ok anyway).\n",i));
  5354. -  /* read drive version */
  5355. -  clr_cmdbuf();
  5356. -  for (i=0;i<12;i++) infobuf[i]=0;
  5357. -  if (sbpro_type==1) OUT(CDo_sel_i_d,0);
  5358. +    int i, j, l;
  5359. +    int teac_possible=0;
  5360. +    
  5361. +    msg(DBG_INI,"check_version entered.\n");
  5362. +    msg(DBG_TE2,"check_version: id=%d, d=%d.\n", D_S[d].drv_id, d);
  5363. +    D_S[d].drv_type=0;
  5364. +
  5365. +    /* check for CR-52x, CR-56x and LCS-7260 */
  5366. +    /* clear any pending error state */
  5367. +    clr_cmdbuf();
  5368. +    drvcmd[0]=CMD0_READ_ERR; /* same as CMD1_ and CMDL_ */
  5369. +    response_count=9;
  5370. +    flags_cmd_out=f_putcmd;
  5371. +    i=cmd_out();
  5372. +    if (i<0) msg(DBG_INI,"CMD0_READERR returns %d (ok anyway).\n",i);
  5373. +    /* read drive version */
  5374. +    clr_cmdbuf();
  5375. +    for (i=0;i<12;i++) infobuf[i]=0;
  5376. +    drvcmd[0]=CMD0_READ_VER; /* same as CMD1_ and CMDL_ */
  5377. +    response_count=12; /* fam1: only 11 */
  5378. +    flags_cmd_out=f_putcmd;
  5379. +    i=cmd_out();
  5380. +    if (i<-1) msg(DBG_INI,"CMD0_READ_VER returns %d\n",i);
  5381. +    if (i==-11) teac_possible++;
  5382. +    j=0;
  5383. +    for (i=0;i<12;i++) j+=infobuf[i];
  5384. +    if (j)
  5385. +    {
  5386. +        for (i=0;i<12;i++)
  5387. +            sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
  5388. +        msgbuf[i*3]=0;
  5389. +        msg(DBG_IDX,"infobuf =%s\n", msgbuf);
  5390. +        msg(DBG_000,"infobuf =%s\n", msgbuf);
  5391. +        for (i=0;i<12;i++)
  5392. +            sprintf(&msgbuf[i*3], " %c ", infobuf[i]);
  5393. +        msgbuf[i*3]=0;
  5394. +        msg(DBG_IDX,"infobuf =%s\n", msgbuf);
  5395. +        msg(DBG_000,"infobuf =%s\n", msgbuf);
  5396. +    }
  5397. +    for (i=0;i<4;i++) if (infobuf[i]!=family1[i]) break;
  5398. +    if (i==4)
  5399. +    {
  5400. +        D_S[d].drive_model[0]='C';
  5401. +        D_S[d].drive_model[1]='R';
  5402. +        D_S[d].drive_model[2]='-';
  5403. +        D_S[d].drive_model[3]='5';
  5404. +        D_S[d].drive_model[4]=infobuf[i++];
  5405. +        D_S[d].drive_model[5]=infobuf[i++];
  5406. +        D_S[d].drive_model[6]=0;
  5407. +        D_S[d].drv_type=drv_fam1;
  5408. +    }
  5409. +    if (!D_S[d].drv_type)
  5410. +    {
  5411. +        for (i=0;i<8;i++) if (infobuf[i]!=family0[i]) break;
  5412. +        if (i==8)
  5413. +        {
  5414. +            D_S[d].drive_model[0]='C';
  5415. +            D_S[d].drive_model[1]='R';
  5416. +            D_S[d].drive_model[2]='-';
  5417. +            D_S[d].drive_model[3]='5';
  5418. +            D_S[d].drive_model[4]='2';
  5419. +            D_S[d].drive_model[5]='x';
  5420. +            D_S[d].drive_model[6]=0;
  5421. +            D_S[d].drv_type=drv_fam0;
  5422. +        }
  5423. +    }
  5424. +    if (!D_S[d].drv_type)
  5425. +    {
  5426. +        for (i=0;i<8;i++) if (infobuf[i]!=familyL[i]) break;
  5427. +        if (i==8)
  5428. +        {
  5429. +            for (j=0;j<8;j++)
  5430. +                D_S[d].drive_model[j]=infobuf[j];
  5431. +            D_S[d].drive_model[8]=0;
  5432. +            D_S[d].drv_type=drv_famL;
  5433. +        }
  5434. +    }
  5435. +    if (!D_S[d].drv_type)
  5436. +    {
  5437. +        /* check for CD200 */
  5438. +        clr_cmdbuf();
  5439. +        drvcmd[0]=CMD2_READ_ERR;
  5440. +        response_count=9;
  5441. +        flags_cmd_out=f_putcmd;
  5442. +        i=cmd_out();
  5443. +        if (i<0) msg(DBG_INI,"CMD2_READERR returns %d (ok anyway).\n",i);
  5444. +        if (i<0) msg(DBG_000,"CMD2_READERR returns %d (ok anyway).\n",i);
  5445. +        /* read drive version */
  5446. +        clr_cmdbuf();
  5447. +        for (i=0;i<12;i++) infobuf[i]=0;
  5448. +        if (sbpro_type==1) OUT(CDo_sel_i_d,0);
  5449.  #if 0
  5450. -  OUT(CDo_reset,0);
  5451. -  sbp_sleep(600);
  5452. -  OUT(CDo_enable,DriveStruct[d].drv_sel);
  5453. -#endif
  5454. -  drvcmd[0]=CMD2_READ_VER;
  5455. -  response_count=12;
  5456. -  flags_cmd_out=f_putcmd;
  5457. -  i=cmd_out(7);
  5458. -  if (i<0) DPRINTF((DBG_INI,"SBPCD: CMD2_READ_VER returns %d\n",i));
  5459. -  if (i>=0) /* from CD200 */
  5460. -    {
  5461. -      for (i=0, j=0;i<12;i++) j+=infobuf[i];
  5462. -      if (j)
  5463. -    {
  5464. -      DPRINTF((DBG_ID,"SBPCD: infobuf = \""));
  5465. -      for (i=0;i<12;i++) DPRINTF((DBG_ID,"%02X ",infobuf[i]));
  5466. -      for (i=0;i<12;i++) DPRINTF((DBG_ID,"%c",infobuf[i]));
  5467. -      DPRINTF((DBG_ID,"\"\n"));
  5468. -    }
  5469. -      for (i=0;i<5;i++) if (infobuf[i]!=family2[i]) break;
  5470. -      if (i==5)
  5471. -    {
  5472. -      DriveStruct[d].drive_model[0]='C';
  5473. -      DriveStruct[d].drive_model[1]='D';
  5474. -      DriveStruct[d].drive_model[2]='2';
  5475. -      DriveStruct[d].drive_model[3]='0';
  5476. -      DriveStruct[d].drive_model[4]='0';
  5477. -      DriveStruct[d].drive_model[5]=infobuf[i++];
  5478. -      DriveStruct[d].drive_model[6]=infobuf[i++];
  5479. -      DriveStruct[d].drive_model[7]=0;
  5480. -      DriveStruct[d].drv_type=drv_fam2;
  5481. +        OUT(CDo_reset,0);
  5482. +        sbp_sleep(600);
  5483. +        OUT(CDo_enable,D_S[d].drv_sel);
  5484. +#endif 0
  5485. +        drvcmd[0]=CMD2_READ_VER;
  5486. +        response_count=12;
  5487. +        flags_cmd_out=f_putcmd;
  5488. +        i=cmd_out();
  5489. +        if (i<0) msg(DBG_INI,"CMD2_READ_VER returns %d\n",i);
  5490. +        if (i==-7) teac_possible++;
  5491. +        j=0;
  5492. +        for (i=0;i<12;i++) j+=infobuf[i];
  5493. +        if (j)
  5494. +        {
  5495. +            for (i=0;i<12;i++)
  5496. +                sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
  5497. +            msgbuf[i*3]=0;
  5498. +            msg(DBG_IDX,"infobuf =%s\n", msgbuf);
  5499. +            for (i=0;i<12;i++)
  5500. +                sprintf(&msgbuf[i*3], " %c ", infobuf[i]);
  5501. +            msgbuf[i*3]=0;
  5502. +            msg(DBG_IDX,"infobuf =%s\n", msgbuf);
  5503. +        }
  5504. +        if (i>=0)
  5505. +        {
  5506. +            for (i=0;i<5;i++) if (infobuf[i]!=family2[i]) break;
  5507. +            if (i==5)
  5508. +            {
  5509. +                D_S[d].drive_model[0]='C';
  5510. +                D_S[d].drive_model[1]='D';
  5511. +                D_S[d].drive_model[2]='2';
  5512. +                D_S[d].drive_model[3]='0';
  5513. +                D_S[d].drive_model[4]='0';
  5514. +                D_S[d].drive_model[5]=infobuf[i++];
  5515. +                D_S[d].drive_model[6]=infobuf[i++];
  5516. +                D_S[d].drive_model[7]=0;
  5517. +                D_S[d].drv_type=drv_fam2;
  5518. +            }
  5519. +        }
  5520.      }
  5521. -    }
  5522. +    if (!D_S[d].drv_type)
  5523. +    {
  5524. +        /* check for TEAC CD-55A */
  5525. +        msg(DBG_TEA,"teac_possible: %d\n",teac_possible);
  5526. +        for (j=1;j<=((D_S[d].drv_id==0)?3:1);j++)
  5527. +        {
  5528. +            for (l=1;l<=((D_S[d].drv_id==0)?10:1);l++)
  5529. +            {
  5530. +                msg(DBG_TEA,"TEAC reset #%d-%d.\n", j, l);
  5531. +                if (sbpro_type==1) OUT(CDo_reset,0);
  5532. +                else
  5533. +                {
  5534. +                    OUT(CDo_enable,D_S[d].drv_sel);
  5535. +                    OUT(CDo_sel_i_d,0);
  5536. +                    OUT(CDo_command,CMDT_RESET);
  5537. +                    for (i=0;i<9;i++) OUT(CDo_command,0);
  5538. +                }
  5539. +                sbp_sleep(50);
  5540. +                OUT(CDo_enable,D_S[d].drv_sel);
  5541. +                OUT(CDo_sel_i_d,0);
  5542. +                i=inb(CDi_status);
  5543. +                msg(DBG_TEA,"TEAC CDi_status: %02X.\n",i);
  5544. +#if 0
  5545. +                if (i&s_not_result_ready) continue; /* drive not present or ready */
  5546. +#endif
  5547. +                i=inb(CDi_info);
  5548. +                msg(DBG_TEA,"TEAC CDi_info: %02X.\n",i);
  5549. +                if (i==0x55) break; /* drive found */
  5550. +            }
  5551. +            if (i==0x55) break; /* drive found */
  5552. +        }
  5553. +        if (i==0x55) /* drive found */
  5554. +        {
  5555. +            msg(DBG_TEA,"TEAC drive found.\n");
  5556. +            clr_cmdbuf();
  5557. +            flags_cmd_out=f_putcmd;
  5558. +            response_count=12;
  5559. +            drvcmd[0]=CMDT_READ_VER;
  5560. +            drvcmd[4]=response_count;
  5561. +            for (i=0;i<12;i++) infobuf[i]=0;
  5562. +            i=cmd_out_T();
  5563. +            if (i!=0) msg(DBG_TEA,"cmd_out_T(CMDT_READ_VER) returns %d.\n",i);
  5564. +            for (i=1;i<6;i++) if (infobuf[i]!=familyT[i-1]) break;
  5565. +            if (i==6)
  5566. +            {
  5567. +                D_S[d].drive_model[0]='C';
  5568. +                D_S[d].drive_model[1]='D';
  5569. +                D_S[d].drive_model[2]='-';
  5570. +                D_S[d].drive_model[3]='5';
  5571. +                D_S[d].drive_model[4]='5';
  5572. +                D_S[d].drive_model[5]=0;
  5573. +                D_S[d].drv_type=drv_famT;
  5574. +            }
  5575. +        }
  5576. +    }
  5577. +    if (!D_S[d].drv_type)
  5578. +    {
  5579. +        msg(DBG_TEA,"no drive found at address %03X under ID %d.\n",CDo_command,D_S[d].drv_id);
  5580. +        return (-522);
  5581. +    }
  5582. +    for (j=0;j<4;j++) D_S[d].firmware_version[j]=infobuf[i+j];
  5583. +    if (famL_drive)
  5584. +    {
  5585. +        u_char lcs_firm_e1[]="A E1";
  5586. +        u_char lcs_firm_f4[]="A4F4";
  5587. +        
  5588. +        for (j=0;j<4;j++)
  5589. +            if (D_S[d].firmware_version[j]!=lcs_firm_e1[j]) break;
  5590. +        if (j==4) D_S[d].drv_type=drv_e1;
  5591. +
  5592. +        for (j=0;j<4;j++)
  5593. +            if (D_S[d].firmware_version[j]!=lcs_firm_f4[j]) break;
  5594. +        if (j==4) D_S[d].drv_type=drv_f4;
  5595.  
  5596. -  if (!DriveStruct[d].drv_type)
  5597. -    {
  5598. -      /* check for CR-52x, CR-56x and LCS-7260 */
  5599. -      /* clear any pending error state */
  5600. -      clr_cmdbuf();
  5601. -      drvcmd[0]=CMD0_READ_ERR; /* same as CMD1_ and CMDL_ */
  5602. -      response_count=9;
  5603. -      flags_cmd_out=f_putcmd;
  5604. -      i=cmd_out(7);
  5605. -      if (i<0) DPRINTF((DBG_INI,"SBPCD: CMD0_READERR returns %d (ok anyway).\n",i));
  5606. -      /* read drive version */
  5607. -      clr_cmdbuf();
  5608. -      for (i=0;i<12;i++) infobuf[i]=0;
  5609. -      drvcmd[0]=CMD0_READ_VER; /* same as CMD1_ and CMDL_ */
  5610. -      response_count=12;
  5611. -      flags_cmd_out=f_putcmd;
  5612. -      i=cmd_out(7);
  5613. -      if (i<0) DPRINTF((DBG_INI,"SBPCD: CMD0_READ_VER returns %d\n",i));
  5614. -
  5615. -      for (i=0, j=0;i<12;i++) j+=infobuf[i];
  5616. -      if (j)
  5617. -    {
  5618. -      DPRINTF((DBG_ID,"SBPCD: infobuf = \""));
  5619. -      for (i=0;i<12;i++) DPRINTF((DBG_ID,"%02X ",infobuf[i]));
  5620. -      for (i=0;i<12;i++) DPRINTF((DBG_ID,"%c",infobuf[i]));
  5621. -      DPRINTF((DBG_ID,"\"\n"));
  5622. -    }
  5623. -
  5624. -      for (i=0;i<4;i++) if (infobuf[i]!=family1[i]) break;
  5625. -      if (i==4)
  5626. -    {
  5627. -      DriveStruct[d].drive_model[0]='C';
  5628. -      DriveStruct[d].drive_model[1]='R';
  5629. -      DriveStruct[d].drive_model[2]='-';
  5630. -      DriveStruct[d].drive_model[3]='5';
  5631. -      DriveStruct[d].drive_model[4]=infobuf[i++];
  5632. -      DriveStruct[d].drive_model[5]=infobuf[i++];
  5633. -      DriveStruct[d].drive_model[6]=0;
  5634. -      DriveStruct[d].drv_type=drv_fam1;
  5635. -    }
  5636. -      if (!DriveStruct[d].drv_type)
  5637. -    {
  5638. -      for (i=0;i<8;i++) if (infobuf[i]!=family0[i]) break;
  5639. -      if (i==8)
  5640. -        {
  5641. -          DriveStruct[d].drive_model[0]='C';
  5642. -          DriveStruct[d].drive_model[1]='R';
  5643. -          DriveStruct[d].drive_model[2]='-';
  5644. -          DriveStruct[d].drive_model[3]='5';
  5645. -          DriveStruct[d].drive_model[4]='2';
  5646. -          DriveStruct[d].drive_model[5]='x';
  5647. -          DriveStruct[d].drive_model[6]=0;
  5648. -          DriveStruct[d].drv_type=drv_fam0;
  5649. -        }
  5650. -    }
  5651. -      if (!DriveStruct[d].drv_type)
  5652. -    {
  5653. -      for (i=0;i<8;i++) if (infobuf[i]!=familyL[i]) break;
  5654. -      if (i==8)
  5655. -        {
  5656. -          for (j=0;j<8;j++)
  5657. -        DriveStruct[d].drive_model[j]=infobuf[j];
  5658. -          DriveStruct[d].drive_model[8]=0;
  5659. -          DriveStruct[d].drv_type=drv_famL;
  5660. -        }
  5661. +        if (!D_S[d].drv_type) ask_mail();
  5662.      }
  5663. -    }
  5664. -  if (!DriveStruct[d].drv_type)
  5665. -    {
  5666. -      DPRINTF((DBG_INI,"SBPCD: check_version: error.\n"));
  5667. -      return (-1);
  5668. -    }
  5669. -  for (j=0;j<4;j++) DriveStruct[d].firmware_version[j]=infobuf[i+j];
  5670. -  if (famL_drive)
  5671. -    {
  5672. -      for (i=0;i<2;i++)
  5673. -    {
  5674. -      for (j=0;j<4;j++)
  5675. -        if (DriveStruct[d].firmware_version[j]!=lcs_firm[i][j]) break;
  5676. -      if (j==4) break;
  5677. +    else if (famT_drive)
  5678. +    {
  5679. +        j=infobuf[4]; /* one-byte version??? - here: 0x15 */
  5680. +        if (j=='5')
  5681. +        {
  5682. +            D_S[d].firmware_version[0]=infobuf[7];
  5683. +            D_S[d].firmware_version[1]=infobuf[8];
  5684. +            D_S[d].firmware_version[2]=infobuf[10];
  5685. +            D_S[d].firmware_version[3]=infobuf[11];
  5686. +        }
  5687. +        else
  5688. +        {
  5689. +            if (j!=0x15) ask_mail();
  5690. +            D_S[d].firmware_version[0]='0';
  5691. +            D_S[d].firmware_version[1]='.';
  5692. +            D_S[d].firmware_version[2]='0'+(j>>4);
  5693. +            D_S[d].firmware_version[3]='0'+(j&0x0f);
  5694. +        }
  5695.      }
  5696. -      if (j!=4) ask_mail();
  5697. -      DriveStruct[d].drv_type=drv_260;
  5698. -    }
  5699. -  else
  5700. -    {
  5701. -      j = (DriveStruct[d].firmware_version[0] & 0x0F) * 100 +
  5702. -    (DriveStruct[d].firmware_version[2] & 0x0F) *10 +
  5703. -      (DriveStruct[d].firmware_version[3] & 0x0F);
  5704. -      if (fam0_drive)
  5705. -    {
  5706. -      if (j<200) DriveStruct[d].drv_type=drv_199;
  5707. -      else if (j<201) DriveStruct[d].drv_type=drv_200;
  5708. -      else if (j<210) DriveStruct[d].drv_type=drv_201;
  5709. -      else if (j<211) DriveStruct[d].drv_type=drv_210;
  5710. -      else if (j<300) DriveStruct[d].drv_type=drv_211;
  5711. -      else if (j>=300) DriveStruct[d].drv_type=drv_300;
  5712. -    }
  5713. -      else if (fam1_drive)
  5714. -    {
  5715. -      if (j<100) DriveStruct[d].drv_type=drv_099;
  5716. -      else
  5717. -        {
  5718. -          DriveStruct[d].drv_type=drv_100;
  5719. -          ask_mail();
  5720. -        }
  5721. -    }
  5722. -      else if (fam2_drive)
  5723. -    {
  5724. -      printk("\n\nSBPCD: new drive CD200 (%s)detected.\n",
  5725. -         DriveStruct[d].firmware_version);
  5726. -      printk("SBPCD: support is not fulfilled yet.\n");
  5727. -      if (j!=101) ask_mail(); /* only 1.01 known at time */
  5728. +    else /* CR-52x, CR-56x, CD200 */
  5729. +    {
  5730. +        j = (D_S[d].firmware_version[0] & 0x0F) * 100 +
  5731. +            (D_S[d].firmware_version[2] & 0x0F) *10 +
  5732. +                (D_S[d].firmware_version[3] & 0x0F);
  5733. +        if (fam0_drive)
  5734. +        {
  5735. +            if (j<200) D_S[d].drv_type=drv_199;
  5736. +            else if (j<201) D_S[d].drv_type=drv_200;
  5737. +            else if (j<210) D_S[d].drv_type=drv_201;
  5738. +            else if (j<211) D_S[d].drv_type=drv_210;
  5739. +            else if (j<300) D_S[d].drv_type=drv_211;
  5740. +            else if (j>=300) D_S[d].drv_type=drv_300;
  5741. +        }
  5742. +        else if (fam1_drive)
  5743. +        {
  5744. +            if (j<100) D_S[d].drv_type=drv_099;
  5745. +            else
  5746. +            {
  5747. +                D_S[d].drv_type=drv_100;
  5748. +                if ((j!=500)||(j!=102)) ask_mail();
  5749. +            }
  5750. +        }
  5751. +        else if (fam2_drive)
  5752. +        {
  5753. +            msg(DBG_INF,"new drive CD200 (%s)detected.\n", D_S[d].firmware_version);
  5754. +            msg(DBG_INF,"support is not fulfilled yet - audio should work.\n");
  5755. +            if ((j!=101)&&(j!=35)) ask_mail(); /* only 1.01 and 0.35 known at time */
  5756. +        }
  5757.      }
  5758. -    }
  5759. -  DPRINTF((DBG_LCS,"SBPCD: drive type %02X\n",DriveStruct[d].drv_type));
  5760. -  DPRINTF((DBG_INI,"SBPCD: check_version done.\n"));
  5761. -  return (0);
  5762. +    msg(DBG_LCS,"drive type %02X\n",D_S[d].drv_type);
  5763. +    msg(DBG_INI,"check_version done.\n");
  5764. +    return (0);
  5765.  }
  5766.  /*==========================================================================*/
  5767. -static int switch_drive(int i)
  5768. -{
  5769. -  d=i;
  5770. -  if (DriveStruct[d].drv_id!=-1)
  5771. -    {
  5772. -      OUT(CDo_enable,DriveStruct[d].drv_sel);
  5773. -      DPRINTF((DBG_DID,"SBPCD: drive %d (ID=%d) activated.\n", i, DriveStruct[d].drv_id));
  5774. -      return (0);
  5775. -    }
  5776. -  else return (-1);
  5777. +static void switch_drive(int i)
  5778. +{
  5779. +    d=i;
  5780. +    OUT(CDo_enable,D_S[d].drv_sel);
  5781. +    msg(DBG_DID,"drive %d (ID=%d) activated.\n", i, D_S[d].drv_id);
  5782. +    return;
  5783.  }
  5784.  /*==========================================================================*/
  5785. +#ifdef PATH_CHECK
  5786.  /*
  5787. - * probe for the presence of drives on the selected controller
  5788. + * probe for the presence of an interface card
  5789.   */
  5790. -static int check_drives(void)
  5791. +static int check_card(int port)
  5792.  {
  5793. -  int i, j;
  5794. -  char *printk_header="";
  5795. -
  5796. -  DPRINTF((DBG_INI,"SBPCD: check_drives entered.\n"));
  5797. -
  5798. -  ndrives=0;
  5799. -  for (j=0;j<NR_SBPCD;j++)
  5800. -    {
  5801. -      DriveStruct[ndrives].drv_id=j;
  5802. -      if (sbpro_type==1) DriveStruct[ndrives].drv_sel=(j&0x01)<<1|(j&0x02)>>1;
  5803. -      else DriveStruct[ndrives].drv_sel=j;
  5804. -      switch_drive(ndrives);
  5805. -      DPRINTF((DBG_INI,"SBPCD: check_drives: drive %d (ID=%d) activated.\n",ndrives,j));
  5806. -      i=check_version();
  5807. -      if (i<0) DPRINTF((DBG_INI,"SBPCD: check_version returns %d.\n",i));
  5808. -      else
  5809. -    {
  5810. -      DriveStruct[d].drv_options=drv_pattern[j];
  5811. -      if (fam0L_drive) DriveStruct[d].drv_options&=~(speed_auto|speed_300|speed_150);
  5812. -      printk("%sDrive %d (ID=%d): %.9s (%.4s)\n", printk_header, d,
  5813. -         DriveStruct[d].drv_id,
  5814. -         DriveStruct[d].drive_model,
  5815. -         DriveStruct[d].firmware_version);
  5816. -      printk_header="       - ";
  5817. -      ndrives++;
  5818. -    }
  5819. -
  5820. -    }
  5821. -  for (j=ndrives;j<NR_SBPCD;j++) DriveStruct[j].drv_id=-1;
  5822. -  if (ndrives==0) return (-1);
  5823. -  return (0);
  5824. +#undef N_RESPO
  5825. +#define N_RESPO 20
  5826. +    int i, j, k;
  5827. +    u_char response[N_RESPO];
  5828. +    u_char save_port0;
  5829. +    u_char save_port3;
  5830. +    
  5831. +    msg(DBG_INI,"check_card entered.\n");
  5832. +    save_port0=inb(port+0);
  5833. +    save_port3=inb(port+3);
  5834. +    
  5835. +    for (j=0;j<NR_SBPCD;j++)
  5836. +    {
  5837. +        OUT(port+3,j) ; /* enable drive #j */
  5838. +        OUT(port+0,CMD0_PATH_CHECK);
  5839. +        for (i=10;i>0;i--) OUT(port+0,0);
  5840. +        for (k=0;k<N_RESPO;k++) response[k]=0;
  5841. +        for (k=0;k<N_RESPO;k++)
  5842. +        {
  5843. +            for (i=10000;i>0;i--)
  5844. +            {
  5845. +                if (inb(port+1)&s_not_result_ready) continue;
  5846. +                response[k]=inb(port+0);
  5847. +                break;
  5848. +            }
  5849. +        }
  5850. +        for (i=0;i<N_RESPO;i++)
  5851. +            sprintf(&msgbuf[i*3], " %02X", response[i]);
  5852. +        msgbuf[i*3]=0;
  5853. +        msg(DBG_TEA,"path check 00 (%d): %s\n", j, msgbuf);
  5854. +        OUT(port+0,CMD0_PATH_CHECK);
  5855. +        for (i=10;i>0;i--) OUT(port+0,0);
  5856. +        for (k=0;k<N_RESPO;k++) response[k]=0xFF;
  5857. +        for (k=0;k<N_RESPO;k++)
  5858. +        {
  5859. +            for (i=10000;i>0;i--)
  5860. +            {
  5861. +                if (inb(port+1)&s_not_result_ready) continue;
  5862. +                response[k]=inb(port+0);
  5863. +                break;
  5864. +            }
  5865. +        }
  5866. +        for (i=0;i<N_RESPO;i++)
  5867. +            sprintf(&msgbuf[i*3], " %02X", response[i]);
  5868. +        msgbuf[i*3]=0;
  5869. +        msg(DBG_TEA,"path check 00 (%d): %s\n", j, msgbuf);
  5870. +
  5871. +        if (response[0]==0xAA)
  5872. +            if (response[1]==0x55)
  5873. +                return (0);
  5874. +    }
  5875. +    for (j=0;j<NR_SBPCD;j++)
  5876. +    {
  5877. +        OUT(port+3,j) ; /* enable drive #j */
  5878. +        OUT(port+0,CMD2_READ_VER);
  5879. +        for (i=10;i>0;i--) OUT(port+0,0);
  5880. +        for (k=0;k<N_RESPO;k++) response[k]=0;
  5881. +        for (k=0;k<N_RESPO;k++)
  5882. +        {
  5883. +            for (i=1000000;i>0;i--)
  5884. +            {
  5885. +                if (inb(port+1)&s_not_result_ready) continue;
  5886. +                response[k]=inb(port+0);
  5887. +                break;
  5888. +            }
  5889. +        }
  5890. +        for (i=0;i<N_RESPO;i++)
  5891. +            sprintf(&msgbuf[i*3], " %02X", response[i]);
  5892. +        msgbuf[i*3]=0;
  5893. +        msg(DBG_TEA,"path check 12 (%d): %s\n", j, msgbuf);
  5894. +
  5895. +        OUT(port+0,CMD2_READ_VER);
  5896. +        for (i=10;i>0;i--) OUT(port+0,0);
  5897. +        for (k=0;k<N_RESPO;k++) response[k]=0xFF;
  5898. +        for (k=0;k<N_RESPO;k++)
  5899. +        {
  5900. +            for (i=1000000;i>0;i--)
  5901. +            {
  5902. +                if (inb(port+1)&s_not_result_ready) continue;
  5903. +                response[k]=inb(port+0);
  5904. +                break;
  5905. +            }
  5906. +        }
  5907. +        for (i=0;i<N_RESPO;i++)
  5908. +            sprintf(&msgbuf[i*3], " %02X", response[i]);
  5909. +        msgbuf[i*3]=0;
  5910. +        msg(DBG_TEA,"path check 12 (%d): %s\n", j, msgbuf);
  5911. +
  5912. +        if (response[0]==0xAA)
  5913. +            if (response[1]==0x55)
  5914. +                return (0);
  5915. +    }
  5916. +    OUT(port+0,save_port0);
  5917. +    OUT(port+3,save_port3);
  5918. +    return (0); /* in any case - no real "function" at time */
  5919.  }
  5920. +#endif PATH_CHECK
  5921.  /*==========================================================================*/
  5922. -#if 000
  5923. -static void timewait(void)
  5924. +/*==========================================================================*/
  5925. +/*
  5926. + * probe for the presence of drives on the selected controller
  5927. + */
  5928. +static int check_drives(void)
  5929.  {
  5930. -  int i;
  5931. -  for (i=0; i<65500; i++);
  5932. +    int i, j;
  5933. +    
  5934. +    msg(DBG_INI,"check_drives entered.\n");
  5935. +    ndrives=0;
  5936. +    for (j=0;j<NR_SBPCD;j++)
  5937. +    {
  5938. +        D_S[ndrives].drv_id=j;
  5939. +        if (sbpro_type==1) D_S[ndrives].drv_sel=(j&0x01)<<1|(j&0x02)>>1;
  5940. +        else D_S[ndrives].drv_sel=j;
  5941. +        switch_drive(ndrives);
  5942. +        msg(DBG_INI,"check_drives: drive %d (ID=%d) activated.\n",ndrives,j);
  5943. +        msg(DBG_000,"check_drives: drive %d (ID=%d) activated.\n",ndrives,j);
  5944. +        i=check_version();
  5945. +        if (i<0) msg(DBG_INI,"check_version returns %d.\n",i);
  5946. +        else
  5947. +        {
  5948. +            D_S[d].drv_options=drv_pattern[j];
  5949. +            if (fam0L_drive) D_S[d].drv_options&=~(speed_auto|speed_300|speed_150);
  5950. +            msg(DBG_INF, "Drive %d (ID=%d): %.9s (%.4s) at 0x%03X (type %d)\n",
  5951. +                d,
  5952. +                D_S[d].drv_id,
  5953. +                D_S[d].drive_model,
  5954. +                D_S[d].firmware_version,
  5955. +                CDo_command,
  5956. +                sbpro_type);
  5957. +            ndrives++;
  5958. +        }
  5959. +    }
  5960. +    for (j=ndrives;j<NR_SBPCD;j++) D_S[j].drv_id=-1;
  5961. +    if (ndrives==0) return (-1);
  5962. +    return (0);
  5963.  }
  5964. -#endif 000
  5965.  /*==========================================================================*/
  5966.  #if FUTURE
  5967.  /*
  5968. @@ -2664,41 +3417,40 @@
  5969.   */            
  5970.  static int obey_audio_state(u_char audio_state, u_char func,u_char subfunc)
  5971.  {
  5972. -  switch (audio_state)                   /* audio status from controller  */
  5973. -    {
  5974. -    case aud_11: /* "audio play in progress" */
  5975. -    case audx11:
  5976. -      switch (func)                      /* DOS command code */
  5977. -    {
  5978. -    case cmd_07: /* input flush  */
  5979. -    case cmd_0d: /* open device  */
  5980. -    case cmd_0e: /* close device */
  5981. -    case cmd_0c: /* ioctl output */
  5982. -      return (1);
  5983. -    case cmd_03: /* ioctl input  */
  5984. -      switch (subfunc)
  5985. -        /* DOS ioctl input subfunction */
  5986. -        {
  5987. -        case cxi_00:
  5988. -        case cxi_06:
  5989. -        case cxi_09:
  5990. -          return (1);
  5991. -        default:
  5992. -          return (ERROR15);
  5993. -        }
  5994. -      return (1);
  5995. +    switch (audio_state)                   /* audio status from controller  */
  5996. +    {
  5997. +    case aud_11: /* "audio play in progress" */
  5998. +    case audx11:
  5999. +        switch (func)                      /* DOS command code */
  6000. +        {
  6001. +        case cmd_07: /* input flush  */
  6002. +        case cmd_0d: /* open device  */
  6003. +        case cmd_0e: /* close device */
  6004. +        case cmd_0c: /* ioctl output */
  6005. +            return (1);
  6006. +        case cmd_03: /* ioctl input  */
  6007. +            switch (subfunc)
  6008. +                /* DOS ioctl input subfunction */
  6009. +            {
  6010. +            case cxi_00:
  6011. +            case cxi_06:
  6012. +            case cxi_09:
  6013. +                return (1);
  6014. +            default:
  6015. +                return (ERROR15);
  6016. +            }
  6017. +            return (1);
  6018. +        default:
  6019. +            return (ERROR15);
  6020. +        }
  6021. +        return (1);
  6022. +    case aud_12:                  /* "audio play paused"      */
  6023. +    case audx12:
  6024. +        return (1);
  6025.      default:
  6026. -      return (ERROR15);
  6027. +        return (2);
  6028.      }
  6029. -      return (1);
  6030. -    case aud_12:                  /* "audio play paused"      */
  6031. -    case audx12:
  6032. -      return (1);
  6033. -    default:
  6034. -      return (2);
  6035. -    }
  6036.  }
  6037. -#endif FUTURE
  6038.  /*==========================================================================*/
  6039.  /* allowed is only
  6040.   * ioctl_o, flush_input, open_device, close_device, 
  6041. @@ -2708,320 +3460,266 @@
  6042.  static int check_allowed1(u_char func1, u_char func2)
  6043.  {
  6044.  #if 000
  6045. -  if (func1==ioctl_o) return (0);
  6046. -  if (func1==read_long) return (-1);
  6047. -  if (func1==read_long_prefetch) return (-1);
  6048. -  if (func1==seek) return (-1);
  6049. -  if (func1==audio_play) return (-1);
  6050. -  if (func1==audio_pause) return (-1);
  6051. -  if (func1==audio_resume) return (-1);
  6052. -  if (func1!=ioctl_i) return (0);
  6053. -  if (func2==tell_SubQ_run_tot) return (-1);
  6054. -  if (func2==tell_cdsize) return (-1);
  6055. -  if (func2==tell_TocDescrip) return (-1);
  6056. -  if (func2==tell_TocEntry) return (-1);
  6057. -  if (func2==tell_subQ_info) return (-1);
  6058. -  if (fam1_drive) if (func2==tell_SubChanInfo) return (-1);
  6059. -  if (func2==tell_UPC) return (-1);
  6060. +    if (func1==ioctl_o) return (0);
  6061. +    if (func1==read_long) return (-1);
  6062. +    if (func1==read_long_prefetch) return (-1);
  6063. +    if (func1==seek) return (-1);
  6064. +    if (func1==audio_play) return (-1);
  6065. +    if (func1==audio_pause) return (-1);
  6066. +    if (func1==audio_resume) return (-1);
  6067. +    if (func1!=ioctl_i) return (0);
  6068. +    if (func2==tell_SubQ_run_tot) return (-1);
  6069. +    if (func2==tell_cdsize) return (-1);
  6070. +    if (func2==tell_TocDescrip) return (-1);
  6071. +    if (func2==tell_TocEntry) return (-1);
  6072. +    if (func2==tell_subQ_info) return (-1);
  6073. +    if (fam1_drive) if (func2==tell_SubChanInfo) return (-1);
  6074. +    if (func2==tell_UPC) return (-1);
  6075.  #else
  6076. -  return (0);
  6077. +    return (0);
  6078.  #endif 000
  6079.  }
  6080.  /*==========================================================================*/
  6081.  static int check_allowed2(u_char func1, u_char func2)
  6082.  {
  6083.  #if 000
  6084. -  if (func1==read_long) return (-1);
  6085. -  if (func1==read_long_prefetch) return (-1);
  6086. -  if (func1==seek) return (-1);
  6087. -  if (func1==audio_play) return (-1);
  6088. +    if (func1==read_long) return (-1);
  6089. +    if (func1==read_long_prefetch) return (-1);
  6090. +    if (func1==seek) return (-1);
  6091. +    if (func1==audio_play) return (-1);
  6092.    if (func1!=ioctl_o) return (0);
  6093. -  if (fam1_drive)
  6094. -    {
  6095. -      if (func2==EjectDisk) return (-1);
  6096. -      if (func2==CloseTray) return (-1);
  6097. -    }
  6098. +    if (fam1_drive)
  6099. +    {
  6100. +        if (func2==EjectDisk) return (-1);
  6101. +        if (func2==CloseTray) return (-1);
  6102. +    }
  6103.  #else
  6104. -  return (0);
  6105. +    return (0);
  6106.  #endif 000
  6107.  }
  6108.  /*==========================================================================*/
  6109.  static int check_allowed3(u_char func1, u_char func2)
  6110.  {
  6111.  #if 000
  6112. -  if (func1==ioctl_i)
  6113. -    {
  6114. -      if (func2==tell_address) return (0);
  6115. -      if (func2==tell_capabiliti) return (0);
  6116. -      if (func2==tell_CD_changed) return (0);
  6117. -      if (fam0L_drive) if (func2==tell_SubChanInfo) return (0);
  6118. -      return (-1);
  6119. -    }
  6120. -  if (func1==ioctl_o)
  6121. -    {
  6122. -      if (func2==DriveReset) return (0);
  6123. -      if (fam0L_drive)
  6124. +    if (func1==ioctl_i)
  6125.      {
  6126. -      if (func2==EjectDisk) return (0);
  6127. -      if (func2==LockDoor) return (0);
  6128. -      if (func2==CloseTray) return (0);
  6129. +        if (func2==tell_address) return (0);
  6130. +        if (func2==tell_capabiliti) return (0);
  6131. +        if (func2==tell_CD_changed) return (0);
  6132. +        if (fam0L_drive) if (func2==tell_SubChanInfo) return (0);
  6133. +        return (-1);
  6134.      }
  6135. -      return (-1);
  6136. +    if (func1==ioctl_o)
  6137. +    {
  6138. +        if (func2==DriveReset) return (0);
  6139. +        if (fam0L_drive)
  6140. +        {
  6141. +            if (func2==EjectDisk) return (0);
  6142. +            if (func2==LockDoor) return (0);
  6143. +      if (func2==CloseTray) return (0);
  6144. +        }
  6145. +        return (-1);
  6146.      }
  6147. -  if (func1==flush_input) return (-1);
  6148. -  if (func1==read_long) return (-1);
  6149. -  if (func1==read_long_prefetch) return (-1);
  6150. -  if (func1==seek) return (-1);
  6151. -  if (func1==audio_play) return (-1);
  6152. -  if (func1==audio_pause) return (-1);
  6153. -  if (func1==audio_resume) return (-1);
  6154. +    if (func1==flush_input) return (-1);
  6155. +    if (func1==read_long) return (-1);
  6156. +    if (func1==read_long_prefetch) return (-1);
  6157. +    if (func1==seek) return (-1);
  6158. +    if (func1==audio_play) return (-1);
  6159. +    if (func1==audio_pause) return (-1);
  6160. +    if (func1==audio_resume) return (-1);
  6161.  #else
  6162. -  return (0);
  6163. +    return (0);
  6164.  #endif 000
  6165.  }
  6166.  /*==========================================================================*/
  6167.  static int seek_pos_audio_end(void)
  6168.  {
  6169. -  int i;
  6170. +    int i;
  6171.  
  6172. -  i=msf2blk(DriveStruct[d].pos_audio_end)-1;
  6173. -  if (i<0) return (-1);
  6174. -  i=xx_Seek(i,0);
  6175. -  return (i);
  6176. +    i=msf2blk(D_S[d].pos_audio_end)-1;
  6177. +    if (i<0) return (-1);
  6178. +    i=cc_Seek(i,0);
  6179. +    return (i);
  6180.  }
  6181. +#endif FUTURE
  6182.  /*==========================================================================*/
  6183.  static int ReadToC(void)
  6184.  {
  6185. -  int i, j;
  6186. -  DriveStruct[d].diskstate_flags &= ~toc_bit;
  6187. -  DriveStruct[d].ored_ctl_adr=0;
  6188. -  for (j=DriveStruct[d].n_first_track;j<=DriveStruct[d].n_last_track;j++)
  6189. -    {
  6190. -      i=xx_ReadTocEntry(j);
  6191. -      if (i<0) return (i);
  6192. -      DriveStruct[d].TocBuffer[j].nixbyte=DriveStruct[d].TocEnt_nixbyte;
  6193. -      DriveStruct[d].TocBuffer[j].ctl_adr=DriveStruct[d].TocEnt_ctl_adr;
  6194. -      DriveStruct[d].TocBuffer[j].number=DriveStruct[d].TocEnt_number;
  6195. -      DriveStruct[d].TocBuffer[j].format=DriveStruct[d].TocEnt_format;
  6196. -      DriveStruct[d].TocBuffer[j].address=DriveStruct[d].TocEnt_address;
  6197. -      DriveStruct[d].ored_ctl_adr |= DriveStruct[d].TocEnt_ctl_adr;
  6198. -    }
  6199. -/* fake entry for LeadOut Track */
  6200. -  DriveStruct[d].TocBuffer[j].nixbyte=0;
  6201. -  DriveStruct[d].TocBuffer[j].ctl_adr=0;
  6202. -  DriveStruct[d].TocBuffer[j].number=CDROM_LEADOUT;
  6203. -  DriveStruct[d].TocBuffer[j].format=0;
  6204. -  DriveStruct[d].TocBuffer[j].address=DriveStruct[d].size_msf;
  6205. -
  6206. -  DriveStruct[d].diskstate_flags |= toc_bit;
  6207. -  return (0);
  6208. +    int i, j;
  6209. +    D_S[d].diskstate_flags &= ~toc_bit;
  6210. +    D_S[d].ored_ctl_adr=0;
  6211. +    for (j=D_S[d].n_first_track;j<=D_S[d].n_last_track;j++)
  6212. +    {
  6213. +        i=cc_ReadTocEntry(j);
  6214. +        if (i<0)
  6215. +        {
  6216. +            msg(DBG_INF,"cc_ReadTocEntry(%d) returns %d.\n",j,i);
  6217. +            return (i);
  6218. +        }
  6219. +        D_S[d].TocBuffer[j].nixbyte=D_S[d].TocEnt_nixbyte;
  6220. +        D_S[d].TocBuffer[j].ctl_adr=D_S[d].TocEnt_ctl_adr;
  6221. +        D_S[d].TocBuffer[j].number=D_S[d].TocEnt_number;
  6222. +        D_S[d].TocBuffer[j].format=D_S[d].TocEnt_format;
  6223. +        D_S[d].TocBuffer[j].address=D_S[d].TocEnt_address;
  6224. +        D_S[d].ored_ctl_adr |= D_S[d].TocEnt_ctl_adr;
  6225. +    }
  6226. +    /* fake entry for LeadOut Track */
  6227. +    D_S[d].TocBuffer[j].nixbyte=0;
  6228. +    D_S[d].TocBuffer[j].ctl_adr=0;
  6229. +    D_S[d].TocBuffer[j].number=CDROM_LEADOUT;
  6230. +    D_S[d].TocBuffer[j].format=0;
  6231. +    D_S[d].TocBuffer[j].address=D_S[d].size_msf;
  6232. +    
  6233. +    D_S[d].diskstate_flags |= toc_bit;
  6234. +    return (0);
  6235.  }
  6236.  /*==========================================================================*/
  6237.  static int DiskInfo(void)
  6238.  {
  6239. -  int i, j;
  6240. -
  6241. -      DriveStruct[d].mode=READ_M1;
  6242. -
  6243. +    int i, j;
  6244. +    
  6245. +    D_S[d].mode=READ_M1;
  6246. +    
  6247.  #undef LOOP_COUNT
  6248. -#define LOOP_COUNT 20 /* needed for some "old" drives */
  6249. -
  6250. -  for (j=1;j<LOOP_COUNT;j++)
  6251. -    {
  6252. -      i=SetSpeed();
  6253. -      if (i<0)
  6254. -    {
  6255. -      DPRINTF((DBG_INF,"SBPCD: DiskInfo: SetSpeed returns %d\n", i));
  6256. -      continue;
  6257. -    }
  6258. -      i=xx_ModeSense();
  6259. -      if (i<0)
  6260. -    {
  6261. -      DPRINTF((DBG_INF,"SBPCD: DiskInfo: xx_ModeSense returns %d\n", i));
  6262. -      continue;
  6263. -    }
  6264. -      i=xx_ReadCapacity();
  6265. -      if (i>=0) break;
  6266. -      DPRINTF((DBG_INF,"SBPCD: DiskInfo: ReadCapacity #%d returns %d\n", j, i));
  6267. -      i=DriveReset();
  6268. -    }
  6269. -  if (j==LOOP_COUNT) return (-2); /* give up */
  6270. -
  6271. -  i=xx_ReadTocDescr();
  6272. -  if (i<0)
  6273. -    {
  6274. -      DPRINTF((DBG_INF,"SBPCD: DiskInfo: ReadTocDescr returns %d\n", i));
  6275. -      return (i);
  6276. -    }
  6277. -  i=ReadToC();
  6278. -  if (i<0)
  6279. -    {
  6280. -      DPRINTF((DBG_INF,"SBPCD: DiskInfo: ReadToC returns %d\n", i));
  6281. -      return (i);
  6282. -    }
  6283. -  i=yy_CheckMultiSession();
  6284. -  if (i<0)
  6285. -    {
  6286. -      DPRINTF((DBG_INF,"SBPCD: DiskInfo: yy_CheckMultiSession returns %d\n", i));
  6287. -      return (i);
  6288. -    }
  6289. -  i=xx_ReadTocEntry(DriveStruct[d].n_first_track);
  6290. -  if (i<0)
  6291. -    {
  6292. -      DPRINTF((DBG_INF,"SBPCD: DiskInfo: xx_ReadTocEntry(1) returns %d\n", i));
  6293. -      return (i);
  6294. -    }
  6295. -  i=xx_ReadUPC();
  6296. -  if (i<0)
  6297. -    {
  6298. -      DPRINTF((DBG_INF,"SBPCD: DiskInfo: xx_ReadUPC returns %d\n", i));
  6299. -      return (i);
  6300. -    }
  6301. -#ifdef XA_TEST2
  6302. -  if ((fam0L_drive) && (DriveStruct[d].xa_byte==0x20)) /* XA disk with old drive */
  6303. -      {
  6304. -    xx_ModeSelect(CD_FRAMESIZE_XA);
  6305. -    xx_ModeSense();
  6306. -      }
  6307. -#endif XA_TEST2
  6308. -
  6309. -  return (0);
  6310. +#define LOOP_COUNT 10 /* needed for some "old" drives */
  6311. +    
  6312. +    msg(DBG_000,"DiskInfo entered.\n");
  6313. +    for (j=1;j<LOOP_COUNT;j++)
  6314. +    {
  6315. +        i=SetSpeed();
  6316. +        if (i<0)
  6317. +        {
  6318. +            msg(DBG_INF,"DiskInfo: SetSpeed returns %d\n", i);
  6319. +            continue;
  6320. +        }
  6321. +        i=cc_ModeSense();
  6322. +        if (i<0)
  6323. +        {
  6324. +            msg(DBG_INF,"DiskInfo: cc_ModeSense returns %d\n", i);
  6325. +            continue;
  6326. +        }
  6327. +        i=cc_ReadCapacity();
  6328. +        if (i>=0) break;
  6329. +        msg(DBG_INF,"DiskInfo: ReadCapacity #%d returns %d\n", j, i);
  6330. +        i=cc_DriveReset();
  6331. +    }
  6332. +    if (j==LOOP_COUNT) return (-33); /* give up */
  6333. +    
  6334. +    i=cc_ReadTocDescr();
  6335. +    if (i<0)
  6336. +    {
  6337. +        msg(DBG_INF,"DiskInfo: ReadTocDescr returns %d\n", i);
  6338. +        return (i);
  6339. +    }
  6340. +    i=ReadToC();
  6341. +    if (i<0)
  6342. +    {
  6343. +        msg(DBG_INF,"DiskInfo: ReadToC returns %d\n", i);
  6344. +        return (i);
  6345. +    }
  6346. +    i=cc_CheckMultiSession();
  6347. +    if (i<0)
  6348. +    {
  6349. +        msg(DBG_INF,"DiskInfo: cc_CheckMultiSession returns %d\n", i);
  6350. +        return (i);
  6351. +    }
  6352. +    if (D_S[d].f_multisession) D_S[d].sbp_bufsiz=1;  /* possibly a weird PhotoCD */
  6353. +    
  6354. +    i=cc_ReadTocEntry(D_S[d].n_first_track);
  6355. +    if (i<0)
  6356. +    {
  6357. +        msg(DBG_INF,"DiskInfo: cc_ReadTocEntry(1) returns %d\n", i);
  6358. +        return (i);
  6359. +    }
  6360. +    i=cc_ReadUPC();
  6361. +    if (i<0) msg(DBG_INF,"DiskInfo: cc_ReadUPC returns %d\n", i);
  6362. +    if ((fam0L_drive) && (D_S[d].xa_byte==0x20))
  6363. +    {
  6364. +        /* XA disk with old drive */
  6365. +        cc_ModeSelect(CD_FRAMESIZE_XA);
  6366. +        cc_ModeSense();
  6367. +    }
  6368. +    if (famT_drive)    cc_prep_mode_T();
  6369. +    msg(DBG_000,"DiskInfo done.\n");
  6370. +    return (0);
  6371.  }
  6372.  /*==========================================================================*/
  6373. +#if FUTURE
  6374.  /*
  6375.   *  called always if driver gets entered
  6376.   *  returns 0 or ERROR2 or ERROR15
  6377.   */
  6378.  static int prepare(u_char func, u_char subfunc)
  6379.  {
  6380. -  int i;
  6381. -
  6382. -  if (fam0L_drive)
  6383. -    {
  6384. -      i=inb(CDi_status);
  6385. -      if (i&s_attention) GetStatus();
  6386. -    }
  6387. -  else if (fam1_drive) GetStatus();
  6388. -  else if (fam2_drive) GetStatus();
  6389. -  if (DriveStruct[d].CD_changed==0xFF)
  6390. -    {
  6391. -#if MANY_SESSION
  6392. -#else
  6393. -      DriveStruct[d].diskstate_flags=0;
  6394. -#endif MANY_SESSION
  6395. -      DriveStruct[d].audio_state=0;
  6396. -      if (!st_diskok)
  6397. -    {
  6398. -      i=check_allowed1(func,subfunc);
  6399. -      if (i<0) return (-2);
  6400. -    }
  6401. -      else 
  6402. -    {
  6403. -      i=check_allowed3(func,subfunc);
  6404. -      if (i<0)
  6405. -        {
  6406. -          DriveStruct[d].CD_changed=1;
  6407. -          return (-15);
  6408. -        }
  6409. +    int i;
  6410. +    
  6411. +    if (fam0L_drive)
  6412. +    {
  6413. +        i=inb(CDi_status);
  6414. +        if (i&s_attention) GetStatus();
  6415. +    }
  6416. +    else if (fam1_drive) GetStatus();
  6417. +    else if (fam2_drive) GetStatus();
  6418. +    else if (famT_drive) GetStatus();
  6419. +    if (D_S[d].CD_changed==0xFF)
  6420. +    {
  6421. +        D_S[d].diskstate_flags=0;
  6422. +        D_S[d].audio_state=0;
  6423. +        if (!st_diskok)
  6424. +        {
  6425. +            i=check_allowed1(func,subfunc);
  6426. +            if (i<0) return (-2);
  6427. +        }
  6428. +        else 
  6429. +        {
  6430. +            i=check_allowed3(func,subfunc);
  6431. +            if (i<0)
  6432. +            {
  6433. +                D_S[d].CD_changed=1;
  6434. +                return (-15);
  6435. +            }
  6436. +        }
  6437.      }
  6438. -    }
  6439. -  else
  6440. -    {
  6441. -      if (!st_diskok)
  6442. +    else
  6443.      {
  6444. -#if MANY_SESSION
  6445. -#else
  6446. -      DriveStruct[d].diskstate_flags=0;
  6447. -#endif MANY_SESSION
  6448. -      DriveStruct[d].audio_state=0;
  6449. -      i=check_allowed1(func,subfunc);
  6450. -      if (i<0) return (-2);
  6451. -    }
  6452. -      else
  6453. -    { 
  6454. -      if (st_busy)
  6455. -        {
  6456. -          if (DriveStruct[d].audio_state!=audio_pausing)
  6457. -        {
  6458. -          i=check_allowed2(func,subfunc);
  6459. -          if (i<0) return (-2);
  6460. -        }
  6461. -        }
  6462. -      else
  6463. -        {
  6464. -          if (DriveStruct[d].audio_state==audio_playing) seek_pos_audio_end();
  6465. -          DriveStruct[d].audio_state=0;
  6466. -        }
  6467. -      if (!frame_size_valid)
  6468. -        {
  6469. -          i=DiskInfo();
  6470. -          if (i<0)
  6471. +        if (!st_diskok)
  6472.          {
  6473. -#if MANY_SESSION
  6474. -#else
  6475. -          DriveStruct[d].diskstate_flags=0;
  6476. -#endif MANY_SESSION
  6477. -          DriveStruct[d].audio_state=0;
  6478. -          i=check_allowed1(func,subfunc);
  6479. -          if (i<0) return (-2);
  6480. +            D_S[d].diskstate_flags=0;
  6481. +            D_S[d].audio_state=0;
  6482. +            i=check_allowed1(func,subfunc);
  6483. +            if (i<0) return (-2);
  6484. +        }
  6485. +        else
  6486. +        { 
  6487. +            if (st_busy)
  6488. +            {
  6489. +                if (D_S[d].audio_state!=audio_pausing)
  6490. +                {
  6491. +                    i=check_allowed2(func,subfunc);
  6492. +                    if (i<0) return (-2);
  6493. +                }
  6494. +            }
  6495. +            else
  6496. +            {
  6497. +                if (D_S[d].audio_state==audio_playing) seek_pos_audio_end();
  6498. +                D_S[d].audio_state=0;
  6499. +            }
  6500. +            if (!frame_size_valid)
  6501. +            {
  6502. +                i=DiskInfo();
  6503. +                if (i<0)
  6504. +                {
  6505. +                    D_S[d].diskstate_flags=0;
  6506. +                    D_S[d].audio_state=0;
  6507. +                    i=check_allowed1(func,subfunc);
  6508. +                    if (i<0) return (-2);
  6509. +                }
  6510. +            }
  6511.          }
  6512. -        }
  6513. -    }
  6514. -    }
  6515. -  return (0);
  6516. -}
  6517. -/*==========================================================================*/
  6518. -static int xx_PlayAudio(int pos_audio_start,int pos_audio_end)
  6519. -{
  6520. -  int i, n;
  6521. -
  6522. -  if (DriveStruct[d].audio_state==audio_playing) return (-EINVAL);
  6523. -  clr_cmdbuf();
  6524. -  if (famL_drive)
  6525. -    {
  6526. -      drvcmd[0]=CMDL_PLAY;
  6527. -      i=msf2blk(pos_audio_start);
  6528. -      n=msf2blk(pos_audio_end)+1-i;
  6529. -      drvcmd[1]=(i>>16)&0x00FF;
  6530. -      drvcmd[2]=(i>>8)&0x00FF;
  6531. -      drvcmd[3]=i&0x00FF;
  6532. -      drvcmd[4]=(n>>16)&0x00FF;
  6533. -      drvcmd[5]=(n>>8)&0x00FF;
  6534. -      drvcmd[6]=n&0x00FF;
  6535. -      flags_cmd_out = f_putcmd | f_respo2 | f_lopsta | f_getsta |
  6536. -    f_ResponseStatus | f_obey_p_check | f_wait_if_busy;
  6537. -    }
  6538. -  else
  6539. -    {
  6540. -      if (fam1_drive)
  6541. -    {
  6542. -      drvcmd[0]=CMD1_PLAY_MSF;
  6543. -      flags_cmd_out = f_putcmd | f_respo2 | f_ResponseStatus |
  6544. -        f_obey_p_check | f_wait_if_busy;
  6545. -    }
  6546. -      else if (fam2_drive)
  6547. -    {
  6548. -      drvcmd[0]=CMD2_PLAY_MSF;
  6549. -      flags_cmd_out = f_putcmd | f_ResponseStatus;
  6550. -    }
  6551. -      else if (fam0_drive)
  6552. -    {
  6553. -      drvcmd[0]=CMD0_PLAY_MSF;
  6554. -      flags_cmd_out = f_putcmd | f_respo2 | f_lopsta | f_getsta |
  6555. -        f_ResponseStatus | f_obey_p_check | f_wait_if_busy;
  6556. -    }
  6557. -      drvcmd[1]=(pos_audio_start>>16)&0x00FF;
  6558. -      drvcmd[2]=(pos_audio_start>>8)&0x00FF;
  6559. -      drvcmd[3]=pos_audio_start&0x00FF;
  6560. -      drvcmd[4]=(pos_audio_end>>16)&0x00FF;
  6561. -      drvcmd[5]=(pos_audio_end>>8)&0x00FF;
  6562. -      drvcmd[6]=pos_audio_end&0x00FF;
  6563.      }
  6564. -  response_count=0;
  6565. -  i=cmd_out(7);
  6566. -  return (i);
  6567. +    return (0);
  6568.  }
  6569. -/*==========================================================================*/
  6570. +#endif FUTURE
  6571.  /*==========================================================================*/
  6572.  /*==========================================================================*/
  6573.  /*
  6574. @@ -3029,43 +3727,43 @@
  6575.   */
  6576.  static int sbp_status(void)
  6577.  {
  6578. -  int st;
  6579. -
  6580. -  st=ResponseStatus();
  6581. -  if (st<0)
  6582. -    {
  6583. -      DPRINTF((DBG_INF,"SBPCD: sbp_status: timeout.\n"));
  6584. -      return (0);
  6585. -    }
  6586. -
  6587. -  if (!st_spinning) DPRINTF((DBG_SPI,"SBPCD: motor got off - ignoring.\n"));
  6588. -
  6589. -  if (st_check) 
  6590. -    {
  6591. -      DPRINTF((DBG_INF,"SBPCD: st_check detected - retrying.\n"));
  6592. -      return (0);
  6593. -    }
  6594. -  if (!st_door_closed)
  6595. -    {
  6596. -      DPRINTF((DBG_INF,"SBPCD: door is open - retrying.\n"));
  6597. -      return (0);
  6598. -    }
  6599. -  if (!st_caddy_in)
  6600. -    {
  6601. -      DPRINTF((DBG_INF,"SBPCD: disk removed - retrying.\n"));
  6602. -      return (0);
  6603. -    }
  6604. -  if (!st_diskok) 
  6605. -    {
  6606. -      DPRINTF((DBG_INF,"SBPCD: !st_diskok detected - retrying.\n"));
  6607. -      return (0);
  6608. -    }
  6609. -  if (st_busy) 
  6610. -    {
  6611. -      DPRINTF((DBG_INF,"SBPCD: st_busy detected - retrying.\n"));
  6612. -      return (0);
  6613. -    }
  6614. -  return (1);
  6615. +    int st;
  6616. +    
  6617. +    st=ResponseStatus();
  6618. +    if (st<0)
  6619. +    {
  6620. +        msg(DBG_INF,"sbp_status: timeout.\n");
  6621. +        return (0);
  6622. +    }
  6623. +    
  6624. +    if (!st_spinning) msg(DBG_SPI,"motor got off - ignoring.\n");
  6625. +    
  6626. +    if (st_check) 
  6627. +    {
  6628. +        msg(DBG_INF,"st_check detected - retrying.\n");
  6629. +        return (0);
  6630. +    }
  6631. +    if (!st_door_closed)
  6632. +    {
  6633. +        msg(DBG_INF,"door is open - retrying.\n");
  6634. +        return (0);
  6635. +    }
  6636. +    if (!st_caddy_in)
  6637. +    {
  6638. +        msg(DBG_INF,"disk removed - retrying.\n");
  6639. +        return (0);
  6640. +    }
  6641. +    if (!st_diskok) 
  6642. +    {
  6643. +        msg(DBG_INF,"!st_diskok detected - retrying.\n");
  6644. +        return (0);
  6645. +    }
  6646. +    if (st_busy) 
  6647. +    {
  6648. +        msg(DBG_INF,"st_busy detected - retrying.\n");
  6649. +        return (0);
  6650. +    }
  6651. +    return (1);
  6652.  }
  6653.  /*==========================================================================*/
  6654.  
  6655. @@ -3077,507 +3775,546 @@
  6656.  static int sbpcd_ioctl(struct inode *inode, struct file *file, u_int cmd,
  6657.                 u_long arg)
  6658.  {
  6659. -  int i, st;
  6660. -
  6661. -  DPRINTF((DBG_IO2,"SBPCD: ioctl(%d, 0x%08lX, 0x%08lX)\n",
  6662. -                MINOR(inode->i_rdev), cmd, arg));
  6663. -  if (!inode) return (-EINVAL);
  6664. -  i=MINOR(inode->i_rdev);
  6665. -  if ((i<0) || (i>=NR_SBPCD) || (DriveStruct[i].drv_id==-1))
  6666. -    {
  6667. -      printk("SBPCD: ioctl: bad device: %04X\n", inode->i_rdev);
  6668. -      return (-ENXIO);             /* no such drive */
  6669. -    }
  6670. -  switch_drive(i);
  6671. -
  6672. -  st=GetStatus();
  6673. -  if (st<0) return (-EIO);
  6674. -  
  6675. -  if (!toc_valid)
  6676. -    {
  6677. -      i=DiskInfo();
  6678. -      if (i<0) return (-EIO);    /* error reading TOC */
  6679. -    }
  6680. -  
  6681. -  DPRINTF((DBG_IO2,"SBPCD: ioctl: device %d, request %04X\n",i,cmd));
  6682. -  switch (cmd)         /* Sun-compatible */
  6683. -    {
  6684. -    case DDIOCSDBG:        /* DDI Debug */
  6685. -      if (! suser()) return (-EPERM);
  6686. -      i = verify_area(VERIFY_READ, (int *) arg, sizeof(int));
  6687. -      if (i>=0) i=sbpcd_dbg_ioctl(arg,1);
  6688. -      return (i);
  6689. -
  6690. -    case CDROMPAUSE:     /* Pause the drive */
  6691. -      DPRINTF((DBG_IOC,"SBPCD: ioctl: CDROMPAUSE entered.\n"));
  6692. -      /* pause the drive unit when it is currently in PLAY mode,         */
  6693. -      /* or reset the starting and ending locations when in PAUSED mode. */
  6694. -      /* If applicable, at the next stopping point it reaches            */
  6695. -      /* the drive will discontinue playing.                             */
  6696. -      switch (DriveStruct[d].audio_state)
  6697. -    {
  6698. -    case audio_playing:
  6699. -      if (famL_drive) i=xx_ReadSubQ();
  6700. -      else i=xx_Pause_Resume(1);
  6701. -      if (i<0) return (-EIO);
  6702. -      if (famL_drive) i=xx_Pause_Resume(1);
  6703. -      else i=xx_ReadSubQ();
  6704. -      if (i<0) return (-EIO);
  6705. -      DriveStruct[d].pos_audio_start=DriveStruct[d].SubQ_run_tot;
  6706. -      DriveStruct[d].audio_state=audio_pausing;
  6707. -      return (0);
  6708. -    case audio_pausing:
  6709. -      i=xx_Seek(DriveStruct[d].pos_audio_start,1);
  6710. -      if (i<0) return (-EIO);
  6711. -      return (0);
  6712. -    default:
  6713. -      return (-EINVAL);
  6714. +    int i, st;
  6715. +    
  6716. +    msg(DBG_IO2,"ioctl(%d, 0x%08lX, 0x%08lX)\n",
  6717. +        MINOR(inode->i_rdev), cmd, arg);
  6718. +    if (!inode) return (-EINVAL);
  6719. +    i=MINOR(inode->i_rdev);
  6720. +    if ((i<0) || (i>=NR_SBPCD) || (D_S[i].drv_id==-1))
  6721. +    {
  6722. +        msg(DBG_INF, "ioctl: bad device: %04X\n", inode->i_rdev);
  6723. +        return (-ENXIO);             /* no such drive */
  6724.      }
  6725. -      
  6726. -    case CDROMRESUME: /* resume paused audio play */
  6727. -      DPRINTF((DBG_IOC,"SBPCD: ioctl: CDROMRESUME entered.\n"));
  6728. -      /* resume playing audio tracks when a previous PLAY AUDIO call has  */
  6729. -      /* been paused with a PAUSE command.                                */
  6730. -      /* It will resume playing from the location saved in SubQ_run_tot.  */
  6731. -      if (DriveStruct[d].audio_state!=audio_pausing) return -EINVAL;
  6732. -      if (famL_drive)
  6733. -    i=xx_PlayAudio(DriveStruct[d].pos_audio_start,
  6734. -               DriveStruct[d].pos_audio_end);
  6735. -      else i=xx_Pause_Resume(3);
  6736. -      if (i<0) return (-EIO);
  6737. -      DriveStruct[d].audio_state=audio_playing;
  6738. -      return (0);
  6739. -
  6740. -    case CDROMPLAYMSF:
  6741. -      DPRINTF((DBG_IOC,"SBPCD: ioctl: CDROMPLAYMSF entered.\n"));
  6742. -      if (DriveStruct[d].audio_state==audio_playing)
  6743. -    {
  6744. -      i=xx_Pause_Resume(1);
  6745. -      if (i<0) return (-EIO);
  6746. -      i=xx_ReadSubQ();
  6747. -      if (i<0) return (-EIO);
  6748. -      DriveStruct[d].pos_audio_start=DriveStruct[d].SubQ_run_tot;
  6749. -      i=xx_Seek(DriveStruct[d].pos_audio_start,1);
  6750. -    }
  6751. -      st=verify_area(VERIFY_READ, (void *) arg, sizeof(struct cdrom_msf));
  6752. -      if (st) return (st);
  6753. -      memcpy_fromfs(&msf, (void *) arg, sizeof(struct cdrom_msf));
  6754. -      /* values come as msf-bin */
  6755. -      DriveStruct[d].pos_audio_start = (msf.cdmsf_min0<<16) |
  6756. +    if (d!=i) switch_drive(i);
  6757. +    
  6758. +#if 0
  6759. +    st=GetStatus();
  6760. +    if (st<0) return (-EIO);
  6761. +    
  6762. +    if (!toc_valid)
  6763. +    {
  6764. +        i=DiskInfo();
  6765. +        if (i<0) return (-EIO);    /* error reading TOC */
  6766. +    }
  6767. +#endif
  6768. +    
  6769. +    msg(DBG_IO2,"ioctl: device %d, request %04X\n",i,cmd);
  6770. +    switch (cmd)         /* Sun-compatible */
  6771. +    {
  6772. +    case DDIOCSDBG:        /* DDI Debug */
  6773. +        if (!suser()) return (-EPERM);
  6774. +        i=sbpcd_dbg_ioctl(arg,1);
  6775. +        return (i);
  6776. +        
  6777. +    case CDROMPAUSE:     /* Pause the drive */
  6778. +        msg(DBG_IOC,"ioctl: CDROMPAUSE entered.\n");
  6779. +        /* pause the drive unit when it is currently in PLAY mode,         */
  6780. +        /* or reset the starting and ending locations when in PAUSED mode. */
  6781. +        /* If applicable, at the next stopping point it reaches            */
  6782. +        /* the drive will discontinue playing.                             */
  6783. +        switch (D_S[d].audio_state)
  6784. +        {
  6785. +        case audio_playing:
  6786. +            if (famL_drive) i=cc_ReadSubQ();
  6787. +            else i=cc_Pause_Resume(1);
  6788. +            if (i<0) return (-EIO);
  6789. +            if (famL_drive) i=cc_Pause_Resume(1);
  6790. +            else i=cc_ReadSubQ();
  6791. +            if (i<0) return (-EIO);
  6792. +            D_S[d].pos_audio_start=D_S[d].SubQ_run_tot;
  6793. +            D_S[d].audio_state=audio_pausing;
  6794. +            return (0);
  6795. +        case audio_pausing:
  6796. +            i=cc_Seek(D_S[d].pos_audio_start,1);
  6797. +            if (i<0) return (-EIO);
  6798. +            return (0);
  6799. +        default:
  6800. +            return (-EINVAL);
  6801. +        }
  6802. +        
  6803. +    case CDROMRESUME: /* resume paused audio play */
  6804. +        msg(DBG_IOC,"ioctl: CDROMRESUME entered.\n");
  6805. +        /* resume playing audio tracks when a previous PLAY AUDIO call has  */
  6806. +        /* been paused with a PAUSE command.                                */
  6807. +        /* It will resume playing from the location saved in SubQ_run_tot.  */
  6808. +        if (D_S[d].audio_state!=audio_pausing) return -EINVAL;
  6809. +        if (famL_drive)
  6810. +            i=cc_PlayAudio(D_S[d].pos_audio_start,
  6811. +                       D_S[d].pos_audio_end);
  6812. +        else i=cc_Pause_Resume(3);
  6813. +        if (i<0) return (-EIO);
  6814. +        D_S[d].audio_state=audio_playing;
  6815. +        return (0);
  6816. +        
  6817. +    case CDROMPLAYMSF:
  6818. +        msg(DBG_IOC,"ioctl: CDROMPLAYMSF entered.\n");
  6819. +        if (D_S[d].audio_state==audio_playing)
  6820. +        {
  6821. +            i=cc_Pause_Resume(1);
  6822. +            if (i<0) return (-EIO);
  6823. +            i=cc_ReadSubQ();
  6824. +            if (i<0) return (-EIO);
  6825. +            D_S[d].pos_audio_start=D_S[d].SubQ_run_tot;
  6826. +            i=cc_Seek(D_S[d].pos_audio_start,1);
  6827. +        }
  6828. +        st=verify_area(VERIFY_READ, (void *) arg, sizeof(struct cdrom_msf));
  6829. +        if (st) return (st);
  6830. +        memcpy_fromfs(&msf, (void *) arg, sizeof(struct cdrom_msf));
  6831. +        /* values come as msf-bin */
  6832. +        D_S[d].pos_audio_start = (msf.cdmsf_min0<<16) |
  6833.                          (msf.cdmsf_sec0<<8) |
  6834. -                        msf.cdmsf_frame0;
  6835. -      DriveStruct[d].pos_audio_end = (msf.cdmsf_min1<<16) |
  6836. -                      (msf.cdmsf_sec1<<8) |
  6837. -                      msf.cdmsf_frame1;
  6838. -      DPRINTF((DBG_IOX,"SBPCD: ioctl: CDROMPLAYMSF %08X %08X\n",
  6839. -                           DriveStruct[d].pos_audio_start,DriveStruct[d].pos_audio_end));
  6840. -      i=xx_PlayAudio(DriveStruct[d].pos_audio_start,DriveStruct[d].pos_audio_end);
  6841. -      DPRINTF((DBG_IOC,"SBPCD: ioctl: xx_PlayAudio returns %d\n",i));
  6842. +                msf.cdmsf_frame0;
  6843. +        D_S[d].pos_audio_end = (msf.cdmsf_min1<<16) |
  6844. +            (msf.cdmsf_sec1<<8) |
  6845. +                msf.cdmsf_frame1;
  6846. +        msg(DBG_IOX,"ioctl: CDROMPLAYMSF %08X %08X\n",
  6847. +            D_S[d].pos_audio_start,D_S[d].pos_audio_end);
  6848. +        i=cc_PlayAudio(D_S[d].pos_audio_start,D_S[d].pos_audio_end);
  6849. +        msg(DBG_IOC,"ioctl: cc_PlayAudio returns %d\n",i);
  6850.  #if 0
  6851. -      if (i<0) return (-EIO);
  6852. +        if (i<0) return (-EIO);
  6853.  #endif 0
  6854. -      DriveStruct[d].audio_state=audio_playing;
  6855. -      return (0);
  6856. -
  6857. -    case CDROMPLAYTRKIND: /* Play a track.  This currently ignores index. */
  6858. -      DPRINTF((DBG_IOC,"SBPCD: ioctl: CDROMPLAYTRKIND entered.\n"));
  6859. -      if (DriveStruct[d].audio_state==audio_playing)
  6860. -    {
  6861. -      DPRINTF((DBG_IOX,"SBPCD: CDROMPLAYTRKIND: already audio_playing.\n"));
  6862. -      return (0);
  6863. -      return (-EINVAL);
  6864. -    }
  6865. -      st=verify_area(VERIFY_READ,(void *) arg,sizeof(struct cdrom_ti));
  6866. -      if (st<0)
  6867. -    {
  6868. -      DPRINTF((DBG_IOX,"SBPCD: CDROMPLAYTRKIND: verify_area error.\n"));
  6869. -      return (st);
  6870. -    }
  6871. -      memcpy_fromfs(&ti,(void *) arg,sizeof(struct cdrom_ti));
  6872. -      DPRINTF((DBG_IOX,"SBPCD: ioctl: trk0: %d, ind0: %d, trk1:%d, ind1:%d\n",
  6873. -         ti.cdti_trk0,ti.cdti_ind0,ti.cdti_trk1,ti.cdti_ind1));
  6874. -      if (ti.cdti_trk0<DriveStruct[d].n_first_track) return (-EINVAL);
  6875. -      if (ti.cdti_trk0>DriveStruct[d].n_last_track) return (-EINVAL);
  6876. -      if (ti.cdti_trk1<ti.cdti_trk0) ti.cdti_trk1=ti.cdti_trk0;
  6877. -      if (ti.cdti_trk1>DriveStruct[d].n_last_track) ti.cdti_trk1=DriveStruct[d].n_last_track;
  6878. -      DriveStruct[d].pos_audio_start=DriveStruct[d].TocBuffer[ti.cdti_trk0].address;
  6879. -      DriveStruct[d].pos_audio_end=DriveStruct[d].TocBuffer[ti.cdti_trk1+1].address;
  6880. -      i=xx_PlayAudio(DriveStruct[d].pos_audio_start,DriveStruct[d].pos_audio_end);
  6881. +        D_S[d].audio_state=audio_playing;
  6882. +        return (0);
  6883. +        
  6884. +    case CDROMPLAYTRKIND: /* Play a track.  This currently ignores index. */
  6885. +        msg(DBG_IOC,"ioctl: CDROMPLAYTRKIND entered.\n");
  6886. +        if (D_S[d].audio_state==audio_playing)
  6887. +        {
  6888. +            msg(DBG_IOX,"CDROMPLAYTRKIND: already audio_playing.\n");
  6889. +            return (0);
  6890. +            return (-EINVAL);
  6891. +        }
  6892. +        st=verify_area(VERIFY_READ,(void *) arg,sizeof(struct cdrom_ti));
  6893. +        if (st<0)
  6894. +        {
  6895. +            msg(DBG_IOX,"CDROMPLAYTRKIND: verify_area error.\n");
  6896. +            return (st);
  6897. +        }
  6898. +        memcpy_fromfs(&ti,(void *) arg,sizeof(struct cdrom_ti));
  6899. +        msg(DBG_IOX,"ioctl: trk0: %d, ind0: %d, trk1:%d, ind1:%d\n",
  6900. +            ti.cdti_trk0,ti.cdti_ind0,ti.cdti_trk1,ti.cdti_ind1);
  6901. +        if (ti.cdti_trk0<D_S[d].n_first_track) return (-EINVAL);
  6902. +        if (ti.cdti_trk0>D_S[d].n_last_track) return (-EINVAL);
  6903. +        if (ti.cdti_trk1<ti.cdti_trk0) ti.cdti_trk1=ti.cdti_trk0;
  6904. +        if (ti.cdti_trk1>D_S[d].n_last_track) ti.cdti_trk1=D_S[d].n_last_track;
  6905. +        D_S[d].pos_audio_start=D_S[d].TocBuffer[ti.cdti_trk0].address;
  6906. +        D_S[d].pos_audio_end=D_S[d].TocBuffer[ti.cdti_trk1+1].address;
  6907. +        i=cc_PlayAudio(D_S[d].pos_audio_start,D_S[d].pos_audio_end);
  6908.  #if 0
  6909. -      if (i<0) return (-EIO);
  6910. +        if (i<0) return (-EIO);
  6911.  #endif 0
  6912. -      DriveStruct[d].audio_state=audio_playing;
  6913. -      return (0);
  6914. -        
  6915. -    case CDROMREADTOCHDR:        /* Read the table of contents header */
  6916. -      DPRINTF((DBG_IOC,"SBPCD: ioctl: CDROMREADTOCHDR entered.\n"));
  6917. -      tochdr.cdth_trk0=DriveStruct[d].n_first_track;
  6918. -      tochdr.cdth_trk1=DriveStruct[d].n_last_track;
  6919. -      st=verify_area(VERIFY_WRITE, (void *) arg, sizeof(struct cdrom_tochdr));
  6920. -      if (st) return (st);
  6921. -      memcpy_tofs((void *) arg, &tochdr, sizeof(struct cdrom_tochdr));
  6922. -      return (0);
  6923. -
  6924. -    case CDROMREADTOCENTRY:      /* Read an entry in the table of contents */
  6925. -      DPRINTF((DBG_IOC,"SBPCD: ioctl: CDROMREADTOCENTRY entered.\n"));
  6926. -      st=verify_area(VERIFY_READ, (void *) arg, sizeof(struct cdrom_tocentry));
  6927. -      if (st) return (st);
  6928. -      memcpy_fromfs(&tocentry, (void *) arg, sizeof(struct cdrom_tocentry));
  6929. -      i=tocentry.cdte_track;
  6930. -      if (i==CDROM_LEADOUT) i=DriveStruct[d].n_last_track+1;
  6931. -      else if (i<DriveStruct[d].n_first_track||i>DriveStruct[d].n_last_track) return (-EINVAL);
  6932. -      tocentry.cdte_adr=DriveStruct[d].TocBuffer[i].ctl_adr&0x0F;
  6933. -      tocentry.cdte_ctrl=(DriveStruct[d].TocBuffer[i].ctl_adr>>4)&0x0F;
  6934. -      tocentry.cdte_datamode=DriveStruct[d].TocBuffer[i].format;
  6935. -      if (tocentry.cdte_format==CDROM_MSF) /* MSF-bin required */
  6936. -    { tocentry.cdte_addr.msf.minute=(DriveStruct[d].TocBuffer[i].address>>16)&0x00FF;
  6937. -      tocentry.cdte_addr.msf.second=(DriveStruct[d].TocBuffer[i].address>>8)&0x00FF;
  6938. -      tocentry.cdte_addr.msf.frame=DriveStruct[d].TocBuffer[i].address&0x00FF;
  6939. -    }
  6940. -      else if (tocentry.cdte_format==CDROM_LBA) /* blk required */
  6941. -    tocentry.cdte_addr.lba=msf2blk(DriveStruct[d].TocBuffer[i].address);
  6942. -      else return (-EINVAL);
  6943. -      st=verify_area(VERIFY_WRITE,(void *) arg, sizeof(struct cdrom_tocentry));
  6944. -      if (st) return (st);
  6945. -      memcpy_tofs((void *) arg, &tocentry, sizeof(struct cdrom_tocentry));
  6946. -      return (0);
  6947. -
  6948. -    case CDROMSTOP:      /* Spin down the drive */
  6949. -      DPRINTF((DBG_IOC,"SBPCD: ioctl: CDROMSTOP entered.\n"));
  6950. -      i=xx_Pause_Resume(1);
  6951. -      DriveStruct[d].audio_state=0;
  6952. -      return (0);
  6953. -
  6954. -    case CDROMSTART:  /* Spin up the drive */
  6955. -      DPRINTF((DBG_IOC,"SBPCD: ioctl: CDROMSTART entered.\n"));
  6956. -      xx_SpinUp();
  6957. -      DriveStruct[d].audio_state=0;
  6958. -      return (0);
  6959. -      
  6960. -    case CDROMEJECT:
  6961. -      DPRINTF((DBG_IOC,"SBPCD: ioctl: CDROMEJECT entered.\n"));
  6962. -      if (fam0_drive) return (0);
  6963. -      do i=yy_LockDoor(0);
  6964. -      while (i!=0);
  6965. -      DriveStruct[d].open_count=0; /* to get it locked next time again */
  6966. -      i=yy_SpinDown();
  6967. -      DPRINTF((DBG_IOX,"SBPCD: ioctl: yy_SpinDown returned %d.\n", i));
  6968. -      if (i<0) return (-EIO);
  6969. -      DriveStruct[d].CD_changed=0xFF;
  6970. -      DriveStruct[d].diskstate_flags=0;
  6971. -      DriveStruct[d].audio_state=0;
  6972. -      return (0);
  6973. -      
  6974. -    case CDROMEJECT_SW:
  6975. -      DPRINTF((DBG_IOC,"SBPCD: ioctl: CDROMEJECT_SW entered.\n"));
  6976. -      if (fam0_drive) return (0);
  6977. -      DriveStruct[d].f_eject=arg;
  6978. -      return (0);
  6979. -      
  6980. -    case CDROMVOLCTRL:   /* Volume control */
  6981. -      DPRINTF((DBG_IOC,"SBPCD: ioctl: CDROMVOLCTRL entered.\n"));
  6982. -      st=verify_area(VERIFY_READ,(void *) arg,sizeof(volctrl));
  6983. -      if (st) return (st);
  6984. -      memcpy_fromfs(&volctrl,(char *) arg,sizeof(volctrl));
  6985. -      DriveStruct[d].vol_chan0=0;
  6986. -      DriveStruct[d].vol_ctrl0=volctrl.channel0;
  6987. -      DriveStruct[d].vol_chan1=1;
  6988. -      DriveStruct[d].vol_ctrl1=volctrl.channel1;
  6989. -      i=xx_SetVolume();
  6990. -      return (0);
  6991. -
  6992. -    case CDROMSUBCHNL:   /* Get subchannel info */
  6993. -      DPRINTF((DBG_IOS,"SBPCD: ioctl: CDROMSUBCHNL entered.\n"));
  6994. -      if ((st_spinning)||(!subq_valid)) { i=xx_ReadSubQ();
  6995. -                      if (i<0) return (-EIO);
  6996. -                    }
  6997. -      st=verify_area(VERIFY_WRITE, (void *) arg, sizeof(struct cdrom_subchnl));
  6998. -      if (st)    return (st);
  6999. -      memcpy_fromfs(&SC, (void *) arg, sizeof(struct cdrom_subchnl));
  7000. -      switch (DriveStruct[d].audio_state)
  7001. -    {
  7002. -    case audio_playing:
  7003. -      SC.cdsc_audiostatus=CDROM_AUDIO_PLAY;
  7004. -      break;
  7005. -    case audio_pausing:
  7006. -      SC.cdsc_audiostatus=CDROM_AUDIO_PAUSED;
  7007. -      break;
  7008. -    default:
  7009. -      SC.cdsc_audiostatus=CDROM_AUDIO_NO_STATUS;
  7010. -      break;
  7011. -    }
  7012. -      SC.cdsc_adr=DriveStruct[d].SubQ_ctl_adr;
  7013. -      SC.cdsc_ctrl=DriveStruct[d].SubQ_ctl_adr>>4;
  7014. -      SC.cdsc_trk=bcd2bin(DriveStruct[d].SubQ_trk);
  7015. -      SC.cdsc_ind=bcd2bin(DriveStruct[d].SubQ_pnt_idx);
  7016. -      if (SC.cdsc_format==CDROM_LBA)
  7017. -    {
  7018. -      SC.cdsc_absaddr.lba=msf2blk(DriveStruct[d].SubQ_run_tot);
  7019. -      SC.cdsc_reladdr.lba=msf2blk(DriveStruct[d].SubQ_run_trk);
  7020. -    }
  7021. -      else /* not only if (SC.cdsc_format==CDROM_MSF) */
  7022. -    {
  7023. -      SC.cdsc_absaddr.msf.minute=(DriveStruct[d].SubQ_run_tot>>16)&0x00FF;
  7024. -      SC.cdsc_absaddr.msf.second=(DriveStruct[d].SubQ_run_tot>>8)&0x00FF;
  7025. -      SC.cdsc_absaddr.msf.frame=DriveStruct[d].SubQ_run_tot&0x00FF;
  7026. -      SC.cdsc_reladdr.msf.minute=(DriveStruct[d].SubQ_run_trk>>16)&0x00FF;
  7027. -      SC.cdsc_reladdr.msf.second=(DriveStruct[d].SubQ_run_trk>>8)&0x00FF;
  7028. -      SC.cdsc_reladdr.msf.frame=DriveStruct[d].SubQ_run_trk&0x00FF;
  7029. -    }
  7030. -      memcpy_tofs((void *) arg, &SC, sizeof(struct cdrom_subchnl));
  7031. -      DPRINTF((DBG_IOS,"SBPCD: CDROMSUBCHNL: %1X %02X %08X %08X %02X %02X %06X %06X\n",
  7032. -           SC.cdsc_format,SC.cdsc_audiostatus,
  7033. -           SC.cdsc_adr,SC.cdsc_ctrl,
  7034. -           SC.cdsc_trk,SC.cdsc_ind,
  7035. -           SC.cdsc_absaddr,SC.cdsc_reladdr));
  7036. -      return (0);
  7037. -
  7038. -    case CDROMREADMODE1:
  7039. -      DPRINTF((DBG_IOC,"SBPCD: ioctl: CDROMREADMODE1 requested.\n"));
  7040. -      xx_ModeSelect(CD_FRAMESIZE);
  7041. -      xx_ModeSense();
  7042. -      DriveStruct[d].mode=READ_M1;
  7043. -      return (0);
  7044. -
  7045. -    case CDROMREADMODE2: /* not usable at the moment */
  7046. -      DPRINTF((DBG_IOC,"SBPCD: ioctl: CDROMREADMODE2 requested.\n"));
  7047. -      xx_ModeSelect(CD_FRAMESIZE_XA);
  7048. -      xx_ModeSense();
  7049. -      DriveStruct[d].mode=READ_M2;
  7050. -      return (0);
  7051. -
  7052. -    case CDROMREADAUDIO:
  7053. -      { /* start of CDROMREADAUDIO */
  7054. -    int i=0, j=0, frame, block;
  7055. -    u_int try=0;
  7056. -    u_long timeout;
  7057. -    u_char *p;
  7058. -    u_int data_tries = 0;
  7059. -    u_int data_waits = 0;
  7060. -    u_int data_retrying = 0;
  7061. -    int status_tries;
  7062. -    int error_flag;
  7063. -
  7064. -    DPRINTF((DBG_IOC,"SBPCD: ioctl: CDROMREADAUDIO requested.\n"));
  7065. -    if (fam0_drive) return (-EINVAL);
  7066. -    if (famL_drive) return (-EINVAL);
  7067. -    if (fam2_drive) return (-EINVAL);
  7068. -    if (DriveStruct[d].aud_buf==NULL) return (-EINVAL);
  7069. -    i=verify_area(VERIFY_READ, (void *) arg, sizeof(struct cdrom_read_audio));
  7070. -    if (i) return (i);
  7071. -    memcpy_fromfs(&read_audio, (void *) arg, sizeof(struct cdrom_read_audio));
  7072. -    if (read_audio.nframes>SBP_BUFFER_AUDIO_FRAMES) return (-EINVAL);
  7073. -    i=verify_area(VERIFY_WRITE, read_audio.buf,
  7074. -              read_audio.nframes*CD_FRAMESIZE_RAW);
  7075. -    if (i) return (i);
  7076. -
  7077. -    if (read_audio.addr_format==CDROM_MSF) /* MSF-bin specification of where to start */
  7078. -      block=msf2lba(&read_audio.addr.msf.minute);
  7079. -    else if (read_audio.addr_format==CDROM_LBA) /* lba specification of where to start */
  7080. -      block=read_audio.addr.lba;
  7081. -    else return (-EINVAL);
  7082. -    i=yy_SetSpeed(speed_150,0,0);
  7083. -    if (i) DPRINTF((DBG_AUD,"SBPCD: read_audio: SetSpeed error %d\n", i));
  7084. -    DPRINTF((DBG_AUD,"SBPCD: read_audio: lba: %d, msf: %06X\n",
  7085. -         block, blk2msf(block)));
  7086. -    DPRINTF((DBG_AUD,"SBPCD: read_audio: before xx_ReadStatus.\n"));
  7087. -    while (busy_data) sbp_sleep(10); /* wait a bit */
  7088. -    busy_audio=1;
  7089. -    error_flag=0;
  7090. -    for (data_tries=5; data_tries>0; data_tries--)
  7091. -      {
  7092. -        DPRINTF((DBG_AUD,"SBPCD: data_tries=%d ...\n", data_tries));
  7093. -        DriveStruct[d].mode=READ_AU;
  7094. -        xx_ModeSelect(CD_FRAMESIZE_RAW);
  7095. -        xx_ModeSense();
  7096. -        for (status_tries=3; status_tries > 0; status_tries--)
  7097. -          {
  7098. -        flags_cmd_out |= f_respo3;
  7099. -        xx_ReadStatus();
  7100. -        if (sbp_status() != 0) break;
  7101. -        sbp_sleep(1);    /* wait a bit, try again */
  7102. -          }
  7103. -        if (status_tries == 0)
  7104. -          {
  7105. -        DPRINTF((DBG_AUD,"SBPCD: read_audio: sbp_status: failed after 3 tries.\n"));
  7106. -        continue;
  7107. -          }
  7108. -        DPRINTF((DBG_AUD,"SBPCD: read_audio: sbp_status: ok.\n"));
  7109. -        
  7110. -        flags_cmd_out = f_putcmd | f_respo2 | f_ResponseStatus | f_obey_p_check;
  7111. -        if (fam0L_drive)
  7112. -          {
  7113. -        flags_cmd_out |= f_lopsta | f_getsta | f_bit1;
  7114. -        cmd_type=READ_M2;
  7115. -        drvcmd[0]=CMD0_READ_XA; /* "read XA frames", old drives */
  7116. -        drvcmd[1]=(block>>16)&0x000000ff;
  7117. -        drvcmd[2]=(block>>8)&0x000000ff;
  7118. -        drvcmd[3]=block&0x000000ff;
  7119. -        drvcmd[4]=0;
  7120. -        drvcmd[5]=read_audio.nframes; /* # of frames */
  7121. -        drvcmd[6]=0;
  7122. -          }
  7123. -        else if (fam1_drive)
  7124. -          {
  7125. -        drvcmd[0]=CMD1_READ; /* "read frames", new drives */
  7126. -        lba2msf(block,&drvcmd[1]); /* msf-bin format required */
  7127. -        drvcmd[4]=0;
  7128. -        drvcmd[5]=0;
  7129. -        drvcmd[6]=read_audio.nframes; /* # of frames */
  7130. -          }
  7131. -        else if (fam2_drive) /* CD200: not implemented yet */
  7132. -          {
  7133. -          }
  7134. -        DPRINTF((DBG_AUD,"SBPCD: read_audio: before giving \"read\" command.\n"));
  7135. -        for (i=0;i<7;i++) OUT(CDo_command,drvcmd[i]);
  7136. -        sbp_sleep(0);
  7137. -        DPRINTF((DBG_AUD,"SBPCD: read_audio: after giving \"read\" command.\n"));
  7138. -        for (frame=1;frame<2 && !error_flag; frame++)
  7139. -          {
  7140. -        try=maxtim_data;
  7141. -        for (timeout=jiffies+900; ; )
  7142. -          {
  7143. -            for ( ; try!=0;try--)
  7144. -              {
  7145. -            j=inb(CDi_status);
  7146. -            if (!(j&s_not_data_ready)) break;
  7147. -            if (!(j&s_not_result_ready)) break;
  7148. -            if (fam0L_drive) if (j&s_attention) break;
  7149. -              }
  7150. -            if (try != 0 || timeout <= jiffies) break;
  7151. -            if (data_retrying == 0) data_waits++;
  7152. -            data_retrying = 1;
  7153. -            sbp_sleep(1);
  7154. -            try = 1;
  7155. -          }
  7156. -        if (try==0)
  7157. -          {
  7158. -            DPRINTF((DBG_INF,"SBPCD: read_audio: sbp_data: CDi_status timeout.\n"));
  7159. -            error_flag++;
  7160. -            break;
  7161. -          }
  7162. -        DPRINTF((DBG_AUD,"SBPCD: read_audio: sbp_data: CDi_status ok.\n"));
  7163. -        if (j&s_not_data_ready)
  7164. -          {
  7165. -            printk("SBPCD: read_audio: sbp_data: DATA_READY timeout.\n");
  7166. -            error_flag++;
  7167. -            break;
  7168. -          }
  7169. -        DPRINTF((DBG_AUD,"SBPCD: read_audio: before reading data.\n"));
  7170. -        error_flag=0;
  7171. -        p = DriveStruct[d].aud_buf;
  7172. -        if (sbpro_type==1) OUT(CDo_sel_i_d,1);
  7173. -#if 0
  7174. -        cli();
  7175. -#endif
  7176. -        READ_DATA(CDi_data, p, read_audio.nframes*CD_FRAMESIZE_RAW);
  7177. -#if 0
  7178. -        sti();
  7179. -#endif
  7180. -        if (sbpro_type==1) OUT(CDo_sel_i_d,0);
  7181. -        data_retrying = 0;
  7182. -          }
  7183. -        DPRINTF((DBG_AUD,"SBPCD: read_audio: after reading data.\n"));
  7184. -        if (error_flag)    /* must have been spurious D_RDY or (ATTN&&!D_RDY) */
  7185. -          {
  7186. -        DPRINTF((DBG_AUD,"SBPCD: read_audio: read aborted by drive\n"));
  7187. +        D_S[d].audio_state=audio_playing;
  7188. +        return (0);
  7189. +        
  7190. +    case CDROMREADTOCHDR:        /* Read the table of contents header */
  7191. +        msg(DBG_IOC,"ioctl: CDROMREADTOCHDR entered.\n");
  7192. +        tochdr.cdth_trk0=D_S[d].n_first_track;
  7193. +        tochdr.cdth_trk1=D_S[d].n_last_track;
  7194. +        st=verify_area(VERIFY_WRITE, (void *) arg, sizeof(struct cdrom_tochdr));
  7195. +        if (st) return (st);
  7196. +        memcpy_tofs((void *) arg, &tochdr, sizeof(struct cdrom_tochdr));
  7197. +        return (0);
  7198. +        
  7199. +    case CDROMREADTOCENTRY:      /* Read an entry in the table of contents */
  7200. +        msg(DBG_IOC,"ioctl: CDROMREADTOCENTRY entered.\n");
  7201. +        st=verify_area(VERIFY_READ, (void *) arg, sizeof(struct cdrom_tocentry));
  7202. +        if (st) return (st);
  7203. +        memcpy_fromfs(&tocentry, (void *) arg, sizeof(struct cdrom_tocentry));
  7204. +        i=tocentry.cdte_track;
  7205. +        if (i==CDROM_LEADOUT) i=D_S[d].n_last_track+1;
  7206. +        else if (i<D_S[d].n_first_track||i>D_S[d].n_last_track) return (-EINVAL);
  7207. +        tocentry.cdte_adr=D_S[d].TocBuffer[i].ctl_adr&0x0F;
  7208. +        tocentry.cdte_ctrl=(D_S[d].TocBuffer[i].ctl_adr>>4)&0x0F;
  7209. +        tocentry.cdte_datamode=D_S[d].TocBuffer[i].format;
  7210. +        if (tocentry.cdte_format==CDROM_MSF) /* MSF-bin required */
  7211. +        {
  7212. +            tocentry.cdte_addr.msf.minute=(D_S[d].TocBuffer[i].address>>16)&0x00FF;
  7213. +            tocentry.cdte_addr.msf.second=(D_S[d].TocBuffer[i].address>>8)&0x00FF;
  7214. +            tocentry.cdte_addr.msf.frame=D_S[d].TocBuffer[i].address&0x00FF;
  7215. +        }
  7216. +        else if (tocentry.cdte_format==CDROM_LBA) /* blk required */
  7217. +            tocentry.cdte_addr.lba=msf2blk(D_S[d].TocBuffer[i].address);
  7218. +        else return (-EINVAL);
  7219. +        st=verify_area(VERIFY_WRITE,(void *) arg, sizeof(struct cdrom_tocentry));
  7220. +        if (st) return (st);
  7221. +        memcpy_tofs((void *) arg, &tocentry, sizeof(struct cdrom_tocentry));
  7222. +        return (0);
  7223. +        
  7224. +    case CDROMRESET:      /* hard reset the drive */
  7225. +        msg(DBG_IOC,"ioctl: CDROMRESET entered.\n");
  7226. +        i=DriveReset();
  7227. +        D_S[d].audio_state=0;
  7228. +        return (i);
  7229. +        
  7230. +    case CDROMSTOP:      /* Spin down the drive */
  7231. +        msg(DBG_IOC,"ioctl: CDROMSTOP entered.\n");
  7232. +        i=cc_Pause_Resume(1);
  7233. +        D_S[d].audio_state=0;
  7234. +        return (i);
  7235. +        
  7236. +    case CDROMSTART:  /* Spin up the drive */
  7237. +        msg(DBG_IOC,"ioctl: CDROMSTART entered.\n");
  7238. +        cc_SpinUp();
  7239. +        D_S[d].audio_state=0;
  7240. +        return (0);
  7241. +        
  7242. +    case CDROMEJECT:
  7243. +        msg(DBG_IOC,"ioctl: CDROMEJECT entered.\n");
  7244. +        if (fam0_drive) return (0);
  7245. +        i=UnLockDoor();
  7246. +        D_S[d].open_count=-9; /* to get it locked next time again */
  7247. +        i=cc_SpinDown();
  7248. +        msg(DBG_IOX,"ioctl: cc_SpinDown returned %d.\n", i);
  7249. +        msg(DBG_TEA,"ioctl: cc_SpinDown returned %d.\n", i);
  7250. +        if (i<0) return (-EIO);
  7251. +        D_S[d].CD_changed=0xFF;
  7252. +        D_S[d].diskstate_flags=0;
  7253. +        D_S[d].audio_state=0;
  7254. +        return (0);
  7255. +        
  7256. +    case CDROMEJECT_SW:
  7257. +        msg(DBG_IOC,"ioctl: CDROMEJECT_SW entered.\n");
  7258. +        if (fam0_drive) return (0);
  7259. +        D_S[d].f_eject=arg;
  7260. +        return (0);
  7261. +        
  7262. +    case CDROMVOLCTRL:   /* Volume control */
  7263. +        msg(DBG_IOC,"ioctl: CDROMVOLCTRL entered.\n");
  7264. +        st=verify_area(VERIFY_READ,(void *) arg,sizeof(volctrl));
  7265. +        if (st) return (st);
  7266. +        memcpy_fromfs(&volctrl,(char *) arg,sizeof(volctrl));
  7267. +        D_S[d].vol_chan0=0;
  7268. +        D_S[d].vol_ctrl0=volctrl.channel0;
  7269. +        D_S[d].vol_chan1=1;
  7270. +        D_S[d].vol_ctrl1=volctrl.channel1;
  7271. +        i=cc_SetVolume();
  7272. +        return (0);
  7273. +        
  7274. +    case CDROMVOLREAD:   /* read Volume settings from drive */
  7275. +        msg(DBG_IOC,"ioctl: CDROMVOLREAD entered.\n");
  7276. +        st=verify_area(VERIFY_WRITE,(void *)arg,sizeof(volctrl));
  7277. +        if (st) return (st);
  7278. +        st=cc_GetVolume();
  7279. +        if (st<0) return (st);
  7280. +        volctrl.channel0=D_S[d].vol_ctrl0;
  7281. +        volctrl.channel1=D_S[d].vol_ctrl1;
  7282. +        volctrl.channel2=0;
  7283. +        volctrl.channel2=0;
  7284. +        memcpy_tofs((void *)arg,&volctrl,sizeof(volctrl));
  7285. +        return (0);
  7286. +
  7287. +    case CDROMSUBCHNL:   /* Get subchannel info */
  7288. +        msg(DBG_IOS,"ioctl: CDROMSUBCHNL entered.\n");
  7289. +        if ((st_spinning)||(!subq_valid)) { i=cc_ReadSubQ();
  7290. +                            if (i<0) return (-EIO);
  7291. +                        }
  7292. +        st=verify_area(VERIFY_WRITE, (void *) arg, sizeof(struct cdrom_subchnl));
  7293. +        if (st)    return (st);
  7294. +        memcpy_fromfs(&SC, (void *) arg, sizeof(struct cdrom_subchnl));
  7295. +        switch (D_S[d].audio_state)
  7296. +        {
  7297. +        case audio_playing:
  7298. +            SC.cdsc_audiostatus=CDROM_AUDIO_PLAY;
  7299. +            break;
  7300. +        case audio_pausing:
  7301. +            SC.cdsc_audiostatus=CDROM_AUDIO_PAUSED;
  7302. +            break;
  7303. +        default:
  7304. +            SC.cdsc_audiostatus=CDROM_AUDIO_NO_STATUS;
  7305. +            break;
  7306. +        }
  7307. +        SC.cdsc_adr=D_S[d].SubQ_ctl_adr;
  7308. +        SC.cdsc_ctrl=D_S[d].SubQ_ctl_adr>>4;
  7309. +        SC.cdsc_trk=bcd2bin(D_S[d].SubQ_trk);
  7310. +        SC.cdsc_ind=bcd2bin(D_S[d].SubQ_pnt_idx);
  7311. +        if (SC.cdsc_format==CDROM_LBA)
  7312. +        {
  7313. +            SC.cdsc_absaddr.lba=msf2blk(D_S[d].SubQ_run_tot);
  7314. +            SC.cdsc_reladdr.lba=msf2blk(D_S[d].SubQ_run_trk);
  7315. +        }
  7316. +        else /* not only if (SC.cdsc_format==CDROM_MSF) */
  7317. +        {
  7318. +            SC.cdsc_absaddr.msf.minute=(D_S[d].SubQ_run_tot>>16)&0x00FF;
  7319. +            SC.cdsc_absaddr.msf.second=(D_S[d].SubQ_run_tot>>8)&0x00FF;
  7320. +            SC.cdsc_absaddr.msf.frame=D_S[d].SubQ_run_tot&0x00FF;
  7321. +            SC.cdsc_reladdr.msf.minute=(D_S[d].SubQ_run_trk>>16)&0x00FF;
  7322. +            SC.cdsc_reladdr.msf.second=(D_S[d].SubQ_run_trk>>8)&0x00FF;
  7323. +            SC.cdsc_reladdr.msf.frame=D_S[d].SubQ_run_trk&0x00FF;
  7324. +        }
  7325. +        memcpy_tofs((void *) arg, &SC, sizeof(struct cdrom_subchnl));
  7326. +        msg(DBG_IOS,"CDROMSUBCHNL: %1X %02X %08X %08X %02X %02X %06X %06X\n",
  7327. +            SC.cdsc_format,SC.cdsc_audiostatus,
  7328. +            SC.cdsc_adr,SC.cdsc_ctrl,
  7329. +            SC.cdsc_trk,SC.cdsc_ind,
  7330. +            SC.cdsc_absaddr,SC.cdsc_reladdr);
  7331. +        return (0);
  7332. +        
  7333. +    case CDROMREADMODE1:
  7334. +        msg(DBG_IOC,"ioctl: CDROMREADMODE1 requested.\n");
  7335. +        cc_ModeSelect(CD_FRAMESIZE);
  7336. +        cc_ModeSense();
  7337. +        D_S[d].mode=READ_M1;
  7338. +        return (0);
  7339. +        
  7340. +    case CDROMREADMODE2: /* not usable at the moment */
  7341. +        msg(DBG_IOC,"ioctl: CDROMREADMODE2 requested.\n");
  7342. +        cc_ModeSelect(CD_FRAMESIZE_XA);
  7343. +        cc_ModeSense();
  7344. +        D_S[d].mode=READ_M2;
  7345. +        return (0);
  7346. +        
  7347. +    case CDROMAUDIOBUFSIZ: /* configure the audio buffer size */
  7348. +        msg(DBG_IOC,"ioctl: CDROMAUDIOBUFSIZ entered.\n");
  7349. +#ifdef MODULE
  7350. +        if (D_S[d].sbp_audsiz>0)
  7351. +            vfree(D_S[d].aud_buf);
  7352. +#endif MODULE
  7353. +        D_S[d].aud_buf=NULL;
  7354. +        D_S[d].sbp_audsiz=arg;
  7355. +        if (D_S[d].sbp_audsiz>0)
  7356. +        {
  7357. +            D_S[d].aud_buf=(u_char *) vmalloc(D_S[d].sbp_audsiz*CD_FRAMESIZE_RAW);
  7358. +            if (D_S[d].aud_buf==NULL)
  7359. +            {
  7360. +                msg(DBG_INF,"audio buffer (%d frames) not available.\n",D_S[d].sbp_audsiz);
  7361. +                D_S[d].sbp_audsiz=0;
  7362. +            }
  7363. +            else msg(DBG_INF,"audio buffer size: %d frames.\n",D_S[d].sbp_audsiz);
  7364. +        }
  7365. +        return (D_S[d].sbp_audsiz);
  7366. +
  7367. +    case CDROMREADAUDIO:
  7368. +    { /* start of CDROMREADAUDIO */
  7369. +        int i=0, j=0, frame, block;
  7370. +        u_int try=0;
  7371. +        u_long timeout;
  7372. +        u_char *p;
  7373. +        u_int data_tries = 0;
  7374. +        u_int data_waits = 0;
  7375. +        u_int data_retrying = 0;
  7376. +        int status_tries;
  7377. +        int error_flag;
  7378. +        
  7379. +        msg(DBG_IOC,"ioctl: CDROMREADAUDIO entered.\n");
  7380. +        if (fam0_drive) return (-EINVAL);
  7381. +        if (famL_drive) return (-EINVAL);
  7382. +        if (fam2_drive) return (-EINVAL);
  7383. +        if (famT_drive) return (-EINVAL);
  7384. +        if (D_S[d].aud_buf==NULL) return (-EINVAL);
  7385. +        i=verify_area(VERIFY_READ, (void *) arg, sizeof(struct cdrom_read_audio));
  7386. +        if (i) return (i);
  7387. +        memcpy_fromfs(&read_audio, (void *) arg, sizeof(struct cdrom_read_audio));
  7388. +        if (read_audio.nframes>D_S[d].sbp_audsiz) return (-EINVAL);
  7389. +        i=verify_area(VERIFY_WRITE, read_audio.buf,
  7390. +                  read_audio.nframes*CD_FRAMESIZE_RAW);
  7391. +        if (i) return (i);
  7392. +        
  7393. +        if (read_audio.addr_format==CDROM_MSF) /* MSF-bin specification of where to start */
  7394. +            block=msf2lba(&read_audio.addr.msf.minute);
  7395. +        else if (read_audio.addr_format==CDROM_LBA) /* lba specification of where to start */
  7396. +            block=read_audio.addr.lba;
  7397. +        else return (-EINVAL);
  7398. +        i=cc_SetSpeed(speed_150,0,0);
  7399. +        if (i) msg(DBG_AUD,"read_audio: SetSpeed error %d\n", i);
  7400. +        msg(DBG_AUD,"read_audio: lba: %d, msf: %06X\n",
  7401. +            block, blk2msf(block));
  7402. +        msg(DBG_AUD,"read_audio: before cc_ReadStatus.\n");
  7403. +        while (busy_data) sbp_sleep(10); /* wait a bit */
  7404. +        busy_audio=1;
  7405. +        error_flag=0;
  7406. +        for (data_tries=5; data_tries>0; data_tries--)
  7407. +        {
  7408. +            msg(DBG_AUD,"data_tries=%d ...\n", data_tries);
  7409. +            D_S[d].mode=READ_AU;
  7410. +            cc_ModeSelect(CD_FRAMESIZE_RAW);
  7411. +            cc_ModeSense();
  7412. +            for (status_tries=3; status_tries > 0; status_tries--)
  7413. +            {
  7414. +                flags_cmd_out |= f_respo3;
  7415. +                cc_ReadStatus();
  7416. +                if (sbp_status() != 0) break;
  7417. +                sbp_sleep(1);    /* wait a bit, try again */
  7418. +            }
  7419. +            if (status_tries == 0)
  7420. +            {
  7421. +                msg(DBG_AUD,"read_audio: sbp_status: failed after 3 tries.\n");
  7422. +                continue;
  7423. +            }
  7424. +            msg(DBG_AUD,"read_audio: sbp_status: ok.\n");
  7425. +            
  7426. +            flags_cmd_out = f_putcmd | f_respo2 | f_ResponseStatus | f_obey_p_check;
  7427. +            if (fam0L_drive)
  7428. +            {
  7429. +                flags_cmd_out |= f_lopsta | f_getsta | f_bit1;
  7430. +                cmd_type=READ_M2;
  7431. +                drvcmd[0]=CMD0_READ_XA; /* "read XA frames", old drives */
  7432. +                drvcmd[1]=(block>>16)&0x000000ff;
  7433. +                drvcmd[2]=(block>>8)&0x000000ff;
  7434. +                drvcmd[3]=block&0x000000ff;
  7435. +                drvcmd[4]=0;
  7436. +                drvcmd[5]=read_audio.nframes; /* # of frames */
  7437. +                drvcmd[6]=0;
  7438. +            }
  7439. +            else if (fam1_drive)
  7440. +            {
  7441. +                drvcmd[0]=CMD1_READ; /* "read frames", new drives */
  7442. +                lba2msf(block,&drvcmd[1]); /* msf-bin format required */
  7443. +                drvcmd[4]=0;
  7444. +                drvcmd[5]=0;
  7445. +                drvcmd[6]=read_audio.nframes; /* # of frames */
  7446. +            }
  7447. +            else if (fam2_drive) /* CD200: not tested yet */
  7448. +            {
  7449. +            }
  7450. +            else if (famT_drive) /* CD-55A: not tested yet */
  7451. +            {
  7452. +            }
  7453. +            msg(DBG_AUD,"read_audio: before giving \"read\" command.\n");
  7454. +            for (i=0;i<7;i++) OUT(CDo_command,drvcmd[i]);
  7455. +            sbp_sleep(0);
  7456. +            msg(DBG_AUD,"read_audio: after giving \"read\" command.\n");
  7457. +            for (frame=1;frame<2 && !error_flag; frame++)
  7458. +            {
  7459. +                try=maxtim_data;
  7460. +                for (timeout=jiffies+900; ; )
  7461. +                {
  7462. +                    for ( ; try!=0;try--)
  7463. +                    {
  7464. +                        j=inb(CDi_status);
  7465. +                        if (!(j&s_not_data_ready)) break;
  7466. +                        if (!(j&s_not_result_ready)) break;
  7467. +                        if (fam0L_drive) if (j&s_attention) break;
  7468. +                    }
  7469. +                    if (try != 0 || timeout <= jiffies) break;
  7470. +                    if (data_retrying == 0) data_waits++;
  7471. +                    data_retrying = 1;
  7472. +                    sbp_sleep(1);
  7473. +                    try = 1;
  7474. +                }
  7475. +                if (try==0)
  7476. +                {
  7477. +                    msg(DBG_INF,"read_audio: sbp_data: CDi_status timeout.\n");
  7478. +                    error_flag++;
  7479. +                    break;
  7480. +                }
  7481. +                msg(DBG_AUD,"read_audio: sbp_data: CDi_status ok.\n");
  7482. +                if (j&s_not_data_ready)
  7483. +                {
  7484. +                    msg(DBG_INF, "read_audio: sbp_data: DATA_READY timeout.\n");
  7485. +                    error_flag++;
  7486. +                    break;
  7487. +                }
  7488. +                msg(DBG_AUD,"read_audio: before reading data.\n");
  7489. +                error_flag=0;
  7490. +                p = D_S[d].aud_buf;
  7491. +                if (sbpro_type==1) OUT(CDo_sel_i_d,1);
  7492. +                insb(CDi_data, p, read_audio.nframes*CD_FRAMESIZE_RAW);
  7493. +                if (sbpro_type==1) OUT(CDo_sel_i_d,0);
  7494. +                data_retrying = 0;
  7495. +            }
  7496. +            msg(DBG_AUD,"read_audio: after reading data.\n");
  7497. +            if (error_flag)    /* must have been spurious D_RDY or (ATTN&&!D_RDY) */
  7498. +            {
  7499. +                msg(DBG_AUD,"read_audio: read aborted by drive\n");
  7500.  #if 0000
  7501. -        i=DriveReset();                /* ugly fix to prevent a hang */
  7502. +                i=cc_DriveReset();                /* ugly fix to prevent a hang */
  7503.  #else
  7504. -        i=xx_ReadError();
  7505. +                i=cc_ReadError();
  7506.  #endif 0000
  7507. -        continue;
  7508. -          }
  7509. -        if (fam0L_drive)
  7510. -          {
  7511. -        i=maxtim_data;
  7512. -        for (timeout=jiffies+900; timeout > jiffies; timeout--)
  7513. -          {
  7514. -            for ( ;i!=0;i--)
  7515. -              {
  7516. -            j=inb(CDi_status);
  7517. -            if (!(j&s_not_data_ready)) break;
  7518. -            if (!(j&s_not_result_ready)) break;
  7519. -            if (j&s_attention) break;
  7520. -              }
  7521. -            if (i != 0 || timeout <= jiffies) break;
  7522. -            sbp_sleep(0);
  7523. -            i = 1;
  7524. -          }
  7525. -        if (i==0) { DPRINTF((DBG_AUD,"SBPCD: read_audio: STATUS TIMEOUT AFTER READ")); }
  7526. -        if (!(j&s_attention))
  7527. -          {
  7528. -            DPRINTF((DBG_AUD,"SBPCD: read_audio: sbp_data: timeout waiting DRV_ATTN - retrying\n"));
  7529. -            i=DriveReset();  /* ugly fix to prevent a hang */
  7530. -          continue;
  7531. -          }
  7532. -          }
  7533. -        do
  7534. -          {
  7535. -        if (fam0L_drive) xx_ReadStatus();
  7536. -        i=ResponseStatus();  /* builds status_byte, returns orig. status (old) or faked p_success_old (new) */
  7537. -        if (i<0) { DPRINTF((DBG_AUD,
  7538. -                    "SBPCD: read_audio: xx_ReadStatus error after read: %02X\n",
  7539. -                    DriveStruct[d].status_byte));
  7540. -               continue; /* FIXME */
  7541. -             }
  7542. -          }
  7543. -        while ((fam0L_drive)&&(!st_check)&&(!(i&p_success_old)));
  7544. -        if (st_check)
  7545. -          {
  7546. -        i=xx_ReadError();
  7547. -        DPRINTF((DBG_AUD,"SBPCD: read_audio: xx_ReadError was necessary after read: %02X\n",i));
  7548. -        continue;
  7549. -          }
  7550. -        memcpy_tofs((u_char *) read_audio.buf,
  7551. -            (u_char *) DriveStruct[d].aud_buf,
  7552. -            read_audio.nframes*CD_FRAMESIZE_RAW);
  7553. -        DPRINTF((DBG_AUD,"SBPCD: read_audio: memcpy_tofs done.\n"));
  7554. -        break;
  7555. -      }
  7556. -    xx_ModeSelect(CD_FRAMESIZE);
  7557. -    xx_ModeSense();
  7558. -    DriveStruct[d].mode=READ_M1;
  7559. -    busy_audio=0;
  7560. -    if (data_tries == 0)
  7561. -      {
  7562. -        DPRINTF((DBG_AUD,"SBPCD: read_audio: failed after 5 tries.\n"));
  7563. -        return (-8);
  7564. -      }
  7565. -    DPRINTF((DBG_AUD,"SBPCD: read_audio: successful return.\n"));
  7566. -    return (0);
  7567. -      } /* end of CDROMREADAUDIO */
  7568. -
  7569. -    case CDROMMULTISESSION: /* tell start-of-last-session */
  7570. -      DPRINTF((DBG_IOC,"SBPCD: ioctl: CDROMMULTISESSION entered.\n"));
  7571. -      st=verify_area(VERIFY_READ, (void *) arg, sizeof(struct cdrom_multisession));
  7572. -      if (st) return (st);
  7573. -      memcpy_fromfs(&ms_info, (void *) arg, sizeof(struct cdrom_multisession));
  7574. -      if (ms_info.addr_format==CDROM_MSF) /* MSF-bin requested */
  7575. -    lba2msf(DriveStruct[d].lba_multi,&ms_info.addr.msf.minute);
  7576. -      else if (ms_info.addr_format==CDROM_LBA) /* lba requested */
  7577. -    ms_info.addr.lba=DriveStruct[d].lba_multi;
  7578. -      else return (-EINVAL);
  7579. -      if (DriveStruct[d].f_multisession) ms_info.xa_flag=1; /* valid redirection address */
  7580. -      else ms_info.xa_flag=0; /* invalid redirection address */
  7581. -      st=verify_area(VERIFY_WRITE,(void *) arg, sizeof(struct cdrom_multisession));
  7582. -      if (st) return (st);
  7583. -      memcpy_tofs((void *) arg, &ms_info, sizeof(struct cdrom_multisession));
  7584. -      DPRINTF((DBG_MUL,"SBPCD: ioctl: CDROMMULTISESSION done (%d, %08X).\n",
  7585. -           ms_info.xa_flag, ms_info.addr.lba));
  7586. -      return (0);
  7587. -
  7588. -    case BLKRASET:
  7589. -      if(!suser())  return -EACCES;
  7590. -      if(!inode->i_rdev) return -EINVAL;
  7591. -      if(arg > 0xff) return -EINVAL;
  7592. -      read_ahead[MAJOR(inode->i_rdev)] = arg;
  7593. -      return (0);
  7594. -
  7595. -    default:
  7596. -      DPRINTF((DBG_IOC,"SBPCD: ioctl: unknown function request %04X\n", cmd));
  7597. -      return (-EINVAL);
  7598. -    } /* end switch(cmd) */
  7599. +                continue;
  7600. +            }
  7601. +            if (fam0L_drive)
  7602. +            {
  7603. +                i=maxtim_data;
  7604. +                for (timeout=jiffies+900; timeout > jiffies; timeout--)
  7605. +                {
  7606. +                    for ( ;i!=0;i--)
  7607. +                    {
  7608. +                        j=inb(CDi_status);
  7609. +                        if (!(j&s_not_data_ready)) break;
  7610. +                        if (!(j&s_not_result_ready)) break;
  7611. +                        if (j&s_attention) break;
  7612. +                    }
  7613. +                    if (i != 0 || timeout <= jiffies) break;
  7614. +                    sbp_sleep(0);
  7615. +                    i = 1;
  7616. +                }
  7617. +                if (i==0) msg(DBG_AUD,"read_audio: STATUS TIMEOUT AFTER READ");
  7618. +                if (!(j&s_attention))
  7619. +                {
  7620. +                    msg(DBG_AUD,"read_audio: sbp_data: timeout waiting DRV_ATTN - retrying\n");
  7621. +                    i=cc_DriveReset();  /* ugly fix to prevent a hang */
  7622. +                    continue;
  7623. +                }
  7624. +            }
  7625. +            do
  7626. +            {
  7627. +                if (fam0L_drive) cc_ReadStatus();
  7628. +                i=ResponseStatus();  /* builds status_bits, returns orig. status (old) or faked p_success (new) */
  7629. +                if (i<0) { msg(DBG_AUD,
  7630. +                           "read_audio: cc_ReadStatus error after read: %02X\n",
  7631. +                           D_S[d].status_bits);
  7632. +                       continue; /* FIXME */
  7633. +                   }
  7634. +            }
  7635. +            while ((fam0L_drive)&&(!st_check)&&(!(i&p_success)));
  7636. +            if (st_check)
  7637. +            {
  7638. +                i=cc_ReadError();
  7639. +                msg(DBG_AUD,"read_audio: cc_ReadError was necessary after read: %02X\n",i);
  7640. +                continue;
  7641. +            }
  7642. +            memcpy_tofs((u_char *) read_audio.buf,
  7643. +                    (u_char *) D_S[d].aud_buf,
  7644. +                    read_audio.nframes*CD_FRAMESIZE_RAW);
  7645. +            msg(DBG_AUD,"read_audio: memcpy_tofs done.\n");
  7646. +            break;
  7647. +        }
  7648. +        cc_ModeSelect(CD_FRAMESIZE);
  7649. +        cc_ModeSense();
  7650. +        D_S[d].mode=READ_M1;
  7651. +        busy_audio=0;
  7652. +        if (data_tries == 0)
  7653. +        {
  7654. +            msg(DBG_AUD,"read_audio: failed after 5 tries.\n");
  7655. +            return (-8);
  7656. +        }
  7657. +        msg(DBG_AUD,"read_audio: successful return.\n");
  7658. +        return (0);
  7659. +    } /* end of CDROMREADAUDIO */
  7660. +        
  7661. +    case CDROMMULTISESSION: /* tell start-of-last-session */
  7662. +        msg(DBG_IOC,"ioctl: CDROMMULTISESSION entered.\n");
  7663. +        st=verify_area(VERIFY_READ, (void *) arg, sizeof(struct cdrom_multisession));
  7664. +        if (st) return (st);
  7665. +        memcpy_fromfs(&ms_info, (void *) arg, sizeof(struct cdrom_multisession));
  7666. +        if (ms_info.addr_format==CDROM_MSF) /* MSF-bin requested */
  7667. +            lba2msf(D_S[d].lba_multi,&ms_info.addr.msf.minute);
  7668. +        else if (ms_info.addr_format==CDROM_LBA) /* lba requested */
  7669. +            ms_info.addr.lba=D_S[d].lba_multi;
  7670. +        else return (-EINVAL);
  7671. +        if (D_S[d].f_multisession) ms_info.xa_flag=1; /* valid redirection address */
  7672. +        else ms_info.xa_flag=0; /* invalid redirection address */
  7673. +        st=verify_area(VERIFY_WRITE,(void *) arg, sizeof(struct cdrom_multisession));
  7674. +        if (st) return (st);
  7675. +        memcpy_tofs((void *) arg, &ms_info, sizeof(struct cdrom_multisession));
  7676. +        msg(DBG_MUL,"ioctl: CDROMMULTISESSION done (%d, %08X).\n",
  7677. +            ms_info.xa_flag, ms_info.addr.lba);
  7678. +        return (0);
  7679. +        
  7680. +    case BLKRASET:
  7681. +        if(!suser())  return -EACCES;
  7682. +        if(!inode->i_rdev) return -EINVAL;
  7683. +        if(arg > 0xff) return -EINVAL;
  7684. +        read_ahead[MAJOR(inode->i_rdev)] = arg;
  7685. +        return (0);
  7686. +        
  7687. +    default:
  7688. +        msg(DBG_IOC,"ioctl: unknown function request %04X\n", cmd);
  7689. +        return (-EINVAL);
  7690. +    } /* end switch(cmd) */
  7691.  }
  7692.  /*==========================================================================*/
  7693.  /*
  7694. @@ -3585,18 +4322,18 @@
  7695.   */
  7696.  static void sbp_transfer(void)
  7697.  {
  7698. -  long offs;
  7699. -  
  7700. -  while ( (CURRENT->nr_sectors > 0) &&
  7701. -      (CURRENT->sector/4 >= DriveStruct[d].sbp_first_frame) &&
  7702. -      (CURRENT->sector/4 <= DriveStruct[d].sbp_last_frame) )
  7703. -    {
  7704. -      offs = (CURRENT->sector - DriveStruct[d].sbp_first_frame * 4) * 512;
  7705. -      memcpy(CURRENT->buffer, DriveStruct[d].sbp_buf + offs, 512);
  7706. -      CURRENT->nr_sectors--;
  7707. -      CURRENT->sector++;
  7708. -      CURRENT->buffer += 512;
  7709. -    }
  7710. +    long offs;
  7711. +    
  7712. +    while ( (CURRENT->nr_sectors > 0) &&
  7713. +           (CURRENT->sector/4 >= D_S[d].sbp_first_frame) &&
  7714. +           (CURRENT->sector/4 <= D_S[d].sbp_last_frame) )
  7715. +    {
  7716. +        offs = (CURRENT->sector - D_S[d].sbp_first_frame * 4) * 512;
  7717. +        memcpy(CURRENT->buffer, D_S[d].sbp_buf + offs, 512);
  7718. +        CURRENT->nr_sectors--;
  7719. +        CURRENT->sector++;
  7720. +        CURRENT->buffer += 512;
  7721. +    }
  7722.  }
  7723.  /*==========================================================================*/
  7724.  /*
  7725. @@ -3604,328 +4341,459 @@
  7726.   */
  7727.  static void DO_SBPCD_REQUEST(void)
  7728.  {
  7729. -  u_int block;
  7730. -  u_int nsect;
  7731. -  int i, status_tries, data_tries;
  7732. -  
  7733. -request_loop:
  7734. -  INIT_REQUEST;
  7735. -  sti();
  7736. -
  7737. -  if ((CURRENT==NULL)||(CURRENT->dev<0)) goto err_done;
  7738. -  if (CURRENT -> sector == -1) goto err_done;
  7739. -  if (CURRENT->cmd != READ)
  7740. -    {
  7741. -      printk("SBPCD: bad cmd %d\n", CURRENT->cmd);
  7742. -      goto err_done;
  7743. -    }
  7744. -  i = MINOR(CURRENT->dev);
  7745. -  if ( (i<0) || (i>=NR_SBPCD) || (DriveStruct[i].drv_id==-1))
  7746. -    {
  7747. -      printk("SBPCD: do_request: bad device: %04X\n", CURRENT->dev);
  7748. -      goto err_done;
  7749. -    }
  7750. -  switch_drive(i);
  7751. -
  7752. -  block = CURRENT->sector; /* always numbered as 512-byte-pieces */
  7753. -  nsect = CURRENT->nr_sectors; /* always counted as 512-byte-pieces */
  7754. -
  7755. -  DPRINTF((DBG_BSZ,"SBPCD: read sector %d (%d sectors)\n", block, nsect));
  7756. +    u_int block;
  7757. +    u_int nsect;
  7758. +    int i, status_tries, data_tries;
  7759. +    
  7760. + request_loop:
  7761. +    INIT_REQUEST;
  7762. +    sti();
  7763. +    
  7764. +    if ((CURRENT==NULL)||(CURRENT->dev<0)) goto err_done;
  7765. +    if (CURRENT -> sector == -1) goto err_done;
  7766. +    if (CURRENT->cmd != READ)
  7767. +    {
  7768. +        msg(DBG_INF, "bad cmd %d\n", CURRENT->cmd);
  7769. +        goto err_done;
  7770. +    }
  7771. +    i = MINOR(CURRENT->dev);
  7772. +    if ( (i<0) || (i>=NR_SBPCD) || (D_S[i].drv_id==-1))
  7773. +    {
  7774. +        msg(DBG_INF, "do_request: bad device: %04X\n", CURRENT->dev);
  7775. +        goto err_done;
  7776. +    }
  7777. +    while (busy_audio) sbp_sleep(100); /* wait a bit */
  7778. +    busy_data=1;
  7779. +    
  7780. +    if (D_S[i].audio_state==audio_playing) goto err_done;
  7781. +    if (d!=i) switch_drive(i);
  7782. +    
  7783. +    block = CURRENT->sector; /* always numbered as 512-byte-pieces */
  7784. +    nsect = CURRENT->nr_sectors; /* always counted as 512-byte-pieces */
  7785. +    
  7786. +    msg(DBG_BSZ,"read sector %d (%d sectors)\n", block, nsect);
  7787.  #if 0
  7788. -  DPRINTF((DBG_MUL,"SBPCD: read LBA %d\n", block/4));
  7789. +    msg(DBG_MUL,"read LBA %d\n", block/4);
  7790.  #endif
  7791. -
  7792. -  sbp_transfer();
  7793. -  /* if we satisfied the request from the buffer, we're done. */
  7794. -  if (CURRENT->nr_sectors == 0)
  7795. -    {
  7796. -      end_request(1);
  7797. -      goto request_loop;
  7798. -    }
  7799. -
  7800. -  i=prepare(0,0); /* at moment not really a hassle check, but ... */
  7801. -  if (i!=0)
  7802. -    DPRINTF((DBG_INF,"SBPCD: \"prepare\" tells error %d -- ignored\n", i));
  7803. -
  7804. -  while (busy_audio) sbp_sleep(100); /* wait a bit */
  7805. -  busy_data=1;
  7806. -
  7807. -  if (!st_spinning) xx_SpinUp();
  7808. -
  7809. -#ifdef XA_TEST1
  7810. -  if ((fam0L_drive) && (DriveStruct[d].xa_byte==0x20)) /* XA disk with old drive */
  7811. -      {
  7812. -    xx_ModeSelect(CD_FRAMESIZE_XA);
  7813. -    xx_ModeSense();
  7814. -      }
  7815. -#endif XA_TEST1
  7816. -
  7817. -  for (data_tries=n_retries; data_tries > 0; data_tries--)
  7818. -    {
  7819. -      for (status_tries=3; status_tries > 0; status_tries--)
  7820. +    
  7821. +    sbp_transfer();
  7822. +    /* if we satisfied the request from the buffer, we're done. */
  7823. +    if (CURRENT->nr_sectors == 0)
  7824.      {
  7825. -      flags_cmd_out |= f_respo3;
  7826. -      xx_ReadStatus();
  7827. -      if (sbp_status() != 0) break;
  7828. -      if (st_check) xx_ReadError();
  7829. -      sbp_sleep(1);    /* wait a bit, try again */
  7830. -    }
  7831. -      if (status_tries == 0)
  7832. -    {
  7833. -      DPRINTF((DBG_INF,"SBPCD: sbp_status: failed after 3 tries\n"));
  7834. -      break;
  7835. +        end_request(1);
  7836. +        goto request_loop;
  7837.      }
  7838.  
  7839. -      sbp_read_cmd();
  7840. -      sbp_sleep(0);
  7841. -      if (sbp_data() != 0)
  7842. +#if FUTURE
  7843. +    i=prepare(0,0); /* at moment not really a hassle check, but ... */
  7844. +    if (i!=0)
  7845. +        msg(DBG_INF,"\"prepare\" tells error %d -- ignored\n", i);
  7846. +#endif FUTURE
  7847. +    
  7848. +    if (!st_spinning) cc_SpinUp();
  7849. +    
  7850. +    for (data_tries=n_retries; data_tries > 0; data_tries--)
  7851.      {
  7852. -      end_request(1);
  7853. -      goto request_loop;
  7854. +        for (status_tries=3; status_tries > 0; status_tries--)
  7855. +        {
  7856. +            flags_cmd_out |= f_respo3;
  7857. +            cc_ReadStatus();
  7858. +            if (sbp_status() != 0) break;
  7859. +            if (st_check) cc_ReadError();
  7860. +            sbp_sleep(1);    /* wait a bit, try again */
  7861. +        }
  7862. +        if (status_tries == 0)
  7863. +        {
  7864. +            msg(DBG_INF,"sbp_status: failed after 3 tries\n");
  7865. +            break;
  7866. +        }
  7867. +        
  7868. +        sbp_read_cmd();
  7869. +        sbp_sleep(0);
  7870. +        if (sbp_data() != 0)
  7871. +        {
  7872. +            end_request(1);
  7873. +            goto request_loop;
  7874. +        }
  7875.      }
  7876. -    }
  7877. -  
  7878. -err_done:
  7879. -  busy_data=0;
  7880. -  end_request(0);
  7881. -  sbp_sleep(10);    /* wait a bit, try again */
  7882. -  goto request_loop;
  7883. +    
  7884. + err_done:
  7885. +    busy_data=0;
  7886. +    end_request(0);
  7887. +    sbp_sleep(0);    /* wait a bit, try again */
  7888. +    goto request_loop;
  7889.  }
  7890.  /*==========================================================================*/
  7891.  /*
  7892.   *  build and send the READ command.
  7893. - *  Maybe it would be better to "set mode1" before ...
  7894.   */
  7895.  static void sbp_read_cmd(void)
  7896.  {
  7897. -  int i;
  7898. -  int block;
  7899. +#undef OLD
  7900.  
  7901. -  DriveStruct[d].sbp_first_frame=DriveStruct[d].sbp_last_frame=-1;      /* purge buffer */
  7902. -  block=CURRENT->sector/4;
  7903. -  if (block+SBP_BUFFER_FRAMES <= DriveStruct[d].CDsize_frm)
  7904. -    DriveStruct[d].sbp_read_frames = SBP_BUFFER_FRAMES;
  7905. -  else
  7906. -    {
  7907. -      DriveStruct[d].sbp_read_frames=DriveStruct[d].CDsize_frm-block;
  7908. -                                      /* avoid reading past end of data */
  7909. -      if (DriveStruct[d].sbp_read_frames < 1)
  7910. -    {
  7911. -      DPRINTF((DBG_INF,"SBPCD: requested frame %d, CD size %d ???\n",
  7912. -                block, DriveStruct[d].CDsize_frm));
  7913. -      DriveStruct[d].sbp_read_frames=1;
  7914. +    int i;
  7915. +    int block;
  7916. +    
  7917. +    D_S[d].sbp_first_frame=D_S[d].sbp_last_frame=-1;      /* purge buffer */
  7918. +    D_S[d].sbp_current = 0;
  7919. +    block=CURRENT->sector/4;
  7920. +    if (block+D_S[d].sbp_bufsiz <= D_S[d].CDsize_frm)
  7921. +        D_S[d].sbp_read_frames = D_S[d].sbp_bufsiz;
  7922. +    else
  7923. +    {
  7924. +        D_S[d].sbp_read_frames=D_S[d].CDsize_frm-block;
  7925. +        /* avoid reading past end of data */
  7926. +        if (D_S[d].sbp_read_frames < 1)
  7927. +        {
  7928. +            msg(DBG_INF,"requested frame %d, CD size %d ???\n",
  7929. +                block, D_S[d].CDsize_frm);
  7930. +            D_S[d].sbp_read_frames=1;
  7931. +        }
  7932.      }
  7933. -    }
  7934. -  DriveStruct[d].sbp_current = 0;
  7935. -
  7936. -  flags_cmd_out = f_putcmd |
  7937. -                  f_respo2 |
  7938. -                  f_ResponseStatus |
  7939. -                  f_obey_p_check;
  7940. -
  7941. -  if (fam0L_drive)
  7942. -    {
  7943. -      flags_cmd_out |= f_lopsta | f_getsta | f_bit1;
  7944. -      if (DriveStruct[d].xa_byte==0x20)
  7945. -    {
  7946. -      cmd_type=READ_M2;
  7947. -      drvcmd[0]=CMD0_READ_XA; /* "read XA frames", old drives */
  7948. -      drvcmd[1]=(block>>16)&0x000000ff;
  7949. -      drvcmd[2]=(block>>8)&0x000000ff;
  7950. -      drvcmd[3]=block&0x000000ff;
  7951. -      drvcmd[4]=0;
  7952. -      drvcmd[5]=DriveStruct[d].sbp_read_frames;
  7953. -      drvcmd[6]=0;
  7954. -    }
  7955. -      else
  7956. -    {
  7957. -      drvcmd[0]=CMD0_READ; /* "read frames", old drives */
  7958. -      
  7959. -      if (DriveStruct[d].drv_type>=drv_201)
  7960. -        {
  7961. -          lba2msf(block,&drvcmd[1]); /* msf-bcd format required */
  7962. -          bin2bcdx(&drvcmd[1]);
  7963. -          bin2bcdx(&drvcmd[2]);
  7964. -          bin2bcdx(&drvcmd[3]);
  7965. -        }
  7966. -      else
  7967. -        {
  7968. -          drvcmd[1]=(block>>16)&0x000000ff;
  7969. -          drvcmd[2]=(block>>8)&0x000000ff;
  7970. -          drvcmd[3]=block&0x000000ff;
  7971. -        }
  7972. -      drvcmd[4]=0;
  7973. -      drvcmd[5]=DriveStruct[d].sbp_read_frames;
  7974. -      drvcmd[6]=(DriveStruct[d].drv_type<drv_201)?0:2; /* flag "lba or msf-bcd format" */
  7975. +    
  7976. +    flags_cmd_out = f_putcmd | f_respo2 | f_ResponseStatus | f_obey_p_check;
  7977. +    clr_cmdbuf();
  7978. +    if (fam0L_drive)
  7979. +    {
  7980. +        flags_cmd_out |= f_lopsta | f_getsta | f_bit1;
  7981. +        if (D_S[d].xa_byte==0x20)
  7982. +        {
  7983. +            cmd_type=READ_M2;
  7984. +            drvcmd[0]=CMD0_READ_XA; /* "read XA frames", old drives */
  7985. +            drvcmd[1]=(block>>16)&0x000000ff;
  7986. +            drvcmd[2]=(block>>8)&0x000000ff;
  7987. +            drvcmd[3]=block&0x000000ff;
  7988. +            drvcmd[5]=D_S[d].sbp_read_frames;
  7989. +        }
  7990. +        else
  7991. +        {
  7992. +            drvcmd[0]=CMD0_READ; /* "read frames", old drives */
  7993. +            if (D_S[d].drv_type>=drv_201)
  7994. +            {
  7995. +                lba2msf(block,&drvcmd[1]); /* msf-bcd format required */
  7996. +                bin2bcdx(&drvcmd[1]);
  7997. +                bin2bcdx(&drvcmd[2]);
  7998. +                bin2bcdx(&drvcmd[3]);
  7999. +            }
  8000. +            else
  8001. +            {
  8002. +                drvcmd[1]=(block>>16)&0x000000ff;
  8003. +                drvcmd[2]=(block>>8)&0x000000ff;
  8004. +                drvcmd[3]=block&0x000000ff;
  8005. +            }
  8006. +            drvcmd[5]=D_S[d].sbp_read_frames;
  8007. +            drvcmd[6]=(D_S[d].drv_type<drv_201)?0:2; /* flag "lba or msf-bcd format" */
  8008. +        }
  8009.      }
  8010. -    }
  8011. -  else if (fam1_drive)
  8012. -    {
  8013. -      drvcmd[0]=CMD1_READ;
  8014. -      lba2msf(block,&drvcmd[1]); /* msf-bin format required */
  8015. -      drvcmd[4]=0;
  8016. -      drvcmd[5]=0;
  8017. -      drvcmd[6]=DriveStruct[d].sbp_read_frames;
  8018. -    }
  8019. -  else if (fam2_drive)
  8020. -    {
  8021. -      drvcmd[0]=CMD2_READ;
  8022. -      lba2msf(block,&drvcmd[1]); /* msf-bin format required */
  8023. -      drvcmd[4]=0;
  8024. -      drvcmd[5]=DriveStruct[d].sbp_read_frames;
  8025. -      drvcmd[6]=0x02;
  8026. -    }
  8027. -  SBPCD_CLI;
  8028. -  for (i=0;i<7;i++) OUT(CDo_command,drvcmd[i]);
  8029. -  SBPCD_STI;
  8030. -
  8031. -  return;
  8032. +    else if (fam1_drive)
  8033. +    {
  8034. +        drvcmd[0]=CMD1_READ;
  8035. +        lba2msf(block,&drvcmd[1]); /* msf-bin format required */
  8036. +        drvcmd[6]=D_S[d].sbp_read_frames;
  8037. +    }
  8038. +    else if (fam2_drive)
  8039. +    {
  8040. +        drvcmd[0]=CMD2_READ;
  8041. +        lba2msf(block,&drvcmd[1]); /* msf-bin format required */
  8042. +        drvcmd[5]=D_S[d].sbp_read_frames;
  8043. +        drvcmd[6]=0x02;
  8044. +    }
  8045. +    else if (famT_drive)
  8046. +    {
  8047. +        drvcmd[0]=CMDT_READ;
  8048. +        drvcmd[2]=(block>>24)&0x0ff;
  8049. +        drvcmd[3]=(block>>16)&0x0ff;
  8050. +        drvcmd[4]=(block>>8)&0x0ff;
  8051. +        drvcmd[5]=block&0x0ff;
  8052. +        drvcmd[7]=(D_S[d].sbp_read_frames>>8)&0x0ff;
  8053. +        drvcmd[8]=D_S[d].sbp_read_frames&0x0ff;
  8054. +    }
  8055. +#ifdef OLD
  8056. +    SBPCD_CLI;
  8057. +    for (i=0;i<7;i++) OUT(CDo_command,drvcmd[i]);
  8058. +    if (famT_drive) for (i=7;i<10;i++) OUT(CDo_command,drvcmd[i]);
  8059. +    SBPCD_STI;
  8060. +#else
  8061. +    flags_cmd_out=f_putcmd;
  8062. +    response_count=0;
  8063. +    i=cmd_out(); /* immediate return here - read data "ourselves" */
  8064. +    if (i<0) msg(DBG_INF,"error giving READ command: %0d\n", i);
  8065. +#endif OLD
  8066. +    return;
  8067.  }
  8068.  /*==========================================================================*/
  8069.  /*
  8070.   *  Check the completion of the read-data command.  On success, read
  8071. - *  the SBP_BUFFER_FRAMES * 2048 bytes of data from the disk into buffer.
  8072. + *  the D_S[d].sbp_bufsiz * 2048 bytes of data from the disk into buffer.
  8073.   */
  8074.  static int sbp_data(void)
  8075.  {
  8076. -  int i=0, j=0, frame;
  8077. -  u_int try=0;
  8078. -  u_long timeout;
  8079. -  u_char *p;
  8080. -  u_int data_tries = 0;
  8081. -  u_int data_waits = 0;
  8082. -  u_int data_retrying = 0;
  8083. -  int error_flag;
  8084. -  int xa_count;
  8085. -  error_flag=0;
  8086. -
  8087. -  for (frame=DriveStruct[d].sbp_current;frame<DriveStruct[d].sbp_read_frames&&!error_flag; frame++)
  8088. -    {
  8089. -      SBPCD_CLI;
  8090. -      try=maxtim_data;
  8091. +    int i=0, j=0, l, frame;
  8092. +    u_int try=0;
  8093. +    u_long timeout;
  8094. +    u_char *p;
  8095. +    u_int data_tries = 0;
  8096. +    u_int data_waits = 0;
  8097. +    u_int data_retrying = 0;
  8098. +    int error_flag;
  8099. +    int xa_count;
  8100. +    int max_latency;
  8101. +    int success;
  8102. +    int wait;
  8103. +    int duration;
  8104. +    
  8105. +    error_flag=0;
  8106. +    success=0;
  8107.  #if LONG_TIMING
  8108. -      for (timeout=jiffies+900; ; )
  8109. +    max_latency=900;
  8110.  #else
  8111. -      for (timeout=jiffies+ ( (famL_drive)? 300:100 ); ; )
  8112. -#endif
  8113. -    {
  8114. -      for ( ; try!=0;try--)
  8115. -        {
  8116. -          j=inb(CDi_status);
  8117. -          if (!(j&s_not_data_ready)) break;
  8118. -          if (!(j&s_not_result_ready)) break;
  8119. -          if (fam0L_drive) if (j&s_attention) break;
  8120. -        }
  8121. -      if (try != 0 || timeout <= jiffies) break;
  8122. -      if (data_retrying == 0) data_waits++;
  8123. -      data_retrying = 1;
  8124. -      sbp_sleep(1);
  8125. -      try = 1;
  8126. -    }
  8127. -      if (try==0)
  8128. -    {
  8129. -      DPRINTF((DBG_INF,"SBPCD: sbp_data: CDi_status timeout.\n"));
  8130. -      error_flag++;
  8131. -      break;
  8132. -    }
  8133. -
  8134. -      if (j&s_not_data_ready)
  8135. -    {
  8136. -      if ((DriveStruct[d].ored_ctl_adr&0x40)==0)
  8137. -        printk("SBPCD: CD contains no data tracks.\n");
  8138. -      else printk("SBPCD: sbp_data: DATA_READY timeout.\n");
  8139. -      error_flag++;
  8140. -      break;
  8141. -    }
  8142. -
  8143. -      SBPCD_STI;
  8144. -      error_flag=0;
  8145. -      p = DriveStruct[d].sbp_buf + frame *  CD_FRAMESIZE;
  8146. -
  8147. -      if (sbpro_type==1) OUT(CDo_sel_i_d,1);
  8148. -      if (cmd_type==READ_M2) READ_DATA(CDi_data, xa_head_buf, CD_XA_HEAD);
  8149. -      READ_DATA(CDi_data, p, CD_FRAMESIZE);
  8150. -      if (cmd_type==READ_M2) READ_DATA(CDi_data, xa_tail_buf, CD_XA_TAIL);
  8151. -      if (sbpro_type==1) OUT(CDo_sel_i_d,0);
  8152. -      DriveStruct[d].sbp_current++;
  8153. -      if (cmd_type==READ_M2)
  8154. -    {
  8155. -      DPRINTF((DBG_XA,"SBPCD: xa_head:"));
  8156. -      for (xa_count=0;xa_count<CD_XA_HEAD;xa_count++)
  8157. -        DPRINTF((DBG_XA," %02X", xa_head_buf[xa_count]));
  8158. -      DPRINTF((DBG_XA,"\n"));
  8159. -    }
  8160. -      data_tries++;
  8161. -      data_retrying = 0;
  8162. -      if (data_tries >= 1000)
  8163. -    {
  8164. -      DPRINTF((DBG_INF,"SBPCD: info: %d waits in %d frames.\n",
  8165. -                data_waits, data_tries));
  8166. -      data_waits = data_tries = 0;
  8167. +    if (D_S[d].f_multisession) max_latency=900;
  8168. +    else if (fam0L_drive) max_latency=300;
  8169. +    else if (famT_drive) max_latency=300;
  8170. +    else max_latency=100;
  8171. +#endif
  8172. +    msg(DBG_TE2,"beginning to READ\n");
  8173. +    duration=jiffies;
  8174. +    for (frame=0;frame<D_S[d].sbp_read_frames&&!error_flag; frame++)
  8175. +    {
  8176. +        SBPCD_CLI;
  8177. +        
  8178. +        del_timer(&data_timer);
  8179. +        data_timer.expires=max_latency;
  8180. +        timed_out_data=0;
  8181. +        add_timer(&data_timer);
  8182. +        while (!timed_out_data) 
  8183. +        {
  8184. +            if (D_S[d].f_multisession) try=maxtim_data*4;
  8185. +            else try=maxtim_data;
  8186. +            msg(DBG_000,"sbp_data: CDi_status loop: try=%d.\n",try);
  8187. +            for ( ; try!=0;try--)
  8188. +            {
  8189. +                j=inb(CDi_status);
  8190. +                if (!(j&s_not_data_ready)) break;;
  8191. +                if (!(j&s_not_result_ready)) break;
  8192. +                if (fam0L_drive) if (j&s_attention) break;
  8193. +            }
  8194. +            if (!(j&s_not_data_ready)) goto data_ready;
  8195. +            if (try==0)
  8196. +            {
  8197. +                if (data_retrying == 0) data_waits++;
  8198. +                data_retrying = 1;
  8199. +                msg(DBG_000,"sbp_data: CDi_status loop: sleeping.\n");
  8200. +                sbp_sleep(1);
  8201. +                try = 1;
  8202. +            }
  8203. +        }
  8204. +        msg(DBG_INF,"sbp_data: CDi_status loop expired.\n");
  8205. +    data_ready:
  8206. +        del_timer(&data_timer);
  8207. +
  8208. +        if (timed_out_data)
  8209. +        {
  8210. +            msg(DBG_INF,"sbp_data: CDi_status timeout (timed_out_data) (%02X).\n", j);
  8211. +            error_flag++;
  8212. +            break;
  8213. +        }
  8214. +        if (try==0)
  8215. +        {
  8216. +            msg(DBG_INF,"sbp_data: CDi_status timeout (try=0) (%02X).\n", j);
  8217. +            error_flag++;
  8218. +            break;
  8219. +        }
  8220. +        if (!(j&s_not_result_ready))
  8221. +        {
  8222. +            msg(DBG_INF, "sbp_data: RESULT_READY where DATA_READY awaited (%02X).\n", j);
  8223. +            response_count=20;
  8224. +            j=ResponseInfo();
  8225. +            j=inb(CDi_status);
  8226. +        }
  8227. +        if (j&s_not_data_ready)
  8228. +        {
  8229. +            if ((D_S[d].ored_ctl_adr&0x40)==0)
  8230. +                msg(DBG_INF, "CD contains no data tracks.\n");
  8231. +            else msg(DBG_INF, "sbp_data: DATA_READY timeout (%02X).\n", j);
  8232. +            error_flag++;
  8233. +            break;
  8234. +        }
  8235. +        SBPCD_STI;
  8236. +        error_flag=0;
  8237. +        msg(DBG_000, "sbp_data: beginning to read.\n");
  8238. +        p = D_S[d].sbp_buf + frame *  CD_FRAMESIZE;
  8239. +        if (sbpro_type==1) OUT(CDo_sel_i_d,1);
  8240. +        if (cmd_type==READ_M2) insb(CDi_data, xa_head_buf, CD_XA_HEAD);
  8241. +        insb(CDi_data, p, CD_FRAMESIZE);
  8242. +        if (cmd_type==READ_M2) insb(CDi_data, xa_tail_buf, CD_XA_TAIL);
  8243. +        if (famT_drive)    msg(DBG_TE2, "================frame read=================.\n");
  8244. +        D_S[d].sbp_current++;
  8245. +        if (sbpro_type==1) OUT(CDo_sel_i_d,0);
  8246. +        if (cmd_type==READ_M2)
  8247. +        {
  8248. +            for (xa_count=0;xa_count<CD_XA_HEAD;xa_count++)
  8249. +                sprintf(&msgbuf[xa_count*3], " %02X", xa_head_buf[xa_count]);
  8250. +            msgbuf[xa_count*3]=0;
  8251. +            msg(DBG_XA1,"xa head:%s\n", msgbuf);
  8252. +        }
  8253. +        data_retrying = 0;
  8254. +        data_tries++;
  8255. +        if (data_tries >= 1000)
  8256. +        {
  8257. +            msg(DBG_INF,"sbp_data() statistics: %d waits in %d frames.\n", data_waits, data_tries);
  8258. +            data_waits = data_tries = 0;
  8259. +        }
  8260.      }
  8261. -    }
  8262. -  SBPCD_STI;
  8263. -  
  8264. -  if (error_flag)    /* must have been spurious D_RDY or (ATTN&&!D_RDY) */
  8265. -    {
  8266. -      DPRINTF((DBG_INF,"SBPCD: read aborted by drive\n"));
  8267. +    duration=jiffies-duration;
  8268. +    msg(DBG_TE2,"time to read %d frames: %d jiffies .\n",frame,duration);
  8269. +    if (famT_drive)
  8270. +    {
  8271. +        wait=8;
  8272. +        do
  8273. +        {
  8274. +            sbp_sleep(1);
  8275. +            OUT(CDo_sel_i_d,0);
  8276. +            i=inb(CDi_status);
  8277. +            if (!(i&s_not_data_ready))
  8278. +            {
  8279. +                OUT(CDo_sel_i_d,1);
  8280. +                j=0;
  8281. +                do
  8282. +                {
  8283. +                    i=inb(CDi_data);
  8284. +                    j++;
  8285. +                    i=inb(CDi_status);
  8286. +                }
  8287. +                while (!(i&s_not_data_ready));
  8288. +                msg(DBG_TEA, "=============too much data (%d bytes)=================.\n", j);
  8289. +            }
  8290. +            if (!(i&s_not_result_ready))
  8291. +            {
  8292. +                OUT(CDo_sel_i_d,0);
  8293. +                l=0;
  8294. +                do
  8295. +                {
  8296. +                    infobuf[l++]=inb(CDi_info);
  8297. +                    i=inb(CDi_status);
  8298. +                }
  8299. +                while (!(i&s_not_result_ready));
  8300. +                if (infobuf[0]==0x00) success=1;
  8301. +#if 1
  8302. +                for (j=0;j<l;j++) sprintf(&msgbuf[j*3], " %02X", infobuf[j]);
  8303. +                msgbuf[j*3]=0;
  8304. +                msg(DBG_TE2,"sbp_data info response:%s\n", msgbuf);
  8305. +#endif
  8306. +                if (infobuf[0]==0x02)
  8307. +                {
  8308. +                    error_flag++;
  8309. +                    do
  8310. +                    {
  8311. +                        ++recursion;
  8312. +                        if (recursion>1) msg(DBG_TEA,"cmd_out_T READ_ERR recursion (sbp_data): %d !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n",recursion);
  8313. +                        else msg(DBG_TEA,"sbp_data: CMDT_READ_ERR necessary.\n");
  8314. +                        clr_cmdbuf();
  8315. +                        drvcmd[0]=CMDT_READ_ERR;
  8316. +                        j=cmd_out_T(); /* !!! recursive here !!! */
  8317. +                        --recursion;
  8318. +                        sbp_sleep(1);
  8319. +                    }
  8320. +                    while (j<0);
  8321. +                    D_S[d].error_state=infobuf[2];
  8322. +                    D_S[d].b3=infobuf[3];
  8323. +                    D_S[d].b4=infobuf[4];
  8324. +                }
  8325. +                break;
  8326. +            }
  8327. +            else
  8328. +            {
  8329.  #if 0
  8330. -      i=DriveReset();                /* ugly fix to prevent a hang */
  8331. -#else
  8332. -      i=xx_ReadError();
  8333. +                msg(DBG_TEA, "============= waiting for result=================.\n");
  8334. +                sbp_sleep(1);
  8335.  #endif
  8336. -      return (0);
  8337. -    }
  8338. -
  8339. -  if (fam0L_drive)
  8340. -    {
  8341. -      SBPCD_CLI;
  8342. -      i=maxtim_data;
  8343. -      for (timeout=jiffies+100; timeout > jiffies; timeout--)
  8344. -    {
  8345. -      for ( ;i!=0;i--)
  8346. -        {
  8347. -          j=inb(CDi_status);
  8348. -          if (!(j&s_not_data_ready)) break;
  8349. -          if (!(j&s_not_result_ready)) break;
  8350. -          if (j&s_attention) break;
  8351. -        }
  8352. -      if (i != 0 || timeout <= jiffies) break;
  8353. -      sbp_sleep(0);
  8354. -      i = 1;
  8355. -    }
  8356. -      if (i==0) { DPRINTF((DBG_INF,"SBPCD: STATUS TIMEOUT AFTER READ")); }
  8357. -      if (!(j&s_attention))
  8358. -    {
  8359. -      DPRINTF((DBG_INF,"SBPCD: sbp_data: timeout waiting DRV_ATTN - retrying\n"));
  8360. -      i=DriveReset();  /* ugly fix to prevent a hang */
  8361. -      SBPCD_STI;
  8362. -      return (0);
  8363. +            }
  8364. +        }
  8365. +        while (wait--);
  8366.      }
  8367. -      SBPCD_STI;
  8368. -    }
  8369.  
  8370. -  do
  8371. -    {
  8372. -      if (fam0L_drive) xx_ReadStatus();
  8373. -      i=ResponseStatus();  /* builds status_byte, returns orig. status (old) or faked p_success_old (new) */
  8374. -      if (i<0) { DPRINTF((DBG_INF,"SBPCD: xx_ReadStatus error after read: %02X\n",
  8375. -                   DriveStruct[d].status_byte));
  8376. -         return (0);
  8377. -           }
  8378. -    }
  8379. -  while ((fam0L_drive)&&(!st_check)&&(!(i&p_success_old)));
  8380. -  if (st_check)
  8381. -    {
  8382. -      i=xx_ReadError();
  8383. -      DPRINTF((DBG_INF,"SBPCD: xx_ReadError was necessary after read: %02X\n",i));
  8384. -      return (0);
  8385. -    }
  8386. -
  8387. -  DriveStruct[d].sbp_first_frame = CURRENT -> sector / 4;
  8388. -  DriveStruct[d].sbp_last_frame = DriveStruct[d].sbp_first_frame + DriveStruct[d].sbp_read_frames - 1;
  8389. -  sbp_transfer();
  8390. -  return (1);
  8391. +    if (error_flag) /* must have been spurious D_RDY or (ATTN&&!D_RDY) */
  8392. +    {
  8393. +        msg(DBG_TEA, "================error flag: %d=================.\n", error_flag);
  8394. +        msg(DBG_INF,"sbp_data: read aborted by drive.\n");
  8395. +#if 1
  8396. +        i=cc_DriveReset(); /* ugly fix to prevent a hang */
  8397. +#else
  8398. +        i=cc_ReadError();
  8399. +#endif
  8400. +        return (0);
  8401. +    }
  8402. +    
  8403. +    if (fam0L_drive)
  8404. +    {
  8405. +        SBPCD_CLI;
  8406. +        i=maxtim_data;
  8407. +        for (timeout=jiffies+100; timeout > jiffies; timeout--)
  8408. +        {
  8409. +            for ( ;i!=0;i--)
  8410. +            {
  8411. +                j=inb(CDi_status);
  8412. +                if (!(j&s_not_data_ready)) break;
  8413. +                if (!(j&s_not_result_ready)) break;
  8414. +                if (j&s_attention) break;
  8415. +            }
  8416. +            if (i != 0 || timeout <= jiffies) break;
  8417. +            sbp_sleep(0);
  8418. +            i = 1;
  8419. +        }
  8420. +        if (i==0) msg(DBG_INF,"status timeout after READ.\n");
  8421. +        if (!(j&s_attention))
  8422. +        {
  8423. +            msg(DBG_INF,"sbp_data: timeout waiting DRV_ATTN - retrying.\n");
  8424. +            i=cc_DriveReset();  /* ugly fix to prevent a hang */
  8425. +            SBPCD_STI;
  8426. +            return (0);
  8427. +        }
  8428. +        SBPCD_STI;
  8429. +    }
  8430. +    
  8431. +#if 0
  8432. +    if (!success)
  8433. +#endif 0
  8434. +        do
  8435. +        {
  8436. +            if (fam0L_drive) cc_ReadStatus();
  8437. +#if 1
  8438. +            if (famT_drive) msg(DBG_TE2, "================before ResponseStatus=================.\n", i);
  8439. +#endif 1
  8440. +            i=ResponseStatus();  /* builds status_bits, returns orig. status (old) or faked p_success (new) */
  8441. +#if 1
  8442. +            if (famT_drive)    msg(DBG_TE2, "================ResponseStatus: %d=================.\n", i);
  8443. +#endif 1
  8444. +            if (i<0)
  8445. +            {
  8446. +                msg(DBG_INF,"bad cc_ReadStatus after read: %02X\n", D_S[d].status_bits);
  8447. +                return (0);
  8448. +            }
  8449. +        }
  8450. +        while ((fam0L_drive)&&(!st_check)&&(!(i&p_success)));
  8451. +    if (st_check)
  8452. +    {
  8453. +        i=cc_ReadError();
  8454. +        msg(DBG_INF,"cc_ReadError was necessary after read: %d\n",i);
  8455. +        return (0);
  8456. +    }
  8457. +    if (fatal_err)
  8458. +    {
  8459. +        fatal_err=0;
  8460. +        D_S[d].sbp_first_frame=D_S[d].sbp_last_frame=-1;      /* purge buffer */
  8461. +        D_S[d].sbp_current = 0;
  8462. +        msg(DBG_INF,"sbp_data: fatal_err - retrying.\n");
  8463. +        return (0);
  8464. +    }
  8465. +    
  8466. +    D_S[d].sbp_first_frame = CURRENT -> sector / 4;
  8467. +    D_S[d].sbp_last_frame = D_S[d].sbp_first_frame + D_S[d].sbp_read_frames - 1;
  8468. +    sbp_transfer();
  8469. +#if 1
  8470. +    if (famT_drive)    msg(DBG_TE2, "================sbp_transfer() done=================.\n");
  8471. +#endif 1
  8472. +    return (1);
  8473.  }
  8474.  /*==========================================================================*/
  8475.  /*==========================================================================*/
  8476. @@ -3934,71 +4802,83 @@
  8477.   */
  8478.  static int sbpcd_open(struct inode *ip, struct file *fp)
  8479.  {
  8480. -  int i;
  8481. -
  8482. -  i = MINOR(ip->i_rdev);
  8483. -  if ((i<0) || (i>=NR_SBPCD) || (DriveStruct[i].drv_id==-1))
  8484. -    {
  8485. -      printk("SBPCD: open: bad device: %04X\n", ip->i_rdev);
  8486. -      return (-ENXIO);             /* no such drive */
  8487. -    }
  8488. -  if (fp->f_mode & 2)
  8489. -      return -EROFS;
  8490. -  
  8491. -  switch_drive(i);
  8492. -
  8493. -  flags_cmd_out |= f_respo2;
  8494. -  xx_ReadStatus();                         /* command: give 1-byte status */
  8495. -  i=ResponseStatus();
  8496. -  if (!st_door_closed)
  8497. -    {
  8498. -      yy_CloseTray();
  8499. -      flags_cmd_out |= f_respo2;
  8500. -      xx_ReadStatus();
  8501. -      i=ResponseStatus();
  8502. -    }
  8503. -  if (!st_spinning)
  8504. -    {
  8505. -      xx_SpinUp();
  8506. -      flags_cmd_out |= f_respo2;
  8507. -      xx_ReadStatus();
  8508. -      i=ResponseStatus();
  8509. -    }
  8510. -  if (i<0)
  8511. -    {
  8512. -      DPRINTF((DBG_INF,"SBPCD: sbpcd_open: xx_ReadStatus timed out\n"));
  8513. -      return (-EIO);                  /* drive doesn't respond */
  8514. -    }
  8515. -  DPRINTF((DBG_STA,"SBPCD: sbpcd_open: status %02X\n", DriveStruct[d].status_byte));
  8516. -  if (!st_door_closed||!st_caddy_in)
  8517. -    {
  8518. -      printk("SBPCD: sbpcd_open: no disk in drive\n");
  8519. +    int i;
  8520. +    
  8521. +    i = MINOR(ip->i_rdev);
  8522. +    if ((i<0) || (i>=NR_SBPCD) || (D_S[i].drv_id==-1))
  8523. +    {
  8524. +        msg(DBG_INF, "open: bad device: %04X\n", ip->i_rdev);
  8525. +        return (-ENXIO);             /* no such drive */
  8526. +    }
  8527. +    if (fp->f_mode & 2)
  8528. +        return -EROFS;
  8529. +    
  8530. +    switch_drive(i);
  8531. +    
  8532. +    i=cc_ReadError();
  8533. +    flags_cmd_out |= f_respo2;
  8534. +    cc_ReadStatus();                         /* command: give 1-byte status */
  8535. +    i=ResponseStatus();
  8536. +    if (famT_drive&&(i<0))
  8537. +    {
  8538. +        cc_DriveReset();
  8539. +        i=ResponseStatus();
  8540. +    }
  8541. +    if (i<0)
  8542. +    {
  8543. +        msg(DBG_INF,"sbpcd_open: ResponseStatus timed out (%d).\n",i);
  8544. +        return (-EIO);                  /* drive doesn't respond */
  8545. +    }
  8546. +    if (famT_drive)    msg(DBG_TE2,"sbpcd_open: ResponseStatus=%02X\n", i);
  8547. +    if (!st_door_closed)
  8548. +    {
  8549. +        if (famT_drive)    msg(DBG_TE2,"sbpcd_open: !st_door_closed.\n");
  8550. +        cc_CloseTray();
  8551. +        flags_cmd_out |= f_respo2;
  8552. +        cc_ReadStatus();
  8553. +        i=ResponseStatus();
  8554. +    }
  8555. +    if (!(famT_drive))
  8556. +        if (!st_spinning)
  8557. +        {
  8558. +            if (famT_drive)    msg(DBG_TE2,"sbpcd_open: !st_spinning.\n");
  8559. +            cc_SpinUp();
  8560. +            flags_cmd_out |= f_respo2;
  8561. +            cc_ReadStatus();
  8562. +            i=ResponseStatus();
  8563. +        }
  8564. +    if (famT_drive)    msg(DBG_TE2,"sbpcd_open: status %02X\n", D_S[d].status_bits);
  8565. +    if (!st_door_closed||!st_caddy_in)
  8566. +    {
  8567. +        msg(DBG_INF, "sbpcd_open: no disk in drive.\n");
  8568. +        D_S[d].open_count=0;
  8569.  #if JUKEBOX
  8570. -      do
  8571. -    i=yy_LockDoor(0);
  8572. -      while (i!=0);
  8573. -      if (!fam0_drive) yy_SpinDown(); /* eject tray */
  8574. +        if (!fam0_drive)
  8575. +        {
  8576. +            i=UnLockDoor();
  8577. +            cc_SpinDown(); /* eject tray */
  8578. +        }
  8579.  #endif
  8580. -      return (-ENXIO);
  8581. -    }
  8582. -/*
  8583. - * try to keep an "open" counter here and lock the door if 0->1.
  8584. - */
  8585. -  MOD_INC_USE_COUNT;
  8586. -  DPRINTF((DBG_LCK,"SBPCD: open_count: %d -> %d\n",
  8587. -       DriveStruct[d].open_count,DriveStruct[d].open_count+1));
  8588. -  if (++DriveStruct[d].open_count==1)
  8589. -    {
  8590. -      do
  8591. -    i=yy_LockDoor(1);
  8592. -      while (i!=0);
  8593. -    }
  8594. -  if (!st_spinning) xx_SpinUp();
  8595. -
  8596. -  i=DiskInfo();
  8597. -  if ((DriveStruct[d].ored_ctl_adr&0x40)==0)
  8598. -    DPRINTF((DBG_INF,"SBPCD: CD contains no data tracks.\n"));
  8599. -  return (0);
  8600. +        return (-ENXIO);
  8601. +    }
  8602. +    /*
  8603. +     * try to keep an "open" counter here and lock the door if 0->1.
  8604. +     */
  8605. +    MOD_INC_USE_COUNT;
  8606. +    msg(DBG_LCK,"open_count: %d -> %d\n",
  8607. +        D_S[d].open_count,D_S[d].open_count+1);
  8608. +    if (++D_S[d].open_count<=1)
  8609. +    {
  8610. +        i=LockDoor();
  8611. +        D_S[d].open_count=1;
  8612. +        if (famT_drive)    msg(DBG_TE2,"sbpcd_open: before i=DiskInfo();.\n");
  8613. +        i=DiskInfo();
  8614. +        if (famT_drive)    msg(DBG_TE2,"sbpcd_open: after i=DiskInfo();.\n");
  8615. +        if ((D_S[d].ored_ctl_adr&0x40)==0)
  8616. +            msg(DBG_INF,"CD contains no data tracks.\n");
  8617. +    }
  8618. +    if (!st_spinning) cc_SpinUp();
  8619. +    return (0);
  8620.  }
  8621.  /*==========================================================================*/
  8622.  /*
  8623. @@ -4006,37 +4886,37 @@
  8624.   */
  8625.  static void sbpcd_release(struct inode * ip, struct file * file)
  8626.  {
  8627. -  int i;
  8628. -
  8629. -  i = MINOR(ip->i_rdev);
  8630. -  if ((i<0) || (i>=NR_SBPCD) || (DriveStruct[i].drv_id==-1))
  8631. -    {
  8632. -      printk("SBPCD: release: bad device: %04X\n", ip->i_rdev);
  8633. -      return;
  8634. -    }
  8635. -  switch_drive(i);
  8636. -
  8637. -  DriveStruct[d].sbp_first_frame=DriveStruct[d].sbp_last_frame=-1;
  8638. -  sync_dev(ip->i_rdev);                   /* nonsense if read only device? */
  8639. -  invalidate_buffers(ip->i_rdev);
  8640. -
  8641. -/*
  8642. - * try to keep an "open" counter here and unlock the door if 1->0.
  8643. - */
  8644. -  MOD_DEC_USE_COUNT;
  8645. -  DPRINTF((DBG_LCK,"SBPCD: open_count: %d -> %d\n",
  8646. -       DriveStruct[d].open_count,DriveStruct[d].open_count-1));
  8647. -  if (DriveStruct[d].open_count!=0) /* CDROMEJECT may have been done */
  8648. -    {
  8649. -      if (--DriveStruct[d].open_count==0) 
  8650. -    {
  8651. -      do
  8652. -        i=yy_LockDoor(0);
  8653. -      while (i!=0);
  8654. -      if (DriveStruct[d].f_eject) yy_SpinDown();
  8655. -      DriveStruct[d].diskstate_flags &= ~cd_size_bit;
  8656. +    int i;
  8657. +    
  8658. +    i = MINOR(ip->i_rdev);
  8659. +    if ((i<0) || (i>=NR_SBPCD) || (D_S[i].drv_id==-1))
  8660. +    {
  8661. +        msg(DBG_INF, "release: bad device: %04X\n", ip->i_rdev);
  8662. +        return;
  8663. +    }
  8664. +    switch_drive(i);
  8665. +    
  8666. +    D_S[d].sbp_first_frame=D_S[d].sbp_last_frame=-1;
  8667. +    sync_dev(ip->i_rdev);                   /* nonsense if read only device? */
  8668. +    invalidate_buffers(ip->i_rdev);
  8669. +    
  8670. +    /*
  8671. +     * try to keep an "open" counter here and unlock the door if 1->0.
  8672. +     */
  8673. +    MOD_DEC_USE_COUNT;
  8674. +    msg(DBG_LCK,"open_count: %d -> %d\n",
  8675. +        D_S[d].open_count,D_S[d].open_count-1);
  8676. +    if (D_S[d].open_count>-2) /* CDROMEJECT may have been done */
  8677. +    {
  8678. +        if (--D_S[d].open_count<=0) 
  8679. +        {
  8680. +            i=UnLockDoor();
  8681. +            if (D_S[d].audio_state!=audio_playing)
  8682. +                if (D_S[d].f_eject) cc_SpinDown();
  8683. +            D_S[d].diskstate_flags &= ~cd_size_bit;
  8684. +            D_S[d].open_count=0; 
  8685. +        }
  8686.      }
  8687. -    }
  8688.  }
  8689.  /*==========================================================================*/
  8690.  /*
  8691. @@ -4044,19 +4924,19 @@
  8692.   */
  8693.  static struct file_operations sbpcd_fops =
  8694.  {
  8695. -  NULL,                   /* lseek - default */
  8696. -  block_read,             /* read - general block-dev read */
  8697. -  block_write,            /* write - general block-dev write */
  8698. -  NULL,                   /* readdir - bad */
  8699. -  NULL,                   /* select */
  8700. -  sbpcd_ioctl,            /* ioctl */
  8701. -  NULL,                   /* mmap */
  8702. -  sbpcd_open,             /* open */
  8703. -  sbpcd_release,          /* release */
  8704. -  NULL,                   /* fsync */
  8705. -  NULL,                   /* fasync */
  8706. -  sbpcd_chk_disk_change,  /* media_change */
  8707. -  NULL                    /* revalidate */
  8708. +    NULL,                   /* lseek - default */
  8709. +    block_read,             /* read - general block-dev read */
  8710. +    block_write,            /* write - general block-dev write */
  8711. +    NULL,                   /* readdir - bad */
  8712. +    NULL,                   /* select */
  8713. +    sbpcd_ioctl,            /* ioctl */
  8714. +    NULL,                   /* mmap */
  8715. +    sbpcd_open,             /* open */
  8716. +    sbpcd_release,          /* release */
  8717. +    NULL,                   /* fsync */
  8718. +    NULL,                   /* fasync */
  8719. +    sbpcd_chk_disk_change,  /* media_change */
  8720. +    NULL                    /* revalidate */
  8721.  };
  8722.  /*==========================================================================*/
  8723.  /*
  8724. @@ -4084,82 +4964,80 @@
  8725.  #endif
  8726.  void sbpcd_setup(char *s, int *p)
  8727.  {
  8728. -  setup_done++;
  8729. -  DPRINTF((DBG_INI,"SBPCD: sbpcd_setup called with %04X,%s\n",p[1], s));
  8730. -  sbpro_type=0;
  8731. -  if (!strcmp(s,str_sb)) sbpro_type=1;
  8732. -  else if (!strcmp(s,str_sb_l)) sbpro_type=1;
  8733. -  else if (!strcmp(s,str_sp)) sbpro_type=2;
  8734. -  else if (!strcmp(s,str_sp_l)) sbpro_type=2;
  8735. -  if (p[0]>0) sbpcd_ioaddr=p[1];
  8736. -
  8737. -  CDo_command=sbpcd_ioaddr;
  8738. -  CDi_info=sbpcd_ioaddr;
  8739. -  CDi_status=sbpcd_ioaddr+1;
  8740. -  CDo_sel_i_d=sbpcd_ioaddr+1;
  8741. -  CDo_reset=sbpcd_ioaddr+2;
  8742. -  CDo_enable=sbpcd_ioaddr+3; 
  8743. -  if (sbpro_type==1)
  8744. -    {
  8745. -      MIXER_addr=sbpcd_ioaddr-0x10+0x04;
  8746. -      MIXER_data=sbpcd_ioaddr-0x10+0x05;
  8747. -      CDi_data=sbpcd_ioaddr;
  8748. -    }
  8749. -  else CDi_data=sbpcd_ioaddr+2;
  8750. +    setup_done++;
  8751. +    msg(DBG_INI,"sbpcd_setup called with %04X,%s\n",p[1], s);
  8752. +    sbpro_type=0;
  8753. +    if (!strcmp(s,str_sb)) sbpro_type=1;
  8754. +    else if (!strcmp(s,str_sb_l)) sbpro_type=1;
  8755. +    else if (!strcmp(s,str_sp)) sbpro_type=2;
  8756. +    else if (!strcmp(s,str_sp_l)) sbpro_type=2;
  8757. +    if (p[0]>0) sbpcd_ioaddr=p[1];
  8758. +    
  8759. +    CDo_command=sbpcd_ioaddr;
  8760. +    CDi_info=sbpcd_ioaddr;
  8761. +    CDi_status=sbpcd_ioaddr+1;
  8762. +    CDo_sel_i_d=sbpcd_ioaddr+1;
  8763. +    CDo_reset=sbpcd_ioaddr+2;
  8764. +    CDo_enable=sbpcd_ioaddr+3; 
  8765. +    if (sbpro_type==1)
  8766. +    {
  8767. +        MIXER_addr=sbpcd_ioaddr-0x10+0x04;
  8768. +        MIXER_data=sbpcd_ioaddr-0x10+0x05;
  8769. +        CDi_data=sbpcd_ioaddr;
  8770. +    }
  8771. +    else CDi_data=sbpcd_ioaddr+2;
  8772.  }
  8773.  /*==========================================================================*/
  8774.  /*
  8775.   * Sequoia S-1000 CD-ROM Interface Configuration
  8776.   * as used within SPEA Media FX card
  8777. - * The SPEA soundcard has to get jumpered for 
  8778. + * The SPEA soundcard has to get configured for 
  8779.   *     -> interface type "Matsushita/Panasonic" (not Sony or Mitsumi)
  8780.   *     -> I/O base address (0x320, 0x330, 0x340, 0x350)
  8781.   */
  8782.  static int config_spea(void)
  8783.  {
  8784. -  int n_ports=0x10; /* 2:0x00, 8:0x10, 16:0x20, 32:0x30 */
  8785. -/* What is n_ports? Number of addresses or base address offset? */
  8786. -  int irq_number=0; /* 2:0x01, 7:0x03, 12:0x05, 15:0x07, OFF:0x00 */
  8787. -  int dma_channel=0; /* 0:0x08, 1:0x18, 3:0x38, 5:0x58, 6:0x68, 7:0x78, OFF: 0x00 */
  8788. -  int dack_polarity=0; /* L:0x00, H:0x80 */
  8789. -  int drq_polarity=0x40; /* L:0x00, H:0x40 */
  8790. -
  8791. -  int i;
  8792. -
  8793. +    int n_ports=0x10; /* 2:0x00, 8:0x10, 16:0x20, 32:0x30 */
  8794. +    /* What is n_ports? Number of addresses or base address offset? */
  8795. +    int irq_number=0; /* 2:0x01, 7:0x03, 12:0x05, 15:0x07, OFF:0x00 */
  8796. +    int dma_channel=0; /* 0:0x08, 1:0x18, 3:0x38, 5:0x58, 6:0x68, 7:0x78, OFF: 0x00 */
  8797. +    int dack_polarity=0; /* L:0x00, H:0x80 */
  8798. +    int drq_polarity=0x40; /* L:0x00, H:0x40 */
  8799. +    
  8800. +    int i;
  8801. +    
  8802.  #define SPEA_REG_1 sbpcd_ioaddr+4
  8803.  #define SPEA_REG_2 sbpcd_ioaddr+5
  8804. -
  8805. -  OUT(SPEA_REG_1,0xFF);
  8806. -  i=inb(SPEA_REG_1);
  8807. -  if (i!=0x0F)
  8808. -    {
  8809. -      DPRINTF((DBG_SEQ,"SBPCD: no SPEA interface at %04X present.\n",
  8810. -           sbpcd_ioaddr));
  8811. -      return (-1); /* no interface found */
  8812. -    }
  8813. -  OUT(SPEA_REG_1,0x04);
  8814. -  OUT(SPEA_REG_2,0xC0);
  8815. -
  8816. -  OUT(SPEA_REG_1,0x05);
  8817. -  OUT(SPEA_REG_2,0x10|drq_polarity|dack_polarity);
  8818. -
  8819. +    
  8820. +    OUT(SPEA_REG_1,0xFF);
  8821. +    i=inb(SPEA_REG_1);
  8822. +    if (i!=0x0F)
  8823. +    {
  8824. +        msg(DBG_SEQ,"no SPEA interface at %04X present.\n", sbpcd_ioaddr);
  8825. +        return (-1); /* no interface found */
  8826. +    }
  8827. +    OUT(SPEA_REG_1,0x04);
  8828. +    OUT(SPEA_REG_2,0xC0);
  8829. +    
  8830. +    OUT(SPEA_REG_1,0x05);
  8831. +    OUT(SPEA_REG_2,0x10|drq_polarity|dack_polarity);
  8832. +    
  8833.  #if 1
  8834.  #define SPEA_PATTERN 0x80
  8835.  #else
  8836.  #define SPEA_PATTERN 0x00
  8837.  #endif
  8838. -  OUT(SPEA_REG_1,0x06);
  8839. -  OUT(SPEA_REG_2,dma_channel|irq_number|SPEA_PATTERN);
  8840. -  OUT(SPEA_REG_2,dma_channel|irq_number|SPEA_PATTERN);
  8841. -
  8842. -  OUT(SPEA_REG_1,0x09);
  8843. -  i=(inb(SPEA_REG_2)&0xCF)|n_ports;
  8844. -  OUT(SPEA_REG_2,i);
  8845. -
  8846. -  sbpro_type = 0; /* acts like a LaserMate interface now */
  8847. -  DPRINTF((DBG_SEQ,"SBPCD: found SPEA interface at %04X.\n",
  8848. -       sbpcd_ioaddr));
  8849. -  return (0);
  8850. +    OUT(SPEA_REG_1,0x06);
  8851. +    OUT(SPEA_REG_2,dma_channel|irq_number|SPEA_PATTERN);
  8852. +    OUT(SPEA_REG_2,dma_channel|irq_number|SPEA_PATTERN);
  8853. +    
  8854. +    OUT(SPEA_REG_1,0x09);
  8855. +    i=(inb(SPEA_REG_2)&0xCF)|n_ports;
  8856. +    OUT(SPEA_REG_2,i);
  8857. +    
  8858. +    sbpro_type = 0; /* acts like a LaserMate interface now */
  8859. +    msg(DBG_SEQ,"found SPEA interface at %04X.\n", sbpcd_ioaddr);
  8860. +    return (0);
  8861.  }
  8862.  /*==========================================================================*/
  8863.  /*
  8864. @@ -4168,261 +5046,261 @@
  8865.  #ifdef MODULE
  8866.  int init_module(void)
  8867.  #else
  8868. -unsigned long SBPCD_INIT(u_long mem_start, u_long mem_end)
  8869. +    unsigned long SBPCD_INIT(u_long mem_start, u_long mem_end)
  8870.  #endif MODULE
  8871.  {
  8872. -  int i=0, j=0;
  8873. -  int addr[2]={1, CDROM_PORT};
  8874. -  int port_index;
  8875. -   
  8876. -  sti(); /* necessary, has consequences for other drivers' init routines */
  8877. -
  8878. -  DPRINTF((DBG_INF,"SBPCD version %s\n", VERSION));
  8879. -
  8880. +    int i=0, j=0;
  8881. +    int addr[2]={1, CDROM_PORT};
  8882. +    int port_index;
  8883. +    
  8884. +    sti();
  8885. +    
  8886. +    msg(DBG_INF,"sbpcd.c %s\n", VERSION);
  8887.  #ifndef MODULE
  8888. -  if (!setup_done)
  8889. -    {
  8890. -      DPRINTF((DBG_INF,"SBPCD: Looking for Matsushita, Panasonic, CreativeLabs, IBM, Longshine CD-ROM drives\n"));
  8891. -      DPRINTF((DBG_WRN,"SBPCD: \n"));
  8892. -      DPRINTF((DBG_WRN,"SBPCD: = = = = = = = = = = W A R N I N G = = = = = = = = = =\n"));
  8893. -      DPRINTF((DBG_WRN,"SBPCD: Auto-Probing can cause a hang (f.e. touching an ethernet card).\n"));
  8894. -      DPRINTF((DBG_WRN,"SBPCD: If that happens, you have to reboot and use the\n"));
  8895. -      DPRINTF((DBG_WRN,"SBPCD: LILO (kernel) command line feature like:\n"));
  8896. -      DPRINTF((DBG_WRN,"SBPCD: \n"));
  8897. -      DPRINTF((DBG_WRN,"SBPCD:    LILO boot: linux sbpcd=0x230,SoundBlaster\n"));
  8898. -      DPRINTF((DBG_WRN,"SBPCD: or like:\n"));
  8899. -      DPRINTF((DBG_WRN,"SBPCD:    LILO boot: linux sbpcd=0x300,LaserMate\n"));
  8900. -      DPRINTF((DBG_WRN,"SBPCD: or like:\n"));
  8901. -      DPRINTF((DBG_WRN,"SBPCD:    LILO boot: linux sbpcd=0x330,SPEA\n"));
  8902. -      DPRINTF((DBG_WRN,"SBPCD: \n"));
  8903. -      DPRINTF((DBG_WRN,"SBPCD: with your REAL address.\n"));
  8904. -      DPRINTF((DBG_WRN,"SBPCD: = = = = = = = = = = END of WARNING = = = = = = = = = =\n"));
  8905. -      DPRINTF((DBG_WRN,"SBPCD: \n"));
  8906. -    }
  8907. +#if DISTRIBUTION
  8908. +    if (!setup_done)
  8909. +    {
  8910. +        msg(DBG_INF,"Looking for Matsushita/Panasonic, CreativeLabs, IBM, Longshine, TEAC CD-ROM drives\n");
  8911. +        msg(DBG_INF,"\n= = = = = = = = = = W A R N I N G = = = = = = = = = =\n");
  8912. +        msg(DBG_INF,"Auto-Probing can cause a hang (f.e. touching an ethernet card).\n");
  8913. +        msg(DBG_INF,"If that happens, you have to reboot and use the\n");
  8914. +        msg(DBG_INF,"LILO (kernel) command line feature like:\n");
  8915. +        msg(DBG_INF,"\n   LILO boot: ... sbpcd=0x230,SoundBlaster\n");
  8916. +        msg(DBG_INF,"or like:\n");
  8917. +        msg(DBG_INF,"   LILO boot: ... sbpcd=0x300,LaserMate\n");
  8918. +        msg(DBG_INF,"or like:\n");
  8919. +        msg(DBG_INF,"   LILO boot: ... sbpcd=0x330,SPEA\n");
  8920. +        msg(DBG_INF,"\nwith your REAL address.\n");
  8921. +        msg(DBG_INF,"= = = = = = = = = = END of WARNING = = = = = = = = = =\n\n");
  8922. +    }
  8923. +#endif DISTRIBUTION
  8924. +    sbpcd[0]=sbpcd_ioaddr; /* possibly changed by kernel command line */
  8925. +    sbpcd[1]=sbpro_type; /* possibly changed by kernel command line */
  8926.  #endif MODULE
  8927. -  sbpcd_probe[0]=sbpcd_ioaddr; /* possibly changed by kernel command line */
  8928. -  sbpcd_probe[1]=sbpro_type; /* possibly changed by kernel command line */
  8929. -
  8930. -  for (port_index=0;port_index<NUM_PROBE;port_index+=2)
  8931. -    {
  8932. -      addr[1]=sbpcd_probe[port_index];
  8933. -      if (addr[1]==0) break;
  8934. -      if (check_region(addr[1],4))
  8935. -    {
  8936. -      DPRINTF((DBG_INI,"SBPCD: check_region: %03X is not free.\n",addr[1]));
  8937. -      continue;
  8938. -    }
  8939. -      if (sbpcd_probe[port_index+1]==0) type=str_lm;
  8940. -      else if (sbpcd_probe[port_index+1]==1) type=str_sb;
  8941. -      else type=str_sp;
  8942. -      sbpcd_setup(type, addr);
  8943. -      DPRINTF((DBG_INF,"SBPCD: Trying to detect a %s CD-ROM drive at 0x%X.\n", type, CDo_command));
  8944. -      DPRINTF((DBG_INF,"SBPCD: - "));
  8945. -      if (sbpcd_probe[port_index+1]==2)
  8946. -    {
  8947. -      i=config_spea();
  8948. -      if (i<0)
  8949. -        {
  8950. -          DPRINTF((DBG_INF,"\n"));
  8951. -          continue;
  8952. -        }
  8953. -    }
  8954. -      i=check_drives();
  8955. -      DPRINTF((DBG_INI,"SBPCD: check_drives done.\n"));
  8956. -      if (i>=0) break; /* drive found */
  8957. -      DPRINTF((DBG_INF,"\n"));
  8958. -    } /* end of cycling through the set of possible I/O port addresses */
  8959. -
  8960. -  if (ndrives==0)
  8961. -    {
  8962. -      printk("SBPCD: No drive found.\n");
  8963. -#if PRINTK_BUG
  8964. -      sti(); /* to avoid possible "printk" bug */
  8965. -#endif
  8966. +    
  8967. +    for (port_index=0;port_index<NUM_PROBE;port_index+=2)
  8968. +    {
  8969. +        addr[1]=sbpcd[port_index];
  8970. +        if (addr[1]==0) break;
  8971. +        if (check_region(addr[1],4))
  8972. +        {
  8973. +            msg(DBG_INF,"check_region: %03X is not free.\n",addr[1]);
  8974. +            continue;
  8975. +        }
  8976. +        if (sbpcd[port_index+1]==2) type=str_sp;
  8977. +        else if (sbpcd[port_index+1]==1) type=str_sb;
  8978. +        else type=str_lm;
  8979. +        sbpcd_setup(type, addr);
  8980. +#if DISTRIBUTION
  8981. +        msg(DBG_INF,"Scanning 0x%X (%s)...\n", CDo_command, type);
  8982. +#endif DISTRIBUTION
  8983. +        if (sbpcd[port_index+1]==2)
  8984. +        {
  8985. +            i=config_spea();
  8986. +            if (i<0) continue;
  8987. +        }
  8988. +#ifdef PATH_CHECK
  8989. +        if (check_card(addr[1])) continue;
  8990. +#endif PATH_CHECK
  8991. +        i=check_drives();
  8992. +        msg(DBG_INI,"check_drives done.\n");
  8993. +        if (i>=0) break; /* drive found */
  8994. +    } /* end of cycling through the set of possible I/O port addresses */
  8995. +    
  8996. +    if (ndrives==0)
  8997. +    {
  8998. +        msg(DBG_INF, "No drive found.\n");
  8999.  #ifdef MODULE
  9000. -      return -EIO;
  9001. +        return -EIO;
  9002.  #else
  9003. -      goto init_done;
  9004. +        goto init_done;
  9005.  #endif MODULE
  9006. -    }
  9007. -
  9008. -  if (port_index>0)
  9009. -    {
  9010. -      printk("SBPCD: You should configure sbpcd.h for your hardware.\n");
  9011. -#if PRINTK_BUG
  9012. -      sti(); /* to avoid possible "printk" bug */
  9013. -#endif
  9014. -    }
  9015. +    }
  9016. +    
  9017. +    if (port_index>0)
  9018. +        msg(DBG_INF, "You should configure sbpcd.h for your hardware.\n");
  9019. +    check_datarate();
  9020. +    msg(DBG_INI,"check_datarate done.\n");
  9021. +    
  9022. +#if 0
  9023. +    if (!famL_drive)
  9024. +    {
  9025. +        OUT(CDo_reset,0);
  9026. +        sbp_sleep(100);
  9027. +    }
  9028. +#endif 0
  9029.  
  9030. -  printk("SBPCD: %d %s CD-ROM drive(s) at 0x%04X.\n",
  9031. -       ndrives, type, CDo_command);
  9032. -#if PRINTK_BUG
  9033. -  sti(); /* to avoid possible "printk" bug */
  9034. -#endif
  9035. -  check_datarate();
  9036. -  DPRINTF((DBG_INI,"SBPCD: check_datarate done.\n"));
  9037. -
  9038. -   if (!famL_drive)
  9039. -   {
  9040. -     OUT(CDo_reset,0);
  9041. -     sbp_sleep(100);
  9042. -   }
  9043. -
  9044. -  for (j=0;j<NR_SBPCD;j++)
  9045. -    {
  9046. -      if (DriveStruct[j].drv_id==-1) continue;
  9047. -      switch_drive(j);
  9048. -      if (!famL_drive) xy_DriveReset();
  9049. -      if (!st_spinning) xx_SpinUp();
  9050. -      DriveStruct[d].sbp_first_frame = -1;  /* First frame in buffer */
  9051. -      DriveStruct[d].sbp_last_frame = -1;   /* Last frame in buffer  */
  9052. -      DriveStruct[d].sbp_read_frames = 0;   /* Number of frames being read to buffer */
  9053. -      DriveStruct[d].sbp_current = 0;       /* Frame being currently read */
  9054. -      DriveStruct[d].CD_changed=1;
  9055. -      DriveStruct[d].frame_size=CD_FRAMESIZE;
  9056. +    for (j=0;j<NR_SBPCD;j++)
  9057. +    {
  9058. +        if (D_S[j].drv_id==-1) continue;
  9059. +        switch_drive(j);
  9060. +#if 1
  9061. +        if (!famL_drive) cc_DriveReset();
  9062. +#endif 0
  9063. +        if (!st_spinning) cc_SpinUp();
  9064. +        D_S[d].sbp_first_frame = -1;  /* First frame in buffer */
  9065. +        D_S[d].sbp_last_frame = -1;   /* Last frame in buffer  */
  9066. +        D_S[d].sbp_read_frames = 0;   /* Number of frames being read to buffer */
  9067. +        D_S[d].sbp_current = 0;       /* Frame being currently read */
  9068. +        D_S[d].CD_changed=1;
  9069. +        D_S[d].frame_size=CD_FRAMESIZE;
  9070.  #if EJECT
  9071. -      if (!fam0_drive) DriveStruct[d].f_eject=1;
  9072. -      else DriveStruct[d].f_eject=0;
  9073. +        if (!fam0_drive) D_S[d].f_eject=1;
  9074. +        else D_S[d].f_eject=0;
  9075.  #else
  9076. -      DriveStruct[d].f_eject=0;
  9077. +        D_S[d].f_eject=0;
  9078.  #endif
  9079. -
  9080. -      xx_ReadStatus();
  9081. -      i=ResponseStatus();  /* returns orig. status or p_busy_new */
  9082. -      if (i<0)
  9083. -    DPRINTF((DBG_INF,"SBPCD: init: ResponseStatus returns %02X\n",i));
  9084. -      else
  9085. -    {
  9086. -      if (st_check)
  9087. -        {
  9088. -          i=xx_ReadError();
  9089. -          DPRINTF((DBG_INI,"SBPCD: init: xx_ReadError returns %d\n",i));
  9090. -        }
  9091. -    }
  9092. -      DPRINTF((DBG_INI,"SBPCD: init: first GetStatus: %d\n",i));
  9093. -      DPRINTF((DBG_LCS,"SBPCD: init: first GetStatus: error_byte=%d\n",
  9094. -           DriveStruct[d].error_byte));
  9095. -      if (DriveStruct[d].error_byte==aud_12)
  9096. -    {
  9097. -      do { i=GetStatus();
  9098. -           DPRINTF((DBG_INI,"SBPCD: init: second GetStatus: %02X\n",i));
  9099. -           DPRINTF((DBG_LCS,
  9100. -            "SBPCD: init: second GetStatus: error_byte=%d\n",
  9101. -            DriveStruct[d].error_byte));
  9102. -           if (i<0) break;
  9103. -           if (!st_caddy_in) break;
  9104. -         }
  9105. -      while (!st_diskok);
  9106. +        
  9107. +        cc_ReadStatus();
  9108. +        i=ResponseStatus();  /* returns orig. status or p_busy_new */
  9109. +        if (i<0)
  9110. +            msg(DBG_INF,"init: ResponseStatus returns %02X\n",i);
  9111. +        else
  9112. +        {
  9113. +            if (st_check)
  9114. +            {
  9115. +                i=cc_ReadError();
  9116. +                msg(DBG_INI,"init: cc_ReadError returns %d\n",i);
  9117. +            }
  9118. +        }
  9119. +        msg(DBG_INI,"init: first GetStatus: %d\n",i);
  9120. +        msg(DBG_LCS,"init: first GetStatus: error_byte=%d\n",
  9121. +            D_S[d].error_byte);
  9122. +        if (D_S[d].error_byte==aud_12)
  9123. +        {
  9124. +            timeout=jiffies+200;
  9125. +            do
  9126. +            {
  9127. +                i=GetStatus();
  9128. +                msg(DBG_INI,"init: second GetStatus: %02X\n",i);
  9129. +                msg(DBG_LCS,
  9130. +                    "init: second GetStatus: error_byte=%d\n",
  9131. +                    D_S[d].error_byte);
  9132. +                if (i<0) break;
  9133. +                if (!st_caddy_in) break;
  9134. +                }
  9135. +            while ((!st_diskok)||(timeout<jiffies));
  9136. +        }
  9137. +        i=SetSpeed();
  9138. +        if (i>=0) D_S[d].CD_changed=1;
  9139.      }
  9140. -      i=SetSpeed();
  9141. -      if (i>=0) DriveStruct[d].CD_changed=1;
  9142. -    }
  9143. -
  9144. -/*
  9145. - * Turn on the CD audio channels.
  9146. - * For "compatible" soundcards (with "SBPRO 0" or "SBPRO 2"), the addresses
  9147. - * are obtained from SOUND_BASE (see sbpcd.h).
  9148. - */
  9149. -  if ((sbpro_type==1) || (SOUND_BASE))
  9150. -    {
  9151. -      if (sbpro_type!=1)
  9152. +    
  9153. +    /*
  9154. +     * Turn on the CD audio channels.
  9155. +     * For "compatible" soundcards (with "SBPRO 0" or "SBPRO 2"), the addresses
  9156. +     * are obtained from SOUND_BASE (see sbpcd.h).
  9157. +     */
  9158. +    if ((sbpro_type==1) || (SOUND_BASE))
  9159.      {
  9160. -      MIXER_addr=SOUND_BASE+0x04; /* sound card's address register */
  9161. -      MIXER_data=SOUND_BASE+0x05; /* sound card's data register */
  9162. +        if (sbpro_type!=1)
  9163. +        {
  9164. +            MIXER_addr=SOUND_BASE+0x04; /* sound card's address register */
  9165. +            MIXER_data=SOUND_BASE+0x05; /* sound card's data register */
  9166. +        }
  9167. +        OUT(MIXER_addr,MIXER_CD_Volume); /* select SB Pro mixer register */
  9168. +        OUT(MIXER_data,0xCC); /* one nibble per channel, max. value: 0xFF */
  9169.      }
  9170. -      OUT(MIXER_addr,MIXER_CD_Volume); /* select SB Pro mixer register */
  9171. -      OUT(MIXER_data,0xCC); /* one nibble per channel, max. value: 0xFF */
  9172. -    }
  9173. -
  9174. -  if (register_blkdev(MAJOR_NR, major_name, &sbpcd_fops) != 0)
  9175. -    {
  9176. -      printk("SBPCD: Can't get MAJOR %d for Matsushita CDROM\n", MAJOR_NR);
  9177. -#if PRINTK_BUG
  9178. -      sti(); /* to avoid possible "printk" bug */
  9179. -#endif
  9180. +    
  9181. +    if (register_blkdev(MAJOR_NR, major_name, &sbpcd_fops) != 0)
  9182. +    {
  9183. +        msg(DBG_INF, "Can't get MAJOR %d for Matsushita CDROM\n", MAJOR_NR);
  9184.  #ifdef MODULE
  9185. -      return -EIO;
  9186. +        return -EIO;
  9187.  #else
  9188. -      goto init_done;
  9189. +        goto init_done;
  9190.  #endif MODULE
  9191. -    }
  9192. -  blk_dev[MAJOR_NR].request_fn = DEVICE_REQUEST;
  9193. -  read_ahead[MAJOR_NR] = SBP_BUFFER_FRAMES * (CD_FRAMESIZE / 512);
  9194. -  
  9195. -  request_region(CDo_command,4,major_name);
  9196. -
  9197. -  for (j=0;j<NR_SBPCD;j++)
  9198. -    {
  9199. -      if (DriveStruct[j].drv_id==-1) continue;
  9200. -      switch_drive(j);
  9201. -/*
  9202. - * allocate memory for the frame buffers
  9203. - */
  9204. +    }
  9205. +    blk_dev[MAJOR_NR].request_fn = DEVICE_REQUEST;
  9206. +    read_ahead[MAJOR_NR] = SBP_BUFFER_FRAMES * (CD_FRAMESIZE / 512);
  9207. +    
  9208. +    request_region(CDo_command,4,major_name);
  9209. +    
  9210. +    for (j=0;j<NR_SBPCD;j++)
  9211. +    {
  9212. +        if (D_S[j].drv_id==-1) continue;
  9213. +        switch_drive(j);
  9214. +        /*
  9215. +         * allocate memory for the frame buffers
  9216. +         */
  9217. +        D_S[j].aud_buf=NULL;
  9218. +        D_S[j].sbp_audsiz=0;
  9219. +        D_S[j].sbp_bufsiz=SBP_BUFFER_FRAMES;
  9220. +        if (D_S[j].drv_type&drv_fam1)
  9221. +            if (READ_AUDIO>0) D_S[j].sbp_audsiz=READ_AUDIO;
  9222.  #ifdef MODULE
  9223. -      DriveStruct[j].sbp_buf=(u_char *) kmalloc(SBP_BUFFER_FRAMES*CD_FRAMESIZE, GFP_KERNEL);
  9224. -      DriveStruct[j].aud_buf=NULL;
  9225. +        D_S[j].sbp_buf=(u_char *) vmalloc(D_S[j].sbp_bufsiz*CD_FRAMESIZE);
  9226. +        if (D_S[j].sbp_buf==NULL)
  9227. +        {
  9228. +            msg(DBG_INF,"data buffer (%d frames) not available.\n",D_S[j].sbp_bufsiz);
  9229. +            return -EIO;
  9230. +        }
  9231. +        msg(DBG_INF,"data buffer size: %d frames.\n",SBP_BUFFER_FRAMES);
  9232. +        if (D_S[j].sbp_audsiz>0)
  9233. +        {
  9234. +            D_S[j].aud_buf=(u_char *) vmalloc(D_S[j].sbp_audsiz*CD_FRAMESIZE_RAW);
  9235. +            if (D_S[j].aud_buf==NULL) msg(DBG_INF,"audio buffer (%d frames) not available.\n",D_S[j].sbp_audsiz);
  9236. +            else msg(DBG_INF,"audio buffer size: %d frames.\n",D_S[j].sbp_audsiz);
  9237. +        }
  9238.  #else
  9239. -      DriveStruct[j].sbp_buf=(u_char *)mem_start;
  9240. -      mem_start += SBP_BUFFER_FRAMES*CD_FRAMESIZE;
  9241. -      if ((fam1_drive) && (SBP_BUFFER_AUDIO_FRAMES>0))
  9242. -    {
  9243. -      DriveStruct[j].aud_buf=(u_char *)mem_start;
  9244. -      mem_start += SBP_BUFFER_AUDIO_FRAMES*CD_FRAMESIZE_RAW;
  9245. -    }
  9246. -      else DriveStruct[j].aud_buf=NULL;
  9247. +        D_S[j].sbp_buf=(u_char *)mem_start;
  9248. +        mem_start += D_S[j].sbp_bufsiz*CD_FRAMESIZE;
  9249. +        if (D_S[j].sbp_audsiz>0)
  9250. +        {
  9251. +            D_S[j].aud_buf=(u_char *)mem_start;
  9252. +            mem_start += D_S[j].sbp_audsiz*CD_FRAMESIZE_RAW;
  9253. +        }
  9254.  #endif MODULE
  9255. -/*
  9256. - * set the block size
  9257. - */
  9258. -      sbpcd_blocksizes[j]=CD_FRAMESIZE;
  9259. -    }
  9260. -  blksize_size[MAJOR_NR]=sbpcd_blocksizes;
  9261. -
  9262. +        /*
  9263. +         * set the block size
  9264. +         */
  9265. +        sbpcd_blocksizes[j]=CD_FRAMESIZE;
  9266. +    }
  9267. +    blksize_size[MAJOR_NR]=sbpcd_blocksizes;
  9268. +    
  9269.  #ifdef MODULE
  9270. -return (0);
  9271. +    return (0);
  9272.  #else
  9273. -init_done:
  9274. + init_done:
  9275.  #if !(SBPCD_ISSUE-1)
  9276.  #ifdef CONFIG_SBPCD2
  9277. -  mem_start=sbpcd2_init(mem_start, mem_end);
  9278. +    mem_start=sbpcd2_init(mem_start, mem_end);
  9279.  #endif
  9280.  #ifdef CONFIG_SBPCD3
  9281. -  mem_start=sbpcd3_init(mem_start, mem_end);
  9282. +    mem_start=sbpcd3_init(mem_start, mem_end);
  9283.  #endif
  9284.  #ifdef CONFIG_SBPCD4
  9285. -  mem_start=sbpcd4_init(mem_start, mem_end);
  9286. +    mem_start=sbpcd4_init(mem_start, mem_end);
  9287.  #endif
  9288.  #endif
  9289. -#if !(SBPCD_ISSUE-1)
  9290. -  DPRINTF((DBG_INF,"SBPCD: init done.\n"));
  9291. -#endif
  9292. -  return (mem_start);
  9293. +    return (mem_start);
  9294.  #endif MODULE
  9295.  }
  9296.  /*==========================================================================*/
  9297.  #ifdef MODULE
  9298.  void cleanup_module(void)
  9299.  {
  9300. -  int j;
  9301. -
  9302. -  if (MOD_IN_USE)
  9303. -    {
  9304. -      printk("%s module in use - can't remove it.\n", major_name);
  9305. -      return;
  9306. -    }
  9307. -  if ((unregister_blkdev(MAJOR_NR, major_name) == -EINVAL))
  9308. -    {
  9309. -      printk("What's that: can't unregister %s\n", major_name);
  9310. -      return;
  9311. -    }
  9312. -  release_region(CDo_command,4);
  9313. -
  9314. -  for (j=0;j<NR_SBPCD;j++)
  9315. -    {
  9316. -      if (DriveStruct[j].drv_id==-1) continue;
  9317. -      kfree_s(DriveStruct[j].sbp_buf, SBP_BUFFER_FRAMES*CD_FRAMESIZE);
  9318. -    }
  9319. -  printk("%s module released.\n", major_name);
  9320. +    int j;
  9321. +    
  9322. +    if (MOD_IN_USE)
  9323. +    {
  9324. +        msg(DBG_INF, "%s module in use - can't remove it.\n", major_name);
  9325. +        return;
  9326. +    }
  9327. +    if ((unregister_blkdev(MAJOR_NR, major_name) == -EINVAL))
  9328. +    {
  9329. +        msg(DBG_INF, "What's that: can't unregister %s.\n", major_name);
  9330. +        return;
  9331. +    }
  9332. +    release_region(CDo_command,4);
  9333. +    
  9334. +    for (j=0;j<NR_SBPCD;j++)
  9335. +    {
  9336. +        if (D_S[j].drv_id==-1) continue;
  9337. +        vfree(D_S[j].sbp_buf);
  9338. +        if (D_S[j].sbp_audsiz>0)
  9339. +            vfree(D_S[j].aud_buf);
  9340. +    }
  9341. +    msg(DBG_INF, "%s module released.\n", major_name);
  9342.  }
  9343.  #endif MODULE
  9344.  /*==========================================================================*/
  9345. @@ -4433,53 +5311,70 @@
  9346.   */
  9347.  static int sbpcd_chk_disk_change(dev_t full_dev)
  9348.  {
  9349. -  int i, st;
  9350. -
  9351. -  DPRINTF((DBG_CHK,"SBPCD: media_check (%d) called\n", MINOR(full_dev)));
  9352. -  return (0); /* "busy" test necessary before we really can check */
  9353. -
  9354. -  i=MINOR(full_dev);
  9355. -  if ( (i<0) || (i>=NR_SBPCD) || (DriveStruct[i].drv_id==-1) )
  9356. -    {
  9357. -      printk("SBPCD: media_check: invalid device %04X.\n", full_dev);
  9358. -      return (-1);
  9359. -    }
  9360. -
  9361. -  switch_drive(i);
  9362. -  
  9363. -  xx_ReadStatus();                         /* command: give 1-byte status */
  9364. -  st=ResponseStatus();
  9365. -  DPRINTF((DBG_CHK,"SBPCD: media_check: %02X\n",DriveStruct[d].status_byte));
  9366. -  if (st<0)
  9367. -    {
  9368. -      DPRINTF((DBG_INF,"SBPCD: media_check: ResponseStatus error.\n"));
  9369. -      return (1); /* status not obtainable */
  9370. -    }
  9371. -  if (DriveStruct[d].CD_changed==0xFF) DPRINTF((DBG_CHK,"SBPCD: media_check: \"changed\" assumed.\n"));
  9372. -  if (!st_spinning) DPRINTF((DBG_CHK,"SBPCD: media_check: motor off.\n"));
  9373. -  if (!st_door_closed)
  9374. -    {
  9375. -      DPRINTF((DBG_CHK,"SBPCD: media_check: door open.\n"));
  9376. -      DriveStruct[d].CD_changed=0xFF;
  9377. -    }
  9378. -  if (!st_caddy_in)
  9379. -    {
  9380. -      DPRINTF((DBG_CHK,"SBPCD: media_check: no disk in drive.\n"));
  9381. -      DriveStruct[d].CD_changed=0xFF;
  9382. -    }
  9383. -  if (!st_diskok) DPRINTF((DBG_CHK,"SBPCD: media_check: !st_diskok.\n"));
  9384. -  
  9385. +    int i, st;
  9386. +    
  9387. +    msg(DBG_CHK,"media_check (%d) called\n", MINOR(full_dev));
  9388. +    return (0); /* "busy" test necessary before we really can check */
  9389. +    
  9390. +    i=MINOR(full_dev);
  9391. +    if ( (i<0) || (i>=NR_SBPCD) || (D_S[i].drv_id==-1) )
  9392. +    {
  9393. +        msg(DBG_INF, "media_check: invalid device %04X.\n", full_dev);
  9394. +        return (-1);
  9395. +    }
  9396. +    
  9397. +    switch_drive(i);
  9398. +    
  9399. +    cc_ReadStatus();                         /* command: give 1-byte status */
  9400. +    st=ResponseStatus();
  9401. +    msg(DBG_CHK,"media_check: %02X\n",D_S[d].status_bits);
  9402. +    if (st<0)
  9403. +    {
  9404. +        msg(DBG_INF,"media_check: ResponseStatus error.\n");
  9405. +        return (1); /* status not obtainable */
  9406. +    }
  9407. +    if (D_S[d].CD_changed==0xFF) msg(DBG_CHK,"media_check: \"changed\" assumed.\n");
  9408. +    if (!st_spinning) msg(DBG_CHK,"media_check: motor off.\n");
  9409. +    if (!st_door_closed)
  9410. +    {
  9411. +        msg(DBG_CHK,"media_check: door open.\n");
  9412. +        D_S[d].CD_changed=0xFF;
  9413. +    }
  9414. +    if (!st_caddy_in)
  9415. +    {
  9416. +        msg(DBG_CHK,"media_check: no disk in drive.\n");
  9417. +        D_S[d].open_count=0;
  9418. +        D_S[d].CD_changed=0xFF;
  9419. +    }
  9420. +    if (!st_diskok) msg(DBG_CHK,"media_check: !st_diskok.\n");
  9421. +    
  9422.  #if 0000
  9423. -  if (DriveStruct[d].CD_changed==0xFF)
  9424. -    {
  9425. -      DriveStruct[d].CD_changed=1;
  9426. -      return (1); /* driver had a change detected before */
  9427. -    }
  9428. +    if (D_S[d].CD_changed==0xFF)
  9429. +    {
  9430. +        D_S[d].CD_changed=1;
  9431. +        return (1); /* driver had a change detected before */
  9432. +    }
  9433.  #endif 0000 /* seems to give additional errors at the moment */
  9434. -
  9435. -  if (!st_diskok) return (1); /* disk not o.k. */
  9436. -  if (!st_caddy_in) return (1); /* disk removed */
  9437. -  if (!st_door_closed) return (1); /* door open */
  9438. -  return (0);
  9439. +    
  9440. +    if (!st_diskok) return (1); /* disk not o.k. */
  9441. +    if (!st_caddy_in) return (1); /* disk removed */
  9442. +    if (!st_door_closed) return (1); /* door open */
  9443. +    return (0);
  9444.  }
  9445.  /*==========================================================================*/
  9446. +/*
  9447. + * Overrides for Emacs so that we follow Linus's tabbing style.
  9448. + * Emacs will notice this stuff at the end of the file and automatically
  9449. + * adjust the settings for this buffer only.  This must remain at the end
  9450. + * of the file. 
  9451. + * ---------------------------------------------------------------------------
  9452. + * Local variables:
  9453. + * c-indent-level: 8
  9454. + * c-brace-imaginary-offset: 0
  9455. + * c-brace-offset: -8
  9456. + * c-argdecl-indent: 8
  9457. + * c-label-offset: -8
  9458. + * c-continued-statement-offset: 8
  9459. + * c-continued-brace-offset: 0
  9460. + * End:
  9461. + */
  9462. diff -u --recursive --new-file v1.2.7/linux/drivers/char/ChangeLog linux/drivers/char/ChangeLog
  9463. --- v1.2.7/linux/drivers/char/ChangeLog    Sat Apr 29 12:42:21 1995
  9464. +++ linux/drivers/char/ChangeLog    Tue May  2 08:38:31 1995
  9465. @@ -1,14 +1,36 @@
  9466. +Tue May  2 00:53:25 1995    <tytso@rsx-11.mit.edu>
  9467. +
  9468. +    * tty_io.c (tty_set_ldisc): Wait until the output buffer is
  9469. +        drained before closing the old line discipline --- needed
  9470. +        in only one case: XON/XOFF processing.
  9471. +
  9472. +    * n_tty.c (n_tty_close): Don't bother waiting until the output
  9473. +        driver is closed; in general, the line discipline
  9474. +        shouldn't care if the hardware is finished
  9475. +        transmitting before the line discipline terminates.
  9476. +
  9477. +    * tty_io.c (release_dev): Shutdown the line discipline after
  9478. +        decrementing the tty count variable; but set the
  9479. +        TTY_CLOSING flag so that we know that this tty structure
  9480. +        isn't long for this world.
  9481. +
  9482. +    * tty_io.c (init_dev): Add sanity code to check to see if
  9483. +        TTY_CLOSING is set on a tty structure; if so, something
  9484. +        bad has happened (probably a line discipline close blocked
  9485. +        when it shouldn't have; so do a kernel printk and then
  9486. +        return an error).
  9487. +
  9488.  Wed Apr 26 10:23:44 1995  Theodore Y. Ts'o  <tytso@localhost>
  9489.  
  9490. -    * tty_io.c (release_dev): Try to shutdown the line discpline
  9491. +    * tty_io.c (release_dev): Try to shutdown the line discipline
  9492.          *before* decrementing the tty count variable; this removes
  9493.          a potential race condition which occurs when the line
  9494. -        discpline close blocks, and another process then tries
  9495. +        discipline close blocks, and another process then tries
  9496.          open the same serial port.
  9497.  
  9498.      * serial.c (rs_hangup): When hanging up, flush the output buffer
  9499. -        befure shutting down the UART.  Otherwise the line
  9500. -        discpline close blocks waiting for the characters to get
  9501. +        before shutting down the UART.  Otherwise the line
  9502. +        discipline close blocks waiting for the characters to get
  9503.          flushed, which never happens until the serial port gets reused.
  9504.  
  9505.  Wed Apr 12 08:06:16 1995  Theodore Y. Ts'o  <tytso@localhost>
  9506. diff -u --recursive --new-file v1.2.7/linux/drivers/char/n_tty.c linux/drivers/char/n_tty.c
  9507. --- v1.2.7/linux/drivers/char/n_tty.c    Mon Feb 20 21:29:52 1995
  9508. +++ linux/drivers/char/n_tty.c    Tue May  2 08:33:51 1995
  9509. @@ -676,7 +676,6 @@
  9510.  
  9511.  static void n_tty_close(struct tty_struct *tty)
  9512.  {
  9513. -    tty_wait_until_sent(tty, 0);
  9514.      n_tty_flush_buffer(tty);
  9515.      if (tty->read_buf) {
  9516.          free_page((unsigned long) tty->read_buf);
  9517. diff -u --recursive --new-file v1.2.7/linux/drivers/char/tty_io.c linux/drivers/char/tty_io.c
  9518. --- v1.2.7/linux/drivers/char/tty_io.c    Sat Apr 29 12:42:21 1995
  9519. +++ linux/drivers/char/tty_io.c    Tue May  2 08:33:51 1995
  9520. @@ -204,6 +204,8 @@
  9521.          return 0;    /* We are already in the desired discipline */
  9522.      o_ldisc = tty->ldisc;
  9523.  
  9524. +    tty_wait_until_sent(tty, 0);
  9525. +    
  9526.      /* Shutdown the current discipline. */
  9527.      if (tty->ldisc.close)
  9528.          (tty->ldisc.close)(tty);
  9529. @@ -865,8 +867,15 @@
  9530.              }
  9531.          }
  9532.          tty = NULL;
  9533. -    } else
  9534. +    } else {
  9535. +        if ((*tty_loc)->flags & (1 << TTY_CLOSING)) {
  9536. +            printk("Attempt to open closing tty %s.\n",
  9537. +                   tty_name(*tty_loc));
  9538. +            printk("Ack!!!!  This should never happen!!\n");
  9539. +            return -EINVAL;
  9540. +        }
  9541.          (*tty_loc)->count++;
  9542. +    }
  9543.      if (driver->type == TTY_DRIVER_TYPE_PTY) {
  9544.          if (!*o_tp_loc) {
  9545.              *o_tp_loc = o_tp;
  9546. @@ -1006,22 +1015,6 @@
  9547.              tty->link->count = 0;
  9548.          }
  9549.      }
  9550. -    if (tty->count <= 1) {
  9551. -        /*
  9552. -         * Shutdown the current line discipline, and reset it
  9553. -         * to N_TTY.
  9554. -         */
  9555. -        if (tty->ldisc.close)
  9556. -            (tty->ldisc.close)(tty);
  9557. -        tty->ldisc = ldiscs[N_TTY];
  9558. -        tty->termios->c_line = N_TTY;
  9559. -        if (o_tty && o_tty->count <= 0) {
  9560. -            if (o_tty->ldisc.close)
  9561. -                (o_tty->ldisc.close)(o_tty);
  9562. -            o_tty->ldisc = ldiscs[N_TTY];
  9563. -            o_tty->termios->c_line = N_TTY;
  9564. -        }
  9565. -    }
  9566.      if (--tty->count < 0) {
  9567.          printk("release_dev: bad tty->count (%d) for %s\n",
  9568.                 tty->count, tty_name(tty));
  9569. @@ -1030,6 +1023,9 @@
  9570.      if (tty->count)
  9571.          return;
  9572.  
  9573. +    /*
  9574. +     * We're committed; at this point, we must not block!
  9575. +     */
  9576.      if (o_tty) {
  9577.          if (o_tty->count)
  9578.              return;
  9579. @@ -1041,6 +1037,7 @@
  9580.  #ifdef TTY_DEBUG_HANGUP
  9581.      printk("freeing tty structure...");
  9582.  #endif
  9583. +    tty->flags |= (1 << TTY_CLOSING);
  9584.  
  9585.      /*
  9586.       * Make sure there aren't any processes that still think this
  9587. @@ -1055,6 +1052,20 @@
  9588.              (*p)->tty = NULL;
  9589.      }
  9590.  
  9591. +    /*
  9592. +     * Shutdown the current line discipline, and reset it to
  9593. +     * N_TTY.
  9594. +     */
  9595. +    if (tty->ldisc.close)
  9596. +        (tty->ldisc.close)(tty);
  9597. +    tty->ldisc = ldiscs[N_TTY];
  9598. +    tty->termios->c_line = N_TTY;
  9599. +    if (o_tty) {
  9600. +        if (o_tty->ldisc.close)
  9601. +            (o_tty->ldisc.close)(o_tty);
  9602. +        o_tty->ldisc = ldiscs[N_TTY];
  9603. +    }
  9604. +    
  9605.      tty->driver.table[idx] = NULL;
  9606.      if (tty->driver.flags & TTY_DRIVER_RESET_TERMIOS) {
  9607.          tty->driver.termios[idx] = NULL;
  9608. diff -u --recursive --new-file v1.2.7/linux/drivers/net/8390.h linux/drivers/net/8390.h
  9609. --- v1.2.7/linux/drivers/net/8390.h    Sat Apr 29 12:42:21 1995
  9610. +++ linux/drivers/net/8390.h    Tue May  2 08:01:57 1995
  9611. @@ -60,7 +60,7 @@
  9612.    struct enet_statistics stat;
  9613.  };
  9614.  
  9615. -/* The maximum number of 8390 interrupt serivce routines called per IRQ. */
  9616. +/* The maximum number of 8390 interrupt service routines called per IRQ. */
  9617.  #define MAX_SERVICE 12
  9618.  
  9619.  /* The maximum number of jiffies waited before assuming a Tx failed. */
  9620. diff -u --recursive --new-file v1.2.7/linux/drivers/net/CONFIG linux/drivers/net/CONFIG
  9621. --- v1.2.7/linux/drivers/net/CONFIG    Sun Feb 12 16:07:22 1995
  9622. +++ linux/drivers/net/CONFIG    Tue May  2 07:10:16 1995
  9623. @@ -40,10 +40,27 @@
  9624.  #       EWRK3_DEBUG    Set the desired debug level
  9625.  #
  9626.  #  DE4x5        The DIGITAL series of PCI/EISA Ethernet Cards,
  9627. -#            DE425, DE434 and DE435
  9628. -#       DE4x5_DEBUG    Set the desired debug level
  9629. -#    IS_ZYNX         May allow driver to work with Zynx cards - 
  9630. +#            DE425, DE434, DE435, DE500
  9631. +#     DE4X5_DEBUG    Set the desired debug level
  9632. +#     IS_NOT_DEC        May allow driver to work with Zynx & SMC cards - 
  9633.  #            see linux/drivers/net/README.de4x5
  9634. +#     DE4X5_AUTOSENSE   (Default) auto media/mode selection
  9635. +#                       If you want at least one board to not autosense then
  9636. +#                       no board can autosense. For a board mix of several
  9637. +#                    types, OR the manual values [eg for a DE500 (100M) with
  9638. +#                    a DE450 (AUI) use '-DDE4X5_AUTOSENSE=(0x80|0x08)']
  9639. +#                       For full auto media/mode selection           = 0x4000
  9640. +#                       For manual TP media selection                = 0x01
  9641. +#                       For manual TP/Nway media selection (DC21041) = 0x02
  9642. +#                       For manual BNC media selection               = 0x04
  9643. +#                       For manual AUI media selection               = 0x08
  9644. +#                       For manual BNC/AUI media selection (DC21040) = 0x10
  9645. +#                       For manual 10Mb/s mode selection   (DC21140) = 0x40
  9646. +#                       For manual 100Mb/s mode selection  (DC21140) = 0x80
  9647. +#                       The DC21040 will default to TP if TP_NW is specified
  9648. +#                       The DC21041 will default to BNC if BNC_AUI is specified
  9649. +#                       The DC21140 needs it's speed to be manually set to
  9650. +#                       10Mb/s or 100Mb/s (AUTO defaults to 10Mb/s)
  9651.  #
  9652.  
  9653.  # The following options exist, but cannot be set in this file.
  9654. @@ -66,4 +83,4 @@
  9655.  PLIP_OPTS    =
  9656.  DEPCA_OPTS    = -DDEPCA_DEBUG=1
  9657.  EWRK3_OPTS    = -DEWRK3_DEBUG=1
  9658. -DE4x5_OPTS    = -DDE4x5_DEBUG=1
  9659. +DE4X5_OPTS    = -DDE4X5_DEBUG=1 -DDE4X5_AUTOSENSE=0x4000
  9660. diff -u --recursive --new-file v1.2.7/linux/drivers/net/README.de4x5 linux/drivers/net/README.de4x5
  9661. --- v1.2.7/linux/drivers/net/README.de4x5    Sun Feb 12 16:07:47 1995
  9662. +++ linux/drivers/net/README.de4x5    Tue May  2 07:10:16 1995
  9663. @@ -1,36 +1,47 @@
  9664. -The  de425/de434/de435 driver in this  distribution is designed to work with
  9665. -the Digital Equipment Corporation series  of PCI/EISA ethernet cards (DE425,
  9666. -DE434, DE435) and with all kernels that support PCI.
  9667. +The de425/de434/de435/de500 driver in this distribution  is designed to work
  9668. +with  the  Digital Equipment Corporation   series of PCI/EISA ethernet cards
  9669. +(DE425, DE434, DE435, DE500) and with all kernels that support PCI.
  9670.  
  9671.  Auto media detection is provided so that the  media choice isn't compiled in
  9672. -and is flexible enough to be able to reconfigure on-the-fly.
  9673. +and is  flexible enough to be able  to  reconfigure on-the-fly. This feature
  9674. +hasn't been included for the DE500 unfortunately, due  to a potential patent
  9675. +dispute. When I get around to implementing the autosense algorithm by myself
  9676. +(which could legally be difficult to prove since I'm  part of the group that
  9677. +has implemented the patented algorithm) you'll  have an auto speed selection
  9678. +for the de500. If you want the auto speed feature yell at Digital. If enough
  9679. +of you do things might change.
  9680.  
  9681. -The ability to  load this  driver as  a loadable  module has been  included,
  9682. +The ability to load   this driver as  a loadable  module has been  included,
  9683.  although I don't recommend its use with PCI, since PCI dynamically allocates
  9684. -where the card will go at boot time.
  9685. +where the card will go at boot time (i.e. the  card would have to be present
  9686. +in the system at boot time for its address/IRQ to be assigned).
  9687.  
  9688. -The performance we've achieved  so far has been  measured through the 'ttcp'
  9689. -tool at   1.08MB/s.  This measures   the total tcp stack  performance which
  9690. -includes  the  card,  so  don't expect   to  get  much  nearer the  1.25MB/s
  9691. -theoretical ethernet rate.
  9692. -
  9693. -    ************************************************************************
  9694. -    However there is still a known bug which causes ttcp to hang on transmit
  9695. -    (receive  is  OK), although  the  adapter/driver  continues to  function
  9696. -    normally for  other applications e.g.  nfs  mounting disks, pinging etc.
  9697. -    The cause is under investigation.
  9698. -    ************************************************************************
  9699. +The performance we've achieved  so far has  been measured through the 'ttcp'
  9700. +tool at 1.06MB/s for  TCP  and 1.17MB/s for  UDP.   This measures  the total
  9701. +stack performance which  includes the  card, so don't   expect to get   much
  9702. +nearer the 1.25MB/s theoretical ethernet rate.
  9703. +
  9704. +                TCP           UDP
  9705. +             TX     RX     TX     RX
  9706. +    DE425   1030k  997k   1170k  1128k                 (EISA on a Dell 433DE)
  9707. +    DE434   1063k  995k   1170k  1125k                 (PCI: DECpc XL 466d2)
  9708. +    DE435   1063k  995k   1170k  1125k                 (PCI: DECpc XL 466d2)
  9709. +    DE500   1063k  998k   1170k  1125k  in 10Mb/s mode (PCI: DECpc XL 466d2)
  9710. +
  9711. +All  values are   typical  (in kBytes/sec) from   a  sample of   4  for each
  9712. +measurement. Their error  is approx +/-20k on a  quiet (private) network and
  9713. +also depend on what load the CPU has, CPU speed etc.
  9714.  
  9715. -ZYNX  cards,  which   use  the PCI  DECchip  DC21040,  are  not specifically
  9716. +ZYNX and SMC cards, which use the PCI DECchip  DC21040, are not specifically
  9717.  supported in this driver because
  9718.  
  9719.  a) I have  no information on them.   
  9720.  b) I cannot test  them with the driver.
  9721.  c) Donald Becker's 'tulip.c' driver  works with them....well one person says
  9722. -   they do and another doesn't, so take your pick!
  9723. +   they do and another says they do not, so take your pick!
  9724.  
  9725.  This driver can be made to work with the ZYNX  (and may be  the SMC) card by
  9726. -setting a compile time flag in linux/drivers/net/CONFIG
  9727. +setting a compile time flag (IS_NOT_DEC) in linux/drivers/net/CONFIG
  9728.  
  9729.  Enjoy!
  9730.  
  9731. diff -u --recursive --new-file v1.2.7/linux/drivers/net/de4x5.c linux/drivers/net/de4x5.c
  9732. --- v1.2.7/linux/drivers/net/de4x5.c    Sun Feb 12 16:07:22 1995
  9733. +++ linux/drivers/net/de4x5.c    Wed May  3 07:17:10 1995
  9734. @@ -1,6 +1,6 @@
  9735.  /*  de4x5.c: A DIGITAL DE425/DE434/DE435 ethernet driver for linux.
  9736.  
  9737. -    Copyright 1994 Digital Equipment Corporation.
  9738. +    Copyright 1994, 1995 Digital Equipment Corporation.
  9739.  
  9740.      This software may be used and distributed according to the terms of
  9741.      the GNU Public License, incorporated herein by reference.
  9742. @@ -11,17 +11,22 @@
  9743.      DE425 TP/COAX EISA
  9744.      DE434 TP PCI
  9745.      DE435 TP/COAX/AUI PCI
  9746. +    DE500 10/100 PCI Fasternet
  9747.  
  9748. -    The driver has been tested on a  relatively busy network using the DE425
  9749. -    and DE435 cards and benchmarked with 'ttcp': it  transferred 16M of data
  9750. -    at 1.08MB/s (8.6Mb/s) to a DECstation 5000/200.
  9751. -
  9752. -    ************************************************************************
  9753. -    However there is still a known bug which causes ttcp to hang on transmit
  9754. -    (receive  is  OK), although  the  adapter/driver  continues to  function
  9755. -    normally for  other applications e.g.  nfs  mounting disks, pinging etc.
  9756. -    The cause is under investigation.
  9757. -    ************************************************************************
  9758. +    The driver has been tested on a relatively busy network using the DE425,
  9759. +    DE434, DE435 and DE500 cards and benchmarked with 'ttcp': it transferred
  9760. +    16M of data to a DECstation 5000/200 as follows:
  9761. +
  9762. +                TCP           UDP
  9763. +             TX     RX     TX     RX
  9764. +    DE425   1030k  997k   1170k  1128k
  9765. +    DE434   1063k  995k   1170k  1125k
  9766. +    DE435   1063k  995k   1170k  1125k
  9767. +    DE500   1063k  998k   1170k  1125k  in 10Mb/s mode
  9768. +
  9769. +    All  values are typical (in   kBytes/sec) from a  sample  of 4 for  each
  9770. +    measurement. Their error is +/-20k on a quiet (private) network and also
  9771. +    depend on what load the CPU has.
  9772.  
  9773.      The author may    be  reached as davies@wanton.lkg.dec.com  or   Digital
  9774.      Equipment Corporation, 550 King Street, Littleton MA 01460.
  9775. @@ -98,9 +103,6 @@
  9776.  
  9777.      TO DO:
  9778.      ------
  9779. -    1. Add DC21041 Nway/Autosense support
  9780. -    2. Add DC21140 Autosense support
  9781. -    3. Add timer support
  9782.  
  9783.  
  9784.      Revision History
  9785. @@ -109,18 +111,26 @@
  9786.      Version   Date        Description
  9787.    
  9788.        0.1     17-Nov-94   Initial writing. ALPHA code release.
  9789. -      0.2     13-Jan-95   Added PCI support for DE435's
  9790. -      0.21    19-Jan-95   Added auto media detection
  9791. -      0.22    10-Feb-95   Fix interrupt handler call <chris@cosy.sbg.ac.at>
  9792. -                          Fix recognition bug reported by <bkm@star.rl.ac.uk>
  9793. -              Add request/release_region code
  9794. -              Add loadable modules support for PCI
  9795. -              Clean up loadable modules support
  9796. +      0.2     13-Jan-95   Added PCI support for DE435's.
  9797. +      0.21    19-Jan-95   Added auto media detection.
  9798. +      0.22    10-Feb-95   Fix interrupt handler call <chris@cosy.sbg.ac.at>.
  9799. +                          Fix recognition bug reported by <bkm@star.rl.ac.uk>.
  9800. +              Add request/release_region code.
  9801. +              Add loadable modules support for PCI.
  9802. +              Clean up loadable modules support.
  9803. +      0.23    28-Feb-95   Added DC21041 and DC21140 support. 
  9804. +                          Fix missed frame counter value and initialisation.
  9805. +              Fixed EISA probe.
  9806. +      0.24    11-Apr-95   Change delay routine to use <linux/udelay>.
  9807. +                          Change TX_BUFFS_AVAIL macro.
  9808. +              Change media autodetection to allow manual setting.
  9809. +              Completed DE500 (DC21140) support.
  9810. +      0.241   18-Apr-95   Interim release without DE500 Autosense Algorithm.
  9811.  
  9812.      =========================================================================
  9813.  */
  9814.  
  9815. -static char *version = "de4x5.c:v0.22 2/10/95 davies@wanton.lkg.dec.com\n";
  9816. +static char *version = "de4x5.c:v0.241 4/18/95 davies@wanton.lkg.dec.com\n";
  9817.  
  9818.  #include <linux/config.h>
  9819.  #ifdef MODULE
  9820. @@ -140,6 +150,7 @@
  9821.  #include <linux/ioport.h>
  9822.  #include <linux/malloc.h>
  9823.  #include <linux/pci.h>
  9824. +#include <linux/delay.h>
  9825.  #include <asm/bitops.h>
  9826.  #include <asm/io.h>
  9827.  #include <asm/dma.h>
  9828. @@ -161,6 +172,12 @@
  9829.  static int de4x5_debug = 1;
  9830.  #endif
  9831.  
  9832. +#ifdef DE4X5_AUTOSENSE              /* Should be done on a per adapter basis */
  9833. +static int de4x5_autosense = DE4X5_AUTOSENSE;
  9834. +#else
  9835. +static int de4x5_autosense = AUTO;      /* Do auto media/mode sensing */
  9836. +#endif
  9837. +
  9838.  /*
  9839.  ** Ethernet PROM defines
  9840.  */
  9841. @@ -198,79 +215,102 @@
  9842.  #define DE4X5_PCI_TOTAL_SIZE 0x80        /* I/O address extent */
  9843.  
  9844.  /*
  9845. -** Timer defines
  9846. -*/
  9847. -#define TIMER_WIDTH   16
  9848. -#define TIMER_PORT    0x43
  9849. -#define TIMER_LATCH   0x06
  9850. -#define TIMER_READ    0x40
  9851. -#define TIMER_TICK    419  /*ns*/
  9852. -#define DELAY_QUANT   5    /*us*/
  9853. -
  9854. -#define LWPAD ((long)(sizeof(long) - 1)) /* for longword alignment */
  9855. +** Memory Alignment. Each descriptor is 4 longwords long. To force a
  9856. +** particular alignment on the TX descriptor, adjust DESC_SKIP_LEN and
  9857. +** DESC_ALIGN. ALIGN aligns the start address of the private memory area
  9858. +** and hence the RX descriptor ring's first entry. 
  9859. +*/
  9860. +#define ALIGN4      ((u_long)4 - 1)    /* 1 longword align */
  9861. +#define ALIGN8      ((u_long)8 - 1)    /* 2 longword align */
  9862. +#define ALIGN16     ((u_long)16 - 1)   /* 4 longword align */
  9863. +#define ALIGN32     ((u_long)32 - 1)   /* 8 longword align */
  9864. +#define ALIGN64     ((u_long)64 - 1)   /* 16 longword align */
  9865. +#define ALIGN128    ((u_long)128 - 1)  /* 32 longword align */
  9866. +
  9867. +#define ALIGN         ALIGN32          /* Keep the DC21040 happy... */
  9868. +#define CACHE_ALIGN   CAL_16LONG
  9869. +#define DESC_SKIP_LEN DSL_0            /* Must agree with DESC_ALIGN */
  9870. +/*#define DESC_ALIGN    u_long dummy[4]; / * Must agree with DESC_SKIP_LEN */
  9871. +#define DESC_ALIGN
  9872.  
  9873. -#ifndef IS_ZYNX                          /* See README.de4x5 for using this */
  9874. -static int is_zynx = 0;
  9875. +#ifndef IS_NOT_DEC                     /* See README.de4x5 for using this */
  9876. +static int is_not_dec = 0;
  9877.  #else
  9878. -static int is_zynx = 1;
  9879. +static int is_not_dec = 1;
  9880.  #endif
  9881.  
  9882.  /*
  9883.  ** DE4X5 IRQ ENABLE/DISABLE
  9884.  */
  9885. -static u_long irq_mask = IMR_RIM | IMR_TIM | IMR_TUM ;
  9886. +static u_long irq_mask = IMR_SEM | IMR_RIM | IMR_RUM | IMR_TIM | IMR_TUM ;
  9887.  
  9888.  static u_long irq_en   = IMR_NIM | IMR_AIM;
  9889.  
  9890. -#define ENABLE_IRQs \
  9891. +#define ENABLE_IRQs { \
  9892.      imr |= irq_en;\
  9893. -    outl(imr, DE4X5_IMR)                    /* Enable the IRQs */
  9894. +    outl(imr, DE4X5_IMR);                   /* Enable the IRQs */\
  9895. +}
  9896.  
  9897. -#define DISABLE_IRQs \
  9898. +#define DISABLE_IRQs {\
  9899.      imr = inl(DE4X5_IMR);\
  9900.      imr &= ~irq_en;\
  9901. -    outl(imr, DE4X5_IMR)                    /* Disable the IRQs */
  9902. +    outl(imr, DE4X5_IMR);                   /* Disable the IRQs */\
  9903. +}
  9904.  
  9905. -#define UNMASK_IRQs \
  9906. +#define UNMASK_IRQs {\
  9907.      imr |= irq_mask;\
  9908. -    outl(imr, DE4X5_IMR)                    /* Unmask the IRQs */
  9909. +    outl(imr, DE4X5_IMR);                   /* Unmask the IRQs */\
  9910. +}
  9911.  
  9912. -#define MASK_IRQs \
  9913. +#define MASK_IRQs {\
  9914.      imr = inl(DE4X5_IMR);\
  9915.      imr &= ~irq_mask;\
  9916. -    outl(imr, DE4X5_IMR)                    /* Mask the IRQs */
  9917. +    outl(imr, DE4X5_IMR);                   /* Mask the IRQs */\
  9918. +}
  9919.  
  9920.  /*
  9921.  ** DE4X5 START/STOP
  9922.  */
  9923. -#define START_DE4X5 \
  9924. +#define START_DE4X5 {\
  9925.      omr = inl(DE4X5_OMR);\
  9926.      omr |= OMR_ST | OMR_SR;\
  9927. -    outl(omr, DE4X5_OMR)                    /* Enable the TX and/or RX */
  9928. +    outl(omr, DE4X5_OMR);                   /* Enable the TX and/or RX */\
  9929. +}
  9930.  
  9931. -#define STOP_DE4X5 \
  9932. +#define STOP_DE4X5 {\
  9933.      omr = inl(DE4X5_OMR);\
  9934.      omr &= ~(OMR_ST|OMR_SR);\
  9935. -    outl(omr, DE4X5_OMR)                    /* Disable the TX and/or RX */
  9936. +    outl(omr, DE4X5_OMR);                   /* Disable the TX and/or RX */ \
  9937. +}
  9938.  
  9939.  /*
  9940.  ** DE4X5 SIA RESET
  9941.  */
  9942. -#define RESET_SIA \
  9943. -    outl(SICR_RESET, DE4X5_SICR);           /* Reset SIA connectivity regs */ \
  9944. -    outl(STRR_RESET, DE4X5_STRR);           /* Write reset values */ \
  9945. -    outl(SIGR_RESET, DE4X5_SIGR)            /* Write reset values */
  9946. +#define RESET_SIA outl(0, DE4X5_SICR);      /* Reset SIA connectivity regs */
  9947. +
  9948. +/*
  9949. +** SROM Structure
  9950. +*/
  9951. +struct de4x5_srom {
  9952. +  char reserved[18];
  9953. +  char version;
  9954. +  char num_adapters;
  9955. +  char ieee_addr[6];
  9956. +  char info[100];
  9957. +  short chksum;
  9958. +};
  9959.  
  9960.  /*
  9961.  ** DE4X5 Descriptors. Make sure that all the RX buffers are contiguous
  9962.  ** and have sizes of both a power of 2 and a multiple of 4.
  9963.  ** A size of 256 bytes for each buffer was chosen because over 90% of
  9964. -** all packets in our network are <256 bytes long.
  9965. +** all packets in our network are <256 bytes long and 64 longword alignment
  9966. +** is possible.
  9967.  */
  9968. -#define NUM_RX_DESC 64                       /* Number of RX descriptors */
  9969. +#define NUM_RX_DESC 8                        /* Number of RX descriptors */
  9970.  #define NUM_TX_DESC 8                        /* Number of TX descriptors */
  9971.  #define BUFF_ALLOC_RETRIES 10                /* In case of memory shortage */
  9972. -#define RX_BUFF_SZ 256                       /* Power of 2 for kmalloc and */
  9973. +#define RX_BUFF_SZ 1536                      /* Power of 2 for kmalloc and */
  9974.                                               /* Multiple of 4 for DC21040 */
  9975.  
  9976.  struct de4x5_desc {
  9977. @@ -278,6 +318,7 @@
  9978.      u_long des1;
  9979.      char *buf;
  9980.      char *next;
  9981. +    DESC_ALIGN
  9982.  };
  9983.  
  9984.  /*
  9985. @@ -308,48 +349,76 @@
  9986.      char rxRingSize;
  9987.      char txRingSize;
  9988.      char bus;                                /* EISA or PCI */
  9989. +    u_short chipset;                         /* DC21040, DC21041 or DC21140 */
  9990. +    long media;                              /* Media (eg TP), mode (eg 100B)*/
  9991. +    int  autosense;                          /* Allow/disallow autosensing */
  9992. +    int  tx_enable;                          /* Enable descriptor polling */
  9993.      char lostMedia;                          /* Possibly lost media */
  9994. +    int  setup_f;                            /* Setup frame filtering type */
  9995.  };
  9996.  
  9997. +
  9998. +/*
  9999. +** The transmit ring full condition is described by the tx_old and tx_new
  10000. +** pointers by:
  10001. +**    tx_old            = tx_new    Empty ring
  10002. +**    tx_old            = tx_new+1  Full ring
  10003. +**    tx_old+txRingSize = tx_new+1  Full ring  (wrapped condition)
  10004. +*/
  10005.  #define TX_BUFFS_AVAIL ((lp->tx_old<=lp->tx_new)?\
  10006.               lp->tx_old+lp->txRingSize-lp->tx_new-1:\
  10007.                           lp->tx_old               -lp->tx_new-1)
  10008. -#define TX_SUSPENDED   (((sts & STS_TS) ^ TS_SUSP)==0)
  10009. +/*#define TX_BUFFS_AVAIL ((lp->tx_ring[lp->tx_new].status)>=0 ? 1 : 0)*/
  10010.  
  10011.  /*
  10012.  ** Public Functions
  10013.  */
  10014. -static int  de4x5_open(struct device *dev);
  10015. -static int  de4x5_queue_pkt(struct sk_buff *skb, struct device *dev);
  10016. -static void de4x5_interrupt(int irq, struct pt_regs * regs);
  10017. -static int  de4x5_close(struct device *dev);
  10018. -static struct enet_statistics *de4x5_get_stats(struct device *dev);
  10019. -static void set_multicast_list(struct device *dev, int num_addrs, void *addrs);
  10020. -static int  de4x5_ioctl(struct device *dev, struct ifreq *rq, int cmd);
  10021. +static int     de4x5_open(struct device *dev);
  10022. +static int     de4x5_queue_pkt(struct sk_buff *skb, struct device *dev);
  10023. +static void    de4x5_interrupt(int irq, struct pt_regs *regs);
  10024. +static int     de4x5_close(struct device *dev);
  10025. +static struct  enet_statistics *de4x5_get_stats(struct device *dev);
  10026. +static void    set_multicast_list(struct device *dev, int num_addrs, void *addrs);
  10027. +static int     de4x5_ioctl(struct device *dev, struct ifreq *rq, int cmd);
  10028.  
  10029.  /*
  10030.  ** Private functions
  10031.  */
  10032. -static int  de4x5_hw_init(struct device *dev, short iobase);
  10033. -static int  de4x5_init(struct device *dev);
  10034. -static int  de4x5_rx(struct device *dev);
  10035. -static int  de4x5_tx(struct device *dev);
  10036. -
  10037. -static int  autoconf_media(struct device *dev);
  10038. -static void create_packet(struct device *dev, char *frame, int len);
  10039. -static u_short dce_get_ticks(void);
  10040. -static void dce_us_delay(u_long usec);
  10041. -static void dce_ms_delay(u_long msec);
  10042. -static void load_packet(struct device *dev, char *buf, u_long flags, struct sk_buff *skb);
  10043. -static void EISA_signature(char * name, short iobase);
  10044. -static int  DevicePresent(short iobase);
  10045. -static void SetMulticastFilter(struct device *dev, int num_addrs, char *addrs, char *multicast_table);
  10046. -
  10047. -static int aprom_crc (struct device *dev);
  10048. -
  10049. -static void eisa_probe(struct device *dev, short iobase);
  10050. -static void pci_probe(struct device *dev, short iobase);
  10051. -static struct device *alloc_device(struct device *dev, int iobase);
  10052. +static int     de4x5_hw_init(struct device *dev, short iobase);
  10053. +static int     de4x5_init(struct device *dev);
  10054. +static int     de4x5_rx(struct device *dev);
  10055. +static int     de4x5_tx(struct device *dev);
  10056. +
  10057. +static int     autoconf_media(struct device *dev);
  10058. +static void    create_packet(struct device *dev, char *frame, int len);
  10059. +static void    dce_us_delay(u_long usec);
  10060. +static void    dce_ms_delay(u_long msec);
  10061. +static void    load_packet(struct device *dev, char *buf, u_long flags, struct sk_buff *skb);
  10062. +static void    dc21040_autoconf(struct device *dev);
  10063. +static void    dc21041_autoconf(struct device *dev);
  10064. +static void    dc21140_autoconf(struct device *dev);
  10065. +static long    test_media(struct device *dev, long irqs, long irq_mask, long csr13, long csr14, long csr15, long msec);
  10066. +static long    ping_media(struct device *dev);
  10067. +static void    reset_init_sia(struct device *dev, long sicr, long strr, long sigr);
  10068. +static int     test_ans(struct device *dev, long irqs, long irq_mask, long msec);
  10069. +static void    load_ms_timer(struct device *dev, u_long msec);
  10070. +static int     EISA_signature(char *name, long eisa_id);
  10071. +static int     DevicePresent(short iobase);
  10072. +static short   srom_rd(u_short address, u_char offset);
  10073. +static void    srom_latch(u_long command, u_short address);
  10074. +static void    srom_command(u_long command, u_short address);
  10075. +static void    srom_address(u_long command, u_short address, u_char offset);
  10076. +static short   srom_data(u_long command, u_short address);
  10077. +/*static void    srom_busy(u_long command, u_short address);*/
  10078. +static void    sendto_srom(u_long command, u_short addr);
  10079. +static long    getfrom_srom(u_short addr);
  10080. +static void    SetMulticastFilter(struct device *dev, int num_addrs, char *addrs);
  10081. +static int     aprom_crc (struct device *dev);
  10082. +
  10083. +static void    eisa_probe(struct device *dev, short iobase);
  10084. +static void    pci_probe(struct device *dev, short iobase);
  10085. +static struct  device *alloc_device(struct device *dev, int iobase);
  10086. +static char    *build_setup_frame(struct device *dev, int mode);
  10087.  
  10088.  #ifdef MODULE
  10089.  int  init_module(void);
  10090. @@ -371,6 +440,9 @@
  10091.  static struct bus_type {
  10092.      int bus;
  10093.      int device;
  10094. +    int chipset;
  10095. +    struct de4x5_srom srom;
  10096. +    int autosense;
  10097.  } bus;
  10098.  
  10099.  /*
  10100. @@ -382,8 +454,7 @@
  10101.      outl(i | BMR_SWR, DE4X5_BMR);\
  10102.      outl(i, DE4X5_BMR);\
  10103.      for (i=0;i<5;i++) inl(DE4X5_BMR);\
  10104. -           }
  10105. -
  10106. +}
  10107.  
  10108.  
  10109.  
  10110. @@ -409,7 +480,7 @@
  10111.      ** Walk the device list to check that at least one device
  10112.      ** initialised OK
  10113.      */
  10114. -    for (; dev->priv == NULL && dev->next != NULL; dev = dev->next);
  10115. +    for (; (dev->priv == NULL) && (dev->next != NULL); dev = dev->next);
  10116.  
  10117.      if (dev->priv) status = 0;
  10118.      if (iobase == 0) autoprobed = 1;
  10119. @@ -422,10 +493,16 @@
  10120.  de4x5_hw_init(struct device *dev, short iobase)
  10121.  {
  10122.    struct bus_type *lp = &bus;
  10123. -  int tmpbus, i, j, status=0;
  10124. +  int tmpbus, tmpchs, i, j, status=0;
  10125.    char *tmp;
  10126.    u_long nicsr;
  10127.  
  10128. +  /* Ensure we're not sleeping */
  10129. +  if (lp->chipset == DC21041) {
  10130. +    outl(0, PCI_CFDA);
  10131. +    dce_ms_delay(10);
  10132. +  }
  10133. +
  10134.    RESET_DE4X5;
  10135.  
  10136.    if (((nicsr=inl(DE4X5_STS)) & (STS_TS | STS_RS)) == 0) {
  10137. @@ -433,10 +510,14 @@
  10138.      ** Now find out what kind of DC21040/DC21041/DC21140 board we have.
  10139.      */
  10140.      if (lp->bus == PCI) {
  10141. -      if (!is_zynx) {
  10142. -    strcpy(name, "DE435");
  10143. +      if (!is_not_dec) {
  10144. +    if ((lp->chipset == DC21040) || (lp->chipset == DC21041)) {
  10145. +      strcpy(name, "DE435");
  10146. +    } else if (lp->chipset == DC21140) {
  10147. +      strcpy(name, "DE500");                /* Must read the SROM here! */
  10148. +    }
  10149.        } else {
  10150. -    strcpy(name, "ZYNX");
  10151. +    strcpy(name, "UNKNOWN");
  10152.        }
  10153.      } else {
  10154.        EISA_signature(name, EISA_ID0);
  10155. @@ -444,8 +525,6 @@
  10156.  
  10157.      if (*name != '\0') {                         /* found a board signature */
  10158.        dev->base_addr = iobase;
  10159. -      request_region(iobase, (lp->bus == PCI ? DE4X5_PCI_TOTAL_SIZE :
  10160. -                                   DE4X5_EISA_TOTAL_SIZE), name);
  10161.        
  10162.        if (lp->bus == EISA) {
  10163.      printk("%s: %s at %#3x (EISA slot %d)", 
  10164. @@ -462,6 +541,7 @@
  10165.        printk("%2.2x,\n", dev->dev_addr[i]);
  10166.        
  10167.        tmpbus = lp->bus;
  10168. +      tmpchs = lp->chipset;
  10169.  
  10170.        if (status == 0) {
  10171.      struct de4x5_private *lp;
  10172. @@ -470,26 +550,50 @@
  10173.      ** Reserve a section of kernel memory for the adapter
  10174.      ** private area and the TX/RX descriptor rings.
  10175.      */
  10176. -    dev->priv = (void *) kmalloc(sizeof(struct de4x5_private) + LWPAD, 
  10177. +    dev->priv = (void *) kmalloc(sizeof(struct de4x5_private) + ALIGN, 
  10178.                                                     GFP_KERNEL);
  10179.      /*
  10180.      ** Align to a longword boundary
  10181.      */
  10182. -    dev->priv = (void *)(((u_long)dev->priv + LWPAD) & ~LWPAD);
  10183. +    dev->priv = (void *)(((u_long)dev->priv + ALIGN) & ~ALIGN);
  10184.      lp = (struct de4x5_private *)dev->priv;
  10185.      memset(dev->priv, 0, sizeof(struct de4x5_private));
  10186.      lp->bus = tmpbus;
  10187. -    strcpy(lp->adapter_name, name);
  10188. +    lp->chipset = tmpchs;
  10189. +
  10190. +    /*
  10191. +    ** Choose autosensing
  10192. +    */
  10193. +    if (de4x5_autosense & AUTO) {
  10194. +      lp->autosense = AUTO;
  10195. +    } else {
  10196. +      if (lp->chipset != DC21140) {
  10197. +        if ((lp->chipset == DC21040) && (de4x5_autosense & TP_NW)) {
  10198. +          de4x5_autosense = TP;
  10199. +        }
  10200. +        if ((lp->chipset == DC21041) && (de4x5_autosense & BNC_AUI)) {
  10201. +          de4x5_autosense = BNC;
  10202. +        }
  10203. +        lp->autosense = de4x5_autosense & 0x001f;
  10204. +      } else {
  10205. +        lp->autosense = de4x5_autosense & 0x00c0;
  10206. +      }
  10207. +    }
  10208. +
  10209. +    sprintf(lp->adapter_name,"%s (%s)", name, dev->name);
  10210. +    request_region(iobase, (lp->bus == PCI ? DE4X5_PCI_TOTAL_SIZE :
  10211. +                                     DE4X5_EISA_TOTAL_SIZE), 
  10212. +                                         lp->adapter_name);
  10213.  
  10214.      /*
  10215.      ** Allocate contiguous receive buffers, long word aligned. 
  10216.      ** This could be a possible memory leak if the private area
  10217.      ** is ever hosed.
  10218.      */
  10219. -    for (tmp=NULL, j=0; j<BUFF_ALLOC_RETRIES && tmp==NULL; j++) {
  10220. -      if ((tmp = (void *)kmalloc(RX_BUFF_SZ * NUM_RX_DESC + LWPAD, 
  10221. +    for (tmp=NULL, j=0; (j<BUFF_ALLOC_RETRIES) && (tmp==NULL); j++) {
  10222. +      if ((tmp = (void *)kmalloc(RX_BUFF_SZ * NUM_RX_DESC + ALIGN, 
  10223.                                                   GFP_KERNEL)) != NULL) {
  10224. -        tmp = (void *)(((u_long) tmp + LWPAD) & ~LWPAD);
  10225. +        tmp = (char *)(((u_long) tmp + ALIGN) & ~ALIGN);
  10226.          for (i=0; i<NUM_RX_DESC; i++) {
  10227.            lp->rx_ring[i].status = 0;
  10228.            lp->rx_ring[i].des1 = RX_BUFF_SZ;
  10229. @@ -508,8 +612,10 @@
  10230.        lp->tx_ring[lp->txRingSize - 1].des1 |= TD_TER;
  10231.  
  10232.        /* Tell the adapter where the TX/RX rings are located. */
  10233. -      outl((u_long)lp->rx_ring, DE4X5_RRBA);
  10234. -      outl((u_long)lp->tx_ring, DE4X5_TRBA);
  10235. +      outl((long)lp->rx_ring, DE4X5_RRBA);
  10236. +      outl((long)lp->tx_ring, DE4X5_TRBA);
  10237. +
  10238. +      lp->tx_enable = TRUE;
  10239.  
  10240.        if (dev->irq < 2) {
  10241.  #ifndef MODULE
  10242. @@ -526,7 +632,7 @@
  10243.            printk("      and failed to detect IRQ line.\n");
  10244.            status = -ENXIO;
  10245.          } else {
  10246. -          for (dev->irq=0,i=0; i<sizeof(de4x5_irq) && !dev->irq; i++) {
  10247. +          for (dev->irq=0,i=0; (i<sizeof(de4x5_irq)) && (!dev->irq); i++) {
  10248.          if (irqnum == de4x5_irq[i]) {
  10249.            dev->irq = irqnum;
  10250.            printk("      and uses IRQ%d.\n", dev->irq);
  10251. @@ -550,13 +656,13 @@
  10252.                                                              dev->name);
  10253.        status = -ENXIO;
  10254.      }
  10255. +    if (status) release_region(iobase, (lp->bus == PCI ? 
  10256. +                                 DE4X5_PCI_TOTAL_SIZE :
  10257. +                                         DE4X5_EISA_TOTAL_SIZE));
  10258.        } else {
  10259.      printk("      which has an Ethernet PROM CRC error.\n");
  10260.      status = -ENXIO;
  10261.        }
  10262. -      if (status) release_region(iobase, (lp->bus == PCI ? 
  10263. -                                 DE4X5_PCI_TOTAL_SIZE :
  10264. -                                         DE4X5_EISA_TOTAL_SIZE));
  10265.      } else {
  10266.        status = -ENXIO;
  10267.      }
  10268. @@ -583,13 +689,19 @@
  10269.      
  10270.      /* Fill in the generic field of the device structure. */
  10271.      ether_setup(dev);
  10272. +
  10273. +    /* Let the adapter sleep to save power */
  10274. +    if (lp->chipset == DC21041) {
  10275. +      outl(0, DE4X5_SICR);
  10276. +      outl(CFDA_PSM, PCI_CFDA);
  10277. +    }
  10278.    } else {                            /* Incorrectly initialised hardware */
  10279.      struct de4x5_private *lp = (struct de4x5_private *)dev->priv;
  10280.      if (lp) {
  10281. -      kfree_s(lp->rx_ring[0].buf, RX_BUFF_SZ * NUM_RX_DESC + LWPAD);
  10282. +      kfree_s(lp->rx_ring[0].buf, RX_BUFF_SZ * NUM_RX_DESC + ALIGN);
  10283.      }
  10284.      if (dev->priv) {
  10285. -      kfree_s(dev->priv, sizeof(struct de4x5_private) + LWPAD);
  10286. +      kfree_s(dev->priv, sizeof(struct de4x5_private) + ALIGN);
  10287.        dev->priv = NULL;
  10288.      }
  10289.    }
  10290. @@ -604,12 +716,15 @@
  10291.    struct de4x5_private *lp = (struct de4x5_private *)dev->priv;
  10292.    short iobase = dev->base_addr;
  10293.    int i, status = 0;
  10294. -  u_long imr, omr, sts;
  10295. +  long imr, omr, sts;
  10296.  
  10297.    /*
  10298. -  ** Stop the TX and RX...
  10299. +  ** Wake up the adapter
  10300.    */
  10301. -  STOP_DE4X5;
  10302. +  if (lp->chipset == DC21041) {
  10303. +    outl(0, PCI_CFDA);
  10304. +    dce_ms_delay(10);
  10305. +  }
  10306.  
  10307.    if (request_irq(dev->irq, (void *)de4x5_interrupt, 0, lp->adapter_name)) {
  10308.      printk("de4x5_open(): Requested IRQ%d is busy\n",dev->irq);
  10309. @@ -669,21 +784,19 @@
  10310.        dev->tbusy = 0;                         
  10311.        dev->start = 1;
  10312.        dev->interrupt = UNMASK_INTERRUPTS;
  10313. -      
  10314. -      /*
  10315. -      ** Reset any pending interrupts
  10316. -      */
  10317. -      sts = inl(DE4X5_STS);
  10318. -      outl(sts, DE4X5_STS);
  10319. +      dev->trans_start = jiffies;
  10320.  
  10321. -      /*
  10322. -      ** Unmask and enable DE4X5 board interrupts
  10323. -      */
  10324. +      START_DE4X5;
  10325. +
  10326. +      /* Unmask and enable DE4X5 board interrupts */
  10327.        imr = 0;
  10328.        UNMASK_IRQs;
  10329. -      ENABLE_IRQs;
  10330.  
  10331. -      START_DE4X5;
  10332. +      /* Reset any pending (stale) interrupts */
  10333. +      sts = inl(DE4X5_STS);
  10334. +      outl(sts, DE4X5_STS);
  10335. +
  10336. +      ENABLE_IRQs;
  10337.      }
  10338.      if (de4x5_debug > 1) {
  10339.        printk("\tsts:  0x%08x\n", inl(DE4X5_STS));
  10340. @@ -703,70 +816,63 @@
  10341.  }
  10342.  
  10343.  /*
  10344. -** Initialize the DE4X5 operating conditions
  10345. +** Initialize the DE4X5 operating conditions. NB: a chip problem with the
  10346. +** DC21140 requires using perfect filtering mode for that chip. Since I can't
  10347. +** see why I'd want > 14 multicast addresses, I may change all chips to use
  10348. +** the perfect filtering mode. Keep the DMA burst length at 8: there seems
  10349. +** to be data corruption problems if it is larger (UDP errors seen from a
  10350. +** ttcp source).
  10351.  */
  10352.  static int
  10353.  de4x5_init(struct device *dev)
  10354.  {  
  10355.    struct de4x5_private *lp = (struct de4x5_private *)dev->priv;
  10356.    short iobase = dev->base_addr;
  10357. -  int offset, status = 0;
  10358. -  u_long i, j, bmr, omr;
  10359. -  char *pa;
  10360. +  int status = 0;
  10361. +  long i, j, bmr, omr;
  10362. +
  10363. +  /* Lock out other processes whilst setting up the hardware */
  10364. +  set_bit(0, (void *)&dev->tbusy);
  10365.  
  10366. -  /* Ensure a full reset */
  10367.    RESET_DE4X5;
  10368.  
  10369. -  /* Set up automatic transmit polling every 1.6ms */
  10370.    bmr = inl(DE4X5_BMR);
  10371. -  bmr |= TAP_1_6MS | CAL_16LONG;
  10372. +  bmr |= PBL_8 | DESC_SKIP_LEN | CACHE_ALIGN;
  10373.    outl(bmr, DE4X5_BMR);
  10374.  
  10375. -  /* Set up imperfect filtering mode as default, turn off promiscuous mode */
  10376. -  omr = OMR_HP;
  10377. -  offset = IMPERF_PA_OFFSET;
  10378. -
  10379. -  /* Lock out other processes whilst setting up the hardware */
  10380. -  set_bit(0, (void *)&dev->tbusy);
  10381. -
  10382. -  /* Rewrite the descriptor lists' start addresses */
  10383. -  outl((u_long)lp->rx_ring, DE4X5_RRBA);  /* Start of RX Descriptor List */
  10384. -  outl((u_long)lp->tx_ring, DE4X5_TRBA);  /* Start of TX Descriptor List */
  10385. +  if (lp->chipset != DC21140) {
  10386. +    omr = TR_96;
  10387. +    lp->setup_f = HASH_PERF;
  10388. +  } else {
  10389. +    omr = OMR_SDP | OMR_SF;
  10390. +    lp->setup_f = PERFECT;
  10391. +  }
  10392. +  outl((long)lp->rx_ring, DE4X5_RRBA);
  10393. +  outl((long)lp->tx_ring, DE4X5_TRBA);
  10394.  
  10395. -  /* Reset the buffer pointers */
  10396.    lp->rx_new = lp->rx_old = 0;
  10397.    lp->tx_new = lp->tx_old = 0;
  10398.  
  10399. -  /* Initialize each descriptor ownership in the RX ring */
  10400.    for (i = 0; i < lp->rxRingSize; i++) {
  10401.      lp->rx_ring[i].status = R_OWN;
  10402.    }
  10403.  
  10404. -  /* Initialize each descriptor ownership in the TX ring */
  10405.    for (i = 0; i < lp->txRingSize; i++) {
  10406.      lp->tx_ring[i].status = 0;
  10407.    }
  10408.  
  10409. -  /* Initialise the setup frame prior to starting the receive process */
  10410. -  memset(lp->setup_frame, 0, SETUP_FRAME_LEN);
  10411. +  /* Build the setup frame depending on filtering mode */
  10412. +  SetMulticastFilter(dev, 0, NULL);
  10413.  
  10414. -  /* Insert the physical address */
  10415. -  for (pa=lp->setup_frame+offset, j=0; j<ETH_ALEN; j++) {
  10416. -    *(pa + j) = dev->dev_addr[j];
  10417. -    if (j & 0x01) pa += 2;
  10418. +  if (lp->chipset != DC21140) {
  10419. +    load_packet(dev, lp->setup_frame, HASH_F|TD_SET|SETUP_FRAME_LEN, NULL);
  10420. +  } else {
  10421. +    load_packet(dev, lp->setup_frame, PERFECT_F|TD_SET|SETUP_FRAME_LEN, NULL);
  10422.    }
  10423. -
  10424. -  /* Clear the multicast list */
  10425. -  set_multicast_list(dev, 0, NULL);
  10426. -
  10427. -  /* Tell the hardware there's a new packet to be sent */
  10428. -  load_packet(dev, lp->setup_frame, HASH_F | TD_SET | SETUP_FRAME_LEN, NULL);
  10429. -
  10430. -  /* Start the TX process */
  10431.    outl(omr|OMR_ST, DE4X5_OMR);
  10432.  
  10433.    /* Poll for completion of setup frame (interrupts are disabled for now) */
  10434. -  for (j=0, i=0;i<100 && j==0;i++) {
  10435. +  for (j=0, i=0;(i<100) && (j==0);i++) {
  10436.      if (lp->tx_ring[lp->tx_new].status >= 0) j=1;
  10437.    }
  10438.    outl(omr, DE4X5_OMR);                        /* Stop everything! */
  10439. @@ -777,7 +883,6 @@
  10440.      status = -EIO;
  10441.    }
  10442.  
  10443. -  /* Update pointers */
  10444.    lp->tx_new = (++lp->tx_new) % lp->txRingSize;
  10445.    lp->tx_old = lp->tx_new;
  10446.  
  10447. @@ -807,13 +912,9 @@
  10448.    ** The 'lostMedia' threshold accounts for transient errors that
  10449.    ** were noticed when switching media.
  10450.    */
  10451. -  if (dev->tbusy || (lp->lostMedia > 3)) {
  10452. +  if (dev->tbusy || (lp->lostMedia > LOST_MEDIA_THRESHOLD)) {
  10453.      int tickssofar = jiffies - dev->trans_start;
  10454. -    if (tickssofar < 10 && !lp->lostMedia) {
  10455. -      /* Check if TX ring is full or not - 'tbusy' cleared if not full. */
  10456. -      if ((TX_BUFFS_AVAIL > 0) && dev->tbusy) {
  10457. -    dev->tbusy = 0;
  10458. -      }
  10459. +    if (tickssofar < 10 && (lp->lostMedia <= LOST_MEDIA_THRESHOLD)) {
  10460.        status = -1;
  10461.      } else {
  10462.        printk("%s: transmit timed out, status %08x, tbusy:%d, lostMedia:%d tickssofar:%d, resetting.\n",dev->name, inl(DE4X5_STS), dev->tbusy, lp->lostMedia, tickssofar);
  10463. @@ -825,21 +926,21 @@
  10464.        /* Unmask DE4X5 board interrupts */
  10465.        if (!status) {
  10466.      /* Start here to clean stale interrupts later */
  10467. +    dev->interrupt = UNMASK_INTERRUPTS;
  10468. +    dev->start = 1;
  10469. +    dev->tbusy = 0;                         
  10470.      dev->trans_start = jiffies;
  10471. +      
  10472.      START_DE4X5;
  10473.  
  10474. +    /* Unmask DE4X5 board interrupts */
  10475. +    imr = 0;
  10476. +    UNMASK_IRQs;
  10477. +
  10478.      /* Clear any pending (stale) interrupts */
  10479.      sts = inl(DE4X5_STS);
  10480.      outl(sts, DE4X5_STS);
  10481.  
  10482. -    /* Unmask DE4X5 board interrupts */
  10483. -    imr = 0;
  10484. -    UNMASK_IRQs;
  10485. -      
  10486. -    dev->interrupt = UNMASK_INTERRUPTS;
  10487. -    dev->start = 1;
  10488. -    dev->tbusy = 0;                         
  10489. -      
  10490.      ENABLE_IRQs;
  10491.        } else {
  10492.      printk("%s: hardware initialisation failure, status %08x.\n",
  10493. @@ -857,20 +958,18 @@
  10494.      if (set_bit(0, (void*)&dev->tbusy) != 0)
  10495.        printk("%s: Transmitter access conflict.\n", dev->name);
  10496.  
  10497. -    if (TX_BUFFS_AVAIL > 0) {                   /* Fill in a Tx ring entry */
  10498. -      if (((u_long)skb->data & ~0x03) != (u_long)skb->data) {
  10499. -    printk("%s: TX skb buffer alignment prob..\n", dev->name);
  10500. -      }
  10501. -
  10502. +    if (TX_BUFFS_AVAIL) {                       /* Fill in a Tx ring entry */
  10503.        load_packet(dev, skb->data, TD_IC | TD_LS | TD_FS | skb->len, skb);
  10504. -      outl(POLL_DEMAND, DE4X5_TPD);             /* Start the TX */
  10505. +      if (lp->tx_enable) {
  10506. +    outl(POLL_DEMAND, DE4X5_TPD);           /* Start the TX */
  10507. +      }
  10508.  
  10509.        lp->tx_new = (++lp->tx_new) % lp->txRingSize; /* Ensure a wrap */
  10510.      
  10511.        dev->trans_start = jiffies;
  10512.      }
  10513.  
  10514. -    if (TX_BUFFS_AVAIL > 0) {
  10515. +    if (TX_BUFFS_AVAIL) {
  10516.        dev->tbusy = 0;                           /* Another pkt may be queued */
  10517.      }
  10518.    }
  10519. @@ -882,12 +981,12 @@
  10520.  ** The DE4X5 interrupt handler. 
  10521.  */
  10522.  static void
  10523. -de4x5_interrupt(int irq, struct pt_regs * regs)
  10524. +de4x5_interrupt(int irq, struct pt_regs *regs)
  10525.  {
  10526.      struct device *dev = (struct device *)(irq2dev_map[irq]);
  10527.      struct de4x5_private *lp;
  10528.      int iobase;
  10529. -    u_long imr, sts;
  10530. +    u_long imr, omr, sts;
  10531.  
  10532.      if (dev == NULL) {
  10533.      printk ("de4x5_interrupt(): irq %d for unknown device.\n", irq);
  10534. @@ -909,19 +1008,22 @@
  10535.        sts = inl(DE4X5_STS);
  10536.        MASK_IRQs;
  10537.  
  10538. -      /* 
  10539. -      ** Acknowledge the DE4X5 board interrupts
  10540. -      */
  10541. -      outl(sts, DE4X5_STS);
  10542. +      outl(sts, DE4X5_STS);              /* Reset the board interrupts */
  10543.  
  10544. -      if (sts & STS_RI)                     /* Rx interrupt (packet[s] arrived) */
  10545. +      if (sts & (STS_RI | STS_RU))     /* Rx interrupt (packet[s] arrived) */
  10546.      de4x5_rx(dev);
  10547.  
  10548. -      if (sts & STS_TI)                  /* Tx interrupt (packet sent) */
  10549. +      if (sts & (STS_TI | STS_TU))       /* Tx interrupt (packet sent) */
  10550.      de4x5_tx(dev); 
  10551.  
  10552. -      if ((TX_BUFFS_AVAIL > 0) && dev->tbusy) { /* any resources available? */
  10553. -    dev->tbusy = 0;                  /* clear TX busy flag */
  10554. +      if (sts & STS_SE) {                /* Bus Error */
  10555. +    STOP_DE4X5;
  10556. +    printk("%s: Fatal bus error occurred, sts=0x%08lx, device stopped.\n", 
  10557. +                                                           dev->name, sts);
  10558. +      }
  10559. +
  10560. +      if (TX_BUFFS_AVAIL && dev->tbusy) {/* Any resources available? */
  10561. +    dev->tbusy = 0;                  /* Clear TX busy flag */
  10562.      mark_bh(NET_BH);
  10563.        }
  10564.  
  10565. @@ -941,7 +1043,6 @@
  10566.    volatile long status;
  10567.    char *buf;
  10568.  
  10569. -  /* Loop over any new packets for sending up the stack */
  10570.    for (entry = lp->rx_new; lp->rx_ring[entry].status >= 0;entry = lp->rx_new) {
  10571.      status = lp->rx_ring[entry].status;
  10572.  
  10573. @@ -957,7 +1058,7 @@
  10574.      if (status & RD_OF)           lp->stats.rx_fifo_errors++;
  10575.        } else {                              /* A valid frame received */
  10576.      struct sk_buff *skb;
  10577. -    short pkt_len = (short)(lp->rx_ring[entry].status >> 16);
  10578. +    short pkt_len = (short)(lp->rx_ring[entry].status >> 16) - 4;
  10579.  
  10580.      if ((skb = alloc_skb(pkt_len, GFP_ATOMIC)) != NULL) {
  10581.        skb->len = pkt_len;
  10582. @@ -982,7 +1083,7 @@
  10583.        */
  10584.        lp->stats.rx_packets++;
  10585.        for (i=1; i<DE4X5_PKT_STAT_SZ-1; i++) {
  10586. -        if (pkt_len < i*DE4X5_PKT_BIN_SZ) {
  10587. +        if (pkt_len < (i*DE4X5_PKT_BIN_SZ)) {
  10588.            lp->pktStats.bins[i]++;
  10589.            i = DE4X5_PKT_STAT_SZ;
  10590.          }
  10591. @@ -1034,7 +1135,7 @@
  10592.  {
  10593.    struct de4x5_private *lp = (struct de4x5_private *)dev->priv;
  10594.    int entry, iobase = dev->base_addr;
  10595. -  volatile long status;
  10596. +  long status;
  10597.  
  10598.    for (entry = lp->tx_old; entry != lp->tx_new; entry = lp->tx_old) {
  10599.      status = lp->tx_ring[entry].status;
  10600. @@ -1100,6 +1201,12 @@
  10601.  
  10602.    MOD_DEC_USE_COUNT;
  10603.  
  10604. +  /* Put the adapter to sleep to save power */
  10605. +  if (lp->chipset == DC21041) {
  10606. +    outl(0, DE4X5_SICR);
  10607. +    outl(CFDA_PSM, PCI_CFDA);
  10608. +  }
  10609. +
  10610.    return 0;
  10611.  }
  10612.  
  10613. @@ -1109,7 +1216,7 @@
  10614.    struct de4x5_private *lp = (struct de4x5_private *)dev->priv;
  10615.    int iobase = dev->base_addr;
  10616.  
  10617. -  lp->stats.rx_missed_errors = (int) inl(DE4X5_MFC);
  10618. +  lp->stats.rx_missed_errors = (int) (inl(DE4X5_MFC) & (MFC_OVFL | MFC_CNTR));
  10619.      
  10620.    return &lp->stats;
  10621.  }
  10622. @@ -1128,42 +1235,39 @@
  10623.  }
  10624.  /*
  10625.  ** Set or clear the multicast filter for this adaptor.
  10626. -** num_addrs == -1    Promiscuous mode, receive all packets
  10627. +** num_addrs == -1    Promiscuous mode, receive all packets - not supported.
  10628. +**                      Use the ioctls.
  10629.  ** num_addrs == 0    Normal mode, clear multicast list
  10630.  ** num_addrs > 0    Multicast mode, receive normal and MC packets, and do
  10631.  **             best-effort filtering.
  10632.  ** num_addrs == HASH_TABLE_LEN
  10633. -**                    Set all multicast bits
  10634. +**                    Set all multicast bits (pass all multicasts).
  10635.  */
  10636.  static void
  10637.  set_multicast_list(struct device *dev, int num_addrs, void *addrs)
  10638.  {
  10639.    struct de4x5_private *lp = (struct de4x5_private *)dev->priv;
  10640.    int iobase = dev->base_addr;
  10641. -  u_long omr;
  10642.  
  10643.    /* First, double check that the adapter is open */
  10644.    if (irq2dev_map[dev->irq] != NULL) {
  10645. -    omr = inl(DE4X5_OMR);
  10646. -
  10647.      if (num_addrs >= 0) {
  10648. -      SetMulticastFilter(dev, num_addrs, (char *)addrs, lp->setup_frame);
  10649. -
  10650. -      /* Tell the hardware that there's a new packet to be sent */
  10651. -      load_packet(dev, lp->setup_frame, TD_IC | HASH_F | TD_SET | 
  10652. +      SetMulticastFilter(dev, num_addrs, (char *)addrs);
  10653. +      if (lp->setup_f == HASH_PERF) {
  10654. +    load_packet(dev, lp->setup_frame, TD_IC | HASH_F | TD_SET | 
  10655. +                                                SETUP_FRAME_LEN, NULL);
  10656. +      } else {
  10657. +    load_packet(dev, lp->setup_frame, TD_IC | PERFECT_F | TD_SET | 
  10658.                                                  SETUP_FRAME_LEN, NULL);
  10659. +      }
  10660. +
  10661.        lp->tx_new = (++lp->tx_new) % lp->txRingSize;
  10662.        outl(POLL_DEMAND, DE4X5_TPD);                /* Start the TX */
  10663. -
  10664. -      omr &= ~OMR_PR;
  10665. -      omr |= OMR_PM;
  10666. -      outl(omr, DE4X5_OMR);
  10667. -    } else {                             /* set promiscuous mode */
  10668. -      omr |= OMR_PR;
  10669. -      omr &= ~OMR_PM;
  10670. -      outl(omr, DE4X5_OMR);
  10671. +      dev->trans_start = jiffies;
  10672.      }
  10673.    }
  10674. +
  10675. +  return;
  10676.  }
  10677.  
  10678.  /*
  10679. @@ -1171,49 +1275,58 @@
  10680.  ** from a list of ethernet multicast addresses.
  10681.  ** Little endian crc one liner from Matt Thomas, DEC.
  10682.  */
  10683. -static void SetMulticastFilter(struct device *dev, int num_addrs, char *addrs, char *multicast_table)
  10684. +static void SetMulticastFilter(struct device *dev, int num_addrs, char *addrs)
  10685.  {
  10686. -  char j, bit, byte;
  10687. -  long *p = (long *) multicast_table;
  10688. -  int i;
  10689. +  struct de4x5_private *lp = (struct de4x5_private *)dev->priv;
  10690. +  int i, j, bit, byte, iobase = dev->base_addr;
  10691.    u_short hashcode;
  10692. -  u_long crc, poly = CRC_POLYNOMIAL_LE;
  10693. +  u_long crc, omr, poly = CRC_POLYNOMIAL_LE;
  10694. +  char *pa;
  10695.  
  10696. -  if (num_addrs == HASH_TABLE_LEN) {
  10697. -    for (i=0; i<(HASH_TABLE_LEN >> 4); i++) {
  10698. -      *p++ = 0x0000ffff;
  10699. -    }
  10700. -  } else {
  10701. -    /* Clear the multicast table except for the broadcast bit */
  10702. -    memset(multicast_table, 0, (HASH_TABLE_LEN >> 2));
  10703. -    *(multicast_table + (HASH_TABLE_LEN >> 3) - 3) = 0x80;
  10704. -
  10705. -    /* Now update the table */
  10706. -    for (i=0;i<num_addrs;i++) {              /* for each address in the list */
  10707. -      if ((*addrs & 0x01) == 1) {            /* multicast address? */ 
  10708. -    crc = 0xffffffff;                    /* init CRC for each address */
  10709. -    for (byte=0;byte<ETH_ALEN;byte++) {  /* for each address byte */
  10710. +  omr = inl(DE4X5_OMR);
  10711. +  pa = build_setup_frame(dev, ALL);          /* Build the basic frame */
  10712. +
  10713. +  if (lp->setup_f == HASH_PERF) {
  10714. +    if (num_addrs == HASH_TABLE_LEN) {       /* Pass all multicasts */
  10715. +      omr |= OMR_PM;
  10716. +    } else {
  10717. +      omr &= ~OMR_PM;
  10718. +                                             /* Now update the MCA table */
  10719. +      for (i=0;i<num_addrs;i++) {            /* for each address in the list */
  10720. +    if ((*addrs & 0x01) == 1) {          /* multicast address? */ 
  10721. +      crc = 0xffffffff;                  /* init CRC for each address */
  10722. +      for (byte=0;byte<ETH_ALEN;byte++) {/* for each address byte */
  10723.                                           /* process each address bit */ 
  10724. -      for (bit = *addrs++,j=0;j<8;j++, bit>>=1) {
  10725. -        crc = (crc >> 1) ^ (((crc ^ bit) & 0x01) ? poly : 0);
  10726. +        for (bit = *addrs++,j=0;j<8;j++, bit>>=1) {
  10727. +          crc = (crc >> 1) ^ (((crc ^ bit) & 0x01) ? poly : 0);
  10728. +        }
  10729.        }
  10730. -    }
  10731. -    hashcode = crc & ((1 << 9) - 1);     /* hashcode is 9 LSb of CRC */
  10732. +      hashcode = crc & HASH_BITS;        /* hashcode is 9 LSb of CRC */
  10733.  
  10734. -    byte = hashcode >> 3;                /* bit[3-8] -> byte in filter */
  10735. -    bit = 1 << (hashcode & 0x07);        /* bit[0-2] -> bit in byte */
  10736. +      byte = hashcode >> 3;              /* bit[3-8] -> byte in filter */
  10737. +      bit = 1 << (hashcode & 0x07);      /* bit[0-2] -> bit in byte */
  10738.  
  10739. -    byte <<= 1;                          /* calc offset into setup frame */
  10740. -    if (byte & 0x02) {
  10741. -      byte -= 1;
  10742. +      byte <<= 1;                        /* calc offset into setup frame */
  10743. +      if (byte & 0x02) {
  10744. +        byte -= 1;
  10745. +      }
  10746. +      lp->setup_frame[byte] |= bit;
  10747. +      
  10748. +    } else {                             /* skip this address */
  10749. +      addrs += ETH_ALEN;
  10750.      }
  10751. -    multicast_table[byte] |= bit;
  10752. -
  10753. -      } else {                               /* skip this address */
  10754. -    addrs += ETH_ALEN;
  10755. +      }
  10756. +    }
  10757. +  } else {                                   /* Perfect filtering */
  10758. +    omr &= ~OMR_PM;
  10759. +    for (j=0; j<num_addrs; j++) {
  10760. +      for (i=0; i<ETH_ALEN; i++) { 
  10761. +    *(pa + (i&1)) = *addrs++;
  10762. +    if (i & 0x01) pa += 4;
  10763.        }
  10764.      }
  10765.    }
  10766. +  outl(omr, DE4X5_OMR);
  10767.  
  10768.    return;
  10769.  }
  10770. @@ -1226,8 +1339,10 @@
  10771.  {
  10772.    int i, maxSlots;
  10773.    int status;
  10774. -  u_short iobase;
  10775. +  u_short vendor, device, iobase;
  10776.    struct bus_type *lp = &bus;
  10777. +  char name[DE4X5_STRLEN];
  10778. +  long cfid;
  10779.  
  10780.    if (!ioaddr && autoprobed) return ;            /* Been here before ! */
  10781.    if ((ioaddr < 0x1000) && (ioaddr > 0)) return; /* PCI MODULE special */
  10782. @@ -1244,17 +1359,30 @@
  10783.      maxSlots = i + 1;
  10784.    }
  10785.  
  10786. -  for (status = -ENODEV; i<maxSlots && dev!=NULL; i++, iobase+=EISA_SLOT_INC) {
  10787. -    if ((DevicePresent(EISA_APROM) == 0) || is_zynx) { 
  10788. -      if (check_region(iobase, DE4X5_EISA_TOTAL_SIZE) == 0) {
  10789. -    if ((dev = alloc_device(dev, iobase)) != NULL) {
  10790. -      if ((status = de4x5_hw_init(dev, iobase)) == 0) {
  10791. -        num_de4x5s++;
  10792. -      }
  10793. +  for (status = -ENODEV; (i<maxSlots) && (dev!=NULL); i++, iobase+=EISA_SLOT_INC) {
  10794. +    if (EISA_signature(name, EISA_ID)) {
  10795. +      cfid = inl(PCI_CFID);
  10796. +      device = (u_short)(cfid >> 16);
  10797. +      vendor = (u_short) cfid;
  10798. +
  10799. +      lp->bus = EISA;
  10800. +      lp->chipset = device;
  10801. +      if (DevicePresent(EISA_APROM) == 0) { 
  10802. +    /* Write the PCI Configuration Registers */
  10803. +    outl(PCI_COMMAND_IO | PCI_COMMAND_MASTER, PCI_CFCS);
  10804. +    outl(0x00004000, PCI_CFLT);
  10805. +    outl((u_long)iobase, PCI_CBIO);
  10806. +
  10807. +    if (check_region(iobase, DE4X5_EISA_TOTAL_SIZE) == 0) {
  10808. +      if ((dev = alloc_device(dev, iobase)) != NULL) {
  10809. +        if ((status = de4x5_hw_init(dev, iobase)) == 0) {
  10810. +          num_de4x5s++;
  10811. +        }
  10812.        num_eth++;
  10813. +      }
  10814. +    } else if (autoprobed) {
  10815. +      printk("%s: region already allocated at 0x%04x.\n", dev->name, iobase);
  10816.      }
  10817. -      } else if (autoprobed) {
  10818. -    printk("%s: region already allocated at 0x%04x.\n", dev->name, iobase);
  10819.        }
  10820.      }
  10821.    }
  10822. @@ -1295,15 +1423,18 @@
  10823.        dev_last = PCI_LAST_DEV;
  10824.      }
  10825.  
  10826. -    for (; dev_num < dev_last && dev != NULL; dev_num++) {
  10827. +    for (; (dev_num < dev_last) && (dev != NULL); dev_num++) {
  10828.        pcibios_read_config_dword(pb, PCI_DEVICE, PCI_CLASS_REVISION, &class);
  10829.        if (class != 0xffffffff) {
  10830.      pcibios_read_config_word(pb, PCI_DEVICE, PCI_VENDOR_ID, &vendor);
  10831.      pcibios_read_config_word(pb, PCI_DEVICE, PCI_DEVICE_ID, &device);
  10832. -    if ((vendor == DC21040_VID) && (device == DC21040_DID)) {
  10833. +    if (is_DC21040 || is_DC21041 || is_DC21140) {
  10834.        /* Set the device number information */
  10835.        lp->device = dev_num;
  10836.  
  10837. +      /* Set the chipset information */
  10838. +      lp->chipset = device;
  10839. +
  10840.        /* Get the board I/O address */
  10841.        pcibios_read_config_dword(pb, PCI_DEVICE, PCI_BASE_ADDRESS_0, &iobase);
  10842.        iobase &= CBIO_MASK;
  10843. @@ -1317,7 +1448,7 @@
  10844.        pcibios_write_config_word(pb, PCI_DEVICE, PCI_COMMAND, status);
  10845.  
  10846.        /* If there is a device and I/O region is open, initialise dev. */
  10847. -      if ((DevicePresent(DE4X5_APROM) == 0) || is_zynx) {
  10848. +      if ((DevicePresent(DE4X5_APROM) == 0) || is_not_dec) {
  10849.          if (check_region(iobase, DE4X5_PCI_TOTAL_SIZE) == 0) {
  10850.            if ((dev = alloc_device(dev, iobase)) != NULL) {
  10851.          dev->irq = irq;
  10852. @@ -1457,120 +1588,322 @@
  10853.  static int autoconf_media(struct device *dev)
  10854.  {
  10855.    struct de4x5_private *lp = (struct de4x5_private *)dev->priv;
  10856. -  int media, entry, iobase = dev->base_addr;
  10857. -  char frame[64];
  10858. -  u_long i, omr, sisr, linkBad;
  10859. -/*  u_long t_330ms = 920000;*/
  10860. -  u_long t_3s    = 8000000;
  10861. +  int iobase = dev->base_addr;
  10862.  
  10863. -  /* Set up for TP port, with LEDs */
  10864. -  media = TP;
  10865. -  RESET_SIA;
  10866. -  outl(SICR_OE57 | SICR_SEL | SICR_SRL, DE4X5_SICR);
  10867. +  if (lp->chipset == DC21040) {
  10868. +    lp->media = (lp->autosense == AUTO ? TP : lp->autosense);
  10869. +    dc21040_autoconf(dev);
  10870. +  } else if (lp->chipset == DC21041) {
  10871. +    lp->media = (lp->autosense == AUTO ? TP_NW : lp->autosense);
  10872. +    dc21041_autoconf(dev);
  10873. +  } else if (lp->chipset == DC21140) {
  10874. +    /* Force 10Mb/s (_100Mb for 100Mb/s) */
  10875. +    lp->media = (lp->autosense == AUTO ? _10Mb : lp->autosense);
  10876. +    dc21140_autoconf(dev);
  10877. +  }
  10878. +
  10879. +  if (de4x5_debug >= 1 ) {
  10880. +    if (lp->chipset != DC21140) {
  10881. +      printk("%s: Media is %s\n",dev->name,
  10882. +                                    (lp->media == NC  ? "unconnected!" :
  10883. +                    (lp->media == TP  ? "TP." :
  10884. +                    (lp->media == ANS ? "TP/Nway." :
  10885. +                    (lp->media == BNC ? "BNC." : 
  10886. +                    (lp->media == AUI ? "AUI." : 
  10887. +                                                            "BNC/AUI."
  10888. +                    ))))));
  10889. +    } else {
  10890. +      printk("%s: Mode is forced to %s\n",dev->name,
  10891. +                                    (lp->media == NC      ? "link down.":
  10892. +                    (lp->media == _100Mb  ? "100Mb/s." :
  10893. +                    (lp->media == _10Mb   ? "10Mb/s." :
  10894. +                                            "\?\?\?"
  10895. +                    ))));
  10896. +    }
  10897. +  }
  10898.  
  10899. -  /* Test the TP port */
  10900. -  for (linkBad=1,i=0;i<t_3s && linkBad;i++) {
  10901. -    if (((sisr = inl(DE4X5_SISR)) & SISR_LKF) == 0) linkBad = 0;
  10902. -    if (sisr & SISR_NCR) break;
  10903. +  if (lp->media) {
  10904. +    lp->lostMedia = 0;
  10905. +    inl(DE4X5_MFC);                         /* Zero the lost frames counter */
  10906.    }
  10907. -    
  10908. -  if (linkBad) {
  10909. -    /* Set up for BNC (Thinwire) port, with LEDs */
  10910. -    media = BNC;
  10911. -    RESET_SIA;
  10912. -    outl(SIGR_JCK | SIGR_HUJ, DE4X5_SIGR);
  10913. -    outl(STRR_CLD | STRR_CSQ | STRR_RSQ | STRR_DREN | STRR_ECEN, DE4X5_STRR);
  10914. -    outl(SICR_OE57| SICR_OE24 | SICR_OE13 | SICR_SEL |
  10915. -                                         SICR_AUI | SICR_SRL, DE4X5_SICR);
  10916. +  dce_ms_delay(10);
  10917. +
  10918. +  return (lp->media);
  10919. +}
  10920. +
  10921. +static void dc21040_autoconf(struct device *dev)
  10922. +{
  10923. +  struct de4x5_private *lp = (struct de4x5_private *)dev->priv;
  10924. +  int iobase = dev->base_addr;
  10925. +  u_long i, sisr = 0, linkBad;
  10926. +  u_long t_3s    = 3000;
  10927. +
  10928. +  switch (lp->media) {
  10929. +  case TP:
  10930. +    reset_init_sia(dev, 0x8f01, 0xffff, 0x0000);
  10931. +    for (linkBad=1,i=0;(i<t_3s) && linkBad && !(sisr & SISR_NCR);i++) {
  10932. +      if (((sisr = inl(DE4X5_SISR)) & SISR_LKF) == 0) linkBad = 0;
  10933. +      dce_ms_delay(1);
  10934. +    }
  10935. +    if (linkBad && (lp->autosense == AUTO)) {
  10936. +      lp->media = BNC_AUI;
  10937. +      dc21040_autoconf(dev);
  10938. +    }
  10939. +    break;
  10940.  
  10941. -    /* Wait 330ms */
  10942. +  case BNC:
  10943. +  case AUI:
  10944. +  case BNC_AUI:
  10945. +    reset_init_sia(dev, 0x8f09, 0x0705, 0x0006);
  10946.      dce_ms_delay(330);
  10947. -/*    for (i=0; i<t_330ms; i++) {
  10948. -      sisr = inl(DE4X5_SISR);
  10949. +    linkBad = ping_media(dev);
  10950. +    if (linkBad && (lp->autosense == AUTO)) {
  10951. +      lp->media = NC;
  10952. +      dc21040_autoconf(dev);
  10953.      }
  10954. +    break;
  10955. +
  10956. +  case NC:
  10957. +    reset_init_sia(dev, 0x8f01, 0xffff, 0x0000);
  10958. +    break;
  10959. +  }
  10960. +
  10961. +  return;
  10962. +}
  10963. +
  10964. +/*
  10965. +** Autoconfigure the media when using the DC21041. AUI needs to be tested
  10966. +** before BNC, because the BNC port will indicate activity if it's not
  10967. +** terminated correctly. The only way to test for that is to place a loopback
  10968. +** packet onto the network and watch for errors.
  10969.  */
  10970. -    /* Make up a dummy packet with CRC error */
  10971. -    create_packet(dev, frame, sizeof(frame));
  10972. +static void dc21041_autoconf(struct device *dev)
  10973. +{
  10974. +  struct de4x5_private *lp = (struct de4x5_private *)dev->priv;
  10975. +  int iobase = dev->base_addr;
  10976. +  u_long sts, irqs, irq_mask, omr;
  10977.  
  10978. -    /* Setup the packet descriptor */
  10979. -    entry = lp->tx_new;                        /* Remember the ring position */
  10980. -    load_packet(dev, frame, TD_LS | TD_FS | TD_AC | sizeof(frame), NULL);
  10981. +  switch (lp->media) {
  10982. +  case TP_NW:
  10983. +    omr = inl(DE4X5_OMR);        /* Set up full duplex for the autonegotiate */
  10984. +    outl(omr | OMR_FD, DE4X5_OMR);
  10985. +    irqs = STS_LNF | STS_LNP;
  10986. +    irq_mask = IMR_LFM | IMR_LPM;
  10987. +    sts = test_media(dev, irqs, irq_mask, 0xef01, 0xffff, 0x0008, 2400);
  10988. +    if (sts & STS_LNP) {
  10989. +      lp->media = ANS;
  10990. +    } else {
  10991. +      lp->media = AUI;
  10992. +    }
  10993. +    dc21041_autoconf(dev);
  10994. +    break;
  10995.  
  10996. -    /* Start the TX process */
  10997. -    omr = inl(DE4X5_OMR);
  10998. -    outl(omr|OMR_ST, DE4X5_OMR);
  10999. +  case ANS:
  11000. +    irqs = STS_LNP;
  11001. +    irq_mask = IMR_LPM;
  11002. +    sts = test_ans(dev, irqs, irq_mask, 3000);
  11003. +    if (!(sts & STS_LNP) && (lp->autosense == AUTO)) {
  11004. +      lp->media = TP;
  11005. +      dc21041_autoconf(dev);
  11006. +    }
  11007. +    break;
  11008.  
  11009. -    /* Update pointers */
  11010. -    lp->tx_new = (++lp->tx_new) % lp->txRingSize;
  11011. -    lp->tx_old = lp->tx_new;
  11012. +  case TP:
  11013. +    omr = inl(DE4X5_OMR);                      /* Set up half duplex for TP */
  11014. +    outl(omr & ~OMR_FD, DE4X5_OMR);
  11015. +    irqs = STS_LNF | STS_LNP;
  11016. +    irq_mask = IMR_LFM | IMR_LPM;
  11017. +    sts = test_media(dev, irqs, irq_mask, 0xef01, 0xff3f, 0x0008, 2400);
  11018. +    if (!(sts & STS_LNP) && (lp->autosense == AUTO)) {
  11019. +      if (inl(DE4X5_SISR) & SISR_NRA) {    /* Non selected port activity */
  11020. +    lp->media = AUI;
  11021. +      } else {
  11022. +    lp->media = BNC;
  11023. +      }
  11024. +      dc21041_autoconf(dev);
  11025. +    }
  11026. +    break;
  11027.  
  11028. -    /* 
  11029. -    ** Poll for completion of frame (interrupts are disabled for now)...
  11030. -    ** Allow upto 3 seconds to complete.
  11031. -    */
  11032. -    for (linkBad=1,i=0;i<t_3s && linkBad;i++) {
  11033. -      if ((inl(DE4X5_SISR) & SISR_NCR) == 1) break;
  11034. -      if (lp->tx_ring[entry].status >= 0) linkBad=0;
  11035. +  case AUI:
  11036. +    omr = inl(DE4X5_OMR);                      /* Set up half duplex for AUI */
  11037. +    outl(omr & ~OMR_FD, DE4X5_OMR);
  11038. +    irqs = 0;
  11039. +    irq_mask = 0;
  11040. +    sts = test_media(dev, irqs, irq_mask, 0xef09, 0xf7fd, 0x000e, 1000);
  11041. +    if (!(inl(DE4X5_SISR) & SISR_SRA) && (lp->autosense == AUTO)) {
  11042. +      lp->media = BNC;
  11043. +      dc21041_autoconf(dev);
  11044.      }
  11045. -    
  11046. -    outl(omr, DE4X5_OMR);                        /* Stop everything! */
  11047. +    break;
  11048.  
  11049. -    if (linkBad || (lp->tx_ring[entry].status & TD_ES)) {
  11050. -      /* Set up for AUI (Thickwire) port, with LEDs */
  11051. -      media = AUI;
  11052. -      RESET_SIA;
  11053. -      outl(SIGR_JCK | SIGR_HUJ, DE4X5_SIGR);
  11054. -      outl(STRR_CLD | STRR_CSQ | STRR_RSQ | STRR_DREN | STRR_ECEN, DE4X5_STRR);
  11055. -      outl(SICR_OE57| SICR_SEL | SICR_AUI | SICR_SRL, DE4X5_SICR);
  11056. -      
  11057. -      /* Wait 330ms */
  11058. -      dce_ms_delay(330);
  11059. +  case BNC:
  11060. +    omr = inl(DE4X5_OMR);                      /* Set up half duplex for BNC */
  11061. +    outl(omr & ~OMR_FD, DE4X5_OMR);
  11062. +    irqs = 0;
  11063. +    irq_mask = 0;
  11064. +    sts = test_media(dev, irqs, irq_mask, 0xef09, 0xf7fd, 0x0006, 1000);
  11065. +    if (!(inl(DE4X5_SISR) & SISR_SRA) && (lp->autosense == AUTO)) {
  11066. +      lp->media = NC;
  11067. +    } else {                                   /* Ensure media connected */
  11068. +      if (ping_media(dev)) lp->media = NC;
  11069. +    }
  11070. +    break;
  11071.  
  11072. -      /* Setup the packet descriptor */
  11073. -      entry = lp->tx_new;                      /* Remember the ring position */
  11074. -      load_packet(dev, frame, TD_LS | TD_FS | TD_AC | sizeof(frame), NULL);
  11075. -      
  11076. -      /* Start the TX process */
  11077. -      omr = inl(DE4X5_OMR);
  11078. -      outl(omr|OMR_ST, DE4X5_OMR);
  11079. +  case NC:
  11080. +    omr = inl(DE4X5_OMR);        /* Set up full duplex for the autonegotiate */
  11081. +    outl(omr | OMR_FD, DE4X5_OMR);
  11082. +    reset_init_sia(dev, 0xef01, 0xffff, 0x0008);/* Initialise the SIA */
  11083. +    break;
  11084. +  }
  11085.  
  11086. -      /* Update pointers */
  11087. -      lp->tx_new = (++lp->tx_new) % lp->txRingSize;
  11088. -      lp->tx_old = lp->tx_new;
  11089. +  return;
  11090. +}
  11091.  
  11092. -      /* 
  11093. -      ** Poll for completion of frame (interrupts are disabled for now)...
  11094. -      ** Allow 3 seconds to complete.
  11095. -      */
  11096. -      for (linkBad=1,i=0;i<t_3s && linkBad;i++) {
  11097. -    if ((inl(DE4X5_SISR) & SISR_NCR) == 1) break;
  11098. -    if (lp->tx_ring[entry].status >= 0) linkBad=0;
  11099. -      }
  11100. -    
  11101. -      outl(omr, DE4X5_OMR);                        /* Stop everything! */
  11102. +/*
  11103. +** Reduced feature version (temporary I hope)
  11104. +*/
  11105. +static void dc21140_autoconf(struct device *dev)
  11106. +{
  11107. +  struct de4x5_private *lp = (struct de4x5_private *)dev->priv;
  11108. +  int iobase = dev->base_addr;
  11109. +  u_long omr;
  11110.  
  11111. -      if (linkBad || (lp->tx_ring[entry].status & TD_ES)) {
  11112. -    /* Reset the SIA */
  11113. -    outl(SICR_RESET, DE4X5_SICR);        /* Reset SIA connectivity regs */
  11114. -    outl(STRR_RESET, DE4X5_STRR);        /* Write reset values */
  11115. -    outl(SIGR_RESET, DE4X5_SIGR);        /* Write reset values */
  11116. +  switch(lp->media) {
  11117. +  case _100Mb:      /* Set 100Mb/s, MII Port with PCS Function and Scrambler */
  11118. +    omr = (inl(DE4X5_OMR) & ~(OMR_PS | OMR_HBD | OMR_TTM | OMR_PCS | OMR_SCR));
  11119. +    outl(omr | OMR_PS | OMR_HBD | OMR_PCS | OMR_SCR, DE4X5_OMR);
  11120. +    outl(GEP_FDXD | GEP_MODE, DE4X5_GEP);
  11121. +    break;
  11122.  
  11123. -    media = NC;
  11124. -      }
  11125. -    } 
  11126. +  case _10Mb:       /* Set conventional 10Mb/s ENDEC interface */
  11127. +    omr = (inl(DE4X5_OMR) & ~(OMR_PS | OMR_HBD | OMR_TTM | OMR_PCS | OMR_SCR));
  11128. +    outl(omr | OMR_TTM, DE4X5_OMR);
  11129. +    outl(GEP_FDXD, DE4X5_GEP);
  11130. +    break;
  11131.    }
  11132.  
  11133. -  if (de4x5_debug >= 1 ) {
  11134. -    printk("%s: Media is %s.\n",dev->name, 
  11135. -                                 (media == NC  ? "unconnected to this device" :
  11136. -                                 (media == TP  ? "TP" :
  11137. -                                 (media == BNC ? "BNC" : 
  11138. -                                                 "AUI"))));
  11139. +  return;
  11140. +}
  11141. +
  11142. +static long test_media(struct device *dev, long irqs, long irq_mask, long csr13, long csr14, long csr15, long msec)
  11143. +{
  11144. +  struct de4x5_private *lp = (struct de4x5_private *)dev->priv;
  11145. +  int iobase = dev->base_addr;
  11146. +  long sts, time, csr12;
  11147. +
  11148. +  reset_init_sia(dev, csr13, csr14, csr15);
  11149. +
  11150. +  /* Set link_fail_inhibit_timer */
  11151. +  load_ms_timer(dev, msec);
  11152. +
  11153. +  /* clear all pending interrupts */
  11154. +  sts = inl(DE4X5_STS);
  11155. +  outl(sts, DE4X5_STS);
  11156. +
  11157. +  /* clear csr12 NRA and SRA bits */
  11158. +  csr12 = inl(DE4X5_SISR);
  11159. +  outl(csr12, DE4X5_SISR);
  11160. +
  11161. +  /* Poll for timeout - timer interrupt doesn't work correctly */
  11162. +  do {
  11163. +    time = inl(DE4X5_GPT) & GPT_VAL;
  11164. +    sts = inl(DE4X5_STS);
  11165. +  } while ((time != 0) && !(sts & irqs));
  11166. +
  11167. +  sts = inl(DE4X5_STS);
  11168. +
  11169. +  return sts;
  11170. +}
  11171. +
  11172. +/*
  11173. +** Send a packet onto the media and watch for send errors that indicate the
  11174. +** media is bad or unconnected.
  11175. +*/
  11176. +static long ping_media(struct device *dev)
  11177. +{
  11178. +  struct de4x5_private *lp = (struct de4x5_private *)dev->priv;
  11179. +  int entry, iobase = dev->base_addr;
  11180. +  char frame[64];
  11181. +  long i, linkBad, omr;
  11182. +  u_long t_3s    = 3000;
  11183. +
  11184. +  create_packet(dev, frame, sizeof(frame));
  11185. +
  11186. +  entry = lp->tx_new;                        /* Remember the ring position */
  11187. +  load_packet(dev, frame, TD_LS | TD_FS | sizeof(frame),NULL);
  11188. +
  11189. +  omr = inl(DE4X5_OMR);
  11190. +  outl(omr|OMR_ST, DE4X5_OMR);
  11191. +
  11192. +  lp->tx_new = (++lp->tx_new) % lp->txRingSize;
  11193. +  lp->tx_old = lp->tx_new;
  11194. +
  11195. +  /* Poll for completion of frame (interrupts are disabled for now)... */
  11196. +  for (linkBad=1,i=0;(i<t_3s) && linkBad;i++) {
  11197. +    if ((inl(DE4X5_SISR) & SISR_NCR) == 1) break;
  11198. +    if (lp->tx_ring[entry].status >= 0) linkBad=0;
  11199. +    dce_ms_delay(1);
  11200.    }
  11201. +  outl(omr, DE4X5_OMR); 
  11202. +
  11203. +  return ((linkBad || (lp->tx_ring[entry].status & TD_ES)) ? 1 : 0);
  11204. +}
  11205. +
  11206. +/*
  11207. +** Check the Auto Negotiation State. Return OK when a link pass interrupt
  11208. +** is received and the auto-negotiation status is NWAY OK.
  11209. +*/
  11210. +static int test_ans(struct device *dev, long irqs, long irq_mask, long msec)
  11211. +{
  11212. +  struct de4x5_private *lp = (struct de4x5_private *)dev->priv;
  11213. +  int iobase = dev->base_addr;
  11214. +  long sts, ans;
  11215. +
  11216. +  outl(irq_mask, DE4X5_IMR);
  11217. +
  11218. +  /* Set timeout limit */
  11219. +  load_ms_timer(dev, msec);
  11220. +
  11221. +  /* clear all pending interrupts */
  11222. +  sts = inl(DE4X5_STS);
  11223. +  outl(sts, DE4X5_STS);
  11224. +
  11225. +  /* Poll for interrupts */
  11226. +  do {
  11227. +    ans = inl(DE4X5_SISR) & SISR_ANS;
  11228. +    sts = inl(DE4X5_STS);
  11229. +  } while (!(sts & irqs) && (ans ^ ANS_NWOK) != 0);
  11230. +
  11231. +  return ((sts & STS_LNP) && ((ans ^ ANS_NWOK) == 0) ? STS_LNP : 0);
  11232. +}
  11233. +
  11234. +/*
  11235. +**
  11236. +*/
  11237. +static void reset_init_sia(struct device *dev, long sicr, long strr, long sigr)
  11238. +{
  11239. +  struct de4x5_private *lp = (struct de4x5_private *)dev->priv;
  11240. +  int iobase = dev->base_addr;
  11241. +
  11242. +  RESET_SIA;
  11243. +  outl(sigr, DE4X5_SIGR);
  11244. +  outl(strr, DE4X5_STRR);
  11245. +  outl(sicr, DE4X5_SICR);
  11246. +
  11247. +  return;
  11248. +}
  11249. +
  11250. +/*
  11251. +** Load the timer on the DC21041 and 21140. Max time is 13.42 secs.
  11252. +*/
  11253. +static void load_ms_timer(struct device *dev, u_long msec)
  11254. +{
  11255. +  struct de4x5_private *lp = (struct de4x5_private *)dev->priv;
  11256. +  int iobase = dev->base_addr;
  11257.  
  11258. -  if (media) lp->lostMedia = 0;
  11259. +  outl((long)(msec * 10000)/2048, DE4X5_GPT);
  11260.  
  11261. -  return media;
  11262. +  return;
  11263.  }
  11264.  
  11265.  /*
  11266. @@ -1578,7 +1911,7 @@
  11267.  */
  11268.  static void create_packet(struct device *dev, char *frame, int len)
  11269.  {
  11270. -  int i, j;
  11271. +  int i;
  11272.    char *buf = frame;
  11273.  
  11274.    for (i=0; i<ETH_ALEN; i++) {             /* Use this source address */
  11275. @@ -1587,58 +1920,25 @@
  11276.    for (i=0; i<ETH_ALEN; i++) {             /* Use this destination address */
  11277.      *buf++ = dev->dev_addr[i];
  11278.    }
  11279. -  for (j=1; j>=0; j--) {                   /* Packet length (2 bytes) */
  11280. -    *buf++ = (char) ((len >> 8*j) & 0xff);
  11281. -  }
  11282. -  *buf++ = 0;                              /* Data */
  11283.  
  11284. -  for (i=len-4; i<len; i++) {              /* CRC */
  11285. -    buf[i] = 0;
  11286. -  }
  11287. +  *buf++ = 0;                              /* Packet length (2 bytes) */
  11288. +  *buf++ = 1;
  11289.    
  11290.    return;
  11291.  }
  11292.  
  11293.  /*
  11294. -** Get the timer ticks from the PIT
  11295. -*/
  11296. -static u_short dce_get_ticks(void)
  11297. -{
  11298. -  u_short ticks = 0;
  11299. -  
  11300. -  /* Command 8254 to latch T0's count */
  11301. -  outb(TIMER_PORT, TIMER_LATCH);
  11302. -  
  11303. -  /* Read the counter */
  11304. -  ticks = inb(TIMER_READ);
  11305. -  ticks |= (inb(TIMER_READ) << 8);
  11306. -  
  11307. -  return ticks;
  11308. -}
  11309. -
  11310. -/*
  11311.  ** Known delay in microseconds
  11312.  */
  11313.  static void dce_us_delay(u_long usec)
  11314.  {
  11315. -  u_long i, start, now, quant=(DELAY_QUANT*1000)/TIMER_TICK+1;
  11316. -  
  11317. -  for (i=0; i<usec/DELAY_QUANT; i++) {
  11318. -    start=dce_get_ticks();  
  11319. -    for (now=start; (start-now)<quant;) {
  11320. -      now=dce_get_ticks();
  11321. -      if (now > start) {         /* Wrapped counter counting down */
  11322. -    quant -= start;
  11323. -    start = (1 << TIMER_WIDTH);
  11324. -      }
  11325. -    }
  11326. -  }
  11327. +  udelay(usec);
  11328.  
  11329.    return;
  11330.  }
  11331.  
  11332.  /*
  11333. -** Known delay in milliseconds
  11334. +** Known delay in milliseconds, in millisecond steps.
  11335.  */
  11336.  static void dce_ms_delay(u_long msec)
  11337.  {
  11338. @@ -1655,18 +1955,19 @@
  11339.  /*
  11340.  ** Look for a particular board name in the EISA configuration space
  11341.  */
  11342. -static void EISA_signature(char *name, short iobase)
  11343. +int EISA_signature(char *name, long eisa_id)
  11344.  {
  11345.    unsigned long i;
  11346.    char *signatures[] = DE4X5_SIGNATURE;
  11347. -  char ManCode[8];
  11348. +  char ManCode[DE4X5_STRLEN];
  11349.    union {
  11350. -    u_long ID;
  11351. -    u_char Id[4];
  11352. +    long ID;
  11353. +    char Id[4];
  11354.    } Eisa;
  11355. +  int status = 0;
  11356.  
  11357. -  strcpy(name, "");
  11358. -  Eisa.ID = inl(iobase);
  11359. +  *name = '\0';
  11360. +  Eisa.ID = inl(eisa_id);
  11361.  
  11362.    ManCode[0]=(((Eisa.Id[0]>>2)&0x1f)+0x40);
  11363.    ManCode[1]=(((Eisa.Id[1]&0xe0)>>5)+((Eisa.Id[0]&0x03)<<3)+0x40);
  11364. @@ -1675,13 +1976,14 @@
  11365.    ManCode[4]=(((Eisa.Id[3]>>4)&0x0f)+0x30);
  11366.    ManCode[5]='\0';
  11367.  
  11368. -  for (i=0;*signatures[i] != '\0' && *name == '\0';i++) {
  11369. +  for (i=0;(*signatures[i] != '\0') && (*name == '\0');i++) {
  11370.      if (strstr(ManCode, signatures[i]) != NULL) {
  11371.        strcpy(name,ManCode);
  11372. +      status = 1;
  11373.      }
  11374.    }
  11375. -  
  11376. -  return;                                   /* return the device name string */
  11377. +
  11378. +  return status;                           /* return the device name string */
  11379.  }
  11380.  
  11381.  /*
  11382. @@ -1715,26 +2017,34 @@
  11383.    dev.llsig.b = ETH_PROM_SIG;
  11384.    sigLength = sizeof(long) << 1;
  11385.  
  11386. -  for (i=0,j=0;j<sigLength && i<PROBE_LENGTH+sigLength-1;i++) {
  11387. -    if (lp->bus == PCI) {
  11388. -      while ((tmp = inl(aprom_addr)) < 0);
  11389. -      data = (char)tmp;
  11390. -    } else {
  11391. -      data = inb(aprom_addr);
  11392. -    }
  11393. -    if (dev.Sig[j] == data) {   /* track signature */
  11394. -      j++;
  11395. -    } else {                    /* lost signature; begin search again */
  11396. -      if (data == dev.Sig[0]) {
  11397. -    j=1;
  11398. +  if (lp->chipset == DC21040) {
  11399. +    for (i=0,j=0;(j<sigLength) && (i<PROBE_LENGTH+sigLength-1);i++) {
  11400. +      if (lp->bus == PCI) {
  11401. +    while ((tmp = inl(aprom_addr)) < 0);
  11402. +    data = (char)tmp;
  11403.        } else {
  11404. -    j=0;
  11405. +    data = inb(aprom_addr);
  11406. +      }
  11407. +      if (dev.Sig[j] == data) {   /* track signature */
  11408. +    j++;
  11409. +      } else {                    /* lost signature; begin search again */
  11410. +    if (data == dev.Sig[0]) {
  11411. +      j=1;
  11412. +    } else {
  11413. +      j=0;
  11414. +    }
  11415.        }
  11416.      }
  11417. -  }
  11418.  
  11419. -  if (j!=sigLength) {
  11420. -    status = -ENODEV;           /* search failed */
  11421. +    if (j!=sigLength) {
  11422. +      status = -ENODEV;           /* search failed */
  11423. +    }
  11424. +
  11425. +  } else {                        /* use new srom */
  11426. +    short *p = (short *)&lp->srom;
  11427. +    for (i=0; i<(sizeof(struct de4x5_srom)>>1); i++) {
  11428. +      *p++ = srom_rd(aprom_addr, i);
  11429. +    }
  11430.    }
  11431.  
  11432.    return status;
  11433. @@ -1753,12 +2063,17 @@
  11434.      if (k > 0xffff) k-=0xffff;
  11435.  
  11436.      if (lp->bus == PCI) {
  11437. -      while ((tmp = inl(DE4X5_APROM)) < 0);
  11438. -      k += (u_char) tmp;
  11439. -      dev->dev_addr[i++] = (u_char) tmp;
  11440. -      while ((tmp = inl(DE4X5_APROM)) < 0);
  11441. -      k += (u_short) (tmp << 8);
  11442. -      dev->dev_addr[i++] = (u_char) tmp;
  11443. +      if (lp->chipset == DC21040) {
  11444. +    while ((tmp = inl(DE4X5_APROM)) < 0);
  11445. +    k += (u_char) tmp;
  11446. +    dev->dev_addr[i++] = (u_char) tmp;
  11447. +    while ((tmp = inl(DE4X5_APROM)) < 0);
  11448. +    k += (u_short) (tmp << 8);
  11449. +    dev->dev_addr[i++] = (u_char) tmp;
  11450. +      } else {
  11451. +    dev->dev_addr[i] = (u_char) lp->srom.ieee_addr[i]; i++;
  11452. +    dev->dev_addr[i] = (u_char) lp->srom.ieee_addr[i]; i++;
  11453. +      }
  11454.      } else {
  11455.        k += (u_char) (tmp = inb(EISA_APROM));
  11456.        dev->dev_addr[i++] = (u_char) tmp;
  11457. @@ -1771,21 +2086,158 @@
  11458.    if (k == 0xffff) k=0;
  11459.  
  11460.    if (lp->bus == PCI) {
  11461. -    while ((tmp = inl(DE4X5_APROM)) < 0);
  11462. -    chksum = (u_char) tmp;
  11463. -    while ((tmp = inl(DE4X5_APROM)) < 0);
  11464. -    chksum |= (u_short) (tmp << 8);
  11465. +    if (lp->chipset == DC21040) {
  11466. +      while ((tmp = inl(DE4X5_APROM)) < 0);
  11467. +      chksum = (u_char) tmp;
  11468. +      while ((tmp = inl(DE4X5_APROM)) < 0);
  11469. +      chksum |= (u_short) (tmp << 8);
  11470. +      if (k != chksum) status = -1;
  11471. +    }
  11472.    } else {
  11473.      chksum = (u_char) inb(EISA_APROM);
  11474.      chksum |= (u_short) (inb(EISA_APROM) << 8);
  11475. +    if (k != chksum) status = -1;
  11476.    }
  11477.  
  11478. -  if (k != chksum) status = -1;
  11479.  
  11480.    return status;
  11481.  }
  11482.  
  11483.  /*
  11484. +** SROM Read
  11485. +*/
  11486. +static short srom_rd(u_short addr, u_char offset)
  11487. +{
  11488. +  sendto_srom(SROM_RD | SROM_SR, addr);
  11489. +
  11490. +  srom_latch(SROM_RD | SROM_SR | DT_CS, addr);
  11491. +  srom_command(SROM_RD | SROM_SR | DT_IN | DT_CS, addr);
  11492. +  srom_address(SROM_RD | SROM_SR | DT_CS, addr, offset);
  11493. +
  11494. +  return srom_data(SROM_RD | SROM_SR | DT_CS, addr);
  11495. +}
  11496. +
  11497. +static void srom_latch(u_long command, u_short addr)
  11498. +{
  11499. +  sendto_srom(command, addr);
  11500. +  sendto_srom(command | DT_CLK, addr);
  11501. +  sendto_srom(command, addr);
  11502. +
  11503. +  return;
  11504. +}
  11505. +
  11506. +static void srom_command(u_long command, u_short addr)
  11507. +{
  11508. +  srom_latch(command, addr);
  11509. +  srom_latch(command, addr);
  11510. +  srom_latch((command & 0x0000ff00) | DT_CS, addr);
  11511. +
  11512. +  return;
  11513. +}
  11514. +
  11515. +static void srom_address(u_long command, u_short addr, u_char offset)
  11516. +{
  11517. +  long i;
  11518. +  char a;
  11519. +
  11520. +  a = (char)(offset << 2);
  11521. +  for (i=0; i<6; i++, a <<= 1) {
  11522. +    srom_latch(command | ((a < 0) ? DT_IN : 0), addr);
  11523. +  }
  11524. +  dce_us_delay(1);
  11525. +
  11526. +  i = (getfrom_srom(addr) >> 3) & 0x01;
  11527. +  if (i != 0) {
  11528. +    printk("Bad SROM address phase.....\n");
  11529. +  }
  11530. +
  11531. +  return;
  11532. +}
  11533. +
  11534. +static short srom_data(u_long command, u_short addr)
  11535. +{
  11536. +  int i;
  11537. +  short word = 0;
  11538. +  long tmp;
  11539. +
  11540. +  for (i=0; i<16; i++) {
  11541. +    sendto_srom(command  | DT_CLK, addr);
  11542. +    tmp = getfrom_srom(addr);
  11543. +    sendto_srom(command, addr);
  11544. +
  11545. +    word = (word << 1) | ((tmp >> 3) & 0x01);
  11546. +  }
  11547. +
  11548. +  sendto_srom(command & 0x0000ff00, addr);
  11549. +
  11550. +  return word;
  11551. +}
  11552. +
  11553. +/*
  11554. +static void srom_busy(u_long command, u_short addr)
  11555. +{
  11556. +  sendto_srom((command & 0x0000ff00) | DT_CS, addr);
  11557. +
  11558. +  while (!((getfrom_srom(addr) >> 3) & 0x01)) {
  11559. +    dce_ms_delay(1);
  11560. +  }
  11561. +
  11562. +  sendto_srom(command & 0x0000ff00, addr);
  11563. +
  11564. +  return;
  11565. +}
  11566. +*/
  11567. +
  11568. +static void sendto_srom(u_long command, u_short addr)
  11569. +{
  11570. +  outl(command, addr);
  11571. +  dce_us_delay(1);
  11572. +
  11573. +  return;
  11574. +}
  11575. +
  11576. +static long getfrom_srom(u_short addr)
  11577. +{
  11578. +  long tmp;
  11579. +
  11580. +  tmp = inl(addr);
  11581. +  dce_us_delay(1);
  11582. +
  11583. +  return tmp;
  11584. +}
  11585. +
  11586. +static char *build_setup_frame(struct device *dev, int mode)
  11587. +{
  11588. +  struct de4x5_private *lp = (struct de4x5_private *)dev->priv;
  11589. +  int i;
  11590. +  char *pa = lp->setup_frame;
  11591. +
  11592. +  /* Initialise the setup frame */
  11593. +  if (mode == ALL) {
  11594. +    memset(lp->setup_frame, 0, SETUP_FRAME_LEN);
  11595. +  }
  11596. +
  11597. +  if (lp->setup_f == HASH_PERF) {
  11598. +    for (pa=lp->setup_frame+IMPERF_PA_OFFSET, i=0; i<ETH_ALEN; i++) {
  11599. +      *(pa + i) = dev->dev_addr[i];                 /* Host address */
  11600. +      if (i & 0x01) pa += 2;
  11601. +    }
  11602. +    *(lp->setup_frame + (HASH_TABLE_LEN >> 3) - 3) = 0x80; /* B'cast address */
  11603. +  } else {
  11604. +    for (i=0; i<ETH_ALEN; i++) { /* Host address */
  11605. +      *(pa + (i&1)) = dev->dev_addr[i];
  11606. +      if (i & 0x01) pa += 4;
  11607. +    }
  11608. +    for (i=0; i<ETH_ALEN; i++) { /* Broadcast address */
  11609. +      *(pa + (i&1)) = (char) 0xff;
  11610. +      if (i & 0x01) pa += 4;
  11611. +    }
  11612. +  }
  11613. +
  11614. +  return pa;                     /* Points to the next entry */
  11615. +}
  11616. +
  11617. +/*
  11618.  ** Perform IOCTL call functions here. Some are privileged operations and the
  11619.  ** effective uid is checked in those cases.
  11620.  */
  11621. @@ -1812,29 +2264,20 @@
  11622.      break;
  11623.    case DE4X5_SET_HWADDR:             /* Set the hardware address */
  11624.      if (suser()) {
  11625. -      int offset;
  11626. -      char *pa;
  11627. -      u_long omr;
  11628. -
  11629.        memcpy_fromfs(tmp.addr,ioc->data,ETH_ALEN);
  11630.        for (i=0; i<ETH_ALEN; i++) {
  11631.      dev->dev_addr[i] = tmp.addr[i];
  11632.        }
  11633. -      omr = inl(DE4X5_OMR);
  11634. -      if (omr & OMR_HP) {
  11635. -    offset = IMPERF_PA_OFFSET;
  11636. -      } else {
  11637. -    offset = PERF_PA_OFFSET;
  11638. -      }
  11639. -      /* Insert the physical address */
  11640. -      for (pa=lp->setup_frame+offset, i=0; i<ETH_ALEN; i++) {
  11641. -    *(pa + i) = dev->dev_addr[i];
  11642. -    if (i & 0x01) pa += 2;
  11643. -      }
  11644. +      build_setup_frame(dev, PHYS_ADDR_ONLY);
  11645.        /* Set up the descriptor and give ownership to the card */
  11646.        while (set_bit(0, (void *)&dev->tbusy) != 0); /* Wait for lock to free */
  11647. -      load_packet(dev, lp->setup_frame, TD_IC | HASH_F | TD_SET | 
  11648. +      if (lp->setup_f == HASH_PERF) {
  11649. +    load_packet(dev, lp->setup_frame, TD_IC | HASH_F | TD_SET | 
  11650. +                                                SETUP_FRAME_LEN, NULL);
  11651. +      } else {
  11652. +    load_packet(dev, lp->setup_frame, TD_IC | PERFECT_F | TD_SET | 
  11653.                                                  SETUP_FRAME_LEN, NULL);
  11654. +      }
  11655.        lp->tx_new = (++lp->tx_new) % lp->txRingSize;
  11656.        outl(POLL_DEMAND, DE4X5_TPD);                /* Start the TX */
  11657.        dev->tbusy = 0;                              /* Unlock the TX ring */
  11658. @@ -1848,7 +2291,6 @@
  11659.      if (suser()) {
  11660.        omr = inl(DE4X5_OMR);
  11661.        omr |= OMR_PR;
  11662. -      omr &= ~OMR_PM;
  11663.        outl(omr, DE4X5_OMR);
  11664.      } else {
  11665.        status = -EPERM;
  11666. @@ -1893,11 +2335,10 @@
  11667.      }
  11668.  
  11669.      break;
  11670. -  case DE4X5_MCA_EN:                 /* Enable multicast addressing */
  11671. +  case DE4X5_MCA_EN:                 /* Enable pass all multicast addressing */
  11672.      if (suser()) {
  11673.        omr = inl(DE4X5_OMR);
  11674.        omr |= OMR_PM;
  11675. -      omr &= ~OMR_PR;
  11676.        outl(omr, DE4X5_OMR);
  11677.      } else {
  11678.        status = -EPERM;
  11679. @@ -2049,9 +2490,9 @@
  11680.                                   DE4X5_PCI_TOTAL_SIZE :
  11681.                                           DE4X5_EISA_TOTAL_SIZE));
  11682.      if (lp) {
  11683. -      kfree_s(lp->rx_ring[0].buf, RX_BUFF_SZ * NUM_RX_DESC + LWPAD);
  11684. +      kfree_s(lp->rx_ring[0].buf, RX_BUFF_SZ * NUM_RX_DESC + ALIGN);
  11685.      }
  11686. -    kfree_s(thisDE4X5.priv, sizeof(struct de4x5_private) + LWPAD);
  11687. +    kfree_s(thisDE4X5.priv, sizeof(struct de4x5_private) + ALIGN);
  11688.      thisDE4X5.priv = NULL;
  11689.  
  11690.      unregister_netdev(&thisDE4X5);
  11691. diff -u --recursive --new-file v1.2.7/linux/drivers/net/de4x5.h linux/drivers/net/de4x5.h
  11692. --- v1.2.7/linux/drivers/net/de4x5.h    Tue Jan 31 09:39:01 1995
  11693. +++ linux/drivers/net/de4x5.h    Wed May  3 07:17:10 1995
  11694. @@ -23,8 +23,12 @@
  11695.  #define DE4X5_IMR    iobase+(0x038 << lp->bus)  /* Interrupt Mask Register */
  11696.  #define DE4X5_MFC    iobase+(0x040 << lp->bus)  /* Missed Frame Counter */
  11697.  #define DE4X5_APROM  iobase+(0x048 << lp->bus)  /* Ethernet Address PROM */
  11698. +#define DE4X5_BROM   iobase+(0x048 << lp->bus)  /* Boot ROM Register */
  11699. +#define DE4X5_SROM   iobase+(0x048 << lp->bus)  /* Serial ROM Register */
  11700.  #define DE4X5_DDR    iobase+(0x050 << lp->bus)  /* Data Diagnostic Register */
  11701.  #define DE4X5_FDR    iobase+(0x058 << lp->bus)  /* Full Duplex Register */
  11702. +#define DE4X5_GPT    iobase+(0x058 << lp->bus)  /* General Purpose Timer Reg.*/
  11703. +#define DE4X5_GEP    iobase+(0x060 << lp->bus)  /* General Purpose Register */
  11704.  #define DE4X5_SISR   iobase+(0x060 << lp->bus)  /* SIA Status Register */
  11705.  #define DE4X5_SICR   iobase+(0x068 << lp->bus)  /* SIA Connectivity Register */
  11706.  #define DE4X5_STRR   iobase+(0x070 << lp->bus)  /* SIA TX/RX Register */
  11707. @@ -54,7 +58,9 @@
  11708.  #define PCI_CFLT     iobase+0x001c   /* PCI Latency Timer Register */
  11709.  #define PCI_CBIO     iobase+0x0028   /* PCI Base I/O Register */
  11710.  #define PCI_CBMA     iobase+0x002c   /* PCI Base Memory Address Register */
  11711. -#define PCI_CFIT     iobase+0x0038   /* PCI Configuration Interrupt Register */
  11712. +#define PCI_CBER     iobase+0x0030   /* PCI Expansion ROM Base Address Reg. */
  11713. +#define PCI_CFIT     iobase+0x003c   /* PCI Configuration Interrupt Register */
  11714. +#define PCI_CFDA     iobase+0x0040   /* PCI Driver Area Register */
  11715.  
  11716.  /*
  11717.  ** EISA Configuration Register 0 bit definitions
  11718. @@ -94,6 +100,21 @@
  11719.  #define CFID_VID    0x00ff           /* Vendor ID */
  11720.  #define DC21040_DID 0x0002           /* Unique Device ID # */
  11721.  #define DC21040_VID 0x1011           /* DC21040 Manufacturer */
  11722. +#define DC21041_DID 0x0014           /* Unique Device ID # */
  11723. +#define DC21041_VID 0x1011           /* DC21041 Manufacturer */
  11724. +#define DC21140_DID 0x0009           /* Unique Device ID # */
  11725. +#define DC21140_VID 0x1011           /* DC21140 Manufacturer */
  11726. +
  11727. +/*
  11728. +** Chipset defines
  11729. +*/
  11730. +#define DC21040     DC21040_DID
  11731. +#define DC21041     DC21041_DID
  11732. +#define DC21140     DC21140_DID
  11733. +
  11734. +#define is_DC21040 ((vendor == DC21040_VID) && (device == DC21040_DID))
  11735. +#define is_DC21041 ((vendor == DC21041_VID) && (device == DC21041_DID))
  11736. +#define is_DC21140 ((vendor == DC21140_VID) && (device == DC21140_DID))
  11737.  
  11738.  /*
  11739.  ** PCI Configuration Command/Status Register (PCI_CFCS)
  11740. @@ -136,9 +157,21 @@
  11741.  #define CBIO_IOSI   0x00000001       /* I/O Space Indicator (RO, value is 1) */
  11742.  
  11743.  /*
  11744. +** PCI Configuration Expansion ROM Base Address Register (PCI_CBER)
  11745. +*/
  11746. +#define CBER_MASK   0xfffffc00       /* Expansion ROM Base Address Mask */
  11747. +#define CBER_ROME   0x00000001       /* ROM Enable */
  11748. +
  11749. +/*
  11750. +** PCI Configuration Driver Area Register (PCI_CFDA)
  11751. +*/
  11752. +#define CFDA_PSM    0x80000000       /* Power Saving Mode */
  11753. +
  11754. +/*
  11755.  ** DC21040 Bus Mode Register (DE4X5_BMR)
  11756.  */
  11757. -#define BMR_TAP    0x00060000       /* Transmit Automatic Polling */
  11758. +#define BMR_DBO    0x00100000       /* Descriptor Byte Ordering (Endian) */
  11759. +#define BMR_TAP    0x000e0000       /* Transmit Automatic Polling */
  11760.  #define BMR_DAS    0x00010000       /* Diagnostic Address Space */
  11761.  #define BMR_CAL    0x0000c000       /* Cache Alignment */
  11762.  #define BMR_PBL    0x00003f00       /* Programmable Burst Length */
  11763. @@ -151,6 +184,10 @@
  11764.  #define TAP_200US  0x00020000       /* TX automatic polling every 200us */
  11765.  #define TAP_800US  0x00040000       /* TX automatic polling every 800us */
  11766.  #define TAP_1_6MS  0x00060000       /* TX automatic polling every 1.6ms */
  11767. +#define TAP_12_8US 0x00080000       /* TX automatic polling every 12.8us */
  11768. +#define TAP_25_6US 0x000a0000       /* TX automatic polling every 25.6us */
  11769. +#define TAP_51_2US 0x000c0000       /* TX automatic polling every 51.2us */
  11770. +#define TAP_102_4US 0x000e0000      /* TX automatic polling every 102.4us */
  11771.  
  11772.  #define CAL_NOUSE  0x00000000       /* Not used */
  11773.  #define CAL_8LONG  0x00004000       /* 8-longword alignment */
  11774. @@ -165,6 +202,7 @@
  11775.  #define PBL_16     0x00001000       /* 16 longwords DMA burst length */
  11776.  #define PBL_32     0x00002000       /* 32 longwords DMA burst length */
  11777.  
  11778. +#define DSL_0      0x00000000       /*  0 longword  / descriptor */
  11779.  #define DSL_1      0x00000004       /*  1 longword  / descriptor */
  11780.  #define DSL_2      0x00000008       /*  2 longwords / descriptor */
  11781.  #define DSL_4      0x00000010       /*  4 longwords / descriptor */
  11782. @@ -195,20 +233,23 @@
  11783.  /*
  11784.  ** DC21040 Status Register (DE4X5_STS)
  11785.  */
  11786. -#define STS_EB     0x03800000       /* Error Bits */
  11787. +#define STS_BE     0x03800000       /* Bus Error Bits */
  11788.  #define STS_TS     0x00700000       /* Transmit Process State */
  11789.  #define STS_RS     0x000e0000       /* Receive Process State */
  11790.  #define STS_NIS    0x00010000       /* Normal Interrupt Summary */
  11791.  #define STS_AIS    0x00008000       /* Abnormal Interrupt Summary */
  11792. +#define STS_ER     0x00004000       /* Early Receive */
  11793.  #define STS_SE     0x00002000       /* System Error */
  11794.  #define STS_LNF    0x00001000       /* Link Fail */
  11795.  #define STS_FD     0x00000800       /* Full-Duplex Short Frame Received */
  11796. +#define STS_TM     0x00000800       /* Timer Expired (DC21041) */
  11797.  #define STS_AT     0x00000400       /* AUI/TP Pin */
  11798.  #define STS_RWT    0x00000200       /* Receive Watchdog Time-Out */
  11799.  #define STS_RPS    0x00000100       /* Receive Process Stopped */
  11800.  #define STS_RU     0x00000080       /* Receive Buffer Unavailable */
  11801.  #define STS_RI     0x00000040       /* Receive Interrupt */
  11802.  #define STS_UNF    0x00000020       /* Transmit Underflow */
  11803. +#define STS_LNP    0x00000010       /* Link Pass */
  11804.  #define STS_TJT    0x00000008       /* Transmit Jabber Time-Out */
  11805.  #define STS_TU     0x00000004       /* Transmit Buffer Unavailable */
  11806.  #define STS_TPS    0x00000002       /* Transmit Process Stopped */
  11807. @@ -243,6 +284,13 @@
  11808.  /*
  11809.  ** DC21040 Operation Mode Register (DE4X5_OMR)
  11810.  */
  11811. +#define OMR_SDP    0x02000000       /* SD Polarity - MUST BE ASSERTED */
  11812. +#define OMR_SCR    0x01000000       /* Scrambler Mode */
  11813. +#define OMR_PCS    0x00800000       /* PCS Function */
  11814. +#define OMR_TTM    0x00400000       /* Transmit Threshold Mode */
  11815. +#define OMR_SF     0x00200000       /* Store and Forward */
  11816. +#define OMR_HBD    0x00080000       /* HeartBeat Disable */
  11817. +#define OMR_PS     0x00040000       /* Port Select */
  11818.  #define OMR_CA     0x00020000       /* Capture Effect Enable */
  11819.  #define OMR_BP     0x00010000       /* Back Pressure */
  11820.  #define OMR_TR     0x0000c000       /* Threshold Control Bits */
  11821. @@ -270,15 +318,18 @@
  11822.  */
  11823.  #define IMR_NIM    0x00010000       /* Normal Interrupt Summary Mask */
  11824.  #define IMR_AIM    0x00008000       /* Abnormal Interrupt Summary Mask */
  11825. +#define IMR_ERM    0x00004000       /* Early Receive Mask */
  11826.  #define IMR_SEM    0x00002000       /* System Error Mask */
  11827.  #define IMR_LFM    0x00001000       /* Link Fail Mask */
  11828. -#define IMR_FDM    0x00000800       /* Full-Duplex Mask */
  11829. +#define IMR_FDM    0x00000800       /* Full-Duplex (Short Frame) Mask */
  11830. +#define IMR_TMM    0x00000800       /* Timer Expired Mask (DC21041) */
  11831.  #define IMR_ATM    0x00000400       /* AUI/TP Switch Mask */
  11832.  #define IMR_RWM    0x00000200       /* Receive Watchdog Time-Out Mask */
  11833.  #define IMR_RSM    0x00000100       /* Receive Stopped Mask */
  11834.  #define IMR_RUM    0x00000080       /* Receive Buffer Unavailable Mask */
  11835.  #define IMR_RIM    0x00000040       /* Receive Interrupt Mask */
  11836.  #define IMR_UNM    0x00000020       /* Underflow Interrupt Mask */
  11837. +#define IMR_LPM    0x00000010       /* Link Pass */
  11838.  #define IMR_TJM    0x00000008       /* Transmit Time-Out Jabber Mask */
  11839.  #define IMR_TUM    0x00000004       /* Transmit Buffer Unavailable Mask */
  11840.  #define IMR_TSM    0x00000002       /* Transmission Stopped Mask */
  11841. @@ -297,27 +348,89 @@
  11842.  #define APROM_DT   0x000000ff       /* Address Byte */
  11843.  
  11844.  /*
  11845. +** DC21041 Boot/Ethernet Address ROM (DE4X5_BROM)
  11846. +*/
  11847. +#define BROM_MODE 0x00008000       /* MODE_1: 0,  MODE_0: 1  (read only) */
  11848. +#define BROM_RD   0x00004000       /* Read from Boot ROM */
  11849. +#define BROM_WR   0x00002000       /* Write to Boot ROM */
  11850. +#define BROM_BR   0x00001000       /* Select Boot ROM when set */
  11851. +#define BROM_SR   0x00000800       /* Select Serial ROM when set */
  11852. +#define BROM_REG  0x00000400       /* External Register Select */
  11853. +#define BROM_DT   0x000000ff       /* Data Byte */
  11854. +
  11855. +/*
  11856. +** DC21041 Serial/Ethernet Address ROM (DE4X5_SROM)
  11857. +*/
  11858. +#define SROM_MODE 0x00008000       /* MODE_1: 0,  MODE_0: 1  (read only) */
  11859. +#define SROM_RD   0x00004000       /* Read from Boot ROM */
  11860. +#define SROM_WR   0x00002000       /* Write to Boot ROM */
  11861. +#define SROM_BR   0x00001000       /* Select Boot ROM when set */
  11862. +#define SROM_SR   0x00000800       /* Select Serial ROM when set */
  11863. +#define SROM_REG  0x00000400       /* External Register Select */
  11864. +#define SROM_DT   0x000000ff       /* Data Byte */
  11865. +
  11866. +#define DT_OUT    0x00000008       /* Serial Data Out */
  11867. +#define DT_IN     0x00000004       /* Serial Data In */
  11868. +#define DT_CLK    0x00000002       /* Serial ROM Clock */
  11869. +#define DT_CS     0x00000001       /* Serial ROM Chip Select */
  11870. +
  11871. +/*
  11872.  ** DC21040 Full Duplex Register (DE4X5_FDR)
  11873.  */
  11874. -#define FDR_FDACV  0x0000ffff       /* Full Duplex Auto Configuration Value */
  11875. +#define FDR_FDACV  0x0000ffff      /* Full Duplex Auto Configuration Value */
  11876.  
  11877.  /*
  11878. -** DC21040 SIA Status Register (DE4X5_SISR)
  11879. +** DC21041 General Purpose Timer Register (DE4X5_GPT)
  11880.  */
  11881. -#define SISR_DAO   0x00000080       /* PLL All One */
  11882. -#define SISR_DAZ   0x00000040       /* PLL All Zero */
  11883. -#define SISR_DSP   0x00000020       /* PLL Self-Test Pass */
  11884. -#define SISR_DSD   0x00000010       /* PLL Self-Test Done */
  11885. -#define SISR_APS   0x00000008       /* Auto Polarity State */
  11886. -#define SISR_LKF   0x00000004       /* Link Fail Status */
  11887. -#define SISR_NCR   0x00000002       /* Network Connection Error */
  11888. -#define SISR_PAUI  0x00000001       /* AUI_TP Indication */
  11889. +#define GPT_CON  0x00010000        /* One shot: 0,  Continuous: 1 */
  11890. +#define GPT_VAL  0x0000ffff        /* Timer Value */
  11891. +
  11892. +/*
  11893. +** DC21140 General Purpose Register (DE4X5_GEP) (hardware dependent bits)
  11894. +*/
  11895. +/* Valid ONLY for DE500 hardware */
  11896. +#define GEP_LNP  0x00000080        /* Link Pass               (input) */
  11897. +#define GEP_SLNK 0x00000040        /* SYM LINK                (input) */
  11898. +#define GEP_SDET 0x00000020        /* Signal Detect           (input) */
  11899. +#define GEP_FDXD 0x00000008        /* Full Duplex Disable     (output) */
  11900. +#define GEP_PHYL 0x00000004        /* PHY Loopback            (output) */
  11901. +#define GEP_FLED 0x00000002        /* Force Activity LED on   (output) */
  11902. +#define GEP_MODE 0x00000001        /* 0: 10Mb/s,  1: 100Mb/s           */
  11903. +#define GEP_INIT 0x0000010f        /* Setup inputs (0) and outputs (1) */
  11904.  
  11905. -#define SIA_RESET  0x00000000       /* SIA Reset */
  11906. +
  11907. +/*
  11908. +** DC21040 SIA Status Register (DE4X5_SISR)
  11909. +*/
  11910. +#define SISR_LPC   0xffff0000      /* Link Partner's Code Word */
  11911. +#define SISR_LPN   0x00008000      /* Link Partner Negotiable */
  11912. +#define SISR_ANS   0x00007000      /* Auto Negotiation Arbitration State */
  11913. +#define SISR_NSN   0x00000800      /* Non Stable NLPs Detected */
  11914. +#define SISR_ANR_FDS 0x00000400    /* Auto Negotiate Restart/Full Duplex Sel.*/
  11915. +#define SISR_NRA   0x00000200      /* Non Selected Port Receive Activity */
  11916. +#define SISR_SRA   0x00000100      /* Selected Port Receive Activity */
  11917. +#define SISR_DAO   0x00000080      /* PLL All One */
  11918. +#define SISR_DAZ   0x00000040      /* PLL All Zero */
  11919. +#define SISR_DSP   0x00000020      /* PLL Self-Test Pass */
  11920. +#define SISR_DSD   0x00000010      /* PLL Self-Test Done */
  11921. +#define SISR_APS   0x00000008      /* Auto Polarity State */
  11922. +#define SISR_LKF   0x00000004      /* Link Fail Status */
  11923. +#define SISR_NCR   0x00000002      /* Network Connection Error */
  11924. +#define SISR_PAUI  0x00000001      /* AUI_TP Indication */
  11925. +#define SIA_RESET  0x00000000      /* SIA Reset */
  11926. +
  11927. +#define ANS_NDIS   0x00000000      /* Nway disable */
  11928. +#define ANS_TDIS   0x00001000      /* Transmit Disable */
  11929. +#define ANS_ADET   0x00002000      /* Ability Detect */
  11930. +#define ANS_ACK    0x00003000      /* Acknowledge */
  11931. +#define ANS_CACK   0x00004000      /* Complete Acknowledge */
  11932. +#define ANS_NWOK   0x00005000      /* Nway OK - FLP Link Good */
  11933. +#define ANS_LCHK   0x00006000      /* Link Check */
  11934.  
  11935.  /*
  11936.  ** DC21040 SIA Connectivity Register (DE4X5_SICR)
  11937.  */
  11938. +#define SICR_SDM   0xffff0000       /* SIA Diagnostics Mode */
  11939.  #define SICR_OE57  0x00008000       /* Output Enable 5 6 7 */
  11940.  #define SICR_OE24  0x00004000       /* Output Enable 2 4 */
  11941.  #define SICR_OE13  0x00002000       /* Output Enable 1 3 */
  11942. @@ -343,6 +456,7 @@
  11943.  /*
  11944.  ** DC21040 SIA Transmit and Receive Register (DE4X5_STRR)
  11945.  */
  11946. +#define STRR_TAS   0x00008000       /* 10Base-T/AUI Autosensing Enable */
  11947.  #define STRR_SPP   0x00004000       /* Set Polarity Plus */
  11948.  #define STRR_APE   0x00002000       /* Auto Polarity Enable */
  11949.  #define STRR_LTE   0x00001000       /* Link Test Enable */
  11950. @@ -350,6 +464,8 @@
  11951.  #define STRR_CLD   0x00000400       /* Collision Detect Enable */
  11952.  #define STRR_CSQ   0x00000200       /* Collision Squelch Enable */
  11953.  #define STRR_RSQ   0x00000100       /* Receive Squelch Enable */
  11954. +#define STRR_ANE   0x00000080       /* Auto Negotiate Enable */
  11955. +#define STRR_HDE   0x00000040       /* Half Duplex Enable */
  11956.  #define STRR_CPEN  0x00000030       /* Compensation Enable */
  11957.  #define STRR_LSE   0x00000008       /* Link Pulse Send Enable */
  11958.  #define STRR_DREN  0x00000004       /* Driver Enable */
  11959. @@ -360,13 +476,19 @@
  11960.  /*
  11961.  ** DC21040 SIA General Register (DE4X5_SIGR)
  11962.  */
  11963. +#define SIGR_LV2   0x00008000       /* General Purpose LED2 value */
  11964. +#define SIGR_LE2   0x00004000       /* General Purpose LED2 enable */
  11965.  #define SIGR_FRL   0x00002000       /* Force Receiver Low */
  11966.  #define SIGR_DPST  0x00001000       /* PLL Self Test Start */
  11967. +#define SIGR_LSD   0x00000800       /* LED Stretch Disable */
  11968.  #define SIGR_FLF   0x00000400       /* Force Link Fail */
  11969.  #define SIGR_FUSQ  0x00000200       /* Force Unsquelch */
  11970.  #define SIGR_TSCK  0x00000100       /* Test Clock */
  11971. +#define SIGR_LV1   0x00000080       /* General Purpose LED1 value */
  11972. +#define SIGR_LE1   0x00000040       /* General Purpose LED1 enable */
  11973.  #define SIGR_RWR   0x00000020       /* Receive Watchdog Release */
  11974.  #define SIGR_RWD   0x00000010       /* Receive Watchdog Disable */
  11975. +#define SIGR_ABM   0x00000008       /* BNC: 0,  AUI:1 */
  11976.  #define SIGR_JCK   0x00000004       /* Jabber Clock */
  11977.  #define SIGR_HUJ   0x00000002       /* Host Unjab */
  11978.  #define SIGR_JBD   0x00000001       /* Jabber Disable */
  11979. @@ -432,26 +554,63 @@
  11980.  #define HASH_O_F   TD_FT1| TD_F0
  11981.  
  11982.  /*
  11983. +** Media / mode state machine definitions
  11984. +*/
  11985. +#define NC         0x0000          /* No Connection */
  11986. +#define TP         0x0001          /* 10Base-T */
  11987. +#define TP_NW      0x0002          /* 10Base-T with Nway */
  11988. +#define BNC        0x0004          /* Thinwire */
  11989. +#define AUI        0x0008          /* Thickwire */
  11990. +#define BNC_AUI    0x0010          /* BNC/AUI on DC21040 indistinguishable */
  11991. +#define ANS        0x0020          /* Intermediate AutoNegotiation State */
  11992. +
  11993. +#define _10Mb      0x0040          /* 10Mb/s Ethernet */
  11994. +#define _100Mb     0x0080          /* 100Mb/s Ethernet */
  11995. +#define SYM_WAIT   0x0100          /* Wait for SYM_LINK */
  11996. +#define INIT       0x0200          /* Initial state */
  11997. +
  11998. +#define AUTO       0x4000          /* Auto sense the media or speed */
  11999. +
  12000. +/*
  12001.  ** Miscellaneous
  12002.  */
  12003.  #define PCI  0
  12004.  #define EISA 1
  12005.  
  12006. -#define NC         0               /* No Connection */
  12007. -#define TP         1               /* 10Base-T */
  12008. -#define BNC        2               /* Thinwire */
  12009. -#define AUI        3               /* Thickwire */
  12010. -  
  12011.  #define HASH_TABLE_LEN   512       /* Bits */
  12012. +#define HASH_BITS        0x01ff    /* 9 LS bits */
  12013.  
  12014.  #define SETUP_FRAME_LEN  192       /* Bytes */
  12015. -#define PERF_PA_OFFSET   180       /* Bytes */
  12016.  #define IMPERF_PA_OFFSET 156       /* Bytes */
  12017.  
  12018. -#define POLL_DEMAND       1
  12019. +#define POLL_DEMAND          1
  12020. +
  12021. +#define LOST_MEDIA_THRESHOLD 3
  12022. +
  12023. +#define MASK_INTERRUPTS      1
  12024. +#define UNMASK_INTERRUPTS    0
  12025. +
  12026. +#define DE4X5_STRLEN         8
  12027. +
  12028. +/*
  12029. +** Address Filtering Modes
  12030. +*/
  12031. +#define PERFECT              0     /* 16 perfect physical addresses */
  12032. +#define HASH_PERF            1     /* 1 perfect, 512 multicast addresses */
  12033. +#define PERFECT_REJ          2     /* Reject 16 perfect physical addresses */
  12034. +#define ALL_HASH             3     /* Hashes all physical & multicast addrs */
  12035. +
  12036. +#define ALL                  0     /* Clear out all the setup frame */
  12037. +#define PHYS_ADDR_ONLY       1     /* Update the physical address only */
  12038. +
  12039. +/*
  12040. +** Booleans
  12041. +*/
  12042. +#define NO                   0
  12043. +#define FALSE                0
  12044.  
  12045. -#define MASK_INTERRUPTS   1
  12046. -#define UNMASK_INTERRUPTS 0
  12047. +#define YES                  !0
  12048. +#define TRUE                 !0
  12049.  
  12050.  /*
  12051.  ** Include the IOCTL stuff
  12052. diff -u --recursive --new-file v1.2.7/linux/drivers/net/lance.c linux/drivers/net/lance.c
  12053. --- v1.2.7/linux/drivers/net/lance.c    Fri Apr 28 11:10:53 1995
  12054. +++ linux/drivers/net/lance.c    Tue May  2 08:06:18 1995
  12055. @@ -608,7 +608,7 @@
  12056.      outw(((int)&lp->init_block) >> 16, ioaddr+LANCE_DATA);
  12057.  
  12058.      outw(0x0004, ioaddr+LANCE_ADDR);
  12059. -    outw(0x0d15, ioaddr+LANCE_DATA);
  12060. +    outw(0x0915, ioaddr+LANCE_DATA);
  12061.  
  12062.      outw(0x0000, ioaddr+LANCE_ADDR);
  12063.      outw(0x0001, ioaddr+LANCE_DATA);
  12064. diff -u --recursive --new-file v1.2.7/linux/drivers/net/ne.c linux/drivers/net/ne.c
  12065. --- v1.2.7/linux/drivers/net/ne.c    Sat Apr 29 12:42:21 1995
  12066. +++ linux/drivers/net/ne.c    Tue May  2 08:02:12 1995
  12067. @@ -50,7 +50,7 @@
  12068.  /* Do we implement the read before write bugfix ? */
  12069.  /* #define CONFIG_NE_RW_BUGFIX */
  12070.  
  12071. -/* ---- No user-servicable parts below ---- */
  12072. +/* ---- No user-serviceable parts below ---- */
  12073.  
  12074.  extern struct device *init_etherdev(struct device *dev, int sizeof_private,
  12075.                      unsigned long *mem_startp);
  12076. @@ -86,7 +86,7 @@
  12077.  #define NESM_START_PG    0x40    /* First page of TX buffer */
  12078.  #define NESM_STOP_PG    0x80    /* Last page +1 of RX ring */
  12079.  
  12080. -#define NE_RDC_TIMEOUT    0x03    /* Max wait in jiffies for Tx RDC */
  12081. +#define NE_RDC_TIMEOUT    0x02    /* Max wait in jiffies for Tx RDC */
  12082.  
  12083.  int ne_probe(struct device *dev);
  12084.  static int ne_probe1(struct device *dev, int ioaddr);
  12085. @@ -462,7 +462,6 @@
  12086.      SLOW_DOWN_IO;
  12087.  #endif  /* rw_bugfix */
  12088.  
  12089. -    dma_start = jiffies;
  12090.      outb_p(ENISR_RDC, nic_base + EN0_ISR);
  12091.  
  12092.     /* Now the normal output. */
  12093. @@ -477,6 +476,8 @@
  12094.      } else {
  12095.      outsb(NE_BASE + NE_DATAPORT, buf, count);
  12096.      }
  12097. +
  12098. +    dma_start = jiffies;
  12099.  
  12100.  #ifdef CONFIG_NE_SANITY
  12101.      /* This was for the ALPHA version only, but enough people have
  12102. diff -u --recursive --new-file v1.2.7/linux/drivers/net/ppp.c linux/drivers/net/ppp.c
  12103. --- v1.2.7/linux/drivers/net/ppp.c    Thu Feb 23 13:19:17 1995
  12104. +++ linux/drivers/net/ppp.c    Tue May  2 08:02:13 1995
  12105. @@ -31,6 +31,7 @@
  12106.  /* #define NET02D                -* */
  12107.  #define NEW_TTY_DRIVERS                /* */
  12108.  #define OPTIMIZE_FLAG_TIME  ((HZ * 3)/2)    /* */
  12109. +#define CHECK_CHARACTERS
  12110.  
  12111.  #ifdef MODULE
  12112.  #include <linux/module.h>
  12113. @@ -469,8 +470,8 @@
  12114.  #endif
  12115.  
  12116.    if (ppp->dev) {
  12117. -    ppp->dev->flags &= ~IFF_UP; /* down the device */
  12118. -    ppp->dev->flags |= IFF_POINTOPOINT;
  12119. +    dev_close (ppp->dev);
  12120. +    ppp->dev->flags = 0;
  12121.    }
  12122.  
  12123.    kfree (ppp->xbuff);
  12124. @@ -953,14 +954,14 @@
  12125.  
  12126.  #ifdef CHECK_CHARACTERS
  12127.      if (c & 0x80)
  12128. -    sc->sc_flags |= SC_RCV_B7_1;
  12129. +    ppp->flags |= SC_RCV_B7_1;
  12130.      else
  12131. -    sc->sc_flags |= SC_RCV_B7_0;
  12132. +    ppp->flags |= SC_RCV_B7_0;
  12133.  
  12134.      if (paritytab[c >> 5] & (1 << (c & 0x1F)))
  12135. -    sc->sc_flags |= SC_RCV_ODDP;
  12136. +    ppp->flags |= SC_RCV_ODDP;
  12137.      else
  12138. -    sc->sc_flags |= SC_RCV_EVNP;
  12139. +    ppp->flags |= SC_RCV_EVNP;
  12140.  #endif
  12141.  
  12142.      switch (c) {
  12143. @@ -1005,6 +1006,7 @@
  12144.    if (ppp->toss) {
  12145.      PRINTKN (1, (KERN_WARNING "ppp_toss: tossing frame, reason = %d\n",
  12146.           ppp->toss));
  12147. +    slhc_toss (ppp->slcomp);
  12148.      ppp->stats.rerrors++;
  12149.      return;
  12150.    }
  12151. @@ -1018,6 +1020,7 @@
  12152.  
  12153.    if (count < 4) {
  12154.      PRINTKN (1,(KERN_WARNING "ppp: got runt ppp frame, %d chars\n", count));
  12155. +    slhc_toss (ppp->slcomp);
  12156.      ppp->stats.runts++;
  12157.      return;
  12158.    }
  12159. @@ -1025,6 +1028,7 @@
  12160.    /* check PPP error detection field */
  12161.    if (!ppp_check_fcs(ppp)) {
  12162.      PRINTKN (1,(KERN_WARNING "ppp: frame with bad fcs\n"));
  12163. +    slhc_toss (ppp->slcomp);
  12164.      ppp->stats.rerrors++;
  12165.      return;
  12166.    }
  12167. @@ -1067,6 +1071,7 @@
  12168.    /* couldn't cope. */
  12169.    PRINTKN (1,(KERN_WARNING
  12170.            "ppp: dropping packet on the floor: nobody could take it.\n"));
  12171. +  slhc_toss (ppp->slcomp);
  12172.    ppp->stats.tossed++;
  12173.  }
  12174.  
  12175. @@ -1109,6 +1114,7 @@
  12176.        PRINTKN (1,(KERN_NOTICE
  12177.            "ppp: no space to decompress VJ compressed TCP header.\n"));
  12178.        ppp->stats.roverrun++;
  12179. +      slhc_toss (ppp->slcomp);
  12180.        return 1;
  12181.      }
  12182.  
  12183. @@ -1116,6 +1122,7 @@
  12184.      if (count <= 0) {
  12185.        ppp->stats.rerrors++;
  12186.        PRINTKN (1,(KERN_NOTICE "ppp: error in VJ decompression\n"));
  12187. +      slhc_toss (ppp->slcomp);
  12188.        return 1;
  12189.      }
  12190.      ppp->stats.rcomp++;
  12191. @@ -1126,6 +1133,7 @@
  12192.      if (slhc_remember(ppp->slcomp, c, count) <= 0) {
  12193.        ppp->stats.rerrors++;
  12194.        PRINTKN (1,(KERN_NOTICE "ppp: error in VJ memorizing\n"));
  12195. +      slhc_toss (ppp->slcomp);
  12196.        return 1;
  12197.      }
  12198.      ppp->stats.runcomp++;
  12199. @@ -1709,7 +1717,12 @@
  12200.    PRINTKN(4,(KERN_DEBUG "ppp_xmit [%s]: skb %lX busy %d\n", dev->name, 
  12201.           (unsigned long int) skb, ppp->sending));
  12202.  
  12203. -  CHECK_PPP(0);
  12204. +  /* avoid race conditions when the link fails */
  12205. +  if (!ppp->inuse) {
  12206. +    dev_kfree_skb(skb, FREE_WRITE);
  12207. +    dev_close (dev);
  12208. +    return 0;
  12209. +  }
  12210.  
  12211.    if (tty == NULL) {
  12212.      PRINTKN(1,(KERN_ERR "ppp_xmit: %s not connected to a TTY!\n", dev->name));
  12213. @@ -1726,7 +1739,7 @@
  12214.    /* get length from IP header as per Alan Cox bugfix for slip.c */
  12215.    if (len < sizeof(struct iphdr)) {
  12216.      PRINTKN(0,(KERN_ERR "ppp_xmit: given runt packet, ignoring\n"));
  12217. -    return 1;
  12218. +    goto done;
  12219.    }
  12220.    len = ntohs( ((struct iphdr *)(skb->data)) -> tot_len );
  12221.  
  12222. @@ -1750,8 +1763,8 @@
  12223.  
  12224.    /* try to compress, if VJ compression mode is on */
  12225.    if (ppp->flags & SC_COMP_TCP) {
  12226. -    /* NOTE: last 0 argument says never to compress connection ID */
  12227. -    len = slhc_compress(ppp->slcomp, p, len, ppp->cbuff, &p, 0);
  12228. +    len = slhc_compress(ppp->slcomp, p, len, ppp->cbuff, &p, 
  12229. +            !(ppp->flags & SC_NO_TCP_CCID));
  12230.      if (p[0] & SL_TYPE_COMPRESSED_TCP)
  12231.        proto = PROTO_VJCOMP;
  12232.      else {
  12233. @@ -2055,10 +2068,25 @@
  12234.          0, 0, 0, 0,    /* memory */
  12235.          0, 0,        /* base, irq */
  12236.          0, 0, 0, NULL, ppp_init,
  12237. -    },
  12238. -    { "ppp1" , 0, 0, 0, 0,  1, 0, 0, 0, 0, NULL, ppp_init },
  12239. -    { "ppp2" , 0, 0, 0, 0,  2, 0, 0, 0, 0, NULL, ppp_init },
  12240. -    { "ppp3" , 0, 0, 0, 0,  3, 0, 0, 0, 0, NULL, ppp_init },
  12241. +    }
  12242. +    , { "ppp1" , 0, 0, 0, 0,  1, 0, 0, 0, 0, NULL, ppp_init }
  12243. +    , { "ppp2" , 0, 0, 0, 0,  2, 0, 0, 0, 0, NULL, ppp_init }
  12244. +    , { "ppp3" , 0, 0, 0, 0,  3, 0, 0, 0, 0, NULL, ppp_init }
  12245. +
  12246. +#ifdef PPP_PPP_LOTS
  12247. +    , { "ppp4" , 0, 0, 0, 0,  4, 0, 0, 0, 0, NULL, ppp_init }
  12248. +    , { "ppp5" , 0, 0, 0, 0,  5, 0, 0, 0, 0, NULL, ppp_init }
  12249. +    , { "ppp6" , 0, 0, 0, 0,  6, 0, 0, 0, 0, NULL, ppp_init }
  12250. +    , { "ppp7" , 0, 0, 0, 0,  7, 0, 0, 0, 0, NULL, ppp_init }
  12251. +    , { "ppp8" , 0, 0, 0, 0,  8, 0, 0, 0, 0, NULL, ppp_init }
  12252. +    , { "ppp9" , 0, 0, 0, 0,  9, 0, 0, 0, 0, NULL, ppp_init }
  12253. +    , { "ppp10" , 0, 0, 0, 0, 10, 0, 0, 0, 0, NULL, ppp_init }
  12254. +    , { "ppp11" , 0, 0, 0, 0, 11, 0, 0, 0, 0, NULL, ppp_init }
  12255. +    , { "ppp12" , 0, 0, 0, 0, 12, 0, 0, 0, 0, NULL, ppp_init }
  12256. +    , { "ppp13" , 0, 0, 0, 0, 13, 0, 0, 0, 0, NULL, ppp_init }
  12257. +    , { "ppp14" , 0, 0, 0, 0, 14, 0, 0, 0, 0, NULL, ppp_init }
  12258. +    , { "ppp15" , 0, 0, 0, 0, 15, 0, 0, 0, 0, NULL, ppp_init }
  12259. +#endif
  12260.  };
  12261.  
  12262.  int
  12263. diff -u --recursive --new-file v1.2.7/linux/drivers/net/slip.c linux/drivers/net/slip.c
  12264. --- v1.2.7/linux/drivers/net/slip.c    Thu Feb 23 13:27:11 1995
  12265. +++ linux/drivers/net/slip.c    Sat Apr 29 12:41:33 1995
  12266. @@ -1046,6 +1046,13 @@
  12267.      }
  12268.  }
  12269.  
  12270. +static int sl_open_dev(struct device *dev)
  12271. +{
  12272. +    struct slip *sl = &sl_ctrl[dev->base_addr];
  12273. +    if(sl->tty==NULL)
  12274. +        return -ENODEV;
  12275. +    return 0;
  12276. +}
  12277.  
  12278.  /* Initialize the SLIP driver.  Called by DDI. */
  12279.  int
  12280. @@ -1103,7 +1110,7 @@
  12281.      /* Finish setting up the DEVICE info. */
  12282.      dev->mtu        = SL_MTU;
  12283.      dev->hard_start_xmit    = sl_xmit;
  12284. -    dev->open        = sl_open;
  12285. +    dev->open        = sl_open_dev;
  12286.      dev->stop        = sl_close;
  12287.      dev->hard_header    = sl_header;
  12288.      dev->type_trans            = sl_type_trans;
  12289. diff -u --recursive --new-file v1.2.7/linux/drivers/scsi/53c7,8xx.c linux/drivers/scsi/53c7,8xx.c
  12290. --- v1.2.7/linux/drivers/scsi/53c7,8xx.c    Sat Apr 29 12:42:22 1995
  12291. +++ linux/drivers/scsi/53c7,8xx.c    Tue May  2 07:28:31 1995
  12292. @@ -1242,7 +1242,8 @@
  12293.      sti();
  12294.  
  12295.      timeout = jiffies + 50;    /* arbitrary */
  12296. -    while ((hostdata->test_completed == -1) && jiffies < timeout);
  12297. +    while ((hostdata->test_completed == -1) && jiffies < timeout)
  12298. +        barrier();
  12299.  
  12300.      failed = 1;
  12301.      if (hostdata->test_completed == -1)
  12302. @@ -1330,7 +1331,8 @@
  12303.          sti();
  12304.  
  12305.          timeout = jiffies + 500;    /* arbitrary */
  12306. -        while ((hostdata->test_completed == -1) && jiffies < timeout);
  12307. +        while ((hostdata->test_completed == -1) && jiffies < timeout)
  12308. +            barrier();
  12309.          NCR53c7x0_write32 (DSA_REG, 0);
  12310.  
  12311.          if (hostdata->test_completed == 2) {
  12312. diff -u --recursive --new-file v1.2.7/linux/drivers/scsi/NCR5380.c linux/drivers/scsi/NCR5380.c
  12313. --- v1.2.7/linux/drivers/scsi/NCR5380.c    Wed Mar 29 06:52:58 1995
  12314. +++ linux/drivers/scsi/NCR5380.c    Tue May  2 07:30:44 1995
  12315. @@ -636,7 +636,8 @@
  12316.      NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_DATA | 
  12317.      ICR_ASSERT_SEL);
  12318.  
  12319. -    while (probe_irq == IRQ_NONE && jiffies < timeout);
  12320. +    while (probe_irq == IRQ_NONE && jiffies < timeout)
  12321. +        barrier();
  12322.  
  12323.      NCR5380_write(SELECT_ENABLE_REG, 0);
  12324.      NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
  12325. @@ -2147,8 +2148,8 @@
  12326.               */
  12327.              NCR5380_write(TARGET_COMMAND_REG, 0);
  12328.              
  12329. -            while ((NCR5380_read(STATUS_REG) & SR_BSY) && 
  12330. -            !hostdata->connected);
  12331. +            while ((NCR5380_read(STATUS_REG) & SR_BSY) && !hostdata->connected)
  12332. +            barrier();
  12333.              return;
  12334.          case MESSAGE_REJECT:
  12335.              /* Accept message by clearing ACK */
  12336. @@ -2187,8 +2188,8 @@
  12337.              /* Enable reselect interrupts */
  12338.              NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
  12339.              /* Wait for bus free to avoid nasty timeouts */
  12340. -            while ((NCR5380_read(STATUS_REG) & SR_BSY) && 
  12341. -            !hostdata->connected);
  12342. +            while ((NCR5380_read(STATUS_REG) & SR_BSY) && !hostdata->connected)
  12343. +                barrier();
  12344.              return;
  12345.          /* 
  12346.           * The SCSI data pointer is *IMPLICITLY* saved on a disconnect
  12347. diff -u --recursive --new-file v1.2.7/linux/drivers/scsi/aha152x.c linux/drivers/scsi/aha152x.c
  12348. --- v1.2.7/linux/drivers/scsi/aha152x.c    Tue Apr  4 09:05:34 1995
  12349. +++ linux/drivers/scsi/aha152x.c    Tue May  2 07:31:26 1995
  12350. @@ -968,7 +968,7 @@
  12351.    
  12352.          /* sleep until the abortion is complete */
  12353.          while(!abortion_complete)
  12354. -      ;
  12355. +      barrier();
  12356.          aborting=0;
  12357.          return abort_result;
  12358.        }
  12359. diff -u --recursive --new-file v1.2.7/linux/drivers/scsi/aha1542.c linux/drivers/scsi/aha1542.c
  12360. --- v1.2.7/linux/drivers/scsi/aha1542.c    Mon Jan 23 10:38:29 1995
  12361. +++ linux/drivers/scsi/aha1542.c    Tue May  2 07:33:59 1995
  12362. @@ -681,7 +681,8 @@
  12363.      aha1542_queuecommand(SCpnt, internal_done);
  12364.  
  12365.      SCpnt->SCp.Status = 0;
  12366. -    while (!SCpnt->SCp.Status);
  12367. +    while (!SCpnt->SCp.Status)
  12368. +        barrier();
  12369.      return SCpnt->result;
  12370.  }
  12371.  
  12372. diff -u --recursive --new-file v1.2.7/linux/drivers/scsi/buslogic.c linux/drivers/scsi/buslogic.c
  12373. --- v1.2.7/linux/drivers/scsi/buslogic.c    Fri Apr 28 11:10:55 1995
  12374. +++ linux/drivers/scsi/buslogic.c    Tue May  2 07:47:13 1995
  12375. @@ -788,7 +788,7 @@
  12376.  
  12377.      scpnt->SCp.Status = 0;
  12378.      while (!scpnt->SCp.Status)
  12379. -    continue;
  12380. +    barrier();
  12381.      return scpnt->result;
  12382.  }
  12383.  #endif
  12384. diff -u --recursive --new-file v1.2.7/linux/drivers/scsi/in2000.c linux/drivers/scsi/in2000.c
  12385. --- v1.2.7/linux/drivers/scsi/in2000.c    Thu Mar  9 20:37:34 1995
  12386. +++ linux/drivers/scsi/in2000.c    Tue May  2 07:34:38 1995
  12387. @@ -462,7 +462,8 @@
  12388.      if ( in2000_SCptr )
  12389.      {
  12390.      printk("in2000_queue_command waiting for free command block!\n");
  12391. -    while ( in2000_SCptr );
  12392. +    while ( in2000_SCptr )
  12393. +        barrier();
  12394.      }
  12395.      for ( timeout = jiffies + 5; timeout > jiffies; )
  12396.      {
  12397. diff -u --recursive --new-file v1.2.7/linux/drivers/scsi/qlogic.c linux/drivers/scsi/qlogic.c
  12398. --- v1.2.7/linux/drivers/scsi/qlogic.c    Thu Mar  9 20:37:35 1995
  12399. +++ linux/drivers/scsi/qlogic.c    Tue May  2 08:01:57 1995
  12400. @@ -18,7 +18,7 @@
  12401.     Reference Qlogic FAS408 Technical Manual, 53408-510-00A, May 10, 1994
  12402.     (you can reference it, but it is incomplete and inaccurate in places)
  12403.  
  12404. -   Version 0.41
  12405. +   Version 0.43 4/6/95 - kernel 1.2.0+, pcmcia 2.5.4+
  12406.  
  12407.     Functions as standalone, loadable, and PCMCIA driver, the latter from
  12408.     Dave Hind's PCMCIA package.
  12409. @@ -29,6 +29,11 @@
  12410.  /*----------------------------------------------------------------*/
  12411.  /* Configuration */
  12412.  
  12413. +/* Set the following to 2 to use normal interrupt (active high/totempole-
  12414. +   tristate), otherwise use 0 (REQUIRED FOR PCMCIA) for active low, open
  12415. +   drain */
  12416. +#define QL_INT_ACTIVE_HIGH 2
  12417. +
  12418.  /* Set the following to 1 to enable the use of interrupts.  Note that 0 tends
  12419.     to be more stable, but slower (or ties up the system more) */
  12420.  #define QL_USE_IRQ 1
  12421. @@ -100,6 +105,8 @@
  12422.  
  12423.  /*----------------------------------------------------------------*/
  12424.  #ifdef PCMCIA
  12425. +#undef QL_INT_ACTIVE_HIGH
  12426. +#define QL_INT_ACTIVE_HIGH 0
  12427.  #define MODULE
  12428.  #endif 
  12429.  
  12430. @@ -143,7 +150,7 @@
  12431.  /*----------------------------------------------------------------*/
  12432.  /* The qlogic card uses two register maps - These macros select which one */
  12433.  #define REG0 ( outb( inb( qbase + 0xd ) & 0x7f , qbase + 0xd ), outb( 4 , qbase + 0xd ))
  12434. -#define REG1 ( outb( inb( qbase + 0xd ) | 0x80 , qbase + 0xd ), outb( 0xb6 , qbase + 0xd ))
  12435. +#define REG1 ( outb( inb( qbase + 0xd ) | 0x80 , qbase + 0xd ), outb( 0xb4 | QL_INT_ACTIVE_HIGH , qbase + 0xd ))
  12436.  
  12437.  /* following is watchdog timeout in microseconds */
  12438.  #define WATCHDOG 5000000
  12439. @@ -262,8 +269,10 @@
  12440.  static int    ql_wai(void)
  12441.  {
  12442.  int    i,k;
  12443. +    k = 0;
  12444.      i = jiffies + WATCHDOG;
  12445. -    while ( i > jiffies && !qabort && !((k = inb(qbase + 4)) & 0xe0));
  12446. +    while ( i > jiffies && !qabort && !((k = inb(qbase + 4)) & 0xe0))
  12447. +        barrier();
  12448.      if (i <= jiffies)
  12449.          return (DID_TIME_OUT);
  12450.      if (qabort)
  12451. @@ -420,8 +429,10 @@
  12452.          return (k << 16);
  12453.  /* should get bus service interrupt and disconnect interrupt */
  12454.      i = inb(qbase + 5);    /* should be bus service */
  12455. -    while (!qabort && ((i & 0x20) != 0x20))
  12456. +    while (!qabort && ((i & 0x20) != 0x20)) {
  12457. +        barrier();
  12458.          i |= inb(qbase + 5);
  12459. +    }
  12460.  rtrc(0)
  12461.      if (qabort)
  12462.          return ((qabort == 1 ? DID_ABORT : DID_RESET) << 16);
  12463. @@ -493,7 +504,8 @@
  12464.  
  12465.      cmd->scsi_done = done;
  12466.  /* wait for the last command's interrupt to finish */
  12467. -    while (qlcmd != NULL);
  12468. +    while (qlcmd != NULL)
  12469. +        barrier();
  12470.      ql_icmd(cmd);
  12471.      return 0;
  12472.  }
  12473. @@ -556,7 +568,6 @@
  12474.      outb(0x40 | qlcfg8 | qinitid, qbase + 8);    /* (ini) bus id, disable scsi rst */
  12475.      outb(qlcfg5, qbase + 5);        /* select timer */
  12476.      outb(qlcfg9, qbase + 9);            /* prescaler */
  12477. -    qlirq = -1;
  12478.  #if QL_RESET_AT_START
  12479.      outb( 3 , qbase + 3 );
  12480.      REG1;
  12481. @@ -565,6 +576,7 @@
  12482.  #endif
  12483.  #if QL_USE_IRQ
  12484.  /* IRQ probe - toggle pin and check request pending */
  12485. +
  12486.      if( qlirq == -1 ) {
  12487.          save_flags( flags );
  12488.          cli();
  12489. @@ -575,21 +587,24 @@
  12490.          outb(10, 0x20); /* access pending interrupt map */
  12491.          outb(10, 0xa0);
  12492.          while (j--) {
  12493. -            outb(0xb2 , qbase + 0xd);        /* int pin off */
  12494. +            outb(0xb0 | QL_INT_ACTIVE_HIGH , qbase + 0xd);    /* int pin off */
  12495.              i &= ~(inb(0x20) | (inb(0xa0) << 8));    /* find IRQ off */
  12496. -            outb(0xb6 , qbase + 0xd);        /* int pin on */
  12497. +            outb(0xb4 | QL_INT_ACTIVE_HIGH , qbase + 0xd);    /* int pin on */
  12498.              i &= inb(0x20) | (inb(0xa0) << 8);    /* find IRQ on */
  12499.          }
  12500.          REG0;
  12501.          while (inb(qbase + 5));             /* purge int */
  12502. +        j = -1;
  12503.          while (i)                    /* find on bit */
  12504. -            i >>= 1, qlirq++;    /* should check for exactly 1 on */
  12505. -        if (qlirq >= 0 && !request_irq(qlirq, ql_ihandl, 0, "qlogic"))
  12506. -            host->can_queue = 1;
  12507. +            i >>= 1, j++;    /* should check for exactly 1 on */
  12508. +        qlirq = j;
  12509.          restore_flags( flags );
  12510.      }
  12511.      else
  12512. -        printk( "Ql: Using preset IRQ of %d\n", qlirq );
  12513. +        printk( "Ql: Using preset IRQ %d\n", qlirq );
  12514. +
  12515. +    if (qlirq >= 0 && !request_irq(qlirq, ql_ihandl, 0, "qlogic"))
  12516. +        host->can_queue = 1;
  12517.  #endif
  12518.      request_region( qbase , 0x10 ,"qlogic");
  12519.      hreg = scsi_register( host , 0 );    /* no host data */
  12520. @@ -599,7 +614,7 @@
  12521.      if( qlirq != -1 )
  12522.          hreg->irq = qlirq;
  12523.  
  12524. -    sprintf(qinfo, "Qlogic Driver version 0.41, chip %02X at %03X, IRQ %d, TPdma:%d",
  12525. +    sprintf(qinfo, "Qlogic Driver version 0.43, chip %02X at %03X, IRQ %d, TPdma:%d",
  12526.          qltyp, qbase, qlirq, QL_TURBO_PDMA );
  12527.      host->name = qinfo;
  12528.  
  12529. diff -u --recursive --new-file v1.2.7/linux/drivers/scsi/scsi.c linux/drivers/scsi/scsi.c
  12530. --- v1.2.7/linux/drivers/scsi/scsi.c    Fri Apr 14 12:02:42 1995
  12531. +++ linux/drivers/scsi/scsi.c    Tue May  2 07:38:40 1995
  12532. @@ -369,7 +369,7 @@
  12533.           do it right and use a mutex */
  12534.  
  12535.        if (current == task[0])
  12536. -          while (SCpnt->request.dev != 0xfffe);
  12537. +          while (SCpnt->request.dev != 0xfffe) barrier();
  12538.        else if (SCpnt->request.dev != 0xfffe) {
  12539.            struct semaphore sem = MUTEX_LOCKED;
  12540.  
  12541. @@ -421,7 +421,7 @@
  12542.                 256,  scan_scsis_done, SCSI_TIMEOUT, 3);
  12543.  
  12544.        if (current == task[0])
  12545. -          while (SCpnt->request.dev != 0xfffe);
  12546. +          while (SCpnt->request.dev != 0xfffe) barrier();
  12547.        else if (SCpnt->request.dev != 0xfffe) {
  12548.            struct semaphore sem = MUTEX_LOCKED;
  12549.  
  12550. @@ -584,7 +584,7 @@
  12551.                   SCSI_TIMEOUT, 3);
  12552.  
  12553.              if (current == task[0])
  12554. -            while (SCpnt->request.dev != 0xfffe);
  12555. +            while (SCpnt->request.dev != 0xfffe) barrier();
  12556.              else if (SCpnt->request.dev != 0xfffe) {
  12557.              struct semaphore sem = MUTEX_LOCKED;
  12558.  
  12559. @@ -1551,7 +1551,8 @@
  12560.          if (SCpnt->internal_timeout & IN_ABORT)
  12561.              {
  12562.              restore_flags(flags);
  12563. -            while (SCpnt->internal_timeout & IN_ABORT);
  12564. +            while (SCpnt->internal_timeout & IN_ABORT)
  12565. +                barrier();
  12566.              }
  12567.          else
  12568.              {
  12569. @@ -1644,7 +1645,8 @@
  12570.          if (SCpnt->internal_timeout & IN_RESET)
  12571.              {
  12572.              restore_flags(flags);
  12573. -            while (SCpnt->internal_timeout & IN_RESET);
  12574. +            while (SCpnt->internal_timeout & IN_RESET)
  12575. +                barrier();
  12576.              }
  12577.          else
  12578.              {
  12579. diff -u --recursive --new-file v1.2.7/linux/drivers/scsi/sd.c linux/drivers/scsi/sd.c
  12580. --- v1.2.7/linux/drivers/scsi/sd.c    Fri Apr 14 12:02:42 1995
  12581. +++ linux/drivers/scsi/sd.c    Tue May  2 07:39:45 1995
  12582. @@ -89,7 +89,8 @@
  12583.  /* Make sure that only one process can do a check_change_disk at one time.
  12584.   This is also used to lock out further access when the partition table is being re-read. */
  12585.  
  12586. -    while (rscsi_disks[target].device->busy);
  12587. +    while (rscsi_disks[target].device->busy)
  12588. +      barrier();
  12589.  
  12590.      if(rscsi_disks[target].device->removable) {
  12591.        check_disk_change(inode->i_rdev);
  12592. @@ -879,7 +880,7 @@
  12593.             512, sd_init_done,  SD_TIMEOUT,
  12594.             MAX_RETRIES);
  12595.        
  12596. -      while(SCpnt->request.dev != 0xfffe);
  12597. +      while(SCpnt->request.dev != 0xfffe) barrier();
  12598.        
  12599.        the_result = SCpnt->result;
  12600.        
  12601. @@ -905,7 +906,7 @@
  12602.                 512, sd_init_done,  SD_TIMEOUT,
  12603.                 MAX_RETRIES);
  12604.        
  12605. -      while(SCpnt->request.dev != 0xfffe);
  12606. +      while(SCpnt->request.dev != 0xfffe) barrier();
  12607.  
  12608.        spintime = jiffies;
  12609.      };
  12610. @@ -941,7 +942,7 @@
  12611.           MAX_RETRIES);
  12612.      
  12613.      if (current == task[0])
  12614. -      while(SCpnt->request.dev != 0xfffe);
  12615. +      while(SCpnt->request.dev != 0xfffe) barrier();
  12616.      else
  12617.        if (SCpnt->request.dev != 0xfffe){
  12618.            struct semaphore sem = MUTEX_LOCKED;
  12619. diff -u --recursive --new-file v1.2.7/linux/drivers/scsi/sr.c linux/drivers/scsi/sr.c
  12620. --- v1.2.7/linux/drivers/scsi/sr.c    Wed Mar 29 06:52:59 1995
  12621. +++ linux/drivers/scsi/sr.c    Tue May  2 07:40:03 1995
  12622. @@ -926,7 +926,7 @@
  12623.           MAX_RETRIES);
  12624.      
  12625.      if (current == task[0])
  12626. -      while(SCpnt->request.dev != 0xfffe);
  12627. +      while(SCpnt->request.dev != 0xfffe) barrier();
  12628.      else
  12629.        if (SCpnt->request.dev != 0xfffe){
  12630.            struct semaphore sem = MUTEX_LOCKED;
  12631. diff -u --recursive --new-file v1.2.7/linux/drivers/scsi/t128.c linux/drivers/scsi/t128.c
  12632. --- v1.2.7/linux/drivers/scsi/t128.c    Tue Nov 29 10:07:11 1994
  12633. +++ linux/drivers/scsi/t128.c    Tue May  2 07:41:02 1995
  12634. @@ -320,9 +320,9 @@
  12635.  
  12636.  #if 0
  12637.      for (; i; --i) {
  12638. -    while (!(instance->base[T_STATUS_REG_OFFSET]) & T_ST_RDY);
  12639. +    while (!(instance->base[T_STATUS_REG_OFFSET]) & T_ST_RDY) barrier();
  12640.  #else
  12641. -    while (!(instance->base[T_STATUS_REG_OFFSET]) & T_ST_RDY);
  12642. +    while (!(instance->base[T_STATUS_REG_OFFSET]) & T_ST_RDY) barrier();
  12643.      for (; i; --i) {
  12644.  #endif
  12645.      *d++ = *reg;
  12646. @@ -363,9 +363,9 @@
  12647.  
  12648.  #if 0
  12649.      for (; i; --i) {
  12650. -    while (!(instance->base[T_STATUS_REG_OFFSET]) & T_ST_RDY);
  12651. +    while (!(instance->base[T_STATUS_REG_OFFSET]) & T_ST_RDY) barrier();
  12652.  #else
  12653. -    while (!(instance->base[T_STATUS_REG_OFFSET]) & T_ST_RDY);
  12654. +    while (!(instance->base[T_STATUS_REG_OFFSET]) & T_ST_RDY) barrier();
  12655.      for (; i; --i) {
  12656.  #endif
  12657.      *reg = *s++;
  12658. diff -u --recursive --new-file v1.2.7/linux/drivers/scsi/ultrastor.c linux/drivers/scsi/ultrastor.c
  12659. --- v1.2.7/linux/drivers/scsi/ultrastor.c    Mon Jan 16 16:48:19 1995
  12660. +++ linux/drivers/scsi/ultrastor.c    Tue May  2 07:42:04 1995
  12661. @@ -733,13 +733,13 @@
  12662.    retry:
  12663.      if (config.slot)
  12664.      while (inb(config.ogm_address - 1) != 0 &&
  12665. -           config.aborted[mscp_index] == 0xff);
  12666. +           config.aborted[mscp_index] == 0xff) barrier();
  12667.  
  12668.      /* else??? */
  12669.  
  12670.      while ((inb(LCL_DOORBELL_INTR(config.doorbell_address)) & 
  12671.          (config.slot ? 2 : 1)) 
  12672. -       && config.aborted[mscp_index] == 0xff);
  12673. +       && config.aborted[mscp_index] == 0xff) barrier();
  12674.  
  12675.      /* To avoid race conditions, make the code to write to the adapter
  12676.         atomic.  This simplifies the abort code.  */
  12677. diff -u --recursive --new-file v1.2.7/linux/drivers/scsi/wd7000.c linux/drivers/scsi/wd7000.c
  12678. --- v1.2.7/linux/drivers/scsi/wd7000.c    Mon Jan 16 07:17:37 1995
  12679. +++ linux/drivers/scsi/wd7000.c    Tue May  2 07:43:45 1995
  12680. @@ -941,7 +941,7 @@
  12681.  {
  12682.      wd7000_queuecommand(SCpnt, wd7000_scsi_done);
  12683.  
  12684. -    while (SCpnt->SCp.phase > 0);  /* phase counts scbs down to 0 */
  12685. +    while (SCpnt->SCp.phase > 0) barrier();  /* phase counts scbs down to 0 */
  12686.  
  12687.      return SCpnt->result;
  12688.  }
  12689. @@ -964,7 +964,8 @@
  12690.       */
  12691.      mail_out(host, (struct scb *) &icb);
  12692.      timeout = jiffies + WAITnexttimeout;  /* wait up to 2 seconds */
  12693. -    while (icb.phase && jiffies < timeout) /* wait for completion */;
  12694. +    while (icb.phase && jiffies < timeout)
  12695. +        barrier(); /* wait for completion */
  12696.  
  12697.      if (icb.phase)  {
  12698.          printk("wd7000_diagnostics: timed out.\n");
  12699. @@ -1074,7 +1075,8 @@
  12700.       * which in turn means that scatter/gather will be disabled.
  12701.       */
  12702.      mail_out(host, (struct scb *) &icb);
  12703. -    while (icb.phase) /* wait for completion */;
  12704. +    while (icb.phase)
  12705. +        barrier(); /* wait for completion */
  12706.      host->rev1 = icb.primary;
  12707.      host->rev2 = icb.secondary;
  12708.  }
  12709. diff -u --recursive --new-file v1.2.7/linux/include/linux/sbpcd.h linux/include/linux/sbpcd.h
  12710. --- v1.2.7/linux/include/linux/sbpcd.h    Sat Mar 18 12:45:46 1995
  12711. +++ linux/include/linux/sbpcd.h    Mon May  1 21:45:40 1995
  12712. @@ -3,7 +3,10 @@
  12713.   */
  12714.  
  12715.  /*
  12716. - * the definitions for the first controller can get overridden by
  12717. + * Attention! This file contains user-serviceable parts!
  12718. + * I recommend to make use of it...
  12719. + *
  12720. + * The definitions for the first controller can get overridden by
  12721.   * the kernel command line ("lilo boot option").
  12722.   * Examples:
  12723.   *                                 sbpcd=0x230,SoundBlaster
  12724. @@ -12,64 +15,97 @@
  12725.   *                             or
  12726.   *                                 sbpcd=0x330,SPEA
  12727.   *
  12728. - * These strings are case sensitive !!!
  12729. + * If sbpcd gets used as a module, you can load it with
  12730. + *     insmod /usr/src/linux/modules/sbpcd.o sbpcd=0x230,1
  12731. + * or
  12732. + *     insmod /usr/src/linux/modules/sbpcd.o sbpcd=0x300,0
  12733. + * or
  12734. + *     insmod /usr/src/linux/modules/sbpcd.o sbpcd=0x330,2
  12735. + * respective to override the configured address and type.
  12736.   */
  12737.  
  12738.  /*
  12739. - * put your CDROM port base address into CDROM_PORT
  12740. - * and specify the type of your interface in SBPRO.
  12741. + * define your CDROM port base address as CDROM_PORT
  12742. + * and specify the type of your interface card as SBPRO.
  12743.   *
  12744. - * SBPRO addresses typically are 0x0230 (=0x220+0x10), 0x0250, ...
  12745. - * LASERMATE (CI-101P, WDH-7001C) addresses typically are 0x0300, 0x0310, ...
  12746. - * SPEA addresses are 0x320, 0x330, 0x340, 0x350
  12747. - * there are some soundcards on the market with 0x0630, 0x0650, ...
  12748. + * Read linux/drivers/block/README.sbpcd if you are in doubt about the
  12749. + * type of your interface card (you should do that anyway).
  12750.   *
  12751. - * example: if your SBPRO audio address is 0x220, specify 0x230.
  12752. + * address:
  12753. + * ========
  12754. + * SBPRO type addresses typically are 0x0230 (=0x220+0x10), 0x0250, ...
  12755. + * LASERMATE type (CI-101P, WDH-7001C) addresses typically are 0x0300, ...
  12756. + * SPEA addresses are from the LASERMATE type and range.
  12757. + * There are some soundcards on the market with 0x0630, 0x0650, ...; their
  12758. + * type is not obvious (both types are possible).
  12759.   *
  12760. + * example: if your SBPRO audio address is 0x220, specify 0x230 and SBPRO 1.
  12761. + *          if your soundcard has its CDROM port above 0x300, specify
  12762. + *          that address and try SBPRO 0 first.
  12763.   *
  12764. + * interface type:
  12765. + * ===============
  12766.   * set SBPRO to 1 for "true" SoundBlaster card
  12767. - * set SBPRO to 0 for "poor" (no sound) interface cards
  12768. - *                and for "compatible" soundcards.
  12769. + * set SBPRO to 0 for "compatible" soundcards and
  12770. + *                for "poor" (no sound) interface cards.
  12771.   * set SBPRO to 2 for the SPEA Media FX card
  12772.   *
  12773. - * most "compatible" sound boards like Galaxy need to set SBPRO to 0 !!!
  12774. - * if SBPRO gets set wrong, the drive will get found - but any
  12775. + * Almost all "compatible" sound boards need to set SBPRO to 0.
  12776. + * If SBPRO is set wrong, the drives will get found - but any
  12777.   * data access will give errors (audio access will work).
  12778. - * The OmniCD interface card from CreativeLabs needs SBPRO 1.
  12779. + * The "OmniCD" no-sound interface card from CreativeLabs needs SBPRO 1.
  12780.   *
  12781. - * mail to emoenke@gwdg.de if your "compatible" card needs SBPRO 1
  12782. - * (currently I do not know any "compatible" with SBPRO 1)
  12783. - * then I can include better information with the next release.
  12784. - */
  12785. -#if !(SBPCD_ISSUE-1) /* first (or if you have only one) interface board: */
  12786. -#define CDROM_PORT 0x0340
  12787. -#define SBPRO     0
  12788. -#endif
  12789. -
  12790. -/*
  12791. - * If you have a "compatible" soundcard of type "SBPRO 0" or "SBPRO 2",
  12792. - * enter your sound card's base address here if you want sbpcd to turn
  12793. - * the CD sound channels on.
  12794. + * mail to emoenke@gwdg.de if you have a "compatible" sound card which
  12795. + * in fact needs to set SBPRO to 1 (not any known at time).
  12796. + *
  12797. + * sound base:
  12798. + * ===========
  12799. + * The SOUND_BASE definition tells if we should try to turn the CD sound
  12800. + * channels on. It will only be of use regarding soundcards with a SbPro
  12801. + * compatible mixer.
  12802.   *
  12803.   * Example: #define SOUND_BASE 0x220 enables the sound card's CD channels
  12804.   *          #define SOUND_BASE 0     leaves the soundcard untouched
  12805.   */
  12806. -#define SOUND_BASE 0x220
  12807. -
  12808. -/* ignore the rest if you have only one interface board & driver */
  12809. -
  12810. -#if !(SBPCD_ISSUE-2) /* second interface board: */
  12811. -#define CDROM_PORT 0x0320
  12812. -#define SBPRO     0
  12813. +#if !(SBPCD_ISSUE-1)     /* first (or if you have only one) interface board: */
  12814. +#define CDROM_PORT 0x340 /* <-----------<< port address                      */
  12815. +#define SBPRO      0     /* <-----------<< interface type                    */
  12816. +#define SOUND_BASE 0x220 /* <-----------<< sound address of this card or 0   */
  12817.  #endif
  12818. -#if !(SBPCD_ISSUE-3) /* third interface board: */
  12819. -#define CDROM_PORT 0x0630
  12820. -#define SBPRO     1
  12821. +#if !(SBPCD_ISSUE-2)     /* ==================== second interface board: === */
  12822. +#define CDROM_PORT 0x344 /* <-----------<< port address                      */
  12823. +#define SBPRO      0     /* <-----------<< interface type                    */
  12824. +#define SOUND_BASE 0x000 /* <-----------<< sound address of this card or 0   */
  12825.  #endif
  12826. -#if !(SBPCD_ISSUE-4) /* fourth interface board: */
  12827. -#define CDROM_PORT 0x0634
  12828. -#define SBPRO     0
  12829. +#if !(SBPCD_ISSUE-3)     /* ===================== third interface board: === */
  12830. +#define CDROM_PORT 0x634 /* <-----------<< port address                      */
  12831. +#define SBPRO      1     /* <-----------<< interface type                    */
  12832. +#define SOUND_BASE 0x240 /* <-----------<< sound address of this card or 0   */
  12833.  #endif
  12834. +#if !(SBPCD_ISSUE-4)     /* ==================== fourth interface board: === */
  12835. +#define CDROM_PORT 0x634 /* <-----------<< port address                      */
  12836. +#define SBPRO      0     /* <-----------<< interface type                    */
  12837. +#define SOUND_BASE 0x000 /* <-----------<< sound address of this card or 0   */
  12838. +#endif
  12839. +
  12840. +/*
  12841. + * some more or less user dependent definitions - service them!
  12842. + */
  12843. +
  12844. +/* Set this to 0 after you have configured your interface definitions right. */
  12845. +#define DISTRIBUTION 1
  12846. +
  12847. +/* max. number of audio frames to read with one     */
  12848. +/* request (allocates n* 2352 bytes kernel memory!) */
  12849. +/* may be freely adjusted, f.e. 75 (= 1 sec.), at   */
  12850. +/* runtime by use of the CDROMAUDIOBUFSIZ ioctl.    */
  12851. +#define READ_AUDIO 0 
  12852. +
  12853. +/* tray control: eject tray if no disk is in (0 or 1) */
  12854. +#define JUKEBOX 1
  12855. +
  12856. +/* tray control: eject tray after last use (0 or 1) */
  12857. +#define EJECT 1
  12858.  
  12859.  /*==========================================================================*/
  12860.  /*==========================================================================*/
  12861. @@ -79,49 +115,65 @@
  12862.  #ifndef _LINUX_SBPCD_H
  12863.  
  12864.  #define _LINUX_SBPCD_H
  12865. -
  12866.  /*==========================================================================*/
  12867.  /*==========================================================================*/
  12868. +#define LONG_TIMING 0 /* test against timeouts with "gold" CDs on CR-521 */
  12869. +#undef  FUTURE
  12870. +
  12871. +#define TEST_UPC 0
  12872. +#define SPEA_TEST 0
  12873. +#define TEST_STI 0
  12874. +#undef PATH_CHECK
  12875. +/*==========================================================================*/
  12876.  /*
  12877.   * DDI interface definitions
  12878.   * "invented" by Fred N. van Kempen..
  12879.   */
  12880.  #define DDIOCSDBG    0x9000
  12881. -#define DPRINTF(x)    sbpcd_dprintf x
  12882. +
  12883. +/*==========================================================================*/
  12884. +/*
  12885. + * "private" IOCTL functions
  12886. + */
  12887. +#define CDROMRESET        0x5380 /* hard-rest the drive */
  12888. +#define CDROMVOLREAD        0x5381 /* let the drive tell its volume settings */
  12889. +#define CDROMAUDIOBUFSIZ    0x5382 /* set the audio buffer size */
  12890.  
  12891.  /*==========================================================================*/
  12892.  /*
  12893.   * Debug output levels
  12894.   */
  12895. -#define DBG_INF        1    /* necessary information */
  12896. -#define DBG_BSZ        2    /* BLOCK_SIZE trace */
  12897. -#define DBG_REA        3    /* "read" status trace */
  12898. -#define DBG_CHK        4    /* "media check" trace */
  12899. -#define DBG_TIM        5    /* datarate timer test */
  12900. -#define DBG_INI        6    /* initialization trace */
  12901. -#define DBG_TOC        7    /* tell TocEntry values */
  12902. -#define DBG_IOC         8    /* ioctl trace */
  12903. -#define DBG_STA        9    /* "ResponseStatus" trace */
  12904. -#define DBG_ERR        10    /* "xx_ReadError" trace */
  12905. -#define DBG_CMD        11    /* "cmd_out" trace */
  12906. -#define DBG_WRN        12    /* give explanation before auto-probing */
  12907. -#define DBG_MUL         13      /* multi session code test */
  12908. -#define DBG_ID        14    /* "drive_id !=0" test code */
  12909. -#define DBG_IOX        15    /* some special information */
  12910. -#define DBG_DID        16    /* drive ID test */
  12911. -#define DBG_RES        17    /* drive reset info */
  12912. -#define DBG_SPI        18    /* SpinUp test */
  12913. -#define DBG_IOS        19    /* ioctl trace: "subchannel" */
  12914. -#define DBG_IO2        20    /* ioctl trace: general */
  12915. -#define DBG_UPC        21    /* show UPC information */
  12916. -#define DBG_XA         22    /* XA mode debugging */
  12917. -#define DBG_LCK        23    /* door (un)lock info */
  12918. -#define DBG_SQ         24    /* dump SubQ frame */
  12919. -#define DBG_AUD        25      /* "read audio" debugging */
  12920. -#define DBG_SEQ        26      /* Sequoia interface configuration trace */
  12921. -#define DBG_LCS        27      /* Longshine LCS-7260 debugging trace */
  12922. -#define DBG_CD2        28      /* MKE CD200 debugging trace */
  12923. -#define DBG_000        29      /* unnecessary information */
  12924. +#define DBG_INF    1    /* necessary information */
  12925. +#define DBG_BSZ    2    /* BLOCK_SIZE trace */
  12926. +#define DBG_REA    3    /* READ status trace */
  12927. +#define DBG_CHK    4    /* MEDIA CHECK trace */
  12928. +#define DBG_TIM    5    /* datarate timer test */
  12929. +#define DBG_INI    6    /* initialization trace */
  12930. +#define DBG_TOC    7    /* tell TocEntry values */
  12931. +#define DBG_IOC    8    /* ioctl trace */
  12932. +#define DBG_STA    9    /* ResponseStatus() trace */
  12933. +#define DBG_ERR    10    /* cc_ReadError() trace */
  12934. +#define DBG_CMD    11    /* cmd_out() trace */
  12935. +#define DBG_WRN    12    /* give explanation before auto-probing */
  12936. +#define DBG_MUL    13    /* multi session code test */
  12937. +#define DBG_IDX    14    /* test code for drive_id !=0 */
  12938. +#define DBG_IOX    15    /* some special information */
  12939. +#define DBG_DID    16    /* drive ID test */
  12940. +#define DBG_RES    17    /* drive reset info */
  12941. +#define DBG_SPI    18    /* SpinUp test */
  12942. +#define DBG_IOS    19    /* ioctl trace: subchannel functions */
  12943. +#define DBG_IO2    20    /* ioctl trace: general */
  12944. +#define DBG_UPC    21    /* show UPC information */
  12945. +#define DBG_XA1    22    /* XA mode debugging */
  12946. +#define DBG_LCK    23    /* door (un)lock info */
  12947. +#define DBG_SQ1    24    /* dump SubQ frame */
  12948. +#define DBG_AUD    25    /* READ AUDIO debugging */
  12949. +#define DBG_SEQ    26    /* Sequoia interface configuration trace */
  12950. +#define DBG_LCS    27    /* Longshine LCS-7260 debugging trace */
  12951. +#define DBG_CD2    28    /* MKE CD200 debugging trace */
  12952. +#define DBG_TEA    29    /* TEAC CD-55A debugging trace */
  12953. +#define DBG_TE2    30    /* TEAC CD-55A 2nd debugging level */
  12954. +#define DBG_000    31    /* unnecessary information */
  12955.  
  12956.  /*==========================================================================*/
  12957.  /*==========================================================================*/
  12958. @@ -154,35 +206,41 @@
  12959.  /*
  12960.   * disk states (bits of diskstate_flags):
  12961.   */
  12962. -#define upc_valid (DriveStruct[d].diskstate_flags&upc_bit)
  12963. -#define volume_valid (DriveStruct[d].diskstate_flags&volume_bit)
  12964. -#define toc_valid (DriveStruct[d].diskstate_flags&toc_bit)
  12965. -#define cd_size_valid (DriveStruct[d].diskstate_flags&cd_size_bit)
  12966. -#define subq_valid (DriveStruct[d].diskstate_flags&subq_bit)
  12967. -#define frame_size_valid (DriveStruct[d].diskstate_flags&frame_size_bit)
  12968. -
  12969. -/*
  12970. - * bits of the status_byte (result of xx_ReadStatus):
  12971. - */
  12972. -#define p_door_closed 0x80
  12973. -#define p_caddy_in 0x40
  12974. -#define p_spinning 0x20
  12975. -#define p_check 0x10
  12976. -#define p_busy_new 0x08
  12977. -#define p_door_locked 0x04
  12978. -#define p_bit_1 0x02 /* hopefully unused now */
  12979. -#define p_lcs_door_locked 0x02 /* new use of old bit */
  12980. -#define p_disk_ok 0x01
  12981. -#define p_lcs_door_closed 0x01 /* new use of old bit */
  12982. -/*
  12983. - * "old" drives status result bits:
  12984. - */
  12985. -#define p_caddin_old 0x40
  12986. -#define p_success_old 0x08
  12987. -#define p_busy_old 0x04
  12988. +#define upc_valid        (D_S[d].diskstate_flags&upc_bit)
  12989. +#define volume_valid        (D_S[d].diskstate_flags&volume_bit)
  12990. +#define toc_valid        (D_S[d].diskstate_flags&toc_bit)
  12991. +#define cd_size_valid        (D_S[d].diskstate_flags&cd_size_bit)
  12992. +#define subq_valid        (D_S[d].diskstate_flags&subq_bit)
  12993. +#define frame_size_valid    (D_S[d].diskstate_flags&frame_size_bit)
  12994.  
  12995.  /*
  12996. - * "generation specific" defs of the status_byte:
  12997. + * the status_bits variable
  12998. + */
  12999. +#define p_success    0x100
  13000. +#define p_door_closed    0x80
  13001. +#define p_caddy_in    0x40
  13002. +#define p_spinning    0x20
  13003. +#define p_check        0x10
  13004. +#define p_busy_new    0x08
  13005. +#define p_door_locked    0x04
  13006. +#define p_disk_ok    0x01
  13007. +
  13008. +/*
  13009. + * LCS-7260 special status result bits:
  13010. + */
  13011. +#define p_lcs_door_locked    0x02
  13012. +#define p_lcs_door_closed    0x01
  13013. +
  13014. +/*
  13015. + * CR-52x special status result bits:
  13016. + */
  13017. +#define p_caddin_old    0x40
  13018. +#define p_success_old    0x08
  13019. +#define p_busy_old    0x04
  13020. +#define p_bit_1        0x02    /* hopefully unused now */
  13021. +
  13022. +/*
  13023. + * "generation specific" defs of the status result bits:
  13024.   */
  13025.  #define p0_door_closed    0x80
  13026.  #define p0_caddy_in    0x40
  13027. @@ -193,6 +251,14 @@
  13028.  #define p0_bit_1    0x02 /* unused */
  13029.  #define p0_disk_ok    0x01
  13030.  
  13031. +#define pL_disk_in    0x40
  13032. +#define pL_spinning    0x20
  13033. +#define pL_check    0x10
  13034. +#define pL_success    0x08 /* unused ?? */
  13035. +#define pL_busy        0x04
  13036. +#define pL_door_locked    0x02
  13037. +#define pL_door_closed    0x01
  13038. +
  13039.  #define p1_door_closed    0x80
  13040.  #define p1_disk_in    0x40
  13041.  #define p1_spinning    0x20
  13042. @@ -214,60 +280,66 @@
  13043.  /*
  13044.   * used drive states:
  13045.   */
  13046. -#define st_door_closed (DriveStruct[d].status_byte&p_door_closed)
  13047. -#define st_caddy_in (DriveStruct[d].status_byte&p_caddy_in)
  13048. -#define st_spinning (DriveStruct[d].status_byte&p_spinning)
  13049. -#define st_check (DriveStruct[d].status_byte&p_check)
  13050. -#define st_busy (DriveStruct[d].status_byte&p_busy_new)
  13051. -#define st_door_locked (DriveStruct[d].status_byte&p_door_locked)
  13052. -#define st_diskok (DriveStruct[d].status_byte&p_disk_ok)
  13053. +#define st_door_closed    (D_S[d].status_bits&p_door_closed)
  13054. +#define st_caddy_in    (D_S[d].status_bits&p_caddy_in)
  13055. +#define st_spinning    (D_S[d].status_bits&p_spinning)
  13056. +#define st_check    (D_S[d].status_bits&p_check)
  13057. +#define st_busy        (D_S[d].status_bits&p_busy_new)
  13058. +#define st_door_locked    (D_S[d].status_bits&p_door_locked)
  13059. +#define st_diskok    (D_S[d].status_bits&p_disk_ok)
  13060.  
  13061.  /*
  13062.   * bits of the CDi_status register:
  13063.   */
  13064. -#define s_not_result_ready 0x04  /* 0: "result ready" */
  13065. -#define s_not_data_ready 0x02    /* 0: "data ready"   */
  13066. -#define s_attention 0x01         /* 1: "attention required" */
  13067. +#define s_not_result_ready    0x04 /* 0: "result ready" */
  13068. +#define s_not_data_ready    0x02 /* 0: "data ready"   */
  13069. +#define s_attention        0x01 /* 1: "attention required" */
  13070.  /*
  13071.   * usable as:
  13072.   */
  13073. -#define DRV_ATTN               ((inb(CDi_status)&s_attention)!=0)
  13074. -#define DATA_READY             ((inb(CDi_status)&s_not_data_ready)==0)
  13075. -#define RESULT_READY           ((inb(CDi_status)&s_not_result_ready)==0)
  13076. +#define DRV_ATTN    ((inb(CDi_status)&s_attention)!=0)
  13077. +#define DATA_READY    ((inb(CDi_status)&s_not_data_ready)==0)
  13078. +#define RESULT_READY    ((inb(CDi_status)&s_not_result_ready)==0)
  13079.  
  13080.  /*
  13081.   * drive types (firmware versions):
  13082.   */
  13083. -#define drv_fam0 0x08   /* CR-52x family */
  13084. -#define drv_199 (drv_fam0+0x01)    /* <200 */
  13085. -#define drv_200 (drv_fam0+0x02)    /* <201 */
  13086. -#define drv_201 (drv_fam0+0x03)    /* <210 */
  13087. -#define drv_210 (drv_fam0+0x04)    /* <211 */
  13088. -#define drv_211 (drv_fam0+0x05)    /* <300 */
  13089. -#define drv_300 (drv_fam0+0x06)    /* >=300 */
  13090. -
  13091. -#define drv_famL 0x10    /* Longshine family */
  13092. -#define drv_260 (drv_famL+0x01)    /* LCS-7260 */
  13093. -
  13094. -#define drv_fam1 0x20    /* CR-56x family */
  13095. -#define drv_099 (drv_fam1+0x01)    /* <100 */
  13096. -#define drv_100 (drv_fam1+0x02)    /* >=100 */
  13097. -
  13098. -#define drv_fam2 0x80    /* CD200 family */
  13099. -
  13100. -#define fam0_drive (DriveStruct[d].drv_type&drv_fam0)
  13101. -#define famL_drive (DriveStruct[d].drv_type&drv_famL)
  13102. -#define fam1_drive (DriveStruct[d].drv_type&drv_fam1)
  13103. -#define fam2_drive (DriveStruct[d].drv_type&drv_fam2)
  13104. -#define fam0L_drive (DriveStruct[d].drv_type&(drv_fam0|drv_famL))
  13105. -#define fam1L_drive (DriveStruct[d].drv_type&(drv_fam1|drv_famL))
  13106. -#define fam01_drive (DriveStruct[d].drv_type&(drv_fam0|drv_fam1))
  13107. +#define drv_fam0    0x08        /* CR-52x family */
  13108. +#define drv_199        (drv_fam0+0x01)    /* <200 */
  13109. +#define drv_200        (drv_fam0+0x02)    /* <201 */
  13110. +#define drv_201        (drv_fam0+0x03)    /* <210 */
  13111. +#define drv_210        (drv_fam0+0x04)    /* <211 */
  13112. +#define drv_211        (drv_fam0+0x05)    /* <300 */
  13113. +#define drv_300        (drv_fam0+0x06)    /* >=300 */
  13114. +
  13115. +#define drv_famL    0x10        /* Longshine family */
  13116. +#define drv_260        (drv_famL+0x01)    /* LCS-7260 */
  13117. +#define drv_e1        (drv_famL+0x01)    /* LCS-7260, firmware "A E1" */
  13118. +#define drv_f4        (drv_famL+0x02)    /* LCS-7260, firmware "A4F4" */
  13119. +
  13120. +#define drv_fam1    0x20        /* CR-56x family */
  13121. +#define drv_099        (drv_fam1+0x01)    /* <100 */
  13122. +#define drv_100        (drv_fam1+0x02)    /* >=100, only 5.00 known here */
  13123. +
  13124. +#define drv_famT    0x40        /* TEAC CD-55A */
  13125. +#define drv_fam2    0x80        /* CD200 family */
  13126. +
  13127. +#define fam0_drive    (D_S[d].drv_type&drv_fam0)
  13128. +#define famL_drive    (D_S[d].drv_type&drv_famL)
  13129. +#define fam1_drive    (D_S[d].drv_type&drv_fam1)
  13130. +#define fam2_drive    (D_S[d].drv_type&drv_fam2)
  13131. +#define famT_drive    (D_S[d].drv_type&drv_famT)
  13132. +#define fam0L_drive    (D_S[d].drv_type&(drv_fam0|drv_famL))
  13133. +#define fam1L_drive    (D_S[d].drv_type&(drv_fam1|drv_famL))
  13134. +#define fam01_drive    (D_S[d].drv_type&(drv_fam0|drv_fam1))
  13135. +#define fam12_drive    (D_S[d].drv_type&(drv_fam1|drv_fam2))
  13136. +#define fam2T_drive    (D_S[d].drv_type&(drv_fam2|drv_famT))
  13137.  
  13138.  /*
  13139.   * audio states:
  13140.   */
  13141. -#define audio_playing 2
  13142. -#define audio_pausing 1
  13143. +#define audio_playing    2
  13144. +#define audio_pausing    1
  13145.  
  13146.  /*
  13147.   * drv_pattern, drv_options:
  13148. @@ -280,10 +352,10 @@
  13149.  /*
  13150.   * values of cmd_type (0 else):
  13151.   */
  13152. -#define READ_M1  0x01 /* "data mode 1": 2048 bytes per frame */
  13153. -#define READ_M2  0x02 /* "data mode 2": 12+2048+280 bytes per frame */
  13154. -#define READ_SC  0x04 /* "subchannel info": 96 bytes per frame */
  13155. -#define READ_AU  0x08 /* "audio frame": 2352 bytes per frame */
  13156. +#define READ_M1    0x01    /* "data mode 1": 2048 bytes per frame */
  13157. +#define READ_M2    0x02    /* "data mode 2": 12+2048+280 bytes per frame */
  13158. +#define READ_SC    0x04    /* "subchannel info": 96 bytes per frame */
  13159. +#define READ_AU    0x08    /* "audio frame": 2352 bytes per frame */
  13160.  
  13161.  /*
  13162.   * sense_byte:
  13163. @@ -314,32 +386,27 @@
  13164.  /*
  13165.   * highest allowed drive number (MINOR+1)
  13166.   */
  13167. -#define NR_SBPCD 4
  13168. +#define NR_SBPCD    4
  13169.  
  13170.  /*
  13171.   * we try to never disable interrupts - seems to work
  13172.   */
  13173. -#define SBPCD_DIS_IRQ 0
  13174. +#define SBPCD_DIS_IRQ    0
  13175.  
  13176.  /*
  13177.   * "write byte to port"
  13178.   */
  13179. -#define OUT(x,y) outb(y,x)
  13180. -
  13181. -/*
  13182. - * use "REP INSB" for strobing the data in:
  13183. - */
  13184. -#define READ_DATA(port, buf, nr) insb(port, buf, nr)
  13185. +#define OUT(x,y)    outb(y,x)
  13186.  
  13187.  /*==========================================================================*/
  13188.  
  13189. -#define MIXER_CD_Volume    0x28 /* internal SB Pro register address */
  13190. +#define MIXER_CD_Volume    0x28    /* internal SB Pro register address */
  13191.  
  13192.  /*==========================================================================*/
  13193.  /*
  13194.   * Creative Labs Programmers did this:
  13195.   */
  13196. -#define MAX_TRACKS    120 /* why more than 99? */
  13197. +#define MAX_TRACKS    120    /* why more than 99? */
  13198.  
  13199.  /*==========================================================================*/
  13200.  /*
  13201. @@ -347,17 +414,15 @@
  13202.   */
  13203.  typedef union _msf
  13204.  {
  13205. -  u_int n;
  13206. -  u_char c[4];
  13207. -}
  13208. -MSF;
  13209. +    u_int n;
  13210. +    u_char c[4];
  13211. +} MSF;
  13212.  
  13213.  typedef union _blk
  13214.  {
  13215. -  u_int n;
  13216. -  u_char c[4];
  13217. -}
  13218. -BLK;
  13219. +    u_int n;
  13220. +    u_char c[4];
  13221. +} BLK;
  13222.  
  13223.  /*==========================================================================*/
  13224.  
  13225. @@ -519,111 +584,177 @@
  13226.   * CR-56x:      CMD1_
  13227.   * CD200:       CMD2_
  13228.   * LCS-7260:    CMDL_
  13229. + * TEAC CD-55A: CMDT_
  13230.   */
  13231.  #define CMD1_RESET    0x0a
  13232.  #define CMD2_RESET    0x01
  13233. +#define CMDT_RESET    0xc0
  13234. +
  13235.  #define CMD1_LOCK_CTL    0x0c
  13236.  #define CMD2_LOCK_CTL    0x1e
  13237. +#define CMDT_LOCK_CTL    CMD2_LOCK_CTL
  13238.  #define CMDL_LOCK_CTL    0x0e
  13239. +
  13240.  #define CMD1_TRAY_CTL    0x07
  13241.  #define CMD2_TRAY_CTL    0x1b
  13242. +#define CMDT_TRAY_CTL    CMD2_TRAY_CTL
  13243.  #define CMDL_TRAY_CTL    0x0d
  13244. +
  13245.  #define CMD1_MULTISESS    0x8d
  13246.  #define CMDL_MULTISESS    0x8c
  13247. +
  13248.  #define CMD1_SUBCHANINF    0x11
  13249. -#define CMD2_SUBCHANINF    0x
  13250. +#define CMD2_SUBCHANINF    0x??
  13251. +
  13252.  #define CMD2_x02    0x02
  13253.  #define CMD1_x08    0x08
  13254.  #define CMD2_x08    0x08
  13255. +#define CMDT_x08    0x08
  13256. +
  13257.  #define CMD2_SETSPEED    0xda
  13258.  
  13259.  #define CMD0_PATH_CHECK    0x00
  13260. -#define CMD1_PATH_CHECK    0x00
  13261. -#define CMD2_PATH_CHECK    0x
  13262. -#define CMDL_PATH_CHECK    0x00
  13263. +#define CMD1_PATH_CHECK    0x???
  13264. +#define CMD2_PATH_CHECK    0x???
  13265. +#define CMDT_PATH_CHECK    0x???
  13266. +#define CMDL_PATH_CHECK    CMD0_PATH_CHECK
  13267. +
  13268.  #define CMD0_SEEK    0x01
  13269. -#define CMD1_SEEK    0x01
  13270. +#define CMD1_SEEK    CMD0_SEEK
  13271.  #define CMD2_SEEK    0x2b
  13272. -#define CMDL_SEEK    0x01
  13273. +#define CMDT_SEEK    CMD2_SEEK
  13274. +#define CMDL_SEEK    CMD0_SEEK
  13275. +
  13276.  #define CMD0_READ    0x02
  13277.  #define CMD1_READ    0x10
  13278.  #define CMD2_READ    0x28
  13279. -#define CMDL_READ    0x02
  13280. +#define CMDT_READ    CMD2_READ
  13281. +#define CMDL_READ    CMD0_READ
  13282. +
  13283.  #define CMD0_READ_XA    0x03
  13284.  #define CMD2_READ_XA    0xd4
  13285. -#define CMDL_READ_XA    0x03 /* really ?? */
  13286. +#define CMDL_READ_XA    CMD0_READ_XA /* really ?? */
  13287. +
  13288.  #define CMD0_READ_HEAD    0x04
  13289. +
  13290.  #define CMD0_SPINUP    0x05
  13291.  #define CMD1_SPINUP    0x02
  13292.  #define CMD2_SPINUP    CMD2_TRAY_CTL
  13293. -#define CMDL_SPINUP    0x05
  13294. +#define CMDL_SPINUP    CMD0_SPINUP
  13295. +
  13296.  #define CMD0_SPINDOWN    0x06 /* really??? */
  13297.  #define CMD1_SPINDOWN    0x06
  13298.  #define CMD2_SPINDOWN    CMD2_TRAY_CTL
  13299.  #define CMDL_SPINDOWN    0x0d
  13300. +
  13301.  #define CMD0_DIAG    0x07
  13302. +
  13303.  #define CMD0_READ_UPC    0x08
  13304.  #define CMD1_READ_UPC    0x88
  13305. -#define CMD2_READ_UPC    0x
  13306. -#define CMDL_READ_UPC    0x08
  13307. +#define CMD2_READ_UPC    0x???
  13308. +#define CMDL_READ_UPC    CMD0_READ_UPC
  13309. +
  13310.  #define CMD0_READ_ISRC    0x09
  13311. +
  13312.  #define CMD0_PLAY    0x0a
  13313. -#define CMD1_PLAY    0x
  13314. -#define CMD2_PLAY    0x
  13315. -#define CMDL_PLAY    0x0a
  13316. +#define CMD1_PLAY    0x???
  13317. +#define CMD2_PLAY    0x???
  13318. +#define CMDL_PLAY    CMD0_PLAY
  13319. +
  13320.  #define CMD0_PLAY_MSF    0x0b
  13321.  #define CMD1_PLAY_MSF    0x0e
  13322.  #define CMD2_PLAY_MSF    0x47
  13323. -#define CMDL_PLAY_MSF    0x
  13324. +#define CMDT_PLAY_MSF    CMD2_PLAY_MSF
  13325. +#define CMDL_PLAY_MSF    0x???
  13326. +
  13327.  #define CMD0_PLAY_TI    0x0c
  13328. +
  13329.  #define CMD0_STATUS    0x81
  13330.  #define CMD1_STATUS    0x05
  13331.  #define CMD2_STATUS    0x00
  13332. -#define CMDL_STATUS    0x81
  13333. +#define CMDT_STATUS    CMD2_STATUS
  13334. +#define CMDL_STATUS    CMD0_STATUS
  13335. +
  13336.  #define CMD0_READ_ERR    0x82
  13337. -#define CMD1_READ_ERR    0x82
  13338. +#define CMD1_READ_ERR    CMD0_READ_ERR
  13339.  #define CMD2_READ_ERR    0x03
  13340. -#define CMDL_READ_ERR    0x82
  13341. +#define CMDT_READ_ERR    CMD2_READ_ERR /* get audio status */
  13342. +#define CMDL_READ_ERR    CMD0_READ_ERR
  13343. +
  13344.  #define CMD0_READ_VER    0x83
  13345. -#define CMD1_READ_VER    0x83
  13346. +#define CMD1_READ_VER    CMD0_READ_VER
  13347.  #define CMD2_READ_VER    0x12
  13348. -#define CMDL_READ_VER    0x83
  13349. +#define CMDT_READ_VER    CMD2_READ_VER /* really ?? */
  13350. +#define CMDL_READ_VER    CMD0_READ_VER
  13351. +
  13352.  #define CMD0_SETMODE    0x84
  13353.  #define CMD1_SETMODE    0x09
  13354.  #define CMD2_SETMODE    0x55
  13355. -#define CMDL_SETMODE    0x84
  13356. +#define CMDT_SETMODE    CMD2_SETMODE
  13357. +#define CMDL_SETMODE    CMD0_SETMODE
  13358. +
  13359.  #define CMD0_GETMODE    0x85
  13360.  #define CMD1_GETMODE    0x84
  13361.  #define CMD2_GETMODE    0x5a
  13362. -#define CMDL_GETMODE    0x85
  13363. +#define CMDT_GETMODE    CMD2_GETMODE
  13364. +#define CMDL_GETMODE    CMD0_GETMODE
  13365. +
  13366.  #define CMD0_SET_XA    0x86
  13367. +
  13368.  #define CMD0_GET_XA    0x87
  13369. +
  13370.  #define CMD0_CAPACITY    0x88
  13371.  #define CMD1_CAPACITY    0x85
  13372.  #define CMD2_CAPACITY    0x25
  13373. -#define CMDL_CAPACITY    0x88
  13374. +#define CMDL_CAPACITY    CMD0_CAPACITY /* missing in some firmware versions */
  13375. +
  13376.  #define CMD0_READSUBQ    0x89
  13377.  #define CMD1_READSUBQ    0x87
  13378.  #define CMD2_READSUBQ    0x42
  13379. -#define CMDL_READSUBQ    0x89
  13380. +#define CMDT_READSUBQ    CMD2_READSUBQ
  13381. +#define CMDL_READSUBQ    CMD0_READSUBQ
  13382. +
  13383.  #define CMD0_DISKCODE    0x8a
  13384. +
  13385.  #define CMD0_DISKINFO    0x8b
  13386. -#define CMD1_DISKINFO    0x8b
  13387. +#define CMD1_DISKINFO    CMD0_DISKINFO
  13388.  #define CMD2_DISKINFO    0x43
  13389. -#define CMDL_DISKINFO    0x8b
  13390. +#define CMDT_DISKINFO    CMD2_DISKINFO
  13391. +#define CMDL_DISKINFO    CMD0_DISKINFO
  13392. +
  13393.  #define CMD0_READTOC    0x8c
  13394. -#define CMD1_READTOC    0x8c
  13395. -#define CMD2_READTOC    0x
  13396. -#define CMDL_READTOC    0x8c
  13397. +#define CMD1_READTOC    CMD0_READTOC
  13398. +#define CMD2_READTOC    0x???
  13399. +#define CMDL_READTOC    CMD0_READTOC
  13400. +
  13401.  #define CMD0_PAU_RES    0x8d
  13402.  #define CMD1_PAU_RES    0x0d
  13403.  #define CMD2_PAU_RES    0x4b
  13404. -#define CMDL_PAU_RES    0x8d
  13405. +#define CMDT_PAUSE    CMD2_PAU_RES
  13406. +#define CMDL_PAU_RES    CMD0_PAU_RES
  13407. +
  13408.  #define CMD0_PACKET    0x8e
  13409. -#define CMD1_PACKET    0x8e
  13410. -#define CMD2_PACKET    0x
  13411. -#define CMDL_PACKET    0x8e
  13412. +#define CMD1_PACKET    CMD0_PACKET
  13413. +#define CMD2_PACKET    0x???
  13414. +#define CMDL_PACKET    CMD0_PACKET
  13415.  
  13416.  /*==========================================================================*/
  13417.  /*==========================================================================*/
  13418.  #endif _LINUX_SBPCD_H
  13419. +/*==========================================================================*/
  13420. +/*
  13421. + * Overrides for Emacs so that we follow Linus's tabbing style.
  13422. + * Emacs will notice this stuff at the end of the file and automatically
  13423. + * adjust the settings for this buffer only.  This must remain at the end
  13424. + * of the file. 
  13425. + * ---------------------------------------------------------------------------
  13426. + * Local variables:
  13427. + * c-indent-level: 8
  13428. + * c-brace-imaginary-offset: 0
  13429. + * c-brace-offset: -8
  13430. + * c-argdecl-indent: 8
  13431. + * c-label-offset: -8
  13432. + * c-continued-statement-offset: 8
  13433. + * c-continued-brace-offset: 0
  13434. + * End:
  13435. + */
  13436. diff -u --recursive --new-file v1.2.7/linux/include/linux/sched.h linux/include/linux/sched.h
  13437. --- v1.2.7/linux/include/linux/sched.h    Sun Apr  9 11:59:57 1995
  13438. +++ linux/include/linux/sched.h    Tue May  2 07:22:23 1995
  13439. @@ -77,6 +77,8 @@
  13440.  
  13441.  #ifdef __KERNEL__
  13442.  
  13443. +#define barrier() __asm__("": : :"memory")
  13444. +
  13445.  extern void sched_init(void);
  13446.  extern void show_state(void);
  13447.  extern void trap_init(void);
  13448. diff -u --recursive --new-file v1.2.7/linux/include/linux/tty.h linux/include/linux/tty.h
  13449. --- v1.2.7/linux/include/linux/tty.h    Sun Feb 26 16:45:26 1995
  13450. +++ linux/include/linux/tty.h    Tue May  2 08:33:51 1995
  13451. @@ -255,6 +255,7 @@
  13452.  #define TTY_DEBUG 4
  13453.  #define TTY_DO_WRITE_WAKEUP 5
  13454.  #define TTY_PUSH 6
  13455. +#define TTY_CLOSING 7
  13456.  
  13457.  #define TTY_WRITE_FLUSH(tty) tty_write_flush((tty))
  13458.  
  13459. diff -u --recursive --new-file v1.2.7/linux/kernel/ksyms.c linux/kernel/ksyms.c
  13460. --- v1.2.7/linux/kernel/ksyms.c    Fri Apr 28 11:10:56 1995
  13461. +++ linux/kernel/ksyms.c    Tue May  2 08:05:05 1995
  13462. @@ -321,7 +321,6 @@
  13463.      X(n_tty_ioctl),
  13464.      X(tty_register_ldisc),
  13465.      X(kill_fasync),
  13466. -    X(tty_hung_up_p),
  13467.  #endif
  13468.  #ifdef CONFIG_SCSI
  13469.      /* Supports loadable scsi drivers */
  13470. diff -u --recursive --new-file v1.2.7/linux/net/inet/datagram.c linux/net/inet/datagram.c
  13471. --- v1.2.7/linux/net/inet/datagram.c    Thu Mar  9 20:37:36 1995
  13472. +++ linux/net/inet/datagram.c    Tue May  2 18:58:07 1995
  13473. @@ -15,6 +15,7 @@
  13474.   *                    AX.25 now works right, and SPX is feasible.
  13475.   *        Alan Cox    :    Fixed write select of non IP protocol crash.
  13476.   *        Florian  La Roche:    Changed for my new skbuff handling.
  13477. + *        Darryl Miles    :    Fixed non-blocking SOCK_SEQPACKET.
  13478.   *
  13479.   *    Note:
  13480.   *        A lot of this will change when the protocol/socket separation
  13481. @@ -191,6 +192,11 @@
  13482.              return(0);
  13483.  
  13484.          case SEL_OUT:
  13485. +            if (sk->type==SOCK_SEQPACKET && sk->state==TCP_SYN_SENT)
  13486. +            {
  13487. +                /* Connection still in progress */
  13488. +                return(0);
  13489. +            }
  13490.              if (sk->prot && sk->prot->wspace(sk) >= MIN_WRITE_SPACE)
  13491.              {
  13492.                  return(1);
  13493. diff -u --recursive --new-file v1.2.7/linux/net/inet/tcp.c linux/net/inet/tcp.c
  13494. --- v1.2.7/linux/net/inet/tcp.c    Wed Mar 29 06:53:01 1995
  13495. +++ linux/net/inet/tcp.c    Tue May  2 18:57:03 1995
  13496. @@ -2854,7 +2854,7 @@
  13497.      buff = newsk->prot->wmalloc(newsk, MAX_SYN_SIZE, 1, GFP_ATOMIC);
  13498.      if (buff == NULL) 
  13499.      {
  13500. -        sk->err = -ENOMEM;
  13501. +        sk->err = ENOMEM;
  13502.          newsk->dead = 1;
  13503.          newsk->state = TCP_CLOSE;
  13504.          /* And this will destroy it */
  13505.