* [PATCH v2 0/2] Cleanup controller configuration register handling
@ 2025-02-13 6:49 Damien Le Moal
2025-02-13 6:49 ` [PATCH v2 1/2] nvme: Cleanup the definition of the controller config register fields Damien Le Moal
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Damien Le Moal @ 2025-02-13 6:49 UTC (permalink / raw)
To: linux-nvme, Keith Busch, Christoph Hellwig, Sagi Grimberg
A couple of patches to cleanup the definition and handling of the CC
register. No functional changes.
Changes from v1:
- Added comments to describe the CC enum and its fields (patch 1)
- Added review tags to patch 2
Damien Le Moal (2):
nvme: Cleanup the definition of the controller config register fields
nvmet: Use enum definitions instead of hardcoded values
drivers/nvme/target/nvmet.h | 14 ++++++-------
include/linux/nvme.h | 40 ++++++++++++++++++++++++++++++-------
2 files changed, 40 insertions(+), 14 deletions(-)
--
2.48.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 1/2] nvme: Cleanup the definition of the controller config register fields
2025-02-13 6:49 [PATCH v2 0/2] Cleanup controller configuration register handling Damien Le Moal
@ 2025-02-13 6:49 ` Damien Le Moal
2025-02-13 7:05 ` Christoph Hellwig
2025-02-13 17:44 ` Chaitanya Kulkarni
2025-02-13 6:50 ` [PATCH v2 2/2] nvmet: Use enum definitions instead of hardcoded values Damien Le Moal
2025-02-18 15:46 ` [PATCH v2 0/2] Cleanup controller configuration register handling Keith Busch
2 siblings, 2 replies; 6+ messages in thread
From: Damien Le Moal @ 2025-02-13 6:49 UTC (permalink / raw)
To: linux-nvme, Keith Busch, Christoph Hellwig, Sagi Grimberg
Reorganized the enum used to define the fields of the contrller
configuration (CC) register in include/linux/nvme.h to:
1) Group together all the values defined for each field.
2) Add the missing field masks definitions.
3) Add comments to describe the enum and each field.
Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
---
include/linux/nvme.h | 40 +++++++++++++++++++++++++++++++++-------
1 file changed, 33 insertions(+), 7 deletions(-)
diff --git a/include/linux/nvme.h b/include/linux/nvme.h
index fe3b60818fdc..2dc05b1c3283 100644
--- a/include/linux/nvme.h
+++ b/include/linux/nvme.h
@@ -199,28 +199,54 @@ enum {
#define NVME_NVM_IOSQES 6
#define NVME_NVM_IOCQES 4
+/*
+ * Controller Configuration (CC) register (Offset 14h)
+ */
enum {
+ /* Enable (EN): bit 0 */
NVME_CC_ENABLE = 1 << 0,
NVME_CC_EN_SHIFT = 0,
+
+ /* Bits 03:01 are reserved (NVMe Base Specification rev 2.1) */
+
+ /* I/O Command Set Selected (CSS): bits 06:04 */
NVME_CC_CSS_SHIFT = 4,
- NVME_CC_MPS_SHIFT = 7,
- NVME_CC_AMS_SHIFT = 11,
- NVME_CC_SHN_SHIFT = 14,
- NVME_CC_IOSQES_SHIFT = 16,
- NVME_CC_IOCQES_SHIFT = 20,
+ NVME_CC_CSS_MASK = 7 << NVME_CC_CSS_SHIFT,
NVME_CC_CSS_NVM = 0 << NVME_CC_CSS_SHIFT,
NVME_CC_CSS_CSI = 6 << NVME_CC_CSS_SHIFT,
- NVME_CC_CSS_MASK = 7 << NVME_CC_CSS_SHIFT,
+
+ /* Memory Page Size (MPS): bits 10:07 */
+ NVME_CC_MPS_SHIFT = 7,
+ NVME_CC_MPS_MASK = 0xf << NVME_CC_MPS_SHIFT,
+
+ /* Arbitration Mechanism Selected (AMS): bits 13:11 */
+ NVME_CC_AMS_SHIFT = 11,
+ NVME_CC_AMS_MASK = 7 << NVME_CC_AMS_SHIFT,
NVME_CC_AMS_RR = 0 << NVME_CC_AMS_SHIFT,
NVME_CC_AMS_WRRU = 1 << NVME_CC_AMS_SHIFT,
NVME_CC_AMS_VS = 7 << NVME_CC_AMS_SHIFT,
+
+ /* Shutdown Notification (SHN): bits 15:14 */
+ NVME_CC_SHN_SHIFT = 14,
+ NVME_CC_SHN_MASK = 3 << NVME_CC_SHN_SHIFT,
NVME_CC_SHN_NONE = 0 << NVME_CC_SHN_SHIFT,
NVME_CC_SHN_NORMAL = 1 << NVME_CC_SHN_SHIFT,
NVME_CC_SHN_ABRUPT = 2 << NVME_CC_SHN_SHIFT,
- NVME_CC_SHN_MASK = 3 << NVME_CC_SHN_SHIFT,
+
+ /* I/O Submission Queue Entry Size (IOSQES): bits 19:16 */
+ NVME_CC_IOSQES_SHIFT = 16,
+ NVME_CC_IOSQES_MASK = 0xf << NVME_CC_IOSQES_SHIFT,
NVME_CC_IOSQES = NVME_NVM_IOSQES << NVME_CC_IOSQES_SHIFT,
+
+ /* I/O Completion Queue Entry Size (IOCQES): bits 23:20 */
+ NVME_CC_IOCQES_SHIFT = 20,
+ NVME_CC_IOCQES_MASK = 0xf << NVME_CC_IOCQES_SHIFT,
NVME_CC_IOCQES = NVME_NVM_IOCQES << NVME_CC_IOCQES_SHIFT,
+
+ /* Controller Ready Independent of Media Enable (CRIME): bit 24 */
NVME_CC_CRIME = 1 << 24,
+
+ /* Bits 25:31 are reserved (NVMe Base Specification rev 2.1) */
};
enum {
--
2.48.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 2/2] nvmet: Use enum definitions instead of hardcoded values
2025-02-13 6:49 [PATCH v2 0/2] Cleanup controller configuration register handling Damien Le Moal
2025-02-13 6:49 ` [PATCH v2 1/2] nvme: Cleanup the definition of the controller config register fields Damien Le Moal
@ 2025-02-13 6:50 ` Damien Le Moal
2025-02-18 15:46 ` [PATCH v2 0/2] Cleanup controller configuration register handling Keith Busch
2 siblings, 0 replies; 6+ messages in thread
From: Damien Le Moal @ 2025-02-13 6:50 UTC (permalink / raw)
To: linux-nvme, Keith Busch, Christoph Hellwig, Sagi Grimberg
Change the definition of the inline functions nvmet_cc_en(),
nvmet_cc_css(), nvmet_cc_mps(), nvmet_cc_ams(), nvmet_cc_shn(),
nvmet_cc_iosqes(), and nvmet_cc_iocqes() to use the enum difinitions in
include/linux/nvme.h instead of hardcoded values.
Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
---
drivers/nvme/target/nvmet.h | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/drivers/nvme/target/nvmet.h b/drivers/nvme/target/nvmet.h
index 4be8d22d2d8d..d2c1233981e1 100644
--- a/drivers/nvme/target/nvmet.h
+++ b/drivers/nvme/target/nvmet.h
@@ -784,37 +784,37 @@ u16 nvmet_report_invalid_opcode(struct nvmet_req *req);
static inline bool nvmet_cc_en(u32 cc)
{
- return (cc >> NVME_CC_EN_SHIFT) & 0x1;
+ return (cc & NVME_CC_ENABLE) >> NVME_CC_EN_SHIFT;
}
static inline u8 nvmet_cc_css(u32 cc)
{
- return (cc >> NVME_CC_CSS_SHIFT) & 0x7;
+ return (cc & NVME_CC_CSS_MASK) >> NVME_CC_CSS_SHIFT;
}
static inline u8 nvmet_cc_mps(u32 cc)
{
- return (cc >> NVME_CC_MPS_SHIFT) & 0xf;
+ return (cc & NVME_CC_MPS_MASK) >> NVME_CC_MPS_SHIFT;
}
static inline u8 nvmet_cc_ams(u32 cc)
{
- return (cc >> NVME_CC_AMS_SHIFT) & 0x7;
+ return (cc & NVME_CC_AMS_MASK) >> NVME_CC_AMS_SHIFT;
}
static inline u8 nvmet_cc_shn(u32 cc)
{
- return (cc >> NVME_CC_SHN_SHIFT) & 0x3;
+ return (cc & NVME_CC_SHN_MASK) >> NVME_CC_SHN_SHIFT;
}
static inline u8 nvmet_cc_iosqes(u32 cc)
{
- return (cc >> NVME_CC_IOSQES_SHIFT) & 0xf;
+ return (cc & NVME_CC_IOSQES_MASK) >> NVME_CC_IOSQES_SHIFT;
}
static inline u8 nvmet_cc_iocqes(u32 cc)
{
- return (cc >> NVME_CC_IOCQES_SHIFT) & 0xf;
+ return (cc & NVME_CC_IOCQES_MASK) >> NVME_CC_IOCQES_SHIFT;
}
/* Convert a 32-bit number to a 16-bit 0's based number */
--
2.48.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v2 1/2] nvme: Cleanup the definition of the controller config register fields
2025-02-13 6:49 ` [PATCH v2 1/2] nvme: Cleanup the definition of the controller config register fields Damien Le Moal
@ 2025-02-13 7:05 ` Christoph Hellwig
2025-02-13 17:44 ` Chaitanya Kulkarni
1 sibling, 0 replies; 6+ messages in thread
From: Christoph Hellwig @ 2025-02-13 7:05 UTC (permalink / raw)
To: Damien Le Moal; +Cc: linux-nvme, Keith Busch, Sagi Grimberg
Looks good:
Reviewed-by: Christoph Hellwig <hch@lst.de>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 1/2] nvme: Cleanup the definition of the controller config register fields
2025-02-13 6:49 ` [PATCH v2 1/2] nvme: Cleanup the definition of the controller config register fields Damien Le Moal
2025-02-13 7:05 ` Christoph Hellwig
@ 2025-02-13 17:44 ` Chaitanya Kulkarni
1 sibling, 0 replies; 6+ messages in thread
From: Chaitanya Kulkarni @ 2025-02-13 17:44 UTC (permalink / raw)
To: Damien Le Moal, linux-nvme@lists.infradead.org, Keith Busch,
Christoph Hellwig, Sagi Grimberg
On 2/12/2025 10:49 PM, Damien Le Moal wrote:
> Reorganized the enum used to define the fields of the contrller
> configuration (CC) register in include/linux/nvme.h to:
> 1) Group together all the values defined for each field.
> 2) Add the missing field masks definitions.
> 3) Add comments to describe the enum and each field.
>
> Signed-off-by: Damien Le Moal<dlemoal@kernel.org>
Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
-ck
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 0/2] Cleanup controller configuration register handling
2025-02-13 6:49 [PATCH v2 0/2] Cleanup controller configuration register handling Damien Le Moal
2025-02-13 6:49 ` [PATCH v2 1/2] nvme: Cleanup the definition of the controller config register fields Damien Le Moal
2025-02-13 6:50 ` [PATCH v2 2/2] nvmet: Use enum definitions instead of hardcoded values Damien Le Moal
@ 2025-02-18 15:46 ` Keith Busch
2 siblings, 0 replies; 6+ messages in thread
From: Keith Busch @ 2025-02-18 15:46 UTC (permalink / raw)
To: Damien Le Moal; +Cc: linux-nvme, Christoph Hellwig, Sagi Grimberg
On Thu, Feb 13, 2025 at 03:49:58PM +0900, Damien Le Moal wrote:
> A couple of patches to cleanup the definition and handling of the CC
> register. No functional changes.
Thanks, applied to nvme-6.14.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2025-02-18 15:46 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-13 6:49 [PATCH v2 0/2] Cleanup controller configuration register handling Damien Le Moal
2025-02-13 6:49 ` [PATCH v2 1/2] nvme: Cleanup the definition of the controller config register fields Damien Le Moal
2025-02-13 7:05 ` Christoph Hellwig
2025-02-13 17:44 ` Chaitanya Kulkarni
2025-02-13 6:50 ` [PATCH v2 2/2] nvmet: Use enum definitions instead of hardcoded values Damien Le Moal
2025-02-18 15:46 ` [PATCH v2 0/2] Cleanup controller configuration register handling Keith Busch
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox