[golan] Add Connect-IB, ConnectX-4 and ConnectX-4 Lx (Infiniband) support
[ipxe.git] / src / drivers / infiniband / mlx_utils / mlx_lib / mlx_ocbb / mlx_ocbb.c
1 /*
2 * Copyright (C) 2015 Mellanox Technologies Ltd.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301, USA.
18 */
19
20 FILE_LICENCE ( GPL2_OR_LATER );
21
22 #include "mlx_ocbb.h"
23 #include "mlx_icmd.h"
24 #include "mlx_bail.h"
25
26 mlx_status
27 mlx_ocbb_init (
28 IN mlx_utils *utils,
29 IN mlx_uint64 address
30 )
31 {
32 mlx_status status = MLX_SUCCESS;
33 struct mlx_ocbb_init ocbb_init;
34 ocbb_init.address_hi = (mlx_uint32)(address >> 32);
35 ocbb_init.address_lo = (mlx_uint32)address;
36
37 if (utils == NULL) {
38 status = MLX_INVALID_PARAMETER;
39 goto bad_param;
40 }
41
42 status = mlx_icmd_send_command(
43 utils,
44 OCBB_INIT,
45 &ocbb_init,
46 sizeof(ocbb_init),
47 0
48 );
49 MLX_CHECK_STATUS(utils, status, icmd_err, "mlx_icmd_send_command failed");
50 icmd_err:
51 bad_param:
52 return status;
53 }
54
55 mlx_status
56 mlx_ocbb_query_header_status (
57 IN mlx_utils *utils,
58 OUT mlx_uint8 *ocbb_status
59 )
60 {
61 mlx_status status = MLX_SUCCESS;
62 struct mlx_ocbb_query_status ocbb_query_status;
63
64 if (utils == NULL) {
65 status = MLX_INVALID_PARAMETER;
66 goto bad_param;
67 }
68
69 status = mlx_icmd_send_command(
70 utils,
71 OCBB_QUERY_HEADER_STATUS,
72 &ocbb_query_status,
73 0,
74 sizeof(ocbb_query_status)
75 );
76 MLX_CHECK_STATUS(utils, status, icmd_err, "mlx_icmd_send_command failed");
77 *ocbb_status = ocbb_query_status.status;
78 icmd_err:
79 bad_param:
80 return status;
81 }
82
83 mlx_status
84 mlx_ocbb_query_etoc_status (
85 IN mlx_utils *utils,
86 OUT mlx_uint8 *ocbb_status
87 )
88 {
89 mlx_status status = MLX_SUCCESS;
90 struct mlx_ocbb_query_status ocbb_query_status;
91
92 if (utils == NULL) {
93 status = MLX_INVALID_PARAMETER;
94 goto bad_param;
95 }
96
97 status = mlx_icmd_send_command(
98 utils,
99 OCBB_QUERY_ETOC_STATUS,
100 &ocbb_query_status,
101 0,
102 sizeof(ocbb_query_status)
103 );
104 MLX_CHECK_STATUS(utils, status, icmd_err, "mlx_icmd_send_command failed");
105 *ocbb_status = ocbb_query_status.status;
106 icmd_err:
107 bad_param:
108 return status;
109 }
110
111 mlx_status
112 mlx_ocbb_set_event (
113 IN mlx_utils *utils,
114 IN mlx_uint64 event_data,
115 IN mlx_uint8 event_number,
116 IN mlx_uint8 event_length,
117 IN mlx_uint8 data_length,
118 IN mlx_uint8 data_start_offset
119 )
120 {
121 mlx_status status = MLX_SUCCESS;
122 struct mlx_ocbb_set_event ocbb_event;
123
124 if (utils == NULL) {
125 status = MLX_INVALID_PARAMETER;
126 goto bad_param;
127 }
128
129 ocbb_event.data_length = data_length;
130 ocbb_event.data_start_offset = data_start_offset;
131 ocbb_event.event_number = event_number;
132 ocbb_event.event_data = event_data;
133 ocbb_event.event_length = event_length;
134 status = mlx_icmd_send_command(
135 utils,
136 OCBB_QUERY_SET_EVENT,
137 &ocbb_event,
138 sizeof(ocbb_event),
139 0
140 );
141 MLX_CHECK_STATUS(utils, status, icmd_err, "mlx_icmd_send_command failed");
142 icmd_err:
143 bad_param:
144 return status;
145 }