Skip to content

Commit 03c0e84

Browse files
Sergey ShtylyovDamien Le Moal
authored andcommitted
ata: libata-sff: refactor ata_sff_altstatus()
The driver's calls to ata_sff_altstatus() are mostly surrounded by some clumsy checks. Refactor ata_sff_altstatus() to include the repetitive checks and return a 'bool' result indicating if the alternate status register exists or not. While at it, further update the 'kernel-doc' comment -- the alternate status register has never been a part of the taskfile, despite what Jeff and co. think! :-) In ata_sff_lost_interrupt(), wrap the ata_sff_altstatus() call in a WARN_ON_ONCE() check to issue a warning if the device control register does not exist. And while at it, fix the strange argument indentation in the ata_port_warn() call following the call to ata_sff_altstatus(). Signed-off-by: Sergey Shtylyov <s.shtylyov@omp.ru> Signed-off-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>
1 parent 4fc5f0a commit 03c0e84

File tree

1 file changed

+33
-26
lines changed

1 file changed

+33
-26
lines changed

drivers/ata/libata-sff.c

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -70,22 +70,35 @@ EXPORT_SYMBOL_GPL(ata_sff_check_status);
7070
/**
7171
* ata_sff_altstatus - Read device alternate status reg
7272
* @ap: port where the device is
73+
* @status: pointer to a status value
7374
*
74-
* Reads ATA taskfile alternate status register for
75-
* currently-selected device and return its value.
75+
* Reads ATA alternate status register for currently-selected device
76+
* and return its value.
7677
*
77-
* Note: may NOT be used as the check_altstatus() entry in
78-
* ata_port_operations.
78+
* RETURN:
79+
* true if the register exists, false if not.
7980
*
8081
* LOCKING:
8182
* Inherited from caller.
8283
*/
83-
static u8 ata_sff_altstatus(struct ata_port *ap)
84+
static bool ata_sff_altstatus(struct ata_port *ap, u8 *status)
8485
{
85-
if (ap->ops->sff_check_altstatus)
86-
return ap->ops->sff_check_altstatus(ap);
86+
u8 tmp;
87+
88+
if (ap->ops->sff_check_altstatus) {
89+
tmp = ap->ops->sff_check_altstatus(ap);
90+
goto read;
91+
}
92+
if (ap->ioaddr.altstatus_addr) {
93+
tmp = ioread8(ap->ioaddr.altstatus_addr);
94+
goto read;
95+
}
96+
return false;
8797

88-
return ioread8(ap->ioaddr.altstatus_addr);
98+
read:
99+
if (status)
100+
*status = tmp;
101+
return true;
89102
}
90103

91104
/**
@@ -104,12 +117,9 @@ static u8 ata_sff_irq_status(struct ata_port *ap)
104117
{
105118
u8 status;
106119

107-
if (ap->ops->sff_check_altstatus || ap->ioaddr.altstatus_addr) {
108-
status = ata_sff_altstatus(ap);
109-
/* Not us: We are busy */
110-
if (status & ATA_BUSY)
111-
return status;
112-
}
120+
/* Not us: We are busy */
121+
if (ata_sff_altstatus(ap, &status) && (status & ATA_BUSY))
122+
return status;
113123
/* Clear INTRQ latch */
114124
status = ap->ops->sff_check_status(ap);
115125
return status;
@@ -129,10 +139,7 @@ static u8 ata_sff_irq_status(struct ata_port *ap)
129139

130140
static void ata_sff_sync(struct ata_port *ap)
131141
{
132-
if (ap->ops->sff_check_altstatus)
133-
ap->ops->sff_check_altstatus(ap);
134-
else if (ap->ioaddr.altstatus_addr)
135-
ioread8(ap->ioaddr.altstatus_addr);
142+
ata_sff_altstatus(ap, NULL);
136143
}
137144

138145
/**
@@ -164,12 +171,12 @@ EXPORT_SYMBOL_GPL(ata_sff_pause);
164171

165172
void ata_sff_dma_pause(struct ata_port *ap)
166173
{
167-
if (ap->ops->sff_check_altstatus || ap->ioaddr.altstatus_addr) {
168-
/* An altstatus read will cause the needed delay without
169-
messing up the IRQ status */
170-
ata_sff_altstatus(ap);
174+
/*
175+
* An altstatus read will cause the needed delay without
176+
* messing up the IRQ status
177+
*/
178+
if (ata_sff_altstatus(ap, NULL))
171179
return;
172-
}
173180
/* There are no DMA controllers without ctl. BUG here to ensure
174181
we never violate the HDMA1:0 transition timing and risk
175182
corruption. */
@@ -1637,14 +1644,14 @@ void ata_sff_lost_interrupt(struct ata_port *ap)
16371644
return;
16381645
/* See if the controller thinks it is still busy - if so the command
16391646
isn't a lost IRQ but is still in progress */
1640-
status = ata_sff_altstatus(ap);
1647+
if (WARN_ON_ONCE(!ata_sff_altstatus(ap, &status)))
1648+
return;
16411649
if (status & ATA_BUSY)
16421650
return;
16431651

16441652
/* There was a command running, we are no longer busy and we have
16451653
no interrupt. */
1646-
ata_port_warn(ap, "lost interrupt (Status 0x%x)\n",
1647-
status);
1654+
ata_port_warn(ap, "lost interrupt (Status 0x%x)\n", status);
16481655
/* Run the host interrupt logic as if the interrupt had not been
16491656
lost */
16501657
ata_sff_port_intr(ap, qc);

0 commit comments

Comments
 (0)