From nobody Mon Jun 8 05:26:39 2026 Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1DD233B0AE3 for ; Sat, 6 Jun 2026 13:26:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780752374; cv=none; b=Lw0VcvLp7r8fwjnpkLMpsikx+Q7oa6FvyJdPeSTlL98aQwUnwthA99MJ3ZqnIK+DiLklv5psq14tsJjlRX+J0BP4jw0INR+kViDqUfu2jZLsBsVVK43wsVorPpuj+8H1NpnJNGc8HZhO93Y2nLcscXt+98LMOfGFUm0CJHorXVU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780752374; c=relaxed/simple; bh=m24MQbKzf1MwyNbAaZ52Y2HqborWGOg5ZSaflev6tNc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ufiEKh+JGk6vjfFg/kUPOEDw6pKHSIFaXCqVo0Ww8kPuppp7EBZeFe4rwSs3ATcDSkkdARU6dl4Db3Jd5c5+yjK4uqn7NnqK5y6OEiw3z9Nlfub8uWbGi96GQm8CjcdtT5AjIfW1JH1Tzjlxu1NR4+TSIPAsGLo0Ayqbj9hhc1U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=tCoARQtT; arc=none smtp.client-ip=209.85.210.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="tCoARQtT" Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-8423efd76c8so1935751b3a.0 for ; Sat, 06 Jun 2026 06:26:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780752371; x=1781357171; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=NeEBBh0lNzCCAreOc9bk7WWW8nd2UTHn7HjqcTneUFU=; b=tCoARQtTkUAdImZQOO9VdxKaNimwrLM6MmvkZvYHiU1m1QXP5FUUFgcc/xfH4J+wRm urDgogLpn6BxG37T4MzqwHWDWLPeX5oeJeS0RCol+2YitSJ3hUXkTLsEg/YyjUKF1V3G 8UZehEw2L6RrvP/AHzs7cQgA2SfTItwk4sTXNKnVd+usMgo2J/TZwo5qxifFhP1N4cMy xJls2dSi8aioMbSzrii/zz1xvh/+vT3MkswJn4qgc/9m8pL97TcW1KdQOxngoZABGDCG hTtc2FYD1xZjye78rdjx+525Lyu/ODfQm2K8t0oLUj17FxNlT3Dso/nFxWse6j+UpcHo gy0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780752371; x=1781357171; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=NeEBBh0lNzCCAreOc9bk7WWW8nd2UTHn7HjqcTneUFU=; b=WS4WCpiCXp0EW6Vf0KsqdGvllNtKgyUF0NKl0TuHZx1tR6yIcHQ0QulCF8PdAoWC30 ePAiXs/1LYV37XG47WXPcB1/O1gR9MGH3c5HI6IUkJNBOxC2HNafdXdhDLOl+OGPku+2 pHNqnCNO6LC1Kfjt4zhbEVKqlLkGxfVnxMQD1pcOm2fIMXq7UBhfQe5tmCIcBFm7Jr46 5X242t43hp9hYLY0za6d5YHkbO7iOhufGibN/UdowBdV+pa1hWf7PNAgnQIa2HcF4KhR IiBTrKBs2ggaZhnFq2MZp43dQ4qzXawSygXXj1Df6ZAwpQ9G1DxunvoWz/I6kfNXEJkT XI8A== X-Forwarded-Encrypted: i=1; AFNElJ/GPOx6MwFKGP84ye55QmEXO+76oKAsOQRk/AXArE7Y4TG3yOuxzn8nyCWgTW+3ND+zRC4cKlGJxkV9T7s=@vger.kernel.org X-Gm-Message-State: AOJu0Yy6+21YOUILikAVK1lPFgZOtpXMdo2txkJT6FtG53dxis6MzE9k khMcRqNOoJraAtgFoVrCxDwdcxMnCWNK7L8LDVQrFiqghciQsdqXf5QK X-Gm-Gg: Acq92OExGd4rX8aI5zTxLMGGcfjGtUuEL0uTyyjM/rwZoP/AHlTziLUXL9Mf95k50+8 1jnNFvauvUpPW33IN+rQcH9iMmqjmYj2moJOk1YINv2cZH7GfKgO779SFtp9mfvlO//16MjU+Q9 UFTNwKexDpG5Sue89jklwrjN0d5JRQJzSn1bpK8mktrTo+keV3DppF/WYrGm5tN85YoiAJewWDt rVBddfumzyQHLLYohMxyi3C7FuSGCCBBeAg5Xju+1+PEkmLoGyh3U4/DxxCbuXB6Je9hrLu2b5W XbXJrQFOcN3c/Ztuqjx/12q3UP8YS7fGZgeQYs2wis0OtUXDx0tpm9STdySUxH81GlMmqKndnpG XWC2kl8JwtJwtWHEQ8LiSJcRxW4PDC8GNMPyPq/C531eDV7MzRaBDG8FTLBSdBovVfP70itXy0X rseDHNFNrk5nIoa9sGp5xbA015CV1CavspAZw4CDBqOPNYGGg= X-Received: by 2002:a05:6a00:1da3:b0:82f:3a1e:5618 with SMTP id d2e1a72fcca58-842b0dafd4bmr8292626b3a.22.1780752371348; Sat, 06 Jun 2026 06:26:11 -0700 (PDT) Received: from [127.0.1.1] ([223.122.38.120]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-842829188b9sm12910688b3a.59.2026.06.06.06.26.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Jun 2026 06:26:10 -0700 (PDT) From: Nick Chan Date: Sat, 06 Jun 2026 21:25:25 +0800 Subject: [PATCH 1/2] nvme-apple: Only limit admin queue tag space when with Linear SQ is present Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260606-prevent-tag-collision-t8015-v1-1-93ccf4eca550@gmail.com> References: <20260606-prevent-tag-collision-t8015-v1-0-93ccf4eca550@gmail.com> In-Reply-To: <20260606-prevent-tag-collision-t8015-v1-0-93ccf4eca550@gmail.com> To: Sven Peter , Janne Grunau , Neal Gompa , Keith Busch , Jens Axboe , Christoph Hellwig , Sagi Grimberg Cc: asahi@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Nick Chan X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=1520; i=towinchenmi@gmail.com; h=from:subject:message-id; bh=m24MQbKzf1MwyNbAaZ52Y2HqborWGOg5ZSaflev6tNc=; b=owEBbQKS/ZANAwAKAQHKCLemxQgkAcsmYgBqJB/qBCoYq0Ez0tQV9FSpbDzHKmr987/6Tm152 E69XiIGqPCJAjMEAAEKAB0WIQRLUnh4XJes95w8aIMBygi3psUIJAUCaiQf6gAKCRABygi3psUI JL6OEACOBZpKq3tWJKlPioh5me2NNMMRMIe5utVW0bqMBKpjmqP3LeRjWQm/VfeKB48ntOYS1BI hks3Rnd4mrLdzCbnspo9epLHKpgBwJ4CsEKcisn22n9MSykbzwBKIkpgp71ndvvIYb/bxqi086A u440qaBo820Tyc74ElD93CuXgIsAutDV+hw3VJqvTSwPDTXEsZ03bQNGoe7yZOCyrqvj1PIz7fE xkmtUoD+suZJTjmXCn2ohTLExkZnNPABpqNrQ8UkYQ/yjYIgiolVEl4X6LKCLw38/pxF+pIJs+3 1+y88fttHsS7FbTj7lDp2ZSUC+KniJCuFaEJECQjCNpyNLZSpotYI8qY3OK/VaoiGNIgBnyGme+ 7RzHd9HylqE9CsUQs60eWBoCkBlnWEiwTnxWLark0pSduu/Phw7FMOMFlvhJxBcdyWdPCZTIkkt k63yDX1dpoP3QNa37PkcG2VRM+CESHNgOHzcAbgbWQEgFgV7FFb6QJsT2piKh+ltPWZoGPcbZG7 h0CUC+KwmkfrHxHDJHo9+XjYtCKdlx58Pv2TPyH9iB8BXlLPjdsrQXQzWrV8z9kdIBQZ/gUo6KW w14kgVGXMdIhSxF7Sssl/671LE82DMKMlS1Yx11HXwySbpL008BGXMl+pcypaWTzDmUeBo9i2cM VFCscrmIgwrx07A== X-Developer-Key: i=towinchenmi@gmail.com; a=openpgp; fpr=4B5278785C97ACF79C3C688301CA08B7A6C50824 Apple NVMe controllers require tags of pending commands to not be shared across admin and IO queues. However, on Apple A11 without linear SQ, it is not possible for either queue to skip over some tags and must go from 0 to the configured maximum before wrapping around. As a result, in order to prevent tag collision, dynamic tag reservation while a command is in-flight becomes necessary. In this context, there is no reason to limit the admin queue's tag space, as it is not helpful in preventing tag collision. Cc: stable@vger.kernel.org Fixes: 04d8ecf37b5e ("nvme: apple: Add Apple A11 support") Signed-off-by: Nick Chan --- drivers/nvme/host/apple.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/nvme/host/apple.c b/drivers/nvme/host/apple.c index c692fc73babf..c1115e27a0d6 100644 --- a/drivers/nvme/host/apple.c +++ b/drivers/nvme/host/apple.c @@ -1303,7 +1303,10 @@ static int apple_nvme_alloc_tagsets(struct apple_nvm= e *anv) =20 anv->admin_tagset.ops =3D &apple_nvme_mq_admin_ops; anv->admin_tagset.nr_hw_queues =3D 1; - anv->admin_tagset.queue_depth =3D APPLE_NVME_AQ_MQ_TAG_DEPTH; + if (anv->hw->has_lsq_nvmmu) + anv->admin_tagset.queue_depth =3D APPLE_NVME_AQ_MQ_TAG_DEPTH; + else + anv->admin_tagset.queue_depth =3D anv->hw->max_queue_depth - 1; anv->admin_tagset.timeout =3D NVME_ADMIN_TIMEOUT; anv->admin_tagset.numa_node =3D NUMA_NO_NODE; anv->admin_tagset.cmd_size =3D sizeof(struct apple_nvme_iod); --=20 2.54.0 From nobody Mon Jun 8 05:26:39 2026 Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A35CA3B14B1 for ; Sat, 6 Jun 2026 13:26:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780752378; cv=none; b=pPBkEJlE+COuNytDlwP2tbRL/NOfJfatyL8tnyHCoLXzYQLA0TpxZ1ij4+/EhWttjYecx6yGlydCTlvyM2wlQIDv7oBEYn/iVsS/BaLF1g1/JO4ffw8NJjDzTX5eHqI02iLcnC7+bzVDq8BqckGlcjtLEvvlZOEBeLLY1TM2Cas= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780752378; c=relaxed/simple; bh=lrseDDwhEGzRyA1udiirpwFfKwyONLsk+j6dkut+Ezs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=LK3VQAt5oL107XgpA27PJAu0CKDmh2ChpTuBxdq9qfW21nyRDrWgraO4jl+K9xo9V5gh6vzKJhp+NCeqZ4iZ7l+dnbzTa4Yfmlvqp66eCN6tl2TrTNBMFQVbhDiudHMor+7AB9u4f/x0nRhOkII4I3CEs5Z1vqJvAYqysQzHuKo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=R5sCxPVm; arc=none smtp.client-ip=209.85.210.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="R5sCxPVm" Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-8422871b42dso1736182b3a.3 for ; Sat, 06 Jun 2026 06:26:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780752376; x=1781357176; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=42lbift3GUSRsYsWcu6WULLrIkIIMX8MmeNmUG1RfTM=; b=R5sCxPVmqDIJTZuUpyZlwuJsSvsUB9rzY8Be9WKlzZmeEP99pdByLRSjfVAGxwqglx gxwK1RCojDQzryO6BPZI4BH531P5arExhfW9X8ZD0EC2mLvzGeXr6Yv525Fbboh8S/qs oLTrzYHj3/CITkzlNGMdV8Rwpt4l49WVgmtVNFVPuZrue0paFdkyLLwAkMriZguL6GHN NxsZ5YSBAkD0UjatVhTsejv0fN5R0zzd8cQlnn/GlqZBuIF5x/XYb1MULY9vSY+PYJPg VuROH3caBdJqBog5uekE1kusQisPkiY2mNfcRAJcIqOxhjVD176+eZm3WC4bGUaf5nYL 5LEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780752376; x=1781357176; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=42lbift3GUSRsYsWcu6WULLrIkIIMX8MmeNmUG1RfTM=; b=hfMMk2kqt5B/W15GIuXJjRV6y3EL25pmFTPtASA85bTNpa8JikjPXlfyCBN41XhiKS P2Hq4RPg7AudlA3RduT8IELz/3zfYe15Pn9UAxoyfuzWG5/66O0LmgSKTV8lXPX/WFl7 jBrXQy86pFZirbMVYVxgCg1RIfPTrbxsd6BeF3huXOiu3mvx5L+h4QR0jopQ7nDKwgDF LID3mi/Itztb4KEbFogOLthZUztqFV0aA2lUfkVPI0UWNVlxuaIk5FeogiE+UHQ/Iiwi Jvuea57GbQpMv+3/xQszqJe61o8B/UjagHRUF4ee3hOh2sCFWI6x4b3HczLErQkn+3cU hztw== X-Forwarded-Encrypted: i=1; AFNElJ+Feu87JHLHS/ATZ23Pi7c6DC4CYPS2CJZdGu4qQ19rhav2++Dpe7zZXJ7caSpDb7stfDtDVZWa39S+hBI=@vger.kernel.org X-Gm-Message-State: AOJu0YxauxR2DRx5ieNCvmnjFyLf0XUCYRakfci/pd+pEugsganpzq7n kMzqwLkgE20rrrAvVYLp1lTfB+jmYYA0FAX/ariPm5A+Uznwpa5mT6gP X-Gm-Gg: Acq92OH74GKHrqc1DP0Zt09k9O2Jf2qHf879QJwcWCaXZ/vMRxHjLiQ8R127c2+KDxp DMl26MY3rcrl5o5WU2l3VlHNBXf+TP56bMOl65GuMy7f7VY0wl1NceIDfEPtueSUNvSYdzf2ip7 X7PnMHRGMbERCi+SRhyUZ9cOEZTmm7MZUhaLk2YEsi9tRB6/Sgy4rU7Bjxi/UHKwUb4GdkstNlD VsqTOVFMA5rPpyFVGzWiXw6ymu84J5F2tNqgB8oM2TkoJcdVEUdcKo30usqnDmZHhUvqb8WIimR ssmxri1TZGt2MGPiJnb/YN/l1VF3JKCYjqiUcf32QFbZU5raqSDsc3HmqZ/z3tOA4CSt/YRckP4 Uh9QVu8ntRRS+2BDO8ps2DAr5mChA0bbhpwAPTLE+ckuEj+ivTw5lrPKC4jxWIThk3TdMOJtJiJ CrZlHjXDtI5geJ+0QFLSY+pMPLZjLoisTWW8JT X-Received: by 2002:a05:6a00:4c87:b0:81f:5037:a317 with SMTP id d2e1a72fcca58-842b0d4a0d8mr8693533b3a.11.1780752375873; Sat, 06 Jun 2026 06:26:15 -0700 (PDT) Received: from [127.0.1.1] ([223.122.38.120]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-842829188b9sm12910688b3a.59.2026.06.06.06.26.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Jun 2026 06:26:15 -0700 (PDT) From: Nick Chan Date: Sat, 06 Jun 2026 21:25:26 +0800 Subject: [PATCH 2/2] nvme-apple: Prevent tag collision across queues even if tag space is shared Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260606-prevent-tag-collision-t8015-v1-2-93ccf4eca550@gmail.com> References: <20260606-prevent-tag-collision-t8015-v1-0-93ccf4eca550@gmail.com> In-Reply-To: <20260606-prevent-tag-collision-t8015-v1-0-93ccf4eca550@gmail.com> To: Sven Peter , Janne Grunau , Neal Gompa , Keith Busch , Jens Axboe , Christoph Hellwig , Sagi Grimberg Cc: asahi@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Nick Chan , Yuriy Havrylyuk X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=4840; i=towinchenmi@gmail.com; h=from:subject:message-id; bh=bXuJzOynK1zfJuBlVU0RMP2QsgG1y48fTK+be2Wr0r0=; b=owEBbQKS/ZANAwAKAQHKCLemxQgkAcsmYgBqJB/qdLOi84lIuVdy6NqUXI4/UNSlZb9mI5/IT TzMsAgCn/aJAjMEAAEKAB0WIQRLUnh4XJes95w8aIMBygi3psUIJAUCaiQf6gAKCRABygi3psUI JCCYD/9ncU6Tq/2SE3eURPnZaKM+kVw7fBhpQAjY9+yQc/aPkV4qvYhN7uabU4XpKUOsCw0XmL4 QjX+clJQRQ3x0ZutsbGUAE9xuC2BX5oUT6UVf7kFr+3QixZJVD2s3kC+noa8DdEaojRR1SC+5L8 gLEc8CTiDTNqzk3VB/Tvu+2YP1uV+83zggrvi4SasU2wiKjhph9ccd0+sKtS9psNuas9W9TETJL LwpAwBJcSlsBCH6fZwI6bZl7IV+lKc4K+/kVDVysKsh1+S4Kz5lNoYE4fiya/aPRa6AojVohiRn lgtDpBoveWqFY+92x6g6BrBan2YUuht8Bn1Y4fkfLx7IfMzbFLr0GxrvP8Y6o08aF/WTS/JsXB8 5jJ5mdavfE6DvflFCt/I8Onc5LqvcJ8kX0rcNgHY5JSATbkd/AjyJxiKVn4vO9zdHH6gqb3W6wp t86AS6Zq5SplBtxiRoYzbtjKwFI4lLtt+U27B7GcPAvwKL1eCumB4K8AW11xZFLtLa/SFlfZK9p rJSQpX4a6ldMMR3PTzRz6sAOmiaubhFXJDmZ9OYy/EbRICgvp0wTvf0YddUz+Gh4dFlUpMAKLJ7 +n8bf5cY6855i6t87C7tlfCxfxCh4dokI9XjYDNEjU2835AK0lVGWTFx8zAQa1EwLf9DrXoBJ/w 7/tbxNCNCdymomw== X-Developer-Key: i=towinchenmi@gmail.com; a=openpgp; fpr=4B5278785C97ACF79C3C688301CA08B7A6C50824 From: Yuriy Havrylyuk Apple NVMe controllers require tags of pending commands to not be shared across admin and IO queues. However, on Apple A11 without linear SQ, it is not possible for either queue to skip over some tags and must go from 0 to the configured maximum before wrapping around. If a pending command tag is duplicated across queues, the firmware crashes with: "duplicate tag error for tag N", with N being the tag. Instead of partitioning the tag space, which is not possible without linear SQ, prevent tag collisions by keeping track of which tags are currently in-flight across either queues, and return BLK_STS_RESOURCE to temporaily block command submission when a collision would have occurred. Cc: stable@vger.kernel.org Fixes: 04d8ecf37b5e ("nvme: apple: Add Apple A11 support") Signed-off-by: Yuriy Havrylyuk Co-developed-by: Nick Chan Signed-off-by: Nick Chan --- drivers/nvme/host/apple.c | 65 +++++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 65 insertions(+) diff --git a/drivers/nvme/host/apple.c b/drivers/nvme/host/apple.c index c1115e27a0d6..6354edf27225 100644 --- a/drivers/nvme/host/apple.c +++ b/drivers/nvme/host/apple.c @@ -203,6 +203,20 @@ struct apple_nvme { =20 int irq; spinlock_t lock; + + /* + * Tags of pending commands must be unique across both Admin and IO + * queue. However, on T8015, unlike T8103, without linear submission + * queues, it is not possible for the either queue to skip some tags, + * and both queues must go from 0 to their respective configured + * maximum. + * + * Instead of reserving some tags for the admin queue, use a bitfield + * to keep track of pending commands on either queue, and temporaily + * block command submission by returning BLK_STS_RESOURCE until the + * tag is freed on the other queue. + */ + unsigned long t8015_active_tags; }; =20 static_assert(sizeof(struct nvme_command) =3D=3D 64); @@ -290,6 +304,28 @@ static void apple_nvmmu_inval(struct apple_nvme_queue = *q, unsigned int tag) "NVMMU TCB invalidation failed\n"); } =20 +static bool apple_nvme_reserve_tag_t8015(struct apple_nvme *anv, + struct nvme_command *cmd) +{ + u16 tag =3D nvme_tag_from_cid(cmd->common.command_id); + + if (WARN_ON_ONCE(tag >=3D BITS_PER_LONG)) + return false; + + return !test_and_set_bit(tag, &anv->t8015_active_tags); +} + +static void apple_nvme_release_tag_t8015(struct apple_nvme *anv, + __u16 command_id) +{ + u16 tag =3D nvme_tag_from_cid(command_id); + + if (WARN_ON_ONCE(tag >=3D BITS_PER_LONG)) + return; + + clear_bit(tag, &anv->t8015_active_tags); +} + static void apple_nvme_submit_cmd_t8015(struct apple_nvme_queue *q, struct nvme_command *cmd) { @@ -652,6 +688,8 @@ static inline void apple_nvme_update_cq_head(struct app= le_nvme_queue *q) static bool apple_nvme_poll_cq(struct apple_nvme_queue *q, struct io_comp_batch *iob) { + struct apple_nvme *anv =3D queue_to_apple_nvme(q); + unsigned long completed_tags =3D 0; bool found =3D false; =20 while (apple_nvme_cqe_pending(q)) { @@ -664,11 +702,26 @@ static bool apple_nvme_poll_cq(struct apple_nvme_queu= e *q, dma_rmb(); apple_nvme_handle_cqe(q, iob, q->cq_head); apple_nvme_update_cq_head(q); + + if (!anv->hw->has_lsq_nvmmu) { + struct nvme_completion *cqe =3D &q->cqes[q->cq_head]; + u16 tag =3D nvme_tag_from_cid(READ_ONCE(cqe->command_id)); + + if (!WARN_ON_ONCE(tag >=3D BITS_PER_LONG)) + __set_bit(tag, &completed_tags); + } } =20 if (found) writel(q->cq_head, q->cq_db); =20 + if (!anv->hw->has_lsq_nvmmu && completed_tags) { + unsigned long tag_bit; + + for_each_set_bit(tag_bit, &completed_tags, BITS_PER_LONG) + clear_bit(tag_bit, &anv->t8015_active_tags); + } + return found; } =20 @@ -790,6 +843,12 @@ static blk_status_t apple_nvme_queue_rq(struct blk_mq_= hw_ctx *hctx, if (ret) return ret; =20 + if (!anv->hw->has_lsq_nvmmu && + !apple_nvme_reserve_tag_t8015(anv, cmnd)) { + ret =3D BLK_STS_RESOURCE; + goto out_free_cmd; + } + if (blk_rq_nr_phys_segments(req)) { ret =3D apple_nvme_map_data(anv, req, cmnd); if (ret) @@ -806,6 +865,9 @@ static blk_status_t apple_nvme_queue_rq(struct blk_mq_h= w_ctx *hctx, return BLK_STS_OK; =20 out_free_cmd: + if (!anv->hw->has_lsq_nvmmu) + apple_nvme_release_tag_t8015(anv, cmnd->common.command_id); + nvme_cleanup_cmd(req); return ret; } @@ -1165,6 +1227,9 @@ static void apple_nvme_reset_work(struct work_struct = *work) if (ret) goto out; =20 + if (!anv->hw->has_lsq_nvmmu) + WRITE_ONCE(anv->t8015_active_tags, 0); + dev_dbg(anv->dev, "Starting admin queue"); apple_nvme_init_queue(&anv->adminq); nvme_unquiesce_admin_queue(&anv->ctrl); --=20 2.54.0