home *** CD-ROM | disk | FTP | other *** search
/ PC-Online 1996 May / PCOnline_05_1996.bin / linux / source / kernel-s / v1.3 / patch-1.001 / patch-1~
Text File  |  1995-09-03  |  92KB  |  3,000 lines

  1. diff -u --recursive --new-file v1.3.22/linux/Makefile linux/Makefile
  2. --- v1.3.22/linux/Makefile    Sun Sep  3 12:26:48 1995
  3. +++ linux/Makefile    Sun Sep  3 12:28:30 1995
  4. @@ -1,6 +1,6 @@
  5.  VERSION = 1
  6.  PATCHLEVEL = 3
  7. -SUBLEVEL = 22
  8. +SUBLEVEL = 23
  9.  
  10.  ARCH = i386
  11.  
  12. diff -u --recursive --new-file v1.3.22/linux/arch/i386/mm/fault.c linux/arch/i386/mm/fault.c
  13. --- v1.3.22/linux/arch/i386/mm/fault.c    Wed Aug  2 13:20:59 1995
  14. +++ linux/arch/i386/mm/fault.c    Sun Sep  3 13:26:40 1995
  15. @@ -49,6 +49,16 @@
  16.          goto bad_area;
  17.      if (vma->vm_end - address > current->rlim[RLIMIT_STACK].rlim_cur)
  18.          goto bad_area;
  19. +    if (error_code & 4) {
  20. +        /*
  21. +         * accessing the stack below %esp is always a bug.
  22. +         * The "+ 32" is there due to some instructions (like
  23. +         * pusha) doing pre-decrement on the stack and that
  24. +         * doesn't show up until later..
  25. +         */
  26. +        if (address + 32 < regs->esp)
  27. +            goto bad_area;
  28. +    }
  29.      vma->vm_offset -= vma->vm_start - (address & PAGE_MASK);
  30.      vma->vm_start = (address & PAGE_MASK);
  31.  /*
  32. diff -u --recursive --new-file v1.3.22/linux/drivers/block/README.ide linux/drivers/block/README.ide
  33. --- v1.3.22/linux/drivers/block/README.ide    Sun Sep  3 12:26:50 1995
  34. +++ linux/drivers/block/README.ide    Sun Sep  3 12:03:42 1995
  35. @@ -46,6 +46,9 @@
  36.  NEW!    - ide-cd.c now compiles separate from ide.c
  37.  NEW!    - Bus-Master DMA support for Intel PCI Triton chipset IDE interfaces
  38.  NEW!        - for details, see comments at top of triton.c
  39. +NEW!    - ide-cd.c now supports door locking and auto-loading.
  40. +NEW!            Also preliminary support for multisession and direct
  41. +NEW!            reads of audio data.
  42.  
  43.  For work in progress, see the comments in ide.c, ide-cd.c, and triton.c.
  44.  
  45. @@ -160,6 +163,31 @@
  46.      ln -sf /dev/hdc /dev/cdrom
  47.      mkdir /cd
  48.      mount /dev/cdrom /cd -t iso9660 -o ro
  49. +
  50. +If, after doing all of the above, mount doesn't work and you see
  51. +errors from the driver (with dmesg) complaining about `status=0xff',
  52. +this means that the hardware is not responding to the driver's attempts
  53. +to read it.  One of the following is probably the problem:
  54. +
  55. +  - Your hardware is broken.
  56. +
  57. +  - You are using the wrong address for the device, or you have the
  58. +    drive jumpered wrong.  Review the configuration instructions above.
  59. +
  60. +  - Your IDE controller requires some nonstandard initialization sequence
  61. +    before it will work properly.  If this is the case, there will often
  62. +    be a separate MS-DOS driver just for the controller.  IDE interfaces
  63. +    on sound cards usually fall into this category.  Such configurations
  64. +    can often be made to work by first booting MS-DOS, loading the
  65. +    appropriate drivers, and then warm-booting linux (without powering
  66. +    off).  This can be automated using loadlin in the MS-DOS autoexec.
  67. +
  68. +If you always get timeout errors, interrupts from the drive are probably
  69. +not making it to the host.  Check how you have the hardware jumpered
  70. +and make sure it matches what the driver expects (see the configuration
  71. +instructions above).  If you have a PCI system, also check the BIOS
  72. +setup; i've had one report of a system which was shipped with IRQ 15
  73. +disabled by the BIOS.
  74.  
  75.  The kernel is able to execute binaries directly off of the cdrom,
  76.  provided it is mounted with the default block size of 1024 (as above).
  77. diff -u --recursive --new-file v1.3.22/linux/drivers/block/genhd.c linux/drivers/block/genhd.c
  78. --- v1.3.22/linux/drivers/block/genhd.c    Sun Sep  3 12:26:50 1995
  79. +++ linux/drivers/block/genhd.c    Sun Sep  3 12:20:25 1995
  80. @@ -3,20 +3,17 @@
  81.   *  linux/kernel/hd.c
  82.   *
  83.   *  Copyright (C) 1991, 1992  Linus Torvalds
  84. - */
  85. -
  86. -/*
  87. + *
  88. + *
  89.   *  Thanks to Branko Lankester, lankeste@fwi.uva.nl, who found a bug
  90.   *  in the early extended-partition checks and added DM partitions
  91. - */
  92. -
  93. -/*
  94. + *
  95.   *  Support for DiskManager v6.0x added by Mark Lord (mlord@bnr.ca)
  96.   *  with information provided by OnTrack.  This now works for linux fdisk
  97.   *  and LILO, as well as loadlin and bootln.  Note that disks other than
  98.   *  /dev/hda *must* have a "DOS" type 0x51 partition in the first slot (hda1).
  99. - * 
  100. - *  Added support for "missing/deleted" extended partitions - mlord@bnr.ca
  101. + *
  102. + *  More flexible handling of extended partitions - aeb, 950831
  103.   */
  104.  
  105.  #include <linux/config.h>
  106. @@ -82,14 +79,15 @@
  107.  {
  108.      struct buffer_head *bh;
  109.      struct partition *p;
  110. -    unsigned long first_sector, this_sector;
  111. +    unsigned long first_sector, this_sector, this_size;
  112.      int mask = (1 << hd->minor_shift) - 1;
  113. +    int i;
  114.  
  115.      first_sector = hd->part[MINOR(dev)].start_sect;
  116.      this_sector = first_sector;
  117.  
  118.      while (1) {
  119. -        if ((current_minor & mask) >= (4 + hd->max_p))
  120. +        if ((current_minor & mask) >= hd->max_p)
  121.              return;
  122.          if (!(bh = bread(dev,0,1024)))
  123.              return;
  124. @@ -100,29 +98,56 @@
  125.          bh->b_dirt = 0;
  126.          bh->b_uptodate = 0;
  127.          bh->b_req = 0;
  128. +
  129.          if (*(unsigned short *) (bh->b_data+510) != 0xAA55)
  130.              goto done;
  131. +
  132.          p = (struct partition *) (0x1BE + bh->b_data);
  133. +
  134. +        this_size = hd->part[MINOR(dev)].nr_sects;
  135. +
  136.          /*
  137. -         * Process the first entry, which should be the real
  138. -         * data partition.
  139. +         * Usually, the first entry is the real data partition,
  140. +         * the 2nd entry is the next extended partition, or empty,
  141. +         * and the 3rd and 4th entries are unused.
  142. +         * However, DRDOS sometimes has the extended partition as
  143. +         * the first entry (when the data partition is empty),
  144. +         * and OS/2 seems to use all four entries.
  145.           */
  146. -        if (p->sys_ind == EXTENDED_PARTITION)
  147. -            goto done;    /* shouldn't happen */
  148. -        if (p->sys_ind && p->nr_sects)
  149. -            add_partition(hd, current_minor, this_sector+p->start_sect, p->nr_sects);
  150. -        current_minor++;
  151. -        p++;
  152. +
  153. +        /* 
  154. +         * First process the data partition(s)
  155. +         */
  156. +        for (i=0; i<4; i++, p++) {
  157. +            if (!p->nr_sects || p->sys_ind == EXTENDED_PARTITION)
  158. +              continue;
  159. +
  160. +            if (p->start_sect + p->nr_sects > this_size)
  161. +              continue;
  162. +
  163. +            add_partition(hd, current_minor, this_sector+p->start_sect, p->nr_sects);
  164. +            current_minor++;
  165. +            if ((current_minor & mask) >= hd->max_p)
  166. +              goto done;
  167. +        }
  168.          /*
  169. -         * Process the second entry, which should be a link
  170. -         * to the next logical partition.  Create a minor
  171. -         * for this just long enough to get the next partition
  172. -         * table.  The minor will be reused for the real
  173. +         * Next, process the (first) extended partition, if present.
  174. +         * (So far, there seems to be no reason to make
  175. +         *  extended_partition()  recursive and allow a tree
  176. +         *  of extended partitions.)
  177. +         * It should be a link to the next logical partition.
  178. +         * Create a minor for this just long enough to get the next
  179. +         * partition table.  The minor will be reused for the next
  180.           * data partition.
  181.           */
  182. -        if (p->sys_ind != EXTENDED_PARTITION ||
  183. -            !(hd->part[current_minor].nr_sects = p->nr_sects))
  184. -            goto done;  /* no more logicals in this partition */
  185. +        p -= 4;
  186. +        for (i=0; i<4; i++, p++)
  187. +          if(p->nr_sects && p->sys_ind == EXTENDED_PARTITION)
  188. +            break;
  189. +        if (i == 4)
  190. +          goto done;     /* nothing left to do */
  191. +
  192. +        hd->part[current_minor].nr_sects = p->nr_sects;
  193.          hd->part[current_minor].start_sect = first_sector + p->start_sect;
  194.          this_sector = first_sector + p->start_sect;
  195.          dev = ((hd->major) << 8) | current_minor;
  196. @@ -211,6 +236,9 @@
  197.              printk(" <");
  198.              extended_partition(hd, (hd->major << 8) | minor);
  199.              printk(" >");
  200. +            /* prevent someone doing mkfs or mkswap on
  201. +               an extended partition */
  202. +            hd->part[minor].nr_sects = 0;
  203.          }
  204.      }
  205.      /*
  206. diff -u --recursive --new-file v1.3.22/linux/drivers/block/ide-cd.c linux/drivers/block/ide-cd.c
  207. --- v1.3.22/linux/drivers/block/ide-cd.c    Mon Aug 28 14:52:18 1995
  208. +++ linux/drivers/block/ide-cd.c    Sun Sep  3 12:03:42 1995
  209. @@ -41,21 +41,35 @@
  210.   *                       PLAYAUDIO12 is broken on the Aztech; work around it.
  211.   * 2.05x Aug 11, 1995 -- lots of data structure renaming/restructuring in ide.c
  212.   *                       (my apologies to Scott, but now ide-cd.c is independent)
  213. + * 3.00  Aug 22, 1995 -- Implement CDROMMULTISESSION ioctl (UNTESTED).
  214. + *                       Implement CDROMREADAUDIO ioctl (UNTESTED).
  215. + *                       Use input_ide_data() and output_ide_data().
  216. + *                       Add door locking.
  217. + *                       Fix usage count leak in cdrom_open, which happened
  218. + *                        when a read-write mount was attempted.
  219. + *                       Try to load the disk on open.
  220. + *                       Implement CDROMEJECT_SW ioctl (off by default).
  221. + *                       Read total cdrom capacity during open.
  222. + *                       Rearrange logic in cdrom_decode_status.  Issue
  223. + *                        request sense commands for failed packet commands
  224. + *                        from here instead of from cdrom_queue_packet_command.
  225. + *                        Fix a race condition in retrieving error information.
  226. + *                       Suppress printing normal unit attention errors and
  227. + *                        some drive not ready errors.
  228. + *                       Implement CDROMVOLREAD ioctl.
  229. + *                       Implement CDROMREADMODE1/2 ioctls.
  230. + *                       Fix race condition in setting up interrupt handlers
  231. + *                        when the `serialize' option is used.
  232. + * 3.01  Sep  2, 1995 -- Fix ordering of reenabling interrupts in
  233. + *                        cdrom_queue_request.
  234. + *                       Another try at using ide_[input,output]_data.
  235.   *
  236. - * FIX ME!!  A day-one bug exists when the ide.c "serialize" option is used.
  237. - * For this to always work correctly, ide_set_handler() must be called
  238. - * *just before* the final trigger is given to the drive (to cause it to go
  239. - * off and get data and then interrupt us again).  Otherwise, we may get the
  240. - * interrupt before set_handler() has actually run, resulting in "unexpected_intr".
  241. - *
  242. - * This can only happen in scenarios where we handle a "final" interrupt
  243. - * for one IDE port on, say irq14, and then initiate a new request for the
  244. - * other port on, say irq15, from the irq14 interrupt handler.  If we are
  245. - * running with "unmask" on, or have done sti(), then Whammo -- we're exposed.
  246. - *
  247. - * Places where this needs fixing have been identified in the code with "BUG".
  248. - * -ml  August 11, 1995
  249. - *
  250. + * NOTE: I've tried to implement support for multisession CDs and
  251. + * direct audio reads in this version, but i haven't been able to fully
  252. + * test them due to a lack of the proper hardware.  I'd appreciate hearing
  253. + * if the multisession stuff works; i'd also be interested in hearing
  254. + * if you get anything other than a `Parameter not supported'
  255. + * (asc=0x26, ascq=1) error when trying to do a direct audio read.
  256.   *
  257.   * ATAPI cd-rom driver.  To be used with ide.c.
  258.   *
  259. @@ -80,6 +94,7 @@
  260.  #include <linux/hdreg.h>
  261.  #include <linux/cdrom.h>
  262.  #include <asm/irq.h>
  263. +#include <asm/io.h>
  264.  
  265.  #define _IDE_CD_C    /* used in blk.h */
  266.  #include "ide.h"
  267. @@ -98,17 +113,10 @@
  268.  
  269.  #define MIN(a,b) ((a) < (b) ? (a) : (b))
  270.  
  271. -#if 1    /* "old" method */
  272. -#define OUT_WORDS(b,n)  outsw (IDE_DATA_REG, (b), (n))
  273. -#define IN_WORDS(b,n)   insw  (IDE_DATA_REG, (b), (n))
  274. -#else    /* "new" method -- should really fix each instance instead of this */
  275. -#define OUT_WORDS(b,n)    output_ide_data(drive,b,(n)/2)
  276. -#define IN_WORDS(b,n)    input_ide_data(drive,b,(n)/2)
  277. -#endif
  278. -
  279.  /* special command codes for strategy routine. */
  280. -#define PACKET_COMMAND 4315
  281. +#define PACKET_COMMAND        4315
  282.  #define REQUEST_SENSE_COMMAND 4316
  283. +#define RESET_DRIVE_COMMAND   4317
  284.  
  285.  /* Some ATAPI command opcodes (just like SCSI).
  286.     (Some other cdrom-specific codes are in cdrom.h.) */
  287. @@ -116,9 +124,11 @@
  288.  #define REQUEST_SENSE           0x03
  289.  #define START_STOP              0x1b
  290.  #define ALLOW_MEDIUM_REMOVAL    0x1e
  291. +#define READ_CAPACITY        0x25
  292.  #define READ_10                 0x28
  293.  #define MODE_SENSE_10           0x5a
  294.  #define MODE_SELECT_10          0x55
  295. +#define READ_CD                 0xbe
  296.  
  297.  
  298.  /* ATAPI sense keys (mostly copied from scsi.h). */
  299. @@ -135,25 +145,72 @@
  300.  #define MISCOMPARE              0x0e
  301.  
  302.  /* We want some additional flags for cd-rom drives.
  303. -   To save space in the ide_drive_t struct, use one of the fields which
  304. -   doesn't make sense for cd-roms -- `bios_sect'. */
  305. +   To save space in the ide_drive_t struct, use some fields which
  306. +   doesn't make sense for cd-roms -- `bios_sect' and `bios_head'. */
  307.  
  308. -struct ide_cd_flags {
  309. +/* Configuration flags.  These describe the capabilities of the drive.
  310. +   They generally do not change after initialization, unless we learn
  311. +   more about the drive from stuff failing. */
  312. +struct ide_cd_config_flags {
  313.    unsigned drq_interrupt : 1; /* Device sends an interrupt when ready
  314.                                   for a packet command. */
  315.    unsigned no_playaudio12: 1; /* The PLAYAUDIO12 command is not supported. */
  316. -
  317. -  unsigned media_changed : 1; /* Driver has noticed a media change. */
  318. -  unsigned toc_valid     : 1; /* Saved TOC information is current. */
  319.    unsigned no_lba_toc    : 1; /* Drive cannot return TOC info in LBA format. */
  320.    unsigned msf_as_bcd    : 1; /* Drive uses BCD in PLAYAUDIO_MSF. */
  321. +  unsigned no_doorlock   : 1; /* Drive cannot lock the door. */
  322. +  unsigned old_readcd    : 1; /* Drive uses old READ CD opcode. */
  323.    unsigned reserved : 2;
  324.  };
  325. +#define CDROM_CONFIG_FLAGS(drive) ((struct ide_cd_config_flags *)&((drive)->bios_sect))
  326. +
  327. +/* State flags.  These give information about the current state of the
  328. +   drive, and will change during normal operation. */
  329. +struct ide_cd_state_flags {
  330. +  unsigned media_changed : 1; /* Driver has noticed a media change. */
  331. +  unsigned toc_valid     : 1; /* Saved TOC information is current. */
  332. +  unsigned door_locked   : 1; /* We think that the drive door is locked. */
  333. +  unsigned eject_on_close: 1; /* Drive should eject when device is closed. */
  334. +  unsigned reserved : 4;
  335. +};
  336. +#define CDROM_STATE_FLAGS(drive)  ((struct ide_cd_state_flags *)&((drive)->bios_head))
  337.  
  338. -#define CDROM_FLAGS(drive) ((struct ide_cd_flags *)&((drive)->bios_sect))
  339.  
  340.  #define SECTOR_BUFFER_SIZE CD_FRAMESIZE
  341.  
  342. +
  343. +
  344. +/****************************************************************************
  345. + * Routines to read and write data from/to the drive, using
  346. + * the routines input_ide_data() and output_ide_data() from ide.c.
  347. + *
  348. + * All transfer lengths should be multiples of 16-bit shorts.
  349. + */
  350. +
  351. +
  352. +static inline
  353. +void cdrom_in_bytes (ide_drive_t *drive, void *buffer, uint bytecount)
  354. +{
  355. +  ide_input_data (drive, buffer, bytecount / 4);
  356. +  if ((bytecount & 0x03 >= 2))
  357. +    {
  358. +      insw (IDE_DATA_REG, buffer + (bytecount & ~0x03), 1);
  359. +    }
  360. +}
  361. +
  362. +
  363. +static inline
  364. +void cdrom_out_bytes (ide_drive_t *drive, void *buffer, uint bytecount)
  365. +{
  366. +  ide_output_data (drive, buffer, bytecount / 4);
  367. +  if ((bytecount & 0x03 >= 2))
  368. +    {
  369. +      outsw (IDE_DATA_REG, buffer + (bytecount & ~0x03), 1);
  370. +    }
  371. +}
  372. +
  373. +
  374.  
  375.  /****************************************************************************
  376.   * Descriptions of ATAPI error codes.
  377. @@ -298,7 +355,7 @@
  378.  
  379.  
  380.  /****************************************************************************
  381. - * Generic packet command support routines.
  382. + * Generic packet command support and error handling routines.
  383.   */
  384.  
  385.  
  386. @@ -312,7 +369,7 @@
  387.       the drive, and we don't want to fill the syslog with useless errors. */
  388.    if (failed_command &&
  389.        failed_command->c[0] == SCMD_READ_SUBCHANNEL &&
  390. -      (reqbuf->sense_key == 2 || reqbuf->sense_key == 6))
  391. +      (reqbuf->sense_key == NOT_READY || reqbuf->sense_key == UNIT_ATTENTION))
  392.      return;
  393.  
  394.  #if VERBOSE_IDE_CD_ERRORS
  395. @@ -380,6 +437,15 @@
  396.    }
  397.  
  398.  #else
  399. +
  400. +  /* Suppress printing unit attention and `in progress of becoming ready'
  401. +     errors when we're not being verbose. */
  402. +
  403. +  if (reqbuf->sense_key == UNIT_ATTENTION ||
  404. +      (reqbuf->sense_key == NOT_READY && (reqbuf->asc == 4 ||
  405. +                      reqbuf->asc == 0x3a)))
  406. +    return;
  407. +
  408.    printk ("%s: code: %x  key: %x  asc: %x  ascq: %x\n",
  409.        drive->name,
  410.        reqbuf->error_code, reqbuf->sense_key, reqbuf->asc, reqbuf->ascq);
  411. @@ -402,12 +468,14 @@
  412.  }
  413.  
  414.  
  415. -static void cdrom_queue_request_sense (ide_drive_t *drive)
  416. +static void cdrom_queue_request_sense (ide_drive_t *drive, 
  417. +                       struct semaphore *sem,
  418. +                       struct atapi_request_sense *reqbuf)
  419.  {
  420.    struct request *rq;
  421.    struct packet_command *pc;
  422. -  struct atapi_request_sense *reqbuf;
  423.    unsigned long flags;
  424. +  int len;
  425.  
  426.    int major = HWIF(drive)->major;
  427.  
  428. @@ -427,16 +495,30 @@
  429.  
  430.    restore_flags (flags);
  431.  
  432. +  /* If the request didn't explicitly specify where to put the sense data,
  433. +     use the statically allocated structure. */
  434. +  if (reqbuf == NULL)
  435. +    reqbuf = &drive->cdrom_info.sense_data;
  436. +
  437.    /* Make up a new request to retrieve sense information. */
  438. -  reqbuf = &drive->cdrom_info.sense_data;
  439.  
  440.    pc = &HWIF(drive)->request_sense_pc;
  441.    memset (pc, 0, sizeof (*pc));
  442.  
  443. +  /* The request_sense structure has an odd number of (16-bit) words,
  444. +     which won't work well with 32-bit transfers.  However, we don't care
  445. +     about the last two bytes, so just truncate the structure down
  446. +     to an even length. */
  447. +  len = sizeof (*reqbuf) / 4;
  448. +  len *= 4;
  449. +
  450.    pc->c[0] = REQUEST_SENSE;
  451. -  pc->c[4] = sizeof (*reqbuf);
  452. +  pc->c[4] = len;
  453.    pc->buffer = (char *)reqbuf;
  454. -  pc->buflen = sizeof (*reqbuf);
  455. +  pc->buflen = len;
  456. +  pc->sense_data = reqbuf;    /* The only reason to set this here is so
  457. +                   that cdrom_end_request can find the correct
  458. +                   buffer for dumps to the syslog. */
  459.    
  460.    rq = &HWIF(drive)->request_sense_request;
  461.    rq->dev = MKDEV (major, (drive->select.b.unit) << PARTN_BITS);
  462. @@ -446,7 +528,7 @@
  463.    rq->nr_sectors = 0;
  464.    rq->current_nr_sectors = 0;
  465.    rq->buffer = (char *)pc;
  466. -  rq->sem = NULL;
  467. +  rq->sem = sem;
  468.    rq->bh = NULL;
  469.    rq->bhtail = NULL;
  470.    rq->next = NULL;
  471. @@ -477,9 +559,8 @@
  472.  
  473.    if (rq->cmd == REQUEST_SENSE_COMMAND && uptodate)
  474.      {
  475. -      struct atapi_request_sense *reqbuf;
  476. -      reqbuf = &drive->cdrom_info.sense_data;
  477. -      cdrom_analyze_sense_data (drive, reqbuf, NULL);
  478. +      struct packet_command *pc = (struct packet_command *)rq->buffer;
  479. +      cdrom_analyze_sense_data (drive, pc->sense_data, NULL);
  480.      }
  481.  
  482.    ide_end_request (uptodate, HWGROUP(drive));
  483. @@ -490,8 +571,8 @@
  484.     buffers. */
  485.  static void cdrom_saw_media_change (ide_drive_t *drive)
  486.  {
  487. -  CDROM_FLAGS (drive)->media_changed = 1;
  488. -  CDROM_FLAGS (drive)->toc_valid = 0;
  489. +  CDROM_STATE_FLAGS (drive)->media_changed = 1;
  490. +  CDROM_STATE_FLAGS (drive)->toc_valid = 0;
  491.    drive->cdrom_info.nsectors_buffered = 0;
  492.  }
  493.  
  494. @@ -520,97 +601,126 @@
  495.      {
  496.        cmd = rq->cmd;
  497.  
  498. -      /* Check for tray open */
  499. -      if (sense_key == NOT_READY)
  500. +      if (cmd == REQUEST_SENSE_COMMAND)
  501.      {
  502. -      struct packet_command *pc;
  503. -      cdrom_saw_media_change (drive);
  504. +      /* We got an error trying to get sense info from the drive
  505. +         (probably while trying to recover from a former error).
  506. +         Just give up. */
  507.  
  508. -      /* Fail the request if this is a read command. */
  509. -      if (cmd == READ)
  510. -        {
  511. -          printk ("%s : tray open\n", drive->name);
  512. -          cdrom_end_request (0, drive);
  513. -        }
  514. +      struct packet_command *pc = (struct packet_command *)rq->buffer;
  515. +      pc->stat = 1;
  516. +      cdrom_end_request (1, drive);
  517. +      if (ide_error (drive, "request sense failure", stat))
  518. +        return 1;
  519. +    }
  520.  
  521. -      else
  522. +      else if (cmd == PACKET_COMMAND)
  523. +    {
  524. +      /* All other functions, except for READ. */
  525. +
  526. +      struct packet_command *pc = (struct packet_command *)rq->buffer;
  527. +      struct semaphore *sem = NULL;
  528. +
  529. +      /* Check for tray open. */
  530. +      if (sense_key == NOT_READY)
  531.          {
  532. -          /* Otherwise, it's some other packet command.
  533. -         Print an error message to the syslog.
  534. +          cdrom_saw_media_change (drive);
  535. +
  536. +          /* Print an error message to the syslog.
  537.           Exception: don't print anything if this is a read subchannel
  538.           command.  This is because workman constantly polls the drive
  539.           with this command, and we don't want to uselessly fill up
  540.           the syslog. */
  541. -          pc = (struct packet_command *)rq->buffer;
  542.            if (pc->c[0] != SCMD_READ_SUBCHANNEL)
  543. -        printk ("%s : tray open\n", drive->name);
  544. -
  545. -          /* Set the error flag and complete the request. */
  546. -          pc->stat = 1;
  547. -          cdrom_end_request (1, drive);
  548. +        printk ("%s : tray open or drive not ready\n", drive->name);
  549.          }
  550. -    }
  551.  
  552. -      /* Check for media change. */
  553. -      else if (sense_key == UNIT_ATTENTION)
  554. -    {
  555. -      cdrom_saw_media_change (drive);
  556. -      printk ("%s: media changed\n", drive->name);
  557. -
  558. -      /* Return failure for a packet command, so that
  559. -         cdrom_queue_packet_command can do a request sense before
  560. -         the command gets retried. */
  561. +      /* Check for media change. */
  562. +      else if (sense_key == UNIT_ATTENTION)
  563. +        {
  564. +          cdrom_saw_media_change (drive);
  565. +          printk ("%s: media changed\n", drive->name);
  566. +        }
  567.  
  568. -      if (cmd == PACKET_COMMAND)
  569. +      /* Otherwise, print an error. */
  570. +      else
  571.          {
  572. -          struct packet_command *pc = (struct packet_command *)rq->buffer;
  573. -          pc->stat = 1;
  574. -          cdrom_end_request (1, drive);
  575. +          ide_dump_status (drive, "packet command error", stat);
  576.          }
  577.  
  578. -      /* Otherwise, it's a block read.  Arrange to retry it.
  579. -         But be sure to give up if we've retried too many times. */
  580. -      else if ((++rq->errors > ERROR_MAX))
  581. +      /* Set the error flag and complete the request.
  582. +         Then, if we have a CHECK CONDITION status, queue a request
  583. +         sense command.  We must be careful, though: we don't want
  584. +         the thread in cdrom_queue_packet_command to wake up until
  585. +         the request sense has completed.  We do this by transferring
  586. +         the semaphore from the packet command request to the
  587. +         request sense request. */
  588. +
  589. +      if ((stat & ERR_STAT) != 0)
  590.          {
  591. -          cdrom_end_request (0, drive);
  592. +          sem = rq->sem;
  593. +          rq->sem = NULL;
  594.          }
  595. -    }
  596.  
  597. -      /* Don't attempt to retry if this was a packet command. */
  598. -      else if (cmd == PACKET_COMMAND)
  599. -    {
  600. -      struct packet_command *pc = (struct packet_command *)rq->buffer;
  601. -      ide_dump_status (drive, "packet command error", stat);
  602. -      pc->stat = 1;  /* signal error */
  603. +      pc->stat = 1;
  604.        cdrom_end_request (1, drive);
  605. -    }
  606.  
  607. -      /* No point in retrying after an illegal request or data protect error.*/
  608. -      else if (sense_key == ILLEGAL_REQUEST || sense_key == DATA_PROTECT)
  609. -    {
  610. -      ide_dump_status (drive, "command error", stat);
  611. -      cdrom_end_request (0, drive);
  612. +      if ((stat & ERR_STAT) != 0)
  613. +        cdrom_queue_request_sense (drive, sem, pc->sense_data);
  614.      }
  615.  
  616. -      /* If there were other errors, go to the default handler. */
  617. -      else if ((err & ~ABRT_ERR) != 0)
  618. +      else
  619.      {
  620. -      if (ide_error (drive, "cdrom_decode_status", stat))
  621. -        return 1;
  622. -    }
  623. +      /* Handle errors from READ requests. */
  624.  
  625. -      /* Else, abort if we've racked up too many retries. */
  626. -      else if ((++rq->errors > ERROR_MAX))
  627. -    {
  628. -      cdrom_end_request (0, drive);
  629. -    }
  630. +      /* Check for tray open. */
  631. +      if (sense_key == NOT_READY)
  632. +        {
  633. +          cdrom_saw_media_change (drive);
  634.  
  635. -      /* If we got a CHECK_STATUS condition, and this was a READ request,
  636. -     queue a request sense command to try to find out more about
  637. -     what went wrong (and clear a unit attention)?  For packet commands,
  638. -     this is done separately in cdrom_queue_packet_command. */
  639. -      if ((stat & ERR_STAT) != 0 && cmd == READ)
  640. -    cdrom_queue_request_sense (drive);
  641. +          /* Fail the request. */
  642. +          printk ("%s : tray open\n", drive->name);
  643. +          cdrom_end_request (0, drive);
  644. +        }
  645. +
  646. +      /* Check for media change. */
  647. +      else if (sense_key == UNIT_ATTENTION)
  648. +        {
  649. +          cdrom_saw_media_change (drive);
  650. +
  651. +          /* Arrange to retry the request.
  652. +             But be sure to give up if we've retried too many times. */
  653. +          if (++rq->errors > ERROR_MAX)
  654. +        {
  655. +          cdrom_end_request (0, drive);
  656. +        }
  657. +        }
  658. +      /* No point in retrying after an illegal request or
  659. +         data protect error.*/
  660. +      else if (sense_key == ILLEGAL_REQUEST || sense_key == DATA_PROTECT)
  661. +        {
  662. +          ide_dump_status (drive, "command error", stat);
  663. +          cdrom_end_request (0, drive);
  664. +        }
  665. +
  666. +      /* If there were other errors, go to the default handler. */
  667. +      else if ((err & ~ABRT_ERR) != 0)
  668. +        {
  669. +          if (ide_error (drive, "cdrom_decode_status", stat))
  670. +        return 1;
  671. +        }
  672. +
  673. +      /* Else, abort if we've racked up too many retries. */
  674. +      else if ((++rq->errors > ERROR_MAX))
  675. +        {
  676. +          cdrom_end_request (0, drive);
  677. +        }
  678. +
  679. +      /* If we got a CHECK_CONDITION status, queue a request sense
  680. +         command. */
  681. +      if ((stat & ERR_STAT) != 0)
  682. +        cdrom_queue_request_sense (drive, NULL, NULL);
  683. +    }
  684.      }
  685.  
  686.    /* Retry, or handle the next request. */
  687. @@ -620,10 +730,14 @@
  688.  
  689.  
  690.  /* Set up the device registers for transferring a packet command on DEV,
  691. -   expecting to later transfer XFERLEN bytes.  This should be followed
  692. -   by a call to cdrom_transfer_packet_command; however, if this is a
  693. -   drq_interrupt device, one must wait for an interrupt first. */
  694. -static int cdrom_start_packet_command (ide_drive_t *drive, int xferlen)
  695. +   expecting to later transfer XFERLEN bytes.  HANDLER is the routine
  696. +   which actually transfers the command to the drive.  If this is a
  697. +   drq_interrupt device, this routine will arrange for HANDLER to be
  698. +   called when the interrupt from the drive arrives.  Otherwise, HANDLER
  699. +   will be called immediately after the drive is prepared for the transfer. */
  700. +
  701. +static int cdrom_start_packet_command (ide_drive_t *drive, int xferlen,
  702. +                       ide_handler_t *handler)
  703.  {
  704.    /* Wait for the controller to be idle. */
  705.    if (ide_wait_stat (drive, 0, BUSY_STAT, WAIT_READY)) return 1;
  706. @@ -636,19 +750,29 @@
  707.    OUT_BYTE (xferlen & 0xff, IDE_LCYL_REG);
  708.    OUT_BYTE (xferlen >> 8  , IDE_HCYL_REG);
  709.    OUT_BYTE (drive->ctl, IDE_CONTROL_REG);
  710. -  OUT_BYTE (WIN_PACKETCMD, IDE_COMMAND_REG); /* packet command */
  711. +
  712. +  if (CDROM_CONFIG_FLAGS (drive)->drq_interrupt)
  713. +    {
  714. +      ide_set_handler (drive, handler);
  715. +      OUT_BYTE (WIN_PACKETCMD, IDE_COMMAND_REG); /* packet command */
  716. +    }
  717. +  else
  718. +    {
  719. +      OUT_BYTE (WIN_PACKETCMD, IDE_COMMAND_REG); /* packet command */
  720. +      (*handler) (drive);
  721. +    }
  722.  
  723.    return 0;
  724.  }
  725.  
  726.  
  727. -/* Send a packet command to DEV described by CMD_BUF and CMD_LEN.
  728. +/* Send a packet command to DRIVE described by CMD_BUF and CMD_LEN.
  729.     The device registers must have already been prepared
  730.     by cdrom_start_packet_command. */
  731.  static int cdrom_transfer_packet_command (ide_drive_t *drive,
  732.                                            char *cmd_buf, int cmd_len)
  733.  {
  734. -  if (CDROM_FLAGS (drive)->drq_interrupt)
  735. +  if (CDROM_CONFIG_FLAGS (drive)->drq_interrupt)
  736.      {
  737.        /* Here we should have been called after receiving an interrupt
  738.           from the device.  DRQ should how be set. */
  739. @@ -664,7 +788,7 @@
  740.      }
  741.  
  742.    /* Send the command to the device. */
  743. -  OUT_WORDS (cmd_buf, cmd_len/2);
  744. +  cdrom_out_bytes (drive, cmd_buf, cmd_len);
  745.  
  746.    return 0;
  747.  }
  748. @@ -714,7 +838,7 @@
  749.    dest = info->sector_buffer + info->nsectors_buffered * SECTOR_SIZE;
  750.    while (sectors_to_buffer > 0)
  751.      {
  752. -      IN_WORDS (dest, SECTOR_SIZE / 2);
  753. +      cdrom_in_bytes (drive, dest, SECTOR_SIZE);
  754.        --sectors_to_buffer;
  755.        --sectors_to_transfer;
  756.        ++info->nsectors_buffered;
  757. @@ -725,7 +849,7 @@
  758.    while (sectors_to_transfer > 0)
  759.      {
  760.        char dum[SECTOR_SIZE];
  761. -      IN_WORDS (dum, sizeof (dum) / 2);
  762. +      cdrom_in_bytes (drive, dum, sizeof (dum));
  763.        --sectors_to_transfer;
  764.      }
  765.  }
  766. @@ -753,9 +877,9 @@
  767.           and quit this request. */
  768.        while (len > 0)
  769.          {
  770. -          short dum = 0;
  771. -          OUT_WORDS (&dum, 1);
  772. -          len -= 2;
  773. +          int dum = 0;
  774. +      cdrom_out_bytes (drive, &dum, sizeof (dum));
  775. +          len -= sizeof (dum);
  776.          }
  777.      }
  778.  
  779. @@ -833,7 +957,7 @@
  780.      {
  781.        /* We need to throw away a sector. */
  782.        char dum[SECTOR_SIZE];
  783. -      IN_WORDS (dum, sizeof (dum) / 2);
  784. +      cdrom_in_bytes (drive, dum, sizeof (dum));
  785.  
  786.        --rq->current_nr_sectors;
  787.        --nskip;
  788. @@ -869,7 +993,7 @@
  789.            /* Read this_transfer sectors into the current buffer. */
  790.            while (this_transfer > 0)
  791.              {
  792. -              IN_WORDS (rq->buffer, SECTOR_SIZE / 2);
  793. +              cdrom_in_bytes (drive, rq->buffer, SECTOR_SIZE);
  794.                rq->buffer += SECTOR_SIZE;
  795.                --rq->nr_sectors;
  796.                --rq->current_nr_sectors;
  797. @@ -882,7 +1006,7 @@
  798.  
  799.    /* Done moving data!
  800.       Wait for another interrupt. */
  801. -  ide_set_handler(drive, &cdrom_read_intr);    /* this one is okay */
  802. +  ide_set_handler (drive, &cdrom_read_intr);
  803.  }
  804.  
  805.  
  806. @@ -952,7 +1076,7 @@
  807.   * However, for drq_interrupt devices, it is called from an interrupt
  808.   * when the drive is ready to accept the command.
  809.   */
  810. -static int cdrom_start_read_continuation (ide_drive_t *drive)
  811. +static void cdrom_start_read_continuation (ide_drive_t *drive)
  812.  {
  813.    struct packet_command pc;
  814.    struct request *rq = HWGROUP(drive)->rq;
  815. @@ -981,7 +1105,7 @@
  816.                    drive->name, rq->current_nr_sectors);
  817.            cdrom_end_request (0, drive);
  818.            IDE_DO_REQUEST;
  819. -          return 1;
  820. +          return;
  821.          }
  822.  
  823.        sector -= nskip;
  824. @@ -1016,23 +1140,18 @@
  825.      pc.c[5] = conv.b.b0;
  826.    }
  827.  
  828. -  if (cdrom_transfer_packet_command (drive, pc.c, sizeof (pc.c)))
  829. -    return 1;
  830. +  /* Set up to receive the data-ready interrupt from the drive. */
  831. +  ide_set_handler (drive, &cdrom_read_intr);
  832.  
  833. -  /* Set up our interrupt handler and return. */
  834. -  ide_set_handler(drive, &cdrom_read_intr); /* BUG: do this BEFORE triggering drive */
  835. -
  836. -  return 0;
  837. +  /* Send the command to the drive and return. */
  838. +  (void) cdrom_transfer_packet_command (drive, pc.c, sizeof (pc.c));
  839.  }
  840.  
  841.  
  842.  /*
  843.   * Start a read request from the CD-ROM.
  844. - * Returns 0 if the request was started successfully,
  845. - *  1 if there was an error and we should either retry or move on to the
  846. - *  next request.
  847.   */
  848. -static int cdrom_start_read (ide_drive_t *drive, unsigned int block)
  849. +static void cdrom_start_read (ide_drive_t *drive, unsigned int block)
  850.  {
  851.    struct request *rq = HWGROUP(drive)->rq;
  852.  
  853. @@ -1042,23 +1161,13 @@
  854.  
  855.    /* Satisfy whatever we can of this request from our cached sector. */
  856.    if (cdrom_read_from_buffer (drive))
  857. -    return 1;
  858. +    return;
  859.  
  860.    /* Clear the local sector buffer. */
  861.    drive->cdrom_info.nsectors_buffered = 0;
  862.  
  863. -  if (cdrom_start_packet_command (drive, 32768))
  864. -    return 1;
  865. -
  866. -  if (CDROM_FLAGS (drive)->drq_interrupt)
  867. -    ide_set_handler(drive, (ide_handler_t *)&cdrom_start_read_continuation); /* BUG: do this BEFORE triggering drive */
  868. -  else
  869. -    {
  870. -      if (cdrom_start_read_continuation (drive))
  871. -        return 1;
  872. -    }
  873. -
  874. -  return 0;
  875. +  /* Start sending the read request to the drive. */
  876. +  cdrom_start_packet_command (drive, 32768, cdrom_start_read_continuation);
  877.  }
  878.  
  879.  
  880. @@ -1068,9 +1177,11 @@
  881.   * Execute all other packet commands.
  882.   */
  883.  
  884. -/* Forward declaration */
  885. +/* Forward declarations. */
  886.  static int
  887. -cdrom_request_sense (ide_drive_t *drive, struct atapi_request_sense *reqbuf);
  888. +cdrom_lockdoor (ide_drive_t *drive, int lockflag,
  889. +        struct atapi_request_sense *reqbuf);
  890. +
  891.  
  892.  
  893.  /* Interrupt routine for packet command completion. */
  894. @@ -1131,15 +1242,15 @@
  895.          }
  896.  
  897.        /* Transfer the data. */
  898. -      OUT_WORDS (pc->buffer, thislen / 2);
  899. +      cdrom_out_bytes (drive, pc->buffer, thislen);
  900.  
  901.        /* If we haven't moved enough data to satisfy the drive,
  902.           add some padding. */
  903.        while (len > thislen)
  904.          {
  905. -          short dum = 0;
  906. -          OUT_WORDS (&dum, 1);
  907. -          len -= 2;
  908. +          int dum = 0;
  909. +      cdrom_out_bytes (drive, &dum, sizeof (dum));
  910. +          len -= sizeof (dum);
  911.          }
  912.  
  913.        /* Keep count of how much data we've moved. */
  914. @@ -1160,15 +1271,15 @@
  915.          }
  916.  
  917.        /* Transfer the data. */
  918. -      IN_WORDS (pc->buffer, thislen / 2);
  919. +      cdrom_in_bytes (drive, pc->buffer, thislen);
  920.  
  921.        /* If we haven't moved enough data to satisfy the drive,
  922.           add some padding. */
  923.        while (len > thislen)
  924.          {
  925. -          short dum = 0;
  926. -          IN_WORDS (&dum, 1);
  927. -          len -= 2;
  928. +          int dum = 0;
  929. +      cdrom_in_bytes (drive, &dum, sizeof (dum));
  930. +          len -= sizeof (dum);
  931.          }
  932.  
  933.        /* Keep count of how much data we've moved. */
  934. @@ -1184,26 +1295,24 @@
  935.      }
  936.  
  937.    /* Now we wait for another interrupt. */
  938. -  ide_set_handler(drive, &cdrom_pc_intr);    /* this one is okay */
  939. +  ide_set_handler (drive, &cdrom_pc_intr);
  940.  }
  941.  
  942.  
  943. -static int cdrom_do_pc_continuation (ide_drive_t *drive)
  944. +static void cdrom_do_pc_continuation (ide_drive_t *drive)
  945.  {
  946.    struct request *rq = HWGROUP(drive)->rq;
  947.    struct packet_command *pc = (struct packet_command *)rq->buffer;
  948.  
  949. -  if (cdrom_transfer_packet_command (drive, pc->c, sizeof (pc->c)))
  950. -    return 1;
  951. +  /* Set up a handler for the data-ready interrupt. */
  952. +  ide_set_handler (drive, &cdrom_pc_intr);
  953.  
  954. -  /* Set up our interrupt handler and return. */
  955. -  ide_set_handler(drive, &cdrom_pc_intr); /* BUG: do this BEFORE triggering drive */
  956. -
  957. -  return 0;
  958. +  /* Send the command to the drive and return. */
  959. +  cdrom_transfer_packet_command (drive, pc->c, sizeof (pc->c));
  960.  }
  961.  
  962.  
  963. -static int cdrom_do_packet_command (ide_drive_t *drive)
  964. +static void cdrom_do_packet_command (ide_drive_t *drive)
  965.  {
  966.    int len;
  967.    struct request *rq = HWGROUP(drive)->rq;
  968. @@ -1214,42 +1323,34 @@
  969.  
  970.    pc->stat = 0;
  971.  
  972. -  if (cdrom_start_packet_command (drive, len))
  973. -    return 1;
  974. +  /* Start sending the command to the drive. */
  975. +  cdrom_start_packet_command (drive, len, cdrom_do_pc_continuation);
  976. +}
  977.  
  978. -  if (CDROM_FLAGS (drive)->drq_interrupt)
  979. -    ide_set_handler(drive, (ide_handler_t *)&cdrom_do_pc_continuation); /* BUG: do this BEFORE triggering drive */
  980. -  else
  981. -    {
  982. -      if (cdrom_do_pc_continuation (drive))
  983. -        return 1;
  984. -    }
  985.  
  986. -  return 0;
  987. +/* Sleep for TIME jiffies.
  988. +   Not to be called from an interrupt handler. */
  989. +static
  990. +void cdrom_sleep (int time)
  991. +{
  992. +  current->state = TASK_INTERRUPTIBLE;
  993. +  current->timeout = jiffies + time;
  994. +  schedule ();
  995.  }
  996.  
  997.  
  998.  static
  999. -int cdrom_queue_packet_command (ide_drive_t *drive, struct packet_command *pc)
  1000. +void cdrom_queue_request (ide_drive_t *drive, struct request *req)
  1001.  {
  1002. -  int retries = 3;
  1003.    unsigned long flags;
  1004. -  struct request req, **p, **pfirst;
  1005. -  struct semaphore sem = MUTEX_LOCKED;
  1006. +  struct request **p, **pfirst;
  1007.    int major = HWIF(drive)->major;
  1008. +  struct semaphore sem = MUTEX_LOCKED;
  1009.  
  1010. - retry:
  1011. -  req.dev = MKDEV (major, (drive->select.b.unit) << PARTN_BITS);
  1012. -  req.cmd = PACKET_COMMAND;
  1013. -  req.errors = 0;
  1014. -  req.sector = 0;
  1015. -  req.nr_sectors = 0;
  1016. -  req.current_nr_sectors = 0;
  1017. -  req.buffer = (char *)pc;
  1018. -  req.sem = &sem;
  1019. -  req.bh = NULL;
  1020. -  req.bhtail = NULL;
  1021. -  req.next = NULL;
  1022. +  req->dev = MKDEV (major, (drive->select.b.unit) << PARTN_BITS);
  1023. +  req->sem = &sem;
  1024. +  req->errors = 0;
  1025. +  req->next = NULL;
  1026.  
  1027.    save_flags (flags);
  1028.    cli ();
  1029. @@ -1260,42 +1361,88 @@
  1030.      {
  1031.        p = &((*p)->next);
  1032.      }
  1033. -  *p = &req;
  1034. +  *p = req;
  1035.    if (p == pfirst)
  1036.      blk_dev[major].request_fn ();
  1037.  
  1038. +  down (&sem);
  1039. +
  1040.    restore_flags (flags);
  1041. +}
  1042. +static
  1043. +int cdrom_queue_packet_command (ide_drive_t *drive, struct packet_command *pc)
  1044. +{
  1045. +  struct atapi_request_sense my_reqbuf;
  1046. +  int retries = 10;
  1047. +  struct request req;
  1048. +
  1049. +  /* If our caller has not provided a place to stick any sense data,
  1050. +     use our own area. */
  1051. +  if (pc->sense_data == NULL)
  1052. +    pc->sense_data = &my_reqbuf;
  1053. +  pc->sense_data->sense_key = 0;
  1054. +
  1055. +  /* Start of retry loop. */
  1056. +  do {
  1057. +    req.cmd = PACKET_COMMAND;
  1058. +    req.sector = 0;
  1059. +    req.nr_sectors = 0;
  1060. +    req.current_nr_sectors = 0;
  1061. +    req.buffer = (char *)pc;
  1062. +    req.bh = NULL;
  1063. +    req.bhtail = NULL;
  1064.  
  1065. -  down (&sem);
  1066. +    cdrom_queue_request (drive, &req);
  1067.  
  1068. -  if (pc->stat != 0)
  1069. -    {
  1070. -      /* The request failed.  Try to do a request sense to get more information
  1071. -     about the error; store the result in the cdrom_info struct
  1072. -     for this drive.  Check to be sure that it wasn't a request sense
  1073. -     request that failed, though, to prevent infinite loops. */
  1074. -      
  1075. -      struct atapi_request_sense *reqbuf = &drive->cdrom_info.sense_data;
  1076. +    if (pc->stat != 0)
  1077. +      {
  1078. +    /* The request failed.  Retry if it was due to a unit attention status
  1079. +       (usually means media was changed). */
  1080. +    struct atapi_request_sense *reqbuf = pc->sense_data;
  1081. +
  1082. +    if (reqbuf->sense_key == UNIT_ATTENTION)
  1083. +      ;
  1084. +
  1085. +    /* Also retry if the drive is in the process of loading a disk.
  1086. +       This time, however, wait a little between retries to give
  1087. +       the drive time. */
  1088. +    else if (reqbuf->sense_key == NOT_READY && reqbuf->asc == 4)
  1089. +      {
  1090. +        cdrom_sleep (HZ);
  1091. +      }
  1092. +
  1093. +    /* Otherwise, don't retry. */
  1094. +    else
  1095. +      retries = 0;
  1096. +
  1097. +    --retries;
  1098. +      }
  1099. +
  1100. +    /* End of retry loop. */
  1101. +  } while (pc->stat != 0 && retries >= 0);
  1102.  
  1103. -      if (pc->c[0] == REQUEST_SENSE || cdrom_request_sense (drive, reqbuf))
  1104. -    {
  1105. -      memset (reqbuf, 0, sizeof (*reqbuf));
  1106. -      reqbuf->asc = 0xff;
  1107. -    }
  1108. -      cdrom_analyze_sense_data (drive, reqbuf, pc);
  1109.  
  1110. -      /* If the error was a unit attention (usually means media was changed),
  1111. -     retry the command. */
  1112. -      if (reqbuf->sense_key == UNIT_ATTENTION && retries > 0)
  1113. +  /* Return an error if the command failed. */
  1114. +  if (pc->stat != 0)
  1115. +    return -EIO;
  1116. +
  1117. +  else
  1118. +    {
  1119. +      /* The command succeeded.  If it was anything other than a request sense,
  1120. +     eject, or door lock command, and we think that the door is presently
  1121. +     unlocked, lock it again.  (The door was probably unlocked via
  1122. +     an explicit CDROMEJECT ioctl.) */
  1123. +      if (CDROM_STATE_FLAGS (drive)->door_locked == 0 &&
  1124. +      (pc->c[0] != REQUEST_SENSE &&
  1125. +       pc->c[0] != ALLOW_MEDIUM_REMOVAL &&
  1126. +       pc->c[0] != START_STOP))
  1127.      {
  1128. -      --retries;
  1129. -      goto retry;
  1130. +      (void) cdrom_lockdoor (drive, 1, NULL);
  1131.      }
  1132. -
  1133. -      return -EIO;
  1134. +      return 0;
  1135.      }
  1136. -  else
  1137. -    return 0;
  1138.  }
  1139.  
  1140.  
  1141. @@ -1310,6 +1457,14 @@
  1142.  
  1143.    if (rq -> cmd == PACKET_COMMAND || rq -> cmd == REQUEST_SENSE_COMMAND)
  1144.      cdrom_do_packet_command (drive);
  1145. +
  1146. +  else if (rq -> cmd == RESET_DRIVE_COMMAND)
  1147. +    {
  1148. +      cdrom_end_request (1, drive);
  1149. +      if (ide_do_reset (drive))
  1150. +    return;
  1151. +    }
  1152. +
  1153.    else if (rq -> cmd != READ)
  1154.      {
  1155.        printk ("ide-cd: bad cmd %d\n", rq -> cmd);
  1156. @@ -1322,7 +1477,13 @@
  1157.  
  1158.  
  1159.  /****************************************************************************
  1160. - * ioctl handling.
  1161. + * Ioctl handling.
  1162. + *
  1163. + * Routines which queue packet commands take as a final argument a pointer
  1164. + * to an atapi_request_sense struct.  If execution of the command results
  1165. + * in an error with a CHECK CONDITION status, this structure will be filled
  1166. + * with the results of the subsequent request sense command.  The pointer
  1167. + * can also be NULL, in which case no sense information is returned.
  1168.   */
  1169.  
  1170.  static inline
  1171. @@ -1374,59 +1535,74 @@
  1172.  }
  1173.  
  1174.  
  1175. -static void
  1176. -cdrom_check_status (ide_drive_t  *drive)
  1177. -{
  1178. -  struct packet_command pc;
  1179. -
  1180. -  memset (&pc, 0, sizeof (pc));
  1181. -
  1182. -  pc.c[0] = TEST_UNIT_READY;
  1183. -
  1184. -  (void) cdrom_queue_packet_command (drive, &pc);
  1185. -}
  1186. -
  1187. -
  1188.  static int
  1189. -cdrom_request_sense (ide_drive_t *drive, struct atapi_request_sense *reqbuf)
  1190. +cdrom_check_status (ide_drive_t  *drive,
  1191. +            struct atapi_request_sense *reqbuf)
  1192.  {
  1193.    struct packet_command pc;
  1194.  
  1195.    memset (&pc, 0, sizeof (pc));
  1196.  
  1197. -  pc.c[0] = REQUEST_SENSE;
  1198. -  pc.c[4] = sizeof (*reqbuf);
  1199. -  pc.buffer = (char *)reqbuf;
  1200. -  pc.buflen = sizeof (*reqbuf);
  1201. +  pc.sense_data = reqbuf;
  1202. +  pc.c[0] = TEST_UNIT_READY;
  1203.  
  1204.    return cdrom_queue_packet_command (drive, &pc);
  1205.  }
  1206.  
  1207.  
  1208. -#if 0
  1209.  /* Lock the door if LOCKFLAG is nonzero; unlock it otherwise. */
  1210.  static int
  1211. -cdrom_lockdoor (ide_drive_t *drive, int lockflag)
  1212. +cdrom_lockdoor (ide_drive_t *drive, int lockflag,
  1213. +        struct atapi_request_sense *reqbuf)
  1214.  {
  1215. +  struct atapi_request_sense my_reqbuf;
  1216. +  int stat;
  1217.    struct packet_command pc;
  1218.  
  1219. -  memset (&pc, 0, sizeof (pc));
  1220. +  if (reqbuf == NULL)
  1221. +    reqbuf = &my_reqbuf;
  1222.  
  1223. -  pc.c[0] = ALLOW_MEDIUM_REMOVAL;
  1224. -  pc.c[4] = (lockflag != 0);
  1225. -  return cdrom_queue_packet_command (drive, &pc);
  1226. +  /* If the drive cannot lock the door, just pretend. */
  1227. +  if (CDROM_CONFIG_FLAGS (drive)->no_doorlock)
  1228. +    stat = 0;
  1229. +  else
  1230. +    {
  1231. +      memset (&pc, 0, sizeof (pc));
  1232. +      pc.sense_data = reqbuf;
  1233. +
  1234. +      pc.c[0] = ALLOW_MEDIUM_REMOVAL;
  1235. +      pc.c[4] = (lockflag != 0);
  1236. +      stat = cdrom_queue_packet_command (drive, &pc);
  1237. +    }
  1238. +
  1239. +  if (stat == 0)
  1240. +    CDROM_STATE_FLAGS (drive)->door_locked = lockflag;
  1241. +  else
  1242. +    {
  1243. +      /* If we got an illegal field error, the drive
  1244. +     probably cannot lock the door. */
  1245. +      if (reqbuf->sense_key == ILLEGAL_REQUEST && reqbuf->asc == 0x24)
  1246. +    {
  1247. +      printk ("%s: door locking not supported\n", drive->name);
  1248. +      CDROM_CONFIG_FLAGS (drive)->no_doorlock = 1;
  1249. +      stat = 0;
  1250. +      CDROM_STATE_FLAGS (drive)->door_locked = lockflag;
  1251. +    }
  1252. +    }
  1253. +  return stat;
  1254.  }
  1255. -#endif
  1256.  
  1257.  
  1258.  /* Eject the disk if EJECTFLAG is 0.
  1259.     If EJECTFLAG is 1, try to reload the disk. */
  1260.  static int
  1261. -cdrom_eject (ide_drive_t *drive, int ejectflag)
  1262. +cdrom_eject (ide_drive_t *drive, int ejectflag,
  1263. +         struct atapi_request_sense *reqbuf)
  1264.  {
  1265.    struct packet_command pc;
  1266.  
  1267.    memset (&pc, 0, sizeof (pc));
  1268. +  pc.sense_data = reqbuf;
  1269.  
  1270.    pc.c[0] = START_STOP;
  1271.    pc.c[4] = 2 + (ejectflag != 0);
  1272. @@ -1435,11 +1611,13 @@
  1273.  
  1274.  
  1275.  static int
  1276. -cdrom_pause (ide_drive_t *drive, int pauseflag)
  1277. +cdrom_pause (ide_drive_t *drive, int pauseflag,
  1278. +         struct atapi_request_sense *reqbuf)
  1279.  {
  1280.    struct packet_command pc;
  1281.  
  1282.    memset (&pc, 0, sizeof (pc));
  1283. +  pc.sense_data = reqbuf;
  1284.  
  1285.    pc.c[0] = SCMD_PAUSE_RESUME;
  1286.    pc.c[8] = !pauseflag;
  1287. @@ -1448,11 +1626,13 @@
  1288.  
  1289.  
  1290.  static int
  1291. -cdrom_startstop (ide_drive_t *drive, int startflag)
  1292. +cdrom_startstop (ide_drive_t *drive, int startflag,
  1293. +         struct atapi_request_sense *reqbuf)
  1294.  {
  1295.    struct packet_command pc;
  1296.  
  1297.    memset (&pc, 0, sizeof (pc));
  1298. +  pc.sense_data = reqbuf;
  1299.  
  1300.    pc.c[0] = START_STOP;
  1301.    pc.c[1] = 1;
  1302. @@ -1462,12 +1642,44 @@
  1303.  
  1304.  
  1305.  static int
  1306. +cdrom_read_capacity (ide_drive_t *drive, unsigned *capacity,
  1307. +             struct atapi_request_sense *reqbuf)
  1308. +{
  1309. +  struct {
  1310. +    unsigned lba;
  1311. +    unsigned blocklen;
  1312. +  } capbuf;
  1313. +
  1314. +  int stat;
  1315. +  struct packet_command pc;
  1316. +
  1317. +  memset (&pc, 0, sizeof (pc));
  1318. +  pc.sense_data = reqbuf;
  1319. +
  1320. +  pc.c[0] = READ_CAPACITY;
  1321. +  pc.buffer = (char *)&capbuf;
  1322. +  pc.buflen = sizeof (capbuf);
  1323. +
  1324. +  stat = cdrom_queue_packet_command (drive, &pc);
  1325. +  if (stat == 0)
  1326. +    {
  1327. +      byte_swap_long (&capbuf.lba);
  1328. +      *capacity = capbuf.lba;
  1329. +    }
  1330. +
  1331. +  return stat;
  1332. +}
  1333. +
  1334. +
  1335. +static int
  1336.  cdrom_read_tocentry (ide_drive_t *drive, int trackno, int msf_flag,
  1337. -                     char *buf, int buflen)
  1338. +                     int format, char *buf, int buflen,
  1339. +             struct atapi_request_sense *reqbuf)
  1340.  {
  1341.    struct packet_command pc;
  1342.  
  1343.    memset (&pc, 0, sizeof (pc));
  1344. +  pc.sense_data = reqbuf;
  1345.  
  1346.    pc.buffer =  buf;
  1347.    pc.buflen = buflen;
  1348. @@ -1475,6 +1687,7 @@
  1349.    pc.c[6] = trackno;
  1350.    pc.c[7] = (buflen >> 8);
  1351.    pc.c[8] = (buflen & 0xff);
  1352. +  pc.c[9] = (format << 6);
  1353.    if (msf_flag) pc.c[1] = 2;
  1354.    return cdrom_queue_packet_command (drive, &pc);
  1355.  }
  1356. @@ -1482,11 +1695,16 @@
  1357.  
  1358.  /* Try to read the entire TOC for the disk into our internal buffer. */
  1359.  static int
  1360. -cdrom_read_toc (ide_drive_t *drive)
  1361. +cdrom_read_toc (ide_drive_t *drive,
  1362. +        struct atapi_request_sense *reqbuf)
  1363.  {
  1364.    int msf_flag;
  1365.    int stat, ntracks, i;
  1366.    struct atapi_toc *toc = drive->cdrom_info.toc;
  1367. +  struct {
  1368. +    struct atapi_toc_header hdr;
  1369. +    struct atapi_toc_entry  ent;
  1370. +  } ms_tmp;
  1371.  
  1372.    if (toc == NULL)
  1373.      {
  1374. @@ -1504,18 +1722,19 @@
  1375.  
  1376.    /* Check to see if the existing data is still valid.
  1377.       If it is, just return. */
  1378. -  if (CDROM_FLAGS (drive)->toc_valid)
  1379. -    cdrom_check_status (drive);
  1380. +  if (CDROM_STATE_FLAGS (drive)->toc_valid)
  1381. +    (void) cdrom_check_status (drive, NULL);
  1382.  
  1383. -  if (CDROM_FLAGS (drive)->toc_valid) return 0;
  1384. +  if (CDROM_STATE_FLAGS (drive)->toc_valid) return 0;
  1385.  
  1386.    /* Some drives can't return TOC data in LBA format. */
  1387. -  msf_flag = (CDROM_FLAGS (drive)->no_lba_toc);
  1388. +  msf_flag = (CDROM_CONFIG_FLAGS (drive)->no_lba_toc);
  1389.  
  1390.    /* First read just the header, so we know how long the TOC is. */
  1391. -  stat = cdrom_read_tocentry (drive, 0, msf_flag, (char *)toc,
  1392. +  stat = cdrom_read_tocentry (drive, 0, msf_flag, 0, (char *)&toc->hdr,
  1393.                                sizeof (struct atapi_toc_header) +
  1394. -                              sizeof (struct atapi_toc_entry));
  1395. +                              sizeof (struct atapi_toc_entry),
  1396. +                  reqbuf);
  1397.    if (stat) return stat;
  1398.  
  1399.    ntracks = toc->hdr.last_track - toc->hdr.first_track + 1;
  1400. @@ -1523,9 +1742,10 @@
  1401.    if (ntracks > MAX_TRACKS) ntracks = MAX_TRACKS;
  1402.  
  1403.    /* Now read the whole schmeer. */
  1404. -  stat = cdrom_read_tocentry (drive, 0, msf_flag, (char *)toc,
  1405. +  stat = cdrom_read_tocentry (drive, 0, msf_flag, 0, (char *)&toc->hdr,
  1406.                                sizeof (struct atapi_toc_header) +
  1407. -                              (ntracks+1) * sizeof (struct atapi_toc_entry));
  1408. +                              (ntracks+1) * sizeof (struct atapi_toc_entry),
  1409. +                  reqbuf);
  1410.    if (stat) return stat;
  1411.    byte_swap_word (&toc->hdr.toc_length);
  1412.    for (i=0; i<=ntracks; i++)
  1413. @@ -1539,8 +1759,32 @@
  1414.      byte_swap_long (&toc->ent[i].lba);
  1415.      }
  1416.  
  1417. +  /* Read the multisession information. */
  1418. +  stat = cdrom_read_tocentry (drive, 0, msf_flag, 1,
  1419. +                  (char *)&ms_tmp, sizeof (ms_tmp),
  1420. +                  reqbuf);
  1421. +  if (stat) return stat;
  1422. +  if (msf_flag)
  1423. +    {
  1424. +      byte *adr = (byte *)&(ms_tmp.ent.lba);
  1425. +      toc->last_session_lba = msf_to_lba (adr[1], adr[2], adr[3]);
  1426. +    }
  1427. +  else
  1428. +    {
  1429. +      byte_swap_long (&ms_tmp.ent.lba);
  1430. +      toc->last_session_lba = ms_tmp.ent.lba;
  1431. +    }
  1432. +  toc->xa_flag = (ms_tmp.hdr.first_track != ms_tmp.hdr.last_track);
  1433. +
  1434. +  /* Now try to get the total cdrom capacity. */
  1435. +  stat = cdrom_read_capacity (drive, &toc->capacity, reqbuf);
  1436. +  if (stat) toc->capacity = 0x1fffff;
  1437. +
  1438. +  HWIF(drive)->gd->sizes[drive->select.b.unit << PARTN_BITS]
  1439. +    = toc->capacity * SECTORS_PER_FRAME;
  1440. +
  1441.    /* Remember that we've read this stuff. */
  1442. -  CDROM_FLAGS (drive)->toc_valid = 1;
  1443. +  CDROM_STATE_FLAGS (drive)->toc_valid = 1;
  1444.  
  1445.    return 0;
  1446.  }
  1447. @@ -1548,11 +1792,13 @@
  1448.  
  1449.  static int
  1450.  cdrom_read_subchannel (ide_drive_t *drive,
  1451. -                       char *buf, int buflen)
  1452. +                       char *buf, int buflen,
  1453. +               struct atapi_request_sense *reqbuf)
  1454.  {
  1455.    struct packet_command pc;
  1456.  
  1457.    memset (&pc, 0, sizeof (pc));
  1458. +  pc.sense_data = reqbuf;
  1459.  
  1460.    pc.buffer =  buf;
  1461.    pc.buflen = buflen;
  1462. @@ -1568,11 +1814,13 @@
  1463.  /* modeflag: 0 = current, 1 = changeable mask, 2 = default, 3 = saved */
  1464.  static int
  1465.  cdrom_mode_sense (ide_drive_t *drive, int pageno, int modeflag,
  1466. -                  char *buf, int buflen)
  1467. +                  char *buf, int buflen,
  1468. +          struct atapi_request_sense *reqbuf)
  1469.  {
  1470.    struct packet_command pc;
  1471.  
  1472.    memset (&pc, 0, sizeof (pc));
  1473. +  pc.sense_data = reqbuf;
  1474.  
  1475.    pc.buffer =  buf;
  1476.    pc.buflen = buflen;
  1477. @@ -1585,11 +1833,13 @@
  1478.  
  1479.  
  1480.  static int
  1481. -cdrom_mode_select (ide_drive_t *drive, int pageno, char *buf, int buflen)
  1482. +cdrom_mode_select (ide_drive_t *drive, int pageno, char *buf, int buflen,
  1483. +           struct atapi_request_sense *reqbuf)
  1484.  {
  1485.    struct packet_command pc;
  1486.  
  1487.    memset (&pc, 0, sizeof (pc));
  1488. +  pc.sense_data = reqbuf;
  1489.  
  1490.    pc.buffer =  buf;
  1491.    pc.buflen = - buflen;
  1492. @@ -1603,11 +1853,13 @@
  1493.  
  1494.  
  1495.  static int
  1496. -cdrom_play_lba_range_play12 (ide_drive_t *drive, int lba_start, int lba_end)
  1497. +cdrom_play_lba_range_play12 (ide_drive_t *drive, int lba_start, int lba_end,
  1498. +                 struct atapi_request_sense *reqbuf)
  1499.  {
  1500.    struct packet_command pc;
  1501.  
  1502.    memset (&pc, 0, sizeof (pc));
  1503. +  pc.sense_data = reqbuf;
  1504.  
  1505.    pc.c[0] = SCMD_PLAYAUDIO12;
  1506.    *(int *)(&pc.c[2]) = lba_start;
  1507. @@ -1620,17 +1872,19 @@
  1508.  
  1509.  
  1510.  static int
  1511. -cdrom_play_lba_range_msf (ide_drive_t *drive, int lba_start, int lba_end)
  1512. +cdrom_play_lba_range_msf (ide_drive_t *drive, int lba_start, int lba_end,
  1513. +              struct atapi_request_sense *reqbuf)
  1514.  {
  1515.    struct packet_command pc;
  1516.  
  1517.    memset (&pc, 0, sizeof (pc));
  1518. +  pc.sense_data = reqbuf;
  1519.  
  1520.    pc.c[0] = SCMD_PLAYAUDIO_MSF;
  1521.    lba_to_msf (lba_start, &pc.c[3], &pc.c[4], &pc.c[5]);
  1522.    lba_to_msf (lba_end-1, &pc.c[6], &pc.c[7], &pc.c[8]);
  1523.  
  1524. -  if (CDROM_FLAGS (drive)->msf_as_bcd)
  1525. +  if (CDROM_CONFIG_FLAGS (drive)->msf_as_bcd)
  1526.      {
  1527.        pc.c[3] = bin2bcd (pc.c[3]);
  1528.        pc.c[4] = bin2bcd (pc.c[4]);
  1529. @@ -1647,7 +1901,8 @@
  1530.  /* Play audio starting at LBA LBA_START and finishing with the
  1531.     LBA before LBA_END. */
  1532.  static int
  1533. -cdrom_play_lba_range (ide_drive_t *drive, int lba_start, int lba_end)
  1534. +cdrom_play_lba_range (ide_drive_t *drive, int lba_start, int lba_end,
  1535. +              struct atapi_request_sense *reqbuf)
  1536.  {
  1537.    /* This is rather annoying.
  1538.       My NEC-260 won't recognize group 5 commands such as PLAYAUDIO12;
  1539. @@ -1660,27 +1915,29 @@
  1540.       great.  Otherwise, if the drive reports an illegal command code,
  1541.       try PLAYAUDIO_MSF using the NEC 260-style bcd parameters. */
  1542.  
  1543. -  if (CDROM_FLAGS (drive)->no_playaudio12)
  1544. -    return cdrom_play_lba_range_msf (drive, lba_start, lba_end);
  1545. +  if (CDROM_CONFIG_FLAGS (drive)->no_playaudio12)
  1546. +    return cdrom_play_lba_range_msf (drive, lba_start, lba_end, reqbuf);
  1547.    else
  1548.      {
  1549.        int stat;
  1550. -      struct atapi_request_sense *reqbuf;
  1551. +      struct atapi_request_sense my_reqbuf;
  1552.  
  1553. -      stat = cdrom_play_lba_range_play12 (drive, lba_start, lba_end);
  1554. +      if (reqbuf == NULL)
  1555. +    reqbuf = &my_reqbuf;
  1556. +
  1557. +      stat = cdrom_play_lba_range_play12 (drive, lba_start, lba_end, reqbuf);
  1558.        if (stat == 0) return 0;
  1559.  
  1560.        /* It failed.  Try to find out why. */
  1561. -      reqbuf = &drive->cdrom_info.sense_data;
  1562. -      if (reqbuf->sense_key == 0x05 && reqbuf->asc == 0x20)
  1563. +      if (reqbuf->sense_key == ILLEGAL_REQUEST && reqbuf->asc == 0x20)
  1564.          {
  1565.            /* The drive didn't recognize the command.
  1566.               Retry with the MSF variant. */
  1567.            printk ("%s: Drive does not support PLAYAUDIO12; "
  1568.                    "trying PLAYAUDIO_MSF\n", drive->name);
  1569. -          CDROM_FLAGS (drive)->no_playaudio12 = 1;
  1570. -          CDROM_FLAGS (drive)->msf_as_bcd = 1;
  1571. -          return cdrom_play_lba_range_msf (drive, lba_start, lba_end);
  1572. +          CDROM_CONFIG_FLAGS (drive)->no_playaudio12 = 1;
  1573. +          CDROM_CONFIG_FLAGS (drive)->msf_as_bcd = 1;
  1574. +          return cdrom_play_lba_range_msf (drive, lba_start, lba_end, reqbuf);
  1575.          }
  1576.  
  1577.        /* Failed for some other reason.  Give up. */
  1578. @@ -1691,13 +1948,14 @@
  1579.  
  1580.  static
  1581.  int cdrom_get_toc_entry (ide_drive_t *drive, int track,
  1582. -                         struct atapi_toc_entry **ent)
  1583. +                         struct atapi_toc_entry **ent,
  1584. +             struct atapi_request_sense *reqbuf)
  1585.  {
  1586.    int stat, ntracks;
  1587.    struct atapi_toc *toc;
  1588.  
  1589.    /* Make sure our saved TOC is valid. */
  1590. -  stat = cdrom_read_toc (drive);
  1591. +  stat = cdrom_read_toc (drive, reqbuf);
  1592.    if (stat) return stat;
  1593.  
  1594.    toc = drive->cdrom_info.toc;
  1595. @@ -1716,25 +1974,94 @@
  1596.  }
  1597.  
  1598.  
  1599. +static int
  1600. +cdrom_read_block (ide_drive_t *drive, int format, int lba,
  1601. +          char *buf, int buflen,
  1602. +          struct atapi_request_sense *reqbuf)
  1603. +{
  1604. +  struct packet_command pc;
  1605. +  struct atapi_request_sense my_reqbuf;
  1606. +  int stat;
  1607. +
  1608. +  if (reqbuf == NULL)
  1609. +    reqbuf = &my_reqbuf;
  1610. +
  1611. +  memset (&pc, 0, sizeof (pc));
  1612. +  pc.sense_data = reqbuf;
  1613. +
  1614. +  pc.buffer = buf;
  1615. +  pc.buflen = buflen;
  1616. +
  1617. +  if (CDROM_CONFIG_FLAGS (drive)->old_readcd)
  1618. +    pc.c[0] = 0xd4;
  1619. +  else
  1620. +    pc.c[0] = READ_CD;
  1621. +
  1622. +  pc.c[1] = (format << 2);
  1623. +  *(int *)(&pc.c[2]) = lba;
  1624. +  byte_swap_long ((int *)(&pc.c[2]));
  1625. +  pc.c[8] = 1;  /* one block */
  1626. +  pc.c[9] = 0x10;
  1627. +
  1628. +  stat = cdrom_queue_packet_command (drive, &pc);
  1629. +
  1630. +  /* If the drive doesn't recognize the READ CD opcode, retry the command
  1631. +     with an older opcode for that command. */
  1632. +  if (stat && reqbuf->sense_key == ILLEGAL_REQUEST && reqbuf->asc == 0x20 &&
  1633. +      CDROM_CONFIG_FLAGS (drive)->old_readcd == 0)
  1634. +    {
  1635. +      printk ("%s: Drive does not recognize READ_CD; trying opcode 0xd4\n",
  1636. +          drive->name);
  1637. +      CDROM_CONFIG_FLAGS (drive)->old_readcd = 1;
  1638. +      return cdrom_read_block (drive, format, lba, buf, buflen, reqbuf);
  1639. +    }
  1640. +
  1641. +  return stat;
  1642. +}
  1643. +
  1644. +
  1645.  int ide_cdrom_ioctl (ide_drive_t *drive, struct inode *inode,
  1646. -                        struct file *file, unsigned int cmd, unsigned long arg)
  1647. +             struct file *file, unsigned int cmd, unsigned long arg)
  1648.  {
  1649.    switch (cmd)
  1650.      {
  1651.      case CDROMEJECT:
  1652. -      return cdrom_eject (drive, 0);
  1653. +      {
  1654. +    int stat;
  1655. +
  1656. +    if (drive->usage > 1)
  1657. +      return -EBUSY;
  1658. +
  1659. +    stat = cdrom_lockdoor (drive, 0, NULL);
  1660. +    if (stat) return stat;
  1661. +
  1662. +    return cdrom_eject (drive, 0, NULL);
  1663. +      }
  1664. +
  1665. +    case CDROMEJECT_SW:
  1666. +      {
  1667. +    CDROM_STATE_FLAGS (drive)->eject_on_close = arg;
  1668. +    return 0;
  1669. +      }
  1670.  
  1671.      case CDROMPAUSE:
  1672. -      return cdrom_pause (drive, 1);
  1673. +      return cdrom_pause (drive, 1, NULL);
  1674.  
  1675.      case CDROMRESUME:
  1676. -      return cdrom_pause (drive, 0);
  1677. +      return cdrom_pause (drive, 0, NULL);
  1678.  
  1679.      case CDROMSTART:
  1680. -      return cdrom_startstop (drive, 1);
  1681. +      return cdrom_startstop (drive, 1, NULL);
  1682.  
  1683.      case CDROMSTOP:
  1684. -      return cdrom_startstop (drive, 0);
  1685. +      {
  1686. +    int stat;
  1687. +
  1688. +    stat = cdrom_startstop (drive, 0, NULL);
  1689. +    if (stat) return stat;
  1690. +    /* pit says the Dolphin needs this. */
  1691. +    return cdrom_eject (drive, 1, NULL);
  1692. +      }
  1693.  
  1694.      case CDROMPLAYMSF:
  1695.        {
  1696. @@ -1753,7 +2080,7 @@
  1697.  
  1698.          if (lba_end <= lba_start) return -EINVAL;
  1699.  
  1700. -        return cdrom_play_lba_range (drive, lba_start, lba_end);
  1701. +        return cdrom_play_lba_range (drive, lba_start, lba_end, NULL);
  1702.        }
  1703.  
  1704.      /* Like just about every other Linux cdrom driver, we ignore the
  1705. @@ -1769,9 +2096,9 @@
  1706.  
  1707.          memcpy_fromfs (&ti, (void *) arg, sizeof(ti));
  1708.  
  1709. -        stat = cdrom_get_toc_entry (drive, ti.cdti_trk0, &first_toc);
  1710. +        stat = cdrom_get_toc_entry (drive, ti.cdti_trk0, &first_toc, NULL);
  1711.          if (stat) return stat;
  1712. -        stat = cdrom_get_toc_entry (drive, ti.cdti_trk1, &last_toc);
  1713. +        stat = cdrom_get_toc_entry (drive, ti.cdti_trk1, &last_toc, NULL);
  1714.          if (stat) return stat;
  1715.  
  1716.          if (ti.cdti_trk1 != CDROM_LEADOUT) ++last_toc;
  1717. @@ -1780,7 +2107,7 @@
  1718.  
  1719.          if (lba_end <= lba_start) return -EINVAL;
  1720.  
  1721. -        return cdrom_play_lba_range (drive, lba_start, lba_end);
  1722. +        return cdrom_play_lba_range (drive, lba_start, lba_end, NULL);
  1723.        }
  1724.  
  1725.      case CDROMREADTOCHDR:
  1726. @@ -1793,7 +2120,7 @@
  1727.          if (stat) return stat;
  1728.  
  1729.          /* Make sure our saved TOC is valid. */
  1730. -        stat = cdrom_read_toc (drive);
  1731. +        stat = cdrom_read_toc (drive, NULL);
  1732.          if (stat) return stat;
  1733.  
  1734.          toc = drive->cdrom_info.toc;
  1735. @@ -1818,7 +2145,7 @@
  1736.  
  1737.          memcpy_fromfs (&tocentry, (void *) arg, sizeof (tocentry));
  1738.  
  1739. -        stat = cdrom_get_toc_entry (drive, tocentry.cdte_track, &toce);
  1740. +        stat = cdrom_get_toc_entry (drive, tocentry.cdte_track, &toce, NULL);
  1741.          if (stat) return stat;
  1742.  
  1743.          tocentry.cdte_ctrl = toce->control;
  1744. @@ -1853,7 +2180,7 @@
  1745.  
  1746.          memcpy_fromfs (&subchnl, (void *) arg, sizeof (subchnl));
  1747.  
  1748. -        stat = cdrom_read_subchannel (drive, buffer, sizeof (buffer));
  1749. +        stat = cdrom_read_subchannel (drive, buffer, sizeof (buffer), NULL);
  1750.          if (stat) return stat;
  1751.  
  1752.          abs_lba = *(int *)&buffer[8];
  1753. @@ -1898,9 +2225,9 @@
  1754.          if (stat) return stat;
  1755.          memcpy_fromfs (&volctrl, (void *) arg, sizeof (volctrl));
  1756.  
  1757. -        stat = cdrom_mode_sense (drive, 0x0e, 0, buffer, sizeof (buffer));
  1758. +        stat = cdrom_mode_sense (drive, 0x0e, 0, buffer, sizeof (buffer),NULL);
  1759.          if (stat) return stat;
  1760. -        stat = cdrom_mode_sense (drive, 0x0e, 1, mask  , sizeof (buffer));
  1761. +        stat = cdrom_mode_sense (drive, 0x0e, 1, mask  , sizeof (buffer),NULL);
  1762.          if (stat) return stat;
  1763.  
  1764.          buffer[1] = buffer[2] = 0;
  1765. @@ -1910,35 +2237,219 @@
  1766.          buffer[21] = volctrl.channel2 & mask[21];
  1767.          buffer[23] = volctrl.channel3 & mask[23];
  1768.  
  1769. -        return cdrom_mode_select (drive, 0x0e, buffer, sizeof (buffer));
  1770. +        return cdrom_mode_select (drive, 0x0e, buffer, sizeof (buffer), NULL);
  1771. +      }
  1772. +
  1773. +    case CDROMVOLREAD:
  1774. +      {
  1775. +        struct cdrom_volctrl volctrl;
  1776. +        char buffer[24];
  1777. +        int stat;
  1778. +
  1779. +        stat = verify_area (VERIFY_WRITE, (void *) arg, sizeof (volctrl));
  1780. +        if (stat) return stat;
  1781. +
  1782. +        stat = cdrom_mode_sense (drive, 0x0e, 0, buffer, sizeof (buffer), NULL);
  1783. +        if (stat) return stat;
  1784. +
  1785. +        volctrl.channel0 = buffer[17];
  1786. +        volctrl.channel1 = buffer[19];
  1787. +        volctrl.channel2 = buffer[21];
  1788. +        volctrl.channel3 = buffer[23];
  1789. +
  1790. +        memcpy_tofs ((void *) arg, &volctrl, sizeof (volctrl));
  1791. +
  1792. +    return 0;
  1793. +      }
  1794. +
  1795. +    case CDROMMULTISESSION:
  1796. +      {
  1797. +    struct cdrom_multisession ms_info;
  1798. +    struct atapi_toc *toc;
  1799. +    int stat;
  1800. +
  1801. +    stat = verify_area (VERIFY_READ,  (void *)arg, sizeof (ms_info));
  1802. +        if (stat) return stat;
  1803. +    stat = verify_area (VERIFY_WRITE, (void *)arg, sizeof (ms_info));
  1804. +        if (stat) return stat;
  1805. +
  1806. +    memcpy_fromfs (&ms_info, (void *)arg, sizeof (ms_info));
  1807. +
  1808. +    /* Make sure the TOC information is valid. */
  1809. +    stat = cdrom_read_toc (drive, NULL);
  1810. +    if (stat) return stat;
  1811. +
  1812. +    toc = drive->cdrom_info.toc;
  1813. +
  1814. +    if (ms_info.addr_format == CDROM_MSF)
  1815. +      lba_to_msf (toc->last_session_lba,
  1816. +              &ms_info.addr.msf.minute,
  1817. +              &ms_info.addr.msf.second,
  1818. +              &ms_info.addr.msf.frame);
  1819. +
  1820. +    else if (ms_info.addr_format == CDROM_LBA)
  1821. +      ms_info.addr.lba = toc->last_session_lba;
  1822. +
  1823. +    else
  1824. +      return -EINVAL;
  1825. +
  1826. +    ms_info.xa_flag = toc->xa_flag;
  1827. +
  1828. +    memcpy_tofs ((void *)arg, &ms_info, sizeof (ms_info));
  1829. +
  1830. +    return 0;
  1831. +      }
  1832. +
  1833. +    /* Read 2352 byte blocks from audio tracks. */
  1834. +    case CDROMREADAUDIO:
  1835. +      {
  1836. +    int stat, lba;
  1837. +    struct atapi_toc *toc;
  1838. +    struct cdrom_read_audio ra;
  1839. +    char buf[CD_FRAMESIZE_RAW];
  1840. +
  1841. +    /* Make sure the TOC is up to date. */
  1842. +    stat = cdrom_read_toc (drive, NULL);
  1843. +    if (stat) return stat;
  1844. +
  1845. +    toc = drive->cdrom_info.toc;
  1846. +
  1847. +    stat = verify_area (VERIFY_READ, (char *)arg, sizeof (ra));
  1848. +    if (stat) return stat;
  1849. +
  1850. +    memcpy_fromfs (&ra, (void *)arg, sizeof (ra));
  1851. +
  1852. +    if (ra.nframes < 0 || ra.nframes > toc->capacity)
  1853. +      return -EINVAL;
  1854. +    else if (ra.nframes == 0)
  1855. +      return 0;
  1856. +
  1857. +    stat = verify_area (VERIFY_WRITE, (char *)ra.buf,
  1858. +                              ra.nframes * CD_FRAMESIZE_RAW);
  1859. +    if (stat) return stat;
  1860. +
  1861. +    if (ra.addr_format == CDROM_MSF)
  1862. +      lba = msf_to_lba (ra.addr.msf.minute, ra.addr.msf.second,
  1863. +                ra.addr.msf.frame);
  1864. +    
  1865. +    else if (ra.addr_format == CDROM_LBA)
  1866. +      lba = ra.addr.lba;
  1867. +
  1868. +    else
  1869. +      return -EINVAL;
  1870. +
  1871. +    if (lba < 0 || lba >= toc->capacity)
  1872. +      return -EINVAL;
  1873. +
  1874. +    while (ra.nframes > 0)
  1875. +      {
  1876. +        stat = cdrom_read_block (drive, 1, lba, buf,
  1877. +                     CD_FRAMESIZE_RAW, NULL);
  1878. +        if (stat) return stat;
  1879. +        memcpy_tofs (ra.buf, buf, CD_FRAMESIZE_RAW);
  1880. +        ra.buf += CD_FRAMESIZE_RAW;
  1881. +        --ra.nframes;
  1882. +        ++lba;
  1883. +      }
  1884. +
  1885. +    return 0;
  1886. +      }
  1887. +
  1888. +    case CDROMREADMODE1:
  1889. +    case CDROMREADMODE2:
  1890. +      {
  1891. +    struct cdrom_msf msf;
  1892. +    int blocksize, format, stat, lba;
  1893. +    struct atapi_toc *toc;
  1894. +    char buf[CD_FRAMESIZE_RAW0];
  1895. +
  1896. +    if (cmd == CDROMREADMODE1)
  1897. +      {
  1898. +        blocksize = CD_FRAMESIZE;
  1899. +        format = 2;
  1900. +      }
  1901. +    else
  1902. +      {
  1903. +        blocksize = CD_FRAMESIZE_RAW0;
  1904. +        format = 3;
  1905. +      }
  1906. +
  1907. +    stat = verify_area (VERIFY_READ, (char *)arg, sizeof (msf));
  1908. +    if (stat) return stat;
  1909. +    stat = verify_area (VERIFY_WRITE, (char *)arg, blocksize);
  1910. +    if (stat) return stat;
  1911. +
  1912. +    memcpy_fromfs (&msf, (void *)arg, sizeof (msf));
  1913. +
  1914. +    lba = msf_to_lba (msf.cdmsf_min0, msf.cdmsf_sec0, msf.cdmsf_frame0);
  1915. +    
  1916. +    /* Make sure the TOC is up to date. */
  1917. +    stat = cdrom_read_toc (drive, NULL);
  1918. +    if (stat) return stat;
  1919. +
  1920. +    toc = drive->cdrom_info.toc;
  1921. +
  1922. +    if (lba < 0 || lba >= toc->capacity)
  1923. +      return -EINVAL;
  1924. +
  1925. +    stat = cdrom_read_block (drive, format, lba, buf, blocksize, NULL);
  1926. +    if (stat) return stat;
  1927. +
  1928. +    memcpy_tofs ((char *)arg, buf, blocksize);
  1929. +    return 0;
  1930.        }
  1931.  
  1932. +#if 0 /* Doesn't work reliably yet. */
  1933. +    case CDROMRESET:
  1934. +      {
  1935. +    struct request req;
  1936. +    memset (&req, 0, sizeof (req));
  1937. +    req.cmd = RESET_DRIVE_COMMAND;
  1938. +    cdrom_queue_request (drive, &req);
  1939. +    return 0;
  1940. +      }
  1941. +#endif
  1942. +
  1943.  #ifdef TEST
  1944.      case 0x1234:
  1945.        {
  1946.          int stat;
  1947.          struct packet_command pc;
  1948. +    int len, lena;
  1949.  
  1950.          memset (&pc, 0, sizeof (pc));
  1951.  
  1952.          stat = verify_area (VERIFY_READ, (void *) arg, sizeof (pc.c));
  1953.          if (stat) return stat;
  1954.          memcpy_fromfs (&pc.c, (void *) arg, sizeof (pc.c));
  1955. +    arg += sizeof (pc.c);
  1956.  
  1957. -        return cdrom_queue_packet_command (drive, &pc);
  1958. -      }
  1959. +    stat = verify_area (VERIFY_READ, (void *) arg, sizeof (len));
  1960. +        if (stat) return stat;
  1961. +        memcpy_fromfs (&len, (void *) arg , sizeof (len));
  1962. +    arg += sizeof (len);
  1963.  
  1964. -    case 0x1235:
  1965. -      {
  1966. -        int stat;
  1967. -        struct atapi_request_sense reqbuf;
  1968. +    if (len > 0) {
  1969. +      stat = verify_area (VERIFY_WRITE, (void *) arg, len);
  1970. +      if (stat) return stat;
  1971. +    }
  1972.  
  1973. -        stat = verify_area (VERIFY_WRITE, (void *) arg, sizeof (reqbuf));
  1974. -        if (stat) return stat;
  1975. +    lena = len;
  1976. +    if (lena  < 0) lena = 0;
  1977.  
  1978. -        stat = cdrom_request_sense (drive, &reqbuf);
  1979. +    {
  1980. +      char buf[lena];
  1981. +      if (len > 0) {
  1982. +        pc.buflen = len;
  1983. +        pc.buffer = buf;
  1984. +      }
  1985.  
  1986. -        memcpy_tofs ((void *) arg, &reqbuf, sizeof (reqbuf));
  1987. +      stat = cdrom_queue_packet_command (drive, &pc);
  1988. +
  1989. +      if (len > 0)
  1990. +        memcpy_tofs ((void *)arg, buf, len);
  1991. +    }
  1992.  
  1993.          return stat;
  1994.        }
  1995. @@ -1960,10 +2471,10 @@
  1996.  {
  1997.    int retval;
  1998.  
  1999. -  cdrom_check_status (drive);
  2000. +  (void) cdrom_check_status (drive, NULL);
  2001.  
  2002. -  retval = CDROM_FLAGS (drive)->media_changed;
  2003. -  CDROM_FLAGS (drive)->media_changed = 0;
  2004. +  retval = CDROM_STATE_FLAGS (drive)->media_changed;
  2005. +  CDROM_STATE_FLAGS (drive)->media_changed = 0;
  2006.  
  2007.    return retval;
  2008.  }
  2009. @@ -1972,15 +2483,43 @@
  2010.  int ide_cdrom_open (struct inode *ip, struct file *fp, ide_drive_t *drive)
  2011.  {
  2012.    /* no write access */
  2013. -  if (fp->f_mode & 2) return -EROFS;
  2014. +  if (fp->f_mode & 2)
  2015. +    {
  2016. +      --drive->usage;
  2017. +      return -EROFS;
  2018. +    }
  2019.  
  2020. -#if 0 /* With this, one cannot eject a disk with workman */
  2021. -  /* If this is the first open, lock the door. */
  2022. +  /* If this is the first open, check the drive status. */
  2023.    if (drive->usage == 1)
  2024. -    (void) cdrom_lockdoor (drive, 1);
  2025. -#endif
  2026. +    {
  2027. +      int stat;
  2028. +      struct atapi_request_sense my_reqbuf;
  2029. +      my_reqbuf.sense_key = 0;
  2030. +
  2031. +      /* Get the drive status. */
  2032. +      stat = cdrom_check_status (drive, &my_reqbuf);
  2033. +
  2034. +      /* If the tray is open, try to close it. */
  2035. +      if (stat && my_reqbuf.sense_key == NOT_READY)
  2036. +    {
  2037. +      cdrom_eject (drive, 1, &my_reqbuf);
  2038. +      stat = cdrom_check_status (drive, &my_reqbuf);
  2039. +    }
  2040. +
  2041. +      /* Return an error if there are still problems. */
  2042. +      if (stat && my_reqbuf.sense_key != UNIT_ATTENTION)
  2043. +    {
  2044. +      --drive->usage;
  2045. +      return -ENXIO;
  2046. +    }
  2047. +
  2048. +      /* Now lock the door. */
  2049. +      (void) cdrom_lockdoor (drive, 1, &my_reqbuf);
  2050. +
  2051. +      /* And try to read the TOC information now. */
  2052. +      (void) cdrom_read_toc (drive, &my_reqbuf);
  2053. +    }
  2054.  
  2055. -  /* Should check that there's a disk in the drive? */
  2056.    return 0;
  2057.  }
  2058.  
  2059. @@ -1995,10 +2534,12 @@
  2060.      {
  2061.        invalidate_buffers (inode->i_rdev);
  2062.  
  2063. -#if 0
  2064.        /* Unlock the door. */
  2065. -      (void) cdrom_lockdoor (drive, 0);
  2066. -#endif
  2067. +      (void) cdrom_lockdoor (drive, 0, NULL);
  2068. +
  2069. +      /* Do an eject if we were requested to do so. */
  2070. +      if (CDROM_STATE_FLAGS (drive)->eject_on_close)
  2071. +    (void) cdrom_eject (drive, 0, NULL);
  2072.      }
  2073.  }
  2074.  
  2075. @@ -2015,28 +2556,35 @@
  2076.    drive->special.all = 0;
  2077.    drive->ready_stat = 0;
  2078.  
  2079. -  CDROM_FLAGS (drive)->media_changed = 0;
  2080. -  CDROM_FLAGS (drive)->toc_valid     = 0;
  2081. -
  2082. -  CDROM_FLAGS (drive)->no_playaudio12 = 0;
  2083. -  CDROM_FLAGS (drive)->no_lba_toc = 0;
  2084. -  CDROM_FLAGS (drive)->msf_as_bcd = 0;
  2085. -  CDROM_FLAGS (drive)->drq_interrupt = ((drive->id->config & 0x0060) == 0x20);
  2086. +  CDROM_STATE_FLAGS (drive)->media_changed = 0;
  2087. +  CDROM_STATE_FLAGS (drive)->toc_valid     = 0;
  2088. +  CDROM_STATE_FLAGS (drive)->door_locked   = 0;
  2089. +
  2090. +  /* Turn this off by default, since many people don't like it. */
  2091. +  CDROM_STATE_FLAGS (drive)->eject_on_close= 0;
  2092. +
  2093. +  CDROM_CONFIG_FLAGS (drive)->no_doorlock = 0;
  2094. +  CDROM_CONFIG_FLAGS (drive)->no_playaudio12 = 0;
  2095. +  CDROM_CONFIG_FLAGS (drive)->old_readcd = 0;
  2096. +  CDROM_CONFIG_FLAGS (drive)->no_lba_toc = 0;
  2097. +  CDROM_CONFIG_FLAGS (drive)->msf_as_bcd = 0;
  2098. +  CDROM_CONFIG_FLAGS (drive)->drq_interrupt =
  2099. +    ((drive->id->config & 0x0060) == 0x20);
  2100.  
  2101.    /* Accommodate some broken drives... */
  2102.    if (strcmp (drive->id->model, "CD220E") == 0)  /* Creative Labs */
  2103. -    CDROM_FLAGS (drive)->no_lba_toc = 1;
  2104. +    CDROM_CONFIG_FLAGS (drive)->no_lba_toc = 1;
  2105.  
  2106.    else if (strcmp (drive->id->model, "TO-ICSLYAL") == 0 ||  /* Acer CD525E */
  2107.             strcmp (drive->id->model, "OTI-SCYLLA") == 0)
  2108. -    CDROM_FLAGS (drive)->no_lba_toc = 1;
  2109. +    CDROM_CONFIG_FLAGS (drive)->no_lba_toc = 1;
  2110.  
  2111.    else if (strcmp (drive->id->model, "CDA26803I SE") == 0) /* Aztech */
  2112.      {
  2113. -      CDROM_FLAGS (drive)->no_lba_toc = 1;
  2114. +      CDROM_CONFIG_FLAGS (drive)->no_lba_toc = 1;
  2115.  
  2116.        /* This drive _also_ does not implement PLAYAUDIO12 correctly. */
  2117. -      CDROM_FLAGS (drive)->no_playaudio12 = 1;
  2118. +      CDROM_CONFIG_FLAGS (drive)->no_playaudio12 = 1;
  2119.      }
  2120.  
  2121.    drive->cdrom_info.toc               = NULL;
  2122. @@ -2046,19 +2594,14 @@
  2123.  }
  2124.  
  2125.  
  2126. -#undef MIN
  2127. -#undef SECTOR_SIZE
  2128. -#undef SECTOR_BITS
  2129. -
  2130.  
  2131.  /*
  2132.   * TODO:
  2133. - *  Read actual disk capacity.
  2134. - *  Multisession support.
  2135. - *  Direct reading of audio data.
  2136. - *  Eject-on-dismount.
  2137. - *  Lock door while there's a mounted volume.
  2138. + *  CDROM_GET_UPC
  2139. + *  CDROMRESET
  2140. + *  Lock the door when a read request completes successfully and the
  2141. + *   door is not already locked.  Also try to reorganize to reduce
  2142. + *   duplicated functionality between read and ioctl paths?
  2143.   *  Establish interfaces for an IDE port driver, and break out the cdrom
  2144.   *   code into a loadable module.
  2145.   */
  2146. -
  2147. diff -u --recursive --new-file v1.3.22/linux/drivers/block/ide.c linux/drivers/block/ide.c
  2148. --- v1.3.22/linux/drivers/block/ide.c    Sun Sep  3 12:26:51 1995
  2149. +++ linux/drivers/block/ide.c    Sun Sep  3 12:03:00 1995
  2150. @@ -1,5 +1,5 @@
  2151.  /*
  2152. - *  linux/drivers/block/ide.c    Version 5.11  Aug 29, 1995
  2153. + *  linux/drivers/block/ide.c    Version 5.12  Sep 1, 1995
  2154.   *
  2155.   *  Copyright (C) 1994, 1995  Linus Torvalds & authors (see below)
  2156.   */
  2157. @@ -130,15 +130,24 @@
  2158.   *            added automatic PCI CMD640 detection/support
  2159.   *            added option for VLB CMD640 support
  2160.   *            tweaked probe to find cdrom on hdb with disks on hda,hdc
  2161. + *  Version 5.12    some performance tuning
  2162. + *            added message to alert user to bad /dev/hd[cd] entries
  2163. + *            OOOPS!  fixed bug in atapi reset
  2164. + *            driver now forces "serialize" again for all cmd640 chips
  2165. + *            noticed REALLY_SLOW_IO had no effect, moved it to ide.c
  2166. + *            made do_drive_cmd() into public ide_do_drive_cmd()
  2167.   *
  2168.   *  Driver compile-time options are in ide.h
  2169.   *
  2170.   *  To do, in likely order of completion:
  2171. - *    - improved CMD support:  probably handing this off to someone else
  2172. + *    - add ioctls to get/set interface timings on cmd640, ht6560b, triton
  2173.   *    - modify kernel to obtain BIOS geometry for drives on 2nd/3rd/4th i/f
  2174. + *    - improved CMD support:  probably handing this off to someone else
  2175.   *    - find someone to work on IDE *tape drive* support
  2176.   */
  2177.  
  2178. +#undef REALLY_SLOW_IO        /* most systems can safely undef this */
  2179. +
  2180.  #include <linux/config.h>
  2181.  #include <linux/types.h>
  2182.  #include <linux/string.h>
  2183. @@ -156,6 +165,7 @@
  2184.  #include <asm/byteorder.h>
  2185.  #include <asm/irq.h>
  2186.  #include <asm/segment.h>
  2187. +#include <asm/io.h>
  2188.  
  2189.  #ifdef CONFIG_PCI
  2190.  #include <linux/bios32.h>
  2191. @@ -239,7 +249,7 @@
  2192.          /* fill in any non-zero initial values */
  2193.          hwif->noprobe    = (h > 1);
  2194.          hwif->io_base    = default_io_base[h];
  2195. -        hwif->ctl_port    = hwif->io_base ? hwif->io_base + 0x206 : 0x000;
  2196. +        hwif->ctl_port    = hwif->io_base ? hwif->io_base+0x206 : 0x000;
  2197.  #ifdef CONFIG_BLK_DEV_HD
  2198.          if (hwif->io_base == HD_DATA)
  2199.              hwif->noprobe = 1; /* may be overriden by ide_setup() */
  2200. @@ -268,7 +278,6 @@
  2201.      }
  2202.  }
  2203.  
  2204. -#ifdef __i386__
  2205.  #define VLB_SYNC 1
  2206.  /*
  2207.   * Some localbus EIDE interfaces require a special access sequence
  2208. @@ -278,34 +287,32 @@
  2209.   * to ensure that the reads all happen together.
  2210.   */
  2211.  static inline void do_vlb_sync (unsigned short port) {
  2212. -    unsigned int _v;
  2213. -    __asm__ __volatile__    (
  2214. -        "inb %w1,%b0\n\t"
  2215. -        "inb %w1,%b0\n\t"
  2216. -        "inb %w1,%b0"
  2217. -        : "=&a" (_v)        /* outputs */
  2218. -        : "d" (port)    );    /* inputs */
  2219. +    (void) inb (port);
  2220. +    (void) inb (port);
  2221. +    (void) inb (port);
  2222.  }
  2223. -#endif    /* __i386__ */
  2224.  
  2225.  /*
  2226.   * This is used for most PIO data transfers *from* the IDE interface
  2227.   */
  2228.  void ide_input_data (ide_drive_t *drive, void *buffer, unsigned int wcount)
  2229.  {
  2230. +    unsigned short io_base  = HWIF(drive)->io_base;
  2231. +    unsigned short data_reg = io_base+IDE_DATA_OFFSET;
  2232. +
  2233.      if (drive->vlb_32bit) {
  2234.  #ifdef VLB_SYNC
  2235.          if (drive->vlb_sync) {
  2236.              cli();
  2237. -            do_vlb_sync(IDE_NSECTOR_REG);
  2238. -            insl(IDE_DATA_REG, buffer, wcount);
  2239. +            do_vlb_sync(io_base+IDE_NSECTOR_OFFSET);
  2240. +            insl(data_reg, buffer, wcount);
  2241.              if (drive->unmask)
  2242.                  sti();
  2243.          } else
  2244.  #endif /* VLB_SYNC */
  2245. -            insl(IDE_DATA_REG, buffer, wcount);
  2246. +            insl(data_reg, buffer, wcount);
  2247.      } else
  2248. -        insw(IDE_DATA_REG, buffer, wcount<<1);
  2249. +        insw(data_reg, buffer, wcount<<1);
  2250.  }
  2251.  
  2252.  /*
  2253. @@ -313,19 +320,22 @@
  2254.   */
  2255.  void ide_output_data (ide_drive_t *drive, void *buffer, unsigned int wcount)
  2256.  {
  2257. +    unsigned short io_base  = HWIF(drive)->io_base;
  2258. +    unsigned short data_reg = io_base+IDE_DATA_OFFSET;
  2259. +
  2260.      if (drive->vlb_32bit) {
  2261.  #ifdef VLB_SYNC
  2262.          if (drive->vlb_sync) {
  2263.              cli();
  2264. -            do_vlb_sync(IDE_NSECTOR_REG);
  2265. -            outsl(IDE_DATA_REG, buffer, wcount);
  2266. +            do_vlb_sync(io_base+IDE_NSECTOR_OFFSET);
  2267. +            outsl(data_reg, buffer, wcount);
  2268.              if (drive->unmask)
  2269.                  sti();
  2270.          } else
  2271.  #endif /* VLB_SYNC */
  2272. -            outsl(IDE_DATA_REG, buffer, wcount);
  2273. +            outsl(data_reg, buffer, wcount);
  2274.      } else
  2275. -        outsw(IDE_DATA_REG, buffer, wcount<<1);
  2276. +        outsw(data_reg, buffer, wcount<<1);
  2277.  }
  2278.  
  2279.  #if SUPPORT_HT6560B
  2280. @@ -677,8 +687,8 @@
  2281.              if (!drive->keep_settings)
  2282.                  drive->unmask = 0;
  2283.              OUT_BYTE (drive->select.all, IDE_SELECT_REG);
  2284. +            udelay (20);
  2285.              OUT_BYTE (WIN_SRST, IDE_COMMAND_REG);
  2286. -            udelay (10);
  2287.              hwgroup->reset_timeout = jiffies + WAIT_WORSTCASE;
  2288.              start_reset_timer (hwif); /* begin periodic polling */
  2289.              restore_flags (flags);
  2290. @@ -851,12 +861,10 @@
  2291.      err = ide_dump_status(drive, msg, stat);
  2292.      if ((rq = HWGROUP(drive)->rq) == NULL || drive == NULL)
  2293.          return 0;
  2294. -#ifdef IDE_DRIVE_CMD
  2295.      if (rq->cmd == IDE_DRIVE_CMD) {    /* never retry an explicit DRIVE_CMD */
  2296.          end_drive_cmd(drive, stat, err);
  2297.          return 0;
  2298.      }
  2299. -#endif    /* IDE_DRIVE_CMD */
  2300.      if (stat & BUSY_STAT) {        /* other bits are useless when BUSY */
  2301.          rq->errors |= ERROR_RESET;
  2302.      } else {
  2303. @@ -1105,7 +1113,6 @@
  2304.      IDE_DO_REQUEST;
  2305.  }
  2306.  
  2307. -#ifdef IDE_DRIVE_CMD
  2308.  /*
  2309.   * drive_cmd_intr() is invoked on completion of a special DRIVE_CMD.
  2310.   */
  2311. @@ -1120,7 +1127,6 @@
  2312.          return;
  2313.      IDE_DO_REQUEST;
  2314.  }
  2315. -#endif    /* IDE_DRIVE_CMD */
  2316.  
  2317.  /*
  2318.   * do_special() is used to issue WIN_SPECIFY, WIN_RESTORE, and WIN_SETMULT
  2319. @@ -1175,26 +1181,28 @@
  2320.  int ide_wait_stat (ide_drive_t *drive, byte good, byte bad, unsigned long timeout)
  2321.  {
  2322.      byte stat;
  2323. +    unsigned long flags;
  2324. +test:
  2325. +    udelay(1);    /* spec allows drive 400ns to change "BUSY" */
  2326. +    if (OK_STAT((stat = GET_STAT()), good, bad))
  2327. +        return 0;    /* fast exit for most frequent case */
  2328. +    if (!(stat & BUSY_STAT)) {
  2329. +        (void) ide_error(drive, "status error", stat);
  2330. +        return 1;
  2331. +    }
  2332.  
  2333. -    udelay(1);    /* spec allows drive 400ns to assert "BUSY" */
  2334. -    if (GET_STAT() & BUSY_STAT) {
  2335. -        unsigned long flags;
  2336. -        save_flags(flags);
  2337. -        sti();
  2338. -        timeout += jiffies;
  2339. -        while (GET_STAT() & BUSY_STAT) {
  2340. -            if (jiffies > timeout) {
  2341. -                restore_flags(flags);
  2342. -                (void) ide_error(drive, "status timeout", GET_STAT());
  2343. -                return 1;
  2344. -            }
  2345. +    save_flags(flags);
  2346. +    sti();
  2347. +    timeout += jiffies;
  2348. +    do {
  2349. +        if (!((stat = GET_STAT()) & BUSY_STAT)) {
  2350. +            restore_flags(flags);
  2351. +            goto test;
  2352.          }
  2353. -        restore_flags(flags);
  2354. -        udelay(1);    /* spec allows 400ns for status to stabilize */
  2355. -    }
  2356. -    if (OK_STAT(stat=GET_STAT(), good, bad))
  2357. -        return 0;
  2358. -    (void) ide_error(drive, "status error", stat);
  2359. +    } while (jiffies <= timeout);
  2360. +
  2361. +    restore_flags(flags);
  2362. +    (void) ide_error(drive, "status timeout", GET_STAT());
  2363.      return 1;
  2364.  }
  2365.  
  2366. @@ -1205,28 +1213,30 @@
  2367.   */
  2368.  static inline void do_rw_disk (ide_drive_t *drive, struct request *rq, unsigned long block)
  2369.  {
  2370. +    unsigned short io_base = HWIF(drive)->io_base;
  2371. +
  2372.      OUT_BYTE(drive->ctl,IDE_CONTROL_REG);
  2373. -    OUT_BYTE(rq->nr_sectors,IDE_NSECTOR_REG);
  2374. +    OUT_BYTE(rq->nr_sectors,io_base+IDE_NSECTOR_OFFSET);
  2375.      if (drive->select.b.lba) {
  2376.  #ifdef DEBUG
  2377.          printk("%s: %sing: LBAsect=%ld, sectors=%ld, buffer=0x%08lx\n",
  2378.              drive->name, (rq->cmd==READ)?"read":"writ", 
  2379.              block, rq->nr_sectors, (unsigned long) rq->buffer);
  2380.  #endif
  2381. -        OUT_BYTE(block,IDE_SECTOR_REG);
  2382. -        OUT_BYTE(block>>=8,IDE_LCYL_REG);
  2383. -        OUT_BYTE(block>>=8,IDE_HCYL_REG);
  2384. -        OUT_BYTE(((block>>8)&0x0f)|drive->select.all,IDE_SELECT_REG);
  2385. +        OUT_BYTE(block,io_base+IDE_SECTOR_OFFSET);
  2386. +        OUT_BYTE(block>>=8,io_base+IDE_LCYL_OFFSET);
  2387. +        OUT_BYTE(block>>=8,io_base+IDE_HCYL_OFFSET);
  2388. +        OUT_BYTE(((block>>8)&0x0f)|drive->select.all,io_base+IDE_SELECT_OFFSET);
  2389.      } else {
  2390.          unsigned int sect,head,cyl,track;
  2391.          track = block / drive->sect;
  2392.          sect  = block % drive->sect + 1;
  2393. -        OUT_BYTE(sect,IDE_SECTOR_REG);
  2394. +        OUT_BYTE(sect,io_base+IDE_SECTOR_OFFSET);
  2395.          head  = track % drive->head;
  2396.          cyl   = track / drive->head;
  2397. -        OUT_BYTE(cyl,IDE_LCYL_REG);
  2398. -        OUT_BYTE(cyl>>8,IDE_HCYL_REG);
  2399. -        OUT_BYTE(head|drive->select.all,IDE_SELECT_REG);
  2400. +        OUT_BYTE(cyl,io_base+IDE_LCYL_OFFSET);
  2401. +        OUT_BYTE(cyl>>8,io_base+IDE_HCYL_OFFSET);
  2402. +        OUT_BYTE(head|drive->select.all,io_base+IDE_SELECT_OFFSET);
  2403.  #ifdef DEBUG
  2404.          printk("%s: %sing: CHS=%d/%d/%d, sectors=%ld, buffer=0x%08lx\n",
  2405.              drive->name, (rq->cmd==READ)?"read":"writ", cyl,
  2406. @@ -1239,7 +1249,7 @@
  2407.              return;
  2408.  #endif /* CONFIG_BLK_DEV_TRITON */
  2409.          ide_set_handler(drive, &read_intr);
  2410. -        OUT_BYTE(drive->mult_count ? WIN_MULTREAD : WIN_READ, IDE_COMMAND_REG);
  2411. +        OUT_BYTE(drive->mult_count ? WIN_MULTREAD : WIN_READ, io_base+IDE_COMMAND_OFFSET);
  2412.          return;
  2413.      }
  2414.      if (rq->cmd == WRITE) {
  2415. @@ -1247,7 +1257,7 @@
  2416.          if (drive->using_dma && !(HWIF(drive)->dmaproc(ide_dma_write, drive)))
  2417.              return;
  2418.  #endif /* CONFIG_BLK_DEV_TRITON */
  2419. -        OUT_BYTE(drive->mult_count ? WIN_MULTWRITE : WIN_WRITE, IDE_COMMAND_REG);
  2420. +        OUT_BYTE(drive->mult_count ? WIN_MULTWRITE : WIN_WRITE, io_base+IDE_COMMAND_OFFSET);
  2421.          if (ide_wait_stat(drive, DATA_READY, drive->bad_wstat, WAIT_DRQ)) {
  2422.              printk("%s: no DRQ after issuing %s\n", drive->name,
  2423.                  drive->mult_count ? "MULTWRITE" : "WRITE");
  2424. @@ -1265,13 +1275,12 @@
  2425.          }
  2426.          return;
  2427.      }
  2428. -#ifdef IDE_DRIVE_CMD
  2429.      if (rq->cmd == IDE_DRIVE_CMD) {
  2430.          byte *args = rq->buffer;
  2431.          if (args) {
  2432.              printk("%s: DRIVE_CMD cmd=0x%02x sc=0x%02x fr=0x%02x\n",
  2433.               drive->name, args[0], args[1], args[2]);
  2434. -            OUT_BYTE(args[2],IDE_FEATURE_REG);
  2435. +            OUT_BYTE(args[2],io_base+IDE_FEATURE_OFFSET);
  2436.              ide_cmd(drive, args[0], args[1], &drive_cmd_intr);
  2437.              return;
  2438.          } else {
  2439. @@ -1286,7 +1295,6 @@
  2440.              return;
  2441.          }
  2442.      }
  2443. -#endif    /* IDE_DRIVE_CMD */
  2444.      printk("%s: bad command: %d\n", drive->name, rq->cmd);
  2445.      ide_end_request(0, HWGROUP(drive));
  2446.  }
  2447. @@ -1574,6 +1582,10 @@
  2448.                  ide_drive_t *drive = &hwif->drives[unit];
  2449.                  if (drive->present)
  2450.                      return drive;
  2451. +            } else if (major == IDE0_MAJOR && unit < 4) {
  2452. +                printk("ide: probable bad entry for /dev/hd%c%d\n",
  2453. +                 'a' + unit, MINOR(i_rdev) & PARTN_MASK);
  2454. +                printk("ide: to fix it, run:  /usr/src/linux/drivers/block/MAKEDEV.ide\n");
  2455.              }
  2456.              break;
  2457.          }
  2458. @@ -1581,14 +1593,13 @@
  2459.      return NULL;
  2460.  }
  2461.  
  2462. -#ifdef IDE_DRIVE_CMD
  2463.  /*
  2464.   * This function issues a specific IDE drive command onto the
  2465.   * tail of the request queue, and waits for it to be completed.
  2466.   * If arg is NULL, it goes through all the motions,
  2467.   * but without actually sending a command to the drive.
  2468.   */
  2469. -static int do_drive_cmd(int rdev, char *args)
  2470. +int ide_do_drive_cmd(int rdev, char *args)
  2471.  {
  2472.      unsigned long flags;
  2473.      unsigned int major = MAJOR(rdev);
  2474. @@ -1626,7 +1637,6 @@
  2475.      restore_flags(flags);
  2476.      return rq.errors ? -EIO : 0;        /* return -EIO if errors */
  2477.  }
  2478. -#endif    /* IDE_DRIVE_CMD */
  2479.  
  2480.  static int ide_open(struct inode * inode, struct file * filp)
  2481.  {
  2482. @@ -1646,13 +1656,9 @@
  2483.          return ide_cdrom_open (inode, filp, drive);
  2484.  #endif    /* CONFIG_BLK_DEV_IDECD */
  2485.      if (drive->removeable) {
  2486. -        check_disk_change(inode->i_rdev);
  2487. -#ifdef IDE_DRIVE_CMD
  2488. -        {
  2489.          byte door_lock[] = {WIN_DOORLOCK,0,0,0};
  2490. -        do_drive_cmd(inode->i_rdev, door_lock);
  2491. -        }
  2492. -#endif /* IDE_DRIVE_CMD */
  2493. +        check_disk_change(inode->i_rdev);
  2494. +        ide_do_drive_cmd(inode->i_rdev, door_lock);
  2495.      }
  2496.      return 0;
  2497.  }
  2498. @@ -1674,13 +1680,9 @@
  2499.          else
  2500.  #endif    /* CONFIG_BLK_DEV_IDECD */
  2501.          if (drive->removeable) {
  2502. -            invalidate_buffers(inode->i_rdev);
  2503. -#ifdef IDE_DRIVE_CMD
  2504. -            {
  2505.              byte door_unlock[] = {WIN_DOORUNLOCK,0,0,0};
  2506. -            do_drive_cmd(inode->i_rdev, door_unlock);
  2507. -            }
  2508. -#endif /* IDE_DRIVE_CMD */
  2509. +            invalidate_buffers(inode->i_rdev);
  2510. +            ide_do_drive_cmd(inode->i_rdev, door_unlock);
  2511.          }
  2512.      }
  2513.  }
  2514. @@ -1876,10 +1878,7 @@
  2515.              drive->mult_req = arg;
  2516.              drive->special.b.set_multmode = 1;
  2517.              restore_flags(flags);
  2518. -#ifndef IDE_DRIVE_CMD
  2519. -            return 0;
  2520. -#else
  2521. -            do_drive_cmd (inode->i_rdev, NULL);
  2522. +            ide_do_drive_cmd (inode->i_rdev, NULL);
  2523.              return (drive->mult_count == arg) ? 0 : -EIO;
  2524.  
  2525.          case HDIO_DRIVE_CMD:
  2526. @@ -1887,20 +1886,19 @@
  2527.              unsigned long args;
  2528.  
  2529.              if (NULL == (long *) arg)
  2530. -                err = do_drive_cmd(inode->i_rdev,NULL);
  2531. +                err = ide_do_drive_cmd(inode->i_rdev,NULL);
  2532.              else {
  2533.                  if (!(err = verify_area(VERIFY_READ,(long *)arg,sizeof(long))))
  2534.                  {
  2535.                      args = get_user((long *)arg);
  2536.                      if (!(err = verify_area(VERIFY_WRITE,(long *)arg,sizeof(long)))) {
  2537. -                        err = do_drive_cmd(inode->i_rdev,(char *)&args);
  2538. +                        err = ide_do_drive_cmd(inode->i_rdev,(char *)&args);
  2539.                          put_user(args,(long *)arg);
  2540.                      }
  2541.                  }
  2542.              }
  2543.              return err;
  2544.          }
  2545. -#endif /* IDE_DRIVE_CMD */
  2546.  
  2547.          RO_IOCTLS(inode->i_rdev, arg);
  2548.  
  2549. @@ -2398,7 +2396,8 @@
  2550.      byte reg;
  2551.      unsigned short port = 0x178;
  2552.  
  2553. -     printk("ide: buggy CMD640 interface: ");
  2554. +    single_threaded = 1;
  2555. +     printk("ide: buggy CMD640 interface: serialized, ");
  2556.      reg = read_cmd640_vlb(port, 0x50);
  2557.      if (reg == 0xff || (reg & 0x90) != 0x90) {
  2558.  #if TRY_CMD640_VLB_AT_0x78
  2559. @@ -2406,9 +2405,8 @@
  2560.          if (reg == 0xff || (reg & 0x90) != 0x90)
  2561.  #endif
  2562.          {
  2563. -            single_threaded = 1;
  2564.              disallow_unmask = 1;
  2565. -            printk("(probe failed) serialized, disabled unmasking\n");
  2566. +            printk("(probe failed) disabled unmasking\n");
  2567.              return;
  2568.          }
  2569.      }
  2570. @@ -2578,8 +2576,14 @@
  2571.  #if SUPPORT_HT6560B
  2572.              case -4: /* "ht6560b" */
  2573.                  if (hw > 1) goto bad_hwif;
  2574. -                ide_hwifs[0].select = 0x1c;
  2575. -                ide_hwifs[1].select = 0x1d;
  2576. +                /*
  2577. +                 * Using 0x1c and 0x1d apparently selects a
  2578. +                 * faster interface speed than 0x3c and 0x3d.
  2579. +                 *
  2580. +                 * Need to add an ioctl to select between them.
  2581. +                 */
  2582. +                ide_hwifs[0].select = 0x3c;
  2583. +                ide_hwifs[1].select = 0x3d;
  2584.                  goto do_serialize;
  2585.  #endif /* SUPPORT_HT6560B */
  2586.  #if SUPPORT_DTC2278
  2587. @@ -2752,7 +2756,7 @@
  2588.      restore_flags(flags);    /* safe now that hwif->hwgroup is set up */
  2589.  
  2590.      printk("%s at 0x%03x-0x%03x,0x%03x on irq %d", hwif->name,
  2591. -        hwif->io_base, hwif->io_base + 7, hwif->ctl_port, hwif->irq);
  2592. +        hwif->io_base, hwif->io_base+7, hwif->ctl_port, hwif->irq);
  2593.      if (hwgroup->hwif != hwif) {
  2594.          char *name = hwgroup->hwif->name;
  2595.          if (hwgroup->hwif->irq == hwif->irq)
  2596. @@ -2818,12 +2822,13 @@
  2597.      int rc;
  2598.      unsigned char reg;
  2599.  
  2600. +    single_threaded = 1;
  2601.      printk("ide: buggy CMD640 interface: ");
  2602.      if ((rc = pcibios_read_config_byte(bus, fn, 0x51, ®))
  2603.       || (rc =  pcibios_write_config_byte(bus, fn, 0x51, reg | 0xc8)))
  2604.          buggy_interface_fallback (rc);
  2605.      else
  2606. -        printk("disabled read-ahead, enabled secondary\n");
  2607. +        printk("serialized, disabled read-ahead, enabled secondary\n");
  2608.  }
  2609.  #endif /* SUPPORT_CMD640 */
  2610.  
  2611. @@ -2840,8 +2845,6 @@
  2612.      byte fn, bus;
  2613.      int rc;
  2614.  
  2615. -    if (!pcibios_present())
  2616. -        return;
  2617.      save_flags(flags);
  2618.      cli();
  2619.      for (index = 0; !pcibios_find_device (vendor, device, index, &bus, &fn); ++index) {
  2620. @@ -2892,7 +2895,8 @@
  2621.      /*
  2622.       * Find/initialize PCI IDE interfaces
  2623.       */
  2624. -    ide_init_pci ();
  2625. +    if (pcibios_present())
  2626. +        ide_init_pci ();
  2627.  #endif /* CONFIG_PCI */
  2628.  
  2629.      /*
  2630. diff -u --recursive --new-file v1.3.22/linux/drivers/block/ide.h linux/drivers/block/ide.h
  2631. --- v1.3.22/linux/drivers/block/ide.h    Sun Sep  3 12:26:51 1995
  2632. +++ linux/drivers/block/ide.h    Sun Sep  3 14:06:00 1995
  2633. @@ -17,11 +17,10 @@
  2634.  
  2635.  /******************************************************************************
  2636.   * IDE driver configuration options (play with these as desired):
  2637. + * 
  2638. + * REALLY_SLOW_IO can be defined in ide.c and ide-cd.c, if necessary
  2639.   */
  2640. -#undef REALLY_SLOW_IO            /* most systems can safely undef this */
  2641. -#include <asm/io.h>
  2642. -
  2643. -#undef     REALLY_FAST_IO            /* define if ide ports are perfect */
  2644. +#define REALLY_FAST_IO            /* define if ide ports are perfect */
  2645.  #define INITIAL_MULT_COUNT    0    /* off=0; on=2,4,8,16,32, etc.. */
  2646.  
  2647.  #ifndef DISK_RECOVERY_TIME        /* off=0; on=access_delay_time */
  2648. @@ -81,14 +80,25 @@
  2649.  #define HWIF(drive)        ((ide_hwif_t *)drive->hwif)
  2650.  #define HWGROUP(drive)        ((ide_hwgroup_t *)(HWIF(drive)->hwgroup))
  2651.  
  2652. -#define IDE_DATA_REG        (HWIF(drive)->io_base)
  2653. -#define IDE_ERROR_REG        (HWIF(drive)->io_base+1)
  2654. -#define IDE_NSECTOR_REG        (HWIF(drive)->io_base+2)
  2655. -#define IDE_SECTOR_REG        (HWIF(drive)->io_base+3)
  2656. -#define IDE_LCYL_REG        (HWIF(drive)->io_base+4)
  2657. -#define IDE_HCYL_REG        (HWIF(drive)->io_base+5)
  2658. -#define IDE_SELECT_REG        (HWIF(drive)->io_base+6)
  2659. -#define IDE_STATUS_REG        (HWIF(drive)->io_base+7)
  2660. +#define IDE_DATA_OFFSET        (0)
  2661. +#define IDE_ERROR_OFFSET    (1)
  2662. +#define IDE_NSECTOR_OFFSET    (2)
  2663. +#define IDE_SECTOR_OFFSET    (3)
  2664. +#define IDE_LCYL_OFFSET        (4)
  2665. +#define IDE_HCYL_OFFSET        (5)
  2666. +#define IDE_SELECT_OFFSET    (6)
  2667. +#define IDE_STATUS_OFFSET    (7)
  2668. +#define IDE_FEATURE_OFFSET    IDE_ERROR_OFFSET
  2669. +#define IDE_COMMAND_OFFSET    IDE_STATUS_OFFSET
  2670. +
  2671. +#define IDE_DATA_REG        (HWIF(drive)->io_base+IDE_DATA_OFFSET)
  2672. +#define IDE_ERROR_REG        (HWIF(drive)->io_base+IDE_ERROR_OFFSET)
  2673. +#define IDE_NSECTOR_REG        (HWIF(drive)->io_base+IDE_NSECTOR_OFFSET)
  2674. +#define IDE_SECTOR_REG        (HWIF(drive)->io_base+IDE_SECTOR_OFFSET)
  2675. +#define IDE_LCYL_REG        (HWIF(drive)->io_base+IDE_LCYL_OFFSET)
  2676. +#define IDE_HCYL_REG        (HWIF(drive)->io_base+IDE_HCYL_OFFSET)
  2677. +#define IDE_SELECT_REG        (HWIF(drive)->io_base+IDE_SELECT_OFFSET)
  2678. +#define IDE_STATUS_REG        (HWIF(drive)->io_base+IDE_STATUS_OFFSET)
  2679.  #define IDE_CONTROL_REG        (HWIF(drive)->ctl_port)
  2680.  #define IDE_FEATURE_REG        IDE_ERROR_REG
  2681.  #define IDE_COMMAND_REG        IDE_STATUS_REG
  2682. @@ -413,6 +423,17 @@
  2683.   * All allocations are longword aligned.
  2684.   */
  2685.  void *ide_alloc (unsigned long bytecount, unsigned long within_area);
  2686. +
  2687. +/*
  2688. + * This function issues a specific IDE drive command onto the
  2689. + * tail of the request queue, and waits for it to be completed.
  2690. + * If arg is NULL, it goes through all the motions,
  2691. + * but without actually sending a command to the drive.
  2692. + *
  2693. + * The value of arg is passed to the internal handler as rq->buffer.
  2694. + */
  2695. +int ide_do_drive_cmd(int rdev, char *args);
  2696. +
  2697.  
  2698.  #ifdef CONFIG_BLK_DEV_IDECD
  2699.  /*
  2700. diff -u --recursive --new-file v1.3.22/linux/drivers/block/triton.c linux/drivers/block/triton.c
  2701. --- v1.3.22/linux/drivers/block/triton.c    Sun Sep  3 12:26:52 1995
  2702. +++ linux/drivers/block/triton.c    Sun Sep  3 12:03:00 1995
  2703. @@ -194,6 +194,29 @@
  2704.      return 1;    /* let the PIO routines handle this weirdness */
  2705.  }
  2706.  
  2707. +static int config_drive_for_dma (ide_drive_t *drive)
  2708. +{
  2709. +    const char **list;
  2710. +
  2711. +    struct hd_driveid *id = drive->id;
  2712. +    if (id && (id->capability & 1)) {
  2713. +        /* Enable DMA on any drive that supports mword2 DMA */
  2714. +        if ((id->field_valid & 2) && (id->dma_mword & 0x404) == 0x404) {
  2715. +            drive->using_dma = 1;
  2716. +            return 0;        /* DMA enabled */
  2717. +        }
  2718. +        /* Consult the list of known "good" drives */
  2719. +        list = good_dma_drives;
  2720. +        while (*list) {
  2721. +            if (!strcmp(*list++,id->model)) {
  2722. +                drive->using_dma = 1;
  2723. +                return 0;    /* DMA enabled */
  2724. +            }
  2725. +        }
  2726. +    }
  2727. +    return 1;    /* DMA not enabled */
  2728. +}
  2729. +
  2730.  /*
  2731.   * triton_dmaproc() initiates/aborts DMA read/write operations on a drive.
  2732.   *
  2733. @@ -207,40 +230,31 @@
  2734.   */
  2735.  static int triton_dmaproc (ide_dma_action_t func, ide_drive_t *drive)
  2736.  {
  2737. -    const char **list;
  2738.      unsigned long dma_base = HWIF(drive)->dma_base;
  2739. +    unsigned int reading = (1 << 3);
  2740.  
  2741. -    if (func == ide_dma_abort) {
  2742. -        outb(inb(dma_base)&~1, dma_base);    /* stop DMA */
  2743. -        return 0;
  2744. -    }
  2745. -    if (func == ide_dma_check) {
  2746. -        struct hd_driveid *id = drive->id;
  2747. -        if (id && (id->capability & 1)) {
  2748. -            /* Enable DMA on any drive that supports mword2 DMA */
  2749. -            if ((id->field_valid & 2) && (id->dma_mword & 0x404) == 0x404) {
  2750. -                drive->using_dma = 1;
  2751. -                return 0;        /* DMA enabled */
  2752. -            }
  2753. -            /* Consult the list of known "good" drives */
  2754. -            list = good_dma_drives;
  2755. -            while (*list) {
  2756. -                if (!strcmp(*list++,id->model)) {
  2757. -                    drive->using_dma = 1;
  2758. -                    return 0;    /* DMA enabled */
  2759. -                }
  2760. -            }
  2761. -        }
  2762. -        return 1;    /* DMA not enabled */
  2763. +    switch (func) {
  2764. +        case ide_dma_abort:
  2765. +            outb(inb(dma_base)&~1, dma_base);    /* stop DMA */
  2766. +            return 0;
  2767. +        case ide_dma_check:
  2768. +            return config_drive_for_dma (drive);
  2769. +        case ide_dma_write:
  2770. +            reading = 0;
  2771. +        case ide_dma_read:
  2772. +            break;
  2773. +        default:
  2774. +            printk("triton_dmaproc: unsupported func: %d\n", func);
  2775. +            return 1;
  2776.      }
  2777.      if (build_dmatable (drive))
  2778.          return 1;
  2779.      outl(virt_to_bus (HWIF(drive)->dmatable), dma_base + 4); /* PRD table */
  2780. -    outb((!func) << 3, dma_base);            /* specify r/w */
  2781. +    outb(reading, dma_base);            /* specify r/w */
  2782.      outb(0x26, dma_base+2);                /* clear status bits */
  2783.      ide_set_handler (drive, &dma_intr);        /* issue cmd to drive */
  2784. -    OUT_BYTE(func ? WIN_WRITEDMA : WIN_READDMA, IDE_COMMAND_REG);
  2785. -    outb(inb(dma_base)|1, dma_base);            /* begin DMA */
  2786. +    OUT_BYTE(reading ? WIN_READDMA : WIN_WRITEDMA, IDE_COMMAND_REG);
  2787. +    outb(inb(dma_base)|1, dma_base);        /* begin DMA */
  2788.      return 0;
  2789.  }
  2790.  
  2791. @@ -326,8 +340,8 @@
  2792.              base = bmiba + 8;
  2793.          } else
  2794.              continue;
  2795. -        printk("    %s: BusMaster DMA at 0x%04x-0x%04x", hwif->name, base, base+5);
  2796. -        if (check_region(base, 6)) {
  2797. +        printk("    %s: BusMaster DMA at 0x%04x-0x%04x", hwif->name, base, base+7);
  2798. +        if (check_region(base, 8)) {
  2799.              printk(" -- ERROR, PORTS ALREADY IN USE");
  2800.          } else {
  2801.              unsigned long *table;
  2802. diff -u --recursive --new-file v1.3.22/linux/drivers/net/Makefile linux/drivers/net/Makefile
  2803. --- v1.3.22/linux/drivers/net/Makefile    Mon Aug 28 14:52:20 1995
  2804. +++ linux/drivers/net/Makefile    Sun Sep  3 12:08:21 1995
  2805. @@ -245,8 +245,6 @@
  2806.  
  2807.  ifdef CONFIG_ARCNET
  2808.  L_OBJS += arcnet.o
  2809. -else
  2810. -M_OBJS += arcnet.o
  2811.  endif
  2812.  
  2813.  ifdef CONFIG_PI
  2814. diff -u --recursive --new-file v1.3.22/linux/drivers/net/lance.c linux/drivers/net/lance.c
  2815. --- v1.3.22/linux/drivers/net/lance.c    Tue Aug 15 20:39:03 1995
  2816. +++ linux/drivers/net/lance.c    Sun Sep  3 11:13:05 1995
  2817. @@ -319,10 +319,14 @@
  2818.      for (port = lance_portlist; *port; port++) {
  2819.          int ioaddr = *port;
  2820.  
  2821. -        if (   check_region(ioaddr, LANCE_TOTAL_SIZE) == 0
  2822. -            && inb(ioaddr + 14) == 0x57
  2823. -            && inb(ioaddr + 15) == 0x57) {
  2824. -            mem_start = lance_probe1(ioaddr, mem_start);
  2825. +        if ( check_region(ioaddr, LANCE_TOTAL_SIZE) == 0) {
  2826. +            /* Detect "normal" 0x57 0x57 and the NI6510EB 0x52 0x44
  2827. +               signatures w/ minimal I/O reads */
  2828. +            char offset15, offset14 = inb(ioaddr + 14);
  2829. +            
  2830. +            if ((offset14 == 0x52 || offset14 == 0x57) &&
  2831. +                ((offset15 = inb(ioaddr + 15)) == 0x57 || offset15 == 0x44))
  2832. +                mem_start = lance_probe1(ioaddr, mem_start);
  2833.          }
  2834.      }
  2835.  
  2836. diff -u --recursive --new-file v1.3.22/linux/include/asm-i386/io.h linux/include/asm-i386/io.h
  2837. --- v1.3.22/linux/include/asm-i386/io.h    Sun Sep  3 12:27:02 1995
  2838. +++ linux/include/asm-i386/io.h    Sun Sep  3 12:06:48 1995
  2839. @@ -121,10 +121,11 @@
  2840.  #undef RETURN_TYPE
  2841.  #define RETURN_TYPE unsigned short
  2842.  /* __IN(w,"w","0" (0)) */
  2843. -__IN(w,)
  2844. +__IN(w,"")
  2845.  #undef RETURN_TYPE
  2846.  #define RETURN_TYPE unsigned int
  2847.  __IN(l,"")
  2848. +#undef RETURN_TYPE
  2849.  
  2850.  __OUT(b,"b",char)
  2851.  __OUT(w,"w",short)
  2852. diff -u --recursive --new-file v1.3.22/linux/include/linux/hdreg.h linux/include/linux/hdreg.h
  2853. --- v1.3.22/linux/include/linux/hdreg.h    Mon Aug 28 14:52:22 1995
  2854. +++ linux/include/linux/hdreg.h    Sun Sep  3 14:04:52 1995
  2855. @@ -1,8 +1,6 @@
  2856.  #ifndef _LINUX_HDREG_H
  2857.  #define _LINUX_HDREG_H
  2858.  
  2859. -#include <linux/config.h>
  2860. -
  2861.  /*
  2862.   * This file contains some defines for the AT-hd-controller.
  2863.   * Various sources.  
  2864. @@ -154,14 +152,19 @@
  2865.      /* unsigned short reservedyy[96];*/    /* reserved (words 160-255) */
  2866.  };
  2867.  
  2868. +#ifdef __KERNEL__
  2869.  /*
  2870.   * These routines are used for kernel command line parameters from main.c:
  2871.   */
  2872. +#include <linux/config.h>
  2873. +
  2874.  #ifdef CONFIG_BLK_DEV_HD
  2875.  void hd_setup(char *, int *);
  2876.  #endif    /* CONFIG_BLK_DEV_HD */
  2877.  #ifdef CONFIG_BLK_DEV_IDE
  2878.  void ide_setup(char *);
  2879.  #endif    /* CONFIG_BLK_DEV_IDE */
  2880. +
  2881. +#endif  /* __KERNEL__ */
  2882.  
  2883.  #endif    /* _LINUX_HDREG_H */
  2884. diff -u --recursive --new-file v1.3.22/linux/include/linux/igmp.h linux/include/linux/igmp.h
  2885. --- v1.3.22/linux/include/linux/igmp.h    Tue Jun  6 11:22:11 1995
  2886. +++ linux/include/linux/igmp.h    Sun Sep  3 11:19:53 1995
  2887. @@ -25,7 +25,7 @@
  2888.  struct igmphdr
  2889.  {
  2890.      unsigned char type;
  2891. -    unsigned char unused;
  2892. +    unsigned char code;
  2893.      unsigned short csum;
  2894.      unsigned long group;
  2895.  };
  2896. @@ -37,7 +37,7 @@
  2897.  struct igmp_header
  2898.  {
  2899.      unsigned char type;
  2900. -    unsigned char unused;
  2901. +    unsigned char code;
  2902.      unsigned short csum;
  2903.      unsigned long group;
  2904.  };
  2905. diff -u --recursive --new-file v1.3.22/linux/include/linux/mcd.h linux/include/linux/mcd.h
  2906. --- v1.3.22/linux/include/linux/mcd.h    Sun Sep  3 12:27:02 1995
  2907. +++ linux/include/linux/mcd.h    Sun Sep  3 12:09:44 1995
  2908. @@ -110,6 +110,8 @@
  2909.      struct msf    diskTime;
  2910.  };
  2911.  
  2912. +#if 0
  2913.  #ifndef I_WAS_HERE
  2914.  #error Please edit this file first.
  2915. +#endif
  2916.  #endif
  2917. diff -u --recursive --new-file v1.3.22/linux/include/linux/mcdx.h linux/include/linux/mcdx.h
  2918. --- v1.3.22/linux/include/linux/mcdx.h    Sun Sep  3 12:27:02 1995
  2919. +++ linux/include/linux/mcdx.h    Sun Sep  3 12:09:44 1995
  2920. @@ -173,6 +173,8 @@
  2921.  #define MCDX_E        1            /* unspec error */
  2922.  #define MCDX_EOM    2            /* end of media */
  2923.  
  2924. +#if 0
  2925.  #ifndef I_WAS_HERE
  2926.  #error Please edit this file first.
  2927. +#endif
  2928.  #endif
  2929. diff -u --recursive --new-file v1.3.22/linux/net/core/dev.c linux/net/core/dev.c
  2930. --- v1.3.22/linux/net/core/dev.c    Sun Sep  3 12:27:05 1995
  2931. +++ linux/net/core/dev.c    Sun Sep  3 12:00:24 1995
  2932. @@ -1305,7 +1305,7 @@
  2933.   
  2934.  void dev_init(void)
  2935.  {
  2936. -    struct device *dev, *dev2;
  2937. +    struct device *dev, **dp;
  2938.  
  2939.      /*
  2940.       *    Add the devices.
  2941. @@ -1313,24 +1313,25 @@
  2942.       *    from the chain disconnecting the device until the
  2943.       *    next reboot.
  2944.       */
  2945. -     
  2946. -    dev2 = NULL;
  2947. -    for (dev = dev_base; dev != NULL; dev=dev->next) 
  2948. +
  2949. +    dp = &dev_base;
  2950. +    while ((dev = *dp) != NULL)
  2951.      {
  2952. +        int i;
  2953. +        for (i = 0; i < DEV_NUMBUFFS; i++)  {
  2954. +            skb_queue_head_init(dev->buffs + i);
  2955. +        }
  2956. +
  2957.          if (dev->init && dev->init(dev)) 
  2958.          {
  2959.              /*
  2960.               *    It failed to come up. Unhook it.
  2961.               */
  2962. -             
  2963. -            if (dev2 == NULL) 
  2964. -                dev_base = dev->next;
  2965. -            else 
  2966. -                dev2->next = dev->next;
  2967. +            *dp = dev->next;
  2968.          } 
  2969.          else
  2970.          {
  2971. -            dev2 = dev;
  2972. +            dp = &dev->next;
  2973.          }
  2974.      }
  2975.      proc_net_register(&(struct proc_dir_entry) {
  2976. @@ -1339,6 +1340,5 @@
  2977.          0, &proc_net_inode_operations,
  2978.          dev_get_info
  2979.      });
  2980. -
  2981.  }
  2982.  
  2983. diff -u --recursive --new-file v1.3.22/linux/net/ipv4/ip.c linux/net/ipv4/ip.c
  2984. --- v1.3.22/linux/net/ipv4/ip.c    Sun Sep  3 12:27:05 1995
  2985. +++ linux/net/ipv4/ip.c    Sat Sep  2 11:45:37 1995
  2986. @@ -1819,7 +1819,7 @@
  2987.      iph->tot_len = ntohs(skb->len-(((unsigned char *)iph)-skb->data));
  2988.  
  2989.  #ifdef CONFIG_IP_FIREWALL
  2990. -    if(ip_fw_chk(iph, dev, ip_fw_blk_chain, ip_fw_blk_policy, 0) != 1)
  2991. +    if(ip_fw_chk(iph, dev, ip_fw_blk_chain, ip_fw_blk_policy, 0) < 1)
  2992.          /* just don't send this packet */
  2993.          return;
  2994.  #endif    
  2995.