Skip to content

Commit 28a3fc2

Browse files
hreineckehtejun
authored andcommitted
libata: implement ZBC IN translation
ZAC drives implement a 'ZAC Management In' command template, which maps onto the ZBC IN command. Signed-off-by: Hannes Reinecke <hare@suse.de> Signed-off-by: Tejun Heo <tj@kernel.org>
1 parent 3a92945 commit 28a3fc2

6 files changed

Lines changed: 185 additions & 1 deletion

File tree

‎drivers/ata/libata-eh.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2482,6 +2482,7 @@ const char *ata_get_cmd_descript(u8 command)
24822482
{ ATA_CMD_CFA_WRITE_MULT_NE, "CFA WRITE MULTIPLE WITHOUT ERASE" },
24832483
{ ATA_CMD_REQ_SENSE_DATA, "REQUEST SENSE DATA EXT" },
24842484
{ ATA_CMD_SANITIZE_DEVICE, "SANITIZE DEVICE" },
2485+
{ ATA_CMD_ZAC_MGMT_IN, "ZAC MANAGEMENT IN" },
24852486
{ ATA_CMD_READ_LONG, "READ LONG (with retries)" },
24862487
{ ATA_CMD_READ_LONG_ONCE, "READ LONG (without retries)" },
24872488
{ ATA_CMD_WRITE_LONG, "WRITE LONG (with retries)" },

‎drivers/ata/libata-scsi.c‎

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3317,6 +3317,160 @@ static unsigned int ata_scsi_write_same_xlat(struct ata_queued_cmd *qc)
33173317
return 1;
33183318
}
33193319

