pcie

package
v0.0.0-...-1354da5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 24, 2021 License: Apache-2.0 Imports: 6 Imported by: 2

Documentation

Overview

Package pcie builds and parses PCIe Transport Layer Packets (TLP).

Index

Constants

View Source
const (

	// MaxTLPBuffer is a 4 dword header + max data payload.
	MaxTLPBuffer = 4*dwordLen + maxDataLen*dwordLen
)

Variables

View Source
var (
	ErrBadType    = errors.New("bad TLP header type")
	ErrBadLength  = errors.New("bad TLP data length")
	ErrBadAddress = errors.New("bad TLP address")
	ErrTooShort   = errors.New("TLP packet too short")
)

errors

Functions

func CplCalcByteCount

func CplCalcByteCount(firstBE, lastBE, length int) int

See Table 2-37: Calculating Byte Count from Length and Byte Enables.

func CplCalcLowerAddress

func CplCalcLowerAddress(firstBE int, readAddress Address) byte

Table 2-38: Calculating Lower Address from 1st DW BE.

Types

type Address

type Address uint64

Address is the address field in the request header.

type AddressType

type AddressType uint8

AddressType is the address type field in the request header.

const (
	DefaultUntranslated AddressType = 0b00
	TranslationRequest  AddressType = 0b01
	Translated          AddressType = 0b10
	AddressTypeReserved AddressType = 0b11
)

Supported address types.

type CfgHeader

type CfgHeader struct {
	RequestHeader
	Target DeviceID
	// Register number (6b)
	RegisterNumber int
	// Extended register number (4b)
	ExtRegisterNumber int
}

CfgHeader extends RequestHeader and includes the third header dword for configuration read TLPs.

type CfgRd

type CfgRd struct {
	CfgHeader
}

CfgRd TLP: Configuration read request.

func NewCfgRd

func NewCfgRd(reqID DeviceID, tag uint8, target DeviceID, register int) *CfgRd

NewCfgRd builds configuration read request.

func (*CfgRd) ToBytes

func (tlp *CfgRd) ToBytes() []byte

ToBytes encodes CfgRd to wire format.

type CfgWr

type CfgWr struct {
	CfgHeader
	Data []byte
}

CfgWr TLP: Configuration write request.

func NewCfgWr

func NewCfgWr(reqID DeviceID, tag uint8, target DeviceID, register int, data [4]byte) *CfgWr

NewCfgWr builds configuration write request.

func NewCfgWrFromBytes

func NewCfgWrFromBytes(b []byte) (*CfgWr, error)

NewCfgWrFromBytes builds a memory read request from a TLP buffer.

func (*CfgWr) FirstDataByte

func (tlp *CfgWr) FirstDataByte() byte

Returns the first enabled data.

func (*CfgWr) MemoryAddress

func (tlp *CfgWr) MemoryAddress() int

Returns the config space memory address. Table 7-1: Enhanced Configuration Address Mapping.

func (*CfgWr) ToBytes

func (tlp *CfgWr) ToBytes() []byte

ToBytes encodes CfgWr to wire format.

type CompletionStatus

type CompletionStatus uint8

CompletionStatus is the completion status field in the completion header.

const (
	SuccessfulCompletion      CompletionStatus = 0b000
	UnsupportedRequest        CompletionStatus = 0b001
	ConfigurationRequestRetry CompletionStatus = 0b010
	CompleterAbort            CompletionStatus = 0b100
)

Supported completion status.

type Cpl

type Cpl struct {
	CplHeader
	Data []byte
}

Cpl TLP: Completion response.

func NewCpl

func NewCpl(cplID DeviceID, bc int, status CompletionStatus, reqID DeviceID, tag, addressLow uint8, data []byte) (*Cpl, error)

NewCpl builds completion response.

func NewCplForMrd

func NewCplForMrd(cplID DeviceID, status CompletionStatus, mrd *MRd, data []byte) (*Cpl, error)

NewCplForMrd builds a completion response that matches the given memory read request.

func NewCplFromBytes

func NewCplFromBytes(b []byte) (*Cpl, error)

NewCplFromBytes builds completion response from TLP buffer.

func (*Cpl) ToBytes

func (tlp *Cpl) ToBytes() []byte

ToBytes encodes Cpl to wire format.

type CplHeader

