@@ -2015,21 +2015,41 @@ static void nvme_configure_metadata(struct nvme_ctrl *ctrl,
2015
2015
}
2016
2016
2017
2017
2018
- static void nvme_update_atomic_write_disk_info (struct nvme_ns * ns ,
2019
- struct nvme_id_ns * id , struct queue_limits * lim ,
2020
- u32 bs , u32 atomic_bs )
2018
+ static u32 nvme_configure_atomic_write (struct nvme_ns * ns ,
2019
+ struct nvme_id_ns * id , struct queue_limits * lim , u32 bs )
2021
2020
{
2022
- unsigned int boundary = 0 ;
2021
+ u32 atomic_bs , boundary = 0 ;
2023
2022
2024
- if (id -> nsfeat & NVME_NS_FEAT_ATOMICS && id -> nawupf ) {
2025
- if (le16_to_cpu (id -> nabspf ))
2023
+ /*
2024
+ * We do not support an offset for the atomic boundaries.
2025
+ */
2026
+ if (id -> nabo )
2027
+ return bs ;
2028
+
2029
+ if ((id -> nsfeat & NVME_NS_FEAT_ATOMICS ) && id -> nawupf ) {
2030
+ /*
2031
+ * Use the per-namespace atomic write unit when available.
2032
+ */
2033
+ atomic_bs = (1 + le16_to_cpu (id -> nawupf )) * bs ;
2034
+ if (id -> nabspf )
2026
2035
boundary = (le16_to_cpu (id -> nabspf ) + 1 ) * bs ;
2036
+ } else {
2037
+ /*
2038
+ * Use the controller wide atomic write unit. This sucks
2039
+ * because the limit is defined in terms of logical blocks while
2040
+ * namespaces can have different formats, and because there is
2041
+ * no clear language in the specification prohibiting different
2042
+ * values for different controllers in the subsystem.
2043
+ */
2044
+ atomic_bs = (1 + ns -> ctrl -> subsys -> awupf ) * bs ;
2027
2045
}
2046
+
2028
2047
lim -> atomic_write_hw_max = atomic_bs ;
2029
2048
lim -> atomic_write_hw_boundary = boundary ;
2030
2049
lim -> atomic_write_hw_unit_min = bs ;
2031
2050
lim -> atomic_write_hw_unit_max = rounddown_pow_of_two (atomic_bs );
2032
2051
lim -> features |= BLK_FEAT_ATOMIC_WRITES ;
2052
+ return atomic_bs ;
2033
2053
}
2034
2054
2035
2055
static u32 nvme_max_drv_segments (struct nvme_ctrl * ctrl )
@@ -2067,34 +2087,8 @@ static bool nvme_update_disk_info(struct nvme_ns *ns, struct nvme_id_ns *id,
2067
2087
valid = false;
2068
2088
}
2069
2089
2070
- atomic_bs = phys_bs = bs ;
2071
- if (id -> nabo == 0 ) {
2072
- /*
2073
- * Bit 1 indicates whether NAWUPF is defined for this namespace
2074
- * and whether it should be used instead of AWUPF. If NAWUPF ==
2075
- * 0 then AWUPF must be used instead.
2076
- */
2077
- if (id -> nsfeat & NVME_NS_FEAT_ATOMICS && id -> nawupf )
2078
- atomic_bs = (1 + le16_to_cpu (id -> nawupf )) * bs ;
2079
- else
2080
- atomic_bs = (1 + ns -> ctrl -> awupf ) * bs ;
2081
-
2082
- /*
2083
- * Set subsystem atomic bs.
2084
- */
2085
- if (ns -> ctrl -> subsys -> atomic_bs ) {
2086
- if (atomic_bs != ns -> ctrl -> subsys -> atomic_bs ) {
2087
- dev_err_ratelimited (ns -> ctrl -> device ,
2088
- "%s: Inconsistent Atomic Write Size, Namespace will not be added: Subsystem=%d bytes, Controller/Namespace=%d bytes\n" ,
2089
- ns -> disk ? ns -> disk -> disk_name : "?" ,
2090
- ns -> ctrl -> subsys -> atomic_bs ,
2091
- atomic_bs );
2092
- }
2093
- } else
2094
- ns -> ctrl -> subsys -> atomic_bs = atomic_bs ;
2095
-
2096
- nvme_update_atomic_write_disk_info (ns , id , lim , bs , atomic_bs );
2097
- }
2090
+ phys_bs = bs ;
2091
+ atomic_bs = nvme_configure_atomic_write (ns , id , lim , bs );
2098
2092
2099
2093
if (id -> nsfeat & NVME_NS_FEAT_IO_OPT ) {
2100
2094
/* NPWG = Namespace Preferred Write Granularity */
@@ -2382,16 +2376,6 @@ static int nvme_update_ns_info_block(struct nvme_ns *ns,
2382
2376
if (!nvme_update_disk_info (ns , id , & lim ))
2383
2377
capacity = 0 ;
2384
2378
2385
- /*
2386
- * Validate the max atomic write size fits within the subsystem's
2387
- * atomic write capabilities.
2388
- */
2389
- if (lim .atomic_write_hw_max > ns -> ctrl -> subsys -> atomic_bs ) {
2390
- blk_mq_unfreeze_queue (ns -> disk -> queue , memflags );
2391
- ret = - ENXIO ;
2392
- goto out ;
2393
- }
2394
-
2395
2379
nvme_config_discard (ns , & lim );
2396
2380
if (IS_ENABLED (CONFIG_BLK_DEV_ZONED ) &&
2397
2381
ns -> head -> ids .csi == NVME_CSI_ZNS )
@@ -3215,6 +3199,7 @@ static int nvme_init_subsystem(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id)
3215
3199
memcpy (subsys -> model , id -> mn , sizeof (subsys -> model ));
3216
3200
subsys -> vendor_id = le16_to_cpu (id -> vid );
3217
3201
subsys -> cmic = id -> cmic ;
3202
+ subsys -> awupf = le16_to_cpu (id -> awupf );
3218
3203
3219
3204
/* Versions prior to 1.4 don't necessarily report a valid type */
3220
3205
if (id -> cntrltype == NVME_CTRL_DISC ||
@@ -3552,6 +3537,15 @@ static int nvme_init_identify(struct nvme_ctrl *ctrl)
3552
3537
if (ret )
3553
3538
goto out_free ;
3554
3539
}
3540
+
3541
+ if (le16_to_cpu (id -> awupf ) != ctrl -> subsys -> awupf ) {
3542
+ dev_err_ratelimited (ctrl -> device ,
3543
+ "inconsistent AWUPF, controller not added (%u/%u).\n" ,
3544
+ le16_to_cpu (id -> awupf ), ctrl -> subsys -> awupf );
3545
+ ret = - EINVAL ;
3546
+ goto out_free ;
3547
+ }
3548
+
3555
3549
memcpy (ctrl -> subsys -> firmware_rev , id -> fr ,
3556
3550
sizeof (ctrl -> subsys -> firmware_rev ));
3557
3551
@@ -3647,7 +3641,6 @@ static int nvme_init_identify(struct nvme_ctrl *ctrl)
3647
3641
dev_pm_qos_expose_latency_tolerance (ctrl -> device );
3648
3642
else if (!ctrl -> apst_enabled && prev_apst_enabled )
3649
3643
dev_pm_qos_hide_latency_tolerance (ctrl -> device );
3650
- ctrl -> awupf = le16_to_cpu (id -> awupf );
3651
3644
out_free :
3652
3645
kfree (id );
3653
3646
return ret ;
@@ -4036,6 +4029,10 @@ static int nvme_init_ns_head(struct nvme_ns *ns, struct nvme_ns_info *info)
4036
4029
list_add_tail_rcu (& ns -> siblings , & head -> list );
4037
4030
ns -> head = head ;
4038
4031
mutex_unlock (& ctrl -> subsys -> lock );
4032
+
4033
+ #ifdef CONFIG_NVME_MULTIPATH
4034
+ cancel_delayed_work (& head -> remove_work );
4035
+ #endif
4039
4036
return 0 ;
4040
4037
4041
4038
out_put_ns_head :
0 commit comments