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

Configure Feed

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

Merge branch 'for-3.4/drivers' of git://git.kernel.dk/linux-block

Pull block driver bits from Jens Axboe:

- A series of fixes for mtip32xx. Most from Asai at Micron, but also
one from Greg, getting rid of the dependency on PCIE_HOTPLUG.

- A few bug fixes for xen-blkfront, and blkback.

- A virtio-blk fix for Vivek, making resize actually work.

- Two fixes from Stephen, making larger transfers possible on cciss.
This is needed for tape drive support.

* 'for-3.4/drivers' of git://git.kernel.dk/linux-block:
block: mtip32xx: remove HOTPLUG_PCI_PCIE dependancy
mtip32xx: dump tagmap on failure
mtip32xx: fix handling of commands in various scenarios
mtip32xx: Shorten macro names
mtip32xx: misc changes
mtip32xx: Add new sysfs entry 'status'
mtip32xx: make setting comp_time as common
mtip32xx: Add new bitwise flag 'dd_flag'
mtip32xx: fix error handling in mtip_init()
virtio-blk: Call revalidate_disk() upon online disk resize
xen/blkback: Make optional features be really optional.
xen/blkback: Squash the discard support for 'file' and 'phy' type.
mtip32xx: fix incorrect value set for drv_cleanup_done, and re-initialize and start port in mtip_restart_port()
cciss: Fix scsi tape io with more than 255 scatter gather elements
cciss: Initialize scsi host max_sectors for tape drive support
xen-blkfront: make blkif_io_lock spinlock per-device
xen/blkfront: don't put bdev right after getting it
xen-blkfront: use bitmap_set() and bitmap_clear()
xen/blkback: Enable blkback on HVM guests
xen/blkback: use grant-table.c hypercall wrappers

