blob: f6f3bc52c1ac2e21611ba7be2a274c7cb442166d [file] [log] [blame]
Christoph Hellwigc4795fb2011-11-16 09:46:48 -05001#ifndef TARGET_CORE_BACKEND_H
2#define TARGET_CORE_BACKEND_H
3
Andy Grovera3541702015-05-19 14:44:41 -07004#define TRANSPORT_FLAG_PASSTHROUGH 1
Christoph Hellwigc4795fb2011-11-16 09:46:48 -05005
Christoph Hellwig0a06d432015-05-10 18:14:56 +02006struct target_backend_ops {
Christoph Hellwigc4795fb2011-11-16 09:46:48 -05007 char name[16];
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04008 char inquiry_prod[16];
9 char inquiry_rev[4];
Christoph Hellwigc4795fb2011-11-16 09:46:48 -050010 struct module *owner;
11
Andy Grovera3541702015-05-19 14:44:41 -070012 u8 transport_flags;
Christoph Hellwigc4795fb2011-11-16 09:46:48 -050013
Christoph Hellwigc4795fb2011-11-16 09:46:48 -050014 int (*attach_hba)(struct se_hba *, u32);
15 void (*detach_hba)(struct se_hba *);
16 int (*pmode_enable_hba)(struct se_hba *, unsigned long);
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -040017
18 struct se_device *(*alloc_device)(struct se_hba *, const char *);
19 int (*configure_device)(struct se_device *);
20 void (*free_device)(struct se_device *device);
21
22 ssize_t (*set_configfs_dev_params)(struct se_device *,
23 const char *, ssize_t);
24 ssize_t (*show_configfs_dev_params)(struct se_device *, char *);
25
Paolo Bonzinid5829ea2012-09-05 17:09:15 +020026 void (*transport_complete)(struct se_cmd *cmd,
27 struct scatterlist *,
28 unsigned char *);
Christoph Hellwigd6e01752012-05-20 11:59:14 -040029
Christoph Hellwigde103c92012-11-06 12:24:09 -080030 sense_reason_t (*parse_cdb)(struct se_cmd *cmd);
Christoph Hellwigc4795fb2011-11-16 09:46:48 -050031 u32 (*get_device_type)(struct se_device *);
32 sector_t (*get_blocks)(struct se_device *);
Andy Grover7f7caf62013-11-11 08:59:17 -080033 sector_t (*get_alignment_offset_lbas)(struct se_device *);
34 /* lbppbe = logical blocks per physical block exponent. see SBC-3 */
35 unsigned int (*get_lbppbe)(struct se_device *);
36 unsigned int (*get_io_min)(struct se_device *);
37 unsigned int (*get_io_opt)(struct se_device *);
Christoph Hellwig5787cac2012-04-24 00:25:06 -040038 unsigned char *(*get_sense_buffer)(struct se_cmd *);
Nicholas Bellingerd0c8b252013-01-29 22:10:06 -080039 bool (*get_write_cache)(struct se_device *);
Nicholas Bellingerce65e5b2013-12-23 20:28:13 +000040 int (*init_prot)(struct se_device *);
41 int (*format_prot)(struct se_device *);
42 void (*free_prot)(struct se_device *);
Nicholas Bellinger73112ed2014-11-27 13:59:20 -080043
Christoph Hellwig0a06d432015-05-10 18:14:56 +020044 struct configfs_attribute **tb_dev_attrib_attrs;
Christoph Hellwigc4795fb2011-11-16 09:46:48 -050045};
46
Christoph Hellwig9e999a62012-10-07 10:55:50 -040047struct sbc_ops {
Nicholas Bellingera82a9532013-08-19 23:57:30 -070048 sense_reason_t (*execute_rw)(struct se_cmd *cmd, struct scatterlist *,
49 u32, enum dma_data_direction);
Christoph Hellwigde103c92012-11-06 12:24:09 -080050 sense_reason_t (*execute_sync_cache)(struct se_cmd *cmd);
51 sense_reason_t (*execute_write_same)(struct se_cmd *cmd);
Christoph Hellwig62e46942015-06-19 15:10:59 +020052 sense_reason_t (*execute_unmap)(struct se_cmd *cmd,
53 sector_t lba, sector_t nolb);
Christoph Hellwig0c2ad7d2012-06-17 18:40:52 -040054};
55
Christoph Hellwig0a06d432015-05-10 18:14:56 +020056int transport_backend_register(const struct target_backend_ops *);
57void target_backend_unregister(const struct target_backend_ops *);
Christoph Hellwigc4795fb2011-11-16 09:46:48 -050058
Christoph Hellwig6bb35e02012-04-23 11:35:33 -040059void target_complete_cmd(struct se_cmd *, u8);
Roland Dreier2426bd42014-06-10 11:07:47 -070060void target_complete_cmd_with_length(struct se_cmd *, u8, int);
Christoph Hellwigc4795fb2011-11-16 09:46:48 -050061
Christoph Hellwigde103c92012-11-06 12:24:09 -080062sense_reason_t spc_parse_cdb(struct se_cmd *cmd, unsigned int *size);
63sense_reason_t spc_emulate_report_luns(struct se_cmd *cmd);
Hannes Reinecke0dfa1c52012-12-17 09:53:35 +010064sense_reason_t spc_emulate_inquiry_std(struct se_cmd *, unsigned char *);
65sense_reason_t spc_emulate_evpd_83(struct se_cmd *, unsigned char *);
Christoph Hellwigd6e01752012-05-20 11:59:14 -040066
Christoph Hellwigde103c92012-11-06 12:24:09 -080067sense_reason_t sbc_parse_cdb(struct se_cmd *cmd, struct sbc_ops *ops);
Christoph Hellwig6f23ac82012-10-07 10:55:53 -040068u32 sbc_get_device_rev(struct se_device *dev);
69u32 sbc_get_device_type(struct se_device *dev);
Roland Dreier972b29c82013-02-22 09:52:57 -080070sector_t sbc_get_write_same_sectors(struct se_cmd *cmd);
Nicholas Bellinger66a3d5b2014-04-02 14:19:09 -070071void sbc_dif_generate(struct se_cmd *);
Sagi Grimbergf75b6fa2015-04-19 20:27:19 +030072sense_reason_t sbc_dif_verify(struct se_cmd *, sector_t, unsigned int,
Nicholas Bellinger41861fa2014-01-07 22:44:57 +000073 unsigned int, struct scatterlist *, int);
Sagi Grimbergf75b6fa2015-04-19 20:27:19 +030074void sbc_dif_copy_prot(struct se_cmd *, unsigned int, bool,
75 struct scatterlist *, int);
Christoph Hellwigc4795fb2011-11-16 09:46:48 -050076void transport_set_vpd_proto_id(struct t10_vpd *, unsigned char *);
77int transport_set_vpd_assoc(struct t10_vpd *, unsigned char *);
78int transport_set_vpd_ident_type(struct t10_vpd *, unsigned char *);
79int transport_set_vpd_ident(struct t10_vpd *, unsigned char *);
80
Christoph Hellwig5873c4d2015-05-10 18:14:57 +020081extern struct configfs_attribute *sbc_attrib_attrs[];
82extern struct configfs_attribute *passthrough_attrib_attrs[];
83
Christoph Hellwigc4795fb2011-11-16 09:46:48 -050084/* core helpers also used by command snooping in pscsi */
Andy Grover49493142012-01-16 16:57:08 -080085void *transport_kmap_data_sg(struct se_cmd *);
86void transport_kunmap_data_sg(struct se_cmd *);
Nicholas Bellingerc5ff8d62013-08-22 11:58:43 -070087/* core helpers also used by xcopy during internal command setup */
Nicholas Bellingerc5ff8d62013-08-22 11:58:43 -070088sense_reason_t transport_generic_map_mem_to_cmd(struct se_cmd *,
89 struct scatterlist *, u32, struct scatterlist *, u32);
Christoph Hellwigc4795fb2011-11-16 09:46:48 -050090
Nicholas Bellinger29a05de2015-03-22 20:42:19 -070091bool target_lun_is_rdonly(struct se_cmd *);
Andy Grover7bfea53b2015-05-19 14:44:40 -070092sense_reason_t passthrough_parse_cdb(struct se_cmd *cmd,
93 sense_reason_t (*exec_cmd)(struct se_cmd *cmd));
Nicholas Bellingerd30cd122014-11-27 19:15:48 -080094
Sagi Grimberg4e4937e2015-07-16 10:28:05 +030095bool target_sense_desc_format(struct se_device *dev);
Mike Christie8a9ebe72016-01-18 14:09:27 -060096sector_t target_to_linux_sector(struct se_device *dev, sector_t lb);
97bool target_configure_unmap_from_queue(struct se_dev_attrib *attrib,
Mike Christieea263c72016-06-02 20:12:37 -050098 struct request_queue *q);
Sagi Grimberg4e4937e2015-07-16 10:28:05 +030099
Christoph Hellwigc4795fb2011-11-16 09:46:48 -0500100#endif /* TARGET_CORE_BACKEND_H */