/* SPDX-License-Identifier: GPL-2.0-or-later */1/*2* Universal Flash Storage Host controller driver3* Copyright (C) 2011-2013 Samsung India Software Operations4* Copyright (c) 2013-2016, The Linux Foundation. All rights reserved.5*6* Authors:7* Santosh Yaraganavi <[email protected]>8* Vinayak Holikatti <[email protected]>9*/1011#ifndef _UFSHCD_H12#define _UFSHCD_H1314#include <linux/bitfield.h>15#include <linux/blk-crypto-profile.h>16#include <linux/blk-mq.h>17#include <linux/devfreq.h>18#include <linux/fault-inject.h>19#include <linux/debugfs.h>20#include <linux/msi.h>21#include <linux/pm_runtime.h>22#include <linux/dma-direction.h>23#include <scsi/scsi_device.h>24#include <scsi/scsi_host.h>25#include <ufs/unipro.h>26#include <ufs/ufs.h>27#include <ufs/ufs_quirks.h>28#include <ufs/ufshci.h>2930#define UFSHCD "ufshcd"3132struct scsi_device;33struct ufs_hba;3435enum dev_cmd_type {36DEV_CMD_TYPE_NOP = 0x0,37DEV_CMD_TYPE_QUERY = 0x1,38DEV_CMD_TYPE_RPMB = 0x2,39};4041enum ufs_event_type {42/* uic specific errors */43UFS_EVT_PA_ERR = 0,44UFS_EVT_DL_ERR,45UFS_EVT_NL_ERR,46UFS_EVT_TL_ERR,47UFS_EVT_DME_ERR,4849/* fatal errors */50UFS_EVT_AUTO_HIBERN8_ERR,51UFS_EVT_FATAL_ERR,52UFS_EVT_LINK_STARTUP_FAIL,53UFS_EVT_RESUME_ERR,54UFS_EVT_SUSPEND_ERR,55UFS_EVT_WL_SUSP_ERR,56UFS_EVT_WL_RES_ERR,5758/* abnormal events */59UFS_EVT_DEV_RESET,60UFS_EVT_HOST_RESET,61UFS_EVT_ABORT,6263UFS_EVT_CNT,64};6566/**67* struct uic_command - UIC command structure68* @command: UIC command69* @argument1: UIC command argument 170* @argument2: UIC command argument 271* @argument3: UIC command argument 372* @cmd_active: Indicate if UIC command is outstanding73* @done: UIC command completion74*/75struct uic_command {76const u32 command;77const u32 argument1;78u32 argument2;79u32 argument3;80bool cmd_active;81struct completion done;82};8384/* Used to differentiate the power management options */85enum ufs_pm_op {86UFS_RUNTIME_PM,87UFS_SYSTEM_PM,88UFS_SHUTDOWN_PM,89};9091/* Host <-> Device UniPro Link state */92enum uic_link_state {93UIC_LINK_OFF_STATE = 0, /* Link powered down or disabled */94UIC_LINK_ACTIVE_STATE = 1, /* Link is in Fast/Slow/Sleep state */95UIC_LINK_HIBERN8_STATE = 2, /* Link is in Hibernate state */96UIC_LINK_BROKEN_STATE = 3, /* Link is in broken state */97};9899#define ufshcd_is_link_off(hba) ((hba)->uic_link_state == UIC_LINK_OFF_STATE)100#define ufshcd_is_link_active(hba) ((hba)->uic_link_state == \101UIC_LINK_ACTIVE_STATE)102#define ufshcd_is_link_hibern8(hba) ((hba)->uic_link_state == \103UIC_LINK_HIBERN8_STATE)104#define ufshcd_is_link_broken(hba) ((hba)->uic_link_state == \105UIC_LINK_BROKEN_STATE)106#define ufshcd_set_link_off(hba) ((hba)->uic_link_state = UIC_LINK_OFF_STATE)107#define ufshcd_set_link_active(hba) ((hba)->uic_link_state = \108UIC_LINK_ACTIVE_STATE)109#define ufshcd_set_link_hibern8(hba) ((hba)->uic_link_state = \110UIC_LINK_HIBERN8_STATE)111#define ufshcd_set_link_broken(hba) ((hba)->uic_link_state = \112UIC_LINK_BROKEN_STATE)113114#define ufshcd_set_ufs_dev_active(h) \115((h)->curr_dev_pwr_mode = UFS_ACTIVE_PWR_MODE)116#define ufshcd_set_ufs_dev_sleep(h) \117((h)->curr_dev_pwr_mode = UFS_SLEEP_PWR_MODE)118#define ufshcd_set_ufs_dev_poweroff(h) \119((h)->curr_dev_pwr_mode = UFS_POWERDOWN_PWR_MODE)120#define ufshcd_set_ufs_dev_deepsleep(h) \121((h)->curr_dev_pwr_mode = UFS_DEEPSLEEP_PWR_MODE)122#define ufshcd_is_ufs_dev_active(h) \123((h)->curr_dev_pwr_mode == UFS_ACTIVE_PWR_MODE)124#define ufshcd_is_ufs_dev_sleep(h) \125((h)->curr_dev_pwr_mode == UFS_SLEEP_PWR_MODE)126#define ufshcd_is_ufs_dev_poweroff(h) \127((h)->curr_dev_pwr_mode == UFS_POWERDOWN_PWR_MODE)128#define ufshcd_is_ufs_dev_deepsleep(h) \129((h)->curr_dev_pwr_mode == UFS_DEEPSLEEP_PWR_MODE)130131/*132* UFS Power management levels.133* Each level is in increasing order of power savings, except DeepSleep134* which is lower than PowerDown with power on but not PowerDown with135* power off.136*/137enum ufs_pm_level {138UFS_PM_LVL_0,139UFS_PM_LVL_1,140UFS_PM_LVL_2,141UFS_PM_LVL_3,142UFS_PM_LVL_4,143UFS_PM_LVL_5,144UFS_PM_LVL_6,145UFS_PM_LVL_MAX146};147148struct ufs_pm_lvl_states {149enum ufs_dev_pwr_mode dev_state;150enum uic_link_state link_state;151};152153/**154* struct ufshcd_lrb - local reference block155* @utr_descriptor_ptr: UTRD address of the command156* @ucd_req_ptr: UCD address of the command157* @ucd_rsp_ptr: Response UPIU address for this command158* @ucd_prdt_ptr: PRDT address of the command159* @utrd_dma_addr: UTRD dma address for debug160* @ucd_prdt_dma_addr: PRDT dma address for debug161* @ucd_rsp_dma_addr: UPIU response dma address for debug162* @ucd_req_dma_addr: UPIU request dma address for debug163* @scsi_status: SCSI status of the command164* @command_type: SCSI, UFS, Query.165* @task_tag: Task tag of the command166* @lun: LUN of the command167* @intr_cmd: Interrupt command (doesn't participate in interrupt aggregation)168* @req_abort_skip: skip request abort task flag169* @issue_time_stamp: time stamp for debug purposes (CLOCK_MONOTONIC)170* @issue_time_stamp_local_clock: time stamp for debug purposes (local_clock)171* @compl_time_stamp: time stamp for statistics (CLOCK_MONOTONIC)172* @compl_time_stamp_local_clock: time stamp for debug purposes (local_clock)173* @crypto_key_slot: the key slot to use for inline crypto (-1 if none)174* @data_unit_num: the data unit number for the first block for inline crypto175*/176struct ufshcd_lrb {177struct utp_transfer_req_desc *utr_descriptor_ptr;178struct utp_upiu_req *ucd_req_ptr;179struct utp_upiu_rsp *ucd_rsp_ptr;180struct ufshcd_sg_entry *ucd_prdt_ptr;181182dma_addr_t utrd_dma_addr;183dma_addr_t ucd_req_dma_addr;184dma_addr_t ucd_rsp_dma_addr;185dma_addr_t ucd_prdt_dma_addr;186187int scsi_status;188189int command_type;190u8 lun; /* UPIU LUN id field is only 8-bit wide */191bool intr_cmd;192bool req_abort_skip;193ktime_t issue_time_stamp;194u64 issue_time_stamp_local_clock;195ktime_t compl_time_stamp;196u64 compl_time_stamp_local_clock;197#ifdef CONFIG_SCSI_UFS_CRYPTO198int crypto_key_slot;199u64 data_unit_num;200#endif201};202203/**204* struct ufs_query_req - parameters for building a query request205* @query_func: UPIU header query function206* @upiu_req: the query request data207*/208struct ufs_query_req {209u8 query_func;210struct utp_upiu_query upiu_req;211};212213/**214* struct ufs_query_resp - UPIU QUERY215* @response: device response code216* @upiu_res: query response data217*/218struct ufs_query_res {219struct utp_upiu_query upiu_res;220};221222/**223* struct ufs_query - holds relevant data structures for query request224* @request: request upiu and function225* @descriptor: buffer for sending/receiving descriptor226* @response: response upiu and response227*/228struct ufs_query {229struct ufs_query_req request;230u8 *descriptor;231struct ufs_query_res response;232};233234/**235* struct ufs_dev_cmd - all assosiated fields with device management commands236* @type: device management command type - Query, NOP OUT237* @lock: lock to allow one command at a time238* @query: Device management query information239*/240struct ufs_dev_cmd {241enum dev_cmd_type type;242struct mutex lock;243struct ufs_query query;244};245246/**247* struct ufs_clk_info - UFS clock related info248* @list: list headed by hba->clk_list_head249* @clk: clock node250* @name: clock name251* @max_freq: maximum frequency supported by the clock252* @min_freq: min frequency that can be used for clock scaling253* @curr_freq: indicates the current frequency that it is set to254* @keep_link_active: indicates that the clk should not be disabled if255* link is active256* @enabled: variable to check against multiple enable/disable257*/258struct ufs_clk_info {259struct list_head list;260struct clk *clk;261const char *name;262u32 max_freq;263u32 min_freq;264u32 curr_freq;265bool keep_link_active;266bool enabled;267};268269enum ufs_notify_change_status {270PRE_CHANGE,271POST_CHANGE,272};273274struct ufs_pa_layer_attr {275u32 gear_rx;276u32 gear_tx;277u32 lane_rx;278u32 lane_tx;279u32 pwr_rx;280u32 pwr_tx;281u32 hs_rate;282};283284struct ufs_pwr_mode_info {285bool is_valid;286struct ufs_pa_layer_attr info;287};288289/**290* struct ufs_hba_variant_ops - variant specific callbacks291* @name: variant name292* @max_num_rtt: maximum RTT supported by the host293* @init: called when the driver is initialized294* @exit: called to cleanup everything done in init295* @set_dma_mask: For setting another DMA mask than indicated by the 64AS296* capability bit.297* @get_ufs_hci_version: called to get UFS HCI version298* @clk_scale_notify: notifies that clks are scaled up/down299* @setup_clocks: called before touching any of the controller registers300* @hce_enable_notify: called before and after HCE enable bit is set to allow301* variant specific Uni-Pro initialization.302* @link_startup_notify: called before and after Link startup is carried out303* to allow variant specific Uni-Pro initialization.304* @pwr_change_notify: called before and after a power mode change305* is carried out to allow vendor spesific capabilities306* to be set. PRE_CHANGE can modify final_params based307* on desired_pwr_mode, but POST_CHANGE must not alter308* the final_params parameter309* @setup_xfer_req: called before any transfer request is issued310* to set some things311* @setup_task_mgmt: called before any task management request is issued312* to set some things313* @hibern8_notify: called around hibern8 enter/exit314* @apply_dev_quirks: called to apply device specific quirks315* @fixup_dev_quirks: called to modify device specific quirks316* @suspend: called during host controller PM callback317* @resume: called during host controller PM callback318* @dbg_register_dump: used to dump controller debug information319* @phy_initialization: used to initialize phys320* @device_reset: called to issue a reset pulse on the UFS device321* @config_scaling_param: called to configure clock scaling parameters322* @fill_crypto_prdt: initialize crypto-related fields in the PRDT323* @event_notify: called to notify important events324* @mcq_config_resource: called to configure MCQ platform resources325* @get_hba_mac: reports maximum number of outstanding commands supported by326* the controller. Should be implemented for UFSHCI 4.0 or later327* controllers that are not compliant with the UFSHCI 4.0 specification.328* @op_runtime_config: called to config Operation and runtime regs Pointers329* @get_outstanding_cqs: called to get outstanding completion queues330* @config_esi: called to config Event Specific Interrupt331* @config_scsi_dev: called to configure SCSI device parameters332* @freq_to_gear_speed: called to map clock frequency to the max supported gear speed333*/334struct ufs_hba_variant_ops {335const char *name;336int max_num_rtt;337int (*init)(struct ufs_hba *);338void (*exit)(struct ufs_hba *);339u32 (*get_ufs_hci_version)(struct ufs_hba *);340int (*set_dma_mask)(struct ufs_hba *);341int (*clk_scale_notify)(struct ufs_hba *, bool, unsigned long,342enum ufs_notify_change_status);343int (*setup_clocks)(struct ufs_hba *, bool,344enum ufs_notify_change_status);345int (*hce_enable_notify)(struct ufs_hba *,346enum ufs_notify_change_status);347int (*link_startup_notify)(struct ufs_hba *,348enum ufs_notify_change_status);349int (*pwr_change_notify)(struct ufs_hba *,350enum ufs_notify_change_status status,351const struct ufs_pa_layer_attr *desired_pwr_mode,352struct ufs_pa_layer_attr *final_params);353void (*setup_xfer_req)(struct ufs_hba *hba, int tag,354bool is_scsi_cmd);355void (*setup_task_mgmt)(struct ufs_hba *, int, u8);356void (*hibern8_notify)(struct ufs_hba *, enum uic_cmd_dme,357enum ufs_notify_change_status);358int (*apply_dev_quirks)(struct ufs_hba *hba);359void (*fixup_dev_quirks)(struct ufs_hba *hba);360int (*suspend)(struct ufs_hba *, enum ufs_pm_op,361enum ufs_notify_change_status);362int (*resume)(struct ufs_hba *, enum ufs_pm_op);363void (*dbg_register_dump)(struct ufs_hba *hba);364int (*phy_initialization)(struct ufs_hba *);365int (*device_reset)(struct ufs_hba *hba);366void (*config_scaling_param)(struct ufs_hba *hba,367struct devfreq_dev_profile *profile,368struct devfreq_simple_ondemand_data *data);369int (*fill_crypto_prdt)(struct ufs_hba *hba,370const struct bio_crypt_ctx *crypt_ctx,371void *prdt, unsigned int num_segments);372void (*event_notify)(struct ufs_hba *hba,373enum ufs_event_type evt, void *data);374int (*mcq_config_resource)(struct ufs_hba *hba);375int (*get_hba_mac)(struct ufs_hba *hba);376int (*op_runtime_config)(struct ufs_hba *hba);377int (*get_outstanding_cqs)(struct ufs_hba *hba,378unsigned long *ocqs);379int (*config_esi)(struct ufs_hba *hba);380void (*config_scsi_dev)(struct scsi_device *sdev);381u32 (*freq_to_gear_speed)(struct ufs_hba *hba, unsigned long freq);382};383384/* clock gating state */385enum clk_gating_state {386CLKS_OFF,387CLKS_ON,388REQ_CLKS_OFF,389REQ_CLKS_ON,390};391392/**393* struct ufs_clk_gating - UFS clock gating related info394* @gate_work: worker to turn off clocks after some delay as specified in395* delay_ms396* @ungate_work: worker to turn on clocks that will be used in case of397* interrupt context398* @clk_gating_workq: workqueue for clock gating work.399* @lock: serialize access to some struct ufs_clk_gating members. An outer lock400* relative to the host lock401* @state: the current clocks state402* @delay_ms: gating delay in ms403* @is_suspended: clk gating is suspended when set to 1 which can be used404* during suspend/resume405* @delay_attr: sysfs attribute to control delay_attr406* @enable_attr: sysfs attribute to enable/disable clock gating407* @is_enabled: Indicates the current status of clock gating408* @is_initialized: Indicates whether clock gating is initialized or not409* @active_reqs: number of requests that are pending and should be waited for410* completion before gating clocks.411*/412struct ufs_clk_gating {413struct delayed_work gate_work;414struct work_struct ungate_work;415struct workqueue_struct *clk_gating_workq;416417spinlock_t lock;418419enum clk_gating_state state;420unsigned long delay_ms;421bool is_suspended;422struct device_attribute delay_attr;423struct device_attribute enable_attr;424bool is_enabled;425bool is_initialized;426int active_reqs;427};428429/**430* struct ufs_clk_scaling - UFS clock scaling related data431* @workq: workqueue to schedule devfreq suspend/resume work432* @suspend_work: worker to suspend devfreq433* @resume_work: worker to resume devfreq434* @lock: serialize access to some struct ufs_clk_scaling members435* @active_reqs: number of requests that are pending. If this is zero when436* devfreq ->target() function is called then schedule "suspend_work" to437* suspend devfreq.438* @tot_busy_t: Total busy time in current polling window439* @window_start_t: Start time (in jiffies) of the current polling window440* @busy_start_t: Start time of current busy period441* @enable_attr: sysfs attribute to enable/disable clock scaling442* @saved_pwr_info: UFS power mode may also be changed during scaling and this443* one keeps track of previous power mode.444* @target_freq: frequency requested by devfreq framework445* @min_gear: lowest HS gear to scale down to446* @wb_gear: enable Write Booster when HS gear scales above or equal to it, else447* disable Write Booster448* @is_enabled: tracks if scaling is currently enabled or not, controlled by449* clkscale_enable sysfs node450* @is_allowed: tracks if scaling is currently allowed or not, used to block451* clock scaling which is not invoked from devfreq governor452* @is_initialized: Indicates whether clock scaling is initialized or not453* @is_busy_started: tracks if busy period has started or not454* @is_suspended: tracks if devfreq is suspended or not455*/456struct ufs_clk_scaling {457struct workqueue_struct *workq;458struct work_struct suspend_work;459struct work_struct resume_work;460461spinlock_t lock;462463int active_reqs;464unsigned long tot_busy_t;465ktime_t window_start_t;466ktime_t busy_start_t;467struct device_attribute enable_attr;468struct ufs_pa_layer_attr saved_pwr_info;469unsigned long target_freq;470u32 min_gear;471u32 wb_gear;472bool is_enabled;473bool is_allowed;474bool is_initialized;475bool is_busy_started;476bool is_suspended;477bool suspend_on_no_request;478};479480#define UFS_EVENT_HIST_LENGTH 8481/**482* struct ufs_event_hist - keeps history of errors483* @pos: index to indicate cyclic buffer position484* @val: cyclic buffer for registers value485* @tstamp: cyclic buffer for time stamp486* @cnt: error counter487*/488struct ufs_event_hist {489int pos;490u32 val[UFS_EVENT_HIST_LENGTH];491u64 tstamp[UFS_EVENT_HIST_LENGTH];492unsigned long long cnt;493};494495/**496* struct ufs_stats - keeps usage/err statistics497* @hibern8_exit_cnt: Counter to keep track of number of exits,498* reset this after link-startup.499* @last_hibern8_exit_tstamp: Set time after the hibern8 exit.500* Clear after the first successful command completion.501* @event: array with event history.502*/503struct ufs_stats {504u32 hibern8_exit_cnt;505u64 last_hibern8_exit_tstamp;506struct ufs_event_hist event[UFS_EVT_CNT];507};508509/**510* enum ufshcd_state - UFS host controller state511* @UFSHCD_STATE_RESET: Link is not operational. Postpone SCSI command512* processing.513* @UFSHCD_STATE_OPERATIONAL: The host controller is operational and can process514* SCSI commands.515* @UFSHCD_STATE_EH_SCHEDULED_NON_FATAL: The error handler has been scheduled.516* SCSI commands may be submitted to the controller.517* @UFSHCD_STATE_EH_SCHEDULED_FATAL: The error handler has been scheduled. Fail518* newly submitted SCSI commands with error code DID_BAD_TARGET.519* @UFSHCD_STATE_ERROR: An unrecoverable error occurred, e.g. link recovery520* failed. Fail all SCSI commands with error code DID_ERROR.521*/522enum ufshcd_state {523UFSHCD_STATE_RESET,524UFSHCD_STATE_OPERATIONAL,525UFSHCD_STATE_EH_SCHEDULED_NON_FATAL,526UFSHCD_STATE_EH_SCHEDULED_FATAL,527UFSHCD_STATE_ERROR,528};529530enum ufshcd_quirks {531/* Interrupt aggregation support is broken */532UFSHCD_QUIRK_BROKEN_INTR_AGGR = 1 << 0,533534/*535* delay before each dme command is required as the unipro536* layer has shown instabilities537*/538UFSHCD_QUIRK_DELAY_BEFORE_DME_CMDS = 1 << 1,539540/*541* If UFS host controller is having issue in processing LCC (Line542* Control Command) coming from device then enable this quirk.543* When this quirk is enabled, host controller driver should disable544* the LCC transmission on UFS device (by clearing TX_LCC_ENABLE545* attribute of device to 0).546*/547UFSHCD_QUIRK_BROKEN_LCC = 1 << 2,548549/*550* The attribute PA_RXHSUNTERMCAP specifies whether or not the551* inbound Link supports unterminated line in HS mode. Setting this552* attribute to 1 fixes moving to HS gear.553*/554UFSHCD_QUIRK_BROKEN_PA_RXHSUNTERMCAP = 1 << 3,555556/*557* This quirk needs to be enabled if the host controller only allows558* accessing the peer dme attributes in AUTO mode (FAST AUTO or559* SLOW AUTO).560*/561UFSHCD_QUIRK_DME_PEER_ACCESS_AUTO_MODE = 1 << 4,562563/*564* This quirk needs to be enabled if the host controller doesn't565* advertise the correct version in UFS_VER register. If this quirk566* is enabled, standard UFS host driver will call the vendor specific567* ops (get_ufs_hci_version) to get the correct version.568*/569UFSHCD_QUIRK_BROKEN_UFS_HCI_VERSION = 1 << 5,570571/*572* Clear handling for transfer/task request list is just opposite.573*/574UFSHCI_QUIRK_BROKEN_REQ_LIST_CLR = 1 << 6,575576/*577* This quirk needs to be enabled if host controller doesn't allow578* that the interrupt aggregation timer and counter are reset by s/w.579*/580UFSHCI_QUIRK_SKIP_RESET_INTR_AGGR = 1 << 7,581582/*583* This quirks needs to be enabled if host controller cannot be584* enabled via HCE register.585*/586UFSHCI_QUIRK_BROKEN_HCE = 1 << 8,587588/*589* This quirk needs to be enabled if the host controller regards590* resolution of the values of PRDTO and PRDTL in UTRD as byte.591*/592UFSHCD_QUIRK_PRDT_BYTE_GRAN = 1 << 9,593594/*595* This quirk needs to be enabled if the host controller reports596* OCS FATAL ERROR with device error through sense data597*/598UFSHCD_QUIRK_BROKEN_OCS_FATAL_ERROR = 1 << 10,599600/*601* This quirk needs to be enabled if the host controller has602* auto-hibernate capability but it doesn't work.603*/604UFSHCD_QUIRK_BROKEN_AUTO_HIBERN8 = 1 << 11,605606/*607* This quirk needs to disable manual flush for write booster608*/609UFSHCI_QUIRK_SKIP_MANUAL_WB_FLUSH_CTRL = 1 << 12,610611/*612* This quirk needs to disable unipro timeout values613* before power mode change614*/615UFSHCD_QUIRK_SKIP_DEF_UNIPRO_TIMEOUT_SETTING = 1 << 13,616617/*618* This quirk needs to be enabled if the host controller does not619* support UIC command620*/621UFSHCD_QUIRK_BROKEN_UIC_CMD = 1 << 15,622623/*624* This quirk needs to be enabled if the host controller cannot625* support physical host configuration.626*/627UFSHCD_QUIRK_SKIP_PH_CONFIGURATION = 1 << 16,628629/*630* This quirk needs to be enabled if the host controller has631* auto-hibernate capability but it's FASTAUTO only.632*/633UFSHCD_QUIRK_HIBERN_FASTAUTO = 1 << 18,634635/*636* This quirk needs to be enabled if the host controller needs637* to reinit the device after switching to maximum gear.638*/639UFSHCD_QUIRK_REINIT_AFTER_MAX_GEAR_SWITCH = 1 << 19,640641/*642* Some host raises interrupt (per queue) in addition to643* CQES (traditional) when ESI is disabled.644* Enable this quirk will disable CQES and use per queue interrupt.645*/646UFSHCD_QUIRK_MCQ_BROKEN_INTR = 1 << 20,647648/*649* Some host does not implement SQ Run Time Command (SQRTC) register650* thus need this quirk to skip related flow.651*/652UFSHCD_QUIRK_MCQ_BROKEN_RTC = 1 << 21,653654/*655* This quirk needs to be enabled if the host controller supports inline656* encryption but it needs to initialize the crypto capabilities in a657* nonstandard way and/or needs to override blk_crypto_ll_ops. If658* enabled, the standard code won't initialize the blk_crypto_profile;659* ufs_hba_variant_ops::init() must do it instead.660*/661UFSHCD_QUIRK_CUSTOM_CRYPTO_PROFILE = 1 << 22,662663/*664* This quirk needs to be enabled if the host controller supports inline665* encryption but does not support the CRYPTO_GENERAL_ENABLE bit, i.e.666* host controller initialization fails if that bit is set.667*/668UFSHCD_QUIRK_BROKEN_CRYPTO_ENABLE = 1 << 23,669670/*671* This quirk needs to be enabled if the host controller driver copies672* cryptographic keys into the PRDT in order to send them to hardware,673* and therefore the PRDT should be zeroized after each request (as per674* the standard best practice for managing keys).675*/676UFSHCD_QUIRK_KEYS_IN_PRDT = 1 << 24,677678/*679* This quirk indicates that the controller reports the value 1 (not680* supported) in the Legacy Single DoorBell Support (LSDBS) bit of the681* Controller Capabilities register although it supports the legacy682* single doorbell mode.683*/684UFSHCD_QUIRK_BROKEN_LSDBS_CAP = 1 << 25,685686/*687* This quirk indicates that DME_LINKSTARTUP should not be issued a 2nd688* time (refer link_startup_again) after the 1st time was successful,689* because it causes link startup to become unreliable.690*/691UFSHCD_QUIRK_PERFORM_LINK_STARTUP_ONCE = 1 << 26,692};693694enum ufshcd_caps {695/* Allow dynamic clk gating */696UFSHCD_CAP_CLK_GATING = 1 << 0,697698/* Allow hiberb8 with clk gating */699UFSHCD_CAP_HIBERN8_WITH_CLK_GATING = 1 << 1,700701/* Allow dynamic clk scaling */702UFSHCD_CAP_CLK_SCALING = 1 << 2,703704/* Allow auto bkops to enabled during runtime suspend */705UFSHCD_CAP_AUTO_BKOPS_SUSPEND = 1 << 3,706707/*708* This capability allows host controller driver to use the UFS HCI's709* interrupt aggregation capability.710* CAUTION: Enabling this might reduce overall UFS throughput.711*/712UFSHCD_CAP_INTR_AGGR = 1 << 4,713714/*715* This capability allows the device auto-bkops to be always enabled716* except during suspend (both runtime and suspend).717* Enabling this capability means that device will always be allowed718* to do background operation when it's active but it might degrade719* the performance of ongoing read/write operations.720*/721UFSHCD_CAP_KEEP_AUTO_BKOPS_ENABLED_EXCEPT_SUSPEND = 1 << 5,722723/*724* This capability allows host controller driver to automatically725* enable runtime power management by itself instead of waiting726* for userspace to control the power management.727*/728UFSHCD_CAP_RPM_AUTOSUSPEND = 1 << 6,729730/*731* This capability allows the host controller driver to turn-on732* WriteBooster, if the underlying device supports it and is733* provisioned to be used. This would increase the write performance.734*/735UFSHCD_CAP_WB_EN = 1 << 7,736737/*738* This capability allows the host controller driver to use the739* inline crypto engine, if it is present740*/741UFSHCD_CAP_CRYPTO = 1 << 8,742743/*744* This capability allows the controller regulators to be put into745* lpm mode aggressively during clock gating.746* This would increase power savings.747*/748UFSHCD_CAP_AGGR_POWER_COLLAPSE = 1 << 9,749750/*751* This capability allows the host controller driver to use DeepSleep,752* if it is supported by the UFS device. The host controller driver must753* support device hardware reset via the hba->device_reset() callback,754* in order to exit DeepSleep state.755*/756UFSHCD_CAP_DEEPSLEEP = 1 << 10,757758/*759* This capability allows the host controller driver to use temperature760* notification if it is supported by the UFS device.761*/762UFSHCD_CAP_TEMP_NOTIF = 1 << 11,763764/*765* Enable WriteBooster when scaling up the clock and disable766* WriteBooster when scaling the clock down.767*/768UFSHCD_CAP_WB_WITH_CLK_SCALING = 1 << 12,769};770771struct ufs_hba_variant_params {772struct devfreq_dev_profile devfreq_profile;773struct devfreq_simple_ondemand_data ondemand_data;774u16 hba_enable_delay_us;775u32 wb_flush_threshold;776};777778struct ufs_hba_monitor {779unsigned long chunk_size;780781unsigned long nr_sec_rw[2];782ktime_t total_busy[2];783784unsigned long nr_req[2];785/* latencies*/786ktime_t lat_sum[2];787ktime_t lat_max[2];788ktime_t lat_min[2];789790u32 nr_queued[2];791ktime_t busy_start_ts[2];792793ktime_t enabled_ts;794bool enabled;795};796797/**798* struct ufshcd_mcq_opr_info_t - Operation and Runtime registers799*800* @offset: Doorbell Address Offset801* @stride: Steps proportional to queue [0...31]802* @base: base address803*/804struct ufshcd_mcq_opr_info_t {805unsigned long offset;806unsigned long stride;807void __iomem *base;808};809810enum ufshcd_mcq_opr {811OPR_SQD,812OPR_SQIS,813OPR_CQD,814OPR_CQIS,815OPR_MAX,816};817818/**819* struct ufs_hba - per adapter private structure820* @mmio_base: UFSHCI base register address821* @ucdl_base_addr: UFS Command Descriptor base address822* @utrdl_base_addr: UTP Transfer Request Descriptor base address823* @utmrdl_base_addr: UTP Task Management Descriptor base address824* @ucdl_dma_addr: UFS Command Descriptor DMA address825* @utrdl_dma_addr: UTRDL DMA address826* @utmrdl_dma_addr: UTMRDL DMA address827* @host: Scsi_Host instance of the driver828* @dev: device handle829* @ufs_device_wlun: WLUN that controls the entire UFS device.830* @ufs_rpmb_wlun: RPMB WLUN SCSI device831* @hwmon_device: device instance registered with the hwmon core.832* @curr_dev_pwr_mode: active UFS device power mode.833* @uic_link_state: active state of the link to the UFS device.834* @rpm_lvl: desired UFS power management level during runtime PM.835* @spm_lvl: desired UFS power management level during system PM.836* @pm_op_in_progress: whether or not a PM operation is in progress.837* @ahit: value of Auto-Hibernate Idle Timer register.838* @outstanding_tasks: Bits representing outstanding task requests839* @outstanding_lock: Protects @outstanding_reqs.840* @outstanding_reqs: Bits representing outstanding transfer requests841* @capabilities: UFS Controller Capabilities842* @mcq_capabilities: UFS Multi Circular Queue capabilities843* @nutrs: Transfer Request Queue depth supported by controller844* @nortt - Max outstanding RTTs supported by controller845* @nutmrs: Task Management Queue depth supported by controller846* @ufs_version: UFS Version to which controller complies847* @vops: pointer to variant specific operations848* @vps: pointer to variant specific parameters849* @priv: pointer to variant specific private data850* @sg_entry_size: size of struct ufshcd_sg_entry (may include variant fields)851* @irq: Irq number of the controller852* @is_irq_enabled: whether or not the UFS controller interrupt is enabled.853* @dev_ref_clk_freq: reference clock frequency854* @quirks: bitmask with information about deviations from the UFSHCI standard.855* @dev_quirks: bitmask with information about deviations from the UFS standard.856* @tmf_tag_set: TMF tag set.857* @tmf_queue: Used to allocate TMF tags.858* @tmf_rqs: array with pointers to TMF requests while these are in progress.859* @active_uic_cmd: pointer to active UIC command.860* @uic_cmd_mutex: mutex used for serializing UIC command processing.861* @uic_async_done: completion used to wait for power mode or hibernation state862* changes.863* @ufshcd_state: UFSHCD state864* @eh_flags: Error handling flags865* @intr_mask: Interrupt Mask Bits866* @ee_ctrl_mask: Exception event control mask867* @ee_drv_mask: Exception event mask for driver868* @ee_usr_mask: Exception event mask for user (set via debugfs)869* @ee_ctrl_mutex: Used to serialize exception event information.870* @is_powered: flag to check if HBA is powered871* @shutting_down: flag to check if shutdown has been invoked872* @host_sem: semaphore used to serialize concurrent contexts873* @eh_wq: Workqueue that eh_work works on874* @eh_work: Worker to handle UFS errors that require s/w attention875* @eeh_work: Worker to handle exception events876* @errors: HBA errors877* @uic_error: UFS interconnect layer error status878* @saved_err: sticky error mask879* @saved_uic_err: sticky UIC error mask880* @ufs_stats: various error counters881* @force_reset: flag to force eh_work perform a full reset882* @force_pmc: flag to force a power mode change883* @silence_err_logs: flag to silence error logs884* @dev_cmd: ufs device management command information885* @last_dme_cmd_tstamp: time stamp of the last completed DME command886* @nop_out_timeout: NOP OUT timeout value887* @dev_info: information about the UFS device888* @auto_bkops_enabled: to track whether bkops is enabled in device889* @vreg_info: UFS device voltage regulator information890* @clk_list_head: UFS host controller clocks list node head891* @use_pm_opp: Indicates whether OPP based scaling is used or not892* @req_abort_count: number of times ufshcd_abort() has been called893* @lanes_per_direction: number of lanes per data direction between the UFS894* controller and the UFS device.895* @pwr_info: holds current power mode896* @max_pwr_info: keeps the device max valid pwm897* @clk_gating: information related to clock gating898* @caps: bitmask with information about UFS controller capabilities899* @devfreq: frequency scaling information owned by the devfreq core900* @clk_scaling: frequency scaling information owned by the UFS driver901* @system_suspending: system suspend has been started and system resume has902* not yet finished.903* @is_sys_suspended: UFS device has been suspended because of system suspend904* @urgent_bkops_lvl: keeps track of urgent bkops level for device905* @is_urgent_bkops_lvl_checked: keeps track if the urgent bkops level for906* device is known or not.907* @wb_mutex: used to serialize devfreq and sysfs write booster toggling908* @clk_scaling_lock: used to serialize device commands and clock scaling909* @desc_size: descriptor sizes reported by device910* @bsg_dev: struct device associated with the BSG queue911* @bsg_queue: BSG queue associated with the UFS controller912* @rpm_dev_flush_recheck_work: used to suspend from RPM (runtime power913* management) after the UFS device has finished a WriteBooster buffer914* flush or auto BKOP.915* @monitor: statistics about UFS commands916* @crypto_capabilities: Content of crypto capabilities register (0x100)917* @crypto_cap_array: Array of crypto capabilities918* @crypto_cfg_register: Start of the crypto cfg array919* @crypto_profile: the crypto profile of this hba (if applicable)920* @debugfs_root: UFS controller debugfs root directory921* @debugfs_ee_work: used to restore ee_ctrl_mask after a delay922* @debugfs_ee_rate_limit_ms: user configurable delay after which to restore923* ee_ctrl_mask924* @luns_avail: number of regular and well known LUNs supported by the UFS925* device926* @nr_hw_queues: number of hardware queues configured927* @nr_queues: number of Queues of different queue types928* @complete_put: whether or not to call ufshcd_rpm_put() from inside929* ufshcd_resume_complete()930* @mcq_sup: is mcq supported by UFSHC931* @mcq_enabled: is mcq ready to accept requests932* @mcq_esi_enabled: is mcq ESI configured933* @res: array of resource info of MCQ registers934* @mcq_base: Multi circular queue registers base address935* @uhq: array of supported hardware queues936* @mcq_opr: MCQ operation and runtime registers937* @ufs_rtc_update_work: A work for UFS RTC periodic update938* @pm_qos_req: PM QoS request handle939* @pm_qos_enabled: flag to check if pm qos is enabled940* @pm_qos_mutex: synchronizes PM QoS request and status updates941* @critical_health_count: count of critical health exceptions942* @dev_lvl_exception_count: count of device level exceptions since last reset943* @dev_lvl_exception_id: vendor specific information about the device level exception event.944* @rpmbs: list of OP-TEE RPMB devices (one per RPMB region)945*/946struct ufs_hba {947void __iomem *mmio_base;948949/* Virtual memory reference */950struct utp_transfer_cmd_desc *ucdl_base_addr;951struct utp_transfer_req_desc *utrdl_base_addr;952struct utp_task_req_desc *utmrdl_base_addr;953954/* DMA memory reference */955dma_addr_t ucdl_dma_addr;956dma_addr_t utrdl_dma_addr;957dma_addr_t utmrdl_dma_addr;958959struct Scsi_Host *host;960struct device *dev;961struct scsi_device *ufs_device_wlun;962struct scsi_device *ufs_rpmb_wlun;963964#ifdef CONFIG_SCSI_UFS_HWMON965struct device *hwmon_device;966#endif967968enum ufs_dev_pwr_mode curr_dev_pwr_mode;969enum uic_link_state uic_link_state;970/* Desired UFS power management level during runtime PM */971enum ufs_pm_level rpm_lvl;972/* Desired UFS power management level during system PM */973enum ufs_pm_level spm_lvl;974int pm_op_in_progress;975976/* Auto-Hibernate Idle Timer register value */977u32 ahit;978979unsigned long outstanding_tasks;980spinlock_t outstanding_lock;981unsigned long outstanding_reqs;982983u32 capabilities;984int nutrs;985int nortt;986u32 mcq_capabilities;987int nutmrs;988u32 ufs_version;989const struct ufs_hba_variant_ops *vops;990struct ufs_hba_variant_params *vps;991void *priv;992#ifdef CONFIG_SCSI_UFS_VARIABLE_SG_ENTRY_SIZE993size_t sg_entry_size;994#endif995unsigned int irq;996bool is_irq_enabled;997enum ufs_ref_clk_freq dev_ref_clk_freq;998999unsigned int quirks; /* Deviations from standard UFSHCI spec. */10001001/* Device deviations from standard UFS device spec. */1002unsigned int dev_quirks;10031004struct blk_mq_tag_set tmf_tag_set;1005struct request_queue *tmf_queue;1006struct request **tmf_rqs;10071008struct uic_command *active_uic_cmd;1009struct mutex uic_cmd_mutex;1010struct completion *uic_async_done;10111012enum ufshcd_state ufshcd_state;1013u32 eh_flags;1014u32 intr_mask;1015u16 ee_ctrl_mask;1016u16 ee_drv_mask;1017u16 ee_usr_mask;1018struct mutex ee_ctrl_mutex;1019bool is_powered;1020bool shutting_down;1021struct semaphore host_sem;10221023/* Work Queues */1024struct workqueue_struct *eh_wq;1025struct work_struct eh_work;1026struct work_struct eeh_work;10271028/* HBA Errors */1029u32 errors;1030u32 uic_error;1031u32 saved_err;1032u32 saved_uic_err;1033struct ufs_stats ufs_stats;1034bool force_reset;1035bool force_pmc;1036bool silence_err_logs;10371038/* Device management request data */1039struct ufs_dev_cmd dev_cmd;1040ktime_t last_dme_cmd_tstamp;1041int nop_out_timeout;10421043/* Keeps information of the UFS device connected to this host */1044struct ufs_dev_info dev_info;1045bool auto_bkops_enabled;1046struct ufs_vreg_info vreg_info;1047struct list_head clk_list_head;1048bool use_pm_opp;10491050/* Number of requests aborts */1051int req_abort_count;10521053/* Number of lanes available (1 or 2) for Rx/Tx */1054u32 lanes_per_direction;1055struct ufs_pa_layer_attr pwr_info;1056struct ufs_pwr_mode_info max_pwr_info;10571058struct ufs_clk_gating clk_gating;1059/* Control to enable/disable host capabilities */1060u32 caps;10611062struct devfreq *devfreq;1063struct ufs_clk_scaling clk_scaling;1064bool system_suspending;1065bool is_sys_suspended;10661067enum bkops_status urgent_bkops_lvl;1068bool is_urgent_bkops_lvl_checked;10691070struct mutex wb_mutex;1071struct rw_semaphore clk_scaling_lock;10721073struct device bsg_dev;1074struct request_queue *bsg_queue;1075struct delayed_work rpm_dev_flush_recheck_work;10761077struct ufs_hba_monitor monitor;10781079#ifdef CONFIG_SCSI_UFS_CRYPTO1080union ufs_crypto_capabilities crypto_capabilities;1081union ufs_crypto_cap_entry *crypto_cap_array;1082u32 crypto_cfg_register;1083struct blk_crypto_profile crypto_profile;1084#endif1085#ifdef CONFIG_DEBUG_FS1086struct dentry *debugfs_root;1087struct delayed_work debugfs_ee_work;1088u32 debugfs_ee_rate_limit_ms;1089#endif1090#ifdef CONFIG_SCSI_UFS_FAULT_INJECTION1091struct fault_attr trigger_eh_attr;1092struct fault_attr timeout_attr;1093#endif1094u32 luns_avail;1095unsigned int nr_hw_queues;1096unsigned int nr_queues[HCTX_MAX_TYPES];1097bool complete_put;1098bool scsi_host_added;1099bool mcq_sup;1100bool lsdb_sup;1101bool mcq_enabled;1102bool mcq_esi_enabled;1103void __iomem *mcq_base;1104struct ufs_hw_queue *uhq;1105struct ufshcd_mcq_opr_info_t mcq_opr[OPR_MAX];11061107struct delayed_work ufs_rtc_update_work;1108struct pm_qos_request pm_qos_req;1109bool pm_qos_enabled;1110/* synchronizes PM QoS request and status updates */1111struct mutex pm_qos_mutex;11121113int critical_health_count;1114atomic_t dev_lvl_exception_count;1115u64 dev_lvl_exception_id;1116u32 vcc_off_delay_us;1117struct list_head rpmbs;1118};11191120/**1121* struct ufs_hw_queue - per hardware queue structure1122* @mcq_sq_head: base address of submission queue head pointer1123* @mcq_sq_tail: base address of submission queue tail pointer1124* @mcq_cq_head: base address of completion queue head pointer1125* @mcq_cq_tail: base address of completion queue tail pointer1126* @sqe_base_addr: submission queue entry base address1127* @sqe_dma_addr: submission queue dma address1128* @cqe_base_addr: completion queue base address1129* @cqe_dma_addr: completion queue dma address1130* @max_entries: max number of slots in this hardware queue1131* @id: hardware queue ID1132* @sq_tp_slot: current slot to which SQ tail pointer is pointing1133* @sq_lock: serialize submission queue access1134* @cq_tail_slot: current slot to which CQ tail pointer is pointing1135* @cq_head_slot: current slot to which CQ head pointer is pointing1136* @cq_lock: Synchronize between multiple polling instances1137* @sq_mutex: prevent submission queue concurrent access1138*/1139struct ufs_hw_queue {1140void __iomem *mcq_sq_head;1141void __iomem *mcq_sq_tail;1142void __iomem *mcq_cq_head;1143void __iomem *mcq_cq_tail;11441145struct utp_transfer_req_desc *sqe_base_addr;1146dma_addr_t sqe_dma_addr;1147struct cq_entry *cqe_base_addr;1148dma_addr_t cqe_dma_addr;1149u32 max_entries;1150u32 id;1151u32 sq_tail_slot;1152spinlock_t sq_lock;1153u32 cq_tail_slot;1154u32 cq_head_slot;1155spinlock_t cq_lock;1156/* prevent concurrent access to submission queue */1157struct mutex sq_mutex;1158};11591160#define MCQ_QCFG_SIZE 0x4011611162static inline unsigned int ufshcd_mcq_opr_offset(struct ufs_hba *hba,1163enum ufshcd_mcq_opr opr, int idx)1164{1165return hba->mcq_opr[opr].offset + hba->mcq_opr[opr].stride * idx;1166}11671168static inline unsigned int ufshcd_mcq_cfg_offset(unsigned int reg, int idx)1169{1170return reg + MCQ_QCFG_SIZE * idx;1171}11721173#ifdef CONFIG_SCSI_UFS_VARIABLE_SG_ENTRY_SIZE1174static inline size_t ufshcd_sg_entry_size(const struct ufs_hba *hba)1175{1176return hba->sg_entry_size;1177}11781179static inline void ufshcd_set_sg_entry_size(struct ufs_hba *hba, size_t sg_entry_size)1180{1181WARN_ON_ONCE(sg_entry_size < sizeof(struct ufshcd_sg_entry));1182hba->sg_entry_size = sg_entry_size;1183}1184#else1185static inline size_t ufshcd_sg_entry_size(const struct ufs_hba *hba)1186{1187return sizeof(struct ufshcd_sg_entry);1188}11891190#define ufshcd_set_sg_entry_size(hba, sg_entry_size) \1191({ (void)(hba); BUILD_BUG_ON(sg_entry_size != sizeof(struct ufshcd_sg_entry)); })1192#endif11931194#ifdef CONFIG_SCSI_UFS_CRYPTO1195static inline struct ufs_hba *1196ufs_hba_from_crypto_profile(struct blk_crypto_profile *profile)1197{1198return container_of(profile, struct ufs_hba, crypto_profile);1199}1200#endif12011202static inline size_t ufshcd_get_ucd_size(const struct ufs_hba *hba)1203{1204return sizeof(struct utp_transfer_cmd_desc) + SG_ALL * ufshcd_sg_entry_size(hba);1205}12061207/* Returns true if clocks can be gated. Otherwise false */1208static inline bool ufshcd_is_clkgating_allowed(struct ufs_hba *hba)1209{1210return hba->caps & UFSHCD_CAP_CLK_GATING;1211}1212static inline bool ufshcd_can_hibern8_during_gating(struct ufs_hba *hba)1213{1214return hba->caps & UFSHCD_CAP_HIBERN8_WITH_CLK_GATING;1215}1216static inline int ufshcd_is_clkscaling_supported(struct ufs_hba *hba)1217{1218return hba->caps & UFSHCD_CAP_CLK_SCALING;1219}1220static inline bool ufshcd_can_autobkops_during_suspend(struct ufs_hba *hba)1221{1222return hba->caps & UFSHCD_CAP_AUTO_BKOPS_SUSPEND;1223}1224static inline bool ufshcd_is_rpm_autosuspend_allowed(struct ufs_hba *hba)1225{1226return hba->caps & UFSHCD_CAP_RPM_AUTOSUSPEND;1227}12281229static inline bool ufshcd_is_intr_aggr_allowed(struct ufs_hba *hba)1230{1231return (hba->caps & UFSHCD_CAP_INTR_AGGR) &&1232!(hba->quirks & UFSHCD_QUIRK_BROKEN_INTR_AGGR);1233}12341235static inline bool ufshcd_can_aggressive_pc(struct ufs_hba *hba)1236{1237return !!(ufshcd_is_link_hibern8(hba) &&1238(hba->caps & UFSHCD_CAP_AGGR_POWER_COLLAPSE));1239}12401241static inline bool ufshcd_is_auto_hibern8_supported(struct ufs_hba *hba)1242{1243return (hba->capabilities & MASK_AUTO_HIBERN8_SUPPORT) &&1244!(hba->quirks & UFSHCD_QUIRK_BROKEN_AUTO_HIBERN8);1245}12461247static inline bool ufshcd_is_auto_hibern8_enabled(struct ufs_hba *hba)1248{1249return FIELD_GET(UFSHCI_AHIBERN8_TIMER_MASK, hba->ahit);1250}12511252static inline bool ufshcd_is_wb_allowed(struct ufs_hba *hba)1253{1254return hba->caps & UFSHCD_CAP_WB_EN;1255}12561257static inline bool ufshcd_enable_wb_if_scaling_up(struct ufs_hba *hba)1258{1259return hba->caps & UFSHCD_CAP_WB_WITH_CLK_SCALING;1260}12611262#define ufsmcq_writel(hba, val, reg) \1263writel((val), (hba)->mcq_base + (reg))1264#define ufsmcq_readl(hba, reg) \1265readl((hba)->mcq_base + (reg))12661267#define ufsmcq_writelx(hba, val, reg) \1268writel_relaxed((val), (hba)->mcq_base + (reg))1269#define ufsmcq_readlx(hba, reg) \1270readl_relaxed((hba)->mcq_base + (reg))12711272#define ufshcd_writel(hba, val, reg) \1273writel((val), (hba)->mmio_base + (reg))1274#define ufshcd_readl(hba, reg) \1275readl((hba)->mmio_base + (reg))12761277/**1278* ufshcd_rmwl - perform read/modify/write for a controller register1279* @hba: per adapter instance1280* @mask: mask to apply on read value1281* @val: actual value to write1282* @reg: register address1283*/1284static inline void ufshcd_rmwl(struct ufs_hba *hba, u32 mask, u32 val, u32 reg)1285{1286u32 tmp;12871288tmp = ufshcd_readl(hba, reg);1289tmp &= ~mask;1290tmp |= (val & mask);1291ufshcd_writel(hba, tmp, reg);1292}12931294void ufshcd_enable_irq(struct ufs_hba *hba);1295void ufshcd_disable_irq(struct ufs_hba *hba);1296int ufshcd_alloc_host(struct device *, struct ufs_hba **);1297int ufshcd_hba_enable(struct ufs_hba *hba);1298int ufshcd_init(struct ufs_hba *, void __iomem *, unsigned int);1299int ufshcd_link_recovery(struct ufs_hba *hba);1300int ufshcd_make_hba_operational(struct ufs_hba *hba);1301void ufshcd_remove(struct ufs_hba *);1302int ufshcd_uic_hibern8_enter(struct ufs_hba *hba);1303int ufshcd_uic_hibern8_exit(struct ufs_hba *hba);1304void ufshcd_delay_us(unsigned long us, unsigned long tolerance);1305void ufshcd_parse_dev_ref_clk_freq(struct ufs_hba *hba, struct clk *refclk);1306void ufshcd_update_evt_hist(struct ufs_hba *hba, u32 id, u32 val);1307void ufshcd_hba_stop(struct ufs_hba *hba);1308void ufshcd_schedule_eh_work(struct ufs_hba *hba);1309void ufshcd_mcq_config_mac(struct ufs_hba *hba, u32 max_active_cmds);1310unsigned int ufshcd_mcq_queue_cfg_addr(struct ufs_hba *hba);1311u32 ufshcd_mcq_read_cqis(struct ufs_hba *hba, int i);1312void ufshcd_mcq_write_cqis(struct ufs_hba *hba, u32 val, int i);1313unsigned long ufshcd_mcq_poll_cqe_lock(struct ufs_hba *hba,1314struct ufs_hw_queue *hwq);1315void ufshcd_mcq_make_queues_operational(struct ufs_hba *hba);1316void ufshcd_mcq_enable(struct ufs_hba *hba);1317void ufshcd_mcq_enable_esi(struct ufs_hba *hba);1318void ufshcd_mcq_config_esi(struct ufs_hba *hba, struct msi_msg *msg);13191320int ufshcd_opp_config_clks(struct device *dev, struct opp_table *opp_table,1321struct dev_pm_opp *opp, void *data,1322bool scaling_down);1323/**1324* ufshcd_set_variant - set variant specific data to the hba1325* @hba: per adapter instance1326* @variant: pointer to variant specific data1327*/1328static inline void ufshcd_set_variant(struct ufs_hba *hba, void *variant)1329{1330BUG_ON(!hba);1331hba->priv = variant;1332}13331334/**1335* ufshcd_get_variant - get variant specific data from the hba1336* @hba: per adapter instance1337*/1338static inline void *ufshcd_get_variant(struct ufs_hba *hba)1339{1340BUG_ON(!hba);1341return hba->priv;1342}13431344#ifdef CONFIG_PM1345extern int ufshcd_runtime_suspend(struct device *dev);1346extern int ufshcd_runtime_resume(struct device *dev);1347#endif1348#ifdef CONFIG_PM_SLEEP1349extern int ufshcd_system_suspend(struct device *dev);1350extern int ufshcd_system_resume(struct device *dev);1351extern int ufshcd_system_freeze(struct device *dev);1352extern int ufshcd_system_thaw(struct device *dev);1353extern int ufshcd_system_restore(struct device *dev);1354#endif13551356extern int ufshcd_dme_reset(struct ufs_hba *hba);1357extern int ufshcd_dme_enable(struct ufs_hba *hba);1358extern int ufshcd_dme_configure_adapt(struct ufs_hba *hba,1359int agreed_gear,1360int adapt_val);1361extern int ufshcd_dme_set_attr(struct ufs_hba *hba, u32 attr_sel,1362u8 attr_set, u32 mib_val, u8 peer);1363extern int ufshcd_dme_get_attr(struct ufs_hba *hba, u32 attr_sel,1364u32 *mib_val, u8 peer);1365extern int ufshcd_config_pwr_mode(struct ufs_hba *hba,1366struct ufs_pa_layer_attr *desired_pwr_mode);1367extern int ufshcd_uic_change_pwr_mode(struct ufs_hba *hba, u8 mode);13681369/* UIC command interfaces for DME primitives */1370#define DME_LOCAL 01371#define DME_PEER 11372#define ATTR_SET_NOR 0 /* NORMAL */1373#define ATTR_SET_ST 1 /* STATIC */13741375static inline int ufshcd_dme_set(struct ufs_hba *hba, u32 attr_sel,1376u32 mib_val)1377{1378return ufshcd_dme_set_attr(hba, attr_sel, ATTR_SET_NOR,1379mib_val, DME_LOCAL);1380}13811382static inline int ufshcd_dme_st_set(struct ufs_hba *hba, u32 attr_sel,1383u32 mib_val)1384{1385return ufshcd_dme_set_attr(hba, attr_sel, ATTR_SET_ST,1386mib_val, DME_LOCAL);1387}13881389static inline int ufshcd_dme_peer_set(struct ufs_hba *hba, u32 attr_sel,1390u32 mib_val)1391{1392return ufshcd_dme_set_attr(hba, attr_sel, ATTR_SET_NOR,1393mib_val, DME_PEER);1394}13951396static inline int ufshcd_dme_peer_st_set(struct ufs_hba *hba, u32 attr_sel,1397u32 mib_val)1398{1399return ufshcd_dme_set_attr(hba, attr_sel, ATTR_SET_ST,1400mib_val, DME_PEER);1401}14021403static inline int ufshcd_dme_get(struct ufs_hba *hba,1404u32 attr_sel, u32 *mib_val)1405{1406return ufshcd_dme_get_attr(hba, attr_sel, mib_val, DME_LOCAL);1407}14081409static inline int ufshcd_dme_peer_get(struct ufs_hba *hba,1410u32 attr_sel, u32 *mib_val)1411{1412return ufshcd_dme_get_attr(hba, attr_sel, mib_val, DME_PEER);1413}14141415static inline bool ufshcd_is_hs_mode(const struct ufs_pa_layer_attr *pwr_info)1416{1417return (pwr_info->pwr_rx == FAST_MODE ||1418pwr_info->pwr_rx == FASTAUTO_MODE) &&1419(pwr_info->pwr_tx == FAST_MODE ||1420pwr_info->pwr_tx == FASTAUTO_MODE);1421}14221423static inline int ufshcd_disable_host_tx_lcc(struct ufs_hba *hba)1424{1425return ufshcd_dme_set(hba, UIC_ARG_MIB(PA_LOCAL_TX_LCC_ENABLE), 0);1426}14271428void ufshcd_auto_hibern8_update(struct ufs_hba *hba, u32 ahit);1429void ufshcd_fixup_dev_quirks(struct ufs_hba *hba,1430const struct ufs_dev_quirk *fixups);14311432void ufshcd_hold(struct ufs_hba *hba);1433void ufshcd_release(struct ufs_hba *hba);14341435void ufshcd_clkgate_delay_set(struct device *dev, unsigned long value);14361437int ufshcd_get_vreg(struct device *dev, struct ufs_vreg *vreg);14381439int ufshcd_send_uic_cmd(struct ufs_hba *hba, struct uic_command *uic_cmd);14401441int ufshcd_advanced_rpmb_req_handler(struct ufs_hba *hba, struct utp_upiu_req *req_upiu,1442struct utp_upiu_req *rsp_upiu, struct ufs_ehs *ehs_req,1443struct ufs_ehs *ehs_rsp, int sg_cnt,1444struct scatterlist *sg_list, enum dma_data_direction dir);1445int ufshcd_wb_toggle(struct ufs_hba *hba, bool enable);1446int ufshcd_wb_toggle_buf_flush(struct ufs_hba *hba, bool enable);1447int ufshcd_wb_set_resize_en(struct ufs_hba *hba, enum wb_resize_en en_mode);1448int ufshcd_suspend_prepare(struct device *dev);1449int __ufshcd_suspend_prepare(struct device *dev, bool rpm_ok_for_spm);1450void ufshcd_resume_complete(struct device *dev);1451bool ufshcd_is_hba_active(struct ufs_hba *hba);1452void ufshcd_pm_qos_init(struct ufs_hba *hba);1453void ufshcd_pm_qos_exit(struct ufs_hba *hba);1454int ufshcd_dme_rmw(struct ufs_hba *hba, u32 mask, u32 val, u32 attr);14551456/* Wrapper functions for safely calling variant operations */1457static inline int ufshcd_vops_init(struct ufs_hba *hba)1458{1459if (hba->vops && hba->vops->init)1460return hba->vops->init(hba);14611462return 0;1463}14641465static inline int ufshcd_vops_phy_initialization(struct ufs_hba *hba)1466{1467if (hba->vops && hba->vops->phy_initialization)1468return hba->vops->phy_initialization(hba);14691470return 0;1471}14721473extern const struct ufs_pm_lvl_states ufs_pm_lvl_states[];14741475int ufshcd_dump_regs(struct ufs_hba *hba, size_t offset, size_t len,1476const char *prefix);14771478int __ufshcd_write_ee_control(struct ufs_hba *hba, u32 ee_ctrl_mask);1479int ufshcd_write_ee_control(struct ufs_hba *hba);1480int ufshcd_update_ee_control(struct ufs_hba *hba, u16 *mask,1481const u16 *other_mask, u16 set, u16 clr);1482void ufshcd_force_error_recovery(struct ufs_hba *hba);1483void ufshcd_pm_qos_update(struct ufs_hba *hba, bool on);1484u32 ufshcd_us_to_ahit(unsigned int timer);14851486#endif /* End of Header */148714881489