You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

golan.h 8.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. #ifndef _GOLAN_H_
  2. #define _GOLAN_H_
  3. /*
  4. * Copyright (C) 2013-2015 Mellanox Technologies Ltd.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License as
  8. * published by the Free Software Foundation; either version 2 of the
  9. * License, or any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  19. * 02110-1301, USA.
  20. */
  21. FILE_LICENCE ( GPL2_OR_LATER );
  22. #include <byteswap.h>
  23. #include <errno.h>
  24. #include <stdio.h>
  25. #include <unistd.h>
  26. #include <ipxe/io.h>
  27. #include <ipxe/pci.h>
  28. #include <ipxe/pcibackup.h>
  29. #include "CIB_PRM.h"
  30. #define GOLAN_PCI_CONFIG_BAR_SIZE 0x100000//HERMON_PCI_CONFIG_BAR_SIZE //TODO: What is the BAR size?
  31. #define GOLAN_PAS_SIZE sizeof(uint64_t)
  32. #define GOLAN_INVALID_LKEY 0x00000100UL
  33. #define GOLAN_MAX_PORTS 2
  34. #define GOLAN_PORT_BASE 1
  35. #define MELLANOX_VID 0x15b3
  36. #define GOLAN_HCA_BAR PCI_BASE_ADDRESS_0 //BAR 0
  37. #define GOLAN_HCR_MAX_WAIT_MS 10000
  38. #define min(a,b) ((a)<(b)?(a):(b))
  39. #define GOLAN_PAGE_SHIFT 12
  40. #define GOLAN_PAGE_SIZE (1 << GOLAN_PAGE_SHIFT)
  41. #define GOLAN_PAGE_MASK (GOLAN_PAGE_SIZE - 1)
  42. #define MAX_MBOX ( GOLAN_PAGE_SIZE / MAILBOX_STRIDE )
  43. #define DEF_CMD_IDX 1
  44. #define MEM_CMD_IDX 0
  45. #define NO_MBOX 0xffff
  46. #define MEM_MBOX MEM_CMD_IDX
  47. #define GEN_MBOX DEF_CMD_IDX
  48. #define CMD_IF_REV 4
  49. #define MAX_PASE_MBOX ((GOLAN_CMD_PAS_CNT) - 2)
  50. #define CMD_STATUS( golan , idx ) ((struct golan_outbox_hdr *)(get_cmd( (golan) , (idx) )->out))->status
  51. #define CMD_SYND( golan , idx ) ((struct golan_outbox_hdr *)(get_cmd( (golan) , (idx) )->out))->syndrome
  52. #define QRY_PAGES_OUT( golan, idx ) ((struct golan_query_pages_outbox *)(get_cmd( (golan) , (idx) )->out))
  53. #define VIRT_2_BE64_BUS( addr ) cpu_to_be64(((unsigned long long )virt_to_bus(addr)))
  54. #define BE64_BUS_2_VIRT( addr ) bus_to_virt(be64_to_cpu(addr))
  55. #define USR_2_BE64_BUS( addr ) cpu_to_be64(((unsigned long long )user_to_phys(addr, 0)))
  56. #define BE64_BUS_2_USR( addr ) be64_to_cpu(phys_to_user(addr))
  57. #define GET_INBOX(golan, idx) (&(((struct mbox *)(golan->mboxes.inbox))[idx]))
  58. #define GET_OUTBOX(golan, idx) (&(((struct mbox *)(golan->mboxes.outbox))[idx]))
  59. #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
  60. /* Fw status fields */
  61. typedef enum {
  62. NO_ERRORS = 0x0,
  63. SIGNATURE_ERROR = 0x1,
  64. TOKEN_ERROR = 0x2,
  65. BAD_BLOCK_NUMBER = 0x3,
  66. BAD_OUTPUT_POINTER = 0x4, // pointer not align to mailbox size
  67. BAD_INPUT_POINTER = 0x5, // pointer not align to mailbox size
  68. INTERNAL_ERROR = 0x6,
  69. INPUT_LEN_ERROR = 0x7, // input length less than 0x8.
  70. OUTPUT_LEN_ERROR = 0x8, // output length less than 0x8.
  71. RESERVE_NOT_ZERO = 0x9,
  72. BAD_CMD_TYPE = 0x10,
  73. } return_hdr_t;
  74. struct golan_cmdq_md {
  75. void *addr;
  76. u16 log_stride;
  77. u16 size;
  78. };
  79. struct golan_uar {
  80. uint32_t index;
  81. void *virt;
  82. unsigned long phys;
  83. };
  84. /* Queue Pair */
  85. #define GOLAN_SEND_WQE_BB_SIZE 64
  86. #define GOLAN_SEND_UD_WQE_SIZE sizeof(struct golan_send_wqe_ud)
  87. #define GOLAN_RECV_WQE_SIZE sizeof(struct golan_recv_wqe_ud)
  88. #define GOLAN_WQEBBS_PER_SEND_UD_WQE DIV_ROUND_UP(GOLAN_SEND_UD_WQE_SIZE, GOLAN_SEND_WQE_BB_SIZE)
  89. #define GOLAN_SEND_OPCODE 0x0a
  90. #define GOLAN_WQE_CTRL_WQE_IDX_BIT 8
  91. enum golan_ib_qp_state {
  92. GOLAN_IB_QPS_RESET,
  93. GOLAN_IB_QPS_INIT,
  94. GOLAN_IB_QPS_RTR,
  95. GOLAN_IB_QPS_RTS,
  96. GOLAN_IB_QPS_SQD,
  97. GOLAN_IB_QPS_SQE,
  98. GOLAN_IB_QPS_ERR
  99. };
  100. struct golan_send_wqe_ud {
  101. struct golan_wqe_ctrl_seg ctrl;
  102. struct golan_av datagram;
  103. struct golan_wqe_data_seg data;
  104. };
  105. union golan_send_wqe {
  106. struct golan_send_wqe_ud ud;
  107. uint8_t pad[GOLAN_WQEBBS_PER_SEND_UD_WQE * GOLAN_SEND_WQE_BB_SIZE];
  108. };
  109. struct golan_recv_wqe_ud {
  110. struct golan_wqe_data_seg data[2];
  111. };
  112. struct golan_recv_wq {
  113. struct golan_recv_wqe_ud *wqes;
  114. /* WQ size in bytes */
  115. int size;
  116. /* In SQ, it will be increased in wqe_size (number of WQEBBs per WQE) */
  117. u16 next_idx;
  118. /** GRH buffers (if applicable) */
  119. struct ib_global_route_header *grh;
  120. /** Size of GRH buffers */
  121. size_t grh_size;
  122. };
  123. struct golan_send_wq {
  124. union golan_send_wqe *wqes;
  125. /* WQ size in bytes */
  126. int size;
  127. /* In SQ, it will be increased in wqe_size (number of WQEBBs per WQE) */
  128. u16 next_idx;
  129. };
  130. struct golan_queue_pair {
  131. void *wqes;
  132. int size;
  133. struct golan_recv_wq rq;
  134. struct golan_send_wq sq;
  135. struct golan_qp_db *doorbell_record;
  136. u32 doorbell_qpn;
  137. enum golan_ib_qp_state state;
  138. };
  139. /* Completion Queue */
  140. #define GOLAN_CQE_OPCODE_NOT_VALID 0x0f
  141. #define GOLAN_CQE_OPCODE_BIT 4
  142. #define GOLAN_CQ_DB_RECORD_SIZE sizeof(uint64_t)
  143. #define GOLAN_CQE_OWNER_MASK 1
  144. #define MANAGE_PAGES_PSA_OFFSET 0
  145. #define PXE_CMDIF_REF 5
  146. enum {
  147. GOLAN_CQE_SW_OWNERSHIP = 0x0,
  148. GOLAN_CQE_HW_OWNERSHIP = 0x1
  149. };
  150. enum {
  151. GOLAN_CQE_SIZE_64 = 0,
  152. GOLAN_CQE_SIZE_128 = 1
  153. };
  154. struct golan_completion_queue {
  155. struct golan_cqe64 *cqes;
  156. int size;
  157. __be64 *doorbell_record;
  158. };
  159. /* Event Queue */
  160. #define GOLAN_EQE_SIZE sizeof(struct golan_eqe)
  161. #define GOLAN_NUM_EQES 8
  162. #define GOLAN_EQ_DOORBELL_OFFSET 0x40
  163. #define GOLAN_EQ_MAP_ALL_EVENTS \
  164. ((1 << GOLAN_EVENT_TYPE_PATH_MIG )| \
  165. (1 << GOLAN_EVENT_TYPE_COMM_EST )| \
  166. (1 << GOLAN_EVENT_TYPE_SQ_DRAINED )| \
  167. (1 << GOLAN_EVENT_TYPE_SRQ_LAST_WQE )| \
  168. (1 << GOLAN_EVENT_TYPE_SRQ_RQ_LIMIT )| \
  169. (1 << GOLAN_EVENT_TYPE_CQ_ERROR )| \
  170. (1 << GOLAN_EVENT_TYPE_WQ_CATAS_ERROR )| \
  171. (1 << GOLAN_EVENT_TYPE_PATH_MIG_FAILED )| \
  172. (1 << GOLAN_EVENT_TYPE_WQ_INVAL_REQ_ERROR )| \
  173. (1 << GOLAN_EVENT_TYPE_WQ_ACCESS_ERROR )| \
  174. (1 << GOLAN_EVENT_TYPE_SRQ_CATAS_ERROR )| \
  175. (1 << GOLAN_EVENT_TYPE_INTERNAL_ERROR )| \
  176. (1 << GOLAN_EVENT_TYPE_PORT_CHANGE )| \
  177. (1 << GOLAN_EVENT_TYPE_GPIO_EVENT )| \
  178. (1 << GOLAN_EVENT_TYPE_CLIENT_RE_REGISTER )| \
  179. (1 << GOLAN_EVENT_TYPE_REMOTE_CONFIG )| \
  180. (1 << GOLAN_EVENT_TYPE_DB_BF_CONGESTION )| \
  181. (1 << GOLAN_EVENT_TYPE_STALL_EVENT )| \
  182. (1 << GOLAN_EVENT_TYPE_PACKET_DROPPED )| \
  183. (1 << GOLAN_EVENT_TYPE_CMD )| \
  184. (1 << GOLAN_EVENT_TYPE_PAGE_REQUEST ))
  185. enum golan_event {
  186. GOLAN_EVENT_TYPE_COMP = 0x0,
  187. GOLAN_EVENT_TYPE_PATH_MIG = 0x01,
  188. GOLAN_EVENT_TYPE_COMM_EST = 0x02,
  189. GOLAN_EVENT_TYPE_SQ_DRAINED = 0x03,
  190. GOLAN_EVENT_TYPE_SRQ_LAST_WQE = 0x13,
  191. GOLAN_EVENT_TYPE_SRQ_RQ_LIMIT = 0x14,
  192. GOLAN_EVENT_TYPE_CQ_ERROR = 0x04,
  193. GOLAN_EVENT_TYPE_WQ_CATAS_ERROR = 0x05,
  194. GOLAN_EVENT_TYPE_PATH_MIG_FAILED = 0x07,
  195. GOLAN_EVENT_TYPE_WQ_INVAL_REQ_ERROR = 0x10,
  196. GOLAN_EVENT_TYPE_WQ_ACCESS_ERROR = 0x11,
  197. GOLAN_EVENT_TYPE_SRQ_CATAS_ERROR = 0x12,
  198. GOLAN_EVENT_TYPE_INTERNAL_ERROR = 0x08,
  199. GOLAN_EVENT_TYPE_PORT_CHANGE = 0x09,
  200. GOLAN_EVENT_TYPE_GPIO_EVENT = 0x15,
  201. // GOLAN_EVENT_TYPE_CLIENT_RE_REGISTER = 0x16,
  202. GOLAN_EVENT_TYPE_REMOTE_CONFIG = 0x19,
  203. GOLAN_EVENT_TYPE_DB_BF_CONGESTION = 0x1a,
  204. GOLAN_EVENT_TYPE_STALL_EVENT = 0x1b,
  205. GOLAN_EVENT_TYPE_PACKET_DROPPED = 0x1f,
  206. GOLAN_EVENT_TYPE_CMD = 0x0a,
  207. GOLAN_EVENT_TYPE_PAGE_REQUEST = 0x0b,
  208. GOLAN_EVENT_TYPE_PAGE_FAULT = 0x0C,
  209. };
  210. enum golan_port_sub_event {
  211. GOLAN_PORT_CHANGE_SUBTYPE_DOWN = 1,
  212. GOLAN_PORT_CHANGE_SUBTYPE_ACTIVE = 4,
  213. GOLAN_PORT_CHANGE_SUBTYPE_INITIALIZED = 5,
  214. GOLAN_PORT_CHANGE_SUBTYPE_LID = 6,
  215. GOLAN_PORT_CHANGE_SUBTYPE_PKEY = 7,
  216. GOLAN_PORT_CHANGE_SUBTYPE_GUID = 8,
  217. GOLAN_PORT_CHANGE_SUBTYPE_CLIENT_REREG = 9
  218. };
  219. enum {
  220. GOLAN_EQE_SW_OWNERSHIP = 0x0,
  221. GOLAN_EQE_HW_OWNERSHIP = 0x1
  222. };
  223. enum {
  224. GOLAN_EQ_UNARMED = 0,
  225. GOLAN_EQ_ARMED = 1,
  226. };
  227. struct golan_event_queue {
  228. uint8_t eqn;
  229. uint64_t mask;
  230. struct golan_eqe *eqes;
  231. int size;
  232. __be32 *doorbell;
  233. uint32_t cons_index;
  234. };
  235. struct golan_port {
  236. /** Infiniband device */
  237. struct ib_device *ibdev;
  238. /** Network device */
  239. struct net_device *netdev;
  240. /** VEP number */
  241. u8 vep_number;
  242. };
  243. struct golan_mboxes {
  244. void *inbox;
  245. void *outbox;
  246. };
  247. #define GOLAN_OPEN 0x1
  248. struct golan {
  249. struct pci_device *pci;
  250. struct golan_hca_init_seg *iseg;
  251. struct golan_cmdq_md cmd;
  252. struct golan_hca_cap caps; /* stored as big indian*/
  253. struct golan_mboxes mboxes;
  254. struct list_head pages;
  255. uint32_t cmd_bm;
  256. uint32_t total_dma_pages;
  257. struct golan_uar uar;
  258. struct golan_event_queue eq;
  259. uint32_t pdn;
  260. u32 mkey;
  261. u32 flags;
  262. struct golan_port ports[GOLAN_MAX_PORTS];
  263. };
  264. #endif /* _GOLAN_H_*/