Re: [PATCH v3 3/7] ata: libata-scsi: route non-zero LUN commands for multi-LUN ATAPI

From: Hannes Reinecke

Date: Mon Apr 27 2026 - 07:53:22 EST


On 4/26/26 21:09, 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. LUNs
beyond 7 cannot be encoded in the 3-bit CDB field; reject them
with AC_ERR_INVALID.

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..48c7d323d6f9 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 (3-bit field) */
+ if (scmd->device->lun >= 8)

This should be 'max_luns' of the associated scsi device, and the driver
should set the appropriate max_luns value for this specific device
(via blacklist flags etc).

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