+797 -333
+18
Documentation/ABI/testing/sysfs-block-rssd
··· 1 + What: /sys/block/rssd*/registers 2 + Date: March 2012 3 + KernelVersion: 3.3 4 + Contact: Asai Thambi S P <asamymuthupa@micron.com> 5 + Description: This is a read-only file. Dumps below driver information and 6 + hardware registers. 7 + - S ACTive 8 + - Command Issue 9 + - Allocated 10 + - Completed 11 + - PORT IRQ STAT 12 + - HOST IRQ STAT 13 + 14 + What: /sys/block/rssd*/status 15 + Date: April 2012 16 + KernelVersion: 3.4 17 + Contact: Asai Thambi S P <asamymuthupa@micron.com> 18 + Description: This is a read-only file. Indicates the status of the device.
+2 -1
drivers/block/cciss_scsi.c
··· 866 866 sh->can_queue = cciss_tape_cmds; 867 867 sh->sg_tablesize = h->maxsgentries; 868 868 sh->max_cmd_len = MAX_COMMAND_SIZE; 869 + sh->max_sectors = h->cciss_max_sectors; 869 870 870 871 ((struct cciss_scsi_adapter_data_t *) 871 872 h->scsi_ctlr)->scsi_host = sh; ··· 1411 1410 /* track how many SG entries we are using */ 1412 1411 if (request_nsgs > h->maxSG) 1413 1412 h->maxSG = request_nsgs; 1414 - c->Header.SGTotal = (__u8) request_nsgs + chained; 1413 + c->Header.SGTotal = (u16) request_nsgs + chained; 1415 1414 if (request_nsgs > h->max_cmd_sgentries) 1416 1415 c->Header.SGList = h->max_cmd_sgentries; 1417 1416 else
+1 -1
drivers/block/mtip32xx/Kconfig
··· 4 4 5 5 config BLK_DEV_PCIESSD_MTIP32XX 6 6 tristate "Block Device Driver for Micron PCIe SSDs" 7 - depends on HOTPLUG_PCI_PCIE 7 + depends on PCI 8 8 help 9 9 This enables the block driver for Micron PCIe SSDs.
+664 -196
drivers/block/mtip32xx/mtip32xx.c
··· 36 36 #include <linux/idr.h> 37 37 #include <linux/kthread.h> 38 38 #include <../drivers/ata/ahci.h> 39 + #include <linux/export.h> 39 40 #include "mtip32xx.h" 40 41 41 42 #define HW_CMD_SLOT_SZ (MTIP_MAX_COMMAND_SLOTS * 32) ··· 45 44 #define HW_PORT_PRIV_DMA_SZ \ 46 45 (HW_CMD_SLOT_SZ + HW_CMD_TBL_AR_SZ + AHCI_RX_FIS_SZ) 47 46 47 + #define HOST_CAP_NZDMA (1 << 19) 48 48 #define HOST_HSORG 0xFC 49 49 #define HSORG_DISABLE_SLOTGRP_INTR (1<<24) 50 50 #define HSORG_DISABLE_SLOTGRP_PXIS (1<<16) ··· 141 139 int group = 0, commandslot = 0, commandindex = 0; 142 140 struct mtip_cmd *command; 143 141 struct mtip_port *port = dd->port; 142 + static int in_progress; 143 + 144 + if (in_progress) 145 + return; 146 + 147 + in_progress = 1; 144 148 145 149 for (group = 0; group < 4; group++) { 146 150 for (commandslot = 0; commandslot < 32; commandslot++) { ··· 173 165 174 166 up(&port->cmd_slot); 175 167 176 - atomic_set(&dd->drv_cleanup_done, true); 168 + set_bit(MTIP_DDF_CLEANUP_BIT, &dd->dd_flag); 169 + in_progress = 0; 177 170 } 178 171 179 172 /* ··· 271 262 && time_before(jiffies, timeout)) 272 263 mdelay(1); 273 264 265 + if (test_bit(MTIP_DDF_REMOVE_PENDING_BIT, &dd->dd_flag)) 266 + return -1; 267 + 274 268 if (readl(dd->mmio + HOST_CTL) & HOST_RESET) 275 269 return -1; 276 270 ··· 306 294 port->cmd_issue[MTIP_TAG_INDEX(tag)]); 307 295 308 296 spin_unlock_irqrestore(&port->cmd_issue_lock, flags); 297 + 298 + /* Set the command's timeout value.*/ 299 + port->commands[tag].comp_time = jiffies + msecs_to_jiffies( 300 + MTIP_NCQ_COMMAND_TIMEOUT_MS); 309 301 } 310 302 311 303 /* ··· 436 420 writel(0xFFFFFFFF, port->completed[i]); 437 421 438 422 /* Clear any pending interrupts for this port */ 439 - writel(readl(port->mmio + PORT_IRQ_STAT), port->mmio + PORT_IRQ_STAT); 423 + writel(readl(port->dd->mmio + PORT_IRQ_STAT), 424 + port->dd->mmio + PORT_IRQ_STAT); 425 + 426 + /* Clear any pending interrupts on the HBA. */ 427 + writel(readl(port->dd->mmio + HOST_IRQ_STAT), 428 + port->dd->mmio + HOST_IRQ_STAT); 440 429 441 430 /* Enable port interrupts */ 442 431 writel(DEF_PORT_IRQ, port->mmio + PORT_IRQ_MASK); ··· 467 446 while ((readl(port->mmio + PORT_CMD) & PORT_CMD_LIST_ON) 468 447 && time_before(jiffies, timeout)) 469 448 ; 449 + 450 + if (test_bit(MTIP_DDF_REMOVE_PENDING_BIT, &port->dd->dd_flag)) 451 + return; 470 452 471 453 /* 472 454 * Chip quirk: escalate to hba reset if ··· 499 475 while (time_before(jiffies, timeout)) 500 476 ; 501 477 478 + if (test_bit(MTIP_DDF_REMOVE_PENDING_BIT, &port->dd->dd_flag)) 479 + return; 480 + 502 481 /* Clear PxSCTL.DET */ 503 482 writel(readl(port->mmio + PORT_SCR_CTL) & ~1, 504 483 port->mmio + PORT_SCR_CTL); ··· 513 486 && time_before(jiffies, timeout)) 514 487 ; 515 488 489 + if (test_bit(MTIP_DDF_REMOVE_PENDING_BIT, &port->dd->dd_flag)) 490 + return; 491 + 516 492 if ((readl(port->mmio + PORT_SCR_STAT) & 0x01) == 0) 517 493 dev_warn(&port->dd->pdev->dev, 518 494 "COM reset failed\n"); 519 495 520 - /* Clear SError, the PxSERR.DIAG.x should be set so clear it */ 521 - writel(readl(port->mmio + PORT_SCR_ERR), port->mmio + PORT_SCR_ERR); 496 + mtip_init_port(port); 497 + mtip_start_port(port); 522 498 523 - /* Enable the DMA engine */ 524 - mtip_enable_engine(port, 1); 499 + } 500 + 501 + /* 502 + * Helper function for tag logging 503 + */ 504 + static void print_tags(struct driver_data *dd, 505 + char *msg, 506 + unsigned long *tagbits, 507 + int cnt) 508 + { 509 + unsigned char tagmap[128]; 510 + int group, tagmap_len = 0; 511 + 512 + memset(tagmap, 0, sizeof(tagmap)); 513 + for (group = SLOTBITS_IN_LONGS; group > 0; group--) 514 + tagmap_len = sprintf(tagmap + tagmap_len, "%016lX ", 515 + tagbits[group-1]); 516 + dev_warn(&dd->pdev->dev, 517 + "%d command(s) %s: tagmap [%s]", cnt, msg, tagmap); 525 518 } 526 519 527 520 /* ··· 561 514 int tag, cmdto_cnt = 0; 562 515 unsigned int bit, group; 563 516 unsigned int num_command_slots = port->dd->slot_groups * 32; 517 + unsigned long to, tagaccum[SLOTBITS_IN_LONGS]; 564 518 565 519 if (unlikely(!port)) 566 520 return; 567 521 568 - if (atomic_read(&port->dd->resumeflag) == true) { 522 + if (test_bit(MTIP_DDF_RESUME_BIT, &port->dd->dd_flag)) { 569 523 mod_timer(&port->cmd_timer, 570 524 jiffies + msecs_to_jiffies(30000)); 571 525 return; 572 526 } 527 + /* clear the tag accumulator */ 528 + memset(tagaccum, 0, SLOTBITS_IN_LONGS * sizeof(long)); 573 529 574 530 for (tag = 0; tag < num_command_slots; tag++) { 575 531 /* ··· 590 540 command = &port->commands[tag]; 591 541 fis = (struct host_to_dev_fis *) command->command; 592 542 593 - dev_warn(&port->dd->pdev->dev, 594 - "Timeout for command tag %d\n", tag); 595 - 543 + set_bit(tag, tagaccum); 596 544 cmdto_cnt++; 597 545 if (cmdto_cnt == 1) 598 - set_bit(MTIP_FLAG_EH_ACTIVE_BIT, &port->flags); 546 + set_bit(MTIP_PF_EH_ACTIVE_BIT, &port->flags); 599 547 600 548 /* 601 549 * Clear the completed bit. This should prevent ··· 626 578 } 627 579 } 628 580 629 - if (cmdto_cnt) { 630 - dev_warn(&port->dd->pdev->dev, 631 - "%d commands timed out: restarting port", 632 - cmdto_cnt); 581 + if (cmdto_cnt && !test_bit(MTIP_PF_IC_ACTIVE_BIT, &port->flags)) { 582 + print_tags(port->dd, "timed out", tagaccum, cmdto_cnt); 583 + 633 584 mtip_restart_port(port); 634 - clear_bit(MTIP_FLAG_EH_ACTIVE_BIT, &port->flags); 585 + clear_bit(MTIP_PF_EH_ACTIVE_BIT, &port->flags); 635 586 wake_up_interruptible(&port->svc_wait); 587 + } 588 + 589 + if (port->ic_pause_timer) { 590 + to = port->ic_pause_timer + msecs_to_jiffies(1000); 591 + if (time_after(jiffies, to)) { 592 + if (!test_bit(MTIP_PF_IC_ACTIVE_BIT, &port->flags)) { 593 + port->ic_pause_timer = 0; 594 + clear_bit(MTIP_PF_SE_ACTIVE_BIT, &port->flags); 595 + clear_bit(MTIP_PF_DM_ACTIVE_BIT, &port->flags); 596 + clear_bit(MTIP_PF_IC_ACTIVE_BIT, &port->flags); 597 + wake_up_interruptible(&port->svc_wait); 598 + } 599 + 600 + 601 + } 636 602 } 637 603 638 604 /* Restart the timer */ ··· 743 681 complete(waiting); 744 682 } 745 683 746 - /* 747 - * Helper function for tag logging 748 - */ 749 - static void print_tags(struct driver_data *dd, 750 - char *msg, 751 - unsigned long *tagbits) 684 + static void mtip_null_completion(struct mtip_port *port, 685 + int tag, 686 + void *data, 687 + int status) 752 688 { 753 - unsigned int tag, count = 0; 754 - 755 - for (tag = 0; tag < (dd->slot_groups) * 32; tag++) { 756 - if (test_bit(tag, tagbits)) 757 - count++; 758 - } 759 - if (count) 760 - dev_info(&dd->pdev->dev, "%s [%i tags]\n", msg, count); 689 + return; 761 690 } 762 691 692 + static int mtip_read_log_page(struct mtip_port *port, u8 page, u16 *buffer, 693 + dma_addr_t buffer_dma, unsigned int sectors); 694 + static int mtip_get_smart_attr(struct mtip_port *port, unsigned int id, 695 + struct smart_attr *attrib); 763 696 /* 764 697 * Handle an error. 765 698 * ··· 765 708 */ 766 709 static void mtip_handle_tfe(struct driver_data *dd) 767 710 { 768 - int group, tag, bit, reissue; 711 + int group, tag, bit, reissue, rv; 769 712 struct mtip_port *port; 770 - struct mtip_cmd *command; 713 + struct mtip_cmd *cmd; 771 714 u32 completed; 772 715 struct host_to_dev_fis *fis; 773 716 unsigned long tagaccum[SLOTBITS_IN_LONGS]; 717 + unsigned int cmd_cnt = 0; 718 + unsigned char *buf; 719 + char *fail_reason = NULL; 720 + int fail_all_ncq_write = 0, fail_all_ncq_cmds = 0; 774 721 775 722 dev_warn(&dd->pdev->dev, "Taskfile error\n"); 776 723 ··· 783 722 /* Stop the timer to prevent command timeouts. */ 784 723 del_timer(&port->cmd_timer); 785 724 725 + /* clear the tag accumulator */ 726 + memset(tagaccum, 0, SLOTBITS_IN_LONGS * sizeof(long)); 727 + 786 728 /* Set eh_active */ 787 - set_bit(MTIP_FLAG_EH_ACTIVE_BIT, &port->flags); 729 + set_bit(MTIP_PF_EH_ACTIVE_BIT, &port->flags); 788 730 789 731 /* Loop through all the groups */ 790 732 for (group = 0; group < dd->slot_groups; group++) { ··· 795 731 796 732 /* clear completed status register in the hardware.*/ 797 733 writel(completed, port->completed[group]); 798 - 799 - /* clear the tag accumulator */ 800 - memset(tagaccum, 0, SLOTBITS_IN_LONGS * sizeof(long)); 801 734 802 735 /* Process successfully completed commands */ 803 736 for (bit = 0; bit < 32 && completed; bit++) { ··· 806 745 if (tag == MTIP_TAG_INTERNAL) 807 746 continue; 808 747 809 - command = &port->commands[tag]; 810 - if (likely(command->comp_func)) { 748 + cmd = &port->commands[tag]; 749 + if (likely(cmd->comp_func)) { 811 750 set_bit(tag, tagaccum); 812 - atomic_set(&port->commands[tag].active, 0); 813 - command->comp_func(port, 751 + cmd_cnt++; 752 + atomic_set(&cmd->active, 0); 753 + cmd->comp_func(port, 814 754 tag, 815 - command->comp_data, 755 + cmd->comp_data, 816 756 0); 817 757 } else { 818 758 dev_err(&port->dd->pdev->dev, ··· 827 765 } 828 766 } 829 767 } 830 - print_tags(dd, "TFE tags completed:", tagaccum); 768 + 769 + print_tags(dd, "completed (TFE)", tagaccum, cmd_cnt); 831 770 832 771 /* Restart the port */ 833 772 mdelay(20); 834 773 mtip_restart_port(port); 774 + 775 + /* Trying to determine the cause of the error */ 776 + rv = mtip_read_log_page(dd->port, ATA_LOG_SATA_NCQ, 777 + dd->port->log_buf, 778 + dd->port->log_buf_dma, 1); 779 + if (rv) { 780 + dev_warn(&dd->pdev->dev, 781 + "Error in READ LOG EXT (10h) command\n"); 782 + /* non-critical error, don't fail the load */ 783 + } else { 784 + buf = (unsigned char *)dd->port->log_buf; 785 + if (buf[259] & 0x1) { 786 + dev_info(&dd->pdev->dev, 787 + "Write protect bit is set.\n"); 788 + set_bit(MTIP_DDF_WRITE_PROTECT_BIT, &dd->dd_flag); 789 + fail_all_ncq_write = 1; 790 + fail_reason = "write protect"; 791 + } 792 + if (buf[288] == 0xF7) { 793 + dev_info(&dd->pdev->dev, 794 + "Exceeded Tmax, drive in thermal shutdown.\n"); 795 + set_bit(MTIP_DDF_OVER_TEMP_BIT, &dd->dd_flag); 796 + fail_all_ncq_cmds = 1; 797 + fail_reason = "thermal shutdown"; 798 + } 799 + if (buf[288] == 0xBF) { 800 + dev_info(&dd->pdev->dev, 801 + "Drive indicates rebuild has failed.\n"); 802 + fail_all_ncq_cmds = 1; 803 + fail_reason = "rebuild failed"; 804 + } 805 + } 835 806 836 807 /* clear the tag accumulator */ 837 808 memset(tagaccum, 0, SLOTBITS_IN_LONGS * sizeof(long)); ··· 874 779 for (bit = 0; bit < 32; bit++) { 875 780 reissue = 1; 876 781 tag = (group << 5) + bit; 782 + cmd = &port->commands[tag]; 877 783 878 784 /* If the active bit is set re-issue the command */ 879 - if (atomic_read(&port->commands[tag].active) == 0) 785 + if (atomic_read(&cmd->active) == 0) 880 786 continue; 881 787 882 - fis = (struct host_to_dev_fis *) 883 - port->commands[tag].command; 788 + fis = (struct host_to_dev_fis *)cmd->command; 884 789 885 790 /* Should re-issue? */ 886 791 if (tag == MTIP_TAG_INTERNAL || 887 792 fis->command == ATA_CMD_SET_FEATURES) 888 793 reissue = 0; 794 + else { 795 + if (fail_all_ncq_cmds || 796 + (fail_all_ncq_write && 797 + fis->command == ATA_CMD_FPDMA_WRITE)) { 798 + dev_warn(&dd->pdev->dev, 799 + " Fail: %s w/tag %d [%s].\n", 800 + fis->command == ATA_CMD_FPDMA_WRITE ? 801 + "write" : "read", 802 + tag, 803 + fail_reason != NULL ? 804 + fail_reason : "unknown"); 805 + atomic_set(&cmd->active, 0); 806 + if (cmd->comp_func) { 807 + cmd->comp_func(port, tag, 808 + cmd->comp_data, 809 + -ENODATA); 810 + } 811 + continue; 812 + } 813 + } 889 814 890 815 /* 891 816 * First check if this command has 892 817 * exceeded its retries. 893 818 */ 894 - if (reissue && 895 - (port->commands[tag].retries-- > 0)) { 819 + if (reissue && (cmd->retries-- > 0)) { 896 820 897 821 set_bit(tag, tagaccum); 898 822 899 - /* Update the timeout value. */ 900 - port->commands[tag].comp_time = 901 - jiffies + msecs_to_jiffies( 902 - MTIP_NCQ_COMMAND_TIMEOUT_MS); 903 823 /* Re-issue the command. */ 904 824 mtip_issue_ncq_command(port, tag); 905 825 ··· 924 814 /* Retire a command that will not be reissued */ 925 815 dev_warn(&port->dd->pdev->dev, 926 816 "retiring tag %d\n", tag); 927 - atomic_set(&port->commands[tag].active, 0); 817 + atomic_set(&cmd->active, 0); 928 818 929 - if (port->commands[tag].comp_func) 930 - port->commands[tag].comp_func( 819 + if (cmd->comp_func) 820 + cmd->comp_func( 931 821 port, 932 822 tag, 933 - port->commands[tag].comp_data, 823 + cmd->comp_data, 934 824 PORT_IRQ_TF_ERR); 935 825 else 936 826 dev_warn(&port->dd->pdev->dev, ··· 938 828 tag); 939 829 } 940 830 } 941 - print_tags(dd, "TFE tags reissued:", tagaccum); 831 + print_tags(dd, "reissued (TFE)", tagaccum, cmd_cnt); 942 832 943 833 /* clear eh_active */ 944 - clear_bit(MTIP_FLAG_EH_ACTIVE_BIT, &port->flags); 834 + clear_bit(MTIP_PF_EH_ACTIVE_BIT, &port->flags); 945 835 wake_up_interruptible(&port->svc_wait); 946 836 947 837 mod_timer(&port->cmd_timer, ··· 1009 899 struct mtip_port *port = dd->port; 1010 900 struct mtip_cmd *cmd = &port->commands[MTIP_TAG_INTERNAL]; 1011 901 1012 - if (test_bit(MTIP_FLAG_IC_ACTIVE_BIT, &port->flags) && 902 + if (test_bit(MTIP_PF_IC_ACTIVE_BIT, &port->flags) && 1013 903 (cmd != NULL) && !(readl(port->cmd_issue[MTIP_TAG_INTERNAL]) 1014 904 & (1 << MTIP_TAG_INTERNAL))) { 1015 905 if (cmd->comp_func) { ··· 1020 910 return; 1021 911 } 1022 912 } 1023 - 1024 - dev_warn(&dd->pdev->dev, "IRQ status 0x%x ignored.\n", port_stat); 1025 913 1026 914 return; 1027 915 } ··· 1076 968 /* don't proceed further */ 1077 969 return IRQ_HANDLED; 1078 970 } 971 + if (test_bit(MTIP_DDF_REMOVE_PENDING_BIT, 972 + &dd->dd_flag)) 973 + return rv; 1079 974 1080 975 mtip_process_errors(dd, port_stat & PORT_IRQ_ERR); 1081 976 } ··· 1126 1015 port->cmd_issue[MTIP_TAG_INDEX(tag)]); 1127 1016 } 1128 1017 1018 + static bool mtip_pause_ncq(struct mtip_port *port, 1019 + struct host_to_dev_fis *fis) 1020 + { 1021 + struct host_to_dev_fis *reply; 1022 + unsigned long task_file_data; 1023 + 1024 + reply = port->rxfis + RX_FIS_D2H_REG; 1025 + task_file_data = readl(port->mmio+PORT_TFDATA); 1026 + 1027 + if ((task_file_data & 1) || (fis->command == ATA_CMD_SEC_ERASE_UNIT)) 1028 + return false; 1029 + 1030 + if (fis->command == ATA_CMD_SEC_ERASE_PREP) { 1031 + set_bit(MTIP_PF_SE_ACTIVE_BIT, &port->flags); 1032 + port->ic_pause_timer = jiffies; 1033 + return true; 1034 + } else if ((fis->command == ATA_CMD_DOWNLOAD_MICRO) && 1035 + (fis->features == 0x03)) { 1036 + set_bit(MTIP_PF_DM_ACTIVE_BIT, &port->flags); 1037 + port->ic_pause_timer = jiffies; 1038 + return true; 1039 + } else if ((fis->command == ATA_CMD_SEC_ERASE_UNIT) || 1040 + ((fis->command == 0xFC) && 1041 + (fis->features == 0x27 || fis->features == 0x72 || 1042 + fis->features == 0x62 || fis->features == 0x26))) { 1043 + /* Com reset after secure erase or lowlevel format */ 1044 + mtip_restart_port(port); 1045 + return false; 1046 + } 1047 + 1048 + return false; 1049 + } 1050 + 1129 1051 /* 1130 1052 * Wait for port to quiesce 1131 1053 * ··· 1177 1033 1178 1034 to = jiffies + msecs_to_jiffies(timeout); 1179 1035 do { 1180 - if (test_bit(MTIP_FLAG_SVC_THD_ACTIVE_BIT, &port->flags) && 1181 - test_bit(MTIP_FLAG_ISSUE_CMDS_BIT, &port->flags)) { 1036 + if (test_bit(MTIP_PF_SVC_THD_ACTIVE_BIT, &port->flags) && 1037 + test_bit(MTIP_PF_ISSUE_CMDS_BIT, &port->flags)) { 1182 1038 msleep(20); 1183 1039 continue; /* svc thd is actively issuing commands */ 1184 1040 } 1041 + if (test_bit(MTIP_DDF_REMOVE_PENDING_BIT, &port->dd->dd_flag)) 1042 + return -EFAULT; 1185 1043 /* 1186 1044 * Ignore s_active bit 0 of array element 0. 1187 1045 * This bit will always be set ··· 1220 1074 * -EAGAIN Time out waiting for command to complete. 1221 1075 */ 1222 1076 static int mtip_exec_internal_command(struct mtip_port *port, 1223 - void *fis, 1077 + struct host_to_dev_fis *fis, 1224 1078 int fis_len, 1225 1079 dma_addr_t buffer, 1226 1080 int buf_len, ··· 1230 1084 { 1231 1085 struct mtip_cmd_sg *command_sg; 1232 1086 DECLARE_COMPLETION_ONSTACK(wait); 1233 - int rv = 0; 1087 + int rv = 0, ready2go = 1; 1234 1088 struct mtip_cmd *int_cmd = &port->commands[MTIP_TAG_INTERNAL]; 1089 + unsigned long to; 1235 1090 1236 1091 /* Make sure the buffer is 8 byte aligned. This is asic specific. */ 1237 1092 if (buffer & 0x00000007) { ··· 1241 1094 return -EFAULT; 1242 1095 } 1243 1096 1244 - /* Only one internal command should be running at a time */ 1245 - if (test_and_set_bit(MTIP_TAG_INTERNAL, port->allocated)) { 1097 + to = jiffies + msecs_to_jiffies(timeout); 1098 + do { 1099 + ready2go = !test_and_set_bit(MTIP_TAG_INTERNAL, 1100 + port->allocated); 1101 + if (ready2go) 1102 + break; 1103 + mdelay(100); 1104 + } while (time_before(jiffies, to)); 1105 + if (!ready2go) { 1246 1106 dev_warn(&port->dd->pdev->dev, 1247 - "Internal command already active\n"); 1107 + "Internal cmd active. new cmd [%02X]\n", fis->command); 1248 1108 return -EBUSY; 1249 1109 } 1250 - set_bit(MTIP_FLAG_IC_ACTIVE_BIT, &port->flags); 1110 + set_bit(MTIP_PF_IC_ACTIVE_BIT, &port->flags); 1111 + port->ic_pause_timer = 0; 1112 + 1113 + if (fis->command == ATA_CMD_SEC_ERASE_UNIT) 1114 + clear_bit(MTIP_PF_SE_ACTIVE_BIT, &port->flags); 1115 + else if (fis->command == ATA_CMD_DOWNLOAD_MICRO) 1116 + clear_bit(MTIP_PF_DM_ACTIVE_BIT, &port->flags); 1251 1117 1252 1118 if (atomic == GFP_KERNEL) { 1253 - /* wait for io to complete if non atomic */ 1254 - if (mtip_quiesce_io(port, 5000) < 0) { 1255 - dev_warn(&port->dd->pdev->dev, 1256 - "Failed to quiesce IO\n"); 1257 - release_slot(port, MTIP_TAG_INTERNAL); 1258 - clear_bit(MTIP_FLAG_IC_ACTIVE_BIT, &port->flags); 1259 - wake_up_interruptible(&port->svc_wait); 1260 - return -EBUSY; 1119 + if (fis->command != ATA_CMD_STANDBYNOW1) { 1120 + /* wait for io to complete if non atomic */ 1121 + if (mtip_quiesce_io(port, 5000) < 0) { 1122 + dev_warn(&port->dd->pdev->dev, 1123 + "Failed to quiesce IO\n"); 1124 + release_slot(port, MTIP_TAG_INTERNAL); 1125 + clear_bit(MTIP_PF_IC_ACTIVE_BIT, &port->flags); 1126 + wake_up_interruptible(&port->svc_wait); 1127 + return -EBUSY; 1128 + } 1261 1129 } 1262 1130 1263 1131 /* Set the completion function and data for the command. */ ··· 1282 1120 } else { 1283 1121 /* Clear completion - we're going to poll */ 1284 1122 int_cmd->comp_data = NULL; 1285 - int_cmd->comp_func = NULL; 1123 + int_cmd->comp_func = mtip_null_completion; 1286 1124 } 1287 1125 1288 1126 /* Copy the command to the command table */ ··· 1321 1159 "Internal command did not complete [%d] " 1322 1160 "within timeout of %lu ms\n", 1323 1161 atomic, timeout); 1162 + if (mtip_check_surprise_removal(port->dd->pdev) || 1163 + test_bit(MTIP_DDF_REMOVE_PENDING_BIT, 1164 + &port->dd->dd_flag)) { 1165 + rv = -ENXIO; 1166 + goto exec_ic_exit; 1167 + } 1324 1168 rv = -EAGAIN; 1325 1169 } 1326 1170 ··· 1334 1166 & (1 << MTIP_TAG_INTERNAL)) { 1335 1167 dev_warn(&port->dd->pdev->dev, 1336 1168 "Retiring internal command but CI is 1.\n"); 1169 + if (test_bit(MTIP_DDF_REMOVE_PENDING_BIT, 1170 + &port->dd->dd_flag)) { 1171 + hba_reset_nosleep(port->dd); 1172 + rv = -ENXIO; 1173 + } else { 1174 + mtip_restart_port(port); 1175 + rv = -EAGAIN; 1176 + } 1177 + goto exec_ic_exit; 1337 1178 } 1338 1179 1339 1180 } else { 1340 1181 /* Spin for <timeout> checking if command still outstanding */ 1341 1182 timeout = jiffies + msecs_to_jiffies(timeout); 1342 - 1343 - while ((readl( 1344 - port->cmd_issue[MTIP_TAG_INTERNAL]) 1345 - & (1 << MTIP_TAG_INTERNAL)) 1346 - && time_before(jiffies, timeout)) 1347 - ; 1183 + while ((readl(port->cmd_issue[MTIP_TAG_INTERNAL]) 1184 + & (1 << MTIP_TAG_INTERNAL)) 1185 + && time_before(jiffies, timeout)) { 1186 + if (mtip_check_surprise_removal(port->dd->pdev)) { 1187 + rv = -ENXIO; 1188 + goto exec_ic_exit; 1189 + } 1190 + if ((fis->command != ATA_CMD_STANDBYNOW1) && 1191 + test_bit(MTIP_DDF_REMOVE_PENDING_BIT, 1192 + &port->dd->dd_flag)) { 1193 + rv = -ENXIO; 1194 + goto exec_ic_exit; 1195 + } 1196 + } 1348 1197 1349 1198 if (readl(port->cmd_issue[MTIP_TAG_INTERNAL]) 1350 1199 & (1 << MTIP_TAG_INTERNAL)) { 1351 1200 dev_err(&port->dd->pdev->dev, 1352 - "Internal command did not complete [%d]\n", 1353 - atomic); 1201 + "Internal command did not complete [atomic]\n"); 1354 1202 rv = -EAGAIN; 1203 + if (test_bit(MTIP_DDF_REMOVE_PENDING_BIT, 1204 + &port->dd->dd_flag)) { 1205 + hba_reset_nosleep(port->dd); 1206 + rv = -ENXIO; 1207 + } else { 1208 + mtip_restart_port(port); 1209 + rv = -EAGAIN; 1210 + } 1355 1211 } 1356 1212 } 1357 - 1213 + exec_ic_exit: 1358 1214 /* Clear the allocated and active bits for the internal command. */ 1359 1215 atomic_set(&int_cmd->active, 0); 1360 1216 release_slot(port, MTIP_TAG_INTERNAL); 1361 - clear_bit(MTIP_FLAG_IC_ACTIVE_BIT, &port->flags); 1217 + if (rv >= 0 && mtip_pause_ncq(port, fis)) { 1218 + /* NCQ paused */ 1219 + return rv; 1220 + } 1221 + clear_bit(MTIP_PF_IC_ACTIVE_BIT, &port->flags); 1362 1222 wake_up_interruptible(&port->svc_wait); 1363 1223 1364 1224 return rv; ··· 1435 1239 { 1436 1240 int rv = 0; 1437 1241 struct host_to_dev_fis fis; 1242 + 1243 + if (test_bit(MTIP_DDF_REMOVE_PENDING_BIT, &port->dd->dd_flag)) 1244 + return -EFAULT; 1438 1245 1439 1246 /* Build the FIS. */ 1440 1247 memset(&fis, 0, sizeof(struct host_to_dev_fis)); ··· 1512 1313 { 1513 1314 int rv; 1514 1315 struct host_to_dev_fis fis; 1316 + unsigned long start; 1515 1317 1516 1318 /* Build the FIS. */ 1517 1319 memset(&fis, 0, sizeof(struct host_to_dev_fis)); ··· 1520 1320 fis.opts = 1 << 7; 1521 1321 fis.command = ATA_CMD_STANDBYNOW1; 1522 1322 1523 - /* Execute the command. Use a 15-second timeout for large drives. */ 1323 + start = jiffies; 1524 1324 rv = mtip_exec_internal_command(port, 1525 1325 &fis, 1526 1326 5, 1527 1327 0, 1528 1328 0, 1529 1329 0, 1530 - GFP_KERNEL, 1330 + GFP_ATOMIC, 1531 1331 15000); 1332 + dbg_printk(MTIP_DRV_NAME "Time taken to complete standby cmd: %d ms\n", 1333 + jiffies_to_msecs(jiffies - start)); 1334 + if (rv) 1335 + dev_warn(&port->dd->pdev->dev, 1336 + "STANDBY IMMEDIATE command failed.\n"); 1337 + 1338 + return rv; 1339 + } 1340 + 1341 + /* 1342 + * Issue a READ LOG EXT command to the device. 1343 + * 1344 + * @port pointer to the port structure. 1345 + * @page page number to fetch 1346 + * @buffer pointer to buffer 1347 + * @buffer_dma dma address corresponding to @buffer 1348 + * @sectors page length to fetch, in sectors 1349 + * 1350 + * return value 1351 + * @rv return value from mtip_exec_internal_command() 1352 + */ 1353 + static int mtip_read_log_page(struct mtip_port *port, u8 page, u16 *buffer, 1354 + dma_addr_t buffer_dma, unsigned int sectors) 1355 + { 1356 + struct host_to_dev_fis fis; 1357 + 1358 + memset(&fis, 0, sizeof(struct host_to_dev_fis)); 1359 + fis.type = 0x27; 1360 + fis.opts = 1 << 7; 1361 + fis.command = ATA_CMD_READ_LOG_EXT; 1362 + fis.sect_count = sectors & 0xFF; 1363 + fis.sect_cnt_ex = (sectors >> 8) & 0xFF; 1364 + fis.lba_low = page; 1365 + fis.lba_mid = 0; 1366 + fis.device = ATA_DEVICE_OBS; 1367 + 1368 + memset(buffer, 0, sectors * ATA_SECT_SIZE); 1369 + 1370 + return mtip_exec_internal_command(port, 1371 + &fis, 1372 + 5, 1373 + buffer_dma, 1374 + sectors * ATA_SECT_SIZE, 1375 + 0, 1376 + GFP_ATOMIC, 1377 + MTIP_INTERNAL_COMMAND_TIMEOUT_MS); 1378 + } 1379 + 1380 + /* 1381 + * Issue a SMART READ DATA command to the device. 1382 + * 1383 + * @port pointer to the port structure. 1384 + * @buffer pointer to buffer 1385 + * @buffer_dma dma address corresponding to @buffer 1386 + * 1387 + * return value 1388 + * @rv return value from mtip_exec_internal_command() 1389 + */ 1390 + static int mtip_get_smart_data(struct mtip_port *port, u8 *buffer, 1391 + dma_addr_t buffer_dma) 1392 + { 1393 + struct host_to_dev_fis fis; 1394 + 1395 + memset(&fis, 0, sizeof(struct host_to_dev_fis)); 1396 + fis.type = 0x27; 1397 + fis.opts = 1 << 7; 1398 + fis.command = ATA_CMD_SMART; 1399 + fis.features = 0xD0; 1400 + fis.sect_count = 1; 1401 + fis.lba_mid = 0x4F; 1402 + fis.lba_hi = 0xC2; 1403 + fis.device = ATA_DEVICE_OBS; 1404 + 1405 + return mtip_exec_internal_command(port, 1406 + &fis, 1407 + 5, 1408 + buffer_dma, 1409 + ATA_SECT_SIZE, 1410 + 0, 1411 + GFP_ATOMIC, 1412 + 15000); 1413 + } 1414 + 1415 + /* 1416 + * Get the value of a smart attribute 1417 + * 1418 + * @port pointer to the port structure 1419 + * @id attribute number 1420 + * @attrib pointer to return attrib information corresponding to @id 1421 + * 1422 + * return value 1423 + * -EINVAL NULL buffer passed or unsupported attribute @id. 1424 + * -EPERM Identify data not valid, SMART not supported or not enabled 1425 + */ 1426 + static int mtip_get_smart_attr(struct mtip_port *port, unsigned int id, 1427 + struct smart_attr *attrib) 1428 + { 1429 + int rv, i; 1430 + struct smart_attr *pattr; 1431 + 1432 + if (!attrib) 1433 + return -EINVAL; 1434 + 1435 + if (!port->identify_valid) { 1436 + dev_warn(&port->dd->pdev->dev, "IDENTIFY DATA not valid\n"); 1437 + return -EPERM; 1438 + } 1439 + if (!(port->identify[82] & 0x1)) { 1440 + dev_warn(&port->dd->pdev->dev, "SMART not supported\n"); 1441 + return -EPERM; 1442 + } 1443 + if (!(port->identify[85] & 0x1)) { 1444 + dev_warn(&port->dd->pdev->dev, "SMART not enabled\n"); 1445 + return -EPERM; 1446 + } 1447 + 1448 + memset(port->smart_buf, 0, ATA_SECT_SIZE); 1449 + rv = mtip_get_smart_data(port, port->smart_buf, port->smart_buf_dma); 1450 + if (rv) { 1451 + dev_warn(&port->dd->pdev->dev, "Failed to ge SMART data\n"); 1452 + return rv; 1453 + } 1454 + 1455 + pattr = (struct smart_attr *)(port->smart_buf + 2); 1456 + for (i = 0; i < 29; i++, pattr++) 1457 + if (pattr->attr_id == id) { 1458 + memcpy(attrib, pattr, sizeof(struct smart_attr)); 1459 + break; 1460 + } 1461 + 1462 + if (i == 29) { 1463 + dev_warn(&port->dd->pdev->dev, 1464 + "Query for invalid SMART attribute ID\n"); 1465 + rv = -EINVAL; 1466 + } 1532 1467 1533 1468 return rv; 1534 1469 } ··· 1839 1504 fis.cyl_hi = command[5]; 1840 1505 fis.device = command[6] & ~0x10; /* Clear the dev bit*/ 1841 1506 1842 - 1843 - dbg_printk(MTIP_DRV_NAME "%s: User Command: cmd %x, feat %x, " 1844 - "nsect %x, sect %x, lcyl %x, " 1845 - "hcyl %x, sel %x\n", 1507 + dbg_printk(MTIP_DRV_NAME " %s: User Command: cmd %x, feat %x, nsect %x, sect %x, lcyl %x, hcyl %x, sel %x\n", 1846 1508 __func__, 1847 1509 command[0], 1848 1510 command[1], ··· 1866 1534 command[4] = reply->cyl_low; 1867 1535 command[5] = reply->cyl_hi; 1868 1536 1869 - dbg_printk(MTIP_DRV_NAME "%s: Completion Status: stat %x, " 1870 - "err %x , cyl_lo %x cyl_hi %x\n", 1537 + dbg_printk(MTIP_DRV_NAME " %s: Completion Status: stat %x, err %x , cyl_lo %x cyl_hi %x\n", 1871 1538 __func__, 1872 1539 command[0], 1873 1540 command[1], ··· 1909 1578 } 1910 1579 1911 1580 dbg_printk(MTIP_DRV_NAME 1912 - "%s: User Command: cmd %x, sect %x, " 1581 + " %s: User Command: cmd %x, sect %x, " 1913 1582 "feat %x, sectcnt %x\n", 1914 1583 __func__, 1915 1584 command[0], ··· 1938 1607 command[2] = command[3]; 1939 1608 1940 1609 dbg_printk(MTIP_DRV_NAME 1941 - "%s: Completion Status: stat %x, " 1610 + " %s: Completion Status: stat %x, " 1942 1611 "err %x, cmd %x\n", 1943 1612 __func__, 1944 1613 command[0], ··· 2141 1810 } 2142 1811 2143 1812 dbg_printk(MTIP_DRV_NAME 2144 - "taskfile: cmd %x, feat %x, nsect %x," 1813 + " %s: cmd %x, feat %x, nsect %x," 2145 1814 " sect/lbal %x, lcyl/lbam %x, hcyl/lbah %x," 2146 1815 " head/dev %x\n", 1816 + __func__, 2147 1817 fis.command, 2148 1818 fis.features, 2149 1819 fis.sect_count, ··· 2155 1823 2156 1824 switch (fis.command) { 2157 1825 case ATA_CMD_DOWNLOAD_MICRO: 2158 - /* Change timeout for Download Microcode to 60 seconds.*/ 2159 - timeout = 60000; 1826 + /* Change timeout for Download Microcode to 2 minutes */ 1827 + timeout = 120000; 2160 1828 break; 2161 1829 case ATA_CMD_SEC_ERASE_UNIT: 2162 1830 /* Change timeout for Security Erase Unit to 4 minutes.*/ ··· 2172 1840 timeout = 10000; 2173 1841 break; 2174 1842 case ATA_CMD_SMART: 2175 - /* Change timeout for vendor unique command to 10 secs */ 2176 - timeout = 10000; 1843 + /* Change timeout for vendor unique command to 15 secs */ 1844 + timeout = 15000; 2177 1845 break; 2178 1846 default: 2179 1847 timeout = MTIP_IOCTL_COMMAND_TIMEOUT_MS; ··· 2235 1903 req_task->hob_ports[1] = reply->features_ex; 2236 1904 req_task->hob_ports[2] = reply->sect_cnt_ex; 2237 1905 } 2238 - 2239 - /* Com rest after secure erase or lowlevel format */ 2240 - if (((fis.command == ATA_CMD_SEC_ERASE_UNIT) || 2241 - ((fis.command == 0xFC) && 2242 - (fis.features == 0x27 || fis.features == 0x72 || 2243 - fis.features == 0x62 || fis.features == 0x26))) && 2244 - !(reply->command & 1)) { 2245 - mtip_restart_port(dd->port); 2246 - } 2247 - 2248 1906 dbg_printk(MTIP_DRV_NAME 2249 - "%s: Completion: stat %x," 1907 + " %s: Completion: stat %x," 2250 1908 "err %x, sect_cnt %x, lbalo %x," 2251 1909 "lbamid %x, lbahi %x, dev %x\n", 2252 1910 __func__, ··· 2402 2080 struct host_to_dev_fis *fis; 2403 2081 struct mtip_port *port = dd->port; 2404 2082 struct mtip_cmd *command = &port->commands[tag]; 2083 + int dma_dir = (dir == READ) ? DMA_FROM_DEVICE : DMA_TO_DEVICE; 2405 2084 2406 2085 /* Map the scatter list for DMA access */ 2407 - if (dir == READ) 2408 - nents = dma_map_sg(&dd->pdev->dev, command->sg, 2409 - nents, DMA_FROM_DEVICE); 2410 - else 2411 - nents = dma_map_sg(&dd->pdev->dev, command->sg, 2412 - nents, DMA_TO_DEVICE); 2086 + nents = dma_map_sg(&dd->pdev->dev, command->sg, nents, dma_dir); 2413 2087 2414 2088 command->scatter_ents = nents; 2415 2089 ··· 2445 2127 */ 2446 2128 command->comp_data = dd; 2447 2129 command->comp_func = mtip_async_complete; 2448 - command->direction = (dir == READ ? DMA_FROM_DEVICE : DMA_TO_DEVICE); 2130 + command->direction = dma_dir; 2449 2131 2450 2132 /* 2451 2133 * Set the completion function and data for the command passed ··· 2458 2140 * To prevent this command from being issued 2459 2141 * if an internal command is in progress or error handling is active. 2460 2142 */ 2461 - if (unlikely(test_bit(MTIP_FLAG_IC_ACTIVE_BIT, &port->flags) || 2462 - test_bit(MTIP_FLAG_EH_ACTIVE_BIT, &port->flags))) { 2143 + if (port->flags & MTIP_PF_PAUSE_IO) { 2463 2144 set_bit(tag, port->cmds_to_issue); 2464 - set_bit(MTIP_FLAG_ISSUE_CMDS_BIT, &port->flags); 2145 + set_bit(MTIP_PF_ISSUE_CMDS_BIT, &port->flags); 2465 2146 return; 2466 2147 } 2467 2148 2468 2149 /* Issue the command to the hardware */ 2469 2150 mtip_issue_ncq_command(port, tag); 2470 2151 2471 - /* Set the command's timeout value.*/ 2472 - port->commands[tag].comp_time = jiffies + msecs_to_jiffies( 2473 - MTIP_NCQ_COMMAND_TIMEOUT_MS); 2152 + return; 2474 2153 } 2475 2154 2476 2155 /* ··· 2506 2191 down(&dd->port->cmd_slot); 2507 2192 *tag = get_slot(dd->port); 2508 2193 2194 + if (unlikely(test_bit(MTIP_DDF_REMOVE_PENDING_BIT, &dd->dd_flag))) { 2195 + up(&dd->port->cmd_slot); 2196 + return NULL; 2197 + } 2509 2198 if (unlikely(*tag < 0)) 2510 2199 return NULL; 2511 2200 ··· 2526 2207 * return value 2527 2208 * The size, in bytes, of the data copied into buf. 2528 2209 */ 2529 - static ssize_t hw_show_registers(struct device *dev, 2210 + static ssize_t mtip_hw_show_registers(struct device *dev, 2530 2211 struct device_attribute *attr, 2531 2212 char *buf) 2532 2213 { ··· 2535 2216 int size = 0; 2536 2217 int n; 2537 2218 2538 - size += sprintf(&buf[size], "%s:\ns_active:\n", __func__); 2219 + size += sprintf(&buf[size], "S ACTive:\n"); 2539 2220 2540 2221 for (n = 0; n < dd->slot_groups; n++) 2541 2222 size += sprintf(&buf[size], "0x%08x\n", ··· 2559 2240 group_allocated); 2560 2241 } 2561 2242 2562 - size += sprintf(&buf[size], "completed:\n"); 2243 + size += sprintf(&buf[size], "Completed:\n"); 2563 2244 2564 2245 for (n = 0; n < dd->slot_groups; n++) 2565 2246 size += sprintf(&buf[size], "0x%08x\n", 2566 2247 readl(dd->port->completed[n])); 2567 2248 2568 - size += sprintf(&buf[size], "PORT_IRQ_STAT 0x%08x\n", 2249 + size += sprintf(&buf[size], "PORT IRQ STAT : 0x%08x\n", 2569 2250 readl(dd->port->mmio + PORT_IRQ_STAT)); 2570 - size += sprintf(&buf[size], "HOST_IRQ_STAT 0x%08x\n", 2251 + size += sprintf(&buf[size], "HOST IRQ STAT : 0x%08x\n", 2571 2252 readl(dd->mmio + HOST_IRQ_STAT)); 2572 2253 2573 2254 return size; 2574 2255 } 2575 - static DEVICE_ATTR(registers, S_IRUGO, hw_show_registers, NULL); 2256 + 2257 + static ssize_t mtip_hw_show_status(struct device *dev, 2258 + struct device_attribute *attr, 2259 + char *buf) 2260 + { 2261 + struct driver_data *dd = dev_to_disk(dev)->private_data; 2262 + int size = 0; 2263 + 2264 + if (test_bit(MTIP_DDF_OVER_TEMP_BIT, &dd->dd_flag)) 2265 + size += sprintf(buf, "%s", "thermal_shutdown\n"); 2266 + else if (test_bit(MTIP_DDF_WRITE_PROTECT_BIT, &dd->dd_flag)) 2267 + size += sprintf(buf, "%s", "write_protect\n"); 2268 + else 2269 + size += sprintf(buf, "%s", "online\n"); 2270 + 2271 + return size; 2272 + } 2273 + 2274 + static DEVICE_ATTR(registers, S_IRUGO, mtip_hw_show_registers, NULL); 2275 + static DEVICE_ATTR(status, S_IRUGO, mtip_hw_show_status, NULL); 2576 2276 2577 2277 /* 2578 2278 * Create the sysfs related attributes. ··· 2610 2272 2611 2273 if (sysfs_create_file(kobj, &dev_attr_registers.attr)) 2612 2274 dev_warn(&dd->pdev->dev, 2613 - "Error creating registers sysfs entry\n"); 2275 + "Error creating 'registers' sysfs entry\n"); 2276 + if (sysfs_create_file(kobj, &dev_attr_status.attr)) 2277 + dev_warn(&dd->pdev->dev, 2278 + "Error creating 'status' sysfs entry\n"); 2614 2279 return 0; 2615 2280 } 2616 2281 ··· 2633 2292 return -EINVAL; 2634 2293 2635 2294 sysfs_remove_file(kobj, &dev_attr_registers.attr); 2295 + sysfs_remove_file(kobj, &dev_attr_status.attr); 2636 2296 2637 2297 return 0; 2638 2298 } ··· 2726 2384 "FTL rebuild in progress. Polling for completion.\n"); 2727 2385 2728 2386 start = jiffies; 2729 - dd->ftlrebuildflag = 1; 2730 2387 timeout = jiffies + msecs_to_jiffies(MTIP_FTL_REBUILD_TIMEOUT_MS); 2731 2388 2732 2389 do { 2390 + if (unlikely(test_bit(MTIP_DDF_REMOVE_PENDING_BIT, 2391 + &dd->dd_flag))) 2392 + return -EFAULT; 2733 2393 if (mtip_check_surprise_removal(dd->pdev)) 2734 2394 return -EFAULT; 2735 2395 ··· 2752 2408 dev_warn(&dd->pdev->dev, 2753 2409 "FTL rebuild complete (%d secs).\n", 2754 2410 jiffies_to_msecs(jiffies - start) / 1000); 2755 - dd->ftlrebuildflag = 0; 2756 2411 mtip_block_initialize(dd); 2757 - break; 2412 + return 0; 2758 2413 } 2759 2414 ssleep(10); 2760 2415 } while (time_before(jiffies, timeout)); 2761 2416 2762 2417 /* Check for timeout */ 2763 - if (dd->ftlrebuildflag) { 2764 - dev_err(&dd->pdev->dev, 2418 + dev_err(&dd->pdev->dev, 2765 2419 "Timed out waiting for FTL rebuild to complete (%d secs).\n", 2766 2420 jiffies_to_msecs(jiffies - start) / 1000); 2767 - return -EFAULT; 2768 - } 2769 - 2770 - return 0; 2421 + return -EFAULT; 2771 2422 } 2772 2423 2773 2424 /* ··· 2787 2448 * is in progress nor error handling is active 2788 2449 */ 2789 2450 wait_event_interruptible(port->svc_wait, (port->flags) && 2790 - !test_bit(MTIP_FLAG_IC_ACTIVE_BIT, &port->flags) && 2791 - !test_bit(MTIP_FLAG_EH_ACTIVE_BIT, &port->flags)); 2451 + !(port->flags & MTIP_PF_PAUSE_IO)); 2792 2452 2793 2453 if (kthread_should_stop()) 2794 2454 break; 2795 2455 2796 - set_bit(MTIP_FLAG_SVC_THD_ACTIVE_BIT, &port->flags); 2797 - if (test_bit(MTIP_FLAG_ISSUE_CMDS_BIT, &port->flags)) { 2456 + if (unlikely(test_bit(MTIP_DDF_REMOVE_PENDING_BIT, 2457 + &dd->dd_flag))) 2458 + break; 2459 + 2460 + set_bit(MTIP_PF_SVC_THD_ACTIVE_BIT, &port->flags); 2461 + if (test_bit(MTIP_PF_ISSUE_CMDS_BIT, &port->flags)) { 2798 2462 slot = 1; 2799 2463 /* used to restrict the loop to one iteration */ 2800 2464 slot_start = num_cmd_slots; ··· 2822 2480 /* Issue the command to the hardware */ 2823 2481 mtip_issue_ncq_command(port, slot); 2824 2482 2825 - /* Set the command's timeout value.*/ 2826 - port->commands[slot].comp_time = jiffies + 2827 - msecs_to_jiffies(MTIP_NCQ_COMMAND_TIMEOUT_MS); 2828 - 2829 2483 clear_bit(slot, port->cmds_to_issue); 2830 2484 } 2831 2485 2832 - clear_bit(MTIP_FLAG_ISSUE_CMDS_BIT, &port->flags); 2833 - } else if (test_bit(MTIP_FLAG_REBUILD_BIT, &port->flags)) { 2834 - mtip_ftl_rebuild_poll(dd); 2835 - clear_bit(MTIP_FLAG_REBUILD_BIT, &port->flags); 2486 + clear_bit(MTIP_PF_ISSUE_CMDS_BIT, &port->flags); 2487 + } else if (test_bit(MTIP_PF_REBUILD_BIT, &port->flags)) { 2488 + if (!mtip_ftl_rebuild_poll(dd)) 2489 + set_bit(MTIP_DDF_REBUILD_FAILED_BIT, 2490 + &dd->dd_flag); 2491 + clear_bit(MTIP_PF_REBUILD_BIT, &port->flags); 2836 2492 } 2837 - clear_bit(MTIP_FLAG_SVC_THD_ACTIVE_BIT, &port->flags); 2493 + clear_bit(MTIP_PF_SVC_THD_ACTIVE_BIT, &port->flags); 2838 2494 2839 - if (test_bit(MTIP_FLAG_SVC_THD_SHOULD_STOP_BIT, &port->flags)) 2495 + if (test_bit(MTIP_PF_SVC_THD_STOP_BIT, &port->flags)) 2840 2496 break; 2841 2497 } 2842 2498 return 0; ··· 2853 2513 int i; 2854 2514 int rv; 2855 2515 unsigned int num_command_slots; 2516 + unsigned long timeout, timetaken; 2517 + unsigned char *buf; 2518 + struct smart_attr attr242; 2856 2519 2857 2520 dd->mmio = pcim_iomap_table(dd->pdev)[MTIP_ABAR]; 2858 2521 ··· 2890 2547 /* Allocate memory for the command list. */ 2891 2548 dd->port->command_list = 2892 2549 dmam_alloc_coherent(&dd->pdev->dev, 2893 - HW_PORT_PRIV_DMA_SZ + (ATA_SECT_SIZE * 2), 2550 + HW_PORT_PRIV_DMA_SZ + (ATA_SECT_SIZE * 4), 2894 2551 &dd->port->command_list_dma, 2895 2552 GFP_KERNEL); 2896 2553 if (!dd->port->command_list) { ··· 2903 2560 /* Clear the memory we have allocated. */ 2904 2561 memset(dd->port->command_list, 2905 2562 0, 2906 - HW_PORT_PRIV_DMA_SZ + (ATA_SECT_SIZE * 2)); 2563 + HW_PORT_PRIV_DMA_SZ + (ATA_SECT_SIZE * 4)); 2907 2564 2908 2565 /* Setup the addresse of the RX FIS. */ 2909 2566 dd->port->rxfis = dd->port->command_list + HW_CMD_SLOT_SZ; ··· 2919 2576 dd->port->identify_dma = dd->port->command_tbl_dma + 2920 2577 HW_CMD_TBL_AR_SZ; 2921 2578 2922 - /* Setup the address of the sector buffer. */ 2579 + /* Setup the address of the sector buffer - for some non-ncq cmds */ 2923 2580 dd->port->sector_buffer = (void *) dd->port->identify + ATA_SECT_SIZE; 2924 2581 dd->port->sector_buffer_dma = dd->port->identify_dma + ATA_SECT_SIZE; 2582 + 2583 + /* Setup the address of the log buf - for read log command */ 2584 + dd->port->log_buf = (void *)dd->port->sector_buffer + ATA_SECT_SIZE; 2585 + dd->port->log_buf_dma = dd->port->sector_buffer_dma + ATA_SECT_SIZE; 2586 + 2587 + /* Setup the address of the smart buf - for smart read data command */ 2588 + dd->port->smart_buf = (void *)dd->port->log_buf + ATA_SECT_SIZE; 2589 + dd->port->smart_buf_dma = dd->port->log_buf_dma + ATA_SECT_SIZE; 2590 + 2925 2591 2926 2592 /* Point the command headers at the command tables. */ 2927 2593 for (i = 0; i < num_command_slots; i++) { ··· 2975 2623 dd->port->mmio + i*0x80 + PORT_SDBV; 2976 2624 } 2977 2625 2978 - /* Reset the HBA. */ 2979 - if (mtip_hba_reset(dd) < 0) { 2980 - dev_err(&dd->pdev->dev, 2981 - "Card did not reset within timeout\n"); 2982 - rv = -EIO; 2626 + timetaken = jiffies; 2627 + timeout = jiffies + msecs_to_jiffies(30000); 2628 + while (((readl(dd->port->mmio + PORT_SCR_STAT) & 0x0F) != 0x03) && 2629 + time_before(jiffies, timeout)) { 2630 + mdelay(100); 2631 + } 2632 + if (unlikely(mtip_check_surprise_removal(dd->pdev))) { 2633 + timetaken = jiffies - timetaken; 2634 + dev_warn(&dd->pdev->dev, 2635 + "Surprise removal detected at %u ms\n", 2636 + jiffies_to_msecs(timetaken)); 2637 + rv = -ENODEV; 2638 + goto out2 ; 2639 + } 2640 + if (unlikely(test_bit(MTIP_DDF_REMOVE_PENDING_BIT, &dd->dd_flag))) { 2641 + timetaken = jiffies - timetaken; 2642 + dev_warn(&dd->pdev->dev, 2643 + "Removal detected at %u ms\n", 2644 + jiffies_to_msecs(timetaken)); 2645 + rv = -EFAULT; 2983 2646 goto out2; 2647 + } 2648 + 2649 + /* Conditionally reset the HBA. */ 2650 + if (!(readl(dd->mmio + HOST_CAP) & HOST_CAP_NZDMA)) { 2651 + if (mtip_hba_reset(dd) < 0) { 2652 + dev_err(&dd->pdev->dev, 2653 + "Card did not reset within timeout\n"); 2654 + rv = -EIO; 2655 + goto out2; 2656 + } 2657 + } else { 2658 + /* Clear any pending interrupts on the HBA */ 2659 + writel(readl(dd->mmio + HOST_IRQ_STAT), 2660 + dd->mmio + HOST_IRQ_STAT); 2984 2661 } 2985 2662 2986 2663 mtip_init_port(dd->port); ··· 3041 2660 mod_timer(&dd->port->cmd_timer, 3042 2661 jiffies + msecs_to_jiffies(MTIP_TIMEOUT_CHECK_PERIOD)); 3043 2662 2663 + 2664 + if (test_bit(MTIP_DDF_REMOVE_PENDING_BIT, &dd->dd_flag)) { 2665 + rv = -EFAULT; 2666 + goto out3; 2667 + } 2668 + 3044 2669 if (mtip_get_identify(dd->port, NULL) < 0) { 3045 2670 rv = -EFAULT; 3046 2671 goto out3; ··· 3054 2667 3055 2668 if (*(dd->port->identify + MTIP_FTL_REBUILD_OFFSET) == 3056 2669 MTIP_FTL_REBUILD_MAGIC) { 3057 - set_bit(MTIP_FLAG_REBUILD_BIT, &dd->port->flags); 2670 + set_bit(MTIP_PF_REBUILD_BIT, &dd->port->flags); 3058 2671 return MTIP_FTL_REBUILD_MAGIC; 3059 2672 } 3060 2673 mtip_dump_identify(dd->port); 2674 + 2675 + /* check write protect, over temp and rebuild statuses */ 2676 + rv = mtip_read_log_page(dd->port, ATA_LOG_SATA_NCQ, 2677 + dd->port->log_buf, 2678 + dd->port->log_buf_dma, 1); 2679 + if (rv) { 2680 + dev_warn(&dd->pdev->dev, 2681 + "Error in READ LOG EXT (10h) command\n"); 2682 + /* non-critical error, don't fail the load */ 2683 + } else { 2684 + buf = (unsigned char *)dd->port->log_buf; 2685 + if (buf[259] & 0x1) { 2686 + dev_info(&dd->pdev->dev, 2687 + "Write protect bit is set.\n"); 2688 + set_bit(MTIP_DDF_WRITE_PROTECT_BIT, &dd->dd_flag); 2689 + } 2690 + if (buf[288] == 0xF7) { 2691 + dev_info(&dd->pdev->dev, 2692 + "Exceeded Tmax, drive in thermal shutdown.\n"); 2693 + set_bit(MTIP_DDF_OVER_TEMP_BIT, &dd->dd_flag); 2694 + } 2695 + if (buf[288] == 0xBF) { 2696 + dev_info(&dd->pdev->dev, 2697 + "Drive indicates rebuild has failed.\n"); 2698 + /* TODO */ 2699 + } 2700 + } 2701 + 2702 + /* get write protect progess */ 2703 + memset(&attr242, 0, sizeof(struct smart_attr)); 2704 + if (mtip_get_smart_attr(dd->port, 242, &attr242)) 2705 + dev_warn(&dd->pdev->dev, 2706 + "Unable to check write protect progress\n"); 2707 + else 2708 + dev_info(&dd->pdev->dev, 2709 + "Write protect progress: %d%% (%d blocks)\n", 2710 + attr242.cur, attr242.data); 3061 2711 return rv; 3062 2712 3063 2713 out3: ··· 3112 2688 3113 2689 /* Free the command/command header memory. */ 3114 2690 dmam_free_coherent(&dd->pdev->dev, 3115 - HW_PORT_PRIV_DMA_SZ + (ATA_SECT_SIZE * 2), 2691 + HW_PORT_PRIV_DMA_SZ + (ATA_SECT_SIZE * 4), 3116 2692 dd->port->command_list, 3117 2693 dd->port->command_list_dma); 3118 2694 out1: ··· 3136 2712 * Send standby immediate (E0h) to the drive so that it 3137 2713 * saves its state. 3138 2714 */ 3139 - if (atomic_read(&dd->drv_cleanup_done) != true) { 2715 + if (!test_bit(MTIP_DDF_CLEANUP_BIT, &dd->dd_flag)) { 3140 2716 3141 - mtip_standby_immediate(dd->port); 2717 + if (!test_bit(MTIP_PF_REBUILD_BIT, &dd->port->flags)) 2718 + if (mtip_standby_immediate(dd->port)) 2719 + dev_warn(&dd->pdev->dev, 2720 + "STANDBY IMMEDIATE failed\n"); 3142 2721 3143 2722 /* de-initialize the port. */ 3144 2723 mtip_deinit_port(dd->port); ··· 3161 2734 3162 2735 /* Free the command/command header memory. */ 3163 2736 dmam_free_coherent(&dd->pdev->dev, 3164 - HW_PORT_PRIV_DMA_SZ + (ATA_SECT_SIZE * 2), 2737 + HW_PORT_PRIV_DMA_SZ + (ATA_SECT_SIZE * 4), 3165 2738 dd->port->command_list, 3166 2739 dd->port->command_list_dma); 3167 2740 /* Free the memory allocated for the for structure. */ ··· 3319 2892 if (!dd) 3320 2893 return -ENOTTY; 3321 2894 2895 + if (unlikely(test_bit(MTIP_DDF_REMOVE_PENDING_BIT, &dd->dd_flag))) 2896 + return -ENOTTY; 2897 + 3322 2898 switch (cmd) { 3323 2899 case BLKFLSBUF: 3324 2900 return -ENOTTY; ··· 3355 2925 return -EACCES; 3356 2926 3357 2927 if (!dd) 2928 + return -ENOTTY; 2929 + 2930 + if (unlikely(test_bit(MTIP_DDF_REMOVE_PENDING_BIT, &dd->dd_flag))) 3358 2931 return -ENOTTY; 3359 2932 3360 2933 switch (cmd) { ··· 3482 3049 int nents = 0; 3483 3050 int tag = 0; 3484 3051 3052 + if (unlikely(dd->dd_flag & MTIP_DDF_STOP_IO)) { 3053 + if (unlikely(test_bit(MTIP_DDF_REMOVE_PENDING_BIT, 3054 + &dd->dd_flag))) { 3055 + bio_endio(bio, -ENXIO); 3056 + return; 3057 + } 3058 + if (unlikely(test_bit(MTIP_DDF_OVER_TEMP_BIT, &dd->dd_flag))) { 3059 + bio_endio(bio, -ENODATA); 3060 + return; 3061 + } 3062 + if (unlikely(test_bit(MTIP_DDF_WRITE_PROTECT_BIT, 3063 + &dd->dd_flag) && 3064 + bio_data_dir(bio))) { 3065 + bio_endio(bio, -ENODATA); 3066 + return; 3067 + } 3068 + } 3069 + 3485 3070 if (unlikely(!bio_has_data(bio))) { 3486 3071 blk_queue_flush(queue, 0); 3487 3072 bio_endio(bio, 0); ··· 3512 3061 3513 3062 if (unlikely((bio)->bi_vcnt > MTIP_MAX_SG)) { 3514 3063 dev_warn(&dd->pdev->dev, 3515 - "Maximum number of SGL entries exceeded"); 3064 + "Maximum number of SGL entries exceeded\n"); 3516 3065 bio_io_error(bio); 3517 3066 mtip_hw_release_scatterlist(dd, tag); 3518 3067 return; ··· 3661 3210 kobject_put(kobj); 3662 3211 } 3663 3212 3664 - if (dd->mtip_svc_handler) 3213 + if (dd->mtip_svc_handler) { 3214 + set_bit(MTIP_DDF_INIT_DONE_BIT, &dd->dd_flag); 3665 3215 return rv; /* service thread created for handling rebuild */ 3216 + } 3666 3217 3667 3218 start_service_thread: 3668 3219 sprintf(thd_name, "mtip_svc_thd_%02d", index); ··· 3673 3220 dd, thd_name); 3674 3221 3675 3222 if (IS_ERR(dd->mtip_svc_handler)) { 3676 - printk(KERN_ERR "mtip32xx: service thread failed to start\n"); 3223 + dev_err(&dd->pdev->dev, "service thread failed to start\n"); 3677 3224 dd->mtip_svc_handler = NULL; 3678 3225 rv = -EFAULT; 3679 3226 goto kthread_run_error; 3680 3227 } 3228 + 3229 + if (wait_for_rebuild == MTIP_FTL_REBUILD_MAGIC) 3230 + rv = wait_for_rebuild; 3681 3231 3682 3232 return rv; 3683 3233 ··· 3722 3266 struct kobject *kobj; 3723 3267 3724 3268 if (dd->mtip_svc_handler) { 3725 - set_bit(MTIP_FLAG_SVC_THD_SHOULD_STOP_BIT, &dd->port->flags); 3269 + set_bit(MTIP_PF_SVC_THD_STOP_BIT, &dd->port->flags); 3726 3270 wake_up_interruptible(&dd->port->svc_wait); 3727 3271 kthread_stop(dd->mtip_svc_handler); 3728 3272 } 3729 3273 3730 - /* Clean up the sysfs attributes managed by the protocol layer. */ 3731 - kobj = kobject_get(&disk_to_dev(dd->disk)->kobj); 3732 - if (kobj) { 3733 - mtip_hw_sysfs_exit(dd, kobj); 3734 - kobject_put(kobj); 3274 + /* Clean up the sysfs attributes, if created */ 3275 + if (test_bit(MTIP_DDF_INIT_DONE_BIT, &dd->dd_flag)) { 3276 + kobj = kobject_get(&disk_to_dev(dd->disk)->kobj); 3277 + if (kobj) { 3278 + mtip_hw_sysfs_exit(dd, kobj); 3279 + kobject_put(kobj); 3280 + } 3735 3281 } 3736 3282 3737 3283 /* ··· 3741 3283 * from /dev 3742 3284 */ 3743 3285 del_gendisk(dd->disk); 3286 + 3287 + spin_lock(&rssd_index_lock); 3288 + ida_remove(&rssd_index_ida, dd->index); 3289 + spin_unlock(&rssd_index_lock); 3290 + 3744 3291 blk_cleanup_queue(dd->queue); 3745 3292 dd->disk = NULL; 3746 3293 dd->queue = NULL; ··· 3775 3312 3776 3313 /* Delete our gendisk structure, and cleanup the blk queue. */ 3777 3314 del_gendisk(dd->disk); 3315 + 3316 + spin_lock(&rssd_index_lock); 3317 + ida_remove(&rssd_index_ida, dd->index); 3318 + spin_unlock(&rssd_index_lock); 3319 + 3778 3320 blk_cleanup_queue(dd->queue); 3779 3321 dd->disk = NULL; 3780 3322 dd->queue = NULL; ··· 3826 3358 "Unable to allocate memory for driver data\n"); 3827 3359 return -ENOMEM; 3828 3360 } 3829 - 3830 - /* Set the atomic variable as 1 in case of SRSI */ 3831 - atomic_set(&dd->drv_cleanup_done, true); 3832 - 3833 - atomic_set(&dd->resumeflag, false); 3834 3361 3835 3362 /* Attach the private data to this PCI device. */ 3836 3363 pci_set_drvdata(pdev, dd); ··· 3883 3420 * instance number. 3884 3421 */ 3885 3422 instance++; 3886 - 3423 + if (rv != MTIP_FTL_REBUILD_MAGIC) 3424 + set_bit(MTIP_DDF_INIT_DONE_BIT, &dd->dd_flag); 3887 3425 goto done; 3888 3426 3889 3427 block_initialize_err: ··· 3898 3434 pci_set_drvdata(pdev, NULL); 3899 3435 return rv; 3900 3436 done: 3901 - /* Set the atomic variable as 0 in case of SRSI */ 3902 - atomic_set(&dd->drv_cleanup_done, true); 3903 - 3904 3437 return rv; 3905 3438 } 3906 3439 ··· 3913 3452 struct driver_data *dd = pci_get_drvdata(pdev); 3914 3453 int counter = 0; 3915 3454 3455 + set_bit(MTIP_DDF_REMOVE_PENDING_BIT, &dd->dd_flag); 3456 + 3916 3457 if (mtip_check_surprise_removal(pdev)) { 3917 - while (atomic_read(&dd->drv_cleanup_done) == false) { 3458 + while (!test_bit(MTIP_DDF_CLEANUP_BIT, &dd->dd_flag)) { 3918 3459 counter++; 3919 3460 msleep(20); 3920 3461 if (counter == 10) { ··· 3926 3463 } 3927 3464 } 3928 3465 } 3929 - /* Set the atomic variable as 1 in case of SRSI */ 3930 - atomic_set(&dd->drv_cleanup_done, true); 3931 3466 3932 3467 /* Clean up the block layer. */ 3933 3468 mtip_block_remove(dd); ··· 3954 3493 return -EFAULT; 3955 3494 } 3956 3495 3957 - atomic_set(&dd->resumeflag, true); 3496 + set_bit(MTIP_DDF_RESUME_BIT, &dd->dd_flag); 3958 3497 3959 3498 /* Disable ports & interrupts then send standby immediate */ 3960 3499 rv = mtip_block_suspend(dd); ··· 4020 3559 dev_err(&pdev->dev, "Unable to resume\n"); 4021 3560 4022 3561 err: 4023 - atomic_set(&dd->resumeflag, false); 3562 + clear_bit(MTIP_DDF_RESUME_BIT, &dd->dd_flag); 4024 3563 4025 3564 return rv; 4026 3565 } ··· 4069 3608 */ 4070 3609 static int __init mtip_init(void) 4071 3610 { 3611 + int error; 3612 + 4072 3613 printk(KERN_INFO MTIP_DRV_NAME " Version " MTIP_DRV_VERSION "\n"); 4073 3614 4074 3615 /* Allocate a major block device number to use with this driver. */ 4075 - mtip_major = register_blkdev(0, MTIP_DRV_NAME); 4076 - if (mtip_major < 0) { 3616 + error = register_blkdev(0, MTIP_DRV_NAME); 3617 + if (error <= 0) { 4077 3618 printk(KERN_ERR "Unable to register block device (%d)\n", 4078 - mtip_major); 3619 + error); 4079 3620 return -EBUSY; 4080 3621 } 3622 + mtip_major = error; 4081 3623 4082 3624 /* Register our PCI operations. */ 4083 - return pci_register_driver(&mtip_pci_driver); 3625 + error = pci_register_driver(&mtip_pci_driver); 3626 + if (error) 3627 + unregister_blkdev(mtip_major, MTIP_DRV_NAME); 3628 + 3629 + return error; 4084 3630 } 4085 3631 4086 3632 /*
+45 -13
drivers/block/mtip32xx/mtip32xx.h
··· 34 34 /* offset of Device Control register in PCIe extended capabilites space */ 35 35 #define PCIE_CONFIG_EXT_DEVICE_CONTROL_OFFSET 0x48 36 36 37 - /* # of times to retry timed out IOs */ 38 - #define MTIP_MAX_RETRIES 5 37 + /* # of times to retry timed out/failed IOs */ 38 + #define MTIP_MAX_RETRIES 2 39 39 40 40 /* Various timeout values in ms */ 41 41 #define MTIP_NCQ_COMMAND_TIMEOUT_MS 5000 ··· 114 114 #define __force_bit2int (unsigned int __force) 115 115 116 116 /* below are bit numbers in 'flags' defined in mtip_port */ 117 - #define MTIP_FLAG_IC_ACTIVE_BIT 0 118 - #define MTIP_FLAG_EH_ACTIVE_BIT 1 119 - #define MTIP_FLAG_SVC_THD_ACTIVE_BIT 2 120 - #define MTIP_FLAG_ISSUE_CMDS_BIT 4 121 - #define MTIP_FLAG_REBUILD_BIT 5 122 - #define MTIP_FLAG_SVC_THD_SHOULD_STOP_BIT 8 117 + #define MTIP_PF_IC_ACTIVE_BIT 0 /* pio/ioctl */ 118 + #define MTIP_PF_EH_ACTIVE_BIT 1 /* error handling */ 119 + #define MTIP_PF_SE_ACTIVE_BIT 2 /* secure erase */ 120 + #define MTIP_PF_DM_ACTIVE_BIT 3 /* download microcde */ 121 + #define MTIP_PF_PAUSE_IO ((1 << MTIP_PF_IC_ACTIVE_BIT) | \ 122 + (1 << MTIP_PF_EH_ACTIVE_BIT) | \ 123 + (1 << MTIP_PF_SE_ACTIVE_BIT) | \ 124 + (1 << MTIP_PF_DM_ACTIVE_BIT)) 125 + 126 + #define MTIP_PF_SVC_THD_ACTIVE_BIT 4 127 + #define MTIP_PF_ISSUE_CMDS_BIT 5 128 + #define MTIP_PF_REBUILD_BIT 6 129 + #define MTIP_PF_SVC_THD_STOP_BIT 8 130 + 131 + /* below are bit numbers in 'dd_flag' defined in driver_data */ 132 + #define MTIP_DDF_REMOVE_PENDING_BIT 1 133 + #define MTIP_DDF_OVER_TEMP_BIT 2 134 + #define MTIP_DDF_WRITE_PROTECT_BIT 3 135 + #define MTIP_DDF_STOP_IO ((1 << MTIP_DDF_REMOVE_PENDING_BIT) | \ 136 + (1 << MTIP_DDF_OVER_TEMP_BIT) | \ 137 + (1 << MTIP_DDF_WRITE_PROTECT_BIT)) 138 + 139 + #define MTIP_DDF_CLEANUP_BIT 5 140 + #define MTIP_DDF_RESUME_BIT 6 141 + #define MTIP_DDF_INIT_DONE_BIT 7 142 + #define MTIP_DDF_REBUILD_FAILED_BIT 8 143 + 144 + __packed struct smart_attr{ 145 + u8 attr_id; 146 + u16 flags; 147 + u8 cur; 148 + u8 worst; 149 + u32 data; 150 + u8 res[3]; 151 + }; 123 152 124 153 /* Register Frame Information Structure (FIS), host to device. */ 125 154 struct host_to_dev_fis { ··· 374 345 * when the command slot and all associated data structures 375 346 * are no longer needed. 376 347 */ 348 + u16 *log_buf; 349 + dma_addr_t log_buf_dma; 350 + 351 + u8 *smart_buf; 352 + dma_addr_t smart_buf_dma; 353 + 377 354 unsigned long allocated[SLOTBITS_IN_LONGS]; 378 355 /* 379 356 * used to queue commands when an internal command is in progress ··· 403 368 * Timer used to complete commands that have been active for too long. 404 369 */ 405 370 struct timer_list cmd_timer; 371 + unsigned long ic_pause_timer; 406 372 /* 407 373 * Semaphore used to block threads if there are no 408 374 * command slots available. ··· 440 404 441 405 unsigned slot_groups; /* number of slot groups the product supports */ 442 406 443 - atomic_t drv_cleanup_done; /* Atomic variable for SRSI */ 444 - 445 407 unsigned long index; /* Index to determine the disk name */ 446 408 447 - unsigned int ftlrebuildflag; /* FTL rebuild flag */ 448 - 449 - atomic_t resumeflag; /* Atomic variable to track suspend/resume */ 409 + unsigned long dd_flag; /* NOTE: use atomic bit operations on this */ 450 410 451 411 struct task_struct *mtip_svc_handler; /* task_struct of svc thd */ 452 412 };
+1
drivers/block/virtio_blk.c
··· 351 351 cap_str_10, cap_str_2); 352 352 353 353 set_capacity(vblk->disk, capacity); 354 + revalidate_disk(vblk->disk); 354 355 done: 355 356 mutex_unlock(&vblk->config_lock); 356 357 }
+13 -37
drivers/block/xen-blkback/blkback.c
··· 321 321 static void xen_blkbk_unmap(struct pending_req *req) 322 322 { 323 323 struct gnttab_unmap_grant_ref unmap[BLKIF_MAX_SEGMENTS_PER_REQUEST]; 324 + struct page *pages[BLKIF_MAX_SEGMENTS_PER_REQUEST]; 324 325 unsigned int i, invcount = 0; 325 326 grant_handle_t handle; 326 327 int ret; ··· 333 332 gnttab_set_unmap_op(&unmap[invcount], vaddr(req, i), 334 333 GNTMAP_host_map, handle); 335 334 pending_handle(req, i) = BLKBACK_INVALID_HANDLE; 335 + pages[invcount] = virt_to_page(vaddr(req, i)); 336 336 invcount++; 337 337 } 338 338 339 - ret = HYPERVISOR_grant_table_op( 340 - GNTTABOP_unmap_grant_ref, unmap, invcount); 339 + ret = gnttab_unmap_refs(unmap, pages, invcount, false); 341 340 BUG_ON(ret); 342 - /* 343 - * Note, we use invcount, so nr->pages, so we can't index 344 - * using vaddr(req, i). 345 - */ 346 - for (i = 0; i < invcount; i++) { 347 - ret = m2p_remove_override( 348 - virt_to_page(unmap[i].host_addr), false); 349 - if (ret) { 350 - pr_alert(DRV_PFX "Failed to remove M2P override for %lx\n", 351 - (unsigned long)unmap[i].host_addr); 352 - continue; 353 - } 354 - } 355 341 } 356 342 357 343 static int xen_blkbk_map(struct blkif_request *req, ··· 366 378 pending_req->blkif->domid); 367 379 } 368 380 369 - ret = HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, map, nseg); 381 + ret = gnttab_map_refs(map, NULL, &blkbk->pending_page(pending_req, 0), nseg); 370 382 BUG_ON(ret); 371 383 372 384 /* ··· 386 398 if (ret) 387 399 continue; 388 400 389 - ret = m2p_add_override(PFN_DOWN(map[i].dev_bus_addr), 390 - blkbk->pending_page(pending_req, i), NULL); 391 - if (ret) { 392 - pr_alert(DRV_PFX "Failed to install M2P override for %lx (ret: %d)\n", 393 - (unsigned long)map[i].dev_bus_addr, ret); 394 - /* We could switch over to GNTTABOP_copy */ 395 - continue; 396 - } 397 - 398 401 seg[i].buf = map[i].dev_bus_addr | 399 402 (req->u.rw.seg[i].first_sect << 9); 400 403 } ··· 398 419 int err = 0; 399 420 int status = BLKIF_RSP_OKAY; 400 421 struct block_device *bdev = blkif->vbd.bdev; 422 + unsigned long secure; 401 423 402 424 blkif->st_ds_req++; 403 425 404 426 xen_blkif_get(blkif); 405 - if (blkif->blk_backend_type == BLKIF_BACKEND_PHY || 406 - blkif->blk_backend_type == BLKIF_BACKEND_FILE) { 407 - unsigned long secure = (blkif->vbd.discard_secure && 408 - (req->u.discard.flag & BLKIF_DISCARD_SECURE)) ? 409 - BLKDEV_DISCARD_SECURE : 0; 410 - err = blkdev_issue_discard(bdev, 411 - req->u.discard.sector_number, 412 - req->u.discard.nr_sectors, 413 - GFP_KERNEL, secure); 414 - } else 415 - err = -EOPNOTSUPP; 427 + secure = (blkif->vbd.discard_secure && 428 + (req->u.discard.flag & BLKIF_DISCARD_SECURE)) ? 429 + BLKDEV_DISCARD_SECURE : 0; 430 + 431 + err = blkdev_issue_discard(bdev, req->u.discard.sector_number, 432 + req->u.discard.nr_sectors, 433 + GFP_KERNEL, secure); 416 434 417 435 if (err == -EOPNOTSUPP) { 418 436 pr_debug(DRV_PFX "discard op failed, not supported\n"); ··· 806 830 int i, mmap_pages; 807 831 int rc = 0; 808 832 809 - if (!xen_pv_domain()) 833 + if (!xen_domain()) 810 834 return -ENODEV; 811 835 812 836 blkbk = kzalloc(sizeof(struct xen_blkbk), GFP_KERNEL);
-6
drivers/block/xen-blkback/common.h
··· 146 146 BLKIF_PROTOCOL_X86_64 = 3, 147 147 }; 148 148 149 - enum blkif_backend_type { 150 - BLKIF_BACKEND_PHY = 1, 151 - BLKIF_BACKEND_FILE = 2, 152 - }; 153 - 154 149 struct xen_vbd { 155 150 /* What the domain refers to this vbd as. */ 156 151 blkif_vdev_t handle; ··· 172 177 unsigned int irq; 173 178 /* Comms information. */ 174 179 enum blkif_protocol blk_protocol; 175 - enum blkif_backend_type blk_backend_type; 176 180 union blkif_back_rings blk_rings; 177 181 void *blk_ring; 178 182 /* The VBD attached to this interface. */
+33 -58
drivers/block/xen-blkback/xenbus.c
··· 381 381 err = xenbus_printf(xbt, dev->nodename, "feature-flush-cache", 382 382 "%d", state); 383 383 if (err) 384 - xenbus_dev_fatal(dev, err, "writing feature-flush-cache"); 384 + dev_warn(&dev->dev, "writing feature-flush-cache (%d)", err); 385 385 386 386 return err; 387 387 } 388 388 389 - int xen_blkbk_discard(struct xenbus_transaction xbt, struct backend_info *be) 389 + static void xen_blkbk_discard(struct xenbus_transaction xbt, struct backend_info *be) 390 390 { 391 391 struct xenbus_device *dev = be->dev; 392 392 struct xen_blkif *blkif = be->blkif; 393 - char *type; 394 393 int err; 395 394 int state = 0; 395 + struct block_device *bdev = be->blkif->vbd.bdev; 396 + struct request_queue *q = bdev_get_queue(bdev); 396 397 397 - type = xenbus_read(XBT_NIL, dev->nodename, "type", NULL); 398 - if (!IS_ERR(type)) { 399 - if (strncmp(type, "file", 4) == 0) { 400 - state = 1; 401 - blkif->blk_backend_type = BLKIF_BACKEND_FILE; 398 + if (blk_queue_discard(q)) { 399 + err = xenbus_printf(xbt, dev->nodename, 400 + "discard-granularity", "%u", 401 + q->limits.discard_granularity); 402 + if (err) { 403 + dev_warn(&dev->dev, "writing discard-granularity (%d)", err); 404 + return; 402 405 } 403 - if (strncmp(type, "phy", 3) == 0) { 404 - struct block_device *bdev = be->blkif->vbd.bdev; 405 - struct request_queue *q = bdev_get_queue(bdev); 406 - if (blk_queue_discard(q)) { 407 - err = xenbus_printf(xbt, dev->nodename, 408 - "discard-granularity", "%u", 409 - q->limits.discard_granularity); 410 - if (err) { 411 - xenbus_dev_fatal(dev, err, 412 - "writing discard-granularity"); 413 - goto kfree; 414 - } 415 - err = xenbus_printf(xbt, dev->nodename, 416 - "discard-alignment", "%u", 417 - q->limits.discard_alignment); 418 - if (err) { 419 - xenbus_dev_fatal(dev, err, 420 - "writing discard-alignment"); 421 - goto kfree; 422 - } 423 - state = 1; 424 - blkif->blk_backend_type = BLKIF_BACKEND_PHY; 425 - } 426 - /* Optional. */ 427 - err = xenbus_printf(xbt, dev->nodename, 428 - "discard-secure", "%d", 429 - blkif->vbd.discard_secure); 430 - if (err) { 431 - xenbus_dev_fatal(dev, err, 432 - "writting discard-secure"); 433 - goto kfree; 434 - } 406 + err = xenbus_printf(xbt, dev->nodename, 407 + "discard-alignment", "%u", 408 + q->limits.discard_alignment); 409 + if (err) { 410 + dev_warn(&dev->dev, "writing discard-alignment (%d)", err); 411 + return; 435 412 } 436 - } else { 437 - err = PTR_ERR(type); 438 - xenbus_dev_fatal(dev, err, "reading type"); 439 - goto out; 413 + state = 1; 414 + /* Optional. */ 415 + err = xenbus_printf(xbt, dev->nodename, 416 + "discard-secure", "%d", 417 + blkif->vbd.discard_secure); 418 + if (err) { 419 + dev_warn(dev-dev, "writing discard-secure (%d)", err); 420 + return; 421 + } 440 422 } 441 - 442 423 err = xenbus_printf(xbt, dev->nodename, "feature-discard", 443 424 "%d", state); 444 425 if (err) 445 - xenbus_dev_fatal(dev, err, "writing feature-discard"); 446 - kfree: 447 - kfree(type); 448 - out: 449 - return err; 426 + dev_warn(&dev->dev, "writing feature-discard (%d)", err); 450 427 } 451 428 int xen_blkbk_barrier(struct xenbus_transaction xbt, 452 429 struct backend_info *be, int state) ··· 434 457 err = xenbus_printf(xbt, dev->nodename, "feature-barrier", 435 458 "%d", state); 436 459 if (err) 437 - xenbus_dev_fatal(dev, err, "writing feature-barrier"); 460 + dev_warn(&dev->dev, "writing feature-barrier (%d)", err); 438 461 439 462 return err; 440 463 } ··· 666 689 return; 667 690 } 668 691 669 - err = xen_blkbk_flush_diskcache(xbt, be, be->blkif->vbd.flush_support); 670 - if (err) 671 - goto abort; 672 - 673 - err = xen_blkbk_discard(xbt, be); 674 - 675 692 /* If we can't advertise it is OK. */ 676 - err = xen_blkbk_barrier(xbt, be, be->blkif->vbd.flush_support); 693 + xen_blkbk_flush_diskcache(xbt, be, be->blkif->vbd.flush_support); 694 + 695 + xen_blkbk_discard(xbt, be); 696 + 697 + xen_blkbk_barrier(xbt, be, be->blkif->vbd.flush_support); 677 698 678 699 err = xenbus_printf(xbt, dev->nodename, "sectors", "%llu", 679 700 (unsigned long long)vbd_sz(&be->blkif->vbd));
+20 -21
drivers/block/xen-blkfront.c
··· 43 43 #include <linux/slab.h> 44 44 #include <linux/mutex.h> 45 45 #include <linux/scatterlist.h> 46 + #include <linux/bitmap.h> 46 47 47 48 #include <xen/xen.h> 48 49 #include <xen/xenbus.h> ··· 82 81 */ 83 82 struct blkfront_info 84 83 { 84 + spinlock_t io_lock; 85 85 struct mutex mutex; 86 86 struct xenbus_device *xbdev; 87 87 struct gendisk *gd; ··· 106 104 unsigned int discard_alignment; 107 105 int is_ready; 108 106 }; 109 - 110 - static DEFINE_SPINLOCK(blkif_io_lock); 111 107 112 108 static unsigned int nr_minors; 113 109 static unsigned long *minors; ··· 177 177 178 178 spin_lock(&minor_lock); 179 179 if (find_next_bit(minors, end, minor) >= end) { 180 - for (; minor < end; ++minor) 181 - __set_bit(minor, minors); 180 + bitmap_set(minors, minor, nr); 182 181 rc = 0; 183 182 } else 184 183 rc = -EBUSY; ··· 192 193 193 194 BUG_ON(end > nr_minors); 194 195 spin_lock(&minor_lock); 195 - for (; minor < end; ++minor) 196 - __clear_bit(minor, minors); 196 + bitmap_clear(minors, minor, nr); 197 197 spin_unlock(&minor_lock); 198 198 } 199 199 ··· 417 419 struct request_queue *rq; 418 420 struct blkfront_info *info = gd->private_data; 419 421 420 - rq = blk_init_queue(do_blkif_request, &blkif_io_lock); 422 + rq = blk_init_queue(do_blkif_request, &info->io_lock); 421 423 if (rq == NULL) 422 424 return -1; 423 425 ··· 634 636 if (info->rq == NULL) 635 637 return; 636 638 637 - spin_lock_irqsave(&blkif_io_lock, flags); 639 + spin_lock_irqsave(&info->io_lock, flags); 638 640 639 641 /* No more blkif_request(). */ 640 642 blk_stop_queue(info->rq); 641 643 642 644 /* No more gnttab callback work. */ 643 645 gnttab_cancel_free_callback(&info->callback); 644 - spin_unlock_irqrestore(&blkif_io_lock, flags); 646 + spin_unlock_irqrestore(&info->io_lock, flags); 645 647 646 648 /* Flush gnttab callback work. Must be done with no locks held. */ 647 649 flush_work_sync(&info->work); ··· 673 675 { 674 676 struct blkfront_info *info = container_of(work, struct blkfront_info, work); 675 677 676 - spin_lock_irq(&blkif_io_lock); 678 + spin_lock_irq(&info->io_lock); 677 679 if (info->connected == BLKIF_STATE_CONNECTED) 678 680 kick_pending_request_queues(info); 679 - spin_unlock_irq(&blkif_io_lock); 681 + spin_unlock_irq(&info->io_lock); 680 682 } 681 683 682 684 static void blkif_free(struct blkfront_info *info, int suspend) 683 685 { 684 686 /* Prevent new requests being issued until we fix things up. */ 685 - spin_lock_irq(&blkif_io_lock); 687 + spin_lock_irq(&info->io_lock); 686 688 info->connected = suspend ? 687 689 BLKIF_STATE_SUSPENDED : BLKIF_STATE_DISCONNECTED; 688 690 /* No more blkif_request(). */ ··· 690 692 blk_stop_queue(info->rq); 691 693 /* No more gnttab callback work. */ 692 694 gnttab_cancel_free_callback(&info->callback); 693 - spin_unlock_irq(&blkif_io_lock); 695 + spin_unlock_irq(&info->io_lock); 694 696 695 697 /* Flush gnttab callback work. Must be done with no locks held. */ 696 698 flush_work_sync(&info->work); ··· 726 728 struct blkfront_info *info = (struct blkfront_info *)dev_id; 727 729 int error; 728 730 729 - spin_lock_irqsave(&blkif_io_lock, flags); 731 + spin_lock_irqsave(&info->io_lock, flags); 730 732 731 733 if (unlikely(info->connected != BLKIF_STATE_CONNECTED)) { 732 - spin_unlock_irqrestore(&blkif_io_lock, flags); 734 + spin_unlock_irqrestore(&info->io_lock, flags); 733 735 return IRQ_HANDLED; 734 736 } 735 737 ··· 814 816 815 817 kick_pending_request_queues(info); 816 818 817 - spin_unlock_irqrestore(&blkif_io_lock, flags); 819 + spin_unlock_irqrestore(&info->io_lock, flags); 818 820 819 821 return IRQ_HANDLED; 820 822 } ··· 989 991 } 990 992 991 993 mutex_init(&info->mutex); 994 + spin_lock_init(&info->io_lock); 992 995 info->xbdev = dev; 993 996 info->vdevice = vdevice; 994 997 info->connected = BLKIF_STATE_DISCONNECTED; ··· 1067 1068 1068 1069 xenbus_switch_state(info->xbdev, XenbusStateConnected); 1069 1070 1070 - spin_lock_irq(&blkif_io_lock); 1071 + spin_lock_irq(&info->io_lock); 1071 1072 1072 1073 /* Now safe for us to use the shared ring */ 1073 1074 info->connected = BLKIF_STATE_CONNECTED; ··· 1078 1079 /* Kick any other new requests queued since we resumed */ 1079 1080 kick_pending_request_queues(info); 1080 1081 1081 - spin_unlock_irq(&blkif_io_lock); 1082 + spin_unlock_irq(&info->io_lock); 1082 1083 1083 1084 return 0; 1084 1085 } ··· 1276 1277 xenbus_switch_state(info->xbdev, XenbusStateConnected); 1277 1278 1278 1279 /* Kick pending requests. */ 1279 - spin_lock_irq(&blkif_io_lock); 1280 + spin_lock_irq(&info->io_lock); 1280 1281 info->connected = BLKIF_STATE_CONNECTED; 1281 1282 kick_pending_request_queues(info); 1282 - spin_unlock_irq(&blkif_io_lock); 1283 + spin_unlock_irq(&info->io_lock); 1283 1284 1284 1285 add_disk(info->gd); 1285 1286 ··· 1409 1410 mutex_lock(&blkfront_mutex); 1410 1411 1411 1412 bdev = bdget_disk(disk, 0); 1412 - bdput(bdev); 1413 1413 1414 1414 if (bdev->bd_openers) 1415 1415 goto out; ··· 1439 1441 } 1440 1442 1441 1443 out: 1444 + bdput(bdev); 1442 1445 mutex_unlock(&blkfront_mutex); 1443 1446 return 0; 1444 1447 }