[golan] Add Connect-IB, ConnectX-4 and ConnectX-4 Lx (Infiniband) support
[ipxe.git] / src / drivers / infiniband / mlx_utils / mlx_lib / mlx_mtu / mlx_mtu.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_mtu.h"
23 #include "mlx_memory.h"
24 #include "mlx_bail.h"
25
26 mlx_status
27 mlx_get_max_mtu(
28 IN mlx_utils *utils,
29 IN mlx_uint8 port_num,
30 OUT mlx_uint32 *max_mtu
31 )
32 {
33 mlx_status status = MLX_SUCCESS;
34 struct mlx_mtu mtu;
35 mlx_uint32 reg_status;
36 *max_mtu = 0;
37
38 if (utils == NULL) {
39 status = MLX_INVALID_PARAMETER;
40 goto bad_param;
41 }
42
43 mlx_memory_set(utils, &mtu, 0, sizeof(mtu));
44
45 mtu.local_port = port_num;
46
47 status = mlx_reg_access(utils, REG_ID_PMTU, REG_ACCESS_READ, &mtu,
48 sizeof(mtu), &reg_status);
49 MLX_CHECK_STATUS(utils, status, reg_err, "mlx_reg_access failed ");
50 if (reg_status != 0) {
51 MLX_DEBUG_ERROR(utils,"mlx_reg_access failed with status = %d\n", reg_status);
52 status = MLX_FAILED;
53 goto reg_err;
54 }
55 // Return data in bits
56 *max_mtu = mtu.max_mtu * BYTE_TO_BIT;
57 reg_err:
58 bad_param:
59 return status;
60 }