/*
* drivers/net/ethernet/mellanox/mlxsw/cmd.h
* Copyright (c) 2015 Mellanox Technologies. All rights reserved.
* Copyright (c) 2015 Jiri Pirko <jiri@mellanox.com>
* Copyright (c) 2015 Ido Schimmel <idosch@mellanox.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the names of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* Alternatively, this software may be distributed under the terms of the
* GNU General Public License ("GPL") version 2 as published by the Free
* Software Foundation.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#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,
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,
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, 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,
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,