3320+
/**
3321+
* ata_scsi_report_zones_complete - convert ATA output
3322+
* @qc: command structure returning the data
3323+
*
3324+
* Convert T-13 little-endian field representation into
3325+
* T-10 big-endian field representation.
3326+
* What a mess.
3327+
*/
3328+
static void ata_scsi_report_zones_complete(struct ata_queued_cmd *qc)
3329+
{
3330+
struct scsi_cmnd *scmd = qc->scsicmd;
3331+
struct sg_mapping_iter miter;
3332+
unsigned long flags;
3333+
unsigned int bytes = 0;
3334+
3335+
sg_miter_start(&miter, scsi_sglist(scmd), scsi_sg_count(scmd),
3336+
SG_MITER_TO_SG | SG_MITER_ATOMIC);
3337+
3338+
local_irq_save(flags);
3339+
while (sg_miter_next(&miter)) {
3340+
unsigned int offset = 0;
3341+
3342+
if (bytes == 0) {
3343+
char *hdr;
3344+
u32 list_length;
3345+
u64 max_lba, opt_lba;
3346+
u16 same;
3347+
3348+
/* Swizzle header */
3349+
hdr = miter.addr;
3350+
list_length = get_unaligned_le32(&hdr[0]);
3351+
same = get_unaligned_le16(&hdr[4]);
3352+
max_lba = get_unaligned_le64(&hdr[8]);
3353+
opt_lba = get_unaligned_le64(&hdr[16]);
3354+
put_unaligned_be32(list_length, &hdr[0]);
3355+
hdr[4] = same & 0xf;
3356+
put_unaligned_be64(max_lba, &hdr[8]);
3357+
put_unaligned_be64(opt_lba, &hdr[16]);
3358+
offset += 64;
3359+
bytes += 64;
3360+
}
3361+
while (offset < miter.length) {
3362+
char *rec;
3363+
u8 cond, type, non_seq, reset;
3364+
u64 size, start, wp;
3365+
3366+
/* Swizzle zone descriptor */
3367+
rec = miter.addr + offset;
3368+
type = rec[0] & 0xf;
3369+
cond = (rec[1] >> 4) & 0xf;
3370+
non_seq = (rec[1] & 2);
3371+
reset = (rec[1] & 1);
3372+
size = get_unaligned_le64(&rec[8]);
3373+
start = get_unaligned_le64(&rec[16]);
3374+
wp = get_unaligned_le64(&rec[24]);
3375+
rec[0] = type;
3376+
rec[1] = (cond << 4) | non_seq | reset;
3377+
put_unaligned_be64(size, &rec[8]);
3378+
put_unaligned_be64(start, &rec[16]);
3379+
put_unaligned_be64(wp, &rec[24]);
3380+
WARN_ON(offset + 64 > miter.length);
3381+
offset += 64;
3382+
bytes += 64;
3383+
}
3384+
}
3385+
sg_miter_stop(&miter);
3386+
local_irq_restore(flags);
3387+
3388+
ata_scsi_qc_complete(qc);
3389+
}
3390+
3391+
static unsigned int ata_scsi_zbc_in_xlat(struct ata_queued_cmd *qc)
3392+
{
3393+
struct ata_taskfile *tf = &qc->tf;
3394+
struct scsi_cmnd *scmd = qc->scsicmd;
3395+
const u8 *cdb = scmd->cmnd;
3396+
u16 sect, fp = (u16)-1;
3397+
u8 sa, options, bp = 0xff;
3398+
u64 block;
3399+
u32 n_block;
3400+
3401+
if (unlikely(scmd->cmd_len < 16)) {
3402+
ata_dev_warn(qc->dev, "invalid cdb length %d\n",
3403+
scmd->cmd_len);
3404+
fp = 15;
3405+
goto invalid_fld;
3406+
}
3407+
scsi_16_lba_len(cdb, &block, &n_block);
3408+
if (n_block != scsi_bufflen(scmd)) {
3409+
ata_dev_warn(qc->dev, "non-matching transfer count (%d/%d)\n",
3410+
n_block, scsi_bufflen(scmd));
3411+
goto invalid_param_len;
3412+
}
3413+
sa = cdb[1] & 0x1f;
3414+
if (sa != ZI_REPORT_ZONES) {
3415+
ata_dev_warn(qc->dev, "invalid service action %d\n", sa);
3416+
fp = 1;
3417+
goto invalid_fld;
3418+
}
3419+
/*
3420+
* ZAC allows only for transfers in 512 byte blocks,
3421+
* and uses a 16 bit value for the transfer count.
3422+
*/
3423+
if ((n_block / 512) > 0xffff || n_block < 512 || (n_block % 512)) {
3424+
ata_dev_warn(qc->dev, "invalid transfer count %d\n", n_block);
3425+
goto invalid_param_len;
3426+
}
3427+
sect = n_block / 512;
3428+
options = cdb[14];
3429+
3430+
if (ata_ncq_enabled(qc->dev) &&
3431+
ata_fpdma_zac_mgmt_in_supported(qc->dev)) {
3432+
tf->protocol = ATA_PROT_NCQ;
3433+
tf->command = ATA_CMD_FPDMA_RECV;
3434+
tf->hob_nsect = ATA_SUBCMD_FPDMA_RECV_ZAC_MGMT_IN & 0x1f;
3435+
tf->nsect = qc->tag << 3;
3436+
tf->feature = sect & 0xff;
3437+
tf->hob_feature = (sect >> 8) & 0xff;
3438+
tf->auxiliary = ATA_SUBCMD_ZAC_MGMT_IN_REPORT_ZONES;
3439+
} else {
3440+
tf->command = ATA_CMD_ZAC_MGMT_IN;
3441+
tf->feature = ATA_SUBCMD_ZAC_MGMT_IN_REPORT_ZONES;
3442+
tf->protocol = ATA_PROT_DMA;
3443+
tf->hob_feature = options;
3444+
tf->hob_nsect = (sect >> 8) & 0xff;
3445+
tf->nsect = sect & 0xff;
3446+
}
3447+
tf->device = ATA_LBA;
3448+
tf->lbah = (block >> 16) & 0xff;
3449+
tf->lbam = (block >> 8) & 0xff;
3450+
tf->lbal = block & 0xff;
3451+
tf->hob_lbah = (block >> 40) & 0xff;
3452+
tf->hob_lbam = (block >> 32) & 0xff;
3453+
tf->hob_lbal = (block >> 24) & 0xff;
3454+
3455+
tf->flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE | ATA_TFLAG_LBA48;
3456+
qc->flags |= ATA_QCFLAG_RESULT_TF;
3457+
3458+
ata_qc_set_pc_nbytes(qc);
3459+
3460+
qc->complete_fn = ata_scsi_report_zones_complete;
3461+
3462+
return 0;
3463+
3464+
invalid_fld:
3465+
ata_scsi_set_invalid_field(qc->dev, scmd, fp, bp);
3466+
return 1;
3467+
3468+
invalid_param_len:
3469+
/* "Parameter list length error" */
3470+
ata_scsi_set_sense(qc->dev, scmd, ILLEGAL_REQUEST, 0x1a, 0x0);
3471+
return 1;
3472+
}
3473+
33203474
/**
33213475
* ata_mselect_caching - Simulate MODE SELECT for caching info page
33223476
* @qc: Storage for translated ATA taskfile
@@ -3632,6 +3786,9 @@ static inline ata_xlat_func_t ata_get_xlat_func(struct ata_device *dev, u8 cmd)
36323786
return ata_scsi_mode_select_xlat;
36333787
break;
36343788

3789+
case ZBC_IN:
3790+
return ata_scsi_zbc_in_xlat;
3791+
36353792
case START_STOP:
36363793
return ata_scsi_start_stop_xlat;
36373794
}

‎drivers/ata/libata-trace.c‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ libata_trace_parse_subcmd(struct trace_seq *p, unsigned char cmd,
162162
case ATA_SUBCMD_FPDMA_RECV_RD_LOG_DMA_EXT:
163163
trace_seq_printf(p, " READ_LOG_DMA_EXT");
164164
break;
165+
case ATA_SUBCMD_FPDMA_RECV_ZAC_MGMT_IN:
166+
trace_seq_printf(p, " ZAC_MGMT_IN");
167+
break;
165168
}
166169
break;
167170
case ATA_CMD_FPDMA_SEND:
@@ -187,6 +190,13 @@ libata_trace_parse_subcmd(struct trace_seq *p, unsigned char cmd,
187190
break;
188191
}
189192
break;
193+
case ATA_CMD_ZAC_MGMT_IN:
194+
switch (feature) {
195+
case ATA_SUBCMD_ZAC_MGMT_IN_REPORT_ZONES:
196+
trace_seq_printf(p, " REPORT_ZONES");
197+
break;
198+
}
199+
break;
190200
}
191201
trace_seq_putc(p, 0);
192202

‎include/linux/ata.h‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,12 +302,14 @@ enum {
302302
ATA_CMD_CFA_WRITE_MULT_NE = 0xCD,
303303
ATA_CMD_REQ_SENSE_DATA = 0x0B,
304304
ATA_CMD_SANITIZE_DEVICE = 0xB4,
305+
ATA_CMD_ZAC_MGMT_IN = 0x4A,
305306

306307
/* marked obsolete in the ATA/ATAPI-7 spec */
307308
ATA_CMD_RESTORE = 0x10,
308309

