You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mlx_mtu.c 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. FILE_LICENCE ( GPL2_OR_LATER );
  20. #include "mlx_mtu.h"
  21. #include "../../include/public/mlx_memory.h"
  22. #include "../../include/public/mlx_bail.h"
  23. mlx_status
  24. mlx_get_max_mtu(
  25. IN mlx_utils *utils,
  26. IN mlx_uint8 port_num,
  27. OUT mlx_uint32 *max_mtu
  28. )
  29. {
  30. mlx_status status = MLX_SUCCESS;
  31. struct mlx_mtu mtu;
  32. mlx_uint32 reg_status;
  33. *max_mtu = 0;
  34. if (utils == NULL) {
  35. status = MLX_INVALID_PARAMETER;
  36. goto bad_param;
  37. }
  38. mlx_memory_set(utils, &mtu, 0, sizeof(mtu));
  39. mtu.local_port = port_num;
  40. status = mlx_reg_access(utils, REG_ID_PMTU, REG_ACCESS_READ, &mtu,
  41. sizeof(mtu), &reg_status);
  42. MLX_CHECK_STATUS(utils, status, reg_err, "mlx_reg_access failed ");
  43. if (reg_status != 0) {
  44. MLX_DEBUG_ERROR(utils,"mlx_reg_access failed with status = %d\n", reg_status);
  45. status = MLX_FAILED;
  46. goto reg_err;
  47. }
  48. // Return data in bits
  49. *max_mtu = mtu.max_mtu * BYTE_TO_BIT;
  50. reg_err:
  51. bad_param:
  52. return status;
  53. }
  54. mlx_status
  55. mlx_set_admin_mtu(
  56. IN mlx_utils *utils,
  57. IN mlx_uint8 port_num,
  58. IN mlx_uint32 admin_mtu
  59. )
  60. {
  61. mlx_status status = MLX_SUCCESS;
  62. struct mlx_mtu mtu;
  63. mlx_uint32 reg_status;
  64. if (utils == NULL) {
  65. status = MLX_INVALID_PARAMETER;
  66. goto bad_param;
  67. }
  68. mlx_memory_set(utils, &mtu, 0, sizeof(mtu));
  69. mtu.local_port = port_num;
  70. mtu.admin_mtu = admin_mtu;
  71. status = mlx_reg_access(utils, REG_ID_PMTU, REG_ACCESS_WRITE, &mtu,
  72. sizeof(mtu), &reg_status);
  73. MLX_CHECK_STATUS(utils, status, reg_err, "mlx_reg_access failed ");
  74. if (reg_status != 0) {
  75. MLX_DEBUG_ERROR(utils,"mlx_reg_access failed with status = %d\n", reg_status);
  76. status = MLX_FAILED;
  77. goto reg_err;
  78. }
  79. reg_err:
  80. bad_param:
  81. return status;
  82. }