fabrics.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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_le 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. };
  52. /**
  53. * struct nvmf_ctrl_options - Used to hold the options specified
  54. * with the parsing opts enum.
  55. * @mask: Used by the fabrics library to parse through sysfs options
  56. * on adding a NVMe controller.
  57. * @transport: Holds the fabric transport "technology name" (for a lack of
  58. * better description) that will be used by an NVMe controller
  59. * being added.
  60. * @subsysnqn: Hold the fully qualified NQN subystem name (format defined
  61. * in the NVMe specification, "NVMe Qualified Names").
  62. * @traddr: network address that will be used by the host to communicate
  63. * to the added NVMe controller.
  64. * @trsvcid: network port used for host-controller communication.
  65. * @queue_size: Number of IO queue elements.
  66. * @nr_io_queues: Number of controller IO queues that will be established.
  67. * @reconnect_delay: Time between two consecutive reconnect attempts.
  68. * @discovery_nqn: indicates if the subsysnqn is the well-known discovery NQN.
  69. * @kato: Keep-alive timeout.
  70. * @host: Virtual NVMe host, contains the NQN and Host ID.
  71. */
  72. struct nvmf_ctrl_options {
  73. unsigned mask;
  74. char *transport;
  75. char *subsysnqn;
  76. char *traddr;
  77. char *trsvcid;
  78. size_t queue_size;
  79. unsigned int nr_io_queues;
  80. unsigned int reconnect_delay;
  81. bool discovery_nqn;
  82. unsigned int kato;
  83. struct nvmf_host *host;
  84. };
  85. /*
  86. * struct nvmf_transport_ops - used to register a specific
  87. * fabric implementation of NVMe fabrics.
  88. * @entry: Used by the fabrics library to add the new
  89. * registration entry to its linked-list internal tree.
  90. * @name: Name of the NVMe fabric driver implementation.
  91. * @required_opts: sysfs command-line options that must be specified
  92. * when adding a new NVMe controller.
  93. * @allowed_opts: sysfs command-line options that can be specified
  94. * when adding a new NVMe controller.
  95. * @create_ctrl(): function pointer that points to a non-NVMe
  96. * implementation-specific fabric technology
  97. * that would go into starting up that fabric
  98. * for the purpose of conneciton to an NVMe controller
  99. * using that fabric technology.
  100. *
  101. * Notes:
  102. * 1. At minimum, 'required_opts' and 'allowed_opts' should
  103. * be set to the same enum parsing options defined earlier.
  104. * 2. create_ctrl() must be defined (even if it does nothing)
  105. */
  106. struct nvmf_transport_ops {
  107. struct list_head entry;
  108. const char *name;
  109. int required_opts;
  110. int allowed_opts;
  111. struct nvme_ctrl *(*create_ctrl)(struct device *dev,
  112. struct nvmf_ctrl_options *opts);
  113. };
  114. int nvmf_reg_read32(struct nvme_ctrl *ctrl, u32 off, u32 *val);
  115. int nvmf_reg_read64(struct nvme_ctrl *ctrl, u32 off, u64 *val);
  116. int nvmf_reg_write32(struct nvme_ctrl *ctrl, u32 off, u32 val);
  117. int nvmf_connect_admin_queue(struct nvme_ctrl *ctrl);
  118. int nvmf_connect_io_queue(struct nvme_ctrl *ctrl, u16 qid);
  119. void nvmf_register_transport(struct nvmf_transport_ops *ops);
  120. void nvmf_unregister_transport(struct nvmf_transport_ops *ops);
  121. void nvmf_free_options(struct nvmf_ctrl_options *opts);
  122. const char *nvmf_get_subsysnqn(struct nvme_ctrl *ctrl);
  123. int nvmf_get_address(struct nvme_ctrl *ctrl, char *buf, int size);
  124. #endif /* _NVME_FABRICS_H */