Skip to content

Commit 9e6938e

Browse files
committed
ata: libata-core: Remove ata_exec_internal_sg()
ata_exec_internal() is the only caller of ata_exec_internal_sg() and always calls this function with a single element scattergather list. Remove ata_exec_internal_sg() and code it directly in ata_exec_internal(), simplifying a little the sgl handling for the command. While at it, change the function signature to use the proper enum dma_data_direction type for the dma_dir argument, cleanup comments (capitalization and remove useless comments) and change the variable auto_timeout type to a boolean. No functional change. Signed-off-by: Damien Le Moal <[email protected]> Reviewed-by: John Garry <[email protected]> Reviewed-by: Niklas Cassel <[email protected]>
1 parent 21a6f37 commit 9e6938e

File tree

2 files changed

+36
-80
lines changed

2 files changed

+36
-80
lines changed

drivers/ata/libata-core.c

Lines changed: 32 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1480,19 +1480,19 @@ static void ata_qc_complete_internal(struct ata_queued_cmd *qc)
14801480
}
14811481

14821482
/**
1483-
* ata_exec_internal_sg - execute libata internal command
1483+
* ata_exec_internal - execute libata internal command
14841484
* @dev: Device to which the command is sent
14851485
* @tf: Taskfile registers for the command and the result
14861486
* @cdb: CDB for packet command
14871487
* @dma_dir: Data transfer direction of the command
1488-
* @sgl: sg list for the data buffer of the command
1489-
* @n_elem: Number of sg entries
1488+
* @buf: Data buffer of the command
1489+
* @buflen: Length of data buffer
14901490
* @timeout: Timeout in msecs (0 for default)
14911491
*
1492-
* Executes libata internal command with timeout. @tf contains
1493-
* command on entry and result on return. Timeout and error
1494-
* conditions are reported via return value. No recovery action
1495-
* is taken after a command times out. It's caller's duty to
1492+
* Executes libata internal command with timeout. @tf contains
1493+
* the command on entry and the result on return. Timeout and error
1494+
* conditions are reported via the return value. No recovery action
1495+
* is taken after a command times out. It is the caller's duty to
14961496
* clean up after timeout.
14971497
*
14981498
* LOCKING:
@@ -1501,34 +1501,38 @@ static void ata_qc_complete_internal(struct ata_queued_cmd *qc)
15011501
* RETURNS:
15021502
* Zero on success, AC_ERR_* mask on failure
15031503
*/
1504-
static unsigned ata_exec_internal_sg(struct ata_device *dev,
1505-
struct ata_taskfile *tf, const u8 *cdb,
1506-
int dma_dir, struct scatterlist *sgl,
1507-
unsigned int n_elem, unsigned int timeout)
1504+
unsigned int ata_exec_internal(struct ata_device *dev, struct ata_taskfile *tf,
1505+
const u8 *cdb, enum dma_data_direction dma_dir,
1506+
void *buf, unsigned int buflen,
1507+
unsigned int timeout)
15081508
{
15091509
struct ata_link *link = dev->link;
15101510
struct ata_port *ap = link->ap;
15111511
u8 command = tf->command;
1512-
int auto_timeout = 0;
15131512
struct ata_queued_cmd *qc;
1513+
struct scatterlist sgl;
15141514
unsigned int preempted_tag;
15151515
u32 preempted_sactive;
15161516
u64 preempted_qc_active;
15171517
int preempted_nr_active_links;
1518+
bool auto_timeout = false;
15181519
DECLARE_COMPLETION_ONSTACK(wait);
15191520
unsigned long flags;
15201521
unsigned int err_mask;
15211522
int rc;
15221523

1524+
if (WARN_ON(dma_dir != DMA_NONE && !buf))
1525+
return AC_ERR_INVALID;
1526+
15231527
spin_lock_irqsave(ap->lock, flags);
15241528

1525-
/* no internal command while frozen */
1529+
/* No internal command while frozen */
15261530
if (ata_port_is_frozen(ap)) {
15271531
spin_unlock_irqrestore(ap->lock, flags);
15281532
return AC_ERR_SYSTEM;
15291533
}
15301534

1531-
/* initialize internal qc */
1535+
/* Initialize internal qc */
15321536
qc = __ata_qc_from_tag(ap, ATA_TAG_INTERNAL);
15331537

15341538
qc->tag = ATA_TAG_INTERNAL;
@@ -1547,26 +1551,21 @@ static unsigned ata_exec_internal_sg(struct ata_device *dev,
15471551
ap->qc_active = 0;
15481552
ap->nr_active_links = 0;
15491553

1550-
/* prepare & issue qc */
1554+
/* Prepare and issue qc */
15511555
qc->tf = *tf;
15521556
if (cdb)
15531557
memcpy(qc->cdb, cdb, ATAPI_CDB_LEN);
15541558

1555-
/* some SATA bridges need us to indicate data xfer direction */
1559+
/* Some SATA bridges need us to indicate data xfer direction */
15561560
if (tf->protocol == ATAPI_PROT_DMA && (dev->flags & ATA_DFLAG_DMADIR) &&
15571561
dma_dir == DMA_FROM_DEVICE)
15581562
qc->tf.feature |= ATAPI_DMADIR;
15591563

15601564
qc->flags |= ATA_QCFLAG_RESULT_TF;
15611565
qc->dma_dir = dma_dir;
15621566
if (dma_dir != DMA_NONE) {
1563-
unsigned int i, buflen = 0;
1564-
struct scatterlist *sg;
1565-
1566-
for_each_sg(sgl, sg, n_elem, i)
1567-
buflen += sg->length;
1568-
1569-
ata_sg_init(qc, sgl, n_elem);
1567+
sg_init_one(&sgl, buf, buflen);
1568+
ata_sg_init(qc, &sgl, 1);
15701569
qc->nbytes = buflen;
15711570
}
15721571

@@ -1578,11 +1577,11 @@ static unsigned ata_exec_internal_sg(struct ata_device *dev,
15781577
spin_unlock_irqrestore(ap->lock, flags);
15791578

15801579
if (!timeout) {
1581-
if (ata_probe_timeout)
1580+
if (ata_probe_timeout) {
15821581
timeout = ata_probe_timeout * 1000;
1583-
else {
1582+
} else {
15841583
timeout = ata_internal_cmd_timeout(dev, command);
1585-
auto_timeout = 1;
1584+
auto_timeout = true;
15861585
}
15871586
}
15881587

@@ -1595,30 +1594,25 @@ static unsigned ata_exec_internal_sg(struct ata_device *dev,
15951594
ata_sff_flush_pio_task(ap);
15961595

15971596
if (!rc) {
1598-
spin_lock_irqsave(ap->lock, flags);
1599-
1600-
/* We're racing with irq here. If we lose, the
1601-
* following test prevents us from completing the qc
1602-
* twice. If we win, the port is frozen and will be
1603-
* cleaned up by ->post_internal_cmd().
1597+
/*
1598+
* We are racing with irq here. If we lose, the following test
1599+
* prevents us from completing the qc twice. If we win, the port
1600+
* is frozen and will be cleaned up by ->post_internal_cmd().
16041601
*/
1602+
spin_lock_irqsave(ap->lock, flags);
16051603
if (qc->flags & ATA_QCFLAG_ACTIVE) {
16061604
qc->err_mask |= AC_ERR_TIMEOUT;
1607-
16081605
ata_port_freeze(ap);
1609-
16101606
ata_dev_warn(dev, "qc timeout after %u msecs (cmd 0x%x)\n",
16111607
timeout, command);
16121608
}
1613-
16141609
spin_unlock_irqrestore(ap->lock, flags);
16151610
}
16161611

1617-
/* do post_internal_cmd */
16181612
if (ap->ops->post_internal_cmd)
16191613
ap->ops->post_internal_cmd(qc);
16201614

1621-
/* perform minimal error analysis */
1615+
/* Perform minimal error analysis */
16221616
if (qc->flags & ATA_QCFLAG_EH) {
16231617
if (qc->result_tf.status & (ATA_ERR | ATA_DF))
16241618
qc->err_mask |= AC_ERR_DEV;
@@ -1632,7 +1626,7 @@ static unsigned ata_exec_internal_sg(struct ata_device *dev,
16321626
qc->result_tf.status |= ATA_SENSE;
16331627
}
16341628

1635-
/* finish up */
1629+
/* Finish up */
16361630
spin_lock_irqsave(ap->lock, flags);
16371631

16381632
*tf = qc->result_tf;
@@ -1652,44 +1646,6 @@ static unsigned ata_exec_internal_sg(struct ata_device *dev,
16521646
return err_mask;
16531647
}
16541648

1655-
/**
1656-
* ata_exec_internal - execute libata internal command
1657-
* @dev: Device to which the command is sent
1658-
* @tf: Taskfile registers for the command and the result
1659-
* @cdb: CDB for packet command
1660-
* @dma_dir: Data transfer direction of the command
1661-
* @buf: Data buffer of the command
1662-
* @buflen: Length of data buffer
1663-
* @timeout: Timeout in msecs (0 for default)
1664-
*
1665-
* Wrapper around ata_exec_internal_sg() which takes simple
1666-
* buffer instead of sg list.
1667-
*
1668-
* LOCKING:
1669-
* None. Should be called with kernel context, might sleep.
1670-
*
1671-
* RETURNS:
1672-
* Zero on success, AC_ERR_* mask on failure
1673-
*/
1674-
unsigned ata_exec_internal(struct ata_device *dev,
1675-
struct ata_taskfile *tf, const u8 *cdb,
1676-
int dma_dir, void *buf, unsigned int buflen,
1677-
unsigned int timeout)
1678-
{
1679-
struct scatterlist *psg = NULL, sg;
1680-
unsigned int n_elem = 0;
1681-
1682-
if (dma_dir != DMA_NONE) {
1683-
WARN_ON(!buf);
1684-
sg_init_one(&sg, buf, buflen);
1685-
psg = &sg;
1686-
n_elem++;
1687-
}
1688-
1689-
return ata_exec_internal_sg(dev, tf, cdb, dma_dir, psg, n_elem,
1690-
timeout);
1691-
}
1692-
16931649
/**
16941650
* ata_pio_need_iordy - check if iordy needed
16951651
* @adev: ATA device

drivers/ata/libata.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ extern int ata_build_rw_tf(struct ata_queued_cmd *qc, u64 block, u32 n_block,
5050
unsigned int tf_flags, int dld, int class);
5151
extern u64 ata_tf_read_block(const struct ata_taskfile *tf,
5252
struct ata_device *dev);
53-
extern unsigned ata_exec_internal(struct ata_device *dev,
54-
struct ata_taskfile *tf, const u8 *cdb,
55-
int dma_dir, void *buf, unsigned int buflen,
56-
unsigned int timeout);
53+
unsigned int ata_exec_internal(struct ata_device *dev, struct ata_taskfile *tf,
54+
const u8 *cdb, enum dma_data_direction dma_dir,
55+
void *buf, unsigned int buflen,
56+
unsigned int timeout);
5757
extern int ata_wait_ready(struct ata_link *link, unsigned long deadline,
5858
int (*check_ready)(struct ata_link *link));
5959
extern int ata_dev_read_id(struct ata_device *dev, unsigned int *p_class,

0 commit comments

Comments
 (0)