Skip to content

Commit e4f7bdc

Browse files
committed
Merge branch 'for-4.7-zac' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/libata
Pull libata ZAC support from Tejun Heo: "This contains Zone ATA Command support for Shingled Magnetic Recording devices. In addition to sending the new commands down to the device, as ZAC commands depend on getting a lot of responses from the device, piping up responses is beefed up too. However, it doesn't involve changes to libata core mechanism or its interaction with upper layers, so I'm not expecting too many fallouts. Kudos to Hannes for driving SMR support" * 'for-4.7-zac' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/libata: (28 commits) libata: support host-aware and host-managed ZAC devices libata: support device-managed ZAC devices libata: NCQ encapsulation for ZAC MANAGEMENT OUT libata: Implement ZBC OUT translation libata: implement ZBC IN translation libata: fixup ZAC device disabling libata-scsi: Generate sense code for disabled devices libata-trace: decode subcommands libata: Check log page directory before accessing pages libata: Add command definitions for NCQ Encapsulation for READ LOG DMA EXT libata: Separate out ata_dev_config_ncq_send_recv() libata/libsas: Define ATA_CMD_NCQ_NON_DATA libsas: enable FPDMA SEND/RECEIVE libata: do not attempt to retrieve sense code twice libata-scsi: Set information sense field for invalid parameter libata-scsi: set bit pointer for sense code information libata-scsi: Set field pointer in sense code scsi: add scsi_set_sense_field_pointer() libata: Implement control mode page to select sense format libata-scsi: generate correct ATA pass-through sense ...
2 parents 3159ee5 + 6d1003a commit e4f7bdc

17 files changed

Lines changed: 1179 additions & 181 deletions

File tree

‎drivers/ata/libata-core.c‎

Lines changed: 194 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
#include <scsi/scsi_host.h>
6767
#include <linux/libata.h>
6868
#include <asm/byteorder.h>
69+
#include <asm/unaligned.h>
6970
#include <linux/cdrom.h>
7071
#include <linux/ratelimit.h>
7172
#include <linux/pm_runtime.h>
@@ -695,7 +696,7 @@ static int ata_rwcmd_protocol(struct ata_taskfile *tf, struct ata_device *dev)
695696
* RETURNS:
696697
* Block address read from @tf.
697698
*/
698-
u64 ata_tf_read_block(struct ata_taskfile *tf, struct ata_device *dev)
699+
u64 ata_tf_read_block(const struct ata_taskfile *tf, struct ata_device *dev)
699700
{
700701
u64 block = 0;
701702

@@ -720,7 +721,7 @@ u64 ata_tf_read_block(struct ata_taskfile *tf, struct ata_device *dev)
720721
if (!sect) {
721722
ata_dev_warn(dev,
722723
"device reported invalid CHS sector 0\n");
723-
sect = 1; /* oh well */
724+
return U64_MAX;
724725
}
725726

726727
block = (cyl * dev->heads + head) * dev->sectors + sect - 1;
@@ -2079,6 +2080,81 @@ static inline u8 ata_dev_knobble(struct ata_device *dev)
20792080
return ((ap->cbl == ATA_CBL_SATA) && (!ata_id_is_sata(dev->id)));
20802081
}
20812082

