Skip to content

Commit 468175a

Browse files
authored
Merge pull request #215 from xapi-project/sr-iov
Merge feature SR-IOV to master
2 parents 4e9db52 + 6b4d4fc commit 468175a

File tree

5 files changed

+93
-26
lines changed

5 files changed

+93
-26
lines changed

lib/jbuild

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ let runtime_coverage_enabled, coverage_dep =
3232
else
3333
"disabled.ml", ""
3434

35-
let rewriters = ["ppx_deriving_rpc"]
35+
let rewriters = ["ppx_deriving_rpc"; "ppx_sexp_conv"]
3636
let flags = flags rewriters
3737

3838
let () = Printf.ksprintf Jbuild_plugin.V1.send {|
@@ -56,6 +56,7 @@ let () = Printf.ksprintf Jbuild_plugin.V1.send {|
5656
message-switch-core
5757
message-switch-unix
5858
ppx_deriving_rpc
59+
ppx_sexp_conv
5960
re
6061
rpclib
6162
rpclib.xml

lib/xcp_pci.ml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
open Sexplib.Std
2+
3+
type address = {
4+
domain: int;
5+
bus: int;
6+
dev: int;
7+
fn: int;
8+
}
9+
[@@deriving sexp, rpc, rpcty]
10+
11+
let address_of_string str =
12+
Scanf.sscanf str "%04x:%02x:%02x.%02x"
13+
(fun domain bus dev fn -> {domain; bus; dev; fn})
14+
15+
let string_of_address address =
16+
Printf.sprintf "%04x:%02x:%02x.%01x"
17+
address.domain address.bus address.dev address.fn

network/network_interface.ml

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ module D = Debug.Make(struct let name = "network_interface" end)
1818
open D
1919

2020
(** {2 Helper functions} *)
21-
2221
let service_name = "networkd"
2322
let queue_name = ref (Xcp_service.common_prefix ^ service_name)
2423

@@ -325,6 +324,13 @@ module Interface_API(R : RPC) = struct
325324
["Check interface existence"]
326325
(debug_info_p @-> iface_name_p @-> returning result err)
327326

327+
let get_pci_bus_path =
328+
let result = Param.mk ~description:["PCI bus path"] Types.string in
329+
declare
330+
"Interface.get_pci_bus_path"
331+
["Get PCI bus path of the interface"]
332+
(debug_info_p @-> iface_name_p @-> returning result err)
333+
328334
let get_mac =
329335
let result = Param.mk ~description:["MAC address"] Types.string in
330336
declare
@@ -631,5 +637,63 @@ module Interface_API(R : RPC) = struct
631637
["Remove site"]
632638
(debug_info_p @-> site_p @-> returning unit_p err)
633639
end
634-
end
635640

641+
module Sriov = struct
642+
type sriov_pci_t = {
643+
mac: string option;
644+
vlan: int64 option;
645+
rate: int64 option;
646+
} [@@deriving rpcty]
647+
648+
type enable_action_result =
649+
| Modprobe_successful_requires_reboot
650+
| Modprobe_successful
651+
| Sysfs_successful
652+
[@@deriving rpcty]
653+
654+
type enable_result =
655+
| Ok of enable_action_result
656+
| Error of string
657+
[@@deriving rpcty]
658+
659+
type disable_result =
660+
| Ok
661+
| Error of string
662+
[@@deriving rpcty]
663+
664+
type config_error =
665+
| Config_vf_rate_not_supported
666+
| Unknown of string
667+
[@@deriving rpcty]
668+
669+
type config_result =
670+
| Ok
671+
| Error of config_error
672+
[@@deriving rpcty]
673+
674+
let iface_name_p = Param.mk ~name:"name" ~description:["interface name"] iface
675+
676+
let enable =
677+
let result_p = Param.mk ~description:["SR-IOV enable result"] enable_result in
678+
declare
679+
"Sriov.enable"
680+
["Enable SR-IOV"]
681+
(debug_info_p @-> iface_name_p @-> returning result_p err)
682+
683+
let disable =
684+
let result_p = Param.mk ~description:["SR-IOV disable result"] disable_result in
685+
declare
686+
"Sriov.disable"
687+
["Disable SR-IOV"]
688+
(debug_info_p @-> iface_name_p @-> returning result_p err)
689+
690+
let make_vf_config =
691+
let pci_address_p = Param.mk ~description:["pci address"] Xcp_pci.address in
692+
let vf_info_p = Param.mk ~description:["vf info"] sriov_pci_t in
693+
let result_t = Param.mk ~description:["SR-IOV make vf configuration result"] config_result in
694+
declare
695+
"Sriov.make_vf_config"
696+
["Make SR-IOV vf config"]
697+
(debug_info_p @-> pci_address_p @-> vf_info_p @-> returning result_t err)
698+
end
699+
end

xen/xenops_interface.ml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,21 +82,14 @@ module Network = struct
8282
type t =
8383
| Local of string (** name of a local switch *)
8484
| Remote of string * string (** vm.id * switch *)
85+
| Sriov of Xcp_pci.address (** Xcp_pci.address *)
8586
type ts = t list
8687

8788
let default_t = Local "xenbr0"
8889
end
8990

9091
module Pci = struct
91-
include Xenops_types.Pci
92-
93-
let address_of_string str =
94-
Scanf.sscanf str "%04x:%02x:%02x.%02x"
95-
(fun domain bus dev fn -> {domain; bus; dev; fn})
96-
97-
let string_of_address address =
98-
Printf.sprintf "%04x:%02x:%02x.%01x"
99-
address.domain address.bus address.dev address.fn
92+
include Xcp_pci
10093

10194
type id = string * string
10295

@@ -284,6 +277,7 @@ module Vif = struct
284277
ipv4_configuration: ipv4_configuration;
285278
ipv6_configuration: ipv6_configuration;
286279
pvs_proxy: PVS_proxy.t option;
280+
vlan: int64 option;
287281
}
288282

289283
let default_t = {
@@ -300,6 +294,7 @@ module Vif = struct
300294
ipv4_configuration = default_ipv4_configuration;
301295
ipv6_configuration = default_ipv6_configuration;
302296
pvs_proxy = None;
297+
vlan = None;
303298
}
304299

305300
let t_of_rpc rpc = Rpc.struct_extend rpc (rpc_of_t default_t) |> t_of_rpc

xen/xenops_types.ml

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
open Sexplib.Std
2+
open Xcp_pci
23

34
module TopLevel = struct
45
type power_state =
@@ -14,33 +15,22 @@ module TopLevel = struct
1415
[@@deriving sexp, rpc]
1516
end
1617

17-
module Pci = struct
18-
type address = {
19-
domain: int;
20-
bus: int;
21-
dev: int;
22-
fn: int;
23-
}
24-
[@@deriving sexp, rpc]
25-
26-
end
27-
2818
module Vgpu = struct
2919
type gvt_g = {
30-
physical_pci_address: Pci.address option; (* unused; promoted to Vgpu.t *)
20+
physical_pci_address: address option; (* unused; promoted to Vgpu.t *)
3121
low_gm_sz: int64;
3222
high_gm_sz: int64;
3323
fence_sz: int64;
3424
monitor_config_file: string option;
3525
} [@@deriving sexp, rpc]
3626

3727
type nvidia = {
38-
physical_pci_address: Pci.address option; (* unused; promoted to Vgpu.t *)
28+
physical_pci_address: address option; (* unused; promoted to Vgpu.t *)
3929
config_file: string;
4030
} [@@deriving sexp, rpc]
4131

4232
type mxgpu = {
43-
physical_function: Pci.address option; (* unused; promoted to Vgpu.t *)
33+
physical_function: address option; (* unused; promoted to Vgpu.t *)
4434
vgpus_per_pgpu: int64;
4535
framebufferbytes: int64;
4636
} [@@deriving sexp, rpc]

0 commit comments

Comments
 (0)