fabrics.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * NVMe over Fabrics common host code.
  3. * Copyright (c) 2015-2016 HGST, a Western Digital Company.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms and conditions of the GNU General Public License,
  7. * version 2, as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. */
  14. #ifndef _NVME_FABRICS_H
  15. #define _NVME_FABRICS_H 1
  16. #include <linux/in.h>
  17. #include <linux/inet.h>
  18. #define NVMF_MIN_QUEUE_SIZE 16
  19. #define NVMF_MAX_QUEUE_SIZE 1024
  20. #define NVMF_DEF_QUEUE_SIZE 128
  21. #define NVMF_DEF_RECONNECT_DELAY 10
  22. /*
  23. * Define a host as seen by the target. We allocate one at boot, but also
  24. * allow the override it when creating controllers. This is both to provide
  25. * persistence of the Host NQN over multiple boots, and to allow using
  26. * multiple ones, for example in a container scenario. Because we must not
  27. * use different Host NQNs with the same Host ID we generate a Host ID and
  28. * use this structure to keep track of the relation between the two.
  29. */
  30. struct nvmf_host {
  31. struct kref ref;
  32. struct list_head list;
  33. char nqn[NVMF_NQN_SIZE];
  34. uuid_be id;
  35. };
  36. /**
  37. * enum nvmf_parsing_opts - used to define the sysfs parsing options used.
  38. */
  39. enum {
  40. NVMF_OPT_ERR = 0,
  41. NVMF_OPT_TRANSPORT = 1 << 0,
  42. NVMF_OPT_NQN = 1 << 1,
  43. NVMF_OPT_TRADDR = 1 << 2,
  44. NVMF_OPT_TRSVCID = 1 << 3,
  45. NVMF_OPT_QUEUE_SIZE = 1 << 4,
  46. NVMF_OPT_NR_IO_QUEUES = 1 << 5,
  47. NVMF_OPT_TL_RETRY_COUNT = 1 << 6,
  48. NVMF_OPT_KATO = 1 << 7,
  49. NVMF_OPT_HOSTNQN = 1 << 8,
  50. NVMF_OPT_RECONNECT_DELAY = 1 << 9,
  51. NVMF_OPT_HOST_TRADDR = 1 << 10,
  52. };
  53. /**
  54. * struct nvmf_ctrl_options - Used to hold the options specified
  55. * with the parsing opts enum.
  56. * @mask: Used by the fabrics library to parse through sysfs options
  57. * on adding a NVMe controller.
  58. * @transport: Holds the fabric transport "technology name" (for a lack of
  59. * better description) that will be used by an NVMe controller
  60. * being added.
  61. * @subsysnqn: Hold the fully qualified NQN subystem name (format defined
  62. * in the NVMe specification, "NVMe Qualified Names").
  63. * @traddr: The transport-specific TRADDR field for a port on the
  64. * subsystem which is adding a controller.
  65. * @trsvcid: The transport-specific TRSVCID field for a port on the
  66. * subsystem which is adding a controller.
  67. * @host_traddr: A transport-specific field identifying the NVME host port
  68. * to use for the connection to the controller.
  69. * @queue_size: Number of IO queue elements.
  70. * @nr_io_queues: Number of controller IO queues that will be established.
  71. * @reconnect_delay: Time between two consecutive reconnect attempts.
  72. * @discovery_nqn: indicates if the subsysnqn is the well-known discovery NQN.
  73. * @kato: Keep-alive timeout.
  74. * @host: Virtual NVMe host, contains the NQN and Host ID.
  75. */
  76. struct nvmf_ctrl_options {
  77. unsigned mask;
  78. char *transport;
  79. char *subsysnqn;
  80. char *traddr;
  81. char *trsvcid;
  82. char *host_traddr;
  83. size_t queue_size;
  84. unsigned int nr_io_queues;
  85. unsigned int reconnect_delay;
  86. bool discovery_nqn;
  87. unsigned int kato;
  88. struct nvmf_host *host;
  89. };
  90. /*
  91. * struct nvmf_transport_ops - used to register a specific
  92. * fabric implementation of NVMe fabrics.
  93. * @entry: Used by the fabrics library to add the new
  94. * registration entry to its linked-list internal tree.
  95. * @name: Name of the NVMe fabric driver implementation.
  96. * @required_opts: sysfs command-line options that must be specified
  97. * when adding a new NVMe controller.
  98. * @allowed_opts: sysfs command-line options that can be specified
  99. * when adding a new NVMe controller.
  100. * @create_ctrl(): function pointer that points to a non-NVMe
  101. * implementation-specific fabric technology
  102. * that would go into starting up that fabric
  103. * for the purpose of conneciton to an NVMe controller
  104. * using that fabric technology.
  105. *
  106. * Notes:
  107. * 1. At minimum, 'required_opts' and 'allowed_opts' should
  108. * be set to the same enum parsing options defined earlier.
  109. * 2. create_ctrl() must be defined (even if it does nothing)
  110. */
  111. struct nvmf_transport_ops {
  112. struct list_head entry;
  113. const char *name;
  114. int required_opts;
  115. int allowed_opts;
  116. struct nvme_ctrl *(*create_ctrl)(struct device *dev,
  117. struct nvmf_ctrl_options *opts);
  118. };
  119. int nvmf_reg_read32(struct nvme_ctrl *ctrl, u32 off, u32 *val);
  120. int nvmf_reg_read64(struct nvme_ctrl *ctrl, u32 off, u64 *val);
  121. int nvmf_reg_write32(struct nvme_ctrl *ctrl, u32 off, u32 val);
  122. int nvmf_connect_admin_queue(struct nvme_ctrl *ctrl);
  123. int nvmf_connect_io_queue(struct nvme_ctrl *ctrl, u16 qid);
  124. void nvmf_register_transport(struct nvmf_transport_ops *ops);
  125. void nvmf_unregister_transport(struct nvmf_transport_ops *ops);
  126. void nvmf_free_options(struct nvmf_ctrl_options *opts);
  127. const char *nvmf_get_subsysnqn(struct nvme_ctrl *ctrl);
  128. int nvmf_get_address(struct nvme_ctrl *ctrl, char *buf, int size);
  129. #endif /* _NVME_FABRICS_H */