Permalink
Browse files

hand-inlining like some caveman

  • Loading branch information...
Reperator committed Jan 30, 2019
1 parent 47b8136 commit 5bde73079101f3c43d5e5a167f7d90ce7bfbf8d5
Showing with 155 additions and 145 deletions.
  1. +110 −0 lib/ixy.ml
  2. +45 −0 lib/ixy.mli
  3. +0 −51 lib/rXD.ml
  4. +0 −20 lib/rXD.mli
  5. +0 −57 lib/tXD.ml
  6. +0 −17 lib/tXD.mli
@@ -20,6 +20,116 @@ let num_tx_queue_entries = 512

let tx_clean_batch = 32

module RXD = struct
[@@@ocaml.warning "-32"]

type t = Cstruct.t

[%%cstruct
type adv_rxd_read = {
pkt_addr : uint64;
hdr_addr : uint64
} [@@little_endian]
]

[%%cstruct
type adv_rxd_wb = {
pkt_info : uint16;
hdr_info : uint16;
ip_id : uint16;
csum : uint16;
status : uint16; (* Cstruct.uint16 is unboxed and therefore faster *)
error : uint16;
length : uint16;
vlan : uint16
} [@@little_endian]
]

let () = assert (sizeof_adv_rxd_wb = sizeof_adv_rxd_read)

let sizeof = sizeof_adv_rxd_wb

let dd t =
let status = get_adv_rxd_wb_status t in
let stat_dd, stat_eop = 0b01, 0b10 in
match status land (stat_dd lor stat_eop) with
| 0b11 -> true
| 0b01 -> error "jumbo frames are not supported"
| _ -> false

let size t = get_adv_rxd_wb_length t

let split num cs =
let len = Cstruct.len cs in
if num * sizeof > len then
error "cstruct is too small (%d bytes) for %d descriptors" len num;
Array.init
num
(fun i -> Cstruct.sub cs (i * sizeof) sizeof)

let reset cs Memory.{ phys; _ } =
set_adv_rxd_read_pkt_addr cs phys;
set_adv_rxd_read_hdr_addr cs 0L
end

module TXD = struct
[@@@ocaml.warning "-32"]

type t = Cstruct.t

[%%cstruct
type adv_tx_read = {
buffer_addr : uint64;
cmd_type_len : uint32;
olinfo_status : uint32
} [@@little_endian]
]

[%%cstruct
type adv_tx_wb = {
rsvd : uint64;
nxtseq_seed : uint32;
status : uint16; (* Cstruct.uint16 is unboxed and therefore faster *)
more_rsvd : uint16
} [@@little_endian]
]

let () = assert (sizeof_adv_tx_wb = sizeof_adv_tx_read)

let sizeof = sizeof_adv_tx_wb

let dd t =
let stat_dd = 0b1 in
(get_adv_tx_wb_status t) land stat_dd <> 0

let split num cs =
let len = Cstruct.len cs in
if num * sizeof > len then
error "cstruct is too small (%d bytes) for %d descriptors" len num;
Array.init
num
(fun i -> Cstruct.sub cs (i * sizeof) sizeof)

let reset cs Memory.{ size; phys; _ } =
set_adv_tx_read_buffer_addr cs phys;
let const_part =
let dcmd_eop = 0x01000000l in
let dcmd_rs = 0x08000000l in
let dcmd_ifcs = 0x02000000l in
let dcmd_dext = 0x20000000l in
let dtyp_data = 0x00300000l in
let ( lor ) = Int32.logor in
dcmd_eop lor dcmd_rs lor dcmd_ifcs lor dcmd_dext lor dtyp_data in
let size = Int32.of_int size in
set_adv_tx_read_cmd_type_len
cs
(Int32.logor const_part size);
let paylen_shift = 14 in
set_adv_tx_read_olinfo_status
cs
(Int32.shift_left size paylen_shift)
end

type rxq = {
descriptors : RXD.t array;
mempool : Memory.mempool;
@@ -13,6 +13,51 @@ val num_rx_queue_entries : int
val num_tx_queue_entries : int
(** Number of transmit queue entries. *)

module RXD : sig
type t
(** Type of receive descriptors. *)

val sizeof : int
(** [sizeof] is the size of a receive descriptor in bytes. Equal to 16. *)

val split : int -> Cstruct.t -> t array
(** [split n cstruct] splits [cstruct] into [n] receive descriptors. *)

val dd : t -> bool
(** [dd rxd] returns [true] if [rxd]'s DD and EOP bits are set.
Fails if DD is set, but EOP is not set (jumbo frame).
Returns [false] otherwise. *)

val size : t -> int
(** [size rxd] returns [rxd]'s size in bytes. *)

val reset : t -> Memory.pkt_buf -> unit
(** [reset rxd buf] resets [rxd] by resetting its flags and pointing
it to the buffer [buf]. *)
end
(** Receive descriptor handling. *)

module TXD : sig
type t
(** Type of transmit descriptors. *)

val sizeof : int
(** [sizeof] is the size of a transmit descriptor in bytes. Equal to 16. *)

val split : int -> Cstruct.t -> t array
(** [split n cstruct] splits [cstruct] into [n] transmit descriptors. *)

val dd : t -> bool
(** [dd txd] returns true if [txd]'s stat_dd bit is set,
i.e. the packet that has been placed in the corresponding
buffer was sent out by the NIC. *)

val reset : t -> Memory.pkt_buf -> unit
(** [reset txd buf] resets [txd] by resetting its flags and pointing
it to the buffer [buf]. *)
end
(** Transmit descriptor handling. *)

type rxq = private {
descriptors : RXD.t array;
(** RX descriptor ring. *)

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.

0 comments on commit 5bde730

Please sign in to comment.