18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */
28c2ecf20Sopenharmony_ci/* Copyright (c) 2015-2018 Mellanox Technologies. All rights reserved */
38c2ecf20Sopenharmony_ci
48c2ecf20Sopenharmony_ci#ifndef _MLXSW_EMAD_H
58c2ecf20Sopenharmony_ci#define _MLXSW_EMAD_H
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci#define MLXSW_EMAD_MAX_FRAME_LEN 1518	/* Length in u8 */
88c2ecf20Sopenharmony_ci#define MLXSW_EMAD_MAX_RETRY 5
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci/* EMAD Ethernet header */
118c2ecf20Sopenharmony_ci#define MLXSW_EMAD_ETH_HDR_LEN 0x10	/* Length in u8 */
128c2ecf20Sopenharmony_ci#define MLXSW_EMAD_EH_DMAC "\x01\x02\xc9\x00\x00\x01"
138c2ecf20Sopenharmony_ci#define MLXSW_EMAD_EH_SMAC "\x00\x02\xc9\x01\x02\x03"
148c2ecf20Sopenharmony_ci#define MLXSW_EMAD_EH_ETHERTYPE 0x8932
158c2ecf20Sopenharmony_ci#define MLXSW_EMAD_EH_MLX_PROTO 0
168c2ecf20Sopenharmony_ci#define MLXSW_EMAD_EH_PROTO_VERSION 0
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci/* EMAD TLV Types */
198c2ecf20Sopenharmony_cienum {
208c2ecf20Sopenharmony_ci	MLXSW_EMAD_TLV_TYPE_END,
218c2ecf20Sopenharmony_ci	MLXSW_EMAD_TLV_TYPE_OP,
228c2ecf20Sopenharmony_ci	MLXSW_EMAD_TLV_TYPE_STRING,
238c2ecf20Sopenharmony_ci	MLXSW_EMAD_TLV_TYPE_REG,
248c2ecf20Sopenharmony_ci};
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci/* OP TLV */
278c2ecf20Sopenharmony_ci#define MLXSW_EMAD_OP_TLV_LEN 4		/* Length in u32 */
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_cienum {
308c2ecf20Sopenharmony_ci	MLXSW_EMAD_OP_TLV_CLASS_REG_ACCESS = 1,
318c2ecf20Sopenharmony_ci	MLXSW_EMAD_OP_TLV_CLASS_IPC = 2,
328c2ecf20Sopenharmony_ci};
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_cienum mlxsw_emad_op_tlv_status {
358c2ecf20Sopenharmony_ci	MLXSW_EMAD_OP_TLV_STATUS_SUCCESS,
368c2ecf20Sopenharmony_ci	MLXSW_EMAD_OP_TLV_STATUS_BUSY,
378c2ecf20Sopenharmony_ci	MLXSW_EMAD_OP_TLV_STATUS_VERSION_NOT_SUPPORTED,
388c2ecf20Sopenharmony_ci	MLXSW_EMAD_OP_TLV_STATUS_UNKNOWN_TLV,
398c2ecf20Sopenharmony_ci	MLXSW_EMAD_OP_TLV_STATUS_REGISTER_NOT_SUPPORTED,
408c2ecf20Sopenharmony_ci	MLXSW_EMAD_OP_TLV_STATUS_CLASS_NOT_SUPPORTED,
418c2ecf20Sopenharmony_ci	MLXSW_EMAD_OP_TLV_STATUS_METHOD_NOT_SUPPORTED,
428c2ecf20Sopenharmony_ci	MLXSW_EMAD_OP_TLV_STATUS_BAD_PARAMETER,
438c2ecf20Sopenharmony_ci	MLXSW_EMAD_OP_TLV_STATUS_RESOURCE_NOT_AVAILABLE,
448c2ecf20Sopenharmony_ci	MLXSW_EMAD_OP_TLV_STATUS_MESSAGE_RECEIPT_ACK,
458c2ecf20Sopenharmony_ci	MLXSW_EMAD_OP_TLV_STATUS_INTERNAL_ERROR = 0x70,
468c2ecf20Sopenharmony_ci};
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_cistatic inline char *mlxsw_emad_op_tlv_status_str(u8 status)
498c2ecf20Sopenharmony_ci{
508c2ecf20Sopenharmony_ci	switch (status) {
518c2ecf20Sopenharmony_ci	case MLXSW_EMAD_OP_TLV_STATUS_SUCCESS:
528c2ecf20Sopenharmony_ci		return "operation performed";
538c2ecf20Sopenharmony_ci	case MLXSW_EMAD_OP_TLV_STATUS_BUSY:
548c2ecf20Sopenharmony_ci		return "device is busy";
558c2ecf20Sopenharmony_ci	case MLXSW_EMAD_OP_TLV_STATUS_VERSION_NOT_SUPPORTED:
568c2ecf20Sopenharmony_ci		return "version not supported";
578c2ecf20Sopenharmony_ci	case MLXSW_EMAD_OP_TLV_STATUS_UNKNOWN_TLV:
588c2ecf20Sopenharmony_ci		return "unknown TLV";
598c2ecf20Sopenharmony_ci	case MLXSW_EMAD_OP_TLV_STATUS_REGISTER_NOT_SUPPORTED:
608c2ecf20Sopenharmony_ci		return "register not supported";
618c2ecf20Sopenharmony_ci	case MLXSW_EMAD_OP_TLV_STATUS_CLASS_NOT_SUPPORTED:
628c2ecf20Sopenharmony_ci		return "class not supported";
638c2ecf20Sopenharmony_ci	case MLXSW_EMAD_OP_TLV_STATUS_METHOD_NOT_SUPPORTED:
648c2ecf20Sopenharmony_ci		return "method not supported";
658c2ecf20Sopenharmony_ci	case MLXSW_EMAD_OP_TLV_STATUS_BAD_PARAMETER:
668c2ecf20Sopenharmony_ci		return "bad parameter";
678c2ecf20Sopenharmony_ci	case MLXSW_EMAD_OP_TLV_STATUS_RESOURCE_NOT_AVAILABLE:
688c2ecf20Sopenharmony_ci		return "resource not available";
698c2ecf20Sopenharmony_ci	case MLXSW_EMAD_OP_TLV_STATUS_MESSAGE_RECEIPT_ACK:
708c2ecf20Sopenharmony_ci		return "acknowledged. retransmit";
718c2ecf20Sopenharmony_ci	case MLXSW_EMAD_OP_TLV_STATUS_INTERNAL_ERROR:
728c2ecf20Sopenharmony_ci		return "internal error";
738c2ecf20Sopenharmony_ci	default:
748c2ecf20Sopenharmony_ci		return "*UNKNOWN*";
758c2ecf20Sopenharmony_ci	}
768c2ecf20Sopenharmony_ci}
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_cienum {
798c2ecf20Sopenharmony_ci	MLXSW_EMAD_OP_TLV_REQUEST,
808c2ecf20Sopenharmony_ci	MLXSW_EMAD_OP_TLV_RESPONSE
818c2ecf20Sopenharmony_ci};
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_cienum {
848c2ecf20Sopenharmony_ci	MLXSW_EMAD_OP_TLV_METHOD_QUERY = 1,
858c2ecf20Sopenharmony_ci	MLXSW_EMAD_OP_TLV_METHOD_WRITE = 2,
868c2ecf20Sopenharmony_ci	MLXSW_EMAD_OP_TLV_METHOD_SEND = 3,
878c2ecf20Sopenharmony_ci	MLXSW_EMAD_OP_TLV_METHOD_EVENT = 5,
888c2ecf20Sopenharmony_ci};
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ci/* STRING TLV */
918c2ecf20Sopenharmony_ci#define MLXSW_EMAD_STRING_TLV_LEN 33	/* Length in u32 */
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ci/* END TLV */
948c2ecf20Sopenharmony_ci#define MLXSW_EMAD_END_TLV_LEN 1	/* Length in u32 */
958c2ecf20Sopenharmony_ci
968c2ecf20Sopenharmony_ci#endif
97