Channagoud Kadabi | 5890d9b | 2015-01-29 13:04:04 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2013-2015, The Linux Foundation. All rights reserved. |
Deepa Dinamani | ab9c2b9 | 2013-09-12 11:30:58 -0700 | [diff] [blame] | 2 | * |
| 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 | |
| 37 | enum ufs_err |
| 38 | { |
| 39 | UFS_SUCCESS, |
| 40 | UFS_FAILURE, |
| 41 | UFS_RETRY, |
| 42 | }; |
| 43 | |
| 44 | struct 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 | |
| 53 | struct 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 | |
| 62 | struct ufs_uic_meta_data |
| 63 | { |
| 64 | mutex_t uic_mutex; |
| 65 | event_t uic_event; |
| 66 | }; |
| 67 | |
Sundarajan Srinivasan | 332ce6a | 2013-12-04 17:27:46 -0800 | [diff] [blame] | 68 | struct 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 Dinamani | ab9c2b9 | 2013-09-12 11:30:58 -0700 | [diff] [blame] | 89 | struct ufs_dev |
| 90 | { |
| 91 | uint8_t instance; |
| 92 | uint32_t base; |
| 93 | uint8_t num_lus; |
Sundarajan Srinivasan | 332ce6a | 2013-12-04 17:27:46 -0800 | [diff] [blame] | 94 | uint8_t current_lun; |
| 95 | uint32_t serial_num; |
Deepa Dinamani | ab9c2b9 | 2013-09-12 11:30:58 -0700 | [diff] [blame] | 96 | uint32_t block_size; |
Sundarajan Srinivasan | 54380a3 | 2013-10-25 17:38:38 -0700 | [diff] [blame] | 97 | uint32_t erase_blk_size; |
Sridhar Parasuram | 9374faa | 2014-10-23 19:56:12 -0700 | [diff] [blame] | 98 | uint32_t rpmb_rw_size; |
| 99 | uint32_t rpmb_num_blocks; |
Sundarajan Srinivasan | 54380a3 | 2013-10-25 17:38:38 -0700 | [diff] [blame] | 100 | uint64_t capacity; |
Sundarajan Srinivasan | 332ce6a | 2013-12-04 17:27:46 -0800 | [diff] [blame] | 101 | struct ufs_unit_desc lun_cfg[8]; |
Deepa Dinamani | ab9c2b9 | 2013-09-12 11:30:58 -0700 | [diff] [blame] | 102 | |
| 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 | |
| 117 | int ufs_init(struct ufs_dev *dev); |
| 118 | int ufs_read(struct ufs_dev* dev, uint64_t start_lba, addr_t buffer, uint32_t num_blocks); |
| 119 | int ufs_write(struct ufs_dev* dev, uint64_t start_lba, addr_t buffer, uint32_t num_blocks); |
Sundarajan Srinivasan | 54380a3 | 2013-10-25 17:38:38 -0700 | [diff] [blame] | 120 | int ufs_erase(struct ufs_dev* dev, uint64_t start_lba, uint32_t num_blocks); |
Deepa Dinamani | ab9c2b9 | 2013-09-12 11:30:58 -0700 | [diff] [blame] | 121 | uint64_t ufs_get_dev_capacity(struct ufs_dev* dev); |
| 122 | uint32_t ufs_get_serial_num(struct ufs_dev* dev); |
Sundarajan Srinivasan | 332ce6a | 2013-12-04 17:27:46 -0800 | [diff] [blame] | 123 | uint8_t ufs_get_num_of_luns(struct ufs_dev* dev); |
Sundarajan Srinivasan | 54380a3 | 2013-10-25 17:38:38 -0700 | [diff] [blame] | 124 | uint32_t ufs_get_erase_blk_size(struct ufs_dev* dev); |
Sridhar Parasuram | 9ab2481 | 2014-10-01 10:51:23 -0700 | [diff] [blame] | 125 | void ufs_dump_is_register(struct ufs_dev* dev); |
Sundarajan Srinivasan | 2fcaa98 | 2013-10-31 17:44:02 -0700 | [diff] [blame] | 126 | void ufs_dump_hc_registers(struct ufs_dev* dev); |
Channagoud Kadabi | 5890d9b | 2015-01-29 13:04:04 -0800 | [diff] [blame] | 127 | void ufs_rpmb_init(struct ufs_dev *dev); |
Deepa Dinamani | ab9c2b9 | 2013-09-12 11:30:58 -0700 | [diff] [blame] | 128 | #endif |