hinic_hw_api_cmd.h 7.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*
 * Huawei HiNIC PCI Express Linux driver
 * Copyright(c) 2017 Huawei Technologies Co., Ltd
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms and conditions of the GNU General Public License,
 * version 2, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
 *
 */

#ifndef HINIC_HW_API_CMD_H
#define HINIC_HW_API_CMD_H

#include <linux/types.h>
20
#include <linux/semaphore.h>
21 22 23

#include "hinic_hw_if.h"

24 25 26 27 28 29 30 31 32 33 34 35
#define HINIC_API_CMD_PI_IDX_SHIFT                              0

#define HINIC_API_CMD_PI_IDX_MASK                               0xFFFFFF

#define HINIC_API_CMD_PI_SET(val, member)                       \
	(((u32)(val) & HINIC_API_CMD_PI_##member##_MASK) <<     \
	 HINIC_API_CMD_PI_##member##_SHIFT)

#define HINIC_API_CMD_PI_CLEAR(val, member)                     \
	((val) & (~(HINIC_API_CMD_PI_##member##_MASK            \
	 << HINIC_API_CMD_PI_##member##_SHIFT)))

36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
#define HINIC_API_CMD_CHAIN_REQ_RESTART_SHIFT                   1

#define HINIC_API_CMD_CHAIN_REQ_RESTART_MASK                    0x1

#define HINIC_API_CMD_CHAIN_REQ_SET(val, member)                \
	(((u32)(val) & HINIC_API_CMD_CHAIN_REQ_##member##_MASK) << \
	 HINIC_API_CMD_CHAIN_REQ_##member##_SHIFT)

#define HINIC_API_CMD_CHAIN_REQ_GET(val, member)                \
	(((val) >> HINIC_API_CMD_CHAIN_REQ_##member##_SHIFT) &  \
	 HINIC_API_CMD_CHAIN_REQ_##member##_MASK)

#define HINIC_API_CMD_CHAIN_REQ_CLEAR(val, member)              \
	((val) & (~(HINIC_API_CMD_CHAIN_REQ_##member##_MASK     \
	 << HINIC_API_CMD_CHAIN_REQ_##member##_SHIFT)))

#define HINIC_API_CMD_CHAIN_CTRL_RESTART_WB_STAT_SHIFT          1
#define HINIC_API_CMD_CHAIN_CTRL_XOR_ERR_SHIFT                  2
#define HINIC_API_CMD_CHAIN_CTRL_AEQE_EN_SHIFT                  4
#define HINIC_API_CMD_CHAIN_CTRL_AEQ_ID_SHIFT                   8
#define HINIC_API_CMD_CHAIN_CTRL_XOR_CHK_EN_SHIFT               28
#define HINIC_API_CMD_CHAIN_CTRL_CELL_SIZE_SHIFT                30

#define HINIC_API_CMD_CHAIN_CTRL_RESTART_WB_STAT_MASK           0x1
#define HINIC_API_CMD_CHAIN_CTRL_XOR_ERR_MASK                   0x1
#define HINIC_API_CMD_CHAIN_CTRL_AEQE_EN_MASK                   0x1
#define HINIC_API_CMD_CHAIN_CTRL_AEQ_ID_MASK                    0x3
#define HINIC_API_CMD_CHAIN_CTRL_XOR_CHK_EN_MASK                0x3
#define HINIC_API_CMD_CHAIN_CTRL_CELL_SIZE_MASK                 0x3

#define HINIC_API_CMD_CHAIN_CTRL_SET(val, member)               \
	(((u32)(val) & HINIC_API_CMD_CHAIN_CTRL_##member##_MASK) << \
	 HINIC_API_CMD_CHAIN_CTRL_##member##_SHIFT)

#define HINIC_API_CMD_CHAIN_CTRL_CLEAR(val, member)             \
	((val) & (~(HINIC_API_CMD_CHAIN_CTRL_##member##_MASK    \
	 << HINIC_API_CMD_CHAIN_CTRL_##member##_SHIFT)))

74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
#define HINIC_API_CMD_CELL_CTRL_DATA_SZ_SHIFT                   0
#define HINIC_API_CMD_CELL_CTRL_RD_DMA_ATTR_SHIFT               16
#define HINIC_API_CMD_CELL_CTRL_WR_DMA_ATTR_SHIFT               24
#define HINIC_API_CMD_CELL_CTRL_XOR_CHKSUM_SHIFT                56

#define HINIC_API_CMD_CELL_CTRL_DATA_SZ_MASK                    0x3F
#define HINIC_API_CMD_CELL_CTRL_RD_DMA_ATTR_MASK                0x3F
#define HINIC_API_CMD_CELL_CTRL_WR_DMA_ATTR_MASK                0x3F
#define HINIC_API_CMD_CELL_CTRL_XOR_CHKSUM_MASK                 0xFF

#define HINIC_API_CMD_CELL_CTRL_SET(val, member)                \
	((((u64)val) & HINIC_API_CMD_CELL_CTRL_##member##_MASK) << \
	 HINIC_API_CMD_CELL_CTRL_##member##_SHIFT)

#define HINIC_API_CMD_DESC_API_TYPE_SHIFT                       0
#define HINIC_API_CMD_DESC_RD_WR_SHIFT                          1
#define HINIC_API_CMD_DESC_MGMT_BYPASS_SHIFT                    2
#define HINIC_API_CMD_DESC_DEST_SHIFT                           32
#define HINIC_API_CMD_DESC_SIZE_SHIFT                           40
#define HINIC_API_CMD_DESC_XOR_CHKSUM_SHIFT                     56

#define HINIC_API_CMD_DESC_API_TYPE_MASK                        0x1
#define HINIC_API_CMD_DESC_RD_WR_MASK                           0x1
#define HINIC_API_CMD_DESC_MGMT_BYPASS_MASK                     0x1
#define HINIC_API_CMD_DESC_DEST_MASK                            0x1F
#define HINIC_API_CMD_DESC_SIZE_MASK                            0x7FF
#define HINIC_API_CMD_DESC_XOR_CHKSUM_MASK                      0xFF

#define HINIC_API_CMD_DESC_SET(val, member)                     \
	((((u64)val) & HINIC_API_CMD_DESC_##member##_MASK) <<   \
	 HINIC_API_CMD_DESC_##member##_SHIFT)

#define HINIC_API_CMD_STATUS_HEADER_CHAIN_ID_SHIFT              16

#define HINIC_API_CMD_STATUS_HEADER_CHAIN_ID_MASK               0xFF

#define HINIC_API_CMD_STATUS_HEADER_GET(val, member)            \
	(((val) >> HINIC_API_CMD_STATUS_HEADER_##member##_SHIFT) & \
	 HINIC_API_CMD_STATUS_HEADER_##member##_MASK)

#define HINIC_API_CMD_STATUS_CONS_IDX_SHIFT                     0
#define HINIC_API_CMD_STATUS_CHKSUM_ERR_SHIFT                   28

#define HINIC_API_CMD_STATUS_CONS_IDX_MASK                      0xFFFFFF
#define HINIC_API_CMD_STATUS_CHKSUM_ERR_MASK                    0x3

#define HINIC_API_CMD_STATUS_GET(val, member)                   \
	(((val) >> HINIC_API_CMD_STATUS_##member##_SHIFT) &     \
	 HINIC_API_CMD_STATUS_##member##_MASK)

124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
enum hinic_api_cmd_chain_type {
	HINIC_API_CMD_WRITE_TO_MGMT_CPU = 2,

	HINIC_API_CMD_MAX,
};

struct hinic_api_cmd_chain_attr {
	struct hinic_hwif               *hwif;
	enum hinic_api_cmd_chain_type   chain_type;

	u32                             num_cells;
	u16                             cell_size;
};

struct hinic_api_cmd_status {
	u64     header;
	u32     status;
	u32     rsvd0;
	u32     rsvd1;
	u32     rsvd2;
	u64     rsvd3;
};

/* HW struct */
struct hinic_api_cmd_cell {
	u64 ctrl;

	/* address is 64 bit in HW struct */
	u64 next_cell_paddr;

	u64 desc;

	/* HW struct */
	union {
		struct {
			u64 hw_cmd_paddr;
		} write;

		struct {
			u64 hw_wb_resp_paddr;
			u64 hw_cmd_paddr;
		} read;
	};
};

struct hinic_api_cmd_cell_ctxt {
	dma_addr_t                      cell_paddr;
	struct hinic_api_cmd_cell       *cell_vaddr;

	dma_addr_t                      api_cmd_paddr;
	u8                              *api_cmd_vaddr;
};

struct hinic_api_cmd_chain {
	struct hinic_hwif               *hwif;
	enum hinic_api_cmd_chain_type   chain_type;

	u32                             num_cells;
	u16                             cell_size;

	/* HW members in 24 bit format */
	u32                             prod_idx;
	u32                             cons_idx;

188 189
	struct semaphore                sem;

190 191 192 193 194 195 196 197 198 199
	struct hinic_api_cmd_cell_ctxt  *cell_ctxt;

	dma_addr_t                      wb_status_paddr;
	struct hinic_api_cmd_status     *wb_status;

	dma_addr_t                      head_cell_paddr;
	struct hinic_api_cmd_cell       *head_node;
	struct hinic_api_cmd_cell       *curr_node;
};

200 201 202
int hinic_api_cmd_write(struct hinic_api_cmd_chain *chain,
			enum hinic_node_id dest, u8 *cmd, u16 size);

203 204 205 206 207 208
int hinic_api_cmd_init(struct hinic_api_cmd_chain **chain,
		       struct hinic_hwif *hwif);

void hinic_api_cmd_free(struct hinic_api_cmd_chain **chain);

#endif