From a2c17eee5c3b5d197ff7d03830f98849924932c1 Mon Sep 17 00:00:00 2001 From: Rolf Sommerhalder Date: Sun, 20 Dec 2015 11:05:02 +0100 Subject: [PATCH] populate attic from branch igbe --- src/apps/intel/attic/igbe.lua | 47 ++++++++++++ src/apps/intel/attic/igbe_tx.lua | 87 +++++++++++++++++++++++ src/apps/intel/{ => attic}/intel82574.lua | 0 src/apps/intel/attic/regs_i350.inc | 77 ++++++++++++++++++++ 4 files changed, 211 insertions(+) create mode 100644 src/apps/intel/attic/igbe.lua create mode 100644 src/apps/intel/attic/igbe_tx.lua rename src/apps/intel/{ => attic}/intel82574.lua (100%) create mode 100644 src/apps/intel/attic/regs_i350.inc diff --git a/src/apps/intel/attic/igbe.lua b/src/apps/intel/attic/igbe.lua new file mode 100644 index 0000000000..f198c0eb35 --- /dev/null +++ b/src/apps/intel/attic/igbe.lua @@ -0,0 +1,47 @@ +-- igbe.lua -- Intel Gigabit Ethernet base driver + +local pci = require("lib.hardware.pci") + +function configure (conf) + print("pciaddress: " .. conf.pciaddress) + pci.unbind_device_from_linux(conf.pciaddress) + pci.set_bus(self.pciaddress, true) + initialize() +end + +-- [4.6.3 Initialization Sequence] +function initialize () + disable_interrupts() + global_reset_and_general_configuration() + initialize_phy() + initialize_statistics_counters() + -- Skipped, out of scope for this app: + -- Initialize Receive + -- Initialize Transmit + -- Enable Interrupts +end + +-- [4.6.4 Interrupts During Initialization] +function disable_interrupts () + r[EMIC] = bits({0,1,2,3,4,5,6,7,30,31}) +end + +-- [4.6.5 Global Reset and General Configuration] +function global_reset_and_general_configuration () + r[CTRL] = bits({SLU=6, +end + +-- [4.6.7.1 PHY initialization] +function initialize_phy () + -- Expect this to be done in hardware from EEPROM. +end + +-- [4.6.8 Initialization of Statistics] +function initialize_statistics_counters () + -- No action reqired. + -- + -- Data sheet suggests reading all registers to zero them but it + -- also specifies that they all have zero as their initial values. + -- Let's not do unnecessary work. +end + diff --git a/src/apps/intel/attic/igbe_tx.lua b/src/apps/intel/attic/igbe_tx.lua new file mode 100644 index 0000000000..a5458b605a --- /dev/null +++ b/src/apps/intel/attic/igbe_tx.lua @@ -0,0 +1,87 @@ +-- igbe_tx.lua -- Intel Gigabit Ethernet: transmit driver + +local igbe_tx = {} + +local ffi = require("ffi") +local pci = require("lib.hardware.pci") + +local virtual_to_physical = require("core.memory").virtual_to_physical + +local ndescriptors = 256 +local txdesc_t = ffi.typeof("struct { uint64_t address, options; }") +local txdesc_ring_t = ffi.typeof("txdesc_t[?]", ndescriptors) + +-- Transmit descriptor array: txdesc_ring_t allocated in DMA memory. +local desc + +local pci_mmio -- char* to PCI config registers +local pci_fd -- file descriptor for PCI device + +local function configure (conf) + print("pciaddress: " .. conf.pciaddress) + initialize() +end + +-- [4.6.10 Transmit Initialization] +local function initialize () + desc = ffi.cast(txdesc_ring_t, memory.dma_alloc(ffi.sizeof(txdesc_ring_t))) + local phys = virtual_to_physical(desc) + poke(r.TDBAL, phys % 2^32) + poke(r.TDBAH, phys / 2^32) + poke(r.TDLEN, ffi.sizeof(txdesc_ring_t)) + poke(r.TXDCTL, {wthresh=16}) -- throttle/suppress descriptor writeback + poke(r.TXDCTL, {enable=25}) + wait(r.TXDCTL, {enable=25}) +end + +local tdh, tdt = 0, 0 +local txdesc_flags = bits({ifcs=25, dext=29, dtyp0=20, dtyp1=21, eop=24}) + +-- Transmit a packet asynchronously. +local function transmit (packet) + desc[tdt].address = virtual_to_physical(packet.data) + desc.flags = bor(packet.length, txdesc_flags) + txpackets[tdt] = packet + tdt = band(tdt+1, ndescriptors-1) +end + +-- Return true if a new packet can be transmitted. +local function can_transmit () + return band(tdt+1, ndescriptors-1) ~= tdh +end + +-- Synchronize ring state with hardware. +-- Free packets that have now been transmitted. +local function sync () + local cursor = tdh + tdh = peek(r.TDH) + free_packets( + if cursor ~= tdh then + while cursor ~= tdh do + packet.free(packets[cursor]) + packets[cursor] = nil + cursor = band(cursor+1, ndescriptors-1) + end + end + poke(r.TDT, tdt) +end + +-- App callbacks. + +function igbe_tx.configure (conf) + configure(conf) +end + +function igbe_tx.push () + assert(#input == 1, "igbe_tx expects one input link") + while link.can_receive(input[1]) and can_transmit() do + transmit(link.receive(input[1])) + end +end + +function igbe_tx.stop () + free_packets(tdh, tdt) + if pci_fd then pci.close_pci_resource(pci_fd) end +end + +return igbe_tx diff --git a/src/apps/intel/intel82574.lua b/src/apps/intel/attic/intel82574.lua similarity index 100% rename from src/apps/intel/intel82574.lua rename to src/apps/intel/attic/intel82574.lua diff --git a/src/apps/intel/attic/regs_i350.inc b/src/apps/intel/attic/regs_i350.inc new file mode 100644 index 0000000000..c25c878e10 --- /dev/null +++ b/src/apps/intel/attic/regs_i350.inc @@ -0,0 +1,77 @@ +Statistics registers: +0x4000 N/A CRCERRS CRC Error Count RC +0x4004 N/A ALGNERRC Alignment Error Count RC +0x4008 N/A SYMERRS Symbol Error Count RC +0x400C N/A RXERRC RX Error Count RC +0x4010 N/A MPC Missed Packets Count RC +0x4014 N/A SCC Single Collision Count RC +0x4018 N/A ECOL Excessive Collisions Count RC +0x401C N/A MCC Multiple Collision Count RC +0x4020 N/A LATECOL Late Collisions Count RC +0x4028 N/A COLC Collision Count RC +0x4030 N/A DC Defer Count RC +0x4034 N/A TNCRS Transmit - No CRS RC +0x403C N/A HTDPMC Host Transmit Discarded Packets by MAC Count RC +0x4040 N/A RLEC Receive Length Error Count RC +0x4048 N/A XONRXC XON Received Count RC +0x404C N/A XONTXC XON Transmitted Count RC +0x4050 N/A XOFFRXC XOFF Received Count RC +0x4054 N/A XOFFTXC XOFF Transmitted Count RC +0x4058 N/A FCRUC FC Received Unsupported Count RC +0x405C N/A PRC64 Packets Received (64 Bytes) Count RC +0x4060 N/A PRC127 Packets Received (65-127 Bytes) Count RC +0x4064 N/A PRC255 Packets Received (128-255 Bytes) Count RC +0x4068 N/A PRC511 Packets Received (256-511 Bytes) Count RC +0x406C N/A PRC1023 Packets Received (512-1023 Bytes) Count RC +0x4070 N/A PRC1522 Packets Received (1024-1522 Bytes) RC +0x4074 N/A GPRC Good Packets Received Count RC +0x4078 N/A BPRC Broadcast Packets Received Count RC +0x407C N/A MPRC Multicast Packets Received Count RC +0x4080 N/A GPTC Good Packets Transmitted Count RC +0x4088 N/A GORCL Good Octets Received Count (Lo) RC +0x408C N/A GORCH Good Octets Received Count (Hi) RC +0x4090 N/A GOTCL Good Octets Transmitted Count (Lo) RC +0x4094 N/A GOTCH Good Octets Transmitted Count (Hi) RC +0x40A0 N/A RNBC Receive No Buffers Count RC +0x40A4 N/A RUC Receive Under size Count RC +0x40A8 N/A RFC Receive Fragment Count RC +0x40AC N/A ROC Receive Oversize Count RC +0x40B0 N/A RJC Receive Jabber Count RC +0x40B4 N/A MNGPRC Management Packets Receive Count RC +0x40B8 N/A MPDC Management Packets Dropped Count RC +0x40BC N/A MNGPTC Management Packets Transmitted Count RC +0x40C0 N/A TORL Total Octets Received (Lo) RC +0x8FE0 N/A B2OSPC BMC2OS packets sent by BMC RC +0x4158 N/A B2OGPRC BMC2OS packets received by host RC +0x8FE4 N/A O2BGPTC OS2BMC packets received by BMC RC +0x415C N/A O2BSPC OS2BMC packets transmitted by host RC +0x40C4 N/A TORH Total Octets Received (Hi) RC +0x40C8 N/A TOTL Total Octets Transmitted (Lo) RC +0x40CC N/A TOTH Total Octets Transmitted (Hi) RC +0x40D0 N/A TPR Total Packets Received RC +0x40D4 N/A TPT Total Packets transmitted RC +0x40D8 N/A PTC64 Packets Transmitted (64 Bytes) Count RC +0x40DC N/A PTC127 Packets Transmitted (65-127 Bytes) Count RC +0x40E0 N/A PTC255 Packets Transmitted (128-256 Bytes) Count RC +0x40E4 N/A PTC511 Packets Transmitted (256-511 Bytes) Count RC +0x40E8 N/A PTC1023 Packets Transmitted (512-1023 Bytes) Count RC +0x40EC N/A PTC1522 Packets Transmitted (1024-1522 Bytes) Count RC +0x40F0 N/A MPTC Multicast Packets Transmitted Count RC +0x40F4 N/A BPTC Broadcast Packets Transmitted Count RC +0x40F8 N/A TSCTC TCP Segmentation Context Transmitted Count RC +0x4100 N/A IAC Interrupt Assertion Count RC +0x4104 N/A RPTHC Rx Packets to host count RC +0x4148 N/A TLPIC EEE TX LPI Count RC +0x414C N/A RLPIC EEE RX LPI Count RC +0x4118 N/A HGPTC Host Good Packets Transmitted Count RC +0x4120 N/A RXDMTC Rx Descriptor Minimum Threshold Count RC +0x4128 N/A HGORCL Host Good Octets Received Count (Lo) RC +0x412C N/A HGORCH Host Good Octets Received Count (Hi) RC +0x4130 N/A HGOTCL Host Good Octets Transmitted Count (Lo) RC +0x4134 N/A HGOTCH Host Good Octets Transmitted Count (Hi) RC +0x4138 N/A LENERRS Length Errors count register RC +0x4228 N/A SCVPC SerDes/SGMII/1000BASE-KX Code Violations RW +0x41A0 N/A SSVPC Switch Security Violation Packet Count RC +0x41A4 N/A SDPC Switch Drop Packet Count RC/W +0x4154 N/A MNGFBDPC Management full buffer drop packet count RC/W +0x4150 N/A LPBKFBDPC Loopback full buffer drop packet count RC/W