Skip to content

Commit

Permalink
Merge pull request #1 from xtrx-sdr/master
Browse files Browse the repository at this point in the history
merge latest upstream changes
  • Loading branch information
stef authored Apr 5, 2019
2 parents acb94d4 + c83d1e9 commit 071e2ac
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 36 deletions.
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ project(libusb3380 C)
set(MAJOR_VERSION 0)
set(API_COMPAT 0)
set(MINOR_VERSION 1)
set(MAINT_VERSION git)
set(MAINT_VERSION 2)

set(LIBVER "${MAJOR_VERSION}.${API_COMPAT}.${MINOR_VERSION}")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules/")
Expand Down Expand Up @@ -58,7 +58,7 @@ include_directories(.)

set(USB3380_FILES libusb3380.c)
if(CMAKE_SYSTEM_NAME MATCHES "Windows")
set(USB3380_FILES ${USB3380_FILES} xtrx_port.c)
set(USB3380_FILES ${USB3380_FILES} ../libxtrxll/xtrxll_port.c)
endif()

add_library(usb3380 SHARED ${USB3380_FILES})
Expand All @@ -82,8 +82,8 @@ set(CPACK_PACKAGE_NAME "libusb3380")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "USB3380 library")
set(CPACK_PACKAGE_VENDOR "Fairwaves, Inc.")
set(CPACK_PACKAGE_CONTACT "http://fairwaves.co/wp/contact-us/")
set(CPACK_PACKAGE_VERSION ${LIBVER}-1)
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6 (>= 2.17), libusb-1.0")
set(CPACK_PACKAGE_VERSION ${LIBVER}-${MAINT_VERSION})
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6 (>= 2.17), libusb-1.0-0")

set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}")
set(CPACK_SET_DESTDIR "")
Expand Down
77 changes: 45 additions & 32 deletions libusb3380.c
Original file line number Diff line number Diff line change
Expand Up @@ -1223,7 +1223,9 @@ int usb3380_context_init_ex(libusb3380_context_t** octx, libusb_device *dev, lib
} else {
res = libusb_open(dev, &ctx->handle);
if (res) {
LOG_ERR("Unable to initialize DEVICE: %d", res);
LOG_ERR("Unable to initialize DEVICE: error `%s` (%d)!",
libusb_strerror((enum libusb_error)res), res);
res = libusb_to_errno(res);
goto cleanup_mem;
}
}
Expand All @@ -1234,20 +1236,16 @@ int usb3380_context_init_ex(libusb3380_context_t** octx, libusb_device *dev, lib
goto cleanup_ctx;
}

#if 0
res = libusb_reset_device(ctx->handle);
if (res) {
LOG_ERR("Unable to reset USB3380: error `%s` (%d)!",
libusb_strerror((enum libusb_error)res), res);
res = -EACCES;
res = libusb_to_errno(res);
goto cleanup_handle;
}
/*
res = libusb_set_configuration(ctx->handle, 0);
if (res) {
LOG_WARN("Unable to set configurateion : error `%s` (%d)!",
libusb_strerror((enum libusb_error)res), res);
}
*/
#endif

