Re: [PATCH v2 3/5] ata: libata-scsi: route non-zero LUN commands for multi-LUN ATAPI
From: Hannes Reinecke
Date: Thu Apr 23 2026 - 07:08:18 EST
On 4/20/26 14:23, Phil Pemberton wrote:
Two changes are required to route commands to ATAPI LUNs other than 0:
1. __ata_scsi_find_dev(): The existing code rejects any scsi_device
with a non-zero LUN, returning NULL and dropping the command on
the floor. Relax both the PMP and non-PMP branches to allow
non-zero LUNs through when the underlying ata_device is ATAPI
class, since ATAPI devices can legitimately expose multiple LUNs.
2. atapi_xlat(): Older ATAPI devices (SCSI-2 era) expect the LUN in
CDB byte 1 bits 7:5 rather than relying on transport-level LUN
addressing. Encode scmd->device->lun into those bits, preserving
the existing command-specific bits in 4:0. This is required by
both the Panasonic PD/CD combos and Nakamichi CD changers.
Signed-off-by: Phil Pemberton <philpem@xxxxxxxxxxxxx>
---
drivers/ata/libata-scsi.c | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
index 317883bac25f..4e88ae7d94c3 100644
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
@@ -2951,6 +2951,11 @@ static unsigned int atapi_xlat(struct ata_queued_cmd *qc)
memset(qc->cdb, 0, dev->cdb_len);
memcpy(qc->cdb, scmd->cmnd, scmd->cmd_len);
+ /* SCSI-2 CDB LUN encoding: bits 7:5 of byte 1 */
+ if (scmd->device->lun < 8)
+ qc->cdb[1] = (qc->cdb[1] & 0x1f) |
+ ((u8)scmd->device->lun << 5);
+
Hmm. And what happens when scmd->device->lun is _greater_ than 7?
We surely should abort that command, shouldn't we?
Cheers,
Hannes
--
Dr. Hannes Reinecke Kernel Storage Architect
hare@xxxxxxx +49 911 74053 688
SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg
HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich