iPXE
mlx_mtu.c
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2015 Mellanox Technologies Ltd.
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License as
00006  * published by the Free Software Foundation; either version 2 of the
00007  * License, or any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017  * 02110-1301, USA.
00018  */
00019 
00020 FILE_LICENCE ( GPL2_OR_LATER );
00021 
00022 #include "mlx_mtu.h"
00023 #include "../../include/public/mlx_memory.h"
00024 #include "../../include/public/mlx_bail.h"
00025 
00026 mlx_status
00027 mlx_get_max_mtu(
00028                 IN mlx_utils    *utils,
00029                 IN mlx_uint8    port_num,
00030                 OUT mlx_uint32  *max_mtu
00031                 )
00032 {
00033         mlx_status status = MLX_SUCCESS;
00034         struct mlx_mtu mtu;
00035         mlx_uint32 reg_status;
00036         *max_mtu = 0;
00037 
00038         if (utils == NULL) {
00039                 status = MLX_INVALID_PARAMETER;
00040                 goto bad_param;
00041         }
00042 
00043         mlx_memory_set(utils, &mtu, 0, sizeof(mtu));
00044 
00045         mtu.local_port = port_num;
00046 
00047         status = mlx_reg_access(utils, REG_ID_PMTU, REG_ACCESS_READ, &mtu,
00048                         sizeof(mtu), &reg_status);
00049         MLX_CHECK_STATUS(utils, status, reg_err, "mlx_reg_access failed ");
00050         if (reg_status != 0) {
00051                 MLX_DEBUG_ERROR(utils,"mlx_reg_access failed with status = %d\n", reg_status);
00052                 status = MLX_FAILED;
00053                 goto reg_err;
00054         }
00055         // Return data in bits
00056         *max_mtu = mtu.max_mtu * BYTE_TO_BIT;
00057 reg_err:
00058 bad_param:
00059         return status;
00060 }
00061 
00062 mlx_status
00063 mlx_set_admin_mtu(
00064                 IN mlx_utils    *utils,
00065                 IN mlx_uint8    port_num,
00066                 IN mlx_uint32   admin_mtu
00067                 )
00068 {
00069         mlx_status status = MLX_SUCCESS;
00070         struct mlx_mtu mtu;
00071         mlx_uint32 reg_status;
00072 
00073         if (utils == NULL) {
00074                 status = MLX_INVALID_PARAMETER;
00075                 goto bad_param;
00076         }
00077 
00078         mlx_memory_set(utils, &mtu, 0, sizeof(mtu));
00079 
00080         mtu.local_port = port_num;
00081         mtu.admin_mtu = admin_mtu;
00082 
00083         status = mlx_reg_access(utils, REG_ID_PMTU, REG_ACCESS_WRITE, &mtu,
00084                         sizeof(mtu), &reg_status);
00085         MLX_CHECK_STATUS(utils, status, reg_err, "mlx_reg_access failed ");
00086         if (reg_status != 0) {
00087                 MLX_DEBUG_ERROR(utils,"mlx_reg_access failed with status = %d\n", reg_status);
00088                 status = MLX_FAILED;
00089                 goto reg_err;
00090         }
00091 reg_err:
00092 bad_param:
00093         return status;
00094 }