1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
/*
* Universal Flash Storage Feature Support
*
* Copyright (C) 2017-2018 Samsung Electronics Co., Ltd.
*
* Authors:
* Yongmyung Lee <ymhungry.lee@samsung.com>
* Jinyoung Choi <j-young.choi@samsung.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* See the COPYING file in the top-level directory or visit
* <http://www.gnu.org/licenses/gpl-2.0.html>
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This program is provided "AS IS" and "WITH ALL FAULTS" and
* without warranty of any kind. You are solely responsible for
* determining the appropriateness of using and distributing
* the program and assume all risks associated with your exercise
* of rights with respect to the program, including but not limited
* to infringement of third party rights, the risks and costs of
* program errors, damage to or loss of data, programs or equipment,
* and unavailability or interruption of operations. Under no
* circumstances will the contributor of this Program be liable for
* any damages of any kind arising from your use or distribution of
* this program.
*
* The Linux Foundation chooses to take subject only to the GPLv2
* license terms, and distributes only under these terms.
*/
#ifndef _UFSFEATURE_H_
#define _UFSFEATURE_H_
#include "ufs.h"
#include "../../../include/uapi/scsi/ufs/ioctl.h"
#if defined(CONFIG_UFSHPB)
#include "ufshpb.h"
#endif
#include <scsi/scsi_cmnd.h>
/* Constant value*/
#define SECTOR 512
#define SECTOR_SHIFT 9
#define BLOCK 4096
#define SECTORS_PER_BLOCK (BLOCK / SECTOR)
#define BITS_PER_DWORD 32
#define IOCTL_DEV_CTX_MAX_SIZE OS_PAGE_SIZE
#define OS_PAGE_SIZE 4096
#define OS_PAGE_SHIFT 12
/* Description */
#define UFSF_QUERY_DESC_DEVICE_MAX_SIZE 0x57
#define UFSF_QUERY_DESC_CONFIGURAION_MAX_SIZE 0xE2
#define UFSF_QUERY_DESC_UNIT_MAX_SIZE 0x2D
#define UFSF_QUERY_DESC_GEOMETRY_MAX_SIZE 0x58
#define UFSFEATURE_SELECTOR 0x00
/* BIG -> LI */
#define LI_EN_16(x) be16_to_cpu(*(__be16 *)(x))
#define LI_EN_32(x) be32_to_cpu(*(__be32 *)(x))
#define LI_EN_64(x) be64_to_cpu(*(__be64 *)(x))
/* LI -> BIG */
#define GET_BYTE_0(num) (((num) >> 0) & 0xff)
#define GET_BYTE_1(num) (((num) >> 8) & 0xff)
#define GET_BYTE_2(num) (((num) >> 16) & 0xff)
#define GET_BYTE_3(num) (((num) >> 24) & 0xff)
#define GET_BYTE_4(num) (((num) >> 32) & 0xff)
#define GET_BYTE_5(num) (((num) >> 40) & 0xff)
#define GET_BYTE_6(num) (((num) >> 48) & 0xff)
#define GET_BYTE_7(num) (((num) >> 56) & 0xff)
#define INFO_MSG(msg, args...) printk(KERN_INFO "%s:%d " msg "\n", \
__func__, __LINE__, ##args)
#define INIT_INFO(msg, args...) INFO_MSG(msg, ##args)
#define RELEASE_INFO(msg, args...) INFO_MSG(msg, ##args)
#define SYSFS_INFO(msg, args...) INFO_MSG(msg, ##args)
#define ERR_MSG(msg, args...) printk(KERN_ERR "%s:%d " msg "\n", \
__func__, __LINE__, ##args)
#define WARNING_MSG(msg, args...) printk(KERN_WARNING "%s:%d " msg "\n", \
__func__, __LINE__, ##args)
#define seq_scan_lu(lun) for (lun = 0; lun < UFS_UPIU_MAX_GENERAL_LUN; lun++)
#define TMSG(ufsf, lun, msg, args...) \
do { if (ufsf->sdev_ufs_lu[lun] && \
ufsf->sdev_ufs_lu[lun]->request_queue) \
blk_add_trace_msg( \
ufsf->sdev_ufs_lu[lun]->request_queue, \
msg, ##args); \
} while (0) \
struct ufsf_lu_desc {
/* Common info */
int lu_enable; /* 03h bLUEnable */
int lu_queue_depth; /* 06h lu queue depth info*/
int lu_logblk_size; /* 0Ah bLogicalBlockSize. default 0x0C = 4KB */
u64 lu_logblk_cnt; /* 0Bh qLogicalBlockCount. */
#if defined(CONFIG_UFSHPB)
u16 lu_max_active_hpb_rgns; /* 23h:24h wLUMaxActiveHPBRegions */
u16 lu_hpb_pinned_rgn_startidx; /* 25h:26h wHPBPinnedRegionStartIdx */
u16 lu_num_hpb_pinned_rgns; /* 27h:28h wNumHPBPinnedRegions */
int lu_hpb_pinned_end_offset;
#endif
};
struct ufsf_feature {
struct ufs_hba *hba;
int num_lu;
int slave_conf_cnt;
struct scsi_device *sdev_ufs_lu[UFS_UPIU_MAX_GENERAL_LUN];
#if defined(CONFIG_UFSHPB)
struct ufshpb_dev_info hpb_dev_info;
struct ufshpb_lu *ufshpb_lup[UFS_UPIU_MAX_GENERAL_LUN];
struct delayed_work ufshpb_init_work;
struct work_struct ufshpb_reset_work;
struct work_struct ufshpb_eh_work;
wait_queue_head_t wait_hpb;
int ufshpb_state;
struct kref ufshpb_kref;
bool issue_ioctl;
#endif
};
struct ufs_hba;
struct ufshcd_lrb;
int ufsf_hpb_dt_check(struct ufs_hba *hba);
void ufsf_device_check(struct ufs_hba *hba);
int ufsf_check_query(__u32 opcode);
int ufsf_query_ioctl(struct ufsf_feature *ufsf, int lun, void __user *buffer,
struct ufs_ioctl_query_data *ioctl_data,
u8 selector);
bool ufsf_is_valid_lun(int lun);
/* for hpb */
int ufsf_hpb_prepare_pre_req(struct ufsf_feature *ufsf, struct scsi_cmnd *cmd,
int lun);
int ufsf_hpb_prepare_add_lrbp(struct ufsf_feature *ufsf, int add_tag);
void ufsf_hpb_end_pre_req(struct ufsf_feature *ufsf, struct request *req);
void ufsf_hpb_change_lun(struct ufsf_feature *ufsf, struct ufshcd_lrb *lrbp);
void ufsf_hpb_prep_fn(struct ufsf_feature *ufsf, struct ufshcd_lrb *lrbp);
void ufsf_hpb_wakeup_worker_on_idle(struct ufsf_feature *ufsf);
void ufsf_hpb_noti_rb(struct ufsf_feature *ufsf, struct ufshcd_lrb *lrbp);
void ufsf_hpb_reset_lu(struct ufsf_feature *ufsf);
void ufsf_hpb_reset_host(struct ufsf_feature *ufsf);
void ufsf_hpb_init(struct ufsf_feature *ufsf);
void ufsf_hpb_reset(struct ufsf_feature *ufsf);
void ufsf_hpb_suspend(struct ufsf_feature *ufsf);
void ufsf_hpb_resume(struct ufsf_feature *ufsf);
void ufsf_hpb_release(struct ufsf_feature *ufsf);
void ufsf_hpb_set_init_state(struct ufsf_feature *ufsf);
#endif /* End of Header */
|