Merge tag 'rust-6.9' of https://github.com/Rust-for-Linux/linux
[sfrench/cifs-2.6.git] / drivers / nvme / target / core.c
index 8658e9c08534df50c466314c6c70d18d79525324..6bbe4df0166ca56949a5f5b14ad90f68305d6f36 100644 (file)
@@ -358,6 +358,18 @@ int nvmet_enable_port(struct nvmet_port *port)
        if (port->inline_data_size < 0)
                port->inline_data_size = 0;
 
+       /*
+        * If the transport didn't set the max_queue_size properly, then clamp
+        * it to the target limits. Also set default values in case the
+        * transport didn't set it at all.
+        */
+       if (port->max_queue_size < 0)
+               port->max_queue_size = NVMET_MAX_QUEUE_SIZE;
+       else
+               port->max_queue_size = clamp_t(int, port->max_queue_size,
+                                              NVMET_MIN_QUEUE_SIZE,
+                                              NVMET_MAX_QUEUE_SIZE);
+
        port->enabled = true;
        port->tr_ops = ops;
        return 0;
@@ -1223,9 +1235,10 @@ static void nvmet_init_cap(struct nvmet_ctrl *ctrl)
        ctrl->cap |= (15ULL << 24);
        /* maximum queue entries supported: */
        if (ctrl->ops->get_max_queue_size)
-               ctrl->cap |= ctrl->ops->get_max_queue_size(ctrl) - 1;
+               ctrl->cap |= min_t(u16, ctrl->ops->get_max_queue_size(ctrl),
+                                  ctrl->port->max_queue_size) - 1;
        else
-               ctrl->cap |= NVMET_QUEUE_SIZE - 1;
+               ctrl->cap |= ctrl->port->max_queue_size - 1;
 
        if (nvmet_is_passthru_subsys(ctrl->subsys))
                nvmet_passthrough_override_cap(ctrl);
@@ -1411,6 +1424,7 @@ u16 nvmet_alloc_ctrl(const char *subsysnqn, const char *hostnqn,
 
        kref_init(&ctrl->ref);
        ctrl->subsys = subsys;
+       ctrl->pi_support = ctrl->port->pi_enable && ctrl->subsys->pi_support;
        nvmet_init_cap(ctrl);
        WRITE_ONCE(ctrl->aen_enabled, NVMET_AEN_CFG_OPTIONAL);