Skip to content

Commit da65bbd

Browse files
committed
ata: libata: Move sector_buf from struct ata_port to struct ata_device
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]>
1 parent 10e8076 commit da65bbd

File tree

6 files changed

+33
-43
lines changed

6 files changed

+33
-43
lines changed

drivers/ata/libata-core.c

Lines changed: 26 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2125,19 +2125,16 @@ unsigned int ata_read_log_page(struct ata_device *dev, u8 log,
21252125

21262126
static int ata_log_supported(struct ata_device *dev, u8 log)
21272127
{
2128-
struct ata_port *ap = dev->link->ap;
2129-
21302128
if (dev->quirks & ATA_QUIRK_NO_LOG_DIR)
21312129
return 0;
21322130

2133-
if (ata_read_log_page(dev, ATA_LOG_DIRECTORY, 0, ap->sector_buf, 1))
2131+
if (ata_read_log_page(dev, ATA_LOG_DIRECTORY, 0, dev->sector_buf, 1))
21342132
return 0;
2135-
return get_unaligned_le16(&ap->sector_buf[log * 2]);
2133+
return get_unaligned_le16(&dev->sector_buf[log * 2]);
21362134
}
21372135

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

21432140
if (dev->quirks & ATA_QUIRK_NO_ID_DEV_LOG)
@@ -2160,13 +2157,13 @@ static bool ata_identify_page_supported(struct ata_device *dev, u8 page)
21602157
* Read IDENTIFY DEVICE data log, page 0, to figure out if the page is
21612158
* supported.
21622159
*/
2163-
err = ata_read_log_page(dev, ATA_LOG_IDENTIFY_DEVICE, 0, ap->sector_buf,
2164-
1);
2160+
err = ata_read_log_page(dev, ATA_LOG_IDENTIFY_DEVICE, 0,
2161+
dev->sector_buf, 1);
21652162
if (err)
21662163
return false;
21672164

2168-
for (i = 0; i < ap->sector_buf[8]; i++) {
2169-
if (ap->sector_buf[9 + i] == page)
2165+
for (i = 0; i < dev->sector_buf[8]; i++) {
2166+
if (dev->sector_buf[9 + i] == page)
21702167
return true;
21712168
}
21722169

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

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

22242220
if (!ata_log_supported(dev, ATA_LOG_NCQ_SEND_RECV)) {
22252221
ata_dev_warn(dev, "NCQ Send/Recv Log not supported\n");
22262222
return;
22272223
}
22282224
err_mask = ata_read_log_page(dev, ATA_LOG_NCQ_SEND_RECV,
2229-
0, ap->sector_buf, 1);
2225+
0, dev->sector_buf, 1);
22302226
if (!err_mask) {
22312227
u8 *cmds = dev->ncq_send_recv_cmds;
22322228

22332229
dev->flags |= ATA_DFLAG_NCQ_SEND_RECV;
2234-
memcpy(cmds, ap->sector_buf, ATA_LOG_NCQ_SEND_RECV_SIZE);
2230+
memcpy(cmds, dev->sector_buf, ATA_LOG_NCQ_SEND_RECV_SIZE);
22352231

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

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

22492244
if (!ata_log_supported(dev, ATA_LOG_NCQ_NON_DATA)) {
@@ -2252,17 +2247,14 @@ static void ata_dev_config_ncq_non_data(struct ata_device *dev)
22522247
return;
22532248
}
22542249
err_mask = ata_read_log_page(dev, ATA_LOG_NCQ_NON_DATA,
2255-
0, ap->sector_buf, 1);
2256-
if (!err_mask) {
2257-
u8 *cmds = dev->ncq_non_data_cmds;
2258-
2259-
memcpy(cmds, ap->sector_buf, ATA_LOG_NCQ_NON_DATA_SIZE);
2260-
}
2250+
0, dev->sector_buf, 1);
2251+
if (!err_mask)
2252+
memcpy(dev->ncq_non_data_cmds, dev->sector_buf,
2253+
ATA_LOG_NCQ_NON_DATA_SIZE);
22612254
}
22622255

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

22682260
if (!ata_identify_page_supported(dev, ATA_LOG_SATA_SETTINGS))
@@ -2271,12 +2263,11 @@ static void ata_dev_config_ncq_prio(struct ata_device *dev)
22712263
err_mask = ata_read_log_page(dev,
22722264
ATA_LOG_IDENTIFY_DEVICE,
22732265
ATA_LOG_SATA_SETTINGS,
2274-
ap->sector_buf,
2275-
1);
2266+
dev->sector_buf, 1);
22762267
if (err_mask)
22772268
goto not_supported;
22782269

2279-
if (!(ap->sector_buf[ATA_LOG_NCQ_PRIO_OFFSET] & BIT(3)))
2270+
if (!(dev->sector_buf[ATA_LOG_NCQ_PRIO_OFFSET] & BIT(3)))
22802271
goto not_supported;
22812272

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

