blob: ff399369a21a009c428ee154364ca47c7905296d [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);
Nicholas Bellingercd063be2012-11-07 20:01:10 -080052 sense_reason_t (*execute_write_same_unmap)(struct se_cmd *cmd);
Christoph Hellwig62e46942015-06-19 15:10:59 +020053 sense_reason_t (*execute_unmap)(struct se_cmd *cmd,
54 sector_t lba, sector_t nolb);
Christoph Hellwig0c2ad7d2012-06-17 18:40:52 -040055};
56
Christoph Hellwig0a06d432015-05-10 18:14:56 +020057int transport_backend_register(const struct target_backend_ops *);
58void target_backend_unregister(const struct target_backend_ops *);
Christoph Hellwigc4795fb2011-11-16 09:46:48 -050059
Christoph Hellwig6bb35e02012-04-23 11:35:33 -040060void target_complete_cmd(struct se_cmd *, u8);
Roland Dreier2426bd42014-06-10 11:07:47 -070061void target_complete_cmd_with_length(struct se_cmd *, u8, int);
Christoph Hellwigc4795fb2011-11-16 09:46:48 -050062
Christoph Hellwigde103c92012-11-06 12:24:09 -080063sense_reason_t spc_parse_cdb(struct se_cmd *cmd, unsigned int *size);
64sense_reason_t spc_emulate_report_luns(struct se_cmd *cmd);
Hannes Reinecke0dfa1c52012-12-17 09:53:35 +010065sense_reason_t spc_emulate_inquiry_std(struct se_cmd *, unsigned char *);
66sense_reason_t spc_emulate_evpd_83(struct se_cmd *, unsigned char *);
Christoph Hellwigd6e01752012-05-20 11:59:14 -040067
Christoph Hellwigde103c92012-11-06 12:24:09 -080068sense_reason_t sbc_parse_cdb(struct se_cmd *cmd, struct sbc_ops *ops);
Christoph Hellwig6f23ac82012-10-07 10:55:53 -040069u32 sbc_get_device_rev(struct se_device *dev);
70u32 sbc_get_device_type(struct se_device *dev);
Roland Dreier972b29c82013-02-22 09:52:57 -080071sector_t sbc_get_write_same_sectors(struct se_cmd *cmd);
Nicholas Bellinger66a3d5b2014-04-02 14:19:09 -070072void sbc_dif_generate(struct se_cmd *);
Sagi Grimbergf75b6fa2015-04-19 20:27:19 +030073sense_reason_t sbc_dif_verify(struct se_cmd *, sector_t, unsigned int,
Nicholas Bellinger41861fa2014-01-07 22:44:57 +000074 unsigned int, struct scatterlist *, int);
Sagi Grimbergf75b6fa2015-04-19 20:27:19 +030075void sbc_dif_copy_prot(struct se_cmd *, unsigned int, bool,
76 struct scatterlist *, int);
Christoph Hellwigc4795fb2011-11-16 09:46:48 -050077void transport_set_vpd_proto_id(struct t10_vpd *, unsigned char *);
78int transport_set_vpd_assoc(struct t10_vpd *, unsigned char *);
79int transport_set_vpd_ident_type(struct t10_vpd *, unsigned char *);
80int transport_set_vpd_ident(struct t10_vpd *, unsigned char *);
81
Christoph Hellwig5873c4d2015-05-10 18:14:57 +020082extern struct configfs_attribute *sbc_attrib_attrs[];
83extern struct configfs_attribute *passthrough_attrib_attrs[];
84
Christoph Hellwigc4795fb2011-11-16 09:46:48 -050085/* core helpers also used by command snooping in pscsi */
Andy Grover49493142012-01-16 16:57:08 -080086void *transport_kmap_data_sg(struct se_cmd *);
87void transport_kunmap_data_sg(struct se_cmd *);
Nicholas Bellingerc5ff8d62013-08-22 11:58:43 -070088/* core helpers also used by xcopy during internal command setup */
89int target_alloc_sgl(struct scatterlist **, unsigned int *, u32, bool);
90sense_reason_t transport_generic_map_mem_to_cmd(struct se_cmd *,
91 struct scatterlist *, u32, struct scatterlist *, u32);
Christoph Hellwigc4795fb2011-11-16 09:46:48 -050092
Nicholas Bellinger29a05de2015-03-22 20:42:19 -070093bool target_lun_is_rdonly(struct se_cmd *);
Andy Grover7bfea53b2015-05-19 14:44:40 -070094sense_reason_t passthrough_parse_cdb(struct se_cmd *cmd,
95 sense_reason_t (*exec_cmd)(struct se_cmd *cmd));
Nicholas Bellingerd30cd122014-11-27 19:15:48 -080096
Christoph Hellwigc4795fb2011-11-16 09:46:48 -050097#endif /* TARGET_CORE_BACKEND_H */