xref: /linux/drivers/net/ethernet/mellanox/mlxsw/emad.h (revision f9bff0e31881d03badf191d3b0005839391f5f2b)
1 /* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */
2 /* Copyright (c) 2015-2018 Mellanox Technologies. All rights reserved */
3 
4 #ifndef _MLXSW_EMAD_H
5 #define _MLXSW_EMAD_H
6 
7 #define MLXSW_EMAD_MAX_FRAME_LEN 1518	/* Length in u8 */
8 #define MLXSW_EMAD_MAX_RETRY 5
9 
10 /* EMAD Ethernet header */
11 #define MLXSW_EMAD_ETH_HDR_LEN 0x10	/* Length in u8 */
12 #define MLXSW_EMAD_EH_DMAC "\x01\x02\xc9\x00\x00\x01"
13 #define MLXSW_EMAD_EH_SMAC "\x00\x02\xc9\x01\x02\x03"
14 #define MLXSW_EMAD_EH_ETHERTYPE 0x8932
15 #define MLXSW_EMAD_EH_MLX_PROTO 0
16 #define MLXSW_EMAD_EH_PROTO_VERSION 0
17 
18 /* EMAD TLV Types */
19 enum {
20 	MLXSW_EMAD_TLV_TYPE_END,
21 	MLXSW_EMAD_TLV_TYPE_OP,
22 	MLXSW_EMAD_TLV_TYPE_STRING,
23 	MLXSW_EMAD_TLV_TYPE_REG,
24 	MLXSW_EMAD_TLV_TYPE_LATENCY,
25 };
26 
27 /* OP TLV */
28 #define MLXSW_EMAD_OP_TLV_LEN 4		/* Length in u32 */
29 
30 enum {
31 	MLXSW_EMAD_OP_TLV_CLASS_REG_ACCESS = 1,
32 	MLXSW_EMAD_OP_TLV_CLASS_IPC = 2,
33 };
34 
35 enum mlxsw_emad_op_tlv_status {
36 	MLXSW_EMAD_OP_TLV_STATUS_SUCCESS,
37 	MLXSW_EMAD_OP_TLV_STATUS_BUSY,
38 	MLXSW_EMAD_OP_TLV_STATUS_VERSION_NOT_SUPPORTED,
39 	MLXSW_EMAD_OP_TLV_STATUS_UNKNOWN_TLV,
40 	MLXSW_EMAD_OP_TLV_STATUS_REGISTER_NOT_SUPPORTED,
41 	MLXSW_EMAD_OP_TLV_STATUS_CLASS_NOT_SUPPORTED,
42 	MLXSW_EMAD_OP_TLV_STATUS_METHOD_NOT_SUPPORTED,
43 	MLXSW_EMAD_OP_TLV_STATUS_BAD_PARAMETER,
44 	MLXSW_EMAD_OP_TLV_STATUS_RESOURCE_NOT_AVAILABLE,
45 	MLXSW_EMAD_OP_TLV_STATUS_MESSAGE_RECEIPT_ACK,
46 	MLXSW_EMAD_OP_TLV_STATUS_INTERNAL_ERROR = 0x70,
47 };
48 
49 static inline char *mlxsw_emad_op_tlv_status_str(u8 status)
50 {
51 	switch (status) {
52 	case MLXSW_EMAD_OP_TLV_STATUS_SUCCESS:
53 		return "operation performed";
54 	case MLXSW_EMAD_OP_TLV_STATUS_BUSY:
55 		return "device is busy";
56 	case MLXSW_EMAD_OP_TLV_STATUS_VERSION_NOT_SUPPORTED:
57 		return "version not supported";
58 	case MLXSW_EMAD_OP_TLV_STATUS_UNKNOWN_TLV:
59 		return "unknown TLV";
60 	case MLXSW_EMAD_OP_TLV_STATUS_REGISTER_NOT_SUPPORTED:
61 		return "register not supported";
62 	case MLXSW_EMAD_OP_TLV_STATUS_CLASS_NOT_SUPPORTED:
63 		return "class not supported";
64 	case MLXSW_EMAD_OP_TLV_STATUS_METHOD_NOT_SUPPORTED:
65 		return "method not supported";
66 	case MLXSW_EMAD_OP_TLV_STATUS_BAD_PARAMETER:
67 		return "bad parameter";
68 	case MLXSW_EMAD_OP_TLV_STATUS_RESOURCE_NOT_AVAILABLE:
69 		return "resource not available";
70 	case MLXSW_EMAD_OP_TLV_STATUS_MESSAGE_RECEIPT_ACK:
71 		return "acknowledged. retransmit";
72 	case MLXSW_EMAD_OP_TLV_STATUS_INTERNAL_ERROR:
73 		return "internal error";
74 	default:
75 		return "*UNKNOWN*";
76 	}
77 }
78 
79 enum {
80 	MLXSW_EMAD_OP_TLV_REQUEST,
81 	MLXSW_EMAD_OP_TLV_RESPONSE
82 };
83 
84 enum {
85 	MLXSW_EMAD_OP_TLV_METHOD_QUERY = 1,
86 	MLXSW_EMAD_OP_TLV_METHOD_WRITE = 2,
87 	MLXSW_EMAD_OP_TLV_METHOD_SEND = 3,
88 	MLXSW_EMAD_OP_TLV_METHOD_EVENT = 5,
89 };
90 
91 /* STRING TLV */
92 #define MLXSW_EMAD_STRING_TLV_LEN 33	/* Length in u32 */
93 
94 /* LATENCY TLV */
95 #define MLXSW_EMAD_LATENCY_TLV_LEN 7	/* Length in u32 */
96 
97 /* END TLV */
98 #define MLXSW_EMAD_END_TLV_LEN 1	/* Length in u32 */
99 
100 #endif
101