]> git.openfabrics.org - ~adrianc/mstflint.git/commitdiff
Added support for switching MEM to CONFIG in mtcr , also merge cmdif from MFT
authorAdham Masarwah <adham@mellanox.com>
Tue, 23 Dec 2014 13:58:09 +0000 (15:58 +0200)
committerAdrian Chiris <adrianc@mellanox.com>
Tue, 23 Dec 2014 15:08:02 +0000 (17:08 +0200)
Signed-off-by: Adham Masarwah <adham@mellanox.com>
cmdif/tools_cif.c
include/mtcr_ul/mtcr.h
mtcr_ul/mtcr_int_defs.h
mtcr_ul/mtcr_tools_cif.c
mtcr_ul/mtcr_ul.c

index 2997cfda91f99d308af99b4ed644f5c1e89f9f20..7b776ae04574657d6b29ae417a1ee33924d899a6 100644 (file)
  */
 
 #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;
 
@@ -53,7 +57,7 @@
 
 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;
 }
@@ -62,7 +66,7 @@ MError tcif_query_dev_cap(mfile *dev, u_int32_t offset, u_int64_t* data)
 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;
 }
@@ -71,12 +75,32 @@ MError tcif_query_global_def_params(mfile* dev, struct tools_open_query_def_para
 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);
 }
index daa32cdbfb580e8ab9b5bd3beb43d86aac4f6dc8..f09f0f6ffa0d8cbe4472140056f5894b25135e38 100644 (file)
@@ -278,7 +278,7 @@ int icmd_clear_semaphore(mfile *mf);
 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);
index 6f598bd3e4a27b40d467cca426081170e3a6da83..f9766c0f47324ec5e689e33cf2bff08e83ef5aa7 100644 (file)
@@ -78,9 +78,20 @@ struct mfile_t {
     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
 
 
index 516eab8ab7bdeb0d228b1fc51afbb09b1a074b6e..fe0121159ed135480b20f8f3a25ead0f06e02b8b 100644 (file)
@@ -34,6 +34,7 @@
 #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
@@ -122,6 +123,7 @@ static int translate_status(int status) {
     }
 }
 
+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);
@@ -158,7 +160,6 @@ static int tools_cmdif_flash_lock(mfile* mf, int lock_state) {
     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);
@@ -166,7 +167,6 @@ static int tools_cmdif_flash_lock(mfile* mf, int lock_state) {
     } else {
         MWRITE4(TOOLS_HCR_SEM, 0);
     }
-
     return ME_OK;
 }
 
@@ -259,13 +259,15 @@ int tools_cmdif_send_inline_cmd(mfile* mf,
        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);
@@ -315,21 +317,26 @@ static int tools_cmdif_mbox_write(mfile* mf, u_int32_t offset, u_int64_t input)
 
 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;
 }
 
 /*
@@ -368,6 +375,7 @@ static void print_buffer(u_int8_t buffer[TOOLS_HCR_MAX_MBOX], const char* pre)
         ((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,
@@ -388,9 +396,11 @@ int tools_cmdif_send_mbox_command_int(mfile* mf,
             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
@@ -419,6 +429,7 @@ int tools_cmdif_send_mbox_command_int(mfile* mf,
     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);
@@ -451,18 +462,21 @@ int tools_cmdif_send_mbox_command_int(mfile* 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,
@@ -470,7 +484,8 @@ int tools_cmdif_send_mbox_command(mfile* mf,
                                            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);
 }
@@ -483,7 +498,7 @@ int test_mbox(mfile* mf)
        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");
index 9c00ffe3a7621e33d680a3e9f5f428814bcb5d2c..c1352b460d73560e54c1da563c67360cc87c3589 100644 (file)
@@ -480,6 +480,7 @@ static
 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);
@@ -491,7 +492,13 @@ int mtcr_pcicr_mclose(mfile *mf)
         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;
 }
 
@@ -585,7 +592,7 @@ int mtcr_pcicr_mwrite4(mfile *mf, unsigned int offset, u_int32_t value)
 }
 
 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;
@@ -618,8 +625,23 @@ int mtcr_pcicr_open(mfile *mf, const char *name, off_t off, int ioctl_needed)
 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;
 }
 
@@ -1501,14 +1523,15 @@ mfile *mopen(const char *name)
             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);
@@ -1530,7 +1553,7 @@ mfile *mopen(const char *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) {
@@ -1546,14 +1569,7 @@ mfile *mopen(const char *name)
 
     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) {
@@ -1563,7 +1579,7 @@ mfile *mopen(const char *name)
     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) {
@@ -1573,7 +1589,7 @@ mfile *mopen(const char *name)
 
 #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
 
@@ -1636,11 +1652,57 @@ int mclose(mfile *mf)
         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