blob: 043ff4fd9ba7e12bcb8e2b3d9958e3dfbcd9f55c [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * sata_nv.c - NVIDIA nForce SATA
3 *
4 * Copyright 2004 NVIDIA Corp. All rights reserved.
5 * Copyright 2004 Andrew Chew
6 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 *
Jeff Garzikaa7e16d2005-08-29 15:12:56 -04008 * 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 Torvalds1da177e2005-04-16 15:20:36 -070021 *
Jeff Garzikaf36d7f2005-08-28 20:18:39 -040022 *
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 Torvalds1da177e2005-04-16 15:20:36 -070032 */
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>
Jeff Garzika9524a72005-10-30 14:39:11 -050042#include <linux/device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070043#include <scsi/scsi_host.h>
44#include <linux/libata.h>
45
46#define DRV_NAME "sata_nv"
Jeff Garzikaf643712006-04-02 20:41:36 -040047#define DRV_VERSION "0.9"
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
Jeff Garzik10ad05d2006-03-22 23:50:50 -050049enum {
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,
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
Jeff Garzik10ad05d2006-03-22 23:50:50 -050057 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,
67 NV_INT_STATUS_PDEV_HOTPLUG = (NV_INT_STATUS_PDEV_ADDED |
68 NV_INT_STATUS_PDEV_REMOVED),
69 NV_INT_STATUS_SDEV_HOTPLUG = (NV_INT_STATUS_SDEV_ADDED |
70 NV_INT_STATUS_SDEV_REMOVED),
71 NV_INT_STATUS_HOTPLUG = (NV_INT_STATUS_PDEV_HOTPLUG |
72 NV_INT_STATUS_SDEV_HOTPLUG),
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
Jeff Garzik10ad05d2006-03-22 23:50:50 -050074 NV_INT_ENABLE = 0x11,
75 NV_INT_ENABLE_CK804 = 0x441,
76 NV_INT_ENABLE_PDEV_MASK = 0x01,
77 NV_INT_ENABLE_PDEV_PM = 0x02,
78 NV_INT_ENABLE_PDEV_ADDED = 0x04,
79 NV_INT_ENABLE_PDEV_REMOVED = 0x08,
80 NV_INT_ENABLE_SDEV_MASK = 0x10,
81 NV_INT_ENABLE_SDEV_PM = 0x20,
82 NV_INT_ENABLE_SDEV_ADDED = 0x40,
83 NV_INT_ENABLE_SDEV_REMOVED = 0x80,
84 NV_INT_ENABLE_PDEV_HOTPLUG = (NV_INT_ENABLE_PDEV_ADDED |
85 NV_INT_ENABLE_PDEV_REMOVED),
86 NV_INT_ENABLE_SDEV_HOTPLUG = (NV_INT_ENABLE_SDEV_ADDED |
87 NV_INT_ENABLE_SDEV_REMOVED),
88 NV_INT_ENABLE_HOTPLUG = (NV_INT_ENABLE_PDEV_HOTPLUG |
89 NV_INT_ENABLE_SDEV_HOTPLUG),
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
Jeff Garzik10ad05d2006-03-22 23:50:50 -050091 NV_INT_CONFIG = 0x12,
92 NV_INT_CONFIG_METHD = 0x01, // 0 = INT, 1 = SMI
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
Jeff Garzik10ad05d2006-03-22 23:50:50 -050094 // For PCI config register 20
95 NV_MCP_SATA_CFG_20 = 0x50,
96 NV_MCP_SATA_CFG_20_SATA_SPACE_EN = 0x04,
97};
Linus Torvalds1da177e2005-04-16 15:20:36 -070098
99static int nv_init_one (struct pci_dev *pdev, const struct pci_device_id *ent);
100static irqreturn_t nv_interrupt (int irq, void *dev_instance,
101 struct pt_regs *regs);
102static u32 nv_scr_read (struct ata_port *ap, unsigned int sc_reg);
103static void nv_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val);
104static void nv_host_stop (struct ata_host_set *host_set);
105static void nv_enable_hotplug(struct ata_probe_ent *probe_ent);
106static void nv_disable_hotplug(struct ata_host_set *host_set);
Andrew Chewb8870302006-01-04 19:13:04 -0800107static int nv_check_hotplug(struct ata_host_set *host_set);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108static void nv_enable_hotplug_ck804(struct ata_probe_ent *probe_ent);
109static void nv_disable_hotplug_ck804(struct ata_host_set *host_set);
Andrew Chewb8870302006-01-04 19:13:04 -0800110static int nv_check_hotplug_ck804(struct ata_host_set *host_set);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111
112enum nv_host_type
113{
114 GENERIC,
115 NFORCE2,
116 NFORCE3,
Andy Curride7102452005-10-07 08:53:39 -0700117 CK804
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118};
119
Jeff Garzik3b7d6972005-11-10 11:04:11 -0500120static const struct pci_device_id nv_pci_tbl[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE2S_SATA,
122 PCI_ANY_ID, PCI_ANY_ID, 0, 0, NFORCE2 },
123 { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE3S_SATA,
124 PCI_ANY_ID, PCI_ANY_ID, 0, 0, NFORCE3 },
125 { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE3S_SATA2,
126 PCI_ANY_ID, PCI_ANY_ID, 0, 0, NFORCE3 },
127 { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_CK804_SATA,
128 PCI_ANY_ID, PCI_ANY_ID, 0, 0, CK804 },
129 { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_CK804_SATA2,
130 PCI_ANY_ID, PCI_ANY_ID, 0, 0, CK804 },
131 { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP04_SATA,
132 PCI_ANY_ID, PCI_ANY_ID, 0, 0, CK804 },
133 { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP04_SATA2,
134 PCI_ANY_ID, PCI_ANY_ID, 0, 0, CK804 },
Daniel Drake541134c2005-07-03 13:44:39 +0100135 { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP51_SATA,
Andy Curride7102452005-10-07 08:53:39 -0700136 PCI_ANY_ID, PCI_ANY_ID, 0, 0, GENERIC },
Daniel Drake541134c2005-07-03 13:44:39 +0100137 { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP51_SATA2,
Andy Curride7102452005-10-07 08:53:39 -0700138 PCI_ANY_ID, PCI_ANY_ID, 0, 0, GENERIC },
Daniel Drake541134c2005-07-03 13:44:39 +0100139 { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP55_SATA,
Andy Curride7102452005-10-07 08:53:39 -0700140 PCI_ANY_ID, PCI_ANY_ID, 0, 0, GENERIC },
Andy Curride86ee662005-09-19 06:17:52 -0700141 { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP55_SATA2,
Andy Curride7102452005-10-07 08:53:39 -0700142 PCI_ANY_ID, PCI_ANY_ID, 0, 0, GENERIC },
Andrew Chew4c5c8162006-04-20 15:54:26 -0700143 { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP61_SATA,
144 PCI_ANY_ID, PCI_ANY_ID, 0, 0, GENERIC },
145 { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP61_SATA2,
146 PCI_ANY_ID, PCI_ANY_ID, 0, 0, GENERIC },
147 { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP61_SATA3,
148 PCI_ANY_ID, PCI_ANY_ID, 0, 0, GENERIC },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 { PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID,
150 PCI_ANY_ID, PCI_ANY_ID,
151 PCI_CLASS_STORAGE_IDE<<8, 0xffff00, GENERIC },
Daniel Drake541134c2005-07-03 13:44:39 +0100152 { PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID,
153 PCI_ANY_ID, PCI_ANY_ID,
154 PCI_CLASS_STORAGE_RAID<<8, 0xffff00, GENERIC },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 { 0, } /* terminate list */
156};
157
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158struct nv_host_desc
159{
160 enum nv_host_type host_type;
161 void (*enable_hotplug)(struct ata_probe_ent *probe_ent);
162 void (*disable_hotplug)(struct ata_host_set *host_set);
Andrew Chewb8870302006-01-04 19:13:04 -0800163 int (*check_hotplug)(struct ata_host_set *host_set);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164
165};
166static struct nv_host_desc nv_device_tbl[] = {
167 {
168 .host_type = GENERIC,
169 .enable_hotplug = NULL,
170 .disable_hotplug= NULL,
171 .check_hotplug = NULL,
172 },
173 {
174 .host_type = NFORCE2,
175 .enable_hotplug = nv_enable_hotplug,
176 .disable_hotplug= nv_disable_hotplug,
177 .check_hotplug = nv_check_hotplug,
178 },
179 {
180 .host_type = NFORCE3,
181 .enable_hotplug = nv_enable_hotplug,
182 .disable_hotplug= nv_disable_hotplug,
183 .check_hotplug = nv_check_hotplug,
184 },
185 { .host_type = CK804,
186 .enable_hotplug = nv_enable_hotplug_ck804,
187 .disable_hotplug= nv_disable_hotplug_ck804,
188 .check_hotplug = nv_check_hotplug_ck804,
189 },
190};
191
192struct nv_host
193{
194 struct nv_host_desc *host_desc;
195 unsigned long host_flags;
196};
197
198static struct pci_driver nv_pci_driver = {
199 .name = DRV_NAME,
200 .id_table = nv_pci_tbl,
201 .probe = nv_init_one,
202 .remove = ata_pci_remove_one,
203};
204
Jeff Garzik193515d2005-11-07 00:59:37 -0500205static struct scsi_host_template nv_sht = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 .module = THIS_MODULE,
207 .name = DRV_NAME,
208 .ioctl = ata_scsi_ioctl,
209 .queuecommand = ata_scsi_queuecmd,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 .can_queue = ATA_DEF_QUEUE,
211 .this_id = ATA_SHT_THIS_ID,
212 .sg_tablesize = LIBATA_MAX_PRD,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
214 .emulated = ATA_SHT_EMULATED,
215 .use_clustering = ATA_SHT_USE_CLUSTERING,
216 .proc_name = DRV_NAME,
217 .dma_boundary = ATA_DMA_BOUNDARY,
218 .slave_configure = ata_scsi_slave_config,
219 .bios_param = ata_std_bios_param,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220};
221
Jeff Garzik057ace52005-10-22 14:27:05 -0400222static const struct ata_port_operations nv_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 .port_disable = ata_port_disable,
224 .tf_load = ata_tf_load,
225 .tf_read = ata_tf_read,
226 .exec_command = ata_exec_command,
227 .check_status = ata_check_status,
228 .dev_select = ata_std_dev_select,
229 .phy_reset = sata_phy_reset,
230 .bmdma_setup = ata_bmdma_setup,
231 .bmdma_start = ata_bmdma_start,
232 .bmdma_stop = ata_bmdma_stop,
233 .bmdma_status = ata_bmdma_status,
234 .qc_prep = ata_qc_prep,
235 .qc_issue = ata_qc_issue_prot,
236 .eng_timeout = ata_eng_timeout,
237 .irq_handler = nv_interrupt,
238 .irq_clear = ata_bmdma_irq_clear,
239 .scr_read = nv_scr_read,
240 .scr_write = nv_scr_write,
241 .port_start = ata_port_start,
242 .port_stop = ata_port_stop,
243 .host_stop = nv_host_stop,
244};
245
246/* FIXME: The hardware provides the necessary SATA PHY controls
247 * to support ATA_FLAG_SATA_RESET. However, it is currently
248 * necessary to disable that flag, to solve misdetection problems.
249 * See http://bugme.osdl.org/show_bug.cgi?id=3352 for more info.
250 *
251 * This problem really needs to be investigated further. But in the
252 * meantime, we avoid ATA_FLAG_SATA_RESET to get people working.
253 */
254static struct ata_port_info nv_port_info = {
255 .sht = &nv_sht,
256 .host_flags = ATA_FLAG_SATA |
257 /* ATA_FLAG_SATA_RESET | */
258 ATA_FLAG_SRST |
259 ATA_FLAG_NO_LEGACY,
260 .pio_mask = NV_PIO_MASK,
261 .mwdma_mask = NV_MWDMA_MASK,
262 .udma_mask = NV_UDMA_MASK,
263 .port_ops = &nv_ops,
264};
265
266MODULE_AUTHOR("NVIDIA");
267MODULE_DESCRIPTION("low-level driver for NVIDIA nForce SATA controller");
268MODULE_LICENSE("GPL");
269MODULE_DEVICE_TABLE(pci, nv_pci_tbl);
270MODULE_VERSION(DRV_VERSION);
271
272static irqreturn_t nv_interrupt (int irq, void *dev_instance,
273 struct pt_regs *regs)
274{
275 struct ata_host_set *host_set = dev_instance;
276 struct nv_host *host = host_set->private_data;
277 unsigned int i;
278 unsigned int handled = 0;
279 unsigned long flags;
280
281 spin_lock_irqsave(&host_set->lock, flags);
282
283 for (i = 0; i < host_set->n_ports; i++) {
284 struct ata_port *ap;
285
286 ap = host_set->ports[i];
Tejun Heoc1389502005-08-22 14:59:24 +0900287 if (ap &&
Jeff Garzik029f5462006-04-02 10:30:40 -0400288 !(ap->flags & ATA_FLAG_DISABLED)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 struct ata_queued_cmd *qc;
290
291 qc = ata_qc_from_tag(ap, ap->active_tag);
Albert Leee50362e2005-09-27 17:39:50 +0800292 if (qc && (!(qc->tf.flags & ATA_TFLAG_POLLING)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 handled += ata_host_intr(ap, qc);
Andrew Chewb8870302006-01-04 19:13:04 -0800294 else
295 // No request pending? Clear interrupt status
296 // anyway, in case there's one pending.
297 ap->ops->check_status(ap);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 }
299
300 }
301
302 if (host->host_desc->check_hotplug)
Andrew Chewb8870302006-01-04 19:13:04 -0800303 handled += host->host_desc->check_hotplug(host_set);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304
305 spin_unlock_irqrestore(&host_set->lock, flags);
306
307 return IRQ_RETVAL(handled);
308}
309
310static u32 nv_scr_read (struct ata_port *ap, unsigned int sc_reg)
311{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 if (sc_reg > SCR_CONTROL)
313 return 0xffffffffU;
314
Jeff Garzik02cbd922006-03-22 23:59:46 -0500315 return ioread32((void __iomem *)ap->ioaddr.scr_addr + (sc_reg * 4));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316}
317
318static void nv_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val)
319{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 if (sc_reg > SCR_CONTROL)
321 return;
322
Jeff Garzik02cbd922006-03-22 23:59:46 -0500323 iowrite32(val, (void __iomem *)ap->ioaddr.scr_addr + (sc_reg * 4));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324}
325
326static void nv_host_stop (struct ata_host_set *host_set)
327{
328 struct nv_host *host = host_set->private_data;
329
330 // Disable hotplug event interrupts.
331 if (host->host_desc->disable_hotplug)
332 host->host_desc->disable_hotplug(host_set);
333
334 kfree(host);
Jeff Garzikaa8f0dc2005-05-26 21:54:27 -0400335
Jeff Garzik02cbd922006-03-22 23:59:46 -0500336 ata_pci_host_stop(host_set);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337}
338
339static int nv_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
340{
341 static int printed_version = 0;
342 struct nv_host *host;
343 struct ata_port_info *ppi;
344 struct ata_probe_ent *probe_ent;
345 int pci_dev_busy = 0;
346 int rc;
347 u32 bar;
Jeff Garzik02cbd922006-03-22 23:59:46 -0500348 unsigned long base;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349
350 // Make sure this is a SATA controller by counting the number of bars
351 // (NVIDIA SATA controllers will always have six bars). Otherwise,
352 // it's an IDE controller and we ignore it.
353 for (bar=0; bar<6; bar++)
354 if (pci_resource_start(pdev, bar) == 0)
355 return -ENODEV;
356
357 if (!printed_version++)
Jeff Garzika9524a72005-10-30 14:39:11 -0500358 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359
360 rc = pci_enable_device(pdev);
361 if (rc)
362 goto err_out;
363
364 rc = pci_request_regions(pdev, DRV_NAME);
365 if (rc) {
366 pci_dev_busy = 1;
367 goto err_out_disable;
368 }
369
370 rc = pci_set_dma_mask(pdev, ATA_DMA_MASK);
371 if (rc)
372 goto err_out_regions;
373 rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK);
374 if (rc)
375 goto err_out_regions;
376
377 rc = -ENOMEM;
378
379 ppi = &nv_port_info;
Alan Cox47a86592005-10-04 08:09:19 -0400380 probe_ent = ata_pci_init_native_mode(pdev, &ppi, ATA_PORT_PRIMARY | ATA_PORT_SECONDARY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 if (!probe_ent)
382 goto err_out_regions;
383
384 host = kmalloc(sizeof(struct nv_host), GFP_KERNEL);
385 if (!host)
386 goto err_out_free_ent;
387
388 memset(host, 0, sizeof(struct nv_host));
389 host->host_desc = &nv_device_tbl[ent->driver_data];
390
391 probe_ent->private_data = host;
392
Jeff Garzik02cbd922006-03-22 23:59:46 -0500393 probe_ent->mmio_base = pci_iomap(pdev, 5, 0);
394 if (!probe_ent->mmio_base) {
395 rc = -EIO;
396 goto err_out_free_host;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 }
398
Jeff Garzik02cbd922006-03-22 23:59:46 -0500399 base = (unsigned long)probe_ent->mmio_base;
400
401 probe_ent->port[0].scr_addr = base + NV_PORT0_SCR_REG_OFFSET;
402 probe_ent->port[1].scr_addr = base + NV_PORT1_SCR_REG_OFFSET;
403
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 pci_set_master(pdev);
405
406 rc = ata_device_add(probe_ent);
407 if (rc != NV_PORTS)
408 goto err_out_iounmap;
409
410 // Enable hotplug event interrupts.
411 if (host->host_desc->enable_hotplug)
412 host->host_desc->enable_hotplug(probe_ent);
413
414 kfree(probe_ent);
415
416 return 0;
417
418err_out_iounmap:
Jeff Garzik02cbd922006-03-22 23:59:46 -0500419 pci_iounmap(pdev, probe_ent->mmio_base);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420err_out_free_host:
421 kfree(host);
422err_out_free_ent:
423 kfree(probe_ent);
424err_out_regions:
425 pci_release_regions(pdev);
426err_out_disable:
427 if (!pci_dev_busy)
428 pci_disable_device(pdev);
429err_out:
430 return rc;
431}
432
433static void nv_enable_hotplug(struct ata_probe_ent *probe_ent)
434{
435 u8 intr_mask;
436
437 outb(NV_INT_STATUS_HOTPLUG,
438 probe_ent->port[0].scr_addr + NV_INT_STATUS);
439
440 intr_mask = inb(probe_ent->port[0].scr_addr + NV_INT_ENABLE);
441 intr_mask |= NV_INT_ENABLE_HOTPLUG;
442
443 outb(intr_mask, probe_ent->port[0].scr_addr + NV_INT_ENABLE);
444}
445
446static void nv_disable_hotplug(struct ata_host_set *host_set)
447{
448 u8 intr_mask;
449
450 intr_mask = inb(host_set->ports[0]->ioaddr.scr_addr + NV_INT_ENABLE);
451
452 intr_mask &= ~(NV_INT_ENABLE_HOTPLUG);
453
454 outb(intr_mask, host_set->ports[0]->ioaddr.scr_addr + NV_INT_ENABLE);
455}
456
Andrew Chewb8870302006-01-04 19:13:04 -0800457static int nv_check_hotplug(struct ata_host_set *host_set)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458{
459 u8 intr_status;
460
461 intr_status = inb(host_set->ports[0]->ioaddr.scr_addr + NV_INT_STATUS);
462
463 // Clear interrupt status.
464 outb(0xff, host_set->ports[0]->ioaddr.scr_addr + NV_INT_STATUS);
465
466 if (intr_status & NV_INT_STATUS_HOTPLUG) {
467 if (intr_status & NV_INT_STATUS_PDEV_ADDED)
468 printk(KERN_WARNING "nv_sata: "
469 "Primary device added\n");
470
471 if (intr_status & NV_INT_STATUS_PDEV_REMOVED)
472 printk(KERN_WARNING "nv_sata: "
473 "Primary device removed\n");
474
475 if (intr_status & NV_INT_STATUS_SDEV_ADDED)
476 printk(KERN_WARNING "nv_sata: "
477 "Secondary device added\n");
478
479 if (intr_status & NV_INT_STATUS_SDEV_REMOVED)
480 printk(KERN_WARNING "nv_sata: "
481 "Secondary device removed\n");
Andrew Chewb8870302006-01-04 19:13:04 -0800482
483 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 }
Andrew Chewb8870302006-01-04 19:13:04 -0800485
486 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487}
488
489static void nv_enable_hotplug_ck804(struct ata_probe_ent *probe_ent)
490{
491 struct pci_dev *pdev = to_pci_dev(probe_ent->dev);
492 u8 intr_mask;
493 u8 regval;
494
495 pci_read_config_byte(pdev, NV_MCP_SATA_CFG_20, &regval);
496 regval |= NV_MCP_SATA_CFG_20_SATA_SPACE_EN;
497 pci_write_config_byte(pdev, NV_MCP_SATA_CFG_20, regval);
498
499 writeb(NV_INT_STATUS_HOTPLUG, probe_ent->mmio_base + NV_INT_STATUS_CK804);
500
501 intr_mask = readb(probe_ent->mmio_base + NV_INT_ENABLE_CK804);
502 intr_mask |= NV_INT_ENABLE_HOTPLUG;
503
504 writeb(intr_mask, probe_ent->mmio_base + NV_INT_ENABLE_CK804);
505}
506
507static void nv_disable_hotplug_ck804(struct ata_host_set *host_set)
508{
509 struct pci_dev *pdev = to_pci_dev(host_set->dev);
510 u8 intr_mask;
511 u8 regval;
512
513 intr_mask = readb(host_set->mmio_base + NV_INT_ENABLE_CK804);
514
515 intr_mask &= ~(NV_INT_ENABLE_HOTPLUG);
516
517 writeb(intr_mask, host_set->mmio_base + NV_INT_ENABLE_CK804);
518
519 pci_read_config_byte(pdev, NV_MCP_SATA_CFG_20, &regval);
520 regval &= ~NV_MCP_SATA_CFG_20_SATA_SPACE_EN;
521 pci_write_config_byte(pdev, NV_MCP_SATA_CFG_20, regval);
522}
523
Andrew Chewb8870302006-01-04 19:13:04 -0800524static int nv_check_hotplug_ck804(struct ata_host_set *host_set)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525{
526 u8 intr_status;
527
528 intr_status = readb(host_set->mmio_base + NV_INT_STATUS_CK804);
529
530 // Clear interrupt status.
531 writeb(0xff, host_set->mmio_base + NV_INT_STATUS_CK804);
532
533 if (intr_status & NV_INT_STATUS_HOTPLUG) {
534 if (intr_status & NV_INT_STATUS_PDEV_ADDED)
535 printk(KERN_WARNING "nv_sata: "
536 "Primary device added\n");
537
538 if (intr_status & NV_INT_STATUS_PDEV_REMOVED)
539 printk(KERN_WARNING "nv_sata: "
540 "Primary device removed\n");
541
542 if (intr_status & NV_INT_STATUS_SDEV_ADDED)
543 printk(KERN_WARNING "nv_sata: "
544 "Secondary device added\n");
545
546 if (intr_status & NV_INT_STATUS_SDEV_REMOVED)
547 printk(KERN_WARNING "nv_sata: "
548 "Secondary device removed\n");
Andrew Chewb8870302006-01-04 19:13:04 -0800549
550 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 }
Andrew Chewb8870302006-01-04 19:13:04 -0800552
553 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554}
555
556static int __init nv_init(void)
557{
558 return pci_module_init(&nv_pci_driver);
559}
560
561static void __exit nv_exit(void)
562{
563 pci_unregister_driver(&nv_pci_driver);
564}
565
566module_init(nv_init);
567module_exit(nv_exit);