
    g                         S r SSKrSSKrSSKrSSKJr  SSKJr  SSKJ	r	J
r
Jr  SSKrSrSrS	r " S
 S\5      r " S S\5      r " S S\5      r " S S\R(                  5      rg)z"netplan SR-IOV rebind command line    N)sleep   )utils)	PCIDevicebind_vfs_get_pci_slot_name   g?   c                       \ rS rSrSrg)MLX5VFLAGStateNotFound#    N__name__
__module____qualname____firstlineno____static_attributes__r       ;/usr/share/netplan/netplan_cli/cli/commands/sriov_rebind.pyr   r   #       r   r   c                       \ rS rSrSrg)MLX5VFLAGStateCannotBeRead'   r   Nr   r   r   r   r   r   '   r   r   r   c                       \ rS rSrSrg)MLX5VFLAGStateDisabled+   r   Nr   r   r   r   r   r   +   r   r   r   c                   x   ^  \ rS rSrU 4S jrS rS rS\S\4S jr	S\4S jr
S	\S
\4S jrS\S
\4S jrSrU =r$ )NetplanSriovRebind/   c                 $   > [         TU ]  SSSS9  g )NrebindzKRebind SR-IOV virtual functions of given physical functions to their driverT)
command_iddescriptionleaf)super__init__)self	__class__s    r   r'   NetplanSriovRebind.__init__1   s    H%r" 	 	$r   c                    U R                   R                  SSSS9  U R                   R                  S[        S/ SS9  U R                  U l        [
        R                  " S	5      U l        S
U R                  l        [
        R                  " [        R                  S9nU R                  5         U R                  (       an  U R                  R                  [
        R                  5        UR                  [
        R                  5        UR!                  [
        R"                  " S5      5        OmU R                  R                  [
        R$                  5        UR                  [
        R$                  5        UR!                  [
        R"                  " S5      5        U R                  R'                  U5        U R)                  5         g )Nz
--root-dir/zBSearch for configuration files in this root directory instead of /)defaulthelpnetdevs*z*Space separated list of PF interface names)typenargsr-   r.   sriov_rebindF)streamz%(levelname)s:%(message)sz%(message)s)parseradd_argumentstrcommand_rebindfunclogging	getLoggerlogger	propagateStreamHandlersysstdout
parse_argsdebugsetLevelDEBUGsetFormatter	FormatterINFO
addHandlerrun_command)r(   log_handlers     r   runNetplanSriovRebind.run6   s7     s&j 	! 	l  C&R 	! 	T''	''7 %++3::> ::KK  /  /$$W%6%67R%STKK  .  .$$W%6%6}%EF{+r   c           	         U R                    H  n[        U5      n[        U5      nUR                  (       d,  U R                  R                  SR                  U5      5        MV  U R                  X5        [        UR                  UR                  5      nU R                  R                  SR                  U[        U5      5      5        M     g)zeBind virtual functions of SR-IOV devices to their corresponding driver after eswitch mode was changedz1{} does not seem to be a SR-IOV physical functionz{}: bound {} VFsN)r/   r   r   is_pfr<   rB   format!_perform_hardware_specific_quirksr   vfsdriverlen)r(   ifacepci_addrpcidev	bound_vfss        r   r8   !NetplanSriovRebind.command_rebindQ   s    \\E)%0Hx(F<<!!"U"\"\]b"cd
 225A V]];IKK077IOP "r   rT   pfc                    UR                   S;   Gab  [        R                  " 5       nUR                  U R                  5        [        R
                  " 5       nUR                  U5        UR                  R                  5        H  nUR                  (       a  UR                  U:X  d  UR                  U:X  d  M6  UR                  R                  S5      =n(       d  MZ  UR                  nU R                  U5      (       d#  U R                   R#                  U SU S35        M  U R                   R#                  U S35         U R%                  U5        U R                   R#                  U S35        M     g
g
! [&         a#    U R                   R#                  U S35         GM  [(         a#    U R                   R#                  U S35         GMJ  [*         a#    U R                   R#                  U S	35         GMu  f = f)zk
Perform any hardware-specific quirks for the given SR-IOV device to make
sure it's ready before the bind.
)	mlx5_corebondz - LAG mode z is not supported by VF LAGz+ - waiting for the LAG state to be 'active'z - VF LAG state is 'active'z - VF LAG state cannot be readz& - VF LAG state debugfs file not foundz1 - VF LAG state is still 'disabled' after waitingN)rR   netplanParserload_yaml_hierarchyroot_dirStateimport_parser_results	ethernetsvalues
_has_matchset_nameidlinksget
_bond_mode_is_bond_mode_supportedr<   rB   "_wait_for_mlx5_pf_lag_state_activer   r   r   )r(   rT   rY   r5   np_statenetdef	bond_link	bond_modes           r   rP   4NetplanSriovRebind._perform_hardware_specific_quirksb   s    99% ^^%F&&t}}5}}H**62",,335%%&//U*BvyyTYGY$*LL$4$4V$<<y< %.$8$8	#;;IFF KK--|I;Ni.jk$))UG3`*ab	W CCBG !KK--7T.UV7 6 &8  : X KK--7U.VWW5 ` KK--7].^__5 m KK--7j.kllms    E55(G8!'G8'G87G8c                    [        [        [        -  5      nUR                  nSU S3n[        R
                  R                  U5      (       d  [        [        5        [        eUS:  aR   U R                  U5      S:w  a.  U R                  R                  U S35        [        [        5        OgUS-
  nUS:  a  MR  [        e! [         a    [        ef = f)z
The mlx5 driver added support for debugfs in https://github.com/torvalds/linux/commit/7f46a0b7327a
It's available since kernel 5.19 https://cdn.kernel.org/pub/linux/kernel/v5.x/ChangeLog-5.19
/sys/kernel/debug/mlx5/
/lag/stater   activez, VF LAG state is not active yet, retrying...N   )intMAX_WAITING_TIME_SECINTERVAL_SECrU   ospathexistsr   FALLBACK_WAIT_TIME_SECr   _get_mlx5_vf_lag_stater<   rB   	Exceptionr   r   )r(   rY   retriesrU   r{   s        r   rl   5NetplanSriovRebind._wait_for_mlx5_pf_lag_state_active   s    
 *\9:;;(
*=ww~~d## ()((k
1..x8HDKK%%
2^&_` ,'
 kG k %$  1001s   )AC   Cmodereturnc                     US;   $ )z`
Return True or False if the bond mode is one of the supported modes
for the VG LAG activation.
)zactive-backupzbalanced-xorz802.3adr   )r(   r   s     r   rk   *NetplanSriovRebind._is_bond_mode_supported   s    
 CCCr   rU   c                     SU S3n[        US5       nUR                  5       R                  5       sS S S 5        $ ! , (       d  f       g = f)Nrs   rt   r)openreadstrip)r(   rU   r{   fs       r   r~   )NetplanSriovRebind._get_mlx5_vf_lag_state   s5    (
*=$_668>># __s	   ;
A	)r9   r<   )r   r   r   r   r'   rK   r8   r7   r   rP   rl   boolrk   r~   r   __classcell__)r)   s   @r   r   r   /   se    $
6Q")Ws )W	 )WV"%Y "%HDC DD D$s $s $ $r   r   )__doc__r:   rz   r?   timer    r   sriovr   r   r   r]   r}   ry   rx   r   r   r   r   NetplanCommandr   r   r   r   <module>r      sm   $ )  	 
   ; ;    	Y 		 		Y 	M$-- M$r   