@@ -319,6 +319,21 @@ static int zf_stack_init_phys_address_mode(struct zf_stack_impl* sti,
319319 return 0 ;
320320}
321321
322+ static int zf_stack_init_shrub_controller (struct zf_stack_impl * sti ,
323+ struct zf_attr * attr ,
324+ int * shrub_controller_id )
325+ {
326+ zf_stack * st = & sti -> st ;
327+
328+ if ( attr -> shrub_controller_id < -1 || attr -> shrub_controller_id > 9999 ) {
329+ zf_log_stack_err (st , "Bad shrub_controller_id; value must be -1 or in range 0 to 9999 \n" );
330+ return - EINVAL ;
331+ }
332+
333+ * shrub_controller_id = attr -> shrub_controller_id ;
334+ return 0 ;
335+ }
336+
322337static int zf_stack_init_ctpio_stack_config (struct zf_stack_impl * sti ,
323338 struct zf_attr * attr ,
324339 int * ctpio_mode )
@@ -572,14 +587,16 @@ int zf_stack_init_nic_resources(struct zf_stack_impl* sti,
572587 struct zf_attr * attr , int nicno ,
573588 int ifindex , zf_if_info * if_cplane_info ,
574589 unsigned vi_flags , int ctpio_mode ,
575- int rx_datapath , bool phys_address_mode )
590+ int rx_datapath , bool phys_address_mode ,
591+ int shrub_controller_id )
576592{
577593 zf_stack * st = & sti -> st ;
578594 struct zf_stack_nic * st_nic = & st -> nic [nicno ];
579595 struct zf_stack_res_nic * sti_nic = & sti -> nic [nicno ];
580596 ef_pd_flags pd_flags = EF_PD_DEFAULT ;
581597 int rc ;
582598 unsigned long capability_val ;
599+ char shrub_controller_char [5 ];
583600
584601 /* Open driver. */
585602 rc = ef_driver_open (& sti_nic -> dh );
@@ -606,6 +623,18 @@ int zf_stack_init_nic_resources(struct zf_stack_impl* sti,
606623 pd_flags = (ef_pd_flags )(pd_flags | EF_PD_EXPRESS );
607624 }
608625
626+ rc = snprintf (shrub_controller_char , sizeof (shrub_controller_id ), "%d" , shrub_controller_id );
627+ if ( rc < 0 || rc >= (int )sizeof (shrub_controller_char ) ) {
628+ zf_log_stack_err (st , "Failed to format shrub_controller_id\n" );
629+ return - EINVAL ;
630+ }
631+
632+ rc = setenv ("EF_SHRUB_CONTROLLER" , shrub_controller_char , 1 );
633+ if ( rc != 0 && shrub_controller_id != -1 ) {
634+ zf_log_stack_err (st , "Failed to set EF_SHRUB_CONTROLLER environment variable\n" );
635+ return - EINVAL ;
636+ }
637+
609638 if ( phys_address_mode ) {
610639 rc = ef_vi_capabilities_get_from_pd_flags (
611640 sti_nic -> dh , ifindex , (ef_pd_flags )(pd_flags | EF_PD_PHYS_MODE ),
@@ -867,6 +896,11 @@ int zf_stack_alloc(struct zf_attr* attr, struct zf_stack** stack_out)
867896 rc = zf_stack_init_datapath (sti , attr , & rx_datapath );
868897 if ( rc < 0 )
869898 goto fail2 ;
899+
900+ int shrub_controller_id ;
901+ rc = zf_stack_init_shrub_controller (sti , attr , & shrub_controller_id );
902+ if ( rc < 0 )
903+ goto fail2 ;
870904
871905 bool phys_address_mode ;
872906 rc = zf_stack_init_phys_address_mode (sti , attr , & phys_address_mode );
@@ -905,6 +939,7 @@ int zf_stack_alloc(struct zf_attr* attr, struct zf_stack** stack_out)
905939 sti -> sti_log_level = attr -> log_level ;
906940 sti -> sti_rx_datapath = rx_datapath ;
907941 sti -> sti_phys_address_mode = phys_address_mode ;
942+ sti -> sti_shrub_controller_id = shrub_controller_id ;
908943
909944 strncpy (sti -> sti_ctpio_mode , attr -> ctpio_mode , 8 );
910945 if ( st -> encap_type & EF_CP_ENCAP_F_VLAN )
@@ -958,7 +993,8 @@ int zf_stack_alloc(struct zf_attr* attr, struct zf_stack** stack_out)
958993
959994 rc = zf_stack_init_nic_resources (sti , attr , nicno , hwport_ifindex ,
960995 & hwport_cplane_info , vi_flags ,
961- ctpio_mode , rx_datapath , phys_address_mode );
996+ ctpio_mode , rx_datapath , phys_address_mode ,
997+ shrub_controller_id );
962998 if ( rc < 0 )
963999 goto fail3 ;
9641000 }
0 commit comments