1. Aug 25, 2021
    • Nishad Kamdar's avatar
      mmc: core: Return correct emmc response in case of ioctl error · e72a55f2
      Nishad Kamdar authored
      
      
      When a read/write command is sent via ioctl to the kernel,
      and the command fails, the actual error response of the emmc
      is not sent to the user.
      
      IOCTL read/write tests are carried out using commands
      17 (Single BLock Read), 24 (Single Block Write),
      18 (Multi Block Read), 25 (Multi Block Write)
      
      The tests are carried out on a 64Gb emmc device. All of these
      tests try to access an "out of range" sector address (0x09B2FFFF).
      
      It is seen that without the patch the response received by the user
      is not OUT_OF_RANGE error (R1 response 31st bit is not set) as per
      JEDEC specification. After applying the patch proper response is seen.
      This is because the function returns without copying the response to
      the user in case of failure. This patch fixes the issue.
      
      Hence, this memcpy is required whether we get an error response or not.
      Therefor it is moved up from the current position up to immediately
      after we have called mmc_wait_for_req().
      
      The test code and the output of only the CMD17 is included in the
      commit to limit the message length.
      
      CMD17 (Test Code Snippet):
      ==========================
              printf("Forming CMD%d\n", opt_idx);
              /*  single block read */
              cmd.blksz = 512;
              cmd.blocks = 1;
              cmd.write_flag = 0;
              cmd.opcode = 17;
              //cmd.arg = atoi(argv[3]);
              cmd.arg = 0x09B2FFFF;
              /* Expecting response R1B */
              cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC;
      
              memset(data, 0, sizeof(__u8) * 512);
              mmc_ioc_cmd_set_data(cmd, data);
      
              printf("Sending CMD%d: ARG[0x%08x]\n", opt_idx, cmd.arg);
              if(ioctl(fd, MMC_IOC_CMD, &cmd))
                      perror("Error");
      
              printf("\nResponse: %08x\n", cmd.response[0]);
      
      CMD17 (Output without patch):
      =============================
      test@test-LIVA-Z:~$ sudo ./mmc cmd_test /dev/mmcblk0 17
      Entering the do_mmc_commands:Device: /dev/mmcblk0 nargs:4
      Entering the do_mmc_commands:Device: /dev/mmcblk0 options[17, 0x09B2FFF]
      Forming CMD17
      Sending CMD17: ARG[0x09b2ffff]
      Error: Connection timed out
      
      Response: 00000000
      (Incorrect response)
      
      CMD17 (Output with patch):
      ==========================
      test@test-LIVA-Z:~$ sudo ./mmc cmd_test /dev/mmcblk0 17
      [sudo] password for test:
      Entering the do_mmc_commands:Device: /dev/mmcblk0 nargs:4
      Entering the do_mmc_commands:Device: /dev/mmcblk0 options[17, 09B2FFFF]
      Forming CMD17
      Sending CMD17: ARG[0x09b2ffff]
      Error: Connection timed out
      
      Response: 80000900
      (Correct OUT_OF_ERROR response as per JEDEC specification)
      
      Signed-off-by: default avatarNishad Kamdar <nishadkamdar@gmail.com>
      Reviewed-by: default avatarAvri Altman <avri.altman@wdc.com>
      Link: https://lore.kernel.org/r/20210824191726.8296-1-nishadkamdar@gmail.com
      
      
      Signed-off-by: default avatarUlf Hansson <ulf.hansson@linaro.org>
      e72a55f2
    • Haibo Chen's avatar
      mmc: sdhci-esdhc-imx: Select the correct mode for auto tuning · 45334ee1
      Haibo Chen authored
      
      
      USDHC hardware auto tuning circuit support check 1/4/8 data lines and cmd
      line. Out of reset uSDHC, it default select check 4 data lines and do not
      check cmd line. This is incorrect if we use 8 data lines. So need to config
      the auto tuning mode according to current bus width.
      
      Signed-off-by: default avatarHaibo Chen <haibo.chen@nxp.com>
      Link: https://lore.kernel.org/r/1629285415-7495-2-git-send-email-haibo.chen@nxp.com
      
      
      Signed-off-by: default avatarUlf Hansson <ulf.hansson@linaro.org>
      45334ee1
    • Haibo Chen's avatar
      mmc: sdhci-esdhc-imx: Remove redundant code for manual tuning · a0dbbdc2
      Haibo Chen authored
      
      
      For manual tuning method, already call esdhc_prepare_tuning() config the
      necessary registers, so remove the redundant code in esdhc_writew_le() for
      SDHCI_HOST_CONTROL2.
      
      Signed-off-by: default avatarHaibo Chen <haibo.chen@nxp.com>
      Link: https://lore.kernel.org/r/1629285415-7495-1-git-send-email-haibo.chen@nxp.com
      
      
      Signed-off-by: default avatarUlf Hansson <ulf.hansson@linaro.org>
      a0dbbdc2
  2. Aug 24, 2021