]> www.infradead.org Git - users/sagi/libnvme.git/commitdiff
mi: Introduce quirks and endpoint probing
authorJeremy Kerr <jk@codeconstruct.com.au>
Tue, 20 Sep 2022 12:44:09 +0000 (20:44 +0800)
committerJeremy Kerr <jk@codeconstruct.com.au>
Thu, 3 Nov 2022 05:53:50 +0000 (13:53 +0800)
This change introduces a little framework for adding device-specific
quirk flags. This allows the MI core to perform any queries on the
device, and set any quirk flags on specific devices.

This gives us a new (mi-internal) function:

    bool nvme_mi_ep_has_quirk(struct nvme_mi_ep *tp, unsigned long quirk)

which returns true if `quirk` is enabled on this endpoint.

Callers can disable probing through a new external API:

    nvme_mi_set_probe_enabled(nvme_root_t root, bool enabled);

Which will prevent sending any probe commands, and leave the quirks
field unset.

Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
src/libnvme-mi.map
src/nvme/mi-mctp.c
src/nvme/mi.c
src/nvme/mi.h
src/nvme/private.h

index 53af9429101ceb3c03c1a48835d92bf163e3eb83..fad10c9cba5ea55fbf7b86387a7f62f3f8fc77c7 100644 (file)
@@ -1,3 +1,8 @@
+LIBNVME_MI_1_3 {
+       global:
+               nvme_mi_set_probe_enabled;
+};
+
 LIBNVME_MI_1_2 {
        global:
                nvme_mi_admin_get_features;
index 86f5df68dacb366fc9479537f3c3d8130ce3d73b..e74d46f72f56b4afac847aa1bcf73bc934f3a5f8 100644 (file)
@@ -510,6 +510,8 @@ nvme_mi_ep_t nvme_mi_open_mctp(nvme_root_t root, unsigned int netid, __u8 eid)
         */
        ep->timeout = 5000;
 
+       nvme_mi_ep_probe(ep);
+
        return ep;
 
 err_free_ep:
index 6ff0a6f68d1421beae0de2605153b8619b4b2ba5..8ffbaccc94122b6650e2010c5e6bfd89706f82ce 100644 (file)
@@ -33,6 +33,7 @@ nvme_root_t nvme_mi_create_root(FILE *fp, int log_level)
        }
        r->log_level = log_level;
        r->fp = stderr;
+       r->mi_probe_enabled = true;
        if (fp)
                r->fp = fp;
        list_head_init(&r->hosts);
@@ -50,6 +51,20 @@ void nvme_mi_free_root(nvme_root_t root)
        free(root);
 }
 
+void nvme_mi_set_probe_enabled(nvme_root_t root, bool enabled)
+{
+       root->mi_probe_enabled = enabled;
+}
+
+void nvme_mi_ep_probe(struct nvme_mi_ep *ep)
+{
+       if (!ep->root->mi_probe_enabled)
+               return;
+
+       /* no quirks defined yet, nothing to probe! */
+       ep->quirks = 0;
+}
+
 struct nvme_mi_ep *nvme_mi_init_ep(nvme_root_t root)
 {
        struct nvme_mi_ep *ep;
@@ -93,6 +108,11 @@ unsigned int nvme_mi_ep_get_timeout(nvme_mi_ep_t ep)
        return ep->timeout;
 }
 
+static bool nvme_mi_ep_has_quirk(nvme_mi_ep_t ep, unsigned long quirk)
+{
+       return ep->quirks & quirk;
+}
+
 struct nvme_mi_ctrl *nvme_mi_init_ctrl(nvme_mi_ep_t ep, __u16 ctrl_id)
 {
        struct nvme_mi_ctrl *ctrl;
index ab4216dd542449b7bf86e9114d6311b0031b1bf0..90d478dde02ecb8fd0ecc9030147a2fc019adf55 100644 (file)
@@ -403,6 +403,17 @@ nvme_root_t nvme_mi_create_root(FILE *fp, int log_level);
  */
 void nvme_mi_free_root(nvme_root_t root);
 
+/**
+ * nvme_mi_set_probe_enabled() - enable/disable the probe for new endpoints
+ * @root: &nvme_root_t object
+ * @enabled: whether to probe new endpoints
+ *
+ * Controls whether newly-created endpoints are probed for quirks on creation.
+ * Defaults to enabled, which results in some initial messaging with the
+ * endpoint to determine model-specific details.
+ */
+void nvme_mi_set_probe_enabled(nvme_root_t root, bool enabled);
+
 /* Top level management object: NVMe-MI Management Endpoint */
 struct nvme_mi_ep;
 
index cdd1bbf5eb5146fbeacc76d987fee9af04e4607b..bb695bddd10af3a151e502d855d9891e57ec0a13 100644 (file)
@@ -125,6 +125,7 @@ struct nvme_root {
        bool log_pid;
        bool log_timestamp;
        bool modified;
+       bool mi_probe_enabled;
 };
 
 int nvme_set_attr(const char *dir, const char *attr, const char *value);
@@ -195,6 +196,7 @@ struct nvme_mi_ep {
        bool controllers_scanned;
        unsigned int timeout;
        unsigned int mprt_max;
+       unsigned long quirks;
 };
 
 struct nvme_mi_ctrl {
@@ -204,6 +206,7 @@ struct nvme_mi_ctrl {
 };
 
 struct nvme_mi_ep *nvme_mi_init_ep(struct nvme_root *root);
+void nvme_mi_ep_probe(struct nvme_mi_ep *ep);
 
 /* for tests, we need to calculate the correct MICs */
 __u32 nvme_mi_crc32_update(__u32 crc, void *data, size_t len);