#include <linux/bio-integrity.h>
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/kernel.h>
#include <linux/mm.h>
#include <linux/bio-integrity.h>
#include <linux/hdreg.h>
#include <linux/errno.h>
#include <linux/idr.h>
#include <linux/interrupt.h>
#include <linux/init.h>
#include <linux/blkdev.h>
#include <linux/blkpg.h>
#include <linux/blk-pm.h>
#include <linux/delay.h>
#include <linux/rw_hint.h>
#include <linux/major.h>
#include <linux/mutex.h>
#include <linux/string_helpers.h>
#include <linux/slab.h>
#include <linux/sed-opal.h>
#include <linux/pm_runtime.h>
#include <linux/pr.h>
#include <linux/t10-pi.h>
#include <linux/uaccess.h>
#include <asm/unaligned.h>
#include <scsi/scsi.h>
#include <scsi/scsi_cmnd.h>
#include <scsi/scsi_dbg.h>
#include <scsi/scsi_device.h>
#include <scsi/scsi_devinfo.h>
#include <scsi/scsi_driver.h>
#include <scsi/scsi_eh.h>
#include <scsi/scsi_host.h>
#include <scsi/scsi_ioctl.h>
#include <scsi/scsicam.h>
#include <scsi/scsi_common.h>
#include "sd.h"
#include "scsi_priv.h"
#include "scsi_logging.h"
MODULE_AUTHOR(…) …;
MODULE_DESCRIPTION(…) …;
MODULE_LICENSE(…) …;
MODULE_ALIAS_BLOCKDEV_MAJOR(…);
MODULE_ALIAS_BLOCKDEV_MAJOR(…);
MODULE_ALIAS_BLOCKDEV_MAJOR(…);
MODULE_ALIAS_BLOCKDEV_MAJOR(…);
MODULE_ALIAS_BLOCKDEV_MAJOR(…);
MODULE_ALIAS_BLOCKDEV_MAJOR(…);
MODULE_ALIAS_BLOCKDEV_MAJOR(…);
MODULE_ALIAS_BLOCKDEV_MAJOR(…);
MODULE_ALIAS_BLOCKDEV_MAJOR(…);
MODULE_ALIAS_BLOCKDEV_MAJOR(…);
MODULE_ALIAS_BLOCKDEV_MAJOR(…);
MODULE_ALIAS_BLOCKDEV_MAJOR(…);
MODULE_ALIAS_BLOCKDEV_MAJOR(…);
MODULE_ALIAS_BLOCKDEV_MAJOR(…);
MODULE_ALIAS_BLOCKDEV_MAJOR(…);
MODULE_ALIAS_BLOCKDEV_MAJOR(…);
MODULE_ALIAS_SCSI_DEVICE(…);
MODULE_ALIAS_SCSI_DEVICE(…);
MODULE_ALIAS_SCSI_DEVICE(…);
MODULE_ALIAS_SCSI_DEVICE(…);
#define SD_MINORS …
static void sd_config_discard(struct scsi_disk *sdkp, struct queue_limits *lim,
unsigned int mode);
static void sd_config_write_same(struct scsi_disk *sdkp,
struct queue_limits *lim);
static int sd_revalidate_disk(struct gendisk *);
static void sd_unlock_native_capacity(struct gendisk *disk);
static void sd_shutdown(struct device *);
static void scsi_disk_release(struct device *cdev);
static DEFINE_IDA(sd_index_ida);
static mempool_t *sd_page_pool;
static struct lock_class_key sd_bio_compl_lkclass;
static const char *sd_cache_types[] = …;
static void sd_set_flush_flag(struct scsi_disk *sdkp,
struct queue_limits *lim)
{ … }
static ssize_t
cache_type_store(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{ … }
static ssize_t
manage_start_stop_show(struct device *dev,
struct device_attribute *attr, char *buf)
{ … }
static DEVICE_ATTR_RO(manage_start_stop);
static ssize_t
manage_system_start_stop_show(struct device *dev,
struct device_attribute *attr, char *buf)
{ … }
static ssize_t
manage_system_start_stop_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{ … }
static DEVICE_ATTR_RW(manage_system_start_stop);
static ssize_t
manage_runtime_start_stop_show(struct device *dev,
struct device_attribute *attr, char *buf)
{ … }
static ssize_t
manage_runtime_start_stop_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{ … }
static DEVICE_ATTR_RW(manage_runtime_start_stop);
static ssize_t manage_shutdown_show(struct device *dev,
struct device_attribute *attr, char *buf)
{ … }
static ssize_t manage_shutdown_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{ … }
static DEVICE_ATTR_RW(manage_shutdown);
static ssize_t
allow_restart_show(struct device *dev, struct device_attribute *attr, char *buf)
{ … }
static ssize_t
allow_restart_store(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{ … }
static DEVICE_ATTR_RW(allow_restart);
static ssize_t
cache_type_show(struct device *dev, struct device_attribute *attr, char *buf)
{ … }
static DEVICE_ATTR_RW(cache_type);
static ssize_t
FUA_show(struct device *dev, struct device_attribute *attr, char *buf)
{ … }
static DEVICE_ATTR_RO(FUA);
static ssize_t
protection_type_show(struct device *dev, struct device_attribute *attr,
char *buf)
{ … }
static ssize_t
protection_type_store(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{ … }
static DEVICE_ATTR_RW(protection_type);
static ssize_t
protection_mode_show(struct device *dev, struct device_attribute *attr,
char *buf)
{ … }
static DEVICE_ATTR_RO(protection_mode);
static ssize_t
app_tag_own_show(struct device *dev, struct device_attribute *attr, char *buf)
{ … }
static DEVICE_ATTR_RO(app_tag_own);
static ssize_t
thin_provisioning_show(struct device *dev, struct device_attribute *attr,
char *buf)
{ … }
static DEVICE_ATTR_RO(thin_provisioning);
static const char *lbp_mode[] = …;
static ssize_t
provisioning_mode_show(struct device *dev, struct device_attribute *attr,
char *buf)
{ … }
static ssize_t
provisioning_mode_store(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{ … }
static DEVICE_ATTR_RW(provisioning_mode);
static const char *zeroing_mode[] = …;
static ssize_t
zeroing_mode_show(struct device *dev, struct device_attribute *attr,
char *buf)
{ … }
static ssize_t
zeroing_mode_store(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{ … }
static DEVICE_ATTR_RW(zeroing_mode);
static ssize_t
max_medium_access_timeouts_show(struct device *dev,
struct device_attribute *attr, char *buf)
{ … }
static ssize_t
max_medium_access_timeouts_store(struct device *dev,
struct device_attribute *attr, const char *buf,
size_t count)
{ … }
static DEVICE_ATTR_RW(max_medium_access_timeouts);
static ssize_t
max_write_same_blocks_show(struct device *dev, struct device_attribute *attr,
char *buf)
{ … }
static ssize_t
max_write_same_blocks_store(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{ … }
static DEVICE_ATTR_RW(max_write_same_blocks);
static ssize_t
zoned_cap_show(struct device *dev, struct device_attribute *attr, char *buf)
{ … }
static DEVICE_ATTR_RO(zoned_cap);
static ssize_t
max_retries_store(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{ … }
static ssize_t
max_retries_show(struct device *dev, struct device_attribute *attr,
char *buf)
{ … }
static DEVICE_ATTR_RW(max_retries);
static struct attribute *sd_disk_attrs[] = …;
ATTRIBUTE_GROUPS(…);
static struct class sd_disk_class = …;
static void sd_default_probe(dev_t devt)
{ … }
static int sd_major(int major_idx)
{ … }
#ifdef CONFIG_BLK_SED_OPAL
static int sd_sec_submit(void *data, u16 spsp, u8 secp, void *buffer,
size_t len, bool send)
{ … }
#endif
static unsigned int sd_prot_op(bool write, bool dix, bool dif)
{ … }
static unsigned int sd_prot_flag_mask(unsigned int prot_op)
{ … }
static unsigned char sd_setup_protect_cmnd(struct scsi_cmnd *scmd,
unsigned int dix, unsigned int dif)
{ … }
static void sd_disable_discard(struct scsi_disk *sdkp)
{ … }
static void sd_config_discard(struct scsi_disk *sdkp, struct queue_limits *lim,
unsigned int mode)
{ … }
static void *sd_set_special_bvec(struct request *rq, unsigned int data_len)
{ … }
static blk_status_t sd_setup_unmap_cmnd(struct scsi_cmnd *cmd)
{ … }
static void sd_config_atomic(struct scsi_disk *sdkp, struct queue_limits *lim)
{ … }
static blk_status_t sd_setup_write_same16_cmnd(struct scsi_cmnd *cmd,
bool unmap)
{ … }
static blk_status_t sd_setup_write_same10_cmnd(struct scsi_cmnd *cmd,
bool unmap)
{ … }
static blk_status_t sd_setup_write_zeroes_cmnd(struct scsi_cmnd *cmd)
{ … }
static void sd_disable_write_same(struct scsi_disk *sdkp)
{ … }
static void sd_config_write_same(struct scsi_disk *sdkp,
struct queue_limits *lim)
{ … }
static blk_status_t sd_setup_flush_cmnd(struct scsi_cmnd *cmd)
{ … }
static u8 sd_group_number(struct scsi_cmnd *cmd)
{ … }
static blk_status_t sd_setup_rw32_cmnd(struct scsi_cmnd *cmd, bool write,
sector_t lba, unsigned int nr_blocks,
unsigned char flags, unsigned int dld)
{ … }
static blk_status_t sd_setup_rw16_cmnd(struct scsi_cmnd *cmd, bool write,
sector_t lba, unsigned int nr_blocks,
unsigned char flags, unsigned int dld)
{ … }
static blk_status_t sd_setup_rw10_cmnd(struct scsi_cmnd *cmd, bool write,
sector_t lba, unsigned int nr_blocks,
unsigned char flags)
{ … }
static blk_status_t sd_setup_rw6_cmnd(struct scsi_cmnd *cmd, bool write,
sector_t lba, unsigned int nr_blocks,
unsigned char flags)
{ … }
static int sd_cdl_dld(struct scsi_disk *sdkp, struct scsi_cmnd *scmd)
{ … }
static blk_status_t sd_setup_atomic_cmnd(struct scsi_cmnd *cmd,
sector_t lba, unsigned int nr_blocks,
bool boundary, unsigned char flags)
{ … }
static blk_status_t sd_setup_read_write_cmnd(struct scsi_cmnd *cmd)
{ … }
static blk_status_t sd_init_command(struct scsi_cmnd *cmd)
{ … }
static void sd_uninit_command(struct scsi_cmnd *SCpnt)
{ … }
static bool sd_need_revalidate(struct gendisk *disk, struct scsi_disk *sdkp)
{ … }
static int sd_open(struct gendisk *disk, blk_mode_t mode)
{ … }
static void sd_release(struct gendisk *disk)
{ … }
static int sd_getgeo(struct block_device *bdev, struct hd_geometry *geo)
{ … }
static int sd_ioctl(struct block_device *bdev, blk_mode_t mode,
unsigned int cmd, unsigned long arg)
{ … }
static void set_media_not_present(struct scsi_disk *sdkp)
{ … }
static int media_not_present(struct scsi_disk *sdkp,
struct scsi_sense_hdr *sshdr)
{ … }
static unsigned int sd_check_events(struct gendisk *disk, unsigned int clearing)
{ … }
static int sd_sync_cache(struct scsi_disk *sdkp)
{ … }
static void sd_rescan(struct device *dev)
{ … }
static int sd_get_unique_id(struct gendisk *disk, u8 id[16],
enum blk_unique_id type)
{ … }
static int sd_scsi_to_pr_err(struct scsi_sense_hdr *sshdr, int result)
{ … }
static int sd_pr_in_command(struct block_device *bdev, u8 sa,
unsigned char *data, int data_len)
{ … }
static int sd_pr_read_keys(struct block_device *bdev, struct pr_keys *keys_info)
{ … }
static int sd_pr_read_reservation(struct block_device *bdev,
struct pr_held_reservation *rsv)
{ … }
static int sd_pr_out_command(struct block_device *bdev, u8 sa, u64 key,
u64 sa_key, enum scsi_pr_type type, u8 flags)
{ … }
static int sd_pr_register(struct block_device *bdev, u64 old_key, u64 new_key,
u32 flags)
{ … }
static int sd_pr_reserve(struct block_device *bdev, u64 key, enum pr_type type,
u32 flags)
{ … }
static int sd_pr_release(struct block_device *bdev, u64 key, enum pr_type type)
{ … }
static int sd_pr_preempt(struct block_device *bdev, u64 old_key, u64 new_key,
enum pr_type type, bool abort)
{ … }
static int sd_pr_clear(struct block_device *bdev, u64 key)
{ … }
static const struct pr_ops sd_pr_ops = …;
static void scsi_disk_free_disk(struct gendisk *disk)
{ … }
static const struct block_device_operations sd_fops = …;
static void sd_eh_reset(struct scsi_cmnd *scmd)
{ … }
static int sd_eh_action(struct scsi_cmnd *scmd, int eh_disp)
{ … }
static unsigned int sd_completed_bytes(struct scsi_cmnd *scmd)
{ … }
static int sd_done(struct scsi_cmnd *SCpnt)
{ … }
static void
sd_spinup_disk(struct scsi_disk *sdkp)
{ … }
static int sd_read_protection_type(struct scsi_disk *sdkp, unsigned char *buffer)
{ … }
static void sd_config_protection(struct scsi_disk *sdkp,
struct queue_limits *lim)
{ … }
static void read_capacity_error(struct scsi_disk *sdkp, struct scsi_device *sdp,
struct scsi_sense_hdr *sshdr, int sense_valid,
int the_result)
{ … }
#define RC16_LEN …
#if RC16_LEN > SD_BUF_SIZE
#error RC16_LEN must not be more than SD_BUF_SIZE
#endif
#define READ_CAPACITY_RETRIES_ON_RESET …
static int read_capacity_16(struct scsi_disk *sdkp, struct scsi_device *sdp,
struct queue_limits *lim, unsigned char *buffer)
{ … }
static int read_capacity_10(struct scsi_disk *sdkp, struct scsi_device *sdp,
unsigned char *buffer)
{ … }
static int sd_try_rc16_first(struct scsi_device *sdp)
{ … }
static void
sd_read_capacity(struct scsi_disk *sdkp, struct queue_limits *lim,
unsigned char *buffer)
{ … }
static void
sd_print_capacity(struct scsi_disk *sdkp,
sector_t old_capacity)
{ … }
static inline int
sd_do_mode_sense(struct scsi_disk *sdkp, int dbd, int modepage,
unsigned char *buffer, int len, struct scsi_mode_data *data,
struct scsi_sense_hdr *sshdr)
{ … }
static void
sd_read_write_protect_flag(struct scsi_disk *sdkp, unsigned char *buffer)
{ … }
static void
sd_read_cache_type(struct scsi_disk *sdkp, unsigned char *buffer)
{ … }
static bool sd_is_perm_stream(struct scsi_disk *sdkp, unsigned int stream_id)
{ … }
static void sd_read_io_hints(struct scsi_disk *sdkp, unsigned char *buffer)
{ … }
static void sd_read_app_tag_own(struct scsi_disk *sdkp, unsigned char *buffer)
{ … }
static unsigned int sd_discard_mode(struct scsi_disk *sdkp)
{ … }
static void sd_read_block_limits(struct scsi_disk *sdkp,
struct queue_limits *lim)
{ … }
static void sd_read_block_limits_ext(struct scsi_disk *sdkp)
{ … }
static void sd_read_block_characteristics(struct scsi_disk *sdkp,
struct queue_limits *lim)
{ … }
static void sd_read_block_provisioning(struct scsi_disk *sdkp)
{ … }
static void sd_read_write_same(struct scsi_disk *sdkp, unsigned char *buffer)
{ … }
static void sd_read_security(struct scsi_disk *sdkp, unsigned char *buffer)
{ … }
static inline sector_t sd64_to_sectors(struct scsi_disk *sdkp, u8 *buf)
{ … }
static void sd_read_cpr(struct scsi_disk *sdkp)
{ … }
static bool sd_validate_min_xfer_size(struct scsi_disk *sdkp)
{ … }
static bool sd_validate_opt_xfer_size(struct scsi_disk *sdkp,
unsigned int dev_max)
{ … }
static void sd_read_block_zero(struct scsi_disk *sdkp)
{ … }
static int sd_revalidate_disk(struct gendisk *disk)
{ … }
static void sd_unlock_native_capacity(struct gendisk *disk)
{ … }
static int sd_format_disk_name(char *prefix, int index, char *buf, int buflen)
{ … }
static int sd_probe(struct device *dev)
{ … }
static int sd_remove(struct device *dev)
{ … }
static void scsi_disk_release(struct device *dev)
{ … }
static int sd_start_stop_device(struct scsi_disk *sdkp, int start)
{ … }
static void sd_shutdown(struct device *dev)
{ … }
static inline bool sd_do_start_stop(struct scsi_device *sdev, bool runtime)
{ … }
static int sd_suspend_common(struct device *dev, bool runtime)
{ … }
static int sd_suspend_system(struct device *dev)
{ … }
static int sd_suspend_runtime(struct device *dev)
{ … }
static int sd_resume(struct device *dev)
{ … }
static int sd_resume_common(struct device *dev, bool runtime)
{ … }
static int sd_resume_system(struct device *dev)
{ … }
static int sd_resume_runtime(struct device *dev)
{ … }
static const struct dev_pm_ops sd_pm_ops = …;
static struct scsi_driver sd_template = …;
static int __init init_sd(void)
{ … }
static void __exit exit_sd(void)
{ … }
module_init(…) …;
module_exit(exit_sd);
void sd_print_sense_hdr(struct scsi_disk *sdkp, struct scsi_sense_hdr *sshdr)
{ … }
void sd_print_result(const struct scsi_disk *sdkp, const char *msg, int result)
{ … }