xref: /openbmc/linux/drivers/infiniband/hw/ocrdma/ocrdma_hw.h (revision 0898782247ae533d1f4e47a06bc5d4870931b284)
171ee6730SDevesh Sharma /* This file is part of the Emulex RoCE Device Driver for
271ee6730SDevesh Sharma  * RoCE (RDMA over Converged Ethernet) adapters.
371ee6730SDevesh Sharma  * Copyright (C) 2012-2015 Emulex. All rights reserved.
471ee6730SDevesh Sharma  * EMULEX and SLI are trademarks of Emulex.
571ee6730SDevesh Sharma  * www.emulex.com
671ee6730SDevesh Sharma  *
771ee6730SDevesh Sharma  * This software is available to you under a choice of one of two licenses.
871ee6730SDevesh Sharma  * You may choose to be licensed under the terms of the GNU General Public
971ee6730SDevesh Sharma  * License (GPL) Version 2, available from the file COPYING in the main
1071ee6730SDevesh Sharma  * directory of this source tree, or the BSD license below:
1171ee6730SDevesh Sharma  *
1271ee6730SDevesh Sharma  * Redistribution and use in source and binary forms, with or without
1371ee6730SDevesh Sharma  * modification, are permitted provided that the following conditions
1471ee6730SDevesh Sharma  * are met:
1571ee6730SDevesh Sharma  *
1671ee6730SDevesh Sharma  * - Redistributions of source code must retain the above copyright notice,
1771ee6730SDevesh Sharma  *   this list of conditions and the following disclaimer.
1871ee6730SDevesh Sharma  *
1971ee6730SDevesh Sharma  * - Redistributions in binary form must reproduce the above copyright
2071ee6730SDevesh Sharma  *   notice, this list of conditions and the following disclaimer in
2171ee6730SDevesh Sharma  *   the documentation and/or other materials provided with the distribution.
2271ee6730SDevesh Sharma  *
2371ee6730SDevesh Sharma  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2471ee6730SDevesh Sharma  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,THE
2571ee6730SDevesh Sharma  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2671ee6730SDevesh Sharma  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
2771ee6730SDevesh Sharma  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2871ee6730SDevesh Sharma  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2971ee6730SDevesh Sharma  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
3071ee6730SDevesh Sharma  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
3171ee6730SDevesh Sharma  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
3271ee6730SDevesh Sharma  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
3371ee6730SDevesh Sharma  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34fe2caefcSParav Pandit  *
35fe2caefcSParav Pandit  * Contact Information:
36fe2caefcSParav Pandit  * linux-drivers@emulex.com
37fe2caefcSParav Pandit  *
38fe2caefcSParav Pandit  * Emulex
39fe2caefcSParav Pandit  * 3333 Susan Street
40fe2caefcSParav Pandit  * Costa Mesa, CA 92626
4171ee6730SDevesh Sharma  */
42fe2caefcSParav Pandit 
43fe2caefcSParav Pandit #ifndef __OCRDMA_HW_H__
44fe2caefcSParav Pandit #define __OCRDMA_HW_H__
45fe2caefcSParav Pandit 
46fe2caefcSParav Pandit #include "ocrdma_sli.h"
47fe2caefcSParav Pandit 
ocrdma_cpu_to_le32(void * dst,u32 len)48fe2caefcSParav Pandit static inline void ocrdma_cpu_to_le32(void *dst, u32 len)
49fe2caefcSParav Pandit {
50fe2caefcSParav Pandit #ifdef __BIG_ENDIAN
51fe2caefcSParav Pandit 	int i = 0;
52fe2caefcSParav Pandit 	u32 *src_ptr = dst;
53fe2caefcSParav Pandit 	u32 *dst_ptr = dst;
54fe2caefcSParav Pandit 	for (; i < (len / 4); i++)
55fe2caefcSParav Pandit 		*(dst_ptr + i) = cpu_to_le32p(src_ptr + i);
56fe2caefcSParav Pandit #endif
57fe2caefcSParav Pandit }
58fe2caefcSParav Pandit 
ocrdma_le32_to_cpu(void * dst,u32 len)59fe2caefcSParav Pandit static inline void ocrdma_le32_to_cpu(void *dst, u32 len)
60fe2caefcSParav Pandit {
61fe2caefcSParav Pandit #ifdef __BIG_ENDIAN
62fe2caefcSParav Pandit 	int i = 0;
63fe2caefcSParav Pandit 	u32 *src_ptr = dst;
64fe2caefcSParav Pandit 	u32 *dst_ptr = dst;
65fe2caefcSParav Pandit 	for (; i < (len / sizeof(u32)); i++)
66fe2caefcSParav Pandit 		*(dst_ptr + i) = le32_to_cpu(*(src_ptr + i));
67fe2caefcSParav Pandit #endif
68fe2caefcSParav Pandit }
69fe2caefcSParav Pandit 
ocrdma_copy_cpu_to_le32(void * dst,void * src,u32 len)70fe2caefcSParav Pandit static inline void ocrdma_copy_cpu_to_le32(void *dst, void *src, u32 len)
71fe2caefcSParav Pandit {
72fe2caefcSParav Pandit #ifdef __BIG_ENDIAN
73fe2caefcSParav Pandit 	int i = 0;
74fe2caefcSParav Pandit 	u32 *src_ptr = src;
75fe2caefcSParav Pandit 	u32 *dst_ptr = dst;
76fe2caefcSParav Pandit 	for (; i < (len / sizeof(u32)); i++)
77fe2caefcSParav Pandit 		*(dst_ptr + i) = cpu_to_le32p(src_ptr + i);
78fe2caefcSParav Pandit #else
79fe2caefcSParav Pandit 	memcpy(dst, src, len);
80fe2caefcSParav Pandit #endif
81fe2caefcSParav Pandit }
82fe2caefcSParav Pandit 
ocrdma_copy_le32_to_cpu(void * dst,void * src,u32 len)83fe2caefcSParav Pandit static inline void ocrdma_copy_le32_to_cpu(void *dst, void *src, u32 len)
84fe2caefcSParav Pandit {
85fe2caefcSParav Pandit #ifdef __BIG_ENDIAN
86fe2caefcSParav Pandit 	int i = 0;
87fe2caefcSParav Pandit 	u32 *src_ptr = src;
88fe2caefcSParav Pandit 	u32 *dst_ptr = dst;
89fe2caefcSParav Pandit 	for (; i < len / sizeof(u32); i++)
90fe2caefcSParav Pandit 		*(dst_ptr + i) = le32_to_cpu(*(src_ptr + i));
91fe2caefcSParav Pandit #else
92fe2caefcSParav Pandit 	memcpy(dst, src, len);
93fe2caefcSParav Pandit #endif
94fe2caefcSParav Pandit }
95fe2caefcSParav Pandit 
ocrdma_get_db_addr(struct ocrdma_dev * dev,u32 pdid)96cffce990SNaresh Gottumukkala static inline u64 ocrdma_get_db_addr(struct ocrdma_dev *dev, u32 pdid)
97cffce990SNaresh Gottumukkala {
98cffce990SNaresh Gottumukkala 	return dev->nic_info.unmapped_db + (pdid * dev->nic_info.db_page_size);
99cffce990SNaresh Gottumukkala }
100cffce990SNaresh Gottumukkala 
101fe2caefcSParav Pandit int ocrdma_init_hw(struct ocrdma_dev *);
102fe2caefcSParav Pandit void ocrdma_cleanup_hw(struct ocrdma_dev *);
103fe2caefcSParav Pandit 
104fe2caefcSParav Pandit enum ib_qp_state get_ibqp_state(enum ocrdma_qp_state qps);
105fe2caefcSParav Pandit void ocrdma_ring_cq_db(struct ocrdma_dev *, u16 cq_id, bool armed,
106fe2caefcSParav Pandit 		       bool solicited, u16 cqe_popped);
107fe2caefcSParav Pandit 
108fe2caefcSParav Pandit /* verbs specific mailbox commands */
10910a214dcSDevesh Sharma int ocrdma_mbx_get_link_speed(struct ocrdma_dev *dev, u8 *lnk_speed,
11010a214dcSDevesh Sharma 			      u8 *lnk_st);
111fe2caefcSParav Pandit int ocrdma_query_config(struct ocrdma_dev *,
112fe2caefcSParav Pandit 			struct ocrdma_mbx_query_config *config);
113fe2caefcSParav Pandit 
114fe2caefcSParav Pandit int ocrdma_mbx_alloc_pd(struct ocrdma_dev *, struct ocrdma_pd *);
115fe2caefcSParav Pandit int ocrdma_mbx_dealloc_pd(struct ocrdma_dev *, struct ocrdma_pd *);
116fe2caefcSParav Pandit 
117fe2caefcSParav Pandit int ocrdma_mbx_alloc_lkey(struct ocrdma_dev *, struct ocrdma_hw_mr *hwmr,
118fe2caefcSParav Pandit 			  u32 pd_id, int addr_check);
119fe2caefcSParav Pandit int ocrdma_mbx_dealloc_lkey(struct ocrdma_dev *, int fmr, u32 lkey);
120fe2caefcSParav Pandit 
121fe2caefcSParav Pandit int ocrdma_reg_mr(struct ocrdma_dev *, struct ocrdma_hw_mr *hwmr,
122fe2caefcSParav Pandit 			u32 pd_id, int acc);
123fe2caefcSParav Pandit int ocrdma_mbx_create_cq(struct ocrdma_dev *, struct ocrdma_cq *,
124cffce990SNaresh Gottumukkala 				int entries, int dpp_cq, u16 pd_id);
125*a52c8e24SLeon Romanovsky void ocrdma_mbx_destroy_cq(struct ocrdma_dev *dev, struct ocrdma_cq *cq);
126fe2caefcSParav Pandit 
127fe2caefcSParav Pandit int ocrdma_mbx_create_qp(struct ocrdma_qp *, struct ib_qp_init_attr *attrs,
128fe2caefcSParav Pandit 			 u8 enable_dpp_cq, u16 dpp_cq_id, u16 *dpp_offset,
129fe2caefcSParav Pandit 			 u16 *dpp_credit_lmt);
130fe2caefcSParav Pandit int ocrdma_mbx_modify_qp(struct ocrdma_dev *, struct ocrdma_qp *,
131bc1b04abSPrarit Bhargava 			 struct ib_qp_attr *attrs, int attr_mask);
132fe2caefcSParav Pandit int ocrdma_mbx_query_qp(struct ocrdma_dev *, struct ocrdma_qp *,
133fe2caefcSParav Pandit 			struct ocrdma_qp_params *param);
134fe2caefcSParav Pandit int ocrdma_mbx_destroy_qp(struct ocrdma_dev *, struct ocrdma_qp *);
1351afc0454SNaresh Gottumukkala int ocrdma_mbx_create_srq(struct ocrdma_dev *, struct ocrdma_srq *,
136fe2caefcSParav Pandit 			  struct ib_srq_init_attr *,
137fe2caefcSParav Pandit 			  struct ocrdma_pd *);
138fe2caefcSParav Pandit int ocrdma_mbx_modify_srq(struct ocrdma_srq *, struct ib_srq_attr *);
139fe2caefcSParav Pandit int ocrdma_mbx_query_srq(struct ocrdma_srq *, struct ib_srq_attr *);
14068e326deSLeon Romanovsky void ocrdma_mbx_destroy_srq(struct ocrdma_dev *dev, struct ocrdma_srq *srq);
141fe2caefcSParav Pandit 
142d3456914SLeon Romanovsky int ocrdma_alloc_av(struct ocrdma_dev *dev, struct ocrdma_ah *ah);
143d3456914SLeon Romanovsky void ocrdma_free_av(struct ocrdma_dev *dev, struct ocrdma_ah *ah);
144fe2caefcSParav Pandit 
145057729cbSNaresh Gottumukkala int ocrdma_qp_state_change(struct ocrdma_qp *, enum ib_qp_state new_state,
146fe2caefcSParav Pandit 			    enum ib_qp_state *old_ib_state);
147fe2caefcSParav Pandit bool ocrdma_is_qp_in_sq_flushlist(struct ocrdma_cq *, struct ocrdma_qp *);
148fe2caefcSParav Pandit bool ocrdma_is_qp_in_rq_flushlist(struct ocrdma_cq *, struct ocrdma_qp *);
149fe2caefcSParav Pandit void ocrdma_flush_qp(struct ocrdma_qp *);
150ea617626SDevesh Sharma int ocrdma_get_irq(struct ocrdma_dev *dev, struct ocrdma_eq *eq);
151fe2caefcSParav Pandit 
152a51f06e1SSelvin Xavier int ocrdma_mbx_rdma_stats(struct ocrdma_dev *, bool reset);
153a51f06e1SSelvin Xavier char *port_speed_string(struct ocrdma_dev *dev);
15431dbdd9aSSelvin Xavier void ocrdma_init_service_level(struct ocrdma_dev *);
1559ba1377dSMitesh Ahuja void ocrdma_alloc_pd_pool(struct ocrdma_dev *dev);
1569ba1377dSMitesh Ahuja void ocrdma_free_pd_range(struct ocrdma_dev *dev);
15710a214dcSDevesh Sharma void ocrdma_update_link_state(struct ocrdma_dev *dev, u8 lstate);
15831dbdd9aSSelvin Xavier 
159fe2caefcSParav Pandit #endif				/* __OCRDMA_HW_H__ */
160