1  /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
2  /*
3   * Copyright (c) 2014 Intel Corporation.  All rights reserved.
4   */
5  
6  #ifndef OPA_SMI_H
7  #define OPA_SMI_H
8  
9  #include <rdma/ib_mad.h>
10  #include <rdma/ib_smi.h>
11  
12  #define OPA_SMP_LID_DATA_SIZE			2016
13  #define OPA_SMP_DR_DATA_SIZE			1872
14  #define OPA_SMP_MAX_PATH_HOPS			64
15  
16  #define OPA_MAX_VLS				32
17  #define OPA_MAX_SLS				32
18  #define OPA_MAX_SCS				32
19  
20  #define OPA_LID_PERMISSIVE			cpu_to_be32(0xFFFFFFFF)
21  
22  struct opa_smp {
23  	u8	base_version;
24  	u8	mgmt_class;
25  	u8	class_version;
26  	u8	method;
27  	__be16	status;
28  	u8	hop_ptr;
29  	u8	hop_cnt;
30  	__be64	tid;
31  	__be16	attr_id;
32  	__be16	resv;
33  	__be32	attr_mod;
34  	__be64	mkey;
35  	union {
36  		struct {
37  			uint8_t data[OPA_SMP_LID_DATA_SIZE];
38  		} lid;
39  		struct {
40  			__be32	dr_slid;
41  			__be32	dr_dlid;
42  			u8	initial_path[OPA_SMP_MAX_PATH_HOPS];
43  			u8	return_path[OPA_SMP_MAX_PATH_HOPS];
44  			u8	reserved[8];
45  			u8	data[OPA_SMP_DR_DATA_SIZE];
46  		} dr;
47  	} route;
48  } __packed;
49  
50  
51  /* Subnet management attributes */
52  /* ... */
53  #define OPA_ATTRIB_ID_NODE_DESCRIPTION		cpu_to_be16(0x0010)
54  #define OPA_ATTRIB_ID_NODE_INFO			cpu_to_be16(0x0011)
55  #define OPA_ATTRIB_ID_PORT_INFO			cpu_to_be16(0x0015)
56  #define OPA_ATTRIB_ID_PARTITION_TABLE		cpu_to_be16(0x0016)
57  #define OPA_ATTRIB_ID_SL_TO_SC_MAP		cpu_to_be16(0x0017)
58  #define OPA_ATTRIB_ID_VL_ARBITRATION		cpu_to_be16(0x0018)
59  #define OPA_ATTRIB_ID_SM_INFO			cpu_to_be16(0x0020)
60  #define OPA_ATTRIB_ID_CABLE_INFO		cpu_to_be16(0x0032)
61  #define OPA_ATTRIB_ID_AGGREGATE			cpu_to_be16(0x0080)
62  #define OPA_ATTRIB_ID_SC_TO_SL_MAP		cpu_to_be16(0x0082)
63  #define OPA_ATTRIB_ID_SC_TO_VLR_MAP		cpu_to_be16(0x0083)
64  #define OPA_ATTRIB_ID_SC_TO_VLT_MAP		cpu_to_be16(0x0084)
65  #define OPA_ATTRIB_ID_SC_TO_VLNT_MAP		cpu_to_be16(0x0085)
66  /* ... */
67  #define OPA_ATTRIB_ID_PORT_STATE_INFO		cpu_to_be16(0x0087)
68  /* ... */
69  #define OPA_ATTRIB_ID_BUFFER_CONTROL_TABLE	cpu_to_be16(0x008A)
70  /* ... */
71  
72  struct opa_node_description {
73  	u8 data[64];
74  } __packed;
75  
76  struct opa_node_info {
77  	u8      base_version;
78  	u8      class_version;
79  	u8      node_type;
80  	u8      num_ports;
81  	__be32  reserved;
82  	__be64  system_image_guid;
83  	__be64  node_guid;
84  	__be64  port_guid;
85  	__be16  partition_cap;
86  	__be16  device_id;
87  	__be32  revision;
88  	u8      local_port_num;
89  	u8      vendor_id[3];   /* network byte order */
90  } __packed;
91  
92  #define OPA_PARTITION_TABLE_BLK_SIZE 32
93  
94  static inline u8
opa_get_smp_direction(struct opa_smp * smp)95  opa_get_smp_direction(struct opa_smp *smp)
96  {
97  	return ib_get_smp_direction((struct ib_smp *)smp);
98  }
99  
opa_get_smp_data(struct opa_smp * smp)100  static inline u8 *opa_get_smp_data(struct opa_smp *smp)
101  {
102  	if (smp->mgmt_class == IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE)
103  		return smp->route.dr.data;
104  
105  	return smp->route.lid.data;
106  }
107  
opa_get_smp_data_size(struct opa_smp * smp)108  static inline size_t opa_get_smp_data_size(struct opa_smp *smp)
109  {
110  	if (smp->mgmt_class == IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE)
111  		return sizeof(smp->route.dr.data);
112  
113  	return sizeof(smp->route.lid.data);
114  }
115  
opa_get_smp_header_size(struct opa_smp * smp)116  static inline size_t opa_get_smp_header_size(struct opa_smp *smp)
117  {
118  	if (smp->mgmt_class == IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE)
119  		return sizeof(*smp) - sizeof(smp->route.dr.data);
120  
121  	return sizeof(*smp) - sizeof(smp->route.lid.data);
122  }
123  
124  #endif /* OPA_SMI_H */
125