type CplHeader struct {
	TlpHeader
	// Completer ID.
	CplID DeviceID
	// Byte count: the number of bytes left for transmission, including those in
	// the current packet (12b).
	BC int
	// Completion status.
	Status CompletionStatus
	// Requester ID.
	ReqID DeviceID
	// Unique tag for all outstanding requests.
	Tag uint8
	// Lower Byte Address for starting byte of Completion (7b).
	AddressLow uint8
}

CplHeader extends TlpHeader and includes the second and third header dwords for Completion TLPs. See section 2.2.9. Completion Rules

type DeviceID

type DeviceID struct {
	Bus      uint8
	Device   uint8
	Function uint8
}

DeviceID is a configuration space address that uniquely identifies the device on the PCIe fabric.

func NewDeviceID

func NewDeviceID(value uint16) (addr DeviceID)

NewDeviceID builds a new DeviceID from an encoded uint16 value.

func (*DeviceID) FromString

func (id *DeviceID) FromString(value string) error

FromString assigns DeviceID from an encoded string value.

func (*DeviceID) FromUint16

func (id *DeviceID) FromUint16(value uint16)

FromUint16 assigns DeviceID from an encoded uint16 value.

func (DeviceID) String

func (id DeviceID) String() string

func (*DeviceID) ToUint16

func (id *DeviceID) ToUint16() uint16

ToUint16 encodes DeviceID to a uint16 value.

type IORd

type IORd struct {
	RequestHeader
	Address Address
}

IORd TLP: I/O read request.

func NewIORd

func NewIORd(reqID DeviceID, tag uint8, addr uint64, length uint32) (*IORd, error)

NewIORd builds memory read request. |length| is the number of BYTES to read and must be DWORD aligned.

func (*IORd) ToBytes

func (tlp *IORd) ToBytes() []byte

ToBytes encodes IORd to wire format.

type IOWrt

type IOWrt struct {
	RequestHeader
	Address Address
	Data    []byte
}

IOWrt TLP: Memory write request.

func NewIOWrt

func NewIOWrt(reqID DeviceID, addr uint64, data []byte) (*IOWrt, error)

NewIOWrt builds memory write request. len(data) must be DW aligned.

func (*IOWrt) ToBytes

func (tlp *IOWrt) ToBytes() []byte

ToBytes encodes IOWrt to wire format.

type MRd

type MRd struct {
	RequestHeader
	Address Address
}

MRd TLP: Memory read request.

func NewMRd

func NewMRd(reqID DeviceID, tag uint8, addr uint64, length uint32) (*MRd, error)

NewMRd builds memory read request. |length| is the number of BYTES to read and must be DWORD aligned.

func NewMRdFromBytes

func NewMRdFromBytes(b []byte) (*MRd, error)

NewMRdFromBytes builds a memory read request from a TLP buffer.

func (*MRd) ToBytes

func (tlp *MRd) ToBytes() []byte

ToBytes encodes MRd to wire format.

type MWr

type MWr struct {
	RequestHeader
	Address Address
	Data    []byte
}

MWr TLP: Memory write request.

func NewMWr

func NewMWr(reqID DeviceID, addr uint64, data []byte) (*MWr, error)

NewMWr builds memory write request. len(data) must be DWORD aligned.

func NewMWrFromBytes

func NewMWrFromBytes(b []byte) (*MWr, error)

NewMWrFromBytes builds a memory write request from a TLP buffer.

func (*MWr) ToBytes

func (tlp *MWr) ToBytes() []byte

ToBytes encodes MWr to wire format.

type RequestHeader

type RequestHeader struct {
	TlpHeader
	// Requester ID.
	ReqID DeviceID
	// Unique tag for all outstanding requests.
	Tag uint8
	// First Byte Enable (4b).
	FirstBE uint8
	// Last Byte Enable (4b).
	LastBE uint8
}

RequestHeader extends TlpHeader and includes the second header dword on Memory, IO, and Config Request TLPs.

type TlpHeader

type TlpHeader struct {
	// Format and type.
	Type TlpType
	// Traffic class (3b).
	TC TrafficClass
	// Indicates that a Memory Request is an LN Read or LN Write (1b).
	LN bool
	// Presence of TLP Processing Hints (1b).
	TH bool
	// Presence of TLP digest in the form of a single DW at the end of the TLP (1b).
	TD bool
	// Indicates the TLP is poisoned (1b).
	EP bool
	// Attributes (3b): no-snoop, relaxed ordering, id-based ordering.
	NS  bool
	RO  bool
	IBO bool
	// Address Type (2b).
	AT AddressType
	// Length of data payload in DW (10b).
	Length int
}

