Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/nab/target-pending

Pull SCSI target fixes from Nicholas Bellinger:
"The highlights this merge window include:

- Allow target fabric drivers to function as built-in. (Roland)
- Fix tcm_loop multi-TPG endpoint nexus bug. (Hannes)
- Move per device config_item_type into se_subsystem_api, allowing
configfs attributes to be defined at module_init time. (Jerome +
nab)
- Convert existing IBLOCK/FILEIO/RAMDISK/PSCSI/TCMU drivers to use
external configfs attributes. (nab)
- A number of iser-target fixes related to active session + network
portal shutdown stability during extended stress testing. (Sagi +
Slava)
- Dynamic allocation of T10-PI contexts for iser-target, fixing a
potentially bogus iscsi_np->tpg_np pointer reference in >= v3.14
code. (Sagi)
- iser-target performance + scalability improvements. (Sagi)
- Fixes for SPC-4 Persistent Reservation AllRegistrants spec
compliance. (Ilias + James + nab)
- Avoid potential short kern_sendmsg() in iscsi-target for now until
Al's conversion to use msghdr iteration is merged post -rc1.
(Viro)

Also, Sagi has requested a number of iser-target patches (9) that
address stability issues he's encountered during extended stress
testing be considered for v3.10.y + v3.14.y code. Given the amount of
LOC involved, it will certainly require extra backporting effort.

Apologies in advance to Greg-KH & Co on this. Sagi and I will be
working post-merge to ensure they each get applied correctly"

* 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/nab/target-pending: (53 commits)
target: Allow AllRegistrants to re-RESERVE existing reservation
uapi/linux/target_core_user.h: fix headers_install.sh badness
iscsi-target: Fail connection on short sendmsg writes
iscsi-target: nullify session in failed login sequence
target: Avoid dropping AllRegistrants reservation during unregister
target: Fix R_HOLDER bit usage for AllRegistrants
iscsi-target: Drop left-over bogus iscsi_np->tpg_np
iser-target: Fix wc->wr_id cast warning
iser-target: Remove code duplication
iser-target: Adjust log levels and prettify some prints
iser-target: Use debug_level parameter to control logging level
iser-target: Fix logout sequence
iser-target: Don't wait for session commands from completion context
iser-target: Reduce CQ lock contention by batch polling
iser-target: Introduce isert_poll_budget
iser-target: Remove an atomic operation from the IO path
iser-target: Remove redundant call to isert_conn_terminate
iser-target: Use single CQ for TX and RX
iser-target: Centralize completion elements to a context
iser-target: Cast wr_id with uintptr_t instead of unsinged long
...

