@@ -1855,26 +1855,14 @@ static int nvme_identify_ns_nvm(struct nvme_ctrl *ctrl, unsigned int nsid,
18551855 return ret ;
18561856}
18571857
1858- static void nvme_init_ms ( struct nvme_ctrl * ctrl , struct nvme_ns_head * head ,
1858+ static void nvme_configure_pi_elbas ( struct nvme_ns_head * head ,
18591859 struct nvme_id_ns * id , struct nvme_id_ns_nvm * nvm )
18601860{
1861- bool first = id -> dps & NVME_NS_DPS_PI_FIRST ;
1862- unsigned lbaf = nvme_lbaf_index (id -> flbas );
1863- u32 elbaf ;
1864-
1865- head -> pi_size = 0 ;
1866- head -> ms = le16_to_cpu (id -> lbaf [lbaf ].ms );
1867- if (!nvm || !(ctrl -> ctratt & NVME_CTRL_ATTR_ELBAS )) {
1868- head -> pi_size = sizeof (struct t10_pi_tuple );
1869- head -> guard_type = NVME_NVM_NS_16B_GUARD ;
1870- goto set_pi ;
1871- }
1872-
1873- elbaf = le32_to_cpu (nvm -> elbaf [lbaf ]);
1861+ u32 elbaf = le32_to_cpu (nvm -> elbaf [nvme_lbaf_index (id -> flbas )]);
18741862
18751863 /* no support for storage tag formats right now */
18761864 if (nvme_elbaf_sts (elbaf ))
1877- goto set_pi ;
1865+ return ;
18781866
18791867 head -> guard_type = nvme_elbaf_guard_type (elbaf );
18801868 switch (head -> guard_type ) {
@@ -1887,29 +1875,32 @@ static void nvme_init_ms(struct nvme_ctrl *ctrl, struct nvme_ns_head *head,
18871875 default :
18881876 break ;
18891877 }
1890-
1891- set_pi :
1892- if (head -> pi_size && head -> ms >= head -> pi_size )
1893- head -> pi_type = id -> dps & NVME_NS_DPS_PI_MASK ;
1894- else
1895- head -> pi_type = 0 ;
1896-
1897- if (first )
1898- head -> pi_offset = 0 ;
1899- else
1900- head -> pi_offset = head -> ms - head -> pi_size ;
19011878}
19021879
19031880static void nvme_configure_metadata (struct nvme_ctrl * ctrl ,
19041881 struct nvme_ns_head * head , struct nvme_id_ns * id ,
19051882 struct nvme_id_ns_nvm * nvm )
19061883{
1907- nvme_init_ms (ctrl , head , id , nvm );
1908-
19091884 head -> features &= ~(NVME_NS_METADATA_SUPPORTED | NVME_NS_EXT_LBAS );
1885+ head -> pi_type = 0 ;
1886+ head -> pi_size = 0 ;
1887+ head -> pi_offset = 0 ;
1888+ head -> ms = le16_to_cpu (id -> lbaf [nvme_lbaf_index (id -> flbas )].ms );
19101889 if (!head -> ms || !(ctrl -> ops -> flags & NVME_F_METADATA_SUPPORTED ))
19111890 return ;
19121891
1892+ if (nvm && (ctrl -> ctratt & NVME_CTRL_ATTR_ELBAS )) {
1893+ nvme_configure_pi_elbas (head , id , nvm );
1894+ } else {
1895+ head -> pi_size = sizeof (struct t10_pi_tuple );
1896+ head -> guard_type = NVME_NVM_NS_16B_GUARD ;
1897+ }
1898+
1899+ if (head -> pi_size && head -> ms >= head -> pi_size )
1900+ head -> pi_type = id -> dps & NVME_NS_DPS_PI_MASK ;
1901+ if (!(id -> dps & NVME_NS_DPS_PI_FIRST ))
1902+ head -> pi_offset = head -> ms - head -> pi_size ;
1903+
19131904 if (ctrl -> ops -> flags & NVME_F_FABRICS ) {
19141905 /*
19151906 * The NVMe over Fabrics specification only supports metadata as
0 commit comments