TlpHeader is the first header dword, common on all TLPs. See section 2.2.1. Common Packet Header Fields.

func (*TlpHeader) DataLength

func (h *TlpHeader) DataLength() int

DataLength decodes h.Length to data length. See Table 2-4 Length[9:0] Field Encoding.

type TlpType

type TlpType uint8

TlpType is the format and type field in the TLP header. See Table 2-3 in PCI EXPRESS BASE SPECIFICATION, REV. 3.1a.

const (
	// MRd3 is a Memory Read Request encoded with 3 dwords.
	MRd3 TlpType = (fmt3DWNoData << 5) | 0b00000
	// MRd4 is a Memory Read Request encoded with 4 dwords.
	MRd4 TlpType = (fmt4DWNoData << 5) | 0b00000
	// MRdLk3 is a Memory Read Request-Locked encoded with 3 dwords.
	MRdLk3 TlpType = (fmt3DWNoData << 5) | 0b00001
	// MRdLk4 is a Memory Read Request-Locked encoded with 4 dwords.
	MRdLk4 TlpType = (fmt4DWNoData << 5) | 0b00001
	// MWr3 is a Memory Write Request encoded with 3 dwords.
	MWr3 TlpType = (fmt3DWWithData << 5) | 0b00000
	// MWr4 is a Memory Write Request encoded with 4 dwords.
	MWr4 TlpType = (fmt4DWWithData << 5) | 0b00000
	// IORdT is an I/O Read Request.
	IORdT TlpType = (fmt3DWNoData << 5) | 0b00010
	// IOWrtT is an I/O Write Request.
	IOWrtT TlpType = (fmt3DWWithData << 5) | 0b00010
	// CfgRd0 is a Configuration Read of Type 0.
	CfgRd0 TlpType = (fmt3DWNoData << 5) | 0b00100
	// CfgWr0 is a Configuration Write of Type 0.
	CfgWr0 TlpType = (fmt3DWWithData << 5) | 0b00100
	// CfgRd1 is a Configuration Read of Type 1.
	CfgRd1 TlpType = (fmt3DWNoData << 5) | 0b00101
	// CfgWr1 is a Configuration Write of Type 1.
	CfgWr1 TlpType = (fmt3DWWithData << 5) | 0b00101
	// CplE is a Completion without Data. Used for I/O and
	// Configuration Write Completions with any
	// Completion Status.
	CplE TlpType = (fmt3DWNoData << 5) | 0b01010
	// CplD is a Completion with Data. Used for Memory,
	// I/O, and Configuration Read Completions.
	CplD TlpType = (fmt3DWWithData << 5) | 0b01010
	// CplLk is a Completion for Locked Memory Read without
	// Data. Used only in error case.
	CplLk TlpType = (fmt3DWNoData << 5) | 0b01011
	// CplLkD is a Completion for Locked Memory Read –
	// otherwise like CplD.
	CplLkD TlpType = (fmt3DWWithData << 5) | 0b01011
	// MRIOV is a Multi-Root I/O Virtualization and Sharing (MR-IOV) TLP prefix.
	MRIOV TlpType = (fmtTlpPrefix << 5) | 0b00000
	// LocalVendPrefix is a Local TLP prefix with vendor sub-field.
	LocalVendPrefix TlpType = (fmtTlpPrefix << 5) | 0b01110
	// ExtTPH is an Extended TPH TLP prefix.
	ExtTPH TlpType = (fmtTlpPrefix << 5) | 0b10000
	// PASID is a Process Address Space ID (PASID) TLP Prefix.
	PASID TlpType = (fmtTlpPrefix << 5) | 0b10001
	// EndEndVendPrefix is an End-to-End TLP prefix with vendor sub-field.
	EndEndVendPrefix TlpType = (fmtTlpPrefix << 5) | 0b11110
)

type TrafficClass

type TrafficClass uint8

TrafficClass is the traffic class field in the request header and used to set quality of service (QoS).

const (
	TC0 TrafficClass = iota
	TC1
	TC2
	TC3
	TC4
	TC5
	TC6
	TC7
)

Supported traffic classes.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL