^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Universal Flash Storage Host Performance Booster
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2017-2021 Samsung Electronics Co., Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Authors:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Yongmyung Lee <ymhungry.lee@samsung.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Jinyoung Choi <j-young.choi@samsung.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #ifndef _UFSHPB_H_
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #define _UFSHPB_H_
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) /* hpb response UPIU macro */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #define HPB_RSP_NONE 0x0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #define HPB_RSP_REQ_REGION_UPDATE 0x1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #define HPB_RSP_DEV_RESET 0x2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #define MAX_ACTIVE_NUM 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #define MAX_INACTIVE_NUM 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #define DEV_DATA_SEG_LEN 0x14
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #define DEV_SENSE_SEG_LEN 0x12
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #define DEV_DES_TYPE 0x80
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define DEV_ADDITIONAL_LEN 0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) /* hpb map & entries macro */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #define HPB_RGN_SIZE_UNIT 512
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #define HPB_ENTRY_BLOCK_SIZE 4096
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #define HPB_ENTRY_SIZE 0x8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #define PINNED_NOT_SET U32_MAX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) /* hpb support chunk size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #define HPB_LEGACY_CHUNK_HIGH 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #define HPB_MULTI_CHUNK_LOW 7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #define HPB_MULTI_CHUNK_HIGH 255
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) /* hpb vender defined opcode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #define UFSHPB_READ 0xF8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #define UFSHPB_READ_BUFFER 0xF9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #define UFSHPB_READ_BUFFER_ID 0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #define UFSHPB_WRITE_BUFFER 0xFA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #define UFSHPB_WRITE_BUFFER_INACT_SINGLE_ID 0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #define UFSHPB_WRITE_BUFFER_PREFETCH_ID 0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #define UFSHPB_WRITE_BUFFER_INACT_ALL_ID 0x03
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #define HPB_WRITE_BUFFER_CMD_LENGTH 10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #define MAX_HPB_READ_ID 0x7F
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #define HPB_READ_BUFFER_CMD_LENGTH 10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #define LU_ENABLED_HPB_FUNC 0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #define HPB_RESET_REQ_RETRIES 10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #define HPB_MAP_REQ_RETRIES 5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) #define HPB_REQUEUE_TIME_MS 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) #define HPB_SUPPORT_VERSION 0x200
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) #define HPB_SUPPORT_LEGACY_VERSION 0x100
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) enum UFSHPB_MODE {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) HPB_HOST_CONTROL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) HPB_DEVICE_CONTROL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) enum UFSHPB_STATE {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) HPB_INIT = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) HPB_PRESENT = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) HPB_SUSPEND,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) HPB_FAILED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) HPB_RESET,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) enum HPB_RGN_STATE {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) HPB_RGN_INACTIVE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) HPB_RGN_ACTIVE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) /* pinned regions are always active */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) HPB_RGN_PINNED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) enum HPB_SRGN_STATE {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) HPB_SRGN_UNUSED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) HPB_SRGN_INVALID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) HPB_SRGN_VALID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) HPB_SRGN_ISSUED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) * struct ufshpb_lu_info - UFSHPB logical unit related info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) * @num_blocks: the number of logical block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) * @pinned_start: the start region number of pinned region
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) * @num_pinned: the number of pinned regions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) * @max_active_rgns: maximum number of active regions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) struct ufshpb_lu_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) int num_blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) int pinned_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) int num_pinned;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) int max_active_rgns;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) struct ufshpb_map_ctx {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) struct page **m_page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) unsigned long *ppn_dirty;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) struct ufshpb_subregion {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) struct ufshpb_map_ctx *mctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) enum HPB_SRGN_STATE srgn_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) int rgn_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) int srgn_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) bool is_last;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) /* subregion reads - for host mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) unsigned int reads;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) /* below information is used by rsp_list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) struct list_head list_act_srgn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) struct ufshpb_region {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) struct ufshpb_lu *hpb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) struct ufshpb_subregion *srgn_tbl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) enum HPB_RGN_STATE rgn_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) int rgn_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) int srgn_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) /* below information is used by rsp_list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) struct list_head list_inact_rgn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) /* below information is used by lru */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) struct list_head list_lru_rgn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) unsigned long rgn_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) #define RGN_FLAG_DIRTY 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) #define RGN_FLAG_UPDATE 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) /* region reads - for host mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) spinlock_t rgn_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) unsigned int reads;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) /* region "cold" timer - for host mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) ktime_t read_timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) unsigned int read_timeout_expiries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) struct list_head list_expired_rgn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) #define for_each_sub_region(rgn, i, srgn) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) for ((i) = 0; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) ((i) < (rgn)->srgn_cnt) && ((srgn) = &(rgn)->srgn_tbl[i]); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) (i)++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) * struct ufshpb_req - HPB related request structure (write/read buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) * @req: block layer request structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) * @bio: bio for this request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) * @hpb: ufshpb_lu structure that related to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) * @list_req: ufshpb_req mempool list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) * @sense: store its sense data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) * @mctx: L2P map information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) * @rgn_idx: target region index
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) * @srgn_idx: target sub-region index
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) * @lun: target logical unit number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) * @m_page: L2P map information data for pre-request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) * @len: length of host-side cached L2P map in m_page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) * @lpn: start LPN of L2P map in m_page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) struct ufshpb_req {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) struct request *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) struct bio *bio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) struct ufshpb_lu *hpb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) struct list_head list_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) struct ufshpb_map_ctx *mctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) unsigned int rgn_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) unsigned int srgn_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) unsigned int lun;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) } rb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) struct page *m_page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) unsigned int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) unsigned long lpn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) } wb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) struct victim_select_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) struct list_head lh_lru_rgn; /* LRU list of regions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) int max_lru_active_cnt; /* supported hpb #region - pinned #region */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) atomic_t active_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) * ufshpb_params - ufs hpb parameters
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) * @requeue_timeout_ms - requeue threshold of wb command (0x2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) * @activation_thld - min reads [IOs] to activate/update a region
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) * @normalization_factor - shift right the region's reads
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) * @eviction_thld_enter - min reads [IOs] for the entering region in eviction
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) * @eviction_thld_exit - max reads [IOs] for the exiting region in eviction
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) * @read_timeout_ms - timeout [ms] from the last read IO to the region
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) * @read_timeout_expiries - amount of allowable timeout expireis
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) * @timeout_polling_interval_ms - frequency in which timeouts are checked
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) * @inflight_map_req - number of inflight map requests
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) struct ufshpb_params {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) unsigned int requeue_timeout_ms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) unsigned int activation_thld;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) unsigned int normalization_factor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) unsigned int eviction_thld_enter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) unsigned int eviction_thld_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) unsigned int read_timeout_ms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) unsigned int read_timeout_expiries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) unsigned int timeout_polling_interval_ms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) unsigned int inflight_map_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) struct ufshpb_stats {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) u64 hit_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) u64 miss_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) u64 rb_noti_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) u64 rb_active_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) u64 rb_inactive_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) u64 map_req_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) u64 pre_req_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) u64 umap_req_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) struct ufshpb_lu {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) int lun;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) struct scsi_device *sdev_ufs_lu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) spinlock_t rgn_state_lock; /* for protect rgn/srgn state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) struct ufshpb_region *rgn_tbl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) atomic_t hpb_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) spinlock_t rsp_list_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) struct list_head lh_act_srgn; /* hold rsp_list_lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) struct list_head lh_inact_rgn; /* hold rsp_list_lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) /* pre request information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) struct ufshpb_req *pre_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) int num_inflight_pre_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) int throttle_pre_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) int num_inflight_map_req; /* hold param_lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) spinlock_t param_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) struct list_head lh_pre_req_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) int cur_read_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) int pre_req_min_tr_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) int pre_req_max_tr_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) /* cached L2P map management worker */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) struct work_struct map_work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) /* for selecting victim */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) struct victim_select_info lru_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) struct work_struct ufshpb_normalization_work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) struct delayed_work ufshpb_read_to_work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) unsigned long work_data_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) #define TIMEOUT_WORK_RUNNING 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) /* pinned region information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) u32 lu_pinned_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) u32 lu_pinned_end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) /* HPB related configuration */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) u32 rgns_per_lu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) u32 srgns_per_lu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) u32 last_srgn_entries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) int srgns_per_rgn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) u32 srgn_mem_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) u32 entries_per_rgn_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) u32 entries_per_rgn_shift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) u32 entries_per_srgn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) u32 entries_per_srgn_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) u32 entries_per_srgn_shift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) u32 pages_per_srgn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) bool is_hcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) struct ufshpb_stats stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) struct ufshpb_params params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) struct kmem_cache *map_req_cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) struct kmem_cache *m_page_cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) struct list_head list_hpb_lu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) struct ufs_hba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) struct ufshcd_lrb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) #ifndef CONFIG_SCSI_UFS_HPB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) static int ufshpb_prep(struct ufs_hba *hba, struct ufshcd_lrb *lrbp) { return 0; }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) static void ufshpb_rsp_upiu(struct ufs_hba *hba, struct ufshcd_lrb *lrbp) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) static void ufshpb_resume(struct ufs_hba *hba) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) static void ufshpb_suspend(struct ufs_hba *hba) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) static void ufshpb_reset(struct ufs_hba *hba) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) static void ufshpb_reset_host(struct ufs_hba *hba) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) static void ufshpb_init(struct ufs_hba *hba) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) static void ufshpb_init_hpb_lu(struct ufs_hba *hba, struct scsi_device *sdev) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) static void ufshpb_destroy_lu(struct ufs_hba *hba, struct scsi_device *sdev) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) static void ufshpb_remove(struct ufs_hba *hba) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) static bool ufshpb_is_allowed(struct ufs_hba *hba) { return false; }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) static void ufshpb_get_geo_info(struct ufs_hba *hba, u8 *geo_buf) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) static void ufshpb_get_dev_info(struct ufs_hba *hba, u8 *desc_buf) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) static bool ufshpb_is_legacy(struct ufs_hba *hba) { return false; }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) int ufshpb_prep(struct ufs_hba *hba, struct ufshcd_lrb *lrbp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) void ufshpb_rsp_upiu(struct ufs_hba *hba, struct ufshcd_lrb *lrbp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) void ufshpb_resume(struct ufs_hba *hba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) void ufshpb_suspend(struct ufs_hba *hba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) void ufshpb_reset(struct ufs_hba *hba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) void ufshpb_reset_host(struct ufs_hba *hba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) void ufshpb_init(struct ufs_hba *hba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) void ufshpb_init_hpb_lu(struct ufs_hba *hba, struct scsi_device *sdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) void ufshpb_destroy_lu(struct ufs_hba *hba, struct scsi_device *sdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) void ufshpb_remove(struct ufs_hba *hba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) bool ufshpb_is_allowed(struct ufs_hba *hba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) void ufshpb_get_geo_info(struct ufs_hba *hba, u8 *geo_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) void ufshpb_get_dev_info(struct ufs_hba *hba, u8 *desc_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) bool ufshpb_is_legacy(struct ufs_hba *hba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) extern struct attribute_group ufs_sysfs_hpb_stat_group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) extern struct attribute_group ufs_sysfs_hpb_param_group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) #endif /* End of Header */