devlink_linecard.sh 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. #!/bin/bash
  2. # SPDX-License-Identifier: GPL-2.0
  3. #
  4. # In addition to the common variables, user might use:
  5. # LC_SLOT - If not set, all probed line cards are going to be tested,
  6. # with an exception of the "activation_16x100G_test".
  7. # It set, only the selected line card is going to be used
  8. # for tests, including "activation_16x100G_test".
  9. lib_dir=$(dirname $0)/../../../net/forwarding
  10. ALL_TESTS="
  11. unprovision_test
  12. provision_test
  13. activation_16x100G_test
  14. "
  15. NUM_NETIFS=0
  16. source $lib_dir/lib.sh
  17. source $lib_dir/devlink_lib.sh
  18. until_lc_state_is()
  19. {
  20. local state=$1; shift
  21. local current=$("$@")
  22. echo "$current"
  23. [ "$current" == "$state" ]
  24. }
  25. until_lc_state_is_not()
  26. {
  27. ! until_lc_state_is "$@"
  28. }
  29. lc_state_get()
  30. {
  31. local lc=$1
  32. devlink lc show $DEVLINK_DEV lc $lc -j | jq -e -r ".[][][].state"
  33. }
  34. lc_wait_until_state_changes()
  35. {
  36. local lc=$1
  37. local state=$2
  38. local timeout=$3 # ms
  39. busywait "$timeout" until_lc_state_is_not "$state" lc_state_get "$lc"
  40. }
  41. lc_wait_until_state_becomes()
  42. {
  43. local lc=$1
  44. local state=$2
  45. local timeout=$3 # ms
  46. busywait "$timeout" until_lc_state_is "$state" lc_state_get "$lc"
  47. }
  48. until_lc_port_count_is()
  49. {
  50. local port_count=$1; shift
  51. local current=$("$@")
  52. echo "$current"
  53. [ $current == $port_count ]
  54. }
  55. lc_port_count_get()
  56. {
  57. local lc=$1
  58. devlink port -j | jq -e -r ".[][] | select(.lc==$lc) | .port" | wc -l
  59. }
  60. lc_wait_until_port_count_is()
  61. {
  62. local lc=$1
  63. local port_count=$2
  64. local timeout=$3 # ms
  65. busywait "$timeout" until_lc_port_count_is "$port_count" lc_port_count_get "$lc"
  66. }
  67. lc_nested_devlink_dev_get()
  68. {
  69. local lc=$1
  70. devlink lc show $DEVLINK_DEV lc $lc -j | jq -e -r ".[][][].nested_devlink"
  71. }
  72. PROV_UNPROV_TIMEOUT=8000 # ms
  73. POST_PROV_ACT_TIMEOUT=2000 # ms
  74. PROV_PORTS_INSTANTIATION_TIMEOUT=15000 # ms
  75. unprovision_one()
  76. {
  77. local lc=$1
  78. local state
  79. state=$(lc_state_get $lc)
  80. check_err $? "Failed to get state of linecard $lc"
  81. if [[ "$state" == "unprovisioned" ]]; then
  82. return
  83. fi
  84. log_info "Unprovisioning linecard $lc"
  85. devlink lc set $DEVLINK_DEV lc $lc notype
  86. check_err $? "Failed to trigger linecard $lc unprovisioning"
  87. state=$(lc_wait_until_state_changes $lc "unprovisioning" \
  88. $PROV_UNPROV_TIMEOUT)
  89. check_err $? "Failed to unprovision linecard $lc (timeout)"
  90. [ "$state" == "unprovisioned" ]
  91. check_err $? "Failed to unprovision linecard $lc (state=$state)"
  92. }
  93. provision_one()
  94. {
  95. local lc=$1
  96. local type=$2
  97. local state
  98. log_info "Provisioning linecard $lc"
  99. devlink lc set $DEVLINK_DEV lc $lc type $type
  100. check_err $? "Failed trigger linecard $lc provisioning"
  101. state=$(lc_wait_until_state_changes $lc "provisioning" \
  102. $PROV_UNPROV_TIMEOUT)
  103. check_err $? "Failed to provision linecard $lc (timeout)"
  104. [ "$state" == "provisioned" ] || [ "$state" == "active" ]
  105. check_err $? "Failed to provision linecard $lc (state=$state)"
  106. provisioned_type=$(devlink lc show $DEVLINK_DEV lc $lc -j | jq -e -r ".[][][].type")
  107. [ "$provisioned_type" == "$type" ]
  108. check_err $? "Wrong provision type returned for linecard $lc (got \"$provisioned_type\", expected \"$type\")"
  109. # Wait for possible activation to make sure the state
  110. # won't change after return from this function.
  111. state=$(lc_wait_until_state_becomes $lc "active" \
  112. $POST_PROV_ACT_TIMEOUT)
  113. }
  114. unprovision_test()
  115. {
  116. RET=0
  117. local lc
  118. lc=$LC_SLOT
  119. unprovision_one $lc
  120. log_test "Unprovision"
  121. }
  122. LC_16X100G_TYPE="16x100G"
  123. LC_16X100G_PORT_COUNT=16
  124. supported_types_check()
  125. {
  126. local lc=$1
  127. local supported_types_count
  128. local type_index
  129. local lc_16x100_found=false
  130. supported_types_count=$(devlink lc show $DEVLINK_DEV lc $lc -j | \
  131. jq -e -r ".[][][].supported_types | length")
  132. [ $supported_types_count != 0 ]
  133. check_err $? "No supported types found for linecard $lc"
  134. for (( type_index=0; type_index<$supported_types_count; type_index++ ))
  135. do
  136. type=$(devlink lc show $DEVLINK_DEV lc $lc -j | \
  137. jq -e -r ".[][][].supported_types[$type_index]")
  138. if [[ "$type" == "$LC_16X100G_TYPE" ]]; then
  139. lc_16x100_found=true
  140. break
  141. fi
  142. done
  143. [ $lc_16x100_found = true ]
  144. check_err $? "16X100G not found between supported types of linecard $lc"
  145. }
  146. ports_check()
  147. {
  148. local lc=$1
  149. local expected_port_count=$2
  150. local port_count
  151. port_count=$(lc_wait_until_port_count_is $lc $expected_port_count \
  152. $PROV_PORTS_INSTANTIATION_TIMEOUT)
  153. [ $port_count != 0 ]
  154. check_err $? "No port associated with linecard $lc"
  155. [ $port_count == $expected_port_count ]
  156. check_err $? "Unexpected port count linecard $lc (got $port_count, expected $expected_port_count)"
  157. }
  158. lc_dev_info_provisioned_check()
  159. {
  160. local lc=$1
  161. local nested_devlink_dev=$2
  162. local fixed_hw_revision
  163. local running_ini_version
  164. fixed_hw_revision=$(devlink dev info $nested_devlink_dev -j | \
  165. jq -e -r '.[][].versions.fixed."hw.revision"')
  166. check_err $? "Failed to get linecard $lc fixed.hw.revision"
  167. log_info "Linecard $lc fixed.hw.revision: \"$fixed_hw_revision\""
  168. running_ini_version=$(devlink dev info $nested_devlink_dev -j | \
  169. jq -e -r '.[][].versions.running."ini.version"')
  170. check_err $? "Failed to get linecard $lc running.ini.version"
  171. log_info "Linecard $lc running.ini.version: \"$running_ini_version\""
  172. }
  173. provision_test()
  174. {
  175. RET=0
  176. local lc
  177. local type
  178. local state
  179. local nested_devlink_dev
  180. lc=$LC_SLOT
  181. supported_types_check $lc
  182. state=$(lc_state_get $lc)
  183. check_err $? "Failed to get state of linecard $lc"
  184. if [[ "$state" != "unprovisioned" ]]; then
  185. unprovision_one $lc
  186. fi
  187. provision_one $lc $LC_16X100G_TYPE
  188. ports_check $lc $LC_16X100G_PORT_COUNT
  189. nested_devlink_dev=$(lc_nested_devlink_dev_get $lc)
  190. check_err $? "Failed to get nested devlink handle of linecard $lc"
  191. lc_dev_info_provisioned_check $lc $nested_devlink_dev
  192. log_test "Provision"
  193. }
  194. ACTIVATION_TIMEOUT=20000 # ms
  195. interface_check()
  196. {
  197. ip link set $h1 up
  198. ip link set $h2 up
  199. ifaces_upped=true
  200. setup_wait
  201. }
  202. lc_dev_info_active_check()
  203. {
  204. local lc=$1
  205. local nested_devlink_dev=$2
  206. local fixed_device_fw_psid
  207. local running_device_fw
  208. fixed_device_fw_psid=$(devlink dev info $nested_devlink_dev -j | \
  209. jq -e -r ".[][].versions.fixed" | \
  210. jq -e -r '."fw.psid"')
  211. check_err $? "Failed to get linecard $lc fixed fw PSID"
  212. log_info "Linecard $lc fixed.fw.psid: \"$fixed_device_fw_psid\""
  213. running_device_fw=$(devlink dev info $nested_devlink_dev -j | \
  214. jq -e -r ".[][].versions.running.fw")
  215. check_err $? "Failed to get linecard $lc running.fw.version"
  216. log_info "Linecard $lc running.fw: \"$running_device_fw\""
  217. }
  218. activation_16x100G_test()
  219. {
  220. RET=0
  221. local lc
  222. local type
  223. local state
  224. local nested_devlink_dev
  225. lc=$LC_SLOT
  226. type=$LC_16X100G_TYPE
  227. unprovision_one $lc
  228. provision_one $lc $type
  229. state=$(lc_wait_until_state_becomes $lc "active" \
  230. $ACTIVATION_TIMEOUT)
  231. check_err $? "Failed to get linecard $lc activated (timeout)"
  232. interface_check
  233. nested_devlink_dev=$(lc_nested_devlink_dev_get $lc)
  234. check_err $? "Failed to get nested devlink handle of linecard $lc"
  235. lc_dev_info_active_check $lc $nested_devlink_dev
  236. log_test "Activation 16x100G"
  237. }
  238. setup_prepare()
  239. {
  240. local lc_num=$(devlink lc show -j | jq -e -r ".[][\"$DEVLINK_DEV\"] |length")
  241. if [[ $? -ne 0 ]] || [[ $lc_num -eq 0 ]]; then
  242. echo "SKIP: No linecard support found"
  243. exit $ksft_skip
  244. fi
  245. if [ -z "$LC_SLOT" ]; then
  246. echo "SKIP: \"LC_SLOT\" variable not provided"
  247. exit $ksft_skip
  248. fi
  249. # Interfaces are not present during the script start,
  250. # that's why we define NUM_NETIFS here so dummy
  251. # implicit veth pairs are not created.
  252. NUM_NETIFS=2
  253. h1=${NETIFS[p1]}
  254. h2=${NETIFS[p2]}
  255. ifaces_upped=false
  256. }
  257. cleanup()
  258. {
  259. if [ "$ifaces_upped" = true ] ; then
  260. ip link set $h1 down
  261. ip link set $h2 down
  262. fi
  263. }
  264. trap cleanup EXIT
  265. setup_prepare
  266. tests_run
  267. exit $EXIT_STATUS