| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Copyright (C) 1999 Eric Youngdale |
|---|
| 3 | 4 | * Copyright (C) 2014 Christoph Hellwig |
|---|
| .. | .. |
|---|
| 39 | 40 | #include "scsi_priv.h" |
|---|
| 40 | 41 | #include "scsi_logging.h" |
|---|
| 41 | 42 | |
|---|
| 42 | | -static struct kmem_cache *scsi_sdb_cache; |
|---|
| 43 | +/* |
|---|
| 44 | + * Size of integrity metadata is usually small, 1 inline sg should |
|---|
| 45 | + * cover normal cases. |
|---|
| 46 | + */ |
|---|
| 47 | +#ifdef CONFIG_ARCH_NO_SG_CHAIN |
|---|
| 48 | +#define SCSI_INLINE_PROT_SG_CNT 0 |
|---|
| 49 | +#define SCSI_INLINE_SG_CNT 0 |
|---|
| 50 | +#else |
|---|
| 51 | +#define SCSI_INLINE_PROT_SG_CNT 1 |
|---|
| 52 | +#define SCSI_INLINE_SG_CNT 2 |
|---|
| 53 | +#endif |
|---|
| 54 | + |
|---|
| 43 | 55 | static struct kmem_cache *scsi_sense_cache; |
|---|
| 44 | 56 | static struct kmem_cache *scsi_sense_isadma_cache; |
|---|
| 45 | 57 | static DEFINE_MUTEX(scsi_sense_cache_mutex); |
|---|
| .. | .. |
|---|
| 141 | 153 | |
|---|
| 142 | 154 | static void scsi_mq_requeue_cmd(struct scsi_cmnd *cmd) |
|---|
| 143 | 155 | { |
|---|
| 144 | | - struct scsi_device *sdev = cmd->device; |
|---|
| 145 | | - |
|---|
| 146 | 156 | if (cmd->request->rq_flags & RQF_DONTPREP) { |
|---|
| 147 | 157 | cmd->request->rq_flags &= ~RQF_DONTPREP; |
|---|
| 148 | 158 | scsi_mq_uninit_cmd(cmd); |
|---|
| .. | .. |
|---|
| 150 | 160 | WARN_ON_ONCE(true); |
|---|
| 151 | 161 | } |
|---|
| 152 | 162 | blk_mq_requeue_request(cmd->request, true); |
|---|
| 153 | | - put_device(&sdev->sdev_gendev); |
|---|
| 154 | 163 | } |
|---|
| 155 | 164 | |
|---|
| 156 | 165 | /** |
|---|
| .. | .. |
|---|
| 168 | 177 | static void __scsi_queue_insert(struct scsi_cmnd *cmd, int reason, bool unbusy) |
|---|
| 169 | 178 | { |
|---|
| 170 | 179 | struct scsi_device *device = cmd->device; |
|---|
| 171 | | - struct request_queue *q = device->request_queue; |
|---|
| 172 | | - unsigned long flags; |
|---|
| 173 | 180 | |
|---|
| 174 | 181 | SCSI_LOG_MLQUEUE(1, scmd_printk(KERN_INFO, cmd, |
|---|
| 175 | 182 | "Inserting command %p into mlqueue\n", cmd)); |
|---|
| .. | .. |
|---|
| 181 | 188 | * active on the host/device. |
|---|
| 182 | 189 | */ |
|---|
| 183 | 190 | if (unbusy) |
|---|
| 184 | | - scsi_device_unbusy(device); |
|---|
| 191 | + scsi_device_unbusy(device, cmd); |
|---|
| 185 | 192 | |
|---|
| 186 | 193 | /* |
|---|
| 187 | 194 | * Requeue this command. It will go before all other commands |
|---|
| .. | .. |
|---|
| 190 | 197 | * before blk_cleanup_queue() finishes. |
|---|
| 191 | 198 | */ |
|---|
| 192 | 199 | cmd->result = 0; |
|---|
| 193 | | - if (q->mq_ops) { |
|---|
| 194 | | - /* |
|---|
| 195 | | - * Before a SCSI command is dispatched, |
|---|
| 196 | | - * get_device(&sdev->sdev_gendev) is called and the host, |
|---|
| 197 | | - * target and device busy counters are increased. Since |
|---|
| 198 | | - * requeuing a request causes these actions to be repeated and |
|---|
| 199 | | - * since scsi_device_unbusy() has already been called, |
|---|
| 200 | | - * put_device(&device->sdev_gendev) must still be called. Call |
|---|
| 201 | | - * put_device() after blk_mq_requeue_request() to avoid that |
|---|
| 202 | | - * removal of the SCSI device can start before requeueing has |
|---|
| 203 | | - * happened. |
|---|
| 204 | | - */ |
|---|
| 205 | | - blk_mq_requeue_request(cmd->request, true); |
|---|
| 206 | | - put_device(&device->sdev_gendev); |
|---|
| 207 | | - return; |
|---|
| 208 | | - } |
|---|
| 209 | | - spin_lock_irqsave(q->queue_lock, flags); |
|---|
| 210 | | - blk_requeue_request(q, cmd->request); |
|---|
| 211 | | - kblockd_schedule_work(&device->requeue_work); |
|---|
| 212 | | - spin_unlock_irqrestore(q->queue_lock, flags); |
|---|
| 200 | + |
|---|
| 201 | + blk_mq_requeue_request(cmd->request, true); |
|---|
| 213 | 202 | } |
|---|
| 214 | 203 | |
|---|
| 215 | | -/* |
|---|
| 216 | | - * Function: scsi_queue_insert() |
|---|
| 204 | +/** |
|---|
| 205 | + * scsi_queue_insert - Reinsert a command in the queue. |
|---|
| 206 | + * @cmd: command that we are adding to queue. |
|---|
| 207 | + * @reason: why we are inserting command to queue. |
|---|
| 217 | 208 | * |
|---|
| 218 | | - * Purpose: Insert a command in the midlevel queue. |
|---|
| 209 | + * We do this for one of two cases. Either the host is busy and it cannot accept |
|---|
| 210 | + * any more commands for the time being, or the device returned QUEUE_FULL and |
|---|
| 211 | + * can accept no more commands. |
|---|
| 219 | 212 | * |
|---|
| 220 | | - * Arguments: cmd - command that we are adding to queue. |
|---|
| 221 | | - * reason - why we are inserting command to queue. |
|---|
| 222 | | - * |
|---|
| 223 | | - * Lock status: Assumed that lock is not held upon entry. |
|---|
| 224 | | - * |
|---|
| 225 | | - * Returns: Nothing. |
|---|
| 226 | | - * |
|---|
| 227 | | - * Notes: We do this for one of two cases. Either the host is busy |
|---|
| 228 | | - * and it cannot accept any more commands for the time being, |
|---|
| 229 | | - * or the device returned QUEUE_FULL and can accept no more |
|---|
| 230 | | - * commands. |
|---|
| 231 | | - * Notes: This could be called either from an interrupt context or a |
|---|
| 232 | | - * normal process context. |
|---|
| 213 | + * Context: This could be called either from an interrupt context or a normal |
|---|
| 214 | + * process context. |
|---|
| 233 | 215 | */ |
|---|
| 234 | 216 | void scsi_queue_insert(struct scsi_cmnd *cmd, int reason) |
|---|
| 235 | 217 | { |
|---|
| .. | .. |
|---|
| 267 | 249 | |
|---|
| 268 | 250 | req = blk_get_request(sdev->request_queue, |
|---|
| 269 | 251 | data_direction == DMA_TO_DEVICE ? |
|---|
| 270 | | - REQ_OP_SCSI_OUT : REQ_OP_SCSI_IN, BLK_MQ_REQ_PREEMPT); |
|---|
| 252 | + REQ_OP_SCSI_OUT : REQ_OP_SCSI_IN, |
|---|
| 253 | + rq_flags & RQF_PM ? BLK_MQ_REQ_PM : 0); |
|---|
| 271 | 254 | if (IS_ERR(req)) |
|---|
| 272 | 255 | return ret; |
|---|
| 273 | 256 | rq = scsi_req(req); |
|---|
| .. | .. |
|---|
| 279 | 262 | rq->cmd_len = COMMAND_SIZE(cmd[0]); |
|---|
| 280 | 263 | memcpy(rq->cmd, cmd, rq->cmd_len); |
|---|
| 281 | 264 | rq->retries = retries; |
|---|
| 282 | | - if (likely(!sdev->timeout_override)) |
|---|
| 283 | | - req->timeout = timeout; |
|---|
| 284 | | - else |
|---|
| 285 | | - req->timeout = sdev->timeout_override; |
|---|
| 286 | | - |
|---|
| 265 | + req->timeout = timeout; |
|---|
| 287 | 266 | req->cmd_flags |= flags; |
|---|
| 288 | 267 | req->rq_flags |= rq_flags | RQF_QUIET; |
|---|
| 289 | 268 | |
|---|
| .. | .. |
|---|
| 316 | 295 | EXPORT_SYMBOL(__scsi_execute); |
|---|
| 317 | 296 | |
|---|
| 318 | 297 | /* |
|---|
| 319 | | - * Function: scsi_init_cmd_errh() |
|---|
| 320 | | - * |
|---|
| 321 | | - * Purpose: Initialize cmd fields related to error handling. |
|---|
| 322 | | - * |
|---|
| 323 | | - * Arguments: cmd - command that is ready to be queued. |
|---|
| 324 | | - * |
|---|
| 325 | | - * Notes: This function has the job of initializing a number of |
|---|
| 326 | | - * fields related to error handling. Typically this will |
|---|
| 327 | | - * be called once for each command, as required. |
|---|
| 328 | | - */ |
|---|
| 329 | | -static void scsi_init_cmd_errh(struct scsi_cmnd *cmd) |
|---|
| 330 | | -{ |
|---|
| 331 | | - cmd->serial_number = 0; |
|---|
| 332 | | - scsi_set_resid(cmd, 0); |
|---|
| 333 | | - memset(cmd->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE); |
|---|
| 334 | | - if (cmd->cmd_len == 0) |
|---|
| 335 | | - cmd->cmd_len = scsi_command_size(cmd->cmnd); |
|---|
| 336 | | -} |
|---|
| 337 | | - |
|---|
| 338 | | -/* |
|---|
| 339 | | - * Decrement the host_busy counter and wake up the error handler if necessary. |
|---|
| 340 | | - * Avoid as follows that the error handler is not woken up if shost->host_busy |
|---|
| 341 | | - * == shost->host_failed: use call_rcu() in scsi_eh_scmd_add() in combination |
|---|
| 342 | | - * with an RCU read lock in this function to ensure that this function in its |
|---|
| 343 | | - * entirety either finishes before scsi_eh_scmd_add() increases the |
|---|
| 298 | + * Wake up the error handler if necessary. Avoid as follows that the error |
|---|
| 299 | + * handler is not woken up if host in-flight requests number == |
|---|
| 300 | + * shost->host_failed: use call_rcu() in scsi_eh_scmd_add() in combination |
|---|
| 301 | + * with an RCU read lock in this function to ensure that this function in |
|---|
| 302 | + * its entirety either finishes before scsi_eh_scmd_add() increases the |
|---|
| 344 | 303 | * host_failed counter or that it notices the shost state change made by |
|---|
| 345 | 304 | * scsi_eh_scmd_add(). |
|---|
| 346 | 305 | */ |
|---|
| 347 | | -static void scsi_dec_host_busy(struct Scsi_Host *shost) |
|---|
| 306 | +static void scsi_dec_host_busy(struct Scsi_Host *shost, struct scsi_cmnd *cmd) |
|---|
| 348 | 307 | { |
|---|
| 349 | 308 | unsigned long flags; |
|---|
| 350 | 309 | |
|---|
| 351 | 310 | rcu_read_lock(); |
|---|
| 352 | | - atomic_dec(&shost->host_busy); |
|---|
| 311 | + __clear_bit(SCMD_STATE_INFLIGHT, &cmd->state); |
|---|
| 353 | 312 | if (unlikely(scsi_host_in_recovery(shost))) { |
|---|
| 354 | 313 | spin_lock_irqsave(shost->host_lock, flags); |
|---|
| 355 | 314 | if (shost->host_failed || shost->host_eh_scheduled) |
|---|
| .. | .. |
|---|
| 359 | 318 | rcu_read_unlock(); |
|---|
| 360 | 319 | } |
|---|
| 361 | 320 | |
|---|
| 362 | | -void scsi_device_unbusy(struct scsi_device *sdev) |
|---|
| 321 | +void scsi_device_unbusy(struct scsi_device *sdev, struct scsi_cmnd *cmd) |
|---|
| 363 | 322 | { |
|---|
| 364 | 323 | struct Scsi_Host *shost = sdev->host; |
|---|
| 365 | 324 | struct scsi_target *starget = scsi_target(sdev); |
|---|
| 366 | 325 | |
|---|
| 367 | | - scsi_dec_host_busy(shost); |
|---|
| 326 | + scsi_dec_host_busy(shost, cmd); |
|---|
| 368 | 327 | |
|---|
| 369 | 328 | if (starget->can_queue > 0) |
|---|
| 370 | 329 | atomic_dec(&starget->target_busy); |
|---|
| .. | .. |
|---|
| 374 | 333 | |
|---|
| 375 | 334 | static void scsi_kick_queue(struct request_queue *q) |
|---|
| 376 | 335 | { |
|---|
| 377 | | - if (q->mq_ops) |
|---|
| 378 | | - blk_mq_run_hw_queues(q, false); |
|---|
| 379 | | - else |
|---|
| 380 | | - blk_run_queue(q); |
|---|
| 336 | + blk_mq_run_hw_queues(q, false); |
|---|
| 381 | 337 | } |
|---|
| 382 | 338 | |
|---|
| 383 | 339 | /* |
|---|
| .. | .. |
|---|
| 419 | 375 | spin_unlock_irqrestore(shost->host_lock, flags); |
|---|
| 420 | 376 | scsi_kick_queue(sdev->request_queue); |
|---|
| 421 | 377 | spin_lock_irqsave(shost->host_lock, flags); |
|---|
| 422 | | - |
|---|
| 378 | + |
|---|
| 423 | 379 | scsi_device_put(sdev); |
|---|
| 424 | 380 | } |
|---|
| 425 | 381 | out: |
|---|
| .. | .. |
|---|
| 448 | 404 | |
|---|
| 449 | 405 | static inline bool scsi_host_is_busy(struct Scsi_Host *shost) |
|---|
| 450 | 406 | { |
|---|
| 451 | | - if (shost->can_queue > 0 && |
|---|
| 452 | | - atomic_read(&shost->host_busy) >= shost->can_queue) |
|---|
| 453 | | - return true; |
|---|
| 454 | 407 | if (atomic_read(&shost->host_blocked) > 0) |
|---|
| 455 | 408 | return true; |
|---|
| 456 | 409 | if (shost->host_self_blocked) |
|---|
| .. | .. |
|---|
| 517 | 470 | spin_unlock_irqrestore(shost->host_lock, flags); |
|---|
| 518 | 471 | } |
|---|
| 519 | 472 | |
|---|
| 520 | | -/* |
|---|
| 521 | | - * Function: scsi_run_queue() |
|---|
| 473 | +/** |
|---|
| 474 | + * scsi_run_queue - Select a proper request queue to serve next. |
|---|
| 475 | + * @q: last request's queue |
|---|
| 522 | 476 | * |
|---|
| 523 | | - * Purpose: Select a proper request queue to serve next |
|---|
| 524 | | - * |
|---|
| 525 | | - * Arguments: q - last request's queue |
|---|
| 526 | | - * |
|---|
| 527 | | - * Returns: Nothing |
|---|
| 528 | | - * |
|---|
| 529 | | - * Notes: The previous command was completely finished, start |
|---|
| 530 | | - * a new one if possible. |
|---|
| 477 | + * The previous command was completely finished, start a new one if possible. |
|---|
| 531 | 478 | */ |
|---|
| 532 | 479 | static void scsi_run_queue(struct request_queue *q) |
|---|
| 533 | 480 | { |
|---|
| .. | .. |
|---|
| 538 | 485 | if (!list_empty(&sdev->host->starved_list)) |
|---|
| 539 | 486 | scsi_starved_list_run(sdev->host); |
|---|
| 540 | 487 | |
|---|
| 541 | | - if (q->mq_ops) |
|---|
| 542 | | - blk_mq_run_hw_queues(q, false); |
|---|
| 543 | | - else |
|---|
| 544 | | - blk_run_queue(q); |
|---|
| 488 | + blk_mq_run_hw_queues(q, false); |
|---|
| 545 | 489 | } |
|---|
| 546 | 490 | |
|---|
| 547 | 491 | void scsi_requeue_run_queue(struct work_struct *work) |
|---|
| .. | .. |
|---|
| 552 | 496 | sdev = container_of(work, struct scsi_device, requeue_work); |
|---|
| 553 | 497 | q = sdev->request_queue; |
|---|
| 554 | 498 | scsi_run_queue(q); |
|---|
| 555 | | -} |
|---|
| 556 | | - |
|---|
| 557 | | -/* |
|---|
| 558 | | - * Function: scsi_requeue_command() |
|---|
| 559 | | - * |
|---|
| 560 | | - * Purpose: Handle post-processing of completed commands. |
|---|
| 561 | | - * |
|---|
| 562 | | - * Arguments: q - queue to operate on |
|---|
| 563 | | - * cmd - command that may need to be requeued. |
|---|
| 564 | | - * |
|---|
| 565 | | - * Returns: Nothing |
|---|
| 566 | | - * |
|---|
| 567 | | - * Notes: After command completion, there may be blocks left |
|---|
| 568 | | - * over which weren't finished by the previous command |
|---|
| 569 | | - * this can be for a number of reasons - the main one is |
|---|
| 570 | | - * I/O errors in the middle of the request, in which case |
|---|
| 571 | | - * we need to request the blocks that come after the bad |
|---|
| 572 | | - * sector. |
|---|
| 573 | | - * Notes: Upon return, cmd is a stale pointer. |
|---|
| 574 | | - */ |
|---|
| 575 | | -static void scsi_requeue_command(struct request_queue *q, struct scsi_cmnd *cmd) |
|---|
| 576 | | -{ |
|---|
| 577 | | - struct scsi_device *sdev = cmd->device; |
|---|
| 578 | | - struct request *req = cmd->request; |
|---|
| 579 | | - unsigned long flags; |
|---|
| 580 | | - |
|---|
| 581 | | - spin_lock_irqsave(q->queue_lock, flags); |
|---|
| 582 | | - blk_unprep_request(req); |
|---|
| 583 | | - req->special = NULL; |
|---|
| 584 | | - scsi_put_command(cmd); |
|---|
| 585 | | - blk_requeue_request(q, req); |
|---|
| 586 | | - spin_unlock_irqrestore(q->queue_lock, flags); |
|---|
| 587 | | - |
|---|
| 588 | | - scsi_run_queue(q); |
|---|
| 589 | | - |
|---|
| 590 | | - put_device(&sdev->sdev_gendev); |
|---|
| 591 | 499 | } |
|---|
| 592 | 500 | |
|---|
| 593 | 501 | void scsi_run_host_queues(struct Scsi_Host *shost) |
|---|
| .. | .. |
|---|
| 608 | 516 | } |
|---|
| 609 | 517 | } |
|---|
| 610 | 518 | |
|---|
| 611 | | -static void scsi_mq_free_sgtables(struct scsi_cmnd *cmd) |
|---|
| 519 | +void scsi_free_sgtables(struct scsi_cmnd *cmd) |
|---|
| 612 | 520 | { |
|---|
| 613 | | - struct scsi_data_buffer *sdb; |
|---|
| 614 | | - |
|---|
| 615 | 521 | if (cmd->sdb.table.nents) |
|---|
| 616 | | - sg_free_table_chained(&cmd->sdb.table, true); |
|---|
| 617 | | - if (cmd->request->next_rq) { |
|---|
| 618 | | - sdb = cmd->request->next_rq->special; |
|---|
| 619 | | - if (sdb) |
|---|
| 620 | | - sg_free_table_chained(&sdb->table, true); |
|---|
| 621 | | - } |
|---|
| 522 | + sg_free_table_chained(&cmd->sdb.table, |
|---|
| 523 | + SCSI_INLINE_SG_CNT); |
|---|
| 622 | 524 | if (scsi_prot_sg_count(cmd)) |
|---|
| 623 | | - sg_free_table_chained(&cmd->prot_sdb->table, true); |
|---|
| 525 | + sg_free_table_chained(&cmd->prot_sdb->table, |
|---|
| 526 | + SCSI_INLINE_PROT_SG_CNT); |
|---|
| 624 | 527 | } |
|---|
| 528 | +EXPORT_SYMBOL_GPL(scsi_free_sgtables); |
|---|
| 625 | 529 | |
|---|
| 626 | 530 | static void scsi_mq_uninit_cmd(struct scsi_cmnd *cmd) |
|---|
| 627 | 531 | { |
|---|
| 628 | | - scsi_mq_free_sgtables(cmd); |
|---|
| 532 | + scsi_free_sgtables(cmd); |
|---|
| 629 | 533 | scsi_uninit_cmd(cmd); |
|---|
| 630 | | - scsi_del_cmd_from_list(cmd); |
|---|
| 631 | 534 | } |
|---|
| 632 | 535 | |
|---|
| 633 | | -/* |
|---|
| 634 | | - * Function: scsi_release_buffers() |
|---|
| 635 | | - * |
|---|
| 636 | | - * Purpose: Free resources allocate for a scsi_command. |
|---|
| 637 | | - * |
|---|
| 638 | | - * Arguments: cmd - command that we are bailing. |
|---|
| 639 | | - * |
|---|
| 640 | | - * Lock status: Assumed that no lock is held upon entry. |
|---|
| 641 | | - * |
|---|
| 642 | | - * Returns: Nothing |
|---|
| 643 | | - * |
|---|
| 644 | | - * Notes: In the event that an upper level driver rejects a |
|---|
| 645 | | - * command, we must release resources allocated during |
|---|
| 646 | | - * the __init_io() function. Primarily this would involve |
|---|
| 647 | | - * the scatter-gather table. |
|---|
| 648 | | - */ |
|---|
| 649 | | -static void scsi_release_buffers(struct scsi_cmnd *cmd) |
|---|
| 536 | +static void scsi_run_queue_async(struct scsi_device *sdev) |
|---|
| 650 | 537 | { |
|---|
| 651 | | - if (cmd->sdb.table.nents) |
|---|
| 652 | | - sg_free_table_chained(&cmd->sdb.table, false); |
|---|
| 538 | + if (scsi_target(sdev)->single_lun || |
|---|
| 539 | + !list_empty(&sdev->host->starved_list)) { |
|---|
| 540 | + kblockd_schedule_work(&sdev->requeue_work); |
|---|
| 541 | + } else { |
|---|
| 542 | + /* |
|---|
| 543 | + * smp_mb() present in sbitmap_queue_clear() or implied in |
|---|
| 544 | + * .end_io is for ordering writing .device_busy in |
|---|
| 545 | + * scsi_device_unbusy() and reading sdev->restarts. |
|---|
| 546 | + */ |
|---|
| 547 | + int old = atomic_read(&sdev->restarts); |
|---|
| 653 | 548 | |
|---|
| 654 | | - memset(&cmd->sdb, 0, sizeof(cmd->sdb)); |
|---|
| 655 | | - |
|---|
| 656 | | - if (scsi_prot_sg_count(cmd)) |
|---|
| 657 | | - sg_free_table_chained(&cmd->prot_sdb->table, false); |
|---|
| 658 | | -} |
|---|
| 659 | | - |
|---|
| 660 | | -static void scsi_release_bidi_buffers(struct scsi_cmnd *cmd) |
|---|
| 661 | | -{ |
|---|
| 662 | | - struct scsi_data_buffer *bidi_sdb = cmd->request->next_rq->special; |
|---|
| 663 | | - |
|---|
| 664 | | - sg_free_table_chained(&bidi_sdb->table, false); |
|---|
| 665 | | - kmem_cache_free(scsi_sdb_cache, bidi_sdb); |
|---|
| 666 | | - cmd->request->next_rq->special = NULL; |
|---|
| 549 | + /* |
|---|
| 550 | + * ->restarts has to be kept as non-zero if new budget |
|---|
| 551 | + * contention occurs. |
|---|
| 552 | + * |
|---|
| 553 | + * No need to run queue when either another re-run |
|---|
| 554 | + * queue wins in updating ->restarts or a new budget |
|---|
| 555 | + * contention occurs. |
|---|
| 556 | + */ |
|---|
| 557 | + if (old && atomic_cmpxchg(&sdev->restarts, old, 0) == old) |
|---|
| 558 | + blk_mq_run_hw_queues(sdev->request_queue, true); |
|---|
| 559 | + } |
|---|
| 667 | 560 | } |
|---|
| 668 | 561 | |
|---|
| 669 | 562 | /* Returns false when no more bytes to process, true if there are more */ |
|---|
| 670 | 563 | static bool scsi_end_request(struct request *req, blk_status_t error, |
|---|
| 671 | | - unsigned int bytes, unsigned int bidi_bytes) |
|---|
| 564 | + unsigned int bytes) |
|---|
| 672 | 565 | { |
|---|
| 673 | 566 | struct scsi_cmnd *cmd = blk_mq_rq_to_pdu(req); |
|---|
| 674 | 567 | struct scsi_device *sdev = cmd->device; |
|---|
| .. | .. |
|---|
| 677 | 570 | if (blk_update_request(req, error, bytes)) |
|---|
| 678 | 571 | return true; |
|---|
| 679 | 572 | |
|---|
| 680 | | - /* Bidi request must be completed as a whole */ |
|---|
| 681 | | - if (unlikely(bidi_bytes) && |
|---|
| 682 | | - blk_update_request(req->next_rq, error, bidi_bytes)) |
|---|
| 683 | | - return true; |
|---|
| 684 | | - |
|---|
| 685 | 573 | if (blk_queue_add_random(q)) |
|---|
| 686 | 574 | add_disk_randomness(req->rq_disk); |
|---|
| 687 | 575 | |
|---|
| 688 | 576 | if (!blk_rq_is_scsi(req)) { |
|---|
| 689 | 577 | WARN_ON_ONCE(!(cmd->flags & SCMD_INITIALIZED)); |
|---|
| 690 | 578 | cmd->flags &= ~SCMD_INITIALIZED; |
|---|
| 691 | | - destroy_rcu_head(&cmd->rcu); |
|---|
| 692 | 579 | } |
|---|
| 693 | 580 | |
|---|
| 694 | | - if (req->mq_ctx) { |
|---|
| 695 | | - /* |
|---|
| 696 | | - * In the MQ case the command gets freed by __blk_mq_end_request, |
|---|
| 697 | | - * so we have to do all cleanup that depends on it earlier. |
|---|
| 698 | | - * |
|---|
| 699 | | - * We also can't kick the queues from irq context, so we |
|---|
| 700 | | - * will have to defer it to a workqueue. |
|---|
| 701 | | - */ |
|---|
| 702 | | - scsi_mq_uninit_cmd(cmd); |
|---|
| 581 | + /* |
|---|
| 582 | + * Calling rcu_barrier() is not necessary here because the |
|---|
| 583 | + * SCSI error handler guarantees that the function called by |
|---|
| 584 | + * call_rcu() has been called before scsi_end_request() is |
|---|
| 585 | + * called. |
|---|
| 586 | + */ |
|---|
| 587 | + destroy_rcu_head(&cmd->rcu); |
|---|
| 703 | 588 | |
|---|
| 704 | | - /* |
|---|
| 705 | | - * queue is still alive, so grab the ref for preventing it |
|---|
| 706 | | - * from being cleaned up during running queue. |
|---|
| 707 | | - */ |
|---|
| 708 | | - percpu_ref_get(&q->q_usage_counter); |
|---|
| 589 | + /* |
|---|
| 590 | + * In the MQ case the command gets freed by __blk_mq_end_request, |
|---|
| 591 | + * so we have to do all cleanup that depends on it earlier. |
|---|
| 592 | + * |
|---|
| 593 | + * We also can't kick the queues from irq context, so we |
|---|
| 594 | + * will have to defer it to a workqueue. |
|---|
| 595 | + */ |
|---|
| 596 | + scsi_mq_uninit_cmd(cmd); |
|---|
| 709 | 597 | |
|---|
| 710 | | - __blk_mq_end_request(req, error); |
|---|
| 598 | + /* |
|---|
| 599 | + * queue is still alive, so grab the ref for preventing it |
|---|
| 600 | + * from being cleaned up during running queue. |
|---|
| 601 | + */ |
|---|
| 602 | + percpu_ref_get(&q->q_usage_counter); |
|---|
| 711 | 603 | |
|---|
| 712 | | - if (scsi_target(sdev)->single_lun || |
|---|
| 713 | | - !list_empty(&sdev->host->starved_list)) |
|---|
| 714 | | - kblockd_schedule_work(&sdev->requeue_work); |
|---|
| 715 | | - else |
|---|
| 716 | | - blk_mq_run_hw_queues(q, true); |
|---|
| 604 | + __blk_mq_end_request(req, error); |
|---|
| 717 | 605 | |
|---|
| 718 | | - percpu_ref_put(&q->q_usage_counter); |
|---|
| 719 | | - } else { |
|---|
| 720 | | - unsigned long flags; |
|---|
| 606 | + scsi_run_queue_async(sdev); |
|---|
| 721 | 607 | |
|---|
| 722 | | - if (bidi_bytes) |
|---|
| 723 | | - scsi_release_bidi_buffers(cmd); |
|---|
| 724 | | - scsi_release_buffers(cmd); |
|---|
| 725 | | - scsi_put_command(cmd); |
|---|
| 726 | | - |
|---|
| 727 | | - spin_lock_irqsave(q->queue_lock, flags); |
|---|
| 728 | | - blk_finish_request(req, error); |
|---|
| 729 | | - spin_unlock_irqrestore(q->queue_lock, flags); |
|---|
| 730 | | - |
|---|
| 731 | | - scsi_run_queue(q); |
|---|
| 732 | | - } |
|---|
| 733 | | - |
|---|
| 734 | | - put_device(&sdev->sdev_gendev); |
|---|
| 608 | + percpu_ref_put(&q->q_usage_counter); |
|---|
| 735 | 609 | return false; |
|---|
| 736 | 610 | } |
|---|
| 737 | 611 | |
|---|
| .. | .. |
|---|
| 779 | 653 | struct request_queue *q) |
|---|
| 780 | 654 | { |
|---|
| 781 | 655 | /* A new command will be prepared and issued. */ |
|---|
| 782 | | - if (q->mq_ops) { |
|---|
| 783 | | - scsi_mq_requeue_cmd(cmd); |
|---|
| 784 | | - } else { |
|---|
| 785 | | - /* Unprep request and put it back at head of the queue. */ |
|---|
| 786 | | - scsi_release_buffers(cmd); |
|---|
| 787 | | - scsi_requeue_command(q, cmd); |
|---|
| 656 | + scsi_mq_requeue_cmd(cmd); |
|---|
| 657 | +} |
|---|
| 658 | + |
|---|
| 659 | +static bool scsi_cmd_runtime_exceeced(struct scsi_cmnd *cmd) |
|---|
| 660 | +{ |
|---|
| 661 | + struct request *req = cmd->request; |
|---|
| 662 | + unsigned long wait_for; |
|---|
| 663 | + |
|---|
| 664 | + if (cmd->allowed == SCSI_CMD_RETRIES_NO_LIMIT) |
|---|
| 665 | + return false; |
|---|
| 666 | + |
|---|
| 667 | + wait_for = (cmd->allowed + 1) * req->timeout; |
|---|
| 668 | + if (time_before(cmd->jiffies_at_alloc + wait_for, jiffies)) { |
|---|
| 669 | + scmd_printk(KERN_ERR, cmd, "timing out command, waited %lus\n", |
|---|
| 670 | + wait_for/HZ); |
|---|
| 671 | + return true; |
|---|
| 788 | 672 | } |
|---|
| 673 | + return false; |
|---|
| 789 | 674 | } |
|---|
| 790 | 675 | |
|---|
| 791 | 676 | /* Helper for scsi_io_completion() when special action required. */ |
|---|
| .. | .. |
|---|
| 796 | 681 | int level = 0; |
|---|
| 797 | 682 | enum {ACTION_FAIL, ACTION_REPREP, ACTION_RETRY, |
|---|
| 798 | 683 | ACTION_DELAYED_RETRY} action; |
|---|
| 799 | | - unsigned long wait_for = (cmd->allowed + 1) * req->timeout; |
|---|
| 800 | 684 | struct scsi_sense_hdr sshdr; |
|---|
| 801 | 685 | bool sense_valid; |
|---|
| 802 | 686 | bool sense_current = true; /* false implies "deferred sense" */ |
|---|
| .. | .. |
|---|
| 895 | 779 | /* See SSC3rXX or current. */ |
|---|
| 896 | 780 | action = ACTION_FAIL; |
|---|
| 897 | 781 | break; |
|---|
| 782 | + case DATA_PROTECT: |
|---|
| 783 | + action = ACTION_FAIL; |
|---|
| 784 | + if ((sshdr.asc == 0x0C && sshdr.ascq == 0x12) || |
|---|
| 785 | + (sshdr.asc == 0x55 && |
|---|
| 786 | + (sshdr.ascq == 0x0E || sshdr.ascq == 0x0F))) { |
|---|
| 787 | + /* Insufficient zone resources */ |
|---|
| 788 | + blk_stat = BLK_STS_ZONE_OPEN_RESOURCE; |
|---|
| 789 | + } |
|---|
| 790 | + break; |
|---|
| 898 | 791 | default: |
|---|
| 899 | 792 | action = ACTION_FAIL; |
|---|
| 900 | 793 | break; |
|---|
| .. | .. |
|---|
| 902 | 795 | } else |
|---|
| 903 | 796 | action = ACTION_FAIL; |
|---|
| 904 | 797 | |
|---|
| 905 | | - if (action != ACTION_FAIL && |
|---|
| 906 | | - time_before(cmd->jiffies_at_alloc + wait_for, jiffies)) |
|---|
| 798 | + if (action != ACTION_FAIL && scsi_cmd_runtime_exceeced(cmd)) |
|---|
| 907 | 799 | action = ACTION_FAIL; |
|---|
| 908 | 800 | |
|---|
| 909 | 801 | switch (action) { |
|---|
| .. | .. |
|---|
| 930 | 822 | scsi_print_command(cmd); |
|---|
| 931 | 823 | } |
|---|
| 932 | 824 | } |
|---|
| 933 | | - if (!scsi_end_request(req, blk_stat, blk_rq_err_bytes(req), 0)) |
|---|
| 825 | + if (!scsi_end_request(req, blk_stat, blk_rq_err_bytes(req))) |
|---|
| 934 | 826 | return; |
|---|
| 935 | | - /*FALLTHRU*/ |
|---|
| 827 | + fallthrough; |
|---|
| 936 | 828 | case ACTION_REPREP: |
|---|
| 937 | 829 | scsi_io_completion_reprep(cmd, q); |
|---|
| 938 | 830 | break; |
|---|
| .. | .. |
|---|
| 1020 | 912 | return result; |
|---|
| 1021 | 913 | } |
|---|
| 1022 | 914 | |
|---|
| 1023 | | -/* |
|---|
| 1024 | | - * Function: scsi_io_completion() |
|---|
| 915 | +/** |
|---|
| 916 | + * scsi_io_completion - Completion processing for SCSI commands. |
|---|
| 917 | + * @cmd: command that is finished. |
|---|
| 918 | + * @good_bytes: number of processed bytes. |
|---|
| 1025 | 919 | * |
|---|
| 1026 | | - * Purpose: Completion processing for block device I/O requests. |
|---|
| 920 | + * We will finish off the specified number of sectors. If we are done, the |
|---|
| 921 | + * command block will be released and the queue function will be goosed. If we |
|---|
| 922 | + * are not done then we have to figure out what to do next: |
|---|
| 1027 | 923 | * |
|---|
| 1028 | | - * Arguments: cmd - command that is finished. |
|---|
| 924 | + * a) We can call scsi_io_completion_reprep(). The request will be |
|---|
| 925 | + * unprepared and put back on the queue. Then a new command will |
|---|
| 926 | + * be created for it. This should be used if we made forward |
|---|
| 927 | + * progress, or if we want to switch from READ(10) to READ(6) for |
|---|
| 928 | + * example. |
|---|
| 1029 | 929 | * |
|---|
| 1030 | | - * Lock status: Assumed that no lock is held upon entry. |
|---|
| 930 | + * b) We can call scsi_io_completion_action(). The request will be |
|---|
| 931 | + * put back on the queue and retried using the same command as |
|---|
| 932 | + * before, possibly after a delay. |
|---|
| 1031 | 933 | * |
|---|
| 1032 | | - * Returns: Nothing |
|---|
| 1033 | | - * |
|---|
| 1034 | | - * Notes: We will finish off the specified number of sectors. If we |
|---|
| 1035 | | - * are done, the command block will be released and the queue |
|---|
| 1036 | | - * function will be goosed. If we are not done then we have to |
|---|
| 1037 | | - * figure out what to do next: |
|---|
| 1038 | | - * |
|---|
| 1039 | | - * a) We can call scsi_requeue_command(). The request |
|---|
| 1040 | | - * will be unprepared and put back on the queue. Then |
|---|
| 1041 | | - * a new command will be created for it. This should |
|---|
| 1042 | | - * be used if we made forward progress, or if we want |
|---|
| 1043 | | - * to switch from READ(10) to READ(6) for example. |
|---|
| 1044 | | - * |
|---|
| 1045 | | - * b) We can call __scsi_queue_insert(). The request will |
|---|
| 1046 | | - * be put back on the queue and retried using the same |
|---|
| 1047 | | - * command as before, possibly after a delay. |
|---|
| 1048 | | - * |
|---|
| 1049 | | - * c) We can call scsi_end_request() with blk_stat other than |
|---|
| 1050 | | - * BLK_STS_OK, to fail the remainder of the request. |
|---|
| 934 | + * c) We can call scsi_end_request() with blk_stat other than |
|---|
| 935 | + * BLK_STS_OK, to fail the remainder of the request. |
|---|
| 1051 | 936 | */ |
|---|
| 1052 | 937 | void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes) |
|---|
| 1053 | 938 | { |
|---|
| .. | .. |
|---|
| 1064 | 949 | * scsi_result_to_blk_status may have reset the host_byte |
|---|
| 1065 | 950 | */ |
|---|
| 1066 | 951 | scsi_req(req)->result = cmd->result; |
|---|
| 1067 | | - scsi_req(req)->resid_len = scsi_get_resid(cmd); |
|---|
| 1068 | | - |
|---|
| 1069 | | - if (unlikely(scsi_bidi_cmnd(cmd))) { |
|---|
| 1070 | | - /* |
|---|
| 1071 | | - * Bidi commands Must be complete as a whole, |
|---|
| 1072 | | - * both sides at once. |
|---|
| 1073 | | - */ |
|---|
| 1074 | | - scsi_req(req->next_rq)->resid_len = scsi_in(cmd)->resid; |
|---|
| 1075 | | - if (scsi_end_request(req, BLK_STS_OK, blk_rq_bytes(req), |
|---|
| 1076 | | - blk_rq_bytes(req->next_rq))) |
|---|
| 1077 | | - WARN_ONCE(true, |
|---|
| 1078 | | - "Bidi command with remaining bytes"); |
|---|
| 1079 | | - return; |
|---|
| 1080 | | - } |
|---|
| 1081 | | - } |
|---|
| 1082 | | - |
|---|
| 1083 | | - /* no bidi support yet, other than in pass-through */ |
|---|
| 1084 | | - if (unlikely(blk_bidi_rq(req))) { |
|---|
| 1085 | | - WARN_ONCE(true, "Only support bidi command in passthrough"); |
|---|
| 1086 | | - scmd_printk(KERN_ERR, cmd, "Killing bidi command\n"); |
|---|
| 1087 | | - if (scsi_end_request(req, BLK_STS_IOERR, blk_rq_bytes(req), |
|---|
| 1088 | | - blk_rq_bytes(req->next_rq))) |
|---|
| 1089 | | - WARN_ONCE(true, "Bidi command with remaining bytes"); |
|---|
| 1090 | | - return; |
|---|
| 1091 | 952 | } |
|---|
| 1092 | 953 | |
|---|
| 1093 | 954 | /* |
|---|
| .. | .. |
|---|
| 1099 | 960 | blk_rq_sectors(req), good_bytes)); |
|---|
| 1100 | 961 | |
|---|
| 1101 | 962 | /* |
|---|
| 1102 | | - * Next deal with any sectors which we were able to correctly |
|---|
| 1103 | | - * handle. Failed, zero length commands always need to drop down |
|---|
| 963 | + * Failed, zero length commands always need to drop down |
|---|
| 1104 | 964 | * to retry code. Fast path should return in this block. |
|---|
| 1105 | 965 | */ |
|---|
| 1106 | 966 | if (likely(blk_rq_bytes(req) > 0 || blk_stat == BLK_STS_OK)) { |
|---|
| 1107 | | - if (likely(!scsi_end_request(req, blk_stat, good_bytes, 0))) |
|---|
| 967 | + if (likely(!scsi_end_request(req, blk_stat, good_bytes))) |
|---|
| 1108 | 968 | return; /* no bytes remaining */ |
|---|
| 1109 | 969 | } |
|---|
| 1110 | 970 | |
|---|
| 1111 | 971 | /* Kill remainder if no retries. */ |
|---|
| 1112 | 972 | if (unlikely(blk_stat && scsi_noretry_cmd(cmd))) { |
|---|
| 1113 | | - if (scsi_end_request(req, blk_stat, blk_rq_bytes(req), 0)) |
|---|
| 973 | + if (scsi_end_request(req, blk_stat, blk_rq_bytes(req))) |
|---|
| 1114 | 974 | WARN_ONCE(true, |
|---|
| 1115 | 975 | "Bytes remaining after failed, no-retry command"); |
|---|
| 1116 | 976 | return; |
|---|
| .. | .. |
|---|
| 1126 | 986 | scsi_io_completion_action(cmd, result); |
|---|
| 1127 | 987 | } |
|---|
| 1128 | 988 | |
|---|
| 1129 | | -static int scsi_init_sgtable(struct request *req, struct scsi_data_buffer *sdb) |
|---|
| 989 | +static inline bool scsi_cmd_needs_dma_drain(struct scsi_device *sdev, |
|---|
| 990 | + struct request *rq) |
|---|
| 1130 | 991 | { |
|---|
| 992 | + return sdev->dma_drain_len && blk_rq_is_passthrough(rq) && |
|---|
| 993 | + !op_is_write(req_op(rq)) && |
|---|
| 994 | + sdev->host->hostt->dma_need_drain(rq); |
|---|
| 995 | +} |
|---|
| 996 | + |
|---|
| 997 | +/** |
|---|
| 998 | + * scsi_alloc_sgtables - allocate S/G tables for a command |
|---|
| 999 | + * @cmd: command descriptor we wish to initialize |
|---|
| 1000 | + * |
|---|
| 1001 | + * Returns: |
|---|
| 1002 | + * * BLK_STS_OK - on success |
|---|
| 1003 | + * * BLK_STS_RESOURCE - if the failure is retryable |
|---|
| 1004 | + * * BLK_STS_IOERR - if the failure is fatal |
|---|
| 1005 | + */ |
|---|
| 1006 | +blk_status_t scsi_alloc_sgtables(struct scsi_cmnd *cmd) |
|---|
| 1007 | +{ |
|---|
| 1008 | + struct scsi_device *sdev = cmd->device; |
|---|
| 1009 | + struct request *rq = cmd->request; |
|---|
| 1010 | + unsigned short nr_segs = blk_rq_nr_phys_segments(rq); |
|---|
| 1011 | + struct scatterlist *last_sg = NULL; |
|---|
| 1012 | + blk_status_t ret; |
|---|
| 1013 | + bool need_drain = scsi_cmd_needs_dma_drain(sdev, rq); |
|---|
| 1131 | 1014 | int count; |
|---|
| 1015 | + |
|---|
| 1016 | + if (WARN_ON_ONCE(!nr_segs)) |
|---|
| 1017 | + return BLK_STS_IOERR; |
|---|
| 1018 | + |
|---|
| 1019 | + /* |
|---|
| 1020 | + * Make sure there is space for the drain. The driver must adjust |
|---|
| 1021 | + * max_hw_segments to be prepared for this. |
|---|
| 1022 | + */ |
|---|
| 1023 | + if (need_drain) |
|---|
| 1024 | + nr_segs++; |
|---|
| 1132 | 1025 | |
|---|
| 1133 | 1026 | /* |
|---|
| 1134 | 1027 | * If sg table allocation fails, requeue request later. |
|---|
| 1135 | 1028 | */ |
|---|
| 1136 | | - if (unlikely(sg_alloc_table_chained(&sdb->table, |
|---|
| 1137 | | - blk_rq_nr_phys_segments(req), sdb->table.sgl))) |
|---|
| 1138 | | - return BLKPREP_DEFER; |
|---|
| 1029 | + if (unlikely(sg_alloc_table_chained(&cmd->sdb.table, nr_segs, |
|---|
| 1030 | + cmd->sdb.table.sgl, SCSI_INLINE_SG_CNT))) |
|---|
| 1031 | + return BLK_STS_RESOURCE; |
|---|
| 1139 | 1032 | |
|---|
| 1140 | | - /* |
|---|
| 1033 | + /* |
|---|
| 1141 | 1034 | * Next, walk the list, and fill in the addresses and sizes of |
|---|
| 1142 | 1035 | * each segment. |
|---|
| 1143 | 1036 | */ |
|---|
| 1144 | | - count = blk_rq_map_sg(req->q, req, sdb->table.sgl); |
|---|
| 1145 | | - BUG_ON(count > sdb->table.nents); |
|---|
| 1146 | | - sdb->table.nents = count; |
|---|
| 1147 | | - sdb->length = blk_rq_payload_bytes(req); |
|---|
| 1148 | | - return BLKPREP_OK; |
|---|
| 1149 | | -} |
|---|
| 1037 | + count = __blk_rq_map_sg(rq->q, rq, cmd->sdb.table.sgl, &last_sg); |
|---|
| 1150 | 1038 | |
|---|
| 1151 | | -/* |
|---|
| 1152 | | - * Function: scsi_init_io() |
|---|
| 1153 | | - * |
|---|
| 1154 | | - * Purpose: SCSI I/O initialize function. |
|---|
| 1155 | | - * |
|---|
| 1156 | | - * Arguments: cmd - Command descriptor we wish to initialize |
|---|
| 1157 | | - * |
|---|
| 1158 | | - * Returns: 0 on success |
|---|
| 1159 | | - * BLKPREP_DEFER if the failure is retryable |
|---|
| 1160 | | - * BLKPREP_KILL if the failure is fatal |
|---|
| 1161 | | - */ |
|---|
| 1162 | | -int scsi_init_io(struct scsi_cmnd *cmd) |
|---|
| 1163 | | -{ |
|---|
| 1164 | | - struct scsi_device *sdev = cmd->device; |
|---|
| 1165 | | - struct request *rq = cmd->request; |
|---|
| 1166 | | - bool is_mq = (rq->mq_ctx != NULL); |
|---|
| 1167 | | - int error = BLKPREP_KILL; |
|---|
| 1039 | + if (blk_rq_bytes(rq) & rq->q->dma_pad_mask) { |
|---|
| 1040 | + unsigned int pad_len = |
|---|
| 1041 | + (rq->q->dma_pad_mask & ~blk_rq_bytes(rq)) + 1; |
|---|
| 1168 | 1042 | |
|---|
| 1169 | | - if (WARN_ON_ONCE(!blk_rq_nr_phys_segments(rq))) |
|---|
| 1170 | | - goto err_exit; |
|---|
| 1171 | | - |
|---|
| 1172 | | - error = scsi_init_sgtable(rq, &cmd->sdb); |
|---|
| 1173 | | - if (error) |
|---|
| 1174 | | - goto err_exit; |
|---|
| 1175 | | - |
|---|
| 1176 | | - if (blk_bidi_rq(rq)) { |
|---|
| 1177 | | - if (!rq->q->mq_ops) { |
|---|
| 1178 | | - struct scsi_data_buffer *bidi_sdb = |
|---|
| 1179 | | - kmem_cache_zalloc(scsi_sdb_cache, GFP_ATOMIC); |
|---|
| 1180 | | - if (!bidi_sdb) { |
|---|
| 1181 | | - error = BLKPREP_DEFER; |
|---|
| 1182 | | - goto err_exit; |
|---|
| 1183 | | - } |
|---|
| 1184 | | - |
|---|
| 1185 | | - rq->next_rq->special = bidi_sdb; |
|---|
| 1186 | | - } |
|---|
| 1187 | | - |
|---|
| 1188 | | - error = scsi_init_sgtable(rq->next_rq, rq->next_rq->special); |
|---|
| 1189 | | - if (error) |
|---|
| 1190 | | - goto err_exit; |
|---|
| 1043 | + last_sg->length += pad_len; |
|---|
| 1044 | + cmd->extra_len += pad_len; |
|---|
| 1191 | 1045 | } |
|---|
| 1046 | + |
|---|
| 1047 | + if (need_drain) { |
|---|
| 1048 | + sg_unmark_end(last_sg); |
|---|
| 1049 | + last_sg = sg_next(last_sg); |
|---|
| 1050 | + sg_set_buf(last_sg, sdev->dma_drain_buf, sdev->dma_drain_len); |
|---|
| 1051 | + sg_mark_end(last_sg); |
|---|
| 1052 | + |
|---|
| 1053 | + cmd->extra_len += sdev->dma_drain_len; |
|---|
| 1054 | + count++; |
|---|
| 1055 | + } |
|---|
| 1056 | + |
|---|
| 1057 | + BUG_ON(count > cmd->sdb.table.nents); |
|---|
| 1058 | + cmd->sdb.table.nents = count; |
|---|
| 1059 | + cmd->sdb.length = blk_rq_payload_bytes(rq); |
|---|
| 1192 | 1060 | |
|---|
| 1193 | 1061 | if (blk_integrity_rq(rq)) { |
|---|
| 1194 | 1062 | struct scsi_data_buffer *prot_sdb = cmd->prot_sdb; |
|---|
| 1195 | | - int ivecs, count; |
|---|
| 1063 | + int ivecs; |
|---|
| 1196 | 1064 | |
|---|
| 1197 | | - if (prot_sdb == NULL) { |
|---|
| 1065 | + if (WARN_ON_ONCE(!prot_sdb)) { |
|---|
| 1198 | 1066 | /* |
|---|
| 1199 | 1067 | * This can happen if someone (e.g. multipath) |
|---|
| 1200 | 1068 | * queues a command to a device on an adapter |
|---|
| 1201 | 1069 | * that does not support DIX. |
|---|
| 1202 | 1070 | */ |
|---|
| 1203 | | - WARN_ON_ONCE(1); |
|---|
| 1204 | | - error = BLKPREP_KILL; |
|---|
| 1205 | | - goto err_exit; |
|---|
| 1071 | + ret = BLK_STS_IOERR; |
|---|
| 1072 | + goto out_free_sgtables; |
|---|
| 1206 | 1073 | } |
|---|
| 1207 | 1074 | |
|---|
| 1208 | 1075 | ivecs = blk_rq_count_integrity_sg(rq->q, rq->bio); |
|---|
| 1209 | 1076 | |
|---|
| 1210 | 1077 | if (sg_alloc_table_chained(&prot_sdb->table, ivecs, |
|---|
| 1211 | | - prot_sdb->table.sgl)) { |
|---|
| 1212 | | - error = BLKPREP_DEFER; |
|---|
| 1213 | | - goto err_exit; |
|---|
| 1078 | + prot_sdb->table.sgl, |
|---|
| 1079 | + SCSI_INLINE_PROT_SG_CNT)) { |
|---|
| 1080 | + ret = BLK_STS_RESOURCE; |
|---|
| 1081 | + goto out_free_sgtables; |
|---|
| 1214 | 1082 | } |
|---|
| 1215 | 1083 | |
|---|
| 1216 | 1084 | count = blk_rq_map_integrity_sg(rq->q, rq->bio, |
|---|
| 1217 | 1085 | prot_sdb->table.sgl); |
|---|
| 1218 | | - BUG_ON(unlikely(count > ivecs)); |
|---|
| 1219 | | - BUG_ON(unlikely(count > queue_max_integrity_segments(rq->q))); |
|---|
| 1086 | + BUG_ON(count > ivecs); |
|---|
| 1087 | + BUG_ON(count > queue_max_integrity_segments(rq->q)); |
|---|
| 1220 | 1088 | |
|---|
| 1221 | 1089 | cmd->prot_sdb = prot_sdb; |
|---|
| 1222 | 1090 | cmd->prot_sdb->table.nents = count; |
|---|
| 1223 | 1091 | } |
|---|
| 1224 | 1092 | |
|---|
| 1225 | | - return BLKPREP_OK; |
|---|
| 1226 | | -err_exit: |
|---|
| 1227 | | - if (is_mq) { |
|---|
| 1228 | | - scsi_mq_free_sgtables(cmd); |
|---|
| 1229 | | - } else { |
|---|
| 1230 | | - scsi_release_buffers(cmd); |
|---|
| 1231 | | - cmd->request->special = NULL; |
|---|
| 1232 | | - scsi_put_command(cmd); |
|---|
| 1233 | | - put_device(&sdev->sdev_gendev); |
|---|
| 1234 | | - } |
|---|
| 1235 | | - return error; |
|---|
| 1093 | + return BLK_STS_OK; |
|---|
| 1094 | +out_free_sgtables: |
|---|
| 1095 | + scsi_free_sgtables(cmd); |
|---|
| 1096 | + return ret; |
|---|
| 1236 | 1097 | } |
|---|
| 1237 | | -EXPORT_SYMBOL(scsi_init_io); |
|---|
| 1098 | +EXPORT_SYMBOL(scsi_alloc_sgtables); |
|---|
| 1238 | 1099 | |
|---|
| 1239 | 1100 | /** |
|---|
| 1240 | 1101 | * scsi_initialize_rq - initialize struct scsi_cmnd partially |
|---|
| .. | .. |
|---|
| 1269 | 1130 | } |
|---|
| 1270 | 1131 | } |
|---|
| 1271 | 1132 | |
|---|
| 1272 | | -/* Add a command to the list used by the aacraid and dpt_i2o drivers */ |
|---|
| 1273 | | -void scsi_add_cmd_to_list(struct scsi_cmnd *cmd) |
|---|
| 1274 | | -{ |
|---|
| 1275 | | - struct scsi_device *sdev = cmd->device; |
|---|
| 1276 | | - struct Scsi_Host *shost = sdev->host; |
|---|
| 1277 | | - unsigned long flags; |
|---|
| 1278 | | - |
|---|
| 1279 | | - if (shost->use_cmd_list) { |
|---|
| 1280 | | - spin_lock_irqsave(&sdev->list_lock, flags); |
|---|
| 1281 | | - list_add_tail(&cmd->list, &sdev->cmd_list); |
|---|
| 1282 | | - spin_unlock_irqrestore(&sdev->list_lock, flags); |
|---|
| 1283 | | - } |
|---|
| 1284 | | -} |
|---|
| 1285 | | - |
|---|
| 1286 | | -/* Remove a command from the list used by the aacraid and dpt_i2o drivers */ |
|---|
| 1287 | | -void scsi_del_cmd_from_list(struct scsi_cmnd *cmd) |
|---|
| 1288 | | -{ |
|---|
| 1289 | | - struct scsi_device *sdev = cmd->device; |
|---|
| 1290 | | - struct Scsi_Host *shost = sdev->host; |
|---|
| 1291 | | - unsigned long flags; |
|---|
| 1292 | | - |
|---|
| 1293 | | - if (shost->use_cmd_list) { |
|---|
| 1294 | | - spin_lock_irqsave(&sdev->list_lock, flags); |
|---|
| 1295 | | - BUG_ON(list_empty(&cmd->list)); |
|---|
| 1296 | | - list_del_init(&cmd->list); |
|---|
| 1297 | | - spin_unlock_irqrestore(&sdev->list_lock, flags); |
|---|
| 1298 | | - } |
|---|
| 1299 | | -} |
|---|
| 1300 | | - |
|---|
| 1301 | | -/* Called after a request has been started. */ |
|---|
| 1133 | +/* Called before a request is prepared. See also scsi_mq_prep_fn(). */ |
|---|
| 1302 | 1134 | void scsi_init_command(struct scsi_device *dev, struct scsi_cmnd *cmd) |
|---|
| 1303 | 1135 | { |
|---|
| 1304 | 1136 | void *buf = cmd->sense_buffer; |
|---|
| .. | .. |
|---|
| 1306 | 1138 | struct request *rq = blk_mq_rq_from_pdu(cmd); |
|---|
| 1307 | 1139 | unsigned int flags = cmd->flags & SCMD_PRESERVED_FLAGS; |
|---|
| 1308 | 1140 | unsigned long jiffies_at_alloc; |
|---|
| 1309 | | - int retries; |
|---|
| 1141 | + int retries, to_clear; |
|---|
| 1142 | + bool in_flight; |
|---|
| 1310 | 1143 | |
|---|
| 1311 | 1144 | if (!blk_rq_is_scsi(rq) && !(flags & SCMD_INITIALIZED)) { |
|---|
| 1312 | 1145 | flags |= SCMD_INITIALIZED; |
|---|
| .. | .. |
|---|
| 1315 | 1148 | |
|---|
| 1316 | 1149 | jiffies_at_alloc = cmd->jiffies_at_alloc; |
|---|
| 1317 | 1150 | retries = cmd->retries; |
|---|
| 1318 | | - /* zero out the cmd, except for the embedded scsi_request */ |
|---|
| 1319 | | - memset((char *)cmd + sizeof(cmd->req), 0, |
|---|
| 1320 | | - sizeof(*cmd) - sizeof(cmd->req) + dev->host->hostt->cmd_size); |
|---|
| 1151 | + in_flight = test_bit(SCMD_STATE_INFLIGHT, &cmd->state); |
|---|
| 1152 | + /* |
|---|
| 1153 | + * Zero out the cmd, except for the embedded scsi_request. Only clear |
|---|
| 1154 | + * the driver-private command data if the LLD does not supply a |
|---|
| 1155 | + * function to initialize that data. |
|---|
| 1156 | + */ |
|---|
| 1157 | + to_clear = sizeof(*cmd) - sizeof(cmd->req); |
|---|
| 1158 | + if (!dev->host->hostt->init_cmd_priv) |
|---|
| 1159 | + to_clear += dev->host->hostt->cmd_size; |
|---|
| 1160 | + memset((char *)cmd + sizeof(cmd->req), 0, to_clear); |
|---|
| 1321 | 1161 | |
|---|
| 1322 | 1162 | cmd->device = dev; |
|---|
| 1323 | 1163 | cmd->sense_buffer = buf; |
|---|
| .. | .. |
|---|
| 1326 | 1166 | INIT_DELAYED_WORK(&cmd->abort_work, scmd_eh_abort_handler); |
|---|
| 1327 | 1167 | cmd->jiffies_at_alloc = jiffies_at_alloc; |
|---|
| 1328 | 1168 | cmd->retries = retries; |
|---|
| 1169 | + if (in_flight) |
|---|
| 1170 | + __set_bit(SCMD_STATE_INFLIGHT, &cmd->state); |
|---|
| 1329 | 1171 | |
|---|
| 1330 | | - scsi_add_cmd_to_list(cmd); |
|---|
| 1331 | 1172 | } |
|---|
| 1332 | 1173 | |
|---|
| 1333 | | -static int scsi_setup_scsi_cmnd(struct scsi_device *sdev, struct request *req) |
|---|
| 1174 | +static blk_status_t scsi_setup_scsi_cmnd(struct scsi_device *sdev, |
|---|
| 1175 | + struct request *req) |
|---|
| 1334 | 1176 | { |
|---|
| 1335 | 1177 | struct scsi_cmnd *cmd = blk_mq_rq_to_pdu(req); |
|---|
| 1336 | 1178 | |
|---|
| .. | .. |
|---|
| 1341 | 1183 | * submit a request without an attached bio. |
|---|
| 1342 | 1184 | */ |
|---|
| 1343 | 1185 | if (req->bio) { |
|---|
| 1344 | | - int ret = scsi_init_io(cmd); |
|---|
| 1345 | | - if (unlikely(ret)) |
|---|
| 1186 | + blk_status_t ret = scsi_alloc_sgtables(cmd); |
|---|
| 1187 | + if (unlikely(ret != BLK_STS_OK)) |
|---|
| 1346 | 1188 | return ret; |
|---|
| 1347 | 1189 | } else { |
|---|
| 1348 | 1190 | BUG_ON(blk_rq_bytes(req)); |
|---|
| .. | .. |
|---|
| 1354 | 1196 | cmd->cmnd = scsi_req(req)->cmd; |
|---|
| 1355 | 1197 | cmd->transfersize = blk_rq_bytes(req); |
|---|
| 1356 | 1198 | cmd->allowed = scsi_req(req)->retries; |
|---|
| 1357 | | - return BLKPREP_OK; |
|---|
| 1199 | + return BLK_STS_OK; |
|---|
| 1358 | 1200 | } |
|---|
| 1359 | 1201 | |
|---|
| 1360 | | -/* |
|---|
| 1361 | | - * Setup a normal block command. These are simple request from filesystems |
|---|
| 1362 | | - * that still need to be translated to SCSI CDBs from the ULD. |
|---|
| 1363 | | - */ |
|---|
| 1364 | | -static int scsi_setup_fs_cmnd(struct scsi_device *sdev, struct request *req) |
|---|
| 1202 | +static blk_status_t |
|---|
| 1203 | +scsi_device_state_check(struct scsi_device *sdev, struct request *req) |
|---|
| 1365 | 1204 | { |
|---|
| 1366 | | - struct scsi_cmnd *cmd = blk_mq_rq_to_pdu(req); |
|---|
| 1367 | | - |
|---|
| 1368 | | - if (unlikely(sdev->handler && sdev->handler->prep_fn)) { |
|---|
| 1369 | | - int ret = sdev->handler->prep_fn(sdev, req); |
|---|
| 1370 | | - if (ret != BLKPREP_OK) |
|---|
| 1371 | | - return ret; |
|---|
| 1372 | | - } |
|---|
| 1373 | | - |
|---|
| 1374 | | - cmd->cmnd = scsi_req(req)->cmd = scsi_req(req)->__cmd; |
|---|
| 1375 | | - memset(cmd->cmnd, 0, BLK_MAX_CDB); |
|---|
| 1376 | | - return scsi_cmd_to_driver(cmd)->init_command(cmd); |
|---|
| 1377 | | -} |
|---|
| 1378 | | - |
|---|
| 1379 | | -static int scsi_setup_cmnd(struct scsi_device *sdev, struct request *req) |
|---|
| 1380 | | -{ |
|---|
| 1381 | | - struct scsi_cmnd *cmd = blk_mq_rq_to_pdu(req); |
|---|
| 1382 | | - |
|---|
| 1383 | | - if (!blk_rq_bytes(req)) |
|---|
| 1384 | | - cmd->sc_data_direction = DMA_NONE; |
|---|
| 1385 | | - else if (rq_data_dir(req) == WRITE) |
|---|
| 1386 | | - cmd->sc_data_direction = DMA_TO_DEVICE; |
|---|
| 1387 | | - else |
|---|
| 1388 | | - cmd->sc_data_direction = DMA_FROM_DEVICE; |
|---|
| 1389 | | - |
|---|
| 1390 | | - if (blk_rq_is_scsi(req)) |
|---|
| 1391 | | - return scsi_setup_scsi_cmnd(sdev, req); |
|---|
| 1392 | | - else |
|---|
| 1393 | | - return scsi_setup_fs_cmnd(sdev, req); |
|---|
| 1394 | | -} |
|---|
| 1395 | | - |
|---|
| 1396 | | -static int |
|---|
| 1397 | | -scsi_prep_state_check(struct scsi_device *sdev, struct request *req) |
|---|
| 1398 | | -{ |
|---|
| 1399 | | - int ret = BLKPREP_OK; |
|---|
| 1400 | | - |
|---|
| 1401 | | - /* |
|---|
| 1402 | | - * If the device is not in running state we will reject some |
|---|
| 1403 | | - * or all commands. |
|---|
| 1404 | | - */ |
|---|
| 1405 | | - if (unlikely(sdev->sdev_state != SDEV_RUNNING)) { |
|---|
| 1406 | | - switch (sdev->sdev_state) { |
|---|
| 1407 | | - case SDEV_OFFLINE: |
|---|
| 1408 | | - case SDEV_TRANSPORT_OFFLINE: |
|---|
| 1409 | | - /* |
|---|
| 1410 | | - * If the device is offline we refuse to process any |
|---|
| 1411 | | - * commands. The device must be brought online |
|---|
| 1412 | | - * before trying any recovery commands. |
|---|
| 1413 | | - */ |
|---|
| 1205 | + switch (sdev->sdev_state) { |
|---|
| 1206 | + case SDEV_CREATED: |
|---|
| 1207 | + return BLK_STS_OK; |
|---|
| 1208 | + case SDEV_OFFLINE: |
|---|
| 1209 | + case SDEV_TRANSPORT_OFFLINE: |
|---|
| 1210 | + /* |
|---|
| 1211 | + * If the device is offline we refuse to process any |
|---|
| 1212 | + * commands. The device must be brought online |
|---|
| 1213 | + * before trying any recovery commands. |
|---|
| 1214 | + */ |
|---|
| 1215 | + if (!sdev->offline_already) { |
|---|
| 1216 | + sdev->offline_already = true; |
|---|
| 1414 | 1217 | sdev_printk(KERN_ERR, sdev, |
|---|
| 1415 | 1218 | "rejecting I/O to offline device\n"); |
|---|
| 1416 | | - ret = BLKPREP_KILL; |
|---|
| 1417 | | - break; |
|---|
| 1418 | | - case SDEV_DEL: |
|---|
| 1419 | | - /* |
|---|
| 1420 | | - * If the device is fully deleted, we refuse to |
|---|
| 1421 | | - * process any commands as well. |
|---|
| 1422 | | - */ |
|---|
| 1423 | | - sdev_printk(KERN_ERR, sdev, |
|---|
| 1424 | | - "rejecting I/O to dead device\n"); |
|---|
| 1425 | | - ret = BLKPREP_KILL; |
|---|
| 1426 | | - break; |
|---|
| 1427 | | - case SDEV_BLOCK: |
|---|
| 1428 | | - case SDEV_CREATED_BLOCK: |
|---|
| 1429 | | - ret = BLKPREP_DEFER; |
|---|
| 1430 | | - break; |
|---|
| 1431 | | - case SDEV_QUIESCE: |
|---|
| 1432 | | - /* |
|---|
| 1433 | | - * If the devices is blocked we defer normal commands. |
|---|
| 1434 | | - */ |
|---|
| 1435 | | - if (req && !(req->rq_flags & RQF_PREEMPT)) |
|---|
| 1436 | | - ret = BLKPREP_DEFER; |
|---|
| 1437 | | - break; |
|---|
| 1438 | | - default: |
|---|
| 1439 | | - /* |
|---|
| 1440 | | - * For any other not fully online state we only allow |
|---|
| 1441 | | - * special commands. In particular any user initiated |
|---|
| 1442 | | - * command is not allowed. |
|---|
| 1443 | | - */ |
|---|
| 1444 | | - if (req && !(req->rq_flags & RQF_PREEMPT)) |
|---|
| 1445 | | - ret = BLKPREP_KILL; |
|---|
| 1446 | | - break; |
|---|
| 1447 | 1219 | } |
|---|
| 1448 | | - } |
|---|
| 1449 | | - return ret; |
|---|
| 1450 | | -} |
|---|
| 1451 | | - |
|---|
| 1452 | | -static int |
|---|
| 1453 | | -scsi_prep_return(struct request_queue *q, struct request *req, int ret) |
|---|
| 1454 | | -{ |
|---|
| 1455 | | - struct scsi_device *sdev = q->queuedata; |
|---|
| 1456 | | - |
|---|
| 1457 | | - switch (ret) { |
|---|
| 1458 | | - case BLKPREP_KILL: |
|---|
| 1459 | | - case BLKPREP_INVALID: |
|---|
| 1460 | | - scsi_req(req)->result = DID_NO_CONNECT << 16; |
|---|
| 1461 | | - /* release the command and kill it */ |
|---|
| 1462 | | - if (req->special) { |
|---|
| 1463 | | - struct scsi_cmnd *cmd = req->special; |
|---|
| 1464 | | - scsi_release_buffers(cmd); |
|---|
| 1465 | | - scsi_put_command(cmd); |
|---|
| 1466 | | - put_device(&sdev->sdev_gendev); |
|---|
| 1467 | | - req->special = NULL; |
|---|
| 1468 | | - } |
|---|
| 1469 | | - break; |
|---|
| 1470 | | - case BLKPREP_DEFER: |
|---|
| 1220 | + return BLK_STS_IOERR; |
|---|
| 1221 | + case SDEV_DEL: |
|---|
| 1471 | 1222 | /* |
|---|
| 1472 | | - * If we defer, the blk_peek_request() returns NULL, but the |
|---|
| 1473 | | - * queue must be restarted, so we schedule a callback to happen |
|---|
| 1474 | | - * shortly. |
|---|
| 1223 | + * If the device is fully deleted, we refuse to |
|---|
| 1224 | + * process any commands as well. |
|---|
| 1475 | 1225 | */ |
|---|
| 1476 | | - if (atomic_read(&sdev->device_busy) == 0) |
|---|
| 1477 | | - blk_delay_queue(q, SCSI_QUEUE_DELAY); |
|---|
| 1478 | | - break; |
|---|
| 1226 | + sdev_printk(KERN_ERR, sdev, |
|---|
| 1227 | + "rejecting I/O to dead device\n"); |
|---|
| 1228 | + return BLK_STS_IOERR; |
|---|
| 1229 | + case SDEV_BLOCK: |
|---|
| 1230 | + case SDEV_CREATED_BLOCK: |
|---|
| 1231 | + return BLK_STS_RESOURCE; |
|---|
| 1232 | + case SDEV_QUIESCE: |
|---|
| 1233 | + /* |
|---|
| 1234 | + * If the device is blocked we only accept power management |
|---|
| 1235 | + * commands. |
|---|
| 1236 | + */ |
|---|
| 1237 | + if (req && WARN_ON_ONCE(!(req->rq_flags & RQF_PM))) |
|---|
| 1238 | + return BLK_STS_RESOURCE; |
|---|
| 1239 | + return BLK_STS_OK; |
|---|
| 1479 | 1240 | default: |
|---|
| 1480 | | - req->rq_flags |= RQF_DONTPREP; |
|---|
| 1241 | + /* |
|---|
| 1242 | + * For any other not fully online state we only allow |
|---|
| 1243 | + * power management commands. |
|---|
| 1244 | + */ |
|---|
| 1245 | + if (req && !(req->rq_flags & RQF_PM)) |
|---|
| 1246 | + return BLK_STS_IOERR; |
|---|
| 1247 | + return BLK_STS_OK; |
|---|
| 1481 | 1248 | } |
|---|
| 1482 | | - |
|---|
| 1483 | | - return ret; |
|---|
| 1484 | | -} |
|---|
| 1485 | | - |
|---|
| 1486 | | -static int scsi_prep_fn(struct request_queue *q, struct request *req) |
|---|
| 1487 | | -{ |
|---|
| 1488 | | - struct scsi_device *sdev = q->queuedata; |
|---|
| 1489 | | - struct scsi_cmnd *cmd = blk_mq_rq_to_pdu(req); |
|---|
| 1490 | | - int ret; |
|---|
| 1491 | | - |
|---|
| 1492 | | - ret = scsi_prep_state_check(sdev, req); |
|---|
| 1493 | | - if (ret != BLKPREP_OK) |
|---|
| 1494 | | - goto out; |
|---|
| 1495 | | - |
|---|
| 1496 | | - if (!req->special) { |
|---|
| 1497 | | - /* Bail if we can't get a reference to the device */ |
|---|
| 1498 | | - if (unlikely(!get_device(&sdev->sdev_gendev))) { |
|---|
| 1499 | | - ret = BLKPREP_DEFER; |
|---|
| 1500 | | - goto out; |
|---|
| 1501 | | - } |
|---|
| 1502 | | - |
|---|
| 1503 | | - scsi_init_command(sdev, cmd); |
|---|
| 1504 | | - req->special = cmd; |
|---|
| 1505 | | - } |
|---|
| 1506 | | - |
|---|
| 1507 | | - cmd->tag = req->tag; |
|---|
| 1508 | | - cmd->request = req; |
|---|
| 1509 | | - cmd->prot_op = SCSI_PROT_NORMAL; |
|---|
| 1510 | | - |
|---|
| 1511 | | - ret = scsi_setup_cmnd(sdev, req); |
|---|
| 1512 | | -out: |
|---|
| 1513 | | - return scsi_prep_return(q, req, ret); |
|---|
| 1514 | | -} |
|---|
| 1515 | | - |
|---|
| 1516 | | -static void scsi_unprep_fn(struct request_queue *q, struct request *req) |
|---|
| 1517 | | -{ |
|---|
| 1518 | | - scsi_uninit_cmd(blk_mq_rq_to_pdu(req)); |
|---|
| 1519 | 1249 | } |
|---|
| 1520 | 1250 | |
|---|
| 1521 | 1251 | /* |
|---|
| .. | .. |
|---|
| 1537 | 1267 | /* |
|---|
| 1538 | 1268 | * unblock after device_blocked iterates to zero |
|---|
| 1539 | 1269 | */ |
|---|
| 1540 | | - if (atomic_dec_return(&sdev->device_blocked) > 0) { |
|---|
| 1541 | | - /* |
|---|
| 1542 | | - * For the MQ case we take care of this in the caller. |
|---|
| 1543 | | - */ |
|---|
| 1544 | | - if (!q->mq_ops) |
|---|
| 1545 | | - blk_delay_queue(q, SCSI_QUEUE_DELAY); |
|---|
| 1270 | + if (atomic_dec_return(&sdev->device_blocked) > 0) |
|---|
| 1546 | 1271 | goto out_dec; |
|---|
| 1547 | | - } |
|---|
| 1548 | 1272 | SCSI_LOG_MLQUEUE(3, sdev_printk(KERN_INFO, sdev, |
|---|
| 1549 | 1273 | "unblocking device at zero depth\n")); |
|---|
| 1550 | 1274 | } |
|---|
| .. | .. |
|---|
| 1619 | 1343 | */ |
|---|
| 1620 | 1344 | static inline int scsi_host_queue_ready(struct request_queue *q, |
|---|
| 1621 | 1345 | struct Scsi_Host *shost, |
|---|
| 1622 | | - struct scsi_device *sdev) |
|---|
| 1346 | + struct scsi_device *sdev, |
|---|
| 1347 | + struct scsi_cmnd *cmd) |
|---|
| 1623 | 1348 | { |
|---|
| 1624 | | - unsigned int busy; |
|---|
| 1625 | | - |
|---|
| 1626 | 1349 | if (scsi_host_in_recovery(shost)) |
|---|
| 1627 | 1350 | return 0; |
|---|
| 1628 | 1351 | |
|---|
| 1629 | | - busy = atomic_inc_return(&shost->host_busy) - 1; |
|---|
| 1630 | 1352 | if (atomic_read(&shost->host_blocked) > 0) { |
|---|
| 1631 | | - if (busy) |
|---|
| 1353 | + if (scsi_host_busy(shost) > 0) |
|---|
| 1632 | 1354 | goto starved; |
|---|
| 1633 | 1355 | |
|---|
| 1634 | 1356 | /* |
|---|
| .. | .. |
|---|
| 1642 | 1364 | "unblocking host at zero depth\n")); |
|---|
| 1643 | 1365 | } |
|---|
| 1644 | 1366 | |
|---|
| 1645 | | - if (shost->can_queue > 0 && busy >= shost->can_queue) |
|---|
| 1646 | | - goto starved; |
|---|
| 1647 | 1367 | if (shost->host_self_blocked) |
|---|
| 1648 | 1368 | goto starved; |
|---|
| 1649 | 1369 | |
|---|
| .. | .. |
|---|
| 1655 | 1375 | spin_unlock_irq(shost->host_lock); |
|---|
| 1656 | 1376 | } |
|---|
| 1657 | 1377 | |
|---|
| 1378 | + __set_bit(SCMD_STATE_INFLIGHT, &cmd->state); |
|---|
| 1379 | + |
|---|
| 1658 | 1380 | return 1; |
|---|
| 1659 | 1381 | |
|---|
| 1660 | 1382 | starved: |
|---|
| .. | .. |
|---|
| 1663 | 1385 | list_add_tail(&sdev->starved_entry, &shost->starved_list); |
|---|
| 1664 | 1386 | spin_unlock_irq(shost->host_lock); |
|---|
| 1665 | 1387 | out_dec: |
|---|
| 1666 | | - scsi_dec_host_busy(shost); |
|---|
| 1388 | + scsi_dec_host_busy(shost, cmd); |
|---|
| 1667 | 1389 | return 0; |
|---|
| 1668 | 1390 | } |
|---|
| 1669 | 1391 | |
|---|
| .. | .. |
|---|
| 1679 | 1401 | * needs to return 'not busy'. Otherwise, request stacking drivers |
|---|
| 1680 | 1402 | * may hold requests forever. |
|---|
| 1681 | 1403 | */ |
|---|
| 1682 | | -static int scsi_lld_busy(struct request_queue *q) |
|---|
| 1404 | +static bool scsi_mq_lld_busy(struct request_queue *q) |
|---|
| 1683 | 1405 | { |
|---|
| 1684 | 1406 | struct scsi_device *sdev = q->queuedata; |
|---|
| 1685 | 1407 | struct Scsi_Host *shost; |
|---|
| 1686 | 1408 | |
|---|
| 1687 | 1409 | if (blk_queue_dying(q)) |
|---|
| 1688 | | - return 0; |
|---|
| 1410 | + return false; |
|---|
| 1689 | 1411 | |
|---|
| 1690 | 1412 | shost = sdev->host; |
|---|
| 1691 | 1413 | |
|---|
| .. | .. |
|---|
| 1696 | 1418 | * in SCSI layer. |
|---|
| 1697 | 1419 | */ |
|---|
| 1698 | 1420 | if (scsi_host_in_recovery(shost) || scsi_device_is_busy(sdev)) |
|---|
| 1699 | | - return 1; |
|---|
| 1421 | + return true; |
|---|
| 1700 | 1422 | |
|---|
| 1701 | | - return 0; |
|---|
| 1702 | | -} |
|---|
| 1703 | | - |
|---|
| 1704 | | -/* |
|---|
| 1705 | | - * Kill a request for a dead device |
|---|
| 1706 | | - */ |
|---|
| 1707 | | -static void scsi_kill_request(struct request *req, struct request_queue *q) |
|---|
| 1708 | | -{ |
|---|
| 1709 | | - struct scsi_cmnd *cmd = blk_mq_rq_to_pdu(req); |
|---|
| 1710 | | - struct scsi_device *sdev; |
|---|
| 1711 | | - struct scsi_target *starget; |
|---|
| 1712 | | - struct Scsi_Host *shost; |
|---|
| 1713 | | - |
|---|
| 1714 | | - blk_start_request(req); |
|---|
| 1715 | | - |
|---|
| 1716 | | - scmd_printk(KERN_INFO, cmd, "killing request\n"); |
|---|
| 1717 | | - |
|---|
| 1718 | | - sdev = cmd->device; |
|---|
| 1719 | | - starget = scsi_target(sdev); |
|---|
| 1720 | | - shost = sdev->host; |
|---|
| 1721 | | - scsi_init_cmd_errh(cmd); |
|---|
| 1722 | | - cmd->result = DID_NO_CONNECT << 16; |
|---|
| 1723 | | - atomic_inc(&cmd->device->iorequest_cnt); |
|---|
| 1724 | | - |
|---|
| 1725 | | - /* |
|---|
| 1726 | | - * SCSI request completion path will do scsi_device_unbusy(), |
|---|
| 1727 | | - * bump busy counts. To bump the counters, we need to dance |
|---|
| 1728 | | - * with the locks as normal issue path does. |
|---|
| 1729 | | - */ |
|---|
| 1730 | | - atomic_inc(&sdev->device_busy); |
|---|
| 1731 | | - atomic_inc(&shost->host_busy); |
|---|
| 1732 | | - if (starget->can_queue > 0) |
|---|
| 1733 | | - atomic_inc(&starget->target_busy); |
|---|
| 1734 | | - |
|---|
| 1735 | | - blk_complete_request(req); |
|---|
| 1423 | + return false; |
|---|
| 1736 | 1424 | } |
|---|
| 1737 | 1425 | |
|---|
| 1738 | 1426 | static void scsi_softirq_done(struct request *rq) |
|---|
| 1739 | 1427 | { |
|---|
| 1740 | 1428 | struct scsi_cmnd *cmd = blk_mq_rq_to_pdu(rq); |
|---|
| 1741 | | - unsigned long wait_for = (cmd->allowed + 1) * rq->timeout; |
|---|
| 1742 | 1429 | int disposition; |
|---|
| 1743 | 1430 | |
|---|
| 1744 | 1431 | INIT_LIST_HEAD(&cmd->eh_entry); |
|---|
| .. | .. |
|---|
| 1748 | 1435 | atomic_inc(&cmd->device->ioerr_cnt); |
|---|
| 1749 | 1436 | |
|---|
| 1750 | 1437 | disposition = scsi_decide_disposition(cmd); |
|---|
| 1751 | | - if (disposition != SUCCESS && |
|---|
| 1752 | | - time_before(cmd->jiffies_at_alloc + wait_for, jiffies)) { |
|---|
| 1753 | | - sdev_printk(KERN_ERR, cmd->device, |
|---|
| 1754 | | - "timing out command, waited %lus\n", |
|---|
| 1755 | | - wait_for/HZ); |
|---|
| 1438 | + if (disposition != SUCCESS && scsi_cmd_runtime_exceeced(cmd)) |
|---|
| 1756 | 1439 | disposition = SUCCESS; |
|---|
| 1757 | | - } |
|---|
| 1758 | 1440 | |
|---|
| 1759 | 1441 | scsi_log_completion(cmd, disposition); |
|---|
| 1760 | 1442 | |
|---|
| 1761 | 1443 | switch (disposition) { |
|---|
| 1762 | | - case SUCCESS: |
|---|
| 1763 | | - scsi_finish_command(cmd); |
|---|
| 1764 | | - break; |
|---|
| 1765 | | - case NEEDS_RETRY: |
|---|
| 1766 | | - scsi_queue_insert(cmd, SCSI_MLQUEUE_EH_RETRY); |
|---|
| 1767 | | - break; |
|---|
| 1768 | | - case ADD_TO_MLQUEUE: |
|---|
| 1769 | | - scsi_queue_insert(cmd, SCSI_MLQUEUE_DEVICE_BUSY); |
|---|
| 1770 | | - break; |
|---|
| 1771 | | - default: |
|---|
| 1772 | | - scsi_eh_scmd_add(cmd); |
|---|
| 1773 | | - break; |
|---|
| 1444 | + case SUCCESS: |
|---|
| 1445 | + scsi_finish_command(cmd); |
|---|
| 1446 | + break; |
|---|
| 1447 | + case NEEDS_RETRY: |
|---|
| 1448 | + scsi_queue_insert(cmd, SCSI_MLQUEUE_EH_RETRY); |
|---|
| 1449 | + break; |
|---|
| 1450 | + case ADD_TO_MLQUEUE: |
|---|
| 1451 | + scsi_queue_insert(cmd, SCSI_MLQUEUE_DEVICE_BUSY); |
|---|
| 1452 | + break; |
|---|
| 1453 | + default: |
|---|
| 1454 | + scsi_eh_scmd_add(cmd); |
|---|
| 1455 | + break; |
|---|
| 1774 | 1456 | } |
|---|
| 1775 | 1457 | } |
|---|
| 1776 | 1458 | |
|---|
| .. | .. |
|---|
| 1855 | 1537 | return 0; |
|---|
| 1856 | 1538 | } |
|---|
| 1857 | 1539 | |
|---|
| 1858 | | -/** |
|---|
| 1859 | | - * scsi_done - Invoke completion on finished SCSI command. |
|---|
| 1860 | | - * @cmd: The SCSI Command for which a low-level device driver (LLDD) gives |
|---|
| 1861 | | - * ownership back to SCSI Core -- i.e. the LLDD has finished with it. |
|---|
| 1862 | | - * |
|---|
| 1863 | | - * Description: This function is the mid-level's (SCSI Core) interrupt routine, |
|---|
| 1864 | | - * which regains ownership of the SCSI command (de facto) from a LLDD, and |
|---|
| 1865 | | - * calls blk_complete_request() for further processing. |
|---|
| 1866 | | - * |
|---|
| 1867 | | - * This function is interrupt context safe. |
|---|
| 1868 | | - */ |
|---|
| 1869 | | -static void scsi_done(struct scsi_cmnd *cmd) |
|---|
| 1870 | | -{ |
|---|
| 1871 | | - trace_scsi_dispatch_cmd_done(cmd); |
|---|
| 1872 | | - blk_complete_request(cmd->request); |
|---|
| 1873 | | -} |
|---|
| 1874 | | - |
|---|
| 1875 | | -/* |
|---|
| 1876 | | - * Function: scsi_request_fn() |
|---|
| 1877 | | - * |
|---|
| 1878 | | - * Purpose: Main strategy routine for SCSI. |
|---|
| 1879 | | - * |
|---|
| 1880 | | - * Arguments: q - Pointer to actual queue. |
|---|
| 1881 | | - * |
|---|
| 1882 | | - * Returns: Nothing |
|---|
| 1883 | | - * |
|---|
| 1884 | | - * Lock status: request queue lock assumed to be held when called. |
|---|
| 1885 | | - * |
|---|
| 1886 | | - * Note: See sd_zbc.c sd_zbc_write_lock_zone() for write order |
|---|
| 1887 | | - * protection for ZBC disks. |
|---|
| 1888 | | - */ |
|---|
| 1889 | | -static void scsi_request_fn(struct request_queue *q) |
|---|
| 1890 | | - __releases(q->queue_lock) |
|---|
| 1891 | | - __acquires(q->queue_lock) |
|---|
| 1892 | | -{ |
|---|
| 1893 | | - struct scsi_device *sdev = q->queuedata; |
|---|
| 1894 | | - struct Scsi_Host *shost; |
|---|
| 1895 | | - struct scsi_cmnd *cmd; |
|---|
| 1896 | | - struct request *req; |
|---|
| 1897 | | - |
|---|
| 1898 | | - /* |
|---|
| 1899 | | - * To start with, we keep looping until the queue is empty, or until |
|---|
| 1900 | | - * the host is no longer able to accept any more requests. |
|---|
| 1901 | | - */ |
|---|
| 1902 | | - shost = sdev->host; |
|---|
| 1903 | | - for (;;) { |
|---|
| 1904 | | - int rtn; |
|---|
| 1905 | | - /* |
|---|
| 1906 | | - * get next queueable request. We do this early to make sure |
|---|
| 1907 | | - * that the request is fully prepared even if we cannot |
|---|
| 1908 | | - * accept it. |
|---|
| 1909 | | - */ |
|---|
| 1910 | | - req = blk_peek_request(q); |
|---|
| 1911 | | - if (!req) |
|---|
| 1912 | | - break; |
|---|
| 1913 | | - |
|---|
| 1914 | | - if (unlikely(!scsi_device_online(sdev))) { |
|---|
| 1915 | | - sdev_printk(KERN_ERR, sdev, |
|---|
| 1916 | | - "rejecting I/O to offline device\n"); |
|---|
| 1917 | | - scsi_kill_request(req, q); |
|---|
| 1918 | | - continue; |
|---|
| 1919 | | - } |
|---|
| 1920 | | - |
|---|
| 1921 | | - if (!scsi_dev_queue_ready(q, sdev)) |
|---|
| 1922 | | - break; |
|---|
| 1923 | | - |
|---|
| 1924 | | - /* |
|---|
| 1925 | | - * Remove the request from the request list. |
|---|
| 1926 | | - */ |
|---|
| 1927 | | - if (!(blk_queue_tagged(q) && !blk_queue_start_tag(q, req))) |
|---|
| 1928 | | - blk_start_request(req); |
|---|
| 1929 | | - |
|---|
| 1930 | | - spin_unlock_irq(q->queue_lock); |
|---|
| 1931 | | - cmd = blk_mq_rq_to_pdu(req); |
|---|
| 1932 | | - if (cmd != req->special) { |
|---|
| 1933 | | - printk(KERN_CRIT "impossible request in %s.\n" |
|---|
| 1934 | | - "please mail a stack trace to " |
|---|
| 1935 | | - "linux-scsi@vger.kernel.org\n", |
|---|
| 1936 | | - __func__); |
|---|
| 1937 | | - blk_dump_rq_flags(req, "foo"); |
|---|
| 1938 | | - BUG(); |
|---|
| 1939 | | - } |
|---|
| 1940 | | - |
|---|
| 1941 | | - /* |
|---|
| 1942 | | - * We hit this when the driver is using a host wide |
|---|
| 1943 | | - * tag map. For device level tag maps the queue_depth check |
|---|
| 1944 | | - * in the device ready fn would prevent us from trying |
|---|
| 1945 | | - * to allocate a tag. Since the map is a shared host resource |
|---|
| 1946 | | - * we add the dev to the starved list so it eventually gets |
|---|
| 1947 | | - * a run when a tag is freed. |
|---|
| 1948 | | - */ |
|---|
| 1949 | | - if (blk_queue_tagged(q) && !(req->rq_flags & RQF_QUEUED)) { |
|---|
| 1950 | | - spin_lock_irq(shost->host_lock); |
|---|
| 1951 | | - if (list_empty(&sdev->starved_entry)) |
|---|
| 1952 | | - list_add_tail(&sdev->starved_entry, |
|---|
| 1953 | | - &shost->starved_list); |
|---|
| 1954 | | - spin_unlock_irq(shost->host_lock); |
|---|
| 1955 | | - goto not_ready; |
|---|
| 1956 | | - } |
|---|
| 1957 | | - |
|---|
| 1958 | | - if (!scsi_target_queue_ready(shost, sdev)) |
|---|
| 1959 | | - goto not_ready; |
|---|
| 1960 | | - |
|---|
| 1961 | | - if (!scsi_host_queue_ready(q, shost, sdev)) |
|---|
| 1962 | | - goto host_not_ready; |
|---|
| 1963 | | - |
|---|
| 1964 | | - if (sdev->simple_tags) |
|---|
| 1965 | | - cmd->flags |= SCMD_TAGGED; |
|---|
| 1966 | | - else |
|---|
| 1967 | | - cmd->flags &= ~SCMD_TAGGED; |
|---|
| 1968 | | - |
|---|
| 1969 | | - /* |
|---|
| 1970 | | - * Finally, initialize any error handling parameters, and set up |
|---|
| 1971 | | - * the timers for timeouts. |
|---|
| 1972 | | - */ |
|---|
| 1973 | | - scsi_init_cmd_errh(cmd); |
|---|
| 1974 | | - |
|---|
| 1975 | | - /* |
|---|
| 1976 | | - * Dispatch the command to the low-level driver. |
|---|
| 1977 | | - */ |
|---|
| 1978 | | - cmd->scsi_done = scsi_done; |
|---|
| 1979 | | - rtn = scsi_dispatch_cmd(cmd); |
|---|
| 1980 | | - if (rtn) { |
|---|
| 1981 | | - scsi_queue_insert(cmd, rtn); |
|---|
| 1982 | | - spin_lock_irq(q->queue_lock); |
|---|
| 1983 | | - goto out_delay; |
|---|
| 1984 | | - } |
|---|
| 1985 | | - spin_lock_irq(q->queue_lock); |
|---|
| 1986 | | - } |
|---|
| 1987 | | - |
|---|
| 1988 | | - return; |
|---|
| 1989 | | - |
|---|
| 1990 | | - host_not_ready: |
|---|
| 1991 | | - if (scsi_target(sdev)->can_queue > 0) |
|---|
| 1992 | | - atomic_dec(&scsi_target(sdev)->target_busy); |
|---|
| 1993 | | - not_ready: |
|---|
| 1994 | | - /* |
|---|
| 1995 | | - * lock q, handle tag, requeue req, and decrement device_busy. We |
|---|
| 1996 | | - * must return with queue_lock held. |
|---|
| 1997 | | - * |
|---|
| 1998 | | - * Decrementing device_busy without checking it is OK, as all such |
|---|
| 1999 | | - * cases (host limits or settings) should run the queue at some |
|---|
| 2000 | | - * later time. |
|---|
| 2001 | | - */ |
|---|
| 2002 | | - spin_lock_irq(q->queue_lock); |
|---|
| 2003 | | - blk_requeue_request(q, req); |
|---|
| 2004 | | - atomic_dec(&sdev->device_busy); |
|---|
| 2005 | | -out_delay: |
|---|
| 2006 | | - if (!atomic_read(&sdev->device_busy) && !scsi_device_blocked(sdev)) |
|---|
| 2007 | | - blk_delay_queue(q, SCSI_QUEUE_DELAY); |
|---|
| 2008 | | -} |
|---|
| 2009 | | - |
|---|
| 2010 | | -static inline blk_status_t prep_to_mq(int ret) |
|---|
| 2011 | | -{ |
|---|
| 2012 | | - switch (ret) { |
|---|
| 2013 | | - case BLKPREP_OK: |
|---|
| 2014 | | - return BLK_STS_OK; |
|---|
| 2015 | | - case BLKPREP_DEFER: |
|---|
| 2016 | | - return BLK_STS_RESOURCE; |
|---|
| 2017 | | - default: |
|---|
| 2018 | | - return BLK_STS_IOERR; |
|---|
| 2019 | | - } |
|---|
| 2020 | | -} |
|---|
| 2021 | | - |
|---|
| 2022 | 1540 | /* Size in bytes of the sg-list stored in the scsi-mq command-private data. */ |
|---|
| 2023 | | -static unsigned int scsi_mq_sgl_size(struct Scsi_Host *shost) |
|---|
| 1541 | +static unsigned int scsi_mq_inline_sgl_size(struct Scsi_Host *shost) |
|---|
| 2024 | 1542 | { |
|---|
| 2025 | | - return min_t(unsigned int, shost->sg_tablesize, SG_CHUNK_SIZE) * |
|---|
| 1543 | + return min_t(unsigned int, shost->sg_tablesize, SCSI_INLINE_SG_CNT) * |
|---|
| 2026 | 1544 | sizeof(struct scatterlist); |
|---|
| 2027 | 1545 | } |
|---|
| 2028 | 1546 | |
|---|
| 2029 | | -static int scsi_mq_prep_fn(struct request *req) |
|---|
| 1547 | +static blk_status_t scsi_prepare_cmd(struct request *req) |
|---|
| 2030 | 1548 | { |
|---|
| 2031 | 1549 | struct scsi_cmnd *cmd = blk_mq_rq_to_pdu(req); |
|---|
| 2032 | 1550 | struct scsi_device *sdev = req->q->queuedata; |
|---|
| .. | .. |
|---|
| 2035 | 1553 | |
|---|
| 2036 | 1554 | scsi_init_command(sdev, cmd); |
|---|
| 2037 | 1555 | |
|---|
| 2038 | | - req->special = cmd; |
|---|
| 2039 | | - |
|---|
| 2040 | 1556 | cmd->request = req; |
|---|
| 2041 | | - |
|---|
| 2042 | 1557 | cmd->tag = req->tag; |
|---|
| 2043 | 1558 | cmd->prot_op = SCSI_PROT_NORMAL; |
|---|
| 1559 | + if (blk_rq_bytes(req)) |
|---|
| 1560 | + cmd->sc_data_direction = rq_dma_dir(req); |
|---|
| 1561 | + else |
|---|
| 1562 | + cmd->sc_data_direction = DMA_NONE; |
|---|
| 2044 | 1563 | |
|---|
| 2045 | 1564 | sg = (void *)cmd + sizeof(struct scsi_cmnd) + shost->hostt->cmd_size; |
|---|
| 2046 | 1565 | cmd->sdb.table.sgl = sg; |
|---|
| .. | .. |
|---|
| 2052 | 1571 | (struct scatterlist *)(cmd->prot_sdb + 1); |
|---|
| 2053 | 1572 | } |
|---|
| 2054 | 1573 | |
|---|
| 2055 | | - if (blk_bidi_rq(req)) { |
|---|
| 2056 | | - struct request *next_rq = req->next_rq; |
|---|
| 2057 | | - struct scsi_data_buffer *bidi_sdb = blk_mq_rq_to_pdu(next_rq); |
|---|
| 1574 | + /* |
|---|
| 1575 | + * Special handling for passthrough commands, which don't go to the ULP |
|---|
| 1576 | + * at all: |
|---|
| 1577 | + */ |
|---|
| 1578 | + if (blk_rq_is_scsi(req)) |
|---|
| 1579 | + return scsi_setup_scsi_cmnd(sdev, req); |
|---|
| 2058 | 1580 | |
|---|
| 2059 | | - memset(bidi_sdb, 0, sizeof(struct scsi_data_buffer)); |
|---|
| 2060 | | - bidi_sdb->table.sgl = |
|---|
| 2061 | | - (struct scatterlist *)(bidi_sdb + 1); |
|---|
| 1581 | + if (sdev->handler && sdev->handler->prep_fn) { |
|---|
| 1582 | + blk_status_t ret = sdev->handler->prep_fn(sdev, req); |
|---|
| 2062 | 1583 | |
|---|
| 2063 | | - next_rq->special = bidi_sdb; |
|---|
| 1584 | + if (ret != BLK_STS_OK) |
|---|
| 1585 | + return ret; |
|---|
| 2064 | 1586 | } |
|---|
| 2065 | 1587 | |
|---|
| 2066 | | - blk_mq_start_request(req); |
|---|
| 2067 | | - |
|---|
| 2068 | | - return scsi_setup_cmnd(sdev, req); |
|---|
| 1588 | + cmd->cmnd = scsi_req(req)->cmd = scsi_req(req)->__cmd; |
|---|
| 1589 | + memset(cmd->cmnd, 0, BLK_MAX_CDB); |
|---|
| 1590 | + return scsi_cmd_to_driver(cmd)->init_command(cmd); |
|---|
| 2069 | 1591 | } |
|---|
| 2070 | 1592 | |
|---|
| 2071 | 1593 | static void scsi_mq_done(struct scsi_cmnd *cmd) |
|---|
| 2072 | 1594 | { |
|---|
| 1595 | + if (unlikely(blk_should_fake_timeout(cmd->request->q))) |
|---|
| 1596 | + return; |
|---|
| 1597 | + if (unlikely(test_and_set_bit(SCMD_STATE_COMPLETE, &cmd->state))) |
|---|
| 1598 | + return; |
|---|
| 2073 | 1599 | trace_scsi_dispatch_cmd_done(cmd); |
|---|
| 2074 | 1600 | blk_mq_complete_request(cmd->request); |
|---|
| 2075 | 1601 | } |
|---|
| 2076 | 1602 | |
|---|
| 2077 | | -static void scsi_mq_put_budget(struct blk_mq_hw_ctx *hctx) |
|---|
| 1603 | +static void scsi_mq_put_budget(struct request_queue *q) |
|---|
| 2078 | 1604 | { |
|---|
| 2079 | | - struct request_queue *q = hctx->queue; |
|---|
| 2080 | 1605 | struct scsi_device *sdev = q->queuedata; |
|---|
| 2081 | 1606 | |
|---|
| 2082 | 1607 | atomic_dec(&sdev->device_busy); |
|---|
| 2083 | | - put_device(&sdev->sdev_gendev); |
|---|
| 2084 | 1608 | } |
|---|
| 2085 | 1609 | |
|---|
| 2086 | | -static bool scsi_mq_get_budget(struct blk_mq_hw_ctx *hctx) |
|---|
| 1610 | +static bool scsi_mq_get_budget(struct request_queue *q) |
|---|
| 2087 | 1611 | { |
|---|
| 2088 | | - struct request_queue *q = hctx->queue; |
|---|
| 2089 | 1612 | struct scsi_device *sdev = q->queuedata; |
|---|
| 2090 | 1613 | |
|---|
| 2091 | | - if (!get_device(&sdev->sdev_gendev)) |
|---|
| 2092 | | - goto out; |
|---|
| 2093 | | - if (!scsi_dev_queue_ready(q, sdev)) |
|---|
| 2094 | | - goto out_put_device; |
|---|
| 1614 | + if (scsi_dev_queue_ready(q, sdev)) |
|---|
| 1615 | + return true; |
|---|
| 2095 | 1616 | |
|---|
| 2096 | | - return true; |
|---|
| 1617 | + atomic_inc(&sdev->restarts); |
|---|
| 2097 | 1618 | |
|---|
| 2098 | | -out_put_device: |
|---|
| 2099 | | - put_device(&sdev->sdev_gendev); |
|---|
| 2100 | | -out: |
|---|
| 2101 | | - if (atomic_read(&sdev->device_busy) == 0 && !scsi_device_blocked(sdev)) |
|---|
| 2102 | | - blk_mq_delay_run_hw_queue(hctx, SCSI_QUEUE_DELAY); |
|---|
| 1619 | + /* |
|---|
| 1620 | + * Orders atomic_inc(&sdev->restarts) and atomic_read(&sdev->device_busy). |
|---|
| 1621 | + * .restarts must be incremented before .device_busy is read because the |
|---|
| 1622 | + * code in scsi_run_queue_async() depends on the order of these operations. |
|---|
| 1623 | + */ |
|---|
| 1624 | + smp_mb__after_atomic(); |
|---|
| 1625 | + |
|---|
| 1626 | + /* |
|---|
| 1627 | + * If all in-flight requests originated from this LUN are completed |
|---|
| 1628 | + * before reading .device_busy, sdev->device_busy will be observed as |
|---|
| 1629 | + * zero, then blk_mq_delay_run_hw_queues() will dispatch this request |
|---|
| 1630 | + * soon. Otherwise, completion of one of these requests will observe |
|---|
| 1631 | + * the .restarts flag, and the request queue will be run for handling |
|---|
| 1632 | + * this request, see scsi_end_request(). |
|---|
| 1633 | + */ |
|---|
| 1634 | + if (unlikely(atomic_read(&sdev->device_busy) == 0 && |
|---|
| 1635 | + !scsi_device_blocked(sdev))) |
|---|
| 1636 | + blk_mq_delay_run_hw_queues(sdev->request_queue, SCSI_QUEUE_DELAY); |
|---|
| 2103 | 1637 | return false; |
|---|
| 2104 | 1638 | } |
|---|
| 2105 | 1639 | |
|---|
| .. | .. |
|---|
| 2114 | 1648 | blk_status_t ret; |
|---|
| 2115 | 1649 | int reason; |
|---|
| 2116 | 1650 | |
|---|
| 2117 | | - ret = prep_to_mq(scsi_prep_state_check(sdev, req)); |
|---|
| 2118 | | - if (ret != BLK_STS_OK) |
|---|
| 2119 | | - goto out_put_budget; |
|---|
| 1651 | + /* |
|---|
| 1652 | + * If the device is not in running state we will reject some or all |
|---|
| 1653 | + * commands. |
|---|
| 1654 | + */ |
|---|
| 1655 | + if (unlikely(sdev->sdev_state != SDEV_RUNNING)) { |
|---|
| 1656 | + ret = scsi_device_state_check(sdev, req); |
|---|
| 1657 | + if (ret != BLK_STS_OK) |
|---|
| 1658 | + goto out_put_budget; |
|---|
| 1659 | + } |
|---|
| 2120 | 1660 | |
|---|
| 2121 | 1661 | ret = BLK_STS_RESOURCE; |
|---|
| 2122 | 1662 | if (!scsi_target_queue_ready(shost, sdev)) |
|---|
| 2123 | 1663 | goto out_put_budget; |
|---|
| 2124 | | - if (!scsi_host_queue_ready(q, shost, sdev)) |
|---|
| 1664 | + if (!scsi_host_queue_ready(q, shost, sdev, cmd)) |
|---|
| 2125 | 1665 | goto out_dec_target_busy; |
|---|
| 2126 | 1666 | |
|---|
| 2127 | 1667 | if (!(req->rq_flags & RQF_DONTPREP)) { |
|---|
| 2128 | | - ret = prep_to_mq(scsi_mq_prep_fn(req)); |
|---|
| 1668 | + ret = scsi_prepare_cmd(req); |
|---|
| 2129 | 1669 | if (ret != BLK_STS_OK) |
|---|
| 2130 | 1670 | goto out_dec_host_busy; |
|---|
| 2131 | 1671 | req->rq_flags |= RQF_DONTPREP; |
|---|
| 2132 | 1672 | } else { |
|---|
| 2133 | | - blk_mq_start_request(req); |
|---|
| 1673 | + clear_bit(SCMD_STATE_COMPLETE, &cmd->state); |
|---|
| 2134 | 1674 | } |
|---|
| 2135 | 1675 | |
|---|
| 1676 | + cmd->flags &= SCMD_PRESERVED_FLAGS; |
|---|
| 2136 | 1677 | if (sdev->simple_tags) |
|---|
| 2137 | 1678 | cmd->flags |= SCMD_TAGGED; |
|---|
| 2138 | | - else |
|---|
| 2139 | | - cmd->flags &= ~SCMD_TAGGED; |
|---|
| 1679 | + if (bd->last) |
|---|
| 1680 | + cmd->flags |= SCMD_LAST; |
|---|
| 2140 | 1681 | |
|---|
| 2141 | | - scsi_init_cmd_errh(cmd); |
|---|
| 1682 | + scsi_set_resid(cmd, 0); |
|---|
| 1683 | + memset(cmd->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE); |
|---|
| 2142 | 1684 | cmd->scsi_done = scsi_mq_done; |
|---|
| 2143 | 1685 | |
|---|
| 1686 | + blk_mq_start_request(req); |
|---|
| 2144 | 1687 | reason = scsi_dispatch_cmd(cmd); |
|---|
| 2145 | 1688 | if (reason) { |
|---|
| 2146 | 1689 | scsi_set_blocked(cmd, reason); |
|---|
| .. | .. |
|---|
| 2151 | 1694 | return BLK_STS_OK; |
|---|
| 2152 | 1695 | |
|---|
| 2153 | 1696 | out_dec_host_busy: |
|---|
| 2154 | | - scsi_dec_host_busy(shost); |
|---|
| 1697 | + scsi_dec_host_busy(shost, cmd); |
|---|
| 2155 | 1698 | out_dec_target_busy: |
|---|
| 2156 | 1699 | if (scsi_target(sdev)->can_queue > 0) |
|---|
| 2157 | 1700 | atomic_dec(&scsi_target(sdev)->target_busy); |
|---|
| 2158 | 1701 | out_put_budget: |
|---|
| 2159 | | - scsi_mq_put_budget(hctx); |
|---|
| 1702 | + scsi_mq_put_budget(q); |
|---|
| 2160 | 1703 | switch (ret) { |
|---|
| 2161 | 1704 | case BLK_STS_OK: |
|---|
| 2162 | 1705 | break; |
|---|
| 2163 | 1706 | case BLK_STS_RESOURCE: |
|---|
| 2164 | | - if (atomic_read(&sdev->device_busy) || |
|---|
| 2165 | | - scsi_device_blocked(sdev)) |
|---|
| 1707 | + case BLK_STS_ZONE_RESOURCE: |
|---|
| 1708 | + if (scsi_device_blocked(sdev)) |
|---|
| 2166 | 1709 | ret = BLK_STS_DEV_RESOURCE; |
|---|
| 2167 | 1710 | break; |
|---|
| 2168 | 1711 | default: |
|---|
| .. | .. |
|---|
| 2177 | 1720 | */ |
|---|
| 2178 | 1721 | if (req->rq_flags & RQF_DONTPREP) |
|---|
| 2179 | 1722 | scsi_mq_uninit_cmd(cmd); |
|---|
| 1723 | + scsi_run_queue_async(sdev); |
|---|
| 2180 | 1724 | break; |
|---|
| 2181 | 1725 | } |
|---|
| 2182 | 1726 | return ret; |
|---|
| .. | .. |
|---|
| 2197 | 1741 | const bool unchecked_isa_dma = shost->unchecked_isa_dma; |
|---|
| 2198 | 1742 | struct scsi_cmnd *cmd = blk_mq_rq_to_pdu(rq); |
|---|
| 2199 | 1743 | struct scatterlist *sg; |
|---|
| 1744 | + int ret = 0; |
|---|
| 2200 | 1745 | |
|---|
| 2201 | 1746 | if (unchecked_isa_dma) |
|---|
| 2202 | 1747 | cmd->flags |= SCMD_UNCHECKED_ISA_DMA; |
|---|
| .. | .. |
|---|
| 2209 | 1754 | if (scsi_host_get_prot(shost)) { |
|---|
| 2210 | 1755 | sg = (void *)cmd + sizeof(struct scsi_cmnd) + |
|---|
| 2211 | 1756 | shost->hostt->cmd_size; |
|---|
| 2212 | | - cmd->prot_sdb = (void *)sg + scsi_mq_sgl_size(shost); |
|---|
| 1757 | + cmd->prot_sdb = (void *)sg + scsi_mq_inline_sgl_size(shost); |
|---|
| 2213 | 1758 | } |
|---|
| 2214 | 1759 | |
|---|
| 2215 | | - return 0; |
|---|
| 1760 | + if (shost->hostt->init_cmd_priv) { |
|---|
| 1761 | + ret = shost->hostt->init_cmd_priv(shost, cmd); |
|---|
| 1762 | + if (ret < 0) |
|---|
| 1763 | + scsi_free_sense_buffer(unchecked_isa_dma, |
|---|
| 1764 | + cmd->sense_buffer); |
|---|
| 1765 | + } |
|---|
| 1766 | + |
|---|
| 1767 | + return ret; |
|---|
| 2216 | 1768 | } |
|---|
| 2217 | 1769 | |
|---|
| 2218 | 1770 | static void scsi_mq_exit_request(struct blk_mq_tag_set *set, struct request *rq, |
|---|
| 2219 | 1771 | unsigned int hctx_idx) |
|---|
| 2220 | 1772 | { |
|---|
| 1773 | + struct Scsi_Host *shost = set->driver_data; |
|---|
| 2221 | 1774 | struct scsi_cmnd *cmd = blk_mq_rq_to_pdu(rq); |
|---|
| 2222 | 1775 | |
|---|
| 1776 | + if (shost->hostt->exit_cmd_priv) |
|---|
| 1777 | + shost->hostt->exit_cmd_priv(shost, cmd); |
|---|
| 2223 | 1778 | scsi_free_sense_buffer(cmd->flags & SCMD_UNCHECKED_ISA_DMA, |
|---|
| 2224 | 1779 | cmd->sense_buffer); |
|---|
| 2225 | 1780 | } |
|---|
| .. | .. |
|---|
| 2230 | 1785 | |
|---|
| 2231 | 1786 | if (shost->hostt->map_queues) |
|---|
| 2232 | 1787 | return shost->hostt->map_queues(shost); |
|---|
| 2233 | | - return blk_mq_map_queues(set); |
|---|
| 1788 | + return blk_mq_map_queues(&set->map[HCTX_TYPE_DEFAULT]); |
|---|
| 2234 | 1789 | } |
|---|
| 2235 | 1790 | |
|---|
| 2236 | 1791 | void __scsi_init_queue(struct Scsi_Host *shost, struct request_queue *q) |
|---|
| .. | .. |
|---|
| 2251 | 1806 | blk_queue_max_integrity_segments(q, shost->sg_prot_tablesize); |
|---|
| 2252 | 1807 | } |
|---|
| 2253 | 1808 | |
|---|
| 1809 | + if (dev->dma_mask) { |
|---|
| 1810 | + shost->max_sectors = min_t(unsigned int, shost->max_sectors, |
|---|
| 1811 | + dma_max_mapping_size(dev) >> SECTOR_SHIFT); |
|---|
| 1812 | + } |
|---|
| 2254 | 1813 | blk_queue_max_hw_sectors(q, shost->max_sectors); |
|---|
| 2255 | 1814 | if (shost->unchecked_isa_dma) |
|---|
| 2256 | 1815 | blk_queue_bounce_limit(q, BLK_BOUNCE_ISA); |
|---|
| 2257 | 1816 | blk_queue_segment_boundary(q, shost->dma_boundary); |
|---|
| 2258 | 1817 | dma_set_seg_boundary(dev, shost->dma_boundary); |
|---|
| 2259 | 1818 | |
|---|
| 2260 | | - blk_queue_max_segment_size(q, dma_get_max_seg_size(dev)); |
|---|
| 2261 | | - |
|---|
| 2262 | | - if (!shost->use_clustering) |
|---|
| 2263 | | - q->limits.cluster = 0; |
|---|
| 1819 | + blk_queue_max_segment_size(q, shost->max_segment_size); |
|---|
| 1820 | + blk_queue_virt_boundary(q, shost->virt_boundary_mask); |
|---|
| 1821 | + dma_set_max_seg_size(dev, queue_max_segment_size(q)); |
|---|
| 2264 | 1822 | |
|---|
| 2265 | 1823 | /* |
|---|
| 2266 | 1824 | * Set a reasonable default alignment: The larger of 32-byte (dword), |
|---|
| .. | .. |
|---|
| 2273 | 1831 | } |
|---|
| 2274 | 1832 | EXPORT_SYMBOL_GPL(__scsi_init_queue); |
|---|
| 2275 | 1833 | |
|---|
| 2276 | | -static int scsi_old_init_rq(struct request_queue *q, struct request *rq, |
|---|
| 2277 | | - gfp_t gfp) |
|---|
| 2278 | | -{ |
|---|
| 2279 | | - struct Scsi_Host *shost = q->rq_alloc_data; |
|---|
| 2280 | | - const bool unchecked_isa_dma = shost->unchecked_isa_dma; |
|---|
| 2281 | | - struct scsi_cmnd *cmd = blk_mq_rq_to_pdu(rq); |
|---|
| 2282 | | - |
|---|
| 2283 | | - memset(cmd, 0, sizeof(*cmd)); |
|---|
| 2284 | | - |
|---|
| 2285 | | - if (unchecked_isa_dma) |
|---|
| 2286 | | - cmd->flags |= SCMD_UNCHECKED_ISA_DMA; |
|---|
| 2287 | | - cmd->sense_buffer = scsi_alloc_sense_buffer(unchecked_isa_dma, gfp, |
|---|
| 2288 | | - NUMA_NO_NODE); |
|---|
| 2289 | | - if (!cmd->sense_buffer) |
|---|
| 2290 | | - goto fail; |
|---|
| 2291 | | - cmd->req.sense = cmd->sense_buffer; |
|---|
| 2292 | | - |
|---|
| 2293 | | - if (scsi_host_get_prot(shost) >= SHOST_DIX_TYPE0_PROTECTION) { |
|---|
| 2294 | | - cmd->prot_sdb = kmem_cache_zalloc(scsi_sdb_cache, gfp); |
|---|
| 2295 | | - if (!cmd->prot_sdb) |
|---|
| 2296 | | - goto fail_free_sense; |
|---|
| 2297 | | - } |
|---|
| 2298 | | - |
|---|
| 2299 | | - return 0; |
|---|
| 2300 | | - |
|---|
| 2301 | | -fail_free_sense: |
|---|
| 2302 | | - scsi_free_sense_buffer(unchecked_isa_dma, cmd->sense_buffer); |
|---|
| 2303 | | -fail: |
|---|
| 2304 | | - return -ENOMEM; |
|---|
| 2305 | | -} |
|---|
| 2306 | | - |
|---|
| 2307 | | -static void scsi_old_exit_rq(struct request_queue *q, struct request *rq) |
|---|
| 2308 | | -{ |
|---|
| 2309 | | - struct scsi_cmnd *cmd = blk_mq_rq_to_pdu(rq); |
|---|
| 2310 | | - |
|---|
| 2311 | | - if (cmd->prot_sdb) |
|---|
| 2312 | | - kmem_cache_free(scsi_sdb_cache, cmd->prot_sdb); |
|---|
| 2313 | | - scsi_free_sense_buffer(cmd->flags & SCMD_UNCHECKED_ISA_DMA, |
|---|
| 2314 | | - cmd->sense_buffer); |
|---|
| 2315 | | -} |
|---|
| 2316 | | - |
|---|
| 2317 | | -struct request_queue *scsi_old_alloc_queue(struct scsi_device *sdev) |
|---|
| 2318 | | -{ |
|---|
| 2319 | | - struct Scsi_Host *shost = sdev->host; |
|---|
| 2320 | | - struct request_queue *q; |
|---|
| 2321 | | - |
|---|
| 2322 | | - q = blk_alloc_queue_node(GFP_KERNEL, NUMA_NO_NODE, NULL); |
|---|
| 2323 | | - if (!q) |
|---|
| 2324 | | - return NULL; |
|---|
| 2325 | | - q->cmd_size = sizeof(struct scsi_cmnd) + shost->hostt->cmd_size; |
|---|
| 2326 | | - q->rq_alloc_data = shost; |
|---|
| 2327 | | - q->request_fn = scsi_request_fn; |
|---|
| 2328 | | - q->init_rq_fn = scsi_old_init_rq; |
|---|
| 2329 | | - q->exit_rq_fn = scsi_old_exit_rq; |
|---|
| 2330 | | - q->initialize_rq_fn = scsi_initialize_rq; |
|---|
| 2331 | | - |
|---|
| 2332 | | - if (blk_init_allocated_queue(q) < 0) { |
|---|
| 2333 | | - blk_cleanup_queue(q); |
|---|
| 2334 | | - return NULL; |
|---|
| 2335 | | - } |
|---|
| 2336 | | - |
|---|
| 2337 | | - __scsi_init_queue(shost, q); |
|---|
| 2338 | | - blk_queue_flag_set(QUEUE_FLAG_SCSI_PASSTHROUGH, q); |
|---|
| 2339 | | - blk_queue_prep_rq(q, scsi_prep_fn); |
|---|
| 2340 | | - blk_queue_unprep_rq(q, scsi_unprep_fn); |
|---|
| 2341 | | - blk_queue_softirq_done(q, scsi_softirq_done); |
|---|
| 2342 | | - blk_queue_rq_timed_out(q, scsi_times_out); |
|---|
| 2343 | | - blk_queue_lld_busy(q, scsi_lld_busy); |
|---|
| 2344 | | - return q; |
|---|
| 2345 | | -} |
|---|
| 2346 | | - |
|---|
| 2347 | | -static const struct blk_mq_ops scsi_mq_ops = { |
|---|
| 1834 | +static const struct blk_mq_ops scsi_mq_ops_no_commit = { |
|---|
| 2348 | 1835 | .get_budget = scsi_mq_get_budget, |
|---|
| 2349 | 1836 | .put_budget = scsi_mq_put_budget, |
|---|
| 2350 | 1837 | .queue_rq = scsi_queue_rq, |
|---|
| .. | .. |
|---|
| 2357 | 1844 | .exit_request = scsi_mq_exit_request, |
|---|
| 2358 | 1845 | .initialize_rq_fn = scsi_initialize_rq, |
|---|
| 2359 | 1846 | .cleanup_rq = scsi_cleanup_rq, |
|---|
| 1847 | + .busy = scsi_mq_lld_busy, |
|---|
| 1848 | + .map_queues = scsi_map_queues, |
|---|
| 1849 | +}; |
|---|
| 1850 | + |
|---|
| 1851 | + |
|---|
| 1852 | +static void scsi_commit_rqs(struct blk_mq_hw_ctx *hctx) |
|---|
| 1853 | +{ |
|---|
| 1854 | + struct request_queue *q = hctx->queue; |
|---|
| 1855 | + struct scsi_device *sdev = q->queuedata; |
|---|
| 1856 | + struct Scsi_Host *shost = sdev->host; |
|---|
| 1857 | + |
|---|
| 1858 | + shost->hostt->commit_rqs(shost, hctx->queue_num); |
|---|
| 1859 | +} |
|---|
| 1860 | + |
|---|
| 1861 | +static const struct blk_mq_ops scsi_mq_ops = { |
|---|
| 1862 | + .get_budget = scsi_mq_get_budget, |
|---|
| 1863 | + .put_budget = scsi_mq_put_budget, |
|---|
| 1864 | + .queue_rq = scsi_queue_rq, |
|---|
| 1865 | + .commit_rqs = scsi_commit_rqs, |
|---|
| 1866 | + .complete = scsi_softirq_done, |
|---|
| 1867 | + .timeout = scsi_timeout, |
|---|
| 1868 | +#ifdef CONFIG_BLK_DEBUG_FS |
|---|
| 1869 | + .show_rq = scsi_show_rq, |
|---|
| 1870 | +#endif |
|---|
| 1871 | + .init_request = scsi_mq_init_request, |
|---|
| 1872 | + .exit_request = scsi_mq_exit_request, |
|---|
| 1873 | + .initialize_rq_fn = scsi_initialize_rq, |
|---|
| 1874 | + .cleanup_rq = scsi_cleanup_rq, |
|---|
| 1875 | + .busy = scsi_mq_lld_busy, |
|---|
| 2360 | 1876 | .map_queues = scsi_map_queues, |
|---|
| 2361 | 1877 | }; |
|---|
| 2362 | 1878 | |
|---|
| .. | .. |
|---|
| 2375 | 1891 | int scsi_mq_setup_tags(struct Scsi_Host *shost) |
|---|
| 2376 | 1892 | { |
|---|
| 2377 | 1893 | unsigned int cmd_size, sgl_size; |
|---|
| 1894 | + struct blk_mq_tag_set *tag_set = &shost->tag_set; |
|---|
| 2378 | 1895 | |
|---|
| 2379 | 1896 | sgl_size = max_t(unsigned int, sizeof(struct scatterlist), |
|---|
| 2380 | | - scsi_mq_sgl_size(shost)); |
|---|
| 1897 | + scsi_mq_inline_sgl_size(shost)); |
|---|
| 2381 | 1898 | cmd_size = sizeof(struct scsi_cmnd) + shost->hostt->cmd_size + sgl_size; |
|---|
| 2382 | 1899 | if (scsi_host_get_prot(shost)) |
|---|
| 2383 | | - cmd_size += sizeof(struct scsi_data_buffer) + sgl_size; |
|---|
| 1900 | + cmd_size += sizeof(struct scsi_data_buffer) + |
|---|
| 1901 | + sizeof(struct scatterlist) * SCSI_INLINE_PROT_SG_CNT; |
|---|
| 2384 | 1902 | |
|---|
| 2385 | | - memset(&shost->tag_set, 0, sizeof(shost->tag_set)); |
|---|
| 2386 | | - shost->tag_set.ops = &scsi_mq_ops; |
|---|
| 2387 | | - shost->tag_set.nr_hw_queues = shost->nr_hw_queues ? : 1; |
|---|
| 2388 | | - shost->tag_set.queue_depth = shost->can_queue; |
|---|
| 2389 | | - shost->tag_set.cmd_size = cmd_size; |
|---|
| 2390 | | - shost->tag_set.numa_node = NUMA_NO_NODE; |
|---|
| 2391 | | - shost->tag_set.flags = BLK_MQ_F_SHOULD_MERGE | BLK_MQ_F_SG_MERGE; |
|---|
| 2392 | | - shost->tag_set.flags |= |
|---|
| 1903 | + memset(tag_set, 0, sizeof(*tag_set)); |
|---|
| 1904 | + if (shost->hostt->commit_rqs) |
|---|
| 1905 | + tag_set->ops = &scsi_mq_ops; |
|---|
| 1906 | + else |
|---|
| 1907 | + tag_set->ops = &scsi_mq_ops_no_commit; |
|---|
| 1908 | + tag_set->nr_hw_queues = shost->nr_hw_queues ? : 1; |
|---|
| 1909 | + tag_set->queue_depth = shost->can_queue; |
|---|
| 1910 | + tag_set->cmd_size = cmd_size; |
|---|
| 1911 | + tag_set->numa_node = NUMA_NO_NODE; |
|---|
| 1912 | + tag_set->flags = BLK_MQ_F_SHOULD_MERGE; |
|---|
| 1913 | + tag_set->flags |= |
|---|
| 2393 | 1914 | BLK_ALLOC_POLICY_TO_MQ_FLAG(shost->hostt->tag_alloc_policy); |
|---|
| 2394 | | - shost->tag_set.driver_data = shost; |
|---|
| 1915 | + tag_set->driver_data = shost; |
|---|
| 1916 | + if (shost->host_tagset) |
|---|
| 1917 | + tag_set->flags |= BLK_MQ_F_TAG_HCTX_SHARED; |
|---|
| 2395 | 1918 | |
|---|
| 2396 | | - return blk_mq_alloc_tag_set(&shost->tag_set); |
|---|
| 1919 | + return blk_mq_alloc_tag_set(tag_set); |
|---|
| 2397 | 1920 | } |
|---|
| 2398 | 1921 | |
|---|
| 2399 | 1922 | void scsi_mq_destroy_tags(struct Scsi_Host *shost) |
|---|
| .. | .. |
|---|
| 2412 | 1935 | { |
|---|
| 2413 | 1936 | struct scsi_device *sdev = NULL; |
|---|
| 2414 | 1937 | |
|---|
| 2415 | | - if (q->mq_ops) { |
|---|
| 2416 | | - if (q->mq_ops == &scsi_mq_ops) |
|---|
| 2417 | | - sdev = q->queuedata; |
|---|
| 2418 | | - } else if (q->request_fn == scsi_request_fn) |
|---|
| 1938 | + if (q->mq_ops == &scsi_mq_ops_no_commit || |
|---|
| 1939 | + q->mq_ops == &scsi_mq_ops) |
|---|
| 2419 | 1940 | sdev = q->queuedata; |
|---|
| 2420 | 1941 | if (!sdev || !get_device(&sdev->sdev_gendev)) |
|---|
| 2421 | 1942 | sdev = NULL; |
|---|
| 2422 | 1943 | |
|---|
| 2423 | 1944 | return sdev; |
|---|
| 2424 | 1945 | } |
|---|
| 2425 | | -EXPORT_SYMBOL_GPL(scsi_device_from_queue); |
|---|
| 2426 | 1946 | |
|---|
| 2427 | | -/* |
|---|
| 2428 | | - * Function: scsi_block_requests() |
|---|
| 1947 | +/** |
|---|
| 1948 | + * scsi_block_requests - Utility function used by low-level drivers to prevent |
|---|
| 1949 | + * further commands from being queued to the device. |
|---|
| 1950 | + * @shost: host in question |
|---|
| 2429 | 1951 | * |
|---|
| 2430 | | - * Purpose: Utility function used by low-level drivers to prevent further |
|---|
| 2431 | | - * commands from being queued to the device. |
|---|
| 2432 | | - * |
|---|
| 2433 | | - * Arguments: shost - Host in question |
|---|
| 2434 | | - * |
|---|
| 2435 | | - * Returns: Nothing |
|---|
| 2436 | | - * |
|---|
| 2437 | | - * Lock status: No locks are assumed held. |
|---|
| 2438 | | - * |
|---|
| 2439 | | - * Notes: There is no timer nor any other means by which the requests |
|---|
| 2440 | | - * get unblocked other than the low-level driver calling |
|---|
| 2441 | | - * scsi_unblock_requests(). |
|---|
| 1952 | + * There is no timer nor any other means by which the requests get unblocked |
|---|
| 1953 | + * other than the low-level driver calling scsi_unblock_requests(). |
|---|
| 2442 | 1954 | */ |
|---|
| 2443 | 1955 | void scsi_block_requests(struct Scsi_Host *shost) |
|---|
| 2444 | 1956 | { |
|---|
| .. | .. |
|---|
| 2446 | 1958 | } |
|---|
| 2447 | 1959 | EXPORT_SYMBOL(scsi_block_requests); |
|---|
| 2448 | 1960 | |
|---|
| 2449 | | -/* |
|---|
| 2450 | | - * Function: scsi_unblock_requests() |
|---|
| 1961 | +/** |
|---|
| 1962 | + * scsi_unblock_requests - Utility function used by low-level drivers to allow |
|---|
| 1963 | + * further commands to be queued to the device. |
|---|
| 1964 | + * @shost: host in question |
|---|
| 2451 | 1965 | * |
|---|
| 2452 | | - * Purpose: Utility function used by low-level drivers to allow further |
|---|
| 2453 | | - * commands from being queued to the device. |
|---|
| 2454 | | - * |
|---|
| 2455 | | - * Arguments: shost - Host in question |
|---|
| 2456 | | - * |
|---|
| 2457 | | - * Returns: Nothing |
|---|
| 2458 | | - * |
|---|
| 2459 | | - * Lock status: No locks are assumed held. |
|---|
| 2460 | | - * |
|---|
| 2461 | | - * Notes: There is no timer nor any other means by which the requests |
|---|
| 2462 | | - * get unblocked other than the low-level driver calling |
|---|
| 2463 | | - * scsi_unblock_requests(). |
|---|
| 2464 | | - * |
|---|
| 2465 | | - * This is done as an API function so that changes to the |
|---|
| 2466 | | - * internals of the scsi mid-layer won't require wholesale |
|---|
| 2467 | | - * changes to drivers that use this feature. |
|---|
| 1966 | + * There is no timer nor any other means by which the requests get unblocked |
|---|
| 1967 | + * other than the low-level driver calling scsi_unblock_requests(). This is done |
|---|
| 1968 | + * as an API function so that changes to the internals of the scsi mid-layer |
|---|
| 1969 | + * won't require wholesale changes to drivers that use this feature. |
|---|
| 2468 | 1970 | */ |
|---|
| 2469 | 1971 | void scsi_unblock_requests(struct Scsi_Host *shost) |
|---|
| 2470 | 1972 | { |
|---|
| .. | .. |
|---|
| 2473 | 1975 | } |
|---|
| 2474 | 1976 | EXPORT_SYMBOL(scsi_unblock_requests); |
|---|
| 2475 | 1977 | |
|---|
| 2476 | | -/* |
|---|
| 2477 | | - * Function: scsi_set_cmd_timeout_override() |
|---|
| 2478 | | - * |
|---|
| 2479 | | - * Purpose: Utility function used by low-level drivers to override |
|---|
| 2480 | | - timeout for the scsi commands. |
|---|
| 2481 | | - * |
|---|
| 2482 | | - * Arguments: sdev - scsi device in question |
|---|
| 2483 | | - * timeout - timeout in jiffies |
|---|
| 2484 | | - * |
|---|
| 2485 | | - * Returns: Nothing |
|---|
| 2486 | | - * |
|---|
| 2487 | | - * Lock status: No locks are assumed held. |
|---|
| 2488 | | - * |
|---|
| 2489 | | - * Notes: Some platforms might be very slow and command completion may |
|---|
| 2490 | | - * take much longer than default scsi command timeouts. |
|---|
| 2491 | | - * SCSI Read/Write command timeout can be changed by |
|---|
| 2492 | | - * blk_queue_rq_timeout() but there is no option to override |
|---|
| 2493 | | - * timeout for rest of the scsi commands. This function would |
|---|
| 2494 | | - * would allow this. |
|---|
| 2495 | | - */ |
|---|
| 2496 | | -void scsi_set_cmd_timeout_override(struct scsi_device *sdev, |
|---|
| 2497 | | - unsigned int timeout) |
|---|
| 2498 | | -{ |
|---|
| 2499 | | - sdev->timeout_override = timeout; |
|---|
| 2500 | | -} |
|---|
| 2501 | | -EXPORT_SYMBOL(scsi_set_cmd_timeout_override); |
|---|
| 2502 | | - |
|---|
| 2503 | | -int __init scsi_init_queue(void) |
|---|
| 2504 | | -{ |
|---|
| 2505 | | - scsi_sdb_cache = kmem_cache_create("scsi_data_buffer", |
|---|
| 2506 | | - sizeof(struct scsi_data_buffer), |
|---|
| 2507 | | - 0, 0, NULL); |
|---|
| 2508 | | - if (!scsi_sdb_cache) { |
|---|
| 2509 | | - printk(KERN_ERR "SCSI: can't init scsi sdb cache\n"); |
|---|
| 2510 | | - return -ENOMEM; |
|---|
| 2511 | | - } |
|---|
| 2512 | | - |
|---|
| 2513 | | - return 0; |
|---|
| 2514 | | -} |
|---|
| 2515 | | - |
|---|
| 2516 | 1978 | void scsi_exit_queue(void) |
|---|
| 2517 | 1979 | { |
|---|
| 2518 | 1980 | kmem_cache_destroy(scsi_sense_cache); |
|---|
| 2519 | 1981 | kmem_cache_destroy(scsi_sense_isadma_cache); |
|---|
| 2520 | | - kmem_cache_destroy(scsi_sdb_cache); |
|---|
| 2521 | 1982 | } |
|---|
| 2522 | 1983 | |
|---|
| 2523 | 1984 | /** |
|---|
| .. | .. |
|---|
| 2584 | 2045 | real_buffer[1] = data->medium_type; |
|---|
| 2585 | 2046 | real_buffer[2] = data->device_specific; |
|---|
| 2586 | 2047 | real_buffer[3] = data->block_descriptor_length; |
|---|
| 2587 | | - |
|---|
| 2588 | 2048 | |
|---|
| 2589 | 2049 | cmd[0] = MODE_SELECT; |
|---|
| 2590 | 2050 | cmd[4] = len; |
|---|
| .. | .. |
|---|
| 2610 | 2070 | * @sshdr: place to put sense data (or NULL if no sense to be collected). |
|---|
| 2611 | 2071 | * must be SCSI_SENSE_BUFFERSIZE big. |
|---|
| 2612 | 2072 | * |
|---|
| 2613 | | - * Returns zero if unsuccessful, or the header offset (either 4 |
|---|
| 2614 | | - * or 8 depending on whether a six or ten byte command was |
|---|
| 2615 | | - * issued) if successful. |
|---|
| 2073 | + * Returns zero if successful, or a negative error number on failure |
|---|
| 2616 | 2074 | */ |
|---|
| 2617 | 2075 | int |
|---|
| 2618 | 2076 | scsi_mode_sense(struct scsi_device *sdev, int dbd, int modepage, |
|---|
| .. | .. |
|---|
| 2627 | 2085 | |
|---|
| 2628 | 2086 | memset(data, 0, sizeof(*data)); |
|---|
| 2629 | 2087 | memset(&cmd[0], 0, 12); |
|---|
| 2088 | + |
|---|
| 2089 | + dbd = sdev->set_dbd_for_ms ? 8 : dbd; |
|---|
| 2630 | 2090 | cmd[1] = dbd & 0x18; /* allows DBD and LLBA bits */ |
|---|
| 2631 | 2091 | cmd[2] = modepage; |
|---|
| 2632 | 2092 | |
|---|
| .. | .. |
|---|
| 2657 | 2117 | |
|---|
| 2658 | 2118 | result = scsi_execute_req(sdev, cmd, DMA_FROM_DEVICE, buffer, len, |
|---|
| 2659 | 2119 | sshdr, timeout, retries, NULL); |
|---|
| 2120 | + if (result < 0) |
|---|
| 2121 | + return result; |
|---|
| 2660 | 2122 | |
|---|
| 2661 | 2123 | /* This code looks awful: what it's doing is making sure an |
|---|
| 2662 | 2124 | * ILLEGAL REQUEST sense return identifies the actual command |
|---|
| .. | .. |
|---|
| 2668 | 2130 | if (scsi_sense_valid(sshdr)) { |
|---|
| 2669 | 2131 | if ((sshdr->sense_key == ILLEGAL_REQUEST) && |
|---|
| 2670 | 2132 | (sshdr->asc == 0x20) && (sshdr->ascq == 0)) { |
|---|
| 2671 | | - /* |
|---|
| 2133 | + /* |
|---|
| 2672 | 2134 | * Invalid command operation code |
|---|
| 2673 | 2135 | */ |
|---|
| 2674 | 2136 | sdev->use_10_for_ms = 0; |
|---|
| .. | .. |
|---|
| 2677 | 2139 | } |
|---|
| 2678 | 2140 | } |
|---|
| 2679 | 2141 | |
|---|
| 2680 | | - if(scsi_status_is_good(result)) { |
|---|
| 2142 | + if (scsi_status_is_good(result)) { |
|---|
| 2681 | 2143 | if (unlikely(buffer[0] == 0x86 && buffer[1] == 0x0b && |
|---|
| 2682 | 2144 | (modepage == 6 || modepage == 8))) { |
|---|
| 2683 | 2145 | /* Initio breakage? */ |
|---|
| .. | .. |
|---|
| 2687 | 2149 | data->device_specific = 0; |
|---|
| 2688 | 2150 | data->longlba = 0; |
|---|
| 2689 | 2151 | data->block_descriptor_length = 0; |
|---|
| 2690 | | - } else if(use_10_for_ms) { |
|---|
| 2152 | + } else if (use_10_for_ms) { |
|---|
| 2691 | 2153 | data->length = buffer[0]*256 + buffer[1] + 2; |
|---|
| 2692 | 2154 | data->medium_type = buffer[2]; |
|---|
| 2693 | 2155 | data->device_specific = buffer[3]; |
|---|
| .. | .. |
|---|
| 2701 | 2163 | data->block_descriptor_length = buffer[3]; |
|---|
| 2702 | 2164 | } |
|---|
| 2703 | 2165 | data->header_length = header_length; |
|---|
| 2166 | + result = 0; |
|---|
| 2704 | 2167 | } else if ((status_byte(result) == CHECK_CONDITION) && |
|---|
| 2705 | 2168 | scsi_sense_valid(sshdr) && |
|---|
| 2706 | 2169 | sshdr->sense_key == UNIT_ATTENTION && retry_count) { |
|---|
| 2707 | 2170 | retry_count--; |
|---|
| 2708 | 2171 | goto retry; |
|---|
| 2709 | 2172 | } |
|---|
| 2710 | | - |
|---|
| 2173 | + if (result > 0) |
|---|
| 2174 | + result = -EIO; |
|---|
| 2711 | 2175 | return result; |
|---|
| 2712 | 2176 | } |
|---|
| 2713 | 2177 | EXPORT_SYMBOL(scsi_mode_sense); |
|---|
| .. | .. |
|---|
| 2770 | 2234 | goto illegal; |
|---|
| 2771 | 2235 | } |
|---|
| 2772 | 2236 | break; |
|---|
| 2773 | | - |
|---|
| 2237 | + |
|---|
| 2774 | 2238 | case SDEV_RUNNING: |
|---|
| 2775 | 2239 | switch (oldstate) { |
|---|
| 2776 | 2240 | case SDEV_CREATED: |
|---|
| .. | .. |
|---|
| 2812 | 2276 | switch (oldstate) { |
|---|
| 2813 | 2277 | case SDEV_RUNNING: |
|---|
| 2814 | 2278 | case SDEV_CREATED_BLOCK: |
|---|
| 2279 | + case SDEV_QUIESCE: |
|---|
| 2280 | + case SDEV_OFFLINE: |
|---|
| 2815 | 2281 | break; |
|---|
| 2816 | 2282 | default: |
|---|
| 2817 | 2283 | goto illegal; |
|---|
| .. | .. |
|---|
| 2856 | 2322 | break; |
|---|
| 2857 | 2323 | |
|---|
| 2858 | 2324 | } |
|---|
| 2325 | + sdev->offline_already = false; |
|---|
| 2859 | 2326 | sdev->sdev_state = state; |
|---|
| 2860 | 2327 | return 0; |
|---|
| 2861 | 2328 | |
|---|
| .. | .. |
|---|
| 3045 | 2512 | EXPORT_SYMBOL_GPL(sdev_evt_send_simple); |
|---|
| 3046 | 2513 | |
|---|
| 3047 | 2514 | /** |
|---|
| 3048 | | - * scsi_request_fn_active() - number of kernel threads inside scsi_request_fn() |
|---|
| 3049 | | - * @sdev: SCSI device to count the number of scsi_request_fn() callers for. |
|---|
| 3050 | | - */ |
|---|
| 3051 | | -static int scsi_request_fn_active(struct scsi_device *sdev) |
|---|
| 3052 | | -{ |
|---|
| 3053 | | - struct request_queue *q = sdev->request_queue; |
|---|
| 3054 | | - int request_fn_active; |
|---|
| 3055 | | - |
|---|
| 3056 | | - WARN_ON_ONCE(sdev->host->use_blk_mq); |
|---|
| 3057 | | - |
|---|
| 3058 | | - spin_lock_irq(q->queue_lock); |
|---|
| 3059 | | - request_fn_active = q->request_fn_active; |
|---|
| 3060 | | - spin_unlock_irq(q->queue_lock); |
|---|
| 3061 | | - |
|---|
| 3062 | | - return request_fn_active; |
|---|
| 3063 | | -} |
|---|
| 3064 | | - |
|---|
| 3065 | | -/** |
|---|
| 3066 | | - * scsi_wait_for_queuecommand() - wait for ongoing queuecommand() calls |
|---|
| 3067 | | - * @sdev: SCSI device pointer. |
|---|
| 3068 | | - * |
|---|
| 3069 | | - * Wait until the ongoing shost->hostt->queuecommand() calls that are |
|---|
| 3070 | | - * invoked from scsi_request_fn() have finished. |
|---|
| 3071 | | - */ |
|---|
| 3072 | | -static void scsi_wait_for_queuecommand(struct scsi_device *sdev) |
|---|
| 3073 | | -{ |
|---|
| 3074 | | - WARN_ON_ONCE(sdev->host->use_blk_mq); |
|---|
| 3075 | | - |
|---|
| 3076 | | - while (scsi_request_fn_active(sdev)) |
|---|
| 3077 | | - msleep(20); |
|---|
| 3078 | | -} |
|---|
| 3079 | | - |
|---|
| 3080 | | -/** |
|---|
| 3081 | | - * scsi_device_quiesce - Block user issued commands. |
|---|
| 2515 | + * scsi_device_quiesce - Block all commands except power management. |
|---|
| 3082 | 2516 | * @sdev: scsi device to quiesce. |
|---|
| 3083 | 2517 | * |
|---|
| 3084 | 2518 | * This works by trying to transition to the SDEV_QUIESCE state |
|---|
| 3085 | 2519 | * (which must be a legal transition). When the device is in this |
|---|
| 3086 | | - * state, only special requests will be accepted, all others will |
|---|
| 3087 | | - * be deferred. Since special requests may also be requeued requests, |
|---|
| 3088 | | - * a successful return doesn't guarantee the device will be |
|---|
| 3089 | | - * totally quiescent. |
|---|
| 2520 | + * state, only power management requests will be accepted, all others will |
|---|
| 2521 | + * be deferred. |
|---|
| 3090 | 2522 | * |
|---|
| 3091 | 2523 | * Must be called with user context, may sleep. |
|---|
| 3092 | 2524 | * |
|---|
| .. | .. |
|---|
| 3148 | 2580 | * device deleted during suspend) |
|---|
| 3149 | 2581 | */ |
|---|
| 3150 | 2582 | mutex_lock(&sdev->state_mutex); |
|---|
| 2583 | + if (sdev->sdev_state == SDEV_QUIESCE) |
|---|
| 2584 | + scsi_device_set_state(sdev, SDEV_RUNNING); |
|---|
| 3151 | 2585 | if (sdev->quiesced_by) { |
|---|
| 3152 | 2586 | sdev->quiesced_by = NULL; |
|---|
| 3153 | 2587 | blk_clear_pm_only(sdev->request_queue); |
|---|
| 3154 | 2588 | } |
|---|
| 3155 | | - if (sdev->sdev_state == SDEV_QUIESCE) |
|---|
| 3156 | | - scsi_device_set_state(sdev, SDEV_RUNNING); |
|---|
| 3157 | 2589 | mutex_unlock(&sdev->state_mutex); |
|---|
| 3158 | 2590 | } |
|---|
| 3159 | 2591 | EXPORT_SYMBOL(scsi_device_resume); |
|---|
| .. | .. |
|---|
| 3201 | 2633 | int scsi_internal_device_block_nowait(struct scsi_device *sdev) |
|---|
| 3202 | 2634 | { |
|---|
| 3203 | 2635 | struct request_queue *q = sdev->request_queue; |
|---|
| 3204 | | - unsigned long flags; |
|---|
| 3205 | 2636 | int err = 0; |
|---|
| 3206 | 2637 | |
|---|
| 3207 | 2638 | err = scsi_device_set_state(sdev, SDEV_BLOCK); |
|---|
| .. | .. |
|---|
| 3212 | 2643 | return err; |
|---|
| 3213 | 2644 | } |
|---|
| 3214 | 2645 | |
|---|
| 3215 | | - /* |
|---|
| 2646 | + /* |
|---|
| 3216 | 2647 | * The device has transitioned to SDEV_BLOCK. Stop the |
|---|
| 3217 | 2648 | * block layer from calling the midlayer with this device's |
|---|
| 3218 | | - * request queue. |
|---|
| 2649 | + * request queue. |
|---|
| 3219 | 2650 | */ |
|---|
| 3220 | | - if (q->mq_ops) { |
|---|
| 3221 | | - blk_mq_quiesce_queue_nowait(q); |
|---|
| 3222 | | - } else { |
|---|
| 3223 | | - spin_lock_irqsave(q->queue_lock, flags); |
|---|
| 3224 | | - blk_stop_queue(q); |
|---|
| 3225 | | - spin_unlock_irqrestore(q->queue_lock, flags); |
|---|
| 3226 | | - } |
|---|
| 3227 | | - |
|---|
| 2651 | + blk_mq_quiesce_queue_nowait(q); |
|---|
| 3228 | 2652 | return 0; |
|---|
| 3229 | 2653 | } |
|---|
| 3230 | 2654 | EXPORT_SYMBOL_GPL(scsi_internal_device_block_nowait); |
|---|
| .. | .. |
|---|
| 3243 | 2667 | * a legal transition). When the device is in this state, command processing |
|---|
| 3244 | 2668 | * is paused until the device leaves the SDEV_BLOCK state. See also |
|---|
| 3245 | 2669 | * scsi_internal_device_unblock(). |
|---|
| 3246 | | - * |
|---|
| 3247 | | - * To do: avoid that scsi_send_eh_cmnd() calls queuecommand() after |
|---|
| 3248 | | - * scsi_internal_device_block() has blocked a SCSI device and also |
|---|
| 3249 | | - * remove the rport mutex lock and unlock calls from srp_queuecommand(). |
|---|
| 3250 | 2670 | */ |
|---|
| 3251 | 2671 | static int scsi_internal_device_block(struct scsi_device *sdev) |
|---|
| 3252 | 2672 | { |
|---|
| .. | .. |
|---|
| 3255 | 2675 | |
|---|
| 3256 | 2676 | mutex_lock(&sdev->state_mutex); |
|---|
| 3257 | 2677 | err = scsi_internal_device_block_nowait(sdev); |
|---|
| 3258 | | - if (err == 0) { |
|---|
| 3259 | | - if (q->mq_ops) |
|---|
| 3260 | | - blk_mq_quiesce_queue(q); |
|---|
| 3261 | | - else |
|---|
| 3262 | | - scsi_wait_for_queuecommand(sdev); |
|---|
| 3263 | | - } |
|---|
| 2678 | + if (err == 0) |
|---|
| 2679 | + blk_mq_quiesce_queue(q); |
|---|
| 3264 | 2680 | mutex_unlock(&sdev->state_mutex); |
|---|
| 3265 | 2681 | |
|---|
| 3266 | 2682 | return err; |
|---|
| 3267 | 2683 | } |
|---|
| 3268 | | - |
|---|
| 2684 | + |
|---|
| 3269 | 2685 | void scsi_start_queue(struct scsi_device *sdev) |
|---|
| 3270 | 2686 | { |
|---|
| 3271 | 2687 | struct request_queue *q = sdev->request_queue; |
|---|
| 3272 | | - unsigned long flags; |
|---|
| 3273 | 2688 | |
|---|
| 3274 | | - if (q->mq_ops) { |
|---|
| 3275 | | - blk_mq_unquiesce_queue(q); |
|---|
| 3276 | | - } else { |
|---|
| 3277 | | - spin_lock_irqsave(q->queue_lock, flags); |
|---|
| 3278 | | - blk_start_queue(q); |
|---|
| 3279 | | - spin_unlock_irqrestore(q->queue_lock, flags); |
|---|
| 3280 | | - } |
|---|
| 2689 | + blk_mq_unquiesce_queue(q); |
|---|
| 3281 | 2690 | } |
|---|
| 3282 | 2691 | |
|---|
| 3283 | 2692 | /** |
|---|
| .. | .. |
|---|
| 3298 | 2707 | int scsi_internal_device_unblock_nowait(struct scsi_device *sdev, |
|---|
| 3299 | 2708 | enum scsi_device_state new_state) |
|---|
| 3300 | 2709 | { |
|---|
| 2710 | + switch (new_state) { |
|---|
| 2711 | + case SDEV_RUNNING: |
|---|
| 2712 | + case SDEV_TRANSPORT_OFFLINE: |
|---|
| 2713 | + break; |
|---|
| 2714 | + default: |
|---|
| 2715 | + return -EINVAL; |
|---|
| 2716 | + } |
|---|
| 2717 | + |
|---|
| 3301 | 2718 | /* |
|---|
| 3302 | 2719 | * Try to transition the scsi device to SDEV_RUNNING or one of the |
|---|
| 3303 | 2720 | * offlined states and goose the device queue if successful. |
|---|
| .. | .. |
|---|
| 3355 | 2772 | static void |
|---|
| 3356 | 2773 | device_block(struct scsi_device *sdev, void *data) |
|---|
| 3357 | 2774 | { |
|---|
| 3358 | | - scsi_internal_device_block(sdev); |
|---|
| 2775 | + int ret; |
|---|
| 2776 | + |
|---|
| 2777 | + ret = scsi_internal_device_block(sdev); |
|---|
| 2778 | + |
|---|
| 2779 | + WARN_ONCE(ret, "scsi_internal_device_block(%s) failed: ret = %d\n", |
|---|
| 2780 | + dev_name(&sdev->sdev_gendev), ret); |
|---|
| 3359 | 2781 | } |
|---|
| 3360 | 2782 | |
|---|
| 3361 | 2783 | static int |
|---|
| .. | .. |
|---|
| 3404 | 2826 | } |
|---|
| 3405 | 2827 | EXPORT_SYMBOL_GPL(scsi_target_unblock); |
|---|
| 3406 | 2828 | |
|---|
| 2829 | +int |
|---|
| 2830 | +scsi_host_block(struct Scsi_Host *shost) |
|---|
| 2831 | +{ |
|---|
| 2832 | + struct scsi_device *sdev; |
|---|
| 2833 | + int ret = 0; |
|---|
| 2834 | + |
|---|
| 2835 | + /* |
|---|
| 2836 | + * Call scsi_internal_device_block_nowait so we can avoid |
|---|
| 2837 | + * calling synchronize_rcu() for each LUN. |
|---|
| 2838 | + */ |
|---|
| 2839 | + shost_for_each_device(sdev, shost) { |
|---|
| 2840 | + mutex_lock(&sdev->state_mutex); |
|---|
| 2841 | + ret = scsi_internal_device_block_nowait(sdev); |
|---|
| 2842 | + mutex_unlock(&sdev->state_mutex); |
|---|
| 2843 | + if (ret) { |
|---|
| 2844 | + scsi_device_put(sdev); |
|---|
| 2845 | + break; |
|---|
| 2846 | + } |
|---|
| 2847 | + } |
|---|
| 2848 | + |
|---|
| 2849 | + /* |
|---|
| 2850 | + * SCSI never enables blk-mq's BLK_MQ_F_BLOCKING flag so |
|---|
| 2851 | + * calling synchronize_rcu() once is enough. |
|---|
| 2852 | + */ |
|---|
| 2853 | + WARN_ON_ONCE(shost->tag_set.flags & BLK_MQ_F_BLOCKING); |
|---|
| 2854 | + |
|---|
| 2855 | + if (!ret) |
|---|
| 2856 | + synchronize_rcu(); |
|---|
| 2857 | + |
|---|
| 2858 | + return ret; |
|---|
| 2859 | +} |
|---|
| 2860 | +EXPORT_SYMBOL_GPL(scsi_host_block); |
|---|
| 2861 | + |
|---|
| 2862 | +int |
|---|
| 2863 | +scsi_host_unblock(struct Scsi_Host *shost, int new_state) |
|---|
| 2864 | +{ |
|---|
| 2865 | + struct scsi_device *sdev; |
|---|
| 2866 | + int ret = 0; |
|---|
| 2867 | + |
|---|
| 2868 | + shost_for_each_device(sdev, shost) { |
|---|
| 2869 | + ret = scsi_internal_device_unblock(sdev, new_state); |
|---|
| 2870 | + if (ret) { |
|---|
| 2871 | + scsi_device_put(sdev); |
|---|
| 2872 | + break; |
|---|
| 2873 | + } |
|---|
| 2874 | + } |
|---|
| 2875 | + return ret; |
|---|
| 2876 | +} |
|---|
| 2877 | +EXPORT_SYMBOL_GPL(scsi_host_unblock); |
|---|
| 2878 | + |
|---|
| 3407 | 2879 | /** |
|---|
| 3408 | 2880 | * scsi_kmap_atomic_sg - find and atomically map an sg-elemnt |
|---|
| 3409 | 2881 | * @sgl: scatter-gather list |
|---|