@@ -813,6 +813,30 @@ static blk_status_t nvme_setup_discard(struct nvme_ns *ns, struct request *req,
813
813
return BLK_STS_OK ;
814
814
}
815
815
816
+ static void nvme_set_ref_tag (struct nvme_ns * ns , struct nvme_command * cmnd ,
817
+ struct request * req )
818
+ {
819
+ u32 upper , lower ;
820
+ u64 ref48 ;
821
+
822
+ /* both rw and write zeroes share the same reftag format */
823
+ switch (ns -> guard_type ) {
824
+ case NVME_NVM_NS_16B_GUARD :
825
+ cmnd -> rw .reftag = cpu_to_le32 (t10_pi_ref_tag (req ));
826
+ break ;
827
+ case NVME_NVM_NS_64B_GUARD :
828
+ ref48 = ext_pi_ref_tag (req );
829
+ lower = lower_32_bits (ref48 );
830
+ upper = upper_32_bits (ref48 );
831
+
832
+ cmnd -> rw .reftag = cpu_to_le32 (lower );
833
+ cmnd -> rw .cdw3 = cpu_to_le32 (upper );
834
+ break ;
835
+ default :
836
+ break ;
837
+ }
838
+ }
839
+
816
840
static inline blk_status_t nvme_setup_write_zeroes (struct nvme_ns * ns ,
817
841
struct request * req , struct nvme_command * cmnd )
818
842
{
@@ -834,8 +858,7 @@ static inline blk_status_t nvme_setup_write_zeroes(struct nvme_ns *ns,
834
858
switch (ns -> pi_type ) {
835
859
case NVME_NS_DPS_PI_TYPE1 :
836
860
case NVME_NS_DPS_PI_TYPE2 :
837
- cmnd -> write_zeroes .reftag =
838
- cpu_to_le32 (t10_pi_ref_tag (req ));
861
+ nvme_set_ref_tag (ns , cmnd , req );
839
862
break ;
840
863
}
841
864
}
@@ -861,7 +884,8 @@ static inline blk_status_t nvme_setup_rw(struct nvme_ns *ns,
861
884
cmnd -> rw .opcode = op ;
862
885
cmnd -> rw .flags = 0 ;
863
886
cmnd -> rw .nsid = cpu_to_le32 (ns -> head -> ns_id );
864
- cmnd -> rw .rsvd2 = 0 ;
887
+ cmnd -> rw .cdw2 = 0 ;
888
+ cmnd -> rw .cdw3 = 0 ;
865
889
cmnd -> rw .metadata = 0 ;
866
890
cmnd -> rw .slba = cpu_to_le64 (nvme_sect_to_lba (ns , blk_rq_pos (req )));
867
891
cmnd -> rw .length = cpu_to_le16 ((blk_rq_bytes (req ) >> ns -> lba_shift ) - 1 );
@@ -892,7 +916,7 @@ static inline blk_status_t nvme_setup_rw(struct nvme_ns *ns,
892
916
NVME_RW_PRINFO_PRCHK_REF ;
893
917
if (op == nvme_cmd_zone_append )
894
918
control |= NVME_RW_APPEND_PIREMAP ;
895
- cmnd -> rw . reftag = cpu_to_le32 ( t10_pi_ref_tag ( req ) );
919
+ nvme_set_ref_tag ( ns , cmnd , req );
896
920
break ;
897
921
}
898
922
}
@@ -1544,33 +1568,58 @@ int nvme_getgeo(struct block_device *bdev, struct hd_geometry *geo)
1544
1568
}
1545
1569
1546
1570
#ifdef CONFIG_BLK_DEV_INTEGRITY
1547
- static void nvme_init_integrity (struct gendisk * disk , u16 ms , u8 pi_type ,
1571
+ static void nvme_init_integrity (struct gendisk * disk , struct nvme_ns * ns ,
1548
1572
u32 max_integrity_segments )
1549
1573
{
1550
1574
struct blk_integrity integrity = { };
1551
1575
1552
- switch (pi_type ) {
1576
+ switch (ns -> pi_type ) {
1553
1577
case NVME_NS_DPS_PI_TYPE3 :
1554
- integrity .profile = & t10_pi_type3_crc ;
1555
- integrity .tag_size = sizeof (u16 ) + sizeof (u32 );
1556
- integrity .flags |= BLK_INTEGRITY_DEVICE_CAPABLE ;
1578
+ switch (ns -> guard_type ) {
1579
+ case NVME_NVM_NS_16B_GUARD :
1580
+ integrity .profile = & t10_pi_type3_crc ;
1581
+ integrity .tag_size = sizeof (u16 ) + sizeof (u32 );
1582
+ integrity .flags |= BLK_INTEGRITY_DEVICE_CAPABLE ;
1583
+ break ;
1584
+ case NVME_NVM_NS_64B_GUARD :
1585
+ integrity .profile = & ext_pi_type3_crc64 ;
1586
+ integrity .tag_size = sizeof (u16 ) + 6 ;
1587
+ integrity .flags |= BLK_INTEGRITY_DEVICE_CAPABLE ;
1588
+ break ;
1589
+ default :
1590
+ integrity .profile = NULL ;
1591
+ break ;
1592
+ }
1557
1593
break ;
1558
1594
case NVME_NS_DPS_PI_TYPE1 :
1559
1595
case NVME_NS_DPS_PI_TYPE2 :
1560
- integrity .profile = & t10_pi_type1_crc ;
1561
- integrity .tag_size = sizeof (u16 );
1562
- integrity .flags |= BLK_INTEGRITY_DEVICE_CAPABLE ;
1596
+ switch (ns -> guard_type ) {
1597
+ case NVME_NVM_NS_16B_GUARD :
1598
+ integrity .profile = & t10_pi_type1_crc ;
1599
+ integrity .tag_size = sizeof (u16 );
1600
+ integrity .flags |= BLK_INTEGRITY_DEVICE_CAPABLE ;
1601
+ break ;
1602
+ case NVME_NVM_NS_64B_GUARD :
1603
+ integrity .profile = & ext_pi_type1_crc64 ;
1604
+ integrity .tag_size = sizeof (u16 );
1605
+ integrity .flags |= BLK_INTEGRITY_DEVICE_CAPABLE ;
1606
+ break ;
1607
+ default :
1608
+ integrity .profile = NULL ;
1609
+ break ;
1610
+ }
1563
1611
break ;
1564
1612
default :
1565
1613
integrity .profile = NULL ;
1566
1614
break ;
1567
1615
}
1568
- integrity .tuple_size = ms ;
1616
+
1617
+ integrity .tuple_size = ns -> ms ;
1569
1618
blk_integrity_register (disk , & integrity );
1570
1619
blk_queue_max_integrity_segments (disk -> queue , max_integrity_segments );
1571
1620
}
1572
1621
#else
1573
- static void nvme_init_integrity (struct gendisk * disk , u16 ms , u8 pi_type ,
1622
+ static void nvme_init_integrity (struct gendisk * disk , struct nvme_ns * ns ,
1574
1623
u32 max_integrity_segments )
1575
1624
{
1576
1625
}
@@ -1612,17 +1661,73 @@ static bool nvme_ns_ids_equal(struct nvme_ns_ids *a, struct nvme_ns_ids *b)
1612
1661
a -> csi == b -> csi ;
1613
1662
}
1614
1663
1615
- static void nvme_configure_metadata (struct nvme_ns * ns , struct nvme_id_ns * id )
1664
+ static int nvme_init_ms (struct nvme_ns * ns , struct nvme_id_ns * id )
1616
1665
{
1666
+ bool first = id -> dps & NVME_NS_DPS_PI_FIRST ;
1667
+ unsigned lbaf = nvme_lbaf_index (id -> flbas );
1617
1668
struct nvme_ctrl * ctrl = ns -> ctrl ;
1669
+ struct nvme_command c = { };
1670
+ struct nvme_id_ns_nvm * nvm ;
1671
+ int ret = 0 ;
1672
+ u32 elbaf ;
1673
+
1674
+ ns -> pi_size = 0 ;
1675
+ ns -> ms = le16_to_cpu (id -> lbaf [lbaf ].ms );
1676
+ if (!(ctrl -> ctratt & NVME_CTRL_ATTR_ELBAS )) {
1677
+ ns -> pi_size = sizeof (struct t10_pi_tuple );
1678
+ ns -> guard_type = NVME_NVM_NS_16B_GUARD ;
1679
+ goto set_pi ;
1680
+ }
1681
+
1682
+ nvm = kzalloc (sizeof (* nvm ), GFP_KERNEL );
1683
+ if (!nvm )
1684
+ return - ENOMEM ;
1618
1685
1619
- ns -> ms = le16_to_cpu (id -> lbaf [id -> flbas & NVME_NS_FLBAS_LBA_MASK ].ms );
1620
- if (id -> dps & NVME_NS_DPS_PI_FIRST ||
1621
- ns -> ms == sizeof (struct t10_pi_tuple ))
1686
+ c .identify .opcode = nvme_admin_identify ;
1687
+ c .identify .nsid = cpu_to_le32 (ns -> head -> ns_id );
1688
+ c .identify .cns = NVME_ID_CNS_CS_NS ;
1689
+ c .identify .csi = NVME_CSI_NVM ;
1690
+
1691
+ ret = nvme_submit_sync_cmd (ns -> ctrl -> admin_q , & c , nvm , sizeof (* nvm ));
1692
+ if (ret )
1693
+ goto free_data ;
1694
+
1695
+ elbaf = le32_to_cpu (nvm -> elbaf [lbaf ]);
1696
+
1697
+ /* no support for storage tag formats right now */
1698
+ if (nvme_elbaf_sts (elbaf ))
1699
+ goto free_data ;
1700
+
1701
+ ns -> guard_type = nvme_elbaf_guard_type (elbaf );
1702
+ switch (ns -> guard_type ) {
1703
+ case NVME_NVM_NS_64B_GUARD :
1704
+ ns -> pi_size = sizeof (struct crc64_pi_tuple );
1705
+ break ;
1706
+ case NVME_NVM_NS_16B_GUARD :
1707
+ ns -> pi_size = sizeof (struct t10_pi_tuple );
1708
+ break ;
1709
+ default :
1710
+ break ;
1711
+ }
1712
+
1713
+ free_data :
1714
+ kfree (nvm );
1715
+ set_pi :
1716
+ if (ns -> pi_size && (first || ns -> ms == ns -> pi_size ))
1622
1717
ns -> pi_type = id -> dps & NVME_NS_DPS_PI_MASK ;
1623
1718
else
1624
1719
ns -> pi_type = 0 ;
1625
1720
1721
+ return ret ;
1722
+ }
1723
+
1724
+ static void nvme_configure_metadata (struct nvme_ns * ns , struct nvme_id_ns * id )
1725
+ {
1726
+ struct nvme_ctrl * ctrl = ns -> ctrl ;
1727
+
1728
+ if (nvme_init_ms (ns , id ))
1729
+ return ;
1730
+
1626
1731
ns -> features &= ~(NVME_NS_METADATA_SUPPORTED | NVME_NS_EXT_LBAS );
1627
1732
if (!ns -> ms || !(ctrl -> ops -> flags & NVME_F_METADATA_SUPPORTED ))
1628
1733
return ;
@@ -1738,7 +1843,7 @@ static void nvme_update_disk_info(struct gendisk *disk,
1738
1843
if (ns -> ms ) {
1739
1844
if (IS_ENABLED (CONFIG_BLK_DEV_INTEGRITY ) &&
1740
1845
(ns -> features & NVME_NS_METADATA_SUPPORTED ))
1741
- nvme_init_integrity (disk , ns -> ms , ns -> pi_type ,
1846
+ nvme_init_integrity (disk , ns ,
1742
1847
ns -> ctrl -> max_integrity_segments );
1743
1848
else if (!nvme_ns_has_pi (ns ))
1744
1849
capacity = 0 ;
@@ -1793,7 +1898,7 @@ static void nvme_set_chunk_sectors(struct nvme_ns *ns, struct nvme_id_ns *id)
1793
1898
1794
1899
static int nvme_update_ns_info (struct nvme_ns * ns , struct nvme_id_ns * id )
1795
1900
{
1796
- unsigned lbaf = id -> flbas & NVME_NS_FLBAS_LBA_MASK ;
1901
+ unsigned lbaf = nvme_lbaf_index ( id -> flbas ) ;
1797
1902
int ret ;
1798
1903
1799
1904
blk_mq_freeze_queue (ns -> disk -> queue );
@@ -2138,20 +2243,27 @@ static int nvme_configure_timestamp(struct nvme_ctrl *ctrl)
2138
2243
return ret ;
2139
2244
}
2140
2245
2141
- static int nvme_configure_acre (struct nvme_ctrl * ctrl )
2246
+ static int nvme_configure_host_options (struct nvme_ctrl * ctrl )
2142
2247
{
2143
2248
struct nvme_feat_host_behavior * host ;
2249
+ u8 acre = 0 , lbafee = 0 ;
2144
2250
int ret ;
2145
2251
2146
2252
/* Don't bother enabling the feature if retry delay is not reported */
2147
- if (!ctrl -> crdt [0 ])
2253
+ if (ctrl -> crdt [0 ])
2254
+ acre = NVME_ENABLE_ACRE ;
2255
+ if (ctrl -> ctratt & NVME_CTRL_ATTR_ELBAS )
2256
+ lbafee = NVME_ENABLE_LBAFEE ;
2257
+
2258
+ if (!acre && !lbafee )
2148
2259
return 0 ;
2149
2260
2150
2261
host = kzalloc (sizeof (* host ), GFP_KERNEL );
2151
2262
if (!host )
2152
2263
return 0 ;
2153
2264
2154
- host -> acre = NVME_ENABLE_ACRE ;
2265
+ host -> acre = acre ;
2266
+ host -> lbafee = lbafee ;
2155
2267
ret = nvme_set_features (ctrl , NVME_FEAT_HOST_BEHAVIOR , 0 ,
2156
2268
host , sizeof (* host ), NULL );
2157
2269
kfree (host );
@@ -2989,7 +3101,7 @@ int nvme_init_ctrl_finish(struct nvme_ctrl *ctrl)
2989
3101
if (ret < 0 )
2990
3102
return ret ;
2991
3103
2992
- ret = nvme_configure_acre (ctrl );
3104
+ ret = nvme_configure_host_options (ctrl );
2993
3105
if (ret < 0 )
2994
3106
return ret ;
2995
3107
@@ -4703,12 +4815,14 @@ static inline void _nvme_check_size(void)
4703
4815
BUILD_BUG_ON (sizeof (struct nvme_id_ctrl ) != NVME_IDENTIFY_DATA_SIZE );
4704
4816
BUILD_BUG_ON (sizeof (struct nvme_id_ns ) != NVME_IDENTIFY_DATA_SIZE );
4705
4817
BUILD_BUG_ON (sizeof (struct nvme_id_ns_zns ) != NVME_IDENTIFY_DATA_SIZE );
4818
+ BUILD_BUG_ON (sizeof (struct nvme_id_ns_nvm ) != NVME_IDENTIFY_DATA_SIZE );
4706
4819
BUILD_BUG_ON (sizeof (struct nvme_id_ctrl_zns ) != NVME_IDENTIFY_DATA_SIZE );
4707
4820
BUILD_BUG_ON (sizeof (struct nvme_id_ctrl_nvm ) != NVME_IDENTIFY_DATA_SIZE );
4708
4821
BUILD_BUG_ON (sizeof (struct nvme_lba_range_type ) != 64 );
4709
4822
BUILD_BUG_ON (sizeof (struct nvme_smart_log ) != 512 );
4710
4823
BUILD_BUG_ON (sizeof (struct nvme_dbbuf ) != 64 );
4711
4824
BUILD_BUG_ON (sizeof (struct nvme_directive_cmd ) != 64 );
4825
+ BUILD_BUG_ON (sizeof (struct nvme_feat_host_behavior ) != 512 );
4712
4826
}
4713
4827
4714
4828
0 commit comments