[PATCH] sata_nv: kill not-working hotplug code
[deliverable/linux.git] / drivers / scsi / sata_nv.c
CommitLineData
1da177e4
LT
1/*
2 * sata_nv.c - NVIDIA nForce SATA
3 *
4 * Copyright 2004 NVIDIA Corp. All rights reserved.
5 * Copyright 2004 Andrew Chew
6 *
aa7e16d6
JG
7 *
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.
1da177e4 21 *
af36d7f0
JG
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 *
1da177e4
LT
32 */
33
34#include <linux/config.h>
35#include <linux/kernel.h>
36#include <linux/module.h>
37#include <linux/pci.h>
38#include <linux/init.h>
39#include <linux/blkdev.h>
40#include <linux/delay.h>
41#include <linux/interrupt.h>
a9524a76 42#include <linux/device.h>
1da177e4
LT
43#include <scsi/scsi_host.h>
44#include <linux/libata.h>
45
46#define DRV_NAME "sata_nv"
af64371a 47#define DRV_VERSION "0.9"
1da177e4 48
10ad05df
JG
49enum {
50 NV_PORTS = 2,
51 NV_PIO_MASK = 0x1f,
52 NV_MWDMA_MASK = 0x07,
53 NV_UDMA_MASK = 0x7f,
54 NV_PORT0_SCR_REG_OFFSET = 0x00,
55 NV_PORT1_SCR_REG_OFFSET = 0x40,
1da177e4 56
10ad05df
JG
57 NV_INT_STATUS = 0x10,
58 NV_INT_STATUS_CK804 = 0x440,
59 NV_INT_STATUS_PDEV_INT = 0x01,
60 NV_INT_STATUS_PDEV_PM = 0x02,
61 NV_INT_STATUS_PDEV_ADDED = 0x04,
62 NV_INT_STATUS_PDEV_REMOVED = 0x08,
63 NV_INT_STATUS_SDEV_INT = 0x10,
64 NV_INT_STATUS_SDEV_PM = 0x20,
65 NV_INT_STATUS_SDEV_ADDED = 0x40,
66 NV_INT_STATUS_SDEV_REMOVED = 0x80,
1da177e4 67
10ad05df
JG
68 NV_INT_ENABLE = 0x11,
69 NV_INT_ENABLE_CK804 = 0x441,
70 NV_INT_ENABLE_PDEV_MASK = 0x01,
71 NV_INT_ENABLE_PDEV_PM = 0x02,
72 NV_INT_ENABLE_PDEV_ADDED = 0x04,
73 NV_INT_ENABLE_PDEV_REMOVED = 0x08,
74 NV_INT_ENABLE_SDEV_MASK = 0x10,
75 NV_INT_ENABLE_SDEV_PM = 0x20,
76 NV_INT_ENABLE_SDEV_ADDED = 0x40,
77 NV_INT_ENABLE_SDEV_REMOVED = 0x80,
1da177e4 78
10ad05df
JG
79 NV_INT_CONFIG = 0x12,
80 NV_INT_CONFIG_METHD = 0x01, // 0 = INT, 1 = SMI
1da177e4 81
10ad05df
JG
82 // For PCI config register 20
83 NV_MCP_SATA_CFG_20 = 0x50,
84 NV_MCP_SATA_CFG_20_SATA_SPACE_EN = 0x04,
85};
1da177e4
LT
86
87static int nv_init_one (struct pci_dev *pdev, const struct pci_device_id *ent);
88static irqreturn_t nv_interrupt (int irq, void *dev_instance,
89 struct pt_regs *regs);
90static u32 nv_scr_read (struct ata_port *ap, unsigned int sc_reg);
91static void nv_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val);
92static void nv_host_stop (struct ata_host_set *host_set);
1da177e4
LT
93
94enum nv_host_type
95{
96 GENERIC,
97 NFORCE2,
98 NFORCE3,
e710245b 99 CK804
1da177e4
LT
100};
101
3b7d697d 102static const struct pci_device_id nv_pci_tbl[] = {
1da177e4
LT
103 { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE2S_SATA,
104 PCI_ANY_ID, PCI_ANY_ID, 0, 0, NFORCE2 },
105 { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE3S_SATA,
106 PCI_ANY_ID, PCI_ANY_ID, 0, 0, NFORCE3 },
107 { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE3S_SATA2,
108 PCI_ANY_ID, PCI_ANY_ID, 0, 0, NFORCE3 },
109 { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_CK804_SATA,
110 PCI_ANY_ID, PCI_ANY_ID, 0, 0, CK804 },
111 { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_CK804_SATA2,
112 PCI_ANY_ID, PCI_ANY_ID, 0, 0, CK804 },
113 { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP04_SATA,
114 PCI_ANY_ID, PCI_ANY_ID, 0, 0, CK804 },
115 { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP04_SATA2,
116 PCI_ANY_ID, PCI_ANY_ID, 0, 0, CK804 },
541134cf 117 { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP51_SATA,
e710245b 118 PCI_ANY_ID, PCI_ANY_ID, 0, 0, GENERIC },
541134cf 119 { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP51_SATA2,
e710245b 120 PCI_ANY_ID, PCI_ANY_ID, 0, 0, GENERIC },
541134cf 121 { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP55_SATA,
e710245b 122 PCI_ANY_ID, PCI_ANY_ID, 0, 0, GENERIC },
e86ee668 123 { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP55_SATA2,
e710245b 124 PCI_ANY_ID, PCI_ANY_ID, 0, 0, GENERIC },
4c5c8161
AC
125 { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP61_SATA,
126 PCI_ANY_ID, PCI_ANY_ID, 0, 0, GENERIC },
127 { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP61_SATA2,
128 PCI_ANY_ID, PCI_ANY_ID, 0, 0, GENERIC },
129 { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP61_SATA3,
130 PCI_ANY_ID, PCI_ANY_ID, 0, 0, GENERIC },
1da177e4
LT
131 { PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID,
132 PCI_ANY_ID, PCI_ANY_ID,
133 PCI_CLASS_STORAGE_IDE<<8, 0xffff00, GENERIC },
541134cf
DD
134 { PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID,
135 PCI_ANY_ID, PCI_ANY_ID,
136 PCI_CLASS_STORAGE_RAID<<8, 0xffff00, GENERIC },
1da177e4
LT
137 { 0, } /* terminate list */
138};
139
1da177e4
LT
140struct nv_host_desc
141{
142 enum nv_host_type host_type;
1da177e4
LT
143};
144static struct nv_host_desc nv_device_tbl[] = {
145 {
146 .host_type = GENERIC,
1da177e4
LT
147 },
148 {
149 .host_type = NFORCE2,
1da177e4
LT
150 },
151 {
152 .host_type = NFORCE3,
1da177e4
LT
153 },
154 { .host_type = CK804,
1da177e4
LT
155 },
156};
157
158struct nv_host
159{
160 struct nv_host_desc *host_desc;
161 unsigned long host_flags;
162};
163
164static struct pci_driver nv_pci_driver = {
165 .name = DRV_NAME,
166 .id_table = nv_pci_tbl,
167 .probe = nv_init_one,
168 .remove = ata_pci_remove_one,
169};
170
193515d5 171static struct scsi_host_template nv_sht = {
1da177e4
LT
172 .module = THIS_MODULE,
173 .name = DRV_NAME,
174 .ioctl = ata_scsi_ioctl,
175 .queuecommand = ata_scsi_queuecmd,
1da177e4
LT
176 .can_queue = ATA_DEF_QUEUE,
177 .this_id = ATA_SHT_THIS_ID,
178 .sg_tablesize = LIBATA_MAX_PRD,
1da177e4
LT
179 .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
180 .emulated = ATA_SHT_EMULATED,
181 .use_clustering = ATA_SHT_USE_CLUSTERING,
182 .proc_name = DRV_NAME,
183 .dma_boundary = ATA_DMA_BOUNDARY,
184 .slave_configure = ata_scsi_slave_config,
ccf68c34 185 .slave_destroy = ata_scsi_slave_destroy,
1da177e4 186 .bios_param = ata_std_bios_param,
1da177e4
LT
187};
188
057ace5e 189static const struct ata_port_operations nv_ops = {
1da177e4
LT
190 .port_disable = ata_port_disable,
191 .tf_load = ata_tf_load,
192 .tf_read = ata_tf_read,
193 .exec_command = ata_exec_command,
194 .check_status = ata_check_status,
195 .dev_select = ata_std_dev_select,
196 .phy_reset = sata_phy_reset,
197 .bmdma_setup = ata_bmdma_setup,
198 .bmdma_start = ata_bmdma_start,
199 .bmdma_stop = ata_bmdma_stop,
200 .bmdma_status = ata_bmdma_status,
201 .qc_prep = ata_qc_prep,
202 .qc_issue = ata_qc_issue_prot,
203 .eng_timeout = ata_eng_timeout,
a6b2c5d4 204 .data_xfer = ata_pio_data_xfer,
1da177e4
LT
205 .irq_handler = nv_interrupt,
206 .irq_clear = ata_bmdma_irq_clear,
207 .scr_read = nv_scr_read,
208 .scr_write = nv_scr_write,
209 .port_start = ata_port_start,
210 .port_stop = ata_port_stop,
211 .host_stop = nv_host_stop,
212};
213
214/* FIXME: The hardware provides the necessary SATA PHY controls
215 * to support ATA_FLAG_SATA_RESET. However, it is currently
216 * necessary to disable that flag, to solve misdetection problems.
217 * See http://bugme.osdl.org/show_bug.cgi?id=3352 for more info.
218 *
219 * This problem really needs to be investigated further. But in the
220 * meantime, we avoid ATA_FLAG_SATA_RESET to get people working.
221 */
222static struct ata_port_info nv_port_info = {
223 .sht = &nv_sht,
224 .host_flags = ATA_FLAG_SATA |
225 /* ATA_FLAG_SATA_RESET | */
226 ATA_FLAG_SRST |
227 ATA_FLAG_NO_LEGACY,
228 .pio_mask = NV_PIO_MASK,
229 .mwdma_mask = NV_MWDMA_MASK,
230 .udma_mask = NV_UDMA_MASK,
231 .port_ops = &nv_ops,
232};
233
234MODULE_AUTHOR("NVIDIA");
235MODULE_DESCRIPTION("low-level driver for NVIDIA nForce SATA controller");
236MODULE_LICENSE("GPL");
237MODULE_DEVICE_TABLE(pci, nv_pci_tbl);
238MODULE_VERSION(DRV_VERSION);
239
240static irqreturn_t nv_interrupt (int irq, void *dev_instance,
241 struct pt_regs *regs)
242{
243 struct ata_host_set *host_set = dev_instance;
1da177e4
LT
244 unsigned int i;
245 unsigned int handled = 0;
246 unsigned long flags;
247
248 spin_lock_irqsave(&host_set->lock, flags);
249
250 for (i = 0; i < host_set->n_ports; i++) {
251 struct ata_port *ap;
252
253 ap = host_set->ports[i];
c1389503 254 if (ap &&
029f5468 255 !(ap->flags & ATA_FLAG_DISABLED)) {
1da177e4
LT
256 struct ata_queued_cmd *qc;
257
258 qc = ata_qc_from_tag(ap, ap->active_tag);
e50362ec 259 if (qc && (!(qc->tf.flags & ATA_TFLAG_POLLING)))
1da177e4 260 handled += ata_host_intr(ap, qc);
b887030a
AC
261 else
262 // No request pending? Clear interrupt status
263 // anyway, in case there's one pending.
264 ap->ops->check_status(ap);
1da177e4
LT
265 }
266
267 }
268
1da177e4
LT
269 spin_unlock_irqrestore(&host_set->lock, flags);
270
271 return IRQ_RETVAL(handled);
272}
273
274static u32 nv_scr_read (struct ata_port *ap, unsigned int sc_reg)
275{
1da177e4
LT
276 if (sc_reg > SCR_CONTROL)
277 return 0xffffffffU;
278
02cbd926 279 return ioread32((void __iomem *)ap->ioaddr.scr_addr + (sc_reg * 4));
1da177e4
LT
280}
281
282static void nv_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val)
283{
1da177e4
LT
284 if (sc_reg > SCR_CONTROL)
285 return;
286
02cbd926 287 iowrite32(val, (void __iomem *)ap->ioaddr.scr_addr + (sc_reg * 4));
1da177e4
LT
288}
289
290static void nv_host_stop (struct ata_host_set *host_set)
291{
292 struct nv_host *host = host_set->private_data;
293
1da177e4 294 kfree(host);
aa8f0dc6 295
02cbd926 296 ata_pci_host_stop(host_set);
1da177e4
LT
297}
298
299static int nv_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
300{
301 static int printed_version = 0;
302 struct nv_host *host;
303 struct ata_port_info *ppi;
304 struct ata_probe_ent *probe_ent;
305 int pci_dev_busy = 0;
306 int rc;
307 u32 bar;
02cbd926 308 unsigned long base;
1da177e4
LT
309
310 // Make sure this is a SATA controller by counting the number of bars
311 // (NVIDIA SATA controllers will always have six bars). Otherwise,
312 // it's an IDE controller and we ignore it.
313 for (bar=0; bar<6; bar++)
314 if (pci_resource_start(pdev, bar) == 0)
315 return -ENODEV;
316
317 if (!printed_version++)
a9524a76 318 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
1da177e4
LT
319
320 rc = pci_enable_device(pdev);
321 if (rc)
322 goto err_out;
323
324 rc = pci_request_regions(pdev, DRV_NAME);
325 if (rc) {
326 pci_dev_busy = 1;
327 goto err_out_disable;
328 }
329
330 rc = pci_set_dma_mask(pdev, ATA_DMA_MASK);
331 if (rc)
332 goto err_out_regions;
333 rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK);
334 if (rc)
335 goto err_out_regions;
336
337 rc = -ENOMEM;
338
339 ppi = &nv_port_info;
47a86593 340 probe_ent = ata_pci_init_native_mode(pdev, &ppi, ATA_PORT_PRIMARY | ATA_PORT_SECONDARY);
1da177e4
LT
341 if (!probe_ent)
342 goto err_out_regions;
343
344 host = kmalloc(sizeof(struct nv_host), GFP_KERNEL);
345 if (!host)
346 goto err_out_free_ent;
347
348 memset(host, 0, sizeof(struct nv_host));
349 host->host_desc = &nv_device_tbl[ent->driver_data];
350
351 probe_ent->private_data = host;
352
02cbd926
JG
353 probe_ent->mmio_base = pci_iomap(pdev, 5, 0);
354 if (!probe_ent->mmio_base) {
355 rc = -EIO;
356 goto err_out_free_host;
357 }
1da177e4 358
02cbd926 359 base = (unsigned long)probe_ent->mmio_base;
1da177e4 360
02cbd926
JG
361 probe_ent->port[0].scr_addr = base + NV_PORT0_SCR_REG_OFFSET;
362 probe_ent->port[1].scr_addr = base + NV_PORT1_SCR_REG_OFFSET;
1da177e4
LT
363
364 pci_set_master(pdev);
365
366 rc = ata_device_add(probe_ent);
367 if (rc != NV_PORTS)
368 goto err_out_iounmap;
369
1da177e4
LT
370 kfree(probe_ent);
371
372 return 0;
373
374err_out_iounmap:
02cbd926 375 pci_iounmap(pdev, probe_ent->mmio_base);
1da177e4
LT
376err_out_free_host:
377 kfree(host);
378err_out_free_ent:
379 kfree(probe_ent);
380err_out_regions:
381 pci_release_regions(pdev);
382err_out_disable:
383 if (!pci_dev_busy)
384 pci_disable_device(pdev);
385err_out:
386 return rc;
387}
388
1da177e4
LT
389static int __init nv_init(void)
390{
391 return pci_module_init(&nv_pci_driver);
392}
393
394static void __exit nv_exit(void)
395{
396 pci_unregister_driver(&nv_pci_driver);
397}
398
399module_init(nv_init);
400module_exit(nv_exit);
This page took 0.149512 seconds and 5 git commands to generate.