2083+
static void ata_dev_config_ncq_send_recv(struct ata_device *dev)
2084+
{
2085+
struct ata_port *ap = dev->link->ap;
2086+
unsigned int err_mask;
2087+
int log_index = ATA_LOG_NCQ_SEND_RECV * 2;
2088+
u16 log_pages;
2089+
2090+
err_mask = ata_read_log_page(dev, ATA_LOG_DIRECTORY,
2091+
0, ap->sector_buf, 1);
2092+
if (err_mask) {
2093+
ata_dev_dbg(dev,
2094+
"failed to get Log Directory Emask 0x%x\n",
2095+
err_mask);
2096+
return;
2097+
}
2098+
log_pages = get_unaligned_le16(&ap->sector_buf[log_index]);
2099+
if (!log_pages) {
2100+
ata_dev_warn(dev,
2101+
"NCQ Send/Recv Log not supported\n");
2102+
return;
2103+
}
2104+
err_mask = ata_read_log_page(dev, ATA_LOG_NCQ_SEND_RECV,
2105+
0, ap->sector_buf, 1);
2106+
if (err_mask) {
2107+
ata_dev_dbg(dev,
2108+
"failed to get NCQ Send/Recv Log Emask 0x%x\n",
2109+
err_mask);
2110+
} else {
2111+
u8 *cmds = dev->ncq_send_recv_cmds;
2112+
2113+
dev->flags |= ATA_DFLAG_NCQ_SEND_RECV;
2114+
memcpy(cmds, ap->sector_buf, ATA_LOG_NCQ_SEND_RECV_SIZE);
2115+
2116+
if (dev->horkage & ATA_HORKAGE_NO_NCQ_TRIM) {
2117+
ata_dev_dbg(dev, "disabling queued TRIM support\n");
2118+
cmds[ATA_LOG_NCQ_SEND_RECV_DSM_OFFSET] &=
2119+
~ATA_LOG_NCQ_SEND_RECV_DSM_TRIM;
2120+
}
2121+
}
2122+
}
2123+
2124+
static void ata_dev_config_ncq_non_data(struct ata_device *dev)
2125+
{
2126+
struct ata_port *ap = dev->link->ap;
2127+
unsigned int err_mask;
2128+
int log_index = ATA_LOG_NCQ_NON_DATA * 2;
2129+
u16 log_pages;
2130+
2131+
err_mask = ata_read_log_page(dev, ATA_LOG_DIRECTORY,
2132+
0, ap->sector_buf, 1);
2133+
if (err_mask) {
2134+
ata_dev_dbg(dev,
2135+
"failed to get Log Directory Emask 0x%x\n",
2136+
err_mask);
2137+
return;
2138+
}
2139+
log_pages = get_unaligned_le16(&ap->sector_buf[log_index]);
2140+
if (!log_pages) {
2141+
ata_dev_warn(dev,
2142+
"NCQ Send/Recv Log not supported\n");
2143+
return;
2144+
}
2145+
err_mask = ata_read_log_page(dev, ATA_LOG_NCQ_NON_DATA,
2146+
0, ap->sector_buf, 1);
2147+
if (err_mask) {
2148+
ata_dev_dbg(dev,
2149+
"failed to get NCQ Non-Data Log Emask 0x%x\n",
2150+
err_mask);
2151+
} else {
2152+
u8 *cmds = dev->ncq_non_data_cmds;
2153+
2154+
memcpy(cmds, ap->sector_buf, ATA_LOG_NCQ_NON_DATA_SIZE);
2155+
}
2156+
}
2157+
20822158
static int ata_dev_config_ncq(struct ata_device *dev,
20832159
char *desc, size_t desc_sz)
20842160
{
@@ -2123,29 +2199,125 @@ static int ata_dev_config_ncq(struct ata_device *dev,
21232199
snprintf(desc, desc_sz, "NCQ (depth %d/%d)%s", hdepth,
21242200
ddepth, aa_desc);
21252201

2126-
if ((ap->flags & ATA_FLAG_FPDMA_AUX) &&
2127-
ata_id_has_ncq_send_and_recv(dev->id)) {
2128-
err_mask = ata_read_log_page(dev, ATA_LOG_NCQ_SEND_RECV,
2129-
0, ap->sector_buf, 1);
2130-
if (err_mask) {
2131-
ata_dev_dbg(dev,
2132-
"failed to get NCQ Send/Recv Log Emask 0x%x\n",
2133-
err_mask);
2134-
} else {
2135-
u8 *cmds = dev->ncq_send_recv_cmds;
2202+
if ((ap->flags & ATA_FLAG_FPDMA_AUX)) {
2203+
if (ata_id_has_ncq_send_and_recv(dev->id))
2204+
ata_dev_config_ncq_send_recv(dev);
2205+
if (ata_id_has_ncq_non_data(dev->id))
2206+
ata_dev_config_ncq_non_data(dev);
2207+
}
21362208

2137-
dev->flags |= ATA_DFLAG_NCQ_SEND_RECV;
2138-
memcpy(cmds, ap->sector_buf, ATA_LOG_NCQ_SEND_RECV_SIZE);
2209+
return 0;
2210+
}
21392211

2140-
if (dev->horkage & ATA_HORKAGE_NO_NCQ_TRIM) {
2141-
ata_dev_dbg(dev, "disabling queued TRIM support\n");
2142-
cmds[ATA_LOG_NCQ_SEND_RECV_DSM_OFFSET] &=
2143-
~ATA_LOG_NCQ_SEND_RECV_DSM_TRIM;
2144-
}
2212+
static void ata_dev_config_sense_reporting(struct ata_device *dev)
2213+
{
2214+
unsigned int err_mask;
2215+
2216+
if (!ata_id_has_sense_reporting(dev->id))
2217+
return;
2218+
2219+
if (ata_id_sense_reporting_enabled(dev->id))
2220+
return;
2221+
2222+
err_mask = ata_dev_set_feature(dev, SETFEATURE_SENSE_DATA, 0x1);
2223+
if (err_mask) {
2224+
ata_dev_dbg(dev,
2225+
"failed to enable Sense Data Reporting, Emask 0x%x\n",
2226+
err_mask);
2227+
}
2228+
}
2229+
2230+
static void ata_dev_config_zac(struct ata_device *dev)
2231+
{
2232+
struct ata_port *ap = dev->link->ap;
2233+
unsigned int err_mask;
2234+
u8 *identify_buf = ap->sector_buf;
2235+
int log_index = ATA_LOG_SATA_ID_DEV_DATA * 2, i, found = 0;
2236+
u16 log_pages;
2237+
2238+
dev->zac_zones_optimal_open = U32_MAX;
2239+
dev->zac_zones_optimal_nonseq = U32_MAX;
2240+
dev->zac_zones_max_open = U32_MAX;
2241+
2242+
/*
2243+
* Always set the 'ZAC' flag for Host-managed devices.
2244+
*/
2245+
if (dev->class == ATA_DEV_ZAC)
2246+
dev->flags |= ATA_DFLAG_ZAC;
2247+
else if (ata_id_zoned_cap(dev->id) == 0x01)
2248+
/*
2249+
* Check for host-aware devices.
2250+
*/
2251+
dev->flags |= ATA_DFLAG_ZAC;
2252+
2253+
if (!(dev->flags & ATA_DFLAG_ZAC))
2254+
return;
2255+
2256+
/*
2257+
* Read Log Directory to figure out if IDENTIFY DEVICE log
2258+
* is supported.
2259+
*/
2260+
err_mask = ata_read_log_page(dev, ATA_LOG_DIRECTORY,
2261+
0, ap->sector_buf, 1);
2262+
if (err_mask) {
2263+
ata_dev_info(dev,
2264+
"failed to get Log Directory Emask 0x%x\n",
2265+
err_mask);
2266+
return;
2267+
}
2268+
log_pages = get_unaligned_le16(&ap->sector_buf[log_index]);
2269+
if (log_pages == 0) {
2270+
ata_dev_warn(dev,
2271+
"ATA Identify Device Log not supported\n");
2272+
return;
2273+
}
2274+
/*
2275+
* Read IDENTIFY DEVICE data log, page 0, to figure out
2276+
* if page 9 is supported.
2277+
*/
2278+
err_mask = ata_read_log_page(dev, ATA_LOG_SATA_ID_DEV_DATA, 0,
2279+
identify_buf, 1);
2280+
if (err_mask) {
2281+
ata_dev_info(dev,
2282+
"failed to get Device Identify Log Emask 0x%x\n",
2283+
err_mask);
2284+
return;
2285+
}
2286+
log_pages = identify_buf[8];
2287+
for (i = 0; i < log_pages; i++) {
2288+
if (identify_buf[9 + i] == ATA_LOG_ZONED_INFORMATION) {
2289+
found++;
2290+
break;
21452291
}
21462292
}
2293+
if (!found) {
2294+
ata_dev_warn(dev,
2295+
"ATA Zoned Information Log not supported\n");
2296+
return;
2297+
}
21472298

2148-
return 0;
2299+
/*
2300+
* Read IDENTIFY DEVICE data log, page 9 (Zoned-device information)
2301+
*/
2302+
err_mask = ata_read_log_page(dev, ATA_LOG_SATA_ID_DEV_DATA,
2303+
ATA_LOG_ZONED_INFORMATION,
2304+
identify_buf, 1);
2305+
if (!err_mask) {
2306+
u64 zoned_cap, opt_open, opt_nonseq, max_open;
2307+
2308+
zoned_cap = get_unaligned_le64(&identify_buf[8]);
2309+
if ((zoned_cap >> 63))
2310+
dev->zac_zoned_cap = (zoned_cap & 1);
2311+
opt_open = get_unaligned_le64(&identify_buf[24]);
2312+
if ((opt_open >> 63))
2313+
dev->zac_zones_optimal_open = (u32)opt_open;
2314+
opt_nonseq = get_unaligned_le64(&identify_buf[32]);
2315+
if ((opt_nonseq >> 63))
2316+
dev->zac_zones_optimal_nonseq = (u32)opt_nonseq;
2317+
max_open = get_unaligned_le64(&identify_buf[40]);
2318+
if ((max_open >> 63))
2319+
dev->zac_zones_max_open = (u32)max_open;
2320+
}
21492321
}
21502322

21512323
/**
@@ -2370,7 +2542,8 @@ int ata_dev_configure(struct ata_device *dev)
23702542
dev->devslp_timing[i] = sata_setting[j];
23712543
}
23722544
}
2373-
2545+
ata_dev_config_sense_reporting(dev);
2546+
ata_dev_config_zac(dev);
23742547
dev->cdb_len = 16;
23752548
}
23762549

0 commit comments

Comments
 (0)