*/
#include <common/compatibility.h>
+#include <common/bit_slice.h>
#include "tools_cif.h"
#define TOOLS_HCR_MAX_MBOX 256
#define QUERY_DEV_CAP_OP 0x3
#define QUERY_DEF_PARAMS_OP 0x73
+#define QPC_READ_OP 0x67
+#define QPC_WRITE_OP 0x69
+
#define CHECK_RC(rc) \
if (rc) return rc;
MError tcif_query_dev_cap(mfile *dev, u_int32_t offset, u_int64_t* data)
{
- int rc = tools_cmdif_send_mbox_command(dev, QUERY_DEV_CAP_OP, 0, offset, data, 8, 1); CHECK_RC(rc);
+ int rc = tools_cmdif_send_mbox_command(dev, 0, QUERY_DEV_CAP_OP, 0, offset, data, 8, 1); CHECK_RC(rc);
BE32_TO_CPU(data, 2);
return ME_OK;
}
MError tcif_query_global_def_params(mfile* dev, struct tools_open_query_def_params_global* global_params)
{
u_int8_t data[TOOLS_OPEN_QUERY_DEF_PARAMS_GLOBAL_SIZE] = {0};
- int rc = tools_cmdif_send_mbox_command(dev, QUERY_DEF_PARAMS_OP, 0, 0, data, sizeof(data), 0);CHECK_RC(rc);
+ int rc = tools_cmdif_send_mbox_command(dev, 0, QUERY_DEF_PARAMS_OP, 0, 0, data, sizeof(data), 0);CHECK_RC(rc);
tools_open_query_def_params_global_unpack(global_params, data);
return ME_OK;
}
MError tcif_query_per_port_def_params(mfile* dev, u_int8_t port, struct tools_open_query_def_params_per_port* port_params)
{
u_int8_t data[TOOLS_OPEN_QUERY_DEF_PARAMS_PER_PORT_SIZE] = {0};
- int rc = tools_cmdif_send_mbox_command(dev, QUERY_DEF_PARAMS_OP, port, 0, data, sizeof(data), 0);CHECK_RC(rc);
+ int rc = tools_cmdif_send_mbox_command(dev, 0, QUERY_DEF_PARAMS_OP, port, 0, data, sizeof(data), 0);CHECK_RC(rc);
tools_open_query_def_params_per_port_unpack(port_params, data);
return ME_OK;
}
+MError tcif_qpc_context_read(mfile* dev, u_int32_t qpn, u_int32_t source, u_int8_t* data, u_int32_t len)
+{
+ u_int32_t input_mod = 0;
+ input_mod = MERGE(input_mod, source, 24, 8);
+ input_mod = MERGE(input_mod, qpn , 0, 24);
+ int rc = tools_cmdif_send_mbox_command(dev, input_mod, QPC_READ_OP, 0, 0, data, len, 0);
+ CHECK_RC(rc);
+ return ME_OK;
+}
+
+MError tcif_qpc_context_write(mfile* dev, u_int32_t qpn, u_int32_t source, u_int8_t* data, u_int32_t len)
+{
+ u_int32_t input_mod = 0;
+ input_mod = MERGE(input_mod, source, 24, 8);
+ input_mod = MERGE(input_mod, qpn , 0, 24);
+ int rc = tools_cmdif_send_mbox_command(dev, input_mod, QPC_WRITE_OP, 0, 0, data, len, 0);
+ CHECK_RC(rc);
+ return ME_OK;
+}
+
const char* tcif_err2str(MError rc) {
return m_err2str(rc);
}
int tools_cmdif_send_inline_cmd(mfile* mf, u_int64_t in_param, u_int64_t* out_param,
u_int32_t input_modifier, u_int16_t opcode, u_int8_t opcode_modifier);
-int tools_cmdif_send_mbox_command(mfile* mf, u_int16_t opcode, u_int8_t opcode_modifier,
+int tools_cmdif_send_mbox_command(mfile* mf, u_int32_t input_modifier, u_int16_t opcode, u_int8_t opcode_modifier,
int data_offs_in_mbox, void* data, int data_size, int skip_write);
int tools_cmdif_unlock_semaphore(mfile *mf);
f_maccess_reg maccess_reg;
f_mclose mclose;
+ /******** RESERVED FIELDS FOR SWITCHING METHOD IF NEEDED ******/
+ void *res_ctx; // Reserved access method context
+ int res_access_type;
+ int res_fdlock;
+ f_mread4 res_mread4;
+ f_mwrite4 res_mwrite4;
+ f_mread4_block res_mread4_block;
+ f_mwrite4_block res_mwrite4_block;
+ /*************************************************************/
+
//for ICMD access
icmd_params icmd;
};
+
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <errno.h>
#include <bit_slice.h>
#include <common/tools_utils.h>
#define MWRITE4(offs, val) do {WRITE_WORD(offs, val);} while (0)
#else
#define MREAD4(offs, val) do { if (mread4 (mf, offs, val) != 4) { \
- /*fprintf(stderr, "-E- Cr read (0x%08x) failed: %s(%d)\n", (u_int32_t)(offs), strerror(errno), (u_int32_t)errno);*/ \
- return 2; } /*printf("-D- %s:%d mread4: offs = %#x, val = %#x\n", __FUNCTION__, __LINE__, offs, val);*/\
+ /*fprintf(stderr, "-E- Cr read (0x%08x) failed: %s(%d)\n", (unsigned int)(offs), strerror(errno), errno); */\
+ return 2; } /*printf("-D- %s:%d mread4: offs = %#x, val = %#x\n", __FUNCTION__, __LINE__, (unsigned int)offs, (unsigned int)(*val));*/\
} while (0)
#define MWRITE4(offs, val) do { if (mwrite4(mf, offs, val) != 4) { \
- /*fprintf(stderr, "-E- Cr write (0x%08x, 0x%08x) failed: %s(%d)\n", (u_int32_t)(offs), (u_int32_t)(val), strerror(errno), (u_int32_t)errno);*/ \
+ /*fprintf(stderr, "-E- Cr write (0x%08x, 0x%08x) failed: %s(%d)\n", (u_int32_t)(offs), (u_int32_t)(*val), strerror(errno), (u_int32_t)errno);*/ \
return 2; } /*printf("-D- %s:%d mwrite4: offs = %#x, val = %#x\n", __FUNCTION__, __LINE__, offs, val);*/ \
} while (0)
#endif
}
}
+extern void mpci_change(mfile* mf);
static void tools_cmdif_pack(tools_cmdif* cmd, u_int32_t* buf) {
memset((char*)buf, 0, CMD_IF_SIZE);
if (lock_state) {
do {
if (++cnt > TOOLS_SEM_TRIES) {
- //printf("-E- Can not obtain Flash semaphore");
return ME_SEM_LOCKED;
}
MREAD4(TOOLS_HCR_SEM, &word);
} else {
MWRITE4(TOOLS_HCR_SEM, 0);
}
-
return ME_OK;
}
cmdif.opcode_modifier = opcode_modifier;
//take semaphore
+ mpci_change(mf);
if (tools_cmdif_flash_lock(mf, 1)) {
- return ME_SEM_LOCKED;
+ mpci_change(mf);
+ return ME_SEM_LOCKED;
}
int rc = tools_cmdif_send_cmd_int(mf, &cmdif);
// release it
tools_cmdif_flash_lock(mf, 0);
-
+ mpci_change(mf);
*out_param = cmdif.out_param;
if (rc || cmdif.status) {
return (rc != ME_CMDIF_BAD_STATUS) ? rc : translate_status(cmdif.status);
int tools_cmdif_is_supported(mfile *mf)
{
+ int rc = ME_OK;
if (!mf) {
return ME_BAD_PARAMS;
}
+ mpci_change(mf);
// take semaphore
if (tools_cmdif_flash_lock(mf, 1)) {
- return ME_SEM_LOCKED;
+ rc = ME_SEM_LOCKED;
+ goto cleanup;
}
// run mailbox write cmd (read command fails after driver restart or internal reset)
- int rc = tools_cmdif_mbox_write(mf, 0x0, 0);
+ rc = tools_cmdif_mbox_write(mf, 0x0, 0);
if (rc) {
tools_cmdif_flash_lock(mf, 0);
- return rc;
+ goto cleanup;
}
tools_cmdif_flash_lock(mf, 0);
- return ME_OK;
+cleanup:
+ mpci_change(mf);
+ return rc;
}
/*
((byte_sz) + ((8 - ((byte_sz) & 7) == 8) ? 0 : (8 - ((byte_sz) & 7))))
int tools_cmdif_send_mbox_command_int(mfile* mf,
+ u_int32_t input_modifier,
u_int16_t opcode,
u_int8_t opcode_modifier,
int data_offs_in_mbox,
data_offs_in_mbox + write_data_size_quad_alligned > TOOLS_HCR_MAX_MBOX) {
return ME_BAD_PARAMS;
}
+ mpci_change(mf);
//take semaphore
if (tools_cmdif_flash_lock(mf, 1)) {
- return ME_SEM_LOCKED;
+ rc = ME_SEM_LOCKED;
+ goto exitrc;
}
// write to mailbox if needed
memset(&cmdif, 0, sizeof(tools_cmdif));
cmdif.opcode = opcode;
cmdif.opcode_modifier = opcode_modifier;
+ cmdif.input_modifier = input_modifier;
rc = tools_cmdif_send_cmd_int(mf, &cmdif);
//printf("-D- tools_cmdif_send_cmd_int: rc = 0x%x, cmdif.status: 0x%x\n", rc, cmdif.status);
//read_entire_mbox(mf);
cleanup:
tools_cmdif_flash_lock(mf, 0);
//printf("-D- rc in cmdif: 0x%x\n", rc);
+exitrc:
+ mpci_change(mf);
return rc;
}
int tools_cmdif_reg_access(mfile *mf, void* data, int write_data_size, int read_data_size)
{
- return tools_cmdif_send_mbox_command_int(mf, REG_ACCESS_OP, 0, \
+ return tools_cmdif_send_mbox_command_int(mf, 0, REG_ACCESS_OP, 0, \
0, data, write_data_size, read_data_size, 0);
}
int tools_cmdif_send_mbox_command(mfile* mf,
+ u_int32_t input_modifier,
u_int16_t opcode,
u_int8_t opcode_modifier,
int data_offs_in_mbox,
int data_size,
int skip_write)
{
- return tools_cmdif_send_mbox_command_int(mf, opcode, opcode_modifier, \
+
+ return tools_cmdif_send_mbox_command_int(mf, input_modifier, opcode, opcode_modifier, \
data_offs_in_mbox, data, data_size,\
data_size, skip_write);
}
u_int32_t data_r[8] = {0};
//take semaphore
if (tools_cmdif_flash_lock(mf, 1)) {
- return ME_SEM_LOCKED;
+ return ME_SEM_LOCKED;
}
// write data to mbox
printf("-D- writing data to Mbox.\n");
int mtcr_pcicr_mclose(mfile *mf)
{
struct pcicr_context* ctx = mf->ctx;
+ struct pciconf_context* conf_ctx = mf->res_ctx;
if (ctx) {
if (ctx->ptr) {
munmap(ctx->ptr,MTCR_MAP_SIZE);
free(ctx);
mf->ctx = NULL;
}
-
+ if (conf_ctx) {
+ if (conf_ctx->fd != -1) {
+ close(conf_ctx->fd);
+ }
+ free(conf_ctx);
+ mf->res_ctx = NULL;
+ }
return 0;
}
}
static
-int mtcr_pcicr_open(mfile *mf, const char *name, off_t off, int ioctl_needed)
+int mtcr_pcicr_open(mfile *mf, const char *name, char* conf_name, off_t off, int ioctl_needed)
{
int rc;
struct pcicr_context *ctx;
end:
if (rc) {
mtcr_pcicr_mclose(mf);
+ return rc;
+ }
+ if (conf_name != NULL) {
+ mfile* conf_mf = mopen(conf_name);
+ if (conf_mf != NULL) {
+ mf->res_ctx = conf_mf->ctx;
+ mf->res_access_type = conf_mf->access_type;
+ mf->res_fdlock = conf_mf->fdlock;
+ mf->supp_fw_ifc = conf_mf->supp_fw_ifc;
+ mf->address_domain = conf_mf->address_domain;
+ mf->res_mread4 = conf_mf->mread4;
+ mf->res_mwrite4 = conf_mf->mwrite4;
+ mf->res_mread4_block = conf_mf->mread4_block;
+ mf->res_mwrite4_block = conf_mf->mwrite4_block;
+ free(conf_mf);
+ }
}
-
return rc;
}
goto open_failed;
}
}
-
+ sprintf(cbuf, "/sys/bus/pci/devices/%4.4x:%2.2x:%2.2x.%1.1x/config",
+ domain, bus, dev, func);
if (force) {
switch (access) {
case MTCR_ACCESS_CONFIG:
rc = mtcr_pciconf_open(mf, name);
break;
case MTCR_ACCESS_MEMORY:
- rc = mtcr_pcicr_open(mf, name, 0, 0);
+ rc = mtcr_pcicr_open(mf, name, cbuf, 0, 0);
break;
case MTCR_ACCESS_INBAND:
rc = mtcr_inband_open(mf, name);
sprintf(rbuf, "/sys/bus/pci/devices/%4.4x:%2.2x:%2.2x.%1.1x/resource0",
domain, bus, dev, func);
- rc = mtcr_pcicr_open(mf, rbuf, 0, 0);
+ rc = mtcr_pcicr_open(mf, rbuf, cbuf, 0, 0);
if (rc == 0) {
return mf;
} else if (rc == 1) {
sprintf(pdbuf, "/proc/bus/pci/%4.4x:%2.2x/%2.2x.%1.1x",
domain, bus, dev, func);
- rc = mtcr_pcicr_open(mf, pdbuf, offset, 1);
- if (rc == 0) {
- return mf;
- } else if (rc == 1) {
- goto access_config;
- }
-
- rc = mtcr_pcicr_open(mf, pdbuf, offset, 1);
+ rc = mtcr_pcicr_open(mf, pdbuf, cbuf, offset, 1);
if (rc == 0) {
return mf;
} else if (rc == 1) {
if (!domain) {
sprintf(pbuf, "/proc/bus/pci/%2.2x/%2.2x.%1.1x",
bus, dev, func);
- rc = mtcr_pcicr_open(mf, pbuf, offset, 1);
+ rc = mtcr_pcicr_open(mf, pbuf, cbuf, offset, 1);
if (rc == 0) {
return mf;
} else if (rc == 1) {
#if CONFIG_USE_DEV_MEM
/* Non-portable, but helps some systems */
- if (!mtcr_pcicr_open(mf, "/dev/mem", offset, 0))
+ if (!mtcr_pcicr_open(mf, "/dev/mem", cbuf, offset, 0))
return mf;
#endif
if (mf->fdlock) {
close(mf->fdlock);
}
+ if (mf->res_fdlock) {
+ close(mf->res_fdlock);
+ }
free(mf);
}
return 0;
}
+extern void mpci_change(mfile* mf)
+{
+ if (!mf->res_ctx) {
+ return;
+ }
+ if (mf->res_access_type == MTCR_ACCESS_CONFIG) {
+ mf->res_access_type = MTCR_ACCESS_MEMORY;
+ mf->access_type = MTCR_ACCESS_CONFIG;
+ } else if (mf->res_access_type == MTCR_ACCESS_MEMORY) {
+ mf->res_access_type = MTCR_ACCESS_CONFIG;
+ mf->access_type = MTCR_ACCESS_MEMORY;
+ } else {
+ return;
+ }
+
+ /***** Switching READ WRITE FUNCS ******/
+ f_mread4 tmp_mread4 = mf->mread4;
+ mf->mread4 = mf->res_mread4;
+ mf->res_mread4 = tmp_mread4;
+
+ f_mwrite4 tmp_mwrite4 = mf->mwrite4;
+ mf->mwrite4 = mf->res_mwrite4;
+ mf->res_mwrite4 = tmp_mwrite4;
+
+ f_mread4_block tmp_mread4_block = mf->mread4_block;
+ mf->mread4_block = mf->res_mread4_block;
+ mf->res_mread4_block = tmp_mread4_block;
+
+ f_mwrite4_block tmp_mwrite4_block = mf->mwrite4_block;
+ mf->mwrite4_block = mf->res_mwrite4_block;
+ mf->res_mwrite4_block = tmp_mwrite4_block;
+
+ /***** Switching FD LOCKs ******/
+ int tmp_lock = mf->res_fdlock;
+ mf->res_fdlock = mf->fdlock;
+ mf->fdlock = tmp_lock;
+
+ /***** Switching CNTX ******/
+ void* tmp_ctx = mf->res_ctx;
+ mf->res_ctx = mf->ctx;
+ mf->ctx = tmp_ctx;
+}
+
mfile *mopen_fw_ctx(void* fw_cmd_context, void* fw_cmd_func)
{
// not implemented