1 /* 2 Copyright (C) 2010, 2012, 2017 Rocky Bernstein <rocky@gnu.org> 3 4 This program is free software: you can redistribute it and/or modify 5 it under the terms of the GNU General Public License as published by 6 the Free Software Foundation, either version 3 of the License, or 7 (at your option) any later version. 8 9 This program is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 GNU General Public License for more details. 13 14 You should have received a copy of the GNU General Public License 15 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 18 #ifndef CDIO_DRIVER_MMC_CMD_HELPER_H_ 19 #define CDIO_DRIVER_MMC_CMD_HELPER_H_ 20 21 /* Boilerplate initialization code to setup running MMC command. We 22 assume variables 'p_cdio', 'p_buf', and 'i_size' are previously 23 defined. It does the following: 24 25 1. Defines a cdb variable, 26 2. zeros cdb variable 27 3 Checks to see if we have a cdio object and can run an MMC command 28 4. Sets up the command field of cdb to passed in value mmc_cmd. 29 */ 30 #define MMC_CMD_SETUP(mmc_cmd) \ 31 mmc_cdb_t cdb = {{0, }}; \ 32 \ 33 if ( ! p_cdio ) return DRIVER_OP_UNINIT; \ 34 if ( ! p_cdio->op.run_mmc_cmd ) return DRIVER_OP_UNSUPPORTED; \ 35 \ 36 CDIO_MMC_SET_COMMAND(cdb.field, mmc_cmd) 37 38 /* Boilerplate initialization code to setup running MMC read command 39 needs to set the cdb 16-bit length field. See above 40 comment for MMC_CMD_SETUP. 41 */ 42 #define MMC_CMD_SETUP_READ16(mmc_cmd) \ 43 MMC_CMD_SETUP(mmc_cmd); \ 44 \ 45 /* Setup to read header, to get length of data */ \ 46 CDIO_MMC_SET_READ_LENGTH16(cdb.field, i_size) 47 48 /* Boilerplate code to run a MMC command. 49 50 We assume variables 'p_cdio', 'mmc_timeout_ms', 'cdb', 'i_size' and 51 'p_buf' are defined previously. 52 53 'direction' is the SCSI direction (read, write, none) of the 54 command. 55 */ 56 #define MMC_RUN_CMD(direction, i_timeout) \ 57 p_cdio->op.run_mmc_cmd(p_cdio->env, \ 58 i_timeout, \ 59 mmc_get_cmd_len(cdb.field[0]), \ 60 &cdb, \ 61 direction, i_size, p_buf) 62 63 #endif /* CDIO_DRIVER_MMC_CMD_HELPER_H_ */ 64