blob: e7a6df9bcea6172d3e83a8720710730a6ad2f964 [file] [log] [blame]
Sridhar Parasuram7357e9b2014-10-01 12:19:11 -07001/* Copyright (c) 2013-2014, 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 _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 Srinivasanb3fc9982014-01-30 11:53:04 -080049#define UTP_GENERIC_CMD_TIMEOUT 40000
Deepa Dinamaniab9c2b92013-09-12 11:30:58 -070050
51struct utp_prdt_entry
52{
53 uint32_t data_base_addr;
54 uint32_t data_upper_addr;
55 uint8_t resv_0[4];
56 uint32_t data_byte_cnt;
57}__PACKED;
58
59struct utp_trans_req_desc
60{
61 uint8_t resv_0[3];
62 uint8_t cmd_type_dd_irq;
63 uint8_t resv_1[4];
64 uint8_t overall_cmd_status;
65 uint8_t resv_2[7];
66 uint8_t cmd_desc_base_addr[4];
67 uint8_t cmd_desc_base_addr_upper[4];
68 uint16_t resp_upiu_len;
69 uint16_t resp_upiu_offset;
70 uint16_t prdt_len;
71 uint16_t prdt_offset;
72}__PACKED;
73
74enum utp_utrd_irq_type
75{
76 UTRD_REGULAR_CMD = 0,
77 UTRD_IRQ_CMD = 1,
78};
79
80enum utp_utrd_overall_status_type
81{
82 UTRD_OCS_SUCCESS = 0x0,
83 UTRD_OCS_INVALID_COM_TABLE_ATTR = 0x1,
84 UTRD_OCS_INVALID_PRDT_ATTR = 0x2,
85 UTRD_OCS_MISMATCH_DATA_BUFFER_SIZE = 0x3,
86 UTRD_OCS_MISMATCH_RESPONSE_UPIU_SIZE = 0x4,
87 UTRD_OCS_COMMUNICATION_FAILURE = 0x5,
88 UTRD_OCS_ABORTED = 0x6,
89 UTRD_OCS_INVALID_OCS_VALUE = 0xf,
90};
91
92struct utp_utrd_req_build_type
93{
94 struct upiu_basic_hdr *req_upiu;
95 uint32_t req_upiu_len;
96 uint32_t resp_upiu_len;
97 enum upiu_cmd_type cmd_type;
98 enum upiu_dd_type dd;
99 enum utp_utrd_irq_type irq;
100 enum utp_utrd_overall_status_type ocs;
101 uint32_t prdt_offset;
102 uint32_t prdt_len;
103 uint32_t timeout;
104};
105
106struct utp_task_mgmt_req_desc
107{
108 uint8_t resv_0[3];
109 uint8_t irq;
110 uint8_t resv_1[4];
111 uint8_t overall_cmd_status;
112 uint8_t resv_2[7];
113}__PACKED;
114
115enum utp_utmrd_irq_type
116{
117 NO_IRQ = 0,
118 ENABLE_IRQ = 1,
119};
120
121enum utp_utmrd_overall_status_type
122{
123 UTMRD_OCS_SUCCESS = 0x0,
124 UTMRD_OCS_TASK_MGMT_FUNC_ATTR = 0x1,
125 UTMRD_OCS_MISMATCH_TASK_MGMT_REQ_SIZE = 0x2,
126 UTMRD_OCS_MISMATCH_TASK_MGMT_RES_SIZE = 0x3,
127 UTMRD_OCS_PEER_COMM_FAILURE = 0x4,
128 UTMRD_OCS_ABORTED = 0x5,
129 UTMRD_OCS_FATAL_ERR = 0x6,
130};
131
132struct utrd_cmd_desc
133{
134 struct upiu_gen_hdr *req_upiu;
135 uint32_t resp_upiu_len;
136 uint32_t num_prdt;
137};
138
139struct utp_bitmap_access_type
140{
141 uint32_t *bitmap;
142 uint32_t door_bell_bit;
143 mutex_t *mutx;
144};
145
146int utp_enqueue_upiu(struct ufs_dev *dev, struct upiu_req_build_type *upiu_data);
147void utp_process_req_completion(struct ufs_req_irq_type *irq);
Sridhar Parasuram7357e9b2014-10-01 12:19:11 -0700148int utp_poll_utrd_complete(struct ufs_dev *dev);
Deepa Dinamaniab9c2b92013-09-12 11:30:58 -0700149#endif