This patch removes dependency to libpciaccess for rewriting PCI configuration space after reset. This is now done via a single file from updated uio_netx diff --git a/libcifx/CMakeLists.txt b/libcifx/CMakeLists.txt index 46c6f5e..ac80bad 100644 --- a/libcifx/CMakeLists.txt +++ b/libcifx/CMakeLists.txt @@ -72,7 +72,6 @@ endif(VIRTETH) target_link_directories( cifx PRIVATE - $<$>:${LIBPCIACCESS_LIBRARY_DIRS}> $<$:${LIBDNL_LIBRARY_DIRS}> $<$:${LIBDNL_CLI_LIBRARY_DIRS}> ) @@ -83,7 +82,6 @@ target_include_directories( cifx ${tk_dir}/Source/ ${tk_dir}/Common/cifXAPI/ ${tk_dir}/Common/HilscherDefinitions/ - $<$>:${LIBPCIACCESS_INCLUDE_DIRS}> $<$:${src_dir}/netx_tap/ ${LIBDNL_CLI_INCLUDE_DIRS} ${LIBDNL_INCLUDE_DIRS}> ) @@ -91,7 +89,6 @@ target_link_libraries( cifx PRIVATE pthread rt - $<$>:pciaccess> $<$,$>:dl> $<$:${LIBDNL_LIBRARIES}> $<$:${LIBDNL_CLI_LIBRARIES}> diff --git a/libcifx/cifxlinux.c b/libcifx/cifxlinux.c index d1fd7f4..5267b1d 100644 --- a/libcifx/cifxlinux.c +++ b/libcifx/cifxlinux.c @@ -657,70 +657,6 @@ void cifx_ISA_unmap_dpm( void* dpmaddr, int dpmlen) munmap( dpmaddr, dpmlen); } -#ifndef CIFX_TOOLKIT_DISABLEPCI - /*****************************************************************************/ - /*! Try to find a matching PCI card by verifying the physical BAR addresses - * \param dev_instance Device to search for. PCI data will be inserted into - O/S dependent part - * \return !=0 if a matching PCI card was found */ - /*****************************************************************************/ - static int match_pci_card(PDEVICEINSTANCE dev_instance, unsigned long ulPys_Addr) - { - struct pci_device_iterator *pci_dev_it; - struct pci_device *dev; - int ret = 0; - - static const struct pci_id_match id_match = - { - .vendor_id = PCI_MATCH_ANY, - .device_id = PCI_MATCH_ANY, - .subvendor_id = PCI_MATCH_ANY, - .subdevice_id = PCI_MATCH_ANY, - }; - - pci_dev_it = pci_id_match_iterator_create(&id_match); - - while( NULL != (dev = pci_device_next(pci_dev_it)) ) - { - int bar; - - pci_device_probe(dev); - - for(bar = 0; bar < sizeof(dev->regions) / sizeof(dev->regions[0]); ++bar) - { - if(dev->regions[bar].base_addr == (pciaddr_t)ulPys_Addr) - { - PCIFX_DEVICE_INTERNAL_T internal = (PCIFX_DEVICE_INTERNAL_T)dev_instance->pvOSDependent; - #ifdef VERBOSE - printf("matched pci card @ bus=%d,dev=%d,func=%d,vendor=0x%x,device=0x%x,subvendor=0x%x,subdevice=0x%x \n", - dev->bus, dev->dev, dev->func, - dev->vendor_id, dev->device_id, dev->subvendor_id, dev->subdevice_id); - #endif - /* detect flash based card by device- and sub_device id */ - if ( (dev->vendor_id == HILSCHER_PCI_VENDOR_ID) && - ( - ((dev->device_id == NETPLC100C_PCI_DEVICE_ID) && (dev->subdevice_id == NETPLC100C_PCI_SUBYSTEM_ID_FLASH)) || - ((dev->device_id == NETJACK100_PCI_DEVICE_ID) && (dev->subdevice_id == NETJACK100_PCI_SUBYSTEM_ID_FLASH)) || - (dev->device_id == CIFX4000_PCI_DEVICE_ID) - ) - ) - { - dev_instance->eDeviceType = eCIFX_DEVICE_FLASH_BASED; - } - - internal->pci = *dev; - ret = 1; - break; - } - } - } - - pci_iterator_destroy(pci_dev_it); - - return ret; - } -#endif /* CIFX_TOOLKIT_DISABLEPCI */ - /*****************************************************************************/ /*! Thread for cyclic Toolkit timer, which handles polling of COS bits on * non-irq cards @@ -904,34 +840,9 @@ static int32_t cifXDriverAddDevice(struct CIFX_DEVICE_T* ptDevice, unsigned int if(ptDevice->pci_card != 0) { -#ifndef CIFX_TOOLKIT_DISABLEPCI - /* Try to find the card on the PCI bus. If it is not found, deny to work with this card */ - if(!match_pci_card(ptDevInstance, ptDevice->dpmaddr)) - { - /* Don't add this device */ - if (g_ulTraceLevel & TRACE_LEVEL_ERROR) - { - USER_Trace(ptDevInstance, - TRACE_LEVEL_ERROR, - "Error finding pci device (Phys. Addr 0x%lx) on PCI bus", - ptDevice->dpmaddr); - } - } else - { ptDevInstance->fPCICard = 1; ret = CIFX_NO_ERROR; - } -#else - if (g_ulTraceLevel & TRACE_LEVEL_ERROR) - { - USER_Trace(ptDevInstance, - TRACE_LEVEL_ERROR, - "cifX Driver was compiled without PCI support. Unable to handle requested PCI card @0x%lx!", - ptDevice->dpmaddr); - } -#endif - } else - { + } else { ptDevInstance->fPCICard = 0; ret = CIFX_NO_ERROR; } diff --git a/libcifx/cifxlinux_internal.h b/libcifx/cifxlinux_internal.h index 24cbb26..1b62f28 100644 --- a/libcifx/cifxlinux_internal.h +++ b/libcifx/cifxlinux_internal.h @@ -18,10 +18,6 @@ #include "cifxlinux.h" -#ifndef CIFX_TOOLKIT_DISABLEPCI - #include "pciaccess.h" -#endif - #include #include #include "cifXToolkit.h" @@ -46,11 +42,6 @@ typedef struct CIFX_DEVICE_INTERNAL_Ttag int user_card; /*!< !=0 if user specified card. This card will not be deleted on exit */ FILE *log_file; /*!< Handle to logfile if any */ - -#ifndef CIFX_TOOLKIT_DISABLEPCI - struct pci_device pci; /*!< pci device information if it is a pci device */ -#endif - PDEVICEINSTANCE devinstance; /*!< Toolkit device instance */ int eth_support; diff --git a/libcifx/os_linux.c b/libcifx/os_linux.c index 2985a4f..55281da 100644 --- a/libcifx/os_linux.c +++ b/libcifx/os_linux.c @@ -28,10 +28,6 @@ #include #include -#ifndef CIFX_TOOLKIT_DISABLEPCI - #include -#endif - #include "cifXErrors.h" #include "OS_Dependent.h" @@ -49,7 +45,7 @@ #define BLOCK32 sizeof(uint32_t) /*****************************************************************************/ -/*! O/S Specific initialization (initializes libpciaccess) +/*! O/S Specific initialization * \return CIFX_NO_ERROR on success */ /*****************************************************************************/ int32_t OS_Init(void) @@ -59,30 +55,17 @@ int32_t OS_Init(void) #ifdef VERBOSE_1 printf("%s() called\n", __FUNCTION__); #endif - -#ifndef CIFX_TOOLKIT_DISABLEPCI - if(0 != (err = pci_system_init())) - { - fprintf( stderr, "Error initializing PCI access subsystem (pci_system_init=%d)", err); - ret = CIFX_FUNCTION_FAILED; - } -#endif - return ret; } /*****************************************************************************/ -/*! O/S Specific de-initialization (de-initializes libpciaccess) */ +/*! O/S Specific de-initialization */ /*****************************************************************************/ void OS_Deinit(void) { #ifdef VERBOSE_1 printf("%s() called\n", __FUNCTION__); #endif - -#ifndef CIFX_TOOLKIT_DISABLEPCI - pci_system_cleanup(); -#endif } /*****************************************************************************/ @@ -208,17 +191,19 @@ void OS_Memmove(void* pvDest, void* pvSrc, uint32_t ulSize) { pvDest = memmove(pvDest, pvSrc, ulSize); } +#define PCI_CONFIG_SPACE_SIZE 256 + /*****************************************************************************/ /*! Read PCI configuration area of specified card * \param pvOSDependent OS Dependent parameter to identify card * \return Pointer to configuration data (passed to WritePCIConfig) */ /*****************************************************************************/ void* OS_ReadPCIConfig(void* pvOSDependent) { -#ifndef CIFX_TOOLKIT_DISABLEPCI - PCIFX_DEVICE_INTERNAL_T info = (PCIFX_DEVICE_INTERNAL_T)pvOSDependent; - - int pci_ret; - void *pci_buf; + PCIFX_DEVICE_INTERNAL_T info = (PCIFX_DEVICE_INTERNAL_T)pvOSDependent; + int fd; + void *pci_buf; + void* ret = NULL; + char strbuf[128]; #ifdef VERBOSE_1 printf("%s() called\n", __FUNCTION__); #endif @@ -231,19 +216,21 @@ void* OS_ReadPCIConfig(void* pvOSDependent) { perror("pci_buf malloc failed"); return NULL; } - - if ((pci_ret = pci_device_cfg_read(&info->pci, pci_buf, 0, 256, NULL)) ) - { + sprintf( strbuf, "/sys/class/uio/uio%d/device/pcicfg", info->userdevice->uio_num); + fd = open( strbuf, O_RDONLY); + if (fd >= 0) { + if (PCI_CONFIG_SPACE_SIZE == read( fd, pci_buf, PCI_CONFIG_SPACE_SIZE)) { + ret = pci_buf; + } + close(fd); #ifdef VERBOSE - printf("libnetx: pci_read_block() returns %d\n", pci_ret); + printf("libnetx: Trying to read pcicfg space returend %d\n", pci_ret); #endif - free( pci_buf); - pci_buf = NULL; } - return pci_buf; -#else - return NULL; -#endif /* CIFX_TOOLKIT_DISABLEPCI */ + if (ret == NULL) + free(pci_buf); + + return ret; } /*****************************************************************************/ @@ -252,23 +239,24 @@ void* OS_ReadPCIConfig(void* pvOSDependent) { * \param pvPCIConfig Pointer returned from ReadPCIConfig */ /*****************************************************************************/ void OS_WritePCIConfig(void* pvOSDependent, void* pvPCIConfig) { - -#ifndef CIFX_TOOLKIT_DISABLEPCI - int pci_ret; - PCIFX_DEVICE_INTERNAL_T info = (PCIFX_DEVICE_INTERNAL_T)pvOSDependent; + PCIFX_DEVICE_INTERNAL_T info = (PCIFX_DEVICE_INTERNAL_T)pvOSDependent; + int fd; + int ret; + char strbuf[128]; #ifdef VERBOSE_1 printf("%s() called\n", __FUNCTION__); #endif - - if ((pci_ret = pci_device_cfg_write(&info->pci, pvPCIConfig, 0, 256, NULL)) ) - { + sprintf( strbuf, "/sys/class/uio/uio%d/device/pcicfg", info->userdevice->uio_num); + fd = open( strbuf, O_WRONLY); + if (fd >= 0) { + ret = write( fd, pvPCIConfig, PCI_CONFIG_SPACE_SIZE); + close(fd); #ifdef VERBOSE - printf("libnetx: pci_write_block() returns %d\n", pci_ret); + printf("libnetx: Writing pcicfg space returned %d\n", ret); #endif } free(pvPCIConfig); -#endif } /*****************************************************************************/ diff --git a/uio_netx/uio_netx.c b/uio_netx/uio_netx.c index f82a77e..ea60fe0 100644 --- a/uio_netx/uio_netx.c +++ b/uio_netx/uio_netx.c @@ -112,6 +112,8 @@ MODULE_PARM_DESC(dma_buffer_size, "Size of a DMA-buffer."); #define EXT_MEM_NAME "extmem" #define DMA_MEM_NAME "dma" +#define PCI_CONFIG_SPACE_SIZE 256 + DEFINE_MUTEX(custom_list_lock); uint8_t card_count = 0; @@ -144,6 +146,33 @@ struct netx_custom_dev { int* irq; }; +struct pci_dev *test_dev = NULL; + +ssize_t uio_read_pcicfg(struct device *dev, struct device_attribute *attr, char *buf) { + int32_t offset = 0; + while(offset < PCI_CONFIG_SPACE_SIZE) { + pci_read_config_byte( to_pci_dev(dev), offset, &buf[offset]); + offset++; + } + return PCI_CONFIG_SPACE_SIZE; +} + +ssize_t uio_write_pcicfg(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) { + size_t ret = size; + if (size <= PCI_CONFIG_SPACE_SIZE) { + int32_t offset = 0; + while(offset < size) { + pci_write_config_byte( to_pci_dev(dev), offset, buf[offset]); + offset++; + } + } + return ret; +} + +/* NOTE: On cifX device PCI config space gets lost during reset. As a workaround */ +/* we safe and restore configuration space via sysfs when a reset is done. */ +static DEVICE_ATTR(pcicfg, S_IWUSR | S_IRUGO, uio_read_pcicfg, uio_write_pcicfg); + static LIST_HEAD(custom_list); static int netx_enable_irq(struct uio_info *dev_info, s32 irq_on) @@ -464,7 +493,14 @@ static int __devinit netx_pci_probe(struct pci_dev *dev, "registered NXPCA-PCI adapter card in %d bit mode\n", pxa_info->dpm_mode); } + + /* create interface for pci configuration space */ + if (device_create_file( &dev->dev, &dev_attr_pcicfg) != 0) + goto out_pcicfg; + return 0; +out_pcicfg: + device_remove_file( &dev->dev, &dev_attr_pcicfg); out_unmap_plx: iounmap(((struct uio_netx_priv*)(info->priv))->pxa_info->plx); out_free_pxa: @@ -491,6 +527,9 @@ static void netx_pci_remove(struct pci_dev *dev) { struct uio_info *info = pci_get_drvdata(dev); struct pxa_dev_info *pxa_info = ((struct uio_netx_priv*)info->priv)->pxa_info; + + device_remove_file( &dev->dev, &dev_attr_pcicfg); + if (pxa_info) { if ( pxa_info->plx) iounmap(pxa_info->plx);