309310
/* Subcmds for ATA_CMD_FPDMA_RECV */
310311
ATA_SUBCMD_FPDMA_RECV_RD_LOG_DMA_EXT = 0x01,
312+
ATA_SUBCMD_FPDMA_RECV_ZAC_MGMT_IN = 0x02,
311313

312314
/* Subcmds for ATA_CMD_FPDMA_SEND */
313315
ATA_SUBCMD_FPDMA_SEND_DSM = 0x00,
@@ -318,6 +320,9 @@ enum {
318320
ATA_SUBCMD_NCQ_NON_DATA_SET_FEATURES = 0x05,
319321
ATA_SUBCMD_NCQ_NON_DATA_ZERO_EXT = 0x06,
320322

323+
/* Subcmds for ATA_CMD_ZAC_MGMT_IN */
324+
ATA_SUBCMD_ZAC_MGMT_IN_REPORT_ZONES = 0x00,
325+
321326
/* READ_LOG_EXT pages */
322327
ATA_LOG_DIRECTORY = 0x0,
323328
ATA_LOG_SATA_NCQ = 0x10,
@@ -341,7 +346,10 @@ enum {
341346
ATA_LOG_NCQ_SEND_RECV_RD_LOG_SUPPORTED = (1 << 0),
342347
ATA_LOG_NCQ_SEND_RECV_WR_LOG_OFFSET = 0x0C,
343348
ATA_LOG_NCQ_SEND_RECV_WR_LOG_SUPPORTED = (1 << 0),
344-
ATA_LOG_NCQ_SEND_RECV_SIZE = 0x10,
349+
ATA_LOG_NCQ_SEND_RECV_ZAC_MGMT_OFFSET = 0x10,
350+
ATA_LOG_NCQ_SEND_RECV_ZAC_MGMT_OUT_SUPPORTED = (1 << 0),
351+
ATA_LOG_NCQ_SEND_RECV_ZAC_MGMT_IN_SUPPORTED = (1 << 1),
352+
ATA_LOG_NCQ_SEND_RECV_SIZE = 0x14,
345353

346354
/* NCQ Non-Data log */
347355
ATA_LOG_NCQ_NON_DATA_SUBCMDS_OFFSET = 0x00,

‎include/linux/libata.h‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1651,6 +1651,13 @@ static inline bool ata_fpdma_read_log_supported(struct ata_device *dev)
16511651
ATA_LOG_NCQ_SEND_RECV_RD_LOG_SUPPORTED);
16521652
}
16531653

1654+
static inline bool ata_fpdma_zac_mgmt_in_supported(struct ata_device *dev)
1655+
{
1656+
return (dev->flags & ATA_DFLAG_NCQ_SEND_RECV) &&
1657+
(dev->ncq_send_recv_cmds[ATA_LOG_NCQ_SEND_RECV_ZAC_MGMT_OFFSET] &
1658+
ATA_LOG_NCQ_SEND_RECV_ZAC_MGMT_IN_SUPPORTED);
1659+
}
1660+
16541661
static inline void ata_qc_set_polling(struct ata_queued_cmd *qc)
16551662
{
16561663
qc->tf.ctl |= ATA_NIEN;

‎include/trace/events/libata.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
ata_opcode_name(ATA_CMD_CFA_WRITE_MULT_NE), \
9999
ata_opcode_name(ATA_CMD_REQ_SENSE_DATA), \
100100
ata_opcode_name(ATA_CMD_SANITIZE_DEVICE), \
101+
ata_opcode_name(ATA_CMD_ZAC_MGMT_IN), \
101102
ata_opcode_name(ATA_CMD_RESTORE), \
102103
ata_opcode_name(ATA_CMD_READ_LONG), \
103104
ata_opcode_name(ATA_CMD_READ_LONG_ONCE), \

0 commit comments

Comments
 (0)