+1553 -1280
+862 -811
drivers/infiniband/ulp/isert/ib_isert.c
··· 22 22 #include <linux/socket.h> 23 23 #include <linux/in.h> 24 24 #include <linux/in6.h> 25 - #include <linux/llist.h> 26 25 #include <rdma/ib_verbs.h> 27 26 #include <rdma/rdma_cm.h> 28 27 #include <target/target_core_base.h> ··· 35 36 #define ISERT_MAX_CONN 8 36 37 #define ISER_MAX_RX_CQ_LEN (ISERT_QP_MAX_RECV_DTOS * ISERT_MAX_CONN) 37 38 #define ISER_MAX_TX_CQ_LEN (ISERT_QP_MAX_REQ_DTOS * ISERT_MAX_CONN) 39 + #define ISER_MAX_CQ_LEN (ISER_MAX_RX_CQ_LEN + ISER_MAX_TX_CQ_LEN + \ 40 + ISERT_MAX_CONN) 41 + 42 + int isert_debug_level = 0; 43 + module_param_named(debug_level, isert_debug_level, int, 0644); 44 + MODULE_PARM_DESC(debug_level, "Enable debug tracing if > 0 (default:0)"); 38 45 39 46 static DEFINE_MUTEX(device_list_mutex); 40 47 static LIST_HEAD(device_list); 41 - static struct workqueue_struct *isert_rx_wq; 42 48 static struct workqueue_struct *isert_comp_wq; 49 + static struct workqueue_struct *isert_release_wq; 43 50 44 51 static void 45 52 isert_unmap_cmd(struct isert_cmd *isert_cmd, struct isert_conn *isert_conn); ··· 59 54 struct isert_rdma_wr *wr); 60 55 static int 61 56 isert_put_response(struct iscsi_conn *conn, struct iscsi_cmd *cmd); 57 + static int 58 + isert_rdma_post_recvl(struct isert_conn *isert_conn); 59 + static int 60 + isert_rdma_accept(struct isert_conn *isert_conn); 61 + struct rdma_cm_id *isert_setup_id(struct isert_np *isert_np); 62 + 63 + static inline bool 64 + isert_prot_cmd(struct isert_conn *conn, struct se_cmd *cmd) 65 + { 66 + return (conn->pi_support && 67 + cmd->prot_op != TARGET_PROT_NORMAL); 68 + } 69 + 62 70 63 71 static void 64 72 isert_qp_event_callback(struct ib_event *e, void *context) 65 73 { 66 74 struct isert_conn *isert_conn = (struct isert_conn *)context; 67 75 68 - pr_err("isert_qp_event_callback event: %d\n", e->event); 76 + isert_err("conn %p event: %d\n", isert_conn, e->event); 69 77 switch (e->event) { 70 78 case IB_EVENT_COMM_EST: 71 79 rdma_notify(isert_conn->conn_cm_id, IB_EVENT_COMM_EST); 72 80 break; 73 81 case IB_EVENT_QP_LAST_WQE_REACHED: 74 - pr_warn("Reached TX IB_EVENT_QP_LAST_WQE_REACHED:\n"); 82 + isert_warn("Reached TX IB_EVENT_QP_LAST_WQE_REACHED\n"); 75 83 break; 76 84 default: 77 85 break; ··· 98 80 99 81 ret = ib_query_device(ib_dev, devattr); 100 82 if (ret) { 101 - pr_err("ib_query_device() failed: %d\n", ret); 83 + isert_err("ib_query_device() failed: %d\n", ret); 102 84 return ret; 103 85 } 104 - pr_debug("devattr->max_sge: %d\n", devattr->max_sge); 105 - pr_debug("devattr->max_sge_rd: %d\n", devattr->max_sge_rd); 86 + isert_dbg("devattr->max_sge: %d\n", devattr->max_sge); 87 + isert_dbg("devattr->max_sge_rd: %d\n", devattr->max_sge_rd); 106 88 107 89 return 0; 108 90 } 109 91 110 92 static int 111 - isert_conn_setup_qp(struct isert_conn *isert_conn, struct rdma_cm_id *cma_id, 112 - u8 protection) 93 + isert_conn_setup_qp(struct isert_conn *isert_conn, struct rdma_cm_id *cma_id) 113 94 { 114 95 struct isert_device *device = isert_conn->conn_device; 115 96 struct ib_qp_init_attr attr; 116 - int ret, index, min_index = 0; 97 + struct isert_comp *comp; 98 + int ret, i, min = 0; 117 99 118 100 mutex_lock(&device_list_mutex); 119 - for (index = 0; index < device->cqs_used; index++) 120 - if (device->cq_active_qps[index] < 121 - device->cq_active_qps[min_index]) 122 - min_index = index; 123 - device->cq_active_qps[min_index]++; 124 - pr_debug("isert_conn_setup_qp: Using min_index: %d\n", min_index); 101 + for (i = 0; i < device->comps_used; i++) 102 + if (device->comps[i].active_qps < 103 + device->comps[min].active_qps) 104 + min = i; 105 + comp = &device->comps[min]; 106 + comp->active_qps++; 107 + isert_info("conn %p, using comp %p min_index: %d\n", 108 + isert_conn, comp, min); 125 109 mutex_unlock(&device_list_mutex); 126 110 127 111 memset(&attr, 0, sizeof(struct ib_qp_init_attr)); 128 112 attr.event_handler = isert_qp_event_callback; 129 113 attr.qp_context = isert_conn; 130 - attr.send_cq = device->dev_tx_cq[min_index]; 131 - attr.recv_cq = device->dev_rx_cq[min_index]; 114 + attr.send_cq = comp->cq; 115 + attr.recv_cq = comp->cq; 132 116 attr.cap.max_send_wr = ISERT_QP_MAX_REQ_DTOS; 133 - attr.cap.max_recv_wr = ISERT_QP_MAX_RECV_DTOS; 117 + attr.cap.max_recv_wr = ISERT_QP_MAX_RECV_DTOS + 1; 134 118 /* 135 119 * FIXME: Use devattr.max_sge - 2 for max_send_sge as 136 120 * work-around for RDMA_READs with ConnectX-2. ··· 146 126 attr.cap.max_recv_sge = 1; 147 127 attr.sq_sig_type = IB_SIGNAL_REQ_WR; 148 128 attr.qp_type = IB_QPT_RC; 149 - if (protection) 129 + if (device->pi_capable) 150 130 attr.create_flags |= IB_QP_CREATE_SIGNATURE_EN; 151 - 152 - pr_debug("isert_conn_setup_qp cma_id->device: %p\n", 153 - cma_id->device); 154 - pr_debug("isert_conn_setup_qp conn_pd->device: %p\n", 155 - isert_conn->conn_pd->device); 156 131 157 132 ret = rdma_create_qp(cma_id, isert_conn->conn_pd, &attr); 158 133 if (ret) { 159 - pr_err("rdma_create_qp failed for cma_id %d\n", ret); 160 - return ret; 134 + isert_err("rdma_create_qp failed for cma_id %d\n", ret); 135 + goto err; 161 136 } 162 137 isert_conn->conn_qp = cma_id->qp; 163 - pr_debug("rdma_create_qp() returned success >>>>>>>>>>>>>>>>>>>>>>>>>.\n"); 164 138 165 139 return 0; 140 + err: 141 + mutex_lock(&device_list_mutex); 142 + comp->active_qps--; 143 + mutex_unlock(&device_list_mutex); 144 + 145 + return ret; 166 146 } 167 147 168 148 static void 169 149 isert_cq_event_callback(struct ib_event *e, void *context) 170 150 { 171 - pr_debug("isert_cq_event_callback event: %d\n", e->event); 151 + isert_dbg("event: %d\n", e->event); 172 152 } 173 153 174 154 static int ··· 202 182 } 203 183 204 184 isert_conn->conn_rx_desc_head = 0; 185 + 205 186 return 0; 206 187 207 188 dma_map_fail: ··· 214 193 kfree(isert_conn->conn_rx_descs); 215 194 isert_conn->conn_rx_descs = NULL; 216 195 fail: 196 + isert_err("conn %p failed to allocate rx descriptors\n", isert_conn); 197 + 217 198 return -ENOMEM; 218 199 } 219 200 ··· 239 216 isert_conn->conn_rx_descs = NULL; 240 217 } 241 218 242 - static void isert_cq_tx_work(struct work_struct *); 243 - static void isert_cq_tx_callback(struct ib_cq *, void *); 244 - static void isert_cq_rx_work(struct work_struct *); 245 - static void isert_cq_rx_callback(struct ib_cq *, void *); 219 + static void isert_cq_work(struct work_struct *); 220 + static void isert_cq_callback(struct ib_cq *, void *); 246 221 247 222 static int 248 223 isert_create_device_ib_res(struct isert_device *device) 249 224 { 250 225 struct ib_device *ib_dev = device->ib_device; 251 - struct isert_cq_desc *cq_desc; 252 226 struct ib_device_attr *dev_attr; 253 - int ret = 0, i, j; 254 - int max_rx_cqe, max_tx_cqe; 227 + int ret = 0, i; 228 + int max_cqe; 255 229 256 230 dev_attr = &device->dev_attr; 257 231 ret = isert_query_device(ib_dev, dev_attr); 258 232 if (ret) 259 233 return ret; 260 234 261 - max_rx_cqe = min(ISER_MAX_RX_CQ_LEN, dev_attr->max_cqe); 262 - max_tx_cqe = min(ISER_MAX_TX_CQ_LEN, dev_attr->max_cqe); 235 + max_cqe = min(ISER_MAX_CQ_LEN, dev_attr->max_cqe); 263 236 264 237 /* asign function handlers */ 265 238 if (dev_attr->device_cap_flags & IB_DEVICE_MEM_MGT_EXTENSIONS && ··· 273 254 device->pi_capable = dev_attr->device_cap_flags & 274 255 IB_DEVICE_SIGNATURE_HANDOVER ? true : false; 275 256 276 - device->cqs_used = min_t(int, num_online_cpus(), 277 - device->ib_device->num_comp_vectors); 278 - device->cqs_used = min(ISERT_MAX_CQ, device->cqs_used); 279 - pr_debug("Using %d CQs, device %s supports %d vectors support " 280 - "Fast registration %d pi_capable %d\n", 281 - device->cqs_used, device->ib_device->name, 282 - device->ib_device->num_comp_vectors, device->use_fastreg, 283 - device->pi_capable); 284 - device->cq_desc = kzalloc(sizeof(struct isert_cq_desc) * 285 - device->cqs_used, GFP_KERNEL); 286 - if (!device->cq_desc) { 287 - pr_err("Unable to allocate device->cq_desc\n"); 257 + device->comps_used = min(ISERT_MAX_CQ, min_t(int, num_online_cpus(), 258 + device->ib_device->num_comp_vectors)); 259 + isert_info("Using %d CQs, %s supports %d vectors support " 260 + "Fast registration %d pi_capable %d\n", 261 + device->comps_used, device->ib_device->name, 262 + device->ib_device->num_comp_vectors, device->use_fastreg, 263 + device->pi_capable); 264 + 265 + device->comps = kcalloc(device->comps_used, sizeof(struct isert_comp), 266 + GFP_KERNEL); 267 + if (!device->comps) { 268 + isert_err("Unable to allocate completion contexts\n"); 288 269 return -ENOMEM; 289 270 } 290 - cq_desc = device->cq_desc; 291 271 292 - for (i = 0; i < device->cqs_used; i++) { 293 - cq_desc[i].device = device; 294 - cq_desc[i].cq_index = i; 272 + for (i = 0; i < device->comps_used; i++) { 273 + struct isert_comp *comp = &device->comps[i]; 295 274 296 - INIT_WORK(&cq_desc[i].cq_rx_work, isert_cq_rx_work); 297 - device->dev_rx_cq[i] = ib_create_cq(device->ib_device, 298 - isert_cq_rx_callback, 299 - isert_cq_event_callback, 300 - (void *)&cq_desc[i], 301 - max_rx_cqe, i); 302 - if (IS_ERR(device->dev_rx_cq[i])) { 303 - ret = PTR_ERR(device->dev_rx_cq[i]); 304 - device->dev_rx_cq[i] = NULL; 275 + comp->device = device; 276 + INIT_WORK(&comp->work, isert_cq_work); 277 + comp->cq = ib_create_cq(device->ib_device, 278 + isert_cq_callback, 279 + isert_cq_event_callback, 280 + (void *)comp, 281 + max_cqe, i); 282 + if (IS_ERR(comp->cq)) { 283 + ret = PTR_ERR(comp->cq); 284 + comp->cq = NULL; 305 285 goto out_cq; 306 286 } 307 287 308 - INIT_WORK(&cq_desc[i].cq_tx_work, isert_cq_tx_work); 309 - device->dev_tx_cq[i] = ib_create_cq(device->ib_device, 310 - isert_cq_tx_callback, 311 - isert_cq_event_callback, 312 - (void *)&cq_desc[i], 313 - max_tx_cqe, i); 314 - if (IS_ERR(device->dev_tx_cq[i])) { 315 - ret = PTR_ERR(device->dev_tx_cq[i]); 316 - device->dev_tx_cq[i] = NULL; 317 - goto out_cq; 318 - } 319 - 320 - ret = ib_req_notify_cq(device->dev_rx_cq[i], IB_CQ_NEXT_COMP); 321 - if (ret) 322 - goto out_cq; 323 - 324 - ret = ib_req_notify_cq(device->dev_tx_cq[i], IB_CQ_NEXT_COMP); 288 + ret = ib_req_notify_cq(comp->cq, IB_CQ_NEXT_COMP); 325 289 if (ret) 326 290 goto out_cq; 327 291 } ··· 312 310 return 0; 313 311 314 312 out_cq: 315 - for (j = 0; j < i; j++) { 316 - cq_desc = &device->cq_desc[j]; 313 + for (i = 0; i < device->comps_used; i++) { 314 + struct isert_comp *comp = &device->comps[i]; 317 315 318 - if (device->dev_rx_cq[j]) { 319 - cancel_work_sync(&cq_desc->cq_rx_work); 320 - ib_destroy_cq(device->dev_rx_cq[j]); 321 - } 322 - if (device->dev_tx_cq[j]) { 323 - cancel_work_sync(&cq_desc->cq_tx_work); 324 - ib_destroy_cq(device->dev_tx_cq[j]); 316 + if (comp->cq) { 317 + cancel_work_sync(&comp->work); 318 + ib_destroy_cq(comp->cq); 325 319 } 326 320 } 327 - kfree(device->cq_desc); 321 + kfree(device->comps); 328 322 329 323 return ret; 330 324 } ··· 328 330 static void 329 331 isert_free_device_ib_res(struct isert_device *device) 330 332 { 331 - struct isert_cq_desc *cq_desc; 332 333 int i; 333 334 334 - for (i = 0; i < device->cqs_used; i++) { 335 - cq_desc = &device->cq_desc[i]; 335 + isert_info("device %p\n", device); 336 336 337 - cancel_work_sync(&cq_desc->cq_rx_work); 338 - cancel_work_sync(&cq_desc->cq_tx_work); 339 - ib_destroy_cq(device->dev_rx_cq[i]); 340 - ib_destroy_cq(device->dev_tx_cq[i]); 341 - device->dev_rx_cq[i] = NULL; 342 - device->dev_tx_cq[i] = NULL; 337 + for (i = 0; i < device->comps_used; i++) { 338 + struct isert_comp *comp = &device->comps[i]; 339 + 340 + cancel_work_sync(&comp->work); 341 + ib_destroy_cq(comp->cq); 342 + comp->cq = NULL; 343 343 } 344 - 345 - kfree(device->cq_desc); 344 + kfree(device->comps); 346 345 } 347 346 348 347 static void ··· 347 352 { 348 353 mutex_lock(&device_list_mutex); 349 354 device->refcount--; 355 + isert_info("device %p refcount %d\n", device, device->refcount); 350 356 if (!device->refcount) { 351 357 isert_free_device_ib_res(device); 352 358 list_del(&device->dev_node); ··· 366 370 list_for_each_entry(device, &device_list, dev_node) { 367 371 if (device->ib_device->node_guid == cma_id->device->node_guid) { 368 372 device->refcount++; 373 + isert_info("Found iser device %p refcount %d\n", 374 + device, device->refcount); 369 375 mutex_unlock(&device_list_mutex); 370 376 return device; 371 377 } ··· 391 393 392 394 device->refcount++; 393 395 list_add_tail(&device->dev_node, &device_list); 396 + isert_info("Created a new iser device %p refcount %d\n", 397 + device, device->refcount); 394 398 mutex_unlock(&device_list_mutex); 395 399 396 400 return device; ··· 407 407 if (list_empty(&isert_conn->conn_fr_pool)) 408 408 return; 409 409 410 - pr_debug("Freeing conn %p fastreg pool", isert_conn); 410 + isert_info("Freeing conn %p fastreg pool", isert_conn); 411 411 412 412 list_for_each_entry_safe(fr_desc, tmp, 413 413 &isert_conn->conn_fr_pool, list) { ··· 425 425 } 426 426 427 427 if (i < isert_conn->conn_fr_pool_size) 428 - pr_warn("Pool still has %d regions registered\n", 428 + isert_warn("Pool still has %d regions registered\n", 429 429 isert_conn->conn_fr_pool_size - i); 430 430 } 431 431 432 432 static int 433 + isert_create_pi_ctx(struct fast_reg_descriptor *desc, 434 + struct ib_device *device, 435 + struct ib_pd *pd) 436 + { 437 + struct ib_mr_init_attr mr_init_attr; 438 + struct pi_context *pi_ctx; 439 + int ret; 440 + 441 + pi_ctx = kzalloc(sizeof(*desc->pi_ctx), GFP_KERNEL); 442 + if (!pi_ctx) { 443 + isert_err("Failed to allocate pi context\n"); 444 + return -ENOMEM; 445 + } 446 + 447 + pi_ctx->prot_frpl = ib_alloc_fast_reg_page_list(device, 448 + ISCSI_ISER_SG_TABLESIZE); 449 + if (IS_ERR(pi_ctx->prot_frpl)) { 450 + isert_err("Failed to allocate prot frpl err=%ld\n", 451 + PTR_ERR(pi_ctx->prot_frpl)); 452 + ret = PTR_ERR(pi_ctx->prot_frpl); 453 + goto err_pi_ctx; 454 + } 455 + 456 + pi_ctx->prot_mr = ib_alloc_fast_reg_mr(pd, ISCSI_ISER_SG_TABLESIZE); 457 + if (IS_ERR(pi_ctx->prot_mr)) { 458 + isert_err("Failed to allocate prot frmr err=%ld\n", 459 + PTR_ERR(pi_ctx->prot_mr)); 460 + ret = PTR_ERR(pi_ctx->prot_mr); 461 + goto err_prot_frpl; 462 + } 463 + desc->ind |= ISERT_PROT_KEY_VALID; 464 + 465 + memset(&mr_init_attr, 0, sizeof(mr_init_attr)); 466 + mr_init_attr.max_reg_descriptors = 2; 467 + mr_init_attr.flags |= IB_MR_SIGNATURE_EN; 468 + pi_ctx->sig_mr = ib_create_mr(pd, &mr_init_attr); 469 + if (IS_ERR(pi_ctx->sig_mr)) { 470 + isert_err("Failed to allocate signature enabled mr err=%ld\n", 471 + PTR_ERR(pi_ctx->sig_mr)); 472 + ret = PTR_ERR(pi_ctx->sig_mr); 473 + goto err_prot_mr; 474 + } 475 + 476 + desc->pi_ctx = pi_ctx; 477 + desc->ind |= ISERT_SIG_KEY_VALID; 478 + desc->ind &= ~ISERT_PROTECTED; 479 + 480 + return 0; 481 + 482 + err_prot_mr: 483 + ib_dereg_mr(desc->pi_ctx->prot_mr); 484 + err_prot_frpl: 485 + ib_free_fast_reg_page_list(desc->pi_ctx->prot_frpl); 486 + err_pi_ctx: 487 + kfree(desc->pi_ctx); 488 + 489 + return ret; 490 + } 491 + 492 + static int 433 493 isert_create_fr_desc(struct ib_device *ib_device, struct ib_pd *pd, 434 - struct fast_reg_descriptor *fr_desc, u8 protection) 494 + struct fast_reg_descriptor *fr_desc) 435 495 { 436 496 int ret; 437 497 438 498 fr_desc->data_frpl = ib_alloc_fast_reg_page_list(ib_device, 439 499 ISCSI_ISER_SG_TABLESIZE); 440 500 if (IS_ERR(fr_desc->data_frpl)) { 441 - pr_err("Failed to allocate data frpl err=%ld\n", 442 - PTR_ERR(fr_desc->data_frpl)); 501 + isert_err("Failed to allocate data frpl err=%ld\n", 502 + PTR_ERR(fr_desc->data_frpl)); 443 503 return PTR_ERR(fr_desc->data_frpl); 444 504 } 445 505 446 506 fr_desc->data_mr = ib_alloc_fast_reg_mr(pd, ISCSI_ISER_SG_TABLESIZE); 447 507 if (IS_ERR(fr_desc->data_mr)) { 448 - pr_err("Failed to allocate data frmr err=%ld\n", 449 - PTR_ERR(fr_desc->data_mr)); 508 + isert_err("Failed to allocate data frmr err=%ld\n", 509 + PTR_ERR(fr_desc->data_mr)); 450 510 ret = PTR_ERR(fr_desc->data_mr); 451 511 goto err_data_frpl; 452 512 } 453 - pr_debug("Create fr_desc %p page_list %p\n", 454 - fr_desc, fr_desc->data_frpl->page_list); 455 513 fr_desc->ind |= ISERT_DATA_KEY_VALID; 456 514 457 - if (protection) { 458 - struct ib_mr_init_attr mr_init_attr = {0}; 459 - struct pi_context *pi_ctx; 460 - 461 - fr_desc->pi_ctx = kzalloc(sizeof(*fr_desc->pi_ctx), GFP_KERNEL); 462 - if (!fr_desc->pi_ctx) { 463 - pr_err("Failed to allocate pi context\n"); 464 - ret = -ENOMEM; 465 - goto err_data_mr; 466 - } 467 - pi_ctx = fr_desc->pi_ctx; 468 - 469 - pi_ctx->prot_frpl = ib_alloc_fast_reg_page_list(ib_device, 470 - ISCSI_ISER_SG_TABLESIZE); 471 - if (IS_ERR(pi_ctx->prot_frpl)) { 472 - pr_err("Failed to allocate prot frpl err=%ld\n", 473 - PTR_ERR(pi_ctx->prot_frpl)); 474 - ret = PTR_ERR(pi_ctx->prot_frpl); 475 - goto err_pi_ctx; 476 - } 477 - 478 - pi_ctx->prot_mr = ib_alloc_fast_reg_mr(pd, ISCSI_ISER_SG_TABLESIZE); 479 - if (IS_ERR(pi_ctx->prot_mr)) { 480 - pr_err("Failed to allocate prot frmr err=%ld\n", 481 - PTR_ERR(pi_ctx->prot_mr)); 482 - ret = PTR_ERR(pi_ctx->prot_mr); 483 - goto err_prot_frpl; 484 - } 485 - fr_desc->ind |= ISERT_PROT_KEY_VALID; 486 - 487 - mr_init_attr.max_reg_descriptors = 2; 488 - mr_init_attr.flags |= IB_MR_SIGNATURE_EN; 489 - pi_ctx->sig_mr = ib_create_mr(pd, &mr_init_attr); 490 - if (IS_ERR(pi_ctx->sig_mr)) { 491 - pr_err("Failed to allocate signature enabled mr err=%ld\n", 492 - PTR_ERR(pi_ctx->sig_mr)); 493 - ret = PTR_ERR(pi_ctx->sig_mr); 494 - goto err_prot_mr; 495 - } 496 - fr_desc->ind |= ISERT_SIG_KEY_VALID; 497 - } 498 - fr_desc->ind &= ~ISERT_PROTECTED; 515 + isert_dbg("Created fr_desc %p\n", fr_desc); 499 516 500 517 return 0; 501 - err_prot_mr: 502 - ib_dereg_mr(fr_desc->pi_ctx->prot_mr); 503 - err_prot_frpl: 504 - ib_free_fast_reg_page_list(fr_desc->pi_ctx->prot_frpl); 505 - err_pi_ctx: 506 - kfree(fr_desc->pi_ctx); 507 - err_data_mr: 508 - ib_dereg_mr(fr_desc->data_mr); 518 + 509 519 err_data_frpl: 510 520 ib_free_fast_reg_page_list(fr_desc->data_frpl); 511 521 ··· 523 513 } 524 514 525 515 static int 526 - isert_conn_create_fastreg_pool(struct isert_conn *isert_conn, u8 pi_support) 516 + isert_conn_create_fastreg_pool(struct isert_conn *isert_conn) 527 517 { 528 518 struct fast_reg_descriptor *fr_desc; 529 519 struct isert_device *device = isert_conn->conn_device; ··· 541 531 for (i = 0; i < tag_num; i++) { 542 532 fr_desc = kzalloc(sizeof(*fr_desc), GFP_KERNEL); 543 533 if (!fr_desc) { 544 - pr_err("Failed to allocate fast_reg descriptor\n"); 534 + isert_err("Failed to allocate fast_reg descriptor\n"); 545 535 ret = -ENOMEM; 546 536 goto err; 547 537 } 548 538 549 539 ret = isert_create_fr_desc(device->ib_device, 550 - isert_conn->conn_pd, fr_desc, 551 - pi_support); 540 + isert_conn->conn_pd, fr_desc); 552 541 if (ret) { 553 - pr_err("Failed to create fastreg descriptor err=%d\n", 542 + isert_err("Failed to create fastreg descriptor err=%d\n", 554 543 ret); 555 544 kfree(fr_desc); 556 545 goto err; ··· 559 550 isert_conn->conn_fr_pool_size++; 560 551 } 561 552 562 - pr_debug("Creating conn %p fastreg pool size=%d", 553 + isert_dbg("Creating conn %p fastreg pool size=%d", 563 554 isert_conn, isert_conn->conn_fr_pool_size); 564 555 565 556 return 0; ··· 572 563 static int 573 564 isert_connect_request(struct rdma_cm_id *cma_id, struct rdma_cm_event *event) 574 565 { 575 - struct iscsi_np *np = cma_id->context; 576 - struct isert_np *isert_np = np->np_context; 566 + struct isert_np *isert_np = cma_id->context; 567 + struct iscsi_np *np = isert_np->np; 577 568 struct isert_conn *isert_conn; 578 569 struct isert_device *device; 579 570 struct ib_device *ib_dev = cma_id->device; 580 571 int ret = 0; 581 - u8 pi_support; 582 572 583 573 spin_lock_bh(&np->np_thread_lock); 584 574 if (!np->enabled) { 585 575 spin_unlock_bh(&np->np_thread_lock); 586 - pr_debug("iscsi_np is not enabled, reject connect request\n"); 576 + isert_dbg("iscsi_np is not enabled, reject connect request\n"); 587 577 return rdma_reject(cma_id, NULL, 0); 588 578 } 589 579 spin_unlock_bh(&np->np_thread_lock); 590 580 591 - pr_debug("Entering isert_connect_request cma_id: %p, context: %p\n", 581 + isert_dbg("cma_id: %p, portal: %p\n", 592 582 cma_id, cma_id->context); 593 583 594 584 isert_conn = kzalloc(sizeof(struct isert_conn), GFP_KERNEL); 595 585 if (!isert_conn) { 596 - pr_err("Unable to allocate isert_conn\n"); 586 + isert_err("Unable to allocate isert_conn\n"); 597 587 return -ENOMEM; 598 588 } 599 589 isert_conn->state = ISER_CONN_INIT; 600 590 INIT_LIST_HEAD(&isert_conn->conn_accept_node); 601 591 init_completion(&isert_conn->conn_login_comp); 592 + init_completion(&isert_conn->login_req_comp); 602 593 init_completion(&isert_conn->conn_wait); 603 - init_completion(&isert_conn->conn_wait_comp_err); 604 594 kref_init(&isert_conn->conn_kref); 605 595 mutex_init(&isert_conn->conn_mutex); 606 596 spin_lock_init(&isert_conn->conn_lock); 607 597 INIT_LIST_HEAD(&isert_conn->conn_fr_pool); 608 598 609 - cma_id->context = isert_conn; 610 599 isert_conn->conn_cm_id = cma_id; 611 600 612 601 isert_conn->login_buf = kzalloc(ISCSI_DEF_MAX_RECV_SEG_LEN + 613 602 ISER_RX_LOGIN_SIZE, GFP_KERNEL); 614 603 if (!isert_conn->login_buf) { 615 - pr_err("Unable to allocate isert_conn->login_buf\n"); 604 + isert_err("Unable to allocate isert_conn->login_buf\n"); 616 605 ret = -ENOMEM; 617 606 goto out; 618 607 } ··· 618 611 isert_conn->login_req_buf = isert_conn->login_buf; 619 612 isert_conn->login_rsp_buf = isert_conn->login_buf + 620 613 ISCSI_DEF_MAX_RECV_SEG_LEN; 621 - pr_debug("Set login_buf: %p login_req_buf: %p login_rsp_buf: %p\n", 614 + isert_dbg("Set login_buf: %p login_req_buf: %p login_rsp_buf: %p\n", 622 615 isert_conn->login_buf, isert_conn->login_req_buf, 623 616 isert_conn->login_rsp_buf); 624 617 ··· 628 621 629 622 ret = ib_dma_mapping_error(ib_dev, isert_conn->login_req_dma); 630 623 if (ret) { 631 - pr_err("ib_dma_mapping_error failed for login_req_dma: %d\n", 624 + isert_err("ib_dma_mapping_error failed for login_req_dma: %d\n", 632 625 ret); 633 626 isert_conn->login_req_dma = 0; 634 627 goto out_login_buf; ··· 640 633 641 634 ret = ib_dma_mapping_error(ib_dev, isert_conn->login_rsp_dma); 642 635 if (ret) { 643 - pr_err("ib_dma_mapping_error failed for login_rsp_dma: %d\n", 636 + isert_err("ib_dma_mapping_error failed for login_rsp_dma: %d\n", 644 637 ret); 645 638 isert_conn->login_rsp_dma = 0; 646 639 goto out_req_dma_map; ··· 656 649 isert_conn->initiator_depth = min_t(u8, 657 650 event->param.conn.initiator_depth, 658 651 device->dev_attr.max_qp_init_rd_atom); 659 - pr_debug("Using initiator_depth: %u\n", isert_conn->initiator_depth); 652 + isert_dbg("Using initiator_depth: %u\n", isert_conn->initiator_depth); 660 653 661 654 isert_conn->conn_device = device; 662 655 isert_conn->conn_pd = ib_alloc_pd(isert_conn->conn_device->ib_device); 663 656 if (IS_ERR(isert_conn->conn_pd)) { 664 657 ret = PTR_ERR(isert_conn->conn_pd); 665 - pr_err("ib_alloc_pd failed for conn %p: ret=%d\n", 658 + isert_err("ib_alloc_pd failed for conn %p: ret=%d\n", 666 659 isert_conn, ret); 667 660 goto out_pd; 668 661 } ··· 671 664 IB_ACCESS_LOCAL_WRITE); 672 665 if (IS_ERR(isert_conn->conn_mr)) { 673 666 ret = PTR_ERR(isert_conn->conn_mr); 674 - pr_err("ib_get_dma_mr failed for conn %p: ret=%d\n", 667 + isert_err("ib_get_dma_mr failed for conn %p: ret=%d\n", 675 668 isert_conn, ret); 676 669 goto out_mr; 677 670 } 678 671 679 - pi_support = np->tpg_np->tpg->tpg_attrib.t10_pi; 680 - if (pi_support && !device->pi_capable) { 681 - pr_err("Protection information requested but not supported, " 682 - "rejecting connect request\n"); 683 - ret = rdma_reject(cma_id, NULL, 0); 684 - goto out_mr; 685 - } 672 + ret = isert_conn_setup_qp(isert_conn, cma_id); 673 + if (ret) 674 + goto out_conn_dev; 686 675 687 - ret = isert_conn_setup_qp(isert_conn, cma_id, pi_support); 676 + ret = isert_rdma_post_recvl(isert_conn); 677 + if (ret) 678 + goto out_conn_dev; 679 + 680 + ret = isert_rdma_accept(isert_conn); 688 681 if (ret) 689 682 goto out_conn_dev; 690 683 ··· 692 685 list_add_tail(&isert_conn->conn_accept_node, &isert_np->np_accept_list); 693 686 mutex_unlock(&isert_np->np_accept_mutex); 694 687 695 - pr_debug("isert_connect_request() up np_sem np: %p\n", np); 688 + isert_info("np %p: Allow accept_np to continue\n", np); 696 689 up(&isert_np->np_sem); 697 690 return 0; 698 691 ··· 712 705 kfree(isert_conn->login_buf); 713 706 out: 714 707 kfree(isert_conn); 708 + rdma_reject(cma_id, NULL, 0); 715 709 return ret; 716 710 } 717 711 ··· 721 713 { 722 714 struct ib_device *ib_dev = isert_conn->conn_cm_id->device; 723 715 struct isert_device *device = isert_conn->conn_device; 724 - int cq_index; 725 716 726 - pr_debug("Entering isert_connect_release(): >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n"); 717 + isert_dbg("conn %p\n", isert_conn); 727 718 728 719 if (device && device->use_fastreg) 729 720 isert_conn_free_fastreg_pool(isert_conn); 730 721 731 - if (isert_conn->conn_qp) { 732 - cq_index = ((struct isert_cq_desc *) 733 - isert_conn->conn_qp->recv_cq->cq_context)->cq_index; 734 - pr_debug("isert_connect_release: cq_index: %d\n", cq_index); 735 - isert_conn->conn_device->cq_active_qps[cq_index]--; 736 - 737 - rdma_destroy_qp(isert_conn->conn_cm_id); 738 - } 739 - 740 722 isert_free_rx_descriptors(isert_conn); 741 723 rdma_destroy_id(isert_conn->conn_cm_id); 724 + 725 + if (isert_conn->conn_qp) { 726 + struct isert_comp *comp = isert_conn->conn_qp->recv_cq->cq_context; 727 + 728 + isert_dbg("dec completion context %p active_qps\n", comp); 729 + mutex_lock(&device_list_mutex); 730 + comp->active_qps--; 731 + mutex_unlock(&device_list_mutex); 732 + 733 + ib_destroy_qp(isert_conn->conn_qp); 734 + } 742 735 743 736 ib_dereg_mr(isert_conn->conn_mr); 744 737 ib_dealloc_pd(isert_conn->conn_pd); ··· 756 747 757 748 if (device) 758 749 isert_device_try_release(device); 759 - 760 - pr_debug("Leaving isert_connect_release >>>>>>>>>>>>\n"); 761 750 } 762 751 763 752 static void 764 753 isert_connected_handler(struct rdma_cm_id *cma_id) 765 754 { 766 - struct isert_conn *isert_conn = cma_id->context; 755 + struct isert_conn *isert_conn = cma_id->qp->qp_context; 767 756 768 - kref_get(&isert_conn->conn_kref); 757 + isert_info("conn %p\n", isert_conn); 758 + 759 + if (!kref_get_unless_zero(&isert_conn->conn_kref)) { 760 + isert_warn("conn %p connect_release is running\n", isert_conn); 761 + return; 762 + } 763 + 764 + mutex_lock(&isert_conn->conn_mutex); 765 + if (isert_conn->state != ISER_CONN_FULL_FEATURE) 766 + isert_conn->state = ISER_CONN_UP; 767 + mutex_unlock(&isert_conn->conn_mutex); 769 768 } 770 769 771 770 static void ··· 782 765 struct isert_conn *isert_conn = container_of(kref, 783 766 struct isert_conn, conn_kref); 784 767 785 - pr_debug("Calling isert_connect_release for final kref %s/%d\n", 786 - current->comm, current->pid); 768 + isert_info("conn %p final kref %s/%d\n", isert_conn, current->comm, 769 + current->pid); 787 770 788 771 isert_connect_release(isert_conn); 789 772 } ··· 794 777 kref_put(&isert_conn->conn_kref, isert_release_conn_kref); 795 778 } 796 779 780 + /** 781 + * isert_conn_terminate() - Initiate connection termination 782 + * @isert_conn: isert connection struct 783 + * 784 + * Notes: 785 + * In case the connection state is FULL_FEATURE, move state 786 + * to TEMINATING and start teardown sequence (rdma_disconnect). 787 + * In case the connection state is UP, complete flush as well. 788 + * 789 + * This routine must be called with conn_mutex held. Thus it is 790 + * safe to call multiple times. 791 + */ 797 792 static void 798 - isert_disconnect_work(struct work_struct *work) 793 + isert_conn_terminate(struct isert_conn *isert_conn) 799 794 { 800 - struct isert_conn *isert_conn = container_of(work, 801 - struct isert_conn, conn_logout_work); 795 + int err; 802 796 803 - pr_debug("isert_disconnect_work(): >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n"); 804 - mutex_lock(&isert_conn->conn_mutex); 805 - if (isert_conn->state == ISER_CONN_UP) 797 + switch (isert_conn->state) { 798 + case ISER_CONN_TERMINATING: 799 + break; 800 + case ISER_CONN_UP: 801 + case ISER_CONN_FULL_FEATURE: /* FALLTHRU */ 802 + isert_info("Terminating conn %p state %d\n", 803 + isert_conn, isert_conn->state); 806 804 isert_conn->state = ISER_CONN_TERMINATING; 807 - 808 - if (isert_conn->post_recv_buf_count == 0 && 809 - atomic_read(&isert_conn->post_send_buf_count) == 0) { 810 - mutex_unlock(&isert_conn->conn_mutex); 811 - goto wake_up; 805 + err = rdma_disconnect(isert_conn->conn_cm_id); 806 + if (err) 807 + isert_warn("Failed rdma_disconnect isert_conn %p\n", 808 + isert_conn); 809 + break; 810 + default: 811 + isert_warn("conn %p teminating in state %d\n", 812 + isert_conn, isert_conn->state); 812 813 } 813 - if (!isert_conn->conn_cm_id) { 814 - mutex_unlock(&isert_conn->conn_mutex); 815 - isert_put_conn(isert_conn); 816 - return; 817 - } 818 - 819 - if (isert_conn->disconnect) { 820 - /* Send DREQ/DREP towards our initiator */ 821 - rdma_disconnect(isert_conn->conn_cm_id); 822 - } 823 - 824 - mutex_unlock(&isert_conn->conn_mutex); 825 - 826 - wake_up: 827 - complete(&isert_conn->conn_wait); 828 814 } 829 815 830 816 static int 831 - isert_disconnected_handler(struct rdma_cm_id *cma_id, bool disconnect) 817 + isert_np_cma_handler(struct isert_np *isert_np, 818 + enum rdma_cm_event_type event) 832 819 { 833 - struct isert_conn *isert_conn; 820 + isert_dbg("isert np %p, handling event %d\n", isert_np, event); 834 821 835 - if (!cma_id->qp) { 836 - struct isert_np *isert_np = cma_id->context; 837 - 822 + switch (event) { 823 + case RDMA_CM_EVENT_DEVICE_REMOVAL: 838 824 isert_np->np_cm_id = NULL; 839 - return -1; 825 + break; 826 + case RDMA_CM_EVENT_ADDR_CHANGE: 827 + isert_np->np_cm_id = isert_setup_id(isert_np); 828 + if (IS_ERR(isert_np->np_cm_id)) { 829 + isert_err("isert np %p setup id failed: %ld\n", 830 + isert_np, PTR_ERR(isert_np->np_cm_id)); 831 + isert_np->np_cm_id = NULL; 832 + } 833 + break; 834 + default: 835 + isert_err("isert np %p Unexpected event %d\n", 836 + isert_np, event); 840 837 } 841 838 842 - isert_conn = (struct isert_conn *)cma_id->context; 839 + return -1; 840 + } 843 841 844 - isert_conn->disconnect = disconnect; 845 - INIT_WORK(&isert_conn->conn_logout_work, isert_disconnect_work); 846 - schedule_work(&isert_conn->conn_logout_work); 842 + static int 843 + isert_disconnected_handler(struct rdma_cm_id *cma_id, 844 + enum rdma_cm_event_type event) 845 + { 846 + struct isert_np *isert_np = cma_id->context; 847 + struct isert_conn *isert_conn; 848 + 849 + if (isert_np->np_cm_id == cma_id) 850 + return isert_np_cma_handler(cma_id->context, event); 851 + 852 + isert_conn = cma_id->qp->qp_context; 853 + 854 + mutex_lock(&isert_conn->conn_mutex); 855 + isert_conn_terminate(isert_conn); 856 + mutex_unlock(&isert_conn->conn_mutex); 857 + 858 + isert_info("conn %p completing conn_wait\n", isert_conn); 859 + complete(&isert_conn->conn_wait); 847 860 848 861 return 0; 862 + } 863 + 864 + static void 865 + isert_connect_error(struct rdma_cm_id *cma_id) 866 + { 867 + struct isert_conn *isert_conn = cma_id->qp->qp_context; 868 + 869 + isert_put_conn(isert_conn); 849 870 } 850 871 851 872 static int 852 873 isert_cma_handler(struct rdma_cm_id *cma_id, struct rdma_cm_event *event) 853 874 { 854 875 int ret = 0; 855 - bool disconnect = false; 856 876 857 - pr_debug("isert_cma_handler: event %d status %d conn %p id %p\n", 858 - event->event, event->status, cma_id->context, cma_id); 877 + isert_info("event %d status %d id %p np %p\n", event->event, 878 + event->status, cma_id, cma_id->context); 859 879 860 880 switch (event->event) { 861 881 case RDMA_CM_EVENT_CONNECT_REQUEST: 862 882 ret = isert_connect_request(cma_id, event); 863 883 if (ret) 864 - pr_err("isert_cma_handler failed RDMA_CM_EVENT: 0x%08x %d\n", 865 - event->event, ret); 884 + isert_err("failed handle connect request %d\n", ret); 866 885 break; 867 886 case RDMA_CM_EVENT_ESTABLISHED: 868 887 isert_connected_handler(cma_id); ··· 906 853 case RDMA_CM_EVENT_ADDR_CHANGE: /* FALLTHRU */ 907 854 case RDMA_CM_EVENT_DISCONNECTED: /* FALLTHRU */ 908 855 case RDMA_CM_EVENT_DEVICE_REMOVAL: /* FALLTHRU */ 909 - disconnect = true; 910 856 case RDMA_CM_EVENT_TIMEWAIT_EXIT: /* FALLTHRU */ 911 - ret = isert_disconnected_handler(cma_id, disconnect); 857 + ret = isert_disconnected_handler(cma_id, event->event); 912 858 break; 859 + case RDMA_CM_EVENT_REJECTED: /* FALLTHRU */ 860 + case RDMA_CM_EVENT_UNREACHABLE: /* FALLTHRU */ 913 861 case RDMA_CM_EVENT_CONNECT_ERROR: 862 + isert_connect_error(cma_id); 863 + break; 914 864 default: 915 - pr_err("Unhandled RDMA CMA event: %d\n", event->event); 865 + isert_err("Unhandled RDMA CMA event: %d\n", event->event); 916 866 break; 917 867 } 918 868 ··· 932 876 933 877 for (rx_wr = isert_conn->conn_rx_wr, i = 0; i < count; i++, rx_wr++) { 934 878 rx_desc = &isert_conn->conn_rx_descs[rx_head]; 935 - rx_wr->wr_id = (unsigned long)rx_desc; 879 + rx_wr->wr_id = (uintptr_t)rx_desc; 936 880 rx_wr->sg_list = &rx_desc->rx_sg; 937 881 rx_wr->num_sge = 1; 938 882 rx_wr->next = rx_wr + 1; ··· 946 890 ret = ib_post_recv(isert_conn->conn_qp, isert_conn->conn_rx_wr, 947 891 &rx_wr_failed); 948 892 if (ret) { 949 - pr_err("ib_post_recv() failed with ret: %d\n", ret); 893 + isert_err("ib_post_recv() failed with ret: %d\n", ret); 950 894 isert_conn->post_recv_buf_count -= count; 951 895 } else { 952 - pr_debug("isert_post_recv(): Posted %d RX buffers\n", count); 896 + isert_dbg("isert_post_recv(): Posted %d RX buffers\n", count); 953 897 isert_conn->conn_rx_desc_head = rx_head; 954 898 } 955 899 return ret; ··· 966 910 ISER_HEADERS_LEN, DMA_TO_DEVICE); 967 911 968 912 send_wr.next = NULL; 969 - send_wr.wr_id = (unsigned long)tx_desc; 913 + send_wr.wr_id = (uintptr_t)tx_desc; 970 914 send_wr.sg_list = tx_desc->tx_sg; 971 915 send_wr.num_sge = tx_desc->num_sge; 972 916 send_wr.opcode = IB_WR_SEND; 973 917 send_wr.send_flags = IB_SEND_SIGNALED; 974 918 975 - atomic_inc(&isert_conn->post_send_buf_count); 976 - 977 919 ret = ib_post_send(isert_conn->conn_qp, &send_wr, &send_wr_failed); 978 - if (ret) { 979 - pr_err("ib_post_send() failed, ret: %d\n", ret); 980 - atomic_dec(&isert_conn->post_send_buf_count); 981 - } 920 + if (ret) 921 + isert_err("ib_post_send() failed, ret: %d\n", ret); 982 922 983 923 return ret; 984 924 } ··· 997 945 998 946 if (tx_desc->tx_sg[0].lkey != isert_conn->conn_mr->lkey) { 999 947 tx_desc->tx_sg[0].lkey = isert_conn->conn_mr->lkey; 1000 - pr_debug("tx_desc %p lkey mismatch, fixing\n", tx_desc); 948 + isert_dbg("tx_desc %p lkey mismatch, fixing\n", tx_desc); 1001 949 } 1002 950 } 1003 951 ··· 1011 959 dma_addr = ib_dma_map_single(ib_dev, (void *)tx_desc, 1012 960 ISER_HEADERS_LEN, DMA_TO_DEVICE); 1013 961 if (ib_dma_mapping_error(ib_dev, dma_addr)) { 1014 - pr_err("ib_dma_mapping_error() failed\n"); 962 + isert_err("ib_dma_mapping_error() failed\n"); 1015 963 return -ENOMEM; 1016 964 } 1017 965 ··· 1020 968 tx_desc->tx_sg[0].length = ISER_HEADERS_LEN; 1021 969 tx_desc->tx_sg[0].lkey = isert_conn->conn_mr->lkey; 1022 970 1023 - pr_debug("isert_init_tx_hdrs: Setup tx_sg[0].addr: 0x%llx length: %u" 1024 - " lkey: 0x%08x\n", tx_desc->tx_sg[0].addr, 1025 - tx_desc->tx_sg[0].length, tx_desc->tx_sg[0].lkey); 971 + isert_dbg("Setup tx_sg[0].addr: 0x%llx length: %u lkey: 0x%x\n", 972 + tx_desc->tx_sg[0].addr, tx_desc->tx_sg[0].length, 973 + tx_desc->tx_sg[0].lkey); 1026 974 1027 975 return 0; 1028 976 } 1029 977 1030 978 static void 1031 979 isert_init_send_wr(struct isert_conn *isert_conn, struct isert_cmd *isert_cmd, 1032 - struct ib_send_wr *send_wr, bool coalesce) 980 + struct ib_send_wr *send_wr) 1033 981 { 1034 982 struct iser_tx_desc *tx_desc = &isert_cmd->tx_desc; 1035 983 1036 984 isert_cmd->rdma_wr.iser_ib_op = ISER_IB_SEND; 1037 - send_wr->wr_id = (unsigned long)&isert_cmd->tx_desc; 985 + send_wr->wr_id = (uintptr_t)&isert_cmd->tx_desc; 1038 986 send_wr->opcode = IB_WR_SEND; 1039 987 send_wr->sg_list = &tx_desc->tx_sg[0]; 1040 988 send_wr->num_sge = isert_cmd->tx_desc.num_sge; 1041 - /* 1042 - * Coalesce send completion interrupts by only setting IB_SEND_SIGNALED 1043 - * bit for every ISERT_COMP_BATCH_COUNT number of ib_post_send() calls. 1044 - */ 1045 - mutex_lock(&isert_conn->conn_mutex); 1046 - if (coalesce && isert_conn->state == ISER_CONN_UP && 1047 - ++isert_conn->conn_comp_batch < ISERT_COMP_BATCH_COUNT) { 1048 - tx_desc->llnode_active = true; 1049 - llist_add(&tx_desc->comp_llnode, &isert_conn->conn_comp_llist); 1050 - mutex_unlock(&isert_conn->conn_mutex); 1051 - return; 1052 - } 1053 - isert_conn->conn_comp_batch = 0; 1054 - tx_desc->comp_llnode_batch = llist_del_all(&isert_conn->conn_comp_llist); 1055 - mutex_unlock(&isert_conn->conn_mutex); 1056 - 1057 989 send_wr->send_flags = IB_SEND_SIGNALED; 1058 990 } 1059 991 ··· 1053 1017 sge.length = ISER_RX_LOGIN_SIZE; 1054 1018 sge.lkey = isert_conn->conn_mr->lkey; 1055 1019 1056 - pr_debug("Setup sge: addr: %llx length: %d 0x%08x\n", 1020 + isert_dbg("Setup sge: addr: %llx length: %d 0x%08x\n", 1057 1021 sge.addr, sge.length, sge.lkey); 1058 1022 1059 1023 memset(&rx_wr, 0, sizeof(struct ib_recv_wr)); 1060 - rx_wr.wr_id = (unsigned long)isert_conn->login_req_buf; 1024 + rx_wr.wr_id = (uintptr_t)isert_conn->login_req_buf; 1061 1025 rx_wr.sg_list = &sge; 1062 1026 rx_wr.num_sge = 1; 1063 1027 1064 1028 isert_conn->post_recv_buf_count++; 1065 1029 ret = ib_post_recv(isert_conn->conn_qp, &rx_wr, &rx_wr_fail); 1066 1030 if (ret) { 1067 - pr_err("ib_post_recv() failed: %d\n", ret); 1031 + isert_err("ib_post_recv() failed: %d\n", ret); 1068 1032 isert_conn->post_recv_buf_count--; 1069 1033 } 1070 1034 1071 - pr_debug("ib_post_recv(): returned success >>>>>>>>>>>>>>>>>>>>>>>>\n"); 1072 1035 return ret; 1073 1036 } 1074 1037 ··· 1107 1072 if (login->login_complete) { 1108 1073 if (!conn->sess->sess_ops->SessionType && 1109 1074 isert_conn->conn_device->use_fastreg) { 1110 - /* Normal Session and fastreg is used */ 1111 - u8 pi_support = login->np->tpg_np->tpg->tpg_attrib.t10_pi; 1112 - 1113 - ret = isert_conn_create_fastreg_pool(isert_conn, 1114 - pi_support); 1075 + ret = isert_conn_create_fastreg_pool(isert_conn); 1115 1076 if (ret) { 1116 - pr_err("Conn: %p failed to create" 1077 + isert_err("Conn: %p failed to create" 1117 1078 " fastreg pool\n", isert_conn); 1118 1079 return ret; 1119 1080 } ··· 1123 1092 if (ret) 1124 1093 return ret; 1125 1094 1126 - isert_conn->state = ISER_CONN_UP; 1095 + /* Now we are in FULL_FEATURE phase */ 1096 + mutex_lock(&isert_conn->conn_mutex); 1097 + isert_conn->state = ISER_CONN_FULL_FEATURE; 1098 + mutex_unlock(&isert_conn->conn_mutex); 1127 1099 goto post_send; 1128 1100 } 1129 1101 ··· 1143 1109 } 1144 1110 1145 1111 static void 1146 - isert_rx_login_req(struct iser_rx_desc *rx_desc, int rx_buflen, 1147 - struct isert_conn *isert_conn) 1112 + isert_rx_login_req(struct isert_conn *isert_conn) 1148 1113 { 1114 + struct iser_rx_desc *rx_desc = (void *)isert_conn->login_req_buf; 1115 + int rx_buflen = isert_conn->login_req_len; 1149 1116 struct iscsi_conn *conn = isert_conn->conn; 1150 1117 struct iscsi_login *login = conn->conn_login; 1151 1118 int size; 1152 1119 1153 - if (!login) { 1154 - pr_err("conn->conn_login is NULL\n"); 1155 - dump_stack(); 1156 - return; 1157 - } 1120 + isert_info("conn %p\n", isert_conn); 1121 + 1122 + WARN_ON_ONCE(!login); 1158 1123 1159 1124 if (login->first_request) { 1160 1125 struct iscsi_login_req *login_req = ··· 1179 1146 memcpy(&login->req[0], (void *)&rx_desc->iscsi_header, ISCSI_HDR_LEN); 1180 1147 1181 1148 size = min(rx_buflen, MAX_KEY_VALUE_PAIRS); 1182 - pr_debug("Using login payload size: %d, rx_buflen: %d MAX_KEY_VALUE_PAIRS: %d\n", 1183 - size, rx_buflen, MAX_KEY_VALUE_PAIRS); 1149 + isert_dbg("Using login payload size: %d, rx_buflen: %d " 1150 + "MAX_KEY_VALUE_PAIRS: %d\n", size, rx_buflen, 1151 + MAX_KEY_VALUE_PAIRS); 1184 1152 memcpy(login->req_buf, &rx_desc->data[0], size); 1185 1153 1186 1154 if (login->first_request) { ··· 1200 1166 1201 1167 cmd = iscsit_allocate_cmd(conn, TASK_INTERRUPTIBLE); 1202 1168 if (!cmd) { 1203 - pr_err("Unable to allocate iscsi_cmd + isert_cmd\n"); 1169 + isert_err("Unable to allocate iscsi_cmd + isert_cmd\n"); 1204 1170 return NULL; 1205 1171 } 1206 1172 isert_cmd = iscsit_priv_cmd(cmd); ··· 1243 1209 sg = &cmd->se_cmd.t_data_sg[0]; 1244 1210 sg_nents = max(1UL, DIV_ROUND_UP(imm_data_len, PAGE_SIZE)); 1245 1211 1246 - pr_debug("Copying Immediate SG: %p sg_nents: %u from %p imm_data_len: %d\n", 1247 - sg, sg_nents, &rx_desc->data[0], imm_data_len); 1212 + isert_dbg("Copying Immediate SG: %p sg_nents: %u from %p imm_data_len: %d\n", 1213 + sg, sg_nents, &rx_desc->data[0], imm_data_len); 1248 1214 1249 1215 sg_copy_from_buffer(sg, sg_nents, &rx_desc->data[0], imm_data_len); 1250 1216 ··· 1288 1254 * FIXME: Unexpected unsolicited_data out 1289 1255 */ 1290 1256 if (!cmd->unsolicited_data) { 1291 - pr_err("Received unexpected solicited data payload\n"); 1257 + isert_err("Received unexpected solicited data payload\n"); 1292 1258 dump_stack(); 1293 1259 return -1; 1294 1260 } 1295 1261 1296 - pr_debug("Unsolicited DataOut unsol_data_len: %u, write_data_done: %u, data_length: %u\n", 1297 - unsol_data_len, cmd->write_data_done, cmd->se_cmd.data_length); 1262 + isert_dbg("Unsolicited DataOut unsol_data_len: %u, " 1263 + "write_data_done: %u, data_length: %u\n", 1264 + unsol_data_len, cmd->write_data_done, 1265 + cmd->se_cmd.data_length); 1298 1266 1299 1267 sg_off = cmd->write_data_done / PAGE_SIZE; 1300 1268 sg_start = &cmd->se_cmd.t_data_sg[sg_off]; ··· 1306 1270 * FIXME: Non page-aligned unsolicited_data out 1307 1271 */ 1308 1272 if (page_off) { 1309 - pr_err("Received unexpected non-page aligned data payload\n"); 1273 + isert_err("unexpected non-page aligned data payload\n"); 1310 1274 dump_stack(); 1311 1275 return -1; 1312 1276 } 1313 - pr_debug("Copying DataOut: sg_start: %p, sg_off: %u sg_nents: %u from %p %u\n", 1314 - sg_start, sg_off, sg_nents, &rx_desc->data[0], unsol_data_len); 1277 + isert_dbg("Copying DataOut: sg_start: %p, sg_off: %u " 1278 + "sg_nents: %u from %p %u\n", sg_start, sg_off, 1279 + sg_nents, &rx_desc->data[0], unsol_data_len); 1315 1280 1316 1281 sg_copy_from_buffer(sg_start, sg_nents, &rx_desc->data[0], 1317 1282 unsol_data_len); ··· 1359 1322 1360 1323 text_in = kzalloc(payload_length, GFP_KERNEL); 1361 1324 if (!text_in) { 1362 - pr_err("Unable to allocate text_in of payload_length: %u\n", 1363 - payload_length); 1325 + isert_err("Unable to allocate text_in of payload_length: %u\n", 1326 + payload_length); 1364 1327 return -ENOMEM; 1365 1328 } 1366 1329 cmd->text_in_ptr = text_in; ··· 1385 1348 1386 1349 if (sess->sess_ops->SessionType && 1387 1350 (!(opcode & ISCSI_OP_TEXT) || !(opcode & ISCSI_OP_LOGOUT))) { 1388 - pr_err("Got illegal opcode: 0x%02x in SessionType=Discovery," 1389 - " ignoring\n", opcode); 1351 + isert_err("Got illegal opcode: 0x%02x in SessionType=Discovery," 1352 + " ignoring\n", opcode); 1390 1353 return 0; 1391 1354 } 1392 1355 ··· 1432 1395 break; 1433 1396 1434 1397 ret = iscsit_handle_logout_cmd(conn, cmd, (unsigned char *)hdr); 1435 - if (ret > 0) 1436 - wait_for_completion_timeout(&conn->conn_logout_comp, 1437 - SECONDS_FOR_LOGOUT_COMP * 1438 - HZ); 1439 1398 break; 1440 1399 case ISCSI_OP_TEXT: 1441 1400 cmd = isert_allocate_cmd(conn); ··· 1443 1410 rx_desc, (struct iscsi_text *)hdr); 1444 1411 break; 1445 1412 default: 1446 - pr_err("Got unknown iSCSI OpCode: 0x%02x\n", opcode); 1413 + isert_err("Got unknown iSCSI OpCode: 0x%02x\n", opcode); 1447 1414 dump_stack(); 1448 1415 break; 1449 1416 } ··· 1464 1431 if (iser_hdr->flags & ISER_RSV) { 1465 1432 read_stag = be32_to_cpu(iser_hdr->read_stag); 1466 1433 read_va = be64_to_cpu(iser_hdr->read_va); 1467 - pr_debug("ISER_RSV: read_stag: 0x%08x read_va: 0x%16llx\n", 1468 - read_stag, (unsigned long long)read_va); 1434 + isert_dbg("ISER_RSV: read_stag: 0x%x read_va: 0x%llx\n", 1435 + read_stag, (unsigned long long)read_va); 1469 1436 } 1470 1437 if (iser_hdr->flags & ISER_WSV) { 1471 1438 write_stag = be32_to_cpu(iser_hdr->write_stag); 1472 1439 write_va = be64_to_cpu(iser_hdr->write_va); 1473 - pr_debug("ISER_WSV: write__stag: 0x%08x write_va: 0x%16llx\n", 1474 - write_stag, (unsigned long long)write_va); 1440 + isert_dbg("ISER_WSV: write_stag: 0x%x write_va: 0x%llx\n", 1441 + write_stag, (unsigned long long)write_va); 1475 1442 } 1476 1443 1477 - pr_debug("ISER ISCSI_CTRL PDU\n"); 1444 + isert_dbg("ISER ISCSI_CTRL PDU\n"); 1478 1445 break; 1479 1446 case ISER_HELLO: 1480 - pr_err("iSER Hello message\n"); 1447 + isert_err("iSER Hello message\n"); 1481 1448 break; 1482 1449 default: 1483 - pr_warn("Unknown iSER hdr flags: 0x%02x\n", iser_hdr->flags); 1450 + isert_warn("Unknown iSER hdr flags: 0x%02x\n", iser_hdr->flags); 1484 1451 break; 1485 1452 } 1486 1453 ··· 1490 1457 1491 1458 static void 1492 1459 isert_rx_completion(struct iser_rx_desc *desc, struct isert_conn *isert_conn, 1493 - unsigned long xfer_len) 1460 + u32 xfer_len) 1494 1461 { 1495 1462 struct ib_device *ib_dev = isert_conn->conn_cm_id->device; 1496 1463 struct iscsi_hdr *hdr; ··· 1500 1467 if ((char *)desc == isert_conn->login_req_buf) { 1501 1468 rx_dma = isert_conn->login_req_dma; 1502 1469 rx_buflen = ISER_RX_LOGIN_SIZE; 1503 - pr_debug("ISER login_buf: Using rx_dma: 0x%llx, rx_buflen: %d\n", 1470 + isert_dbg("login_buf: Using rx_dma: 0x%llx, rx_buflen: %d\n", 1504 1471 rx_dma, rx_buflen); 1505 1472 } else { 1506 1473 rx_dma = desc->dma_addr; 1507 1474 rx_buflen = ISER_RX_PAYLOAD_SIZE; 1508 - pr_debug("ISER req_buf: Using rx_dma: 0x%llx, rx_buflen: %d\n", 1475 + isert_dbg("req_buf: Using rx_dma: 0x%llx, rx_buflen: %d\n", 1509 1476 rx_dma, rx_buflen); 1510 1477 } 1511 1478 1512 1479 ib_dma_sync_single_for_cpu(ib_dev, rx_dma, rx_buflen, DMA_FROM_DEVICE); 1513 1480 1514 1481 hdr = &desc->iscsi_header; 1515 - pr_debug("iSCSI opcode: 0x%02x, ITT: 0x%08x, flags: 0x%02x dlen: %d\n", 1482 + isert_dbg("iSCSI opcode: 0x%02x, ITT: 0x%08x, flags: 0x%02x dlen: %d\n", 1516 1483 hdr->opcode, hdr->itt, hdr->flags, 1517 1484 (int)(xfer_len - ISER_HEADERS_LEN)); 1518 1485 1519 - if ((char *)desc == isert_conn->login_req_buf) 1520 - isert_rx_login_req(desc, xfer_len - ISER_HEADERS_LEN, 1521 - isert_conn); 1522 - else 1486 + if ((char *)desc == isert_conn->login_req_buf) { 1487 + isert_conn->login_req_len = xfer_len - ISER_HEADERS_LEN; 1488 + if (isert_conn->conn) { 1489 + struct iscsi_login *login = isert_conn->conn->conn_login; 1490 + 1491 + if (login && !login->first_request) 1492 + isert_rx_login_req(isert_conn); 1493 + } 1494 + mutex_lock(&isert_conn->conn_mutex); 1495 + complete(&isert_conn->login_req_comp); 1496 + mutex_unlock(&isert_conn->conn_mutex); 1497 + } else { 1523 1498 isert_rx_do_work(desc, isert_conn); 1499 + } 1524 1500 1525 1501 ib_dma_sync_single_for_device(ib_dev, rx_dma, rx_buflen, 1526 1502 DMA_FROM_DEVICE); 1527 1503 1528 1504 isert_conn->post_recv_buf_count--; 1529 - pr_debug("iSERT: Decremented post_recv_buf_count: %d\n", 1530 - isert_conn->post_recv_buf_count); 1505 + isert_dbg("Decremented post_recv_buf_count: %d\n", 1506 + isert_conn->post_recv_buf_count); 1531 1507 1532 1508 if ((char *)desc == isert_conn->login_req_buf) 1533 1509 return; ··· 1547 1505 ISERT_MIN_POSTED_RX); 1548 1506 err = isert_post_recv(isert_conn, count); 1549 1507 if (err) { 1550 - pr_err("isert_post_recv() count: %d failed, %d\n", 1508 + isert_err("isert_post_recv() count: %d failed, %d\n", 1551 1509 count, err); 1552 1510 } 1553 1511 } ··· 1576 1534 data->dma_nents = ib_dma_map_sg(ib_dev, data->sg, data->nents, 1577 1535 data->dma_dir); 1578 1536 if (unlikely(!data->dma_nents)) { 1579 - pr_err("Cmd: unable to dma map SGs %p\n", sg); 1537 + isert_err("Cmd: unable to dma map SGs %p\n", sg); 1580 1538 return -EINVAL; 1581 1539 } 1582 1540 1583 - pr_debug("Mapped cmd: %p count: %u sg: %p sg_nents: %u rdma_len %d\n", 1584 - isert_cmd, data->dma_nents, data->sg, data->nents, data->len); 1541 + isert_dbg("Mapped cmd: %p count: %u sg: %p sg_nents: %u rdma_len %d\n", 1542 + isert_cmd, data->dma_nents, data->sg, data->nents, data->len); 1585 1543 1586 1544 return 0; 1587 1545 } ··· 1602 1560 { 1603 1561 struct isert_rdma_wr *wr = &isert_cmd->rdma_wr; 1604 1562 1605 - pr_debug("isert_unmap_cmd: %p\n", isert_cmd); 1563 + isert_dbg("Cmd %p\n", isert_cmd); 1606 1564 1607 1565 if (wr->data.sg) { 1608 - pr_debug("isert_unmap_cmd: %p unmap_sg op\n", isert_cmd); 1566 + isert_dbg("Cmd %p unmap_sg op\n", isert_cmd); 1609 1567 isert_unmap_data_buf(isert_conn, &wr->data); 1610 1568 } 1611 1569 1612 1570 if (wr->send_wr) { 1613 - pr_debug("isert_unmap_cmd: %p free send_wr\n", isert_cmd); 1571 + isert_dbg("Cmd %p free send_wr\n", isert_cmd); 1614 1572 kfree(wr->send_wr); 1615 1573 wr->send_wr = NULL; 1616 1574 } 1617 1575 1618 1576 if (wr->ib_sge) { 1619 - pr_debug("isert_unmap_cmd: %p free ib_sge\n", isert_cmd); 1577 + isert_dbg("Cmd %p free ib_sge\n", isert_cmd); 1620 1578 kfree(wr->ib_sge); 1621 1579 wr->ib_sge = NULL; 1622 1580 } ··· 1628 1586 struct isert_rdma_wr *wr = &isert_cmd->rdma_wr; 1629 1587 LIST_HEAD(unmap_list); 1630 1588 1631 - pr_debug("unreg_fastreg_cmd: %p\n", isert_cmd); 1589 + isert_dbg("Cmd %p\n", isert_cmd); 1632 1590 1633 1591 if (wr->fr_desc) { 1634 - pr_debug("unreg_fastreg_cmd: %p free fr_desc %p\n", 1635 - isert_cmd, wr->fr_desc); 1592 + isert_dbg("Cmd %p free fr_desc %p\n", isert_cmd, wr->fr_desc); 1636 1593 if (wr->fr_desc->ind & ISERT_PROTECTED) { 1637 1594 isert_unmap_data_buf(isert_conn, &wr->prot); 1638 1595 wr->fr_desc->ind &= ~ISERT_PROTECTED; ··· 1643 1602 } 1644 1603 1645 1604 if (wr->data.sg) { 1646 - pr_debug("unreg_fastreg_cmd: %p unmap_sg op\n", isert_cmd); 1605 + isert_dbg("Cmd %p unmap_sg op\n", isert_cmd); 1647 1606 isert_unmap_data_buf(isert_conn, &wr->data); 1648 1607 } 1649 1608 ··· 1659 1618 struct iscsi_conn *conn = isert_conn->conn; 1660 1619 struct isert_device *device = isert_conn->conn_device; 1661 1620 1662 - pr_debug("Entering isert_put_cmd: %p\n", isert_cmd); 1621 + isert_dbg("Cmd %p\n", isert_cmd); 1663 1622 1664 1623 switch (cmd->iscsi_opcode) { 1665 1624 case ISCSI_OP_SCSI_CMD: ··· 1709 1668 * associated cmd->se_cmd needs to be released. 1710 1669 */ 1711 1670 if (cmd->se_cmd.se_tfo != NULL) { 1712 - pr_debug("Calling transport_generic_free_cmd from" 1671 + isert_dbg("Calling transport_generic_free_cmd from" 1713 1672 " isert_put_cmd for 0x%02x\n", 1714 1673 cmd->iscsi_opcode); 1715 1674 transport_generic_free_cmd(&cmd->se_cmd, 0); ··· 1728 1687 isert_unmap_tx_desc(struct iser_tx_desc *tx_desc, struct ib_device *ib_dev) 1729 1688 { 1730 1689 if (tx_desc->dma_addr != 0) { 1731 - pr_debug("Calling ib_dma_unmap_single for tx_desc->dma_addr\n"); 1690 + isert_dbg("unmap single for tx_desc->dma_addr\n"); 1732 1691 ib_dma_unmap_single(ib_dev, tx_desc->dma_addr, 1733 1692 ISER_HEADERS_LEN, DMA_TO_DEVICE); 1734 1693 tx_desc->dma_addr = 0; ··· 1740 1699 struct ib_device *ib_dev, bool comp_err) 1741 1700 { 1742 1701 if (isert_cmd->pdu_buf_dma != 0) { 1743 - pr_debug("Calling ib_dma_unmap_single for isert_cmd->pdu_buf_dma\n"); 1702 + isert_dbg("unmap single for isert_cmd->pdu_buf_dma\n"); 1744 1703 ib_dma_unmap_single(ib_dev, isert_cmd->pdu_buf_dma, 1745 1704 isert_cmd->pdu_buf_len, DMA_TO_DEVICE); 1746 1705 isert_cmd->pdu_buf_dma = 0; ··· 1758 1717 1759 1718 ret = ib_check_mr_status(sig_mr, IB_MR_CHECK_SIG_STATUS, &mr_status); 1760 1719 if (ret) { 1761 - pr_err("ib_check_mr_status failed, ret %d\n", ret); 1720 + isert_err("ib_check_mr_status failed, ret %d\n", ret); 1762 1721 goto fail_mr_status; 1763 1722 } 1764 1723 ··· 1781 1740 do_div(sec_offset_err, block_size); 1782 1741 se_cmd->bad_sector = sec_offset_err + se_cmd->t_task_lba; 1783 1742 1784 - pr_err("isert: PI error found type %d at sector 0x%llx " 1785 - "expected 0x%x vs actual 0x%x\n", 1786 - mr_status.sig_err.err_type, 1787 - (unsigned long long)se_cmd->bad_sector, 1788 - mr_status.sig_err.expected, 1789 - mr_status.sig_err.actual); 1743 + isert_err("PI error found type %d at sector 0x%llx " 1744 + "expected 0x%x vs actual 0x%x\n", 1745 + mr_status.sig_err.err_type, 1746 + (unsigned long long)se_cmd->bad_sector, 1747 + mr_status.sig_err.expected, 1748 + mr_status.sig_err.actual); 1790 1749 ret = 1; 1791 1750 } 1792 1751 ··· 1842 1801 cmd->write_data_done = wr->data.len; 1843 1802 wr->send_wr_num = 0; 1844 1803 1845 - pr_debug("Cmd: %p RDMA_READ comp calling execute_cmd\n", isert_cmd); 1804 + isert_dbg("Cmd: %p RDMA_READ comp calling execute_cmd\n", isert_cmd); 1846 1805 spin_lock_bh(&cmd->istate_lock); 1847 1806 cmd->cmd_flags |= ICF_GOT_LAST_DATAOUT; 1848 1807 cmd->i_state = ISTATE_RECEIVED_LAST_DATAOUT; ··· 1864 1823 struct ib_device *ib_dev = isert_conn->conn_cm_id->device; 1865 1824 struct iscsi_cmd *cmd = isert_cmd->iscsi_cmd; 1866 1825 1826 + isert_dbg("Cmd %p i_state %d\n", isert_cmd, cmd->i_state); 1827 + 1867 1828 switch (cmd->i_state) { 1868 1829 case ISTATE_SEND_TASKMGTRSP: 1869 - pr_debug("Calling iscsit_tmr_post_handler >>>>>>>>>>>>>>>>>\n"); 1870 - 1871 - atomic_dec(&isert_conn->post_send_buf_count); 1872 1830 iscsit_tmr_post_handler(cmd, cmd->conn); 1873 - 1831 + case ISTATE_SEND_REJECT: /* FALLTHRU */ 1832 + case ISTATE_SEND_TEXTRSP: /* FALLTHRU */ 1874 1833 cmd->i_state = ISTATE_SENT_STATUS; 1875 - isert_completion_put(&isert_cmd->tx_desc, isert_cmd, ib_dev, false); 1876 - break; 1877 - case ISTATE_SEND_REJECT: 1878 - pr_debug("Got isert_do_control_comp ISTATE_SEND_REJECT: >>>\n"); 1879 - atomic_dec(&isert_conn->post_send_buf_count); 1880 - 1881 - cmd->i_state = ISTATE_SENT_STATUS; 1882 - isert_completion_put(&isert_cmd->tx_desc, isert_cmd, ib_dev, false); 1834 + isert_completion_put(&isert_cmd->tx_desc, isert_cmd, 1835 + ib_dev, false); 1883 1836 break; 1884 1837 case ISTATE_SEND_LOGOUTRSP: 1885 - pr_debug("Calling iscsit_logout_post_handler >>>>>>>>>>>>>>\n"); 1886 - 1887 - atomic_dec(&isert_conn->post_send_buf_count); 1888 1838 iscsit_logout_post_handler(cmd, cmd->conn); 1889 1839 break; 1890 - case ISTATE_SEND_TEXTRSP: 1891 - atomic_dec(&isert_conn->post_send_buf_count); 1892 - cmd->i_state = ISTATE_SENT_STATUS; 1893 - isert_completion_put(&isert_cmd->tx_desc, isert_cmd, ib_dev, false); 1894 - break; 1895 1840 default: 1896 - pr_err("Unknown do_control_comp i_state %d\n", cmd->i_state); 1841 + isert_err("Unknown i_state %d\n", cmd->i_state); 1897 1842 dump_stack(); 1898 1843 break; 1899 1844 } ··· 1892 1865 struct ib_device *ib_dev) 1893 1866 { 1894 1867 struct iscsi_cmd *cmd = isert_cmd->iscsi_cmd; 1895 - struct isert_rdma_wr *wr = &isert_cmd->rdma_wr; 1896 1868 1897 1869 if (cmd->i_state == ISTATE_SEND_TASKMGTRSP || 1898 1870 cmd->i_state == ISTATE_SEND_LOGOUTRSP || ··· 1904 1878 return; 1905 1879 } 1906 1880 1907 - /** 1908 - * If send_wr_num is 0 this means that we got 1909 - * RDMA completion and we cleared it and we should 1910 - * simply decrement the response post. else the 1911 - * response is incorporated in send_wr_num, just 1912 - * sub it. 1913 - **/ 1914 - if (wr->send_wr_num) 1915 - atomic_sub(wr->send_wr_num, &isert_conn->post_send_buf_count); 1916 - else 1917 - atomic_dec(&isert_conn->post_send_buf_count); 1918 - 1919 1881 cmd->i_state = ISTATE_SENT_STATUS; 1920 1882 isert_completion_put(tx_desc, isert_cmd, ib_dev, false); 1921 - } 1922 - 1923 - static void 1924 - __isert_send_completion(struct iser_tx_desc *tx_desc, 1925 - struct isert_conn *isert_conn) 1926 - { 1927 - struct ib_device *ib_dev = isert_conn->conn_cm_id->device; 1928 - struct isert_cmd *isert_cmd = tx_desc->isert_cmd; 1929 - struct isert_rdma_wr *wr; 1930 - 1931 - if (!isert_cmd) { 1932 - atomic_dec(&isert_conn->post_send_buf_count); 1933 - isert_unmap_tx_desc(tx_desc, ib_dev); 1934 - return; 1935 - } 1936 - wr = &isert_cmd->rdma_wr; 1937 - 1938 - switch (wr->iser_ib_op) { 1939 - case ISER_IB_RECV: 1940 - pr_err("isert_send_completion: Got ISER_IB_RECV\n"); 1941 - dump_stack(); 1942 - break; 1943 - case ISER_IB_SEND: 1944 - pr_debug("isert_send_completion: Got ISER_IB_SEND\n"); 1945 - isert_response_completion(tx_desc, isert_cmd, 1946 - isert_conn, ib_dev); 1947 - break; 1948 - case ISER_IB_RDMA_WRITE: 1949 - pr_debug("isert_send_completion: Got ISER_IB_RDMA_WRITE\n"); 1950 - atomic_sub(wr->send_wr_num, &isert_conn->post_send_buf_count); 1951 - isert_completion_rdma_write(tx_desc, isert_cmd); 1952 - break; 1953 - case ISER_IB_RDMA_READ: 1954 - pr_debug("isert_send_completion: Got ISER_IB_RDMA_READ:\n"); 1955 - 1956 - atomic_sub(wr->send_wr_num, &isert_conn->post_send_buf_count); 1957 - isert_completion_rdma_read(tx_desc, isert_cmd); 1958 - break; 1959 - default: 1960 - pr_err("Unknown wr->iser_ib_op: 0x%02x\n", wr->iser_ib_op); 1961 - dump_stack(); 1962 - break; 1963 - } 1964 1883 } 1965 1884 1966 1885 static void 1967 1886 isert_send_completion(struct iser_tx_desc *tx_desc, 1968 1887 struct isert_conn *isert_conn) 1969 1888 { 1970 - struct llist_node *llnode = tx_desc->comp_llnode_batch; 1971 - struct iser_tx_desc *t; 1972 - /* 1973 - * Drain coalesced completion llist starting from comp_llnode_batch 1974 - * setup in isert_init_send_wr(), and then complete trailing tx_desc. 1975 - */ 1976 - while (llnode) { 1977 - t = llist_entry(llnode, struct iser_tx_desc, comp_llnode); 1978 - llnode = llist_next(llnode); 1979 - __isert_send_completion(t, isert_conn); 1980 - } 1981 - __isert_send_completion(tx_desc, isert_conn); 1982 - } 1983 - 1984 - static void 1985 - isert_cq_drain_comp_llist(struct isert_conn *isert_conn, struct ib_device *ib_dev) 1986 - { 1987 - struct llist_node *llnode; 1988 - struct isert_rdma_wr *wr; 1989 - struct iser_tx_desc *t; 1990 - 1991 - mutex_lock(&isert_conn->conn_mutex); 1992 - llnode = llist_del_all(&isert_conn->conn_comp_llist); 1993 - isert_conn->conn_comp_batch = 0; 1994 - mutex_unlock(&isert_conn->conn_mutex); 1995 - 1996 - while (llnode) { 1997 - t = llist_entry(llnode, struct iser_tx_desc, comp_llnode); 1998 - llnode = llist_next(llnode); 1999 - wr = &t->isert_cmd->rdma_wr; 2000 - 2001 - /** 2002 - * If send_wr_num is 0 this means that we got 2003 - * RDMA completion and we cleared it and we should 2004 - * simply decrement the response post. else the 2005 - * response is incorporated in send_wr_num, just 2006 - * sub it. 2007 - **/ 2008 - if (wr->send_wr_num) 2009 - atomic_sub(wr->send_wr_num, 2010 - &isert_conn->post_send_buf_count); 2011 - else 2012 - atomic_dec(&isert_conn->post_send_buf_count); 2013 - 2014 - isert_completion_put(t, t->isert_cmd, ib_dev, true); 2015 - } 2016 - } 2017 - 2018 - static void 2019 - isert_cq_tx_comp_err(struct iser_tx_desc *tx_desc, struct isert_conn *isert_conn) 2020 - { 2021 1889 struct ib_device *ib_dev = isert_conn->conn_cm_id->device; 2022 1890 struct isert_cmd *isert_cmd = tx_desc->isert_cmd; 2023 - struct llist_node *llnode = tx_desc->comp_llnode_batch; 2024 1891 struct isert_rdma_wr *wr; 2025 - struct iser_tx_desc *t; 2026 1892 2027 - while (llnode) { 2028 - t = llist_entry(llnode, struct iser_tx_desc, comp_llnode); 2029 - llnode = llist_next(llnode); 2030 - wr = &t->isert_cmd->rdma_wr; 2031 - 2032 - /** 2033 - * If send_wr_num is 0 this means that we got 2034 - * RDMA completion and we cleared it and we should 2035 - * simply decrement the response post. else the 2036 - * response is incorporated in send_wr_num, just 2037 - * sub it. 2038 - **/ 2039 - if (wr->send_wr_num) 2040 - atomic_sub(wr->send_wr_num, 2041 - &isert_conn->post_send_buf_count); 2042 - else 2043 - atomic_dec(&isert_conn->post_send_buf_count); 2044 - 2045 - isert_completion_put(t, t->isert_cmd, ib_dev, true); 2046 - } 2047 - tx_desc->comp_llnode_batch = NULL; 2048 - 2049 - if (!isert_cmd) 1893 + if (!isert_cmd) { 2050 1894 isert_unmap_tx_desc(tx_desc, ib_dev); 2051 - else 2052 - isert_completion_put(tx_desc, isert_cmd, ib_dev, true); 2053 - } 2054 - 2055 - static void 2056 - isert_cq_rx_comp_err(struct isert_conn *isert_conn) 2057 - { 2058 - struct ib_device *ib_dev = isert_conn->conn_cm_id->device; 2059 - struct iscsi_conn *conn = isert_conn->conn; 2060 - 2061 - if (isert_conn->post_recv_buf_count) 2062 1895 return; 2063 - 2064 - isert_cq_drain_comp_llist(isert_conn, ib_dev); 2065 - 2066 - if (conn->sess) { 2067 - target_sess_cmd_list_set_waiting(conn->sess->se_sess); 2068 - target_wait_for_sess_cmds(conn->sess->se_sess); 2069 1896 } 1897 + wr = &isert_cmd->rdma_wr; 2070 1898 2071 - while (atomic_read(&isert_conn->post_send_buf_count)) 2072 - msleep(3000); 1899 + isert_dbg("Cmd %p iser_ib_op %d\n", isert_cmd, wr->iser_ib_op); 2073 1900 2074 - mutex_lock(&isert_conn->conn_mutex); 2075 - isert_conn->state = ISER_CONN_DOWN; 2076 - mutex_unlock(&isert_conn->conn_mutex); 1901 + switch (wr->iser_ib_op) { 1902 + case ISER_IB_RECV: 1903 + isert_err("Got ISER_IB_RECV\n"); 1904 + dump_stack(); 1905 + break; 1906 + case ISER_IB_SEND: 1907 + isert_response_completion(tx_desc, isert_cmd, 1908 + isert_conn, ib_dev); 1909 + break; 1910 + case ISER_IB_RDMA_WRITE: 1911 + isert_completion_rdma_write(tx_desc, isert_cmd); 1912 + break; 1913 + case ISER_IB_RDMA_READ: 1914 + isert_completion_rdma_read(tx_desc, isert_cmd); 1915 + break; 1916 + default: 1917 + isert_err("Unknown wr->iser_ib_op: 0x%x\n", wr->iser_ib_op); 1918 + dump_stack(); 1919 + break; 1920 + } 1921 + } 2077 1922 2078 - iscsit_cause_connection_reinstatement(isert_conn->conn, 0); 1923 + /** 1924 + * is_isert_tx_desc() - Indicate if the completion wr_id 1925 + * is a TX descriptor or not. 1926 + * @isert_conn: iser connection 1927 + * @wr_id: completion WR identifier 1928 + * 1929 + * Since we cannot rely on wc opcode in FLUSH errors 1930 + * we must work around it by checking if the wr_id address 1931 + * falls in the iser connection rx_descs buffer. If so 1932 + * it is an RX descriptor, otherwize it is a TX. 1933 + */ 1934 + static inline bool 1935 + is_isert_tx_desc(struct isert_conn *isert_conn, void *wr_id) 1936 + { 1937 + void *start = isert_conn->conn_rx_descs; 1938 + int len = ISERT_QP_MAX_RECV_DTOS * sizeof(*isert_conn->conn_rx_descs); 2079 1939 2080 - complete(&isert_conn->conn_wait_comp_err); 1940 + if (wr_id >= start && wr_id < start + len) 1941 + return false; 1942 + 1943 + return true; 2081 1944 } 2082 1945 2083 1946 static void 2084 - isert_cq_tx_work(struct work_struct *work) 1947 + isert_cq_comp_err(struct isert_conn *isert_conn, struct ib_wc *wc) 2085 1948 { 2086 - struct isert_cq_desc *cq_desc = container_of(work, 2087 - struct isert_cq_desc, cq_tx_work); 2088 - struct isert_device *device = cq_desc->device; 2089 - int cq_index = cq_desc->cq_index; 2090 - struct ib_cq *tx_cq = device->dev_tx_cq[cq_index]; 1949 + if (wc->wr_id == ISER_BEACON_WRID) { 1950 + isert_info("conn %p completing conn_wait_comp_err\n", 1951 + isert_conn); 1952 + complete(&isert_conn->conn_wait_comp_err); 1953 + } else if (is_isert_tx_desc(isert_conn, (void *)(uintptr_t)wc->wr_id)) { 1954 + struct ib_device *ib_dev = isert_conn->conn_cm_id->device; 1955 + struct isert_cmd *isert_cmd; 1956 + struct iser_tx_desc *desc; 1957 + 1958 + desc = (struct iser_tx_desc *)(uintptr_t)wc->wr_id; 1959 + isert_cmd = desc->isert_cmd; 1960 + if (!isert_cmd) 1961 + isert_unmap_tx_desc(desc, ib_dev); 1962 + else 1963 + isert_completion_put(desc, isert_cmd, ib_dev, true); 1964 + } else { 1965 + isert_conn->post_recv_buf_count--; 1966 + if (!isert_conn->post_recv_buf_count) 1967 + iscsit_cause_connection_reinstatement(isert_conn->conn, 0); 1968 + } 1969 + } 1970 + 1971 + static void 1972 + isert_handle_wc(struct ib_wc *wc) 1973 + { 2091 1974 struct isert_conn *isert_conn; 2092 1975 struct iser_tx_desc *tx_desc; 2093 - struct ib_wc wc; 2094 - 2095 - while (ib_poll_cq(tx_cq, 1, &wc) == 1) { 2096 - tx_desc = (struct iser_tx_desc *)(unsigned long)wc.wr_id; 2097 - isert_conn = wc.qp->qp_context; 2098 - 2099 - if (wc.status == IB_WC_SUCCESS) { 2100 - isert_send_completion(tx_desc, isert_conn); 2101 - } else { 2102 - pr_debug("TX wc.status != IB_WC_SUCCESS >>>>>>>>>>>>>>\n"); 2103 - pr_debug("TX wc.status: 0x%08x\n", wc.status); 2104 - pr_debug("TX wc.vendor_err: 0x%08x\n", wc.vendor_err); 2105 - 2106 - if (wc.wr_id != ISER_FASTREG_LI_WRID) { 2107 - if (tx_desc->llnode_active) 2108 - continue; 2109 - 2110 - atomic_dec(&isert_conn->post_send_buf_count); 2111 - isert_cq_tx_comp_err(tx_desc, isert_conn); 2112 - } 2113 - } 2114 - } 2115 - 2116 - ib_req_notify_cq(tx_cq, IB_CQ_NEXT_COMP); 2117 - } 2118 - 2119 - static void 2120 - isert_cq_tx_callback(struct ib_cq *cq, void *context) 2121 - { 2122 - struct isert_cq_desc *cq_desc = (struct isert_cq_desc *)context; 2123 - 2124 - queue_work(isert_comp_wq, &cq_desc->cq_tx_work); 2125 - } 2126 - 2127 - static void 2128 - isert_cq_rx_work(struct work_struct *work) 2129 - { 2130 - struct isert_cq_desc *cq_desc = container_of(work, 2131 - struct isert_cq_desc, cq_rx_work); 2132 - struct isert_device *device = cq_desc->device; 2133 - int cq_index = cq_desc->cq_index; 2134 - struct ib_cq *rx_cq = device->dev_rx_cq[cq_index]; 2135 - struct isert_conn *isert_conn; 2136 1976 struct iser_rx_desc *rx_desc; 2137 - struct ib_wc wc; 2138 - unsigned long xfer_len; 2139 1977 2140 - while (ib_poll_cq(rx_cq, 1, &wc) == 1) { 2141 - rx_desc = (struct iser_rx_desc *)(unsigned long)wc.wr_id; 2142 - isert_conn = wc.qp->qp_context; 2143 - 2144 - if (wc.status == IB_WC_SUCCESS) { 2145 - xfer_len = (unsigned long)wc.byte_len; 2146 - isert_rx_completion(rx_desc, isert_conn, xfer_len); 1978 + isert_conn = wc->qp->qp_context; 1979 + if (likely(wc->status == IB_WC_SUCCESS)) { 1980 + if (wc->opcode == IB_WC_RECV) { 1981 + rx_desc = (struct iser_rx_desc *)(uintptr_t)wc->wr_id; 1982 + isert_rx_completion(rx_desc, isert_conn, wc->byte_len); 2147 1983 } else { 2148 - pr_debug("RX wc.status != IB_WC_SUCCESS >>>>>>>>>>>>>>\n"); 2149 - if (wc.status != IB_WC_WR_FLUSH_ERR) { 2150 - pr_debug("RX wc.status: 0x%08x\n", wc.status); 2151 - pr_debug("RX wc.vendor_err: 0x%08x\n", 2152 - wc.vendor_err); 2153 - } 2154 - isert_conn->post_recv_buf_count--; 2155 - isert_cq_rx_comp_err(isert_conn); 1984 + tx_desc = (struct iser_tx_desc *)(uintptr_t)wc->wr_id; 1985 + isert_send_completion(tx_desc, isert_conn); 2156 1986 } 2157 - } 1987 + } else { 1988 + if (wc->status != IB_WC_WR_FLUSH_ERR) 1989 + isert_err("wr id %llx status %d vend_err %x\n", 1990 + wc->wr_id, wc->status, wc->vendor_err); 1991 + else 1992 + isert_dbg("flush error: wr id %llx\n", wc->wr_id); 2158 1993 2159 - ib_req_notify_cq(rx_cq, IB_CQ_NEXT_COMP); 1994 + if (wc->wr_id != ISER_FASTREG_LI_WRID) 1995 + isert_cq_comp_err(isert_conn, wc); 1996 + } 2160 1997 } 2161 1998 2162 1999 static void 2163 - isert_cq_rx_callback(struct ib_cq *cq, void *context) 2000 + isert_cq_work(struct work_struct *work) 2164 2001 { 2165 - struct isert_cq_desc *cq_desc = (struct isert_cq_desc *)context; 2002 + enum { isert_poll_budget = 65536 }; 2003 + struct isert_comp *comp = container_of(work, struct isert_comp, 2004 + work); 2005 + struct ib_wc *const wcs = comp->wcs; 2006 + int i, n, completed = 0; 2166 2007 2167 - queue_work(isert_rx_wq, &cq_desc->cq_rx_work); 2008 + while ((n = ib_poll_cq(comp->cq, ARRAY_SIZE(comp->wcs), wcs)) > 0) { 2009 + for (i = 0; i < n; i++) 2010 + isert_handle_wc(&wcs[i]); 2011 + 2012 + completed += n; 2013 + if (completed >= isert_poll_budget) 2014 + break; 2015 + } 2016 + 2017 + ib_req_notify_cq(comp->cq, IB_CQ_NEXT_COMP); 2018 + } 2019 + 2020 + static void 2021 + isert_cq_callback(struct ib_cq *cq, void *context) 2022 + { 2023 + struct isert_comp *comp = context; 2024 + 2025 + queue_work(isert_comp_wq, &comp->work); 2168 2026 } 2169 2027 2170 2028 static int ··· 2057 2147 struct ib_send_wr *wr_failed; 2058 2148 int ret; 2059 2149 2060 - atomic_inc(&isert_conn->post_send_buf_count); 2061 - 2062 2150 ret = ib_post_send(isert_conn->conn_qp, &isert_cmd->tx_desc.send_wr, 2063 2151 &wr_failed); 2064 2152 if (ret) { 2065 - pr_err("ib_post_send failed with %d\n", ret); 2066 - atomic_dec(&isert_conn->post_send_buf_count); 2153 + isert_err("ib_post_send failed with %d\n", ret); 2067 2154 return ret; 2068 2155 } 2069 2156 return ret; ··· 2107 2200 isert_cmd->tx_desc.num_sge = 2; 2108 2201 } 2109 2202 2110 - isert_init_send_wr(isert_conn, isert_cmd, send_wr, false); 2203 + isert_init_send_wr(isert_conn, isert_cmd, send_wr); 2111 2204 2112 - pr_debug("Posting SCSI Response IB_WR_SEND >>>>>>>>>>>>>>>>>>>>>>\n"); 2205 + isert_dbg("Posting SCSI Response\n"); 2113 2206 2114 2207 return isert_post_response(isert_conn, isert_cmd); 2115 2208 } ··· 2138 2231 struct isert_conn *isert_conn = (struct isert_conn *)conn->context; 2139 2232 struct isert_device *device = isert_conn->conn_device; 2140 2233 2141 - if (device->pi_capable) 2142 - return TARGET_PROT_ALL; 2234 + if (conn->tpg->tpg_attrib.t10_pi) { 2235 + if (device->pi_capable) { 2236 + isert_info("conn %p PI offload enabled\n", isert_conn); 2237 + isert_conn->pi_support = true; 2238 + return TARGET_PROT_ALL; 2239 + } 2240 + } 2241 + 2242 + isert_info("conn %p PI offload disabled\n", isert_conn); 2243 + isert_conn->pi_support = false; 2143 2244 2144 2245 return TARGET_PROT_NORMAL; 2145 2246 } ··· 2165 2250 &isert_cmd->tx_desc.iscsi_header, 2166 2251 nopout_response); 2167 2252 isert_init_tx_hdrs(isert_conn, &isert_cmd->tx_desc); 2168 - isert_init_send_wr(isert_conn, isert_cmd, send_wr, false); 2253 + isert_init_send_wr(isert_conn, isert_cmd, send_wr); 2169 2254 2170 - pr_debug("Posting NOPIN Response IB_WR_SEND >>>>>>>>>>>>>>>>>>>>>>\n"); 2255 + isert_dbg("conn %p Posting NOPIN Response\n", isert_conn); 2171 2256 2172 2257 return isert_post_response(isert_conn, isert_cmd); 2173 2258 } ··· 2183 2268 iscsit_build_logout_rsp(cmd, conn, (struct iscsi_logout_rsp *) 2184 2269 &isert_cmd->tx_desc.iscsi_header); 2185 2270 isert_init_tx_hdrs(isert_conn, &isert_cmd->tx_desc); 2186 - isert_init_send_wr(isert_conn, isert_cmd, send_wr, false); 2271 + isert_init_send_wr(isert_conn, isert_cmd, send_wr); 2187 2272 2188 - pr_debug("Posting Logout Response IB_WR_SEND >>>>>>>>>>>>>>>>>>>>>>\n"); 2273 + isert_dbg("conn %p Posting Logout Response\n", isert_conn); 2189 2274 2190 2275 return isert_post_response(isert_conn, isert_cmd); 2191 2276 } ··· 2201 2286 iscsit_build_task_mgt_rsp(cmd, conn, (struct iscsi_tm_rsp *) 2202 2287 &isert_cmd->tx_desc.iscsi_header); 2203 2288 isert_init_tx_hdrs(isert_conn, &isert_cmd->tx_desc); 2204 - isert_init_send_wr(isert_conn, isert_cmd, send_wr, false); 2289 + isert_init_send_wr(isert_conn, isert_cmd, send_wr); 2205 2290 2206 - pr_debug("Posting Task Management Response IB_WR_SEND >>>>>>>>>>>>>>>>>>>>>>\n"); 2291 + isert_dbg("conn %p Posting Task Management Response\n", isert_conn); 2207 2292 2208 2293 return isert_post_response(isert_conn, isert_cmd); 2209 2294 } ··· 2233 2318 tx_dsg->lkey = isert_conn->conn_mr->lkey; 2234 2319 isert_cmd->tx_desc.num_sge = 2; 2235 2320 2236 - isert_init_send_wr(isert_conn, isert_cmd, send_wr, false); 2321 + isert_init_send_wr(isert_conn, isert_cmd, send_wr); 2237 2322 2238 - pr_debug("Posting Reject IB_WR_SEND >>>>>>>>>>>>>>>>>>>>>>\n"); 2323 + isert_dbg("conn %p Posting Reject\n", isert_conn); 2239 2324 2240 2325 return isert_post_response(isert_conn, isert_cmd); 2241 2326 } ··· 2273 2358 tx_dsg->lkey = isert_conn->conn_mr->lkey; 2274 2359 isert_cmd->tx_desc.num_sge = 2; 2275 2360 } 2276 - isert_init_send_wr(isert_conn, isert_cmd, send_wr, false); 2361 + isert_init_send_wr(isert_conn, isert_cmd, send_wr); 2277 2362 2278 - pr_debug("Posting Text Response IB_WR_SEND >>>>>>>>>>>>>>>>>>>>>>\n"); 2363 + isert_dbg("conn %p Text Reject\n", isert_conn); 2279 2364 2280 2365 return isert_post_response(isert_conn, isert_cmd); 2281 2366 } ··· 2298 2383 2299 2384 send_wr->sg_list = ib_sge; 2300 2385 send_wr->num_sge = sg_nents; 2301 - send_wr->wr_id = (unsigned long)&isert_cmd->tx_desc; 2386 + send_wr->wr_id = (uintptr_t)&isert_cmd->tx_desc; 2302 2387 /* 2303 2388 * Perform mapping of TCM scatterlist memory ib_sge dma_addr. 2304 2389 */ 2305 2390 for_each_sg(sg_start, tmp_sg, sg_nents, i) { 2306 - pr_debug("ISER RDMA from SGL dma_addr: 0x%16llx dma_len: %u, page_off: %u\n", 2307 - (unsigned long long)tmp_sg->dma_address, 2308 - tmp_sg->length, page_off); 2391 + isert_dbg("RDMA from SGL dma_addr: 0x%llx dma_len: %u, " 2392 + "page_off: %u\n", 2393 + (unsigned long long)tmp_sg->dma_address, 2394 + tmp_sg->length, page_off); 2309 2395 2310 2396 ib_sge->addr = ib_sg_dma_address(ib_dev, tmp_sg) + page_off; 2311 2397 ib_sge->length = min_t(u32, data_left, 2312 2398 ib_sg_dma_len(ib_dev, tmp_sg) - page_off); 2313 2399 ib_sge->lkey = isert_conn->conn_mr->lkey; 2314 2400 2315 - pr_debug("RDMA ib_sge: addr: 0x%16llx length: %u lkey: %08x\n", 2316 - ib_sge->addr, ib_sge->length, ib_sge->lkey); 2401 + isert_dbg("RDMA ib_sge: addr: 0x%llx length: %u lkey: %x\n", 2402 + ib_sge->addr, ib_sge->length, ib_sge->lkey); 2317 2403 page_off = 0; 2318 2404 data_left -= ib_sge->length; 2319 2405 ib_sge++; 2320 - pr_debug("Incrementing ib_sge pointer to %p\n", ib_sge); 2406 + isert_dbg("Incrementing ib_sge pointer to %p\n", ib_sge); 2321 2407 } 2322 2408 2323 - pr_debug("Set outgoing sg_list: %p num_sg: %u from TCM SGLs\n", 2324 - send_wr->sg_list, send_wr->num_sge); 2409 + isert_dbg("Set outgoing sg_list: %p num_sg: %u from TCM SGLs\n", 2410 + send_wr->sg_list, send_wr->num_sge); 2325 2411 2326 2412 return sg_nents; 2327 2413 } ··· 2354 2438 2355 2439 ib_sge = kzalloc(sizeof(struct ib_sge) * data->nents, GFP_KERNEL); 2356 2440 if (!ib_sge) { 2357 - pr_warn("Unable to allocate ib_sge\n"); 2441 + isert_warn("Unable to allocate ib_sge\n"); 2358 2442 ret = -ENOMEM; 2359 2443 goto unmap_cmd; 2360 2444 } ··· 2364 2448 wr->send_wr = kzalloc(sizeof(struct ib_send_wr) * wr->send_wr_num, 2365 2449 GFP_KERNEL); 2366 2450 if (!wr->send_wr) { 2367 - pr_debug("Unable to allocate wr->send_wr\n"); 2451 + isert_dbg("Unable to allocate wr->send_wr\n"); 2368 2452 ret = -ENOMEM; 2369 2453 goto unmap_cmd; 2370 2454 } ··· 2428 2512 chunk_start = start_addr; 2429 2513 end_addr = start_addr + ib_sg_dma_len(ib_dev, tmp_sg); 2430 2514 2431 - pr_debug("SGL[%d] dma_addr: 0x%16llx len: %u\n", 2432 - i, (unsigned long long)tmp_sg->dma_address, 2433 - tmp_sg->length); 2515 + isert_dbg("SGL[%d] dma_addr: 0x%llx len: %u\n", 2516 + i, (unsigned long long)tmp_sg->dma_address, 2517 + tmp_sg->length); 2434 2518 2435 2519 if ((end_addr & ~PAGE_MASK) && i < last_ent) { 2436 2520 new_chunk = 0; ··· 2441 2525 page = chunk_start & PAGE_MASK; 2442 2526 do { 2443 2527 fr_pl[n_pages++] = page; 2444 - pr_debug("Mapped page_list[%d] page_addr: 0x%16llx\n", 2445 - n_pages - 1, page); 2528 + isert_dbg("Mapped page_list[%d] page_addr: 0x%llx\n", 2529 + n_pages - 1, page); 2446 2530 page += PAGE_SIZE; 2447 2531 } while (page < end_addr); 2448 2532 } 2449 2533 2450 2534 return n_pages; 2535 + } 2536 + 2537 + static inline void 2538 + isert_inv_rkey(struct ib_send_wr *inv_wr, struct ib_mr *mr) 2539 + { 2540 + u32 rkey; 2541 + 2542 + memset(inv_wr, 0, sizeof(*inv_wr)); 2543 + inv_wr->wr_id = ISER_FASTREG_LI_WRID; 2544 + inv_wr->opcode = IB_WR_LOCAL_INV; 2545 + inv_wr->ex.invalidate_rkey = mr->rkey; 2546 + 2547 + /* Bump the key */ 2548 + rkey = ib_inc_rkey(mr->rkey); 2549 + ib_update_fast_reg_key(mr, rkey); 2451 2550 } 2452 2551 2453 2552 static int ··· 2479 2548 struct ib_send_wr *bad_wr, *wr = NULL; 2480 2549 int ret, pagelist_len; 2481 2550 u32 page_off; 2482 - u8 key; 2483 2551 2484 2552 if (mem->dma_nents == 1) { 2485 2553 sge->lkey = isert_conn->conn_mr->lkey; 2486 2554 sge->addr = ib_sg_dma_address(ib_dev, &mem->sg[0]); 2487 2555 sge->length = ib_sg_dma_len(ib_dev, &mem->sg[0]); 2488 - pr_debug("%s:%d sge: addr: 0x%llx length: %u lkey: %x\n", 2489 - __func__, __LINE__, sge->addr, sge->length, 2490 - sge->lkey); 2556 + isert_dbg("sge: addr: 0x%llx length: %u lkey: %x\n", 2557 + sge->addr, sge->length, sge->lkey); 2491 2558 return 0; 2492 2559 } 2493 2560 ··· 2501 2572 2502 2573 page_off = mem->offset % PAGE_SIZE; 2503 2574 2504 - pr_debug("Use fr_desc %p sg_nents %d offset %u\n", 2505 - fr_desc, mem->nents, mem->offset); 2575 + isert_dbg("Use fr_desc %p sg_nents %d offset %u\n", 2576 + fr_desc, mem->nents, mem->offset); 2506 2577 2507 2578 pagelist_len = isert_map_fr_pagelist(ib_dev, mem->sg, mem->nents, 2508 2579 &frpl->page_list[0]); 2509 2580 2510 - if (!(fr_desc->ind & ISERT_DATA_KEY_VALID)) { 2511 - memset(&inv_wr, 0, sizeof(inv_wr)); 2512 - inv_wr.wr_id = ISER_FASTREG_LI_WRID; 2513 - inv_wr.opcode = IB_WR_LOCAL_INV; 2514 - inv_wr.ex.invalidate_rkey = mr->rkey; 2581 + if (!(fr_desc->ind & ind)) { 2582 + isert_inv_rkey(&inv_wr, mr); 2515 2583 wr = &inv_wr; 2516 - /* Bump the key */ 2517 - key = (u8)(mr->rkey & 0x000000FF); 2518 - ib_update_fast_reg_key(mr, ++key); 2519 2584 } 2520 2585 2521 2586 /* Prepare FASTREG WR */ ··· 2531 2608 2532 2609 ret = ib_post_send(isert_conn->conn_qp, wr, &bad_wr); 2533 2610 if (ret) { 2534 - pr_err("fast registration failed, ret:%d\n", ret); 2611 + isert_err("fast registration failed, ret:%d\n", ret); 2535 2612 return ret; 2536 2613 } 2537 2614 fr_desc->ind &= ~ind; ··· 2540 2617 sge->addr = frpl->page_list[0] + page_off; 2541 2618 sge->length = mem->len; 2542 2619 2543 - pr_debug("%s:%d sge: addr: 0x%llx length: %u lkey: %x\n", 2544 - __func__, __LINE__, sge->addr, sge->length, 2545 - sge->lkey); 2620 + isert_dbg("sge: addr: 0x%llx length: %u lkey: %x\n", 2621 + sge->addr, sge->length, sge->lkey); 2546 2622 2547 2623 return ret; 2548 2624 } ··· 2587 2665 isert_set_dif_domain(se_cmd, sig_attrs, &sig_attrs->mem); 2588 2666 break; 2589 2667 default: 2590 - pr_err("Unsupported PI operation %d\n", se_cmd->prot_op); 2668 + isert_err("Unsupported PI operation %d\n", se_cmd->prot_op); 2591 2669 return -EINVAL; 2592 2670 } 2593 2671 ··· 2603 2681 } 2604 2682 2605 2683 static int 2606 - isert_reg_sig_mr(struct isert_conn *isert_conn, struct se_cmd *se_cmd, 2607 - struct fast_reg_descriptor *fr_desc, 2608 - struct ib_sge *data_sge, struct ib_sge *prot_sge, 2609 - struct ib_sge *sig_sge) 2684 + isert_reg_sig_mr(struct isert_conn *isert_conn, 2685 + struct se_cmd *se_cmd, 2686 + struct isert_rdma_wr *rdma_wr, 2687 + struct fast_reg_descriptor *fr_desc) 2610 2688 { 2611 2689 struct ib_send_wr sig_wr, inv_wr; 2612 2690 struct ib_send_wr *bad_wr, *wr = NULL; 2613 2691 struct pi_context *pi_ctx = fr_desc->pi_ctx; 2614 2692 struct ib_sig_attrs sig_attrs; 2615 2693 int ret; 2616 - u32 key; 2617 2694 2618 2695 memset(&sig_attrs, 0, sizeof(sig_attrs)); 2619 2696 ret = isert_set_sig_attrs(se_cmd, &sig_attrs); ··· 2622 2701 sig_attrs.check_mask = isert_set_prot_checks(se_cmd->prot_checks); 2623 2702 2624 2703 if (!(fr_desc->ind & ISERT_SIG_KEY_VALID)) { 2625 - memset(&inv_wr, 0, sizeof(inv_wr)); 2626 - inv_wr.opcode = IB_WR_LOCAL_INV; 2627 - inv_wr.wr_id = ISER_FASTREG_LI_WRID; 2628 - inv_wr.ex.invalidate_rkey = pi_ctx->sig_mr->rkey; 2704 + isert_inv_rkey(&inv_wr, pi_ctx->sig_mr); 2629 2705 wr = &inv_wr; 2630 - /* Bump the key */ 2631 - key = (u8)(pi_ctx->sig_mr->rkey & 0x000000FF); 2632 - ib_update_fast_reg_key(pi_ctx->sig_mr, ++key); 2633 2706 } 2634 2707 2635 2708 memset(&sig_wr, 0, sizeof(sig_wr)); 2636 2709 sig_wr.opcode = IB_WR_REG_SIG_MR; 2637 2710 sig_wr.wr_id = ISER_FASTREG_LI_WRID; 2638 - sig_wr.sg_list = data_sge; 2711 + sig_wr.sg_list = &rdma_wr->ib_sg[DATA]; 2639 2712 sig_wr.num_sge = 1; 2640 2713 sig_wr.wr.sig_handover.access_flags = IB_ACCESS_LOCAL_WRITE; 2641 2714 sig_wr.wr.sig_handover.sig_attrs = &sig_attrs; 2642 2715 sig_wr.wr.sig_handover.sig_mr = pi_ctx->sig_mr; 2643 2716 if (se_cmd->t_prot_sg) 2644 - sig_wr.wr.sig_handover.prot = prot_sge; 2717 + sig_wr.wr.sig_handover.prot = &rdma_wr->ib_sg[PROT]; 2645 2718 2646 2719 if (!wr) 2647 2720 wr = &sig_wr; ··· 2644 2729 2645 2730 ret = ib_post_send(isert_conn->conn_qp, wr, &bad_wr); 2646 2731 if (ret) { 2647 - pr_err("fast registration failed, ret:%d\n", ret); 2732 + isert_err("fast registration failed, ret:%d\n", ret); 2648 2733 goto err; 2649 2734 } 2650 2735 fr_desc->ind &= ~ISERT_SIG_KEY_VALID; 2651 2736 2652 - sig_sge->lkey = pi_ctx->sig_mr->lkey; 2653 - sig_sge->addr = 0; 2654 - sig_sge->length = se_cmd->data_length; 2737 + rdma_wr->ib_sg[SIG].lkey = pi_ctx->sig_mr->lkey; 2738 + rdma_wr->ib_sg[SIG].addr = 0; 2739 + rdma_wr->ib_sg[SIG].length = se_cmd->data_length; 2655 2740 if (se_cmd->prot_op != TARGET_PROT_DIN_STRIP && 2656 2741 se_cmd->prot_op != TARGET_PROT_DOUT_INSERT) 2657 2742 /* 2658 2743 * We have protection guards on the wire 2659 2744 * so we need to set a larget transfer 2660 2745 */ 2661 - sig_sge->length += se_cmd->prot_length; 2746 + rdma_wr->ib_sg[SIG].length += se_cmd->prot_length; 2662 2747 2663 - pr_debug("sig_sge: addr: 0x%llx length: %u lkey: %x\n", 2664 - sig_sge->addr, sig_sge->length, 2665 - sig_sge->lkey); 2748 + isert_dbg("sig_sge: addr: 0x%llx length: %u lkey: %x\n", 2749 + rdma_wr->ib_sg[SIG].addr, rdma_wr->ib_sg[SIG].length, 2750 + rdma_wr->ib_sg[SIG].lkey); 2666 2751 err: 2752 + return ret; 2753 + } 2754 + 2755 + static int 2756 + isert_handle_prot_cmd(struct isert_conn *isert_conn, 2757 + struct isert_cmd *isert_cmd, 2758 + struct isert_rdma_wr *wr) 2759 + { 2760 + struct isert_device *device = isert_conn->conn_device; 2761 + struct se_cmd *se_cmd = &isert_cmd->iscsi_cmd->se_cmd; 2762 + int ret; 2763 + 2764 + if (!wr->fr_desc->pi_ctx) { 2765 + ret = isert_create_pi_ctx(wr->fr_desc, 2766 + device->ib_device, 2767 + isert_conn->conn_pd); 2768 + if (ret) { 2769 + isert_err("conn %p failed to allocate pi_ctx\n", 2770 + isert_conn); 2771 + return ret; 2772 + } 2773 + } 2774 + 2775 + if (se_cmd->t_prot_sg) { 2776 + ret = isert_map_data_buf(isert_conn, isert_cmd, 2777 + se_cmd->t_prot_sg, 2778 + se_cmd->t_prot_nents, 2779 + se_cmd->prot_length, 2780 + 0, wr->iser_ib_op, &wr->prot); 2781 + if (ret) { 2782 + isert_err("conn %p failed to map protection buffer\n", 2783 + isert_conn); 2784 + return ret; 2785 + } 2786 + 2787 + memset(&wr->ib_sg[PROT], 0, sizeof(wr->ib_sg[PROT])); 2788 + ret = isert_fast_reg_mr(isert_conn, wr->fr_desc, &wr->prot, 2789 + ISERT_PROT_KEY_VALID, &wr->ib_sg[PROT]); 2790 + if (ret) { 2791 + isert_err("conn %p failed to fast reg mr\n", 2792 + isert_conn); 2793 + goto unmap_prot_cmd; 2794 + } 2795 + } 2796 + 2797 + ret = isert_reg_sig_mr(isert_conn, se_cmd, wr, wr->fr_desc); 2798 + if (ret) { 2799 + isert_err("conn %p failed to fast reg mr\n", 2800 + isert_conn); 2801 + goto unmap_prot_cmd; 2802 + } 2803 + wr->fr_desc->ind |= ISERT_PROTECTED; 2804 + 2805 + return 0; 2806 + 2807 + unmap_prot_cmd: 2808 + if (se_cmd->t_prot_sg) 2809 + isert_unmap_data_buf(isert_conn, &wr->prot); 2810 + 2667 2811 return ret; 2668 2812 } 2669 2813 ··· 2733 2759 struct se_cmd *se_cmd = &cmd->se_cmd; 2734 2760 struct isert_cmd *isert_cmd = iscsit_priv_cmd(cmd); 2735 2761 struct isert_conn *isert_conn = conn->context; 2736 - struct ib_sge data_sge; 2737 - struct ib_send_wr *send_wr; 2738 2762 struct fast_reg_descriptor *fr_desc = NULL; 2763 + struct ib_send_wr *send_wr; 2764 + struct ib_sge *ib_sg; 2739 2765 u32 offset; 2740 2766 int ret = 0; 2741 2767 unsigned long flags; ··· 2749 2775 if (ret) 2750 2776 return ret; 2751 2777 2752 - if (wr->data.dma_nents != 1 || 2753 - se_cmd->prot_op != TARGET_PROT_NORMAL) { 2778 + if (wr->data.dma_nents != 1 || isert_prot_cmd(isert_conn, se_cmd)) { 2754 2779 spin_lock_irqsave(&isert_conn->conn_lock, flags); 2755 2780 fr_desc = list_first_entry(&isert_conn->conn_fr_pool, 2756 2781 struct fast_reg_descriptor, list); ··· 2759 2786 } 2760 2787 2761 2788 ret = isert_fast_reg_mr(isert_conn, fr_desc, &wr->data, 2762 - ISERT_DATA_KEY_VALID, &data_sge); 2789 + ISERT_DATA_KEY_VALID, &wr->ib_sg[DATA]); 2763 2790 if (ret) 2764 2791 goto unmap_cmd; 2765 2792 2766 - if (se_cmd->prot_op != TARGET_PROT_NORMAL) { 2767 - struct ib_sge prot_sge, sig_sge; 2768 - 2769 - if (se_cmd->t_prot_sg) { 2770 - ret = isert_map_data_buf(isert_conn, isert_cmd, 2771 - se_cmd->t_prot_sg, 2772 - se_cmd->t_prot_nents, 2773 - se_cmd->prot_length, 2774 - 0, wr->iser_ib_op, &wr->prot); 2775 - if (ret) 2776 - goto unmap_cmd; 2777 - 2778 - ret = isert_fast_reg_mr(isert_conn, fr_desc, &wr->prot, 2779 - ISERT_PROT_KEY_VALID, &prot_sge); 2780 - if (ret) 2781 - goto unmap_prot_cmd; 2782 - } 2783 - 2784 - ret = isert_reg_sig_mr(isert_conn, se_cmd, fr_desc, 2785 - &data_sge, &prot_sge, &sig_sge); 2793 + if (isert_prot_cmd(isert_conn, se_cmd)) { 2794 + ret = isert_handle_prot_cmd(isert_conn, isert_cmd, wr); 2786 2795 if (ret) 2787 - goto unmap_prot_cmd; 2796 + goto unmap_cmd; 2788 2797 2789 - fr_desc->ind |= ISERT_PROTECTED; 2790 - memcpy(&wr->s_ib_sge, &sig_sge, sizeof(sig_sge)); 2791 - } else 2792 - memcpy(&wr->s_ib_sge, &data_sge, sizeof(data_sge)); 2798 + ib_sg = &wr->ib_sg[SIG]; 2799 + } else { 2800 + ib_sg = &wr->ib_sg[DATA]; 2801 + } 2793 2802 2803 + memcpy(&wr->s_ib_sge, ib_sg, sizeof(*ib_sg)); 2794 2804 wr->ib_sge = &wr->s_ib_sge; 2795 2805 wr->send_wr_num = 1; 2796 2806 memset(&wr->s_send_wr, 0, sizeof(*send_wr)); ··· 2783 2827 send_wr = &isert_cmd->rdma_wr.s_send_wr; 2784 2828 send_wr->sg_list = &wr->s_ib_sge; 2785 2829 send_wr->num_sge = 1; 2786 - send_wr->wr_id = (unsigned long)&isert_cmd->tx_desc; 2830 + send_wr->wr_id = (uintptr_t)&isert_cmd->tx_desc; 2787 2831 if (wr->iser_ib_op == ISER_IB_RDMA_WRITE) { 2788 2832 send_wr->opcode = IB_WR_RDMA_WRITE; 2789 2833 send_wr->wr.rdma.remote_addr = isert_cmd->read_va; 2790 2834 send_wr->wr.rdma.rkey = isert_cmd->read_stag; 2791 - send_wr->send_flags = se_cmd->prot_op == TARGET_PROT_NORMAL ? 2835 + send_wr->send_flags = !isert_prot_cmd(isert_conn, se_cmd) ? 2792 2836 0 : IB_SEND_SIGNALED; 2793 2837 } else { 2794 2838 send_wr->opcode = IB_WR_RDMA_READ; ··· 2798 2842 } 2799 2843 2800 2844 return 0; 2801 - unmap_prot_cmd: 2802 - if (se_cmd->t_prot_sg) 2803 - isert_unmap_data_buf(isert_conn, &wr->prot); 2845 + 2804 2846 unmap_cmd: 2805 2847 if (fr_desc) { 2806 2848 spin_lock_irqsave(&isert_conn->conn_lock, flags); ··· 2821 2867 struct ib_send_wr *wr_failed; 2822 2868 int rc; 2823 2869 2824 - pr_debug("Cmd: %p RDMA_WRITE data_length: %u\n", 2870 + isert_dbg("Cmd: %p RDMA_WRITE data_length: %u\n", 2825 2871 isert_cmd, se_cmd->data_length); 2872 + 2826 2873 wr->iser_ib_op = ISER_IB_RDMA_WRITE; 2827 2874 rc = device->reg_rdma_mem(conn, cmd, wr); 2828 2875 if (rc) { 2829 - pr_err("Cmd: %p failed to prepare RDMA res\n", isert_cmd); 2876 + isert_err("Cmd: %p failed to prepare RDMA res\n", isert_cmd); 2830 2877 return rc; 2831 2878 } 2832 2879 2833 - if (se_cmd->prot_op == TARGET_PROT_NORMAL) { 2880 + if (!isert_prot_cmd(isert_conn, se_cmd)) { 2834 2881 /* 2835 2882 * Build isert_conn->tx_desc for iSCSI response PDU and attach 2836 2883 */ ··· 2841 2886 &isert_cmd->tx_desc.iscsi_header); 2842 2887 isert_init_tx_hdrs(isert_conn, &isert_cmd->tx_desc); 2843 2888 isert_init_send_wr(isert_conn, isert_cmd, 2844 - &isert_cmd->tx_desc.send_wr, false); 2889 + &isert_cmd->tx_desc.send_wr); 2845 2890 isert_cmd->rdma_wr.s_send_wr.next = &isert_cmd->tx_desc.send_wr; 2846 2891 wr->send_wr_num += 1; 2847 2892 } 2848 2893 2849 - atomic_add(wr->send_wr_num, &isert_conn->post_send_buf_count); 2850 - 2851 2894 rc = ib_post_send(isert_conn->conn_qp, wr->send_wr, &wr_failed); 2852 - if (rc) { 2853 - pr_warn("ib_post_send() failed for IB_WR_RDMA_WRITE\n"); 2854 - atomic_sub(wr->send_wr_num, &isert_conn->post_send_buf_count); 2855 - } 2895 + if (rc) 2896 + isert_warn("ib_post_send() failed for IB_WR_RDMA_WRITE\n"); 2856 2897 2857 - if (se_cmd->prot_op == TARGET_PROT_NORMAL) 2858 - pr_debug("Cmd: %p posted RDMA_WRITE + Response for iSER Data " 2898 + if (!isert_prot_cmd(isert_conn, se_cmd)) 2899 + isert_dbg("Cmd: %p posted RDMA_WRITE + Response for iSER Data " 2859 2900 "READ\n", isert_cmd); 2860 2901 else 2861 - pr_debug("Cmd: %p posted RDMA_WRITE for iSER Data READ\n", 2902 + isert_dbg("Cmd: %p posted RDMA_WRITE for iSER Data READ\n", 2862 2903 isert_cmd); 2863 2904 2864 2905 return 1; ··· 2871 2920 struct ib_send_wr *wr_failed; 2872 2921 int rc; 2873 2922 2874 - pr_debug("Cmd: %p RDMA_READ data_length: %u write_data_done: %u\n", 2923 + isert_dbg("Cmd: %p RDMA_READ data_length: %u write_data_done: %u\n", 2875 2924 isert_cmd, se_cmd->data_length, cmd->write_data_done); 2876 2925 wr->iser_ib_op = ISER_IB_RDMA_READ; 2877 2926 rc = device->reg_rdma_mem(conn, cmd, wr); 2878 2927 if (rc) { 2879 - pr_err("Cmd: %p failed to prepare RDMA res\n", isert_cmd); 2928 + isert_err("Cmd: %p failed to prepare RDMA res\n", isert_cmd); 2880 2929 return rc; 2881 2930 } 2882 2931 2883 - atomic_add(wr->send_wr_num, &isert_conn->post_send_buf_count); 2884 - 2885 2932 rc = ib_post_send(isert_conn->conn_qp, wr->send_wr, &wr_failed); 2886 - if (rc) { 2887 - pr_warn("ib_post_send() failed for IB_WR_RDMA_READ\n"); 2888 - atomic_sub(wr->send_wr_num, &isert_conn->post_send_buf_count); 2889 - } 2890 - pr_debug("Cmd: %p posted RDMA_READ memory for ISER Data WRITE\n", 2933 + if (rc) 2934 + isert_warn("ib_post_send() failed for IB_WR_RDMA_READ\n"); 2935 + 2936 + isert_dbg("Cmd: %p posted RDMA_READ memory for ISER Data WRITE\n", 2891 2937 isert_cmd); 2892 2938 2893 2939 return 0; ··· 2900 2952 ret = isert_put_nopin(cmd, conn, false); 2901 2953 break; 2902 2954 default: 2903 - pr_err("Unknown immediate state: 0x%02x\n", state); 2955 + isert_err("Unknown immediate state: 0x%02x\n", state); 2904 2956 ret = -EINVAL; 2905 2957 break; 2906 2958 } ··· 2911 2963 static int 2912 2964 isert_response_queue(struct iscsi_conn *conn, struct iscsi_cmd *cmd, int state) 2913 2965 { 2966 + struct isert_conn *isert_conn = conn->context; 2914 2967 int ret; 2915 2968 2916 2969 switch (state) { 2917 2970 case ISTATE_SEND_LOGOUTRSP: 2918 2971 ret = isert_put_logout_rsp(cmd, conn); 2919 - if (!ret) { 2920 - pr_debug("Returning iSER Logout -EAGAIN\n"); 2921 - ret = -EAGAIN; 2922 - } 2972 + if (!ret) 2973 + isert_conn->logout_posted = true; 2923 2974 break; 2924 2975 case ISTATE_SEND_NOPIN: 2925 2976 ret = isert_put_nopin(cmd, conn, true); ··· 2940 2993 ret = isert_put_response(conn, cmd); 2941 2994 break; 2942 2995 default: 2943 - pr_err("Unknown response state: 0x%02x\n", state); 2996 + isert_err("Unknown response state: 0x%02x\n", state); 2944 2997 ret = -EINVAL; 2945 2998 break; 2946 2999 } 2947 3000 2948 3001 return ret; 3002 + } 3003 + 3004 + struct rdma_cm_id * 3005 + isert_setup_id(struct isert_np *isert_np) 3006 + { 3007 + struct iscsi_np *np = isert_np->np; 3008 + struct rdma_cm_id *id; 3009 + struct sockaddr *sa; 3010 + int ret; 3011 + 3012 + sa = (struct sockaddr *)&np->np_sockaddr; 3013 + isert_dbg("ksockaddr: %p, sa: %p\n", &np->np_sockaddr, sa); 3014 + 3015 + id = rdma_create_id(isert_cma_handler, isert_np, 3016 + RDMA_PS_TCP, IB_QPT_RC); 3017 + if (IS_ERR(id)) { 3018 + isert_err("rdma_create_id() failed: %ld\n", PTR_ERR(id)); 3019 + ret = PTR_ERR(id); 3020 + goto out; 3021 + } 3022 + isert_dbg("id %p context %p\n", id, id->context); 3023 + 3024 + ret = rdma_bind_addr(id, sa); 3025 + if (ret) { 3026 + isert_err("rdma_bind_addr() failed: %d\n", ret); 3027 + goto out_id; 3028 + } 3029 + 3030 + ret = rdma_listen(id, ISERT_RDMA_LISTEN_BACKLOG); 3031 + if (ret) { 3032 + isert_err("rdma_listen() failed: %d\n", ret); 3033 + goto out_id; 3034 + } 3035 + 3036 + return id; 3037 + out_id: 3038 + rdma_destroy_id(id); 3039 + out: 3040 + return ERR_PTR(ret); 2949 3041 } 2950 3042 2951 3043 static int ··· 2993 3007 { 2994 3008 struct isert_np *isert_np; 2995 3009 struct rdma_cm_id *isert_lid; 2996 - struct sockaddr *sa; 2997 3010 int ret; 2998 3011 2999 3012 isert_np = kzalloc(sizeof(struct isert_np), GFP_KERNEL); 3000 3013 if (!isert_np) { 3001 - pr_err("Unable to allocate struct isert_np\n"); 3014 + isert_err("Unable to allocate struct isert_np\n"); 3002 3015 return -ENOMEM; 3003 3016 } 3004 3017 sema_init(&isert_np->np_sem, 0); 3005 3018 mutex_init(&isert_np->np_accept_mutex); 3006 3019 INIT_LIST_HEAD(&isert_np->np_accept_list); 3007 3020 init_completion(&isert_np->np_login_comp); 3021 + isert_np->np = np; 3008 3022 3009 - sa = (struct sockaddr *)ksockaddr; 3010 - pr_debug("ksockaddr: %p, sa: %p\n", ksockaddr, sa); 3011 3023 /* 3012 3024 * Setup the np->np_sockaddr from the passed sockaddr setup 3013 3025 * in iscsi_target_configfs.c code.. ··· 3013 3029 memcpy(&np->np_sockaddr, ksockaddr, 3014 3030 sizeof(struct __kernel_sockaddr_storage)); 3015 3031 3016 - isert_lid = rdma_create_id(isert_cma_handler, np, RDMA_PS_TCP, 3017 - IB_QPT_RC); 3032 + isert_lid = isert_setup_id(isert_np); 3018 3033 if (IS_ERR(isert_lid)) { 3019 - pr_err("rdma_create_id() for isert_listen_handler failed: %ld\n", 3020 - PTR_ERR(isert_lid)); 3021 3034 ret = PTR_ERR(isert_lid); 3022 3035 goto out; 3023 3036 } 3024 3037 3025 - ret = rdma_bind_addr(isert_lid, sa); 3026 - if (ret) { 3027 - pr_err("rdma_bind_addr() for isert_lid failed: %d\n", ret); 3028 - goto out_lid; 3029 - } 3030 - 3031 - ret = rdma_listen(isert_lid, ISERT_RDMA_LISTEN_BACKLOG); 3032 - if (ret) { 3033 - pr_err("rdma_listen() for isert_lid failed: %d\n", ret); 3034 - goto out_lid; 3035 - } 3036 - 3037 3038 isert_np->np_cm_id = isert_lid; 3038 3039 np->np_context = isert_np; 3039 - pr_debug("Setup isert_lid->context: %p\n", isert_lid->context); 3040 3040 3041 3041 return 0; 3042 3042 3043 - out_lid: 3044 - rdma_destroy_id(isert_lid); 3045 3043 out: 3046 3044 kfree(isert_np); 3045 + 3047 3046 return ret; 3048 3047 } 3049 3048 ··· 3042 3075 cp.retry_count = 7; 3043 3076 cp.rnr_retry_count = 7; 3044 3077 3045 - pr_debug("Before rdma_accept >>>>>>>>>>>>>>>>>>>>.\n"); 3046 - 3047 3078 ret = rdma_accept(cm_id, &cp); 3048 3079 if (ret) { 3049 - pr_err("rdma_accept() failed with: %d\n", ret); 3080 + isert_err("rdma_accept() failed with: %d\n", ret); 3050 3081 return ret; 3051 3082 } 3052 - 3053 - pr_debug("After rdma_accept >>>>>>>>>>>>>>>>>>>>>.\n"); 3054 3083 3055 3084 return 0; 3056 3085 } ··· 3057 3094 struct isert_conn *isert_conn = (struct isert_conn *)conn->context; 3058 3095 int ret; 3059 3096 3060 - pr_debug("isert_get_login_rx before conn_login_comp conn: %p\n", conn); 3097 + isert_info("before login_req comp conn: %p\n", isert_conn); 3098 + ret = wait_for_completion_interruptible(&isert_conn->login_req_comp); 3099 + if (ret) { 3100 + isert_err("isert_conn %p interrupted before got login req\n", 3101 + isert_conn); 3102 + return ret; 3103 + } 3104 + reinit_completion(&isert_conn->login_req_comp); 3105 + 3061 3106 /* 3062 3107 * For login requests after the first PDU, isert_rx_login_req() will 3063 3108 * kick schedule_delayed_work(&conn->login_work) as the packet is ··· 3075 3104 if (!login->first_request) 3076 3105 return 0; 3077 3106 3107 + isert_rx_login_req(isert_conn); 3108 + 3109 + isert_info("before conn_login_comp conn: %p\n", conn); 3078 3110 ret = wait_for_completion_interruptible(&isert_conn->conn_login_comp); 3079 3111 if (ret) 3080 3112 return ret; 3081 3113 3082 - pr_debug("isert_get_login_rx processing login->req: %p\n", login->req); 3114 + isert_info("processing login->req: %p\n", login->req); 3115 + 3083 3116 return 0; 3084 3117 } 3085 3118 ··· 3136 3161 spin_lock_bh(&np->np_thread_lock); 3137 3162 if (np->np_thread_state >= ISCSI_NP_THREAD_RESET) { 3138 3163 spin_unlock_bh(&np->np_thread_lock); 3139 - pr_debug("np_thread_state %d for isert_accept_np\n", 3164 + isert_dbg("np_thread_state %d for isert_accept_np\n", 3140 3165 np->np_thread_state); 3141 3166 /** 3142 3167 * No point in stalling here when np_thread ··· 3161 3186 isert_conn->conn = conn; 3162 3187 max_accept = 0; 3163 3188 3164 - ret = isert_rdma_post_recvl(isert_conn); 3165 - if (ret) 3166 - return ret; 3167 - 3168 - ret = isert_rdma_accept(isert_conn); 3169 - if (ret) 3170 - return ret; 3171 - 3172 3189 isert_set_conn_info(np, conn, isert_conn); 3173 3190 3174 - pr_debug("Processing isert_accept_np: isert_conn: %p\n", isert_conn); 3191 + isert_dbg("Processing isert_conn: %p\n", isert_conn); 3192 + 3175 3193 return 0; 3176 3194 } 3177 3195 ··· 3172 3204 isert_free_np(struct iscsi_np *np) 3173 3205 { 3174 3206 struct isert_np *isert_np = (struct isert_np *)np->np_context; 3207 + struct isert_conn *isert_conn, *n; 3175 3208 3176 3209 if (isert_np->np_cm_id) 3177 3210 rdma_destroy_id(isert_np->np_cm_id); 3178 3211 3212 + /* 3213 + * FIXME: At this point we don't have a good way to insure 3214 + * that at this point we don't have hanging connections that 3215 + * completed RDMA establishment but didn't start iscsi login 3216 + * process. So work-around this by cleaning up what ever piled 3217 + * up in np_accept_list. 3218 + */ 3219 + mutex_lock(&isert_np->np_accept_mutex); 3220 + if (!list_empty(&isert_np->np_accept_list)) { 3221 + isert_info("Still have isert connections, cleaning up...\n"); 3222 + list_for_each_entry_safe(isert_conn, n, 3223 + &isert_np->np_accept_list, 3224 + conn_accept_node) { 3225 + isert_info("cleaning isert_conn %p state (%d)\n", 3226 + isert_conn, isert_conn->state); 3227 + isert_connect_release(isert_conn); 3228 + } 3229 + } 3230 + mutex_unlock(&isert_np->np_accept_mutex); 3231 + 3179 3232 np->np_context = NULL; 3180 3233 kfree(isert_np); 3234 + } 3235 + 3236 + static void isert_release_work(struct work_struct *work) 3237 + { 3238 + struct isert_conn *isert_conn = container_of(work, 3239 + struct isert_conn, 3240 + release_work); 3241 + 3242 + isert_info("Starting release conn %p\n", isert_conn); 3243 + 3244 + wait_for_completion(&isert_conn->conn_wait); 3245 + 3246 + mutex_lock(&isert_conn->conn_mutex); 3247 + isert_conn->state = ISER_CONN_DOWN; 3248 + mutex_unlock(&isert_conn->conn_mutex); 3249 + 3250 + isert_info("Destroying conn %p\n", isert_conn); 3251 + isert_put_conn(isert_conn); 3252 + } 3253 + 3254 + static void 3255 + isert_wait4logout(struct isert_conn *isert_conn) 3256 + { 3257 + struct iscsi_conn *conn = isert_conn->conn; 3258 + 3259 + isert_info("conn %p\n", isert_conn); 3260 + 3261 + if (isert_conn->logout_posted) { 3262 + isert_info("conn %p wait for conn_logout_comp\n", isert_conn); 3263 + wait_for_completion_timeout(&conn->conn_logout_comp, 3264 + SECONDS_FOR_LOGOUT_COMP * HZ); 3265 + } 3266 + } 3267 + 3268 + static void 3269 + isert_wait4cmds(struct iscsi_conn *conn) 3270 + { 3271 + isert_info("iscsi_conn %p\n", conn); 3272 + 3273 + if (conn->sess) { 3274 + target_sess_cmd_list_set_waiting(conn->sess->se_sess); 3275 + target_wait_for_sess_cmds(conn->sess->se_sess); 3276 + } 3277 + } 3278 + 3279 + static void 3280 + isert_wait4flush(struct isert_conn *isert_conn) 3281 + { 3282 + struct ib_recv_wr *bad_wr; 3283 + 3284 + isert_info("conn %p\n", isert_conn); 3285 + 3286 + init_completion(&isert_conn->conn_wait_comp_err); 3287 + isert_conn->beacon.wr_id = ISER_BEACON_WRID; 3288 + /* post an indication that all flush errors were consumed */ 3289 + if (ib_post_recv(isert_conn->conn_qp, &isert_conn->beacon, &bad_wr)) { 3290 + isert_err("conn %p failed to post beacon", isert_conn); 3291 + return; 3292 + } 3293 + 3294 + wait_for_completion(&isert_conn->conn_wait_comp_err); 3181 3295 } 3182 3296 3183 3297 static void isert_wait_conn(struct iscsi_conn *conn) 3184 3298 { 3185 3299 struct isert_conn *isert_conn = conn->context; 3186 3300 3187 - pr_debug("isert_wait_conn: Starting \n"); 3301 + isert_info("Starting conn %p\n", isert_conn); 3188 3302 3189 3303 mutex_lock(&isert_conn->conn_mutex); 3190 - if (isert_conn->conn_cm_id && !isert_conn->disconnect) { 3191 - pr_debug("Calling rdma_disconnect from isert_wait_conn\n"); 3192 - rdma_disconnect(isert_conn->conn_cm_id); 3193 - } 3194 3304 /* 3195 3305 * Only wait for conn_wait_comp_err if the isert_conn made it 3196 3306 * into full feature phase.. ··· 3277 3231 mutex_unlock(&isert_conn->conn_mutex); 3278 3232 return; 3279 3233 } 3280 - if (isert_conn->state == ISER_CONN_UP) 3281 - isert_conn->state = ISER_CONN_TERMINATING; 3234 + isert_conn_terminate(isert_conn); 3282 3235 mutex_unlock(&isert_conn->conn_mutex); 3283 3236 3284 - wait_for_completion(&isert_conn->conn_wait_comp_err); 3237 + isert_wait4cmds(conn); 3238 + isert_wait4flush(isert_conn); 3239 + isert_wait4logout(isert_conn); 3285 3240 3286 - wait_for_completion(&isert_conn->conn_wait); 3287 - isert_put_conn(isert_conn); 3241 + INIT_WORK(&isert_conn->release_work, isert_release_work); 3242 + queue_work(isert_release_wq, &isert_conn->release_work); 3288 3243 } 3289 3244 3290 3245 static void isert_free_conn(struct iscsi_conn *conn) ··· 3320 3273 { 3321 3274 int ret; 3322 3275 3323 - isert_rx_wq = alloc_workqueue("isert_rx_wq", 0, 0); 3324 - if (!isert_rx_wq) { 3325 - pr_err("Unable to allocate isert_rx_wq\n"); 3276 + isert_comp_wq = alloc_workqueue("isert_comp_wq", 0, 0); 3277 + if (!isert_comp_wq) { 3278 + isert_err("Unable to allocate isert_comp_wq\n"); 3279 + ret = -ENOMEM; 3326 3280 return -ENOMEM; 3327 3281 } 3328 3282 3329 - isert_comp_wq = alloc_workqueue("isert_comp_wq", 0, 0); 3330 - if (!isert_comp_wq) { 3331 - pr_err("Unable to allocate isert_comp_wq\n"); 3283 + isert_release_wq = alloc_workqueue("isert_release_wq", WQ_UNBOUND, 3284 + WQ_UNBOUND_MAX_ACTIVE); 3285 + if (!isert_release_wq) { 3286 + isert_err("Unable to allocate isert_release_wq\n"); 3332 3287 ret = -ENOMEM; 3333 - goto destroy_rx_wq; 3288 + goto destroy_comp_wq; 3334 3289 } 3335 3290 3336 3291 iscsit_register_transport(&iser_target_transport); 3337 - pr_debug("iSER_TARGET[0] - Loaded iser_target_transport\n"); 3292 + isert_info("iSER_TARGET[0] - Loaded iser_target_transport\n"); 3293 + 3338 3294 return 0; 3339 3295 3340 - destroy_rx_wq: 3341 - destroy_workqueue(isert_rx_wq); 3296 + destroy_comp_wq: 3297 + destroy_workqueue(isert_comp_wq); 3298 + 3342 3299 return ret; 3343 3300 } 3344 3301 3345 3302 static void __exit isert_exit(void) 3346 3303 { 3347 3304 flush_scheduled_work(); 3305 + destroy_workqueue(isert_release_wq); 3348 3306 destroy_workqueue(isert_comp_wq); 3349 - destroy_workqueue(isert_rx_wq); 3350 3307 iscsit_unregister_transport(&iser_target_transport); 3351 - pr_debug("iSER_TARGET[0] - Released iser_target_transport\n"); 3308 + isert_info("iSER_TARGET[0] - Released iser_target_transport\n"); 3352 3309 } 3353 3310 3354 3311 MODULE_DESCRIPTION("iSER-Target for mainline target infrastructure");
+61 -19
drivers/infiniband/ulp/isert/ib_isert.h
··· 4 4 #include <rdma/ib_verbs.h> 5 5 #include <rdma/rdma_cm.h> 6 6 7 + #define DRV_NAME "isert" 8 + #define PFX DRV_NAME ": " 9 + 10 + #define isert_dbg(fmt, arg...) \ 11 + do { \ 12 + if (unlikely(isert_debug_level > 2)) \ 13 + printk(KERN_DEBUG PFX "%s: " fmt,\ 14 + __func__ , ## arg); \ 15 + } while (0) 16 + 17 + #define isert_warn(fmt, arg...) \ 18 + do { \ 19 + if (unlikely(isert_debug_level > 0)) \ 20 + pr_warn(PFX "%s: " fmt, \ 21 + __func__ , ## arg); \ 22 + } while (0) 23 + 24 + #define isert_info(fmt, arg...) \ 25 + do { \ 26 + if (unlikely(isert_debug_level > 1)) \ 27 + pr_info(PFX "%s: " fmt, \ 28 + __func__ , ## arg); \ 29 + } while (0) 30 + 31 + #define isert_err(fmt, arg...) \ 32 + pr_err(PFX "%s: " fmt, __func__ , ## arg) 33 + 7 34 #define ISERT_RDMA_LISTEN_BACKLOG 10 8 35 #define ISCSI_ISER_SG_TABLESIZE 256 9 36 #define ISER_FASTREG_LI_WRID 0xffffffffffffffffULL 37 + #define ISER_BEACON_WRID 0xfffffffffffffffeULL 10 38 11 39 enum isert_desc_type { 12 40 ISCSI_TX_CONTROL, ··· 51 23 enum iser_conn_state { 52 24 ISER_CONN_INIT, 53 25 ISER_CONN_UP, 26 + ISER_CONN_FULL_FEATURE, 54 27 ISER_CONN_TERMINATING, 55 28 ISER_CONN_DOWN, 56 29 }; ··· 73 44 struct ib_sge tx_sg[2]; 74 45 int num_sge; 75 46 struct isert_cmd *isert_cmd; 76 - struct llist_node *comp_llnode_batch; 77 - struct llist_node comp_llnode; 78 - bool llnode_active; 79 47 struct ib_send_wr send_wr; 80 48 } __packed; 81 49 ··· 107 81 enum dma_data_direction dma_dir; 108 82 }; 109 83 84 + enum { 85 + DATA = 0, 86 + PROT = 1, 87 + SIG = 2, 88 + }; 89 + 110 90 struct isert_rdma_wr { 111 91 struct list_head wr_list; 112 92 struct isert_cmd *isert_cmd; ··· 122 90 int send_wr_num; 123 91 struct ib_send_wr *send_wr; 124 92 struct ib_send_wr s_send_wr; 93 + struct ib_sge ib_sg[3]; 125 94 struct isert_data_buf data; 126 95 struct isert_data_buf prot; 127 96 struct fast_reg_descriptor *fr_desc; ··· 150 117 struct isert_conn { 151 118 enum iser_conn_state state; 152 119 int post_recv_buf_count; 153 - atomic_t post_send_buf_count; 154 120 u32 responder_resources; 155 121 u32 initiator_depth; 122 + bool pi_support; 156 123 u32 max_sge; 157 124 char *login_buf; 158 125 char *login_req_buf; 159 126 char *login_rsp_buf; 160 127 u64 login_req_dma; 128 + int login_req_len; 161 129 u64 login_rsp_dma; 162 130 unsigned int conn_rx_desc_head; 163 131 struct iser_rx_desc *conn_rx_descs; ··· 166 132 struct iscsi_conn *conn; 167 133 struct list_head conn_accept_node; 168 134 struct completion conn_login_comp; 135 + struct completion login_req_comp; 169 136 struct iser_tx_desc conn_login_tx_desc; 170 137 struct rdma_cm_id *conn_cm_id; 171 138 struct ib_pd *conn_pd; 172 139 struct ib_mr *conn_mr; 173 140 struct ib_qp *conn_qp; 174 141 struct isert_device *conn_device; 175 - struct work_struct conn_logout_work; 176 142 struct mutex conn_mutex; 177 143 struct completion conn_wait; 178 144 struct completion conn_wait_comp_err; ··· 181 147 int conn_fr_pool_size; 182 148 /* lock to protect fastreg pool */ 183 149 spinlock_t conn_lock; 184 - #define ISERT_COMP_BATCH_COUNT 8 185 - int conn_comp_batch; 186 - struct llist_head conn_comp_llist; 187 - bool disconnect; 150 + struct work_struct release_work; 151 + struct ib_recv_wr beacon; 152 + bool logout_posted; 188 153 }; 189 154 190 155 #define ISERT_MAX_CQ 64 191 156 192 - struct isert_cq_desc { 193 - struct isert_device *device; 194 - int cq_index; 195 - struct work_struct cq_rx_work; 196 - struct work_struct cq_tx_work; 157 + /** 158 + * struct isert_comp - iSER completion context 159 + * 160 + * @device: pointer to device handle 161 + * @cq: completion queue 162 + * @wcs: work completion array 163 + * @active_qps: Number of active QPs attached 164 + * to completion context 165 + * @work: completion work handle 166 + */ 167 + struct isert_comp { 168 + struct isert_device *device; 169 + struct ib_cq *cq; 170 + struct ib_wc wcs[16]; 171 + int active_qps; 172 + struct work_struct work; 197 173 }; 198 174 199 175 struct isert_device { 200 176 int use_fastreg; 201 177 bool pi_capable; 202 - int cqs_used; 203 178 int refcount; 204 - int cq_active_qps[ISERT_MAX_CQ]; 205 179 struct ib_device *ib_device; 206 - struct ib_cq *dev_rx_cq[ISERT_MAX_CQ]; 207 - struct ib_cq *dev_tx_cq[ISERT_MAX_CQ]; 208 - struct isert_cq_desc *cq_desc; 180 + struct isert_comp *comps; 181 + int comps_used; 209 182 struct list_head dev_node; 210 183 struct ib_device_attr dev_attr; 211 184 int (*reg_rdma_mem)(struct iscsi_conn *conn, ··· 223 182 }; 224 183 225 184 struct isert_np { 185 + struct iscsi_np *np; 226 186 struct semaphore np_sem; 227 187 struct rdma_cm_id *np_cm_id; 228 188 struct mutex np_accept_mutex;
+1
drivers/target/iscsi/iscsi_target.c
··· 609 609 610 610 return ret; 611 611 r2t_out: 612 + iscsit_unregister_transport(&iscsi_target_transport); 612 613 kmem_cache_destroy(lio_r2t_cache); 613 614 ooo_out: 614 615 kmem_cache_destroy(lio_ooo_cache);
-1
drivers/target/iscsi/iscsi_target_core.h
··· 790 790 void *np_context; 791 791 struct iscsit_transport *np_transport; 792 792 struct list_head np_list; 793 - struct iscsi_tpg_np *tpg_np; 794 793 } ____cacheline_aligned; 795 794 796 795 struct iscsi_tpg_np {
+8 -3
drivers/target/iscsi/iscsi_target_login.c
··· 281 281 { 282 282 struct iscsi_session *sess = NULL; 283 283 struct iscsi_login_req *pdu = (struct iscsi_login_req *)buf; 284 - enum target_prot_op sup_pro_ops; 285 284 int ret; 286 285 287 286 sess = kzalloc(sizeof(struct iscsi_session), GFP_KERNEL); ··· 342 343 kfree(sess); 343 344 return -ENOMEM; 344 345 } 345 - sup_pro_ops = conn->conn_transport->iscsit_get_sup_prot_ops(conn); 346 346 347 - sess->se_sess = transport_init_session(sup_pro_ops); 347 + sess->se_sess = transport_init_session(TARGET_PROT_NORMAL); 348 348 if (IS_ERR(sess->se_sess)) { 349 349 iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR, 350 350 ISCSI_LOGIN_STATUS_NO_RESOURCES); ··· 1159 1161 } 1160 1162 kfree(conn->sess->sess_ops); 1161 1163 kfree(conn->sess); 1164 + conn->sess = NULL; 1162 1165 1163 1166 old_sess_out: 1164 1167 iscsi_stop_login_thread_timer(np); ··· 1202 1203 sock_release(conn->sock); 1203 1204 conn->sock = NULL; 1204 1205 } 1206 + 1207 + if (conn->conn_transport->iscsit_wait_conn) 1208 + conn->conn_transport->iscsit_wait_conn(conn); 1205 1209 1206 1210 if (conn->conn_transport->iscsit_free_conn) 1207 1211 conn->conn_transport->iscsit_free_conn(conn); ··· 1365 1363 goto new_sess_out; 1366 1364 } 1367 1365 login->zero_tsih = zero_tsih; 1366 + 1367 + conn->sess->se_sess->sup_prot_ops = 1368 + conn->conn_transport->iscsit_get_sup_prot_ops(conn); 1368 1369 1369 1370 tpg = conn->tpg; 1370 1371 if (!tpg) {
-1
drivers/target/iscsi/iscsi_target_tpg.c
··· 501 501 init_completion(&tpg_np->tpg_np_comp); 502 502 kref_init(&tpg_np->tpg_np_kref); 503 503 tpg_np->tpg_np = np; 504 - np->tpg_np = tpg_np; 505 504 tpg_np->tpg = tpg; 506 505 507 506 spin_lock(&tpg->tpg_np_lock);
+1 -2
drivers/target/iscsi/iscsi_target_transport.c
··· 26 26 27 27 void iscsit_put_transport(struct iscsit_transport *t) 28 28 { 29 - if (t->owner) 30 - module_put(t->owner); 29 + module_put(t->owner); 31 30 } 32 31 33 32 int iscsit_register_transport(struct iscsit_transport *t)
+11 -15
drivers/target/iscsi/iscsi_target_util.c
··· 1356 1356 struct iscsi_conn *conn, 1357 1357 struct iscsi_data_count *count) 1358 1358 { 1359 - int data = count->data_length, total_tx = 0, tx_loop = 0, iov_len; 1359 + int ret, iov_len; 1360 1360 struct kvec *iov_p; 1361 1361 struct msghdr msg; 1362 1362 1363 1363 if (!conn || !conn->sock || !conn->conn_ops) 1364 1364 return -1; 1365 1365 1366 - if (data <= 0) { 1367 - pr_err("Data length is: %d\n", data); 1366 + if (count->data_length <= 0) { 1367 + pr_err("Data length is: %d\n", count->data_length); 1368 1368 return -1; 1369 1369 } 1370 1370 ··· 1373 1373 iov_p = count->iov; 1374 1374 iov_len = count->iov_count; 1375 1375 1376 - while (total_tx < data) { 1377 - tx_loop = kernel_sendmsg(conn->sock, &msg, iov_p, iov_len, 1378 - (data - total_tx)); 1379 - if (tx_loop <= 0) { 1380 - pr_debug("tx_loop: %d total_tx %d\n", 1381 - tx_loop, total_tx); 1382 - return tx_loop; 1383 - } 1384 - total_tx += tx_loop; 1385 - pr_debug("tx_loop: %d, total_tx: %d, data: %d\n", 1386 - tx_loop, total_tx, data); 1376 + ret = kernel_sendmsg(conn->sock, &msg, iov_p, iov_len, 1377 + count->data_length); 1378 + if (ret != count->data_length) { 1379 + pr_err("Unexpected ret: %d send data %d\n", 1380 + ret, count->data_length); 1381 + return -EPIPE; 1387 1382 } 1383 + pr_debug("ret: %d, sent data: %d\n", ret, count->data_length); 1388 1384 1389 - return total_tx; 1385 + return ret; 1390 1386 } 1391 1387 1392 1388 int rx_data(
+23 -43
drivers/target/loopback/tcm_loop.c
··· 138 138 set_host_byte(sc, DID_TRANSPORT_DISRUPTED); 139 139 goto out_done; 140 140 } 141 - tl_nexus = tl_hba->tl_nexus; 141 + tl_nexus = tl_tpg->tl_nexus; 142 142 if (!tl_nexus) { 143 143 scmd_printk(KERN_ERR, sc, "TCM_Loop I_T Nexus" 144 144 " does not exist\n"); ··· 218 218 * to struct scsi_device 219 219 */ 220 220 static int tcm_loop_issue_tmr(struct tcm_loop_tpg *tl_tpg, 221 - struct tcm_loop_nexus *tl_nexus, 222 221 int lun, int task, enum tcm_tmreq_table tmr) 223 222 { 224 223 struct se_cmd *se_cmd = NULL; 225 224 struct se_session *se_sess; 226 225 struct se_portal_group *se_tpg; 226 + struct tcm_loop_nexus *tl_nexus; 227 227 struct tcm_loop_cmd *tl_cmd = NULL; 228 228 struct tcm_loop_tmr *tl_tmr = NULL; 229 229 int ret = TMR_FUNCTION_FAILED, rc; 230 + 231 + /* 232 + * Locate the tl_nexus and se_sess pointers 233 + */ 234 + tl_nexus = tl_tpg->tl_nexus; 235 + if (!tl_nexus) { 236 + pr_err("Unable to perform device reset without" 237 + " active I_T Nexus\n"); 238 + return ret; 239 + } 230 240 231 241 tl_cmd = kmem_cache_zalloc(tcm_loop_cmd_cache, GFP_KERNEL); 232 242 if (!tl_cmd) { ··· 253 243 254 244 se_cmd = &tl_cmd->tl_se_cmd; 255 245 se_tpg = &tl_tpg->tl_se_tpg; 256 - se_sess = tl_nexus->se_sess; 246 + se_sess = tl_tpg->tl_nexus->se_sess; 257 247 /* 258 248 * Initialize struct se_cmd descriptor from target_core_mod infrastructure 259 249 */ ··· 298 288 static int tcm_loop_abort_task(struct scsi_cmnd *sc) 299 289 { 300 290 struct tcm_loop_hba *tl_hba; 301 - struct tcm_loop_nexus *tl_nexus; 302 291 struct tcm_loop_tpg *tl_tpg; 303 292 int ret = FAILED; 304 293 ··· 305 296 * Locate the tcm_loop_hba_t pointer 306 297 */ 307 298 tl_hba = *(struct tcm_loop_hba **)shost_priv(sc->device->host); 308 - /* 309 - * Locate the tl_nexus and se_sess pointers 310 - */ 311 - tl_nexus = tl_hba->tl_nexus; 312 - if (!tl_nexus) { 313 - pr_err("Unable to perform device reset without" 314 - " active I_T Nexus\n"); 315 - return FAILED; 316 - } 317 - 318 - /* 319 - * Locate the tl_tpg pointer from TargetID in sc->device->id 320 - */ 321 299 tl_tpg = &tl_hba->tl_hba_tpgs[sc->device->id]; 322 - ret = tcm_loop_issue_tmr(tl_tpg, tl_nexus, sc->device->lun, 300 + ret = tcm_loop_issue_tmr(tl_tpg, sc->device->lun, 323 301 sc->request->tag, TMR_ABORT_TASK); 324 302 return (ret == TMR_FUNCTION_COMPLETE) ? SUCCESS : FAILED; 325 303 } ··· 318 322 static int tcm_loop_device_reset(struct scsi_cmnd *sc) 319 323 { 320 324 struct tcm_loop_hba *tl_hba; 321 - struct tcm_loop_nexus *tl_nexus; 322 325 struct tcm_loop_tpg *tl_tpg; 323 326 int ret = FAILED; 324 327 ··· 325 330 * Locate the tcm_loop_hba_t pointer 326 331 */ 327 332 tl_hba = *(struct tcm_loop_hba **)shost_priv(sc->device->host); 328 - /* 329 - * Locate the tl_nexus and se_sess pointers 330 - */ 331 - tl_nexus = tl_hba->tl_nexus; 332 - if (!tl_nexus) { 333 - pr_err("Unable to perform device reset without" 334 - " active I_T Nexus\n"); 335 - return FAILED; 336 - } 337 - /* 338 - * Locate the tl_tpg pointer from TargetID in sc->device->id 339 - */ 340 333 tl_tpg = &tl_hba->tl_hba_tpgs[sc->device->id]; 341 - ret = tcm_loop_issue_tmr(tl_tpg, tl_nexus, sc->device->lun, 334 + 335 + ret = tcm_loop_issue_tmr(tl_tpg, sc->device->lun, 342 336 0, TMR_LUN_RESET); 343 337 return (ret == TMR_FUNCTION_COMPLETE) ? SUCCESS : FAILED; 344 338 } ··· 924 940 struct tcm_loop_nexus *tl_nexus; 925 941 int ret = -ENOMEM; 926 942 927 - if (tl_tpg->tl_hba->tl_nexus) { 928 - pr_debug("tl_tpg->tl_hba->tl_nexus already exists\n"); 943 + if (tl_tpg->tl_nexus) { 944 + pr_debug("tl_tpg->tl_nexus already exists\n"); 929 945 return -EEXIST; 930 946 } 931 947 se_tpg = &tl_tpg->tl_se_tpg; ··· 960 976 */ 961 977 __transport_register_session(se_tpg, tl_nexus->se_sess->se_node_acl, 962 978 tl_nexus->se_sess, tl_nexus); 963 - tl_tpg->tl_hba->tl_nexus = tl_nexus; 979 + tl_tpg->tl_nexus = tl_nexus; 964 980 pr_debug("TCM_Loop_ConfigFS: Established I_T Nexus to emulated" 965 981 " %s Initiator Port: %s\n", tcm_loop_dump_proto_id(tl_hba), 966 982 name); ··· 976 992 { 977 993 struct se_session *se_sess; 978 994 struct tcm_loop_nexus *tl_nexus; 979 - struct tcm_loop_hba *tl_hba = tpg->tl_hba; 980 995 981 - if (!tl_hba) 982 - return -ENODEV; 983 - 984 - tl_nexus = tl_hba->tl_nexus; 996 + tl_nexus = tpg->tl_nexus; 985 997 if (!tl_nexus) 986 998 return -ENODEV; 987 999 ··· 993 1013 } 994 1014 995 1015 pr_debug("TCM_Loop_ConfigFS: Removing I_T Nexus to emulated" 996 - " %s Initiator Port: %s\n", tcm_loop_dump_proto_id(tl_hba), 1016 + " %s Initiator Port: %s\n", tcm_loop_dump_proto_id(tpg->tl_hba), 997 1017 tl_nexus->se_sess->se_node_acl->initiatorname); 998 1018 /* 999 1019 * Release the SCSI I_T Nexus to the emulated SAS Target Port 1000 1020 */ 1001 1021 transport_deregister_session(tl_nexus->se_sess); 1002 - tpg->tl_hba->tl_nexus = NULL; 1022 + tpg->tl_nexus = NULL; 1003 1023 kfree(tl_nexus); 1004 1024 return 0; 1005 1025 } ··· 1015 1035 struct tcm_loop_nexus *tl_nexus; 1016 1036 ssize_t ret; 1017 1037 1018 - tl_nexus = tl_tpg->tl_hba->tl_nexus; 1038 + tl_nexus = tl_tpg->tl_nexus; 1019 1039 if (!tl_nexus) 1020 1040 return -ENODEV; 1021 1041
+1 -6
drivers/target/loopback/tcm_loop.h
··· 27 27 }; 28 28 29 29 struct tcm_loop_nexus { 30 - int it_nexus_active; 31 - /* 32 - * Pointer to Linux/SCSI HBA from linux/include/scsi_host.h 33 - */ 34 - struct scsi_host *sh; 35 30 /* 36 31 * Pointer to TCM session for I_T Nexus 37 32 */ ··· 46 51 atomic_t tl_tpg_port_count; 47 52 struct se_portal_group tl_se_tpg; 48 53 struct tcm_loop_hba *tl_hba; 54 + struct tcm_loop_nexus *tl_nexus; 49 55 }; 50 56 51 57 struct tcm_loop_hba { ··· 55 59 struct se_hba_s *se_hba; 56 60 struct se_lun *tl_hba_lun; 57 61 struct se_port *tl_hba_lun_sep; 58 - struct tcm_loop_nexus *tl_nexus; 59 62 struct device dev; 60 63 struct Scsi_Host *sh; 61 64 struct tcm_loop_tpg tl_hba_tpgs[TL_TPGS_PER_HBA];
+96 -258
drivers/target/target_core_configfs.c
··· 50 50 #include "target_core_rd.h" 51 51 #include "target_core_xcopy.h" 52 52 53 + #define TB_CIT_SETUP(_name, _item_ops, _group_ops, _attrs) \ 54 + static void target_core_setup_##_name##_cit(struct se_subsystem_api *sa) \ 55 + { \ 56 + struct target_backend_cits *tbc = &sa->tb_cits; \ 57 + struct config_item_type *cit = &tbc->tb_##_name##_cit; \ 58 + \ 59 + cit->ct_item_ops = _item_ops; \ 60 + cit->ct_group_ops = _group_ops; \ 61 + cit->ct_attrs = _attrs; \ 62 + cit->ct_owner = sa->owner; \ 63 + pr_debug("Setup generic %s\n", __stringify(_name)); \ 64 + } 65 + 53 66 extern struct t10_alua_lu_gp *default_lu_gp; 54 67 55 68 static LIST_HEAD(g_tf_list); ··· 139 126 140 127 pr_debug("Target_Core_ConfigFS: REGISTER -> group: %p name:" 141 128 " %s\n", group, name); 142 - /* 143 - * Below are some hardcoded request_module() calls to automatically 144 - * local fabric modules when the following is called: 145 - * 146 - * mkdir -p /sys/kernel/config/target/$MODULE_NAME 147 - * 148 - * Note that this does not limit which TCM fabric module can be 149 - * registered, but simply provids auto loading logic for modules with 150 - * mkdir(2) system calls with known TCM fabric modules. 151 - */ 152 - if (!strncmp(name, "iscsi", 5)) { 153 - /* 154 - * Automatically load the LIO Target fabric module when the 155 - * following is called: 156 - * 157 - * mkdir -p $CONFIGFS/target/iscsi 158 - */ 159 - ret = request_module("iscsi_target_mod"); 160 - if (ret < 0) { 161 - pr_err("request_module() failed for" 162 - " iscsi_target_mod.ko: %d\n", ret); 163 - return ERR_PTR(-EINVAL); 164 - } 165 - } else if (!strncmp(name, "loopback", 8)) { 166 - /* 167 - * Automatically load the tcm_loop fabric module when the 168 - * following is called: 169 - * 170 - * mkdir -p $CONFIGFS/target/loopback 171 - */ 172 - ret = request_module("tcm_loop"); 173 - if (ret < 0) { 174 - pr_err("request_module() failed for" 175 - " tcm_loop.ko: %d\n", ret); 176 - return ERR_PTR(-EINVAL); 177 - } 178 - } 179 129 180 130 tf = target_core_get_fabric(name); 181 131 if (!tf) { 182 - pr_err("target_core_get_fabric() failed for %s\n", 132 + pr_err("target_core_register_fabric() trying autoload for %s\n", 183 133 name); 134 + 135 + /* 136 + * Below are some hardcoded request_module() calls to automatically 137 + * local fabric modules when the following is called: 138 + * 139 + * mkdir -p /sys/kernel/config/target/$MODULE_NAME 140 + * 141 + * Note that this does not limit which TCM fabric module can be 142 + * registered, but simply provids auto loading logic for modules with 143 + * mkdir(2) system calls with known TCM fabric modules. 144 + */ 145 + 146 + if (!strncmp(name, "iscsi", 5)) { 147 + /* 148 + * Automatically load the LIO Target fabric module when the 149 + * following is called: 150 + * 151 + * mkdir -p $CONFIGFS/target/iscsi 152 + */ 153 + ret = request_module("iscsi_target_mod"); 154 + if (ret < 0) { 155 + pr_err("request_module() failed for" 156 + " iscsi_target_mod.ko: %d\n", ret); 157 + return ERR_PTR(-EINVAL); 158 + } 159 + } else if (!strncmp(name, "loopback", 8)) { 160 + /* 161 + * Automatically load the tcm_loop fabric module when the 162 + * following is called: 163 + * 164 + * mkdir -p $CONFIGFS/target/loopback 165 + */ 166 + ret = request_module("tcm_loop"); 167 + if (ret < 0) { 168 + pr_err("request_module() failed for" 169 + " tcm_loop.ko: %d\n", ret); 170 + return ERR_PTR(-EINVAL); 171 + } 172 + } 173 + 174 + tf = target_core_get_fabric(name); 175 + } 176 + 177 + if (!tf) { 178 + pr_err("target_core_get_fabric() failed for %s\n", 179 + name); 184 180 return ERR_PTR(-EINVAL); 185 181 } 186 182 pr_debug("Target_Core_ConfigFS: REGISTER -> Located fabric:" ··· 584 562 // Stop functions called by external Target Fabrics Modules 585 563 //############################################################################*/ 586 564 587 - /* Start functions for struct config_item_type target_core_dev_attrib_cit */ 588 - 589 - #define DEF_DEV_ATTRIB_SHOW(_name) \ 590 - static ssize_t target_core_dev_show_attr_##_name( \ 591 - struct se_dev_attrib *da, \ 592 - char *page) \ 593 - { \ 594 - return snprintf(page, PAGE_SIZE, "%u\n", \ 595 - (u32)da->da_dev->dev_attrib._name); \ 596 - } 597 - 598 - #define DEF_DEV_ATTRIB_STORE(_name) \ 599 - static ssize_t target_core_dev_store_attr_##_name( \ 600 - struct se_dev_attrib *da, \ 601 - const char *page, \ 602 - size_t count) \ 603 - { \ 604 - unsigned long val; \ 605 - int ret; \ 606 - \ 607 - ret = kstrtoul(page, 0, &val); \ 608 - if (ret < 0) { \ 609 - pr_err("kstrtoul() failed with" \ 610 - " ret: %d\n", ret); \ 611 - return -EINVAL; \ 612 - } \ 613 - ret = se_dev_set_##_name(da->da_dev, (u32)val); \ 614 - \ 615 - return (!ret) ? count : -EINVAL; \ 616 - } 617 - 618 - #define DEF_DEV_ATTRIB(_name) \ 619 - DEF_DEV_ATTRIB_SHOW(_name); \ 620 - DEF_DEV_ATTRIB_STORE(_name); 621 - 622 - #define DEF_DEV_ATTRIB_RO(_name) \ 623 - DEF_DEV_ATTRIB_SHOW(_name); 565 + /* Start functions for struct config_item_type tb_dev_attrib_cit */ 624 566 625 567 CONFIGFS_EATTR_STRUCT(target_core_dev_attrib, se_dev_attrib); 626 - #define SE_DEV_ATTR(_name, _mode) \ 627 - static struct target_core_dev_attrib_attribute \ 628 - target_core_dev_attrib_##_name = \ 629 - __CONFIGFS_EATTR(_name, _mode, \ 630 - target_core_dev_show_attr_##_name, \ 631 - target_core_dev_store_attr_##_name); 632 - 633 - #define SE_DEV_ATTR_RO(_name); \ 634 - static struct target_core_dev_attrib_attribute \ 635 - target_core_dev_attrib_##_name = \ 636 - __CONFIGFS_EATTR_RO(_name, \ 637 - target_core_dev_show_attr_##_name); 638 - 639 - DEF_DEV_ATTRIB(emulate_model_alias); 640 - SE_DEV_ATTR(emulate_model_alias, S_IRUGO | S_IWUSR); 641 - 642 - DEF_DEV_ATTRIB(emulate_dpo); 643 - SE_DEV_ATTR(emulate_dpo, S_IRUGO | S_IWUSR); 644 - 645 - DEF_DEV_ATTRIB(emulate_fua_write); 646 - SE_DEV_ATTR(emulate_fua_write, S_IRUGO | S_IWUSR); 647 - 648 - DEF_DEV_ATTRIB(emulate_fua_read); 649 - SE_DEV_ATTR(emulate_fua_read, S_IRUGO | S_IWUSR); 650 - 651 - DEF_DEV_ATTRIB(emulate_write_cache); 652 - SE_DEV_ATTR(emulate_write_cache, S_IRUGO | S_IWUSR); 653 - 654 - DEF_DEV_ATTRIB(emulate_ua_intlck_ctrl); 655 - SE_DEV_ATTR(emulate_ua_intlck_ctrl, S_IRUGO | S_IWUSR); 656 - 657 - DEF_DEV_ATTRIB(emulate_tas); 658 - SE_DEV_ATTR(emulate_tas, S_IRUGO | S_IWUSR); 659 - 660 - DEF_DEV_ATTRIB(emulate_tpu); 661 - SE_DEV_ATTR(emulate_tpu, S_IRUGO | S_IWUSR); 662 - 663 - DEF_DEV_ATTRIB(emulate_tpws); 664 - SE_DEV_ATTR(emulate_tpws, S_IRUGO | S_IWUSR); 665 - 666 - DEF_DEV_ATTRIB(emulate_caw); 667 - SE_DEV_ATTR(emulate_caw, S_IRUGO | S_IWUSR); 668 - 669 - DEF_DEV_ATTRIB(emulate_3pc); 670 - SE_DEV_ATTR(emulate_3pc, S_IRUGO | S_IWUSR); 671 - 672 - DEF_DEV_ATTRIB(pi_prot_type); 673 - SE_DEV_ATTR(pi_prot_type, S_IRUGO | S_IWUSR); 674 - 675 - DEF_DEV_ATTRIB_RO(hw_pi_prot_type); 676 - SE_DEV_ATTR_RO(hw_pi_prot_type); 677 - 678 - DEF_DEV_ATTRIB(pi_prot_format); 679 - SE_DEV_ATTR(pi_prot_format, S_IRUGO | S_IWUSR); 680 - 681 - DEF_DEV_ATTRIB(enforce_pr_isids); 682 - SE_DEV_ATTR(enforce_pr_isids, S_IRUGO | S_IWUSR); 683 - 684 - DEF_DEV_ATTRIB(is_nonrot); 685 - SE_DEV_ATTR(is_nonrot, S_IRUGO | S_IWUSR); 686 - 687 - DEF_DEV_ATTRIB(emulate_rest_reord); 688 - SE_DEV_ATTR(emulate_rest_reord, S_IRUGO | S_IWUSR); 689 - 690 - DEF_DEV_ATTRIB(force_pr_aptpl); 691 - SE_DEV_ATTR(force_pr_aptpl, S_IRUGO | S_IWUSR); 692 - 693 - DEF_DEV_ATTRIB_RO(hw_block_size); 694 - SE_DEV_ATTR_RO(hw_block_size); 695 - 696 - DEF_DEV_ATTRIB(block_size); 697 - SE_DEV_ATTR(block_size, S_IRUGO | S_IWUSR); 698 - 699 - DEF_DEV_ATTRIB_RO(hw_max_sectors); 700 - SE_DEV_ATTR_RO(hw_max_sectors); 701 - 702 - DEF_DEV_ATTRIB(fabric_max_sectors); 703 - SE_DEV_ATTR(fabric_max_sectors, S_IRUGO | S_IWUSR); 704 - 705 - DEF_DEV_ATTRIB(optimal_sectors); 706 - SE_DEV_ATTR(optimal_sectors, S_IRUGO | S_IWUSR); 707 - 708 - DEF_DEV_ATTRIB_RO(hw_queue_depth); 709 - SE_DEV_ATTR_RO(hw_queue_depth); 710 - 711 - DEF_DEV_ATTRIB(queue_depth); 712 - SE_DEV_ATTR(queue_depth, S_IRUGO | S_IWUSR); 713 - 714 - DEF_DEV_ATTRIB(max_unmap_lba_count); 715 - SE_DEV_ATTR(max_unmap_lba_count, S_IRUGO | S_IWUSR); 716 - 717 - DEF_DEV_ATTRIB(max_unmap_block_desc_count); 718 - SE_DEV_ATTR(max_unmap_block_desc_count, S_IRUGO | S_IWUSR); 719 - 720 - DEF_DEV_ATTRIB(unmap_granularity); 721 - SE_DEV_ATTR(unmap_granularity, S_IRUGO | S_IWUSR); 722 - 723 - DEF_DEV_ATTRIB(unmap_granularity_alignment); 724 - SE_DEV_ATTR(unmap_granularity_alignment, S_IRUGO | S_IWUSR); 725 - 726 - DEF_DEV_ATTRIB(max_write_same_len); 727 - SE_DEV_ATTR(max_write_same_len, S_IRUGO | S_IWUSR); 728 - 729 568 CONFIGFS_EATTR_OPS(target_core_dev_attrib, se_dev_attrib, da_group); 730 - 731 - static struct configfs_attribute *target_core_dev_attrib_attrs[] = { 732 - &target_core_dev_attrib_emulate_model_alias.attr, 733 - &target_core_dev_attrib_emulate_dpo.attr, 734 - &target_core_dev_attrib_emulate_fua_write.attr, 735 - &target_core_dev_attrib_emulate_fua_read.attr, 736 - &target_core_dev_attrib_emulate_write_cache.attr, 737 - &target_core_dev_attrib_emulate_ua_intlck_ctrl.attr, 738 - &target_core_dev_attrib_emulate_tas.attr, 739 - &target_core_dev_attrib_emulate_tpu.attr, 740 - &target_core_dev_attrib_emulate_tpws.attr, 741 - &target_core_dev_attrib_emulate_caw.attr, 742 - &target_core_dev_attrib_emulate_3pc.attr, 743 - &target_core_dev_attrib_pi_prot_type.attr, 744 - &target_core_dev_attrib_hw_pi_prot_type.attr, 745 - &target_core_dev_attrib_pi_prot_format.attr, 746 - &target_core_dev_attrib_enforce_pr_isids.attr, 747 - &target_core_dev_attrib_force_pr_aptpl.attr, 748 - &target_core_dev_attrib_is_nonrot.attr, 749 - &target_core_dev_attrib_emulate_rest_reord.attr, 750 - &target_core_dev_attrib_hw_block_size.attr, 751 - &target_core_dev_attrib_block_size.attr, 752 - &target_core_dev_attrib_hw_max_sectors.attr, 753 - &target_core_dev_attrib_fabric_max_sectors.attr, 754 - &target_core_dev_attrib_optimal_sectors.attr, 755 - &target_core_dev_attrib_hw_queue_depth.attr, 756 - &target_core_dev_attrib_queue_depth.attr, 757 - &target_core_dev_attrib_max_unmap_lba_count.attr, 758 - &target_core_dev_attrib_max_unmap_block_desc_count.attr, 759 - &target_core_dev_attrib_unmap_granularity.attr, 760 - &target_core_dev_attrib_unmap_granularity_alignment.attr, 761 - &target_core_dev_attrib_max_write_same_len.attr, 762 - NULL, 763 - }; 764 569 765 570 static struct configfs_item_operations target_core_dev_attrib_ops = { 766 571 .show_attribute = target_core_dev_attrib_attr_show, 767 572 .store_attribute = target_core_dev_attrib_attr_store, 768 573 }; 769 574 770 - static struct config_item_type target_core_dev_attrib_cit = { 771 - .ct_item_ops = &target_core_dev_attrib_ops, 772 - .ct_attrs = target_core_dev_attrib_attrs, 773 - .ct_owner = THIS_MODULE, 774 - }; 575 + TB_CIT_SETUP(dev_attrib, &target_core_dev_attrib_ops, NULL, NULL); 775 576 776 - /* End functions for struct config_item_type target_core_dev_attrib_cit */ 577 + /* End functions for struct config_item_type tb_dev_attrib_cit */ 777 578 778 - /* Start functions for struct config_item_type target_core_dev_wwn_cit */ 579 + /* Start functions for struct config_item_type tb_dev_wwn_cit */ 779 580 780 581 CONFIGFS_EATTR_STRUCT(target_core_dev_wwn, t10_wwn); 781 582 #define SE_DEV_WWN_ATTR(_name, _mode) \ ··· 829 984 .store_attribute = target_core_dev_wwn_attr_store, 830 985 }; 831 986 832 - static struct config_item_type target_core_dev_wwn_cit = { 833 - .ct_item_ops = &target_core_dev_wwn_ops, 834 - .ct_attrs = target_core_dev_wwn_attrs, 835 - .ct_owner = THIS_MODULE, 836 - }; 987 + TB_CIT_SETUP(dev_wwn, &target_core_dev_wwn_ops, NULL, target_core_dev_wwn_attrs); 837 988 838 - /* End functions for struct config_item_type target_core_dev_wwn_cit */ 989 + /* End functions for struct config_item_type tb_dev_wwn_cit */ 839 990 840 - /* Start functions for struct config_item_type target_core_dev_pr_cit */ 991 + /* Start functions for struct config_item_type tb_dev_pr_cit */ 841 992 842 993 CONFIGFS_EATTR_STRUCT(target_core_dev_pr, se_device); 843 994 #define SE_DEV_PR_ATTR(_name, _mode) \ ··· 1294 1453 .store_attribute = target_core_dev_pr_attr_store, 1295 1454 }; 1296 1455 1297 - static struct config_item_type target_core_dev_pr_cit = { 1298 - .ct_item_ops = &target_core_dev_pr_ops, 1299 - .ct_attrs = target_core_dev_pr_attrs, 1300 - .ct_owner = THIS_MODULE, 1301 - }; 1456 + TB_CIT_SETUP(dev_pr, &target_core_dev_pr_ops, NULL, target_core_dev_pr_attrs); 1302 1457 1303 - /* End functions for struct config_item_type target_core_dev_pr_cit */ 1458 + /* End functions for struct config_item_type tb_dev_pr_cit */ 1304 1459 1305 - /* Start functions for struct config_item_type target_core_dev_cit */ 1460 + /* Start functions for struct config_item_type tb_dev_cit */ 1306 1461 1307 1462 static ssize_t target_core_show_dev_info(void *p, char *page) 1308 1463 { ··· 1762 1925 .store = target_core_store_dev_lba_map, 1763 1926 }; 1764 1927 1765 - static struct configfs_attribute *lio_core_dev_attrs[] = { 1928 + static struct configfs_attribute *target_core_dev_attrs[] = { 1766 1929 &target_core_attr_dev_info.attr, 1767 1930 &target_core_attr_dev_control.attr, 1768 1931 &target_core_attr_dev_alias.attr, ··· 1821 1984 .store_attribute = target_core_dev_store, 1822 1985 }; 1823 1986 1824 - static struct config_item_type target_core_dev_cit = { 1825 - .ct_item_ops = &target_core_dev_item_ops, 1826 - .ct_attrs = lio_core_dev_attrs, 1827 - .ct_owner = THIS_MODULE, 1828 - }; 1987 + TB_CIT_SETUP(dev, &target_core_dev_item_ops, NULL, target_core_dev_attrs); 1829 1988 1830 - /* End functions for struct config_item_type target_core_dev_cit */ 1989 + /* End functions for struct config_item_type tb_dev_cit */ 1831 1990 1832 1991 /* Start functions for struct config_item_type target_core_alua_lu_gp_cit */ 1833 1992 ··· 2503 2670 2504 2671 /* End functions for struct config_item_type target_core_alua_tg_pt_gp_cit */ 2505 2672 2506 - /* Start functions for struct config_item_type target_core_alua_tg_pt_gps_cit */ 2673 + /* Start functions for struct config_item_type tb_alua_tg_pt_gps_cit */ 2507 2674 2508 2675 static struct config_group *target_core_alua_create_tg_pt_gp( 2509 2676 struct config_group *group, ··· 2554 2721 .drop_item = &target_core_alua_drop_tg_pt_gp, 2555 2722 }; 2556 2723 2557 - static struct config_item_type target_core_alua_tg_pt_gps_cit = { 2558 - .ct_group_ops = &target_core_alua_tg_pt_gps_group_ops, 2559 - .ct_owner = THIS_MODULE, 2560 - }; 2724 + TB_CIT_SETUP(dev_alua_tg_pt_gps, NULL, &target_core_alua_tg_pt_gps_group_ops, NULL); 2561 2725 2562 - /* End functions for struct config_item_type target_core_alua_tg_pt_gps_cit */ 2726 + /* End functions for struct config_item_type tb_alua_tg_pt_gps_cit */ 2563 2727 2564 2728 /* Start functions for struct config_item_type target_core_alua_cit */ 2565 2729 ··· 2574 2744 2575 2745 /* End functions for struct config_item_type target_core_alua_cit */ 2576 2746 2577 - /* Start functions for struct config_item_type target_core_stat_cit */ 2747 + /* Start functions for struct config_item_type tb_dev_stat_cit */ 2578 2748 2579 2749 static struct config_group *target_core_stat_mkdir( 2580 2750 struct config_group *group, ··· 2595 2765 .drop_item = &target_core_stat_rmdir, 2596 2766 }; 2597 2767 2598 - static struct config_item_type target_core_stat_cit = { 2599 - .ct_group_ops = &target_core_stat_group_ops, 2600 - .ct_owner = THIS_MODULE, 2601 - }; 2768 + TB_CIT_SETUP(dev_stat, NULL, &target_core_stat_group_ops, NULL); 2602 2769 2603 - /* End functions for struct config_item_type target_core_stat_cit */ 2770 + /* End functions for struct config_item_type tb_dev_stat_cit */ 2604 2771 2605 2772 /* Start functions for struct config_item_type target_core_hba_cit */ 2606 2773 ··· 2633 2806 if (!dev_cg->default_groups) 2634 2807 goto out_free_device; 2635 2808 2636 - config_group_init_type_name(dev_cg, name, &target_core_dev_cit); 2809 + config_group_init_type_name(dev_cg, name, &t->tb_cits.tb_dev_cit); 2637 2810 config_group_init_type_name(&dev->dev_attrib.da_group, "attrib", 2638 - &target_core_dev_attrib_cit); 2811 + &t->tb_cits.tb_dev_attrib_cit); 2639 2812 config_group_init_type_name(&dev->dev_pr_group, "pr", 2640 - &target_core_dev_pr_cit); 2813 + &t->tb_cits.tb_dev_pr_cit); 2641 2814 config_group_init_type_name(&dev->t10_wwn.t10_wwn_group, "wwn", 2642 - &target_core_dev_wwn_cit); 2815 + &t->tb_cits.tb_dev_wwn_cit); 2643 2816 config_group_init_type_name(&dev->t10_alua.alua_tg_pt_gps_group, 2644 - "alua", &target_core_alua_tg_pt_gps_cit); 2817 + "alua", &t->tb_cits.tb_dev_alua_tg_pt_gps_cit); 2645 2818 config_group_init_type_name(&dev->dev_stat_grps.stat_group, 2646 - "statistics", &target_core_stat_cit); 2819 + "statistics", &t->tb_cits.tb_dev_stat_cit); 2647 2820 2648 2821 dev_cg->default_groups[0] = &dev->dev_attrib.da_group; 2649 2822 dev_cg->default_groups[1] = &dev->dev_pr_group; ··· 2936 3109 }; 2937 3110 2938 3111 /* Stop functions for struct config_item_type target_core_hba_cit */ 3112 + 3113 + void target_core_setup_sub_cits(struct se_subsystem_api *sa) 3114 + { 3115 + target_core_setup_dev_cit(sa); 3116 + target_core_setup_dev_attrib_cit(sa); 3117 + target_core_setup_dev_pr_cit(sa); 3118 + target_core_setup_dev_wwn_cit(sa); 3119 + target_core_setup_dev_alua_tg_pt_gps_cit(sa); 3120 + target_core_setup_dev_stat_cit(sa); 3121 + } 3122 + EXPORT_SYMBOL(target_core_setup_sub_cits); 2939 3123 2940 3124 static int __init target_core_init_configfs(void) 2941 3125 {
+36 -54
drivers/target/target_core_device.c
··· 659 659 dev, dev->dev_attrib.max_unmap_lba_count); 660 660 return 0; 661 661 } 662 + EXPORT_SYMBOL(se_dev_set_max_unmap_lba_count); 662 663 663 664 int se_dev_set_max_unmap_block_desc_count( 664 665 struct se_device *dev, ··· 671 670 dev, dev->dev_attrib.max_unmap_block_desc_count); 672 671 return 0; 673 672 } 673 + EXPORT_SYMBOL(se_dev_set_max_unmap_block_desc_count); 674 674 675 675 int se_dev_set_unmap_granularity( 676 676 struct se_device *dev, ··· 682 680 dev, dev->dev_attrib.unmap_granularity); 683 681 return 0; 684 682 } 683 + EXPORT_SYMBOL(se_dev_set_unmap_granularity); 685 684 686 685 int se_dev_set_unmap_granularity_alignment( 687 686 struct se_device *dev, ··· 693 690 dev, dev->dev_attrib.unmap_granularity_alignment); 694 691 return 0; 695 692 } 693 + EXPORT_SYMBOL(se_dev_set_unmap_granularity_alignment); 696 694 697 695 int se_dev_set_max_write_same_len( 698 696 struct se_device *dev, ··· 704 700 dev, dev->dev_attrib.max_write_same_len); 705 701 return 0; 706 702 } 703 + EXPORT_SYMBOL(se_dev_set_max_write_same_len); 707 704 708 705 static void dev_set_t10_wwn_model_alias(struct se_device *dev) 709 706 { ··· 743 738 744 739 return 0; 745 740 } 741 + EXPORT_SYMBOL(se_dev_set_emulate_model_alias); 746 742 747 743 int se_dev_set_emulate_dpo(struct se_device *dev, int flag) 748 744 { ··· 759 753 760 754 return 0; 761 755 } 756 + EXPORT_SYMBOL(se_dev_set_emulate_dpo); 762 757 763 758 int se_dev_set_emulate_fua_write(struct se_device *dev, int flag) 764 759 { ··· 767 760 pr_err("Illegal value %d\n", flag); 768 761 return -EINVAL; 769 762 } 770 - 771 - if (flag && 772 - dev->transport->transport_type == TRANSPORT_PLUGIN_PHBA_PDEV) { 773 - pr_err("emulate_fua_write not supported for pSCSI\n"); 774 - return -EINVAL; 775 - } 776 763 dev->dev_attrib.emulate_fua_write = flag; 777 764 pr_debug("dev[%p]: SE Device Forced Unit Access WRITEs: %d\n", 778 765 dev, dev->dev_attrib.emulate_fua_write); 779 766 return 0; 780 767 } 768 + EXPORT_SYMBOL(se_dev_set_emulate_fua_write); 781 769 782 770 int se_dev_set_emulate_fua_read(struct se_device *dev, int flag) 783 771 { ··· 788 786 789 787 return 0; 790 788 } 789 + EXPORT_SYMBOL(se_dev_set_emulate_fua_read); 791 790 792 791 int se_dev_set_emulate_write_cache(struct se_device *dev, int flag) 793 792 { 794 793 if (flag != 0 && flag != 1) { 795 794 pr_err("Illegal value %d\n", flag); 796 - return -EINVAL; 797 - } 798 - if (flag && 799 - dev->transport->transport_type == TRANSPORT_PLUGIN_PHBA_PDEV) { 800 - pr_err("emulate_write_cache not supported for pSCSI\n"); 801 795 return -EINVAL; 802 796 } 803 797 if (flag && ··· 807 809 dev, dev->dev_attrib.emulate_write_cache); 808 810 return 0; 809 811 } 812 + EXPORT_SYMBOL(se_dev_set_emulate_write_cache); 810 813 811 814 int se_dev_set_emulate_ua_intlck_ctrl(struct se_device *dev, int flag) 812 815 { ··· 828 829 829 830 return 0; 830 831 } 832 + EXPORT_SYMBOL(se_dev_set_emulate_ua_intlck_ctrl); 831 833 832 834 int se_dev_set_emulate_tas(struct se_device *dev, int flag) 833 835 { ··· 849 849 850 850 return 0; 851 851 } 852 + EXPORT_SYMBOL(se_dev_set_emulate_tas); 852 853 853 854 int se_dev_set_emulate_tpu(struct se_device *dev, int flag) 854 855 { ··· 871 870 dev, flag); 872 871 return 0; 873 872 } 873 + EXPORT_SYMBOL(se_dev_set_emulate_tpu); 874 874 875 875 int se_dev_set_emulate_tpws(struct se_device *dev, int flag) 876 876 { ··· 893 891 dev, flag); 894 892 return 0; 895 893 } 894 + EXPORT_SYMBOL(se_dev_set_emulate_tpws); 896 895 897 896 int se_dev_set_emulate_caw(struct se_device *dev, int flag) 898 897 { ··· 907 904 908 905 return 0; 909 906 } 907 + EXPORT_SYMBOL(se_dev_set_emulate_caw); 910 908 911 909 int se_dev_set_emulate_3pc(struct se_device *dev, int flag) 912 910 { ··· 921 917 922 918 return 0; 923 919 } 920 + EXPORT_SYMBOL(se_dev_set_emulate_3pc); 924 921 925 922 int se_dev_set_pi_prot_type(struct se_device *dev, int flag) 926 923 { ··· 975 970 976 971 return 0; 977 972 } 973 + EXPORT_SYMBOL(se_dev_set_pi_prot_type); 978 974 979 975 int se_dev_set_pi_prot_format(struct se_device *dev, int flag) 980 976 { ··· 1011 1005 1012 1006 return 0; 1013 1007 } 1008 + EXPORT_SYMBOL(se_dev_set_pi_prot_format); 1014 1009 1015 1010 int se_dev_set_enforce_pr_isids(struct se_device *dev, int flag) 1016 1011 { ··· 1024 1017 (dev->dev_attrib.enforce_pr_isids) ? "Enabled" : "Disabled"); 1025 1018 return 0; 1026 1019 } 1020 + EXPORT_SYMBOL(se_dev_set_enforce_pr_isids); 1027 1021 1028 1022 int se_dev_set_force_pr_aptpl(struct se_device *dev, int flag) 1029 1023 { ··· 1042 1034 pr_debug("dev[%p]: SE Device force_pr_aptpl: %d\n", dev, flag); 1043 1035 return 0; 1044 1036 } 1037 + EXPORT_SYMBOL(se_dev_set_force_pr_aptpl); 1045 1038 1046 1039 int se_dev_set_is_nonrot(struct se_device *dev, int flag) 1047 1040 { ··· 1055 1046 dev, flag); 1056 1047 return 0; 1057 1048 } 1049 + EXPORT_SYMBOL(se_dev_set_is_nonrot); 1058 1050 1059 1051 int se_dev_set_emulate_rest_reord(struct se_device *dev, int flag) 1060 1052 { ··· 1068 1058 pr_debug("dev[%p]: SE Device emulate_rest_reord: %d\n", dev, flag); 1069 1059 return 0; 1070 1060 } 1061 + EXPORT_SYMBOL(se_dev_set_emulate_rest_reord); 1071 1062 1072 1063 /* 1073 1064 * Note, this can only be called on unexported SE Device Object. ··· 1087 1076 return -EINVAL; 1088 1077 } 1089 1078 1090 - if (dev->transport->transport_type == TRANSPORT_PLUGIN_PHBA_PDEV) { 1079 + if (queue_depth > dev->dev_attrib.queue_depth) { 1091 1080 if (queue_depth > dev->dev_attrib.hw_queue_depth) { 1092 - pr_err("dev[%p]: Passed queue_depth: %u" 1093 - " exceeds TCM/SE_Device TCQ: %u\n", 1094 - dev, queue_depth, 1081 + pr_err("dev[%p]: Passed queue_depth:" 1082 + " %u exceeds TCM/SE_Device MAX" 1083 + " TCQ: %u\n", dev, queue_depth, 1095 1084 dev->dev_attrib.hw_queue_depth); 1096 1085 return -EINVAL; 1097 1086 } 1098 - } else { 1099 - if (queue_depth > dev->dev_attrib.queue_depth) { 1100 - if (queue_depth > dev->dev_attrib.hw_queue_depth) { 1101 - pr_err("dev[%p]: Passed queue_depth:" 1102 - " %u exceeds TCM/SE_Device MAX" 1103 - " TCQ: %u\n", dev, queue_depth, 1104 - dev->dev_attrib.hw_queue_depth); 1105 - return -EINVAL; 1106 - } 1107 - } 1108 1087 } 1109 - 1110 1088 dev->dev_attrib.queue_depth = dev->queue_depth = queue_depth; 1111 1089 pr_debug("dev[%p]: SE Device TCQ Depth changed to: %u\n", 1112 1090 dev, queue_depth); 1113 1091 return 0; 1114 1092 } 1093 + EXPORT_SYMBOL(se_dev_set_queue_depth); 1115 1094 1116 1095 int se_dev_set_fabric_max_sectors(struct se_device *dev, u32 fabric_max_sectors) 1117 1096 { ··· 1124 1123 DA_STATUS_MAX_SECTORS_MIN); 1125 1124 return -EINVAL; 1126 1125 } 1127 - if (dev->transport->transport_type == TRANSPORT_PLUGIN_PHBA_PDEV) { 1128 - if (fabric_max_sectors > dev->dev_attrib.hw_max_sectors) { 1129 - pr_err("dev[%p]: Passed fabric_max_sectors: %u" 1130 - " greater than TCM/SE_Device max_sectors:" 1131 - " %u\n", dev, fabric_max_sectors, 1132 - dev->dev_attrib.hw_max_sectors); 1133 - return -EINVAL; 1134 - } 1135 - } else { 1136 - if (fabric_max_sectors > DA_STATUS_MAX_SECTORS_MAX) { 1137 - pr_err("dev[%p]: Passed fabric_max_sectors: %u" 1138 - " greater than DA_STATUS_MAX_SECTORS_MAX:" 1139 - " %u\n", dev, fabric_max_sectors, 1140 - DA_STATUS_MAX_SECTORS_MAX); 1141 - return -EINVAL; 1142 - } 1126 + if (fabric_max_sectors > DA_STATUS_MAX_SECTORS_MAX) { 1127 + pr_err("dev[%p]: Passed fabric_max_sectors: %u" 1128 + " greater than DA_STATUS_MAX_SECTORS_MAX:" 1129 + " %u\n", dev, fabric_max_sectors, 1130 + DA_STATUS_MAX_SECTORS_MAX); 1131 + return -EINVAL; 1143 1132 } 1144 1133 /* 1145 1134 * Align max_sectors down to PAGE_SIZE to follow transport_allocate_data_tasks() ··· 1146 1155 dev, fabric_max_sectors); 1147 1156 return 0; 1148 1157 } 1158 + EXPORT_SYMBOL(se_dev_set_fabric_max_sectors); 1149 1159 1150 1160 int se_dev_set_optimal_sectors(struct se_device *dev, u32 optimal_sectors) 1151 1161 { ··· 1154 1162 pr_err("dev[%p]: Unable to change SE Device" 1155 1163 " optimal_sectors while export_count is %d\n", 1156 1164 dev, dev->export_count); 1157 - return -EINVAL; 1158 - } 1159 - if (dev->transport->transport_type == TRANSPORT_PLUGIN_PHBA_PDEV) { 1160 - pr_err("dev[%p]: Passed optimal_sectors cannot be" 1161 - " changed for TCM/pSCSI\n", dev); 1162 1165 return -EINVAL; 1163 1166 } 1164 1167 if (optimal_sectors > dev->dev_attrib.fabric_max_sectors) { ··· 1168 1181 dev, optimal_sectors); 1169 1182 return 0; 1170 1183 } 1184 + EXPORT_SYMBOL(se_dev_set_optimal_sectors); 1171 1185 1172 1186 int se_dev_set_block_size(struct se_device *dev, u32 block_size) 1173 1187 { ··· 1189 1201 return -EINVAL; 1190 1202 } 1191 1203 1192 - if (dev->transport->transport_type == TRANSPORT_PLUGIN_PHBA_PDEV) { 1193 - pr_err("dev[%p]: Not allowed to change block_size for" 1194 - " Physical Device, use for Linux/SCSI to change" 1195 - " block_size for underlying hardware\n", dev); 1196 - return -EINVAL; 1197 - } 1198 - 1199 1204 dev->dev_attrib.block_size = block_size; 1200 1205 pr_debug("dev[%p]: SE Device block_size changed to %u\n", 1201 1206 dev, block_size); ··· 1199 1218 1200 1219 return 0; 1201 1220 } 1221 + EXPORT_SYMBOL(se_dev_set_block_size); 1202 1222 1203 1223 struct se_lun *core_dev_add_lun( 1204 1224 struct se_portal_group *tpg,
+42
drivers/target/target_core_file.c
··· 37 37 38 38 #include <target/target_core_base.h> 39 39 #include <target/target_core_backend.h> 40 + #include <target/target_core_backend_configfs.h> 40 41 41 42 #include "target_core_file.h" 42 43 ··· 935 934 return sbc_parse_cdb(cmd, &fd_sbc_ops); 936 935 } 937 936 937 + DEF_TB_DEFAULT_ATTRIBS(fileio); 938 + 939 + static struct configfs_attribute *fileio_backend_dev_attrs[] = { 940 + &fileio_dev_attrib_emulate_model_alias.attr, 941 + &fileio_dev_attrib_emulate_dpo.attr, 942 + &fileio_dev_attrib_emulate_fua_write.attr, 943 + &fileio_dev_attrib_emulate_fua_read.attr, 944 + &fileio_dev_attrib_emulate_write_cache.attr, 945 + &fileio_dev_attrib_emulate_ua_intlck_ctrl.attr, 946 + &fileio_dev_attrib_emulate_tas.attr, 947 + &fileio_dev_attrib_emulate_tpu.attr, 948 + &fileio_dev_attrib_emulate_tpws.attr, 949 + &fileio_dev_attrib_emulate_caw.attr, 950 + &fileio_dev_attrib_emulate_3pc.attr, 951 + &fileio_dev_attrib_pi_prot_type.attr, 952 + &fileio_dev_attrib_hw_pi_prot_type.attr, 953 + &fileio_dev_attrib_pi_prot_format.attr, 954 + &fileio_dev_attrib_enforce_pr_isids.attr, 955 + &fileio_dev_attrib_is_nonrot.attr, 956 + &fileio_dev_attrib_emulate_rest_reord.attr, 957 + &fileio_dev_attrib_force_pr_aptpl.attr, 958 + &fileio_dev_attrib_hw_block_size.attr, 959 + &fileio_dev_attrib_block_size.attr, 960 + &fileio_dev_attrib_hw_max_sectors.attr, 961 + &fileio_dev_attrib_fabric_max_sectors.attr, 962 + &fileio_dev_attrib_optimal_sectors.attr, 963 + &fileio_dev_attrib_hw_queue_depth.attr, 964 + &fileio_dev_attrib_queue_depth.attr, 965 + &fileio_dev_attrib_max_unmap_lba_count.attr, 966 + &fileio_dev_attrib_max_unmap_block_desc_count.attr, 967 + &fileio_dev_attrib_unmap_granularity.attr, 968 + &fileio_dev_attrib_unmap_granularity_alignment.attr, 969 + &fileio_dev_attrib_max_write_same_len.attr, 970 + NULL, 971 + }; 972 + 938 973 static struct se_subsystem_api fileio_template = { 939 974 .name = "fileio", 940 975 .inquiry_prod = "FILEIO", ··· 994 957 995 958 static int __init fileio_module_init(void) 996 959 { 960 + struct target_backend_cits *tbc = &fileio_template.tb_cits; 961 + 962 + target_core_setup_sub_cits(&fileio_template); 963 + tbc->tb_dev_attrib_cit.ct_attrs = fileio_backend_dev_attrs; 964 + 997 965 return transport_subsystem_register(&fileio_template); 998 966 } 999 967
+3 -4
drivers/target/target_core_hba.c
··· 36 36 #include <target/target_core_base.h> 37 37 #include <target/target_core_backend.h> 38 38 #include <target/target_core_fabric.h> 39 + #include <target/target_core_configfs.h> 39 40 40 41 #include "target_core_internal.h" 41 42 ··· 138 137 return hba; 139 138 140 139 out_module_put: 141 - if (hba->transport->owner) 142 - module_put(hba->transport->owner); 140 + module_put(hba->transport->owner); 143 141 hba->transport = NULL; 144 142 out_free_hba: 145 143 kfree(hba); ··· 159 159 pr_debug("CORE_HBA[%d] - Detached HBA from Generic Target" 160 160 " Core\n", hba->hba_id); 161 161 162 - if (hba->transport->owner) 163 - module_put(hba->transport->owner); 162 + module_put(hba->transport->owner); 164 163 165 164 hba->transport = NULL; 166 165 kfree(hba);
+42
drivers/target/target_core_iblock.c
··· 41 41 42 42 #include <target/target_core_base.h> 43 43 #include <target/target_core_backend.h> 44 + #include <target/target_core_backend_configfs.h> 44 45 45 46 #include "target_core_iblock.h" 46 47 ··· 859 858 return q->flush_flags & REQ_FLUSH; 860 859 } 861 860 861 + DEF_TB_DEFAULT_ATTRIBS(iblock); 862 + 863 + static struct configfs_attribute *iblock_backend_dev_attrs[] = { 864 + &iblock_dev_attrib_emulate_model_alias.attr, 865 + &iblock_dev_attrib_emulate_dpo.attr, 866 + &iblock_dev_attrib_emulate_fua_write.attr, 867 + &iblock_dev_attrib_emulate_fua_read.attr, 868 + &iblock_dev_attrib_emulate_write_cache.attr, 869 + &iblock_dev_attrib_emulate_ua_intlck_ctrl.attr, 870 + &iblock_dev_attrib_emulate_tas.attr, 871 + &iblock_dev_attrib_emulate_tpu.attr, 872 + &iblock_dev_attrib_emulate_tpws.attr, 873 + &iblock_dev_attrib_emulate_caw.attr, 874 + &iblock_dev_attrib_emulate_3pc.attr, 875 + &iblock_dev_attrib_pi_prot_type.attr, 876 + &iblock_dev_attrib_hw_pi_prot_type.attr, 877 + &iblock_dev_attrib_pi_prot_format.attr, 878 + &iblock_dev_attrib_enforce_pr_isids.attr, 879 + &iblock_dev_attrib_is_nonrot.attr, 880 + &iblock_dev_attrib_emulate_rest_reord.attr, 881 + &iblock_dev_attrib_force_pr_aptpl.attr, 882 + &iblock_dev_attrib_hw_block_size.attr, 883 + &iblock_dev_attrib_block_size.attr, 884 + &iblock_dev_attrib_hw_max_sectors.attr, 885 + &iblock_dev_attrib_fabric_max_sectors.attr, 886 + &iblock_dev_attrib_optimal_sectors.attr, 887 + &iblock_dev_attrib_hw_queue_depth.attr, 888 + &iblock_dev_attrib_queue_depth.attr, 889 + &iblock_dev_attrib_max_unmap_lba_count.attr, 890 + &iblock_dev_attrib_max_unmap_block_desc_count.attr, 891 + &iblock_dev_attrib_unmap_granularity.attr, 892 + &iblock_dev_attrib_unmap_granularity_alignment.attr, 893 + &iblock_dev_attrib_max_write_same_len.attr, 894 + NULL, 895 + }; 896 + 862 897 static struct se_subsystem_api iblock_template = { 863 898 .name = "iblock", 864 899 .inquiry_prod = "IBLOCK", ··· 920 883 921 884 static int __init iblock_module_init(void) 922 885 { 886 + struct target_backend_cits *tbc = &iblock_template.tb_cits; 887 + 888 + target_core_setup_sub_cits(&iblock_template); 889 + tbc->tb_dev_attrib_cit.ct_attrs = iblock_backend_dev_attrs; 890 + 923 891 return transport_subsystem_register(&iblock_template); 924 892 } 925 893
-28
drivers/target/target_core_internal.h
··· 18 18 struct se_lun *); 19 19 void core_dev_unexport(struct se_device *, struct se_portal_group *, 20 20 struct se_lun *); 21 - int se_dev_set_task_timeout(struct se_device *, u32); 22 - int se_dev_set_max_unmap_lba_count(struct se_device *, u32); 23 - int se_dev_set_max_unmap_block_desc_count(struct se_device *, u32); 24 - int se_dev_set_unmap_granularity(struct se_device *, u32); 25 - int se_dev_set_unmap_granularity_alignment(struct se_device *, u32); 26 - int se_dev_set_max_write_same_len(struct se_device *, u32); 27 - int se_dev_set_emulate_model_alias(struct se_device *, int); 28 - int se_dev_set_emulate_dpo(struct se_device *, int); 29 - int se_dev_set_emulate_fua_write(struct se_device *, int); 30 - int se_dev_set_emulate_fua_read(struct se_device *, int); 31 - int se_dev_set_emulate_write_cache(struct se_device *, int); 32 - int se_dev_set_emulate_ua_intlck_ctrl(struct se_device *, int); 33 - int se_dev_set_emulate_tas(struct se_device *, int); 34 - int se_dev_set_emulate_tpu(struct se_device *, int); 35 - int se_dev_set_emulate_tpws(struct se_device *, int); 36 - int se_dev_set_emulate_caw(struct se_device *, int); 37 - int se_dev_set_emulate_3pc(struct se_device *, int); 38 - int se_dev_set_pi_prot_type(struct se_device *, int); 39 - int se_dev_set_pi_prot_format(struct se_device *, int); 40 - int se_dev_set_enforce_pr_isids(struct se_device *, int); 41 - int se_dev_set_force_pr_aptpl(struct se_device *, int); 42 - int se_dev_set_is_nonrot(struct se_device *, int); 43 - int se_dev_set_emulate_rest_reord(struct se_device *dev, int); 44 - int se_dev_set_queue_depth(struct se_device *, u32); 45 - int se_dev_set_max_sectors(struct se_device *, u32); 46 - int se_dev_set_fabric_max_sectors(struct se_device *, u32); 47 - int se_dev_set_optimal_sectors(struct se_device *, u32); 48 - int se_dev_set_block_size(struct se_device *, u32); 49 21 struct se_lun *core_dev_add_lun(struct se_portal_group *, struct se_device *, u32); 50 22 void core_dev_del_lun(struct se_portal_group *, struct se_lun *); 51 23 struct se_lun *core_get_lun_from_tpg(struct se_portal_group *, u32);
+94 -31
drivers/target/target_core_pr.c
··· 76 76 }; 77 77 78 78 static void __core_scsi3_complete_pro_release(struct se_device *, struct se_node_acl *, 79 - struct t10_pr_registration *, int); 79 + struct t10_pr_registration *, int, int); 80 80 81 81 static sense_reason_t 82 82 target_scsi2_reservation_check(struct se_cmd *cmd) ··· 1177 1177 * service action with the SERVICE ACTION RESERVATION KEY 1178 1178 * field set to zero (see 5.7.11.3). 1179 1179 */ 1180 - __core_scsi3_complete_pro_release(dev, nacl, pr_reg, 0); 1180 + __core_scsi3_complete_pro_release(dev, nacl, pr_reg, 0, 1); 1181 1181 ret = 1; 1182 1182 /* 1183 1183 * For 'All Registrants' reservation types, all existing ··· 1219 1219 1220 1220 pr_reg->pr_reg_deve->def_pr_registered = 0; 1221 1221 pr_reg->pr_reg_deve->pr_res_key = 0; 1222 - list_del(&pr_reg->pr_reg_list); 1222 + if (!list_empty(&pr_reg->pr_reg_list)) 1223 + list_del(&pr_reg->pr_reg_list); 1223 1224 /* 1224 1225 * Caller accessing *pr_reg using core_scsi3_locate_pr_reg(), 1225 1226 * so call core_scsi3_put_pr_reg() to decrement our reference. ··· 1272 1271 { 1273 1272 struct t10_reservation *pr_tmpl = &dev->t10_pr; 1274 1273 struct t10_pr_registration *pr_reg, *pr_reg_tmp, *pr_res_holder; 1274 + bool free_reg = false; 1275 1275 /* 1276 1276 * If the passed se_node_acl matches the reservation holder, 1277 1277 * release the reservation. ··· 1280 1278 spin_lock(&dev->dev_reservation_lock); 1281 1279 pr_res_holder = dev->dev_pr_res_holder; 1282 1280 if ((pr_res_holder != NULL) && 1283 - (pr_res_holder->pr_reg_nacl == nacl)) 1284 - __core_scsi3_complete_pro_release(dev, nacl, pr_res_holder, 0); 1281 + (pr_res_holder->pr_reg_nacl == nacl)) { 1282 + __core_scsi3_complete_pro_release(dev, nacl, pr_res_holder, 0, 1); 1283 + free_reg = true; 1284 + } 1285 1285 spin_unlock(&dev->dev_reservation_lock); 1286 1286 /* 1287 1287 * Release any registration associated with the struct se_node_acl. 1288 1288 */ 1289 1289 spin_lock(&pr_tmpl->registration_lock); 1290 + if (pr_res_holder && free_reg) 1291 + __core_scsi3_free_registration(dev, pr_res_holder, NULL, 0); 1292 + 1290 1293 list_for_each_entry_safe(pr_reg, pr_reg_tmp, 1291 1294 &pr_tmpl->registration_list, pr_reg_list) { 1292 1295 ··· 1314 1307 if (pr_res_holder != NULL) { 1315 1308 struct se_node_acl *pr_res_nacl = pr_res_holder->pr_reg_nacl; 1316 1309 __core_scsi3_complete_pro_release(dev, pr_res_nacl, 1317 - pr_res_holder, 0); 1310 + pr_res_holder, 0, 0); 1318 1311 } 1319 1312 spin_unlock(&dev->dev_reservation_lock); 1320 1313 ··· 1436 1429 struct target_core_fabric_ops *tmp_tf_ops; 1437 1430 unsigned char *buf; 1438 1431 unsigned char *ptr, *i_str = NULL, proto_ident, tmp_proto_ident; 1439 - char *iport_ptr = NULL, dest_iport[64], i_buf[PR_REG_ISID_ID_LEN]; 1432 + char *iport_ptr = NULL, i_buf[PR_REG_ISID_ID_LEN]; 1440 1433 sense_reason_t ret; 1441 1434 u32 tpdl, tid_len = 0; 1442 1435 int dest_local_nexus; 1443 1436 u32 dest_rtpi = 0; 1444 - 1445 - memset(dest_iport, 0, 64); 1446 1437 1447 1438 local_se_deve = se_sess->se_node_acl->device_list[cmd->orig_fe_lun]; 1448 1439 /* ··· 2110 2105 /* 2111 2106 * sa_res_key=0 Unregister Reservation Key for registered I_T Nexus. 2112 2107 */ 2113 - pr_holder = core_scsi3_check_implicit_release( 2114 - cmd->se_dev, pr_reg); 2108 + type = pr_reg->pr_res_type; 2109 + pr_holder = core_scsi3_check_implicit_release(cmd->se_dev, 2110 + pr_reg); 2115 2111 if (pr_holder < 0) { 2116 2112 ret = TCM_RESERVATION_CONFLICT; 2117 2113 goto out; 2118 2114 } 2119 - type = pr_reg->pr_res_type; 2120 2115 2121 2116 spin_lock(&pr_tmpl->registration_lock); 2122 2117 /* ··· 2274 2269 spin_lock(&dev->dev_reservation_lock); 2275 2270 pr_res_holder = dev->dev_pr_res_holder; 2276 2271 if (pr_res_holder) { 2272 + int pr_res_type = pr_res_holder->pr_res_type; 2277 2273 /* 2278 2274 * From spc4r17 Section 5.7.9: Reserving: 2279 2275 * ··· 2285 2279 * the logical unit, then the command shall be completed with 2286 2280 * RESERVATION CONFLICT status. 2287 2281 */ 2288 - if (pr_res_holder != pr_reg) { 2282 + if ((pr_res_holder != pr_reg) && 2283 + (pr_res_type != PR_TYPE_WRITE_EXCLUSIVE_ALLREG) && 2284 + (pr_res_type != PR_TYPE_EXCLUSIVE_ACCESS_ALLREG)) { 2289 2285 struct se_node_acl *pr_res_nacl = pr_res_holder->pr_reg_nacl; 2290 2286 pr_err("SPC-3 PR: Attempted RESERVE from" 2291 2287 " [%s]: %s while reservation already held by" ··· 2393 2385 struct se_device *dev, 2394 2386 struct se_node_acl *se_nacl, 2395 2387 struct t10_pr_registration *pr_reg, 2396 - int explicit) 2388 + int explicit, 2389 + int unreg) 2397 2390 { 2398 2391 struct target_core_fabric_ops *tfo = se_nacl->se_tpg->se_tpg_tfo; 2399 2392 char i_buf[PR_REG_ISID_ID_LEN]; 2393 + int pr_res_type = 0, pr_res_scope = 0; 2400 2394 2401 2395 memset(i_buf, 0, PR_REG_ISID_ID_LEN); 2402 2396 core_pr_dump_initiator_port(pr_reg, i_buf, PR_REG_ISID_ID_LEN); 2403 2397 /* 2404 2398 * Go ahead and release the current PR reservation holder. 2399 + * If an All Registrants reservation is currently active and 2400 + * a unregister operation is requested, replace the current 2401 + * dev_pr_res_holder with another active registration. 2405 2402 */ 2406 - dev->dev_pr_res_holder = NULL; 2403 + if (dev->dev_pr_res_holder) { 2404 + pr_res_type = dev->dev_pr_res_holder->pr_res_type; 2405 + pr_res_scope = dev->dev_pr_res_holder->pr_res_scope; 2406 + dev->dev_pr_res_holder->pr_res_type = 0; 2407 + dev->dev_pr_res_holder->pr_res_scope = 0; 2408 + dev->dev_pr_res_holder->pr_res_holder = 0; 2409 + dev->dev_pr_res_holder = NULL; 2410 + } 2411 + if (!unreg) 2412 + goto out; 2407 2413 2408 - pr_debug("SPC-3 PR [%s] Service Action: %s RELEASE cleared" 2409 - " reservation holder TYPE: %s ALL_TG_PT: %d\n", 2410 - tfo->get_fabric_name(), (explicit) ? "explicit" : "implicit", 2411 - core_scsi3_pr_dump_type(pr_reg->pr_res_type), 2412 - (pr_reg->pr_reg_all_tg_pt) ? 1 : 0); 2414 + spin_lock(&dev->t10_pr.registration_lock); 2415 + list_del_init(&pr_reg->pr_reg_list); 2416 + /* 2417 + * If the I_T nexus is a reservation holder, the persistent reservation 2418 + * is of an all registrants type, and the I_T nexus is the last remaining 2419 + * registered I_T nexus, then the device server shall also release the 2420 + * persistent reservation. 2421 + */ 2422 + if (!list_empty(&dev->t10_pr.registration_list) && 2423 + ((pr_res_type == PR_TYPE_WRITE_EXCLUSIVE_ALLREG) || 2424 + (pr_res_type == PR_TYPE_EXCLUSIVE_ACCESS_ALLREG))) { 2425 + dev->dev_pr_res_holder = 2426 + list_entry(dev->t10_pr.registration_list.next, 2427 + struct t10_pr_registration, pr_reg_list); 2428 + dev->dev_pr_res_holder->pr_res_type = pr_res_type; 2429 + dev->dev_pr_res_holder->pr_res_scope = pr_res_scope; 2430 + dev->dev_pr_res_holder->pr_res_holder = 1; 2431 + } 2432 + spin_unlock(&dev->t10_pr.registration_lock); 2433 + out: 2434 + if (!dev->dev_pr_res_holder) { 2435 + pr_debug("SPC-3 PR [%s] Service Action: %s RELEASE cleared" 2436 + " reservation holder TYPE: %s ALL_TG_PT: %d\n", 2437 + tfo->get_fabric_name(), (explicit) ? "explicit" : 2438 + "implicit", core_scsi3_pr_dump_type(pr_res_type), 2439 + (pr_reg->pr_reg_all_tg_pt) ? 1 : 0); 2440 + } 2413 2441 pr_debug("SPC-3 PR [%s] RELEASE Node: %s%s\n", 2414 2442 tfo->get_fabric_name(), se_nacl->initiatorname, 2415 2443 i_buf); ··· 2576 2532 * server shall not establish a unit attention condition. 2577 2533 */ 2578 2534 __core_scsi3_complete_pro_release(dev, se_sess->se_node_acl, 2579 - pr_reg, 1); 2535 + pr_reg, 1, 0); 2580 2536 2581 2537 spin_unlock(&dev->dev_reservation_lock); 2582 2538 ··· 2664 2620 if (pr_res_holder) { 2665 2621 struct se_node_acl *pr_res_nacl = pr_res_holder->pr_reg_nacl; 2666 2622 __core_scsi3_complete_pro_release(dev, pr_res_nacl, 2667 - pr_res_holder, 0); 2623 + pr_res_holder, 0, 0); 2668 2624 } 2669 2625 spin_unlock(&dev->dev_reservation_lock); 2670 2626 /* ··· 2723 2679 */ 2724 2680 if (dev->dev_pr_res_holder) 2725 2681 __core_scsi3_complete_pro_release(dev, nacl, 2726 - dev->dev_pr_res_holder, 0); 2682 + dev->dev_pr_res_holder, 0, 0); 2727 2683 2728 2684 dev->dev_pr_res_holder = pr_reg; 2729 2685 pr_reg->pr_res_holder = 1; ··· 2968 2924 */ 2969 2925 if (pr_reg_n != pr_res_holder) 2970 2926 __core_scsi3_complete_pro_release(dev, 2971 - pr_res_holder->pr_reg_nacl, 2972 - dev->dev_pr_res_holder, 0); 2927 + pr_res_holder->pr_reg_nacl, 2928 + dev->dev_pr_res_holder, 0, 0); 2973 2929 /* 2974 2930 * b) Remove the registrations for all I_T nexuses identified 2975 2931 * by the SERVICE ACTION RESERVATION KEY field, except the ··· 3103 3059 struct t10_reservation *pr_tmpl = &dev->t10_pr; 3104 3060 unsigned char *buf; 3105 3061 unsigned char *initiator_str; 3106 - char *iport_ptr = NULL, dest_iport[64], i_buf[PR_REG_ISID_ID_LEN]; 3062 + char *iport_ptr = NULL, i_buf[PR_REG_ISID_ID_LEN]; 3107 3063 u32 tid_len, tmp_tid_len; 3108 3064 int new_reg = 0, type, scope, matching_iname; 3109 3065 sense_reason_t ret; ··· 3115 3071 return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; 3116 3072 } 3117 3073 3118 - memset(dest_iport, 0, 64); 3119 3074 memset(i_buf, 0, PR_REG_ISID_ID_LEN); 3120 3075 se_tpg = se_sess->se_tpg; 3121 3076 tf_ops = se_tpg->se_tpg_tfo; ··· 3432 3389 * holder (i.e., the I_T nexus on which the 3433 3390 */ 3434 3391 __core_scsi3_complete_pro_release(dev, pr_res_nacl, 3435 - dev->dev_pr_res_holder, 0); 3392 + dev->dev_pr_res_holder, 0, 0); 3436 3393 /* 3437 3394 * g) Move the persistent reservation to the specified I_T nexus using 3438 3395 * the same scope and type as the persistent reservation released in ··· 3880 3837 unsigned char *buf; 3881 3838 u32 add_desc_len = 0, add_len = 0, desc_len, exp_desc_len; 3882 3839 u32 off = 8; /* off into first Full Status descriptor */ 3883 - int format_code = 0; 3840 + int format_code = 0, pr_res_type = 0, pr_res_scope = 0; 3841 + bool all_reg = false; 3884 3842 3885 3843 if (cmd->data_length < 8) { 3886 3844 pr_err("PRIN SA READ_FULL_STATUS SCSI Data Length: %u" ··· 3897 3853 buf[1] = ((dev->t10_pr.pr_generation >> 16) & 0xff); 3898 3854 buf[2] = ((dev->t10_pr.pr_generation >> 8) & 0xff); 3899 3855 buf[3] = (dev->t10_pr.pr_generation & 0xff); 3856 + 3857 + spin_lock(&dev->dev_reservation_lock); 3858 + if (dev->dev_pr_res_holder) { 3859 + struct t10_pr_registration *pr_holder = dev->dev_pr_res_holder; 3860 + 3861 + if (pr_holder->pr_res_type == PR_TYPE_WRITE_EXCLUSIVE_ALLREG || 3862 + pr_holder->pr_res_type == PR_TYPE_EXCLUSIVE_ACCESS_ALLREG) { 3863 + all_reg = true; 3864 + pr_res_type = pr_holder->pr_res_type; 3865 + pr_res_scope = pr_holder->pr_res_scope; 3866 + } 3867 + } 3868 + spin_unlock(&dev->dev_reservation_lock); 3900 3869 3901 3870 spin_lock(&pr_tmpl->registration_lock); 3902 3871 list_for_each_entry_safe(pr_reg, pr_reg_tmp, ··· 3958 3901 * reservation holder for PR_HOLDER bit. 3959 3902 * 3960 3903 * Also, if this registration is the reservation 3961 - * holder, fill in SCOPE and TYPE in the next byte. 3904 + * holder or there is an All Registrants reservation 3905 + * active, fill in SCOPE and TYPE in the next byte. 3962 3906 */ 3963 3907 if (pr_reg->pr_res_holder) { 3964 3908 buf[off++] |= 0x01; 3965 3909 buf[off++] = (pr_reg->pr_res_scope & 0xf0) | 3966 3910 (pr_reg->pr_res_type & 0x0f); 3967 - } else 3911 + } else if (all_reg) { 3912 + buf[off++] |= 0x01; 3913 + buf[off++] = (pr_res_scope & 0xf0) | 3914 + (pr_res_type & 0x0f); 3915 + } else { 3968 3916 off += 2; 3917 + } 3969 3918 3970 3919 off += 4; /* Skip over reserved area */ 3971 3920 /*
+26
drivers/target/target_core_pscsi.c
··· 44 44 45 45 #include <target/target_core_base.h> 46 46 #include <target/target_core_backend.h> 47 + #include <target/target_core_backend_configfs.h> 47 48 48 49 #include "target_core_alua.h" 49 50 #include "target_core_pscsi.h" ··· 1166 1165 kfree(pt); 1167 1166 } 1168 1167 1168 + DEF_TB_DEV_ATTRIB_RO(pscsi, hw_pi_prot_type); 1169 + TB_DEV_ATTR_RO(pscsi, hw_pi_prot_type); 1170 + 1171 + DEF_TB_DEV_ATTRIB_RO(pscsi, hw_block_size); 1172 + TB_DEV_ATTR_RO(pscsi, hw_block_size); 1173 + 1174 + DEF_TB_DEV_ATTRIB_RO(pscsi, hw_max_sectors); 1175 + TB_DEV_ATTR_RO(pscsi, hw_max_sectors); 1176 + 1177 + DEF_TB_DEV_ATTRIB_RO(pscsi, hw_queue_depth); 1178 + TB_DEV_ATTR_RO(pscsi, hw_queue_depth); 1179 + 1180 + static struct configfs_attribute *pscsi_backend_dev_attrs[] = { 1181 + &pscsi_dev_attrib_hw_pi_prot_type.attr, 1182 + &pscsi_dev_attrib_hw_block_size.attr, 1183 + &pscsi_dev_attrib_hw_max_sectors.attr, 1184 + &pscsi_dev_attrib_hw_queue_depth.attr, 1185 + NULL, 1186 + }; 1187 + 1169 1188 static struct se_subsystem_api pscsi_template = { 1170 1189 .name = "pscsi", 1171 1190 .owner = THIS_MODULE, ··· 1206 1185 1207 1186 static int __init pscsi_module_init(void) 1208 1187 { 1188 + struct target_backend_cits *tbc = &pscsi_template.tb_cits; 1189 + 1190 + target_core_setup_sub_cits(&pscsi_template); 1191 + tbc->tb_dev_attrib_cit.ct_attrs = pscsi_backend_dev_attrs; 1192 + 1209 1193 return transport_subsystem_register(&pscsi_template); 1210 1194 } 1211 1195
+41
drivers/target/target_core_rd.c
··· 34 34 35 35 #include <target/target_core_base.h> 36 36 #include <target/target_core_backend.h> 37 + #include <target/target_core_backend_configfs.h> 37 38 38 39 #include "target_core_rd.h" 39 40 ··· 633 632 return sbc_parse_cdb(cmd, &rd_sbc_ops); 634 633 } 635 634 635 + DEF_TB_DEFAULT_ATTRIBS(rd_mcp); 636 + 637 + static struct configfs_attribute *rd_mcp_backend_dev_attrs[] = { 638 + &rd_mcp_dev_attrib_emulate_model_alias.attr, 639 + &rd_mcp_dev_attrib_emulate_dpo.attr, 640 + &rd_mcp_dev_attrib_emulate_fua_write.attr, 641 + &rd_mcp_dev_attrib_emulate_fua_read.attr, 642 + &rd_mcp_dev_attrib_emulate_write_cache.attr, 643 + &rd_mcp_dev_attrib_emulate_ua_intlck_ctrl.attr, 644 + &rd_mcp_dev_attrib_emulate_tas.attr, 645 + &rd_mcp_dev_attrib_emulate_tpu.attr, 646 + &rd_mcp_dev_attrib_emulate_tpws.attr, 647 + &rd_mcp_dev_attrib_emulate_caw.attr, 648 + &rd_mcp_dev_attrib_emulate_3pc.attr, 649 + &rd_mcp_dev_attrib_pi_prot_type.attr, 650 + &rd_mcp_dev_attrib_hw_pi_prot_type.attr, 651 + &rd_mcp_dev_attrib_pi_prot_format.attr, 652 + &rd_mcp_dev_attrib_enforce_pr_isids.attr, 653 + &rd_mcp_dev_attrib_is_nonrot.attr, 654 + &rd_mcp_dev_attrib_emulate_rest_reord.attr, 655 + &rd_mcp_dev_attrib_force_pr_aptpl.attr, 656 + &rd_mcp_dev_attrib_hw_block_size.attr, 657 + &rd_mcp_dev_attrib_block_size.attr, 658 + &rd_mcp_dev_attrib_hw_max_sectors.attr, 659 + &rd_mcp_dev_attrib_fabric_max_sectors.attr, 660 + &rd_mcp_dev_attrib_optimal_sectors.attr, 661 + &rd_mcp_dev_attrib_hw_queue_depth.attr, 662 + &rd_mcp_dev_attrib_queue_depth.attr, 663 + &rd_mcp_dev_attrib_max_unmap_lba_count.attr, 664 + &rd_mcp_dev_attrib_max_unmap_block_desc_count.attr, 665 + &rd_mcp_dev_attrib_unmap_granularity.attr, 666 + &rd_mcp_dev_attrib_unmap_granularity_alignment.attr, 667 + &rd_mcp_dev_attrib_max_write_same_len.attr, 668 + NULL, 669 + }; 670 + 636 671 static struct se_subsystem_api rd_mcp_template = { 637 672 .name = "rd_mcp", 638 673 .inquiry_prod = "RAMDISK-MCP", ··· 690 653 691 654 int __init rd_module_init(void) 692 655 { 656 + struct target_backend_cits *tbc = &rd_mcp_template.tb_cits; 693 657 int ret; 658 + 659 + target_core_setup_sub_cits(&rd_mcp_template); 660 + tbc->tb_dev_attrib_cit.ct_attrs = rd_mcp_backend_dev_attrs; 694 661 695 662 ret = transport_subsystem_register(&rd_mcp_template); 696 663 if (ret < 0) {
+42
drivers/target/target_core_user.c
··· 28 28 #include <target/target_core_base.h> 29 29 #include <target/target_core_fabric.h> 30 30 #include <target/target_core_backend.h> 31 + #include <target/target_core_backend_configfs.h> 32 + 31 33 #include <linux/target_core_user.h> 32 34 33 35 /* ··· 1094 1092 return ret; 1095 1093 } 1096 1094 1095 + DEF_TB_DEFAULT_ATTRIBS(tcmu); 1096 + 1097 + static struct configfs_attribute *tcmu_backend_dev_attrs[] = { 1098 + &tcmu_dev_attrib_emulate_model_alias.attr, 1099 + &tcmu_dev_attrib_emulate_dpo.attr, 1100 + &tcmu_dev_attrib_emulate_fua_write.attr, 1101 + &tcmu_dev_attrib_emulate_fua_read.attr, 1102 + &tcmu_dev_attrib_emulate_write_cache.attr, 1103 + &tcmu_dev_attrib_emulate_ua_intlck_ctrl.attr, 1104 + &tcmu_dev_attrib_emulate_tas.attr, 1105 + &tcmu_dev_attrib_emulate_tpu.attr, 1106 + &tcmu_dev_attrib_emulate_tpws.attr, 1107 + &tcmu_dev_attrib_emulate_caw.attr, 1108 + &tcmu_dev_attrib_emulate_3pc.attr, 1109 + &tcmu_dev_attrib_pi_prot_type.attr, 1110 + &tcmu_dev_attrib_hw_pi_prot_type.attr, 1111 + &tcmu_dev_attrib_pi_prot_format.attr, 1112 + &tcmu_dev_attrib_enforce_pr_isids.attr, 1113 + &tcmu_dev_attrib_is_nonrot.attr, 1114 + &tcmu_dev_attrib_emulate_rest_reord.attr, 1115 + &tcmu_dev_attrib_force_pr_aptpl.attr, 1116 + &tcmu_dev_attrib_hw_block_size.attr, 1117 + &tcmu_dev_attrib_block_size.attr, 1118 + &tcmu_dev_attrib_hw_max_sectors.attr, 1119 + &tcmu_dev_attrib_fabric_max_sectors.attr, 1120 + &tcmu_dev_attrib_optimal_sectors.attr, 1121 + &tcmu_dev_attrib_hw_queue_depth.attr, 1122 + &tcmu_dev_attrib_queue_depth.attr, 1123 + &tcmu_dev_attrib_max_unmap_lba_count.attr, 1124 + &tcmu_dev_attrib_max_unmap_block_desc_count.attr, 1125 + &tcmu_dev_attrib_unmap_granularity.attr, 1126 + &tcmu_dev_attrib_unmap_granularity_alignment.attr, 1127 + &tcmu_dev_attrib_max_write_same_len.attr, 1128 + NULL, 1129 + }; 1130 + 1097 1131 static struct se_subsystem_api tcmu_template = { 1098 1132 .name = "user", 1099 1133 .inquiry_prod = "USER", ··· 1150 1112 1151 1113 static int __init tcmu_module_init(void) 1152 1114 { 1115 + struct target_backend_cits *tbc = &tcmu_template.tb_cits; 1153 1116 int ret; 1154 1117 1155 1118 BUILD_BUG_ON((sizeof(struct tcmu_cmd_entry) % TCMU_OP_ALIGN_SIZE) != 0); ··· 1172 1133 if (ret < 0) { 1173 1134 goto out_unreg_device; 1174 1135 } 1136 + 1137 + target_core_setup_sub_cits(&tcmu_template); 1138 + tbc->tb_dev_attrib_cit.ct_attrs = tcmu_backend_dev_attrs; 1175 1139 1176 1140 ret = transport_subsystem_register(&tcmu_template); 1177 1141 if (ret)
+43
include/target/target_core_backend.h
··· 5 5 #define TRANSPORT_PLUGIN_VHBA_PDEV 2 6 6 #define TRANSPORT_PLUGIN_VHBA_VDEV 3 7 7 8 + struct target_backend_cits { 9 + struct config_item_type tb_dev_cit; 10 + struct config_item_type tb_dev_attrib_cit; 11 + struct config_item_type tb_dev_pr_cit; 12 + struct config_item_type tb_dev_wwn_cit; 13 + struct config_item_type tb_dev_alua_tg_pt_gps_cit; 14 + struct config_item_type tb_dev_stat_cit; 15 + }; 16 + 8 17 struct se_subsystem_api { 9 18 struct list_head sub_api_list; 10 19 ··· 53 44 int (*init_prot)(struct se_device *); 54 45 int (*format_prot)(struct se_device *); 55 46 void (*free_prot)(struct se_device *); 47 + 48 + struct target_backend_cits tb_cits; 56 49 }; 57 50 58 51 struct sbc_ops { ··· 106 95 struct scatterlist *, u32, struct scatterlist *, u32); 107 96 108 97 void array_free(void *array, int n); 98 + 99 + /* From target_core_configfs.c to setup default backend config_item_types */ 100 + void target_core_setup_sub_cits(struct se_subsystem_api *); 101 + 102 + /* attribute helpers from target_core_device.c for backend drivers */ 103 + int se_dev_set_max_unmap_lba_count(struct se_device *, u32); 104 + int se_dev_set_max_unmap_block_desc_count(struct se_device *, u32); 105 + int se_dev_set_unmap_granularity(struct se_device *, u32); 106 + int se_dev_set_unmap_granularity_alignment(struct se_device *, u32); 107 + int se_dev_set_max_write_same_len(struct se_device *, u32); 108 + int se_dev_set_emulate_model_alias(struct se_device *, int); 109 + int se_dev_set_emulate_dpo(struct se_device *, int); 110 + int se_dev_set_emulate_fua_write(struct se_device *, int); 111 + int se_dev_set_emulate_fua_read(struct se_device *, int); 112 + int se_dev_set_emulate_write_cache(struct se_device *, int); 113 + int se_dev_set_emulate_ua_intlck_ctrl(struct se_device *, int); 114 + int se_dev_set_emulate_tas(struct se_device *, int); 115 + int se_dev_set_emulate_tpu(struct se_device *, int); 116 + int se_dev_set_emulate_tpws(struct se_device *, int); 117 + int se_dev_set_emulate_caw(struct se_device *, int); 118 + int se_dev_set_emulate_3pc(struct se_device *, int); 119 + int se_dev_set_pi_prot_type(struct se_device *, int); 120 + int se_dev_set_pi_prot_format(struct se_device *, int); 121 + int se_dev_set_enforce_pr_isids(struct se_device *, int); 122 + int se_dev_set_force_pr_aptpl(struct se_device *, int); 123 + int se_dev_set_is_nonrot(struct se_device *, int); 124 + int se_dev_set_emulate_rest_reord(struct se_device *dev, int); 125 + int se_dev_set_queue_depth(struct se_device *, u32); 126 + int se_dev_set_max_sectors(struct se_device *, u32); 127 + int se_dev_set_fabric_max_sectors(struct se_device *, u32); 128 + int se_dev_set_optimal_sectors(struct se_device *, u32); 129 + int se_dev_set_block_size(struct se_device *, u32); 109 130 110 131 #endif /* TARGET_CORE_BACKEND_H */
+120
include/target/target_core_backend_configfs.h
··· 1 + #ifndef TARGET_CORE_BACKEND_CONFIGFS_H 2 + #define TARGET_CORE_BACKEND_CONFIGFS_H 3 + 4 + #include <target/configfs_macros.h> 5 + 6 + #define DEF_TB_DEV_ATTRIB_SHOW(_backend, _name) \ 7 + static ssize_t _backend##_dev_show_attr_##_name( \ 8 + struct se_dev_attrib *da, \ 9 + char *page) \ 10 + { \ 11 + return snprintf(page, PAGE_SIZE, "%u\n", \ 12 + (u32)da->da_dev->dev_attrib._name); \ 13 + } 14 + 15 + #define DEF_TB_DEV_ATTRIB_STORE(_backend, _name) \ 16 + static ssize_t _backend##_dev_store_attr_##_name( \ 17 + struct se_dev_attrib *da, \ 18 + const char *page, \ 19 + size_t count) \ 20 + { \ 21 + unsigned long val; \ 22 + int ret; \ 23 + \ 24 + ret = kstrtoul(page, 0, &val); \ 25 + if (ret < 0) { \ 26 + pr_err("kstrtoul() failed with ret: %d\n", ret); \ 27 + return -EINVAL; \ 28 + } \ 29 + ret = se_dev_set_##_name(da->da_dev, (u32)val); \ 30 + \ 31 + return (!ret) ? count : -EINVAL; \ 32 + } 33 + 34 + #define DEF_TB_DEV_ATTRIB(_backend, _name) \ 35 + DEF_TB_DEV_ATTRIB_SHOW(_backend, _name); \ 36 + DEF_TB_DEV_ATTRIB_STORE(_backend, _name); 37 + 38 + #define DEF_TB_DEV_ATTRIB_RO(_backend, name) \ 39 + DEF_TB_DEV_ATTRIB_SHOW(_backend, name); 40 + 41 + CONFIGFS_EATTR_STRUCT(target_backend_dev_attrib, se_dev_attrib); 42 + #define TB_DEV_ATTR(_backend, _name, _mode) \ 43 + static struct target_backend_dev_attrib_attribute _backend##_dev_attrib_##_name = \ 44 + __CONFIGFS_EATTR(_name, _mode, \ 45 + _backend##_dev_show_attr_##_name, \ 46 + _backend##_dev_store_attr_##_name); 47 + 48 + #define TB_DEV_ATTR_RO(_backend, _name) \ 49 + static struct target_backend_dev_attrib_attribute _backend##_dev_attrib_##_name = \ 50 + __CONFIGFS_EATTR_RO(_name, \ 51 + _backend##_dev_show_attr_##_name); 52 + 53 + /* 54 + * Default list of target backend device attributes as defined by 55 + * struct se_dev_attrib 56 + */ 57 + 58 + #define DEF_TB_DEFAULT_ATTRIBS(_backend) \ 59 + DEF_TB_DEV_ATTRIB(_backend, emulate_model_alias); \ 60 + TB_DEV_ATTR(_backend, emulate_model_alias, S_IRUGO | S_IWUSR); \ 61 + DEF_TB_DEV_ATTRIB(_backend, emulate_dpo); \ 62 + TB_DEV_ATTR(_backend, emulate_dpo, S_IRUGO | S_IWUSR); \ 63 + DEF_TB_DEV_ATTRIB(_backend, emulate_fua_write); \ 64 + TB_DEV_ATTR(_backend, emulate_fua_write, S_IRUGO | S_IWUSR); \ 65 + DEF_TB_DEV_ATTRIB(_backend, emulate_fua_read); \ 66 + TB_DEV_ATTR(_backend, emulate_fua_read, S_IRUGO | S_IWUSR); \ 67 + DEF_TB_DEV_ATTRIB(_backend, emulate_write_cache); \ 68 + TB_DEV_ATTR(_backend, emulate_write_cache, S_IRUGO | S_IWUSR); \ 69 + DEF_TB_DEV_ATTRIB(_backend, emulate_ua_intlck_ctrl); \ 70 + TB_DEV_ATTR(_backend, emulate_ua_intlck_ctrl, S_IRUGO | S_IWUSR); \ 71 + DEF_TB_DEV_ATTRIB(_backend, emulate_tas); \ 72 + TB_DEV_ATTR(_backend, emulate_tas, S_IRUGO | S_IWUSR); \ 73 + DEF_TB_DEV_ATTRIB(_backend, emulate_tpu); \ 74 + TB_DEV_ATTR(_backend, emulate_tpu, S_IRUGO | S_IWUSR); \ 75 + DEF_TB_DEV_ATTRIB(_backend, emulate_tpws); \ 76 + TB_DEV_ATTR(_backend, emulate_tpws, S_IRUGO | S_IWUSR); \ 77 + DEF_TB_DEV_ATTRIB(_backend, emulate_caw); \ 78 + TB_DEV_ATTR(_backend, emulate_caw, S_IRUGO | S_IWUSR); \ 79 + DEF_TB_DEV_ATTRIB(_backend, emulate_3pc); \ 80 + TB_DEV_ATTR(_backend, emulate_3pc, S_IRUGO | S_IWUSR); \ 81 + DEF_TB_DEV_ATTRIB(_backend, pi_prot_type); \ 82 + TB_DEV_ATTR(_backend, pi_prot_type, S_IRUGO | S_IWUSR); \ 83 + DEF_TB_DEV_ATTRIB_RO(_backend, hw_pi_prot_type); \ 84 + TB_DEV_ATTR_RO(_backend, hw_pi_prot_type); \ 85 + DEF_TB_DEV_ATTRIB(_backend, pi_prot_format); \ 86 + TB_DEV_ATTR(_backend, pi_prot_format, S_IRUGO | S_IWUSR); \ 87 + DEF_TB_DEV_ATTRIB(_backend, enforce_pr_isids); \ 88 + TB_DEV_ATTR(_backend, enforce_pr_isids, S_IRUGO | S_IWUSR); \ 89 + DEF_TB_DEV_ATTRIB(_backend, is_nonrot); \ 90 + TB_DEV_ATTR(_backend, is_nonrot, S_IRUGO | S_IWUSR); \ 91 + DEF_TB_DEV_ATTRIB(_backend, emulate_rest_reord); \ 92 + TB_DEV_ATTR(_backend, emulate_rest_reord, S_IRUGO | S_IWUSR); \ 93 + DEF_TB_DEV_ATTRIB(_backend, force_pr_aptpl); \ 94 + TB_DEV_ATTR(_backend, force_pr_aptpl, S_IRUGO | S_IWUSR); \ 95 + DEF_TB_DEV_ATTRIB_RO(_backend, hw_block_size); \ 96 + TB_DEV_ATTR_RO(_backend, hw_block_size); \ 97 + DEF_TB_DEV_ATTRIB(_backend, block_size); \ 98 + TB_DEV_ATTR(_backend, block_size, S_IRUGO | S_IWUSR); \ 99 + DEF_TB_DEV_ATTRIB_RO(_backend, hw_max_sectors); \ 100 + TB_DEV_ATTR_RO(_backend, hw_max_sectors); \ 101 + DEF_TB_DEV_ATTRIB(_backend, fabric_max_sectors); \ 102 + TB_DEV_ATTR(_backend, fabric_max_sectors, S_IRUGO | S_IWUSR); \ 103 + DEF_TB_DEV_ATTRIB(_backend, optimal_sectors); \ 104 + TB_DEV_ATTR(_backend, optimal_sectors, S_IRUGO | S_IWUSR); \ 105 + DEF_TB_DEV_ATTRIB_RO(_backend, hw_queue_depth); \ 106 + TB_DEV_ATTR_RO(_backend, hw_queue_depth); \ 107 + DEF_TB_DEV_ATTRIB(_backend, queue_depth); \ 108 + TB_DEV_ATTR(_backend, queue_depth, S_IRUGO | S_IWUSR); \ 109 + DEF_TB_DEV_ATTRIB(_backend, max_unmap_lba_count); \ 110 + TB_DEV_ATTR(_backend, max_unmap_lba_count, S_IRUGO | S_IWUSR); \ 111 + DEF_TB_DEV_ATTRIB(_backend, max_unmap_block_desc_count); \ 112 + TB_DEV_ATTR(_backend, max_unmap_block_desc_count, S_IRUGO | S_IWUSR); \ 113 + DEF_TB_DEV_ATTRIB(_backend, unmap_granularity); \ 114 + TB_DEV_ATTR(_backend, unmap_granularity, S_IRUGO | S_IWUSR); \ 115 + DEF_TB_DEV_ATTRIB(_backend, unmap_granularity_alignment); \ 116 + TB_DEV_ATTR(_backend, unmap_granularity_alignment, S_IRUGO | S_IWUSR); \ 117 + DEF_TB_DEV_ATTRIB(_backend, max_write_same_len); \ 118 + TB_DEV_ATTR(_backend, max_write_same_len, S_IRUGO | S_IWUSR); 119 + 120 + #endif /* TARGET_CORE_BACKEND_CONFIGFS_H */
-4
include/uapi/linux/target_core_user.h
··· 6 6 #include <linux/types.h> 7 7 #include <linux/uio.h> 8 8 9 - #ifndef __packed 10 - #define __packed __attribute__((packed)) 11 - #endif 12 - 13 9 #define TCMU_VERSION "1.0" 14 10 15 11 /*