1aef9ec39SRoland Dreier /* 2aef9ec39SRoland Dreier * Copyright (c) 2005 Cisco Systems. All rights reserved. 3aef9ec39SRoland Dreier * 4aef9ec39SRoland Dreier * This software is available to you under a choice of one of two 5aef9ec39SRoland Dreier * licenses. You may choose to be licensed under the terms of the GNU 6aef9ec39SRoland Dreier * General Public License (GPL) Version 2, available from the file 7aef9ec39SRoland Dreier * COPYING in the main directory of this source tree, or the 8aef9ec39SRoland Dreier * OpenIB.org BSD license below: 9aef9ec39SRoland Dreier * 10aef9ec39SRoland Dreier * Redistribution and use in source and binary forms, with or 11aef9ec39SRoland Dreier * without modification, are permitted provided that the following 12aef9ec39SRoland Dreier * conditions are met: 13aef9ec39SRoland Dreier * 14aef9ec39SRoland Dreier * - Redistributions of source code must retain the above 15aef9ec39SRoland Dreier * copyright notice, this list of conditions and the following 16aef9ec39SRoland Dreier * disclaimer. 17aef9ec39SRoland Dreier * 18aef9ec39SRoland Dreier * - Redistributions in binary form must reproduce the above 19aef9ec39SRoland Dreier * copyright notice, this list of conditions and the following 20aef9ec39SRoland Dreier * disclaimer in the documentation and/or other materials 21aef9ec39SRoland Dreier * provided with the distribution. 22aef9ec39SRoland Dreier * 23aef9ec39SRoland Dreier * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 24aef9ec39SRoland Dreier * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 25aef9ec39SRoland Dreier * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 26aef9ec39SRoland Dreier * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 27aef9ec39SRoland Dreier * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 28aef9ec39SRoland Dreier * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 29aef9ec39SRoland Dreier * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 30aef9ec39SRoland Dreier * SOFTWARE. 31aef9ec39SRoland Dreier */ 32aef9ec39SRoland Dreier 33aef9ec39SRoland Dreier #ifndef IB_SRP_H 34aef9ec39SRoland Dreier #define IB_SRP_H 35aef9ec39SRoland Dreier 36aef9ec39SRoland Dreier #include <linux/types.h> 37aef9ec39SRoland Dreier #include <linux/list.h> 388e9e5f4fSIngo Molnar #include <linux/mutex.h> 39cf368713SRoland Dreier #include <linux/scatterlist.h> 40aef9ec39SRoland Dreier 41aef9ec39SRoland Dreier #include <scsi/scsi_host.h> 42aef9ec39SRoland Dreier #include <scsi/scsi_cmnd.h> 43aef9ec39SRoland Dreier 44aef9ec39SRoland Dreier #include <rdma/ib_verbs.h> 45aef9ec39SRoland Dreier #include <rdma/ib_sa.h> 46aef9ec39SRoland Dreier #include <rdma/ib_cm.h> 47f5358a17SRoland Dreier #include <rdma/ib_fmr_pool.h> 48aef9ec39SRoland Dreier 49aef9ec39SRoland Dreier enum { 50aef9ec39SRoland Dreier SRP_PATH_REC_TIMEOUT_MS = 1000, 51aef9ec39SRoland Dreier SRP_ABORT_TIMEOUT_MS = 5000, 52aef9ec39SRoland Dreier 53aef9ec39SRoland Dreier SRP_PORT_REDIRECT = 1, 54aef9ec39SRoland Dreier SRP_DLID_REDIRECT = 2, 559fe4bcf4SDavid Dillow SRP_STALE_CONN = 3, 56aef9ec39SRoland Dreier 575f068992SRoland Dreier SRP_MAX_LUN = 512, 5874b0a15bSVu Pham SRP_DEF_SG_TABLESIZE = 12, 59aef9ec39SRoland Dreier 604d73f95fSBart Van Assche SRP_DEFAULT_QUEUE_SIZE = 1 << 6, 61dd5e6e38SBart Van Assche SRP_RSP_SQ_SIZE = 1, 62dd5e6e38SBart Van Assche SRP_TSK_MGMT_SQ_SIZE = 1, 634d73f95fSBart Van Assche SRP_DEFAULT_CMD_SQ_SIZE = SRP_DEFAULT_QUEUE_SIZE - SRP_RSP_SQ_SIZE - 644d73f95fSBart Van Assche SRP_TSK_MGMT_SQ_SIZE, 65aef9ec39SRoland Dreier 66f8b6e31eSDavid Dillow SRP_TAG_NO_REQ = ~0U, 67f8b6e31eSDavid Dillow SRP_TAG_TSK_MGMT = 1U << 31, 68f5358a17SRoland Dreier 69be8b9814SDavid Dillow SRP_FMR_SIZE = 512, 708f26c9ffSDavid Dillow 718f26c9ffSDavid Dillow SRP_MAP_ALLOW_FMR = 0, 728f26c9ffSDavid Dillow SRP_MAP_NO_FMR = 1, 73aef9ec39SRoland Dreier }; 74aef9ec39SRoland Dreier 75aef9ec39SRoland Dreier enum srp_target_state { 76aef9ec39SRoland Dreier SRP_TARGET_LIVE, 77ef6c49d8SBart Van Assche SRP_TARGET_REMOVED, 78aef9ec39SRoland Dreier }; 79aef9ec39SRoland Dreier 80bb12588aSDavid Dillow enum srp_iu_type { 81bb12588aSDavid Dillow SRP_IU_CMD, 82bb12588aSDavid Dillow SRP_IU_TSK_MGMT, 83bb12588aSDavid Dillow SRP_IU_RSP, 848cba2077SDavid Dillow }; 858cba2077SDavid Dillow 86f5358a17SRoland Dreier struct srp_device { 87f5358a17SRoland Dreier struct list_head dev_list; 88aef9ec39SRoland Dreier struct ib_device *dev; 89aef9ec39SRoland Dreier struct ib_pd *pd; 90aef9ec39SRoland Dreier struct ib_mr *mr; 91bf628dc2SRoland Dreier u64 fmr_page_mask; 928f26c9ffSDavid Dillow int fmr_page_size; 938f26c9ffSDavid Dillow int fmr_max_size; 94d1b4289eSBart Van Assche int max_pages_per_fmr; 95d1b4289eSBart Van Assche bool has_fmr; 96f5358a17SRoland Dreier }; 97f5358a17SRoland Dreier 98f5358a17SRoland Dreier struct srp_host { 9905321937SGreg Kroah-Hartman struct srp_device *srp_dev; 100f5358a17SRoland Dreier u8 port; 101ee959b00STony Jones struct device dev; 102aef9ec39SRoland Dreier struct list_head target_list; 103b3589fd4SMatthew Wilcox spinlock_t target_lock; 104aef9ec39SRoland Dreier struct completion released; 105aef9ec39SRoland Dreier struct list_head list; 1062d7091bcSBart Van Assche struct mutex add_target_mutex; 107aef9ec39SRoland Dreier }; 108aef9ec39SRoland Dreier 109aef9ec39SRoland Dreier struct srp_request { 110aef9ec39SRoland Dreier struct list_head list; 111aef9ec39SRoland Dreier struct scsi_cmnd *scmnd; 112aef9ec39SRoland Dreier struct srp_iu *cmd; 1138f26c9ffSDavid Dillow struct ib_pool_fmr **fmr_list; 1148f26c9ffSDavid Dillow u64 *map_page; 115c07d424dSDavid Dillow struct srp_direct_buf *indirect_desc; 116c07d424dSDavid Dillow dma_addr_t indirect_dma_addr; 1178f26c9ffSDavid Dillow short nfmr; 118d945e1dfSRoland Dreier short index; 119aef9ec39SRoland Dreier }; 120aef9ec39SRoland Dreier 121aef9ec39SRoland Dreier struct srp_target_port { 1229af76271SDavid Dillow /* These are RW in the hot path, and commonly used together */ 1239af76271SDavid Dillow struct list_head free_tx; 1249af76271SDavid Dillow struct list_head free_reqs; 1259af76271SDavid Dillow spinlock_t lock; 1269af76271SDavid Dillow s32 req_lim; 1279af76271SDavid Dillow 1289af76271SDavid Dillow /* These are read-only in the hot path */ 1299af76271SDavid Dillow struct ib_cq *send_cq ____cacheline_aligned_in_smp; 1309af76271SDavid Dillow struct ib_cq *recv_cq; 1319af76271SDavid Dillow struct ib_qp *qp; 132d1b4289eSBart Van Assche struct ib_fmr_pool *fmr_pool; 1339af76271SDavid Dillow u32 lkey; 1349af76271SDavid Dillow u32 rkey; 1359af76271SDavid Dillow enum srp_target_state state; 13649248644SDavid Dillow unsigned int max_iu_len; 13749248644SDavid Dillow unsigned int cmd_sg_cnt; 138c07d424dSDavid Dillow unsigned int indirect_size; 139c07d424dSDavid Dillow bool allow_ext_sg; 1409af76271SDavid Dillow 1419af76271SDavid Dillow /* Everything above this point is used in the hot path of 1429af76271SDavid Dillow * command processing. Try to keep them packed into cachelines. 1439af76271SDavid Dillow */ 1449af76271SDavid Dillow 145aef9ec39SRoland Dreier __be64 id_ext; 146aef9ec39SRoland Dreier __be64 ioc_guid; 147aef9ec39SRoland Dreier __be64 service_id; 14801cb9bcbSIshai Rabinovitz __be64 initiator_ext; 1490c0450dbSRamachandra K u16 io_class; 150aef9ec39SRoland Dreier struct srp_host *srp_host; 151aef9ec39SRoland Dreier struct Scsi_Host *scsi_host; 1529dd69a60SBart Van Assche struct srp_rport *rport; 153aef9ec39SRoland Dreier char target_name[32]; 154aef9ec39SRoland Dreier unsigned int scsi_id; 155c07d424dSDavid Dillow unsigned int sg_tablesize; 1564d73f95fSBart Van Assche int queue_size; 1574d73f95fSBart Van Assche int req_ring_size; 1584b5e5f41SBart Van Assche int comp_vector; 1597bb312e4SVu Pham int tl_retry_count; 160aef9ec39SRoland Dreier 161aef9ec39SRoland Dreier struct ib_sa_path_rec path; 1623633b3d0SIshai Rabinovitz __be16 orig_dgid[8]; 163aef9ec39SRoland Dreier struct ib_sa_query *path_query; 164aef9ec39SRoland Dreier int path_query_id; 165aef9ec39SRoland Dreier 166c9b03c1aSBart Van Assche u32 rq_tmo_jiffies; 167294c875aSBart Van Assche bool connected; 168c9b03c1aSBart Van Assche 169aef9ec39SRoland Dreier struct ib_cm_id *cm_id; 170aef9ec39SRoland Dreier 171aef9ec39SRoland Dreier int max_ti_iu_len; 172aef9ec39SRoland Dreier 1736bfa24faSRoland Dreier int zero_req_lim; 1746bfa24faSRoland Dreier 1754d73f95fSBart Van Assche struct srp_iu **tx_ring; 1764d73f95fSBart Van Assche struct srp_iu **rx_ring; 1774d73f95fSBart Van Assche struct srp_request *req_ring; 178aef9ec39SRoland Dreier 179c1120f89SBart Van Assche struct work_struct tl_err_work; 180ef6c49d8SBart Van Assche struct work_struct remove_work; 181aef9ec39SRoland Dreier 182aef9ec39SRoland Dreier struct list_head list; 183aef9ec39SRoland Dreier struct completion done; 184aef9ec39SRoland Dreier int status; 185948d1e88SBart Van Assche bool qp_in_error; 186f8b6e31eSDavid Dillow 187f8b6e31eSDavid Dillow struct completion tsk_mgmt_done; 188f8b6e31eSDavid Dillow u8 tsk_mgmt_status; 189aef9ec39SRoland Dreier }; 190aef9ec39SRoland Dreier 191aef9ec39SRoland Dreier struct srp_iu { 192dcb4cb85SBart Van Assche struct list_head list; 19385507bccSRalph Campbell u64 dma; 194aef9ec39SRoland Dreier void *buf; 195aef9ec39SRoland Dreier size_t size; 196aef9ec39SRoland Dreier enum dma_data_direction direction; 197aef9ec39SRoland Dreier }; 198aef9ec39SRoland Dreier 1998f26c9ffSDavid Dillow struct srp_map_state { 2008f26c9ffSDavid Dillow struct ib_pool_fmr **next_fmr; 2018f26c9ffSDavid Dillow struct srp_direct_buf *desc; 2028f26c9ffSDavid Dillow u64 *pages; 2038f26c9ffSDavid Dillow dma_addr_t base_dma_addr; 2048f26c9ffSDavid Dillow u32 fmr_len; 2058f26c9ffSDavid Dillow u32 total_len; 2068f26c9ffSDavid Dillow unsigned int npages; 2078f26c9ffSDavid Dillow unsigned int nfmr; 2088f26c9ffSDavid Dillow unsigned int ndesc; 2098f26c9ffSDavid Dillow struct scatterlist *unmapped_sg; 2108f26c9ffSDavid Dillow int unmapped_index; 2118f26c9ffSDavid Dillow dma_addr_t unmapped_addr; 2128f26c9ffSDavid Dillow }; 2138f26c9ffSDavid Dillow 214aef9ec39SRoland Dreier #endif /* IB_SRP_H */ 215