if (libusb_kernel_driver_active(ctx->handle, 0)) {
res = libusb_detach_kernel_driver(ctx->handle, 0);
if (res) {
Expand All @@ -1260,7 +1258,7 @@ int usb3380_context_init_ex(libusb3380_context_t** octx, libusb_device *dev, lib
if (res) {
LOG_ERR("Unable to claim interface: error `%s` (%d)!",
libusb_strerror((enum libusb_error)res), res);
res = -EACCES;
res = libusb_to_errno(res);
goto cleanup_handle;
}

Expand Down Expand Up @@ -1326,6 +1324,7 @@ int usb3380_init_root_complex(libusb3380_context_t* ctx,
{
int res;
uint32_t reg;
unsigned i;
bool reinit = false;

/* Check intersection of BAR2 and BAR3 spaces */
Expand Down Expand Up @@ -1387,13 +1386,31 @@ int usb3380_init_root_complex(libusb3380_context_t* ctx,
return res;
}
#endif
// Check and reset dedicated EP states
const char* ep_names[6] = { "CSROUT", "CSRIN", "PCIOUT", "PCIIN", "STATIN",
"RCIN" };
for (i = 0; i < 6; i++) {
res = usb3380_csr_mm_cfg_read(ctx, DEP_RSP + i * 0x10, &reg);
if (res) {
return res;
}
LOG_DEBUG("EPd %9s: RSP:%08x Halt:%d Toggle:%d",
ep_names[i], reg, (reg & 1) ? 1 : 0, (reg & 2) ? 1 : 0);

res = usb3380_csr_mm_cfg_write(ctx, DEP_RSP + i * 0x10,
(1<<0) | (1<<2) | (1<<7));
if (res) {
return res;
}
}

res = usb3380_idxreg_read(ctx, CHIPREV, &reg);
if (res) {
return res;
}
LOG_DEBUG("Chip REV %08x", reg);

#if 0
res = usb3380_csr_mm_cfg_read(ctx, USBCTL, &reg);
if (res) {
return res;
Expand All @@ -1402,7 +1419,7 @@ int usb3380_init_root_complex(libusb3380_context_t* ctx,
(reg & USBSTAT_SS_MODE) ? 5000 :
(reg & USBSTAT_HS_MODE) ? 480 :
(reg & USBSTAT_FS_MODE) ? 12 : 0);

#endif

res = usb3380_idxreg_read(ctx, HS_INTPOLL_RATE, &reg);
if (res) {
Expand Down Expand Up @@ -1544,7 +1561,6 @@ int usb3380_init_root_complex(libusb3380_context_t* ctx,
LOG_DEBUG("INCH %8x", reg);
#endif
// Enabgle credit calculation only for requested GPEPs
unsigned i;
for (reg = 0, i = 0; i < 4; i++) {
if (cfg->gpep_fifo_in_size[i] == 0)
reg |= (1U << (28 + i));
Expand Down Expand Up @@ -1588,31 +1604,14 @@ int usb3380_init_root_complex(libusb3380_context_t* ctx,
return res;
}

// Check EP states
const char* ep_names[6] = { "CSROUT", "CSRIN", "PCIOUT", "PCIIN", "STATIN",
"RCIN" };
for (i = 0; i < 6; i++) {
res = usb3380_csr_mm_cfg_read(ctx, DEP_RSP + i * 0x10, &reg);
if (res) {
return res;
}
LOG_DEBUG("EPd %9s: %08x Halt:%d Toggle:%d",
ep_names[i], reg, (reg & 1) ? 1 : 0, (reg & 2) ? 1 : 0);

res = usb3380_csr_mm_cfg_write(ctx, DEP_RSP + i * 0x10, 0);
if (res) {
return res;
}
}

const char* gpep_names[11] = { "EP0", "GPEP0 OUT", "GPEP1 OUT", "GPEP2 OUT",
"GPEP3 OUT", NULL, NULL, "GPEP0 IN",
"GPEP1 IN", "GPEP2 IN", "GPEP3 IN" };
for (i = 0; i < 11; i++) {
if (i == 5 || i == 6)
continue;

uint32_t eprsp, avail;
uint32_t epcfg, eprsp, avail;
res = usb3380_csr_mm_cfg_read(ctx, EP_STAT + i * 0x20, &reg);
if (res) {
return res;
Expand All @@ -1626,17 +1625,31 @@ int usb3380_init_root_complex(libusb3380_context_t* ctx,
return res;
}

LOG_DEBUG("EPg %9s: %04x %08x %08x Pkts: %2d Avail:%5d Empty:%d Full:%d STALL:%d TO:%d",
LOG_DEBUG("EPg %9s: %04x RSP:%08x STAT:%08x Pkts: %2d Avail:%5d Empty:%d Full:%d STALL:%d TO:%d",
gpep_names[i], EP_CFG + i*0x20, eprsp, reg, (reg >> 24) & 0x1f, avail,
(reg & (1<<10)) ? 1 : 0, (reg & (1<<11)) ? 1 : 0,
(reg & (1<<20)) ? 1 : 0, (reg & (1<<21)) ? 1 : 0);

if (i == 1 || i == 3) { //GPEP0 & GPEP2
res = usb3380_csr_mm_cfg_read(ctx, EP_CFG + i * 0x20, &epcfg);
if (res) {
return res;
}

epcfg = epcfg | (0xfu << 24); // Max burst size
res = usb3380_csr_mm_cfg_write(ctx, EP_CFG + i * 0x20, epcfg);
if (res) {
return res;
}
}

res = usb3380_csr_mm_cfg_write(ctx, EP_STAT + i * 0x20, 1<<9);
if (res) {
return res;
}

res = usb3380_csr_mm_cfg_write(ctx, EP_RSP + i * 0x20, 0);
// Clear all response bits, except toggle
res = usb3380_csr_mm_cfg_write(ctx, EP_RSP + i * 0x20, 0xfd);
if (res) {
return res;
}
Expand Down

0 comments on commit 071e2ac

Please sign in to comment.