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 9.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  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 <ipxe/pci.h>
  23. #include <ipxe/pcibackup.h>
  24. #include <byteswap.h>
  25. #include <errno.h>
  26. #include <ipxe/io.h>
  27. #include <stdio.h>
  28. #include <unistd.h>
  29. #include "CIB_PRM.h"
  30. #include "mlx_utils/include/public/mlx_utils.h"
  31. #define GOLAN_PCI_CONFIG_BAR_SIZE 0x100000//HERMON_PCI_CONFIG_BAR_SIZE //TODO: What is the BAR size?
  32. #define GOLAN_PAS_SIZE sizeof(uint64_t)
  33. #define GOLAN_INVALID_LKEY 0x00000100UL
  34. #define GOLAN_MAX_PORTS 2
  35. #define GOLAN_PORT_BASE 1
  36. #define MELLANOX_VID 0x15b3
  37. #define GOLAN_HCA_BAR PCI_BASE_ADDRESS_0 //BAR 0
  38. #define GOLAN_HCR_MAX_WAIT_MS 10000
  39. #define min(a,b) ((a)<(b)?(a):(b))
  40. #define GOLAN_PAGE_SHIFT 12
  41. #define GOLAN_PAGE_SIZE (1 << GOLAN_PAGE_SHIFT)
  42. #define GOLAN_PAGE_MASK (GOLAN_PAGE_SIZE - 1)
  43. #define MAX_MBOX ( GOLAN_PAGE_SIZE / MAILBOX_STRIDE )
  44. #define DEF_CMD_IDX 1
  45. #define MEM_CMD_IDX 0
  46. #define NO_MBOX 0xffff
  47. #define MEM_MBOX MEM_CMD_IDX
  48. #define GEN_MBOX DEF_CMD_IDX
  49. #define CMD_IF_REV 4
  50. #define MAX_PASE_MBOX ((GOLAN_CMD_PAS_CNT) - 2)
  51. #define CMD_STATUS( golan , idx ) ((struct golan_outbox_hdr *)(get_cmd( (golan) , (idx) )->out))->status
  52. #define CMD_SYND( golan , idx ) ((struct golan_outbox_hdr *)(get_cmd( (golan) , (idx) )->out))->syndrome
  53. #define QRY_PAGES_OUT( golan, idx ) ((struct golan_query_pages_outbox *)(get_cmd( (golan) , (idx) )->out))
  54. #define VIRT_2_BE64_BUS( addr ) cpu_to_be64(((unsigned long long )virt_to_bus(addr)))
  55. #define BE64_BUS_2_VIRT( addr ) bus_to_virt(be64_to_cpu(addr))
  56. #define USR_2_BE64_BUS( addr ) cpu_to_be64(((unsigned long long )user_to_phys(addr, 0)))
  57. #define BE64_BUS_2_USR( addr ) be64_to_cpu(phys_to_user(addr))
  58. #define GET_INBOX(golan, idx) (&(((struct mbox *)(golan->mboxes.inbox))[idx]))
  59. #define GET_OUTBOX(golan, idx) (&(((struct mbox *)(golan->mboxes.outbox))[idx]))
  60. #define GOLAN_MBOX_IN( cmd_ptr, in_ptr ) ( { \
  61. union { \
  62. __be32 raw[4]; \
  63. typeof ( *(in_ptr) ) cooked; \
  64. } *u = container_of ( &(cmd_ptr)->in[0], typeof ( *u ), raw[0] ); \
  65. &u->cooked; } )
  66. #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
  67. /* Fw status fields */
  68. typedef enum {
  69. NO_ERRORS = 0x0,
  70. SIGNATURE_ERROR = 0x1,
  71. TOKEN_ERROR = 0x2,
  72. BAD_BLOCK_NUMBER = 0x3,
  73. BAD_OUTPUT_POINTER = 0x4, // pointer not align to mailbox size
  74. BAD_INPUT_POINTER = 0x5, // pointer not align to mailbox size
  75. INTERNAL_ERROR = 0x6,
  76. INPUT_LEN_ERROR = 0x7, // input length less than 0x8.
  77. OUTPUT_LEN_ERROR = 0x8, // output length less than 0x8.
  78. RESERVE_NOT_ZERO = 0x9,
  79. BAD_CMD_TYPE = 0x10,
  80. } return_hdr_t;
  81. struct golan_cmdq_md {
  82. void *addr;
  83. u16 log_stride;
  84. u16 size;
  85. };
  86. struct golan_uar {
  87. uint32_t index;
  88. void *virt;
  89. unsigned long phys;
  90. };
  91. struct golan_firmware_area {
  92. /* length of area in pages */
  93. uint32_t npages;
  94. /** Firmware area in external memory
  95. *
  96. * This is allocated when first needed, and freed only on
  97. * final teardown, in order to avoid memory map changes at
  98. * runtime.
  99. */
  100. userptr_t area;
  101. };
  102. /* Queue Pair */
  103. #define GOLAN_SEND_WQE_BB_SIZE 64
  104. #define GOLAN_SEND_UD_WQE_SIZE sizeof(struct golan_send_wqe_ud)
  105. #define GOLAN_RECV_WQE_SIZE sizeof(struct golan_recv_wqe_ud)
  106. #define GOLAN_WQEBBS_PER_SEND_UD_WQE DIV_ROUND_UP(GOLAN_SEND_UD_WQE_SIZE, GOLAN_SEND_WQE_BB_SIZE)
  107. #define GOLAN_SEND_OPCODE 0x0a
  108. #define GOLAN_WQE_CTRL_WQE_IDX_BIT 8
  109. enum golan_ib_qp_state {
  110. GOLAN_IB_QPS_RESET,
  111. GOLAN_IB_QPS_INIT,
  112. GOLAN_IB_QPS_RTR,
  113. GOLAN_IB_QPS_RTS,
  114. GOLAN_IB_QPS_SQD,
  115. GOLAN_IB_QPS_SQE,
  116. GOLAN_IB_QPS_ERR
  117. };
  118. struct golan_send_wqe_ud {
  119. struct golan_wqe_ctrl_seg ctrl;
  120. struct golan_av datagram;
  121. struct golan_wqe_data_seg data;
  122. };
  123. union golan_send_wqe {
  124. struct golan_send_wqe_ud ud;
  125. uint8_t pad[GOLAN_WQEBBS_PER_SEND_UD_WQE * GOLAN_SEND_WQE_BB_SIZE];
  126. };
  127. struct golan_recv_wqe_ud {
  128. struct golan_wqe_data_seg data[2];
  129. };
  130. struct golan_recv_wq {
  131. struct golan_recv_wqe_ud *wqes;
  132. /* WQ size in bytes */
  133. int size;
  134. /* In SQ, it will be increased in wqe_size (number of WQEBBs per WQE) */
  135. u16 next_idx;
  136. /** GRH buffers (if applicable) */
  137. struct ib_global_route_header *grh;
  138. /** Size of GRH buffers */
  139. size_t grh_size;
  140. };
  141. struct golan_send_wq {
  142. union golan_send_wqe *wqes;
  143. /* WQ size in bytes */
  144. int size;
  145. /* In SQ, it will be increased in wqe_size (number of WQEBBs per WQE) */
  146. u16 next_idx;
  147. };
  148. struct golan_queue_pair {
  149. void *wqes;
  150. int size;
  151. struct golan_recv_wq rq;
  152. struct golan_send_wq sq;
  153. struct golan_qp_db *doorbell_record;
  154. u32 doorbell_qpn;
  155. enum golan_ib_qp_state state;
  156. };
  157. /* Completion Queue */
  158. #define GOLAN_CQE_OPCODE_NOT_VALID 0x0f
  159. #define GOLAN_CQE_OPCODE_BIT 4
  160. #define GOLAN_CQ_DB_RECORD_SIZE sizeof(uint64_t)
  161. #define GOLAN_CQE_OWNER_MASK 1
  162. #define MANAGE_PAGES_PSA_OFFSET 0
  163. #define PXE_CMDIF_REF 5
  164. enum {
  165. GOLAN_CQE_SW_OWNERSHIP = 0x0,
  166. GOLAN_CQE_HW_OWNERSHIP = 0x1
  167. };
  168. enum {
  169. GOLAN_CQE_SIZE_64 = 0,
  170. GOLAN_CQE_SIZE_128 = 1
  171. };
  172. struct golan_completion_queue {
  173. struct golan_cqe64 *cqes;
  174. int size;
  175. __be64 *doorbell_record;
  176. };
  177. /* Event Queue */
  178. #define GOLAN_EQE_SIZE sizeof(struct golan_eqe)
  179. #define GOLAN_NUM_EQES 8
  180. #define GOLAN_EQ_DOORBELL_OFFSET 0x40
  181. #define DB_BUFFER0_EVEN_OFFSET 0x800
  182. #define DB_BUFFER0_ODD_OFFSET 0x900
  183. #define GOLAN_EQ_MAP_ALL_EVENTS \
  184. ((1 << GOLAN_EVENT_TYPE_PATH_MIG )| \
  185. (1 << GOLAN_EVENT_TYPE_COMM_EST )| \
  186. (1 << GOLAN_EVENT_TYPE_SQ_DRAINED )| \
  187. (1 << GOLAN_EVENT_TYPE_SRQ_LAST_WQE )| \
  188. (1 << GOLAN_EVENT_TYPE_SRQ_RQ_LIMIT )| \
  189. (1 << GOLAN_EVENT_TYPE_CQ_ERROR )| \
  190. (1 << GOLAN_EVENT_TYPE_WQ_CATAS_ERROR )| \
  191. (1 << GOLAN_EVENT_TYPE_PATH_MIG_FAILED )| \
  192. (1 << GOLAN_EVENT_TYPE_WQ_INVAL_REQ_ERROR )| \
  193. (1 << GOLAN_EVENT_TYPE_WQ_ACCESS_ERROR )| \
  194. (1 << GOLAN_EVENT_TYPE_SRQ_CATAS_ERROR )| \
  195. (1 << GOLAN_EVENT_TYPE_INTERNAL_ERROR )| \
  196. (1 << GOLAN_EVENT_TYPE_PORT_CHANGE )| \
  197. (1 << GOLAN_EVENT_TYPE_GPIO_EVENT )| \
  198. (1 << GOLAN_EVENT_TYPE_CLIENT_RE_REGISTER )| \
  199. (1 << GOLAN_EVENT_TYPE_REMOTE_CONFIG )| \
  200. (1 << GOLAN_EVENT_TYPE_DB_BF_CONGESTION )| \
  201. (1 << GOLAN_EVENT_TYPE_STALL_EVENT )| \
  202. (1 << GOLAN_EVENT_TYPE_PACKET_DROPPED )| \
  203. (1 << GOLAN_EVENT_TYPE_CMD )| \
  204. (1 << GOLAN_EVENT_TYPE_PAGE_REQUEST ))
  205. enum golan_event {
  206. GOLAN_EVENT_TYPE_COMP = 0x0,
  207. GOLAN_EVENT_TYPE_PATH_MIG = 0x01,
  208. GOLAN_EVENT_TYPE_COMM_EST = 0x02,
  209. GOLAN_EVENT_TYPE_SQ_DRAINED = 0x03,
  210. GOLAN_EVENT_TYPE_SRQ_LAST_WQE = 0x13,
  211. GOLAN_EVENT_TYPE_SRQ_RQ_LIMIT = 0x14,
  212. GOLAN_EVENT_TYPE_CQ_ERROR = 0x04,
  213. GOLAN_EVENT_TYPE_WQ_CATAS_ERROR = 0x05,
  214. GOLAN_EVENT_TYPE_PATH_MIG_FAILED = 0x07,
  215. GOLAN_EVENT_TYPE_WQ_INVAL_REQ_ERROR = 0x10,
  216. GOLAN_EVENT_TYPE_WQ_ACCESS_ERROR = 0x11,
  217. GOLAN_EVENT_TYPE_SRQ_CATAS_ERROR = 0x12,
  218. GOLAN_EVENT_TYPE_INTERNAL_ERROR = 0x08,
  219. GOLAN_EVENT_TYPE_PORT_CHANGE = 0x09,
  220. GOLAN_EVENT_TYPE_GPIO_EVENT = 0x15,
  221. // GOLAN_EVENT_TYPE_CLIENT_RE_REGISTER = 0x16,
  222. GOLAN_EVENT_TYPE_REMOTE_CONFIG = 0x19,
  223. GOLAN_EVENT_TYPE_DB_BF_CONGESTION = 0x1a,
  224. GOLAN_EVENT_TYPE_STALL_EVENT = 0x1b,
  225. GOLAN_EVENT_TYPE_PACKET_DROPPED = 0x1f,
  226. GOLAN_EVENT_TYPE_CMD = 0x0a,
  227. GOLAN_EVENT_TYPE_PAGE_REQUEST = 0x0b,
  228. GOLAN_EVENT_TYPE_PAGE_FAULT = 0x0C,
  229. };
  230. enum golan_port_sub_event {
  231. GOLAN_PORT_CHANGE_SUBTYPE_DOWN = 1,
  232. GOLAN_PORT_CHANGE_SUBTYPE_ACTIVE = 4,
  233. GOLAN_PORT_CHANGE_SUBTYPE_INITIALIZED = 5,
  234. GOLAN_PORT_CHANGE_SUBTYPE_LID = 6,
  235. GOLAN_PORT_CHANGE_SUBTYPE_PKEY = 7,
  236. GOLAN_PORT_CHANGE_SUBTYPE_GUID = 8,
  237. GOLAN_PORT_CHANGE_SUBTYPE_CLIENT_REREG = 9
  238. };
  239. enum {
  240. GOLAN_EQE_SW_OWNERSHIP = 0x0,
  241. GOLAN_EQE_HW_OWNERSHIP = 0x1
  242. };
  243. enum {
  244. GOLAN_EQ_UNARMED = 0,
  245. GOLAN_EQ_ARMED = 1,
  246. };
  247. struct golan_event_queue {
  248. uint8_t eqn;
  249. uint64_t mask;
  250. struct golan_eqe *eqes;
  251. int size;
  252. __be32 *doorbell;
  253. uint32_t cons_index;
  254. };
  255. struct golan_port {
  256. /** Infiniband device */
  257. struct ib_device *ibdev;
  258. /** Network device */
  259. struct net_device *netdev;
  260. /** VEP number */
  261. u8 vep_number;
  262. };
  263. struct golan_mboxes {
  264. void *inbox;
  265. void *outbox;
  266. };
  267. #define GOLAN_OPEN 0x1
  268. struct golan {
  269. struct pci_device *pci;
  270. struct golan_hca_init_seg *iseg;
  271. struct golan_cmdq_md cmd;
  272. struct golan_hca_cap caps; /* stored as big indian*/
  273. struct golan_mboxes mboxes;
  274. struct list_head pages;
  275. uint32_t cmd_bm;
  276. uint32_t total_dma_pages;
  277. struct golan_uar uar;
  278. struct golan_event_queue eq;
  279. uint32_t pdn;
  280. u32 mkey;
  281. u32 flags;
  282. mlx_utils *utils;
  283. struct golan_port ports[GOLAN_MAX_PORTS];
  284. #define GOLAN_FW_AREAS_NUM 2
  285. struct golan_firmware_area fw_areas[GOLAN_FW_AREAS_NUM];
  286. };
  287. #endif /* _GOLAN_H_*/