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