21 #include <linux/pci.h>
27 #include <linux/random.h>
31 #include <linux/module.h>
38 #include <../drivers/ata/ahci.h>
39 #include <linux/export.h>
43 #define HW_CMD_SLOT_SZ (MTIP_MAX_COMMAND_SLOTS * 32)
44 #define HW_CMD_TBL_SZ (AHCI_CMD_TBL_HDR_SZ + (MTIP_MAX_SG * 16))
45 #define HW_CMD_TBL_AR_SZ (HW_CMD_TBL_SZ * MTIP_MAX_COMMAND_SLOTS)
46 #define HW_PORT_PRIV_DMA_SZ \
47 (HW_CMD_SLOT_SZ + HW_CMD_TBL_AR_SZ + AHCI_RX_FIS_SZ)
49 #define HOST_CAP_NZDMA (1 << 19)
50 #define HOST_HSORG 0xFC
51 #define HSORG_DISABLE_SLOTGRP_INTR (1<<24)
52 #define HSORG_DISABLE_SLOTGRP_PXIS (1<<16)
53 #define HSORG_HWREV 0xFF00
54 #define HSORG_STYLE 0x8
55 #define HSORG_SLOTGROUPS 0x7
57 #define PORT_COMMAND_ISSUE 0x38
58 #define PORT_SDBV 0x7C
60 #define PORT_OFFSET 0x100
61 #define PORT_MEM_SIZE 0x80
63 #define PORT_IRQ_ERR \
64 (PORT_IRQ_HBUS_ERR | PORT_IRQ_IF_ERR | PORT_IRQ_CONNECT | \
65 PORT_IRQ_PHYRDY | PORT_IRQ_UNK_FIS | PORT_IRQ_BAD_PMP | \
66 PORT_IRQ_TF_ERR | PORT_IRQ_HBUS_DATA_ERR | PORT_IRQ_IF_NONFATAL | \
68 #define PORT_IRQ_LEGACY \
69 (PORT_IRQ_PIOS_FIS | PORT_IRQ_D2H_REG_FIS)
70 #define PORT_IRQ_HANDLED \
71 (PORT_IRQ_SDB_FIS | PORT_IRQ_LEGACY | \
72 PORT_IRQ_TF_ERR | PORT_IRQ_IF_ERR | \
73 PORT_IRQ_CONNECT | PORT_IRQ_PHYRDY)
74 #define DEF_PORT_IRQ \
75 (PORT_IRQ_ERR | PORT_IRQ_LEGACY | PORT_IRQ_SDB_FIS)
78 #define MTIP_PRODUCT_UNKNOWN 0x00
79 #define MTIP_PRODUCT_ASICFPGA 0x11
88 static int mtip_major;
89 static struct dentry *dfs_parent;
97 struct mtip_compat_ide_task_request_s {
119 static bool mtip_check_surprise_removal(
struct pci_dev *pdev)
124 pci_read_config_word(pdev, 0x00, &vendor_id);
125 if (vendor_id == 0xFFFF)
143 int group = 0, commandslot = 0, commandindex = 0;
146 static int in_progress;
153 for (group = 0; group < 4; group++) {
154 for (commandslot = 0; commandslot < 32; commandslot++) {
155 if (!(port->
allocated[group] & (1 << commandslot)))
158 commandindex = group << 5 | commandslot;
159 command = &port->
commands[commandindex];
195 static int get_slot(
struct mtip_port *port)
198 unsigned int num_command_slots = port->
dd->slot_groups * 32;
209 for (i = 0; i < 10; i++) {
211 num_command_slots, 1);
212 if ((slot < num_command_slots) &&
216 dev_warn(&port->
dd->pdev->dev,
"Failed to get a tag.\n");
218 if (mtip_check_surprise_removal(port->
dd->pdev)) {
220 mtip_command_cleanup(port->
dd);
234 static inline void release_slot(
struct mtip_port *port,
int tag)
253 static int hba_reset_nosleep(
struct driver_data *dd)
297 static inline void mtip_issue_ncq_command(
struct mtip_port *port,
int tag)
350 static int mtip_enable_engine(
struct mtip_port *port,
int enable)
371 static inline void mtip_start_port(
struct mtip_port *port)
374 mtip_enable_fis(port, 1);
377 mtip_enable_engine(port, 1);
389 static inline void mtip_deinit_port(
struct mtip_port *port)
395 mtip_enable_engine(port, 0);
398 mtip_enable_fis(port, 0);
414 static void mtip_init_port(
struct mtip_port *port)
417 mtip_deinit_port(port);
435 for (i = 0; i < port->
dd->slot_groups; i++)
457 static void mtip_restart_port(
struct mtip_port *port)
459 unsigned long timeout;
462 mtip_enable_engine(port, 0);
479 "PxCMD.CR not clear, escalating reset\n");
481 if (hba_reset_nosleep(port->
dd))
483 "HBA reset escalation failed.\n");
489 dev_warn(&port->
dd->pdev->dev,
"Issuing COM reset\n");
520 "COM reset failed\n");
522 mtip_init_port(port);
523 mtip_start_port(port);
532 unsigned long *tagbits,
535 unsigned char tagmap[128];
536 int group, tagmap_len = 0;
538 memset(tagmap, 0,
sizeof(tagmap));
540 tagmap_len =
sprintf(tagmap + tagmap_len,
"%016lX ",
543 "%d command(s) %s: tagmap [%s]", cnt, msg, tagmap);
555 static void mtip_timeout_function(
unsigned long int data)
560 int tag, cmdto_cnt = 0;
562 unsigned int num_command_slots;
575 num_command_slots = port->
dd->slot_groups * 32;
577 for (tag = 0; tag < num_command_slots; tag++) {
623 release_slot(port, tag);
630 print_tags(port->
dd,
"timed out", tagaccum, cmdto_cnt);
632 mtip_restart_port(port);
675 static void mtip_async_complete(
struct mtip_port *port,
691 "Command tag %d failed due to TFE\n", tag);
709 release_slot(port, tag);
729 static void mtip_completion(
struct mtip_port *port,
738 "Internal command %d completed with TFE\n", tag);
746 static void mtip_null_completion(
struct mtip_port *port,
756 static int mtip_get_smart_attr(
struct mtip_port *port,
unsigned int id,
766 static void mtip_handle_tfe(
struct driver_data *dd)
774 unsigned int cmd_cnt = 0;
776 char *fail_reason =
NULL;
777 int fail_all_ncq_write = 0, fail_all_ncq_cmds = 0;
797 goto handle_tfe_exit;
804 for (group = 0; group < dd->
slot_groups; group++) {
811 for (bit = 0; bit < 32 &&
completed; bit++) {
812 if (!(completed & (1<<bit)))
814 tag = (group << 5) + bit;
831 "Missing completion func for tag %d",
833 if (mtip_check_surprise_removal(dd->
pdev)) {
834 mtip_command_cleanup(dd);
842 print_tags(dd,
"completed (TFE)", tagaccum, cmd_cnt);
846 mtip_restart_port(port);
851 dd->
port->log_buf_dma, 1);
854 "Error in READ LOG EXT (10h) command\n");
857 buf = (
unsigned char *)dd->
port->log_buf;
858 if (buf[259] & 0x1) {
860 "Write protect bit is set.\n");
862 fail_all_ncq_write = 1;
863 fail_reason =
"write protect";
865 if (buf[288] == 0xF7) {
867 "Exceeded Tmax, drive in thermal shutdown.\n");
869 fail_all_ncq_cmds = 1;
870 fail_reason =
"thermal shutdown";
872 if (buf[288] == 0xBF) {
874 "Drive indicates rebuild has failed.\n");
875 fail_all_ncq_cmds = 1;
876 fail_reason =
"rebuild failed";
884 for (group = 0; group < dd->
slot_groups; group++) {
885 for (bit = 0; bit < 32; bit++) {
887 tag = (group << 5) + bit;
901 if (fail_all_ncq_cmds ||
902 (fail_all_ncq_write &&
905 " Fail: %s w/tag %d [%s].\n",
909 fail_reason !=
NULL ?
910 fail_reason :
"unknown");
925 if (reissue && (cmd->
retries-- > 0)) {
930 mtip_issue_ncq_command(port, tag);
937 "retiring tag %d\n", tag);
948 "Bad completion for tag %d\n",
952 print_tags(dd,
"reissued (TFE)", tagaccum, cmd_cnt);
966 static inline void mtip_process_sdbf(
struct driver_data *dd)
974 for (group = 0; group < dd->
slot_groups; group++) {
984 (bit < 32) && completed;
985 bit++, completed >>= 1) {
986 if (completed & 0x01) {
987 tag = (group << 5) | bit;
1007 if (mtip_check_surprise_removal(
1009 mtip_command_cleanup(dd);
1021 static inline void mtip_process_legacy(
struct driver_data *dd,
u32 port_stat)
1044 static inline void mtip_process_errors(
struct driver_data *dd,
u32 port_stat)
1047 mtip_handle_tfe(dd);
1051 "Clearing PxSERR.DIAG.x\n");
1057 "Clearing PxSERR.DIAG.n\n");
1063 "Port stat errors %x unhandled\n",
1072 u32 hba_stat, port_stat;
1085 mtip_process_sdbf(dd);
1089 mtip_command_cleanup(dd);
1097 mtip_process_errors(dd, port_stat & PORT_IRQ_ERR);
1101 mtip_process_legacy(dd, port_stat & PORT_IRQ_LEGACY);
1114 static void mtip_tasklet(
unsigned long data)
1129 static irqreturn_t mtip_irq_handler(
int irq,
void *instance)
1132 tasklet_schedule(&dd->
tasklet);
1136 static void mtip_issue_non_ncq_command(
struct mtip_port *port,
int tag)
1143 static bool mtip_pause_ncq(
struct mtip_port *port,
1147 unsigned long task_file_data;
1155 if ((task_file_data & 1))
1173 mtip_restart_port(port);
1190 static int mtip_quiesce_io(
struct mtip_port *port,
unsigned long timeout)
1210 for (n = 1; n < port->
dd->slot_groups; n++)
1219 return active ? -
EBUSY : 0;
1240 static int mtip_exec_internal_command(
struct mtip_port *port,
1247 unsigned long timeout)
1251 int rv = 0, ready2go = 1;
1256 if (buffer & 0x00000007) {
1258 "SG buffer is not 8 byte aligned\n");
1272 "Internal cmd active. new cmd [%02X]\n", fis->
command);
1286 if (mtip_quiesce_io(port, 5000) < 0) {
1288 "Failed to quiesce IO\n");
1303 int_cmd->
comp_func = mtip_null_completion;
1339 "Internal command did not complete [%d] "
1340 "within timeout of %lu ms\n",
1342 if (mtip_check_surprise_removal(port->
dd->pdev) ||
1344 &port->
dd->dd_flag)) {
1356 if (mtip_check_surprise_removal(port->
dd->pdev)) {
1362 &port->
dd->dd_flag)) {
1375 "Internal command [%02X] failed\n", fis->
command);
1382 &port->
dd->dd_flag)) {
1383 mtip_restart_port(port);
1391 if (rv >= 0 && mtip_pause_ncq(port, fis)) {
1414 static inline void ata_swap_string(
u16 *buf,
unsigned int len)
1417 for (i = 0; i < (len/2); i++)
1440 static int mtip_get_identify(
struct mtip_port *port,
void __user *user_buffer)
1461 if (mtip_exec_internal_command(port,
1479 #ifdef __LITTLE_ENDIAN
1480 ata_swap_string(port->
identify + 27, 40);
1481 ata_swap_string(port->
identify + 23, 8);
1482 ata_swap_string(port->
identify + 10, 20);
1498 ATA_ID_WORDS *
sizeof(
u16))) {
1517 static int mtip_standby_immediate(
struct mtip_port *port)
1521 unsigned long start;
1530 rv = mtip_exec_internal_command(port,
1542 "STANDBY IMMEDIATE command failed.\n");
1576 return mtip_exec_internal_command(port,
1596 static int mtip_get_smart_data(
struct mtip_port *port,
u8 *buffer,
1611 return mtip_exec_internal_command(port,
1632 static int mtip_get_smart_attr(
struct mtip_port *port,
unsigned int id,
1642 dev_warn(&port->
dd->pdev->dev,
"IDENTIFY DATA not valid\n");
1646 dev_warn(&port->
dd->pdev->dev,
"SMART not supported\n");
1650 dev_warn(&port->
dd->pdev->dev,
"SMART not enabled\n");
1657 dev_warn(&port->
dd->pdev->dev,
"Failed to ge SMART data\n");
1662 for (i = 0; i < 29; i++, pattr++)
1670 "Query for invalid SMART attribute ID\n");
1690 u64 total, raw0, raw1, raw2, raw3;
1695 total = raw0 | raw1<<16 | raw2<<32 | raw3<<48;
1718 mtip_deinit_port(dd->
port);
1732 "Reset bit did not clear.\n");
1747 static void mtip_dump_identify(
struct mtip_port *port)
1750 unsigned short revid;
1758 "Serial No.: %s\n", cbuf);
1762 "Firmware Ver.: %s\n", cbuf);
1765 dev_info(&port->
dd->pdev->dev,
"Model: %s\n", cbuf);
1767 if (mtip_hw_get_capacity(port->
dd, §ors))
1769 "Capacity: %llu sectors (%llu MB)\n",
1774 switch (revid & 0xFF) {
1786 "Card Type: %s\n", cbuf);
1798 static inline void fill_command_sg(
struct driver_data *dd,
1803 unsigned int dma_len;
1809 for (n = 0; n < nents; n++) {
1811 if (dma_len > 0x400000)
1813 "DMA segment length truncated\n");
1831 static int exec_drive_task(
struct mtip_port *port,
u8 *command)
1846 fis.
device = command[6] & ~0x10;
1859 if (mtip_exec_internal_command(port,
1873 command[5] = reply->
cyl_hi;
1898 static int exec_drive_command(
struct mtip_port *port,
u8 *command,
1899 void __user *user_buffer)
1905 int rv = 0, xfer_sz = command[3];
1917 "Memory allocation failed (%d bytes)\n",
1943 " %s: User Command: cmd %x, sect %x, "
1944 "feat %x, sectcnt %x\n",
1952 if (mtip_exec_internal_command(port,
1955 (xfer_sz ? dma_addr : 0),
1962 goto exit_drive_command;
1971 " %s: Completion Status: stat %x, "
1972 "err %x, nsect %x\n",
1983 goto exit_drive_command;
2005 static unsigned int implicit_sector(
unsigned char command,
2008 unsigned int rv = 0;
2039 static void mtip_set_timeout(
struct driver_data *dd,
2041 unsigned int *timeout,
u8 erasemode)
2050 *timeout = ((*(dd->
port->identify + 90) * 2) * 60000);
2052 *timeout = ((*(dd->
port->identify + 89) * 2) * 60000);
2074 static int exec_drive_taskfile(
struct driver_data *dd,
2087 unsigned int taskin = 0;
2088 unsigned int taskout = 0;
2090 unsigned int timeout;
2091 unsigned int force_single_sector;
2093 unsigned long task_file_data;
2094 int intotal = outtotal + req_task->
out_size;
2100 if (taskin > 130560 || taskout > 130560) {
2107 if (outbuf ==
NULL) {
2115 outbuf_dma = pci_map_single(dd->
pdev,
2119 if (outbuf_dma == 0) {
2123 dma_buffer = outbuf_dma;
2128 if (inbuf ==
NULL) {
2137 inbuf_dma = pci_map_single(dd->
pdev,
2140 if (inbuf_dma == 0) {
2144 dma_buffer = inbuf_dma;
2194 if ((taskin || taskout) && (!fis.
sect_count)) {
2198 if (!force_single_sector) {
2200 "data movement but "
2201 "sect_count is 0\n");
2209 " %s: cmd %x, feat %x, nsect %x,"
2210 " sect/lbal %x, lcyl/lbam %x, hcyl/lbah %x,"
2227 mtip_set_timeout(dd, &fis, &timeout, erasemode);
2230 if (force_single_sector)
2236 if (mtip_exec_internal_command(dd->
port,
2260 pci_unmap_single(dd->
pdev, inbuf_dma,
2263 pci_unmap_single(dd->
pdev, outbuf_dma,
2285 " %s: Completion: stat %x,"
2286 "err %x, sect_cnt %x, lbalo %x,"
2287 "lbamid %x, lbahi %x, dev %x\n",
2311 pci_unmap_single(dd->
pdev, inbuf_dma,
2314 pci_unmap_single(dd->
pdev, outbuf_dma,
2339 static int mtip_hw_ioctl(
struct driver_data *dd,
unsigned int cmd,
2346 sizeof(
u16) * ATA_ID_WORDS))
2352 u8 drive_command[4];
2356 (
void __user *) arg,
2357 sizeof(drive_command)))
2361 if (exec_drive_command(dd->
port,
2363 (
void __user *) (arg+4)))
2369 sizeof(drive_command)))
2376 u8 drive_command[7];
2380 (
void __user *) arg,
2381 sizeof(drive_command)))
2385 if (exec_drive_task(dd->
port, drive_command))
2391 sizeof(drive_command)))
2404 outtotal =
sizeof(req_task);
2406 ret = exec_drive_taskfile(dd, (
void __user *) arg,
2407 &req_task, outtotal);
2444 int nsect,
int nents,
int tag,
void *
callback,
2445 void *data,
int dir)
2471 fis->
lba_mid = (start >> 8) & 0xFF;
2472 fis->
lba_hi = (start >> 16) & 0xFF;
2484 fill_command_sg(dd, command, nents);
2497 command->
comp_func = mtip_async_complete;
2518 mtip_issue_ncq_command(port, tag);
2532 static void mtip_hw_release_scatterlist(
struct driver_data *dd,
int tag)
2534 release_slot(dd->
port, tag);
2557 *tag = get_slot(dd->
port);
2568 return dd->
port->commands[*
tag].sg;
2585 struct driver_data *dd = dev_to_disk(dev)->private_data;
2589 size +=
sprintf(buf,
"%s",
"thermal_shutdown\n");
2591 size +=
sprintf(buf,
"%s",
"write_protect\n");
2593 size +=
sprintf(buf,
"%s",
"online\n");
2600 static ssize_t mtip_hw_read_registers(
struct file *
f,
char __user *ubuf,
2601 size_t len, loff_t *
offset)
2605 u32 group_allocated;
2612 size +=
sprintf(&buf[size],
"H/ S ACTive : [ 0x");
2615 size +=
sprintf(&buf[size],
"%08X ",
2618 size +=
sprintf(&buf[size],
"]\n");
2619 size +=
sprintf(&buf[size],
"H/ Command Issue : [ 0x");
2622 size +=
sprintf(&buf[size],
"%08X ",
2625 size +=
sprintf(&buf[size],
"]\n");
2626 size +=
sprintf(&buf[size],
"H/ Completed : [ 0x");
2629 size +=
sprintf(&buf[size],
"%08X ",
2632 size +=
sprintf(&buf[size],
"]\n");
2633 size +=
sprintf(&buf[size],
"H/ PORT IRQ STAT : [ 0x%08X ]\n",
2635 size +=
sprintf(&buf[size],
"H/ HOST IRQ STAT : [ 0x%08X ]\n",
2637 size +=
sprintf(&buf[size],
"\n");
2639 size +=
sprintf(&buf[size],
"L/ Allocated : [ 0x");
2642 if (
sizeof(
long) >
sizeof(
u32))
2644 dd->
port->allocated[n/2] >> (32*(n&1));
2646 group_allocated = dd->
port->allocated[
n];
2647 size +=
sprintf(&buf[size],
"%08X ", group_allocated);
2649 size +=
sprintf(&buf[size],
"]\n");
2651 size +=
sprintf(&buf[size],
"L/ Commands in Q : [ 0x");
2654 if (
sizeof(
long) >
sizeof(
u32))
2656 dd->
port->cmds_to_issue[n/2] >> (32*(n&1));
2658 group_allocated = dd->
port->cmds_to_issue[
n];
2659 size +=
sprintf(&buf[size],
"%08X ", group_allocated);
2661 size +=
sprintf(&buf[size],
"]\n");
2663 *offset = size <= len ? size :
len;
2671 static ssize_t mtip_hw_read_flags(
struct file *f,
char __user *ubuf,
2672 size_t len, loff_t *offset)
2681 size +=
sprintf(&buf[size],
"Flag-port : [ %08lX ]\n",
2683 size +=
sprintf(&buf[size],
"Flag-dd : [ %08lX ]\n",
2686 *offset = size <= len ? size :
len;
2697 .read = mtip_hw_read_registers,
2704 .read = mtip_hw_read_flags,
2725 "Error creating 'status' sysfs entry\n");
2749 static int mtip_hw_debugfs_init(
struct driver_data *dd)
2755 if (IS_ERR_OR_NULL(dd->
dfs_node)) {
2757 "Error creating node %s under debugfs\n",
2758 dd->
disk->disk_name);
2771 static void mtip_hw_debugfs_exit(
struct driver_data *dd)
2785 static inline void hba_setup(
struct driver_data *dd)
2807 static void mtip_detect_product(
struct driver_data *dd)
2810 unsigned int rev, slotgroups;
2829 "ASIC-FPGA design, HS rev 0x%x, "
2830 "%i slot groups [%i slots]\n",
2837 "Warning: driver only supports "
2857 static int mtip_ftl_rebuild_poll(
struct driver_data *dd)
2859 unsigned long timeout, cnt = 0,
start;
2862 "FTL rebuild in progress. Polling for completion.\n");
2871 if (mtip_check_surprise_removal(dd->
pdev))
2874 if (mtip_get_identify(dd->
port,
NULL) < 0)
2883 "FTL rebuild in progress (%d secs).\n",
2889 "FTL rebuild complete (%d secs).\n",
2891 mtip_block_initialize(dd);
2899 "Timed out waiting for FTL rebuild to complete (%d secs).\n",
2913 static int mtip_service_thread(
void *data)
2916 unsigned long slot, slot_start, slot_wrap;
2917 unsigned int num_cmd_slots = dd->
slot_groups * 32;
2939 slot_start = num_cmd_slots;
2943 num_cmd_slots, slot);
2944 if (slot_wrap == 1) {
2945 if ((slot_start >= slot) ||
2946 (slot >= num_cmd_slots))
2949 if (
unlikely(slot_start == num_cmd_slots))
2952 if (
unlikely(slot == num_cmd_slots)) {
2959 mtip_issue_ncq_command(port, slot);
2966 if (!mtip_ftl_rebuild_poll(dd))
2991 unsigned int num_command_slots;
2992 unsigned long timeout, timetaken;
2998 mtip_detect_product(dd);
3012 "Memory allocation: port structure\n");
3017 sema_init(&dd->
port->cmd_slot, num_command_slots - 1);
3027 dd->
port->command_list =
3030 &dd->
port->command_list_dma,
3032 if (!dd->
port->command_list) {
3034 "Memory allocation: command list\n");
3053 dd->
port->identify = dd->
port->command_table +
3055 dd->
port->identify_dma = dd->
port->command_tbl_dma +
3072 for (i = 0; i < num_command_slots; i++) {
3073 dd->
port->commands[
i].command_header =
3074 dd->
port->command_list +
3076 dd->
port->commands[
i].command_header_dma =
3077 dd->
port->command_list_dma +
3080 dd->
port->commands[
i].command =
3082 dd->
port->commands[
i].command_dma =
3086 dd->
port->commands[i].command_header->ctbau =
3088 (dd->
port->commands[i].command_dma >> 16) >> 16);
3089 dd->
port->commands[
i].command_header->ctba =
3091 dd->
port->commands[i].command_dma & 0xFFFFFFFF);
3106 dd->
port->s_active[
i] =
3108 dd->
port->cmd_issue[
i] =
3110 dd->
port->completed[
i] =
3121 timetaken =
jiffies - timetaken;
3123 "Surprise removal detected at %u ms\n",
3129 timetaken =
jiffies - timetaken;
3131 "Removal detected at %u ms\n",
3139 if (mtip_hba_reset(dd) < 0) {
3141 "Card did not reset within timeout\n");
3151 mtip_init_port(dd->
port);
3152 mtip_start_port(dd->
port);
3155 rv = devm_request_irq(&dd->
pdev->dev,
3164 "Unable to allocate IRQ %d\n", dd->
pdev->irq);
3175 dd->
port->cmd_timer.data = (
unsigned long int) dd->
port;
3176 dd->
port->cmd_timer.function = mtip_timeout_function;
3186 if (mtip_get_identify(dd->
port,
NULL) < 0) {
3196 mtip_dump_identify(dd->
port);
3201 dd->
port->log_buf_dma, 1);
3204 "Error in READ LOG EXT (10h) command\n");
3207 buf = (
unsigned char *)dd->
port->log_buf;
3208 if (buf[259] & 0x1) {
3210 "Write protect bit is set.\n");
3213 if (buf[288] == 0xF7) {
3215 "Exceeded Tmax, drive in thermal shutdown.\n");
3218 if (buf[288] == 0xBF) {
3220 "Drive indicates rebuild has failed.\n");
3227 if (mtip_get_smart_attr(dd->
port, 242, &attr242))
3229 "Unable to check write protect progress\n");
3232 "Write protect progress: %u%% (%u blocks)\n",
3247 mtip_deinit_port(dd->
port);
3252 dd->
port->command_list,
3253 dd->
port->command_list_dma);
3278 if (mtip_standby_immediate(dd->
port))
3280 "STANDBY IMMEDIATE failed\n");
3283 mtip_deinit_port(dd->
port);
3301 dd->
port->command_list,
3302 dd->
port->command_list_dma);
3320 static int mtip_hw_shutdown(
struct driver_data *dd)
3326 mtip_standby_immediate(dd->
port);
3343 static int mtip_hw_suspend(
struct driver_data *dd)
3349 if (mtip_standby_immediate(dd->
port) != 0) {
3351 "Failed standby-immediate command\n");
3358 mtip_deinit_port(dd->
port);
3381 if (mtip_hba_reset(dd) != 0) {
3383 "Unable to reset the HBA\n");
3391 mtip_init_port(dd->
port);
3392 mtip_start_port(dd->
port);
3405 static int rssd_disk_name_format(
char *
prefix,
3410 const int base =
'z' -
'a' + 1;
3411 char *begin = buf +
strlen(prefix);
3422 *--p =
'a' + (index %
unit);
3423 index = (index /
unit) - 1;
3424 }
while (index >= 0);
3465 return mtip_hw_ioctl(dd, cmd, arg);
3469 #ifdef CONFIG_COMPAT
3483 static int mtip_block_compat_ioctl(
struct block_device *dev,
3503 struct mtip_compat_ide_task_request_s
__user *compat_req_task;
3505 int compat_tasksize, outtotal,
ret;
3508 sizeof(
struct mtip_compat_ide_task_request_s);
3511 (
struct mtip_compat_ide_task_request_s
__user *) arg;
3523 outtotal =
sizeof(
struct mtip_compat_ide_task_request_s);
3525 ret = exec_drive_taskfile(dd, (
void __user *) arg,
3526 &req_task, outtotal);
3542 return mtip_hw_ioctl(dd, cmd, arg);
3574 if (!(mtip_hw_get_capacity(dd, &capacity))) {
3576 "Could not get drive capacity.\n");
3593 static const struct block_device_operations mtip_block_ops = {
3594 .ioctl = mtip_block_ioctl,
3595 #ifdef CONFIG_COMPAT
3596 .compat_ioctl = mtip_block_compat_ioctl,
3598 .getgeo = mtip_block_getgeo,
3617 struct bio_vec *bvec;
3633 bio_data_dir(bio))) {
3643 if (
unlikely(!bio_has_data(bio))) {
3649 sg = mtip_hw_get_scatterlist(dd, &tag);
3655 "Maximum number of SGL entries exceeded\n");
3657 mtip_hw_release_scatterlist(dd, tag);
3662 bio_for_each_segment(bvec, bio, nents) {
3663 sg_set_page(&sg[nents],
3670 mtip_hw_submit_io(dd,
3693 static int mtip_block_initialize(
struct driver_data *dd)
3695 int rv = 0, wait_for_rebuild = 0;
3697 unsigned int index = 0;
3699 unsigned char thd_name[16];
3702 goto skip_create_disk;
3705 wait_for_rebuild = mtip_hw_init(dd);
3706 if (wait_for_rebuild < 0) {
3708 "Protocol layer initialization failed\n");
3710 goto protocol_init_error;
3716 "Unable to allocate gendisk structure\n");
3718 goto alloc_disk_error;
3726 spin_lock(&rssd_index_lock);
3728 spin_unlock(&rssd_index_lock);
3734 rv = rssd_disk_name_format(
"rssd",
3736 dd->
disk->disk_name,
3739 goto disk_index_error;
3741 dd->
disk->driverfs_dev = &dd->
pdev->dev;
3744 dd->
disk->fops = &mtip_block_ops;
3745 dd->
disk->private_data =
dd;
3753 goto start_service_thread;
3760 "Unable to allocate request queue\n");
3762 goto block_queue_alloc_init_error;
3786 if (!(mtip_hw_get_capacity(dd, &capacity))) {
3788 "Could not read drive capacity\n");
3790 goto read_capacity_error;
3792 set_capacity(dd->
disk, capacity);
3803 mtip_hw_sysfs_init(dd, kobj);
3806 mtip_hw_debugfs_init(dd);
3813 start_service_thread:
3814 sprintf(thd_name,
"mtip_svc_thd_%02d", index);
3820 dev_err(&dd->
pdev->dev,
"service thread failed to start\n");
3823 goto kthread_run_error;
3827 rv = wait_for_rebuild;
3832 mtip_hw_debugfs_exit(dd);
3837 read_capacity_error:
3840 block_queue_alloc_init_error:
3842 spin_lock(&rssd_index_lock);
3844 spin_unlock(&rssd_index_lock);
3852 protocol_init_error:
3866 static int mtip_block_remove(
struct driver_data *dd)
3880 mtip_hw_sysfs_exit(dd, kobj);
3884 mtip_hw_debugfs_exit(dd);
3892 spin_lock(&rssd_index_lock);
3894 spin_unlock(&rssd_index_lock);
3918 static int mtip_block_shutdown(
struct driver_data *dd)
3921 "Shutting down %s ...\n", dd->
disk->disk_name);
3926 spin_lock(&rssd_index_lock);
3928 spin_unlock(&rssd_index_lock);
3934 mtip_hw_shutdown(dd);
3938 static int mtip_block_suspend(
struct driver_data *dd)
3941 "Suspending %s ...\n", dd->
disk->disk_name);
3942 mtip_hw_suspend(dd);
3946 static int mtip_block_resume(
struct driver_data *dd)
3949 dd->
disk->disk_name);
3963 static int mtip_pci_probe(
struct pci_dev *pdev,
3973 "Unable to allocate memory for driver data\n");
3978 pci_set_drvdata(pdev, dd);
3982 dev_err(&pdev->
dev,
"Unable to enable device\n");
3989 dev_err(&pdev->
dev,
"Unable to map regions\n");
3994 rv = pci_set_consistent_dma_mask(pdev,
DMA_BIT_MASK(64));
3997 rv = pci_set_consistent_dma_mask(pdev,
4001 "64-bit DMA enable failed\n");
4009 if (pci_enable_msi(pdev)) {
4011 "Unable to enable MSI interrupt.\n");
4012 goto block_initialize_err;
4016 dd->
major = mtip_major;
4021 rv = mtip_block_initialize(dd);
4024 "Unable to initialize block layer\n");
4025 goto block_initialize_err;
4037 block_initialize_err:
4045 pci_set_drvdata(pdev,
NULL);
4058 static void mtip_pci_remove(
struct pci_dev *pdev)
4065 if (mtip_check_surprise_removal(pdev)) {
4069 if (counter == 10) {
4071 mtip_command_cleanup(dd);
4078 mtip_block_remove(dd);
4100 "Driver private datastructure is NULL\n");
4107 rv = mtip_block_suspend(dd);
4110 "Failed to suspend controller\n");
4134 static int mtip_pci_resume(
struct pci_dev *pdev)
4139 dd = pci_get_drvdata(pdev);
4142 "Driver private datastructure is NULL\n");
4156 "Failed to enable card during resume\n");
4165 rv = mtip_block_resume(dd);
4181 static void mtip_pci_shutdown(
struct pci_dev *pdev)
4185 mtip_block_shutdown(dd);
4203 .id_table = mtip_pci_tbl,
4204 .probe = mtip_pci_probe,
4205 .remove = mtip_pci_remove,
4206 .suspend = mtip_pci_suspend,
4207 .resume = mtip_pci_resume,
4208 .shutdown = mtip_pci_shutdown,
4223 static int __init mtip_init(
void)
4232 pr_err(
"Unable to register block device (%d)\n",
4240 if (IS_ERR_OR_NULL(dfs_parent)) {
4241 pr_warn(
"Error creating debugfs parent\n");
4247 error = pci_register_driver(&mtip_pci_driver);
4266 static void __exit mtip_exit(
void)