Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * Copyright(c) 2013-2015 Intel Corporation. All rights reserved.
0004  */
0005 #ifndef __LABEL_H__
0006 #define __LABEL_H__
0007 
0008 #include <linux/ndctl.h>
0009 #include <linux/sizes.h>
0010 #include <linux/uuid.h>
0011 #include <linux/io.h>
0012 
0013 enum {
0014     NSINDEX_SIG_LEN = 16,
0015     NSINDEX_ALIGN = 256,
0016     NSINDEX_SEQ_MASK = 0x3,
0017     NSLABEL_UUID_LEN = 16,
0018     NSLABEL_NAME_LEN = 64,
0019     NSLABEL_FLAG_ROLABEL = 0x1,  /* read-only label */
0020     NSLABEL_FLAG_LOCAL = 0x2,    /* DIMM-local namespace */
0021     NSLABEL_FLAG_BTT = 0x4,      /* namespace contains a BTT */
0022     NSLABEL_FLAG_UPDATING = 0x8, /* label being updated */
0023     BTT_ALIGN = 4096,            /* all btt structures */
0024     BTTINFO_SIG_LEN = 16,
0025     BTTINFO_UUID_LEN = 16,
0026     BTTINFO_FLAG_ERROR = 0x1,    /* error state (read-only) */
0027     BTTINFO_MAJOR_VERSION = 1,
0028     ND_LABEL_MIN_SIZE = 256 * 4, /* see sizeof_namespace_index() */
0029     ND_LABEL_ID_SIZE = 50,
0030     ND_NSINDEX_INIT = 0x1,
0031 };
0032 
0033 /**
0034  * struct nd_namespace_index - label set superblock
0035  * @sig: NAMESPACE_INDEX\0
0036  * @flags: placeholder
0037  * @labelsize: log2 size (v1 labels 128 bytes v2 labels 256 bytes)
0038  * @seq: sequence number for this index
0039  * @myoff: offset of this index in label area
0040  * @mysize: size of this index struct
0041  * @otheroff: offset of other index
0042  * @labeloff: offset of first label slot
0043  * @nslot: total number of label slots
0044  * @major: label area major version
0045  * @minor: label area minor version
0046  * @checksum: fletcher64 of all fields
0047  * @free: bitmap, nlabel bits
0048  *
0049  * The size of free[] is rounded up so the total struct size is a
0050  * multiple of NSINDEX_ALIGN bytes.  Any bits this allocates beyond
0051  * nlabel bits must be zero.
0052  */
0053 struct nd_namespace_index {
0054     u8 sig[NSINDEX_SIG_LEN];
0055     u8 flags[3];
0056     u8 labelsize;
0057     __le32 seq;
0058     __le64 myoff;
0059     __le64 mysize;
0060     __le64 otheroff;
0061     __le64 labeloff;
0062     __le32 nslot;
0063     __le16 major;
0064     __le16 minor;
0065     __le64 checksum;
0066     u8 free[];
0067 };
0068 
0069 /**
0070  * struct cxl_region_label - CXL 2.0 Table 211
0071  * @type: uuid identifying this label format (region)
0072  * @uuid: uuid for the region this label describes
0073  * @flags: NSLABEL_FLAG_UPDATING (all other flags reserved)
0074  * @nlabel: 1 per interleave-way in the region
0075  * @position: this label's position in the set
0076  * @dpa: start address in device-local capacity for this label
0077  * @rawsize: size of this label's contribution to region
0078  * @hpa: mandatory system physical address to map this region
0079  * @slot: slot id of this label in label area
0080  * @ig: interleave granularity (1 << @ig) * 256 bytes
0081  * @align: alignment in SZ_256M blocks
0082  * @reserved: reserved
0083  * @checksum: fletcher64 sum of this label
0084  */
0085 struct cxl_region_label {
0086     u8 type[NSLABEL_UUID_LEN];
0087     u8 uuid[NSLABEL_UUID_LEN];
0088     __le32 flags;
0089     __le16 nlabel;
0090     __le16 position;
0091     __le64 dpa;
0092     __le64 rawsize;
0093     __le64 hpa;
0094     __le32 slot;
0095     __le32 ig;
0096     __le32 align;
0097     u8 reserved[0xac];
0098     __le64 checksum;
0099 };
0100 
0101 /**
0102  * struct nvdimm_efi_label - namespace superblock
0103  * @uuid: UUID per RFC 4122
0104  * @name: optional name (NULL-terminated)
0105  * @flags: see NSLABEL_FLAG_*
0106  * @nlabel: num labels to describe this ns
0107  * @position: labels position in set
0108  * @isetcookie: interleave set cookie
0109  * @lbasize: LBA size in bytes or 0 for pmem
0110  * @dpa: DPA of NVM range on this DIMM
0111  * @rawsize: size of namespace
0112  * @slot: slot of this label in label area
0113  * @align: physical address alignment of the namespace
0114  * @reserved: reserved
0115  * @type_guid: copy of struct acpi_nfit_system_address.range_guid
0116  * @abstraction_guid: personality id (btt, btt2, fsdax, devdax....)
0117  * @reserved2: reserved
0118  * @checksum: fletcher64 sum of this object
0119  */
0120 struct nvdimm_efi_label {
0121     u8 uuid[NSLABEL_UUID_LEN];
0122     u8 name[NSLABEL_NAME_LEN];
0123     __le32 flags;
0124     __le16 nlabel;
0125     __le16 position;
0126     __le64 isetcookie;
0127     __le64 lbasize;
0128     __le64 dpa;
0129     __le64 rawsize;
0130     __le32 slot;
0131     /*
0132      * Accessing fields past this point should be gated by a
0133      * efi_namespace_label_has() check.
0134      */
0135     u8 align;
0136     u8 reserved[3];
0137     guid_t type_guid;
0138     guid_t abstraction_guid;
0139     u8 reserved2[88];
0140     __le64 checksum;
0141 };
0142 
0143 /**
0144  * struct nvdimm_cxl_label - CXL 2.0 Table 212
0145  * @type: uuid identifying this label format (namespace)
0146  * @uuid: uuid for the namespace this label describes
0147  * @name: friendly name for the namespace
0148  * @flags: NSLABEL_FLAG_UPDATING (all other flags reserved)
0149  * @nrange: discontiguous namespace support
0150  * @position: this label's position in the set
0151  * @dpa: start address in device-local capacity for this label
0152  * @rawsize: size of this label's contribution to namespace
0153  * @slot: slot id of this label in label area
0154  * @align: alignment in SZ_256M blocks
0155  * @region_uuid: host interleave set identifier
0156  * @abstraction_uuid: personality driver for this namespace
0157  * @lbasize: address geometry for disk-like personalities
0158  * @reserved: reserved
0159  * @checksum: fletcher64 sum of this label
0160  */
0161 struct nvdimm_cxl_label {
0162     u8 type[NSLABEL_UUID_LEN];
0163     u8 uuid[NSLABEL_UUID_LEN];
0164     u8 name[NSLABEL_NAME_LEN];
0165     __le32 flags;
0166     __le16 nrange;
0167     __le16 position;
0168     __le64 dpa;
0169     __le64 rawsize;
0170     __le32 slot;
0171     __le32 align;
0172     u8 region_uuid[16];
0173     u8 abstraction_uuid[16];
0174     __le16 lbasize;
0175     u8 reserved[0x56];
0176     __le64 checksum;
0177 };
0178 
0179 struct nd_namespace_label {
0180     union {
0181         struct nvdimm_cxl_label cxl;
0182         struct nvdimm_efi_label efi;
0183     };
0184 };
0185 
0186 #define NVDIMM_BTT_GUID "8aed63a2-29a2-4c66-8b12-f05d15d3922a"
0187 #define NVDIMM_BTT2_GUID "18633bfc-1735-4217-8ac9-17239282d3f8"
0188 #define NVDIMM_PFN_GUID "266400ba-fb9f-4677-bcb0-968f11d0d225"
0189 #define NVDIMM_DAX_GUID "97a86d9c-3cdd-4eda-986f-5068b4f80088"
0190 
0191 #define CXL_REGION_UUID "529d7c61-da07-47c4-a93f-ecdf2c06f444"
0192 #define CXL_NAMESPACE_UUID "68bb2c0a-5a77-4937-9f85-3caf41a0f93c"
0193 
0194 /**
0195  * struct nd_label_id - identifier string for dpa allocation
0196  * @id: "pmem-<namespace uuid>"
0197  */
0198 struct nd_label_id {
0199     char id[ND_LABEL_ID_SIZE];
0200 };
0201 
0202 /*
0203  * If the 'best' index is invalid, so is the 'next' index.  Otherwise,
0204  * the next index is MOD(index+1, 2)
0205  */
0206 static inline int nd_label_next_nsindex(int index)
0207 {
0208     if (index < 0)
0209         return -1;
0210 
0211     return (index + 1) % 2;
0212 }
0213 
0214 struct nvdimm_drvdata;
0215 int nd_label_data_init(struct nvdimm_drvdata *ndd);
0216 size_t sizeof_namespace_index(struct nvdimm_drvdata *ndd);
0217 int nd_label_active_count(struct nvdimm_drvdata *ndd);
0218 struct nd_namespace_label *nd_label_active(struct nvdimm_drvdata *ndd, int n);
0219 u32 nd_label_alloc_slot(struct nvdimm_drvdata *ndd);
0220 bool nd_label_free_slot(struct nvdimm_drvdata *ndd, u32 slot);
0221 u32 nd_label_nfree(struct nvdimm_drvdata *ndd);
0222 struct nd_region;
0223 struct nd_namespace_pmem;
0224 int nd_pmem_namespace_label_update(struct nd_region *nd_region,
0225         struct nd_namespace_pmem *nspm, resource_size_t size);
0226 #endif /* __LABEL_H__ */