/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */
/* Copyright (c) 2015-2018 Mellanox Technologies. All rights reserved */
#ifndef _MLXSW_CMD_H
#define _MLXSW_CMD_H
#include "item.h"
#define MLXSW_CMD_MBOX_SIZE 4096
static inline char *mlxsw_cmd_mbox_alloc(void)
{
return kzalloc(MLXSW_CMD_MBOX_SIZE, GFP_KERNEL);
}
static inline void mlxsw_cmd_mbox_free(char *mbox)
{
kfree(mbox);
}
static inline void mlxsw_cmd_mbox_zero(char *mbox)
{
memset(mbox, 0, MLXSW_CMD_MBOX_SIZE);
}
struct mlxsw_core;
int mlxsw_cmd_exec(struct mlxsw_core *mlxsw_core, u16 opcode, u8 opcode_mod,
u32 in_mod, bool out_mbox_direct, bool reset_ok,
char *in_mbox, size_t in_mbox_size,
char *out_mbox, size_t out_mbox_size);
static inline int mlxsw_cmd_exec_in(struct mlxsw_core *mlxsw_core, u16 opcode,
u8 opcode_mod, u32 in_mod, char *in_mbox,
size_t in_mbox_size)
{
return mlxsw_cmd_exec(mlxsw_core, opcode, opcode_mod, in_mod, false,
false, in_mbox, in_mbox_size, NULL, 0);
}
static inline int mlxsw_cmd_exec_out(struct mlxsw_core *mlxsw_core, u16 opcode,
u8 opcode_mod, u32 in_mod,
bool out_mbox_direct,
char *out_mbox, size_t out_mbox_size)
{
return mlxsw_cmd_exec(mlxsw_core, opcode, opcode_mod, in_mod,
out_mbox_direct, false, NULL, 0,
out_mbox, out_mbox_size);
}
static inline int mlxsw_cmd_exec_none(struct mlxsw_core *mlxsw_core, u16 opcode,
u8 opcode_mod, u32 in_mod)
{
return mlxsw_cmd_exec(mlxsw_core, opcode, opcode_mod, in_mod, false,
false, NULL, 0, NULL, 0);
}
enum mlxsw_cmd_opcode {
MLXSW_CMD_OPCODE_QUERY_FW = 0x004,
MLXSW_CMD_OPCODE_QUERY_BOARDINFO = 0x006,
MLXSW_CMD_OPCODE_QUERY_AQ_CAP = 0x003,
MLXSW_CMD_OPCODE_MAP_FA = 0xFFF,
MLXSW_CMD_OPCODE_UNMAP_FA = 0xFFE,
MLXSW_CMD_OPCODE_CONFIG_PROFILE = 0x100,
MLXSW_CMD_OPCODE_ACCESS_REG = 0x040,
MLXSW_CMD_OPCODE_SW2HW_DQ = 0x201,
MLXSW_CMD_OPCODE_HW2SW_DQ = 0x202,
MLXSW_CMD_OPCODE_2ERR_DQ = 0x01E,
MLXSW_CMD_OPCODE_QUERY_DQ = 0x022,
MLXSW_CMD_OPCODE_SW2HW_CQ = 0x016,
MLXSW_CMD_OPCODE_HW2SW_CQ = 0x017,
MLXSW_CMD_OPCODE_QUERY_CQ = 0x018,
MLXSW_CMD_OPCODE_SW2HW_EQ = 0x013,
MLXSW_CMD_OPCODE_HW2SW_EQ = 0x014,
MLXSW_CMD_OPCODE_QUERY_EQ = 0x015,
MLXSW_CMD_OPCODE_QUERY_RESOURCES = 0x101,
};
static inline const char *mlxsw_cmd_opcode_str(u16 opcode)
{
switch (opcode) {
case MLXSW_CMD_OPCODE_QUERY_FW:
return "QUERY_FW";
case MLXSW_CMD_OPCODE_QUERY_BOARDINFO:
return "QUERY_BOARDINFO";
case MLXSW_CMD_OPCODE_QUERY_AQ_CAP:
return "QUERY_AQ_CAP";
case MLXSW_CMD_OPCODE_MAP