[PATCH] ide-cd: remove struct atapi_capabilities_page (take 2)

2008-01-09 Thread Bartlomiej Zolnierkiewicz

* Remove struct atapi_capabilities_page.

* Add ATAPI_CAPABILITIES_PAGE[_PAD]_SIZE define.

v2:
* The buf[] array access indexes were swapped between 'curspeed'/'maxspeed'.
  (Noticed by Borislav Petkov).

Cc: Borislav Petkov <[EMAIL PROTECTED]>
Signed-off-by: Bartlomiej Zolnierkiewicz <[EMAIL PROTECTED]>
---
this is the replacement patch for the one currently in the IDE tree

 drivers/ide/ide-cd.c |   62 +++---
 drivers/ide/ide-cd.h |  223 ---
 2 files changed, 37 insertions(+), 248 deletions(-)

Index: b/drivers/ide/ide-cd.c
===
--- a/drivers/ide/ide-cd.c
+++ b/drivers/ide/ide-cd.c
@@ -2373,13 +2373,12 @@ int ide_cdrom_lock_door (struct cdrom_de
return cdrom_lockdoor(drive, lock, NULL);
 }
 
-static
-int ide_cdrom_get_capabilities(ide_drive_t *drive, struct 
atapi_capabilities_page *cap)
+static int ide_cdrom_get_capabilities(ide_drive_t *drive, u8 *buf)
 {
struct cdrom_info *info = drive->driver_data;
struct cdrom_device_info *cdi = >devinfo;
struct packet_command cgc;
-   int stat, attempts = 3, size = sizeof(*cap);
+   int stat, attempts = 3, size = ATAPI_CAPABILITIES_PAGE_SIZE;
 
/*
 * ACER50 (and others?) require the full spec length mode sense
@@ -2387,9 +2386,9 @@ int ide_cdrom_get_capabilities(ide_drive
 */
if (!(!strcmp(drive->id->model, "ATAPI CD ROM DRIVE 50X MAX") ||
!strcmp(drive->id->model, "WPI CDS-32X")))
-   size -= sizeof(cap->pad);
+   size -= ATAPI_CAPABILITIES_PAGE_PAD_SIZE;
 
-   init_cdrom_command(, cap, size, CGC_DATA_UNKNOWN);
+   init_cdrom_command(, buf, size, CGC_DATA_UNKNOWN);
do { /* we seem to get stat=0x01,err=0x00 the first time (??) */
stat = cdrom_mode_sense(cdi, , GPMODE_CAPABILITIES_PAGE, 0);
if (!stat)
@@ -2398,20 +2397,22 @@ int ide_cdrom_get_capabilities(ide_drive
return stat;
 }
 
-static
-void ide_cdrom_update_speed (ide_drive_t *drive, struct 
atapi_capabilities_page *cap)
+static void ide_cdrom_update_speed(ide_drive_t *drive, u8 *buf)
 {
struct cdrom_info *cd = drive->driver_data;
u16 curspeed, maxspeed;
 
+   curspeed = *(u16 *)[8 + 14];
+   maxspeed = *(u16 *)[8 +  8];
+
/* The ACER/AOpen 24X cdrom has the speed fields byte-swapped */
if (!drive->id->model[0] &&
!strncmp(drive->id->fw_rev, "241N", 4)) {
-   curspeed = le16_to_cpu(cap->curspeed);
-   maxspeed = le16_to_cpu(cap->maxspeed);
+   curspeed = le16_to_cpu(curspeed);
+   maxspeed = le16_to_cpu(maxspeed);
} else {
-   curspeed = be16_to_cpu(cap->curspeed);
-   maxspeed = be16_to_cpu(cap->maxspeed);
+   curspeed = be16_to_cpu(curspeed);
+   maxspeed = be16_to_cpu(maxspeed);
}
 
cd->state_flags.current_speed = (curspeed + (176/2)) / 176;
@@ -2424,14 +2425,14 @@ int ide_cdrom_select_speed (struct cdrom
ide_drive_t *drive = cdi->handle;
struct cdrom_info *cd = drive->driver_data;
struct request_sense sense;
-   struct atapi_capabilities_page cap;
+   u8 buf[ATAPI_CAPABILITIES_PAGE_SIZE];
int stat;
 
if ((stat = cdrom_select_speed(drive, speed, )) < 0)
return stat;
 
-   if (!ide_cdrom_get_capabilities(drive, )) {
-   ide_cdrom_update_speed(drive, );
+   if (!ide_cdrom_get_capabilities(drive, buf)) {
+   ide_cdrom_update_speed(drive, buf);
cdi->speed = cd->state_flags.current_speed;
}
 return 0;
@@ -2615,7 +2616,8 @@ int ide_cdrom_probe_capabilities (ide_dr
 {
struct cdrom_info *cd = drive->driver_data;
struct cdrom_device_info *cdi = >devinfo;
-   struct atapi_capabilities_page cap;
+   u8 buf[ATAPI_CAPABILITIES_PAGE_SIZE];
+   mechtype_t mechtype;
int nslots = 1;
 
cdi->mask = (CDC_CD_R | CDC_CD_RW | CDC_DVD | CDC_DVD_R |
@@ -2645,26 +2647,28 @@ int ide_cdrom_probe_capabilities (ide_dr
cdi->handle = drive;
cdi->ops = _cdrom_dops;
 
-   if (ide_cdrom_get_capabilities(drive, ))
+   if (ide_cdrom_get_capabilities(drive, buf))
return 0;
 
-   if (cap.lock == 0)
+   if ((buf[8 + 6] & 0x01) == 0)
cd->config_flags.no_doorlock = 1;
-   if (cap.eject)
+   if (buf[8 + 6] & 0x08)
cd->config_flags.no_eject = 0;
-   if (cap.cd_r_write)
+   if (buf[8 + 3] & 0x01)
cdi->mask &= ~CDC_CD_R;
-   if (cap.cd_rw_write)
+   if (buf[8 + 3] & 0x02)
cdi->mask &= ~(CDC_CD_RW | CDC_RAM);
-   if (cap.dvd_ram_read || cap.dvd_r_read || cap.dvd_rom)
+   if (buf[8 + 2] & 0x38)
cdi->mask &= ~CDC_DVD;
-   if (cap.dvd_ram_write)
+   if (buf[8 + 3] & 0x20)
  

[PATCH] ide-cd: remove struct atapi_capabilities_page (take 2)

2008-01-09 Thread Bartlomiej Zolnierkiewicz

* Remove struct atapi_capabilities_page.

* Add ATAPI_CAPABILITIES_PAGE[_PAD]_SIZE define.

v2:
* The buf[] array access indexes were swapped between 'curspeed'/'maxspeed'.
  (Noticed by Borislav Petkov).

Cc: Borislav Petkov [EMAIL PROTECTED]
Signed-off-by: Bartlomiej Zolnierkiewicz [EMAIL PROTECTED]
---
this is the replacement patch for the one currently in the IDE tree

 drivers/ide/ide-cd.c |   62 +++---
 drivers/ide/ide-cd.h |  223 ---
 2 files changed, 37 insertions(+), 248 deletions(-)

Index: b/drivers/ide/ide-cd.c
===
--- a/drivers/ide/ide-cd.c
+++ b/drivers/ide/ide-cd.c
@@ -2373,13 +2373,12 @@ int ide_cdrom_lock_door (struct cdrom_de
return cdrom_lockdoor(drive, lock, NULL);
 }
 
-static
-int ide_cdrom_get_capabilities(ide_drive_t *drive, struct 
atapi_capabilities_page *cap)
+static int ide_cdrom_get_capabilities(ide_drive_t *drive, u8 *buf)
 {
struct cdrom_info *info = drive-driver_data;
struct cdrom_device_info *cdi = info-devinfo;
struct packet_command cgc;
-   int stat, attempts = 3, size = sizeof(*cap);
+   int stat, attempts = 3, size = ATAPI_CAPABILITIES_PAGE_SIZE;
 
/*
 * ACER50 (and others?) require the full spec length mode sense
@@ -2387,9 +2386,9 @@ int ide_cdrom_get_capabilities(ide_drive
 */
if (!(!strcmp(drive-id-model, ATAPI CD ROM DRIVE 50X MAX) ||
!strcmp(drive-id-model, WPI CDS-32X)))
-   size -= sizeof(cap-pad);
+   size -= ATAPI_CAPABILITIES_PAGE_PAD_SIZE;
 
-   init_cdrom_command(cgc, cap, size, CGC_DATA_UNKNOWN);
+   init_cdrom_command(cgc, buf, size, CGC_DATA_UNKNOWN);
do { /* we seem to get stat=0x01,err=0x00 the first time (??) */
stat = cdrom_mode_sense(cdi, cgc, GPMODE_CAPABILITIES_PAGE, 0);
if (!stat)
@@ -2398,20 +2397,22 @@ int ide_cdrom_get_capabilities(ide_drive
return stat;
 }
 
-static
-void ide_cdrom_update_speed (ide_drive_t *drive, struct 
atapi_capabilities_page *cap)
+static void ide_cdrom_update_speed(ide_drive_t *drive, u8 *buf)
 {
struct cdrom_info *cd = drive-driver_data;
u16 curspeed, maxspeed;
 
+   curspeed = *(u16 *)buf[8 + 14];
+   maxspeed = *(u16 *)buf[8 +  8];
+
/* The ACER/AOpen 24X cdrom has the speed fields byte-swapped */
if (!drive-id-model[0] 
!strncmp(drive-id-fw_rev, 241N, 4)) {
-   curspeed = le16_to_cpu(cap-curspeed);
-   maxspeed = le16_to_cpu(cap-maxspeed);
+   curspeed = le16_to_cpu(curspeed);
+   maxspeed = le16_to_cpu(maxspeed);
} else {
-   curspeed = be16_to_cpu(cap-curspeed);
-   maxspeed = be16_to_cpu(cap-maxspeed);
+   curspeed = be16_to_cpu(curspeed);
+   maxspeed = be16_to_cpu(maxspeed);
}
 
cd-state_flags.current_speed = (curspeed + (176/2)) / 176;
@@ -2424,14 +2425,14 @@ int ide_cdrom_select_speed (struct cdrom
ide_drive_t *drive = cdi-handle;
struct cdrom_info *cd = drive-driver_data;
struct request_sense sense;
-   struct atapi_capabilities_page cap;
+   u8 buf[ATAPI_CAPABILITIES_PAGE_SIZE];
int stat;
 
if ((stat = cdrom_select_speed(drive, speed, sense))  0)
return stat;
 
-   if (!ide_cdrom_get_capabilities(drive, cap)) {
-   ide_cdrom_update_speed(drive, cap);
+   if (!ide_cdrom_get_capabilities(drive, buf)) {
+   ide_cdrom_update_speed(drive, buf);
cdi-speed = cd-state_flags.current_speed;
}
 return 0;
@@ -2615,7 +2616,8 @@ int ide_cdrom_probe_capabilities (ide_dr
 {
struct cdrom_info *cd = drive-driver_data;
struct cdrom_device_info *cdi = cd-devinfo;
-   struct atapi_capabilities_page cap;
+   u8 buf[ATAPI_CAPABILITIES_PAGE_SIZE];
+   mechtype_t mechtype;
int nslots = 1;
 
cdi-mask = (CDC_CD_R | CDC_CD_RW | CDC_DVD | CDC_DVD_R |
@@ -2645,26 +2647,28 @@ int ide_cdrom_probe_capabilities (ide_dr
cdi-handle = drive;
cdi-ops = ide_cdrom_dops;
 
-   if (ide_cdrom_get_capabilities(drive, cap))
+   if (ide_cdrom_get_capabilities(drive, buf))
return 0;
 
-   if (cap.lock == 0)
+   if ((buf[8 + 6]  0x01) == 0)
cd-config_flags.no_doorlock = 1;
-   if (cap.eject)
+   if (buf[8 + 6]  0x08)
cd-config_flags.no_eject = 0;
-   if (cap.cd_r_write)
+   if (buf[8 + 3]  0x01)
cdi-mask = ~CDC_CD_R;
-   if (cap.cd_rw_write)
+   if (buf[8 + 3]  0x02)
cdi-mask = ~(CDC_CD_RW | CDC_RAM);
-   if (cap.dvd_ram_read || cap.dvd_r_read || cap.dvd_rom)
+   if (buf[8 + 2]  0x38)
cdi-mask = ~CDC_DVD;
-   if (cap.dvd_ram_write)
+   if (buf[8 + 3]  0x20)