Commit c104f1fa authored by Linus Torvalds's avatar Linus Torvalds

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
parents d8dd0b6d 63634806
What: /sys/block/rssd*/registers
Date: March 2012
KernelVersion: 3.3
Contact: Asai Thambi S P <asamymuthupa@micron.com>
Description: This is a read-only file. Dumps below driver information and
hardware registers.
- S ACTive
- Command Issue
- Allocated
- Completed
- PORT IRQ STAT
- HOST IRQ STAT
What: /sys/block/rssd*/status
Date: April 2012
KernelVersion: 3.4
Contact: Asai Thambi S P <asamymuthupa@micron.com>
Description: This is a read-only file. Indicates the status of the device.
...@@ -866,6 +866,7 @@ cciss_scsi_detect(ctlr_info_t *h) ...@@ -866,6 +866,7 @@ cciss_scsi_detect(ctlr_info_t *h)
sh->can_queue = cciss_tape_cmds; sh->can_queue = cciss_tape_cmds;
sh->sg_tablesize = h->maxsgentries; sh->sg_tablesize = h->maxsgentries;
sh->max_cmd_len = MAX_COMMAND_SIZE; sh->max_cmd_len = MAX_COMMAND_SIZE;
sh->max_sectors = h->cciss_max_sectors;
((struct cciss_scsi_adapter_data_t *) ((struct cciss_scsi_adapter_data_t *)
h->scsi_ctlr)->scsi_host = sh; h->scsi_ctlr)->scsi_host = sh;
...@@ -1410,7 +1411,7 @@ static void cciss_scatter_gather(ctlr_info_t *h, CommandList_struct *c, ...@@ -1410,7 +1411,7 @@ static void cciss_scatter_gather(ctlr_info_t *h, CommandList_struct *c,
/* track how many SG entries we are using */ /* track how many SG entries we are using */
if (request_nsgs > h->maxSG) if (request_nsgs > h->maxSG)
h->maxSG = request_nsgs; h->maxSG = request_nsgs;
c->Header.SGTotal = (__u8) request_nsgs + chained; c->Header.SGTotal = (u16) request_nsgs + chained;
if (request_nsgs > h->max_cmd_sgentries) if (request_nsgs > h->max_cmd_sgentries)
c->Header.SGList = h->max_cmd_sgentries; c->Header.SGList = h->max_cmd_sgentries;
else else
......
...@@ -4,6 +4,6 @@ ...@@ -4,6 +4,6 @@
config BLK_DEV_PCIESSD_MTIP32XX config BLK_DEV_PCIESSD_MTIP32XX
tristate "Block Device Driver for Micron PCIe SSDs" tristate "Block Device Driver for Micron PCIe SSDs"
depends on HOTPLUG_PCI_PCIE depends on PCI
help help
This enables the block driver for Micron PCIe SSDs. This enables the block driver for Micron PCIe SSDs.
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include <linux/idr.h> #include <linux/idr.h>
#include <linux/kthread.h> #include <linux/kthread.h>
#include <../drivers/ata/ahci.h> #include <../drivers/ata/ahci.h>
#include <linux/export.h>
#include "mtip32xx.h" #include "mtip32xx.h"
#define HW_CMD_SLOT_SZ (MTIP_MAX_COMMAND_SLOTS * 32) #define HW_CMD_SLOT_SZ (MTIP_MAX_COMMAND_SLOTS * 32)
...@@ -44,6 +45,7 @@ ...@@ -44,6 +45,7 @@
#define HW_PORT_PRIV_DMA_SZ \ #define HW_PORT_PRIV_DMA_SZ \
(HW_CMD_SLOT_SZ + HW_CMD_TBL_AR_SZ + AHCI_RX_FIS_SZ) (HW_CMD_SLOT_SZ + HW_CMD_TBL_AR_SZ + AHCI_RX_FIS_SZ)
#define HOST_CAP_NZDMA (1 << 19)
#define HOST_HSORG 0xFC #define HOST_HSORG 0xFC
#define HSORG_DISABLE_SLOTGRP_INTR (1<<24) #define HSORG_DISABLE_SLOTGRP_INTR (1<<24)
#define HSORG_DISABLE_SLOTGRP_PXIS (1<<16) #define HSORG_DISABLE_SLOTGRP_PXIS (1<<16)
...@@ -139,6 +141,12 @@ static void mtip_command_cleanup(struct driver_data *dd) ...@@ -139,6 +141,12 @@ static void mtip_command_cleanup(struct driver_data *dd)
int group = 0, commandslot = 0, commandindex = 0; int group = 0, commandslot = 0, commandindex = 0;
struct mtip_cmd *command; struct mtip_cmd *command;
struct mtip_port *port = dd->port; struct mtip_port *port = dd->port;
static int in_progress;
if (in_progress)
return;
in_progress = 1;
for (group = 0; group < 4; group++) { for (group = 0; group < 4; group++) {
for (commandslot = 0; commandslot < 32; commandslot++) { for (commandslot = 0; commandslot < 32; commandslot++) {
...@@ -165,7 +173,8 @@ static void mtip_command_cleanup(struct driver_data *dd) ...@@ -165,7 +173,8 @@ static void mtip_command_cleanup(struct driver_data *dd)
up(&port->cmd_slot); up(&port->cmd_slot);
atomic_set(&dd->drv_cleanup_done, true); set_bit(MTIP_DDF_CLEANUP_BIT, &dd->dd_flag);
in_progress = 0;
} }
/* /*
...@@ -262,6 +271,9 @@ static int hba_reset_nosleep(struct driver_data *dd) ...@@ -262,6 +271,9 @@ static int hba_reset_nosleep(struct driver_data *dd)
&& time_before(jiffies, timeout)) && time_before(jiffies, timeout))
mdelay(1); mdelay(1);
if (test_bit(MTIP_DDF_REMOVE_PENDING_BIT, &dd->dd_flag))
return -1;
if (readl(dd->mmio + HOST_CTL) & HOST_RESET) if (readl(dd->mmio + HOST_CTL) & HOST_RESET)
return -1; return -1;
...@@ -294,6 +306,10 @@ static inline void mtip_issue_ncq_command(struct mtip_port *port, int tag) ...@@ -294,6 +306,10 @@ static inline void mtip_issue_ncq_command(struct mtip_port *port, int tag)
port->cmd_issue[MTIP_TAG_INDEX(tag)]); port->cmd_issue[MTIP_TAG_INDEX(tag)]);
spin_unlock_irqrestore(&port->cmd_issue_lock, flags); spin_unlock_irqrestore(&port->cmd_issue_lock, flags);
/* Set the command's timeout value.*/
port->commands[tag].comp_time = jiffies + msecs_to_jiffies(
MTIP_NCQ_COMMAND_TIMEOUT_MS);
} }
/* /*
...@@ -420,7 +436,12 @@ static void mtip_init_port(struct mtip_port *port) ...@@ -420,7 +436,12 @@ static void mtip_init_port(struct mtip_port *port)
writel(0xFFFFFFFF, port->completed[i]); writel(0xFFFFFFFF, port->completed[i]);
/* Clear any pending interrupts for this port */ /* Clear any pending interrupts for this port */
writel(readl(port->mmio + PORT_IRQ_STAT), port->mmio + PORT_IRQ_STAT); writel(readl(port->dd->mmio + PORT_IRQ_STAT),
port->dd->mmio + PORT_IRQ_STAT);
/* Clear any pending interrupts on the HBA. */
writel(readl(port->dd->mmio + HOST_IRQ_STAT),
port->dd->mmio + HOST_IRQ_STAT);
/* Enable port interrupts */ /* Enable port interrupts */
writel(DEF_PORT_IRQ, port->mmio + PORT_IRQ_MASK); writel(DEF_PORT_IRQ, port->mmio + PORT_IRQ_MASK);
...@@ -447,6 +468,9 @@ static void mtip_restart_port(struct mtip_port *port) ...@@ -447,6 +468,9 @@ static void mtip_restart_port(struct mtip_port *port)
&& time_before(jiffies, timeout)) && time_before(jiffies, timeout))
; ;
if (test_bit(MTIP_DDF_REMOVE_PENDING_BIT, &port->dd->dd_flag))
return;
/* /*
* Chip quirk: escalate to hba reset if * Chip quirk: escalate to hba reset if
* PxCMD.CR not clear after 500 ms * PxCMD.CR not clear after 500 ms
...@@ -475,6 +499,9 @@ static void mtip_restart_port(struct mtip_port *port) ...@@ -475,6 +499,9 @@ static void mtip_restart_port(struct mtip_port *port)
while (time_before(jiffies, timeout)) while (time_before(jiffies, timeout))
; ;
if (test_bit(MTIP_DDF_REMOVE_PENDING_BIT, &port->dd->dd_flag))
return;
/* Clear PxSCTL.DET */ /* Clear PxSCTL.DET */
writel(readl(port->mmio + PORT_SCR_CTL) & ~1, writel(readl(port->mmio + PORT_SCR_CTL) & ~1,
port->mmio + PORT_SCR_CTL); port->mmio + PORT_SCR_CTL);
...@@ -486,15 +513,35 @@ static void mtip_restart_port(struct mtip_port *port) ...@@ -486,15 +513,35 @@ static void mtip_restart_port(struct mtip_port *port)
&& time_before(jiffies, timeout)) && time_before(jiffies, timeout))
; ;
if (test_bit(MTIP_DDF_REMOVE_PENDING_BIT, &port->dd->dd_flag))
return;
if ((readl(port->mmio + PORT_SCR_STAT) & 0x01) == 0) if ((readl(port->mmio + PORT_SCR_STAT) & 0x01) == 0)
dev_warn(&port->dd->pdev->dev, dev_warn(&port->dd->pdev->dev,
"COM reset failed\n"); "COM reset failed\n");
/* Clear SError, the PxSERR.DIAG.x should be set so clear it */ mtip_init_port(port);
writel(readl(port->mmio + PORT_SCR_ERR), port->mmio + PORT_SCR_ERR); mtip_start_port(port);
/* Enable the DMA engine */ }
mtip_enable_engine(port, 1);
/*
* Helper function for tag logging
*/
static void print_tags(struct driver_data *dd,
char *msg,
unsigned long *tagbits,
int cnt)
{
unsigned char tagmap[128];
int group, tagmap_len = 0;
memset(tagmap, 0, sizeof(tagmap));
for (group = SLOTBITS_IN_LONGS; group > 0; group--)
tagmap_len = sprintf(tagmap + tagmap_len, "%016lX ",
tagbits[group-1]);
dev_warn(&dd->pdev->dev,
"%d command(s) %s: tagmap [%s]", cnt, msg, tagmap);
} }
/* /*
...@@ -514,15 +561,18 @@ static void mtip_timeout_function(unsigned long int data) ...@@ -514,15 +561,18 @@ static void mtip_timeout_function(unsigned long int data)
int tag, cmdto_cnt = 0; int tag, cmdto_cnt = 0;
unsigned int bit, group; unsigned int bit, group;
unsigned int num_command_slots = port->dd->slot_groups * 32; unsigned int num_command_slots = port->dd->slot_groups * 32;
unsigned long to, tagaccum[SLOTBITS_IN_LONGS];
if (unlikely(!port)) if (unlikely(!port))
return; return;
if (atomic_read(&port->dd->resumeflag) == true) { if (test_bit(MTIP_DDF_RESUME_BIT, &port->dd->dd_flag)) {
mod_timer(&port->cmd_timer, mod_timer(&port->cmd_timer,
jiffies + msecs_to_jiffies(30000)); jiffies + msecs_to_jiffies(30000));
return; return;
} }
/* clear the tag accumulator */
memset(tagaccum, 0, SLOTBITS_IN_LONGS * sizeof(long));
for (tag = 0; tag < num_command_slots; tag++) { for (tag = 0; tag < num_command_slots; tag++) {
/* /*
...@@ -540,12 +590,10 @@ static void mtip_timeout_function(unsigned long int data) ...@@ -540,12 +590,10 @@ static void mtip_timeout_function(unsigned long int data)
command = &port->commands[tag]; command = &port->commands[tag];
fis = (struct host_to_dev_fis *) command->command; fis = (struct host_to_dev_fis *) command->command;
dev_warn(&port->dd->pdev->dev, set_bit(tag, tagaccum);
"Timeout for command tag %d\n", tag);
cmdto_cnt++; cmdto_cnt++;
if (cmdto_cnt == 1) if (cmdto_cnt == 1)
set_bit(MTIP_FLAG_EH_ACTIVE_BIT, &port->flags); set_bit(MTIP_PF_EH_ACTIVE_BIT, &port->flags);
/* /*
* Clear the completed bit. This should prevent * Clear the completed bit. This should prevent
...@@ -578,15 +626,29 @@ static void mtip_timeout_function(unsigned long int data) ...@@ -578,15 +626,29 @@ static void mtip_timeout_function(unsigned long int data)
} }
} }
if (cmdto_cnt) { if (cmdto_cnt && !test_bit(MTIP_PF_IC_ACTIVE_BIT, &port->flags)) {
dev_warn(&port->dd->pdev->dev, print_tags(port->dd, "timed out", tagaccum, cmdto_cnt);
"%d commands timed out: restarting port",
cmdto_cnt);
mtip_restart_port(port); mtip_restart_port(port);
clear_bit(MTIP_FLAG_EH_ACTIVE_BIT, &port->flags); clear_bit(MTIP_PF_EH_ACTIVE_BIT, &port->flags);
wake_up_interruptible(&port->svc_wait); wake_up_interruptible(&port->svc_wait);
} }
if (port->ic_pause_timer) {
to = port->ic_pause_timer + msecs_to_jiffies(1000);
if (time_after(jiffies, to)) {
if (!test_bit(MTIP_PF_IC_ACTIVE_BIT, &port->flags)) {
port->ic_pause_timer = 0;
clear_bit(MTIP_PF_SE_ACTIVE_BIT, &port->flags);
clear_bit(MTIP_PF_DM_ACTIVE_BIT, &port->flags);
clear_bit(MTIP_PF_IC_ACTIVE_BIT, &port->flags);
wake_up_interruptible(&port->svc_wait);
}
}
}
/* Restart the timer */ /* Restart the timer */
mod_timer(&port->cmd_timer, mod_timer(&port->cmd_timer,
jiffies + msecs_to_jiffies(MTIP_TIMEOUT_CHECK_PERIOD)); jiffies + msecs_to_jiffies(MTIP_TIMEOUT_CHECK_PERIOD));
...@@ -681,23 +743,18 @@ static void mtip_completion(struct mtip_port *port, ...@@ -681,23 +743,18 @@ static void mtip_completion(struct mtip_port *port,
complete(waiting); complete(waiting);
} }
/* static void mtip_null_completion(struct mtip_port *port,
* Helper function for tag logging int tag,
*/ void *data,
static void print_tags(struct driver_data *dd, int status)
char *msg,
unsigned long *tagbits)
{ {
unsigned int tag, count = 0; return;
for (tag = 0; tag < (dd->slot_groups) * 32; tag++) {
if (test_bit(tag, tagbits))
count++;
}
if (count)
dev_info(&dd->pdev->dev, "%s [%i tags]\n", msg, count);
} }
static int mtip_read_log_page(struct mtip_port *port, u8 page, u16 *buffer,
dma_addr_t buffer_dma, unsigned int sectors);
static int mtip_get_smart_attr(struct mtip_port *port, unsigned int id,
struct smart_attr *attrib);
/* /*
* Handle an error. * Handle an error.
* *
...@@ -708,12 +765,16 @@ static void print_tags(struct driver_data *dd, ...@@ -708,12 +765,16 @@ static void print_tags(struct driver_data *dd,
*/ */
static void mtip_handle_tfe(struct driver_data *dd) static void mtip_handle_tfe(struct driver_data *dd)
{ {
int group, tag, bit, reissue; int group, tag, bit, reissue, rv;
struct mtip_port *port; struct mtip_port *port;
struct mtip_cmd *command; struct mtip_cmd *cmd;
u32 completed; u32 completed;
struct host_to_dev_fis *fis; struct host_to_dev_fis *fis;
unsigned long tagaccum[SLOTBITS_IN_LONGS]; unsigned long tagaccum[SLOTBITS_IN_LONGS];
unsigned int cmd_cnt = 0;
unsigned char *buf;
char *fail_reason = NULL;
int fail_all_ncq_write = 0, fail_all_ncq_cmds = 0;
dev_warn(&dd->pdev->dev, "Taskfile error\n"); dev_warn(&dd->pdev->dev, "Taskfile error\n");
...@@ -722,8 +783,11 @@ static void mtip_handle_tfe(struct driver_data *dd) ...@@ -722,8 +783,11 @@ static void mtip_handle_tfe(struct driver_data *dd)
/* Stop the timer to prevent command timeouts. */ /* Stop the timer to prevent command timeouts. */
del_timer(&port->cmd_timer); del_timer(&port->cmd_timer);
/* clear the tag accumulator */
memset(tagaccum, 0, SLOTBITS_IN_LONGS * sizeof(long));
/* Set eh_active */ /* Set eh_active */
set_bit(MTIP_FLAG_EH_ACTIVE_BIT, &port->flags); set_bit(MTIP_PF_EH_ACTIVE_BIT, &port->flags);
/* Loop through all the groups */ /* Loop through all the groups */
for (group = 0; group < dd->slot_groups; group++) { for (group = 0; group < dd->slot_groups; group++) {
...@@ -732,9 +796,6 @@ static void mtip_handle_tfe(struct driver_data *dd) ...@@ -732,9 +796,6 @@ static void mtip_handle_tfe(struct driver_data *dd)
/* clear completed status register in the hardware.*/ /* clear completed status register in the hardware.*/
writel(completed, port->completed[group]); writel(completed, port->completed[group]);
/* clear the tag accumulator */
memset(tagaccum, 0, SLOTBITS_IN_LONGS * sizeof(long));
/* Process successfully completed commands */ /* Process successfully completed commands */
for (bit = 0; bit < 32 && completed; bit++) { for (bit = 0; bit < 32 && completed; bit++) {
if (!(completed & (1<<bit))) if (!(completed & (1<<bit)))
...@@ -745,13 +806,14 @@ static void mtip_handle_tfe(struct driver_data *dd) ...@@ -745,13 +806,14 @@ static void mtip_handle_tfe(struct driver_data *dd)
if (tag == MTIP_TAG_INTERNAL) if (tag == MTIP_TAG_INTERNAL)
continue; continue;
command = &port->commands[tag]; cmd = &port->commands[tag];
if (likely(command->comp_func)) { if (likely(cmd->comp_func)) {
set_bit(tag, tagaccum); set_bit(tag, tagaccum);
atomic_set(&port->commands[tag].active, 0); cmd_cnt++;
command->comp_func(port, atomic_set(&cmd->active, 0);
cmd->comp_func(port,
tag, tag,
command->comp_data, cmd->comp_data,
0); 0);
} else { } else {
dev_err(&port->dd->pdev->dev, dev_err(&port->dd->pdev->dev,
...@@ -765,12 +827,45 @@ static void mtip_handle_tfe(struct driver_data *dd) ...@@ -765,12 +827,45 @@ static void mtip_handle_tfe(struct driver_data *dd)
} }
} }
} }
print_tags(dd, "TFE tags completed:", tagaccum);
print_tags(dd, "completed (TFE)", tagaccum, cmd_cnt);
/* Restart the port */ /* Restart the port */
mdelay(20); mdelay(20);
mtip_restart_port(port); mtip_restart_port(port);
/* Trying to determine the cause of the error */
rv = mtip_read_log_page(dd->port, ATA_LOG_SATA_NCQ,
dd->port->log_buf,
dd->port->log_buf_dma, 1);
if (rv) {
dev_warn(&dd->pdev->dev,
"Error in READ LOG EXT (10h) command\n");
/* non-critical error, don't fail the load */
} else {
buf = (unsigned char *)dd->port->log_buf;
if (buf[259] & 0x1) {
dev_info(&dd->pdev->dev,
"Write protect bit is set.\n");
set_bit(MTIP_DDF_WRITE_PROTECT_BIT, &dd->dd_flag);
fail_all_ncq_write = 1;
fail_reason = "write protect";
}
if (buf[288] == 0xF7) {
dev_info(&dd->pdev->dev,
"Exceeded Tmax, drive in thermal shutdown.\n");
set_bit(MTIP_DDF_OVER_TEMP_BIT, &dd->dd_flag);
fail_all_ncq_cmds = 1;
fail_reason = "thermal shutdown";
}
if (buf[288] == 0xBF) {
dev_info(&dd->pdev->dev,
"Drive indicates rebuild has failed.\n");
fail_all_ncq_cmds = 1;
fail_reason = "rebuild failed";
}
}
/* clear the tag accumulator */ /* clear the tag accumulator */
memset(tagaccum, 0, SLOTBITS_IN_LONGS * sizeof(long)); memset(tagaccum, 0, SLOTBITS_IN_LONGS * sizeof(long));
...@@ -779,32 +874,47 @@ static void mtip_handle_tfe(struct driver_data *dd) ...@@ -779,32 +874,47 @@ static void mtip_handle_tfe(struct driver_data *dd)
for (bit = 0; bit < 32; bit++) { for (bit = 0; bit < 32; bit++) {
reissue = 1; reissue = 1;
tag = (group << 5) + bit; tag = (group << 5) + bit;
cmd = &port->commands[tag];
/* If the active bit is set re-issue the command */ /* If the active bit is set re-issue the command */
if (atomic_read(&port->commands[tag].active) == 0) if (atomic_read(&cmd->active) == 0)
continue; continue;
fis = (struct host_to_dev_fis *) fis = (struct host_to_dev_fis *)cmd->command;
port->commands[tag].command;
/* Should re-issue? */ /* Should re-issue? */
if (tag == MTIP_TAG_INTERNAL || if (tag == MTIP_TAG_INTERNAL ||
fis->command == ATA_CMD_SET_FEATURES) fis->command == ATA_CMD_SET_FEATURES)
reissue = 0; reissue = 0;
else {
if (fail_all_ncq_cmds ||
(fail_all_ncq_write &&
fis->command == ATA_CMD_FPDMA_WRITE)) {
dev_warn(&dd->pdev->dev,
" Fail: %s w/tag %d [%s].\n",
fis->command == ATA_CMD_FPDMA_WRITE ?
"write" : "read",
tag,
fail_reason != NULL ?
fail_reason : "unknown");
atomic_set(&cmd->active, 0);
if (cmd->comp_func) {
cmd->comp_func(port, tag,
cmd->comp_data,
-ENODATA);
}
continue;
}
}
/* /*
* First check if this command has * First check if this command has
* exceeded its retries. * exceeded its retries.
*/ */
if (reissue && if (reissue && (cmd->retries-- > 0)) {
(port->commands[tag].retries-- > 0)) {
set_bit(tag, tagaccum); set_bit(tag, tagaccum);
/* Update the timeout value. */
port->commands[tag].comp_time =
jiffies + msecs_to_jiffies(
MTIP_NCQ_COMMAND_TIMEOUT_MS);
/* Re-issue the command. */ /* Re-issue the command. */
mtip_issue_ncq_command(port, tag); mtip_issue_ncq_command(port, tag);
...@@ -814,13 +924,13 @@ static void mtip_handle_tfe(struct driver_data *dd) ...@@ -814,13 +924,13 @@ static void mtip_handle_tfe(struct driver_data *dd)
/* Retire a command that will not be reissued */ /* Retire a command that will not be reissued */
dev_warn(&port->dd->pdev->dev, dev_warn(&port->dd->pdev->dev,
"retiring tag %d\n", tag); "retiring tag %d\n", tag);
atomic_set(&port->commands[tag].active, 0); atomic_set(&cmd->active, 0);
if (port->commands[tag].comp_func) if (cmd->comp_func)
port->commands[tag].comp_func( cmd->comp_func(
port, port,
tag, tag,
port->commands[tag].comp_data, cmd->comp_data,
PORT_IRQ_TF_ERR); PORT_IRQ_TF_ERR);
else else
dev_warn(&port->dd->pdev->dev, dev_warn(&port->dd->pdev->dev,
...@@ -828,10 +938,10 @@ static void mtip_handle_tfe(struct driver_data *dd) ...@@ -828,10 +938,10 @@ static void mtip_handle_tfe(struct driver_data *dd)
tag); tag);
} }
} }
print_tags(dd, "TFE tags reissued:", tagaccum); print_tags(dd, "reissued (TFE)", tagaccum, cmd_cnt);
/* clear eh_active */ /* clear eh_active */
clear_bit(MTIP_FLAG_EH_ACTIVE_BIT, &port->flags); clear_bit(MTIP_PF_EH_ACTIVE_BIT, &port->flags);
wake_up_interruptible(&port->svc_wait); wake_up_interruptible(&port->svc_wait);
mod_timer(&port->cmd_timer, mod_timer(&port->cmd_timer,
...@@ -899,7 +1009,7 @@ static inline void mtip_process_legacy(struct driver_data *dd, u32 port_stat) ...@@ -899,7 +1009,7 @@ static inline void mtip_process_legacy(struct driver_data *dd, u32 port_stat)
struct mtip_port *port = dd->port; struct mtip_port *port = dd->port;
struct mtip_cmd *cmd = &port->commands[MTIP_TAG_INTERNAL]; struct mtip_cmd *cmd = &port->commands[MTIP_TAG_INTERNAL];
if (test_bit(MTIP_FLAG_IC_ACTIVE_BIT, &port->flags) && if (test_bit(MTIP_PF_IC_ACTIVE_BIT, &port->flags) &&
(cmd != NULL) && !(readl(port->cmd_issue[MTIP_TAG_INTERNAL]) (cmd != NULL) && !(readl(port->cmd_issue[MTIP_TAG_INTERNAL])
& (1 << MTIP_TAG_INTERNAL))) { & (1 << MTIP_TAG_INTERNAL))) {
if (cmd->comp_func) { if (cmd->comp_func) {
...@@ -911,8 +1021,6 @@ static inline void mtip_process_legacy(struct driver_data *dd, u32 port_stat) ...@@ -911,8 +1021,6 @@ static inline void mtip_process_legacy(struct driver_data *dd, u32 port_stat)
} }
} }
dev_warn(&dd->pdev->dev, "IRQ status 0x%x ignored.\n", port_stat);
return; return;
} }
...@@ -968,6 +1076,9 @@ static inline irqreturn_t mtip_handle_irq(struct driver_data *data) ...@@ -968,6 +1076,9 @@ static inline irqreturn_t mtip_handle_irq(struct driver_data *data)
/* don't proceed further */ /* don't proceed further */
return IRQ_HANDLED; return IRQ_HANDLED;
} }
if (test_bit(MTIP_DDF_REMOVE_PENDING_BIT,
&dd->dd_flag))
return rv;
mtip_process_errors(dd, port_stat & PORT_IRQ_ERR); mtip_process_errors(dd, port_stat & PORT_IRQ_ERR);
} }
...@@ -1015,6 +1126,39 @@ static void mtip_issue_non_ncq_command(struct mtip_port *port, int tag) ...@@ -1015,6 +1126,39 @@ static void mtip_issue_non_ncq_command(struct mtip_port *port, int tag)
port->cmd_issue[MTIP_TAG_INDEX(tag)]); port->cmd_issue[MTIP_TAG_INDEX(tag)]);
} }
static bool mtip_pause_ncq(struct mtip_port *port,
struct host_to_dev_fis *fis)
{
struct host_to_dev_fis *reply;
unsigned long task_file_data;
reply = port->rxfis + RX_FIS_D2H_REG;
task_file_data = readl(port->mmio+PORT_TFDATA);
if ((task_file_data & 1) || (fis->command == ATA_CMD_SEC_ERASE_UNIT))
return false;
if (fis->command == ATA_CMD_SEC_ERASE_PREP) {
set_bit(MTIP_PF_SE_ACTIVE_BIT, &port->flags);
port->ic_pause_timer = jiffies;
return true;
} else if ((fis->command == ATA_CMD_DOWNLOAD_MICRO) &&
(fis->features == 0x03)) {
set_bit(MTIP_PF_DM_ACTIVE_BIT, &port->flags);
port->ic_pause_timer = jiffies;
return true;
} else if ((fis->command == ATA_CMD_SEC_ERASE_UNIT) ||
((fis->command == 0xFC) &&
(fis->features == 0x27 || fis->features == 0x72 ||
fis->features == 0x62 || fis->features == 0x26))) {
/* Com reset after secure erase or lowlevel format */
mtip_restart_port(port);
return false;
}
return false;
}
/* /*
* Wait for port to quiesce * Wait for port to quiesce
* *
...@@ -1033,11 +1177,13 @@ static int mtip_quiesce_io(struct mtip_port *port, unsigned long timeout) ...@@ -1033,11 +1177,13 @@ static int mtip_quiesce_io(struct mtip_port *port, unsigned long timeout)
to = jiffies + msecs_to_jiffies(timeout); to = jiffies + msecs_to_jiffies(timeout);
do { do {
if (test_bit(MTIP_FLAG_SVC_THD_ACTIVE_BIT, &port->flags) && if (test_bit(MTIP_PF_SVC_THD_ACTIVE_BIT, &port->flags) &&
test_bit(MTIP_FLAG_ISSUE_CMDS_BIT, &port->flags)) { test_bit(MTIP_PF_ISSUE_CMDS_BIT, &port->flags)) {
msleep(20); msleep(20);
continue; /* svc thd is actively issuing commands */ continue; /* svc thd is actively issuing commands */
} }
if (test_bit(MTIP_DDF_REMOVE_PENDING_BIT, &port->dd->dd_flag))
return -EFAULT;
/* /*
* Ignore s_active bit 0 of array element 0. * Ignore s_active bit 0 of array element 0.
* This bit will always be set * This bit will always be set
...@@ -1074,7 +1220,7 @@ static int mtip_quiesce_io(struct mtip_port *port, unsigned long timeout) ...@@ -1074,7 +1220,7 @@ static int mtip_quiesce_io(struct mtip_port *port, unsigned long timeout)
* -EAGAIN Time out waiting for command to complete. * -EAGAIN Time out waiting for command to complete.
*/ */
static int mtip_exec_internal_command(struct mtip_port *port, static int mtip_exec_internal_command(struct mtip_port *port,
void *fis, struct host_to_dev_fis *fis,
int fis_len, int fis_len,
dma_addr_t buffer, dma_addr_t buffer,
int buf_len, int buf_len,
...@@ -1084,8 +1230,9 @@ static int mtip_exec_internal_command(struct mtip_port *port, ...@@ -1084,8 +1230,9 @@ static int mtip_exec_internal_command(struct mtip_port *port,
{ {
struct mtip_cmd_sg *command_sg; struct mtip_cmd_sg *command_sg;
DECLARE_COMPLETION_ONSTACK(wait); DECLARE_COMPLETION_ONSTACK(wait);
int rv = 0; int rv = 0, ready2go = 1;
struct mtip_cmd *int_cmd = &port->commands[MTIP_TAG_INTERNAL]; struct mtip_cmd *int_cmd = &port->commands[MTIP_TAG_INTERNAL];
unsigned long to;
/* Make sure the buffer is 8 byte aligned. This is asic specific. */ /* Make sure the buffer is 8 byte aligned. This is asic specific. */
if (buffer & 0x00000007) { if (buffer & 0x00000007) {
...@@ -1094,23 +1241,38 @@ static int mtip_exec_internal_command(struct mtip_port *port, ...@@ -1094,23 +1241,38 @@ static int mtip_exec_internal_command(struct mtip_port *port,
return -EFAULT; return -EFAULT;
} }
/* Only one internal command should be running at a time */ to = jiffies + msecs_to_jiffies(timeout);
if (test_and_set_bit(MTIP_TAG_INTERNAL, port->allocated)) { do {
ready2go = !test_and_set_bit(MTIP_TAG_INTERNAL,
port->allocated);
if (ready2go)
break;
mdelay(100);
} while (time_before(jiffies, to));
if (!ready2go) {
dev_warn(&port->dd->pdev->dev, dev_warn(&port->dd->pdev->dev,
"Internal command already active\n"); "Internal cmd active. new cmd [%02X]\n", fis->command);
return -EBUSY; return -EBUSY;
} }
set_bit(MTIP_FLAG_IC_ACTIVE_BIT, &port->flags); set_bit(MTIP_PF_IC_ACTIVE_BIT, &port->flags);
port->ic_pause_timer = 0;
if (fis->command == ATA_CMD_SEC_ERASE_UNIT)
clear_bit(MTIP_PF_SE_ACTIVE_BIT, &port->flags);
else if (fis->command == ATA_CMD_DOWNLOAD_MICRO)
clear_bit(MTIP_PF_DM_ACTIVE_BIT, &port->flags);
if (atomic == GFP_KERNEL) { if (atomic == GFP_KERNEL) {
/* wait for io to complete if non atomic */ if (fis->command != ATA_CMD_STANDBYNOW1) {
if (mtip_quiesce_io(port, 5000) < 0) { /* wait for io to complete if non atomic */
dev_warn(&port->dd->pdev->dev, if (mtip_quiesce_io(port, 5000) < 0) {
"Failed to quiesce IO\n"); dev_warn(&port->dd->pdev->dev,
release_slot(port, MTIP_TAG_INTERNAL); "Failed to quiesce IO\n");
clear_bit(MTIP_FLAG_IC_ACTIVE_BIT, &port->flags); release_slot(port, MTIP_TAG_INTERNAL);
wake_up_interruptible(&port->svc_wait); clear_bit(MTIP_PF_IC_ACTIVE_BIT, &port->flags);
return -EBUSY; wake_up_interruptible(&port->svc_wait);
return -EBUSY;
}
} }
/* Set the completion function and data for the command. */ /* Set the completion function and data for the command. */
...@@ -1120,7 +1282,7 @@ static int mtip_exec_internal_command(struct mtip_port *port, ...@@ -1120,7 +1282,7 @@ static int mtip_exec_internal_command(struct mtip_port *port,
} else { } else {
/* Clear completion - we're going to poll */ /* Clear completion - we're going to poll */
int_cmd->comp_data = NULL; int_cmd->comp_data = NULL;
int_cmd->comp_func = NULL; int_cmd->comp_func = mtip_null_completion;
} }
/* Copy the command to the command table */ /* Copy the command to the command table */
...@@ -1159,6 +1321,12 @@ static int mtip_exec_internal_command(struct mtip_port *port, ...@@ -1159,6 +1321,12 @@ static int mtip_exec_internal_command(struct mtip_port *port,
"Internal command did not complete [%d] " "Internal command did not complete [%d] "
"within timeout of %lu ms\n", "within timeout of %lu ms\n",
atomic, timeout); atomic, timeout);
if (mtip_check_surprise_removal(port->dd->pdev) ||
test_bit(MTIP_DDF_REMOVE_PENDING_BIT,
&port->dd->dd_flag)) {
rv = -ENXIO;
goto exec_ic_exit;
}
rv = -EAGAIN; rv = -EAGAIN;
} }
...@@ -1166,31 +1334,59 @@ static int mtip_exec_internal_command(struct mtip_port *port, ...@@ -1166,31 +1334,59 @@ static int mtip_exec_internal_command(struct mtip_port *port,
& (1 << MTIP_TAG_INTERNAL)) { & (1 << MTIP_TAG_INTERNAL)) {
dev_warn(&port->dd->pdev->dev, dev_warn(&port->dd->pdev->dev,
"Retiring internal command but CI is 1.\n"); "Retiring internal command but CI is 1.\n");
if (test_bit(MTIP_DDF_REMOVE_PENDING_BIT,
&port->dd->dd_flag)) {
hba_reset_nosleep(port->dd);
rv = -ENXIO;
} else {
mtip_restart_port(port);
rv = -EAGAIN;
}
goto exec_ic_exit;
} }
} else { } else {
/* Spin for <timeout> checking if command still outstanding */ /* Spin for <timeout> checking if command still outstanding */
timeout = jiffies + msecs_to_jiffies(timeout); timeout = jiffies + msecs_to_jiffies(timeout);
while ((readl(port->cmd_issue[MTIP_TAG_INTERNAL])
while ((readl( & (1 << MTIP_TAG_INTERNAL))
port->cmd_issue[MTIP_TAG_INTERNAL]) && time_before(jiffies, timeout)) {
& (1 << MTIP_TAG_INTERNAL)) if (mtip_check_surprise_removal(port->dd->pdev)) {
&& time_before(jiffies, timeout)) rv = -ENXIO;
; goto exec_ic_exit;
}
if ((fis->command != ATA_CMD_STANDBYNOW1) &&
test_bit(MTIP_DDF_REMOVE_PENDING_BIT,
&port->dd->dd_flag)) {
rv = -ENXIO;
goto exec_ic_exit;
}
}
if (readl(port->cmd_issue[MTIP_TAG_INTERNAL]) if (readl(port->cmd_issue[MTIP_TAG_INTERNAL])
& (1 << MTIP_TAG_INTERNAL)) { & (1 << MTIP_TAG_INTERNAL)) {
dev_err(&port->dd->pdev->dev, dev_err(&port->dd->pdev->dev,
"Internal command did not complete [%d]\n", "Internal command did not complete [atomic]\n");
atomic);
rv = -EAGAIN; rv = -EAGAIN;
if (test_bit(MTIP_DDF_REMOVE_PENDING_BIT,
&port->dd->dd_flag)) {
hba_reset_nosleep(port->dd);
rv = -ENXIO;
} else {
mtip_restart_port(port);
rv = -EAGAIN;
}
} }
} }
exec_ic_exit:
/* Clear the allocated and active bits for the internal command. */ /* Clear the allocated and active bits for the internal command. */
atomic_set(&int_cmd->active, 0); atomic_set(&int_cmd->active, 0);
release_slot(port, MTIP_TAG_INTERNAL); release_slot(port, MTIP_TAG_INTERNAL);
clear_bit(MTIP_FLAG_IC_ACTIVE_BIT, &port->flags); if (rv >= 0 && mtip_pause_ncq(port, fis)) {
/* NCQ paused */
return rv;
}
clear_bit(MTIP_PF_IC_ACTIVE_BIT, &port->flags);
wake_up_interruptible(&port->svc_wait); wake_up_interruptible(&port->svc_wait);
return rv; return rv;
...@@ -1240,6 +1436,9 @@ static int mtip_get_identify(struct mtip_port *port, void __user *user_buffer) ...@@ -1240,6 +1436,9 @@ static int mtip_get_identify(struct mtip_port *port, void __user *user_buffer)
int rv = 0; int rv = 0;
struct host_to_dev_fis fis; struct host_to_dev_fis fis;
if (test_bit(MTIP_DDF_REMOVE_PENDING_BIT, &port->dd->dd_flag))
return -EFAULT;
/* Build the FIS. */ /* Build the FIS. */
memset(&fis, 0, sizeof(struct host_to_dev_fis)); memset(&fis, 0, sizeof(struct host_to_dev_fis));
fis.type = 0x27; fis.type = 0x27;
...@@ -1313,6 +1512,7 @@ static int mtip_standby_immediate(struct mtip_port *port) ...@@ -1313,6 +1512,7 @@ static int mtip_standby_immediate(struct mtip_port *port)
{ {
int rv; int rv;
struct host_to_dev_fis fis; struct host_to_dev_fis fis;
unsigned long start;
/* Build the FIS. */ /* Build the FIS. */
memset(&fis, 0, sizeof(struct host_to_dev_fis)); memset(&fis, 0, sizeof(struct host_to_dev_fis));
...@@ -1320,15 +1520,150 @@ static int mtip_standby_immediate(struct mtip_port *port) ...@@ -1320,15 +1520,150 @@ static int mtip_standby_immediate(struct mtip_port *port)
fis.opts = 1 << 7; fis.opts = 1 << 7;
fis.command = ATA_CMD_STANDBYNOW1; fis.command = ATA_CMD_STANDBYNOW1;
/* Execute the command. Use a 15-second timeout for large drives. */ start = jiffies;
rv = mtip_exec_internal_command(port, rv = mtip_exec_internal_command(port,
&fis, &fis,
5, 5,
0, 0,
0, 0,
0, 0,
GFP_KERNEL, GFP_ATOMIC,
15000); 15000);
dbg_printk(MTIP_DRV_NAME "Time taken to complete standby cmd: %d ms\n",
jiffies_to_msecs(jiffies - start));
if (rv)
dev_warn(&port->dd->pdev->dev,
"STANDBY IMMEDIATE command failed.\n");
return rv;
}
/*
* Issue a READ LOG EXT command to the device.
*
* @port pointer to the port structure.
* @page page number to fetch
* @buffer pointer to buffer
* @buffer_dma dma address corresponding to @buffer
* @sectors page length to fetch, in sectors
*
* return value
* @rv return value from mtip_exec_internal_command()
*/
static int mtip_read_log_page(struct mtip_port *port, u8 page, u16 *buffer,
dma_addr_t buffer_dma, unsigned int sectors)
{
struct host_to_dev_fis fis;
memset(&fis, 0, sizeof(struct host_to_dev_fis));
fis.type = 0x27;
fis.opts = 1 << 7;
fis.command = ATA_CMD_READ_LOG_EXT;
fis.sect_count = sectors & 0xFF;
fis.sect_cnt_ex = (sectors >> 8) & 0xFF;
fis.lba_low = page;
fis.lba_mid = 0;
fis.device = ATA_DEVICE_OBS;
memset(buffer, 0, sectors * ATA_SECT_SIZE);
return mtip_exec_internal_command(port,
&fis,
5,
buffer_dma,
sectors * ATA_SECT_SIZE,
0,
GFP_ATOMIC,
MTIP_INTERNAL_COMMAND_TIMEOUT_MS);
}
/*
* Issue a SMART READ DATA command to the device.
*
* @port pointer to the port structure.
* @buffer pointer to buffer
* @buffer_dma dma address corresponding to @buffer
*
* return value
* @rv return value from mtip_exec_internal_command()
*/
static int mtip_get_smart_data(struct mtip_port *port, u8 *buffer,
dma_addr_t buffer_dma)
{
struct host_to_dev_fis fis;
memset(&fis, 0, sizeof(struct host_to_dev_fis));
fis.type = 0x27;
fis.opts = 1 << 7;
fis.command = ATA_CMD_SMART;
fis.features = 0xD0;
fis.sect_count = 1;
fis.lba_mid = 0x4F;
fis.lba_hi = 0xC2;
fis.device = ATA_DEVICE_OBS;
return mtip_exec_internal_command(port,
&fis,
5,
buffer_dma,
ATA_SECT_SIZE,
0,
GFP_ATOMIC,
15000);
}
/*
* Get the value of a smart attribute
*
* @port pointer to the port structure
* @id attribute number
* @attrib pointer to return attrib information corresponding to @id
*
* return value
* -EINVAL NULL buffer passed or unsupported attribute @id.
* -EPERM Identify data not valid, SMART not supported or not enabled
*/
static int mtip_get_smart_attr(struct mtip_port *port, unsigned int id,
struct smart_attr *attrib)
{
int rv, i;
struct smart_attr *pattr;
if (!attrib)
return -EINVAL;
if (!port->identify_valid) {
dev_warn(&port->dd->pdev->dev, "IDENTIFY DATA not valid\n");
return -EPERM;
}
if (!(port->identify[82] & 0x1)) {
dev_warn(&port->dd->pdev->dev, "SMART not supported\n");
return -EPERM;
}
if (!(port->identify[85] & 0x1)) {
dev_warn(&port->dd->pdev->dev, "SMART not enabled\n");
return -EPERM;
}
memset(port->smart_buf, 0, ATA_SECT_SIZE);
rv = mtip_get_smart_data(port, port->smart_buf, port->smart_buf_dma);
if (rv) {
dev_warn(&port->dd->pdev->dev, "Failed to ge SMART data\n");
return rv;
}
pattr = (struct smart_attr *)(port->smart_buf + 2);
for (i = 0; i < 29; i++, pattr++)
if (pattr->attr_id == id) {
memcpy(attrib, pattr, sizeof(struct smart_attr));
break;
}
if (i == 29) {
dev_warn(&port->dd->pdev->dev,
"Query for invalid SMART attribute ID\n");
rv = -EINVAL;
}
return rv; return rv;
} }
...@@ -1504,10 +1839,7 @@ static int exec_drive_task(struct mtip_port *port, u8 *command) ...@@ -1504,10 +1839,7 @@ static int exec_drive_task(struct mtip_port *port, u8 *command)
fis.cyl_hi = command[5]; fis.cyl_hi = command[5];
fis.device = command[6] & ~0x10; /* Clear the dev bit*/ fis.device = command[6] & ~0x10; /* Clear the dev bit*/
dbg_printk(MTIP_DRV_NAME " %s: User Command: cmd %x, feat %x, nsect %x, sect %x, lcyl %x, hcyl %x, sel %x\n",
dbg_printk(MTIP_DRV_NAME "%s: User Command: cmd %x, feat %x, "
"nsect %x, sect %x, lcyl %x, "
"hcyl %x, sel %x\n",
__func__, __func__,
command[0], command[0],
command[1], command[1],
...@@ -1534,8 +1866,7 @@ static int exec_drive_task(struct mtip_port *port, u8 *command) ...@@ -1534,8 +1866,7 @@ static int exec_drive_task(struct mtip_port *port, u8 *command)
command[4] = reply->cyl_low; command[4] = reply->cyl_low;
command[5] = reply->cyl_hi; command[5] = reply->cyl_hi;
dbg_printk(MTIP_DRV_NAME "%s: Completion Status: stat %x, " dbg_printk(MTIP_DRV_NAME " %s: Completion Status: stat %x, err %x , cyl_lo %x cyl_hi %x\n",
"err %x , cyl_lo %x cyl_hi %x\n",
__func__, __func__,
command[0], command[0],
command[1], command[1],
...@@ -1578,7 +1909,7 @@ static int exec_drive_command(struct mtip_port *port, u8 *command, ...@@ -1578,7 +1909,7 @@ static int exec_drive_command(struct mtip_port *port, u8 *command,
} }
dbg_printk(MTIP_DRV_NAME dbg_printk(MTIP_DRV_NAME
"%s: User Command: cmd %x, sect %x, " " %s: User Command: cmd %x, sect %x, "
"feat %x, sectcnt %x\n", "feat %x, sectcnt %x\n",
__func__, __func__,
command[0], command[0],
...@@ -1607,7 +1938,7 @@ static int exec_drive_command(struct mtip_port *port, u8 *command, ...@@ -1607,7 +1938,7 @@ static int exec_drive_command(struct mtip_port *port, u8 *command,
command[2] = command[3]; command[2] = command[3];
dbg_printk(MTIP_DRV_NAME dbg_printk(MTIP_DRV_NAME
"%s: Completion Status: stat %x, " " %s: Completion Status: stat %x, "
"err %x, cmd %x\n", "err %x, cmd %x\n",
__func__, __func__,
command[0], command[0],
...@@ -1810,9 +2141,10 @@ static int exec_drive_taskfile(struct driver_data *dd, ...@@ -1810,9 +2141,10 @@ static int exec_drive_taskfile(struct driver_data *dd,
} }
dbg_printk(MTIP_DRV_NAME dbg_printk(MTIP_DRV_NAME
"taskfile: cmd %x, feat %x, nsect %x," " %s: cmd %x, feat %x, nsect %x,"
" sect/lbal %x, lcyl/lbam %x, hcyl/lbah %x," " sect/lbal %x, lcyl/lbam %x, hcyl/lbah %x,"
" head/dev %x\n", " head/dev %x\n",
__func__,
fis.command, fis.command,
fis.features, fis.features,
fis.sect_count, fis.sect_count,
...@@ -1823,8 +2155,8 @@ static int exec_drive_taskfile(struct driver_data *dd, ...@@ -1823,8 +2155,8 @@ static int exec_drive_taskfile(struct driver_data *dd,
switch (fis.command) { switch (fis.command) {
case ATA_CMD_DOWNLOAD_MICRO: case ATA_CMD_DOWNLOAD_MICRO:
/* Change timeout for Download Microcode to 60 seconds.*/ /* Change timeout for Download Microcode to 2 minutes */
timeout = 60000; timeout = 120000;
break; break;
case ATA_CMD_SEC_ERASE_UNIT: case ATA_CMD_SEC_ERASE_UNIT:
/* Change timeout for Security Erase Unit to 4 minutes.*/ /* Change timeout for Security Erase Unit to 4 minutes.*/
...@@ -1840,8 +2172,8 @@ static int exec_drive_taskfile(struct driver_data *dd, ...@@ -1840,8 +2172,8 @@ static int exec_drive_taskfile(struct driver_data *dd,
timeout = 10000; timeout = 10000;
break; break;
case ATA_CMD_SMART: case ATA_CMD_SMART:
/* Change timeout for vendor unique command to 10 secs */ /* Change timeout for vendor unique command to 15 secs */
timeout = 10000; timeout = 15000;
break; break;
default: default:
timeout = MTIP_IOCTL_COMMAND_TIMEOUT_MS; timeout = MTIP_IOCTL_COMMAND_TIMEOUT_MS;
...@@ -1903,18 +2235,8 @@ static int exec_drive_taskfile(struct driver_data *dd, ...@@ -1903,18 +2235,8 @@ static int exec_drive_taskfile(struct driver_data *dd,
req_task->hob_ports[1] = reply->features_ex; req_task->hob_ports[1] = reply->features_ex;
req_task->hob_ports[2] = reply->sect_cnt_ex; req_task->hob_ports[2] = reply->sect_cnt_ex;
} }
/* Com rest after secure erase or lowlevel format */
if (((fis.command == ATA_CMD_SEC_ERASE_UNIT) ||
((fis.command == 0xFC) &&
(fis.features == 0x27 || fis.features == 0x72 ||
fis.features == 0x62 || fis.features == 0x26))) &&
!(reply->command & 1)) {
mtip_restart_port(dd->port);
}
dbg_printk(MTIP_DRV_NAME dbg_printk(MTIP_DRV_NAME
"%s: Completion: stat %x," " %s: Completion: stat %x,"
"err %x, sect_cnt %x, lbalo %x," "err %x, sect_cnt %x, lbalo %x,"
"lbamid %x, lbahi %x, dev %x\n", "lbamid %x, lbahi %x, dev %x\n",
__func__, __func__,
...@@ -2080,14 +2402,10 @@ static void mtip_hw_submit_io(struct driver_data *dd, sector_t start, ...@@ -2080,14 +2402,10 @@ static void mtip_hw_submit_io(struct driver_data *dd, sector_t start,
struct host_to_dev_fis *fis; struct host_to_dev_fis *fis;
struct mtip_port *port = dd->port; struct mtip_port *port = dd->port;
struct mtip_cmd *command = &port->commands[tag]; struct mtip_cmd *command = &port->commands[tag];
int dma_dir = (dir == READ) ? DMA_FROM_DEVICE : DMA_TO_DEVICE;
/* Map the scatter list for DMA access */ /* Map the scatter list for DMA access */
if (dir == READ) nents = dma_map_sg(&dd->pdev->dev, command->sg, nents, dma_dir);
nents = dma_map_sg(&dd->pdev->dev, command->sg,
nents, DMA_FROM_DEVICE);
else
nents = dma_map_sg(&dd->pdev->dev, command->sg,
nents, DMA_TO_DEVICE);
command->scatter_ents = nents; command->scatter_ents = nents;
...@@ -2127,7 +2445,7 @@ static void mtip_hw_submit_io(struct driver_data *dd, sector_t start, ...@@ -2127,7 +2445,7 @@ static void mtip_hw_submit_io(struct driver_data *dd, sector_t start,
*/ */
command->comp_data = dd; command->comp_data = dd;
command->comp_func = mtip_async_complete; command->comp_func = mtip_async_complete;
command->direction = (dir == READ ? DMA_FROM_DEVICE : DMA_TO_DEVICE); command->direction = dma_dir;
/* /*
* Set the completion function and data for the command passed * Set the completion function and data for the command passed
...@@ -2140,19 +2458,16 @@ static void mtip_hw_submit_io(struct driver_data *dd, sector_t start, ...@@ -2140,19 +2458,16 @@ static void mtip_hw_submit_io(struct driver_data *dd, sector_t start,
* To prevent this command from being issued * To prevent this command from being issued
* if an internal command is in progress or error handling is active. * if an internal command is in progress or error handling is active.
*/ */
if (unlikely(test_bit(MTIP_FLAG_IC_ACTIVE_BIT, &port->flags) || if (port->flags & MTIP_PF_PAUSE_IO) {
test_bit(MTIP_FLAG_EH_ACTIVE_BIT, &port->flags))) {
set_bit(tag, port->cmds_to_issue); set_bit(tag, port->cmds_to_issue);
set_bit(MTIP_FLAG_ISSUE_CMDS_BIT, &port->flags); set_bit(MTIP_PF_ISSUE_CMDS_BIT, &port->flags);
return; return;
} }
/* Issue the command to the hardware */ /* Issue the command to the hardware */
mtip_issue_ncq_command(port, tag); mtip_issue_ncq_command(port, tag);
/* Set the command's timeout value.*/ return;
port->commands[tag].comp_time = jiffies + msecs_to_jiffies(
MTIP_NCQ_COMMAND_TIMEOUT_MS);
} }
/* /*
...@@ -2191,6 +2506,10 @@ static struct scatterlist *mtip_hw_get_scatterlist(struct driver_data *dd, ...@@ -2191,6 +2506,10 @@ static struct scatterlist *mtip_hw_get_scatterlist(struct driver_data *dd,
down(&dd->port->cmd_slot); down(&dd->port->cmd_slot);
*tag = get_slot(dd->port); *tag = get_slot(dd->port);
if (unlikely(test_bit(MTIP_DDF_REMOVE_PENDING_BIT, &dd->dd_flag))) {
up(&dd->port->cmd_slot);
return NULL;
}
if (unlikely(*tag < 0)) if (unlikely(*tag < 0))
return NULL; return NULL;
...@@ -2207,7 +2526,7 @@ static struct scatterlist *mtip_hw_get_scatterlist(struct driver_data *dd, ...@@ -2207,7 +2526,7 @@ static struct scatterlist *mtip_hw_get_scatterlist(struct driver_data *dd,
* return value * return value
* The size, in bytes, of the data copied into buf. * The size, in bytes, of the data copied into buf.
*/ */
static ssize_t hw_show_registers(struct device *dev, static ssize_t mtip_hw_show_registers(struct device *dev,
struct device_attribute *attr, struct device_attribute *attr,
char *buf) char *buf)
{ {
...@@ -2216,7 +2535,7 @@ static ssize_t hw_show_registers(struct device *dev, ...@@ -2216,7 +2535,7 @@ static ssize_t hw_show_registers(struct device *dev,
int size = 0; int size = 0;
int n; int n;
size += sprintf(&buf[size], "%s:\ns_active:\n", __func__); size += sprintf(&buf[size], "S ACTive:\n");
for (n = 0; n < dd->slot_groups; n++) for (n = 0; n < dd->slot_groups; n++)
size += sprintf(&buf[size], "0x%08x\n", size += sprintf(&buf[size], "0x%08x\n",
...@@ -2240,20 +2559,39 @@ static ssize_t hw_show_registers(struct device *dev, ...@@ -2240,20 +2559,39 @@ static ssize_t hw_show_registers(struct device *dev,
group_allocated); group_allocated);
} }
size += sprintf(&buf[size], "completed:\n"); size += sprintf(&buf[size], "Completed:\n");
for (n = 0; n < dd->slot_groups; n++) for (n = 0; n < dd->slot_groups; n++)
size += sprintf(&buf[size], "0x%08x\n", size += sprintf(&buf[size], "0x%08x\n",
readl(dd->port->completed[n])); readl(dd->port->completed[n]));
size += sprintf(&buf[size], "PORT_IRQ_STAT 0x%08x\n", size += sprintf(&buf[size], "PORT IRQ STAT : 0x%08x\n",
readl(dd->port->mmio + PORT_IRQ_STAT)); readl(dd->port->mmio + PORT_IRQ_STAT));
size += sprintf(&buf[size], "HOST_IRQ_STAT 0x%08x\n", size += sprintf(&buf[size], "HOST IRQ STAT : 0x%08x\n",
readl(dd->mmio + HOST_IRQ_STAT)); readl(dd->mmio + HOST_IRQ_STAT));
return size; return size;
} }
static DEVICE_ATTR(registers, S_IRUGO, hw_show_registers, NULL);
static ssize_t mtip_hw_show_status(struct device *dev,
struct device_attribute *attr,
char *buf)
{
struct driver_data *dd = dev_to_disk(dev)->private_data;
int size = 0;
if (test_bit(MTIP_DDF_OVER_TEMP_BIT, &dd->dd_flag))
size += sprintf(buf, "%s", "thermal_shutdown\n");
else if (test_bit(MTIP_DDF_WRITE_PROTECT_BIT, &dd->dd_flag))
size += sprintf(buf, "%s", "write_protect\n");
else
size += sprintf(buf, "%s", "online\n");
return size;
}
static DEVICE_ATTR(registers, S_IRUGO, mtip_hw_show_registers, NULL);
static DEVICE_ATTR(status, S_IRUGO, mtip_hw_show_status, NULL);
/* /*
* Create the sysfs related attributes. * Create the sysfs related attributes.
...@@ -2272,7 +2610,10 @@ static int mtip_hw_sysfs_init(struct driver_data *dd, struct kobject *kobj) ...@@ -2272,7 +2610,10 @@ static int mtip_hw_sysfs_init(struct driver_data *dd, struct kobject *kobj)
if (sysfs_create_file(kobj, &dev_attr_registers.attr)) if (sysfs_create_file(kobj, &dev_attr_registers.attr))
dev_warn(&dd->pdev->dev, dev_warn(&dd->pdev->dev,
"Error creating registers sysfs entry\n"); "Error creating 'registers' sysfs entry\n");
if (sysfs_create_file(kobj, &dev_attr_status.attr))
dev_warn(&dd->pdev->dev,
"Error creating 'status' sysfs entry\n");
return 0; return 0;
} }
...@@ -2292,6 +2633,7 @@ static int mtip_hw_sysfs_exit(struct driver_data *dd, struct kobject *kobj) ...@@ -2292,6 +2633,7 @@ static int mtip_hw_sysfs_exit(struct driver_data *dd, struct kobject *kobj)
return -EINVAL; return -EINVAL;
sysfs_remove_file(kobj, &dev_attr_registers.attr); sysfs_remove_file(kobj, &dev_attr_registers.attr);
sysfs_remove_file(kobj, &dev_attr_status.attr);
return 0; return 0;
} }
...@@ -2384,10 +2726,12 @@ static int mtip_ftl_rebuild_poll(struct driver_data *dd) ...@@ -2384,10 +2726,12 @@ static int mtip_ftl_rebuild_poll(struct driver_data *dd)
"FTL rebuild in progress. Polling for completion.\n"); "FTL rebuild in progress. Polling for completion.\n");
start = jiffies; start = jiffies;
dd->ftlrebuildflag = 1;
timeout = jiffies + msecs_to_jiffies(MTIP_FTL_REBUILD_TIMEOUT_MS); timeout = jiffies + msecs_to_jiffies(MTIP_FTL_REBUILD_TIMEOUT_MS);
do { do {
if (unlikely(test_bit(MTIP_DDF_REMOVE_PENDING_BIT,
&dd->dd_flag)))
return -EFAULT;
if (mtip_check_surprise_removal(dd->pdev)) if (mtip_check_surprise_removal(dd->pdev))
return -EFAULT; return -EFAULT;
...@@ -2408,22 +2752,17 @@ static int mtip_ftl_rebuild_poll(struct driver_data *dd) ...@@ -2408,22 +2752,17 @@ static int mtip_ftl_rebuild_poll(struct driver_data *dd)
dev_warn(&dd->pdev->dev, dev_warn(&dd->pdev->dev,
"FTL rebuild complete (%d secs).\n", "FTL rebuild complete (%d secs).\n",
jiffies_to_msecs(jiffies - start) / 1000); jiffies_to_msecs(jiffies - start) / 1000);
dd->ftlrebuildflag = 0;
mtip_block_initialize(dd); mtip_block_initialize(dd);
break; return 0;
} }
ssleep(10); ssleep(10);
} while (time_before(jiffies, timeout)); } while (time_before(jiffies, timeout));
/* Check for timeout */ /* Check for timeout */
if (dd->ftlrebuildflag) { dev_err(&dd->pdev->dev,
dev_err(&dd->pdev->dev,
"Timed out waiting for FTL rebuild to complete (%d secs).\n", "Timed out waiting for FTL rebuild to complete (%d secs).\n",
jiffies_to_msecs(jiffies - start) / 1000); jiffies_to_msecs(jiffies - start) / 1000);
return -EFAULT; return -EFAULT;
}
return 0;
} }
/* /*
...@@ -2448,14 +2787,17 @@ static int mtip_service_thread(void *data) ...@@ -2448,14 +2787,17 @@ static int mtip_service_thread(void *data)
* is in progress nor error handling is active * is in progress nor error handling is active
*/ */
wait_event_interruptible(port->svc_wait, (port->flags) && wait_event_interruptible(port->svc_wait, (port->flags) &&
!test_bit(MTIP_FLAG_IC_ACTIVE_BIT, &port->flags) && !(port->flags & MTIP_PF_PAUSE_IO));
!test_bit(MTIP_FLAG_EH_ACTIVE_BIT, &port->flags));
if (kthread_should_stop()) if (kthread_should_stop())
break; break;
set_bit(MTIP_FLAG_SVC_THD_ACTIVE_BIT, &port->flags); if (unlikely(test_bit(MTIP_DDF_REMOVE_PENDING_BIT,
if (test_bit(MTIP_FLAG_ISSUE_CMDS_BIT, &port->flags)) { &dd->dd_flag)))
break;
set_bit(MTIP_PF_SVC_THD_ACTIVE_BIT, &port->flags);
if (test_bit(MTIP_PF_ISSUE_CMDS_BIT, &port->flags)) {
slot = 1; slot = 1;
/* used to restrict the loop to one iteration */ /* used to restrict the loop to one iteration */
slot_start = num_cmd_slots; slot_start = num_cmd_slots;
...@@ -2480,21 +2822,19 @@ static int mtip_service_thread(void *data) ...@@ -2480,21 +2822,19 @@ static int mtip_service_thread(void *data)
/* Issue the command to the hardware */ /* Issue the command to the hardware */
mtip_issue_ncq_command(port, slot); mtip_issue_ncq_command(port, slot);
/* Set the command's timeout value.*/
port->commands[slot].comp_time = jiffies +
msecs_to_jiffies(MTIP_NCQ_COMMAND_TIMEOUT_MS);
clear_bit(slot, port->cmds_to_issue); clear_bit(slot, port->cmds_to_issue);
} }
clear_bit(MTIP_FLAG_ISSUE_CMDS_BIT, &port->flags); clear_bit(MTIP_PF_ISSUE_CMDS_BIT, &port->flags);
} else if (test_bit(MTIP_FLAG_REBUILD_BIT, &port->flags)) { } else if (test_bit(MTIP_PF_REBUILD_BIT, &port->flags)) {
mtip_ftl_rebuild_poll(dd); if (!mtip_ftl_rebuild_poll(dd))
clear_bit(MTIP_FLAG_REBUILD_BIT, &port->flags); set_bit(MTIP_DDF_REBUILD_FAILED_BIT,
&dd->dd_flag);
clear_bit(MTIP_PF_REBUILD_BIT, &port->flags);
} }
clear_bit(MTIP_FLAG_SVC_THD_ACTIVE_BIT, &port->flags); clear_bit(MTIP_PF_SVC_THD_ACTIVE_BIT, &port->flags);
if (test_bit(MTIP_FLAG_SVC_THD_SHOULD_STOP_BIT, &port->flags)) if (test_bit(MTIP_PF_SVC_THD_STOP_BIT, &port->flags))
break; break;
} }
return 0; return 0;
...@@ -2513,6 +2853,9 @@ static int mtip_hw_init(struct driver_data *dd) ...@@ -2513,6 +2853,9 @@ static int mtip_hw_init(struct driver_data *dd)
int i; int i;
int rv; int rv;
unsigned int num_command_slots; unsigned int num_command_slots;
unsigned long timeout, timetaken;
unsigned char *buf;
struct smart_attr attr242;
dd->mmio = pcim_iomap_table(dd->pdev)[MTIP_ABAR]; dd->mmio = pcim_iomap_table(dd->pdev)[MTIP_ABAR];
...@@ -2547,7 +2890,7 @@ static int mtip_hw_init(struct driver_data *dd) ...@@ -2547,7 +2890,7 @@ static int mtip_hw_init(struct driver_data *dd)
/* Allocate memory for the command list. */ /* Allocate memory for the command list. */
dd->port->command_list = dd->port->command_list =
dmam_alloc_coherent(&dd->pdev->dev, dmam_alloc_coherent(&dd->pdev->dev,
HW_PORT_PRIV_DMA_SZ + (ATA_SECT_SIZE * 2), HW_PORT_PRIV_DMA_SZ + (ATA_SECT_SIZE * 4),
&dd->port->command_list_dma, &dd->port->command_list_dma,
GFP_KERNEL); GFP_KERNEL);
if (!dd->port->command_list) { if (!dd->port->command_list) {
...@@ -2560,7 +2903,7 @@ static int mtip_hw_init(struct driver_data *dd) ...@@ -2560,7 +2903,7 @@ static int mtip_hw_init(struct driver_data *dd)
/* Clear the memory we have allocated. */ /* Clear the memory we have allocated. */
memset(dd->port->command_list, memset(dd->port->command_list,
0, 0,
HW_PORT_PRIV_DMA_SZ + (ATA_SECT_SIZE * 2)); HW_PORT_PRIV_DMA_SZ + (ATA_SECT_SIZE * 4));
/* Setup the addresse of the RX FIS. */ /* Setup the addresse of the RX FIS. */
dd->port->rxfis = dd->port->command_list + HW_CMD_SLOT_SZ; dd->port->rxfis = dd->port->command_list + HW_CMD_SLOT_SZ;
...@@ -2576,10 +2919,19 @@ static int mtip_hw_init(struct driver_data *dd) ...@@ -2576,10 +2919,19 @@ static int mtip_hw_init(struct driver_data *dd)
dd->port->identify_dma = dd->port->command_tbl_dma + dd->port->identify_dma = dd->port->command_tbl_dma +
HW_CMD_TBL_AR_SZ; HW_CMD_TBL_AR_SZ;
/* Setup the address of the sector buffer. */ /* Setup the address of the sector buffer - for some non-ncq cmds */
dd->port->sector_buffer = (void *) dd->port->identify + ATA_SECT_SIZE; dd->port->sector_buffer = (void *) dd->port->identify + ATA_SECT_SIZE;
dd->port->sector_buffer_dma = dd->port->identify_dma + ATA_SECT_SIZE; dd->port->sector_buffer_dma = dd->port->identify_dma + ATA_SECT_SIZE;
/* Setup the address of the log buf - for read log command */
dd->port->log_buf = (void *)dd->port->sector_buffer + ATA_SECT_SIZE;
dd->port->log_buf_dma = dd->port->sector_buffer_dma + ATA_SECT_SIZE;
/* Setup the address of the smart buf - for smart read data command */
dd->port->smart_buf = (void *)dd->port->log_buf + ATA_SECT_SIZE;
dd->port->smart_buf_dma = dd->port->log_buf_dma + ATA_SECT_SIZE;
/* Point the command headers at the command tables. */ /* Point the command headers at the command tables. */
for (i = 0; i < num_command_slots; i++) { for (i = 0; i < num_command_slots; i++) {
dd->port->commands[i].command_header = dd->port->commands[i].command_header =
...@@ -2623,14 +2975,43 @@ static int mtip_hw_init(struct driver_data *dd) ...@@ -2623,14 +2975,43 @@ static int mtip_hw_init(struct driver_data *dd)
dd->port->mmio + i*0x80 + PORT_SDBV; dd->port->mmio + i*0x80 + PORT_SDBV;
} }
/* Reset the HBA. */ timetaken = jiffies;
if (mtip_hba_reset(dd) < 0) { timeout = jiffies + msecs_to_jiffies(30000);
dev_err(&dd->pdev->dev, while (((readl(dd->port->mmio + PORT_SCR_STAT) & 0x0F) != 0x03) &&
"Card did not reset within timeout\n"); time_before(jiffies, timeout)) {
rv = -EIO; mdelay(100);
}
if (unlikely(mtip_check_surprise_removal(dd->pdev))) {
timetaken = jiffies - timetaken;
dev_warn(&dd->pdev->dev,
"Surprise removal detected at %u ms\n",
jiffies_to_msecs(timetaken));
rv = -ENODEV;
goto out2 ;
}
if (unlikely(test_bit(MTIP_DDF_REMOVE_PENDING_BIT, &dd->dd_flag))) {
timetaken = jiffies - timetaken;
dev_warn(&dd->pdev->dev,
"Removal detected at %u ms\n",
jiffies_to_msecs(timetaken));
rv = -EFAULT;
goto out2; goto out2;
} }
/* Conditionally reset the HBA. */
if (!(readl(dd->mmio + HOST_CAP) & HOST_CAP_NZDMA)) {
if (mtip_hba_reset(dd) < 0) {
dev_err(&dd->pdev->dev,
"Card did not reset within timeout\n");
rv = -EIO;
goto out2;
}
} else {
/* Clear any pending interrupts on the HBA */
writel(readl(dd->mmio + HOST_IRQ_STAT),
dd->mmio + HOST_IRQ_STAT);
}
mtip_init_port(dd->port); mtip_init_port(dd->port);
mtip_start_port(dd->port); mtip_start_port(dd->port);
...@@ -2660,6 +3041,12 @@ static int mtip_hw_init(struct driver_data *dd) ...@@ -2660,6 +3041,12 @@ static int mtip_hw_init(struct driver_data *dd)
mod_timer(&dd->port->cmd_timer, mod_timer(&dd->port->cmd_timer,
jiffies + msecs_to_jiffies(MTIP_TIMEOUT_CHECK_PERIOD)); jiffies + msecs_to_jiffies(MTIP_TIMEOUT_CHECK_PERIOD));
if (test_bit(MTIP_DDF_REMOVE_PENDING_BIT, &dd->dd_flag)) {
rv = -EFAULT;
goto out3;
}
if (mtip_get_identify(dd->port, NULL) < 0) { if (mtip_get_identify(dd->port, NULL) < 0) {
rv = -EFAULT; rv = -EFAULT;
goto out3; goto out3;
...@@ -2667,10 +3054,47 @@ static int mtip_hw_init(struct driver_data *dd) ...@@ -2667,10 +3054,47 @@ static int mtip_hw_init(struct driver_data *dd)
if (*(dd->port->identify + MTIP_FTL_REBUILD_OFFSET) == if (*(dd->port->identify + MTIP_FTL_REBUILD_OFFSET) ==
MTIP_FTL_REBUILD_MAGIC) { MTIP_FTL_REBUILD_MAGIC) {
set_bit(MTIP_FLAG_REBUILD_BIT, &dd->port->flags); set_bit(MTIP_PF_REBUILD_BIT, &dd->port->flags);
return MTIP_FTL_REBUILD_MAGIC; return MTIP_FTL_REBUILD_MAGIC;
} }
mtip_dump_identify(dd->port); mtip_dump_identify(dd->port);
/* check write protect, over temp and rebuild statuses */
rv = mtip_read_log_page(dd->port, ATA_LOG_SATA_NCQ,
dd->port->log_buf,
dd->port->log_buf_dma, 1);
if (rv) {
dev_warn(&dd->pdev->dev,
"Error in READ LOG EXT (10h) command\n");
/* non-critical error, don't fail the load */
} else {
buf = (unsigned char *)dd->port->log_buf;
if (buf[259] & 0x1) {
dev_info(&dd->pdev->dev,
"Write protect bit is set.\n");
set_bit(MTIP_DDF_WRITE_PROTECT_BIT, &dd->dd_flag);
}
if (buf[288] == 0xF7) {
dev_info(&dd->pdev->dev,
"Exceeded Tmax, drive in thermal shutdown.\n");
set_bit(MTIP_DDF_OVER_TEMP_BIT, &dd->dd_flag);
}
if (buf[288] == 0xBF) {
dev_info(&dd->pdev->dev,
"Drive indicates rebuild has failed.\n");
/* TODO */
}
}
/* get write protect progess */
memset(&attr242, 0, sizeof(struct smart_attr));
if (mtip_get_smart_attr(dd->port, 242, &attr242))
dev_warn(&dd->pdev->dev,
"Unable to check write protect progress\n");
else
dev_info(&dd->pdev->dev,
"Write protect progress: %d%% (%d blocks)\n",
attr242.cur, attr242.data);
return rv; return rv;
out3: out3:
...@@ -2688,7 +3112,7 @@ static int mtip_hw_init(struct driver_data *dd) ...@@ -2688,7 +3112,7 @@ static int mtip_hw_init(struct driver_data *dd)
/* Free the command/command header memory. */ /* Free the command/command header memory. */
dmam_free_coherent(&dd->pdev->dev, dmam_free_coherent(&dd->pdev->dev,
HW_PORT_PRIV_DMA_SZ + (ATA_SECT_SIZE * 2), HW_PORT_PRIV_DMA_SZ + (ATA_SECT_SIZE * 4),
dd->port->command_list, dd->port->command_list,
dd->port->command_list_dma); dd->port->command_list_dma);
out1: out1:
...@@ -2712,9 +3136,12 @@ static int mtip_hw_exit(struct driver_data *dd) ...@@ -2712,9 +3136,12 @@ static int mtip_hw_exit(struct driver_data *dd)
* Send standby immediate (E0h) to the drive so that it * Send standby immediate (E0h) to the drive so that it
* saves its state. * saves its state.
*/ */
if (atomic_read(&dd->drv_cleanup_done) != true) { if (!test_bit(MTIP_DDF_CLEANUP_BIT, &dd->dd_flag)) {
mtip_standby_immediate(dd->port); if (!test_bit(MTIP_PF_REBUILD_BIT, &dd->port->flags))
if (mtip_standby_immediate(dd->port))
dev_warn(&dd->pdev->dev,
"STANDBY IMMEDIATE failed\n");
/* de-initialize the port. */ /* de-initialize the port. */
mtip_deinit_port(dd->port); mtip_deinit_port(dd->port);
...@@ -2734,7 +3161,7 @@ static int mtip_hw_exit(struct driver_data *dd) ...@@ -2734,7 +3161,7 @@ static int mtip_hw_exit(struct driver_data *dd)
/* Free the command/command header memory. */ /* Free the command/command header memory. */
dmam_free_coherent(&dd->pdev->dev, dmam_free_coherent(&dd->pdev->dev,
HW_PORT_PRIV_DMA_SZ + (ATA_SECT_SIZE * 2), HW_PORT_PRIV_DMA_SZ + (ATA_SECT_SIZE * 4),
dd->port->command_list, dd->port->command_list,
dd->port->command_list_dma); dd->port->command_list_dma);
/* Free the memory allocated for the for structure. */ /* Free the memory allocated for the for structure. */
...@@ -2892,6 +3319,9 @@ static int mtip_block_ioctl(struct block_device *dev, ...@@ -2892,6 +3319,9 @@ static int mtip_block_ioctl(struct block_device *dev,
if (!dd) if (!dd)
return -ENOTTY; return -ENOTTY;
if (unlikely(test_bit(MTIP_DDF_REMOVE_PENDING_BIT, &dd->dd_flag)))
return -ENOTTY;
switch (cmd) { switch (cmd) {
case BLKFLSBUF: case BLKFLSBUF:
return -ENOTTY; return -ENOTTY;
...@@ -2927,6 +3357,9 @@ static int mtip_block_compat_ioctl(struct block_device *dev, ...@@ -2927,6 +3357,9 @@ static int mtip_block_compat_ioctl(struct block_device *dev,
if (!dd) if (!dd)
return -ENOTTY; return -ENOTTY;
if (unlikely(test_bit(MTIP_DDF_REMOVE_PENDING_BIT, &dd->dd_flag)))
return -ENOTTY;
switch (cmd) { switch (cmd) {
case BLKFLSBUF: case BLKFLSBUF:
return -ENOTTY; return -ENOTTY;
...@@ -3049,6 +3482,24 @@ static void mtip_make_request(struct request_queue *queue, struct bio *bio) ...@@ -3049,6 +3482,24 @@ static void mtip_make_request(struct request_queue *queue, struct bio *bio)
int nents = 0; int nents = 0;
int tag = 0; int tag = 0;
if (unlikely(dd->dd_flag & MTIP_DDF_STOP_IO)) {
if (unlikely(test_bit(MTIP_DDF_REMOVE_PENDING_BIT,
&dd->dd_flag))) {
bio_endio(bio, -ENXIO);
return;
}
if (unlikely(test_bit(MTIP_DDF_OVER_TEMP_BIT, &dd->dd_flag))) {
bio_endio(bio, -ENODATA);
return;
}
if (unlikely(test_bit(MTIP_DDF_WRITE_PROTECT_BIT,
&dd->dd_flag) &&
bio_data_dir(bio))) {
bio_endio(bio, -ENODATA);
return;
}
}
if (unlikely(!bio_has_data(bio))) { if (unlikely(!bio_has_data(bio))) {
blk_queue_flush(queue, 0); blk_queue_flush(queue, 0);
bio_endio(bio, 0); bio_endio(bio, 0);
...@@ -3061,7 +3512,7 @@ static void mtip_make_request(struct request_queue *queue, struct bio *bio) ...@@ -3061,7 +3512,7 @@ static void mtip_make_request(struct request_queue *queue, struct bio *bio)
if (unlikely((bio)->bi_vcnt > MTIP_MAX_SG)) { if (unlikely((bio)->bi_vcnt > MTIP_MAX_SG)) {
dev_warn(&dd->pdev->dev, dev_warn(&dd->pdev->dev,
"Maximum number of SGL entries exceeded"); "Maximum number of SGL entries exceeded\n");
bio_io_error(bio); bio_io_error(bio);
mtip_hw_release_scatterlist(dd, tag); mtip_hw_release_scatterlist(dd, tag);
return; return;
...@@ -3210,8 +3661,10 @@ static int mtip_block_initialize(struct driver_data *dd) ...@@ -3210,8 +3661,10 @@ static int mtip_block_initialize(struct driver_data *dd)
kobject_put(kobj); kobject_put(kobj);
} }
if (dd->mtip_svc_handler) if (dd->mtip_svc_handler) {
set_bit(MTIP_DDF_INIT_DONE_BIT, &dd->dd_flag);
return rv; /* service thread created for handling rebuild */ return rv; /* service thread created for handling rebuild */
}
start_service_thread: start_service_thread:
sprintf(thd_name, "mtip_svc_thd_%02d", index); sprintf(thd_name, "mtip_svc_thd_%02d", index);
...@@ -3220,12 +3673,15 @@ static int mtip_block_initialize(struct driver_data *dd) ...@@ -3220,12 +3673,15 @@ static int mtip_block_initialize(struct driver_data *dd)
dd, thd_name); dd, thd_name);
if (IS_ERR(dd->mtip_svc_handler)) { if (IS_ERR(dd->mtip_svc_handler)) {
printk(KERN_ERR "mtip32xx: service thread failed to start\n"); dev_err(&dd->pdev->dev, "service thread failed to start\n");
dd->mtip_svc_handler = NULL; dd->mtip_svc_handler = NULL;
rv = -EFAULT; rv = -EFAULT;
goto kthread_run_error; goto kthread_run_error;
} }
if (wait_for_rebuild == MTIP_FTL_REBUILD_MAGIC)
rv = wait_for_rebuild;
return rv; return rv;
kthread_run_error: kthread_run_error:
...@@ -3266,16 +3722,18 @@ static int mtip_block_remove(struct driver_data *dd) ...@@ -3266,16 +3722,18 @@ static int mtip_block_remove(struct driver_data *dd)
struct kobject *kobj; struct kobject *kobj;
if (dd->mtip_svc_handler) { if (dd->mtip_svc_handler) {
set_bit(MTIP_FLAG_SVC_THD_SHOULD_STOP_BIT, &dd->port->flags); set_bit(MTIP_PF_SVC_THD_STOP_BIT, &dd->port->flags);
wake_up_interruptible(&dd->port->svc_wait); wake_up_interruptible(&dd->port->svc_wait);
kthread_stop(dd->mtip_svc_handler); kthread_stop(dd->mtip_svc_handler);
} }
/* Clean up the sysfs attributes managed by the protocol layer. */ /* Clean up the sysfs attributes, if created */
kobj = kobject_get(&disk_to_dev(dd->disk)->kobj); if (test_bit(MTIP_DDF_INIT_DONE_BIT, &dd->dd_flag)) {
if (kobj) { kobj = kobject_get(&disk_to_dev(dd->disk)->kobj);
mtip_hw_sysfs_exit(dd, kobj); if (kobj) {
kobject_put(kobj); mtip_hw_sysfs_exit(dd, kobj);
kobject_put(kobj);
}
} }
/* /*
...@@ -3283,6 +3741,11 @@ static int mtip_block_remove(struct driver_data *dd) ...@@ -3283,6 +3741,11 @@ static int mtip_block_remove(struct driver_data *dd)
* from /dev * from /dev
*/ */
del_gendisk(dd->disk); del_gendisk(dd->disk);
spin_lock(&rssd_index_lock);
ida_remove(&rssd_index_ida, dd->index);
spin_unlock(&rssd_index_lock);
blk_cleanup_queue(dd->queue); blk_cleanup_queue(dd->queue);
dd->disk = NULL; dd->disk = NULL;
dd->queue = NULL; dd->queue = NULL;
...@@ -3312,6 +3775,11 @@ static int mtip_block_shutdown(struct driver_data *dd) ...@@ -3312,6 +3775,11 @@ static int mtip_block_shutdown(struct driver_data *dd)
/* Delete our gendisk structure, and cleanup the blk queue. */ /* Delete our gendisk structure, and cleanup the blk queue. */
del_gendisk(dd->disk); del_gendisk(dd->disk);
spin_lock(&rssd_index_lock);
ida_remove(&rssd_index_ida, dd->index);
spin_unlock(&rssd_index_lock);
blk_cleanup_queue(dd->queue); blk_cleanup_queue(dd->queue);
dd->disk = NULL; dd->disk = NULL;
dd->queue = NULL; dd->queue = NULL;
...@@ -3359,11 +3827,6 @@ static int mtip_pci_probe(struct pci_dev *pdev, ...@@ -3359,11 +3827,6 @@ static int mtip_pci_probe(struct pci_dev *pdev,
return -ENOMEM; return -ENOMEM;
} }
/* Set the atomic variable as 1 in case of SRSI */
atomic_set(&dd->drv_cleanup_done, true);
atomic_set(&dd->resumeflag, false);
/* Attach the private data to this PCI device. */ /* Attach the private data to this PCI device. */
pci_set_drvdata(pdev, dd); pci_set_drvdata(pdev, dd);
...@@ -3420,7 +3883,8 @@ static int mtip_pci_probe(struct pci_dev *pdev, ...@@ -3420,7 +3883,8 @@ static int mtip_pci_probe(struct pci_dev *pdev,
* instance number. * instance number.
*/ */
instance++; instance++;
if (rv != MTIP_FTL_REBUILD_MAGIC)
set_bit(MTIP_DDF_INIT_DONE_BIT, &dd->dd_flag);
goto done; goto done;
block_initialize_err: block_initialize_err:
...@@ -3434,9 +3898,6 @@ static int mtip_pci_probe(struct pci_dev *pdev, ...@@ -3434,9 +3898,6 @@ static int mtip_pci_probe(struct pci_dev *pdev,
pci_set_drvdata(pdev, NULL); pci_set_drvdata(pdev, NULL);
return rv; return rv;
done: done:
/* Set the atomic variable as 0 in case of SRSI */
atomic_set(&dd->drv_cleanup_done, true);
return rv; return rv;
} }
...@@ -3452,8 +3913,10 @@ static void mtip_pci_remove(struct pci_dev *pdev) ...@@ -3452,8 +3913,10 @@ static void mtip_pci_remove(struct pci_dev *pdev)
struct driver_data *dd = pci_get_drvdata(pdev); struct driver_data *dd = pci_get_drvdata(pdev);
int counter = 0; int counter = 0;
set_bit(MTIP_DDF_REMOVE_PENDING_BIT, &dd->dd_flag);
if (mtip_check_surprise_removal(pdev)) { if (mtip_check_surprise_removal(pdev)) {
while (atomic_read(&dd->drv_cleanup_done) == false) { while (!test_bit(MTIP_DDF_CLEANUP_BIT, &dd->dd_flag)) {
counter++; counter++;
msleep(20); msleep(20);
if (counter == 10) { if (counter == 10) {
...@@ -3463,8 +3926,6 @@ static void mtip_pci_remove(struct pci_dev *pdev) ...@@ -3463,8 +3926,6 @@ static void mtip_pci_remove(struct pci_dev *pdev)
} }
} }
} }
/* Set the atomic variable as 1 in case of SRSI */
atomic_set(&dd->drv_cleanup_done, true);
/* Clean up the block layer. */ /* Clean up the block layer. */
mtip_block_remove(dd); mtip_block_remove(dd);
...@@ -3493,7 +3954,7 @@ static int mtip_pci_suspend(struct pci_dev *pdev, pm_message_t mesg) ...@@ -3493,7 +3954,7 @@ static int mtip_pci_suspend(struct pci_dev *pdev, pm_message_t mesg)
return -EFAULT; return -EFAULT;
} }
atomic_set(&dd->resumeflag, true); set_bit(MTIP_DDF_RESUME_BIT, &dd->dd_flag);
/* Disable ports & interrupts then send standby immediate */ /* Disable ports & interrupts then send standby immediate */
rv = mtip_block_suspend(dd); rv = mtip_block_suspend(dd);
...@@ -3559,7 +4020,7 @@ static int mtip_pci_resume(struct pci_dev *pdev) ...@@ -3559,7 +4020,7 @@ static int mtip_pci_resume(struct pci_dev *pdev)
dev_err(&pdev->dev, "Unable to resume\n"); dev_err(&pdev->dev, "Unable to resume\n");
err: err:
atomic_set(&dd->resumeflag, false); clear_bit(MTIP_DDF_RESUME_BIT, &dd->dd_flag);
return rv; return rv;
} }
...@@ -3608,18 +4069,25 @@ MODULE_DEVICE_TABLE(pci, mtip_pci_tbl); ...@@ -3608,18 +4069,25 @@ MODULE_DEVICE_TABLE(pci, mtip_pci_tbl);
*/ */
static int __init mtip_init(void) static int __init mtip_init(void)
{ {
int error;
printk(KERN_INFO MTIP_DRV_NAME " Version " MTIP_DRV_VERSION "\n"); printk(KERN_INFO MTIP_DRV_NAME " Version " MTIP_DRV_VERSION "\n");
/* Allocate a major block device number to use with this driver. */ /* Allocate a major block device number to use with this driver. */
mtip_major = register_blkdev(0, MTIP_DRV_NAME); error = register_blkdev(0, MTIP_DRV_NAME);
if (mtip_major < 0) { if (error <= 0) {
printk(KERN_ERR "Unable to register block device (%d)\n", printk(KERN_ERR "Unable to register block device (%d)\n",
mtip_major); error);
return -EBUSY; return -EBUSY;
} }
mtip_major = error;
/* Register our PCI operations. */ /* Register our PCI operations. */
return pci_register_driver(&mtip_pci_driver); error = pci_register_driver(&mtip_pci_driver);
if (error)
unregister_blkdev(mtip_major, MTIP_DRV_NAME);
return error;
} }
/* /*
......
...@@ -34,8 +34,8 @@ ...@@ -34,8 +34,8 @@
/* offset of Device Control register in PCIe extended capabilites space */ /* offset of Device Control register in PCIe extended capabilites space */
#define PCIE_CONFIG_EXT_DEVICE_CONTROL_OFFSET 0x48 #define PCIE_CONFIG_EXT_DEVICE_CONTROL_OFFSET 0x48
/* # of times to retry timed out IOs */ /* # of times to retry timed out/failed IOs */
#define MTIP_MAX_RETRIES 5 #define MTIP_MAX_RETRIES 2
/* Various timeout values in ms */ /* Various timeout values in ms */
#define MTIP_NCQ_COMMAND_TIMEOUT_MS 5000 #define MTIP_NCQ_COMMAND_TIMEOUT_MS 5000
...@@ -114,12 +114,41 @@ ...@@ -114,12 +114,41 @@
#define __force_bit2int (unsigned int __force) #define __force_bit2int (unsigned int __force)
/* below are bit numbers in 'flags' defined in mtip_port */ /* below are bit numbers in 'flags' defined in mtip_port */
#define MTIP_FLAG_IC_ACTIVE_BIT 0 #define MTIP_PF_IC_ACTIVE_BIT 0 /* pio/ioctl */
#define MTIP_FLAG_EH_ACTIVE_BIT 1 #define MTIP_PF_EH_ACTIVE_BIT 1 /* error handling */
#define MTIP_FLAG_SVC_THD_ACTIVE_BIT 2 #define MTIP_PF_SE_ACTIVE_BIT 2 /* secure erase */
#define MTIP_FLAG_ISSUE_CMDS_BIT 4 #define MTIP_PF_DM_ACTIVE_BIT 3 /* download microcde */
#define MTIP_FLAG_REBUILD_BIT 5 #define MTIP_PF_PAUSE_IO ((1 << MTIP_PF_IC_ACTIVE_BIT) | \
#define MTIP_FLAG_SVC_THD_SHOULD_STOP_BIT 8 (1 << MTIP_PF_EH_ACTIVE_BIT) | \
(1 << MTIP_PF_SE_ACTIVE_BIT) | \
(1 << MTIP_PF_DM_ACTIVE_BIT))
#define MTIP_PF_SVC_THD_ACTIVE_BIT 4
#define MTIP_PF_ISSUE_CMDS_BIT 5
#define MTIP_PF_REBUILD_BIT 6
#define MTIP_PF_SVC_THD_STOP_BIT 8
/* below are bit numbers in 'dd_flag' defined in driver_data */
#define MTIP_DDF_REMOVE_PENDING_BIT 1
#define MTIP_DDF_OVER_TEMP_BIT 2
#define MTIP_DDF_WRITE_PROTECT_BIT 3
#define MTIP_DDF_STOP_IO ((1 << MTIP_DDF_REMOVE_PENDING_BIT) | \
(1 << MTIP_DDF_OVER_TEMP_BIT) | \
(1 << MTIP_DDF_WRITE_PROTECT_BIT))
#define MTIP_DDF_CLEANUP_BIT 5
#define MTIP_DDF_RESUME_BIT 6
#define MTIP_DDF_INIT_DONE_BIT 7
#define MTIP_DDF_REBUILD_FAILED_BIT 8
__packed struct smart_attr{
u8 attr_id;
u16 flags;
u8 cur;
u8 worst;
u32 data;
u8 res[3];
};
/* Register Frame Information Structure (FIS), host to device. */ /* Register Frame Information Structure (FIS), host to device. */
struct host_to_dev_fis { struct host_to_dev_fis {
...@@ -345,6 +374,12 @@ struct mtip_port { ...@@ -345,6 +374,12 @@ struct mtip_port {
* when the command slot and all associated data structures * when the command slot and all associated data structures
* are no longer needed. * are no longer needed.
*/ */
u16 *log_buf;
dma_addr_t log_buf_dma;
u8 *smart_buf;
dma_addr_t smart_buf_dma;
unsigned long allocated[SLOTBITS_IN_LONGS]; unsigned long allocated[SLOTBITS_IN_LONGS];
/* /*
* used to queue commands when an internal command is in progress * used to queue commands when an internal command is in progress
...@@ -368,6 +403,7 @@ struct mtip_port { ...@@ -368,6 +403,7 @@ struct mtip_port {
* Timer used to complete commands that have been active for too long. * Timer used to complete commands that have been active for too long.
*/ */
struct timer_list cmd_timer; struct timer_list cmd_timer;
unsigned long ic_pause_timer;
/* /*
* Semaphore used to block threads if there are no * Semaphore used to block threads if there are no
* command slots available. * command slots available.
...@@ -404,13 +440,9 @@ struct driver_data { ...@@ -404,13 +440,9 @@ struct driver_data {
unsigned slot_groups; /* number of slot groups the product supports */ unsigned slot_groups; /* number of slot groups the product supports */
atomic_t drv_cleanup_done; /* Atomic variable for SRSI */
unsigned long index; /* Index to determine the disk name */ unsigned long index; /* Index to determine the disk name */
unsigned int ftlrebuildflag; /* FTL rebuild flag */ unsigned long dd_flag; /* NOTE: use atomic bit operations on this */
atomic_t resumeflag; /* Atomic variable to track suspend/resume */
struct task_struct *mtip_svc_handler; /* task_struct of svc thd */ struct task_struct *mtip_svc_handler; /* task_struct of svc thd */
}; };
......
...@@ -351,6 +351,7 @@ static void virtblk_config_changed_work(struct work_struct *work) ...@@ -351,6 +351,7 @@ static void virtblk_config_changed_work(struct work_struct *work)
cap_str_10, cap_str_2); cap_str_10, cap_str_2);
set_capacity(vblk->disk, capacity); set_capacity(vblk->disk, capacity);
revalidate_disk(vblk->disk);
done: done:
mutex_unlock(&vblk->config_lock); mutex_unlock(&vblk->config_lock);
} }
......
...@@ -321,6 +321,7 @@ struct seg_buf { ...@@ -321,6 +321,7 @@ struct seg_buf {
static void xen_blkbk_unmap(struct pending_req *req) static void xen_blkbk_unmap(struct pending_req *req)
{ {
struct gnttab_unmap_grant_ref unmap[BLKIF_MAX_SEGMENTS_PER_REQUEST]; struct gnttab_unmap_grant_ref unmap[BLKIF_MAX_SEGMENTS_PER_REQUEST];
struct page *pages[BLKIF_MAX_SEGMENTS_PER_REQUEST];
unsigned int i, invcount = 0; unsigned int i, invcount = 0;
grant_handle_t handle; grant_handle_t handle;
int ret; int ret;
...@@ -332,25 +333,12 @@ static void xen_blkbk_unmap(struct pending_req *req) ...@@ -332,25 +333,12 @@ static void xen_blkbk_unmap(struct pending_req *req)
gnttab_set_unmap_op(&unmap[invcount], vaddr(req, i), gnttab_set_unmap_op(&unmap[invcount], vaddr(req, i),
GNTMAP_host_map, handle); GNTMAP_host_map, handle);
pending_handle(req, i) = BLKBACK_INVALID_HANDLE; pending_handle(req, i) = BLKBACK_INVALID_HANDLE;
pages[invcount] = virt_to_page(vaddr(req, i));
invcount++; invcount++;
} }
ret = HYPERVISOR_grant_table_op( ret = gnttab_unmap_refs(unmap, pages, invcount, false);
GNTTABOP_unmap_grant_ref, unmap, invcount);
BUG_ON(ret); BUG_ON(ret);
/*
* Note, we use invcount, so nr->pages, so we can't index
* using vaddr(req, i).
*/
for (i = 0; i < invcount; i++) {
ret = m2p_remove_override(
virt_to_page(unmap[i].host_addr), false);
if (ret) {
pr_alert(DRV_PFX "Failed to remove M2P override for %lx\n",
(unsigned long)unmap[i].host_addr);
continue;
}
}
} }
static int xen_blkbk_map(struct blkif_request *req, static int xen_blkbk_map(struct blkif_request *req,
...@@ -378,7 +366,7 @@ static int xen_blkbk_map(struct blkif_request *req, ...@@ -378,7 +366,7 @@ static int xen_blkbk_map(struct blkif_request *req,
pending_req->blkif->domid); pending_req->blkif->domid);
} }
ret = HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, map, nseg); ret = gnttab_map_refs(map, NULL, &blkbk->pending_page(pending_req, 0), nseg);
BUG_ON(ret); BUG_ON(ret);
/* /*
...@@ -398,15 +386,6 @@ static int xen_blkbk_map(struct blkif_request *req, ...@@ -398,15 +386,6 @@ static int xen_blkbk_map(struct blkif_request *req,
if (ret) if (ret)
continue; continue;
ret = m2p_add_override(PFN_DOWN(map[i].dev_bus_addr),
blkbk->pending_page(pending_req, i), NULL);
if (ret) {
pr_alert(DRV_PFX "Failed to install M2P override for %lx (ret: %d)\n",
(unsigned long)map[i].dev_bus_addr, ret);
/* We could switch over to GNTTABOP_copy */
continue;
}
seg[i].buf = map[i].dev_bus_addr | seg[i].buf = map[i].dev_bus_addr |
(req->u.rw.seg[i].first_sect << 9); (req->u.rw.seg[i].first_sect << 9);
} }
...@@ -419,21 +398,18 @@ static int dispatch_discard_io(struct xen_blkif *blkif, ...@@ -419,21 +398,18 @@ static int dispatch_discard_io(struct xen_blkif *blkif,
int err = 0; int err = 0;
int status = BLKIF_RSP_OKAY; int status = BLKIF_RSP_OKAY;
struct block_device *bdev = blkif->vbd.bdev; struct block_device *bdev = blkif->vbd.bdev;
unsigned long secure;
blkif->st_ds_req++; blkif->st_ds_req++;
xen_blkif_get(blkif); xen_blkif_get(blkif);
if (blkif->blk_backend_type == BLKIF_BACKEND_PHY || secure = (blkif->vbd.discard_secure &&
blkif->blk_backend_type == BLKIF_BACKEND_FILE) { (req->u.discard.flag & BLKIF_DISCARD_SECURE)) ?
unsigned long secure = (blkif->vbd.discard_secure && BLKDEV_DISCARD_SECURE : 0;
(req->u.discard.flag & BLKIF_DISCARD_SECURE)) ?
BLKDEV_DISCARD_SECURE : 0; err = blkdev_issue_discard(bdev, req->u.discard.sector_number,
err = blkdev_issue_discard(bdev, req->u.discard.nr_sectors,
req->u.discard.sector_number, GFP_KERNEL, secure);
req->u.discard.nr_sectors,
GFP_KERNEL, secure);
} else
err = -EOPNOTSUPP;
if (err == -EOPNOTSUPP) { if (err == -EOPNOTSUPP) {
pr_debug(DRV_PFX "discard op failed, not supported\n"); pr_debug(DRV_PFX "discard op failed, not supported\n");
...@@ -830,7 +806,7 @@ static int __init xen_blkif_init(void) ...@@ -830,7 +806,7 @@ static int __init xen_blkif_init(void)
int i, mmap_pages; int i, mmap_pages;
int rc = 0; int rc = 0;
if (!xen_pv_domain()) if (!xen_domain())
return -ENODEV; return -ENODEV;
blkbk = kzalloc(sizeof(struct xen_blkbk), GFP_KERNEL); blkbk = kzalloc(sizeof(struct xen_blkbk), GFP_KERNEL);
......
...@@ -146,11 +146,6 @@ enum blkif_protocol { ...@@ -146,11 +146,6 @@ enum blkif_protocol {
BLKIF_PROTOCOL_X86_64 = 3, BLKIF_PROTOCOL_X86_64 = 3,
}; };
enum blkif_backend_type {
BLKIF_BACKEND_PHY = 1,
BLKIF_BACKEND_FILE = 2,
};
struct xen_vbd { struct xen_vbd {
/* What the domain refers to this vbd as. */ /* What the domain refers to this vbd as. */
blkif_vdev_t handle; blkif_vdev_t handle;
...@@ -177,7 +172,6 @@ struct xen_blkif { ...@@ -177,7 +172,6 @@ struct xen_blkif {
unsigned int irq; unsigned int irq;
/* Comms information. */ /* Comms information. */
enum blkif_protocol blk_protocol; enum blkif_protocol blk_protocol;
enum blkif_backend_type blk_backend_type;
union blkif_back_rings blk_rings; union blkif_back_rings blk_rings;
void *blk_ring; void *blk_ring;
/* The VBD attached to this interface. */ /* The VBD attached to this interface. */
......
...@@ -381,72 +381,49 @@ int xen_blkbk_flush_diskcache(struct xenbus_transaction xbt, ...@@ -381,72 +381,49 @@ int xen_blkbk_flush_diskcache(struct xenbus_transaction xbt,
err = xenbus_printf(xbt, dev->nodename, "feature-flush-cache", err = xenbus_printf(xbt, dev->nodename, "feature-flush-cache",
"%d", state); "%d", state);
if (err) if (err)
xenbus_dev_fatal(dev, err, "writing feature-flush-cache"); dev_warn(&dev->dev, "writing feature-flush-cache (%d)", err);
return err; return err;
} }
int xen_blkbk_discard(struct xenbus_transaction xbt, struct backend_info *be) static void xen_blkbk_discard(struct xenbus_transaction xbt, struct backend_info *be)
{ {
struct xenbus_device *dev = be->dev; struct xenbus_device *dev = be->dev;
struct xen_blkif *blkif = be->blkif; struct xen_blkif *blkif = be->blkif;
char *type;
int err; int err;
int state = 0; int state = 0;
struct block_device *bdev = be->blkif->vbd.bdev;
struct request_queue *q = bdev_get_queue(bdev);
type = xenbus_read(XBT_NIL, dev->nodename, "type", NULL); if (blk_queue_discard(q)) {
if (!IS_ERR(type)) { err = xenbus_printf(xbt, dev->nodename,
if (strncmp(type, "file", 4) == 0) { "discard-granularity", "%u",
state = 1; q->limits.discard_granularity);
blkif->blk_backend_type = BLKIF_BACKEND_FILE; if (err) {
dev_warn(&dev->dev, "writing discard-granularity (%d)", err);
return;
} }
if (strncmp(type, "phy", 3) == 0) { err = xenbus_printf(xbt, dev->nodename,
struct block_device *bdev = be->blkif->vbd.bdev; "discard-alignment", "%u",
struct request_queue *q = bdev_get_queue(bdev); q->limits.discard_alignment);
if (blk_queue_discard(q)) { if (err) {
err = xenbus_printf(xbt, dev->nodename, dev_warn(&dev->dev, "writing discard-alignment (%d)", err);
"discard-granularity", "%u", return;
q->limits.discard_granularity); }
if (err) { state = 1;
xenbus_dev_fatal(dev, err, /* Optional. */
"writing discard-granularity"); err = xenbus_printf(xbt, dev->nodename,
goto kfree; "discard-secure", "%d",
} blkif->vbd.discard_secure);
err = xenbus_printf(xbt, dev->nodename, if (err) {
"discard-alignment", "%u", dev_warn(dev-dev, "writing discard-secure (%d)", err);
q->limits.discard_alignment); return;
if (err) {
xenbus_dev_fatal(dev, err,
"writing discard-alignment");
goto kfree;
}
state = 1;
blkif->blk_backend_type = BLKIF_BACKEND_PHY;
}
/* Optional. */
err = xenbus_printf(xbt, dev->nodename,
"discard-secure", "%d",
blkif->vbd.discard_secure);
if (err) {
xenbus_dev_fatal(dev, err,
"writting discard-secure");
goto kfree;
}
} }
} else {
err = PTR_ERR(type);
xenbus_dev_fatal(dev, err, "reading type");
goto out;
} }
err = xenbus_printf(xbt, dev->nodename, "feature-discard", err = xenbus_printf(xbt, dev->nodename, "feature-discard",
"%d", state); "%d", state);
if (err) if (err)
xenbus_dev_fatal(dev, err, "writing feature-discard"); dev_warn(&dev->dev, "writing feature-discard (%d)", err);
kfree:
kfree(type);
out:
return err;
} }
int xen_blkbk_barrier(struct xenbus_transaction xbt, int xen_blkbk_barrier(struct xenbus_transaction xbt,
struct backend_info *be, int state) struct backend_info *be, int state)
...@@ -457,7 +434,7 @@ int xen_blkbk_barrier(struct xenbus_transaction xbt, ...@@ -457,7 +434,7 @@ int xen_blkbk_barrier(struct xenbus_transaction xbt,
err = xenbus_printf(xbt, dev->nodename, "feature-barrier", err = xenbus_printf(xbt, dev->nodename, "feature-barrier",
"%d", state); "%d", state);
if (err) if (err)
xenbus_dev_fatal(dev, err, "writing feature-barrier"); dev_warn(&dev->dev, "writing feature-barrier (%d)", err);
return err; return err;
} }
...@@ -689,14 +666,12 @@ static void connect(struct backend_info *be) ...@@ -689,14 +666,12 @@ static void connect(struct backend_info *be)
return; return;
} }
err = xen_blkbk_flush_diskcache(xbt, be, be->blkif->vbd.flush_support); /* If we can't advertise it is OK. */
if (err) xen_blkbk_flush_diskcache(xbt, be, be->blkif->vbd.flush_support);
goto abort;
err = xen_blkbk_discard(xbt, be); xen_blkbk_discard(xbt, be);
/* If we can't advertise it is OK. */ xen_blkbk_barrier(xbt, be, be->blkif->vbd.flush_support);
err = xen_blkbk_barrier(xbt, be, be->blkif->vbd.flush_support);
err = xenbus_printf(xbt, dev->nodename, "sectors", "%llu", err = xenbus_printf(xbt, dev->nodename, "sectors", "%llu",
(unsigned long long)vbd_sz(&be->blkif->vbd)); (unsigned long long)vbd_sz(&be->blkif->vbd));
......
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/mutex.h> #include <linux/mutex.h>
#include <linux/scatterlist.h> #include <linux/scatterlist.h>
#include <linux/bitmap.h>
#include <xen/xen.h> #include <xen/xen.h>
#include <xen/xenbus.h> #include <xen/xenbus.h>
...@@ -81,6 +82,7 @@ static const struct block_device_operations xlvbd_block_fops; ...@@ -81,6 +82,7 @@ static const struct block_device_operations xlvbd_block_fops;
*/ */
struct blkfront_info struct blkfront_info
{ {
spinlock_t io_lock;
struct mutex mutex; struct mutex mutex;
struct xenbus_device *xbdev; struct xenbus_device *xbdev;
struct gendisk *gd; struct gendisk *gd;
...@@ -105,8 +107,6 @@ struct blkfront_info ...@@ -105,8 +107,6 @@ struct blkfront_info
int is_ready; int is_ready;
}; };
static DEFINE_SPINLOCK(blkif_io_lock);
static unsigned int nr_minors; static unsigned int nr_minors;
static unsigned long *minors; static unsigned long *minors;
static DEFINE_SPINLOCK(minor_lock); static DEFINE_SPINLOCK(minor_lock);
...@@ -177,8 +177,7 @@ static int xlbd_reserve_minors(unsigned int minor, unsigned int nr) ...@@ -177,8 +177,7 @@ static int xlbd_reserve_minors(unsigned int minor, unsigned int nr)
spin_lock(&minor_lock); spin_lock(&minor_lock);
if (find_next_bit(minors, end, minor) >= end) { if (find_next_bit(minors, end, minor) >= end) {
for (; minor < end; ++minor) bitmap_set(minors, minor, nr);
__set_bit(minor, minors);
rc = 0; rc = 0;
} else } else
rc = -EBUSY; rc = -EBUSY;
...@@ -193,8 +192,7 @@ static void xlbd_release_minors(unsigned int minor, unsigned int nr) ...@@ -193,8 +192,7 @@ static void xlbd_release_minors(unsigned int minor, unsigned int nr)
BUG_ON(end > nr_minors); BUG_ON(end > nr_minors);
spin_lock(&minor_lock); spin_lock(&minor_lock);
for (; minor < end; ++minor) bitmap_clear(minors, minor, nr);
__clear_bit(minor, minors);
spin_unlock(&minor_lock); spin_unlock(&minor_lock);
} }
...@@ -419,7 +417,7 @@ static int xlvbd_init_blk_queue(struct gendisk *gd, u16 sector_size) ...@@ -419,7 +417,7 @@ static int xlvbd_init_blk_queue(struct gendisk *gd, u16 sector_size)
struct request_queue *rq; struct request_queue *rq;
struct blkfront_info *info = gd->private_data; struct blkfront_info *info = gd->private_data;
rq = blk_init_queue(do_blkif_request, &blkif_io_lock); rq = blk_init_queue(do_blkif_request, &info->io_lock);
if (rq == NULL) if (rq == NULL)
return -1; return -1;
...@@ -636,14 +634,14 @@ static void xlvbd_release_gendisk(struct blkfront_info *info) ...@@ -636,14 +634,14 @@ static void xlvbd_release_gendisk(struct blkfront_info *info)
if (info->rq == NULL) if (info->rq == NULL)
return; return;
spin_lock_irqsave(&blkif_io_lock, flags); spin_lock_irqsave(&info->io_lock, flags);
/* No more blkif_request(). */ /* No more blkif_request(). */
blk_stop_queue(info->rq); blk_stop_queue(info->rq);
/* No more gnttab callback work. */ /* No more gnttab callback work. */
gnttab_cancel_free_callback(&info->callback); gnttab_cancel_free_callback(&info->callback);
spin_unlock_irqrestore(&blkif_io_lock, flags); spin_unlock_irqrestore(&info->io_lock, flags);
/* Flush gnttab callback work. Must be done with no locks held. */ /* Flush gnttab callback work. Must be done with no locks held. */
flush_work_sync(&info->work); flush_work_sync(&info->work);
...@@ -675,16 +673,16 @@ static void blkif_restart_queue(struct work_struct *work) ...@@ -675,16 +673,16 @@ static void blkif_restart_queue(struct work_struct *work)
{ {
struct blkfront_info *info = container_of(work, struct blkfront_info, work); struct blkfront_info *info = container_of(work, struct blkfront_info, work);
spin_lock_irq(&blkif_io_lock); spin_lock_irq(&info->io_lock);
if (info->connected == BLKIF_STATE_CONNECTED) if (info->connected == BLKIF_STATE_CONNECTED)
kick_pending_request_queues(info); kick_pending_request_queues(info);
spin_unlock_irq(&blkif_io_lock); spin_unlock_irq(&info->io_lock);
} }
static void blkif_free(struct blkfront_info *info, int suspend) static void blkif_free(struct blkfront_info *info, int suspend)
{ {
/* Prevent new requests being issued until we fix things up. */ /* Prevent new requests being issued until we fix things up. */
spin_lock_irq(&blkif_io_lock); spin_lock_irq(&info->io_lock);
info->connected = suspend ? info->connected = suspend ?
BLKIF_STATE_SUSPENDED : BLKIF_STATE_DISCONNECTED; BLKIF_STATE_SUSPENDED : BLKIF_STATE_DISCONNECTED;
/* No more blkif_request(). */ /* No more blkif_request(). */
...@@ -692,7 +690,7 @@ static void blkif_free(struct blkfront_info *info, int suspend) ...@@ -692,7 +690,7 @@ static void blkif_free(struct blkfront_info *info, int suspend)
blk_stop_queue(info->rq); blk_stop_queue(info->rq);
/* No more gnttab callback work. */ /* No more gnttab callback work. */
gnttab_cancel_free_callback(&info->callback); gnttab_cancel_free_callback(&info->callback);
spin_unlock_irq(&blkif_io_lock); spin_unlock_irq(&info->io_lock);
/* Flush gnttab callback work. Must be done with no locks held. */ /* Flush gnttab callback work. Must be done with no locks held. */
flush_work_sync(&info->work); flush_work_sync(&info->work);
...@@ -728,10 +726,10 @@ static irqreturn_t blkif_interrupt(int irq, void *dev_id) ...@@ -728,10 +726,10 @@ static irqreturn_t blkif_interrupt(int irq, void *dev_id)
struct blkfront_info *info = (struct blkfront_info *)dev_id; struct blkfront_info *info = (struct blkfront_info *)dev_id;
int error; int error;
spin_lock_irqsave(&blkif_io_lock, flags); spin_lock_irqsave(&info->io_lock, flags);
if (unlikely(info->connected != BLKIF_STATE_CONNECTED)) { if (unlikely(info->connected != BLKIF_STATE_CONNECTED)) {
spin_unlock_irqrestore(&blkif_io_lock, flags); spin_unlock_irqrestore(&info->io_lock, flags);
return IRQ_HANDLED; return IRQ_HANDLED;
} }
...@@ -816,7 +814,7 @@ static irqreturn_t blkif_interrupt(int irq, void *dev_id) ...@@ -816,7 +814,7 @@ static irqreturn_t blkif_interrupt(int irq, void *dev_id)
kick_pending_request_queues(info); kick_pending_request_queues(info);
spin_unlock_irqrestore(&blkif_io_lock, flags); spin_unlock_irqrestore(&info->io_lock, flags);
return IRQ_HANDLED; return IRQ_HANDLED;
} }
...@@ -991,6 +989,7 @@ static int blkfront_probe(struct xenbus_device *dev, ...@@ -991,6 +989,7 @@ static int blkfront_probe(struct xenbus_device *dev,
} }
mutex_init(&info->mutex); mutex_init(&info->mutex);
spin_lock_init(&info->io_lock);
info->xbdev = dev; info->xbdev = dev;
info->vdevice = vdevice; info->vdevice = vdevice;
info->connected = BLKIF_STATE_DISCONNECTED; info->connected = BLKIF_STATE_DISCONNECTED;
...@@ -1068,7 +1067,7 @@ static int blkif_recover(struct blkfront_info *info) ...@@ -1068,7 +1067,7 @@ static int blkif_recover(struct blkfront_info *info)
xenbus_switch_state(info->xbdev, XenbusStateConnected); xenbus_switch_state(info->xbdev, XenbusStateConnected);
spin_lock_irq(&blkif_io_lock); spin_lock_irq(&info->io_lock);
/* Now safe for us to use the shared ring */ /* Now safe for us to use the shared ring */
info->connected = BLKIF_STATE_CONNECTED; info->connected = BLKIF_STATE_CONNECTED;
...@@ -1079,7 +1078,7 @@ static int blkif_recover(struct blkfront_info *info) ...@@ -1079,7 +1078,7 @@ static int blkif_recover(struct blkfront_info *info)
/* Kick any other new requests queued since we resumed */ /* Kick any other new requests queued since we resumed */
kick_pending_request_queues(info); kick_pending_request_queues(info);
spin_unlock_irq(&blkif_io_lock); spin_unlock_irq(&info->io_lock);
return 0; return 0;
} }
...@@ -1277,10 +1276,10 @@ static void blkfront_connect(struct blkfront_info *info) ...@@ -1277,10 +1276,10 @@ static void blkfront_connect(struct blkfront_info *info)
xenbus_switch_state(info->xbdev, XenbusStateConnected); xenbus_switch_state(info->xbdev, XenbusStateConnected);
/* Kick pending requests. */ /* Kick pending requests. */
spin_lock_irq(&blkif_io_lock); spin_lock_irq(&info->io_lock);
info->connected = BLKIF_STATE_CONNECTED; info->connected = BLKIF_STATE_CONNECTED;
kick_pending_request_queues(info); kick_pending_request_queues(info);
spin_unlock_irq(&blkif_io_lock); spin_unlock_irq(&info->io_lock);
add_disk(info->gd); add_disk(info->gd);
...@@ -1410,7 +1409,6 @@ static int blkif_release(struct gendisk *disk, fmode_t mode) ...@@ -1410,7 +1409,6 @@ static int blkif_release(struct gendisk *disk, fmode_t mode)
mutex_lock(&blkfront_mutex); mutex_lock(&blkfront_mutex);
bdev = bdget_disk(disk, 0); bdev = bdget_disk(disk, 0);
bdput(bdev);
if (bdev->bd_openers) if (bdev->bd_openers)
goto out; goto out;
...@@ -1441,6 +1439,7 @@ static int blkif_release(struct gendisk *disk, fmode_t mode) ...@@ -1441,6 +1439,7 @@ static int blkif_release(struct gendisk *disk, fmode_t mode)
} }
out: out:
bdput(bdev);
mutex_unlock(&blkfront_mutex); mutex_unlock(&blkfront_mutex);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment