/* 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;80int 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* @cmd: pointer to SCSI command164* @scsi_status: SCSI status of the command165* @command_type: SCSI, UFS, Query.166* @task_tag: Task tag of the command167* @lun: LUN of the command168* @intr_cmd: Interrupt command (doesn't participate in interrupt aggregation)169* @req_abort_skip: skip request abort task flag170* @issue_time_stamp: time stamp for debug purposes (CLOCK_MONOTONIC)171* @issue_time_stamp_local_clock: time stamp for debug purposes (local_clock)172* @compl_time_stamp: time stamp for statistics (CLOCK_MONOTONIC)173* @compl_time_stamp_local_clock: time stamp for debug purposes (local_clock)174* @crypto_key_slot: the key slot to use for inline crypto (-1 if none)175* @data_unit_num: the data unit number for the first block for inline crypto176*/177struct ufshcd_lrb {178struct utp_transfer_req_desc *utr_descriptor_ptr;179struct utp_upiu_req *ucd_req_ptr;180struct utp_upiu_rsp *ucd_rsp_ptr;181struct ufshcd_sg_entry *ucd_prdt_ptr;182183dma_addr_t utrd_dma_addr;184dma_addr_t ucd_req_dma_addr;185dma_addr_t ucd_rsp_dma_addr;186dma_addr_t ucd_prdt_dma_addr;187188struct scsi_cmnd *cmd;189int scsi_status;190191int command_type;192int task_tag;193u8 lun; /* UPIU LUN id field is only 8-bit wide */194bool intr_cmd;195bool req_abort_skip;196ktime_t issue_time_stamp;197u64 issue_time_stamp_local_clock;198ktime_t compl_time_stamp;199u64 compl_time_stamp_local_clock;200#ifdef CONFIG_SCSI_UFS_CRYPTO201int crypto_key_slot;202u64 data_unit_num;203#endif204};205206/**207* struct ufs_query_req - parameters for building a query request208* @query_func: UPIU header query function209* @upiu_req: the query request data210*/211struct ufs_query_req {212u8 query_func;213struct utp_upiu_query upiu_req;214};215216/**217* struct ufs_query_resp - UPIU QUERY218* @response: device response code219* @upiu_res: query response data220*/221struct ufs_query_res {222struct utp_upiu_query upiu_res;223};224225/**226* struct ufs_query - holds relevant data structures for query request227* @request: request upiu and function228* @descriptor: buffer for sending/receiving descriptor229* @response: response upiu and response230*/231struct ufs_query {232struct ufs_query_req request;233u8 *descriptor;234struct ufs_query_res response;235};236237/**238* struct ufs_dev_cmd - all assosiated fields with device management commands239* @type: device management command type - Query, NOP OUT240* @lock: lock to allow one command at a time241* @complete: internal commands completion242* @query: Device management query information243*/244struct ufs_dev_cmd {245enum dev_cmd_type type;246struct mutex lock;247struct completion complete;248struct ufs_query query;249};250251/**252* struct ufs_clk_info - UFS clock related info253* @list: list headed by hba->clk_list_head254* @clk: clock node255* @name: clock name256* @max_freq: maximum frequency supported by the clock257* @min_freq: min frequency that can be used for clock scaling258* @curr_freq: indicates the current frequency that it is set to259* @keep_link_active: indicates that the clk should not be disabled if260* link is active261* @enabled: variable to check against multiple enable/disable262*/263struct ufs_clk_info {264struct list_head list;265struct clk *clk;266const char *name;267u32 max_freq;268u32 min_freq;269u32 curr_freq;270bool keep_link_active;271bool enabled;272};273274enum ufs_notify_change_status {275PRE_CHANGE,276POST_CHANGE,277};278279struct ufs_pa_layer_attr {280u32 gear_rx;281u32 gear_tx;282u32 lane_rx;283u32 lane_tx;284u32 pwr_rx;285u32 pwr_tx;286u32 hs_rate;287};288289struct ufs_pwr_mode_info {290bool is_valid;291struct ufs_pa_layer_attr info;292};293294/**295* struct ufs_hba_variant_ops - variant specific callbacks296* @name: variant name297* @max_num_rtt: maximum RTT supported by the host298* @init: called when the driver is initialized299* @exit: called to cleanup everything done in init300* @set_dma_mask: For setting another DMA mask than indicated by the 64AS301* capability bit.302* @get_ufs_hci_version: called to get UFS HCI version303* @clk_scale_notify: notifies that clks are scaled up/down304* @setup_clocks: called before touching any of the controller registers305* @hce_enable_notify: called before and after HCE enable bit is set to allow306* variant specific Uni-Pro initialization.307* @link_startup_notify: called before and after Link startup is carried out308* to allow variant specific Uni-Pro initialization.309* @pwr_change_notify: called before and after a power mode change310* is carried out to allow vendor spesific capabilities311* to be set. PRE_CHANGE can modify final_params based312* on desired_pwr_mode, but POST_CHANGE must not alter313* the final_params parameter314* @setup_xfer_req: called before any transfer request is issued315* to set some things316* @setup_task_mgmt: called before any task management request is issued317* to set some things318* @hibern8_notify: called around hibern8 enter/exit319* @apply_dev_quirks: called to apply device specific quirks320* @fixup_dev_quirks: called to modify device specific quirks321* @suspend: called during host controller PM callback322* @resume: called during host controller PM callback323* @dbg_register_dump: used to dump controller debug information324* @phy_initialization: used to initialize phys325* @device_reset: called to issue a reset pulse on the UFS device326* @config_scaling_param: called to configure clock scaling parameters327* @fill_crypto_prdt: initialize crypto-related fields in the PRDT328* @event_notify: called to notify important events329* @mcq_config_resource: called to configure MCQ platform resources330* @get_hba_mac: reports maximum number of outstanding commands supported by331* the controller. Should be implemented for UFSHCI 4.0 or later332* controllers that are not compliant with the UFSHCI 4.0 specification.333* @op_runtime_config: called to config Operation and runtime regs Pointers334* @get_outstanding_cqs: called to get outstanding completion queues335* @config_esi: called to config Event Specific Interrupt336* @config_scsi_dev: called to configure SCSI device parameters337* @freq_to_gear_speed: called to map clock frequency to the max supported gear speed338*/339struct ufs_hba_variant_ops {340const char *name;341int max_num_rtt;342int (*init)(struct ufs_hba *);343void (*exit)(struct ufs_hba *);344u32 (*get_ufs_hci_version)(struct ufs_hba *);345int (*set_dma_mask)(struct ufs_hba *);346int (*clk_scale_notify)(struct ufs_hba *, bool, unsigned long,347enum ufs_notify_change_status);348int (*setup_clocks)(struct ufs_hba *, bool,349enum ufs_notify_change_status);350int (*hce_enable_notify)(struct ufs_hba *,351enum ufs_notify_change_status);352int (*link_startup_notify)(struct ufs_hba *,353enum ufs_notify_change_status);354int (*pwr_change_notify)(struct ufs_hba *,355enum ufs_notify_change_status status,356const struct ufs_pa_layer_attr *desired_pwr_mode,357struct ufs_pa_layer_attr *final_params);358void (*setup_xfer_req)(struct ufs_hba *hba, int tag,359bool is_scsi_cmd);360void (*setup_task_mgmt)(struct ufs_hba *, int, u8);361void (*hibern8_notify)(struct ufs_hba *, enum uic_cmd_dme,362enum ufs_notify_change_status);363int (*apply_dev_quirks)(struct ufs_hba *hba);364void (*fixup_dev_quirks)(struct ufs_hba *hba);365int (*suspend)(struct ufs_hba *, enum ufs_pm_op,366enum ufs_notify_change_status);367int (*resume)(struct ufs_hba *, enum ufs_pm_op);368void (*dbg_register_dump)(struct ufs_hba *hba);369int (*phy_initialization)(struct ufs_hba *);370int (*device_reset)(struct ufs_hba *hba);371void (*config_scaling_param)(struct ufs_hba *hba,372struct devfreq_dev_profile *profile,373struct devfreq_simple_ondemand_data *data);374int (*fill_crypto_prdt)(struct ufs_hba *hba,375const struct bio_crypt_ctx *crypt_ctx,376void *prdt, unsigned int num_segments);377void (*event_notify)(struct ufs_hba *hba,378enum ufs_event_type evt, void *data);379int (*mcq_config_resource)(struct ufs_hba *hba);380int (*get_hba_mac)(struct ufs_hba *hba);381int (*op_runtime_config)(struct ufs_hba *hba);382int (*get_outstanding_cqs)(struct ufs_hba *hba,383unsigned long *ocqs);384int (*config_esi)(struct ufs_hba *hba);385void (*config_scsi_dev)(struct scsi_device *sdev);386u32 (*freq_to_gear_speed)(struct ufs_hba *hba, unsigned long freq);387};388389/* clock gating state */390enum clk_gating_state {391CLKS_OFF,392CLKS_ON,393REQ_CLKS_OFF,394REQ_CLKS_ON,395};396397/**398* struct ufs_clk_gating - UFS clock gating related info399* @gate_work: worker to turn off clocks after some delay as specified in400* delay_ms401* @ungate_work: worker to turn on clocks that will be used in case of402* interrupt context403* @clk_gating_workq: workqueue for clock gating work.404* @lock: serialize access to some struct ufs_clk_gating members. An outer lock405* relative to the host lock406* @state: the current clocks state407* @delay_ms: gating delay in ms408* @is_suspended: clk gating is suspended when set to 1 which can be used409* during suspend/resume410* @delay_attr: sysfs attribute to control delay_attr411* @enable_attr: sysfs attribute to enable/disable clock gating412* @is_enabled: Indicates the current status of clock gating413* @is_initialized: Indicates whether clock gating is initialized or not414* @active_reqs: number of requests that are pending and should be waited for415* completion before gating clocks.416*/417struct ufs_clk_gating {418struct delayed_work gate_work;419struct work_struct ungate_work;420struct workqueue_struct *clk_gating_workq;421422spinlock_t lock;423424enum clk_gating_state state;425unsigned long delay_ms;426bool is_suspended;427struct device_attribute delay_attr;428struct device_attribute enable_attr;429bool is_enabled;430bool is_initialized;431int active_reqs;432};433434/**435* struct ufs_clk_scaling - UFS clock scaling related data436* @workq: workqueue to schedule devfreq suspend/resume work437* @suspend_work: worker to suspend devfreq438* @resume_work: worker to resume devfreq439* @lock: serialize access to some struct ufs_clk_scaling members440* @active_reqs: number of requests that are pending. If this is zero when441* devfreq ->target() function is called then schedule "suspend_work" to442* suspend devfreq.443* @tot_busy_t: Total busy time in current polling window444* @window_start_t: Start time (in jiffies) of the current polling window445* @busy_start_t: Start time of current busy period446* @enable_attr: sysfs attribute to enable/disable clock scaling447* @saved_pwr_info: UFS power mode may also be changed during scaling and this448* one keeps track of previous power mode.449* @target_freq: frequency requested by devfreq framework450* @min_gear: lowest HS gear to scale down to451* @wb_gear: enable Write Booster when HS gear scales above or equal to it, else452* disable Write Booster453* @is_enabled: tracks if scaling is currently enabled or not, controlled by454* clkscale_enable sysfs node455* @is_allowed: tracks if scaling is currently allowed or not, used to block456* clock scaling which is not invoked from devfreq governor457* @is_initialized: Indicates whether clock scaling is initialized or not458* @is_busy_started: tracks if busy period has started or not459* @is_suspended: tracks if devfreq is suspended or not460*/461struct ufs_clk_scaling {462struct workqueue_struct *workq;463struct work_struct suspend_work;464struct work_struct resume_work;465466spinlock_t lock;467468int active_reqs;469unsigned long tot_busy_t;470ktime_t window_start_t;471ktime_t busy_start_t;472struct device_attribute enable_attr;473struct ufs_pa_layer_attr saved_pwr_info;474unsigned long target_freq;475u32 min_gear;476u32 wb_gear;477bool is_enabled;478bool is_allowed;479bool is_initialized;480bool is_busy_started;481bool is_suspended;482bool suspend_on_no_request;483};484485#define UFS_EVENT_HIST_LENGTH 8486/**487* struct ufs_event_hist - keeps history of errors488* @pos: index to indicate cyclic buffer position489* @val: cyclic buffer for registers value490* @tstamp: cyclic buffer for time stamp491* @cnt: error counter492*/493struct ufs_event_hist {494int pos;495u32 val[UFS_EVENT_HIST_LENGTH];496u64 tstamp[UFS_EVENT_HIST_LENGTH];497unsigned long long cnt;498};499500/**501* struct ufs_stats - keeps usage/err statistics502* @hibern8_exit_cnt: Counter to keep track of number of exits,503* reset this after link-startup.504* @last_hibern8_exit_tstamp: Set time after the hibern8 exit.505* Clear after the first successful command completion.506* @event: array with event history.507*/508struct ufs_stats {509u32 hibern8_exit_cnt;510u64 last_hibern8_exit_tstamp;511struct ufs_event_hist event[UFS_EVT_CNT];512};513514/**515* enum ufshcd_state - UFS host controller state516* @UFSHCD_STATE_RESET: Link is not operational. Postpone SCSI command517* processing.518* @UFSHCD_STATE_OPERATIONAL: The host controller is operational and can process519* SCSI commands.520* @UFSHCD_STATE_EH_SCHEDULED_NON_FATAL: The error handler has been scheduled.521* SCSI commands may be submitted to the controller.522* @UFSHCD_STATE_EH_SCHEDULED_FATAL: The error handler has been scheduled. Fail523* newly submitted SCSI commands with error code DID_BAD_TARGET.524* @UFSHCD_STATE_ERROR: An unrecoverable error occurred, e.g. link recovery525* failed. Fail all SCSI commands with error code DID_ERROR.526*/527enum ufshcd_state {528UFSHCD_STATE_RESET,529UFSHCD_STATE_OPERATIONAL,530UFSHCD_STATE_EH_SCHEDULED_NON_FATAL,531UFSHCD_STATE_EH_SCHEDULED_FATAL,532UFSHCD_STATE_ERROR,533};534535enum ufshcd_quirks {536/* Interrupt aggregation support is broken */537UFSHCD_QUIRK_BROKEN_INTR_AGGR = 1 << 0,538539/*540* delay before each dme command is required as the unipro541* layer has shown instabilities542*/543UFSHCD_QUIRK_DELAY_BEFORE_DME_CMDS = 1 << 1,544545/*546* If UFS host controller is having issue in processing LCC (Line547* Control Command) coming from device then enable this quirk.548* When this quirk is enabled, host controller driver should disable549* the LCC transmission on UFS device (by clearing TX_LCC_ENABLE550* attribute of device to 0).551*/552UFSHCD_QUIRK_BROKEN_LCC = 1 << 2,553554/*555* The attribute PA_RXHSUNTERMCAP specifies whether or not the556* inbound Link supports unterminated line in HS mode. Setting this557* attribute to 1 fixes moving to HS gear.558*/559UFSHCD_QUIRK_BROKEN_PA_RXHSUNTERMCAP = 1 << 3,560561/*562* This quirk needs to be enabled if the host controller only allows563* accessing the peer dme attributes in AUTO mode (FAST AUTO or564* SLOW AUTO).565*/566UFSHCD_QUIRK_DME_PEER_ACCESS_AUTO_MODE = 1 << 4,567568/*569* This quirk needs to be enabled if the host controller doesn't570* advertise the correct version in UFS_VER register. If this quirk571* is enabled, standard UFS host driver will call the vendor specific572* ops (get_ufs_hci_version) to get the correct version.573*/574UFSHCD_QUIRK_BROKEN_UFS_HCI_VERSION = 1 << 5,575576/*577* Clear handling for transfer/task request list is just opposite.578*/579UFSHCI_QUIRK_BROKEN_REQ_LIST_CLR = 1 << 6,580581/*582* This quirk needs to be enabled if host controller doesn't allow583* that the interrupt aggregation timer and counter are reset by s/w.584*/585UFSHCI_QUIRK_SKIP_RESET_INTR_AGGR = 1 << 7,586587/*588* This quirks needs to be enabled if host controller cannot be589* enabled via HCE register.590*/591UFSHCI_QUIRK_BROKEN_HCE = 1 << 8,592593/*594* This quirk needs to be enabled if the host controller regards595* resolution of the values of PRDTO and PRDTL in UTRD as byte.596*/597UFSHCD_QUIRK_PRDT_BYTE_GRAN = 1 << 9,598599/*600* This quirk needs to be enabled if the host controller reports601* OCS FATAL ERROR with device error through sense data602*/603UFSHCD_QUIRK_BROKEN_OCS_FATAL_ERROR = 1 << 10,604605/*606* This quirk needs to be enabled if the host controller has607* auto-hibernate capability but it doesn't work.608*/609UFSHCD_QUIRK_BROKEN_AUTO_HIBERN8 = 1 << 11,610611/*612* This quirk needs to disable manual flush for write booster613*/614UFSHCI_QUIRK_SKIP_MANUAL_WB_FLUSH_CTRL = 1 << 12,615616/*617* This quirk needs to disable unipro timeout values618* before power mode change619*/620UFSHCD_QUIRK_SKIP_DEF_UNIPRO_TIMEOUT_SETTING = 1 << 13,621622/*623* This quirk needs to be enabled if the host controller does not624* support UIC command625*/626UFSHCD_QUIRK_BROKEN_UIC_CMD = 1 << 15,627628/*629* This quirk needs to be enabled if the host controller cannot630* support physical host configuration.631*/632UFSHCD_QUIRK_SKIP_PH_CONFIGURATION = 1 << 16,633634/*635* This quirk needs to be enabled if the host controller has636* auto-hibernate capability but it's FASTAUTO only.637*/638UFSHCD_QUIRK_HIBERN_FASTAUTO = 1 << 18,639640/*641* This quirk needs to be enabled if the host controller needs642* to reinit the device after switching to maximum gear.643*/644UFSHCD_QUIRK_REINIT_AFTER_MAX_GEAR_SWITCH = 1 << 19,645646/*647* Some host raises interrupt (per queue) in addition to648* CQES (traditional) when ESI is disabled.649* Enable this quirk will disable CQES and use per queue interrupt.650*/651UFSHCD_QUIRK_MCQ_BROKEN_INTR = 1 << 20,652653/*654* Some host does not implement SQ Run Time Command (SQRTC) register655* thus need this quirk to skip related flow.656*/657UFSHCD_QUIRK_MCQ_BROKEN_RTC = 1 << 21,658659/*660* This quirk needs to be enabled if the host controller supports inline661* encryption but it needs to initialize the crypto capabilities in a662* nonstandard way and/or needs to override blk_crypto_ll_ops. If663* enabled, the standard code won't initialize the blk_crypto_profile;664* ufs_hba_variant_ops::init() must do it instead.665*/666UFSHCD_QUIRK_CUSTOM_CRYPTO_PROFILE = 1 << 22,667668/*669* This quirk needs to be enabled if the host controller supports inline670* encryption but does not support the CRYPTO_GENERAL_ENABLE bit, i.e.671* host controller initialization fails if that bit is set.672*/673UFSHCD_QUIRK_BROKEN_CRYPTO_ENABLE = 1 << 23,674675/*676* This quirk needs to be enabled if the host controller driver copies677* cryptographic keys into the PRDT in order to send them to hardware,678* and therefore the PRDT should be zeroized after each request (as per679* the standard best practice for managing keys).680*/681UFSHCD_QUIRK_KEYS_IN_PRDT = 1 << 24,682683/*684* This quirk indicates that the controller reports the value 1 (not685* supported) in the Legacy Single DoorBell Support (LSDBS) bit of the686* Controller Capabilities register although it supports the legacy687* single doorbell mode.688*/689UFSHCD_QUIRK_BROKEN_LSDBS_CAP = 1 << 25,690};691692enum ufshcd_caps {693/* Allow dynamic clk gating */694UFSHCD_CAP_CLK_GATING = 1 << 0,695696/* Allow hiberb8 with clk gating */697UFSHCD_CAP_HIBERN8_WITH_CLK_GATING = 1 << 1,698699/* Allow dynamic clk scaling */700UFSHCD_CAP_CLK_SCALING = 1 << 2,701702/* Allow auto bkops to enabled during runtime suspend */703UFSHCD_CAP_AUTO_BKOPS_SUSPEND = 1 << 3,704705/*706* This capability allows host controller driver to use the UFS HCI's707* interrupt aggregation capability.708* CAUTION: Enabling this might reduce overall UFS throughput.709*/710UFSHCD_CAP_INTR_AGGR = 1 << 4,711712/*713* This capability allows the device auto-bkops to be always enabled714* except during suspend (both runtime and suspend).715* Enabling this capability means that device will always be allowed716* to do background operation when it's active but it might degrade717* the performance of ongoing read/write operations.718*/719UFSHCD_CAP_KEEP_AUTO_BKOPS_ENABLED_EXCEPT_SUSPEND = 1 << 5,720721/*722* This capability allows host controller driver to automatically723* enable runtime power management by itself instead of waiting724* for userspace to control the power management.725*/726UFSHCD_CAP_RPM_AUTOSUSPEND = 1 << 6,727728/*729* This capability allows the host controller driver to turn-on730* WriteBooster, if the underlying device supports it and is731* provisioned to be used. This would increase the write performance.732*/733UFSHCD_CAP_WB_EN = 1 << 7,734735/*736* This capability allows the host controller driver to use the737* inline crypto engine, if it is present738*/739UFSHCD_CAP_CRYPTO = 1 << 8,740741/*742* This capability allows the controller regulators to be put into743* lpm mode aggressively during clock gating.744* This would increase power savings.745*/746UFSHCD_CAP_AGGR_POWER_COLLAPSE = 1 << 9,747748/*749* This capability allows the host controller driver to use DeepSleep,750* if it is supported by the UFS device. The host controller driver must751* support device hardware reset via the hba->device_reset() callback,752* in order to exit DeepSleep state.753*/754UFSHCD_CAP_DEEPSLEEP = 1 << 10,755756/*757* This capability allows the host controller driver to use temperature758* notification if it is supported by the UFS device.759*/760UFSHCD_CAP_TEMP_NOTIF = 1 << 11,761762/*763* Enable WriteBooster when scaling up the clock and disable764* WriteBooster when scaling the clock down.765*/766UFSHCD_CAP_WB_WITH_CLK_SCALING = 1 << 12,767};768769struct ufs_hba_variant_params {770struct devfreq_dev_profile devfreq_profile;771struct devfreq_simple_ondemand_data ondemand_data;772u16 hba_enable_delay_us;773u32 wb_flush_threshold;774};775776struct ufs_hba_monitor {777unsigned long chunk_size;778779unsigned long nr_sec_rw[2];780ktime_t total_busy[2];781782unsigned long nr_req[2];783/* latencies*/784ktime_t lat_sum[2];785ktime_t lat_max[2];786ktime_t lat_min[2];787788u32 nr_queued[2];789ktime_t busy_start_ts[2];790791ktime_t enabled_ts;792bool enabled;793};794795/**796* struct ufshcd_mcq_opr_info_t - Operation and Runtime registers797*798* @offset: Doorbell Address Offset799* @stride: Steps proportional to queue [0...31]800* @base: base address801*/802struct ufshcd_mcq_opr_info_t {803unsigned long offset;804unsigned long stride;805void __iomem *base;806};807808enum ufshcd_mcq_opr {809OPR_SQD,810OPR_SQIS,811OPR_CQD,812OPR_CQIS,813OPR_MAX,814};815816/**817* struct ufs_hba - per adapter private structure818* @mmio_base: UFSHCI base register address819* @ucdl_base_addr: UFS Command Descriptor base address820* @utrdl_base_addr: UTP Transfer Request Descriptor base address821* @utmrdl_base_addr: UTP Task Management Descriptor base address822* @ucdl_dma_addr: UFS Command Descriptor DMA address823* @utrdl_dma_addr: UTRDL DMA address824* @utmrdl_dma_addr: UTMRDL DMA address825* @host: Scsi_Host instance of the driver826* @dev: device handle827* @ufs_device_wlun: WLUN that controls the entire UFS device.828* @hwmon_device: device instance registered with the hwmon core.829* @curr_dev_pwr_mode: active UFS device power mode.830* @uic_link_state: active state of the link to the UFS device.831* @rpm_lvl: desired UFS power management level during runtime PM.832* @spm_lvl: desired UFS power management level during system PM.833* @pm_op_in_progress: whether or not a PM operation is in progress.834* @ahit: value of Auto-Hibernate Idle Timer register.835* @lrb: local reference block836* @outstanding_tasks: Bits representing outstanding task requests837* @outstanding_lock: Protects @outstanding_reqs.838* @outstanding_reqs: Bits representing outstanding transfer requests839* @capabilities: UFS Controller Capabilities840* @mcq_capabilities: UFS Multi Circular Queue capabilities841* @nutrs: Transfer Request Queue depth supported by controller842* @nortt - Max outstanding RTTs supported by controller843* @nutmrs: Task Management Queue depth supported by controller844* @reserved_slot: Used to submit device commands. Protected by @dev_cmd.lock.845* @ufs_version: UFS Version to which controller complies846* @vops: pointer to variant specific operations847* @vps: pointer to variant specific parameters848* @priv: pointer to variant specific private data849* @sg_entry_size: size of struct ufshcd_sg_entry (may include variant fields)850* @irq: Irq number of the controller851* @is_irq_enabled: whether or not the UFS controller interrupt is enabled.852* @dev_ref_clk_freq: reference clock frequency853* @quirks: bitmask with information about deviations from the UFSHCI standard.854* @dev_quirks: bitmask with information about deviations from the UFS standard.855* @tmf_tag_set: TMF tag set.856* @tmf_queue: Used to allocate TMF tags.857* @tmf_rqs: array with pointers to TMF requests while these are in progress.858* @active_uic_cmd: pointer to active UIC command.859* @uic_cmd_mutex: mutex used for serializing UIC command processing.860* @uic_async_done: completion used to wait for power mode or hibernation state861* changes.862* @ufshcd_state: UFSHCD state863* @eh_flags: Error handling flags864* @intr_mask: Interrupt Mask Bits865* @ee_ctrl_mask: Exception event control mask866* @ee_drv_mask: Exception event mask for driver867* @ee_usr_mask: Exception event mask for user (set via debugfs)868* @ee_ctrl_mutex: Used to serialize exception event information.869* @is_powered: flag to check if HBA is powered870* @shutting_down: flag to check if shutdown has been invoked871* @host_sem: semaphore used to serialize concurrent contexts872* @eh_wq: Workqueue that eh_work works on873* @eh_work: Worker to handle UFS errors that require s/w attention874* @eeh_work: Worker to handle exception events875* @errors: HBA errors876* @uic_error: UFS interconnect layer error status877* @saved_err: sticky error mask878* @saved_uic_err: sticky UIC error mask879* @ufs_stats: various error counters880* @force_reset: flag to force eh_work perform a full reset881* @force_pmc: flag to force a power mode change882* @silence_err_logs: flag to silence error logs883* @dev_cmd: ufs device management command information884* @last_dme_cmd_tstamp: time stamp of the last completed DME command885* @nop_out_timeout: NOP OUT timeout value886* @dev_info: information about the UFS device887* @auto_bkops_enabled: to track whether bkops is enabled in device888* @vreg_info: UFS device voltage regulator information889* @clk_list_head: UFS host controller clocks list node head890* @use_pm_opp: Indicates whether OPP based scaling is used or not891* @req_abort_count: number of times ufshcd_abort() has been called892* @lanes_per_direction: number of lanes per data direction between the UFS893* controller and the UFS device.894* @pwr_info: holds current power mode895* @max_pwr_info: keeps the device max valid pwm896* @clk_gating: information related to clock gating897* @caps: bitmask with information about UFS controller capabilities898* @devfreq: frequency scaling information owned by the devfreq core899* @clk_scaling: frequency scaling information owned by the UFS driver900* @system_suspending: system suspend has been started and system resume has901* not yet finished.902* @is_sys_suspended: UFS device has been suspended because of system suspend903* @urgent_bkops_lvl: keeps track of urgent bkops level for device904* @is_urgent_bkops_lvl_checked: keeps track if the urgent bkops level for905* device is known or not.906* @wb_mutex: used to serialize devfreq and sysfs write booster toggling907* @clk_scaling_lock: used to serialize device commands and clock scaling908* @desc_size: descriptor sizes reported by device909* @bsg_dev: struct device associated with the BSG queue910* @bsg_queue: BSG queue associated with the UFS controller911* @rpm_dev_flush_recheck_work: used to suspend from RPM (runtime power912* management) after the UFS device has finished a WriteBooster buffer913* flush or auto BKOP.914* @monitor: statistics about UFS commands915* @crypto_capabilities: Content of crypto capabilities register (0x100)916* @crypto_cap_array: Array of crypto capabilities917* @crypto_cfg_register: Start of the crypto cfg array918* @crypto_profile: the crypto profile of this hba (if applicable)919* @debugfs_root: UFS controller debugfs root directory920* @debugfs_ee_work: used to restore ee_ctrl_mask after a delay921* @debugfs_ee_rate_limit_ms: user configurable delay after which to restore922* ee_ctrl_mask923* @luns_avail: number of regular and well known LUNs supported by the UFS924* device925* @nr_hw_queues: number of hardware queues configured926* @nr_queues: number of Queues of different queue types927* @complete_put: whether or not to call ufshcd_rpm_put() from inside928* ufshcd_resume_complete()929* @mcq_sup: is mcq supported by UFSHC930* @mcq_enabled: is mcq ready to accept requests931* @mcq_esi_enabled: is mcq ESI configured932* @res: array of resource info of MCQ registers933* @mcq_base: Multi circular queue registers base address934* @uhq: array of supported hardware queues935* @dev_cmd_queue: Queue for issuing device management commands936* @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 the944* device level exception event.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;962963#ifdef CONFIG_SCSI_UFS_HWMON964struct device *hwmon_device;965#endif966967enum ufs_dev_pwr_mode curr_dev_pwr_mode;968enum uic_link_state uic_link_state;969/* Desired UFS power management level during runtime PM */970enum ufs_pm_level rpm_lvl;971/* Desired UFS power management level during system PM */972enum ufs_pm_level spm_lvl;973int pm_op_in_progress;974975/* Auto-Hibernate Idle Timer register value */976u32 ahit;977978struct ufshcd_lrb *lrb;979980unsigned long outstanding_tasks;981spinlock_t outstanding_lock;982unsigned long outstanding_reqs;983984u32 capabilities;985int nutrs;986int nortt;987u32 mcq_capabilities;988int nutmrs;989u32 reserved_slot;990u32 ufs_version;991const struct ufs_hba_variant_ops *vops;992struct ufs_hba_variant_params *vps;993void *priv;994#ifdef CONFIG_SCSI_UFS_VARIABLE_SG_ENTRY_SIZE995size_t sg_entry_size;996#endif997unsigned int irq;998bool is_irq_enabled;999enum ufs_ref_clk_freq dev_ref_clk_freq;10001001unsigned int quirks; /* Deviations from standard UFSHCI spec. */10021003/* Device deviations from standard UFS device spec. */1004unsigned int dev_quirks;10051006struct blk_mq_tag_set tmf_tag_set;1007struct request_queue *tmf_queue;1008struct request **tmf_rqs;10091010struct uic_command *active_uic_cmd;1011struct mutex uic_cmd_mutex;1012struct completion *uic_async_done;10131014enum ufshcd_state ufshcd_state;1015u32 eh_flags;1016u32 intr_mask;1017u16 ee_ctrl_mask;1018u16 ee_drv_mask;1019u16 ee_usr_mask;1020struct mutex ee_ctrl_mutex;1021bool is_powered;1022bool shutting_down;1023struct semaphore host_sem;10241025/* Work Queues */1026struct workqueue_struct *eh_wq;1027struct work_struct eh_work;1028struct work_struct eeh_work;10291030/* HBA Errors */1031u32 errors;1032u32 uic_error;1033u32 saved_err;1034u32 saved_uic_err;1035struct ufs_stats ufs_stats;1036bool force_reset;1037bool force_pmc;1038bool silence_err_logs;10391040/* Device management request data */1041struct ufs_dev_cmd dev_cmd;1042ktime_t last_dme_cmd_tstamp;1043int nop_out_timeout;10441045/* Keeps information of the UFS device connected to this host */1046struct ufs_dev_info dev_info;1047bool auto_bkops_enabled;1048struct ufs_vreg_info vreg_info;1049struct list_head clk_list_head;1050bool use_pm_opp;10511052/* Number of requests aborts */1053int req_abort_count;10541055/* Number of lanes available (1 or 2) for Rx/Tx */1056u32 lanes_per_direction;1057struct ufs_pa_layer_attr pwr_info;1058struct ufs_pwr_mode_info max_pwr_info;10591060struct ufs_clk_gating clk_gating;1061/* Control to enable/disable host capabilities */1062u32 caps;10631064struct devfreq *devfreq;1065struct ufs_clk_scaling clk_scaling;1066bool system_suspending;1067bool is_sys_suspended;10681069enum bkops_status urgent_bkops_lvl;1070bool is_urgent_bkops_lvl_checked;10711072struct mutex wb_mutex;1073struct rw_semaphore clk_scaling_lock;10741075struct device bsg_dev;1076struct request_queue *bsg_queue;1077struct delayed_work rpm_dev_flush_recheck_work;10781079struct ufs_hba_monitor monitor;10801081#ifdef CONFIG_SCSI_UFS_CRYPTO1082union ufs_crypto_capabilities crypto_capabilities;1083union ufs_crypto_cap_entry *crypto_cap_array;1084u32 crypto_cfg_register;1085struct blk_crypto_profile crypto_profile;1086#endif1087#ifdef CONFIG_DEBUG_FS1088struct dentry *debugfs_root;1089struct delayed_work debugfs_ee_work;1090u32 debugfs_ee_rate_limit_ms;1091#endif1092#ifdef CONFIG_SCSI_UFS_FAULT_INJECTION1093struct fault_attr trigger_eh_attr;1094struct fault_attr timeout_attr;1095#endif1096u32 luns_avail;1097unsigned int nr_hw_queues;1098unsigned int nr_queues[HCTX_MAX_TYPES];1099bool complete_put;1100bool scsi_host_added;1101bool mcq_sup;1102bool lsdb_sup;1103bool mcq_enabled;1104bool mcq_esi_enabled;1105void __iomem *mcq_base;1106struct ufs_hw_queue *uhq;1107struct ufs_hw_queue *dev_cmd_queue;1108struct ufshcd_mcq_opr_info_t mcq_opr[OPR_MAX];11091110struct delayed_work ufs_rtc_update_work;1111struct pm_qos_request pm_qos_req;1112bool pm_qos_enabled;1113/* synchronizes PM QoS request and status updates */1114struct mutex pm_qos_mutex;11151116int critical_health_count;1117atomic_t dev_lvl_exception_count;1118u64 dev_lvl_exception_id;1119};11201121/**1122* struct ufs_hw_queue - per hardware queue structure1123* @mcq_sq_head: base address of submission queue head pointer1124* @mcq_sq_tail: base address of submission queue tail pointer1125* @mcq_cq_head: base address of completion queue head pointer1126* @mcq_cq_tail: base address of completion queue tail pointer1127* @sqe_base_addr: submission queue entry base address1128* @sqe_dma_addr: submission queue dma address1129* @cqe_base_addr: completion queue base address1130* @cqe_dma_addr: completion queue dma address1131* @max_entries: max number of slots in this hardware queue1132* @id: hardware queue ID1133* @sq_tp_slot: current slot to which SQ tail pointer is pointing1134* @sq_lock: serialize submission queue access1135* @cq_tail_slot: current slot to which CQ tail pointer is pointing1136* @cq_head_slot: current slot to which CQ head pointer is pointing1137* @cq_lock: Synchronize between multiple polling instances1138* @sq_mutex: prevent submission queue concurrent access1139*/1140struct ufs_hw_queue {1141void __iomem *mcq_sq_head;1142void __iomem *mcq_sq_tail;1143void __iomem *mcq_cq_head;1144void __iomem *mcq_cq_tail;11451146struct utp_transfer_req_desc *sqe_base_addr;1147dma_addr_t sqe_dma_addr;1148struct cq_entry *cqe_base_addr;1149dma_addr_t cqe_dma_addr;1150u32 max_entries;1151u32 id;1152u32 sq_tail_slot;1153spinlock_t sq_lock;1154u32 cq_tail_slot;1155u32 cq_head_slot;1156spinlock_t cq_lock;1157/* prevent concurrent access to submission queue */1158struct mutex sq_mutex;1159};11601161#define MCQ_QCFG_SIZE 0x4011621163static inline unsigned int ufshcd_mcq_opr_offset(struct ufs_hba *hba,1164enum ufshcd_mcq_opr opr, int idx)1165{1166return hba->mcq_opr[opr].offset + hba->mcq_opr[opr].stride * idx;1167}11681169static inline unsigned int ufshcd_mcq_cfg_offset(unsigned int reg, int idx)1170{1171return reg + MCQ_QCFG_SIZE * idx;1172}11731174#ifdef CONFIG_SCSI_UFS_VARIABLE_SG_ENTRY_SIZE1175static inline size_t ufshcd_sg_entry_size(const struct ufs_hba *hba)1176{1177return hba->sg_entry_size;1178}11791180static inline void ufshcd_set_sg_entry_size(struct ufs_hba *hba, size_t sg_entry_size)1181{1182WARN_ON_ONCE(sg_entry_size < sizeof(struct ufshcd_sg_entry));1183hba->sg_entry_size = sg_entry_size;1184}1185#else1186static inline size_t ufshcd_sg_entry_size(const struct ufs_hba *hba)1187{1188return sizeof(struct ufshcd_sg_entry);1189}11901191#define ufshcd_set_sg_entry_size(hba, sg_entry_size) \1192({ (void)(hba); BUILD_BUG_ON(sg_entry_size != sizeof(struct ufshcd_sg_entry)); })1193#endif11941195#ifdef CONFIG_SCSI_UFS_CRYPTO1196static inline struct ufs_hba *1197ufs_hba_from_crypto_profile(struct blk_crypto_profile *profile)1198{1199return container_of(profile, struct ufs_hba, crypto_profile);1200}1201#endif12021203static inline size_t ufshcd_get_ucd_size(const struct ufs_hba *hba)1204{1205return sizeof(struct utp_transfer_cmd_desc) + SG_ALL * ufshcd_sg_entry_size(hba);1206}12071208/* Returns true if clocks can be gated. Otherwise false */1209static inline bool ufshcd_is_clkgating_allowed(struct ufs_hba *hba)1210{1211return hba->caps & UFSHCD_CAP_CLK_GATING;1212}1213static inline bool ufshcd_can_hibern8_during_gating(struct ufs_hba *hba)1214{1215return hba->caps & UFSHCD_CAP_HIBERN8_WITH_CLK_GATING;1216}1217static inline int ufshcd_is_clkscaling_supported(struct ufs_hba *hba)1218{1219return hba->caps & UFSHCD_CAP_CLK_SCALING;1220}1221static inline bool ufshcd_can_autobkops_during_suspend(struct ufs_hba *hba)1222{1223return hba->caps & UFSHCD_CAP_AUTO_BKOPS_SUSPEND;1224}1225static inline bool ufshcd_is_rpm_autosuspend_allowed(struct ufs_hba *hba)1226{1227return hba->caps & UFSHCD_CAP_RPM_AUTOSUSPEND;1228}12291230static inline bool ufshcd_is_intr_aggr_allowed(struct ufs_hba *hba)1231{1232return (hba->caps & UFSHCD_CAP_INTR_AGGR) &&1233!(hba->quirks & UFSHCD_QUIRK_BROKEN_INTR_AGGR);1234}12351236static inline bool ufshcd_can_aggressive_pc(struct ufs_hba *hba)1237{1238return !!(ufshcd_is_link_hibern8(hba) &&1239(hba->caps & UFSHCD_CAP_AGGR_POWER_COLLAPSE));1240}12411242static inline bool ufshcd_is_auto_hibern8_supported(struct ufs_hba *hba)1243{1244return (hba->capabilities & MASK_AUTO_HIBERN8_SUPPORT) &&1245!(hba->quirks & UFSHCD_QUIRK_BROKEN_AUTO_HIBERN8);1246}12471248static inline bool ufshcd_is_auto_hibern8_enabled(struct ufs_hba *hba)1249{1250return FIELD_GET(UFSHCI_AHIBERN8_TIMER_MASK, hba->ahit);1251}12521253static inline bool ufshcd_is_wb_allowed(struct ufs_hba *hba)1254{1255return hba->caps & UFSHCD_CAP_WB_EN;1256}12571258static inline bool ufshcd_enable_wb_if_scaling_up(struct ufs_hba *hba)1259{1260return hba->caps & UFSHCD_CAP_WB_WITH_CLK_SCALING;1261}12621263#define ufsmcq_writel(hba, val, reg) \1264writel((val), (hba)->mcq_base + (reg))1265#define ufsmcq_readl(hba, reg) \1266readl((hba)->mcq_base + (reg))12671268#define ufsmcq_writelx(hba, val, reg) \1269writel_relaxed((val), (hba)->mcq_base + (reg))1270#define ufsmcq_readlx(hba, reg) \1271readl_relaxed((hba)->mcq_base + (reg))12721273#define ufshcd_writel(hba, val, reg) \1274writel((val), (hba)->mmio_base + (reg))1275#define ufshcd_readl(hba, reg) \1276readl((hba)->mmio_base + (reg))12771278/**1279* ufshcd_rmwl - perform read/modify/write for a controller register1280* @hba: per adapter instance1281* @mask: mask to apply on read value1282* @val: actual value to write1283* @reg: register address1284*/1285static inline void ufshcd_rmwl(struct ufs_hba *hba, u32 mask, u32 val, u32 reg)1286{1287u32 tmp;12881289tmp = ufshcd_readl(hba, reg);1290tmp &= ~mask;1291tmp |= (val & mask);1292ufshcd_writel(hba, tmp, reg);1293}12941295void ufshcd_enable_irq(struct ufs_hba *hba);1296void ufshcd_disable_irq(struct ufs_hba *hba);1297void ufshcd_enable_intr(struct ufs_hba *hba, u32 intrs);1298int ufshcd_alloc_host(struct device *, struct ufs_hba **);1299int ufshcd_hba_enable(struct ufs_hba *hba);1300int ufshcd_init(struct ufs_hba *, void __iomem *, unsigned int);1301int ufshcd_link_recovery(struct ufs_hba *hba);1302int ufshcd_make_hba_operational(struct ufs_hba *hba);1303void ufshcd_remove(struct ufs_hba *);1304int ufshcd_uic_hibern8_enter(struct ufs_hba *hba);1305int ufshcd_uic_hibern8_exit(struct ufs_hba *hba);1306void ufshcd_delay_us(unsigned long us, unsigned long tolerance);1307void ufshcd_parse_dev_ref_clk_freq(struct ufs_hba *hba, struct clk *refclk);1308void ufshcd_update_evt_hist(struct ufs_hba *hba, u32 id, u32 val);1309void ufshcd_hba_stop(struct ufs_hba *hba);1310void ufshcd_schedule_eh_work(struct ufs_hba *hba);1311void ufshcd_mcq_config_mac(struct ufs_hba *hba, u32 max_active_cmds);1312unsigned int ufshcd_mcq_queue_cfg_addr(struct ufs_hba *hba);1313u32 ufshcd_mcq_read_cqis(struct ufs_hba *hba, int i);1314void ufshcd_mcq_write_cqis(struct ufs_hba *hba, u32 val, int i);1315unsigned long ufshcd_mcq_poll_cqe_lock(struct ufs_hba *hba,1316struct ufs_hw_queue *hwq);1317void ufshcd_mcq_make_queues_operational(struct ufs_hba *hba);1318void ufshcd_mcq_enable(struct ufs_hba *hba);1319void ufshcd_mcq_enable_esi(struct ufs_hba *hba);1320void ufshcd_mcq_config_esi(struct ufs_hba *hba, struct msi_msg *msg);13211322int ufshcd_opp_config_clks(struct device *dev, struct opp_table *opp_table,1323struct dev_pm_opp *opp, void *data,1324bool scaling_down);1325/**1326* ufshcd_set_variant - set variant specific data to the hba1327* @hba: per adapter instance1328* @variant: pointer to variant specific data1329*/1330static inline void ufshcd_set_variant(struct ufs_hba *hba, void *variant)1331{1332BUG_ON(!hba);1333hba->priv = variant;1334}13351336/**1337* ufshcd_get_variant - get variant specific data from the hba1338* @hba: per adapter instance1339*/1340static inline void *ufshcd_get_variant(struct ufs_hba *hba)1341{1342BUG_ON(!hba);1343return hba->priv;1344}13451346#ifdef CONFIG_PM1347extern int ufshcd_runtime_suspend(struct device *dev);1348extern int ufshcd_runtime_resume(struct device *dev);1349#endif1350#ifdef CONFIG_PM_SLEEP1351extern int ufshcd_system_suspend(struct device *dev);1352extern int ufshcd_system_resume(struct device *dev);1353extern int ufshcd_system_freeze(struct device *dev);1354extern int ufshcd_system_thaw(struct device *dev);1355extern int ufshcd_system_restore(struct device *dev);1356#endif13571358extern int ufshcd_dme_reset(struct ufs_hba *hba);1359extern int ufshcd_dme_enable(struct ufs_hba *hba);1360extern int ufshcd_dme_configure_adapt(struct ufs_hba *hba,1361int agreed_gear,1362int adapt_val);1363extern int ufshcd_dme_set_attr(struct ufs_hba *hba, u32 attr_sel,1364u8 attr_set, u32 mib_val, u8 peer);1365extern int ufshcd_dme_get_attr(struct ufs_hba *hba, u32 attr_sel,1366u32 *mib_val, u8 peer);1367extern int ufshcd_config_pwr_mode(struct ufs_hba *hba,1368struct ufs_pa_layer_attr *desired_pwr_mode);1369extern int ufshcd_uic_change_pwr_mode(struct ufs_hba *hba, u8 mode);13701371/* UIC command interfaces for DME primitives */1372#define DME_LOCAL 01373#define DME_PEER 11374#define ATTR_SET_NOR 0 /* NORMAL */1375#define ATTR_SET_ST 1 /* STATIC */13761377static inline int ufshcd_dme_set(struct ufs_hba *hba, u32 attr_sel,1378u32 mib_val)1379{1380return ufshcd_dme_set_attr(hba, attr_sel, ATTR_SET_NOR,1381mib_val, DME_LOCAL);1382}13831384static inline int ufshcd_dme_st_set(struct ufs_hba *hba, u32 attr_sel,1385u32 mib_val)1386{1387return ufshcd_dme_set_attr(hba, attr_sel, ATTR_SET_ST,1388mib_val, DME_LOCAL);1389}13901391static inline int ufshcd_dme_peer_set(struct ufs_hba *hba, u32 attr_sel,1392u32 mib_val)1393{1394return ufshcd_dme_set_attr(hba, attr_sel, ATTR_SET_NOR,1395mib_val, DME_PEER);1396}13971398static inline int ufshcd_dme_peer_st_set(struct ufs_hba *hba, u32 attr_sel,1399u32 mib_val)1400{1401return ufshcd_dme_set_attr(hba, attr_sel, ATTR_SET_ST,1402mib_val, DME_PEER);1403}14041405static inline int ufshcd_dme_get(struct ufs_hba *hba,1406u32 attr_sel, u32 *mib_val)1407{1408return ufshcd_dme_get_attr(hba, attr_sel, mib_val, DME_LOCAL);1409}14101411static inline int ufshcd_dme_peer_get(struct ufs_hba *hba,1412u32 attr_sel, u32 *mib_val)1413{1414return ufshcd_dme_get_attr(hba, attr_sel, mib_val, DME_PEER);1415}14161417static inline bool ufshcd_is_hs_mode(const struct ufs_pa_layer_attr *pwr_info)1418{1419return (pwr_info->pwr_rx == FAST_MODE ||1420pwr_info->pwr_rx == FASTAUTO_MODE) &&1421(pwr_info->pwr_tx == FAST_MODE ||1422pwr_info->pwr_tx == FASTAUTO_MODE);1423}14241425static inline int ufshcd_disable_host_tx_lcc(struct ufs_hba *hba)1426{1427return ufshcd_dme_set(hba, UIC_ARG_MIB(PA_LOCAL_TX_LCC_ENABLE), 0);1428}14291430void ufshcd_auto_hibern8_update(struct ufs_hba *hba, u32 ahit);1431void ufshcd_fixup_dev_quirks(struct ufs_hba *hba,1432const struct ufs_dev_quirk *fixups);1433#define SD_ASCII_STD true1434#define SD_RAW false1435int ufshcd_read_string_desc(struct ufs_hba *hba, u8 desc_index,1436u8 **buf, bool ascii);14371438void ufshcd_hold(struct ufs_hba *hba);1439void ufshcd_release(struct ufs_hba *hba);14401441void ufshcd_clkgate_delay_set(struct device *dev, unsigned long value);14421443int ufshcd_get_vreg(struct device *dev, struct ufs_vreg *vreg);14441445int ufshcd_send_uic_cmd(struct ufs_hba *hba, struct uic_command *uic_cmd);14461447int ufshcd_advanced_rpmb_req_handler(struct ufs_hba *hba, struct utp_upiu_req *req_upiu,1448struct utp_upiu_req *rsp_upiu, struct ufs_ehs *ehs_req,1449struct ufs_ehs *ehs_rsp, int sg_cnt,1450struct scatterlist *sg_list, enum dma_data_direction dir);1451int ufshcd_wb_toggle(struct ufs_hba *hba, bool enable);1452int ufshcd_wb_toggle_buf_flush(struct ufs_hba *hba, bool enable);1453int ufshcd_wb_set_resize_en(struct ufs_hba *hba, enum wb_resize_en en_mode);1454int ufshcd_suspend_prepare(struct device *dev);1455int __ufshcd_suspend_prepare(struct device *dev, bool rpm_ok_for_spm);1456void ufshcd_resume_complete(struct device *dev);1457bool ufshcd_is_hba_active(struct ufs_hba *hba);1458void ufshcd_pm_qos_init(struct ufs_hba *hba);1459void ufshcd_pm_qos_exit(struct ufs_hba *hba);1460int ufshcd_dme_rmw(struct ufs_hba *hba, u32 mask, u32 val, u32 attr);14611462/* Wrapper functions for safely calling variant operations */1463static inline int ufshcd_vops_init(struct ufs_hba *hba)1464{1465if (hba->vops && hba->vops->init)1466return hba->vops->init(hba);14671468return 0;1469}14701471static inline int ufshcd_vops_phy_initialization(struct ufs_hba *hba)1472{1473if (hba->vops && hba->vops->phy_initialization)1474return hba->vops->phy_initialization(hba);14751476return 0;1477}14781479extern const struct ufs_pm_lvl_states ufs_pm_lvl_states[];14801481int ufshcd_dump_regs(struct ufs_hba *hba, size_t offset, size_t len,1482const char *prefix);14831484int __ufshcd_write_ee_control(struct ufs_hba *hba, u32 ee_ctrl_mask);1485int ufshcd_write_ee_control(struct ufs_hba *hba);1486int ufshcd_update_ee_control(struct ufs_hba *hba, u16 *mask,1487const u16 *other_mask, u16 set, u16 clr);1488void ufshcd_force_error_recovery(struct ufs_hba *hba);14891490#endif /* End of Header */149114921493