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_link_speed.c 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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_lib/mlx_link_speed/mlx_link_speed.h"
  21. #include "../../include/public/mlx_memory.h"
  22. #include "../../include/public/mlx_bail.h"
  23. mlx_status
  24. mlx_set_link_speed(
  25. IN mlx_utils *utils,
  26. IN mlx_uint8 port_num,
  27. IN LINK_SPEED_TYPE type,
  28. IN LINK_SPEED speed
  29. )
  30. {
  31. mlx_status status = MLX_SUCCESS;
  32. struct mlx_link_speed link_speed;
  33. mlx_uint32 reg_status;
  34. if (utils == NULL) {
  35. status = MLX_INVALID_PARAMETER;
  36. goto bad_param;
  37. }
  38. mlx_memory_set(utils, &link_speed, 0, sizeof(link_speed));
  39. link_speed.loacl_port = port_num;
  40. link_speed.proto_mask = 1 << type;
  41. status = mlx_reg_access(utils, REG_ID_PTYS, REG_ACCESS_READ, &link_speed,
  42. sizeof(link_speed), &reg_status);
  43. MLX_CHECK_STATUS(utils, status, reg_err, "mlx_reg_access failed ");
  44. if (reg_status != 0) {
  45. MLX_DEBUG_ERROR(utils,"mlx_reg_access failed with status = %d\n", reg_status);
  46. status = MLX_FAILED;
  47. goto reg_err;
  48. }
  49. switch (speed) {
  50. case LINK_SPEED_1GB:
  51. link_speed.eth_proto_admin = link_speed.eth_proto_capability & LINK_SPEED_1GB_MASK;
  52. break;
  53. case LINK_SPEED_10GB:
  54. link_speed.eth_proto_admin = link_speed.eth_proto_capability & LINK_SPEED_10GB_MASK;
  55. break;
  56. case LINK_SPEED_40GB:
  57. link_speed.eth_proto_admin = link_speed.eth_proto_capability & LINK_SPEED_40GB_MASK;
  58. break;
  59. case LINK_SPEED_100GB:
  60. link_speed.eth_proto_admin = link_speed.eth_proto_capability & LINK_SPEED_100GB_MASK;
  61. break;
  62. case LINK_SPEED_SDR:
  63. link_speed.ib_proto_admin = link_speed.ib_proto_capability & LINK_SPEED_SDR_MASK;
  64. break;
  65. case LINK_SPEED_DEFAULT:
  66. if (type == LINK_SPEED_ETH) {
  67. link_speed.eth_proto_admin = link_speed.eth_proto_capability;
  68. } else {
  69. link_speed.ib_proto_admin = link_speed.ib_proto_capability;
  70. }
  71. break;
  72. }
  73. status = mlx_reg_access(utils, REG_ID_PTYS, REG_ACCESS_WRITE, &link_speed,
  74. sizeof(link_speed), &reg_status);
  75. MLX_CHECK_STATUS(utils, status, reg_err, "mlx_reg_access failed ");
  76. if (reg_status != 0) {
  77. MLX_DEBUG_ERROR(utils,"mlx_reg_access failed with status = %d\n", reg_status);
  78. status = MLX_FAILED;
  79. goto reg_err;
  80. }
  81. reg_err:
  82. bad_param:
  83. return status;
  84. }
  85. mlx_status
  86. mlx_get_max_speed(
  87. IN mlx_utils *utils,
  88. IN mlx_uint8 port_num,
  89. IN LINK_SPEED_TYPE type,
  90. OUT mlx_uint64 *speed
  91. )
  92. {
  93. mlx_status status = MLX_SUCCESS;
  94. struct mlx_link_speed link_speed;
  95. mlx_uint32 reg_status;
  96. mlx_uint64 speed_giga = 0;
  97. mlx_uint8 lanes_number = 1;
  98. *speed = 0;
  99. if (utils == NULL) {
  100. status = MLX_INVALID_PARAMETER;
  101. goto bad_param;
  102. }
  103. mlx_memory_set(utils, &link_speed, 0, sizeof(link_speed));
  104. link_speed.loacl_port = port_num;
  105. link_speed.proto_mask = 1 << type;
  106. status = mlx_reg_access(utils, REG_ID_PTYS, REG_ACCESS_READ, &link_speed,
  107. sizeof(link_speed), &reg_status);
  108. MLX_CHECK_STATUS(utils, status, reg_err, "mlx_reg_access failed ");
  109. if (reg_status != 0) {
  110. MLX_DEBUG_ERROR(utils,"mlx_reg_access failed with status = %d\n", reg_status);
  111. status = MLX_FAILED;
  112. goto reg_err;
  113. }
  114. if ( type == LINK_SPEED_ETH ) {
  115. if ( link_speed.eth_proto_capability & LINK_SPEED_100GB_MASK ) {
  116. speed_giga = 100;
  117. } else if ( link_speed.eth_proto_capability & LINK_SPEED_56GB_MASK ) {
  118. speed_giga = 56;
  119. } else if ( link_speed.eth_proto_capability & LINK_SPEED_50GB_MASK ) {
  120. speed_giga = 50;
  121. } else if ( link_speed.eth_proto_capability & LINK_SPEED_40GB_MASK ) {
  122. speed_giga = 40;
  123. } else if (link_speed.eth_proto_capability & LINK_SPEED_25GB_MASK) {
  124. speed_giga = 25;
  125. } else if ( link_speed.eth_proto_capability & LINK_SPEED_20GB_MASK ) {
  126. speed_giga = 20;
  127. } else if ( link_speed.eth_proto_capability & LINK_SPEED_10GB_MASK) {
  128. speed_giga = 10;
  129. } else if ( link_speed.eth_proto_capability & LINK_SPEED_1GB_MASK ) {
  130. speed_giga = 1;
  131. }
  132. } else {
  133. if ( link_speed.ib_proto_capability & LINK_SPEED_EDR_MASK ) {
  134. speed_giga = 25;
  135. } else if ( link_speed.ib_proto_capability & LINK_SPEED_EDR20_MASK ) {
  136. speed_giga = 20;
  137. } else if ( link_speed.ib_proto_capability & LINK_SPEED_FDR_MASK ) {
  138. speed_giga = 14;
  139. } else if ( link_speed.ib_proto_capability & LINK_SPEED_QDR_MASK ) {
  140. speed_giga = 10;
  141. } else if ( link_speed.ib_proto_capability & LINK_SPEED_DDR_MASK ) {
  142. speed_giga = 5;
  143. } else if ( link_speed.ib_proto_capability & LINK_SPEED_SDR_MASK ) {
  144. speed_giga = 2.5;
  145. }
  146. if ( link_speed.ib_link_width_capability & LINK_SPEED_WITDH_12_MASK ) {
  147. lanes_number = 12;
  148. } else if ( link_speed.ib_link_width_capability & LINK_SPEED_WITDH_8_MASK ) {
  149. lanes_number = 8;
  150. } else if (link_speed.ib_link_width_capability & LINK_SPEED_WITDH_4_MASK ) {
  151. lanes_number = 4;
  152. } else if (link_speed.ib_link_width_capability & LINK_SPEED_WITDH_2_MASK ) {
  153. lanes_number = 2;
  154. } else if (link_speed.ib_link_width_capability & LINK_SPEED_WITDH_1_MASK ) {
  155. lanes_number = 1;
  156. }
  157. speed_giga = speed_giga * lanes_number;
  158. }
  159. // Return data in bits
  160. *speed = speed_giga * GIGA_TO_BIT;
  161. reg_err:
  162. bad_param:
  163. return status;
  164. }