1219820Sjeff/*
2219820Sjeff * Copyright (c) 2004, 2005 Topspin Communications.  All rights reserved.
3219820Sjeff * Copyright (c) 2005 Mellanox Technologies. All rights reserved.
4219820Sjeff * Copyright (c) 2006 Cisco Systems.  All rights reserved.
5219820Sjeff *
6219820Sjeff * This software is available to you under a choice of one of two
7219820Sjeff * licenses.  You may choose to be licensed under the terms of the GNU
8219820Sjeff * General Public License (GPL) Version 2, available from the file
9219820Sjeff * COPYING in the main directory of this source tree, or the
10219820Sjeff * OpenIB.org BSD license below:
11219820Sjeff *
12219820Sjeff *     Redistribution and use in source and binary forms, with or
13219820Sjeff *     without modification, are permitted provided that the following
14219820Sjeff *     conditions are met:
15219820Sjeff *
16219820Sjeff *      - Redistributions of source code must retain the above
17219820Sjeff *        copyright notice, this list of conditions and the following
18219820Sjeff *        disclaimer.
19219820Sjeff *
20219820Sjeff *      - Redistributions in binary form must reproduce the above
21219820Sjeff *        copyright notice, this list of conditions and the following
22219820Sjeff *        disclaimer in the documentation and/or other materials
23219820Sjeff *        provided with the distribution.
24219820Sjeff *
25219820Sjeff * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26219820Sjeff * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27219820Sjeff * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28219820Sjeff * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29219820Sjeff * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30219820Sjeff * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31219820Sjeff * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32219820Sjeff * SOFTWARE.
33219820Sjeff */
34219820Sjeff
35219820Sjeff#ifndef MTHCA_CMD_H
36219820Sjeff#define MTHCA_CMD_H
37219820Sjeff
38219820Sjeff#include <rdma/ib_verbs.h>
39219820Sjeff
40219820Sjeff#define MTHCA_MAILBOX_SIZE 4096
41219820Sjeff
42219820Sjeffenum {
43219820Sjeff	/* command completed successfully: */
44219820Sjeff	MTHCA_CMD_STAT_OK 	      = 0x00,
45219820Sjeff	/* Internal error (such as a bus error) occurred while processing command: */
46219820Sjeff	MTHCA_CMD_STAT_INTERNAL_ERR   = 0x01,
47219820Sjeff	/* Operation/command not supported or opcode modifier not supported: */
48219820Sjeff	MTHCA_CMD_STAT_BAD_OP 	      = 0x02,
49219820Sjeff	/* Parameter not supported or parameter out of range: */
50219820Sjeff	MTHCA_CMD_STAT_BAD_PARAM      = 0x03,
51219820Sjeff	/* System not enabled or bad system state: */
52219820Sjeff	MTHCA_CMD_STAT_BAD_SYS_STATE  = 0x04,
53219820Sjeff	/* Attempt to access reserved or unallocaterd resource: */
54219820Sjeff	MTHCA_CMD_STAT_BAD_RESOURCE   = 0x05,
55219820Sjeff	/* Requested resource is currently executing a command, or is otherwise busy: */
56219820Sjeff	MTHCA_CMD_STAT_RESOURCE_BUSY  = 0x06,
57219820Sjeff	/* memory error: */
58219820Sjeff	MTHCA_CMD_STAT_DDR_MEM_ERR    = 0x07,
59219820Sjeff	/* Required capability exceeds device limits: */
60219820Sjeff	MTHCA_CMD_STAT_EXCEED_LIM     = 0x08,
61219820Sjeff	/* Resource is not in the appropriate state or ownership: */
62219820Sjeff	MTHCA_CMD_STAT_BAD_RES_STATE  = 0x09,
63219820Sjeff	/* Index out of range: */
64219820Sjeff	MTHCA_CMD_STAT_BAD_INDEX      = 0x0a,
65219820Sjeff	/* FW image corrupted: */
66219820Sjeff	MTHCA_CMD_STAT_BAD_NVMEM      = 0x0b,
67219820Sjeff	/* Attempt to modify a QP/EE which is not in the presumed state: */
68219820Sjeff	MTHCA_CMD_STAT_BAD_QPEE_STATE = 0x10,
69219820Sjeff	/* Bad segment parameters (Address/Size): */
70219820Sjeff	MTHCA_CMD_STAT_BAD_SEG_PARAM  = 0x20,
71219820Sjeff	/* Memory Region has Memory Windows bound to: */
72219820Sjeff	MTHCA_CMD_STAT_REG_BOUND      = 0x21,
73219820Sjeff	/* HCA local attached memory not present: */
74219820Sjeff	MTHCA_CMD_STAT_LAM_NOT_PRE    = 0x22,
75219820Sjeff	/* Bad management packet (silently discarded): */
76219820Sjeff	MTHCA_CMD_STAT_BAD_PKT 	      = 0x30,
77219820Sjeff	/* More outstanding CQEs in CQ than new CQ size: */
78219820Sjeff	MTHCA_CMD_STAT_BAD_SIZE       = 0x40
79219820Sjeff};
80219820Sjeff
81219820Sjeffenum {
82219820Sjeff	MTHCA_TRANS_INVALID = 0,
83219820Sjeff	MTHCA_TRANS_RST2INIT,
84219820Sjeff	MTHCA_TRANS_INIT2INIT,
85219820Sjeff	MTHCA_TRANS_INIT2RTR,
86219820Sjeff	MTHCA_TRANS_RTR2RTS,
87219820Sjeff	MTHCA_TRANS_RTS2RTS,
88219820Sjeff	MTHCA_TRANS_SQERR2RTS,
89219820Sjeff	MTHCA_TRANS_ANY2ERR,
90219820Sjeff	MTHCA_TRANS_RTS2SQD,
91219820Sjeff	MTHCA_TRANS_SQD2SQD,
92219820Sjeff	MTHCA_TRANS_SQD2RTS,
93219820Sjeff	MTHCA_TRANS_ANY2RST,
94219820Sjeff};
95219820Sjeff
96219820Sjeffenum {
97219820Sjeff	DEV_LIM_FLAG_RC                 = 1 << 0,
98219820Sjeff	DEV_LIM_FLAG_UC                 = 1 << 1,
99219820Sjeff	DEV_LIM_FLAG_UD                 = 1 << 2,
100219820Sjeff	DEV_LIM_FLAG_RD                 = 1 << 3,
101219820Sjeff	DEV_LIM_FLAG_RAW_IPV6           = 1 << 4,
102219820Sjeff	DEV_LIM_FLAG_RAW_ETHER          = 1 << 5,
103219820Sjeff	DEV_LIM_FLAG_SRQ                = 1 << 6,
104219820Sjeff	DEV_LIM_FLAG_IPOIB_CSUM		= 1 << 7,
105219820Sjeff	DEV_LIM_FLAG_BAD_PKEY_CNTR      = 1 << 8,
106219820Sjeff	DEV_LIM_FLAG_BAD_QKEY_CNTR      = 1 << 9,
107219820Sjeff	DEV_LIM_FLAG_MW                 = 1 << 16,
108219820Sjeff	DEV_LIM_FLAG_AUTO_PATH_MIG      = 1 << 17,
109219820Sjeff	DEV_LIM_FLAG_ATOMIC             = 1 << 18,
110219820Sjeff	DEV_LIM_FLAG_RAW_MULTI          = 1 << 19,
111219820Sjeff	DEV_LIM_FLAG_UD_AV_PORT_ENFORCE = 1 << 20,
112219820Sjeff	DEV_LIM_FLAG_UD_MULTI           = 1 << 21,
113219820Sjeff};
114219820Sjeff
115219820Sjeffstruct mthca_mailbox {
116219820Sjeff	dma_addr_t dma;
117219820Sjeff	void      *buf;
118219820Sjeff};
119219820Sjeff
120219820Sjeffstruct mthca_dev_lim {
121219820Sjeff	int max_srq_sz;
122219820Sjeff	int max_qp_sz;
123219820Sjeff	int reserved_qps;
124219820Sjeff	int max_qps;
125219820Sjeff	int reserved_srqs;
126219820Sjeff	int max_srqs;
127219820Sjeff	int reserved_eecs;
128219820Sjeff	int max_eecs;
129219820Sjeff	int max_cq_sz;
130219820Sjeff	int reserved_cqs;
131219820Sjeff	int max_cqs;
132219820Sjeff	int max_mpts;
133219820Sjeff	int reserved_eqs;
134219820Sjeff	int max_eqs;
135219820Sjeff	int reserved_mtts;
136219820Sjeff	int max_mrw_sz;
137219820Sjeff	int reserved_mrws;
138219820Sjeff	int max_mtt_seg;
139219820Sjeff	int max_requester_per_qp;
140219820Sjeff	int max_responder_per_qp;
141219820Sjeff	int max_rdma_global;
142219820Sjeff	int local_ca_ack_delay;
143219820Sjeff	int max_mtu;
144219820Sjeff	int max_port_width;
145219820Sjeff	int max_vl;
146219820Sjeff	int num_ports;
147219820Sjeff	int max_gids;
148219820Sjeff	u16 stat_rate_support;
149219820Sjeff	int max_pkeys;
150219820Sjeff	u32 flags;
151219820Sjeff	int reserved_uars;
152219820Sjeff	int uar_size;
153219820Sjeff	int min_page_sz;
154219820Sjeff	int max_sg;
155219820Sjeff	int max_desc_sz;
156219820Sjeff	int max_qp_per_mcg;
157219820Sjeff	int reserved_mgms;
158219820Sjeff	int max_mcgs;
159219820Sjeff	int reserved_pds;
160219820Sjeff	int max_pds;
161219820Sjeff	int reserved_rdds;
162219820Sjeff	int max_rdds;
163219820Sjeff	int eec_entry_sz;
164219820Sjeff	int qpc_entry_sz;
165219820Sjeff	int eeec_entry_sz;
166219820Sjeff	int eqpc_entry_sz;
167219820Sjeff	int eqc_entry_sz;
168219820Sjeff	int cqc_entry_sz;
169219820Sjeff	int srq_entry_sz;
170219820Sjeff	int uar_scratch_entry_sz;
171219820Sjeff	int mpt_entry_sz;
172219820Sjeff	union {
173219820Sjeff		struct {
174219820Sjeff			int max_avs;
175219820Sjeff		} tavor;
176219820Sjeff		struct {
177219820Sjeff			int resize_srq;
178219820Sjeff			int max_pbl_sz;
179219820Sjeff			u8  bmme_flags;
180219820Sjeff			u32 reserved_lkey;
181219820Sjeff			int lam_required;
182219820Sjeff			u64 max_icm_sz;
183219820Sjeff		} arbel;
184219820Sjeff	} hca;
185219820Sjeff};
186219820Sjeff
187219820Sjeffstruct mthca_adapter {
188219820Sjeff	u32  vendor_id;
189219820Sjeff	u32  device_id;
190219820Sjeff	u32  revision_id;
191219820Sjeff	char board_id[MTHCA_BOARD_ID_LEN];
192219820Sjeff	u8   inta_pin;
193219820Sjeff};
194219820Sjeff
195219820Sjeffstruct mthca_init_hca_param {
196219820Sjeff	u64 qpc_base;
197219820Sjeff	u64 eec_base;
198219820Sjeff	u64 srqc_base;
199219820Sjeff	u64 cqc_base;
200219820Sjeff	u64 eqpc_base;
201219820Sjeff	u64 eeec_base;
202219820Sjeff	u64 eqc_base;
203219820Sjeff	u64 rdb_base;
204219820Sjeff	u64 mc_base;
205219820Sjeff	u64 mpt_base;
206219820Sjeff	u64 mtt_base;
207219820Sjeff	u64 uar_scratch_base;
208219820Sjeff	u64 uarc_base;
209219820Sjeff	u16 log_mc_entry_sz;
210219820Sjeff	u16 mc_hash_sz;
211219820Sjeff	u8  log_num_qps;
212219820Sjeff	u8  log_num_eecs;
213219820Sjeff	u8  log_num_srqs;
214219820Sjeff	u8  log_num_cqs;
215219820Sjeff	u8  log_num_eqs;
216219820Sjeff	u8  log_mc_table_sz;
217219820Sjeff	u8  mtt_seg_sz;
218219820Sjeff	u8  log_mpt_sz;
219219820Sjeff	u8  log_uar_sz;
220219820Sjeff	u8  log_uarc_sz;
221219820Sjeff};
222219820Sjeff
223219820Sjeffstruct mthca_init_ib_param {
224219820Sjeff	int port_width;
225219820Sjeff	int vl_cap;
226219820Sjeff	int mtu_cap;
227219820Sjeff	u16 gid_cap;
228219820Sjeff	u16 pkey_cap;
229219820Sjeff	int set_guid0;
230219820Sjeff	u64 guid0;
231219820Sjeff	int set_node_guid;
232219820Sjeff	u64 node_guid;
233219820Sjeff	int set_si_guid;
234219820Sjeff	u64 si_guid;
235219820Sjeff};
236219820Sjeff
237219820Sjeffstruct mthca_set_ib_param {
238219820Sjeff	int set_si_guid;
239219820Sjeff	int reset_qkey_viol;
240219820Sjeff	u64 si_guid;
241219820Sjeff	u32 cap_mask;
242219820Sjeff};
243219820Sjeff
244219820Sjeffint mthca_cmd_init(struct mthca_dev *dev);
245219820Sjeffvoid mthca_cmd_cleanup(struct mthca_dev *dev);
246219820Sjeffint mthca_cmd_use_events(struct mthca_dev *dev);
247219820Sjeffvoid mthca_cmd_use_polling(struct mthca_dev *dev);
248219820Sjeffvoid mthca_cmd_event(struct mthca_dev *dev, u16 token,
249219820Sjeff		     u8  status, u64 out_param);
250219820Sjeff
251219820Sjeffstruct mthca_mailbox *mthca_alloc_mailbox(struct mthca_dev *dev,
252219820Sjeff					  gfp_t gfp_mask);
253219820Sjeffvoid mthca_free_mailbox(struct mthca_dev *dev, struct mthca_mailbox *mailbox);
254219820Sjeff
255219820Sjeffint mthca_SYS_EN(struct mthca_dev *dev, u8 *status);
256219820Sjeffint mthca_SYS_DIS(struct mthca_dev *dev, u8 *status);
257219820Sjeffint mthca_MAP_FA(struct mthca_dev *dev, struct mthca_icm *icm, u8 *status);
258219820Sjeffint mthca_UNMAP_FA(struct mthca_dev *dev, u8 *status);
259219820Sjeffint mthca_RUN_FW(struct mthca_dev *dev, u8 *status);
260219820Sjeffint mthca_QUERY_FW(struct mthca_dev *dev, u8 *status);
261219820Sjeffint mthca_ENABLE_LAM(struct mthca_dev *dev, u8 *status);
262219820Sjeffint mthca_DISABLE_LAM(struct mthca_dev *dev, u8 *status);
263219820Sjeffint mthca_QUERY_DDR(struct mthca_dev *dev, u8 *status);
264219820Sjeffint mthca_QUERY_DEV_LIM(struct mthca_dev *dev,
265219820Sjeff			struct mthca_dev_lim *dev_lim, u8 *status);
266219820Sjeffint mthca_QUERY_ADAPTER(struct mthca_dev *dev,
267219820Sjeff			struct mthca_adapter *adapter, u8 *status);
268219820Sjeffint mthca_INIT_HCA(struct mthca_dev *dev,
269219820Sjeff		   struct mthca_init_hca_param *param,
270219820Sjeff		   u8 *status);
271219820Sjeffint mthca_INIT_IB(struct mthca_dev *dev,
272219820Sjeff		  struct mthca_init_ib_param *param,
273219820Sjeff		  int port, u8 *status);
274219820Sjeffint mthca_CLOSE_IB(struct mthca_dev *dev, int port, u8 *status);
275219820Sjeffint mthca_CLOSE_HCA(struct mthca_dev *dev, int panic, u8 *status);
276219820Sjeffint mthca_SET_IB(struct mthca_dev *dev, struct mthca_set_ib_param *param,
277219820Sjeff		 int port, u8 *status);
278219820Sjeffint mthca_MAP_ICM(struct mthca_dev *dev, struct mthca_icm *icm, u64 virt, u8 *status);
279219820Sjeffint mthca_MAP_ICM_page(struct mthca_dev *dev, u64 dma_addr, u64 virt, u8 *status);
280219820Sjeffint mthca_UNMAP_ICM(struct mthca_dev *dev, u64 virt, u32 page_count, u8 *status);
281219820Sjeffint mthca_MAP_ICM_AUX(struct mthca_dev *dev, struct mthca_icm *icm, u8 *status);
282219820Sjeffint mthca_UNMAP_ICM_AUX(struct mthca_dev *dev, u8 *status);
283219820Sjeffint mthca_SET_ICM_SIZE(struct mthca_dev *dev, u64 icm_size, u64 *aux_pages,
284219820Sjeff		       u8 *status);
285219820Sjeffint mthca_SW2HW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
286219820Sjeff		    int mpt_index, u8 *status);
287219820Sjeffint mthca_HW2SW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
288219820Sjeff		    int mpt_index, u8 *status);
289219820Sjeffint mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
290219820Sjeff		    int num_mtt, u8 *status);
291219820Sjeffint mthca_SYNC_TPT(struct mthca_dev *dev, u8 *status);
292219820Sjeffint mthca_MAP_EQ(struct mthca_dev *dev, u64 event_mask, int unmap,
293219820Sjeff		 int eq_num, u8 *status);
294219820Sjeffint mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
295219820Sjeff		   int eq_num, u8 *status);
296219820Sjeffint mthca_HW2SW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
297219820Sjeff		   int eq_num, u8 *status);
298219820Sjeffint mthca_SW2HW_CQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
299219820Sjeff		   int cq_num, u8 *status);
300219820Sjeffint mthca_HW2SW_CQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
301219820Sjeff		   int cq_num, u8 *status);
302219820Sjeffint mthca_RESIZE_CQ(struct mthca_dev *dev, int cq_num, u32 lkey, u8 log_size,
303219820Sjeff		    u8 *status);
304219820Sjeffint mthca_SW2HW_SRQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
305219820Sjeff		    int srq_num, u8 *status);
306219820Sjeffint mthca_HW2SW_SRQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
307219820Sjeff		    int srq_num, u8 *status);
308219820Sjeffint mthca_QUERY_SRQ(struct mthca_dev *dev, u32 num,
309219820Sjeff		    struct mthca_mailbox *mailbox, u8 *status);
310219820Sjeffint mthca_ARM_SRQ(struct mthca_dev *dev, int srq_num, int limit, u8 *status);
311219820Sjeffint mthca_MODIFY_QP(struct mthca_dev *dev, enum ib_qp_state cur,
312219820Sjeff		    enum ib_qp_state next, u32 num, int is_ee,
313219820Sjeff		    struct mthca_mailbox *mailbox, u32 optmask,
314219820Sjeff		    u8 *status);
315219820Sjeffint mthca_QUERY_QP(struct mthca_dev *dev, u32 num, int is_ee,
316219820Sjeff		   struct mthca_mailbox *mailbox, u8 *status);
317219820Sjeffint mthca_CONF_SPECIAL_QP(struct mthca_dev *dev, int type, u32 qpn,
318219820Sjeff			  u8 *status);
319219820Sjeffint mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
320219820Sjeff		  int port, struct ib_wc *in_wc, struct ib_grh *in_grh,
321219820Sjeff		  void *in_mad, void *response_mad, u8 *status);
322219820Sjeffint mthca_READ_MGM(struct mthca_dev *dev, int index,
323219820Sjeff		   struct mthca_mailbox *mailbox, u8 *status);
324219820Sjeffint mthca_WRITE_MGM(struct mthca_dev *dev, int index,
325219820Sjeff		    struct mthca_mailbox *mailbox, u8 *status);
326219820Sjeffint mthca_MGID_HASH(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
327219820Sjeff		    u16 *hash, u8 *status);
328219820Sjeffint mthca_NOP(struct mthca_dev *dev, u8 *status);
329219820Sjeff
330219820Sjeff#endif /* MTHCA_CMD_H */
331