Skip to content

Commit

Permalink
ata: libata: Move sector_buf from struct ata_port to struct ata_device
Browse files Browse the repository at this point in the history
The 512B buffer sector_buf field of struct ata_port is used for scanning
devices as well as during error recovery with ata EH. This buffer is
thus useless if a port does not have a device connected to it.
And also given that commands using this buffer are issued to devices,
and not to ports, move this buffer definition from struct ata_port to
struct ata_device.

This change slightly increases system memory usage for systems using a
port-multiplier as in that case we do not need a per-device buffer for
scanning devices (PMP does not allow parallel scanning) nor for EH (as
when entering EH we are guaranteed that all commands to all devices
connected to the PMP have completed or have been aborted). However,
this change reduces memory usage on systems that have many ports with
only few devices rives connected, which is a much more common use case
than the PMP use case.

Suggested-by: Niklas Cassel <[email protected]>
Signed-off-by: Damien Le Moal <[email protected]>
Reviewed-by: Hannes Reinecke <[email protected]>
Reviewed-by: Niklas Cassel <[email protected]>
  • Loading branch information
damien-lemoal committed Sep 7, 2024
1 parent 10e8076 commit da65bbd
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 43 deletions.
63 changes: 26 additions & 37 deletions drivers/ata/libata-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -2125,19 +2125,16 @@ unsigned int ata_read_log_page(struct ata_device *dev, u8 log,

static int ata_log_supported(struct ata_device *dev, u8 log)
{
struct ata_port *ap = dev->link->ap;

if (dev->quirks & ATA_QUIRK_NO_LOG_DIR)
return 0;

if (ata_read_log_page(dev, ATA_LOG_DIRECTORY, 0, ap->sector_buf, 1))
if (ata_read_log_page(dev, ATA_LOG_DIRECTORY, 0, dev->sector_buf, 1))
return 0;
return get_unaligned_le16(&ap->sector_buf[log * 2]);
return get_unaligned_le16(&dev->sector_buf[log * 2]);
}

static bool ata_identify_page_supported(struct ata_device *dev, u8 page)
{
struct ata_port *ap = dev->link->ap;
unsigned int err, i;

if (dev->quirks & ATA_QUIRK_NO_ID_DEV_LOG)
Expand All @@ -2160,13 +2157,13 @@ static bool ata_identify_page_supported(struct ata_device *dev, u8 page)
* Read IDENTIFY DEVICE data log, page 0, to figure out if the page is
* supported.
*/
err = ata_read_log_page(dev, ATA_LOG_IDENTIFY_DEVICE, 0, ap->sector_buf,
1);
err = ata_read_log_page(dev, ATA_LOG_IDENTIFY_DEVICE, 0,
dev->sector_buf, 1);
if (err)
return false;

for (i = 0; i < ap->sector_buf[8]; i++) {
if (ap->sector_buf[9 + i] == page)
for (i = 0; i < dev->sector_buf[8]; i++) {
if (dev->sector_buf[9 + i] == page)
return true;
}

Expand Down Expand Up @@ -2218,20 +2215,19 @@ static inline bool ata_dev_knobble(struct ata_device *dev)

static void ata_dev_config_ncq_send_recv(struct ata_device *dev)
{
struct ata_port *ap = dev->link->ap;
unsigned int err_mask;

if (!ata_log_supported(dev, ATA_LOG_NCQ_SEND_RECV)) {
ata_dev_warn(dev, "NCQ Send/Recv Log not supported\n");
return;
}
err_mask = ata_read_log_page(dev, ATA_LOG_NCQ_SEND_RECV,
0, ap->sector_buf, 1);
0, dev->sector_buf, 1);
if (!err_mask) {
u8 *cmds = dev->ncq_send_recv_cmds;

dev->flags |= ATA_DFLAG_NCQ_SEND_RECV;
memcpy(cmds, ap->sector_buf, ATA_LOG_NCQ_SEND_RECV_SIZE);
memcpy(cmds, dev->sector_buf, ATA_LOG_NCQ_SEND_RECV_SIZE);

if (dev->quirks & ATA_QUIRK_NO_NCQ_TRIM) {
ata_dev_dbg(dev, "disabling queued TRIM support\n");
Expand All @@ -2243,7 +2239,6 @@ static void ata_dev_config_ncq_send_recv(struct ata_device *dev)

static void ata_dev_config_ncq_non_data(struct ata_device *dev)
{
struct ata_port *ap = dev->link->ap;
unsigned int err_mask;

if (!ata_log_supported(dev, ATA_LOG_NCQ_NON_DATA)) {
Expand All @@ -2252,17 +2247,14 @@ static void ata_dev_config_ncq_non_data(struct ata_device *dev)
return;
}
err_mask = ata_read_log_page(dev, ATA_LOG_NCQ_NON_DATA,
0, ap->sector_buf, 1);
if (!err_mask) {
u8 *cmds = dev->ncq_non_data_cmds;

memcpy(cmds, ap->sector_buf, ATA_LOG_NCQ_NON_DATA_SIZE);
}
0, dev->sector_buf, 1);
if (!err_mask)
memcpy(dev->ncq_non_data_cmds, dev->sector_buf,
ATA_LOG_NCQ_NON_DATA_SIZE);
}

static void ata_dev_config_ncq_prio(struct ata_device *dev)
{
struct ata_port *ap = dev->link->ap;
unsigned int err_mask;

if (!ata_identify_page_supported(dev, ATA_LOG_SATA_SETTINGS))
Expand All @@ -2271,12 +2263,11 @@ static void ata_dev_config_ncq_prio(struct ata_device *dev)
err_mask = ata_read_log_page(dev,
ATA_LOG_IDENTIFY_DEVICE,
ATA_LOG_SATA_SETTINGS,
ap->sector_buf,
1);
dev->sector_buf, 1);
if (err_mask)
goto not_supported;

if (!(ap->sector_buf[ATA_LOG_NCQ_PRIO_OFFSET] & BIT(3)))
if (!(dev->sector_buf[ATA_LOG_NCQ_PRIO_OFFSET] & BIT(3)))
goto not_supported;

dev->flags |= ATA_DFLAG_NCQ_PRIO;
Expand Down Expand Up @@ -2392,9 +2383,8 @@ static void ata_dev_config_sense_reporting(struct ata_device *dev)

static void ata_dev_config_zac(struct ata_device *dev)
{
struct ata_port *ap = dev->link->ap;
unsigned int err_mask;
u8 *identify_buf = ap->sector_buf;
u8 *identify_buf = dev->sector_buf;

dev->zac_zones_optimal_open = U32_MAX;
dev->zac_zones_optimal_nonseq = U32_MAX;
Expand Down Expand Up @@ -2446,7 +2436,6 @@ static void ata_dev_config_zac(struct ata_device *dev)

static void ata_dev_config_trusted(struct ata_device *dev)
{
struct ata_port *ap = dev->link->ap;
u64 trusted_cap;
unsigned int err;

Expand All @@ -2460,11 +2449,11 @@ static void ata_dev_config_trusted(struct ata_device *dev)
}

err = ata_read_log_page(dev, ATA_LOG_IDENTIFY_DEVICE, ATA_LOG_SECURITY,
ap->sector_buf, 1);
dev->sector_buf, 1);
if (err)
return;

trusted_cap = get_unaligned_le64(&ap->sector_buf[40]);
trusted_cap = get_unaligned_le64(&dev->sector_buf[40]);
if (!(trusted_cap & (1ULL << 63))) {
ata_dev_dbg(dev,
"Trusted Computing capability qword not valid!\n");
Expand Down Expand Up @@ -2492,12 +2481,12 @@ static void ata_dev_config_cdl(struct ata_device *dev)

err_mask = ata_read_log_page(dev, ATA_LOG_IDENTIFY_DEVICE,
ATA_LOG_SUPPORTED_CAPABILITIES,
ap->sector_buf, 1);
dev->sector_buf, 1);
if (err_mask)
goto not_supported;

/* Check Command Duration Limit Supported bits */
val = get_unaligned_le64(&ap->sector_buf[168]);
val = get_unaligned_le64(&dev->sector_buf[168]);
if (!(val & BIT_ULL(63)) || !(val & BIT_ULL(0)))
goto not_supported;

Expand All @@ -2510,7 +2499,7 @@ static void ata_dev_config_cdl(struct ata_device *dev)
* We must have support for the sense data for successful NCQ commands
* log indicated by the successful NCQ command sense data supported bit.
*/
val = get_unaligned_le64(&ap->sector_buf[8]);
val = get_unaligned_le64(&dev->sector_buf[8]);
if (!(val & BIT_ULL(63)) || !(val & BIT_ULL(47))) {
ata_dev_warn(dev,
"CDL supported but Successful NCQ Command Sense Data is not supported\n");
Expand All @@ -2530,11 +2519,11 @@ static void ata_dev_config_cdl(struct ata_device *dev)
*/
err_mask = ata_read_log_page(dev, ATA_LOG_IDENTIFY_DEVICE,
ATA_LOG_CURRENT_SETTINGS,
ap->sector_buf, 1);
dev->sector_buf, 1);
if (err_mask)
goto not_supported;

val = get_unaligned_le64(&ap->sector_buf[8]);
val = get_unaligned_le64(&dev->sector_buf[8]);
cdl_enabled = val & BIT_ULL(63) && val & BIT_ULL(21);
if (dev->flags & ATA_DFLAG_CDL_ENABLED) {
if (!cdl_enabled) {
Expand Down Expand Up @@ -2591,13 +2580,13 @@ static void ata_dev_config_cdl(struct ata_device *dev)
* Command duration limits is supported: cache the CDL log page 18h
* (command duration descriptors).
*/
err_mask = ata_read_log_page(dev, ATA_LOG_CDL, 0, ap->sector_buf, 1);
err_mask = ata_read_log_page(dev, ATA_LOG_CDL, 0, dev->sector_buf, 1);
if (err_mask) {
ata_dev_warn(dev, "Read Command Duration Limits log failed\n");
goto not_supported;
}

memcpy(dev->cdl, ap->sector_buf, ATA_LOG_CDL_SIZE);
memcpy(dev->cdl, dev->sector_buf, ATA_LOG_CDL_SIZE);
dev->flags |= ATA_DFLAG_CDL;

return;
Expand Down Expand Up @@ -2689,7 +2678,7 @@ static void ata_dev_config_fua(struct ata_device *dev)

static void ata_dev_config_devslp(struct ata_device *dev)
{
u8 *sata_setting = dev->link->ap->sector_buf;
u8 *sata_setting = dev->sector_buf;
unsigned int err_mask;
int i, j;

Expand Down Expand Up @@ -3759,7 +3748,7 @@ static int ata_dev_same_device(struct ata_device *dev, unsigned int new_class,
int ata_dev_reread_id(struct ata_device *dev, unsigned int readid_flags)
{
unsigned int class = dev->class;
u16 *id = (void *)dev->link->ap->sector_buf;
u16 *id = (void *)dev->sector_buf;
int rc;

/* read ID data */
Expand Down
2 changes: 1 addition & 1 deletion drivers/ata/libata-eh.c
Original file line number Diff line number Diff line change
Expand Up @@ -3284,7 +3284,7 @@ static int atapi_eh_clear_ua(struct ata_device *dev)
int i;

for (i = 0; i < ATA_EH_UA_TRIES; i++) {
u8 *sense_buffer = dev->link->ap->sector_buf;
u8 *sense_buffer = dev->sector_buf;
u8 sense_key = 0;
unsigned int err_mask;

Expand Down
3 changes: 1 addition & 2 deletions drivers/ata/libata-pmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -648,8 +648,7 @@ static int sata_pmp_same_pmp(struct ata_device *dev, const u32 *new_gscr)
static int sata_pmp_revalidate(struct ata_device *dev, unsigned int new_class)
{
struct ata_link *link = dev->link;
struct ata_port *ap = link->ap;
u32 *gscr = (void *)ap->sector_buf;
u32 *gscr = (void *)dev->sector_buf;
int rc;

ata_eh_about_to_do(link, NULL, ATA_EH_REVALIDATE);
Expand Down
2 changes: 1 addition & 1 deletion drivers/ata/libata-sata.c
Original file line number Diff line number Diff line change
Expand Up @@ -1448,7 +1448,7 @@ EXPORT_SYMBOL_GPL(sata_async_notification);
static int ata_eh_read_log_10h(struct ata_device *dev,
int *tag, struct ata_taskfile *tf)
{
u8 *buf = dev->link->ap->sector_buf;
u8 *buf = dev->sector_buf;
unsigned int err_mask;
u8 csum;
int i;
Expand Down
2 changes: 1 addition & 1 deletion drivers/ata/libata-zpodd.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ static bool zpready(struct ata_device *dev)
if (!ret || sense_key != NOT_READY)
return false;

sense_buf = dev->link->ap->sector_buf;
sense_buf = dev->sector_buf;
ret = atapi_eh_request_sense(dev, sense_buf, sense_key);
if (ret)
return false;
Expand Down
4 changes: 3 additions & 1 deletion include/linux/libata.h
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,9 @@ struct ata_device {
int spdn_cnt;
/* ering is CLEAR_END, read comment above CLEAR_END */
struct ata_ering ering;

/* For EH */
u8 sector_buf[ATA_SECT_SIZE] ____cacheline_aligned;
};

/* Fields between ATA_DEVICE_CLEAR_BEGIN and ATA_DEVICE_CLEAR_END are
Expand Down Expand Up @@ -916,7 +919,6 @@ struct ata_port {
#endif
/* owned by EH */
u8 *ncq_sense_buf;
u8 sector_buf[ATA_SECT_SIZE] ____cacheline_aligned;
};

/* The following initializer overrides a method to NULL whether one of
Expand Down

0 comments on commit da65bbd

Please sign in to comment.