23932384
static void ata_dev_config_zac(struct ata_device *dev)
23942385
{
2395-
struct ata_port *ap = dev->link->ap;
23962386
unsigned int err_mask;
2397-
u8 *identify_buf = ap->sector_buf;
2387+
u8 *identify_buf = dev->sector_buf;
23982388

23992389
dev->zac_zones_optimal_open = U32_MAX;
24002390
dev->zac_zones_optimal_nonseq = U32_MAX;
@@ -2446,7 +2436,6 @@ static void ata_dev_config_zac(struct ata_device *dev)
24462436

24472437
static void ata_dev_config_trusted(struct ata_device *dev)
24482438
{
2449-
struct ata_port *ap = dev->link->ap;
24502439
u64 trusted_cap;
24512440
unsigned int err;
24522441

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

24622451
err = ata_read_log_page(dev, ATA_LOG_IDENTIFY_DEVICE, ATA_LOG_SECURITY,
2463-
ap->sector_buf, 1);
2452+
dev->sector_buf, 1);
24642453
if (err)
24652454
return;
24662455

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

24932482
err_mask = ata_read_log_page(dev, ATA_LOG_IDENTIFY_DEVICE,
24942483
ATA_LOG_SUPPORTED_CAPABILITIES,
2495-
ap->sector_buf, 1);
2484+
dev->sector_buf, 1);
24962485
if (err_mask)
24972486
goto not_supported;
24982487

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

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

2537-
val = get_unaligned_le64(&ap->sector_buf[8]);
2526+
val = get_unaligned_le64(&dev->sector_buf[8]);
25382527
cdl_enabled = val & BIT_ULL(63) && val & BIT_ULL(21);
25392528
if (dev->flags & ATA_DFLAG_CDL_ENABLED) {
25402529
if (!cdl_enabled) {
@@ -2591,13 +2580,13 @@ static void ata_dev_config_cdl(struct ata_device *dev)
25912580
* Command duration limits is supported: cache the CDL log page 18h
25922581
* (command duration descriptors).
25932582
*/
2594-
err_mask = ata_read_log_page(dev, ATA_LOG_CDL, 0, ap->sector_buf, 1);
2583+
err_mask = ata_read_log_page(dev, ATA_LOG_CDL, 0, dev->sector_buf, 1);
25952584
if (err_mask) {
25962585
ata_dev_warn(dev, "Read Command Duration Limits log failed\n");
25972586
goto not_supported;
25982587
}
25992588

2600-
memcpy(dev->cdl, ap->sector_buf, ATA_LOG_CDL_SIZE);
2589+
memcpy(dev->cdl, dev->sector_buf, ATA_LOG_CDL_SIZE);
26012590
dev->flags |= ATA_DFLAG_CDL;
26022591

26032592
return;
@@ -2689,7 +2678,7 @@ static void ata_dev_config_fua(struct ata_device *dev)
26892678

26902679
static void ata_dev_config_devslp(struct ata_device *dev)
26912680
{
2692-
u8 *sata_setting = dev->link->ap->sector_buf;
2681+
u8 *sata_setting = dev->sector_buf;
26932682
unsigned int err_mask;
26942683
int i, j;
26952684

@@ -3759,7 +3748,7 @@ static int ata_dev_same_device(struct ata_device *dev, unsigned int new_class,
37593748
int ata_dev_reread_id(struct ata_device *dev, unsigned int readid_flags)
37603749
{
37613750
unsigned int class = dev->class;
3762-
u16 *id = (void *)dev->link->ap->sector_buf;
3751+
u16 *id = (void *)dev->sector_buf;
37633752
int rc;
37643753

37653754
/* read ID data */

drivers/ata/libata-eh.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3284,7 +3284,7 @@ static int atapi_eh_clear_ua(struct ata_device *dev)
32843284
int i;
32853285

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

drivers/ata/libata-pmp.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -648,8 +648,7 @@ static int sata_pmp_same_pmp(struct ata_device *dev, const u32 *new_gscr)
648648
static int sata_pmp_revalidate(struct ata_device *dev, unsigned int new_class)
649649
{
650650
struct ata_link *link = dev->link;
651-
struct ata_port *ap = link->ap;
652-
u32 *gscr = (void *)ap->sector_buf;
651+
u32 *gscr = (void *)dev->sector_buf;
653652
int rc;
654653

655654
ata_eh_about_to_do(link, NULL, ATA_EH_REVALIDATE);

drivers/ata/libata-sata.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1448,7 +1448,7 @@ EXPORT_SYMBOL_GPL(sata_async_notification);
14481448
static int ata_eh_read_log_10h(struct ata_device *dev,
14491449
int *tag, struct ata_taskfile *tf)
14501450
{
1451-
u8 *buf = dev->link->ap->sector_buf;
1451+
u8 *buf = dev->sector_buf;
14521452
unsigned int err_mask;
14531453
u8 csum;
14541454
int i;

drivers/ata/libata-zpodd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ static bool zpready(struct ata_device *dev)
112112
if (!ret || sense_key != NOT_READY)
113113
return false;
114114

115-
sense_buf = dev->link->ap->sector_buf;
115+
sense_buf = dev->sector_buf;
116116
ret = atapi_eh_request_sense(dev, sense_buf, sense_key);
117117
if (ret)
118118
return false;

include/linux/libata.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,9 @@ struct ata_device {
769769
int spdn_cnt;
770770
/* ering is CLEAR_END, read comment above CLEAR_END */
771771
struct ata_ering ering;
772+
773+
/* For EH */
774+
u8 sector_buf[ATA_SECT_SIZE] ____cacheline_aligned;
772775
};
773776

774777
/* Fields between ATA_DEVICE_CLEAR_BEGIN and ATA_DEVICE_CLEAR_END are
@@ -916,7 +919,6 @@ struct ata_port {
916919
#endif
917920
/* owned by EH */
918921
u8 *ncq_sense_buf;
919-
u8 sector_buf[ATA_SECT_SIZE] ____cacheline_aligned;
920922
};
921923

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

0 commit comments

Comments
 (0)