162306a36Sopenharmony_ci/* This file is part of the Emulex RoCE Device Driver for
262306a36Sopenharmony_ci * RoCE (RDMA over Converged Ethernet) adapters.
362306a36Sopenharmony_ci * Copyright (C) 2012-2015 Emulex. All rights reserved.
462306a36Sopenharmony_ci * EMULEX and SLI are trademarks of Emulex.
562306a36Sopenharmony_ci * www.emulex.com
662306a36Sopenharmony_ci *
762306a36Sopenharmony_ci * This software is available to you under a choice of one of two licenses.
862306a36Sopenharmony_ci * You may choose to be licensed under the terms of the GNU General Public
962306a36Sopenharmony_ci * License (GPL) Version 2, available from the file COPYING in the main
1062306a36Sopenharmony_ci * directory of this source tree, or the BSD license below:
1162306a36Sopenharmony_ci *
1262306a36Sopenharmony_ci * Redistribution and use in source and binary forms, with or without
1362306a36Sopenharmony_ci * modification, are permitted provided that the following conditions
1462306a36Sopenharmony_ci * are met:
1562306a36Sopenharmony_ci *
1662306a36Sopenharmony_ci * - Redistributions of source code must retain the above copyright notice,
1762306a36Sopenharmony_ci *   this list of conditions and the following disclaimer.
1862306a36Sopenharmony_ci *
1962306a36Sopenharmony_ci * - Redistributions in binary form must reproduce the above copyright
2062306a36Sopenharmony_ci *   notice, this list of conditions and the following disclaimer in
2162306a36Sopenharmony_ci *   the documentation and/or other materials provided with the distribution.
2262306a36Sopenharmony_ci *
2362306a36Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2462306a36Sopenharmony_ci * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,THE
2562306a36Sopenharmony_ci * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2662306a36Sopenharmony_ci * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
2762306a36Sopenharmony_ci * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2862306a36Sopenharmony_ci * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2962306a36Sopenharmony_ci * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
3062306a36Sopenharmony_ci * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
3162306a36Sopenharmony_ci * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
3262306a36Sopenharmony_ci * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
3362306a36Sopenharmony_ci * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3462306a36Sopenharmony_ci *
3562306a36Sopenharmony_ci * Contact Information:
3662306a36Sopenharmony_ci * linux-drivers@emulex.com
3762306a36Sopenharmony_ci *
3862306a36Sopenharmony_ci * Emulex
3962306a36Sopenharmony_ci * 3333 Susan Street
4062306a36Sopenharmony_ci * Costa Mesa, CA 92626
4162306a36Sopenharmony_ci */
4262306a36Sopenharmony_ci
4362306a36Sopenharmony_ci#ifndef __OCRDMA_HW_H__
4462306a36Sopenharmony_ci#define __OCRDMA_HW_H__
4562306a36Sopenharmony_ci
4662306a36Sopenharmony_ci#include "ocrdma_sli.h"
4762306a36Sopenharmony_ci
4862306a36Sopenharmony_cistatic inline void ocrdma_cpu_to_le32(void *dst, u32 len)
4962306a36Sopenharmony_ci{
5062306a36Sopenharmony_ci#ifdef __BIG_ENDIAN
5162306a36Sopenharmony_ci	int i = 0;
5262306a36Sopenharmony_ci	u32 *src_ptr = dst;
5362306a36Sopenharmony_ci	u32 *dst_ptr = dst;
5462306a36Sopenharmony_ci	for (; i < (len / 4); i++)
5562306a36Sopenharmony_ci		*(dst_ptr + i) = cpu_to_le32p(src_ptr + i);
5662306a36Sopenharmony_ci#endif
5762306a36Sopenharmony_ci}
5862306a36Sopenharmony_ci
5962306a36Sopenharmony_cistatic inline void ocrdma_le32_to_cpu(void *dst, u32 len)
6062306a36Sopenharmony_ci{
6162306a36Sopenharmony_ci#ifdef __BIG_ENDIAN
6262306a36Sopenharmony_ci	int i = 0;
6362306a36Sopenharmony_ci	u32 *src_ptr = dst;
6462306a36Sopenharmony_ci	u32 *dst_ptr = dst;
6562306a36Sopenharmony_ci	for (; i < (len / sizeof(u32)); i++)
6662306a36Sopenharmony_ci		*(dst_ptr + i) = le32_to_cpu(*(src_ptr + i));
6762306a36Sopenharmony_ci#endif
6862306a36Sopenharmony_ci}
6962306a36Sopenharmony_ci
7062306a36Sopenharmony_cistatic inline void ocrdma_copy_cpu_to_le32(void *dst, void *src, u32 len)
7162306a36Sopenharmony_ci{
7262306a36Sopenharmony_ci#ifdef __BIG_ENDIAN
7362306a36Sopenharmony_ci	int i = 0;
7462306a36Sopenharmony_ci	u32 *src_ptr = src;
7562306a36Sopenharmony_ci	u32 *dst_ptr = dst;
7662306a36Sopenharmony_ci	for (; i < (len / sizeof(u32)); i++)
7762306a36Sopenharmony_ci		*(dst_ptr + i) = cpu_to_le32p(src_ptr + i);
7862306a36Sopenharmony_ci#else
7962306a36Sopenharmony_ci	memcpy(dst, src, len);
8062306a36Sopenharmony_ci#endif
8162306a36Sopenharmony_ci}
8262306a36Sopenharmony_ci
8362306a36Sopenharmony_cistatic inline void ocrdma_copy_le32_to_cpu(void *dst, void *src, u32 len)
8462306a36Sopenharmony_ci{
8562306a36Sopenharmony_ci#ifdef __BIG_ENDIAN
8662306a36Sopenharmony_ci	int i = 0;
8762306a36Sopenharmony_ci	u32 *src_ptr = src;
8862306a36Sopenharmony_ci	u32 *dst_ptr = dst;
8962306a36Sopenharmony_ci	for (; i < len / sizeof(u32); i++)
9062306a36Sopenharmony_ci		*(dst_ptr + i) = le32_to_cpu(*(src_ptr + i));
9162306a36Sopenharmony_ci#else
9262306a36Sopenharmony_ci	memcpy(dst, src, len);
9362306a36Sopenharmony_ci#endif
9462306a36Sopenharmony_ci}
9562306a36Sopenharmony_ci
9662306a36Sopenharmony_cistatic inline u64 ocrdma_get_db_addr(struct ocrdma_dev *dev, u32 pdid)
9762306a36Sopenharmony_ci{
9862306a36Sopenharmony_ci	return dev->nic_info.unmapped_db + (pdid * dev->nic_info.db_page_size);
9962306a36Sopenharmony_ci}
10062306a36Sopenharmony_ci
10162306a36Sopenharmony_ciint ocrdma_init_hw(struct ocrdma_dev *);
10262306a36Sopenharmony_civoid ocrdma_cleanup_hw(struct ocrdma_dev *);
10362306a36Sopenharmony_ci
10462306a36Sopenharmony_cienum ib_qp_state get_ibqp_state(enum ocrdma_qp_state qps);
10562306a36Sopenharmony_civoid ocrdma_ring_cq_db(struct ocrdma_dev *, u16 cq_id, bool armed,
10662306a36Sopenharmony_ci		       bool solicited, u16 cqe_popped);
10762306a36Sopenharmony_ci
10862306a36Sopenharmony_ci/* verbs specific mailbox commands */
10962306a36Sopenharmony_ciint ocrdma_mbx_get_link_speed(struct ocrdma_dev *dev, u8 *lnk_speed,
11062306a36Sopenharmony_ci			      u8 *lnk_st);
11162306a36Sopenharmony_ciint ocrdma_query_config(struct ocrdma_dev *,
11262306a36Sopenharmony_ci			struct ocrdma_mbx_query_config *config);
11362306a36Sopenharmony_ci
11462306a36Sopenharmony_ciint ocrdma_mbx_alloc_pd(struct ocrdma_dev *, struct ocrdma_pd *);
11562306a36Sopenharmony_ciint ocrdma_mbx_dealloc_pd(struct ocrdma_dev *, struct ocrdma_pd *);
11662306a36Sopenharmony_ci
11762306a36Sopenharmony_ciint ocrdma_mbx_alloc_lkey(struct ocrdma_dev *, struct ocrdma_hw_mr *hwmr,
11862306a36Sopenharmony_ci			  u32 pd_id, int addr_check);
11962306a36Sopenharmony_ciint ocrdma_mbx_dealloc_lkey(struct ocrdma_dev *, int fmr, u32 lkey);
12062306a36Sopenharmony_ci
12162306a36Sopenharmony_ciint ocrdma_reg_mr(struct ocrdma_dev *, struct ocrdma_hw_mr *hwmr,
12262306a36Sopenharmony_ci			u32 pd_id, int acc);
12362306a36Sopenharmony_ciint ocrdma_mbx_create_cq(struct ocrdma_dev *, struct ocrdma_cq *,
12462306a36Sopenharmony_ci				int entries, int dpp_cq, u16 pd_id);
12562306a36Sopenharmony_civoid ocrdma_mbx_destroy_cq(struct ocrdma_dev *dev, struct ocrdma_cq *cq);
12662306a36Sopenharmony_ci
12762306a36Sopenharmony_ciint ocrdma_mbx_create_qp(struct ocrdma_qp *, struct ib_qp_init_attr *attrs,
12862306a36Sopenharmony_ci			 u8 enable_dpp_cq, u16 dpp_cq_id, u16 *dpp_offset,
12962306a36Sopenharmony_ci			 u16 *dpp_credit_lmt);
13062306a36Sopenharmony_ciint ocrdma_mbx_modify_qp(struct ocrdma_dev *, struct ocrdma_qp *,
13162306a36Sopenharmony_ci			 struct ib_qp_attr *attrs, int attr_mask);
13262306a36Sopenharmony_ciint ocrdma_mbx_query_qp(struct ocrdma_dev *, struct ocrdma_qp *,
13362306a36Sopenharmony_ci			struct ocrdma_qp_params *param);
13462306a36Sopenharmony_ciint ocrdma_mbx_destroy_qp(struct ocrdma_dev *, struct ocrdma_qp *);
13562306a36Sopenharmony_ciint ocrdma_mbx_create_srq(struct ocrdma_dev *, struct ocrdma_srq *,
13662306a36Sopenharmony_ci			  struct ib_srq_init_attr *,
13762306a36Sopenharmony_ci			  struct ocrdma_pd *);
13862306a36Sopenharmony_ciint ocrdma_mbx_modify_srq(struct ocrdma_srq *, struct ib_srq_attr *);
13962306a36Sopenharmony_ciint ocrdma_mbx_query_srq(struct ocrdma_srq *, struct ib_srq_attr *);
14062306a36Sopenharmony_civoid ocrdma_mbx_destroy_srq(struct ocrdma_dev *dev, struct ocrdma_srq *srq);
14162306a36Sopenharmony_ci
14262306a36Sopenharmony_ciint ocrdma_alloc_av(struct ocrdma_dev *dev, struct ocrdma_ah *ah);
14362306a36Sopenharmony_civoid ocrdma_free_av(struct ocrdma_dev *dev, struct ocrdma_ah *ah);
14462306a36Sopenharmony_ci
14562306a36Sopenharmony_ciint ocrdma_qp_state_change(struct ocrdma_qp *, enum ib_qp_state new_state,
14662306a36Sopenharmony_ci			    enum ib_qp_state *old_ib_state);
14762306a36Sopenharmony_cibool ocrdma_is_qp_in_sq_flushlist(struct ocrdma_cq *, struct ocrdma_qp *);
14862306a36Sopenharmony_cibool ocrdma_is_qp_in_rq_flushlist(struct ocrdma_cq *, struct ocrdma_qp *);
14962306a36Sopenharmony_civoid ocrdma_flush_qp(struct ocrdma_qp *);
15062306a36Sopenharmony_ciint ocrdma_get_irq(struct ocrdma_dev *dev, struct ocrdma_eq *eq);
15162306a36Sopenharmony_ci
15262306a36Sopenharmony_ciint ocrdma_mbx_rdma_stats(struct ocrdma_dev *, bool reset);
15362306a36Sopenharmony_cichar *port_speed_string(struct ocrdma_dev *dev);
15462306a36Sopenharmony_civoid ocrdma_init_service_level(struct ocrdma_dev *);
15562306a36Sopenharmony_civoid ocrdma_alloc_pd_pool(struct ocrdma_dev *dev);
15662306a36Sopenharmony_civoid ocrdma_free_pd_range(struct ocrdma_dev *dev);
15762306a36Sopenharmony_civoid ocrdma_update_link_state(struct ocrdma_dev *dev, u8 lstate);
15862306a36Sopenharmony_ci
15962306a36Sopenharmony_ci#endif				/* __OCRDMA_HW_H__ */
160