• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
3  *
4  * This program is free software; you can redistribute  it and/or modify it
5  * under  the terms of  the GNU General  Public License as published by the
6  * Free Software Foundation;  either version 2 of the  License, or (at your
7  * 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 
19 #include <config.h>
20 #include "scsi.h"
21 #include "ufs.h"
22 
get_cmnd(uint32_t opcode,uint32_t lba,uint32_t size,uint8_t * cmd)23 static int get_cmnd(uint32_t opcode, uint32_t lba, uint32_t size, uint8_t *cmd)
24 {
25 	ufs_memset(cmd, 0x0, 16);
26 
27 	switch (opcode) {
28 	case UFS_OP_READ_10:
29 		cmd[0] = UFS_OP_READ_10;
30 		cmd[1] = 0;
31 		cmd[2] = (uint8_t)((lba & 0xff000000) >> 24); /* MSB Byte */
32 		cmd[3] = (uint8_t)((lba & 0x00ff0000) >> 16);
33 		cmd[4] = (uint8_t)((lba & 0x0000ff00) >> 8);
34 		cmd[5] = (uint8_t)(lba & 0x000000ff); /* LSB byte */
35 		cmd[6] = 0;
36 		cmd[7] = (uint8_t)((size >> 8) & 0xff);
37 		cmd[8] = (uint8_t)((size) & 0xff);
38 		cmd[9] = 0;
39 		break;
40 
41 	case UFS_OP_TEST_UNIT_READY:
42 		cmd[0] = UFS_OP_TEST_UNIT_READY;
43 		cmd[1] = 0;
44 		cmd[2] = 0;
45 		cmd[3] = 0;
46 		cmd[4] = 0;
47 		cmd[5] = 0;
48 		break;
49 
50 	default:
51 		return -1;
52 	}
53 	return 0;
54 }
55