Sridhar Parasuram | 7357e9b | 2014-10-01 12:19:11 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2013-2014, 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 _UTP_H_ |
| 30 | #define _UTP_H_ |
| 31 | |
| 32 | #include <ufs_hci.h> |
| 33 | #include <upiu.h> |
| 34 | #include <ucs.h> |
| 35 | #include <dme.h> |
| 36 | |
| 37 | /* UPIU general header length without the extra segments. */ |
| 38 | #define UPIU_HDR_LEN 0x20 |
| 39 | |
| 40 | #define UTP_MAX_PRD_DATA_BYTE_CNT 0x40000 |
| 41 | #define UTP_MAX_PRD_DATA_BYTE_CNT_BYTE_SHIFT 18 |
| 42 | #define UTP_MAX_PRD_TABLE_ENTRIES 1024 |
| 43 | |
| 44 | #define UTP_CMD_DESC_BASE_ALIGNMENT_SIZE 128 |
| 45 | #define UTP_REQ_BUILD_CMD_DD_IRQ_FIELD(cmd, dd, irq) ((cmd << 4) | (dd << 1) | irq) |
| 46 | |
| 47 | #define UTP_MUTEX_ACQUIRE_TIMEOUT 0x100000 |
| 48 | |
Sundarajan Srinivasan | b3fc998 | 2014-01-30 11:53:04 -0800 | [diff] [blame] | 49 | #define UTP_GENERIC_CMD_TIMEOUT 40000 |
Sridhar Parasuram | ea079c0 | 2014-10-09 16:37:27 -0700 | [diff] [blame] | 50 | #define UTP_MAX_COMMAND_RETRY 5000000 |
Deepa Dinamani | ab9c2b9 | 2013-09-12 11:30:58 -0700 | [diff] [blame] | 51 | |
| 52 | struct utp_prdt_entry |
| 53 | { |
| 54 | uint32_t data_base_addr; |
| 55 | uint32_t data_upper_addr; |
| 56 | uint8_t resv_0[4]; |
| 57 | uint32_t data_byte_cnt; |
| 58 | }__PACKED; |
| 59 | |
| 60 | struct utp_trans_req_desc |
| 61 | { |
| 62 | uint8_t resv_0[3]; |
| 63 | uint8_t cmd_type_dd_irq; |
| 64 | uint8_t resv_1[4]; |
| 65 | uint8_t overall_cmd_status; |
| 66 | uint8_t resv_2[7]; |
| 67 | uint8_t cmd_desc_base_addr[4]; |
| 68 | uint8_t cmd_desc_base_addr_upper[4]; |
| 69 | uint16_t resp_upiu_len; |
| 70 | uint16_t resp_upiu_offset; |
| 71 | uint16_t prdt_len; |
| 72 | uint16_t prdt_offset; |
| 73 | }__PACKED; |
| 74 | |
| 75 | enum utp_utrd_irq_type |
| 76 | { |
| 77 | UTRD_REGULAR_CMD = 0, |
| 78 | UTRD_IRQ_CMD = 1, |
| 79 | }; |
| 80 | |
| 81 | enum utp_utrd_overall_status_type |
| 82 | { |
| 83 | UTRD_OCS_SUCCESS = 0x0, |
| 84 | UTRD_OCS_INVALID_COM_TABLE_ATTR = 0x1, |
| 85 | UTRD_OCS_INVALID_PRDT_ATTR = 0x2, |
| 86 | UTRD_OCS_MISMATCH_DATA_BUFFER_SIZE = 0x3, |
| 87 | UTRD_OCS_MISMATCH_RESPONSE_UPIU_SIZE = 0x4, |
| 88 | UTRD_OCS_COMMUNICATION_FAILURE = 0x5, |
| 89 | UTRD_OCS_ABORTED = 0x6, |
| 90 | UTRD_OCS_INVALID_OCS_VALUE = 0xf, |
| 91 | }; |
| 92 | |
| 93 | struct utp_utrd_req_build_type |
| 94 | { |
| 95 | struct upiu_basic_hdr *req_upiu; |
| 96 | uint32_t req_upiu_len; |
| 97 | uint32_t resp_upiu_len; |
| 98 | enum upiu_cmd_type cmd_type; |
| 99 | enum upiu_dd_type dd; |
| 100 | enum utp_utrd_irq_type irq; |
| 101 | enum utp_utrd_overall_status_type ocs; |
| 102 | uint32_t prdt_offset; |
| 103 | uint32_t prdt_len; |
| 104 | uint32_t timeout; |
| 105 | }; |
| 106 | |
| 107 | struct utp_task_mgmt_req_desc |
| 108 | { |
| 109 | uint8_t resv_0[3]; |
| 110 | uint8_t irq; |
| 111 | uint8_t resv_1[4]; |
| 112 | uint8_t overall_cmd_status; |
| 113 | uint8_t resv_2[7]; |
| 114 | }__PACKED; |
| 115 | |
| 116 | enum utp_utmrd_irq_type |
| 117 | { |
| 118 | NO_IRQ = 0, |
| 119 | ENABLE_IRQ = 1, |
| 120 | }; |
| 121 | |
| 122 | enum utp_utmrd_overall_status_type |
| 123 | { |
| 124 | UTMRD_OCS_SUCCESS = 0x0, |
| 125 | UTMRD_OCS_TASK_MGMT_FUNC_ATTR = 0x1, |
| 126 | UTMRD_OCS_MISMATCH_TASK_MGMT_REQ_SIZE = 0x2, |
| 127 | UTMRD_OCS_MISMATCH_TASK_MGMT_RES_SIZE = 0x3, |
| 128 | UTMRD_OCS_PEER_COMM_FAILURE = 0x4, |
| 129 | UTMRD_OCS_ABORTED = 0x5, |
| 130 | UTMRD_OCS_FATAL_ERR = 0x6, |
| 131 | }; |
| 132 | |
| 133 | struct utrd_cmd_desc |
| 134 | { |
| 135 | struct upiu_gen_hdr *req_upiu; |
| 136 | uint32_t resp_upiu_len; |
| 137 | uint32_t num_prdt; |
| 138 | }; |
| 139 | |
| 140 | struct utp_bitmap_access_type |
| 141 | { |
| 142 | uint32_t *bitmap; |
| 143 | uint32_t door_bell_bit; |
| 144 | mutex_t *mutx; |
| 145 | }; |
| 146 | |
| 147 | int utp_enqueue_upiu(struct ufs_dev *dev, struct upiu_req_build_type *upiu_data); |
| 148 | void utp_process_req_completion(struct ufs_req_irq_type *irq); |
Sridhar Parasuram | 7357e9b | 2014-10-01 12:19:11 -0700 | [diff] [blame] | 149 | int utp_poll_utrd_complete(struct ufs_dev *dev); |
Deepa Dinamani | ab9c2b9 | 2013-09-12 11:30:58 -0700 | [diff] [blame] | 150 | #endif |