Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * sata_nv.c - NVIDIA nForce SATA |
| 3 | * |
| 4 | * Copyright 2004 NVIDIA Corp. All rights reserved. |
| 5 | * Copyright 2004 Andrew Chew |
| 6 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * |
Jeff Garzik | aa7e16d | 2005-08-29 15:12:56 -0400 | [diff] [blame] | 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2, or (at your option) |
| 11 | * any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; see the file COPYING. If not, write to |
| 20 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | * |
Jeff Garzik | af36d7f | 2005-08-28 20:18:39 -0400 | [diff] [blame] | 22 | * |
| 23 | * libata documentation is available via 'make {ps|pdf}docs', |
| 24 | * as Documentation/DocBook/libata.* |
| 25 | * |
| 26 | * No hardware documentation available outside of NVIDIA. |
| 27 | * This driver programs the NVIDIA SATA controller in a similar |
| 28 | * fashion as with other PCI IDE BMDMA controllers, with a few |
| 29 | * NV-specific details such as register offsets, SATA phy location, |
| 30 | * hotplug info, etc. |
| 31 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | */ |
| 33 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #include <linux/kernel.h> |
| 35 | #include <linux/module.h> |
| 36 | #include <linux/pci.h> |
| 37 | #include <linux/init.h> |
| 38 | #include <linux/blkdev.h> |
| 39 | #include <linux/delay.h> |
| 40 | #include <linux/interrupt.h> |
Jeff Garzik | a9524a7 | 2005-10-30 14:39:11 -0500 | [diff] [blame] | 41 | #include <linux/device.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | #include <scsi/scsi_host.h> |
| 43 | #include <linux/libata.h> |
| 44 | |
| 45 | #define DRV_NAME "sata_nv" |
Jeff Garzik | 8676ce0 | 2006-06-26 20:41:33 -0400 | [diff] [blame] | 46 | #define DRV_VERSION "2.0" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | |
Jeff Garzik | 10ad05d | 2006-03-22 23:50:50 -0500 | [diff] [blame] | 48 | enum { |
| 49 | NV_PORTS = 2, |
| 50 | NV_PIO_MASK = 0x1f, |
| 51 | NV_MWDMA_MASK = 0x07, |
| 52 | NV_UDMA_MASK = 0x7f, |
| 53 | NV_PORT0_SCR_REG_OFFSET = 0x00, |
| 54 | NV_PORT1_SCR_REG_OFFSET = 0x40, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | |
Tejun Heo | 27e4b27 | 2006-06-17 15:49:55 +0900 | [diff] [blame] | 56 | /* INT_STATUS/ENABLE */ |
Jeff Garzik | 10ad05d | 2006-03-22 23:50:50 -0500 | [diff] [blame] | 57 | NV_INT_STATUS = 0x10, |
Jeff Garzik | 10ad05d | 2006-03-22 23:50:50 -0500 | [diff] [blame] | 58 | NV_INT_ENABLE = 0x11, |
Tejun Heo | 27e4b27 | 2006-06-17 15:49:55 +0900 | [diff] [blame] | 59 | NV_INT_STATUS_CK804 = 0x440, |
Jeff Garzik | 10ad05d | 2006-03-22 23:50:50 -0500 | [diff] [blame] | 60 | NV_INT_ENABLE_CK804 = 0x441, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | |
Tejun Heo | 27e4b27 | 2006-06-17 15:49:55 +0900 | [diff] [blame] | 62 | /* INT_STATUS/ENABLE bits */ |
| 63 | NV_INT_DEV = 0x01, |
| 64 | NV_INT_PM = 0x02, |
| 65 | NV_INT_ADDED = 0x04, |
| 66 | NV_INT_REMOVED = 0x08, |
| 67 | |
| 68 | NV_INT_PORT_SHIFT = 4, /* each port occupies 4 bits */ |
| 69 | |
Tejun Heo | 39f8758 | 2006-06-17 15:49:56 +0900 | [diff] [blame] | 70 | NV_INT_ALL = 0x0f, |
Tejun Heo | 5a44eff | 2006-06-17 15:49:56 +0900 | [diff] [blame] | 71 | NV_INT_MASK = NV_INT_DEV | |
| 72 | NV_INT_ADDED | NV_INT_REMOVED, |
Tejun Heo | 39f8758 | 2006-06-17 15:49:56 +0900 | [diff] [blame] | 73 | |
Tejun Heo | 27e4b27 | 2006-06-17 15:49:55 +0900 | [diff] [blame] | 74 | /* INT_CONFIG */ |
Jeff Garzik | 10ad05d | 2006-03-22 23:50:50 -0500 | [diff] [blame] | 75 | NV_INT_CONFIG = 0x12, |
| 76 | NV_INT_CONFIG_METHD = 0x01, // 0 = INT, 1 = SMI |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | |
Jeff Garzik | 10ad05d | 2006-03-22 23:50:50 -0500 | [diff] [blame] | 78 | // For PCI config register 20 |
| 79 | NV_MCP_SATA_CFG_20 = 0x50, |
| 80 | NV_MCP_SATA_CFG_20_SATA_SPACE_EN = 0x04, |
| 81 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | |
| 83 | static int nv_init_one (struct pci_dev *pdev, const struct pci_device_id *ent); |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 84 | static void nv_ck804_host_stop(struct ata_host *host); |
Tejun Heo | ada364e | 2006-06-17 15:49:56 +0900 | [diff] [blame] | 85 | static irqreturn_t nv_generic_interrupt(int irq, void *dev_instance, |
| 86 | struct pt_regs *regs); |
| 87 | static irqreturn_t nv_nf2_interrupt(int irq, void *dev_instance, |
| 88 | struct pt_regs *regs); |
| 89 | static irqreturn_t nv_ck804_interrupt(int irq, void *dev_instance, |
| 90 | struct pt_regs *regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | static u32 nv_scr_read (struct ata_port *ap, unsigned int sc_reg); |
| 92 | static void nv_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | |
Tejun Heo | 39f8758 | 2006-06-17 15:49:56 +0900 | [diff] [blame] | 94 | static void nv_nf2_freeze(struct ata_port *ap); |
| 95 | static void nv_nf2_thaw(struct ata_port *ap); |
| 96 | static void nv_ck804_freeze(struct ata_port *ap); |
| 97 | static void nv_ck804_thaw(struct ata_port *ap); |
| 98 | static void nv_error_handler(struct ata_port *ap); |
| 99 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | enum nv_host_type |
| 101 | { |
| 102 | GENERIC, |
| 103 | NFORCE2, |
Tejun Heo | 27e4b27 | 2006-06-17 15:49:55 +0900 | [diff] [blame] | 104 | NFORCE3 = NFORCE2, /* NF2 == NF3 as far as sata_nv is concerned */ |
Andy Currid | e710245 | 2005-10-07 08:53:39 -0700 | [diff] [blame] | 105 | CK804 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | }; |
| 107 | |
Jeff Garzik | 3b7d697 | 2005-11-10 11:04:11 -0500 | [diff] [blame] | 108 | static const struct pci_device_id nv_pci_tbl[] = { |
Jeff Garzik | 54bb3a9 | 2006-09-27 22:20:11 -0400 | [diff] [blame] | 109 | { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE2S_SATA), NFORCE2 }, |
| 110 | { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE3S_SATA), NFORCE3 }, |
| 111 | { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE3S_SATA2), NFORCE3 }, |
| 112 | { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_CK804_SATA), CK804 }, |
| 113 | { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_CK804_SATA2), CK804 }, |
| 114 | { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP04_SATA), CK804 }, |
| 115 | { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP04_SATA2), CK804 }, |
| 116 | { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP51_SATA), GENERIC }, |
| 117 | { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP51_SATA2), GENERIC }, |
| 118 | { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP55_SATA), GENERIC }, |
| 119 | { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP55_SATA2), GENERIC }, |
| 120 | { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP61_SATA), GENERIC }, |
| 121 | { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP61_SATA2), GENERIC }, |
| 122 | { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP61_SATA3), GENERIC }, |
| 123 | { PCI_VDEVICE(NVIDIA, 0x045c), GENERIC }, |
| 124 | { PCI_VDEVICE(NVIDIA, 0x045d), GENERIC }, |
| 125 | { PCI_VDEVICE(NVIDIA, 0x045e), GENERIC }, |
| 126 | { PCI_VDEVICE(NVIDIA, 0x045f), GENERIC }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | { PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID, |
| 128 | PCI_ANY_ID, PCI_ANY_ID, |
| 129 | PCI_CLASS_STORAGE_IDE<<8, 0xffff00, GENERIC }, |
Daniel Drake | 541134c | 2005-07-03 13:44:39 +0100 | [diff] [blame] | 130 | { PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID, |
| 131 | PCI_ANY_ID, PCI_ANY_ID, |
| 132 | PCI_CLASS_STORAGE_RAID<<8, 0xffff00, GENERIC }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | { 0, } /* terminate list */ |
| 134 | }; |
| 135 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | static struct pci_driver nv_pci_driver = { |
| 137 | .name = DRV_NAME, |
| 138 | .id_table = nv_pci_tbl, |
| 139 | .probe = nv_init_one, |
| 140 | .remove = ata_pci_remove_one, |
| 141 | }; |
| 142 | |
Jeff Garzik | 193515d | 2005-11-07 00:59:37 -0500 | [diff] [blame] | 143 | static struct scsi_host_template nv_sht = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | .module = THIS_MODULE, |
| 145 | .name = DRV_NAME, |
| 146 | .ioctl = ata_scsi_ioctl, |
| 147 | .queuecommand = ata_scsi_queuecmd, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | .can_queue = ATA_DEF_QUEUE, |
| 149 | .this_id = ATA_SHT_THIS_ID, |
| 150 | .sg_tablesize = LIBATA_MAX_PRD, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | .cmd_per_lun = ATA_SHT_CMD_PER_LUN, |
| 152 | .emulated = ATA_SHT_EMULATED, |
| 153 | .use_clustering = ATA_SHT_USE_CLUSTERING, |
| 154 | .proc_name = DRV_NAME, |
| 155 | .dma_boundary = ATA_DMA_BOUNDARY, |
| 156 | .slave_configure = ata_scsi_slave_config, |
Tejun Heo | ccf68c3 | 2006-05-31 18:28:09 +0900 | [diff] [blame] | 157 | .slave_destroy = ata_scsi_slave_destroy, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | .bios_param = ata_std_bios_param, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | }; |
| 160 | |
Tejun Heo | ada364e | 2006-06-17 15:49:56 +0900 | [diff] [blame] | 161 | static const struct ata_port_operations nv_generic_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | .port_disable = ata_port_disable, |
| 163 | .tf_load = ata_tf_load, |
| 164 | .tf_read = ata_tf_read, |
| 165 | .exec_command = ata_exec_command, |
| 166 | .check_status = ata_check_status, |
| 167 | .dev_select = ata_std_dev_select, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | .bmdma_setup = ata_bmdma_setup, |
| 169 | .bmdma_start = ata_bmdma_start, |
| 170 | .bmdma_stop = ata_bmdma_stop, |
| 171 | .bmdma_status = ata_bmdma_status, |
| 172 | .qc_prep = ata_qc_prep, |
| 173 | .qc_issue = ata_qc_issue_prot, |
Tejun Heo | 39f8758 | 2006-06-17 15:49:56 +0900 | [diff] [blame] | 174 | .freeze = ata_bmdma_freeze, |
| 175 | .thaw = ata_bmdma_thaw, |
| 176 | .error_handler = nv_error_handler, |
| 177 | .post_internal_cmd = ata_bmdma_post_internal_cmd, |
Alan Cox | a6b2c5d | 2006-05-22 16:59:59 +0100 | [diff] [blame] | 178 | .data_xfer = ata_pio_data_xfer, |
Tejun Heo | ada364e | 2006-06-17 15:49:56 +0900 | [diff] [blame] | 179 | .irq_handler = nv_generic_interrupt, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | .irq_clear = ata_bmdma_irq_clear, |
| 181 | .scr_read = nv_scr_read, |
| 182 | .scr_write = nv_scr_write, |
| 183 | .port_start = ata_port_start, |
| 184 | .port_stop = ata_port_stop, |
Tejun Heo | e6faf08 | 2006-06-17 15:49:55 +0900 | [diff] [blame] | 185 | .host_stop = ata_pci_host_stop, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | }; |
| 187 | |
Tejun Heo | ada364e | 2006-06-17 15:49:56 +0900 | [diff] [blame] | 188 | static const struct ata_port_operations nv_nf2_ops = { |
| 189 | .port_disable = ata_port_disable, |
| 190 | .tf_load = ata_tf_load, |
| 191 | .tf_read = ata_tf_read, |
| 192 | .exec_command = ata_exec_command, |
| 193 | .check_status = ata_check_status, |
| 194 | .dev_select = ata_std_dev_select, |
Tejun Heo | ada364e | 2006-06-17 15:49:56 +0900 | [diff] [blame] | 195 | .bmdma_setup = ata_bmdma_setup, |
| 196 | .bmdma_start = ata_bmdma_start, |
| 197 | .bmdma_stop = ata_bmdma_stop, |
| 198 | .bmdma_status = ata_bmdma_status, |
| 199 | .qc_prep = ata_qc_prep, |
| 200 | .qc_issue = ata_qc_issue_prot, |
Tejun Heo | 39f8758 | 2006-06-17 15:49:56 +0900 | [diff] [blame] | 201 | .freeze = nv_nf2_freeze, |
| 202 | .thaw = nv_nf2_thaw, |
| 203 | .error_handler = nv_error_handler, |
| 204 | .post_internal_cmd = ata_bmdma_post_internal_cmd, |
Tejun Heo | ada364e | 2006-06-17 15:49:56 +0900 | [diff] [blame] | 205 | .data_xfer = ata_pio_data_xfer, |
| 206 | .irq_handler = nv_nf2_interrupt, |
| 207 | .irq_clear = ata_bmdma_irq_clear, |
| 208 | .scr_read = nv_scr_read, |
| 209 | .scr_write = nv_scr_write, |
| 210 | .port_start = ata_port_start, |
| 211 | .port_stop = ata_port_stop, |
| 212 | .host_stop = ata_pci_host_stop, |
| 213 | }; |
| 214 | |
| 215 | static const struct ata_port_operations nv_ck804_ops = { |
| 216 | .port_disable = ata_port_disable, |
| 217 | .tf_load = ata_tf_load, |
| 218 | .tf_read = ata_tf_read, |
| 219 | .exec_command = ata_exec_command, |
| 220 | .check_status = ata_check_status, |
| 221 | .dev_select = ata_std_dev_select, |
Tejun Heo | ada364e | 2006-06-17 15:49:56 +0900 | [diff] [blame] | 222 | .bmdma_setup = ata_bmdma_setup, |
| 223 | .bmdma_start = ata_bmdma_start, |
| 224 | .bmdma_stop = ata_bmdma_stop, |
| 225 | .bmdma_status = ata_bmdma_status, |
| 226 | .qc_prep = ata_qc_prep, |
| 227 | .qc_issue = ata_qc_issue_prot, |
Tejun Heo | 39f8758 | 2006-06-17 15:49:56 +0900 | [diff] [blame] | 228 | .freeze = nv_ck804_freeze, |
| 229 | .thaw = nv_ck804_thaw, |
| 230 | .error_handler = nv_error_handler, |
| 231 | .post_internal_cmd = ata_bmdma_post_internal_cmd, |
Tejun Heo | ada364e | 2006-06-17 15:49:56 +0900 | [diff] [blame] | 232 | .data_xfer = ata_pio_data_xfer, |
| 233 | .irq_handler = nv_ck804_interrupt, |
| 234 | .irq_clear = ata_bmdma_irq_clear, |
| 235 | .scr_read = nv_scr_read, |
| 236 | .scr_write = nv_scr_write, |
| 237 | .port_start = ata_port_start, |
| 238 | .port_stop = ata_port_stop, |
| 239 | .host_stop = nv_ck804_host_stop, |
| 240 | }; |
| 241 | |
Tejun Heo | ada364e | 2006-06-17 15:49:56 +0900 | [diff] [blame] | 242 | static struct ata_port_info nv_port_info[] = { |
| 243 | /* generic */ |
| 244 | { |
| 245 | .sht = &nv_sht, |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 246 | .flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY, |
Tejun Heo | ada364e | 2006-06-17 15:49:56 +0900 | [diff] [blame] | 247 | .pio_mask = NV_PIO_MASK, |
| 248 | .mwdma_mask = NV_MWDMA_MASK, |
| 249 | .udma_mask = NV_UDMA_MASK, |
| 250 | .port_ops = &nv_generic_ops, |
| 251 | }, |
| 252 | /* nforce2/3 */ |
| 253 | { |
| 254 | .sht = &nv_sht, |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 255 | .flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY, |
Tejun Heo | ada364e | 2006-06-17 15:49:56 +0900 | [diff] [blame] | 256 | .pio_mask = NV_PIO_MASK, |
| 257 | .mwdma_mask = NV_MWDMA_MASK, |
| 258 | .udma_mask = NV_UDMA_MASK, |
| 259 | .port_ops = &nv_nf2_ops, |
| 260 | }, |
| 261 | /* ck804 */ |
| 262 | { |
| 263 | .sht = &nv_sht, |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 264 | .flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY, |
Tejun Heo | ada364e | 2006-06-17 15:49:56 +0900 | [diff] [blame] | 265 | .pio_mask = NV_PIO_MASK, |
| 266 | .mwdma_mask = NV_MWDMA_MASK, |
| 267 | .udma_mask = NV_UDMA_MASK, |
| 268 | .port_ops = &nv_ck804_ops, |
| 269 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | }; |
| 271 | |
| 272 | MODULE_AUTHOR("NVIDIA"); |
| 273 | MODULE_DESCRIPTION("low-level driver for NVIDIA nForce SATA controller"); |
| 274 | MODULE_LICENSE("GPL"); |
| 275 | MODULE_DEVICE_TABLE(pci, nv_pci_tbl); |
| 276 | MODULE_VERSION(DRV_VERSION); |
| 277 | |
Tejun Heo | ada364e | 2006-06-17 15:49:56 +0900 | [diff] [blame] | 278 | static irqreturn_t nv_generic_interrupt(int irq, void *dev_instance, |
| 279 | struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | { |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 281 | struct ata_host *host = dev_instance; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | unsigned int i; |
| 283 | unsigned int handled = 0; |
| 284 | unsigned long flags; |
| 285 | |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 286 | spin_lock_irqsave(&host->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 288 | for (i = 0; i < host->n_ports; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | struct ata_port *ap; |
| 290 | |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 291 | ap = host->ports[i]; |
Tejun Heo | c138950 | 2005-08-22 14:59:24 +0900 | [diff] [blame] | 292 | if (ap && |
Jeff Garzik | 029f546 | 2006-04-02 10:30:40 -0400 | [diff] [blame] | 293 | !(ap->flags & ATA_FLAG_DISABLED)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | struct ata_queued_cmd *qc; |
| 295 | |
| 296 | qc = ata_qc_from_tag(ap, ap->active_tag); |
Albert Lee | e50362e | 2005-09-27 17:39:50 +0800 | [diff] [blame] | 297 | if (qc && (!(qc->tf.flags & ATA_TFLAG_POLLING))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | handled += ata_host_intr(ap, qc); |
Andrew Chew | b887030 | 2006-01-04 19:13:04 -0800 | [diff] [blame] | 299 | else |
| 300 | // No request pending? Clear interrupt status |
| 301 | // anyway, in case there's one pending. |
| 302 | ap->ops->check_status(ap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | } |
| 306 | |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 307 | spin_unlock_irqrestore(&host->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | |
| 309 | return IRQ_RETVAL(handled); |
| 310 | } |
| 311 | |
Tejun Heo | ada364e | 2006-06-17 15:49:56 +0900 | [diff] [blame] | 312 | static int nv_host_intr(struct ata_port *ap, u8 irq_stat) |
| 313 | { |
| 314 | struct ata_queued_cmd *qc = ata_qc_from_tag(ap, ap->active_tag); |
| 315 | int handled; |
| 316 | |
Tejun Heo | 5a44eff | 2006-06-17 15:49:56 +0900 | [diff] [blame] | 317 | /* freeze if hotplugged */ |
| 318 | if (unlikely(irq_stat & (NV_INT_ADDED | NV_INT_REMOVED))) { |
| 319 | ata_port_freeze(ap); |
| 320 | return 1; |
| 321 | } |
| 322 | |
Tejun Heo | ada364e | 2006-06-17 15:49:56 +0900 | [diff] [blame] | 323 | /* bail out if not our interrupt */ |
| 324 | if (!(irq_stat & NV_INT_DEV)) |
| 325 | return 0; |
| 326 | |
| 327 | /* DEV interrupt w/ no active qc? */ |
| 328 | if (unlikely(!qc || (qc->tf.flags & ATA_TFLAG_POLLING))) { |
| 329 | ata_check_status(ap); |
| 330 | return 1; |
| 331 | } |
| 332 | |
| 333 | /* handle interrupt */ |
| 334 | handled = ata_host_intr(ap, qc); |
| 335 | if (unlikely(!handled)) { |
| 336 | /* spurious, clear it */ |
| 337 | ata_check_status(ap); |
| 338 | } |
| 339 | |
| 340 | return 1; |
| 341 | } |
| 342 | |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 343 | static irqreturn_t nv_do_interrupt(struct ata_host *host, u8 irq_stat) |
Tejun Heo | ada364e | 2006-06-17 15:49:56 +0900 | [diff] [blame] | 344 | { |
| 345 | int i, handled = 0; |
| 346 | |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 347 | for (i = 0; i < host->n_ports; i++) { |
| 348 | struct ata_port *ap = host->ports[i]; |
Tejun Heo | ada364e | 2006-06-17 15:49:56 +0900 | [diff] [blame] | 349 | |
| 350 | if (ap && !(ap->flags & ATA_FLAG_DISABLED)) |
| 351 | handled += nv_host_intr(ap, irq_stat); |
| 352 | |
| 353 | irq_stat >>= NV_INT_PORT_SHIFT; |
| 354 | } |
| 355 | |
| 356 | return IRQ_RETVAL(handled); |
| 357 | } |
| 358 | |
| 359 | static irqreturn_t nv_nf2_interrupt(int irq, void *dev_instance, |
| 360 | struct pt_regs *regs) |
| 361 | { |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 362 | struct ata_host *host = dev_instance; |
Tejun Heo | ada364e | 2006-06-17 15:49:56 +0900 | [diff] [blame] | 363 | u8 irq_stat; |
| 364 | irqreturn_t ret; |
| 365 | |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 366 | spin_lock(&host->lock); |
| 367 | irq_stat = inb(host->ports[0]->ioaddr.scr_addr + NV_INT_STATUS); |
| 368 | ret = nv_do_interrupt(host, irq_stat); |
| 369 | spin_unlock(&host->lock); |
Tejun Heo | ada364e | 2006-06-17 15:49:56 +0900 | [diff] [blame] | 370 | |
| 371 | return ret; |
| 372 | } |
| 373 | |
| 374 | static irqreturn_t nv_ck804_interrupt(int irq, void *dev_instance, |
| 375 | struct pt_regs *regs) |
| 376 | { |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 377 | struct ata_host *host = dev_instance; |
Tejun Heo | ada364e | 2006-06-17 15:49:56 +0900 | [diff] [blame] | 378 | u8 irq_stat; |
| 379 | irqreturn_t ret; |
| 380 | |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 381 | spin_lock(&host->lock); |
| 382 | irq_stat = readb(host->mmio_base + NV_INT_STATUS_CK804); |
| 383 | ret = nv_do_interrupt(host, irq_stat); |
| 384 | spin_unlock(&host->lock); |
Tejun Heo | ada364e | 2006-06-17 15:49:56 +0900 | [diff] [blame] | 385 | |
| 386 | return ret; |
| 387 | } |
| 388 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | static u32 nv_scr_read (struct ata_port *ap, unsigned int sc_reg) |
| 390 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | if (sc_reg > SCR_CONTROL) |
| 392 | return 0xffffffffU; |
| 393 | |
Jeff Garzik | 02cbd92 | 2006-03-22 23:59:46 -0500 | [diff] [blame] | 394 | return ioread32((void __iomem *)ap->ioaddr.scr_addr + (sc_reg * 4)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | static void nv_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val) |
| 398 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | if (sc_reg > SCR_CONTROL) |
| 400 | return; |
| 401 | |
Jeff Garzik | 02cbd92 | 2006-03-22 23:59:46 -0500 | [diff] [blame] | 402 | iowrite32(val, (void __iomem *)ap->ioaddr.scr_addr + (sc_reg * 4)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | } |
| 404 | |
Tejun Heo | 39f8758 | 2006-06-17 15:49:56 +0900 | [diff] [blame] | 405 | static void nv_nf2_freeze(struct ata_port *ap) |
| 406 | { |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 407 | unsigned long scr_addr = ap->host->ports[0]->ioaddr.scr_addr; |
Tejun Heo | 39f8758 | 2006-06-17 15:49:56 +0900 | [diff] [blame] | 408 | int shift = ap->port_no * NV_INT_PORT_SHIFT; |
| 409 | u8 mask; |
| 410 | |
| 411 | mask = inb(scr_addr + NV_INT_ENABLE); |
| 412 | mask &= ~(NV_INT_ALL << shift); |
| 413 | outb(mask, scr_addr + NV_INT_ENABLE); |
| 414 | } |
| 415 | |
| 416 | static void nv_nf2_thaw(struct ata_port *ap) |
| 417 | { |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 418 | unsigned long scr_addr = ap->host->ports[0]->ioaddr.scr_addr; |
Tejun Heo | 39f8758 | 2006-06-17 15:49:56 +0900 | [diff] [blame] | 419 | int shift = ap->port_no * NV_INT_PORT_SHIFT; |
| 420 | u8 mask; |
| 421 | |
| 422 | outb(NV_INT_ALL << shift, scr_addr + NV_INT_STATUS); |
| 423 | |
| 424 | mask = inb(scr_addr + NV_INT_ENABLE); |
| 425 | mask |= (NV_INT_MASK << shift); |
| 426 | outb(mask, scr_addr + NV_INT_ENABLE); |
| 427 | } |
| 428 | |
| 429 | static void nv_ck804_freeze(struct ata_port *ap) |
| 430 | { |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 431 | void __iomem *mmio_base = ap->host->mmio_base; |
Tejun Heo | 39f8758 | 2006-06-17 15:49:56 +0900 | [diff] [blame] | 432 | int shift = ap->port_no * NV_INT_PORT_SHIFT; |
| 433 | u8 mask; |
| 434 | |
| 435 | mask = readb(mmio_base + NV_INT_ENABLE_CK804); |
| 436 | mask &= ~(NV_INT_ALL << shift); |
| 437 | writeb(mask, mmio_base + NV_INT_ENABLE_CK804); |
| 438 | } |
| 439 | |
| 440 | static void nv_ck804_thaw(struct ata_port *ap) |
| 441 | { |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 442 | void __iomem *mmio_base = ap->host->mmio_base; |
Tejun Heo | 39f8758 | 2006-06-17 15:49:56 +0900 | [diff] [blame] | 443 | int shift = ap->port_no * NV_INT_PORT_SHIFT; |
| 444 | u8 mask; |
| 445 | |
| 446 | writeb(NV_INT_ALL << shift, mmio_base + NV_INT_STATUS_CK804); |
| 447 | |
| 448 | mask = readb(mmio_base + NV_INT_ENABLE_CK804); |
| 449 | mask |= (NV_INT_MASK << shift); |
| 450 | writeb(mask, mmio_base + NV_INT_ENABLE_CK804); |
| 451 | } |
| 452 | |
| 453 | static int nv_hardreset(struct ata_port *ap, unsigned int *class) |
| 454 | { |
| 455 | unsigned int dummy; |
| 456 | |
| 457 | /* SATA hardreset fails to retrieve proper device signature on |
| 458 | * some controllers. Don't classify on hardreset. For more |
| 459 | * info, see http://bugme.osdl.org/show_bug.cgi?id=3352 |
| 460 | */ |
| 461 | return sata_std_hardreset(ap, &dummy); |
| 462 | } |
| 463 | |
| 464 | static void nv_error_handler(struct ata_port *ap) |
| 465 | { |
| 466 | ata_bmdma_drive_eh(ap, ata_std_prereset, ata_std_softreset, |
| 467 | nv_hardreset, ata_std_postreset); |
| 468 | } |
| 469 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | static int nv_init_one (struct pci_dev *pdev, const struct pci_device_id *ent) |
| 471 | { |
| 472 | static int printed_version = 0; |
Jeff Garzik | 29da9f6 | 2006-09-25 21:56:33 -0400 | [diff] [blame] | 473 | struct ata_port_info *ppi[2]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | struct ata_probe_ent *probe_ent; |
| 475 | int pci_dev_busy = 0; |
| 476 | int rc; |
| 477 | u32 bar; |
Jeff Garzik | 02cbd92 | 2006-03-22 23:59:46 -0500 | [diff] [blame] | 478 | unsigned long base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | |
| 480 | // Make sure this is a SATA controller by counting the number of bars |
| 481 | // (NVIDIA SATA controllers will always have six bars). Otherwise, |
| 482 | // it's an IDE controller and we ignore it. |
| 483 | for (bar=0; bar<6; bar++) |
| 484 | if (pci_resource_start(pdev, bar) == 0) |
| 485 | return -ENODEV; |
| 486 | |
| 487 | if (!printed_version++) |
Jeff Garzik | a9524a7 | 2005-10-30 14:39:11 -0500 | [diff] [blame] | 488 | dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | |
| 490 | rc = pci_enable_device(pdev); |
| 491 | if (rc) |
| 492 | goto err_out; |
| 493 | |
| 494 | rc = pci_request_regions(pdev, DRV_NAME); |
| 495 | if (rc) { |
| 496 | pci_dev_busy = 1; |
| 497 | goto err_out_disable; |
| 498 | } |
| 499 | |
| 500 | rc = pci_set_dma_mask(pdev, ATA_DMA_MASK); |
| 501 | if (rc) |
| 502 | goto err_out_regions; |
| 503 | rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK); |
| 504 | if (rc) |
| 505 | goto err_out_regions; |
| 506 | |
| 507 | rc = -ENOMEM; |
| 508 | |
Jeff Garzik | 29da9f6 | 2006-09-25 21:56:33 -0400 | [diff] [blame] | 509 | ppi[0] = ppi[1] = &nv_port_info[ent->driver_data]; |
| 510 | probe_ent = ata_pci_init_native_mode(pdev, ppi, ATA_PORT_PRIMARY | ATA_PORT_SECONDARY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | if (!probe_ent) |
| 512 | goto err_out_regions; |
| 513 | |
Jeff Garzik | 02cbd92 | 2006-03-22 23:59:46 -0500 | [diff] [blame] | 514 | probe_ent->mmio_base = pci_iomap(pdev, 5, 0); |
| 515 | if (!probe_ent->mmio_base) { |
| 516 | rc = -EIO; |
Tejun Heo | e6faf08 | 2006-06-17 15:49:55 +0900 | [diff] [blame] | 517 | goto err_out_free_ent; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | } |
| 519 | |
Jeff Garzik | 02cbd92 | 2006-03-22 23:59:46 -0500 | [diff] [blame] | 520 | base = (unsigned long)probe_ent->mmio_base; |
| 521 | |
| 522 | probe_ent->port[0].scr_addr = base + NV_PORT0_SCR_REG_OFFSET; |
| 523 | probe_ent->port[1].scr_addr = base + NV_PORT1_SCR_REG_OFFSET; |
| 524 | |
Tejun Heo | ada364e | 2006-06-17 15:49:56 +0900 | [diff] [blame] | 525 | /* enable SATA space for CK804 */ |
| 526 | if (ent->driver_data == CK804) { |
| 527 | u8 regval; |
| 528 | |
| 529 | pci_read_config_byte(pdev, NV_MCP_SATA_CFG_20, ®val); |
| 530 | regval |= NV_MCP_SATA_CFG_20_SATA_SPACE_EN; |
| 531 | pci_write_config_byte(pdev, NV_MCP_SATA_CFG_20, regval); |
| 532 | } |
| 533 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | pci_set_master(pdev); |
| 535 | |
| 536 | rc = ata_device_add(probe_ent); |
| 537 | if (rc != NV_PORTS) |
| 538 | goto err_out_iounmap; |
| 539 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | kfree(probe_ent); |
| 541 | |
| 542 | return 0; |
| 543 | |
| 544 | err_out_iounmap: |
Jeff Garzik | 02cbd92 | 2006-03-22 23:59:46 -0500 | [diff] [blame] | 545 | pci_iounmap(pdev, probe_ent->mmio_base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | err_out_free_ent: |
| 547 | kfree(probe_ent); |
| 548 | err_out_regions: |
| 549 | pci_release_regions(pdev); |
| 550 | err_out_disable: |
| 551 | if (!pci_dev_busy) |
| 552 | pci_disable_device(pdev); |
| 553 | err_out: |
| 554 | return rc; |
| 555 | } |
| 556 | |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 557 | static void nv_ck804_host_stop(struct ata_host *host) |
Tejun Heo | ada364e | 2006-06-17 15:49:56 +0900 | [diff] [blame] | 558 | { |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 559 | struct pci_dev *pdev = to_pci_dev(host->dev); |
Tejun Heo | ada364e | 2006-06-17 15:49:56 +0900 | [diff] [blame] | 560 | u8 regval; |
| 561 | |
| 562 | /* disable SATA space for CK804 */ |
| 563 | pci_read_config_byte(pdev, NV_MCP_SATA_CFG_20, ®val); |
| 564 | regval &= ~NV_MCP_SATA_CFG_20_SATA_SPACE_EN; |
| 565 | pci_write_config_byte(pdev, NV_MCP_SATA_CFG_20, regval); |
| 566 | |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 567 | ata_pci_host_stop(host); |
Tejun Heo | ada364e | 2006-06-17 15:49:56 +0900 | [diff] [blame] | 568 | } |
| 569 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | static int __init nv_init(void) |
| 571 | { |
Pavel Roskin | b788719 | 2006-08-10 18:13:18 +0900 | [diff] [blame] | 572 | return pci_register_driver(&nv_pci_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | } |
| 574 | |
| 575 | static void __exit nv_exit(void) |
| 576 | { |
| 577 | pci_unregister_driver(&nv_pci_driver); |
| 578 | } |
| 579 | |
| 580 | module_init(nv_init); |
| 581 | module_exit(nv_exit); |