blob: 0af2dc54b5b71de3b71410747d5ac2d9a8d14ef5 [file] [log] [blame]
Channagoud Kadabi5890d9b2015-01-29 13:04:04 -08001/* Copyright (c) 2013-2015, The Linux Foundation. All rights reserved.
Deepa Dinamaniab9c2b92013-09-12 11:30:58 -07002 *
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are
5 * met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above
9 * copyright notice, this list of conditions and the following
10 * disclaimer in the documentation and/or other materials provided
11 * with the distribution.
12 * * Neither the name of The Linux Foundation nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#ifndef _UFS_H_
30#define _UFS_H_
31
32#include <sys/types.h>
33#include <kernel/mutex.h>
34#include <kernel/event.h>
35#include <list.h>
36
37enum ufs_err
38{
39 UFS_SUCCESS,
40 UFS_FAILURE,
41 UFS_RETRY,
42};
43
44struct ufs_req_node
45{
46 uint32_t task_id;
47 uint32_t door_bell_bit;
48 event_t *event;
49 struct list_node list_node;
50};
51
52
53struct ufs_utp_req_meta_data
54{
55 mutex_t bitmap_mutex;
56 struct ufs_req_node list_head;
57 uint32_t bitmap;
58 uint32_t task_id;
59 uint64_t list_base_addr;
60};
61
62struct ufs_uic_meta_data
63{
64 mutex_t uic_mutex;
65 event_t uic_event;
66};
67
Sundarajan Srinivasan332ce6a2013-12-04 17:27:46 -080068struct ufs_unit_desc
69{
70 uint8_t desc_len;
71 uint8_t desc_type;
72 uint8_t unit_index;
73 uint8_t lu_enable;
74 uint8_t boot_lun_id;
75 uint8_t lu_wp;
76 uint8_t lu_queue_depth;
77 uint8_t resv;
78 uint8_t mem_type;
79 uint8_t data_reliability;
80 uint8_t logical_blk_size;
81 uint64_t logical_blk_cnt;
82 uint32_t erase_blk_size;
83 uint8_t provisioning_type;
84 uint8_t phy_mem_resource_cnt[8];
85 uint16_t ctx_capabilities;
86 uint8_t large_unit_size_m1;
87}__PACKED;
88
Deepa Dinamaniab9c2b92013-09-12 11:30:58 -070089struct ufs_dev
90{
91 uint8_t instance;
92 uint32_t base;
93 uint8_t num_lus;
Sundarajan Srinivasan332ce6a2013-12-04 17:27:46 -080094 uint8_t current_lun;
95 uint32_t serial_num;
Deepa Dinamaniab9c2b92013-09-12 11:30:58 -070096 uint32_t block_size;
Sundarajan Srinivasan54380a32013-10-25 17:38:38 -070097 uint32_t erase_blk_size;
Sridhar Parasuram9374faa2014-10-23 19:56:12 -070098 uint32_t rpmb_rw_size;
99 uint32_t rpmb_num_blocks;
Sundarajan Srinivasan54380a32013-10-25 17:38:38 -0700100 uint64_t capacity;
Sundarajan Srinivasan332ce6a2013-12-04 17:27:46 -0800101 struct ufs_unit_desc lun_cfg[8];
Deepa Dinamaniab9c2b92013-09-12 11:30:58 -0700102
103 /* UTRD maintainance data structures.*/
104 struct ufs_utp_req_meta_data utrd_data;
105 struct ufs_utp_req_meta_data utmrd_data;
106
107 /* UIC maintainance data structures.*/
108 struct ufs_uic_meta_data uic_data;
109};
110
111/* Define all the basic WLUN type */
112#define UFS_WLUN_REPORT 0x81
113#define UFS_UFS_DEVICE 0xD0
114#define UFS_WLUN_BOOT 0xB0
115#define UFS_WLUN_RPMB 0xC4
116
117int ufs_init(struct ufs_dev *dev);
118int ufs_read(struct ufs_dev* dev, uint64_t start_lba, addr_t buffer, uint32_t num_blocks);
119int ufs_write(struct ufs_dev* dev, uint64_t start_lba, addr_t buffer, uint32_t num_blocks);
Sundarajan Srinivasan54380a32013-10-25 17:38:38 -0700120int ufs_erase(struct ufs_dev* dev, uint64_t start_lba, uint32_t num_blocks);
Deepa Dinamaniab9c2b92013-09-12 11:30:58 -0700121uint64_t ufs_get_dev_capacity(struct ufs_dev* dev);
122uint32_t ufs_get_serial_num(struct ufs_dev* dev);
Sundarajan Srinivasan332ce6a2013-12-04 17:27:46 -0800123uint8_t ufs_get_num_of_luns(struct ufs_dev* dev);
Sundarajan Srinivasan54380a32013-10-25 17:38:38 -0700124uint32_t ufs_get_erase_blk_size(struct ufs_dev* dev);
Sridhar Parasuram9ab24812014-10-01 10:51:23 -0700125void ufs_dump_is_register(struct ufs_dev* dev);
Sundarajan Srinivasan2fcaa982013-10-31 17:44:02 -0700126void ufs_dump_hc_registers(struct ufs_dev* dev);
Channagoud Kadabi5890d9b2015-01-29 13:04:04 -0800127void ufs_rpmb_init(struct ufs_dev *dev);
Deepa Dinamaniab9c2b92013-09-12 11:30:58 -0700128#endif