diff --git a/Makefile b/Makefile index 7d99b1e..447d1f0 100644 --- a/Makefile +++ b/Makefile @@ -1,39 +1,30 @@ -# # ---------------------------------------------------------------------------- -# Title : drivers makefile -# ---------------------------------------------------------------------------- -# File : Makefile -# Created : 2016-08-08 +# Company : SLAC National Accelerator Laboratory # ---------------------------------------------------------------------------- # Description: -# drivers makefile +# Example driver makefile # ---------------------------------------------------------------------------- -# This file is part of the rogue software package. It is subject to -# the license terms in the LICENSE.txt file found in the top-level directory -# of this distribution and at: -# https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html. -# No part of the rogue software package, including this file, may be -# copied, modified, propagated, or distributed except according to the terms +# This file is part of the aes_stream_drivers package. It is subject to +# the license terms in the LICENSE.txt file found in the top-level directory +# of this distribution and at: +# https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html. +# No part of the aes_stream_drivers package, including this file, may be +# copied, modified, propagated, or distributed except according to the terms # contained in the LICENSE.txt file. # ---------------------------------------------------------------------------- -# + MAKE_HOME := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) ARCH ?= arm LOC_VERS := $(wildcard /lib/modules/*/build) LOC_VERS := $(patsubst %/,%,$(dir $(LOC_VERS))) LOC_VERS := $(notdir $(LOC_VERS)) -RCE_DIRS := /afs/slac/g/cci/volumes/vol1/xilinx/linux-xlnx-v2015.2.03 -RCE_DIRS += /afs/slac/g/cci/volumes/vol1/xilinx/linux-xlnx-v2016.4 -RCE_DIRS += /afs/slac/g/cci/volumes/vol1/xilinx/backup/linux-xlnx-v2016.1.01 +RCE_DIRS := /afs/slac.stanford.edu/g/cci/volumes/vol1/xilinx/linux-xlnx-v2016.4 +RCE_DIRS += /afs/slac.stanford.edu/g/cci/volumes/vol1/xilinx/backup/linux-xlnx-v2016.1.01 -all: +all: @echo "Options: app driver rce" app: - @make -C $(MAKE_HOME)/exo_tem/app clean - @make -C $(MAKE_HOME)/exo_tem/app - @make -C $(MAKE_HOME)/pgpcard/app clean - @make -C $(MAKE_HOME)/pgpcard/app @make -C $(MAKE_HOME)/rce_stream/app clean @make -C $(MAKE_HOME)/rce_stream/app @make -C $(MAKE_HOME)/data_dev/app clean @@ -43,12 +34,6 @@ driver: @mkdir -p $(MAKE_HOME)/install; @ $(foreach ver,$(LOC_VERS), \ mkdir -p $(MAKE_HOME)/install/$(ver); \ - make -C $(MAKE_HOME)/exo_tem/driver KVER=$(ver) clean; \ - make -C $(MAKE_HOME)/exo_tem/driver KVER=$(ver); \ - scp $(MAKE_HOME)/exo_tem/driver/*.ko $(MAKE_HOME)/install/$(ver); \ - make -C $(MAKE_HOME)/pgpcard/driver KVER=$(ver) clean; \ - make -C $(MAKE_HOME)/pgpcard/driver KVER=$(ver); \ - scp $(MAKE_HOME)/pgpcard/driver/*.ko $(MAKE_HOME)/install/$(ver); \ make -C $(MAKE_HOME)/data_dev/driver KVER=$(ver) clean; \ make -C $(MAKE_HOME)/data_dev/driver KVER=$(ver); \ scp $(MAKE_HOME)/data_dev/driver/*.ko $(MAKE_HOME)/install/$(ver); \ @@ -65,4 +50,3 @@ rce: make -C $(MAKE_HOME)/rce_memmap/driver KDIR=$(d); \ scp $(MAKE_HOME)/rce_memmap/driver/*.ko $(MAKE_HOME)/install/$(shell make -C $(d) -s kernelversion).$(ARCH)/; \ ) - diff --git a/README.md b/README.md index 924ec1a..0b76d4d 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # aes-stream-drivers -Common repository for streaming kernel drivers (PGP, AxiStream, ExoTem) +Common repository for streaming kernel drivers (datadev, gpuDirect, petalinux, etc) @@ -24,18 +24,10 @@ Contains driver and application code for TID-AIR generic DAQ PCIe cards with Dir options datagpu cfgTxCount=1024 cfgRxCount=1024 cfgSize=131072 cfgMode=1 cfgCont=1 -#### exo_tem/ - -Contains driver and application code for EXO TEM. - #### include/ Contains top level application include files for all drivers -#### pgpcard/ - -Contains driver and application code for the pgpcard - #### rce_hp_buffers/ Contains driver that allocates memory blocks for use in a pure firmware dma engine @@ -48,7 +40,7 @@ Contains driver and application code for the RCE AXI stream DMA # How to build the non-RCE drivers -``` +```bash # Go to the base directory $ cd aes-stream-drivers @@ -63,7 +55,7 @@ $ make app # How to build the RCE drivers -``` +```bash # Go to the base directory $ cd aes-stream-drivers diff --git a/common/app_lib/McsRead.cpp b/common/app_lib/McsRead.cpp deleted file mode 100644 index e537af5..0000000 --- a/common/app_lib/McsRead.cpp +++ /dev/null @@ -1,375 +0,0 @@ -/** - *----------------------------------------------------------------------------- - * Title : Generic MCS File Reader - * ---------------------------------------------------------------------------- - * File : McsRead.cpp - * Author : Larry Ruckman - * Created : 10/14/2013 - * Last update : 08/11/2014 - *----------------------------------------------------------------------------- - * Description : - * Generic MCS File reader - *----------------------------------------------------------------------------- - * This file is part of the aes_stream_drivers package. It is subject to - * the license terms in the LICENSE.txt file found in the top-level directory - * of this distribution and at: - * https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html. - * No part of the aes_stream_drivers package, including this file, may be - * copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE.txt file. - *----------------------------------------------------------------------------- -**/ - -#include "McsRead.h" -#include -#include -#include -#include - -using namespace std; - -// Constructor -McsRead::McsRead ( ) { -} - -// Deconstructor -McsRead::~McsRead ( ) { -} - -// Open file -bool McsRead::open ( string filePath ) { - - promPntr = 16; - promBaseAddr = 0; - endOfFile = false; - - //attempt to open the file - file.open(filePath.c_str() ); - - //check if not opened - if ( !file.is_open() ) { - //show error message - cout << "McsRead::open error = "; - cout << "unable to open" << filePath << endl; - - //close the file - close(); - - //return error - return false; - } - else { - return true; - } -} - -//! Moves the ifstream to beginning of file -void McsRead::beg ( ) { - promPntr = 16; - promBaseAddr = 0; - endOfFile = false; - - file.clear(); - file.seekg(0, ios::beg); -} - -//! Open file -void McsRead::close ( ) { - //close the file - file.close(); -} - -//! Get Address space size file -uint32_t McsRead::startAddr ( ) { - int32_t status = -1; - beg(); - while( (status = next()) != 0); - beg(); - return promAddr[0]; -} - -//! Get end address -uint32_t McsRead::endAddr ( ) { - // Scan for end of file - while(1) { - // Check if need to read - if (!endOfFile) { - next(); - } - //check if end of file - if (endOfFile){ - break; - } - } - return promLastAddr; -} - -//! Get Address space size file -uint32_t McsRead::addrSize ( ) { - // Return the difference - return (endAddr() - startAddr()); -} - -// Get next memory data and address index -int32_t McsRead::read (McsReadData *mem) { - int32_t status = 0; - - //check if we need to read the next line - if(promPntr==16) { - while(1) { - //read the file if end of file is not detected - if (!endOfFile) { - status = next(); - } - - //check for end of file - if (endOfFile){ - mem->endOfFile = endOfFile; - return status; - } - //check for an error - else if (status<0) { - return status; - } - //check for a data read - else if (status==0) { - break; - } - } - } - - //collect the data - mem->address = promAddr[promPntr]; - mem->data = promData[promPntr]; - mem->endOfFile = false; - - //increment the pointer - promPntr++; - - return 0; -} - -// Get next data record -int32_t McsRead::next ( ) { - string line; - - char dataChar[2+1]; - char summing = 0; - char checkSum; - - uint32_t i; - uint32_t byteCnt; - uint32_t addr; - uint32_t recordType; - uint32_t data[16]; - - //check the ifstream status flag - if ( !file.good() ) { - //show error message - cout << "McsRead::next error = "; - cout << "file.good = false" << endl; - - //return error - return -1; - } - else{ - //readout a line - getline(file,line); - - //check for "start code" - if (line.at(0) != ':') { - //show error message - cout << "McsRead::next error = "; - cout << "missing start code" << endl; - cout << "\t line = " << line << endl; - //return error - return -1; - } - else { - //get byte count - dataChar[0] = line.at(1); - dataChar[1] = line.at(2); - dataChar[2] = '\0'; - sscanf(dataChar, "%x", &byteCnt); - summing += (char)(byteCnt); - - //get address index - dataChar[0] = line.at(3); - dataChar[1] = line.at(4); - dataChar[2] = '\0'; - sscanf(dataChar, "%x", &data[0]); - summing += (char)(data[0]); - - dataChar[0] = line.at(5); - dataChar[1] = line.at(6); - dataChar[2] = '\0'; - sscanf(dataChar, "%x", &data[1]); - summing += (char)(data[1]); - - addr = (data[0] << 8) | data[1]; - - //get record type - dataChar[0] = line.at(7); - dataChar[1] = line.at(8); - dataChar[2] = '\0'; - sscanf(dataChar, "%x", &recordType); - summing += (char)(recordType); - - //get the check sum in the line read - dataChar[0] = line.at(9+(2*byteCnt)); - dataChar[1] = line.at(10+(2*byteCnt)); - dataChar[2] = '\0'; - sscanf(dataChar, "%x", &data[0]); - checkSum = -1*(char)(data[0]); - - //check for an invalid byte count - if (byteCnt>16) { - //show error message - cout << "McsRead::next error = "; - cout << "Invalid byte count: "; - cout << byteCnt << endl; - cout << "\t line = " << line << endl; - return -1; - } - - //cout << "byteCnt: " << byteCnt << endl; - //cout << "addr: " << addr << endl; - //cout << "recordType: " << recordType << endl; - - //check the record type - switch ( recordType ) { - case 0://data record - - //check for an invalid byte count - if (byteCnt==0) { - //show error message - cout << "McsRead::next error = "; - cout << "Invalid byte count: "; - cout << byteCnt << endl; - cout << "\t line = " << line << endl; - return -1; - } - //collect the data - for(i=0;i=skim) { - skim += 5.0; - cout << "Erasing the PROM: " << floor(percentage) << " percent done" << endl; - } - } - cout << "Erasing completed" << endl; -} - -//! Write the .mcs file to the PROM -bool PciCardProm::writeBootProm ( ) { - if ( _large ) return(bufferedWriteBootProm()); - else return(unbufferedWriteBootProm()); -} - -//! Write the .mcs file to the PROM -bool PciCardProm::unbufferedWriteBootProm ( ) { - cout << "*******************************************************************" << endl; - cout << "Starting Writing ..." << endl; - McsRead mcsReader; - McsReadData mem; - - uint32_t address = 0; - uint16_t fileData; - double size = double(_promSize); - double percentage; - double skim = 0.0; - bool toggle = false; - - //check for valid file path - if ( !mcsReader.open(_filePath) ) { - mcsReader.close(); - cout << "mcsReader.close() = file path error" << endl; - return false; - } - - //reset the flags - mem.endOfFile = false; - - //read the entire mcs file - while(!mem.endOfFile) { - - //read a line of the mcs file - if (mcsReader.read(&mem)<0){ - cout << "mcsReader.close() = line read error" << endl; - mcsReader.close(); - return false; - } - - // Check if this is the upper or lower byte - if(!toggle) { - toggle = true; - fileData = (uint16_t)mem.data; - } else { - toggle = false; - fileData |= ((uint16_t)mem.data << 8); - programCommand(address,fileData); - address++; - percentage = (((double)address)/size)*100; - percentage *= 2.0;//factor of two from two 8-bit reads for every write 16 bit write - if(percentage>=skim) { - skim += 5.0; - cout << "Writing the PROM: " << percentage << " percent done" << endl; - } - } - } - - mcsReader.close(); - cout << "Writing completed" << endl; - return true; -} - -//! Write the .mcs file to the PROM -bool PciCardProm::bufferedWriteBootProm ( ) { - cout << "*******************************************************************" << endl; - cout << "Starting Writing ..." << endl; - McsRead mcsReader; - McsReadData mem; - - uint32_t address = 0; - uint16_t fileData; - uint16_t i; - - uint32_t bufAddr[256]; - uint16_t bufData[256]; - uint16_t bufSize = 0; - - double size = double(_promSize); - double percentage; - double skim = 5.0; - bool toggle = false; - - //check for valid file path - if ( !mcsReader.open(_filePath) ) { - mcsReader.close(); - cout << "mcsReader.close() = file path error" << endl; - return false; - } - - //reset the flags - mem.endOfFile = false; - - //read the entire mcs file - while(!mem.endOfFile) { - - //read a line of the mcs file - if (mcsReader.read(&mem)<0){ - cout << "mcsReader.close() = line read error" << endl; - mcsReader.close(); - return false; - } - - // Check if this is the upper or lower byte - if(!toggle) { - toggle = true; - fileData = (uint16_t)mem.data; - } else { - toggle = false; - fileData |= ((uint16_t)mem.data << 8); - - // Latch the values - bufAddr[bufSize] = address; - bufData[bufSize] = fileData; - bufSize++; - - // Check if we need to send the buffer - if(bufSize==256) { - bufferedProgramCommand(bufAddr,bufData,bufSize); - bufSize = 0; - } - - address++; - percentage = (((double)address)/size)*100; - percentage *= 2.0;//factor of two from two 8-bit reads for every write 16 bit write - if(percentage>=skim) { - skim += 5.0; - cout << "Writing the PROM: " << floor(percentage) << " percent done" << endl; - } - } - } - - // Check if we need to send the buffer - if(bufSize != 0) { - // Pad the end of the block with ones - for(i=bufSize;i<256;i++){ - bufData[bufSize] = 0xFFFF; - } - // Send the last block program - bufferedProgramCommand(bufAddr,bufData,256); - } - - mcsReader.close(); - cout << "Writing completed" << endl; - return true; -} - -//! Compare the .mcs file with the PROM (true=matches) -bool PciCardProm::verifyBootProm ( ) { - cout << "*******************************************************************" << endl; - cout << "Starting Verification ..." << endl; - McsRead mcsReader; - McsReadData mem; - - uint32_t address = 0; - uint16_t promData,fileData; - double size = double(_promSize); - double percentage; - double skim = 5.0; - bool toggle = false; - - //check for valid file path - if ( !mcsReader.open(_filePath) ) { - mcsReader.close(); - cout << "mcsReader.close() = file path error" << endl; - return(1); - } - - //reset the flags - mem.endOfFile = false; - - //read the entire mcs file - while(!mem.endOfFile) { - - //read a line of the mcs file - if (mcsReader.read(&mem)<0){ - cout << "mcsReader.close() = line read error" << endl; - mcsReader.close(); - return false; - } - - // Check if this is the upper or lower byte - if(!toggle) { - toggle = true; - fileData = (uint16_t)mem.data; - } else { - toggle = false; - fileData |= ((uint16_t)mem.data << 8); - promData = readWordCommand(address); - if(fileData != promData) { - cout << "verifyBootProm error = "; - cout << "invalid read back" << endl; - cout << hex << "\taddress: 0x" << address << endl; - cout << hex << "\tfileData: 0x" << fileData << endl; - cout << hex << "\tpromData: 0x" << promData << endl; - mcsReader.close(); - return false; - } - address++; - percentage = (((double)address)/size)*100; - percentage *= 2.0;//factore of two from two 8-bit reads for every write 16 bit write - if(percentage>=skim) { - skim += 5.0; - cout << "Verifying the PROM: " << floor(percentage) << " percent done" << endl; - } - } - } - - mcsReader.close(); - cout << "Verification completed" << endl; - cout << "*******************************************************************" << endl; - return true; -} - -//! Erase Command -void PciCardProm::eraseCommand(uint32_t address) { - uint16_t status = 0; - - // Unlock the Block - writeToFlash(address,0x60,0xD0); - - // Reset the status register - writeToFlash(address,0x50,0x50); - - // Send the erase command - writeToFlash(address,0x20,0xD0); - - while(1) { - // Get the status register - status = readFlash(address,0x70); - - // Check for erasing failure - if ( (status&0x20) != 0 ) { - - // Unlock the Block - writeToFlash(address,0x60,0xD0); - - // Reset the status register - writeToFlash(address,0x50,0x50); - - // Send the erase command - writeToFlash(address,0x20,0xD0); - - // Check for FLASH not busy - } else if ( (status&0x80) != 0 ) { - break; - } - } - - // Lock the Block - writeToFlash(address,0x60,0x01); -} - -//! Program Command -void PciCardProm::programCommand(uint32_t address, uint16_t data) { - uint16_t status = 0; - - // Unlock the Block - writeToFlash(address,0x60,0xD0); - - // Reset the status register - writeToFlash(address,0x50,0x50); - - // Send the program command - writeToFlash(address,0x40,data); - - while(1) { - // Get the status register - status = readFlash(address,0x70); - - // Check for programming failure - if ( (status&0x10) != 0 ) { - - // Unlock the Block - writeToFlash(address,0x60,0xD0); - - // Reset the status register - writeToFlash(address,0x50,0x50); - - // Send the program command - writeToFlash(address,0x40,data); - - // Check for FLASH not busy - } else if ( (status&0x80) != 0 ) { - break; - } - } - - // Lock the Block - writeToFlash(address,0x60,0x01); -} - -//! Buffered Program Command -void PciCardProm::bufferedProgramCommand(uint32_t *address, uint16_t *data, uint16_t size) { - uint16_t status = 0; - uint16_t i; - - // Unlock the Block - writeToFlash(address[0],0x60,0xD0); - - // Reset the status register - writeToFlash(address[0],0x50,0x50); - - // Send the buffer program command and size - writeToFlash(address[0],0xE8,(size-1)); - - // Load the buffer - for(i=0;i - * Created : 03/19/2014 - * Last update : 08/11/2014 - *----------------------------------------------------------------------------- - * Description : - * PciCard PROM C++ Class - *----------------------------------------------------------------------------- - * This file is part of the aes_stream_drivers package. It is subject to - * the license terms in the LICENSE.txt file found in the top-level directory - * of this distribution and at: - * https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html. - * No part of the aes_stream_drivers package, including this file, may be - * copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE.txt file. - *----------------------------------------------------------------------------- -**/ - -#ifndef __PCICARD_PROM_H__ -#define __PCICARD_PROM_H__ - -#include -#include -#include -#include - -#include -#include -#include - -using namespace std; - -//! Class to contain generic register data. -class PciCardProm { - public: - - //! Constructor - PciCardProm (int32_t fd, string pathToFile, bool large ); - - //! Deconstructor - ~PciCardProm ( ); - - //! Get the PROM size - uint32_t getPromSize (); - - //! Check if file exists - bool fileExist (); - - //! Erase the PROM - void eraseBootProm ( ); - - //! Write the .mcs file to the PROM - bool writeBootProm ( ); - - //! Compare the .mcs file with the PROM - bool verifyBootProm ( ); - - //! Print Reminder - void rebootReminder ( ); - - private: - // Local Variables - string _filePath; - bool _large; - int32_t _fd; - uint32_t _blockSize; - uint32_t _promSize; - - //! Write the .mcs file to the PROM - bool unbufferedWriteBootProm ( ); - - //! Write the .mcs file to the PROM - bool bufferedWriteBootProm ( ); - - //! Erase Command - void eraseCommand(uint32_t address); - - //! Program Command - void programCommand(uint32_t address, uint16_t data); - - //! Buffered Program Command - void bufferedProgramCommand(uint32_t *address, uint16_t *data, uint16_t size); - - //! Read FLASH memory Command - uint16_t readWordCommand(uint32_t address); - - //! Generic FLASH write Command - void writeToFlash(uint32_t address, uint16_t cmd, uint16_t data); - - //! Generic FLASH read Command - uint16_t readFlash(uint32_t address, uint16_t cmd); -}; -#endif diff --git a/common/driver/fpga_prom.c b/common/driver/fpga_prom.c deleted file mode 100755 index 0c56970..0000000 --- a/common/driver/fpga_prom.c +++ /dev/null @@ -1,87 +0,0 @@ -/** - *----------------------------------------------------------------------------- - * Title : Common FPGA Prom Functions - * ---------------------------------------------------------------------------- - * File : fpga_prom.c - * Created : 2017-03-16 - * ---------------------------------------------------------------------------- - * This file is part of the aes_stream_drivers package. It is subject to - * the license terms in the LICENSE.txt file found in the top-level directory - * of this distribution and at: - * https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html. - * No part of the aes_stream_drivers package, including this file, may be - * copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE.txt file. - * ---------------------------------------------------------------------------- -**/ - -#include -#include -#include - -// Prom Read -int32_t FpgaProm_Write(struct DmaDevice *dev, void * base, uint64_t arg) { - int32_t ret; - uint32_t tempVal; - - struct FpgaPromData prom; - struct FpgaProm_Reg *reg = (struct FpgaProm_Reg*)base; - - if ((ret = copy_from_user(&prom,(void *)arg,sizeof(struct FpgaPromData)))) { - dev_warn(dev->device,"PromWrite: copy_from_user failed. ret=%i, user=%p kern=%p\n", ret, (void *)arg, &prom); - return(-1); - } - - if ( dev->debug > 0 ) - dev_info(dev->device,"PromWrite: Addr=0x%x, Cmd=0x%x, Data=0x%x.\n", prom.address, prom.cmd, prom.data); - - // Set the data bus - tempVal = ( (prom.cmd << 16) | prom.data ); - iowrite32(tempVal,&(reg->promData)); - - asm("nop"); - - // Set the address bus and initiate the transfer - tempVal = (~0x80000000 & prom.address); - iowrite32(tempVal,&(reg->promAddr)); - asm("nop"); - return(0); -} - -// Prom write -int32_t FpgaProm_Read(struct DmaDevice *dev, void * base, uint64_t arg) { - int32_t ret; - uint32_t tempVal; - - struct FpgaPromData prom; - struct FpgaProm_Reg *reg = (struct FpgaProm_Reg*)base; - - if ((ret=copy_from_user(&prom,(void *)arg,sizeof(struct FpgaPromData)))) { - dev_warn(dev->device,"PromRead: copy_from_user failed. ret=%i, user=%p kern=%p\n", ret, (void *)arg, &prom); - return(-1); - } - - // Set the data bus - tempVal = ( (prom.cmd << 16) | 0xFF ); - iowrite32(tempVal,&(reg->promData)); - asm("nop"); - - // Set the address bus and initiate the transfer - tempVal = (0x80000000 | prom.address); - iowrite32(tempVal,&(reg->promAddr)); - asm("nop"); - - // Read the data register - prom.data = ioread32(&(reg->promRead)); - - if ( dev->debug > 0 ) - dev_info(dev->device,"PromRead: Addr=0x%x, Cmd=0x%x, Data=0x%x.\n", prom.address, prom.cmd, prom.data); - - // Return the data structure - if ((ret=copy_to_user((void *)arg,&prom,sizeof(struct FpgaPromData)))) { - dev_warn(dev->device,"PromRead: copy_to_user failed. ret=%i, user=%p kern=%p\n", ret, (void *)arg, &prom); - return(-1); - } - return(0); -} - diff --git a/common/driver/fpga_prom.h b/common/driver/fpga_prom.h deleted file mode 100755 index 65611dd..0000000 --- a/common/driver/fpga_prom.h +++ /dev/null @@ -1,36 +0,0 @@ -/** - *----------------------------------------------------------------------------- - * Title : Common FPGA Prom Functions - * ---------------------------------------------------------------------------- - * File : fpga_prom.h - * Created : 2017-03-16 - * ---------------------------------------------------------------------------- - * This file is part of the aes_stream_drivers package. It is subject to - * the license terms in the LICENSE.txt file found in the top-level directory - * of this distribution and at: - * https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html. - * No part of the aes_stream_drivers package, including this file, may be - * copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE.txt file. - * ---------------------------------------------------------------------------- -**/ -#ifndef __FPGA__PROM_H__ -#define __FPGA__PROM_H__ -#include -#include - -struct FpgaProm_Reg { - uint32_t promData; - uint32_t promAddr; - uint32_t promRead; - uint32_t promTest; -}; - -// Prom Read -int32_t FpgaProm_Write(struct DmaDevice *dev, void * base, uint64_t arg); - -// Prom write -int32_t FpgaProm_Read(struct DmaDevice *dev, void * base, uint64_t arg); - -#endif - diff --git a/exo_tem/app/Makefile b/exo_tem/app/Makefile deleted file mode 100644 index 3051db7..0000000 --- a/exo_tem/app/Makefile +++ /dev/null @@ -1,59 +0,0 @@ -# -# ---------------------------------------------------------------------------- -# Title : TEM applications makefile -# ---------------------------------------------------------------------------- -# File : Makefile -# Author : Ryan Herbst, rherbst@slac.stanford.edu -# Created : 2016-08-08 -# Last update: 2016-08-08 -# ---------------------------------------------------------------------------- -# Description: -# TEM applications makefile -# ---------------------------------------------------------------------------- -# This file is part of the aes_stream_driver package. It is subject to -# the license terms in the LICENSE.txt file found in the top-level directory -# of this distribution and at: -# https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html. -# No part of the aes_stream_driver package, including this file, may be -# copied, modified, propagated, or distributed except according to the terms -# contained in the LICENSE.txt file. -# ---------------------------------------------------------------------------- -# - -# Variables -HOME := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) -CC := $(CROSS_COMPILE)g++ -DEF := -BIN := $(HOME)/bin -OBJ := $(HOME)/.obj -CFLAGS := -Wall -I$(HOME)/../../common/app_lib -I$(HOME)/../../include/ -LFLAGS := -lpthread - -# Generic Sources -LIB_DIR := $(HOME)/../../common/app_lib -LIB_SRC := $(wildcard $(LIB_DIR)/*.cpp) -LIB_HDR := $(wildcard $(LIB_DIR)/*.h) -LIB := $(patsubst $(LIB_DIR)/%.cpp,$(OBJ)/%.o,$(LIB_SRC)) - -# Final Sources -SRC_DIR := $(HOME)/src -SRC_SRC := $(wildcard $(SRC_DIR)/*.cpp) -SRC := $(patsubst $(SRC_DIR)/%.cpp,$(BIN)/%,$(SRC_SRC)) - -# Targets -all: $(LIB) $(SRC) - -# Clean -clean: - @rm -f $(BIN)/* - @rm -f $(OBJ)/* - -# Compile Generic Sources -$(OBJ)/%.o: $(LIB_DIR)/%.cpp $(LIB_DIR)/%.h - @test -d $(OBJ) || mkdir $(OBJ) - @echo "Compiling $@"; $(CC) -c $(CFLAGS) $(CFLAGS32) $(DEF) -o $@ $< - -$(BIN)/%: $(SRC_DIR)/%.cpp $(LIB) - @test -d $(BIN) || mkdir $(BIN) - @echo "Compiling $@"; $(CC) $(CFLAGS) $(CFLAGS32) $(DEF) $(OBJ)/* -o $@ $< $(LFLAGS) - diff --git a/exo_tem/app/README.md b/exo_tem/app/README.md deleted file mode 100644 index 825ed2b..0000000 --- a/exo_tem/app/README.md +++ /dev/null @@ -1,16 +0,0 @@ -# How to cross-compile the test applications - -To cross-compile the test applications you need to define the `CROSS_COMPILE` variable when calling `make`. - -For example, to cross-compile the applications for the SLAC buildroot `2019.08` version, for the `x86_64` architecture, you should call `make` this way: - -```bash -$ make \ -CROSS_COMPILE=/afs/slac/package/linuxRT/buildroot-2019.08/host/linux-x86_64/x86_64/usr/bin/x86_64-buildroot-linux-gnu- -``` - -On the other hand, if you do not want to cross-compile the applications, and build it for the host instead, you need to call `make` without defining any variable: - -```bash -$ make -``` diff --git a/exo_tem/app/src/temGetStatus.cpp b/exo_tem/app/src/temGetStatus.cpp deleted file mode 100755 index b810602..0000000 --- a/exo_tem/app/src/temGetStatus.cpp +++ /dev/null @@ -1,99 +0,0 @@ -/** - *----------------------------------------------------------------------------- - * Title : TEM Read Status Utility - * ---------------------------------------------------------------------------- - * File : temGetStatus.cpp - * Author : Ryan Herbst, rherbst@slac.stanford.edu - * Created : 2016-08-08 - * Last update: 2016-08-08 - * ---------------------------------------------------------------------------- - * Description: - * Utility to read the TEM card status. - * ---------------------------------------------------------------------------- - * This file is part of the aes_stream_drivers package. It is subject to - * the license terms in the LICENSE.txt file found in the top-level directory - * of this distribution and at: - * https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html. - * No part of the aes_stream_drivers package, including this file, may be - * copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE.txt file. - * ---------------------------------------------------------------------------- -**/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -using namespace std; - -const char * argp_program_version = "temGetStatus 1.0"; -const char * argp_program_bug_address = "rherbst@slac.stanford.edu"; - -struct PrgArgs { - const char * path; -}; - -static struct PrgArgs DefArgs = { "/dev/temcard_0" }; - -static struct argp_option options[] = { - { "path", 'p', "PATH", OPTION_ARG_OPTIONAL, "Path of temcard device to use. Default=/dev/temcard_0.",0}, - {0} -}; - -static error_t parseArgs ( int key, char *arg, struct argp_state *state ) { - struct PrgArgs *args = (struct PrgArgs *)state->input; - - switch(key) { - case 'p': args->path = arg; break; - default: return ARGP_ERR_UNKNOWN; break; - } - return(0); -} - -static struct argp argp = {options,parseArgs,NULL,NULL}; - -int main (int argc, char **argv) { - TemInfo info; - PciStatus pciStatus; - int s; - struct PrgArgs args; - - memcpy(&args,&DefArgs,sizeof(struct PrgArgs)); - argp_parse(&argp,argc,argv,0,0,&args); - - if ( (s = open(args.path, O_RDWR)) <= 0 ) { - printf("Error opening %s\n",args.path); - return(1); - } - - temGetInfo(s,&info); - temGetPci(s,&pciStatus); - - printf("-------------- Card Info ------------------\n"); - printf(" Version : 0x%.8x\n",info.version); - printf(" Serial : 0x%.16lx\n",info.serial); - printf(" BuildStamp : %s\n",info.buildStamp); - printf(" PromPrgEn : %i\n",info.promPrgEn); - - printf("\n"); - printf("-------------- PCI Info -------------------\n"); - printf(" PciCommand : 0x%.4x\n",pciStatus.pciCommand); - printf(" PciStatus : 0x%.4x\n",pciStatus.pciStatus); - printf(" PciDCommand : 0x%.4x\n",pciStatus.pciDCommand); - printf(" PciDStatus : 0x%.4x\n",pciStatus.pciDStatus); - printf(" PciLCommand : 0x%.4x\n",pciStatus.pciLCommand); - printf(" PciLStatus : 0x%.4x\n",pciStatus.pciLStatus); - printf(" PciLinkState : 0x%x\n",pciStatus.pciLinkState); - printf(" PciFunction : 0x%x\n",pciStatus.pciFunction); - printf(" PciDevice : 0x%x\n",pciStatus.pciDevice); - printf(" PciBus : 0x%.2x\n",pciStatus.pciBus); - printf(" PciLanes : %i\n",pciStatus.pciLanes); - - close(s); -} - diff --git a/exo_tem/app/src/temPromLoad.cpp b/exo_tem/app/src/temPromLoad.cpp deleted file mode 100644 index dc7efc4..0000000 --- a/exo_tem/app/src/temPromLoad.cpp +++ /dev/null @@ -1,130 +0,0 @@ -/** - *----------------------------------------------------------------------------- - * Title : TEM Firmware Update Utility - * ---------------------------------------------------------------------------- - * File : temPromLoad.cpp - * Author : Ryan Herbst, rherbst@slac.stanford.edu - * Created : 2016-08-08 - * Last update: 2016-08-08 - * ---------------------------------------------------------------------------- - * Description: - * Utility to program the TEM card with new firmware. - * ---------------------------------------------------------------------------- - * This file is part of the aes_stream_drivers package. It is subject to - * the license terms in the LICENSE.txt file found in the top-level directory - * of this distribution and at: - * https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html. - * No part of the aes_stream_drivers package, including this file, may be - * copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE.txt file. - * ---------------------------------------------------------------------------- -**/ - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "PciCardProm.h" - -using namespace std; - -const char * argp_program_version = "temPromLoad 1.0"; -const char * argp_program_bug_address = "rherbst@slac.stanford.edu"; - -struct PrgArgs { - const char * path; - const char * file; -}; - -static struct PrgArgs DefArgs = { "/dev/temcard_0", "" }; - -static char args_doc[] = "promFile"; -static char doc[] = "\n PromFile is the appropriate .mcs file for the card."; - -static struct argp_option options[] = { - { "path", 'p', "PATH", OPTION_ARG_OPTIONAL, "Path of temcard device to use. Default=/dev/temcard_0.",0}, - {0} -}; - -error_t parseArgs ( int key, char *arg, struct argp_state *state ) { - struct PrgArgs *args = (struct PrgArgs *)state->input; - - switch(key) { - case 'p': args->path = arg; break; - case ARGP_KEY_ARG: - switch (state->arg_num) { - case 0: args->file = arg; break; - default: argp_usage(state); break; - } - break; - case ARGP_KEY_END: - if ( state->arg_num < 1) argp_usage(state); - break; - default: return ARGP_ERR_UNKNOWN; break; - } - return(0); -} - -static struct argp argp = {options,parseArgs,args_doc,doc}; - -int main (int argc, char **argv) { - int fd; - PciCardProm *prom; - struct PrgArgs args; - - memcpy(&args,&DefArgs,sizeof(struct PrgArgs)); - argp_parse(&argp,argc,argv,0,0,&args); - - if ( (fd = open(args.path, O_RDWR)) <= 0 ) { - printf("Error opening %s\n",args.path); - return(1); - } - - // Create the PciCardG3Prom object - prom = new PciCardProm(fd,args.file,true); - - // Check if the .mcs file exists - if(!prom->fileExist()){ - cout << "Error opening: " << args.file << endl; - delete prom; - close(fd); - return(1); - } - - // Erase the PROM - prom->eraseBootProm(); - - // Write the .mcs file to the PROM - if(!prom->writeBootProm()) { - cout << "Error in prom->bufferedWriteBootProm() function" << endl; - delete prom; - close(fd); - return(1); - } - - // Compare the .mcs file with the PROM - if(!prom->verifyBootProm()) { - cout << "Error in prom->verifyBootProm() function" << endl; - delete prom; - close(fd); - return(1); - } - - // Display Reminder - prom->rebootReminder(); - - // Close all the devices - delete prom; - close(fd); - return(0); -} diff --git a/exo_tem/app/src/temPromVerify.cpp b/exo_tem/app/src/temPromVerify.cpp deleted file mode 100644 index 15fa40b..0000000 --- a/exo_tem/app/src/temPromVerify.cpp +++ /dev/null @@ -1,116 +0,0 @@ -/** - *----------------------------------------------------------------------------- - * Title : TEM Firmware Verify Utility - * ---------------------------------------------------------------------------- - * File : temPromVerify.cpp - * Author : Ryan Herbst, rherbst@slac.stanford.edu - * Created : 2016-08-08 - * Last update: 2016-08-08 - * ---------------------------------------------------------------------------- - * Description: - * Utility to verify the firmware loaded in the TEM Card - * ---------------------------------------------------------------------------- - * This file is part of the aes_stream_drivers package. It is subject to - * the license terms in the LICENSE.txt file found in the top-level directory - * of this distribution and at: - * https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html. - * No part of the aes_stream_drivers package, including this file, may be - * copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE.txt file. - * ---------------------------------------------------------------------------- -**/ -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -using namespace std; - -const char * argp_program_version = "temPromVerify 1.0"; -const char * argp_program_bug_address = "rherbst@slac.stanford.edu"; - -struct PrgArgs { - const char * path; - const char * file; -}; - -static struct PrgArgs DefArgs = { "/dev/temcard_0", "" }; - -static char args_doc[] = "promFile"; -static char doc[] = "\n PromFile is the appropriate .mcs file for the card."; - -static struct argp_option options[] = { - { "path", 'p', "PATH", OPTION_ARG_OPTIONAL, "Path of temcard device to use. Default=/dev/temcard_0.",0}, - {0} -}; - -error_t parseArgs ( int key, char *arg, struct argp_state *state ) { - struct PrgArgs *args = (struct PrgArgs *)state->input; - - switch(key) { - case 'p': args->path = arg; break; - case ARGP_KEY_ARG: - switch (state->arg_num) { - case 0: args->file = arg; break; - default: argp_usage(state); break; - } - break; - case ARGP_KEY_END: - if ( state->arg_num < 1) argp_usage(state); - break; - default: return ARGP_ERR_UNKNOWN; break; - } - return(0); -} - -static struct argp argp = {options,parseArgs,args_doc,doc}; - -int main (int argc, char **argv) { - int fd; - PciCardProm *prom; - struct PrgArgs args; - - memcpy(&args,&DefArgs,sizeof(struct PrgArgs)); - argp_parse(&argp,argc,argv,0,0,&args); - - if ( (fd = open(args.path, O_RDWR)) <= 0 ) { - printf("Error opening %s\n",args.path); - return(1); - } - - // Create the PciCardProm object - prom = new PciCardProm(fd,args.file,true); - - // Check if the .mcs file exists - if(!prom->fileExist()){ - cout << "Error opening: " << args.file << endl; - delete prom; - close(fd); - return(1); - } - - // Compare the .mcs file with the PROM - if(!prom->verifyBootProm()) { - cout << "Error in prom->writeBootProm() function" << endl; - delete prom; - close(fd); - return(1); - } - - // Close all the devices - delete prom; - close(fd); - return(0); -} - diff --git a/exo_tem/app/src/temReadCmd.cpp b/exo_tem/app/src/temReadCmd.cpp deleted file mode 100644 index cc1313c..0000000 --- a/exo_tem/app/src/temReadCmd.cpp +++ /dev/null @@ -1,132 +0,0 @@ -/** - *----------------------------------------------------------------------------- - * Title : TEM read command utility - * ---------------------------------------------------------------------------- - * File : temReadCmd.cpp - * Author : Ryan Herbst, rherbst@slac.stanford.edu - * Created : 2016-08-08 - * Last update: 2016-08-08 - * ---------------------------------------------------------------------------- - * Description: - * This program will open up a tem card port and attempt to read data. - * ---------------------------------------------------------------------------- - * This file is part of the aes_stream_drivers package. It is subject to - * the license terms in the LICENSE.txt file found in the top-level directory - * of this distribution and at: - * https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html. - * No part of the aes_stream_drivers package, including this file, may be - * copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE.txt file. - * ---------------------------------------------------------------------------- -**/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -using namespace std; - -const char * argp_program_version = "temRead 1.0"; -const char * argp_program_bug_address = "rherbst@slac.stanford.edu"; - -struct PrgArgs { - const char * path; - uint32_t prbsDis; -}; - -static struct PrgArgs DefArgs = { "/dev/temcard_0", 0x0 }; - -static char args_doc[] = ""; -static char doc[] = ""; - -static struct argp_option options[] = { - { "path", 'p', "PATH", OPTION_ARG_OPTIONAL, "Path of temcard device to use. Default=/dev/temcard_0.",0}, - { "prbsdis", 'd', 0, OPTION_ARG_OPTIONAL, "Disable PRBS checking.",0}, - {0} -}; - -error_t parseArgs ( int key, char *arg, struct argp_state *state ) { - struct PrgArgs *args = (struct PrgArgs *)state->input; - - switch(key) { - case 'p': args->path = arg; break; - case 'd': args->prbsDis = 1; break; - default: return ARGP_ERR_UNKNOWN; break; - } - return(0); -} - -static struct argp argp = {options,parseArgs,args_doc,doc}; - -int main (int argc, char **argv) { - int32_t s; - int32_t ret; - int32_t count; - fd_set fds; - void * rxData; - uint32_t maxSize; - PrbsData prbs(32,4,1,2,6,31); - bool prbRes; - - struct PrgArgs args; - - struct timeval timeout; - - memcpy(&args,&DefArgs,sizeof(struct PrgArgs)); - argp_parse(&argp,argc,argv,0,0,&args); - - if ( (s = open(args.path, O_RDWR)) <= 0 ) { - printf("Error opening %s\n",args.path); - return(1); - } - temEnableCmdRead(s); - - maxSize = 1024*1024*2; - - if ((rxData = malloc(maxSize)) == NULL ) { - printf("Failed to allocate rxData!\n"); - return(0); - } - - count = 0; - prbRes = 0; - do { - - // Setup fds for select call - FD_ZERO(&fds); - FD_SET(s,&fds); - - // Setup select timeout for 1 second - timeout.tv_sec=2; - timeout.tv_usec=0; - - // Wait for Socket data ready - ret = select(s+1,&fds,NULL,NULL,&timeout); - if ( ret <= 0 ) { - printf("Read timeout\n"); - } - else { - - ret = temRead(s,rxData,maxSize); - - if ( ret < 0 ) printf("Read error. ret=%i\n",ret); - else if ( ret > 0 ) { - if ( args.prbsDis == 0 ) prbRes = prbs.processData(rxData,ret); - - count++; - printf("Read ret=%i, prbs=%i, count=%i\n",ret,prbRes,count); - } - } - } while ( 1 ); - - free(rxData); - - close(s); - return(0); -} - diff --git a/exo_tem/app/src/temReadData.cpp b/exo_tem/app/src/temReadData.cpp deleted file mode 100644 index 08b1966..0000000 --- a/exo_tem/app/src/temReadData.cpp +++ /dev/null @@ -1,132 +0,0 @@ -/** - *----------------------------------------------------------------------------- - * Title : TEM read data utility - * ---------------------------------------------------------------------------- - * File : temReadData.cpp - * Author : Ryan Herbst, rherbst@slac.stanford.edu - * Created : 2016-08-08 - * Last update: 2016-08-08 - * ---------------------------------------------------------------------------- - * Description: - * This program will open up a tem card port and attempt to read data. - * ---------------------------------------------------------------------------- - * This file is part of the aes_stream_drivers package. It is subject to - * the license terms in the LICENSE.txt file found in the top-level directory - * of this distribution and at: - * https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html. - * No part of the aes_stream_drivers package, including this file, may be - * copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE.txt file. - * ---------------------------------------------------------------------------- -**/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -using namespace std; - -const char * argp_program_version = "temRead 1.0"; -const char * argp_program_bug_address = "rherbst@slac.stanford.edu"; - -struct PrgArgs { - const char * path; - uint32_t prbsDis; -}; - -static struct PrgArgs DefArgs = { "/dev/temcard_0", 0x0 }; - -static char args_doc[] = ""; -static char doc[] = ""; - -static struct argp_option options[] = { - { "path", 'p', "PATH", OPTION_ARG_OPTIONAL, "Path of temcard device to use. Default=/dev/temcard_0.",0}, - { "prbsdis", 'd', 0, OPTION_ARG_OPTIONAL, "Disable PRBS checking.",0}, - {0} -}; - -error_t parseArgs ( int key, char *arg, struct argp_state *state ) { - struct PrgArgs *args = (struct PrgArgs *)state->input; - - switch(key) { - case 'p': args->path = arg; break; - case 'd': args->prbsDis = 1; break; - default: return ARGP_ERR_UNKNOWN; break; - } - return(0); -} - -static struct argp argp = {options,parseArgs,args_doc,doc}; - -int main (int argc, char **argv) { - int32_t s; - int32_t ret; - int32_t count; - fd_set fds; - void * rxData; - uint32_t maxSize; - PrbsData prbs(32,4,1,2,6,31); - bool prbRes; - - struct PrgArgs args; - - struct timeval timeout; - - memcpy(&args,&DefArgs,sizeof(struct PrgArgs)); - argp_parse(&argp,argc,argv,0,0,&args); - - if ( (s = open(args.path, O_RDWR)) <= 0 ) { - printf("Error opening %s\n",args.path); - return(1); - } - temEnableDataRead(s); - - maxSize = 1024*1024*2; - - if ((rxData = malloc(maxSize)) == NULL ) { - printf("Failed to allocate rxData!\n"); - return(0); - } - - count = 0; - prbRes = 0; - do { - - // Setup fds for select call - FD_ZERO(&fds); - FD_SET(s,&fds); - - // Setup select timeout for 1 second - timeout.tv_sec=2; - timeout.tv_usec=0; - - // Wait for Socket data ready - ret = select(s+1,&fds,NULL,NULL,&timeout); - if ( ret <= 0 ) { - printf("Read timeout\n"); - } - else { - - ret = temRead(s,rxData,maxSize); - - if ( ret < 0 ) printf("Read error. ret=%i\n",ret); - else if ( ret > 0 ) { - if ( args.prbsDis == 0 ) prbRes = prbs.processData(rxData,ret); - - count++; - printf("Read ret=%i, prbs=%i, count=%i\n",ret,prbRes,count); - } - } - } while ( 1 ); - - free(rxData); - - close(s); - return(0); -} - diff --git a/exo_tem/app/src/temSetDebug.cpp b/exo_tem/app/src/temSetDebug.cpp deleted file mode 100755 index 41007cd..0000000 --- a/exo_tem/app/src/temSetDebug.cpp +++ /dev/null @@ -1,90 +0,0 @@ -/** - *----------------------------------------------------------------------------- - * Title : TEM debug utility - * ---------------------------------------------------------------------------- - * File : temSetDebug.cpp - * Author : Ryan Herbst, rherbst@slac.stanford.edu - * Created : 2016-08-08 - * Last update: 2016-08-08 - * ---------------------------------------------------------------------------- - * Description: - * This program set the TEM driver debug level. - * ---------------------------------------------------------------------------- - * This file is part of the aes_stream_drivers package. It is subject to - * the license terms in the LICENSE.txt file found in the top-level directory - * of this distribution and at: - * https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html. - * No part of the aes_stream_drivers package, including this file, may be - * copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE.txt file. - * ---------------------------------------------------------------------------- -**/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -using namespace std; - -const char * argp_program_version = "temSetDebug 1.0"; -const char * argp_program_bug_address = "rherbst@slac.stanford.edu"; - -struct PrgArgs { - const char * path; - uint32_t level; -}; - -static struct PrgArgs DefArgs = { "/dev/temcard_0", 0x00 }; - -static char args_doc[] = "debugLevel"; -static char doc[] = "\n Debug level is either 0 or 1."; - -static struct argp_option options[] = { - { "path", 'p', "PATH", OPTION_ARG_OPTIONAL, "Path of temcard device to use. Default=/dev/temcard_0.",0}, - {0} -}; - -error_t parseArgs ( int key, char *arg, struct argp_state *state ) { - struct PrgArgs *args = (struct PrgArgs *)state->input; - - switch(key) { - case 'p': args->path = arg; break; - case ARGP_KEY_ARG: - switch (state->arg_num) { - case 0: args->level = strtol(arg,NULL,10); break; - default: argp_usage(state); break; - } - break; - case ARGP_KEY_END: - if ( state->arg_num < 1) argp_usage(state); - break; - default: return ARGP_ERR_UNKNOWN; break; - } - return(0); -} - -static struct argp argp = {options,parseArgs,args_doc,doc}; - -int main (int argc, char **argv) { - int s; - - struct PrgArgs args; - - memcpy(&args,&DefArgs,sizeof(struct PrgArgs)); - argp_parse(&argp,argc,argv,0,0,&args); - - if ( (s = open(args.path, O_RDWR)) <= 0 ) { - printf("Error opening %s\n",args.path); - return(1); - } - - printf("Setting debug level to %i\n",args.level); - dmaSetDebug(s,args.level); - close(s); -} - diff --git a/exo_tem/app/src/temSetLoop.cpp b/exo_tem/app/src/temSetLoop.cpp deleted file mode 100755 index 834becd..0000000 --- a/exo_tem/app/src/temSetLoop.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/** - *----------------------------------------------------------------------------- - * Title : TEM loopback utility - * ---------------------------------------------------------------------------- - * File : temSetLoop.cpp - * Author : Ryan Herbst, rherbst@slac.stanford.edu - * Created : 2016-08-08 - * Last update: 2016-08-08 - * ---------------------------------------------------------------------------- - * Description: - * This program set the PGP card loopback state for a lane. - * ---------------------------------------------------------------------------- - * This file is part of the aes_stream_drivers package. It is subject to - * the license terms in the LICENSE.txt file found in the top-level directory - * of this distribution and at: - * https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html. - * No part of the aes_stream_drivers package, including this file, may be - * copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE.txt file. - * ---------------------------------------------------------------------------- -**/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -using namespace std; - -const char * argp_program_version = "temSetLoop 1.0"; -const char * argp_program_bug_address = "rherbst@slac.stanford.edu"; - -struct PrgArgs { - const char * path; - uint32_t state; -}; - -static struct PrgArgs DefArgs = { "/dev/temcard_0", 0x00 }; - -static char args_doc[] = "enable"; -static char doc[] = "\n Enable is either 0 or 1."; - -static struct argp_option options[] = { - { "path", 'p', "PATH", OPTION_ARG_OPTIONAL, "Path of temcard device to use. Default=/dev/temcard_0.",0}, - {0} -}; - -error_t parseArgs ( int key, char *arg, struct argp_state *state ) { - struct PrgArgs *args = (struct PrgArgs *)state->input; - - switch(key) { - case 'p': args->path = arg; break; - case ARGP_KEY_ARG: - switch (state->arg_num) { - case 0: args->state = strtol(arg,NULL,10); break; - default: argp_usage(state); break; - } - break; - case ARGP_KEY_END: - if ( state->arg_num < 1) argp_usage(state); - break; - default: return ARGP_ERR_UNKNOWN; break; - } - return(0); -} - -static struct argp argp = {options,parseArgs,args_doc,doc}; - -int main (int argc, char **argv) { - int s; - struct PrgArgs args; - - memcpy(&args,&DefArgs,sizeof(struct PrgArgs)); - argp_parse(&argp,argc,argv,0,0,&args); - - if ( (s = open(args.path, O_RDWR)) <= 0 ) { - printf("Error opening %s\n",args.path); - return(1); - } - - temSetLoop(s,args.state); - close(s); -} - diff --git a/exo_tem/app/src/temWriteCmd.cpp b/exo_tem/app/src/temWriteCmd.cpp deleted file mode 100644 index 6941928..0000000 --- a/exo_tem/app/src/temWriteCmd.cpp +++ /dev/null @@ -1,139 +0,0 @@ -/** - *----------------------------------------------------------------------------- - * Title : TEM write command utility - * ---------------------------------------------------------------------------- - * File : temWriteCmd.cpp - * Author : Ryan Herbst, rherbst@slac.stanford.edu - * Created : 2016-08-08 - * Last update: 2016-08-08 - * ---------------------------------------------------------------------------- - * Description: - * Program to send command. Data is prbs - * ---------------------------------------------------------------------------- - * This file is part of the aes_stream_drivers package. It is subject to - * the license terms in the LICENSE.txt file found in the top-level directory - * of this distribution and at: - * https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html. - * No part of the aes_stream_drivers package, including this file, may be - * copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE.txt file. - * ---------------------------------------------------------------------------- -**/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -using namespace std; - -const char * argp_program_version = "temWriteCmd 1.0"; -const char * argp_program_bug_address = "rherbst@slac.stanford.edu"; - -struct PrgArgs { - const char * path; - uint32_t size; - uint32_t count; - uint32_t prbsDis; -}; - -static struct PrgArgs DefArgs = { "/dev/temcard_0", 1000, 1, 0 }; - -static char args_doc[] = ""; -static char doc[] = ""; - -static struct argp_option options[] = { - { "path", 'p', "PATH", OPTION_ARG_OPTIONAL, "Path of temcard device to use. Default=/dev/temcard_0.",0}, - { "prbsdis", 'd', 0, OPTION_ARG_OPTIONAL, "Disable PRBS generation.",0}, - { "size", 's', "SIZE", OPTION_ARG_OPTIONAL, "Size of data to generate. Default=1000",0}, - { "count", 'c', "COUNT", OPTION_ARG_OPTIONAL, "Number of frames to generate. Default=1",0}, - {0} -}; - -error_t parseArgs ( int key, char *arg, struct argp_state *state ) { - struct PrgArgs *args = (struct PrgArgs *)state->input; - - switch(key) { - case 'p': args->path = arg; break; - case 'd': args->prbsDis = 1; break; - case 's': args->size = strtol(arg,NULL,10); break; - case 'c': args->count = strtol(arg,NULL,10); break; - default: return ARGP_ERR_UNKNOWN; break; - } - return(0); -} - -static struct argp argp = {options,parseArgs,args_doc,doc}; - -int main (int argc, char **argv) { - int32_t s; - int32_t ret; - uint32_t count; - fd_set fds; - void * txData; - PrbsData prbs(32,4,1,2,6,31); - bool prbValid; - - struct timeval timeout; - struct PrgArgs args; - - memcpy(&args,&DefArgs,sizeof(struct PrgArgs)); - argp_parse(&argp,argc,argv,0,0,&args); - - if ( (s = open(args.path, O_RDWR)) <= 0 ) { - printf("Error opening %s\n",args.path); - return(1); - } - - if ((txData = malloc(args.size)) == NULL ) { - printf("Failed to allocate rxData!\n"); - return(0); - } - - prbValid = false; - count = 0; - do { - - // Setup fds for select call - FD_ZERO(&fds); - FD_SET(s,&fds); - - // Setup select timeout for 1 second - timeout.tv_sec=2; - timeout.tv_usec=0; - - // Wait for Socket data ready - ret = select(s+1,NULL,&fds,NULL,&timeout); - if ( ret <= 0 ) { - printf("Write timeout\n"); - } - else { - - // Gen data - if ( args.prbsDis == 0 && ! prbValid ) { - prbs.genData(txData,args.size); - prbValid = true; - } - - // DMA Write - ret = temWriteCmd(s,txData,args.size); - - if ( ret < 0 ) printf("Write error. ret=%i\n",ret); - if ( ret > 0 ) { - prbValid = false; - count++; - printf("Write ret=%i, count=%i\n",ret,count); - } - } - } while ( count < args.count ); - - free(txData); - - close(s); - return(0); -} - diff --git a/exo_tem/app/src/temWriteData.cpp b/exo_tem/app/src/temWriteData.cpp deleted file mode 100644 index 384f0d3..0000000 --- a/exo_tem/app/src/temWriteData.cpp +++ /dev/null @@ -1,139 +0,0 @@ -/** - *----------------------------------------------------------------------------- - * Title : TEM write data utility - * ---------------------------------------------------------------------------- - * File : temWriteData.cpp - * Author : Ryan Herbst, rherbst@slac.stanford.edu - * Created : 2016-08-08 - * Last update: 2016-08-08 - * ---------------------------------------------------------------------------- - * Description: - * Program to send data. Data is prbs - * ---------------------------------------------------------------------------- - * This file is part of the aes_stream_drivers package. It is subject to - * the license terms in the LICENSE.txt file found in the top-level directory - * of this distribution and at: - * https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html. - * No part of the aes_stream_drivers package, including this file, may be - * copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE.txt file. - * ---------------------------------------------------------------------------- -**/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -using namespace std; - -const char * argp_program_version = "temWriteData 1.0"; -const char * argp_program_bug_address = "rherbst@slac.stanford.edu"; - -struct PrgArgs { - const char * path; - uint32_t size; - uint32_t count; - uint32_t prbsDis; -}; - -static struct PrgArgs DefArgs = { "/dev/temcard_0", 1000, 1, 0 }; - -static char args_doc[] = ""; -static char doc[] = ""; - -static struct argp_option options[] = { - { "path", 'p', "PATH", OPTION_ARG_OPTIONAL, "Path of temcard device to use. Default=/dev/temcard_0.",0}, - { "prbsdis", 'd', 0, OPTION_ARG_OPTIONAL, "Disable PRBS generation.",0}, - { "size", 's', "SIZE", OPTION_ARG_OPTIONAL, "Size of data to generate. Default=1000",0}, - { "count", 'c', "COUNT", OPTION_ARG_OPTIONAL, "Number of frames to generate. Default=1",0}, - {0} -}; - -error_t parseArgs ( int key, char *arg, struct argp_state *state ) { - struct PrgArgs *args = (struct PrgArgs *)state->input; - - switch(key) { - case 'p': args->path = arg; break; - case 'd': args->prbsDis = 1; break; - case 's': args->size = strtol(arg,NULL,10); break; - case 'c': args->count = strtol(arg,NULL,10); break; - default: return ARGP_ERR_UNKNOWN; break; - } - return(0); -} - -static struct argp argp = {options,parseArgs,args_doc,doc}; - -int main (int argc, char **argv) { - int32_t s; - int32_t ret; - uint32_t count; - fd_set fds; - void * txData; - PrbsData prbs(32,4,1,2,6,31); - bool prbValid; - - struct timeval timeout; - struct PrgArgs args; - - memcpy(&args,&DefArgs,sizeof(struct PrgArgs)); - argp_parse(&argp,argc,argv,0,0,&args); - - if ( (s = open(args.path, O_RDWR)) <= 0 ) { - printf("Error opening %s\n",args.path); - return(1); - } - - if ((txData = malloc(args.size)) == NULL ) { - printf("Failed to allocate rxData!\n"); - return(0); - } - - prbValid = false; - count = 0; - do { - - // Setup fds for select call - FD_ZERO(&fds); - FD_SET(s,&fds); - - // Setup select timeout for 1 second - timeout.tv_sec=2; - timeout.tv_usec=0; - - // Wait for Socket data ready - ret = select(s+1,NULL,&fds,NULL,&timeout); - if ( ret <= 0 ) { - printf("Write timeout\n"); - } - else { - - // Gen data - if ( args.prbsDis == 0 && ! prbValid ) { - prbs.genData(txData,args.size); - prbValid = true; - } - - // DMA Write - ret = temWriteData(s,txData,args.size); - - if ( ret < 0 ) printf("Write error. ret=%i\n",ret); - if ( ret > 0 ) { - prbValid = false; - count++; - printf("Write ret=%i, count=%i\n",ret,count); - } - } - } while ( count < args.count ); - - free(txData); - - close(s); - return(0); -} - diff --git a/exo_tem/driver/Makefile b/exo_tem/driver/Makefile deleted file mode 100644 index acfcab8..0000000 --- a/exo_tem/driver/Makefile +++ /dev/null @@ -1,50 +0,0 @@ -# ---------------------------------------------------------------------------- -# Title : TEM driver makefile -# ---------------------------------------------------------------------------- -# File : Makefile -# Author : Ryan Herbst, rherbst@slac.stanford.edu -# Created : 2016-08-08 -# Last update: 2016-08-08 -# ---------------------------------------------------------------------------- -# Description: -# TEM card driver makefile -# ---------------------------------------------------------------------------- -# This file is part of the aes_stream_drivers package. It is subject to -# the license terms in the LICENSE.txt file found in the top-level directory -# of this distribution and at: -# https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html. -# No part of the aes_stream_drivers package, including this file, may be -# copied, modified, propagated, or distributed except according to the terms -# contained in the LICENSE.txt file. -# ---------------------------------------------------------------------------- - -NAME := temcard -HOME := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) -KVER := $(shell uname -r) -ARCH := $(shell uname -m) -CROSS_COMPILE := -KERNELDIR := /lib/modules/$(KVER)/build -SRCS := $(wildcard src/*.c) -OBJS := $(patsubst %.c,%.o,$(SRCS)) - -ifndef GITV - GITT := $(shell cd $(HOME); git describe --tags) - GITD := $(shell cd $(HOME); git status --short -uno | wc -l) - GITV := $(if $(filter $(GITD),0),$(GITT),$(GITT)-dirty) -endif - -ccflags-y := -I$(HOME)/../../include -ccflags-y += -I$(HOME)/src -ccflags-y += -DDMA_IN_KERNEL=1 -DGITV=\"$(GITV)\" - -$(NAME)-objs := src/dma_buffer.o src/dma_common.o src/fpga_prom.o -$(NAME)-objs += src/tem_gen3.o src/tem_top.o -obj-m := $(NAME).o - -all: - make ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) -C $(KERNELDIR) M=$(HOME) modules - -clean: - make ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) -C $(KERNELDIR) M=$(HOME) clean - rm -f $(OBJS) - diff --git a/exo_tem/driver/README.md b/exo_tem/driver/README.md deleted file mode 100644 index 8b89dd0..0000000 --- a/exo_tem/driver/README.md +++ /dev/null @@ -1,18 +0,0 @@ -# How to cross-compile the kernel driver - -To cross-compile the kernel driver you need to define the `ARCH` and `CROSS_COMPILE` variables when calling `make`. Also, you need to point `KERNELDIR` to the location of the kernel sources. - -For example, to cross-compile the driver for the SLAC buildroot `2019.08` version for the `x86_64` architecture, you should call `make` this way: - -```bash -$ make \ -ARCH=x86_64 \ -CROSS_COMPILE=/afs/slac/package/linuxRT/buildroot-2019.08/host/linux-x86_64/x86_64/usr/bin/x86_64-buildroot-linux-gnu- \ -KERNELDIR=/afs/slac/package/linuxRT/buildroot-2019.08/buildroot-2019.08-x86_64/output/build/linux-4.14.139 -``` - -On the other hand, if you do not want to cross-compile the driver, and build it for the host instead, you need to call `make` without defining any variable: - -```bash -$ make -``` diff --git a/exo_tem/driver/src/dma_buffer.c b/exo_tem/driver/src/dma_buffer.c deleted file mode 120000 index 0704713..0000000 --- a/exo_tem/driver/src/dma_buffer.c +++ /dev/null @@ -1 +0,0 @@ -../../../common/driver/dma_buffer.c \ No newline at end of file diff --git a/exo_tem/driver/src/dma_buffer.h b/exo_tem/driver/src/dma_buffer.h deleted file mode 120000 index 5d5b27c..0000000 --- a/exo_tem/driver/src/dma_buffer.h +++ /dev/null @@ -1 +0,0 @@ -../../../common/driver/dma_buffer.h \ No newline at end of file diff --git a/exo_tem/driver/src/dma_common.c b/exo_tem/driver/src/dma_common.c deleted file mode 120000 index 8d83891..0000000 --- a/exo_tem/driver/src/dma_common.c +++ /dev/null @@ -1 +0,0 @@ -../../../common/driver/dma_common.c \ No newline at end of file diff --git a/exo_tem/driver/src/dma_common.h b/exo_tem/driver/src/dma_common.h deleted file mode 120000 index f6606a0..0000000 --- a/exo_tem/driver/src/dma_common.h +++ /dev/null @@ -1 +0,0 @@ -../../../common/driver/dma_common.h \ No newline at end of file diff --git a/exo_tem/driver/src/fpga_prom.c b/exo_tem/driver/src/fpga_prom.c deleted file mode 120000 index 8795a1a..0000000 --- a/exo_tem/driver/src/fpga_prom.c +++ /dev/null @@ -1 +0,0 @@ -../../../common/driver/fpga_prom.c \ No newline at end of file diff --git a/exo_tem/driver/src/fpga_prom.h b/exo_tem/driver/src/fpga_prom.h deleted file mode 120000 index 0d2882e..0000000 --- a/exo_tem/driver/src/fpga_prom.h +++ /dev/null @@ -1 +0,0 @@ -../../../common/driver/fpga_prom.h \ No newline at end of file diff --git a/exo_tem/driver/src/tem_gen3.c b/exo_tem/driver/src/tem_gen3.c deleted file mode 100755 index d2362eb..0000000 --- a/exo_tem/driver/src/tem_gen3.c +++ /dev/null @@ -1,503 +0,0 @@ -/** - *----------------------------------------------------------------------------- - * Title : TEM Card Gen3 Functions - * ---------------------------------------------------------------------------- - * File : tem_gen3.c - * Author : Ryan Herbst, rherbst@slac.stanford.edu - * Created : 2016-08-11 - * Last update: 2016-08-11 - * ---------------------------------------------------------------------------- - * Description: - * Access functions for TEM. Based upon the PGP generation 3 card. - * ---------------------------------------------------------------------------- - * This file is part of the aes_stream_drivers package. It is subject to - * the license terms in the LICENSE.txt file found in the top-level directory - * of this distribution and at: - * https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html. - * No part of the aes_stream_drivers_package, including this file, may be - * copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE.txt file. - * ---------------------------------------------------------------------------- -**/ -#include -#include -#include -#include -#include -#include - -// Set functions for gen2 card -struct hardware_functions TemG3_functions = { - .irq = TemG3_Irq, - .init = TemG3_Init, - .enable = TemG3_Enable, - .clear = TemG3_Clear, - .retRxBuffer = TemG3_RetRxBuffer, - .sendBuffer = TemG3_SendBuffer, - .command = TemG3_Command, - .seqShow = TemG3_SeqShow -}; - -// Interrupt handler -irqreturn_t TemG3_Irq(int irq, void *dev_id) { - uint32_t stat; - uint32_t descA; - uint32_t descB; - uint32_t dmaId; - uint32_t subId; - irqreturn_t ret; - - struct DmaDesc * desc; - struct DmaBuffer * buff; - struct DmaDevice * dev; - struct TemG3Reg * reg; - - dev = (struct DmaDevice *)dev_id; - reg = (struct TemG3Reg *)dev->reg; - - // Read IRQ Status - stat = ioread32(&(reg->irq)); - asm("nop"); - - // Is this the source - if ( (stat & 0x2) != 0 ) { - - if ( dev->debug > 0 ) dev_info(dev->device,"Irq: IRQ Called.\n"); - - // Disable interrupts - iowrite32(0,&(reg->irq)); - - // Read Tx completion status - stat = ioread32(&(reg->txStat[1])); - asm("nop"); - - // Tx Data is ready - if ( (stat & 0x80000000) != 0 ) { - - do { - - // Read dma value - stat = ioread32(&(reg->txRead)); - asm("nop"); - - if ( (stat & 0x1) == 0x1 ) { - - if ( dev->debug > 0 ) - dev_info(dev->device,"Irq: Return TX Status Value %.8x.\n",stat); - - // Attempt to find buffer in tx pool and return. otherwise return rx entry to hw. - if ((buff = dmaRetBufferIrq (dev,stat&0xFFFFFFFC)) != NULL) { - iowrite32((stat & 0xFFFFFFFC), &(reg->rxFree[buff->owner])); - } - } - - // Repeat while next valid flag is set - } while ( (stat & 0x1) == 0x1 ); - } - - // Read Rx completion status - stat = ioread32(&(reg->rxStatus)); - asm("nop"); - - // Data is ready - if ( (stat & 0x80000000) != 0 ) { - do { - - // Read descriptor - descA = ioread32(&(reg->rxRead[0])); - asm("nop"); - descB = ioread32(&(reg->rxRead[1])); - asm("nop"); - - if ( ( descB & 0x1) == 0x1 ) { - - // Find RX buffer entry - if ((buff = dmaFindBufferList (&(dev->rxBuffers),descB&0xFFFFFFFC)) != NULL) { - - // Extract data from descriptor - buff->count++; - buff->flags = (descA >> 29) & 0x1; // Bit 29 (CONT) - dmaId = (descA >> 26) & 0x7; // Bits 28:26 - subId = (descA >> 24) & 0x3; // Bits 25:24 - buff->size = (descA & 0x00FFFFFF) * 4; // 23:00 - buff->error = 0; - - // Only two dma engines are used - buff->dest = dmaId; - - // Setup errors - if ( (descA >> 31) & 0x1) buff->error |= DMA_ERR_FIFO; - if ( (descA >> 30) & 0x1) buff->error |= TEM_ERR_EOFE; - - // Bit 1 of descB is the or of all errors, determine len error if others are not set - if (( (descB >> 1) & 0x1) && (buff->error == 0) ) buff->error |= DMA_ERR_LEN; - - if ( dev->debug > 0 ) { - dev_info(dev->device,"Irq: Rx Bytes=%i, Dest=%x, Error=0x%x, Cont=%i.\n", - buff->size, buff->dest, buff->error, buff->flags); - } - - // Lock mask records - // This ensures close does not occur while irq routine is - // pushing data to desc rx queue - spin_lock(&dev->maskLock); - - // Find owner of lane/vc - desc = dev->desc[buff->dest]; - - // Return entry to FPGA if lane/vc is not open - if ( desc == NULL ) { - if ( dev->debug > 0 ) { - dev_info(dev->device,"Irq: Port not open return to free list.\n"); - } - iowrite32((descB & 0xFFFFFFFC), &(reg->rxFree[(descA >> 26) & 0x7])); - } - - // lane/vc is open, Add to RX Queue - else dmaRxBuffer(desc,buff); - - // Unlock - spin_unlock(&dev->maskLock); - } - - // Buffer was not found - else dev_warn(dev->device,"Irq: Failed to locate RX descriptor %.8x.\n", - (uint32_t)(descB&0xFFFFFFFC)); - } - - // Repeat while next valid flag is set - } while ( (descB & 0x1) == 0x1 ); - } - - // Enable interrupts - if ( dev->debug > 0 ) - dev_info(dev->device,"Irq: Done.\n"); - iowrite32(1,&(reg->irq)); - ret = IRQ_HANDLED; - } - else ret = IRQ_NONE; - return(ret); -} - -// Init card in top level Probe -void TemG3_Init(struct DmaDevice *dev) { - uint32_t maxFrame; - uint32_t tmp; - uint64_t tmpL; - uint32_t x; - - struct DmaBuffer * buff; - struct TemInfo * info; - struct TemG3Reg * reg; - reg = (struct TemG3Reg *)dev->reg; - - // Remove card reset, bit 1 of control register - tmp = ioread32(&(reg->cardRstStat)); - tmp &= 0xFFFFFFFD; - iowrite32(tmp,&(reg->cardRstStat)); - - // Setup max frame value - maxFrame = dev->cfgSize; - maxFrame |= 0x80000000; - - // Set to hardware - iowrite32(maxFrame,&(reg->rxMaxFrame)); - - // Push receive buffers to hardware - // Distribute rx bufferes evently between free lists - for (x=dev->rxBuffers.baseIdx; x < (dev->rxBuffers.baseIdx + dev->rxBuffers.count); x++) { - buff = dmaGetBufferList(&(dev->rxBuffers),x); - - if ( dmaBufferToHw(buff) < 0 ) - dev_warn(dev->device,"Init: Failed to map dma buffer.\n"); - else { - iowrite32(buff->buffHandle,&(reg->rxFree[x % 8])); - buff->owner = (x % 8); - } - } - - // Init hardware info - dev->hwData = (void *)kmalloc(sizeof(struct TemInfo),GFP_KERNEL); - info = (struct TemInfo *)dev->hwData; - - memset(info,0,sizeof(struct TemInfo)); - - info->version = ioread32(&(reg->version)); - - // Form serial number - tmpL = ioread32(&(reg->serNumUpper)); - info->serial = tmpL << 32; - tmpL = ioread32(&(reg->serNumLower)); - info->serial |= tmpL; - - for (x=0; x < 64; x++) { - ((uint32_t *)info->buildStamp)[x] = ioread32((®->BuildStamp[x])); - } - memset(dev->destMask,0,DMA_MASK_SIZE); - dev->destMask[0] = 0x3; - info->promPrgEn = 1; - - dev_info(dev->device,"Init: Found card. Version=0x%x\n",info->version); -} - -// Enable the card -void TemG3_Enable(struct DmaDevice *dev) { - struct TemG3Reg * reg; - reg = (struct TemG3Reg *)dev->reg; - - // Enable interrupts - iowrite32(1,&(reg->irq)); -} - -// Clear card in top level Remove -void TemG3_Clear(struct DmaDevice *dev) { - uint32_t tmp; - struct TemG3Reg *reg; - reg = (struct TemG3Reg *)dev->reg; - - // Disable interrupts - iowrite32(0,&(reg->irq)); - - // Clear RX buffer - iowrite32(0,&(reg->rxMaxFrame)); - - // Set card reset, bit 1 of control register - tmp = ioread32(&(reg->cardRstStat)); - tmp |= 0x00000002; - iowrite32(tmp,&(reg->cardRstStat)); - - // Clear hw data - kfree(dev->hwData); -} - - -// Return receive buffer to card -// Single write so we don't need to lock -void TemG3_RetRxBuffer(struct DmaDevice *dev, struct DmaBuffer **buff, uint32_t count) { - struct TemG3Reg *reg; - uint32_t x; - - reg = (struct TemG3Reg *)dev->reg; - - for (x=0; x < count; x++) { - if ( dmaBufferToHw(buff[x]) < 0 ) - dev_warn(dev->device,"RetRxBuffer: Failed to map dma buffer.\n"); - else iowrite32(buff[x]->buffHandle,&(reg->rxFree[buff[x]->owner])); - } -} - - -// Send a buffer -int32_t TemG3_SendBuffer(struct DmaDevice *dev, struct DmaBuffer **buff, uint32_t count) { - uint32_t descA; - uint32_t descB; - uint32_t dmaId; - uint32_t subId; - uint32_t x; - - struct TemG3Reg * reg; - - reg = (struct TemG3Reg *)dev->reg; - - for (x=0; x < count; x++) { - - // each DMA lane is a destination - dmaId = buff[x]->dest; - subId = 0; - - if ( dmaBufferToHw(buff[x]) < 0 ) { - dev_warn(dev->device,"SendBuffer: Failed to map dma buffer.\n"); - return(-1); - } - - // Generate Tx descriptor - descA = (buff[x]->flags << 26) & 0x04000000; // Bits 26 = Cont - descA += (subId << 24) & 0x03000000; // Bits 25:24 = VC - descA += (buff[x]->size / 4 ) & 0x00FFFFFF; // Bits 23:0 = Length - descB = buff[x]->buffHandle; - - // Lock hw - spin_lock(&dev->writeHwLock); - - // Write descriptor - iowrite32(descA,&(reg->txWrA[dmaId])); - asm("nop"); - iowrite32(descB,&(reg->txWrB[dmaId])); - asm("nop"); - - // UnLock hw - spin_unlock(&dev->writeHwLock); - } - - return(count); -} - - -// Execute command -int32_t TemG3_Command(struct DmaDevice *dev, uint32_t cmd, uint64_t arg) { - uint32_t mask; - uint32_t tempLane; - uint32_t tempVal; - uint32_t tmp; - int32_t ret; - - struct TemInfo * info; - struct TemG3Reg * reg; - struct PciStatus pciStatus; - - reg = (struct TemG3Reg *)dev->reg; - info = (struct TemInfo * )dev->hwData; - - switch (cmd) { - - // Control loopback - case TEM_Set_Loop: - tempLane = arg & 0xFF; - tempVal = (arg >> 8) & 0x1; - - if ( tempLane > 8 ) return(0); - - spin_lock(&dev->commandLock); - - // Set loop - if ( tempVal ) { - tmp = ioread32(&(reg->pgpCardStat[0])); - tmp |= (0x1 << ((tempLane&0x7) + 0)); - iowrite32(tmp,&(reg->pgpCardStat[0])); - if (dev->debug > 0) dev_info(dev->device,"Set loopback for %u\n", tempLane); - - // Clear loop - } else { - mask = 0xFFFFFFFF ^ (0x1 << ((tempLane&0x7) + 0)); - tmp = ioread32(&(reg->pgpCardStat[0])); - tmp &= mask; - iowrite32(tmp,&(reg->pgpCardStat[0])); - if (dev->debug > 0) dev_info(dev->device,"Clr loopback for %u\n", tempLane); - } - spin_unlock(&dev->commandLock); - return(0); - break; - - // Read card info - case TEM_Read_Info: - if ((ret=copy_to_user((void *)arg,info,sizeof(struct TemInfo)))) { - dev_warn(dev->device,"Command: copy_to_user failed. ret=%i, user=%p kern=%p\n", - ret, (void *)arg, info); - return(-1); - } - return(0); - break; - - // Read PCI Status - case TEM_Read_Pci: - TemG3_GetPci(dev,&pciStatus); - - if ((ret=copy_to_user((void *)arg,&pciStatus,sizeof(struct PciStatus)))) { - dev_warn(dev->device,"Command: copy_to_user failed. ret=%i, user=%p kern=%p\n", - ret, (void *)arg, &pciStatus); - return(-1); - } - return(0); - break; - - // Write to prom - case FPGA_Write_Prom: - return(FpgaProm_Write(dev,reg->promRegs,arg)); - break; - - // Read from prom - case FPGA_Read_Prom: - return(FpgaProm_Read(dev,reg->promRegs,arg)); - break; - - default: - dev_warn(dev->device,"Command: Invalid command=%i\n",cmd); - return(-1); - break; - } - return(-1); -} - - -// Add data to proc dump -void TemG3_SeqShow(struct seq_file *s, struct DmaDevice *dev) { - uint32_t tmp; - - struct TemInfo * info; - struct TemG3Reg * reg; - struct PciStatus status; - - reg = (struct TemG3Reg *)dev->reg; - info = (struct TemInfo * )dev->hwData; - - seq_printf(s,"\n"); - seq_printf(s,"-------------- Card Info ------------------\n"); - seq_printf(s," Version : 0x%.8x\n",info->version); - seq_printf(s," Serial : 0x%.16llx\n",info->serial); - seq_printf(s," BuildStamp : %s\n",info->buildStamp); - seq_printf(s," PromPrgEn : %i\n",info->promPrgEn); - seq_printf(s,"\n"); - - TemG3_GetPci(dev,&status); - seq_printf(s,"-------------- PCI Info -------------------\n"); - seq_printf(s," PciCommand : 0x%.4x\n",status.pciCommand); - seq_printf(s," PciStatus : 0x%.4x\n",status.pciStatus); - seq_printf(s," PciDCommand : 0x%.4x\n",status.pciDCommand); - seq_printf(s," PciDStatus : 0x%.4x\n",status.pciDStatus); - seq_printf(s," PciLCommand : 0x%.4x\n",status.pciLCommand); - seq_printf(s," PciLStatus : 0x%.4x\n",status.pciLStatus); - seq_printf(s," PciLinkState : 0x%x\n",status.pciLinkState); - seq_printf(s," PciFunction : 0x%x\n",status.pciFunction); - seq_printf(s," PciDevice : 0x%x\n",status.pciDevice); - seq_printf(s," PciBus : 0x%.2x\n",status.pciBus); - seq_printf(s," PciLanes : %i\n",status.pciLanes); - seq_printf(s,"\n"); - seq_printf(s,"-------------- General HW -----------------\n"); - - seq_printf(s," TxCount : %i\n",ioread32(&(reg->txCount))); - seq_printf(s," RxCount : %i\n",ioread32(&(reg->rxCount))); - - tmp = ioread32(&(reg->rxStatus)); - seq_printf(s," RxStatusRaw : 0x%.8x\n",tmp); - seq_printf(s," RxReadReady : %i\n",(tmp >> 31)&0x1); - seq_printf(s," RxRetFifoCount : %i\n",tmp&0x3FF); - - tmp = ioread32(&(reg->txStat[1])); - seq_printf(s," TxReadReady : %i\n",(tmp >> 31)&0x1); - seq_printf(s," TxRetFifoCount : %i\n",tmp&0x3FF); - - seq_printf(s," CountReset : %i\n",(ioread32(&(reg->cardRstStat)) >> 0) & 0x1); - seq_printf(s," CardReset : %i\n",(ioread32(&(reg->cardRstStat)) >> 1) & 0x1); -} - - -// Get PCI Status -void TemG3_GetPci(struct DmaDevice *dev, struct PciStatus *status) { - uint32_t tmp; - - struct TemG3Reg *reg; - reg = (struct TemG3Reg *)dev->reg; - - memset(status,0,sizeof(struct PciStatus)); - - tmp = ioread32(&(reg->pciStat[0])); - status->pciCommand = ((tmp >> 16)&0xFFFF); - status->pciStatus = (tmp & 0xFFFF); - - tmp = ioread32(&(reg->pciStat[1])); - status->pciDCommand = ((tmp >> 16)&0xFFFF); - status->pciDStatus = (tmp & 0xFFFF); - - tmp = ioread32(&(reg->pciStat[2])); - status->pciLCommand = ((tmp >> 16)&0xFFFF); - status->pciLStatus = (tmp & 0xFFFF); - status->pciLanes = ((tmp >> 4) & 0x1F); - - tmp = ioread32(&(reg->pciStat[3])); - status->pciLinkState = ((tmp >> 24)&0x7); - status->pciFunction = ((tmp >> 16)&0x3); - status->pciDevice = ((tmp >> 8)&0xF); - status->pciBus = (tmp&0xFF); -} - - diff --git a/exo_tem/driver/src/tem_gen3.h b/exo_tem/driver/src/tem_gen3.h deleted file mode 100755 index a285a0f..0000000 --- a/exo_tem/driver/src/tem_gen3.h +++ /dev/null @@ -1,134 +0,0 @@ -/** - *----------------------------------------------------------------------------- - * Title : TEM Card Gen3 Functions - * ---------------------------------------------------------------------------- - * File : tem_gen3.h - * Author : Ryan Herbst, rherbst@slac.stanford.edu - * Created : 2016-08-11 - * Last update: 2016-08-11 - * ---------------------------------------------------------------------------- - * Description: - * Access functions for TEM. Based upon the PGP generation 3 card. - * ---------------------------------------------------------------------------- - * This file is part of the aes_stream_drivers package. It is subject to - * the license terms in the LICENSE.txt file found in the top-level directory - * of this distribution and at: - * https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html. - * No part of the aes_stream_drivers_package, including this file, may be - * copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE.txt file. - * ---------------------------------------------------------------------------- -**/ -#ifndef __TEM_GEN3_H__ -#define __TEM_GEN3_H__ - -#include -#include -#include -#include - -// Address Map, offset from base -struct TemG3Reg { - - //PciApp.vhd - uint32_t version; // Software_Addr = 0x000, Firmware_Addr(13 downto 2) = 0x000 - uint32_t serNumLower; // Software_Addr = 0x004, Firmware_Addr(13 downto 2) = 0x001 - uint32_t serNumUpper; // Software_Addr = 0x008, Firmware_Addr(13 downto 2) = 0x002 - uint32_t scratch; // Software_Addr = 0x00C, Firmware_Addr(13 downto 2) = 0x003 - uint32_t cardRstStat; // Software_Addr = 0x010, Firmware_Addr(13 downto 2) = 0x004 - uint32_t irq; // Software_Addr = 0x014, Firmware_Addr(13 downto 2) = 0x005 - uint32_t pgpRate; // Software_Addr = 0x018, Firmware_Addr(13 downto 2) = 0x006 - uint32_t vciMode; // Software_Addr = 0x01C, Firmware_Addr(13 downto 2) = 0x007 - uint32_t pgpOpCode; // Software_Addr = 0x020, Firmware_Addr(13 downto 2) = 0x008 - uint32_t sysSpare0[2]; // Software_Addr = 0x028:0x024, Firmware_Addr(13 downto 2) = 0x00A:0x009 - uint32_t pciStat[4]; // Software_Addr = 0x038:0x02C, Firmware_Addr(13 downto 2) = 0x00E:0x00B - uint32_t sysSpare1; // Software_Addr = 0x03C, Firmware_Addr(13 downto 2) = 0x00F - - uint32_t evrCardStat[5]; // Software_Addr = 0x050:0x040, Firmware_Addr(13 downto 2) = 0x012:0x010 - uint32_t evrSpare0[11]; // Software_Addr = 0x07C:0x054, Firmware_Addr(13 downto 2) = 0x01F:0x013 - - uint32_t pgpCardStat[2]; // Software_Addr = 0x084:0x080, Firmware_Addr(13 downto 2) = 0x021:0x020 - uint32_t pgpSpare0[54]; // Software_Addr = 0x15C:0x088, Firmware_Addr(13 downto 2) = 0x05F:0x022 - - uint32_t syncCode[8]; // Software_Addr = 0x17C:0x160, Firmware_Addr(13 downto 2) = 0x067:0x060 - uint32_t runCode[8]; // Software_Addr = 0x19C:0x180, Firmware_Addr(13 downto 2) = 0x067:0x060 - uint32_t acceptCode[8]; // Software_Addr = 0x1BC:0x1A0, Firmware_Addr(13 downto 2) = 0x06F:0x068 - - uint32_t runDelay[8]; // Software_Addr = 0x1DC:0x1C0, Firmware_Addr(13 downto 2) = 0x077:0x070 - uint32_t acceptDelay[8]; // Software_Addr = 0x1FC:0x1E0, Firmware_Addr(13 downto 2) = 0x07F:0x078 - - uint32_t pgpLaneStat[8]; // Software_Addr = 0x21C:0x200, Firmware_Addr(13 downto 2) = 0x087:0x080 - uint32_t evrRunCnt[8]; // Software_Addr = 0x23C:0x220, - uint32_t lutDropCnt[8]; // Software_Addr = 0x25C:0x240, - uint32_t acceptCnt[8]; // Software_Addr = 0x27C:0x260, - uint32_t pgpData[8]; // Software_Addr = 0x29C:0x280, - uint32_t pgpSpare1[24]; // Software_Addr = 0x2FC:0x2A0, - uint32_t BuildStamp[64]; // Software_Addr = 0x3FC:0x300, Firmware_Addr(13 downto 2) = 0x0FF:0x0C0 - - //PciRxDesc.vhd - uint32_t rxFree[8]; // Software_Addr = 0x41C:0x400, Firmware_Addr(13 downto 2) = 0x107:0x100 - uint32_t rxSpare0[24]; // Software_Addr = 0x47C:0x420, Firmware_Addr(13 downto 2) = 0x11F:0x108 - uint32_t rxFreeStat[8]; // Software_Addr = 0x49C:0x480, Firmware_Addr(13 downto 2) = 0x127:0x120 - uint32_t rxSpare1[24]; // Software_Addr = 0x4FC:0x4A0, Firmware_Addr(13 downto 2) = 0x13F:0x128 - uint32_t rxMaxFrame; // Software_Addr = 0x500, Firmware_Addr(13 downto 2) = 0x140 - uint32_t rxCount; // Software_Addr = 0x504, Firmware_Addr(13 downto 2) = 0x141 - uint32_t rxStatus; // Software_Addr = 0x508, Firmware_Addr(13 downto 2) = 0x142 - uint32_t rxRead[4]; // Software_Addr = 0x518:0x50C, Firmware_Addr(13 downto 2) = 0x146:0x143 - uint32_t rxSpare2[185]; // Software_Addr = 0x7FC:0x51C, Firmware_Addr(13 downto 2) = 0x1FF:0x147 - - //PciTxDesc.vhd - uint32_t txWrA[8]; // Software_Addr = 0x81C:0x800, Firmware_Addr(13 downto 2) = 0x207:0x200 - uint32_t txFifoCnt[8]; // Software_Addr = 0x83C:0x820, Firmware_Addr(13 downto 2) = 0x20F:0x208 - uint32_t txSpare0[16]; // Software_Addr = 0x87C:0x840, Firmware_Addr(13 downto 2) = 0x21F:0x210 - uint32_t txWrB[8]; // Software_Addr = 0x89C:0x880, Firmware_Addr(13 downto 2) = 0x227:0x220 - uint32_t txSpare1[24]; // Software_Addr = 0x8FC:0x8A0, Firmware_Addr(13 downto 2) = 0x23F:0x228 - uint32_t txStat[2]; // Software_Addr = 0x904:0x900, Firmware_Addr(13 downto 2) = 0x241:0x240 - uint32_t txCount; // Software_Addr = 0x908, Firmware_Addr(13 downto 2) = 0x242 - uint32_t txRead; // Software_Addr = 0x90C, Firmware_Addr(13 downto 2) = 0x243 - uint32_t txSpare[188]; // Software_Addr = 0x910:0xBFC - - uint32_t promRegs[3]; // Prom registers -}; - -// Set functions for gen3 card -extern struct hardware_functions TemG3_functions; - -// Interrupt handler -irqreturn_t TemG3_Irq(int irq, void *dev_id); - -// Init card in top level Probe -void TemG3_Init(struct DmaDevice *dev); - -// Enable -void TemG3_Enable(struct DmaDevice *dev); - -// Clear card in top level Remove -void TemG3_Clear(struct DmaDevice *dev); - -// Return receive buffer to card -void TemG3_RetRxBuffer(struct DmaDevice *dev, struct DmaBuffer **buff, uint32_t count); - -// Send a buffer -int32_t TemG3_SendBuffer(struct DmaDevice *dev, struct DmaBuffer **buff, uint32_t count); - -// Execute command -int32_t TemG3_Command(struct DmaDevice *dev, uint32_t cmd, uint64_t arg); - -// Add data to proc dump -void TemG3_SeqShow(struct seq_file *s, struct DmaDevice *dev); - -/////////////////////////////////// -// Local helper functions -/////////////////////////////////// - -// Get PCI Status -void TemG3_GetPci(struct DmaDevice *dev, struct PciStatus * status); - -// Prom Read -int32_t TemG3_PromWrite(struct DmaDevice *dev, uint64_t arg); - -// Prom write -int32_t TemG3_PromRead(struct DmaDevice *dev, uint64_t arg); - -#endif - diff --git a/exo_tem/driver/src/tem_top.c b/exo_tem/driver/src/tem_top.c deleted file mode 100755 index 60230ac..0000000 --- a/exo_tem/driver/src/tem_top.c +++ /dev/null @@ -1,200 +0,0 @@ -/** - *----------------------------------------------------------------------------- - * Title : Top level module - * ---------------------------------------------------------------------------- - * File : tem_top.c - * Author : Ryan Herbst, rherbst@slac.stanford.edu - * Created : 2016-08-08 - * Last update: 2016-08-08 - * ---------------------------------------------------------------------------- - * Description: - * Top level module types and functions. - * ---------------------------------------------------------------------------- - * This file is part of the aes_stream_drivers package. It is subject to - * the license terms in the LICENSE.txt file found in the top-level directory - * of this distribution and at: - * https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html. - * No part of the aes_stream_drivers_package, including this file, may be - * copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE.txt file. - * ---------------------------------------------------------------------------- -**/ -#include -#include -#include -#include -#include -#include -#include -#include -#include - -// Init Configuration values -int cfgTxCount = 32; -int cfgRxCount = 32; -int cfgSize = 2097152; -int cfgMode = BUFF_COHERENT; - -struct DmaDevice gDmaDevices[MAX_DMA_DEVICES]; - -// PCI device IDs -static struct pci_device_id Tem_Ids[] = { - { PCI_DEVICE(PCI_VENDOR_ID_SLAC, PCI_DEVICE_ID_TEM) }, - { 0, } -}; - -// Module Name -#define MOD_NAME "temcard" - -MODULE_LICENSE("GPL"); -MODULE_DEVICE_TABLE(pci, Tem_Ids); -module_init(Tem_Init); -module_exit(Tem_Exit); - -// PCI driver structure -static struct pci_driver TemDriver = { - .name = MOD_NAME, - .id_table = Tem_Ids, - .probe = Tem_Probe, - .remove = Tem_Remove, -}; - -// Init Kernel Module -int32_t Tem_Init(void) { - - /* Allocate and clear memory for all devices. */ - memset(gDmaDevices, 0, sizeof(struct DmaDevice)*MAX_DMA_DEVICES); - - pr_info("%s: Init\n", MOD_NAME); - - // Init structures - gCl = NULL; - gDmaDevCount = 0; - - // Register driver - return(pci_register_driver(&TemDriver)); -} - - -// Exit Kernel Module -void Tem_Exit(void) { - pr_info("%s: Exit\n", MOD_NAME); - pci_unregister_driver(&TemDriver); -} - - -// Create and init device -int Tem_Probe(struct pci_dev *pcidev, const struct pci_device_id *dev_id) { - struct DmaDevice *dev; - struct pci_device_id *id; - struct hardware_functions *hfunc; - - int32_t x; - int32_t dummy; - - if ( cfgMode != BUFF_COHERENT || cfgMode != BUFF_STREAM ) { - pr_warn("%s: Probe: Invalid buffer mode = %i.\n",MOD_NAME,cfgMode); - return(-1); - } - - // set hardware functions - hfunc = &(TemG3_functions); - - id = (struct pci_device_id *) dev_id; - - // We keep device instance number in id->driver_data - id->driver_data = -1; - - // Find empty structure - for (x = 0; x < MAX_DMA_DEVICES; x++) { - if (gDmaDevices[x].baseAddr == 0) { - id->driver_data = x; - break; - } - } - - // Overflow - if (id->driver_data < 0) { - pr_warn("%s: Probe: Too Many Devices.\n", MOD_NAME); - return (-1); - } - dev = &gDmaDevices[id->driver_data]; - dev->index = id->driver_data; - - // Increment count - gDmaDevCount++; - - // Create a device name - sprintf(dev->devName,"%s_%i",MOD_NAME,dev->index); - - // Enable the device - dummy = pci_enable_device(pcidev); - - // Get Base Address of registers from pci structure. - dev->baseAddr = pci_resource_start (pcidev, 0); - dev->baseSize = pci_resource_len (pcidev, 0); - - // Set configuration - dev->cfgTxCount = cfgTxCount; - dev->cfgRxCount = cfgRxCount; - dev->cfgSize = cfgSize; - dev->cfgMode = cfgMode; - - // Get IRQ from pci_dev structure. - dev->irq = pcidev->irq; - - // Set device fields - dev->device = &(pcidev->dev); - dev->hwFunc = hfunc; - - // Call common dma init function - return(Dma_Init(dev)); -} - - -// Cleanup device -void Tem_Remove(struct pci_dev *pcidev) { - uint32_t x; - - struct DmaDevice *dev = NULL; - - pr_info("%s: Remove: Remove called.\n", MOD_NAME); - - // Look for matching device - for (x = 0; x < MAX_DMA_DEVICES; x++) { - if ( gDmaDevices[x].baseAddr == pci_resource_start(pcidev, 0)) { - dev = &gDmaDevices[x]; - break; - } - } - - // Device not found - if (dev == NULL) { - pr_warn("%s: Remove: Device Not Found.\n", MOD_NAME); - return; - } - - // Decrement count - gDmaDevCount--; - - // Disable device - pci_disable_device(pcidev); - - // Call common dma init function - Dma_Clean(dev); - pr_info("%s: Remove: Driver is unloaded.\n", MOD_NAME); -} - -// Parameters -module_param(cfgTxCount,int,0); -MODULE_PARM_DESC(cfgTxCount, "TX buffer count"); - -module_param(cfgRxCount,int,0); -MODULE_PARM_DESC(cfgRxCount, "RX buffer count"); - -module_param(cfgSize,int,0); -MODULE_PARM_DESC(cfgSize, "Rx/TX Buffer size"); - -module_param(cfgMode,int,0); -MODULE_PARM_DESC(cfgMode, "RX buffer mode"); - diff --git a/exo_tem/driver/src/tem_top.h b/exo_tem/driver/src/tem_top.h deleted file mode 100755 index e663e10..0000000 --- a/exo_tem/driver/src/tem_top.h +++ /dev/null @@ -1,47 +0,0 @@ -/** - *----------------------------------------------------------------------------- - * Title : Top level module - * ---------------------------------------------------------------------------- - * File : tem_top.h - * Author : Ryan Herbst, rherbst@slac.stanford.edu - * Created : 2016-08-08 - * Last update: 2016-08-08 - * ---------------------------------------------------------------------------- - * Description: - * Top level module types and functions. - * ---------------------------------------------------------------------------- - * This file is part of the aes_stream_drivers package. It is subject to - * the license terms in the LICENSE.txt file found in the top-level directory - * of this distribution and at: - * https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html. - * No part of the aes_stream_drivers_package, including this file, may be - * copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE.txt file. - * ---------------------------------------------------------------------------- -**/ -#ifndef __TEM_TOP_H__ -#define __TEM_TOP_H__ - -#include -#include - -#define MAX_DMA_DEVICES 4 - -// PCI IDs -#define PCI_VENDOR_ID_SLAC 0x1a4a -#define PCI_DEVICE_ID_TEM 0x2020 - -// Init Kernel Module -int32_t Tem_Init(void); - -// Exit Kernel Module -void Tem_Exit(void); - -// Create and init device -int Tem_Probe(struct pci_dev *pcidev, const struct pci_device_id *dev_id); - -// Cleanup device -void Tem_Remove(struct pci_dev *pcidev); - -#endif - diff --git a/include/FpgaProm.h b/include/FpgaProm.h deleted file mode 100755 index 1222638..0000000 --- a/include/FpgaProm.h +++ /dev/null @@ -1,79 +0,0 @@ -/** - *----------------------------------------------------------------------------- - * Title : FPGA Prom Driver - * ---------------------------------------------------------------------------- - * File : FpgaProm.h - * Created : 2016-08-08 - * ---------------------------------------------------------------------------- - * Description: - * FPGA Prom Data - * ---------------------------------------------------------------------------- - * This file is part of the aes_stream_drivers package. It is subject to - * the license terms in the LICENSE.txt file found in the top-level directory - * of this distribution and at: - * https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html. - * No part of the aes_stream_drivers package, including this file, may be - * copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE.txt file. - * ---------------------------------------------------------------------------- -**/ -#ifndef __FPGA_PROM_H__ -#define __FPGA_PROM_H__ - -#ifdef DMA_IN_KERNEL -#include -#else -#include -#endif - -// Commands -#define FPGA_Write_Prom 0x1100 -#define FPGA_Read_Prom 0x1101 - -// Prom Programming -struct FpgaPromData { - uint32_t address; - uint32_t cmd; - uint32_t data; - uint32_t pad; -}; - -// Everything below is hidden during kernel module compile -#ifndef DMA_IN_KERNEL -#include -#include -#include -#include -#include -#include -#include -#include - -// Write to PROM -static inline ssize_t fpgaWriteProm(int32_t fd, uint32_t address, uint32_t cmd, uint32_t data) { - struct FpgaPromData prom; - - prom.address = address; - prom.cmd = cmd; - prom.data = data; - return(ioctl(fd,FPGA_Write_Prom,&prom)); -} - -// Read from PROM -static inline ssize_t fpgaReadProm(int32_t fd, uint32_t address, uint32_t cmd, uint32_t *data) { - struct FpgaPromData prom; - ssize_t res; - - prom.address = address; - prom.cmd = cmd; - prom.data = 0; - res = ioctl(fd,FPGA_Read_Prom,&prom); - - if ( data != NULL ) *data = prom.data; - - return(res); -} - -#endif -#endif - diff --git a/include/PgpDriver.h b/include/PgpDriver.h deleted file mode 100755 index 259a5bc..0000000 --- a/include/PgpDriver.h +++ /dev/null @@ -1,340 +0,0 @@ -/** - *----------------------------------------------------------------------------- - * Title : PGP Card Driver, Shared Header - * ---------------------------------------------------------------------------- - * File : PgpDriver.h - * Author : Ryan Herbst, rherbst@slac.stanford.edu - * Created : 2016-08-08 - * Last update: 2016-08-08 - * ---------------------------------------------------------------------------- - * Description: - * Defintions and inline functions for interacting with PGP driver. - * ---------------------------------------------------------------------------- - * This file is part of the aes_stream_drivers package. It is subject to - * the license terms in the LICENSE.txt file found in the top-level directory - * of this distribution and at: - * https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html. - * No part of the aes_stream_drivers package, including this file, may be - * copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE.txt file. - * ---------------------------------------------------------------------------- -**/ -#ifndef __PGP_DRIVER_H__ -#define __PGP_DRIVER_H__ -#include "DmaDriver.h" - -//! PGP Card Info -struct PgpInfo { - - //! PGP Card Serial # - uint64_t serial; - - //! PGP Card Type - uint32_t type; - - //! PGP Card Version - uint32_t version; - - //! PGP Card Lane Mask - uint32_t laneMask; - - //! PGP Card VCs per Lane Mask - uint32_t vcPerMask; - - //! PGP Card Line Rate - uint32_t pgpRate; - - //! PGP Card Prom Programming Support Flag - uint32_t promPrgEn; - - //! PGP Card EVR Support Flag - uint32_t evrSupport; - - uint32_t pad; - - char buildStamp[256]; -}; - -//! PCI Status -struct PciStatus { - - //! PCI Express Command Field - uint32_t pciCommand; - - //! PCI Express Status Field - uint32_t pciStatus; - - //! PCI Express D Command Field - uint32_t pciDCommand; - - //! PCI Express D Status Field - uint32_t pciDStatus; - - //! PCI Express L Command Field - uint32_t pciLCommand; - - //! PCI Express L Status Field - uint32_t pciLStatus; - - //! PCI Express Link State - uint32_t pciLinkState; - - //! PCI Express Function Number - uint32_t pciFunction; - - //! PCI Express Device Number - uint32_t pciDevice; - - //! PCI Express Bus Number - uint32_t pciBus; - - //! Number Of PCI Lanes - uint32_t pciLanes; - - uint32_t pad; -}; - -//! PGP Lane Status -struct PgpStatus { - - //! Lane number assocaited with this record - uint32_t lane; - - //! Lane loopback status - uint32_t loopBack; - - //! Lane local link ready status - uint32_t locLinkReady; - - //! Lane remote link ready status - uint32_t remLinkReady; - - //! Lane receive PLL ready status - uint32_t rxReady; - - //! Lane transmit PLL ready status - uint32_t txReady; - - //! Lane receive frame counter - uint32_t rxCount; - - //! Lane cell error counter - uint32_t cellErrCnt; - - //! Lane link lost transition counter - uint32_t linkDownCnt; - - //! Lane link error counter - uint32_t linkErrCnt; - - //! Lane FIFO error counter - uint32_t fifoErr; - - //! Lane current received remote sideband data - uint32_t remData; - - //! Lane remote buffer status - uint32_t remBuffStatus; - - uint32_t pad; -}; - -//! EVR Control, one per lane -struct PgpEvrControl { - - //! Lane number associated with this record - uint32_t lane; - - //! Global EVR enable for all lanes, 1 = enable, 0 = disabled - uint32_t evrEnable; // Global flag - - //! Run trigger enable for this lane, 1 = enable, 0 = disable - uint32_t laneRunMask; // 1 = Run trigger enable - - //! EVR Sync enable, 1 = start, 0 = stop - uint32_t evrSyncEn; // 1 = Start, 0 = Stop - - //! Sync select, 0 = async, 1 = sync for start/stop - uint32_t evrSyncSel; // 0 = async, 1 = sync for start/stop - - //! Header checking mask, 1 enable bit for each of 4 virtual channels. - uint32_t headerMask; // 1 = Enable header data checking, one bit per VC (4 bits) - - //! EVR Sync word, 32-bit timing fidicial to transition start/stop on - uint32_t evrSyncWord; // fiducial to transition start stop - - //! 8-bit timing code to assert run trigger - uint32_t runCode; // Run code - - //! Delay between timing code reception and assertion of run trigger - uint32_t runDelay; // Run delay - - //! 8-bit timing code to assert accept trigger - uint32_t acceptCode; // Accept code - - //! Delay between timing code reception and assertion of accept trigger - uint32_t acceptDelay; // Accept delay - - uint32_t pad; -}; - -//! EVR Status, one per lane -struct PgpEvrStatus { - - //! Lane number associated with this record - uint32_t lane; - - //! EVR link error counter - uint32_t linkErrors; - - //! EVR link up state, 0 = down, 1 = up - uint32_t linkUp; - - //! EVR running status, 0 = stopped, 1 = running - uint32_t runStatus; // 1 = Running, 0 = Stopped - - //! Current distributed timing seconds value - uint32_t evrSeconds; - - //! Number of run triggers received - uint32_t runCounter; - - //! Number of accepts triggers received - uint32_t acceptCounter; - - uint32_t pad; -}; - -// Card Types -#define PGP_NONE 0x00 -#define PGP_GEN1 0x01 -#define PGP_GEN2 0x02 -#define PGP_GEN2_VCI 0x12 -#define PGP_GEN3 0x03 -#define PGP_GEN3_VCI 0x13 - -// Error values -#define PGP_ERR_EOFE 0x10 - -// Commands -#define PGP_Read_Info 0x2001 -#define PGP_Read_Pci 0x2002 -#define PGP_Read_Status 0x2003 -#define PGP_Set_Loop 0x2004 -#define PGP_Count_Reset 0x2005 -#define PGP_Send_OpCode 0x2006 -#define PGP_Set_Data 0x2007 -#define PGP_Set_Evr_Cntrl 0x3001 -#define PGP_Get_Evr_Cntrl 0x3002 -#define PGP_Get_Evr_Status 0x3003 -#define PGP_Rst_Evr_Count 0x3004 - -// Everything below is hidden during kernel module compile -#ifndef DMA_IN_KERNEL - -static inline uint32_t pgpSetDest(uint32_t lane, uint32_t vc) { - uint32_t dest; - - dest = lane * 4; - dest += vc; - return(dest); -} - -static inline uint32_t pgpSetFlags(uint32_t cont){ - return(cont & 0x1); -} - -static inline uint32_t pgpGetLane(uint32_t dest) { - return(dest / 4); -} - -static inline uint32_t pgpGetVc(uint32_t dest) { - return(dest % 4); -} - -static inline uint32_t pgpGetCont(uint32_t flags) { - return(flags & 0x1); -} - -// Read Card Info -static inline ssize_t pgpGetInfo(int32_t fd, struct PgpInfo * info) { - return(ioctl(fd,PGP_Read_Info,info)); -} - -// Read PCI Status -static inline ssize_t pgpGetPci(int32_t fd, struct PciStatus * status) { - return(ioctl(fd,PGP_Read_Pci,status)); -} - -// Read Lane Status -static inline ssize_t pgpGetStatus(int32_t fd, uint32_t lane, struct PgpStatus * status) { - status->lane = lane; - return(ioctl(fd,PGP_Read_Status,status)); -} - -// Set Loopback State For Lane -static inline ssize_t pgpSetLoop(int32_t fd, uint32_t lane, uint32_t state) { - uint32_t temp; - - temp = lane & 0xFF; - temp |= ((state << 8) & 0x100); - - return(ioctl(fd,PGP_Set_Loop,temp)); -} - -// Reset counters -static inline ssize_t pgpCountReset(int32_t fd) { - return(ioctl(fd,PGP_Count_Reset,0)); -} - -// Set Sideband Data -static inline ssize_t pgpSetData(int32_t fd, uint32_t lane, uint32_t data) { - uint32_t temp; - - temp = lane & 0xFF; - temp |= ((data << 8) & 0xFF00); - - return(ioctl(fd,PGP_Set_Data,temp)); -} - -// Send OpCode -static inline ssize_t pgpSendOpCode(int32_t fd, uint32_t code) { - return(ioctl(fd,PGP_Send_OpCode,code)); -} - -// Set EVR Control -static inline ssize_t pgpSetEvrControl(int32_t fd, uint32_t lane, struct PgpEvrControl * control) { - control->lane = lane; - return(ioctl(fd,PGP_Set_Evr_Cntrl,control)); -} - -// Get EVR Control -static inline ssize_t pgpGetEvrControl(int32_t fd, uint32_t lane, struct PgpEvrControl * control) { - control->lane = lane; - return(ioctl(fd,PGP_Get_Evr_Cntrl,control)); -} - -// Get EVR Status -static inline ssize_t pgpGetEvrStatus(int32_t fd, uint32_t lane, struct PgpEvrStatus * status) { - status->lane = lane; - return(ioctl(fd,PGP_Get_Evr_Status,status)); -} - -// Reset EVR Counters -static inline ssize_t pgpResetEvrCount(int32_t fd, uint32_t lane) { - return(ioctl(fd,PGP_Rst_Evr_Count,lane)); -} - -// Add destination to mask byte array -static inline void pgpAddMaskBytes(uint8_t * mask, uint32_t lane, uint32_t vc) { - dmaAddMaskBytes(mask,lane*4+vc); -} - -// set lane/vc rx mask, one bit per vc -static inline ssize_t pgpSetMask(int32_t fd, uint32_t lane, uint32_t vc) { - return(dmaSetMask(fd, lane*4+vc)); -} - -#endif -#endif - diff --git a/include/TemDriver.h b/include/TemDriver.h deleted file mode 100755 index 15e6d0a..0000000 --- a/include/TemDriver.h +++ /dev/null @@ -1,117 +0,0 @@ -/** - *----------------------------------------------------------------------------- - * Title : TEM Card Driver, Shared Header - * ---------------------------------------------------------------------------- - * File : TemDriver.h - * Author : Ryan Herbst, rherbst@slac.stanford.edu - * Created : 2016-08-08 - * Last update: 2016-08-08 - * ---------------------------------------------------------------------------- - * Description: - * Defintions and inline functions for interacting with TEM driver. - * ---------------------------------------------------------------------------- - * This file is part of the aes_stream_drivers package. It is subject to - * the license terms in the LICENSE.txt file found in the top-level directory - * of this distribution and at: - * https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html. - * No part of the aes_stream_drivers package, including this file, may be - * copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE.txt file. - * ---------------------------------------------------------------------------- -**/ -#ifndef __TEM_DRIVER_H__ -#define __TEM_DRIVER_H__ -#include -#include - -// Card Info -struct TemInfo { - uint64_t serial; - uint32_t version; - uint32_t promPrgEn; - char buildStamp[256]; -}; - -// PCI Info -struct PciStatus { - uint32_t pciCommand; - uint32_t pciStatus; - uint32_t pciDCommand; - uint32_t pciDStatus; - uint32_t pciLCommand; - uint32_t pciLStatus; - uint32_t pciLinkState; - uint32_t pciFunction; - uint32_t pciDevice; - uint32_t pciBus; - uint32_t pciLanes; - uint32_t pad; -}; - -// Error values -#define TEM_ERR_EOFE 0x10 - -// Commands -#define TEM_Read_Info 0x2001 -#define TEM_Read_Pci 0x2002 -#define TEM_Set_Loop 0x2004 -#define TEM_Count_Reset 0x2005 - -// Destination -#define TEM_DEST_CMD 0 -#define TEM_DEST_DATA 1 - -// Everything below is hidden during kernel module compile -#ifndef DMA_IN_KERNEL - -// Enable command reads, call only once -static inline int32_t temEnableCmdRead(int32_t fd) { - return(dmaSetMask(fd,1 << TEM_DEST_CMD)); -} - -// Enable data reads, call only once -static inline int32_t temEnableDataRead(int32_t fd) { - return(dmaSetMask(fd,1 << TEM_DEST_DATA)); -} - -// Write to TEM command channel -static inline ssize_t temWriteCmd(int32_t fd, const void *buf, size_t count) { - return(dmaWrite(fd,buf,count,0,TEM_DEST_CMD)); -} - -// Write to TEM data channel -static inline ssize_t temWriteData(int32_t fd, const void *buf, size_t count) { - return(dmaWrite(fd,buf,count,0,TEM_DEST_DATA)); -} - -// Read from TEM channel -static inline ssize_t temRead(int fd, void *buf, size_t count) { - uint32_t error; - uint32_t ret; - ret = dmaRead(fd,buf,count,NULL,&error,NULL); - return(error==0?ret:-1); -} - -// Read Card Info -static inline ssize_t temGetInfo(int32_t fd, struct TemInfo * info) { - return(ioctl(fd,TEM_Read_Info,info)); -} - -// Read PCI Status -static inline ssize_t temGetPci(int32_t fd, struct PciStatus * status) { - return(ioctl(fd,TEM_Read_Pci,status)); -} - -// Set Loopback State -static inline ssize_t temSetLoop(int32_t fd, uint32_t state) { - uint32_t temp; - - temp = 0x3; - temp |= ((state << 8) & 0x100); - - return(ioctl(fd,TEM_Set_Loop,temp)); -} - -#endif -#endif - diff --git a/pgpcard/app/Makefile b/pgpcard/app/Makefile deleted file mode 100644 index e3e7d66..0000000 --- a/pgpcard/app/Makefile +++ /dev/null @@ -1,60 +0,0 @@ -# -# ---------------------------------------------------------------------------- -# Title : PGP applications makefile -# ---------------------------------------------------------------------------- -# File : Makefile -# Author : Ryan Herbst, rherbst@slac.stanford.edu -# Created : 2016-08-08 -# Last update: 2016-08-08 -# ---------------------------------------------------------------------------- -# Description: -# PGP applications makefile -# ---------------------------------------------------------------------------- -# This file is part of the aes_stream_drivers package. It is subject to -# the license terms in the LICENSE.txt file found in the top-level directory -# of this distribution and at: -# https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html. -# No part of the aes_stream_drivers package, including this file, may be -# copied, modified, propagated, or distributed except according to the terms -# contained in the LICENSE.txt file. -# ---------------------------------------------------------------------------- -# - -# Variables -HOME := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) -CC := $(CROSS_COMPILE)g++ -DEF := -BIN := $(HOME)/bin -OBJ := $(HOME)/.obj -CFLAGS := -Wall -I$(HOME)/../../include/ -I$(HOME)/../../common/app_lib/ -LFLAGS := -lpthread - -# Generic Sources -LIB_DIR := $(HOME)/../../common/app_lib/ -LIB_SRC := $(wildcard $(LIB_DIR)/*.cpp) -LIB_HDR := $(wildcard $(LIB_DIR)/*.h) -LIB_OBJ := $(patsubst $(LIB_DIR)/%.cpp,$(OBJ)/%.o,$(LIB_SRC)) - -# Application Sources -APP_DIR := $(HOME)/src -APP_SRC := $(wildcard $(APP_DIR)/*.cpp) -APP_BIN := $(patsubst $(APP_DIR)/%.cpp,$(BIN)/%,$(APP_SRC)) - -# Targets -all: $(LIB_OBJ) $(APP_BIN) - -# Clean -clean: - @rm -f $(BIN)/* - @rm -f $(OBJ)/* - -# Compile Generic Sources -$(OBJ)/%.o: $(LIB_DIR)/%.cpp $(LIB_DIR)/%.h - @test -d $(OBJ) || mkdir $(OBJ) - @echo "Compiling $@ from $<"; $(CC) -c $(CFLAGS) $(DEF) -o $@ $< - -# Application sources -$(BIN)/%: $(APP_DIR)/%.cpp $(LIB_OBJ) - @test -d $(BIN) || mkdir $(BIN) - @echo "Compiling $@ from $<"; $(CC) $(CFLAGS) $(CFLAGS32) $(DEF) $(LIB_OBJ) -o $@ $< $(LFLAGS) - diff --git a/pgpcard/app/README.md b/pgpcard/app/README.md deleted file mode 100644 index 825ed2b..0000000 --- a/pgpcard/app/README.md +++ /dev/null @@ -1,16 +0,0 @@ -# How to cross-compile the test applications - -To cross-compile the test applications you need to define the `CROSS_COMPILE` variable when calling `make`. - -For example, to cross-compile the applications for the SLAC buildroot `2019.08` version, for the `x86_64` architecture, you should call `make` this way: - -```bash -$ make \ -CROSS_COMPILE=/afs/slac/package/linuxRT/buildroot-2019.08/host/linux-x86_64/x86_64/usr/bin/x86_64-buildroot-linux-gnu- -``` - -On the other hand, if you do not want to cross-compile the applications, and build it for the host instead, you need to call `make` without defining any variable: - -```bash -$ make -``` diff --git a/pgpcard/app/src/pgpGetStatus.cpp b/pgpcard/app/src/pgpGetStatus.cpp deleted file mode 100755 index 39f01c7..0000000 --- a/pgpcard/app/src/pgpGetStatus.cpp +++ /dev/null @@ -1,127 +0,0 @@ -/** - *----------------------------------------------------------------------------- - * Title : PGP Read Status Utility - * ---------------------------------------------------------------------------- - * File : pgpGetStatus.cpp - * Author : Ryan Herbst, rherbst@slac.stanford.edu - * Created : 2016-08-08 - * Last update: 2016-08-08 - * ---------------------------------------------------------------------------- - * Description: - * Utility to read the PGP card status. - * ---------------------------------------------------------------------------- - * This file is part of the aes_stream_drivers package. It is subject to - * the license terms in the LICENSE.txt file found in the top-level directory - * of this distribution and at: - * https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html. - * No part of the aes_stream_drivers package, including this file, may be - * copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE.txt file. - * ---------------------------------------------------------------------------- -**/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -using namespace std; - -const char * argp_program_version = "pgpGetStatus 1.0"; -const char * argp_program_bug_address = "rherbst@slac.stanford.edu"; - -struct PrgArgs { - const char * path; -}; - -static struct PrgArgs DefArgs = { "/dev/pgpcard_0" }; - -static struct argp_option options[] = { - { "path", 'p', "PATH", OPTION_ARG_OPTIONAL, "Path of pgpcard device to use. Default=/dev/pgpcard_0.",0}, - {0} -}; - -static error_t parseArgs ( int key, char *arg, struct argp_state *state ) { - struct PrgArgs *args = (struct PrgArgs *)state->input; - - switch(key) { - case 'p': args->path = arg; break; - default: return ARGP_ERR_UNKNOWN; break; - } - return(0); -} - -static struct argp argp = {options,parseArgs,NULL,NULL}; - -int main (int argc, char **argv) { - PgpInfo info; - PgpStatus status; - PciStatus pciStatus; - int s; - int x; - struct PrgArgs args; - - memcpy(&args,&DefArgs,sizeof(struct PrgArgs)); - argp_parse(&argp,argc,argv,0,0,&args); - - if ( (s = open(args.path, O_RDWR)) <= 0 ) { - printf("Error opening %s\n",args.path); - return(1); - } - - pgpGetInfo(s,&info); - pgpGetPci(s,&pciStatus); - - printf("-------------- Card Info ------------------\n"); - printf(" Type : 0x%.2x\n",info.type); - printf(" Version : 0x%.8x\n",info.version); - printf(" Serial : 0x%.16lx\n",info.serial); - printf(" BuildStamp : %s\n",info.buildStamp); - printf(" LaneMask : 0x%.4x\n",info.laneMask); - printf(" VcPerMask : 0x%.2x\n",info.vcPerMask); - printf(" PgpRate : %i\n",info.pgpRate); - printf(" PromPrgEn : %i\n",info.promPrgEn); - - printf("\n"); - printf("-------------- PCI Info -------------------\n"); - printf(" PciCommand : 0x%.4x\n",pciStatus.pciCommand); - printf(" PciStatus : 0x%.4x\n",pciStatus.pciStatus); - printf(" PciDCommand : 0x%.4x\n",pciStatus.pciDCommand); - printf(" PciDStatus : 0x%.4x\n",pciStatus.pciDStatus); - printf(" PciLCommand : 0x%.4x\n",pciStatus.pciLCommand); - printf(" PciLStatus : 0x%.4x\n",pciStatus.pciLStatus); - printf(" PciLinkState : 0x%x\n",pciStatus.pciLinkState); - printf(" PciFunction : 0x%x\n",pciStatus.pciFunction); - printf(" PciDevice : 0x%x\n",pciStatus.pciDevice); - printf(" PciBus : 0x%.2x\n",pciStatus.pciBus); - printf(" PciLanes : %i\n",pciStatus.pciLanes); - - for (x=0; x < 8; x++) { - if ( ((1 << x) & info.laneMask) == 0 ) continue; - - pgpGetStatus(s,x,&status); - - printf("\n"); - printf("-------------- Lane %i --------------------\n",x); - - printf(" LoopBack : %i\n",status.loopBack); - printf(" LocLinkReady : %i\n",status.locLinkReady); - printf(" RemLinkReady : %i\n",status.remLinkReady); - printf(" RxReady : %i\n",status.rxReady); - printf(" TxReady : %i\n",status.txReady); - printf(" RxCount : %i\n",status.rxCount); - printf(" CellErrCnt : %i\n",status.cellErrCnt); - printf(" LinkDownCnt : %i\n",status.linkDownCnt); - printf(" LinkErrCnt : %i\n",status.linkErrCnt); - printf(" FifoErr : %i\n",status.fifoErr); - printf(" RemData : 0x%.2x\n",status.remData); - printf(" RemBuffStatus : 0x%.2x\n",status.remBuffStatus); - } - close(s); - -} - diff --git a/pgpcard/app/src/pgpLoopTest.cpp b/pgpcard/app/src/pgpLoopTest.cpp deleted file mode 100644 index cc144b2..0000000 --- a/pgpcard/app/src/pgpLoopTest.cpp +++ /dev/null @@ -1,477 +0,0 @@ -/** - *----------------------------------------------------------------------------- - * Title : PGP rate test utility - * ---------------------------------------------------------------------------- - * File : pgpLoopTest.cpp - * Author : Ryan Herbst, rherbst@slac.stanford.edu - * Created : 2016-08-08 - * Last update: 2016-08-08 - * ---------------------------------------------------------------------------- - * Description: - * Utility to rate test the PGP card. This utility will create a set number of - * write and read threads to emulate a number of read and write applications. - * ---------------------------------------------------------------------------- - * This file is part of the aes_stream_drivers package. It is subject to - * the license terms in the LICENSE.txt file found in the top-level directory - * of this distribution and at: - * https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html. - * No part of the aes_stream_drivers package, including this file, may be - * copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE.txt file. - * ---------------------------------------------------------------------------- -**/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -using namespace std; - -const char * argp_program_version = "pgpLoopTest 1.0"; -const char * argp_program_bug_address = "rherbst@slac.stanford.edu"; - -struct PrgArgs { - const char * path; - uint32_t vcMask; - uint32_t prbsDis; - uint32_t size; - uint32_t idxEn; - uint32_t pause; -}; - -static struct PrgArgs DefArgs = { "/dev/pgpcard_0", 0xFFFFFFFF, 0, 10000, 0 }; - -static char args_doc[] = ""; -static char doc[] = ""; - -static struct argp_option options[] = { - { "path", 'p', "PATH", OPTION_ARG_OPTIONAL, "Path of pgpcard device to use. Default=/dev/pgpcard_0.",0}, - { "vcmask", 'v', "MASK", OPTION_ARG_OPTIONAL, "Mask of vcs for test. 1 bit per vc in hex. i.e. 0xFF.",0}, - { "prbsdis", 'd', 0, OPTION_ARG_OPTIONAL, "Disable PRBS checking.",0}, - { "size", 's', "SIZE", OPTION_ARG_OPTIONAL, "Size for transmitted frames.",0}, - { "indexen", 'i', 0, OPTION_ARG_OPTIONAL, "Use index based receive buffers.",0}, - { "time", 't', "TIME", OPTION_ARG_OPTIONAL, "Pause time between writes in uSec. Default=0",0}, - {0} -}; - -error_t parseArgs ( int key, char *arg, struct argp_state *state ) { - struct PrgArgs *args = (struct PrgArgs *)state->input; - - switch(key) { - case 'p': args->path = arg; break; - case 'v': args->vcMask = strtol(arg,NULL,16); break; - case 's': args->size = strtol(arg,NULL,10); break; - case 'd': args->prbsDis = 1; break; - case 'i': args->idxEn = 1; break; - case 't': args->pause = strtol(arg,NULL,10); break; - default: return ARGP_ERR_UNKNOWN; break; - } - return(0); -} - -static struct argp argp = {options,parseArgs,args_doc,doc}; - -class RunData { - public: - const char * dev; - uint32_t size; - uint32_t lane; - uint32_t vc; - uint64_t count; - uint64_t total; - uint64_t prbErr; - uint32_t pause; - char id[10]; - bool idxEn; - bool enable; - bool prbEn; - bool running; -}; - -void *runWrite ( void *t ) { - fd_set fds; - struct timeval timeout; - int32_t ret; - void * data; - uint32_t lane; - uint32_t vc; - int32_t fd; - PrbsData prbs(32,4,1,2,6,31); - void ** dmaBuffers; - uint32_t dmaSize; - uint32_t dmaCount; - int32_t dmaIndex; - bool prbValid; - - RunData *txData = (RunData *)t; - - if ( (fd = open(txData->dev, O_RDWR )) < 0 ) { - printf("Error opening device\n"); - txData->running = false; - return NULL; - } - - if ( txData->idxEn ) { - if ((dmaBuffers = dmaMapDma(fd,&dmaCount,&dmaSize)) == NULL ) { - printf("Write failed to map dma buffer\n"); - txData->running = false; - return(NULL); - } - } - else { - if ((data = malloc(txData->size)) == NULL ) { - printf("Write failed to allocate buffer\n"); - txData->running = false; - return(NULL); - } - } - - lane = txData->lane; - vc = txData->vc; - - prbValid = false; - - usleep(1000000+100*(lane*4+vc)); - printf("Starting write thread. Lane=%i, Vc=%i, Size=%i\n",lane,vc,txData->size); - - while (txData->enable) { - - // Setup fds for select call - FD_ZERO(&fds); - FD_SET(fd,&fds); - - // Wait for write ready - timeout.tv_sec=0; - timeout.tv_usec=100; - ret = select(fd+1,NULL,&fds,NULL,&timeout); - if ( ret != 0 ) { - - if ( txData->idxEn ) { - dmaIndex = dmaGetIndex(fd); - if ( dmaIndex < 0 ) continue; - data = dmaBuffers[dmaIndex]; - } - - // Gen data - if ( txData->prbEn && ! prbValid ) { - prbs.genData(data,txData->size); - prbValid = true; - } - - if ( txData->idxEn ) ret = dmaWriteIndex(fd,dmaIndex,txData->size,0,pgpSetDest(lane,vc)); - else ret = dmaWrite(fd,data,txData->size,0,pgpSetDest(lane,vc)); - - if ( ret < 0 ) { - printf("Write Error at count %lu. Lane=%i, VC=%i\n",txData->count,lane,vc); - break; - } - else if ( ret > 0 ) { - txData->count++; - txData->total += ret; - prbValid = false; - if ( txData->pause > 0 ) usleep(txData->pause); - } - } - } - - if ( txData->idxEn ) dmaUnMapDma(fd,dmaBuffers); - else free(data); - close(fd); - - txData->running = false; - - printf("Write thread stopped!. Lane=%i, VC=%i\n",lane,vc); - - pthread_exit(NULL); - return(NULL); -} - - -void *runRead ( void *t ) { - fd_set fds; - struct timeval timeout; - int32_t ret; - void * data; - uint32_t maxSize; - uint32_t lane; - uint32_t vc; - uint32_t rxLane; - uint32_t rxVc; - uint32_t rxErr; - uint32_t rxDest; - uint64_t mask; - int32_t fd; - void ** dmaBuffers; - uint32_t dmaSize; - uint32_t dmaCount; - uint32_t dmaIndex; - bool idxEn; - - PrbsData prbs(32,4,1,2,6,31); - - RunData *rxData = (RunData *)t; - - maxSize = rxData->size*2; - idxEn = rxData->idxEn; - - - if ( (fd = open(rxData->dev, O_RDWR )) < 0 ) { - printf("Error opening device\n"); - rxData->running = false; - return NULL; - } - - if ( rxData->idxEn ) { - if ((dmaBuffers = dmaMapDma(fd,&dmaCount,&dmaSize)) == NULL ) { - printf("Read failed to map dma buffer\n"); - rxData->running = false; - return(NULL); - } - } - else { - if ((data = malloc(maxSize)) == NULL ) { - printf("Read failed to allocate buffer\n"); - rxData->running = false; - return(NULL); - } - } - - lane = rxData->lane; - vc = rxData->vc; - mask = (1 << (lane*4 + vc)); - - usleep(100*(lane*4+vc)); - if ( dmaSetMask(fd,mask) != 0 ) { - printf("Error setting mask. lane=%i, vc=%i, mask=0x%.8lx\n",lane,vc,mask); - close(fd); - return NULL; - } - - printf("Starting read thread. Lane=%i, Vc=%i, Size=%i\n",lane,vc,rxData->size); - - while (rxData->enable) { - - // Setup fds for select call - FD_ZERO(&fds); - FD_SET(fd,&fds); - - // Wait for read ready - timeout.tv_sec=0; - timeout.tv_usec=100; - ret = select(fd+1,&fds,NULL,NULL,&timeout); - if ( ret != 0 ) { - - if ( idxEn ) { - ret = dmaReadIndex(fd,&dmaIndex,NULL,&rxErr,&rxDest); - data = dmaBuffers[dmaIndex]; - } - else ret = dmaRead(fd,data,maxSize,NULL,&rxErr,&rxDest); - - rxVc = pgpGetVc(rxDest); - rxLane = pgpGetLane(rxDest); - - if ( ret != 0 ) { - - // data - if ( (rxData->prbEn) && (! prbs.processData(data,ret)) ) { - rxData->prbErr++; - printf("Prbs mismatch. count=%lu, lane=%i, vc=%i\n",rxData->count,lane,vc); - } - if ( idxEn ) dmaRetIndex(fd,dmaIndex); - - // Stop on size mismatch or frame errors - if ( ret != (int)rxData->size || rxErr != 0 || rxLane != lane || rxVc != vc) { - printf("Read Error. Lane=%i, VC=%i, ExpLane=%i, ExpVc=%i, Ret=%i, Exp=%i, rxErr=%i\n",rxLane,rxVc,lane,vc,ret,rxData->size,rxErr); - break; - } - else { - rxData->count++; - rxData->total += ret; - } - } - } - } - - if ( idxEn ) dmaUnMapDma(fd,dmaBuffers); - else free(data); - - close(fd); - rxData->running = false; - - printf("Read thread stopped!. Lane=%i, VC=%i\n",lane,vc); - - pthread_exit(NULL); - return(NULL); -} - - -int main (int argc, char **argv) { - RunData * txData[32]; - RunData * rxData[32]; - pthread_t txThread[32]; - pthread_t rxThread[32]; - uint x; - time_t c_tme; - time_t l_tme; - uint vcCount; - uint lastRx[32]; - uint lastTx[32]; - double totRxRate; - uint64_t totRx; - uint64_t totTx; - uint64_t totRxFreq; - uint64_t totPrb; - double rxRate; - bool runEn; - bool allDone; - int32_t s; - - struct PrgArgs args; - struct PgpInfo info; - - memcpy(&args,&DefArgs,sizeof(struct PrgArgs)); - argp_parse(&argp,argc,argv,0,0,&args); - - if ( (s = open(args.path, O_RDWR)) <= 0 ) { - printf("Error opening %s\n",args.path); - return(1); - } - pgpGetInfo(s,&info); - - // Generating read threads - vcCount = 0; - for (x=0; x < 32; x++) { - if ( ((1 << x) & args.vcMask) && ((1 << (x/4)) & info.laneMask) && ((1 << (x%4)) & info.vcPerMask)) { - rxData[vcCount] = new RunData; - txData[vcCount] = new RunData; - - memset(rxData[vcCount],0,sizeof(RunData)); - - rxData[vcCount]->enable = true; - rxData[vcCount]->running = true; - rxData[vcCount]->lane = x/4; - rxData[vcCount]->vc = x % 4; - rxData[vcCount]->size = (args.size + (x*4)); // (lane * 4 + vc) * 4 - rxData[vcCount]->dev = args.path; - rxData[vcCount]->idxEn = args.idxEn; - rxData[vcCount]->prbEn = !args.prbsDis; - rxData[vcCount]->pause = args.pause; - - sprintf(rxData[vcCount]->id,"%i-%i",x/4,x%4); - memcpy(txData[vcCount],rxData[vcCount],sizeof(RunData)); - - if ( pthread_create(&rxThread[vcCount],NULL,runRead,rxData[vcCount]) ) { - printf("Error creating read thread\n"); - return(2); - } - - if ( pthread_create(&txThread[vcCount],NULL,runWrite,txData[vcCount]) ) { - printf("Error creating write thread\n"); - return(2); - } - vcCount++; - } - } - time(&c_tme); - time(&l_tme); - - usleep(15000); - runEn = true; - allDone = false; - while (!allDone) { - sleep(1); - - // Check for stopped threads - allDone = true; - for (x=0; x < vcCount; x++) { - if ( txData[x]->running == false ) runEn = false; else allDone = false; - if ( rxData[x]->running == false ) runEn = false; else allDone = false; - } - if ( runEn == false ) { - for (x=0; x < vcCount; x++) { - txData[x]->enable = 0; - rxData[x]->enable = 0; - } - } - - time(&c_tme); - printf("\n\n"); - - printf("Lane-VC:"); - for (x=0; x < vcCount; x++) printf(" %15s",txData[x]->id); - printf("\nTxCount:"); - for (x=0; x < vcCount; x++) printf(" %15lu",txData[x]->count); - printf("\n TxFreq:"); - for (x=0; x < vcCount; x++) printf(" %15lu",txData[x]->count-lastTx[x]); - printf("\nTxBytes:"); - for (x=0; x < vcCount; x++) printf(" %15lu",txData[x]->total); - printf("\n TxRate:"); - - totTx = 0; - for (x=0; x < vcCount; x++) { - printf(" %15e",((double)(txData[x]->count-lastTx[x]) * 8.0 * (double)args.size) / (double)(c_tme-l_tme)); - lastTx[x] = txData[x]->count; - totTx += txData[x]->count; - } - printf("\n"); - - printf("RxCount:"); - for (x=0; x < vcCount; x++) printf(" %15lu",rxData[x]->count); - printf("\n RxFreq:"); - for (x=0; x < vcCount; x++) printf(" %15lu",rxData[x]->count-lastRx[x]); - printf("\nRxBytes:"); - for (x=0; x < vcCount; x++) printf(" %15lu",rxData[x]->total); - - if ( ! args.prbsDis ) { - printf("\n PrbErr:"); - for (x=0; x < vcCount; x++) printf(" %15lu",rxData[x]->prbErr); - } - printf("\n RxRate:"); - - totRxRate = 0; - totRxFreq = 0; - totRx = 0; - totPrb = 0; - for (x=0; x < vcCount; x++) { - rxRate = ((double)(rxData[x]->count-lastRx[x]) * 8.0 * (double)args.size) / (double)(c_tme-l_tme); - printf(" %15e",rxRate); - totRxFreq += (rxData[x]->count-lastRx[x]); - lastRx[x] = rxData[x]->count; - totRx += rxData[x]->count; - totPrb += rxData[x]->prbErr; - totRxRate += rxRate; - } - printf("\n"); - printf(" TotTx: %15lu\n",totTx); - printf(" TotRx: %15lu\n",totRx); - printf("TotFreq: %15lu\n",totRxFreq); - if ( ! args.prbsDis ) printf(" PrbErr: %15lu\n",totPrb); - printf("TotRate: %15e\n",totRxRate); - l_tme = c_tme; - } - - printf("\nMain thread stopped!.\n"); - - // Wait for thread to stop - for (x=0; x < vcCount; x++) { - pthread_join(txThread[x], NULL); - pthread_join(rxThread[x], NULL); - } - - for (x=0; x < vcCount; x++) { - delete txData[x]; - delete rxData[x]; - } - close(s); - return(0); -} - diff --git a/pgpcard/app/src/pgpPromLoad.cpp b/pgpcard/app/src/pgpPromLoad.cpp deleted file mode 100644 index de021bc..0000000 --- a/pgpcard/app/src/pgpPromLoad.cpp +++ /dev/null @@ -1,152 +0,0 @@ -/** - *----------------------------------------------------------------------------- - * Title : PGP Firmware Update Utility - * ---------------------------------------------------------------------------- - * File : pgpPromLoad.cpp - * Author : Ryan Herbst, rherbst@slac.stanford.edu - * Created : 2016-08-08 - * Last update: 2016-08-08 - * ---------------------------------------------------------------------------- - * Description: - * Utility to program the PGP card with new firmware. - * ---------------------------------------------------------------------------- - * This file is part of the aes_stream_drivers package. It is subject to - * the license terms in the LICENSE.txt file found in the top-level directory - * of this distribution and at: - * https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html. - * No part of the aes_stream_drivers package, including this file, may be - * copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE.txt file. - * ---------------------------------------------------------------------------- -**/ - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include "PciCardProm.h" - -using namespace std; - -const char * argp_program_version = "pgpPromLoad 1.0"; -const char * argp_program_bug_address = "rherbst@slac.stanford.edu"; - -struct PrgArgs { - const char * path; - const char * file; -}; - -static struct PrgArgs DefArgs = { "/dev/pgpcard_0", "" }; - -static char args_doc[] = "promFile"; -static char doc[] = "\n PromFile is the appropriate .mcs file for the card."; - -static struct argp_option options[] = { - { "path", 'p', "PATH", OPTION_ARG_OPTIONAL, "Path of pgpcard device to use. Default=/dev/pgpcard_0.",0}, - {0} -}; - -error_t parseArgs ( int key, char *arg, struct argp_state *state ) { - struct PrgArgs *args = (struct PrgArgs *)state->input; - - switch(key) { - case 'p': args->path = arg; break; - case ARGP_KEY_ARG: - switch (state->arg_num) { - case 0: args->file = arg; break; - default: argp_usage(state); break; - } - break; - case ARGP_KEY_END: - if ( state->arg_num < 1) argp_usage(state); - break; - default: return ARGP_ERR_UNKNOWN; break; - } - return(0); -} - -static struct argp argp = {options,parseArgs,args_doc,doc}; - -int main (int argc, char **argv) { - int fd; - PciCardProm *prom; - PgpInfo info; - struct PrgArgs args; - bool gen3; - - memcpy(&args,&DefArgs,sizeof(struct PrgArgs)); - argp_parse(&argp,argc,argv,0,0,&args); - - if ( (fd = open(args.path, O_RDWR)) <= 0 ) { - printf("Error opening %s\n",args.path); - return(1); - } - - // Get card info - pgpGetInfo(fd,&info); - gen3 = false; - - // Determine version, use only lower 4 bits to get the base version - switch (info.type & 0xF) { - case PGP_GEN3: gen3 = true; break; - case PGP_GEN2: - if ( info.promPrgEn ) { - ::close(fd); - return(-1); - } - break; - default: - ::close(fd); - return(-1); - break; - } - - // Create the PciCardG3Prom object - prom = new PciCardProm(fd,args.file,gen3); - - // Check if the .mcs file exists - if(!prom->fileExist()){ - cout << "Error opening: " << args.file << endl; - delete prom; - close(fd); - return(1); - } - - // Erase the PROM - prom->eraseBootProm(); - - // Write the .mcs file to the PROM - if(!prom->writeBootProm()) { - cout << "Error in prom->bufferedWriteBootProm() function" << endl; - delete prom; - close(fd); - return(1); - } - - // Compare the .mcs file with the PROM - if(!prom->verifyBootProm()) { - cout << "Error in prom->verifyBootProm() function" << endl; - delete prom; - close(fd); - return(1); - } - - // Display Reminder - prom->rebootReminder(); - - // Close all the devices - delete prom; - close(fd); - return(0); -} diff --git a/pgpcard/app/src/pgpPromVerify.cpp b/pgpcard/app/src/pgpPromVerify.cpp deleted file mode 100644 index 3f5b8ce..0000000 --- a/pgpcard/app/src/pgpPromVerify.cpp +++ /dev/null @@ -1,138 +0,0 @@ -/** - *----------------------------------------------------------------------------- - * Title : PGP Firmware Verify Utility - * ---------------------------------------------------------------------------- - * File : pgpPromVerify.cpp - * Author : Ryan Herbst, rherbst@slac.stanford.edu - * Created : 2016-08-08 - * Last update: 2016-08-08 - * ---------------------------------------------------------------------------- - * Description: - * Utility to verify the firmware loaded in the PGP Card - * ---------------------------------------------------------------------------- - * This file is part of the aes_stream_drivers package. It is subject to - * the license terms in the LICENSE.txt file found in the top-level directory - * of this distribution and at: - * https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html. - * No part of the aes_stream_drivers package, including this file, may be - * copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE.txt file. - * ---------------------------------------------------------------------------- -**/ -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -using namespace std; - -const char * argp_program_version = "pgpPromVerify 1.0"; -const char * argp_program_bug_address = "rherbst@slac.stanford.edu"; - -struct PrgArgs { - const char * path; - const char * file; -}; - -static struct PrgArgs DefArgs = { "/dev/pgpcard_0", "" }; - -static char args_doc[] = "promFile"; -static char doc[] = "\n PromFile is the appropriate .mcs file for the card."; - -static struct argp_option options[] = { - { "path", 'p', "PATH", OPTION_ARG_OPTIONAL, "Path of pgpcard device to use. Default=/dev/pgpcard_0.",0}, - {0} -}; - -error_t parseArgs ( int key, char *arg, struct argp_state *state ) { - struct PrgArgs *args = (struct PrgArgs *)state->input; - - switch(key) { - case 'p': args->path = arg; break; - case ARGP_KEY_ARG: - switch (state->arg_num) { - case 0: args->file = arg; break; - default: argp_usage(state); break; - } - break; - case ARGP_KEY_END: - if ( state->arg_num < 1) argp_usage(state); - break; - default: return ARGP_ERR_UNKNOWN; break; - } - return(0); -} - -static struct argp argp = {options,parseArgs,args_doc,doc}; - -int main (int argc, char **argv) { - int fd; - bool gen3; - PciCardProm *prom; - PgpInfo info; - struct PrgArgs args; - - memcpy(&args,&DefArgs,sizeof(struct PrgArgs)); - argp_parse(&argp,argc,argv,0,0,&args); - - if ( (fd = open(args.path, O_RDWR)) <= 0 ) { - printf("Error opening %s\n",args.path); - return(1); - } - - // Get card info - pgpGetInfo(fd,&info); - gen3 = false; - - // Determine version, use only lower 4 bits to get the base version - switch (info.type & 0xF) { - case PGP_GEN3: gen3 = true; break; - case PGP_GEN2: - if ( info.promPrgEn ) { - ::close(fd); - return(-1); - } - break; - default: - ::close(fd); - return(-1); - break; - } - - // Create the PgpCardProm object - prom = new PciCardProm(fd,args.file,gen3); - - // Check if the .mcs file exists - if(!prom->fileExist()){ - cout << "Error opening: " << args.file << endl; - delete prom; - close(fd); - return(1); - } - - // Compare the .mcs file with the PROM - if(!prom->verifyBootProm()) { - cout << "Error in prom->writeBootProm() function" << endl; - delete prom; - close(fd); - return(1); - } - - // Close all the devices - delete prom; - close(fd); - return(0); -} - diff --git a/pgpcard/app/src/pgpRead.cpp b/pgpcard/app/src/pgpRead.cpp deleted file mode 100644 index 0eb67ca..0000000 --- a/pgpcard/app/src/pgpRead.cpp +++ /dev/null @@ -1,166 +0,0 @@ -/** - *----------------------------------------------------------------------------- - * Title : PGP read utility - * ---------------------------------------------------------------------------- - * File : pgpRead.cpp - * Author : Ryan Herbst, rherbst@slac.stanford.edu - * Created : 2016-08-08 - * Last update: 2016-08-08 - * ---------------------------------------------------------------------------- - * Description: - * This program will open up a pgp card port and attempt to read data. - * ---------------------------------------------------------------------------- - * This file is part of the aes_stream_drivers package. It is subject to - * the license terms in the LICENSE.txt file found in the top-level directory - * of this distribution and at: - * https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html. - * No part of the aes_stream_drivers package, including this file, may be - * copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE.txt file. - * ---------------------------------------------------------------------------- -**/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -using namespace std; - -const char * argp_program_version = "pgpRead 1.0"; -const char * argp_program_bug_address = "rherbst@slac.stanford.edu"; - -struct PrgArgs { - const char * path; - uint32_t lane; - uint32_t prbsDis; - uint32_t idxEn; -}; - -static struct PrgArgs DefArgs = { "/dev/pgpcard_0", 0xFF, 0x0, 0x0 }; - -static char args_doc[] = ""; -static char doc[] = ""; - -static struct argp_option options[] = { - { "path", 'p', "PATH", OPTION_ARG_OPTIONAL, "Path of pgpcard device to use. Default=/dev/pgpcard_0.",0}, - { "lane", 'l', "MASK", OPTION_ARG_OPTIONAL, "Mask of lanes for read. 1 bit per lane in hex. i.e. 0xFF.",0}, - { "prbsdis", 'd', 0, OPTION_ARG_OPTIONAL, "Disable PRBS checking.",0}, - { "indexen", 'i', 0, OPTION_ARG_OPTIONAL, "Use index based receive buffers.",0}, - {0} -}; - -error_t parseArgs ( int key, char *arg, struct argp_state *state ) { - struct PrgArgs *args = (struct PrgArgs *)state->input; - - switch(key) { - case 'p': args->path = arg; break; - case 'l': args->lane = strtol(arg,NULL,16); break; - case 'd': args->prbsDis = 1; break; - case 'i': args->idxEn = 1; break; - default: return ARGP_ERR_UNKNOWN; break; - } - return(0); -} - -static struct argp argp = {options,parseArgs,args_doc,doc}; - -int main (int argc, char **argv) { - int32_t s; - int32_t ret; - int32_t count; - fd_set fds; - void * rxData; - uint32_t maxSize; - uint32_t rxLane; - uint32_t rxVc; - uint32_t rxDest; - uint32_t rxError; - PrbsData prbs(32,4,1,2,6,31); - bool prbRes; - void ** dmaBuffers; - uint32_t dmaSize; - uint32_t dmaCount; - uint32_t dmaIndex; - - struct PgpInfo info; - struct PrgArgs args; - - struct timeval timeout; - - memcpy(&args,&DefArgs,sizeof(struct PrgArgs)); - argp_parse(&argp,argc,argv,0,0,&args); - - if ( (s = open(args.path, O_RDWR)) <= 0 ) { - printf("Error opening %s\n",args.path); - return(1); - } - pgpGetInfo(s,&info); - - dmaSetMask(s,args.lane & info.laneMask); - - maxSize = 1024*1024*2; - - if ( args.idxEn ) { - if ( (dmaBuffers = dmaMapDma(s,&dmaCount,&dmaSize)) == NULL ) { - printf("Failed to map dma buffers!\n"); - return(0); - } - } - else { - if ((rxData = malloc(maxSize)) == NULL ) { - printf("Failed to allocate rxData!\n"); - return(0); - } - } - - count = 0; - prbRes = 0; - do { - - // Setup fds for select call - FD_ZERO(&fds); - FD_SET(s,&fds); - - // Setup select timeout for 1 second - timeout.tv_sec=2; - timeout.tv_usec=0; - - // Wait for Socket data ready - ret = select(s+1,&fds,NULL,NULL,&timeout); - if ( ret <= 0 ) { - printf("Read timeout\n"); - } - else { - - // DMA Read - if ( args.idxEn ) { - ret = dmaReadIndex(s,&dmaIndex,NULL,&rxError,&rxDest); - rxData = dmaBuffers[dmaIndex]; - } - else ret = dmaRead(s,rxData,maxSize,NULL,&rxError,&rxDest); - - rxVc = pgpGetVc(rxDest); - rxLane = pgpGetLane(rxDest); - - if ( ret > 0 ) { - if ( args.prbsDis == 0 ) prbRes = prbs.processData(rxData,ret); - if ( args.idxEn ) dmaRetIndex(s,dmaIndex); - - count++; - printf("Read ret=%i, Lane=%i, Vc=%i, error=%i, prbs=%i, count=%i\n",ret,rxLane,rxVc,rxError,prbRes,count); - } - } - } while ( 1 ); - - if ( args.idxEn ) dmaUnMapDma(s,dmaBuffers); - else free(rxData); - - close(s); - return(0); -} - diff --git a/pgpcard/app/src/pgpSetData.cpp b/pgpcard/app/src/pgpSetData.cpp deleted file mode 100755 index cfc569c..0000000 --- a/pgpcard/app/src/pgpSetData.cpp +++ /dev/null @@ -1,100 +0,0 @@ -/** - *----------------------------------------------------------------------------- - * Title : PGP sideband data utility - * ---------------------------------------------------------------------------- - * File : pgpSetData.cpp - * Author : Ryan Herbst, rherbst@slac.stanford.edu - * Created : 2016-08-08 - * Last update: 2016-08-08 - * ---------------------------------------------------------------------------- - * Description: - * This program set the PGP card sideband data for a lane. - * ---------------------------------------------------------------------------- - * This file is part of the aes_stream_drivers package. It is subject to - * the license terms in the LICENSE.txt file found in the top-level directory - * of this distribution and at: - * https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html. - * No part of the aes_stream_drivers package, including this file, may be - * copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE.txt file. - * ---------------------------------------------------------------------------- -**/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -using namespace std; - -const char * argp_program_version = "pgpSetData 1.0"; -const char * argp_program_bug_address = "rherbst@slac.stanford.edu"; - -struct PrgArgs { - const char * path; - uint32_t lane; - uint32_t data; -}; - -static struct PrgArgs DefArgs = { "/dev/pgpcard_0", 0x0, 0x00 }; - -static char args_doc[] = "data"; -static char doc[] = "\n data is passed as a hex value. i.e. 0xAB."; - -static struct argp_option options[] = { - { "path", 'p', "PATH", OPTION_ARG_OPTIONAL, "Path of pgpcard device to use. Default=/dev/pgpcard_0.",0}, - { "lane", 'l', "MASK", OPTION_ARG_OPTIONAL, "Mask of lanes to set. 1 bit per lane in hex. i.e. 0xFF.",0}, - {0} -}; - -error_t parseArgs ( int key, char *arg, struct argp_state *state ) { - struct PrgArgs *args = (struct PrgArgs *)state->input; - - switch(key) { - case 'p': args->path = arg; break; - case 'l': args->lane = strtol(arg,NULL,16); break; - case ARGP_KEY_ARG: - switch (state->arg_num) { - case 0: args->data = strtol(arg,NULL,16); break; - default: argp_usage(state); break; - } - break; - case ARGP_KEY_END: - if ( state->arg_num < 1) argp_usage(state); - break; - default: return ARGP_ERR_UNKNOWN; break; - } - return(0); -} - -static struct argp argp = {options,parseArgs,args_doc,doc}; - -int main (int argc, char **argv) { - int s; - uint32_t x; - struct PrgArgs args; - struct PgpInfo info; - - memcpy(&args,&DefArgs,sizeof(struct PrgArgs)); - argp_parse(&argp,argc,argv,0,0,&args); - - if ( (s = open(args.path, O_RDWR)) <= 0 ) { - printf("Error opening %s\n",args.path); - return(1); - } - pgpGetInfo(s,&info); - - for (x=0; x < 8; x++) { - if ( ((1 << x) & info.laneMask) != 0 ) { - printf("Setting lane %i data to 0x%.2x\n",x,args.data); - pgpSetData(s,x,args.data); - } - } - close(s); -} - diff --git a/pgpcard/app/src/pgpSetDebug.cpp b/pgpcard/app/src/pgpSetDebug.cpp deleted file mode 100755 index 00cbf86..0000000 --- a/pgpcard/app/src/pgpSetDebug.cpp +++ /dev/null @@ -1,90 +0,0 @@ -/** - *----------------------------------------------------------------------------- - * Title : PGP debug utility - * ---------------------------------------------------------------------------- - * File : pgpSetDebug.cpp - * Author : Ryan Herbst, rherbst@slac.stanford.edu - * Created : 2016-08-08 - * Last update: 2016-08-08 - * ---------------------------------------------------------------------------- - * Description: - * This program set the PGP driver debug level. - * ---------------------------------------------------------------------------- - * This file is part of the aes_stream_drivers package. It is subject to - * the license terms in the LICENSE.txt file found in the top-level directory - * of this distribution and at: - * https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html. - * No part of the aes_stream_drivers package, including this file, may be - * copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE.txt file. - * ---------------------------------------------------------------------------- -**/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -using namespace std; - -const char * argp_program_version = "pgpSetDebug 1.0"; -const char * argp_program_bug_address = "rherbst@slac.stanford.edu"; - -struct PrgArgs { - const char * path; - uint32_t level; -}; - -static struct PrgArgs DefArgs = { "/dev/pgpcard_0", 0x00 }; - -static char args_doc[] = "debugLevel"; -static char doc[] = "\n Debug level is either 0 or 1."; - -static struct argp_option options[] = { - { "path", 'p', "PATH", OPTION_ARG_OPTIONAL, "Path of pgpcard device to use. Default=/dev/pgpcard_0.",0}, - {0} -}; - -error_t parseArgs ( int key, char *arg, struct argp_state *state ) { - struct PrgArgs *args = (struct PrgArgs *)state->input; - - switch(key) { - case 'p': args->path = arg; break; - case ARGP_KEY_ARG: - switch (state->arg_num) { - case 0: args->level = strtol(arg,NULL,10); break; - default: argp_usage(state); break; - } - break; - case ARGP_KEY_END: - if ( state->arg_num < 1) argp_usage(state); - break; - default: return ARGP_ERR_UNKNOWN; break; - } - return(0); -} - -static struct argp argp = {options,parseArgs,args_doc,doc}; - -int main (int argc, char **argv) { - int s; - - struct PrgArgs args; - - memcpy(&args,&DefArgs,sizeof(struct PrgArgs)); - argp_parse(&argp,argc,argv,0,0,&args); - - if ( (s = open(args.path, O_RDWR)) <= 0 ) { - printf("Error opening %s\n",args.path); - return(1); - } - - printf("Setting debug level to %i\n",args.level); - dmaSetDebug(s,args.level); - close(s); -} - diff --git a/pgpcard/app/src/pgpSetLoop.cpp b/pgpcard/app/src/pgpSetLoop.cpp deleted file mode 100755 index 6db5e35..0000000 --- a/pgpcard/app/src/pgpSetLoop.cpp +++ /dev/null @@ -1,100 +0,0 @@ -/** - *----------------------------------------------------------------------------- - * Title : PGP loopback utility - * ---------------------------------------------------------------------------- - * File : pgpSetLoop.cpp - * Author : Ryan Herbst, rherbst@slac.stanford.edu - * Created : 2016-08-08 - * Last update: 2016-08-08 - * ---------------------------------------------------------------------------- - * Description: - * This program set the PGP card loopback state for a lane. - * ---------------------------------------------------------------------------- - * This file is part of the aes_stream_drivers package. It is subject to - * the license terms in the LICENSE.txt file found in the top-level directory - * of this distribution and at: - * https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html. - * No part of the aes_stream_drivers package, including this file, may be - * copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE.txt file. - * ---------------------------------------------------------------------------- -**/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -using namespace std; - -const char * argp_program_version = "pgpSetLoop 1.0"; -const char * argp_program_bug_address = "rherbst@slac.stanford.edu"; - -struct PrgArgs { - const char * path; - uint32_t lane; - uint32_t state; -}; - -static struct PrgArgs DefArgs = { "/dev/pgpcard_0", 0xFF, 0x00 }; - -static char args_doc[] = "enable"; -static char doc[] = "\n Enable is either 0 or 1."; - -static struct argp_option options[] = { - { "path", 'p', "PATH", OPTION_ARG_OPTIONAL, "Path of pgpcard device to use. Default=/dev/pgpcard_0.",0}, - { "lane", 'l', "MASK", OPTION_ARG_OPTIONAL, "Mask of lanes to set. 1 bit per lane in hex. i.e. 0xFF.",0}, - {0} -}; - -error_t parseArgs ( int key, char *arg, struct argp_state *state ) { - struct PrgArgs *args = (struct PrgArgs *)state->input; - - switch(key) { - case 'p': args->path = arg; break; - case 'l': args->lane = strtol(arg,NULL,16); break; - case ARGP_KEY_ARG: - switch (state->arg_num) { - case 0: args->state = strtol(arg,NULL,10); break; - default: argp_usage(state); break; - } - break; - case ARGP_KEY_END: - if ( state->arg_num < 1) argp_usage(state); - break; - default: return ARGP_ERR_UNKNOWN; break; - } - return(0); -} - -static struct argp argp = {options,parseArgs,args_doc,doc}; - -int main (int argc, char **argv) { - int s; - uint32_t x; - struct PgpInfo info; - struct PrgArgs args; - - memcpy(&args,&DefArgs,sizeof(struct PrgArgs)); - argp_parse(&argp,argc,argv,0,0,&args); - - if ( (s = open(args.path, O_RDWR)) <= 0 ) { - printf("Error opening %s\n",args.path); - return(1); - } - pgpGetInfo(s,&info); - - for (x=0; x < 8; x++) { - if ( ((1 << x) & info.laneMask) != 0 ) { - printf("Setting lane %i loop to %i\n",x,args.state); - pgpSetLoop(s,x,args.state); - } - } - close(s); -} - diff --git a/pgpcard/app/src/pgpWrite.cpp b/pgpcard/app/src/pgpWrite.cpp deleted file mode 100644 index 343616d..0000000 --- a/pgpcard/app/src/pgpWrite.cpp +++ /dev/null @@ -1,180 +0,0 @@ -/** - *----------------------------------------------------------------------------- - * Title : PGP write utility - * ---------------------------------------------------------------------------- - * File : pgpWrite.cpp - * Author : Ryan Herbst, rherbst@slac.stanford.edu - * Created : 2016-08-08 - * Last update: 2016-08-08 - * ---------------------------------------------------------------------------- - * Description: - * Program to send data on a PGP lane/VC. Data is prbs - * ---------------------------------------------------------------------------- - * This file is part of the aes_stream_drivers package. It is subject to - * the license terms in the LICENSE.txt file found in the top-level directory - * of this distribution and at: - * https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html. - * No part of the aes_stream_drivers package, including this file, may be - * copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE.txt file. - * ---------------------------------------------------------------------------- -**/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -using namespace std; - -const char * argp_program_version = "pgpWrite 1.0"; -const char * argp_program_bug_address = "rherbst@slac.stanford.edu"; - -struct PrgArgs { - const char * path; - uint32_t lane; - uint32_t vc; - uint32_t size; - uint32_t count; - uint32_t prbsDis; - uint32_t idxEn; -}; - -static struct PrgArgs DefArgs = { "/dev/pgpcard_0", 0, 0, 1000, 1, 0, 0 }; - -static char args_doc[] = "lane vc"; -static char doc[] = " Lane and VC are passed as integers."; - -static struct argp_option options[] = { - { "path", 'p', "PATH", OPTION_ARG_OPTIONAL, "Path of pgpcard device to use. Default=/dev/pgpcard_0.",0}, - { "prbsdis", 'd', 0, OPTION_ARG_OPTIONAL, "Disable PRBS generation.",0}, - { "size", 's', "SIZE", OPTION_ARG_OPTIONAL, "Size of data to generate. Default=1000",0}, - { "count", 'c', "COUNT", OPTION_ARG_OPTIONAL, "Number of frames to generate. Default=1",0}, - { "indexen", 'i', 0, OPTION_ARG_OPTIONAL, "Use index based transmit buffers.",0}, - {0} -}; - -error_t parseArgs ( int key, char *arg, struct argp_state *state ) { - struct PrgArgs *args = (struct PrgArgs *)state->input; - - switch(key) { - case 'p': args->path = arg; break; - case 'd': args->prbsDis = 1; break; - case 's': args->size = strtol(arg,NULL,10); break; - case 'c': args->count = strtol(arg,NULL,10); break; - case 'i': args->idxEn = 1; break; - case ARGP_KEY_ARG: - switch (state->arg_num) { - case 0: args->lane = strtol(arg,NULL,10); break; - case 1: args->vc = strtol(arg,NULL,10); break; - default: argp_usage(state); break; - } - break; - case ARGP_KEY_END: - if ( state->arg_num < 2) argp_usage(state); - break; - default: return ARGP_ERR_UNKNOWN; break; - } - return(0); -} - -static struct argp argp = {options,parseArgs,args_doc,doc}; - -int main (int argc, char **argv) { - int32_t s; - int32_t ret; - uint32_t count; - fd_set fds; - void * txData; - PrbsData prbs(32,4,1,2,6,31); - void ** dmaBuffers; - uint32_t dmaSize; - uint32_t dmaCount; - int32_t dmaIndex; - bool prbValid; - - struct timeval timeout; - struct PgpInfo info; - struct PrgArgs args; - - memcpy(&args,&DefArgs,sizeof(struct PrgArgs)); - argp_parse(&argp,argc,argv,0,0,&args); - - if ( (s = open(args.path, O_RDWR)) <= 0 ) { - printf("Error opening %s\n",args.path); - return(1); - } - pgpGetInfo(s,&info); - - if ( ((1 << args.lane) & info.laneMask) == 0 ) { - printf("Invalid lane %i. Card laneMask = 0x%.2x\n",args.lane,info.laneMask); - return(1); - } - - if ( args.idxEn ) { - if ( (dmaBuffers = dmaMapDma(s,&dmaCount,&dmaSize)) == NULL ) { - printf("Failed to map dma buffers!\n"); - return(0); - } - } - else { - if ((txData = malloc(args.size)) == NULL ) { - printf("Failed to allocate rxData!\n"); - return(0); - } - } - - prbValid = false; - count = 0; - do { - - // Setup fds for select call - FD_ZERO(&fds); - FD_SET(s,&fds); - - // Setup select timeout for 1 second - timeout.tv_sec=2; - timeout.tv_usec=0; - - // Wait for Socket data ready - ret = select(s+1,NULL,&fds,NULL,&timeout); - if ( ret <= 0 ) { - printf("Write timeout\n"); - } - else { - - if ( args.idxEn ) { - dmaIndex = dmaGetIndex(s); - if ( dmaIndex < 0 ) continue; - txData = dmaBuffers[dmaIndex]; - } - - // Gen data - if ( args.prbsDis == 0 && ! prbValid ) { - prbs.genData(txData,args.size); - prbValid = true; - } - - // DMA Write - if ( args.idxEn ) ret = dmaWriteIndex(s,dmaIndex,args.size,0,pgpSetDest(args.lane,args.vc)); - else ret = dmaWrite(s,txData,args.size,0,pgpSetDest(args.lane,args.vc)); - - if ( ret > 0 ) { - prbValid = false; - count++; - printf("Write ret=%i, Lane=%i, Vc=%i, count=%i\n",ret,args.lane,args.vc,count); - } - } - } while ( count < args.count ); - - if ( args.idxEn ) dmaUnMapDma(s,dmaBuffers); - else free(txData); - - close(s); - return(0); -} - diff --git a/pgpcard/driver/Makefile b/pgpcard/driver/Makefile deleted file mode 100644 index 343c9fe..0000000 --- a/pgpcard/driver/Makefile +++ /dev/null @@ -1,49 +0,0 @@ -# ---------------------------------------------------------------------------- -# Title : PGP driver makefile -# ---------------------------------------------------------------------------- -# File : Makefile -# Author : Ryan Herbst, rherbst@slac.stanford.edu -# Created : 2016-08-08 -# Last update: 2016-08-08 -# ---------------------------------------------------------------------------- -# Description: -# PGP card driver makefile -# ---------------------------------------------------------------------------- -# This file is part of the aes_stream_drivers package. It is subject to -# the license terms in the LICENSE.txt file found in the top-level directory -# of this distribution and at: -# https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html. -# No part of the aes_stream_drivers package, including this file, may be -# copied, modified, propagated, or distributed except according to the terms -# contained in the LICENSE.txt file. -# ---------------------------------------------------------------------------- - -NAME := pgpcard -HOME := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) -KVER := $(shell uname -r) -ARCH := $(shell uname -m) -CROSS_COMPILE := -KERNELDIR := /lib/modules/$(KVER)/build -SRCS := $(wildcard src/*.c) -OBJS := $(patsubst %.c,%.o,$(SRCS)) - -ifndef GITV - GITT := $(shell cd $(HOME); git describe --tags) - GITD := $(shell cd $(HOME); git status --short -uno | wc -l) - GITV := $(if $(filter $(GITD),0),$(GITT),$(GITT)-dirty) -endif - -ccflags-y := -I$(HOME)/../../include -ccflags-y += -I$(HOME)/src -ccflags-y += -DDMA_IN_KERNEL=1 -DGITV=\"$(GITV)\" - -$(NAME)-objs := src/dma_buffer.o src/dma_common.o src/fpga_prom.o -$(NAME)-objs += src/pgp_common.o src/pgp_gen2.o src/pgp_gen3.o src/pgp_top.o -obj-m := $(NAME).o - -all: - make ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) -C $(KERNELDIR) M=$(HOME) modules - -clean: - make ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) -C $(KERNELDIR) M=$(HOME) clean - rm -f $(OBJS) diff --git a/pgpcard/driver/README.md b/pgpcard/driver/README.md deleted file mode 100644 index 8b89dd0..0000000 --- a/pgpcard/driver/README.md +++ /dev/null @@ -1,18 +0,0 @@ -# How to cross-compile the kernel driver - -To cross-compile the kernel driver you need to define the `ARCH` and `CROSS_COMPILE` variables when calling `make`. Also, you need to point `KERNELDIR` to the location of the kernel sources. - -For example, to cross-compile the driver for the SLAC buildroot `2019.08` version for the `x86_64` architecture, you should call `make` this way: - -```bash -$ make \ -ARCH=x86_64 \ -CROSS_COMPILE=/afs/slac/package/linuxRT/buildroot-2019.08/host/linux-x86_64/x86_64/usr/bin/x86_64-buildroot-linux-gnu- \ -KERNELDIR=/afs/slac/package/linuxRT/buildroot-2019.08/buildroot-2019.08-x86_64/output/build/linux-4.14.139 -``` - -On the other hand, if you do not want to cross-compile the driver, and build it for the host instead, you need to call `make` without defining any variable: - -```bash -$ make -``` diff --git a/pgpcard/driver/src/dma_buffer.c b/pgpcard/driver/src/dma_buffer.c deleted file mode 120000 index 0704713..0000000 --- a/pgpcard/driver/src/dma_buffer.c +++ /dev/null @@ -1 +0,0 @@ -../../../common/driver/dma_buffer.c \ No newline at end of file diff --git a/pgpcard/driver/src/dma_buffer.h b/pgpcard/driver/src/dma_buffer.h deleted file mode 120000 index 5d5b27c..0000000 --- a/pgpcard/driver/src/dma_buffer.h +++ /dev/null @@ -1 +0,0 @@ -../../../common/driver/dma_buffer.h \ No newline at end of file diff --git a/pgpcard/driver/src/dma_common.c b/pgpcard/driver/src/dma_common.c deleted file mode 120000 index 8d83891..0000000 --- a/pgpcard/driver/src/dma_common.c +++ /dev/null @@ -1 +0,0 @@ -../../../common/driver/dma_common.c \ No newline at end of file diff --git a/pgpcard/driver/src/dma_common.h b/pgpcard/driver/src/dma_common.h deleted file mode 120000 index f6606a0..0000000 --- a/pgpcard/driver/src/dma_common.h +++ /dev/null @@ -1 +0,0 @@ -../../../common/driver/dma_common.h \ No newline at end of file diff --git a/pgpcard/driver/src/fpga_prom.c b/pgpcard/driver/src/fpga_prom.c deleted file mode 120000 index 8795a1a..0000000 --- a/pgpcard/driver/src/fpga_prom.c +++ /dev/null @@ -1 +0,0 @@ -../../../common/driver/fpga_prom.c \ No newline at end of file diff --git a/pgpcard/driver/src/fpga_prom.h b/pgpcard/driver/src/fpga_prom.h deleted file mode 120000 index 0d2882e..0000000 --- a/pgpcard/driver/src/fpga_prom.h +++ /dev/null @@ -1 +0,0 @@ -../../../common/driver/fpga_prom.h \ No newline at end of file diff --git a/pgpcard/driver/src/pgp_common.c b/pgpcard/driver/src/pgp_common.c deleted file mode 100755 index bcf2b53..0000000 --- a/pgpcard/driver/src/pgp_common.c +++ /dev/null @@ -1,73 +0,0 @@ -/** - *----------------------------------------------------------------------------- - * Title : Common PGP functions - * ---------------------------------------------------------------------------- - * File : pgp_common.h - * Author : Ryan Herbst, rherbst@slac.stanford.edu - * Created : 2016-08-08 - * Last update: 2016-08-08 - * ---------------------------------------------------------------------------- - * Description: - * Common PGP functions - * ---------------------------------------------------------------------------- - * This file is part of the aes_stream_drivers package. It is subject to - * the license terms in the LICENSE.txt file found in the top-level directory - * of this distribution and at: - * https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html. - * No part of the aes_stream_drivers package, including this file, may be - * copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE.txt file. - * ---------------------------------------------------------------------------- -**/ -#include -#include - -// Display card Info -void PgpCard_InfoShow(struct seq_file *s, struct PgpInfo *info) { - seq_printf(s,"-------------- Card Info ------------------\n"); - seq_printf(s," Type : 0x%.2x\n",info->type); - seq_printf(s," Version : 0x%.8x\n",info->version); - seq_printf(s," Serial : 0x%.16llx\n",info->serial); - seq_printf(s," BuildStamp : %s\n",info->buildStamp); - seq_printf(s," LaneMask : 0x%.4x\n",info->laneMask); - seq_printf(s," VcPerMask : 0x%.2x\n",info->vcPerMask); - seq_printf(s," PgpRate : %i\n",info->pgpRate); - seq_printf(s," PromPrgEn : %i\n",info->promPrgEn); - seq_printf(s," EvrSupport : %i\n",info->evrSupport); -} - - -// Display PCI Status -void PgpCard_PciShow(struct seq_file *s, struct PciStatus *status) { - seq_printf(s,"-------------- PCI Info -------------------\n"); - seq_printf(s," PciCommand : 0x%.4x\n",status->pciCommand); - seq_printf(s," PciStatus : 0x%.4x\n",status->pciStatus); - seq_printf(s," PciDCommand : 0x%.4x\n",status->pciDCommand); - seq_printf(s," PciDStatus : 0x%.4x\n",status->pciDStatus); - seq_printf(s," PciLCommand : 0x%.4x\n",status->pciLCommand); - seq_printf(s," PciLStatus : 0x%.4x\n",status->pciLStatus); - seq_printf(s," PciLinkState : 0x%x\n",status->pciLinkState); - seq_printf(s," PciFunction : 0x%x\n",status->pciFunction); - seq_printf(s," PciDevice : 0x%x\n",status->pciDevice); - seq_printf(s," PciBus : 0x%.2x\n",status->pciBus); - seq_printf(s," PciLanes : %i\n",status->pciLanes); -} - - -// Display Lane Status -void PgpCard_LaneShow(struct seq_file *s, struct PgpStatus *status) { - seq_printf(s,"-------------- Lane %i --------------------\n",status->lane); - seq_printf(s," LoopBack : %i\n",status->loopBack); - seq_printf(s," LocLinkReady : %i\n",status->locLinkReady); - seq_printf(s," RemLinkReady : %i\n",status->remLinkReady); - seq_printf(s," RxReady : %i\n",status->rxReady); - seq_printf(s," TxReady : %i\n",status->txReady); - seq_printf(s," RxCount : %i\n",status->rxCount); - seq_printf(s," CellErrCnt : %i\n",status->cellErrCnt); - seq_printf(s," LinkDownCnt : %i\n",status->linkDownCnt); - seq_printf(s," LinkErrCnt : %i\n",status->linkErrCnt); - seq_printf(s," FifoErr : %i\n",status->fifoErr); - seq_printf(s," RemData : 0x%.2x\n",status->remData); - seq_printf(s," RemBuffStatus : 0x%.2x\n",status->remBuffStatus); -} - diff --git a/pgpcard/driver/src/pgp_common.h b/pgpcard/driver/src/pgp_common.h deleted file mode 100755 index f184bda..0000000 --- a/pgpcard/driver/src/pgp_common.h +++ /dev/null @@ -1,52 +0,0 @@ -/** - *----------------------------------------------------------------------------- - * Title : Common PGP functions - * ---------------------------------------------------------------------------- - * File : pgp_common.h - * Author : Ryan Herbst, rherbst@slac.stanford.edu - * Created : 2016-08-08 - * Last update: 2016-08-08 - * ---------------------------------------------------------------------------- - * Description: - * Common PGP functions - * ---------------------------------------------------------------------------- - * This file is part of the aes_stream_drivers package. It is subject to - * the license terms in the LICENSE.txt file found in the top-level directory - * of this distribution and at: - * https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html. - * No part of the aes_stream_drivers package, including this file, may be - * copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE.txt file. - * ---------------------------------------------------------------------------- -**/ -#ifndef __PGP_COMMON_H__ -#define __PGP_COMMON_H__ - -#include -#include -#include -#include - -struct pgpprom_reg { - uint32_t promData; - uint32_t promAddr; - uint32_t promRead; -}; - -// Display card Info -void PgpCard_InfoShow(struct seq_file *s, struct PgpInfo *info); - -// Display PCI Status -void PgpCard_PciShow(struct seq_file *s, struct PciStatus *status); - -// Display Lane Status -void PgpCard_LaneShow(struct seq_file *s, struct PgpStatus *status); - -// Prom Read -int32_t PgpCard_PromWrite(struct DmaDevice *dev, struct pgpprom_reg *reg, uint64_t arg); - -// Prom write -int32_t PgpCard_PromRead(struct DmaDevice *dev, struct pgpprom_reg *reg, uint64_t arg); - -#endif - diff --git a/pgpcard/driver/src/pgp_gen2.c b/pgpcard/driver/src/pgp_gen2.c deleted file mode 100755 index cab1eab..0000000 --- a/pgpcard/driver/src/pgp_gen2.c +++ /dev/null @@ -1,665 +0,0 @@ -/** - *----------------------------------------------------------------------------- - * Title : PGP Card Gen1 & Gen2 Functions - * ---------------------------------------------------------------------------- - * File : pgp_gen2.c - * Author : Ryan Herbst, rherbst@slac.stanford.edu - * Created : 2016-08-08 - * Last update: 2016-08-08 - * ---------------------------------------------------------------------------- - * Description: - * Access functions for Gen1 & Gen2 PGP Cards - * ---------------------------------------------------------------------------- - * This file is part of the aes_stream_drivers package. It is subject to - * the license terms in the LICENSE.txt file found in the top-level directory - * of this distribution and at: - * https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html. - * No part of the aes_stream_drivers package, including this file, may be - * copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE.txt file. - * ---------------------------------------------------------------------------- -**/ -#include -#include -#include -#include -#include -#include -#include -#include - -// Set functions for gen2 card -struct hardware_functions PgpCardG2_functions = { - .irq = PgpCardG2_Irq, - .init = PgpCardG2_Init, - .enable = PgpCardG2_Enable, - .clear = PgpCardG2_Clear, - .retRxBuffer = PgpCardG2_RetRxBuffer, - .sendBuffer = PgpCardG2_SendBuffer, - .command = PgpCardG2_Command, - .seqShow = PgpCardG2_SeqShow -}; - -// Interrupt handler -irqreturn_t PgpCardG2_Irq(int irq, void *dev_id) { - uint32_t stat; - uint32_t descA; - uint32_t descB; - uint32_t dmaId; - uint32_t subId; - irqreturn_t ret; - - struct DmaDesc * desc; - struct DmaBuffer * buff; - struct DmaDevice * dev; - struct PgpInfo * info; - struct PgpCardG2Reg * reg; - - dev = (struct DmaDevice *)dev_id; - reg = (struct PgpCardG2Reg *)dev->reg; - info = (struct PgpInfo *)dev->hwData; - - // Read IRQ Status - stat = ioread32(&(reg->irq)); - asm("nop"); - - // Is this the source - if ( (stat & 0x2) != 0 ) { - - if ( dev->debug > 0 ) dev_info(dev->device,"Irq: IRQ Called.\n"); - - // Disable interrupts - iowrite32(0,&(reg->irq)); - - // Read Tx completion status - stat = ioread32(&(reg->txStatus)); - asm("nop"); - - // Tx Data is ready - if ( (stat & 0x00000400) != 0 ) { - - do { - - // Read dma value - stat = ioread32(&(reg->txRead)); - asm("nop"); - if ( dev->debug > 0 ) - dev_info(dev->device,"Irq: Return TX Status Value %.8x.\n",stat); - - // Attempt to find buffer in tx pool and return. otherwise return rx entry to hw. - if ((buff = dmaRetBufferIrq (dev,stat&0xFFFFFFFC)) != NULL) { - iowrite32((stat & 0xFFFFFFFC),&(reg->rxFree)); - } - - // Repeat while next valid flag is set - } while ( (stat & 0x2) != 0 ); - } - - // Read Rx completion status - stat = ioread32(&(reg->rxStatus)); - asm("nop"); - - // Data is ready - if ( (stat & 0x00000400) != 0 ) { - do { - - // Read descriptor - descA = ioread32(&(reg->rxRead0)); - asm("nop"); - descB = ioread32(&(reg->rxRead1)); - asm("nop"); - - // Find RX buffer entry - if ((buff = dmaFindBufferList (&(dev->rxBuffers),descB&0xFFFFFFFC)) != NULL) { - - // Extract data from descriptor - buff->count++; - dmaId = (descA >> 30) & 0x3; - subId = (descA >> 28) & 0x3; - buff->flags = (descA >> 27) & 0x1; - buff->size = (descA & 0x00FFFFFF) * 4; - buff->error = 0; - - // Set DEST, with adjustment for interleaved version - // Each DMA engine is a VC - if ( info->type == PGP_GEN2_VCI ) { - buff->dest = (dmaId & 0x2) * 4; // Lane - buff->dest += (dmaId & 0x1); // VC - } - - // Each lane has 4 VCs, one DMA engine per lane - else { - buff->dest = dmaId * 4; // Lane - buff->dest += subId; // VC - } - - // Setup errors - if ( (descA >> 26) & 0x1) buff->error |= DMA_ERR_LEN; - if ( (descA >> 25) & 0x1) buff->error |= DMA_ERR_FIFO; - if ( (descA >> 24) & 0x1) buff->error |= PGP_ERR_EOFE; - - if ( dev->debug > 0 ) { - dev_info(dev->device,"Irq: Rx Size=%i, Dest=0x%x, Error=0x%x, Cont=%i.\n", - buff->size, buff->dest, buff->error, buff->flags); - } - - // Lock mask records - // This ensures close does not occur while irq routine is - // pushing data to desc rx queue - spin_lock(&dev->maskLock); - - // Find owner of destination - desc = dev->desc[buff->dest]; - - // Return entry to FPGA if /vc is not open - if ( desc == NULL ) { - if ( dev->debug > 0 ) { - dev_info(dev->device,"Irq: Port not open return to free list.\n"); - } - iowrite32((descB & 0xFFFFFFFC),&(reg->rxFree)); - } - - // lane/vc is open, Add to RX Queue - else dmaRxBuffer(desc,buff); - - // Unlock - spin_unlock(&dev->maskLock); - } - - // Buffer was not found - else dev_warn(dev->device,"Irq: Failed to locate RX descriptor 0x%.8x.\n", - (uint32_t)(descB&0xFFFFFFFC)); - - // Repeat while next valid flag is set - } while ( (descB & 0x2) != 0 ); - } - - // Enable interrupts - if ( dev->debug > 0 ) - dev_info(dev->device,"Irq: Done.\n"); - iowrite32(1,&(reg->irq)); - ret = IRQ_HANDLED; - } - else ret = IRQ_NONE; - return(ret); -} - - -// Init card in top level Probe -void PgpCardG2_Init(struct DmaDevice *dev) { - uint32_t tmp; - uint32_t maxFrame; - uint32_t x; - - struct PgpInfo * info; - struct PgpCardG2Reg * reg; - struct DmaBuffer * buff; - - reg = (struct PgpCardG2Reg *)dev->reg; - - // Remove card reset, bit 1 of control register - tmp = ioread32(&(reg->control)); - tmp &= 0xFFFFFFFD; - iowrite32(tmp,&(reg->control)); - - // Setup max frame value - maxFrame = dev->cfgSize / 4; - maxFrame |= 0x80000000; - - // Continue enabled - if ( dev->cfgCont ) maxFrame |= 0x40000000; - dev_info(dev->device,"Init: Setting rx continue flag=%i.\n", dev->cfgCont); - - // Set to hardware - iowrite32(maxFrame,&(reg->rxMaxFrame)); - - // Push receive buffers to hardware - for (x=dev->rxBuffers.baseIdx; x < (dev->rxBuffers.baseIdx + dev->rxBuffers.count); x++) { - buff = dmaGetBufferList(&(dev->rxBuffers),x); - if ( dmaBufferToHw(buff) < 0 ) - dev_warn(dev->device,"Init: Failed to map dma buffer.\n"); - else iowrite32(buff->buffHandle,&(reg->rxFree)); - } - - // Init hardware info - dev->hwData = (void *)kmalloc(sizeof(struct PgpInfo),GFP_KERNEL); - info = (struct PgpInfo *)dev->hwData; - - memset(info,0,sizeof(struct PgpInfo)); - - info->version = ioread32(&(reg->version)); - info->pgpRate = 3125; - info->evrSupport = 0; - memset(dev->destMask,0,DMA_MASK_SIZE); - - // Use firmware version to distinguish between gen1/gen2 & other special cards - switch((info->version >> 12) & 0xFFFFF) { - case 0xCEC80: - dev->destMask[0] = 0xFF; - dev->destMask[1] = 0xFF; - info->type = PGP_GEN1; - info->laneMask = 0xF; - info->vcPerMask = 0xF; - info->promPrgEn = 0; - break; - case 0xCEC82: - dev->destMask[0] = 0xFF; - dev->destMask[1] = 0xFF; - info->type = PGP_GEN2; - info->laneMask = 0xF; - info->vcPerMask = 0xF; - info->promPrgEn = 1; - break; - case 0xCEC83: - dev->destMask[0] = 0x03; - dev->destMask[1] = 0x03; - info->type = PGP_GEN2_VCI; - info->laneMask = 0x5; - info->vcPerMask = 0x3; - info->promPrgEn = 1; - break; - default: - dev->destMask[0] = 0xFF; - dev->destMask[1] = 0xFF; - info->type = PGP_GEN2; - info->laneMask = 0xF; - info->vcPerMask = 0xF; - info->promPrgEn = 1; - break; - } - - dev_info(dev->device,"Init: Found card. Version=0x%x, Type=0x%.2x\n", info->version,info->type); -} - -// enable the card -void PgpCardG2_Enable(struct DmaDevice *dev) { - struct PgpCardG2Reg * reg; - - reg = (struct PgpCardG2Reg *)dev->reg; - - // Enable interrupts - iowrite32(1,&(reg->irq)); -} - -// Clear card in top level Remove -void PgpCardG2_Clear(struct DmaDevice *dev) { - uint32_t tmp; - struct PgpCardG2Reg *reg; - reg = (struct PgpCardG2Reg *)dev->reg; - - // Disable interrupts - iowrite32(0,&(reg->irq)); - - // Clear RX buffer - iowrite32(0,&(reg->rxMaxFrame)); - - // Set card reset, bit 1 of control register - tmp = ioread32(&(reg->control)); - tmp |= 0x00000002; - iowrite32(tmp,&(reg->control)); - - // Clear hw data - kfree(dev->hwData); -} - - -// Return receive buffer to card -// Single write so we don't need to lock -void PgpCardG2_RetRxBuffer(struct DmaDevice *dev, struct DmaBuffer **buff, uint32_t count) { - struct PgpCardG2Reg *reg; - uint32_t x; - - reg = (struct PgpCardG2Reg *)dev->reg; - - for (x=0; x < count; x++) { - if ( dmaBufferToHw(buff[x]) < 0 ) - dev_warn(dev->device,"RetRxBuffer: Failed to map dma buffer.\n"); - else iowrite32(buff[x]->buffHandle,&(reg->rxFree)); - } -} - - -// Send a buffer -int32_t PgpCardG2_SendBuffer(struct DmaDevice *dev, struct DmaBuffer **buff, uint32_t count) { - uint32_t descA; - uint32_t descB; - uint32_t dmaId; - uint32_t subId; - uint32_t x; - - struct PgpInfo * info; - struct PgpCardG2Reg * reg; - - reg = (struct PgpCardG2Reg *)dev->reg; - info = (struct PgpInfo *)dev->hwData; - - for (x=0; x < count; x++) { - - if ( (buff[x]->size % 4) != 0 ) { - dev_warn(dev->device,"SendBuffer: Frame size not a multiple of 4.\n"); - dmaQueuePush(&(dev->tq),buff[x]); - return(-1); - } - - // Lane remap for VC interleaved card where each DMA engine is a single VC - if ( info->type == PGP_GEN2_VCI ) { - dmaId = (buff[x]->dest / 4) + (buff[x]->dest % 4); - subId = 0; - } else { - dmaId = buff[x]->dest / 4; - subId = buff[x]->dest % 4; - } - - if ( dmaBufferToHw(buff[x]) < 0 ) { - dev_warn(dev->device,"SendBuffer: Failed to map dma buffer.\n"); - return(-1); - } - - // Generate Tx descriptor - descA = (dmaId << 30) & 0xC0000000; // Bits 31:30 = Lane - descA += (subId << 28) & 0x30000000; // Bits 29:28 = VC - descA += (buff[x]->flags << 27) & 0x08000000; // Bits 27 = Cont - descA += (buff[x]->size / 4 ) & 0x00FFFFFF; // Bits 23:0 = Length - descB = buff[x]->buffHandle; - - // Lock hw - spin_lock(&dev->writeHwLock); - - // Write descriptor - switch ( dmaId ) { - case 0: - iowrite32(descA,&(reg->txL0Wr0)); - asm("nop"); - iowrite32(descB,&(reg->txL0Wr1)); - asm("nop"); - break; - case 1: - iowrite32(descA,&(reg->txL1Wr0)); - asm("nop"); - iowrite32(descB,&(reg->txL1Wr1)); - asm("nop"); - break; - case 2: - iowrite32(descA,&(reg->txL2Wr0)); - asm("nop"); - iowrite32(descB,&(reg->txL2Wr1)); - asm("nop"); - break; - case 3: - iowrite32(descA,&(reg->txL3Wr0)); - asm("nop"); - iowrite32(descB,&(reg->txL3Wr1)); - asm("nop"); - break; - default: break; - } - - // UnLock hw - spin_unlock(&dev->writeHwLock); - } - return(count); -} - - -// Execute command -int32_t PgpCardG2_Command(struct DmaDevice *dev, uint32_t cmd, uint64_t arg) { - uint32_t mask; - uint32_t tmp; - uint32_t tempLane; - uint32_t tempVal; - int32_t ret; - - struct PgpInfo * info; - struct PgpStatus status; - struct PciStatus pciStatus; - struct PgpCardG2Reg * reg; - - reg = (struct PgpCardG2Reg *)dev->reg; - info = (struct PgpInfo * )dev->hwData; - - switch (cmd) { - - // Control loopback - case PGP_Set_Loop: - tempLane = arg & 0xFF; - tempVal = (arg >> 8) & 0x1; - - if ( tempLane > 4 ) return(0); - - spin_lock(&dev->commandLock); - - // Set loop - if ( tempVal ) { - tmp = ioread32(&(reg->control)); - tmp |= ((0x10 << tempLane) & 0xF0); - iowrite32(tmp,&(reg->control)); - if (dev->debug > 0) dev_info(dev->device,"Set loopback for %u\n", tempLane); - - // Clear loop - } else { - mask = 0xFFFFFFFF ^ ((0x10 << tempLane) & 0xF0); - tmp = ioread32(&(reg->control)); - tmp &= mask; - iowrite32(tmp,&(reg->control)); - if (dev->debug > 0) dev_info(dev->device,"Clr loopback for %u\n", tempLane); - } - spin_unlock(&dev->commandLock); - return(0); - break; - - // Reset counters - case PGP_Count_Reset: - spin_lock(&dev->commandLock); - tmp = ioread32(&(reg->control)); // Store old reg val - iowrite32(tmp|0x1,&(reg->control)); // Set reset bit - iowrite32(tmp,&(reg->control)); // Set old reg val - spin_unlock(&dev->commandLock); - if (dev->debug > 0) dev_info(dev->device,"Count reset\n"); - return(0); - break; - - // Set lane sideband data - case PGP_Set_Data: - tempLane = arg & 0xFF; - tempVal = (arg >> 8) & 0xFF; - - switch ( tempLane ) { - case 0x0: iowrite32(tempVal,&(reg->l0Data)); break; - case 0x1: iowrite32(tempVal,&(reg->l1Data)); break; - case 0x2: iowrite32(tempVal,&(reg->l2Data)); break; - case 0x3: iowrite32(tempVal,&(reg->l3Data)); break; - default: break; - } - - // Debug - if (dev->debug > 0) dev_info(dev->device,"Set local data for %u to %u\n", tempLane, tempVal); - return(0); - break; - - // Read card info - case PGP_Read_Info: - if ((ret=copy_to_user((void *)arg,info,sizeof(struct PgpInfo)))) { - dev_warn(dev->device,"Command: copy_to_user failed. ret=%i, user=%p kern=%p\n", - ret, (void *)arg, info); - return(-1); - } - return(0); - break; - - // Read PCI Status - case PGP_Read_Pci: - PgpCardG2_GetPci(dev,&pciStatus); - - if ((ret=copy_to_user((void *)arg,&pciStatus,sizeof(struct PciStatus)))) { - dev_warn(dev->device,"Command: copy_to_user failed. ret=%i, user=%p kern=%p\n", - ret, (void *)arg, &pciStatus); - return(-1); - } - return(0); - break; - - // Read status for a lane - case PGP_Read_Status: - if ((ret=copy_from_user(&status,(void *)arg,sizeof(struct PgpStatus)))) { - dev_warn(dev->device,"Command: copy_from_user failed. ret=%i, user=%p kern=%p\n", - ret, (void *)arg, &status); - return(-1); - } - - PgpCardG2_GetStatus(dev,&status,status.lane); - - if ((ret=copy_to_user((void *)arg,&status,sizeof(struct PgpStatus)))) { - dev_warn(dev->device,"Command: copy_to_user failed. ret=%i, user=%p kern=%p\n", - ret, (void *)arg, &status); - return(-1); - } - return(0); - break; - - // Write to prom - case FPGA_Write_Prom: - if ( info->promPrgEn ) return(FpgaProm_Write(dev,reg->promRegs,arg)); - else return(-1); - break; - - // Read from prom - case FPGA_Read_Prom: - if ( info->promPrgEn ) return(FpgaProm_Read(dev,reg->promRegs,arg)); - else return(-1); - break; - - default: - dev_warn(dev->device,"Command: Invalid command=%i.\n",cmd); - return(-1); - break; - } -} - -// Add data to proc dump -void PgpCardG2_SeqShow(struct seq_file *s, struct DmaDevice *dev) { - uint32_t tmp; - uint32_t cnt; - uint32_t x; - - struct PgpInfo * info; - struct PciStatus pci; - struct PgpStatus status; - struct PgpCardG2Reg * reg; - - reg = (struct PgpCardG2Reg *)dev->reg; - info = (struct PgpInfo * )dev->hwData; - - seq_printf(s,"\n"); - PgpCard_InfoShow(s,info); - seq_printf(s,"\n"); - PgpCardG2_GetPci(dev,&pci); - PgpCard_PciShow(s,&pci); - - for (x=0; x < 4; x++) { - if ( ((1 << x) & info->laneMask) == 0 ) continue; - PgpCardG2_GetStatus(dev,&status,x); - seq_printf(s,"\n"); - PgpCard_LaneShow(s,&status); - } - - seq_printf(s,"\n"); - seq_printf(s,"-------------- General HW -----------------\n"); - - seq_printf(s," TxCount : %i\n",ioread32(&(reg->txCount))); - seq_printf(s," RxCount : %i\n",ioread32(&(reg->rxCount))); - - tmp = ioread32(&(reg->rxStatus)); - cnt = ((tmp >> 16)&0x3FF) + ((tmp >> 29)&0x1); - - seq_printf(s," RxFreeEmpty : %i\n",(tmp >> 31)&0x1); - seq_printf(s," RxFreeFull : %i\n",(tmp >> 30)&0x1); - seq_printf(s," RxFreeValid : %i\n",(tmp >> 29)&0x1); - seq_printf(s," RxFreeFifoCount : %i\n",(tmp >> 16)&0x3FF); - seq_printf(s," Real Free Fifo Cnt : %i\n",cnt); - seq_printf(s," RxReadReady : %i\n",(tmp >> 10)&0x1); - seq_printf(s," RxRetFifoCount : %i\n",tmp&0x3FF); -} - - -// Get PCI Status -void PgpCardG2_GetPci(struct DmaDevice *dev, struct PciStatus *status) { - uint32_t tmp; - - struct PgpCardG2Reg *reg; - reg = (struct PgpCardG2Reg *)dev->reg; - - memset(status,0,sizeof(struct PciStatus)); - - tmp = ioread32(&(reg->pciStat0)); - status->pciCommand = ((tmp >> 16)&0xFFFF); - status->pciStatus = (tmp & 0xFFFF); - - tmp = ioread32(&(reg->pciStat1)); - status->pciDCommand = ((tmp >> 16)&0xFFFF); - status->pciDStatus = (tmp & 0xFFFF); - - tmp = ioread32(&(reg->pciStat2)); - status->pciLCommand = ((tmp >> 16)&0xFFFF); - status->pciLStatus = (tmp & 0xFFFF); - status->pciLanes = ((tmp >> 4) & 0x1F); - - tmp = ioread32(&(reg->pciStat3)); - status->pciLinkState = ((tmp >> 24)&0x7); - status->pciFunction = ((tmp >> 16)&0x3); - status->pciDevice = ((tmp >> 8)&0xF); - status->pciBus = (tmp&0xFF); -} - -// Get Lane Status -void PgpCardG2_GetStatus(struct DmaDevice *dev, struct PgpStatus *status, uint8_t lane) { - uint32_t tempVal; - - struct PgpCardG2Reg *reg; - reg = (struct PgpCardG2Reg *)dev->reg; - - lane = lane & 0x3; - - memset(status,0,sizeof(struct PgpStatus)); - status->lane = lane; - - // Control reg - tempVal = ioread32(&(reg->control)); - switch(lane) { - case 0: status->loopBack = (tempVal >> 4) & 0x1; break; - case 1: status->loopBack = (tempVal >> 5) & 0x1; break; - case 2: status->loopBack = (tempVal >> 6) & 0x1; break; - case 3: status->loopBack = (tempVal >> 7) & 0x1; break; - } - - // Per lane status - switch(lane) { - case 0: tempVal = ioread32(&(reg->pgp0Stat)); break; - case 1: tempVal = ioread32(&(reg->pgp1Stat)); break; - case 2: tempVal = ioread32(&(reg->pgp2Stat)); break; - case 3: tempVal = ioread32(&(reg->pgp3Stat)); break; - default: tempVal = 0; break; - } - - status->locLinkReady = ( tempVal ) & 0x1; - status->remLinkReady = ( tempVal >> 1) & 0x1; - status->rxReady = ( tempVal >> 2) & 0x1; - status->txReady = ( tempVal >> 3) & 0x1; - status->rxCount = ( tempVal >> 4) & 0xF; - status->cellErrCnt = ( tempVal >> 8) & 0xF; - status->linkDownCnt = ( tempVal >> 12) & 0xF; - status->linkErrCnt = ( tempVal >> 16) & 0xF; - status->fifoErr = ( tempVal >> 20) & 0x1; - - // Remote and buffer status - switch(lane) { - case 0: tempVal = ioread32(&(reg->l0Data)); break; - case 1: tempVal = ioread32(&(reg->l1Data)); break; - case 2: tempVal = ioread32(&(reg->l2Data)); break; - case 3: tempVal = ioread32(&(reg->l3Data)); break; - default: tempVal = 0; break; - } - - status->remData = ( tempVal >> 8) & 0xFF; - status->remBuffStatus = ( tempVal >> 16) & 0xFF; -} - diff --git a/pgpcard/driver/src/pgp_gen2.h b/pgpcard/driver/src/pgp_gen2.h deleted file mode 100755 index e771ca9..0000000 --- a/pgpcard/driver/src/pgp_gen2.h +++ /dev/null @@ -1,124 +0,0 @@ -/** - *----------------------------------------------------------------------------- - * Title : PGP Card Gen1 & Gen2 Functions - * ---------------------------------------------------------------------------- - * File : pgp_gen2.h - * Author : Ryan Herbst, rherbst@slac.stanford.edu - * Created : 2016-08-08 - * Last update: 2016-08-08 - * ---------------------------------------------------------------------------- - * Description: - * Access functions for Gen1 & Gen2 PGP Cards - * ---------------------------------------------------------------------------- - * This file is part of the aes_stream_drivers package. It is subject to - * the license terms in the LICENSE.txt file found in the top-level directory - * of this distribution and at: - * https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html. - * No part of the aes_stream_drivers package, including this file, may be - * copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE.txt file. - * ---------------------------------------------------------------------------- -**/ -#ifndef __PGP_GEN2_H__ -#define __PGP_GEN2_H__ - -#include -#include -#include -#include - -// Address Map, offset from base -struct PgpCardG2Reg { - uint32_t version; // 0x000 - uint32_t scratch; // 0x004 - uint32_t irq; // 0x008 - uint32_t control; // 0x00C - uint32_t l0Data; // 0x010 - uint32_t l1Data; // 0x014 - uint32_t l2Data; // 0x018 - uint32_t l3Data; // 0x01C - - uint32_t spare0[8]; // 0x020 - 0x03C - - uint32_t pgp0Stat; // 0x040 - uint32_t pgp1Stat; // 0x044 - uint32_t pgp2Stat; // 0x048 - uint32_t pgp3Stat; // 0x04C - - uint32_t spare1[12]; // 0x050 - 0x07C - - uint32_t pciStat0; // 0x080 - uint32_t pciStat1; // 0x084 - uint32_t pciStat2; // 0x088 - uint32_t pciStat3; // 0x08C - - uint32_t spare2[220]; // 0x090 - 0x3FC - - uint32_t rxFree; // 0x400 - uint32_t rxMaxFrame; // 0x404 - uint32_t rxStatus; // 0x408 - uint32_t rxCount; // 0x40C - - uint32_t spare3[4]; // 0x410 - 0x41C - - uint32_t rxRead0; // 0x420 - uint32_t rxRead1; // 0x424 - - uint32_t spare4[246]; // 0x428 - 0x7FC - - uint32_t txL0Wr0; // 0x800 - uint32_t txL0Wr1; // 0x804 - uint32_t txL1Wr0; // 0x808 - uint32_t txL1Wr1; // 0x80C - uint32_t txL2Wr0; // 0x810 - uint32_t txL2Wr1; // 0x814 - uint32_t txL3Wr0; // 0x818 - uint32_t txL3Wr1; // 0x81C - uint32_t txStatus; // 0x820 - uint32_t txRead; // 0x824 - uint32_t txCount; // 0x828 - - uint32_t spare5[245]; // 0x82C - 0xBFC - - uint32_t promRegs[3]; // Prom registers -}; - -// Set functions for gen2 card -extern struct hardware_functions PgpCardG2_functions; - -// Interrupt handler -irqreturn_t PgpCardG2_Irq(int irq, void *dev_id); - -// Init card in top level Probe -void PgpCardG2_Init(struct DmaDevice *dev); - -// Enable -void PgpCardG2_Enable(struct DmaDevice *dev); - -// Clear card in top level Remove -void PgpCardG2_Clear(struct DmaDevice *dev); - -// Return receive buffer to card -void PgpCardG2_RetRxBuffer(struct DmaDevice *dev, struct DmaBuffer **buff, uint32_t count); - -// Send a buffer -int32_t PgpCardG2_SendBuffer(struct DmaDevice *dev, struct DmaBuffer **buff, uint32_t count); - -// Execute command -int32_t PgpCardG2_Command(struct DmaDevice *dev, uint32_t cmd, uint64_t arg); - -// Add data to proc dump -void PgpCardG2_SeqShow(struct seq_file *s, struct DmaDevice *dev); - -/////////////////////////////////// -// Local helper functions -/////////////////////////////////// - -// Get PCI Status -void PgpCardG2_GetPci(struct DmaDevice *dev, struct PciStatus * status); - -// Get Lane Status -void PgpCardG2_GetStatus(struct DmaDevice *dev, struct PgpStatus *status, uint8_t lane); - -#endif - diff --git a/pgpcard/driver/src/pgp_gen3.c b/pgpcard/driver/src/pgp_gen3.c deleted file mode 100755 index e0ed767..0000000 --- a/pgpcard/driver/src/pgp_gen3.c +++ /dev/null @@ -1,843 +0,0 @@ -/** - *----------------------------------------------------------------------------- - * Title : PGP Card Gen3 Functions - * ---------------------------------------------------------------------------- - * File : pgp_gen3.c - * Author : Ryan Herbst, rherbst@slac.stanford.edu - * Created : 2016-08-11 - * Last update: 2016-08-11 - * ---------------------------------------------------------------------------- - * Description: - * Access functions for Gen32 PGP Cards - * ---------------------------------------------------------------------------- - * This file is part of the aes_stream_drivers package. It is subject to - * the license terms in the LICENSE.txt file found in the top-level directory - * of this distribution and at: - * https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html. - * No part of the aes_stream_drivers package, including this file, may be - * copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE.txt file. - * ---------------------------------------------------------------------------- -**/ -#include -#include -#include -#include -#include -#include -#include -#include -#include - -// Set functions for gen2 card -struct hardware_functions PgpCardG3_functions = { - .irq = PgpCardG3_Irq, - .init = PgpCardG3_Init, - .enable = PgpCardG3_Enable, - .clear = PgpCardG3_Clear, - .retRxBuffer = PgpCardG3_RetRxBuffer, - .sendBuffer = PgpCardG3_SendBuffer, - .command = PgpCardG3_Command, - .seqShow = PgpCardG3_SeqShow -}; - -// Interrupt handler -irqreturn_t PgpCardG3_Irq(int irq, void *dev_id) { - uint32_t stat; - uint32_t descA; - uint32_t descB; - uint32_t dmaId; - uint32_t subId; - irqreturn_t ret; - - struct DmaDesc * desc; - struct DmaBuffer * buff; - struct DmaDevice * dev; - struct PgpInfo * info; - struct PgpCardG3Reg * reg; - - dev = (struct DmaDevice *)dev_id; - reg = (struct PgpCardG3Reg *)dev->reg; - info = (struct PgpInfo *)dev->hwData; - - // Read IRQ Status - stat = ioread32(&(reg->irq)); - asm("nop"); - - // Is this the source - if ( (stat & 0x2) != 0 ) { - - if ( dev->debug > 0 ) dev_info(dev->device,"Irq: IRQ Called.\n"); - - // Disable interrupts - iowrite32(0,&(reg->irq)); - - // Read Tx completion status - stat = ioread32(&(reg->txStat[1])); - asm("nop"); - - // Tx Data is ready - if ( (stat & 0x80000000) != 0 ) { - - do { - - // Read dma value - stat = ioread32(&(reg->txRead)); - asm("nop"); - - if ( (stat & 0x1) == 0x1 ) { - - if ( dev->debug > 0 ) - dev_info(dev->device,"Irq: Return TX Status Value %.8x.\n",stat); - - // Attempt to find buffer in tx pool and return. otherwise return rx entry to hw. - if ((buff = dmaRetBufferIrq (dev,stat&0xFFFFFFFC)) != NULL) { - iowrite32((stat & 0xFFFFFFFC), &(reg->rxFree[buff->owner])); - } - } - - // Repeat while next valid flag is set - } while ( (stat & 0x1) == 0x1 ); - } - - // Read Rx completion status - stat = ioread32(&(reg->rxStatus)); - asm("nop"); - - // Data is ready - if ( (stat & 0x80000000) != 0 ) { - do { - - // Read descriptor - descA = ioread32(&(reg->rxRead[0])); - asm("nop"); - descB = ioread32(&(reg->rxRead[1])); - asm("nop"); - - if ( ( descB & 0x1) == 0x1 ) { - - // Find RX buffer entry - if ((buff = dmaFindBufferList (&(dev->rxBuffers),descB&0xFFFFFFFC)) != NULL) { - - // Extract data from descriptor - buff->count++; - buff->flags = (descA >> 29) & 0x1; // Bit 29 (CONT) - dmaId = (descA >> 26) & 0x7; // Bits 28:26 - subId = (descA >> 24) & 0x3; // Bits 25:24 - buff->size = (descA & 0x00FFFFFF) * 4; // 23:00 - buff->error = 0; - - // Adjust VC for interleaved version - // Each dma engine is a VC - if ( info->type == PGP_GEN3_VCI ) { - buff->dest = (dmaId / 2) * 4; // lane - buff->dest += (dmaId % 2); // vc - } else { - buff->dest = dmaId * 4; - buff->dest += subId; - } - - // Setup errors - if ( (descA >> 31) & 0x1) buff->error |= DMA_ERR_FIFO; - if ( (descA >> 30) & 0x1) buff->error |= PGP_ERR_EOFE; - - // Bit 1 of descB is the or of all errors, determine len error if others are not set - if (( (descB >> 1) & 0x1) && (buff->error == 0) ) buff->error |= DMA_ERR_LEN; - - if ( dev->debug > 0 ) { - dev_info(dev->device,"Irq: Rx Bytes=%i, Dest=%x, Error=0x%x, Cont=%i.\n", - buff->size, buff->dest, buff->error, buff->flags); - } - - // Lock mask records - // This ensures close does not occur while irq routine is - // pushing data to desc rx queue - spin_lock(&dev->maskLock); - - // Find owner of lane/vc - desc = dev->desc[buff->dest]; - - // Return entry to FPGA if lane/vc is not open - if ( desc == NULL ) { - if ( dev->debug > 0 ) { - dev_info(dev->device,"Irq: Port not open return to free list.\n"); - } - iowrite32((descB & 0xFFFFFFFC), &(reg->rxFree[(descA >> 26) & 0x7])); - } - - // lane/vc is open, Add to RX Queue - else dmaRxBuffer(desc,buff); - - // Unlock - spin_unlock(&dev->maskLock); - } - - // Buffer was not found - else dev_warn(dev->device,"Irq: Failed to locate RX descriptor %.8x.\n", - (uint32_t)(descB&0xFFFFFFFC)); - } - - // Repeat while next valid flag is set - } while ( (descB & 0x1) == 0x1 ); - } - - // Enable interrupts - if ( dev->debug > 0 ) - dev_info(dev->device,"Irq: Done.\n"); - iowrite32(1,&(reg->irq)); - ret = IRQ_HANDLED; - } - else ret = IRQ_NONE; - return(ret); -} - -// Init card in top level Probe -void PgpCardG3_Init(struct DmaDevice *dev) { - uint32_t maxFrame; - uint32_t tmp; - uint64_t tmpL; - uint32_t x; - - struct DmaBuffer * buff; - struct PgpInfo * info; - struct PgpCardG3Reg * reg; - reg = (struct PgpCardG3Reg *)dev->reg; - - // Remove card reset, bit 1 of control register - tmp = ioread32(&(reg->cardRstStat)); - tmp &= 0xFFFFFFFD; - iowrite32(tmp,&(reg->cardRstStat)); - - // Setup max frame value - maxFrame = dev->cfgSize / 4; - maxFrame |= 0x80000000; - - // Continue enabled - if ( dev->cfgCont ) maxFrame |= 0x40000000; - dev_info(dev->device,"Init: Setting rx continue flag=%i.\n", dev->cfgCont); - - // Set to hardware - iowrite32(maxFrame,&(reg->rxMaxFrame)); - - // Push receive buffers to hardware - // Distribute rx bufferes evently between free lists - for (x=dev->rxBuffers.baseIdx; x < (dev->rxBuffers.baseIdx + dev->rxBuffers.count); x++) { - buff = dmaGetBufferList(&(dev->rxBuffers),x); - if ( dmaBufferToHw(buff) < 0 ) - dev_warn(dev->device,"Init: Failed to map dma buffer.\n"); - else { - iowrite32(buff->buffHandle,&(reg->rxFree[x % 8])); - buff->owner = (x % 8); - } - } - - // Init hardware info - dev->hwData = (void *)kmalloc(sizeof(struct PgpInfo),GFP_KERNEL); - info = (struct PgpInfo *)dev->hwData; - - memset(info,0,sizeof(struct PgpInfo)); - - info->version = ioread32(&(reg->version)); - - // Form serial number - tmpL = ioread32(&(reg->serNumUpper)); - info->serial = tmpL << 32; - tmpL = ioread32(&(reg->serNumLower)); - info->serial |= tmpL; - - for (x=0; x < 64; x++) { - ((uint32_t *)info->buildStamp)[x] = ioread32((®->BuildStamp[x])); - } - info->pgpRate = ioread32(&(reg->pgpRate)); - memset(dev->destMask,0,DMA_MASK_SIZE); - - // Card info - if ( (ioread32(&(reg->vciMode)) & 0x1) != 0 ) { - info->type = PGP_GEN3_VCI; - info->laneMask = 0x0F; - info->vcPerMask = 0x3; - dev->destMask[0] = 0x33; - dev->destMask[1] = 0x33; - } else { - info->type = PGP_GEN3; - info->laneMask = 0xFF; - info->vcPerMask = 0xF; - dev->destMask[0] = 0xFF; - dev->destMask[1] = 0xFF; - dev->destMask[2] = 0xFF; - dev->destMask[3] = 0xFF; - } - info->promPrgEn = 1; - info->evrSupport = 1; - - dev_info(dev->device,"Init: Found card. Version=0x%x, Type=0x%.2x\n", - info->version,info->type); -} - -// Enable the card -void PgpCardG3_Enable(struct DmaDevice *dev) { - struct PgpCardG3Reg * reg; - reg = (struct PgpCardG3Reg *)dev->reg; - - // Enable interrupts - iowrite32(1,&(reg->irq)); -} - -// Clear card in top level Remove -void PgpCardG3_Clear(struct DmaDevice *dev) { - uint32_t tmp; - struct PgpCardG3Reg *reg; - reg = (struct PgpCardG3Reg *)dev->reg; - - // Disable interrupts - iowrite32(0,&(reg->irq)); - - // Clear RX buffer - iowrite32(0,&(reg->rxMaxFrame)); - - // Set card reset, bit 1 of control register - tmp = ioread32(&(reg->cardRstStat)); - tmp |= 0x00000002; - iowrite32(tmp,&(reg->cardRstStat)); - - // Clear hw data - kfree(dev->hwData); -} - - -// Return receive buffer to card -// Single write so we don't need to lock -void PgpCardG3_RetRxBuffer(struct DmaDevice *dev, struct DmaBuffer **buff, uint32_t count) { - struct PgpCardG3Reg *reg; - uint32_t x; - - reg = (struct PgpCardG3Reg *)dev->reg; - - for (x=0; x < count; x++) { - if ( dmaBufferToHw(buff[x]) < 0 ) - dev_warn(dev->device,"RetRxBuffer: Failed to map dma buffer.\n"); - else iowrite32(buff[x]->buffHandle,&(reg->rxFree[buff[x]->owner])); - } -} - - -// Send a buffer -int32_t PgpCardG3_SendBuffer(struct DmaDevice *dev, struct DmaBuffer **buff, uint32_t count) { - uint32_t descA; - uint32_t descB; - uint32_t dmaId; - uint32_t subId; - uint32_t x; - - struct PgpInfo * info; - struct PgpCardG3Reg * reg; - - reg = (struct PgpCardG3Reg *)dev->reg; - info = (struct PgpInfo *)dev->hwData; - - for (x=0; x < count; x++) { - - if ( (buff[x]->size % 4) != 0 ) { - dev_warn(dev->device,"SendBuffer: Frame size not a multiple of 4.\n"); - dmaQueuePush(&(dev->tq),buff[x]); - return(-1); - } - - // Lane remap for VC interleaved card where each DMA engine is a single VC - if ( info->type == PGP_GEN3_VCI ) { - dmaId = ((buff[x]->dest / 4) * 2) + (buff[x]->dest % 4); - subId = 0; - } else { - dmaId = buff[x]->dest / 4; - subId = buff[x]->dest % 4; - } - - if ( dmaBufferToHw(buff[x]) < 0 ) { - dev_warn(dev->device,"SendBuffer: Failed to map dma buffer.\n"); - return(-1); - } - - // Generate Tx descriptor - descA = (buff[x]->flags << 26) & 0x04000000; // Bits 26 = Cont - descA += (subId << 24) & 0x03000000; // Bits 25:24 = VC - descA += (buff[x]->size / 4 ) & 0x00FFFFFF; // Bits 23:0 = Length - descB = buff[x]->buffHandle; - - // Lock hw - spin_lock(&dev->writeHwLock); - - // Write descriptor - iowrite32(descA,&(reg->txWrA[dmaId])); - asm("nop"); - iowrite32(descB,&(reg->txWrB[dmaId])); - asm("nop"); - - // UnLock hw - spin_unlock(&dev->writeHwLock); - } - return(count); -} - - -// Execute command -int32_t PgpCardG3_Command(struct DmaDevice *dev, uint32_t cmd, uint64_t arg) { - uint32_t mask; - uint32_t tempLane; - uint32_t tempVal; - uint32_t tmp; - int32_t ret; - - struct PgpInfo * info; - struct PgpStatus status; - struct PciStatus pciStatus; - struct PgpCardG3Reg * reg; - struct PgpEvrControl evrControl; - struct PgpEvrStatus evrStatus; - - reg = (struct PgpCardG3Reg *)dev->reg; - info = (struct PgpInfo * )dev->hwData; - - switch (cmd) { - - // Control loopback - case PGP_Set_Loop: - tempLane = arg & 0xFF; - tempVal = (arg >> 8) & 0x1; - - if ( tempLane > 8 ) return(0); - - spin_lock(&dev->commandLock); - - // Set loop - if ( tempVal ) { - tmp = ioread32(&(reg->pgpCardStat[0])); - tmp |= (0x1 << ((tempLane&0x7) + 0)); - iowrite32(tmp,&(reg->pgpCardStat[0])); - if (dev->debug > 0) dev_info(dev->device,"Set loopback for %u\n", tempLane); - - // Clear loop - } else { - mask = 0xFFFFFFFF ^ (0x1 << ((tempLane&0x7) + 0)); - tmp = ioread32(&(reg->pgpCardStat[0])); - tmp &= mask; - iowrite32(tmp,&(reg->pgpCardStat[0])); - if (dev->debug > 0) dev_info(dev->device,"Clr loopback for %u\n", tempLane); - } - spin_unlock(&dev->commandLock); - return(0); - break; - - // Reset counters - case PGP_Count_Reset: - spin_lock(&dev->commandLock); - tmp = ioread32(&(reg->pgpCardStat[0])); // Store old reg val - iowrite32(tmp|0x1,&(reg->pgpCardStat[0])); // Set reset bit - iowrite32(tmp,&(reg->pgpCardStat[0])); // Set old reg val - spin_unlock(&dev->commandLock); - if (dev->debug > 0) dev_info(dev->device,"Count reset\n"); - return(0); - break; - - // Send OpCode - case PGP_Send_OpCode: - iowrite32(arg&0xFF,&(reg->pgpOpCode)); - if (dev->debug > 0) dev_info(dev->device,"Send OP-Code: %x\n", (uint8_t)arg); - return(0); - break; - - // Set lane sideband data - case PGP_Set_Data: - tempLane = arg & 0xF; - tempVal = (arg >> 8) & 0xFF; - - if ( tempLane > 8 ) return(0); - - iowrite32(tempVal,&(reg->pgpData[tempLane])); - - // Debug - if (dev->debug > 0) dev_info(dev->device,"Set local data for %i to %i\n", tempLane, tempVal); - return(-1); - break; - - // Read card info - case PGP_Read_Info: - if ((ret=copy_to_user((void *)arg,info,sizeof(struct PgpInfo)))) { - dev_warn(dev->device,"Command: copy_to_user failed. ret=%i, user=%p kern=%p\n", - ret, (void *)arg, info); - return(-1); - } - return(0); - break; - - // Read PCI Status - case PGP_Read_Pci: - PgpCardG3_GetPci(dev,&pciStatus); - - if ((ret=copy_to_user((void *)arg,&pciStatus,sizeof(struct PciStatus)))) { - dev_warn(dev->device,"Command: copy_to_user failed. ret=%i, user=%p kern=%p\n", - ret, (void *)arg, &pciStatus); - return(-1); - } - return(0); - break; - - // Read status for a lane - case PGP_Read_Status: - if ((ret=copy_from_user(&status,(void *)arg,sizeof(struct PgpStatus)))) { - dev_warn(dev->device,"Command: copy_from_user failed. ret=%i, user=%p kern=%p\n", - ret, (void *)arg, &status); - return(-1); - } - - PgpCardG3_GetStatus(dev,&status,status.lane); - - if ((ret=copy_to_user((void *)arg,&status,sizeof(struct PgpStatus)))) { - dev_warn(dev->device,"Command: copy_to_user failed. ret=%i, user=%p kern=%p\n", - ret, (void *)arg, &status); - return(-1); - } - return(0); - break; - - // Set EVR lane control - case PGP_Set_Evr_Cntrl: - if ((ret=copy_from_user(&evrControl,(void *)arg,sizeof(struct PgpEvrControl)))) { - dev_warn(dev->device,"Command: copy_from_user failed. ret=%i, user=%p kern=%p\n", - ret, (void *)arg, &evrControl); - return(-1); - } - - PgpCardG3_SetEvrControl(dev, &evrControl, evrControl.lane); - return(0); - - // Get EVR lane control - case PGP_Get_Evr_Cntrl: - if ((ret=copy_from_user(&evrControl,(void *)arg,sizeof(struct PgpEvrControl)))) { - dev_warn(dev->device,"Command: copy_from_user failed. ret=%i, user=%p kern=%p\n", - ret, (void *)arg, &evrControl); - return(-1); - } - - PgpCardG3_GetEvrControl(dev, &evrControl, evrControl.lane); - - if ((ret=copy_to_user((void *)arg,&evrControl,sizeof(struct PgpEvrControl)))) { - dev_warn(dev->device,"Command: copy_to_user failed. ret=%i, user=%p kern=%p\n", - ret, (void *)arg, &evrControl); - return(-1); - } - return(0); - break; - - // Read EVR lane status - case PGP_Get_Evr_Status: - if ((ret=copy_from_user(&evrStatus,(void *)arg,sizeof(struct PgpEvrStatus)))) { - dev_warn(dev->device,"Command: copy_from_user failed. ret=%i, user=%p kern=%p\n", - ret, (void *)arg, &evrStatus); - return(-1); - } - - PgpCardG3_GetEvrStatus(dev, &evrStatus, evrStatus.lane); - - if ((ret=copy_to_user((void *)arg,&evrStatus,sizeof(struct PgpEvrStatus)))) { - dev_warn(dev->device,"Command: copy_to_user failed. ret=%i, user=%p kern=%p\n", - ret, (void *)arg, &evrStatus); - return(-1); - } - return(0); - break; - - // Reset EVR counters - case PGP_Rst_Evr_Count: - tempLane = arg & 0x07; - spin_lock(&dev->commandLock); - tempVal = ioread32(&(reg->evrCardStat[0])); // Store old reg val - iowrite32(tempVal|(0x1<<(tempLane+8)),&(reg->evrCardStat[0])); // Set reset bit - iowrite32(tempVal,&(reg->evrCardStat[0])); // Set old reg val - spin_unlock(&dev->commandLock); - return(0); - break; - - // Write to prom - case FPGA_Write_Prom: - return(FpgaProm_Write(dev,reg->promRegs,arg)); - break; - - // Read from prom - case FPGA_Read_Prom: - return(FpgaProm_Read(dev,reg->promRegs,arg)); - break; - - default: - dev_warn(dev->device,"Command: Invalid command=%i\n",cmd); - return(-1); - break; - } - return(-1); -} - - -// Add data to proc dump -void PgpCardG3_SeqShow(struct seq_file *s, struct DmaDevice *dev) { - uint32_t tmp; - uint32_t x; - - struct PgpInfo * info; - struct PciStatus pci; - struct PgpStatus status; - struct PgpCardG3Reg * reg; - struct PgpEvrStatus evrStatus; - struct PgpEvrControl evrControl; - - reg = (struct PgpCardG3Reg *)dev->reg; - info = (struct PgpInfo * )dev->hwData; - - seq_printf(s,"\n"); - PgpCard_InfoShow(s,info); - seq_printf(s,"\n"); - PgpCardG3_GetPci(dev,&pci); - PgpCard_PciShow(s,&pci); - - for (x=0; x < 8; x++) { - if ( ((1 << x) & info->laneMask) == 0 ) continue; - PgpCardG3_GetStatus(dev,&status,x); - seq_printf(s,"\n"); - PgpCard_LaneShow(s,&status); - } - - seq_printf(s,"\n"); - seq_printf(s,"-------------- General HW -----------------\n"); - - seq_printf(s," TxCount : %i\n",ioread32(&(reg->txCount))); - seq_printf(s," RxCount : %i\n",ioread32(&(reg->rxCount))); - - tmp = ioread32(&(reg->rxStatus)); - seq_printf(s," RxStatusRaw : 0x%.8x\n",tmp); - seq_printf(s," RxReadReady : %i\n",(tmp >> 31)&0x1); - seq_printf(s," RxRetFifoCount : %i\n",tmp&0x3FF); - - tmp = ioread32(&(reg->txStat[1])); - seq_printf(s," TxReadReady : %i\n",(tmp >> 31)&0x1); - seq_printf(s," TxRetFifoCount : %i\n",tmp&0x3FF); - - seq_printf(s," CountReset : %i\n",(ioread32(&(reg->cardRstStat)) >> 0) & 0x1); - seq_printf(s," CardReset : %i\n",(ioread32(&(reg->cardRstStat)) >> 1) & 0x1); - - for (x=0; x < 8; x++) { - PgpCardG3_GetEvrStatus(dev,&evrStatus,x); - PgpCardG3_GetEvrControl(dev,&evrControl,x); - seq_printf(s,"\n"); - seq_printf(s,"-------------- EVR Lane %i -----------------\n",x); - seq_printf(s," evrEnable : %i\n",evrControl.evrEnable); - seq_printf(s," laneRunMask : %i\n",evrControl.laneRunMask); - seq_printf(s," startStopEn : %i\n",evrControl.evrSyncEn); - seq_printf(s," modeSelect : %i\n",evrControl.evrSyncSel); - seq_printf(s," headerMask : %i\n",evrControl.headerMask); - seq_printf(s," startStopWord : %i\n",evrControl.evrSyncWord); - seq_printf(s," runCode : %i\n",evrControl.runCode); - seq_printf(s," acceptCode : %i\n",evrControl.acceptCode); - seq_printf(s," runDelay : %i\n",evrControl.runDelay); - seq_printf(s," acceptDelay : %i\n",evrControl.acceptDelay); - seq_printf(s," linkErrors : %i\n",evrStatus.linkErrors); - seq_printf(s," linkUp : %i\n",evrStatus.linkUp); - seq_printf(s," runStatus : %i\n",evrStatus.runStatus); - seq_printf(s," evrSeconds : %i\n",evrStatus.evrSeconds); - seq_printf(s," runCounter : %i\n",evrStatus.runCounter); - seq_printf(s," acceptCounter : %i\n",evrStatus.runCounter); - } -} - - -// Get PCI Status -void PgpCardG3_GetPci(struct DmaDevice *dev, struct PciStatus *status) { - uint32_t tmp; - - struct PgpCardG3Reg *reg; - reg = (struct PgpCardG3Reg *)dev->reg; - - memset(status,0,sizeof(struct PciStatus)); - - tmp = ioread32(&(reg->pciStat[0])); - status->pciCommand = ((tmp >> 16)&0xFFFF); - status->pciStatus = (tmp & 0xFFFF); - - tmp = ioread32(&(reg->pciStat[1])); - status->pciDCommand = ((tmp >> 16)&0xFFFF); - status->pciDStatus = (tmp & 0xFFFF); - - tmp = ioread32(&(reg->pciStat[2])); - status->pciLCommand = ((tmp >> 16)&0xFFFF); - status->pciLStatus = (tmp & 0xFFFF); - status->pciLanes = ((tmp >> 4) & 0x1F); - - tmp = ioread32(&(reg->pciStat[3])); - status->pciLinkState = ((tmp >> 24)&0x7); - status->pciFunction = ((tmp >> 16)&0x3); - status->pciDevice = ((tmp >> 8)&0xF); - status->pciBus = (tmp&0xFF); -} - - -// Get Lane Status -void PgpCardG3_GetStatus(struct DmaDevice *dev, struct PgpStatus *status, uint8_t lane) { - uint32_t tempVal; - - struct PgpCardG3Reg *reg; - reg = (struct PgpCardG3Reg *)dev->reg; - - lane &= 0x7; - - memset(status,0,sizeof(struct PgpStatus)); - status->lane = lane; - - tempVal = ioread32(&(reg->pgpCardStat[0])); - - if ( lane < 2 ) { - status->txReady = ((tempVal >> (lane+30)) & 0x1); - status->rxReady = ((tempVal >> (lane+28)) & 0x1); - } - status->loopBack = ((tempVal >> (lane+0)) & 0x1); - - tempVal = ioread32(&(reg->pgpCardStat[1])); - status->remLinkReady = (tempVal >> (lane+8)) & 0x1; - status->locLinkReady = (tempVal >> (lane+0)) & 0x1; - - tempVal = ioread32(&(reg->pgpLaneStat[lane])); - status->linkErrCnt = (tempVal >> 28) & 0xF; - status->linkDownCnt = (tempVal >> 24) & 0xF; - status->cellErrCnt = (tempVal >> 20) & 0xF; - status->fifoErr = (((tempVal >> 16) & 0xF) != 0); - status->rxCount += ((tempVal>>12) & 0xF); - status->rxCount += ((tempVal>> 8) & 0xF); - status->rxCount += ((tempVal>> 4) & 0xF); - status->rxCount += ((tempVal>> 0) & 0xF); - - status->remData = (ioread32(&(reg->pgpData[lane])) >> 8) & 0xFF; - //status->remBuffStatus = - -} - - -// Get EVR Status -void PgpCardG3_GetEvrStatus(struct DmaDevice *dev, struct PgpEvrStatus *status, uint8_t lane) { - uint32_t tempVal; - - struct PgpCardG3Reg *reg; - reg = (struct PgpCardG3Reg *)dev->reg; - - lane &= 0x7; - - memset(status,0,sizeof(struct PgpEvrStatus)); - status->lane = lane; - - tempVal = ioread32(&(reg->evrCardStat[0])); - status->linkUp = (tempVal >> 4) & 0x1; - - tempVal = ioread32(&(reg->evrCardStat[1])); - status->runStatus = (tempVal >> (24+lane)) & 0x1; - - tempVal = ioread32(&(reg->evrCardStat[3])); - status->linkErrors = tempVal; - - tempVal = ioread32(&(reg->evrCardStat[4])); - status->evrSeconds = tempVal; - - tempVal = ioread32(&(reg->evrRunCnt[lane])); - status->runCounter = tempVal; - - tempVal = ioread32(&(reg->acceptCnt[lane])); - status->acceptCounter = tempVal; -} - - -// Get EVR Config -void PgpCardG3_GetEvrControl(struct DmaDevice *dev, struct PgpEvrControl *control, uint8_t lane) { - uint32_t tempVal; - - struct PgpCardG3Reg *reg; - reg = (struct PgpCardG3Reg *)dev->reg; - - lane &= 0x7; - - memset(control,0,sizeof(struct PgpEvrControl)); - control->lane = lane; - - tempVal = ioread32(&(reg->syncCode[lane])); - control->evrSyncWord = tempVal; - - tempVal = ioread32(&(reg->runCode[lane])); - control->runCode = tempVal; - - tempVal = ioread32(&(reg->acceptCode[lane])); - control->acceptCode = tempVal; - - tempVal = ioread32(&(reg->runDelay[lane])); - control->runDelay = tempVal; - - tempVal = ioread32(&(reg->acceptDelay[lane])); - control->acceptDelay = tempVal; - - tempVal = ioread32(&(reg->evrCardStat[2])); - control->headerMask = ((tempVal >> (lane*4)) & 0xF); - - tempVal = ioread32(&(reg->evrCardStat[1])); - control->evrEnable = tempVal & 0x1; - control->evrSyncEn = ((tempVal >> (16+lane)) & 0x1); - control->evrSyncSel = ((tempVal >> (8+lane)) & 0x1); - - tempVal = ioread32(&(reg->evrCardStat[0])); - control->laneRunMask = ((tempVal >> (16+lane)) & 0x1); -} - - -// Set EVR Config -void PgpCardG3_SetEvrControl(struct DmaDevice *dev, struct PgpEvrControl *control, uint8_t lane) { - uint32_t tempVal; - uint32_t mask; - - struct PgpCardG3Reg *reg; - reg = (struct PgpCardG3Reg *)dev->reg; - - lane &= 0x7; - - spin_lock(&dev->commandLock); - - iowrite32(control->evrSyncWord,&(reg->syncCode[lane])); - - iowrite32(control->runCode,&(reg->runCode[lane])); - - iowrite32(control->acceptCode,&(reg->acceptCode[lane])); - - iowrite32(control->runDelay,&(reg->runDelay[lane])); - - iowrite32(control->acceptDelay,&(reg->acceptDelay[lane])); - - tempVal = ioread32(&(reg->evrCardStat[2])); - mask = 0xFFFFFFFF ^ (0xF << (lane*4)); - tempVal &= mask; - tempVal |= (control->headerMask << (lane*4)); - iowrite32(tempVal,&(reg->evrCardStat[2])); - - tempVal = ioread32(&(reg->evrCardStat[1])); - mask = 0xFFFFFFFE; - tempVal &= mask; - tempVal |= control->evrEnable; - - mask = 0xFFFFFFFF ^ (0x1 << (lane+16)); - tempVal &= mask; - tempVal |= (control->evrSyncEn << (lane+16)); - - mask = 0xFFFFFFFF ^ (0x1 << (lane+8)); - tempVal &= mask; - tempVal |= (control->evrSyncSel << (lane+8)); - - iowrite32(tempVal,&(reg->evrCardStat[1])); - - tempVal = ioread32(&(reg->evrCardStat[0])); - mask = 0xFFFFFFFF ^ (0x1 << (lane+16)); - tempVal &= mask; - tempVal |= (control->laneRunMask << (lane+16)); - iowrite32(tempVal,&(reg->evrCardStat[0])); - - spin_unlock(&dev->commandLock); -} - diff --git a/pgpcard/driver/src/pgp_gen3.h b/pgpcard/driver/src/pgp_gen3.h deleted file mode 100755 index 89963c7..0000000 --- a/pgpcard/driver/src/pgp_gen3.h +++ /dev/null @@ -1,140 +0,0 @@ -/** - *----------------------------------------------------------------------------- - * Title : PGP Card Gen3 Functions - * ---------------------------------------------------------------------------- - * File : pgp_gen3.h - * Author : Ryan Herbst, rherbst@slac.stanford.edu - * Created : 2016-08-11 - * Last update: 2016-08-11 - * ---------------------------------------------------------------------------- - * Description: - * Access functions for Gen3 - * ---------------------------------------------------------------------------- - * This file is part of the aes_stream_drivers package. It is subject to - * the license terms in the LICENSE.txt file found in the top-level directory - * of this distribution and at: - * https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html. - * No part of the aes_stream_drivers package, including this file, may be - * copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE.txt file. - * ---------------------------------------------------------------------------- -**/ -#ifndef __PGP_GEN3_H__ -#define __PGP_GEN3_H__ - -#include -#include -#include -#include - -// Address Map, offset from base -struct PgpCardG3Reg { - - //PciApp.vhd - uint32_t version; // Software_Addr = 0x000, Firmware_Addr(13 downto 2) = 0x000 - uint32_t serNumLower; // Software_Addr = 0x004, Firmware_Addr(13 downto 2) = 0x001 - uint32_t serNumUpper; // Software_Addr = 0x008, Firmware_Addr(13 downto 2) = 0x002 - uint32_t scratch; // Software_Addr = 0x00C, Firmware_Addr(13 downto 2) = 0x003 - uint32_t cardRstStat; // Software_Addr = 0x010, Firmware_Addr(13 downto 2) = 0x004 - uint32_t irq; // Software_Addr = 0x014, Firmware_Addr(13 downto 2) = 0x005 - uint32_t pgpRate; // Software_Addr = 0x018, Firmware_Addr(13 downto 2) = 0x006 - uint32_t vciMode; // Software_Addr = 0x01C, Firmware_Addr(13 downto 2) = 0x007 - uint32_t pgpOpCode; // Software_Addr = 0x020, Firmware_Addr(13 downto 2) = 0x008 - uint32_t sysSpare0[2]; // Software_Addr = 0x028:0x024, Firmware_Addr(13 downto 2) = 0x00A:0x009 - uint32_t pciStat[4]; // Software_Addr = 0x038:0x02C, Firmware_Addr(13 downto 2) = 0x00E:0x00B - uint32_t sysSpare1; // Software_Addr = 0x03C, Firmware_Addr(13 downto 2) = 0x00F - - uint32_t evrCardStat[5]; // Software_Addr = 0x050:0x040, Firmware_Addr(13 downto 2) = 0x012:0x010 - uint32_t evrSpare0[11]; // Software_Addr = 0x07C:0x054, Firmware_Addr(13 downto 2) = 0x01F:0x013 - - uint32_t pgpCardStat[2]; // Software_Addr = 0x084:0x080, Firmware_Addr(13 downto 2) = 0x021:0x020 - uint32_t pgpSpare0[54]; // Software_Addr = 0x15C:0x088, Firmware_Addr(13 downto 2) = 0x05F:0x022 - - uint32_t syncCode[8]; // Software_Addr = 0x17C:0x160, Firmware_Addr(13 downto 2) = 0x067:0x060 - uint32_t runCode[8]; // Software_Addr = 0x19C:0x180, Firmware_Addr(13 downto 2) = 0x067:0x060 - uint32_t acceptCode[8]; // Software_Addr = 0x1BC:0x1A0, Firmware_Addr(13 downto 2) = 0x06F:0x068 - - uint32_t runDelay[8]; // Software_Addr = 0x1DC:0x1C0, Firmware_Addr(13 downto 2) = 0x077:0x070 - uint32_t acceptDelay[8]; // Software_Addr = 0x1FC:0x1E0, Firmware_Addr(13 downto 2) = 0x07F:0x078 - - uint32_t pgpLaneStat[8]; // Software_Addr = 0x21C:0x200, Firmware_Addr(13 downto 2) = 0x087:0x080 - uint32_t evrRunCnt[8]; // Software_Addr = 0x23C:0x220, - uint32_t lutDropCnt[8]; // Software_Addr = 0x25C:0x240, - uint32_t acceptCnt[8]; // Software_Addr = 0x27C:0x260, - uint32_t pgpData[8]; // Software_Addr = 0x29C:0x280, - uint32_t pgpSpare1[24]; // Software_Addr = 0x2FC:0x2A0, - uint32_t BuildStamp[64]; // Software_Addr = 0x3FC:0x300, Firmware_Addr(13 downto 2) = 0x0FF:0x0C0 - - //PciRxDesc.vhd - uint32_t rxFree[8]; // Software_Addr = 0x41C:0x400, Firmware_Addr(13 downto 2) = 0x107:0x100 - uint32_t rxSpare0[24]; // Software_Addr = 0x47C:0x420, Firmware_Addr(13 downto 2) = 0x11F:0x108 - uint32_t rxFreeStat[8]; // Software_Addr = 0x49C:0x480, Firmware_Addr(13 downto 2) = 0x127:0x120 - uint32_t rxSpare1[24]; // Software_Addr = 0x4FC:0x4A0, Firmware_Addr(13 downto 2) = 0x13F:0x128 - uint32_t rxMaxFrame; // Software_Addr = 0x500, Firmware_Addr(13 downto 2) = 0x140 - uint32_t rxCount; // Software_Addr = 0x504, Firmware_Addr(13 downto 2) = 0x141 - uint32_t rxStatus; // Software_Addr = 0x508, Firmware_Addr(13 downto 2) = 0x142 - uint32_t rxRead[4]; // Software_Addr = 0x518:0x50C, Firmware_Addr(13 downto 2) = 0x146:0x143 - uint32_t rxSpare2[185]; // Software_Addr = 0x7FC:0x51C, Firmware_Addr(13 downto 2) = 0x1FF:0x147 - - //PciTxDesc.vhd - uint32_t txWrA[8]; // Software_Addr = 0x81C:0x800, Firmware_Addr(13 downto 2) = 0x207:0x200 - uint32_t txFifoCnt[8]; // Software_Addr = 0x83C:0x820, Firmware_Addr(13 downto 2) = 0x20F:0x208 - uint32_t txSpare0[16]; // Software_Addr = 0x87C:0x840, Firmware_Addr(13 downto 2) = 0x21F:0x210 - uint32_t txWrB[8]; // Software_Addr = 0x89C:0x880, Firmware_Addr(13 downto 2) = 0x227:0x220 - uint32_t txSpare1[24]; // Software_Addr = 0x8FC:0x8A0, Firmware_Addr(13 downto 2) = 0x23F:0x228 - uint32_t txStat[2]; // Software_Addr = 0x904:0x900, Firmware_Addr(13 downto 2) = 0x241:0x240 - uint32_t txCount; // Software_Addr = 0x908, Firmware_Addr(13 downto 2) = 0x242 - uint32_t txRead; // Software_Addr = 0x90C, Firmware_Addr(13 downto 2) = 0x243 - uint32_t txSpare[188]; // Software_Addr = 0x910:0xBFC - - uint32_t promRegs[3]; // Prom registers -}; - -// Set functions for gen3 card -extern struct hardware_functions PgpCardG3_functions; - -// Interrupt handler -irqreturn_t PgpCardG3_Irq(int irq, void *dev_id); - -// Init card in top level Probe -void PgpCardG3_Init(struct DmaDevice *dev); - -// Enable -void PgpCardG3_Enable(struct DmaDevice *dev); - -// Clear card in top level Remove -void PgpCardG3_Clear(struct DmaDevice *dev); - -// Return receive buffer to card -void PgpCardG3_RetRxBuffer(struct DmaDevice *dev, struct DmaBuffer **buff, uint32_t count); - -// Send a buffer -int32_t PgpCardG3_SendBuffer(struct DmaDevice *dev, struct DmaBuffer **buff, uint32_t count); - -// Execute command -int32_t PgpCardG3_Command(struct DmaDevice *dev, uint32_t cmd, uint64_t arg); - -// Add data to proc dump -void PgpCardG3_SeqShow(struct seq_file *s, struct DmaDevice *dev); - -/////////////////////////////////// -// Local helper functions -/////////////////////////////////// - -// Get PCI Status -void PgpCardG3_GetPci(struct DmaDevice *dev, struct PciStatus * status); - -// Get Lane Status -void PgpCardG3_GetStatus(struct DmaDevice *dev, struct PgpStatus *status, uint8_t lane); - -// Get EVR Control -void PgpCardG3_GetEvrControl(struct DmaDevice *dev, struct PgpEvrControl *control, uint8_t lane); - -// Set EVR Control -void PgpCardG3_SetEvrControl(struct DmaDevice *dev, struct PgpEvrControl *control, uint8_t lane); - -// Get EVR Status -void PgpCardG3_GetEvrStatus(struct DmaDevice *dev, struct PgpEvrStatus *status, uint8_t lane); - -#endif - diff --git a/pgpcard/driver/src/pgp_top.c b/pgpcard/driver/src/pgp_top.c deleted file mode 100755 index 4dddd98..0000000 --- a/pgpcard/driver/src/pgp_top.c +++ /dev/null @@ -1,222 +0,0 @@ -/** - *----------------------------------------------------------------------------- - * Title : Top level module - * ---------------------------------------------------------------------------- - * File : pgp_top.c - * Author : Ryan Herbst, rherbst@slac.stanford.edu - * Created : 2016-08-08 - * Last update: 2016-08-08 - * ---------------------------------------------------------------------------- - * Description: - * Top level module types and functions. - * ---------------------------------------------------------------------------- - * This file is part of the aes_stream_drivers package. It is subject to - * the license terms in the LICENSE.txt file found in the top-level directory - * of this distribution and at: - * https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html. - * No part of the aes_stream_drivers package, including this file, may be - * copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE.txt file. - * ---------------------------------------------------------------------------- -**/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -// Init Configuration values -int cfgTxCount = 32; -int cfgRxCount = 32; -int cfgSize = 2097152; -int cfgMode = BUFF_COHERENT; -int cfgCont = 1; - -// Global array of devices -struct DmaDevice gDmaDevices[MAX_DMA_DEVICES]; - -// PCI device IDs -static struct pci_device_id PgpCard_Ids[] = { - { PCI_DEVICE(PCI_VENDOR_ID_SLAC, PCI_DEVICE_ID_GEN2) }, - { PCI_DEVICE(PCI_VENDOR_ID_SLAC, PCI_DEVICE_ID_GEN3) }, - { 0, } -}; - -// Module Name -#define MOD_NAME "pgpcard" - -MODULE_LICENSE("GPL"); -MODULE_DEVICE_TABLE(pci, PgpCard_Ids); -module_init(PgpCard_Init); -module_exit(PgpCard_Exit); - -// PCI driver structure -static struct pci_driver PgpCardDriver = { - .name = MOD_NAME, - .id_table = PgpCard_Ids, - .probe = PgpCard_Probe, - .remove = PgpCard_Remove, -}; - -// Init Kernel Module -int32_t PgpCard_Init(void) { - - /* Allocate and clear memory for all devices. */ - memset(gDmaDevices, 0, sizeof(struct DmaDevice)*MAX_DMA_DEVICES); - - pr_info("%s: Init\n",MOD_NAME); - - // Init structures - gCl = NULL; - gDmaDevCount = 0; - - // Register driver - return(pci_register_driver(&PgpCardDriver)); -} - - -// Exit Kernel Module -void PgpCard_Exit(void) { - pr_info("%s: Exit.\n",MOD_NAME); - pci_unregister_driver(&PgpCardDriver); -} - - -// Create and init device -int PgpCard_Probe(struct pci_dev *pcidev, const struct pci_device_id *dev_id) { - struct DmaDevice *dev; - struct pci_device_id *id; - struct hardware_functions *hfunc; - - int32_t x; - int32_t dummy; - - if ( cfgMode != BUFF_COHERENT && cfgMode != BUFF_STREAM ) { - pr_warn("%s: Probe: Invalid buffer mode = %i.\n",MOD_NAME,cfgMode); - return(-1); - } - - // First check for valid device - switch ( pcidev->device ) { - case PCI_DEVICE_ID_GEN2: hfunc = &(PgpCardG2_functions); break; - case PCI_DEVICE_ID_GEN3: hfunc = &(PgpCardG3_functions); break; - default: - pr_warn("%s: Probe: Unkown device.\n",MOD_NAME); - return (-1); - break; - } - - id = (struct pci_device_id *) dev_id; - - // We keep device instance number in id->driver_data - id->driver_data = -1; - - // Find empty structure - for (x = 0; x < MAX_DMA_DEVICES; x++) { - if (gDmaDevices[x].baseAddr == 0) { - id->driver_data = x; - break; - } - } - - // Overflow - if (id->driver_data < 0) { - pr_warn("%s: Probe: Too Many Devices.\n",MOD_NAME); - return (-1); - } - dev = &gDmaDevices[id->driver_data]; - dev->index = id->driver_data; - - // Increment count - gDmaDevCount++; - - // Create a device name - sprintf(dev->devName,"%s_%i",MOD_NAME,dev->index); - - // Enable the device - dummy = pci_enable_device(pcidev); - pci_set_master(pcidev); - - // Get Base Address of registers from pci structure. - dev->baseAddr = pci_resource_start (pcidev, 0); - dev->baseSize = pci_resource_len (pcidev, 0); - - // Remap the I/O register block so that it can be safely accessed. - if ( Dma_MapReg(dev) < 0 ) return(-1); - - // Set configuration - dev->cfgTxCount = cfgTxCount; - dev->cfgRxCount = cfgRxCount; - dev->cfgSize = cfgSize; - dev->cfgMode = cfgMode; - dev->cfgCont = cfgCont; - - // Get IRQ from pci_dev structure. - dev->irq = pcidev->irq; - - // Set device fields - dev->device = &(pcidev->dev); - dev->hwFunc = hfunc; - - dev->rwBase = dev->base; - dev->rwSize = 0x400; - - // Call common dma init function - return(Dma_Init(dev)); -} - - -// Cleanup device -void PgpCard_Remove(struct pci_dev *pcidev) { - uint32_t x; - - struct DmaDevice *dev = NULL; - - pr_info("%s: Remove: Remove called.\n",MOD_NAME); - - // Look for matching device - for (x = 0; x < MAX_DMA_DEVICES; x++) { - if ( gDmaDevices[x].baseAddr == pci_resource_start(pcidev, 0)) { - dev = &gDmaDevices[x]; - break; - } - } - - // Device not found - if (dev == NULL) { - pr_err("%s: Remove: Device Not Found.\n",MOD_NAME); - return; - } - - // Decrement count - gDmaDevCount--; - - // Call common dma init function - Dma_Clean(dev); - // Disable device - pci_disable_device(pcidev); - - pr_info("%s: Remove: Driver is unloaded.\n",MOD_NAME); -} - -// Parameters -module_param(cfgTxCount,int,0); -MODULE_PARM_DESC(cfgTxCount, "TX buffer count"); - -module_param(cfgRxCount,int,0); -MODULE_PARM_DESC(cfgRxCount, "RX buffer count"); - -module_param(cfgSize,int,0); -MODULE_PARM_DESC(cfgSize, "Rx/TX Buffer size"); - -module_param(cfgMode,int,0); -MODULE_PARM_DESC(cfgMode, "RX buffer mode"); - -module_param(cfgCont,int,0); -MODULE_PARM_DESC(cfgCont, "RX continue enable"); - diff --git a/pgpcard/driver/src/pgp_top.h b/pgpcard/driver/src/pgp_top.h deleted file mode 100755 index 289f49d..0000000 --- a/pgpcard/driver/src/pgp_top.h +++ /dev/null @@ -1,48 +0,0 @@ -/** - *----------------------------------------------------------------------------- - * Title : Top level module - * ---------------------------------------------------------------------------- - * File : pgp_top.h - * Author : Ryan Herbst, rherbst@slac.stanford.edu - * Created : 2016-08-08 - * Last update: 2016-08-08 - * ---------------------------------------------------------------------------- - * Description: - * Top level module types and functions. - * ---------------------------------------------------------------------------- - * This file is part of the aes_stream_drivers package. It is subject to - * the license terms in the LICENSE.txt file found in the top-level directory - * of this distribution and at: - * https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html. - * No part of the aes_stream_drivers package, including this file, may be - * copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE.txt file. - * ---------------------------------------------------------------------------- -**/ -#ifndef __PGP_TOP_H__ -#define __PGP_TOP_H__ - -#include -#include - -#define MAX_DMA_DEVICES 4 - -// PCI IDs -#define PCI_VENDOR_ID_SLAC 0x1a4a -#define PCI_DEVICE_ID_GEN2 0x2000 -#define PCI_DEVICE_ID_GEN3 0x2020 - -// Init Kernel Module -int32_t PgpCard_Init(void); - -// Exit Kernel Module -void PgpCard_Exit(void); - -// Create and init device -int PgpCard_Probe(struct pci_dev *pcidev, const struct pci_device_id *dev_id); - -// Cleanup device -void PgpCard_Remove(struct pci_dev *pcidev); - -#endif -