{"id":2225154,"url":"http://patchwork.ozlabs.org/api/1.1/patches/2225154/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-ide/patch/20260420122321.4161027-4-philpem@philpem.me.uk/","project":{"id":13,"url":"http://patchwork.ozlabs.org/api/1.1/projects/13/?format=json","name":"Linux IDE development","link_name":"linux-ide","list_id":"linux-ide.vger.kernel.org","list_email":"linux-ide@vger.kernel.org","web_url":null,"scm_url":null,"webscm_url":null},"msgid":"<20260420122321.4161027-4-philpem@philpem.me.uk>","date":"2026-04-20T12:23:19","name":"[v2,3/5] ata: libata-scsi: route non-zero LUN commands for multi-LUN ATAPI","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"e402831915852a190c5d26d55ea77db1fb6e049f","submitter":{"id":93108,"url":"http://patchwork.ozlabs.org/api/1.1/people/93108/?format=json","name":"Phil Pemberton","email":"philpem@philpem.me.uk"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/linux-ide/patch/20260420122321.4161027-4-philpem@philpem.me.uk/mbox/","series":[{"id":500602,"url":"http://patchwork.ozlabs.org/api/1.1/series/500602/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-ide/list/?series=500602","date":"2026-04-20T12:23:21","name":"ata: libata-scsi: multi-LUN ATAPI device support","version":2,"mbox":"http://patchwork.ozlabs.org/series/500602/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2225154/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2225154/checks/","tags":{},"headers":{"Return-Path":"\n <linux-ide+bounces-5496-incoming=patchwork.ozlabs.org@vger.kernel.org>","X-Original-To":["incoming@patchwork.ozlabs.org","linux-ide@vger.kernel.org"],"Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (1024-bit key;\n unprotected) header.d=philpem.me.uk header.i=@philpem.me.uk\n header.a=rsa-sha256 header.s=mail header.b=Dz/93QVn;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org\n (client-ip=2600:3c04:e001:36c::12fc:5321; helo=tor.lore.kernel.org;\n envelope-from=linux-ide+bounces-5496-incoming=patchwork.ozlabs.org@vger.kernel.org;\n receiver=patchwork.ozlabs.org)","smtp.subspace.kernel.org;\n\tdkim=pass (1024-bit key) header.d=philpem.me.uk header.i=@philpem.me.uk\n header.b=\"Dz/93QVn\"","smtp.subspace.kernel.org;\n arc=none smtp.client-ip=178.62.38.78","smtp.subspace.kernel.org;\n dmarc=pass (p=reject dis=none) header.from=philpem.me.uk","smtp.subspace.kernel.org;\n spf=pass smtp.mailfrom=philpem.me.uk"],"Received":["from tor.lore.kernel.org (tor.lore.kernel.org\n [IPv6:2600:3c04:e001:36c::12fc:5321])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fzlgr10gCz1yCv\n\tfor <incoming@patchwork.ozlabs.org>; Mon, 20 Apr 2026 22:50:00 +1000 (AEST)","from smtp.subspace.kernel.org (conduit.subspace.kernel.org\n [100.90.174.1])\n\tby tor.lore.kernel.org (Postfix) with ESMTP id 2BAFE304B370\n\tfor <incoming@patchwork.ozlabs.org>; Mon, 20 Apr 2026 12:45:31 +0000 (UTC)","from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id 0F07339E184;\n\tMon, 20 Apr 2026 12:45:27 +0000 (UTC)","from nick.sneptech.io (nick.sneptech.io [178.62.38.78])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby smtp.subspace.kernel.org (Postfix) with ESMTPS id 8DFB92D7DDD;\n\tMon, 20 Apr 2026 12:45:25 +0000 (UTC)","from wolf.philpem.me.uk (81-187-163-148.ip4.reverse-dns.uk\n [81.187.163.148])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest\n SHA256)\n\t(No client certificate requested)\n\t(Authenticated sender: mailrelay_wolf@philpem.me.uk)\n\tby nick.sneptech.io (Postfix) with ESMTPSA id 36724BEFE2;\n\tMon, 20 Apr 2026 12:23:29 +0000 (UTC)","from cheetah.homenet.philpem.me.uk (cheetah.homenet.philpem.me.uk\n [10.0.0.32])\n\tby wolf.philpem.me.uk (Postfix) with ESMTPSA id AF6965FC59;\n\tMon, 20 Apr 2026 13:23:28 +0100 (BST)"],"ARC-Seal":"i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1776689126; cv=none;\n b=kKwTi/riA3syWjfhX7Ac/qyuggdAcsXdBl3CO+6WlkqOCnC7xs3Wlrsxt2Jcb3TpRZBdGz0bgwC/OTw5t7S8AJETfZIQhEq/9ZpFtoMN74bI+YIBN685yVXzr9sCKKh/Ykx7YpNBDbfJdTe+oRIa3emVQn6arv9B7o9WMX3BuxA=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1776689126; c=relaxed/simple;\n\tbh=mOszOGgiRniI+v2UWq22eRi5tmlU02g5ePSKlT10boU=;\n\th=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:\n\t MIME-Version;\n b=cYtLgKX9dgwNkCg7OkfWOqJbVQoKmPP1KAcmtAKGa6XUx1XiJCe7AW1GxijqWZXBTLZVOM7R8oEglwrQLIwrTk3GXzhp1IZmpb8siQ6kww2427WE0VgtOD6A7wOjK9PAcHQphSH//R2shSycD2PSvj6S+7RkFg/pc1GZE6AcmX8=","ARC-Authentication-Results":"i=1; smtp.subspace.kernel.org;\n dmarc=pass (p=reject dis=none) header.from=philpem.me.uk;\n spf=pass smtp.mailfrom=philpem.me.uk;\n dkim=pass (1024-bit key) header.d=philpem.me.uk header.i=@philpem.me.uk\n header.b=Dz/93QVn; arc=none smtp.client-ip=178.62.38.78","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=philpem.me.uk;\n\ts=mail; t=1776687809;\n\tbh=mOszOGgiRniI+v2UWq22eRi5tmlU02g5ePSKlT10boU=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=Dz/93QVnxhsZ5AVlWbrYuCF6+9GAlDgaeyk0NVRHgYcEce8yM4EBkV1619R9ybLbN\n\t u7zMIy3UtqNnCaR5mBZ442Sy6dgdh/mXZ81ZH25A8F69BHtXcW9NiF8ln1MUx0I6K0\n\t 2PsLvnG+CgVefxXvCwhtE1hWsPc10RS0BP/QxsJE=","From":"Phil Pemberton <philpem@philpem.me.uk>","To":"Damien Le Moal <dlemoal@kernel.org>,\n\tNiklas Cassel <cassel@kernel.org>","Cc":"\"James E . J . Bottomley\" <James.Bottomley@HansenPartnership.com>,\n\t\"Martin K . Petersen\" <martin.petersen@oracle.com>,\n\tHannes Reinecke <hare@suse.de>,\n\tlinux-ide@vger.kernel.org,\n\tlinux-scsi@vger.kernel.org,\n\tlinux-kernel@vger.kernel.org,\n\tPhil Pemberton <philpem@philpem.me.uk>","Subject":"[PATCH v2 3/5] ata: libata-scsi: route non-zero LUN commands for\n multi-LUN ATAPI","Date":"Mon, 20 Apr 2026 13:23:19 +0100","Message-ID":"<20260420122321.4161027-4-philpem@philpem.me.uk>","X-Mailer":"git-send-email 2.43.0","In-Reply-To":"<20260420122321.4161027-1-philpem@philpem.me.uk>","References":"<20260420122321.4161027-1-philpem@philpem.me.uk>","Precedence":"bulk","X-Mailing-List":"linux-ide@vger.kernel.org","List-Id":"<linux-ide.vger.kernel.org>","List-Subscribe":"<mailto:linux-ide+subscribe@vger.kernel.org>","List-Unsubscribe":"<mailto:linux-ide+unsubscribe@vger.kernel.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit"},"content":"Two changes are required to route commands to ATAPI LUNs other than 0:\n\n1. __ata_scsi_find_dev():  The existing code rejects any scsi_device\n   with a non-zero LUN, returning NULL and dropping the command on\n   the floor.  Relax both the PMP and non-PMP branches to allow\n   non-zero LUNs through when the underlying ata_device is ATAPI\n   class, since ATAPI devices can legitimately expose multiple LUNs.\n\n2. atapi_xlat():  Older ATAPI devices (SCSI-2 era) expect the LUN in\n   CDB byte 1 bits 7:5 rather than relying on transport-level LUN\n   addressing.  Encode scmd->device->lun into those bits, preserving\n   the existing command-specific bits in 4:0.  This is required by\n   both the Panasonic PD/CD combos and Nakamichi CD changers.\n\nSigned-off-by: Phil Pemberton <philpem@philpem.me.uk>\n---\n drivers/ata/libata-scsi.c | 17 +++++++++++++++--\n 1 file changed, 15 insertions(+), 2 deletions(-)","diff":"diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c\nindex 317883bac25f..4e88ae7d94c3 100644\n--- a/drivers/ata/libata-scsi.c\n+++ b/drivers/ata/libata-scsi.c\n@@ -2951,6 +2951,11 @@ static unsigned int atapi_xlat(struct ata_queued_cmd *qc)\n \tmemset(qc->cdb, 0, dev->cdb_len);\n \tmemcpy(qc->cdb, scmd->cmnd, scmd->cmd_len);\n \n+\t/* SCSI-2 CDB LUN encoding: bits 7:5 of byte 1 */\n+\tif (scmd->device->lun < 8)\n+\t\tqc->cdb[1] = (qc->cdb[1] & 0x1f) |\n+\t\t\t      ((u8)scmd->device->lun << 5);\n+\n \tqc->complete_fn = atapi_qc_complete;\n \n \tqc->tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE;\n@@ -3059,19 +3064,27 @@ static struct ata_device *ata_find_dev(struct ata_port *ap, unsigned int devno)\n static struct ata_device *__ata_scsi_find_dev(struct ata_port *ap,\n \t\t\t\t\t      const struct scsi_device *scsidev)\n {\n+\tstruct ata_device *dev;\n \tint devno;\n \n \t/* skip commands not addressed to targets we simulate */\n \tif (!sata_pmp_attached(ap)) {\n-\t\tif (unlikely(scsidev->channel || scsidev->lun))\n+\t\tif (unlikely(scsidev->channel))\n \t\t\treturn NULL;\n \t\tdevno = scsidev->id;\n \t} else {\n-\t\tif (unlikely(scsidev->id || scsidev->lun))\n+\t\tif (unlikely(scsidev->id))\n \t\t\treturn NULL;\n \t\tdevno = scsidev->channel;\n \t}\n \n+\tif (unlikely(scsidev->lun)) {\n+\t\tdev = ata_find_dev(ap, devno);\n+\t\tif (!dev || dev->class != ATA_DEV_ATAPI)\n+\t\t\treturn NULL;\n+\t\treturn dev;\n+\t}\n+\n \treturn ata_find_dev(ap, devno);\n }\n \n","prefixes":["v2","3/5"]}