From: Tejun Heo <htejun@gmail.com>
To: su henry <henry.su.ati@gmail.com>
Cc: axboe@kernel.dk, linux-scsi@vger.kernel.org,
James Bottomley <James.Bottomley@suse.de>
Subject: Re: [PATCH RFC] support sata odd zero power
Date: Fri, 25 Jun 2010 15:39:16 +0200 [thread overview]
Message-ID: <4C24B184.6050009@gmail.com> (raw)
In-Reply-To: <AANLkTimajvNh3frP9LcytXUhFAGk1gB52wa0LlGe0ZS0@mail.gmail.com>
(cc'ing James)
On 06/25/2010 12:15 PM, su henry wrote:
> --- a/drivers/scsi/sr.c
> +++ b/drivers/scsi/sr.c
> @@ -55,6 +55,7 @@
> #include <scsi/scsi_eh.h>
> #include <scsi/scsi_host.h>
> #include <scsi/scsi_ioctl.h> /* For the door lock/unlock commands */
> +#include <acpi/acpi_bus.h>
>
> #include "scsi_logging.h"
> #include "sr.h"
> @@ -89,6 +90,19 @@ static struct scsi_driver sr_template = {
> .done = sr_done,
> };
>
> +static struct sr_zpodd_device_info {
> + acpi_handle handle;
> + mechtype_t mechtype;
> +
> +#define SR_NO_MEDIA_TIMEOUT (120*HZ)
> +#define SR_IS_ZPODD 0x01
> +#define SR_ZPODD_NO_DISK 0x02
> +#define SR_ZPODD_NEED_EJECT 0x04
> +
> + u32 flags;
It's more customary to use unsigned int.
> + unsigned long last_jiffies;
> +} sr_zpodd_device;
Can you please align fields? Also, single struct for the whole
system? I haven't read the spec but I don't think anybody would be
defining things like this system-wide. Right?
> @@ -205,6 +219,7 @@ static int sr_media_change(struct
> cdrom_device_info *cdi, int slot)
> struct scsi_cd *cd = cdi->handle;
> int retval;
> struct scsi_sense_hdr *sshdr;
> + int isvalid;
bool?
> if (CDSL_CURRENT != slot) {
> /* no changer support */
> @@ -213,7 +228,59 @@ static int sr_media_change(struct
> cdrom_device_info *cdi, int slot)
>
> sshdr = kzalloc(sizeof(*sshdr), GFP_KERNEL);
> retval = sr_test_unit_ready(cd->device, sshdr);
> - if (retval || (scsi_sense_valid(sshdr) &&
> + isvalid = scsi_sense_valid(sshdr);
> +
> + if (!(sr_zpodd_device.flags & SR_IS_ZPODD))
> + goto out_not_zpodd_device;
> +
> + /* Remove the power supply to the drive with no media and
> + * tray closed for tray/drawer/pop-up type drive,
> + * or no media and tray open for caddy/slot type drive.
> + */
> + switch (sr_zpodd_device.mechtype) {
> + case mechtype_caddy:
> + /* 3a/02(asc/ascq) means MEDIUM NOT PRESENT - TRAY OPEN */
> + if (isvalid && (sshdr->asc == 0x3a &&
> + sshdr->ascq == 0x02)) {
> + if (!(sr_zpodd_device.flags & SR_ZPODD_NO_DISK)) {
> + sr_zpodd_device.flags |= SR_ZPODD_NO_DISK;
> + sr_zpodd_device.last_jiffies = jiffies;
> + } else if (time_after(jiffies,
> + sr_zpodd_device.last_jiffies +
> + SR_NO_MEDIA_TIMEOUT)) {
> + acpi_bus_set_power(sr_zpodd_device.handle,
> + ACPI_STATE_D3);
> + }
> + } else
> + sr_zpodd_device.flags &= ~SR_ZPODD_NO_DISK;
> + break;
This thing definitely belongs to struct scsi_cd. What are the
synchronization rules here? Also, what happens if async notification
is in use? How does the timer get activated then?
> + default:
> + /*tray/drawer/pop-up type*/
> + /* 3a/01(asc/ascq) means MEDIUM NOT PRESENT - TRAY CLOSED */
> + if (isvalid && (sshdr->asc == 0x3a &&
> + sshdr->ascq == 0x01)) {
> +
> + /* Eject the tray for a tray type drive*/
> + if (sr_zpodd_device.flags & SR_ZPODD_NEED_EJECT) {
> + sr_tray_move(cdi, 1);
> + sr_zpodd_device.flags &= ~SR_ZPODD_NEED_EJECT;
> + } else if (!(sr_zpodd_device.flags &
> + SR_ZPODD_NO_DISK)) {
> + sr_zpodd_device.flags |= SR_ZPODD_NO_DISK;
> + sr_zpodd_device.last_jiffies = jiffies;
> + } else if (time_after(jiffies,
> + sr_zpodd_device.last_jiffies
> + + SR_NO_MEDIA_TIMEOUT)) {
> + acpi_bus_set_power(sr_zpodd_device.handle,
> + ACPI_STATE_D3);
> + }
> + } else
> + sr_zpodd_device.flags &= ~SR_ZPODD_NO_DISK;
> + break;
> + }
It would probably be better to separate decision making and updating
states.
Thanks.
--
tejun
next prev parent reply other threads:[~2010-06-25 13:39 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-06-25 10:15 [PATCH RFC] support sata odd zero power su henry
2010-06-25 13:39 ` Tejun Heo [this message]
2010-06-28 8:43 ` su henry
2010-06-28 9:04 ` Tejun Heo
2010-06-28 10:42 ` su henry
2010-06-28 12:45 ` Tejun Heo
2010-06-25 14:01 ` James Bottomley
2010-06-28 7:35 ` su henry
2010-06-28 13:42 ` James Bottomley
2010-06-29 1:26 ` su henry
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4C24B184.6050009@gmail.com \
--to=htejun@gmail.com \
--cc=James.Bottomley@suse.de \
--cc=axboe@kernel.dk \
--cc=henry.su.ati@gmail.com \
--cc=linux-scsi@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox