at 25.11-pre 3.1 kB view raw
1{ 2 config, 3 lib, 4 pkgs, 5 ... 6}: 7 8let 9 cfg = config.services.rshim; 10 11 rshimCommand = 12 [ "${cfg.package}/bin/rshim" ] 13 ++ lib.optionals (cfg.backend != null) [ "--backend ${cfg.backend}" ] 14 ++ lib.optionals (cfg.device != null) [ "--device ${cfg.device}" ] 15 ++ lib.optionals (cfg.index != null) [ "--index ${builtins.toString cfg.index}" ] 16 ++ [ "--log-level ${builtins.toString cfg.log-level}" ]; 17in 18{ 19 options.services.rshim = { 20 enable = lib.mkEnableOption "user-space rshim driver for the BlueField SoC"; 21 22 package = lib.mkPackageOption pkgs "rshim-user-space" { }; 23 24 backend = lib.mkOption { 25 type = 26 with lib.types; 27 nullOr (enum [ 28 "usb" 29 "pcie" 30 "pcie_lf" 31 ]); 32 description = '' 33 Specify the backend to attach. If not specified, the driver will scan 34 all rshim backends unless the `device` option is given with a device 35 name specified. 36 ''; 37 default = null; 38 example = "pcie"; 39 }; 40 41 device = lib.mkOption { 42 type = with lib.types; nullOr str; 43 description = '' 44 Specify the device name to attach. The backend driver can be deduced 45 from the device name, thus the `backend` option is not needed. 46 ''; 47 default = null; 48 example = "pcie-04:00.2"; 49 }; 50 51 index = lib.mkOption { 52 type = with lib.types; nullOr int; 53 description = '' 54 Specify the index to create device path `/dev/rshim<index>`. It's also 55 used to create network interface name `tmfifo_net<index>`. This option 56 is needed when multiple rshim instances are running. 57 ''; 58 default = null; 59 example = 1; 60 }; 61 62 log-level = lib.mkOption { 63 type = lib.types.int; 64 description = '' 65 Specify the log level (0:none, 1:error, 2:warning, 3:notice, 4:debug). 66 ''; 67 default = 2; 68 example = 4; 69 }; 70 71 config = lib.mkOption { 72 type = 73 with lib.types; 74 attrsOf (oneOf [ 75 int 76 str 77 ]); 78 description = '' 79 Structural setting for the rshim configuration file 80 (`/etc/rshim.conf`). It can be used to specify the static mapping 81 between rshim devices and rshim names. It can also be used to ignore 82 some rshim devices. 83 ''; 84 default = { }; 85 example = { 86 DISPLAY_LEVEL = 0; 87 rshim0 = "usb-2-1.7"; 88 none = "usb-1-1.4"; 89 }; 90 }; 91 }; 92 93 config = lib.mkIf cfg.enable { 94 environment.etc = lib.mkIf (cfg.config != { }) { 95 "rshim.conf".text = lib.generators.toKeyValue { 96 mkKeyValue = lib.generators.mkKeyValueDefault { } " "; 97 } cfg.config; 98 }; 99 100 systemd.services.rshim = { 101 after = [ "network.target" ]; 102 serviceConfig = { 103 Restart = "always"; 104 Type = "forking"; 105 ExecStart = [ 106 (lib.concatStringsSep " \\\n" rshimCommand) 107 ]; 108 KillMode = "control-group"; 109 }; 110 wantedBy = [ "multi-user.target" ]; 111 }; 112 }; 113 114 meta.maintainers = with lib.maintainers; [ nikstur ]; 115}