xref: /freebsd/sys/dev/ata/chipsets/ata-netcell.c (revision 13014ca04aad1931d41958b56f71a2c65b9a7a2c)
113014ca0SSøren Schmidt /*-
213014ca0SSøren Schmidt  * Copyright (c) 1998 - 2008 S�ren Schmidt <sos@FreeBSD.org>
313014ca0SSøren Schmidt  * All rights reserved.
413014ca0SSøren Schmidt  *
513014ca0SSøren Schmidt  * Redistribution and use in source and binary forms, with or without
613014ca0SSøren Schmidt  * modification, are permitted provided that the following conditions
713014ca0SSøren Schmidt  * are met:
813014ca0SSøren Schmidt  * 1. Redistributions of source code must retain the above copyright
913014ca0SSøren Schmidt  *    notice, this list of conditions and the following disclaimer,
1013014ca0SSøren Schmidt  *    without modification, immediately at the beginning of the file.
1113014ca0SSøren Schmidt  * 2. Redistributions in binary form must reproduce the above copyright
1213014ca0SSøren Schmidt  *    notice, this list of conditions and the following disclaimer in the
1313014ca0SSøren Schmidt  *    documentation and/or other materials provided with the distribution.
1413014ca0SSøren Schmidt  *
1513014ca0SSøren Schmidt  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1613014ca0SSøren Schmidt  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1713014ca0SSøren Schmidt  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1813014ca0SSøren Schmidt  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
1913014ca0SSøren Schmidt  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2013014ca0SSøren Schmidt  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2113014ca0SSøren Schmidt  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2213014ca0SSøren Schmidt  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2313014ca0SSøren Schmidt  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2413014ca0SSøren Schmidt  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2513014ca0SSøren Schmidt  */
2613014ca0SSøren Schmidt 
2713014ca0SSøren Schmidt #include <sys/cdefs.h>
2813014ca0SSøren Schmidt __FBSDID("$FreeBSD$");
2913014ca0SSøren Schmidt 
3013014ca0SSøren Schmidt #include "opt_ata.h"
3113014ca0SSøren Schmidt #include <sys/param.h>
3213014ca0SSøren Schmidt #include <sys/module.h>
3313014ca0SSøren Schmidt #include <sys/systm.h>
3413014ca0SSøren Schmidt #include <sys/kernel.h>
3513014ca0SSøren Schmidt #include <sys/ata.h>
3613014ca0SSøren Schmidt #include <sys/bus.h>
3713014ca0SSøren Schmidt #include <sys/endian.h>
3813014ca0SSøren Schmidt #include <sys/malloc.h>
3913014ca0SSøren Schmidt #include <sys/lock.h>
4013014ca0SSøren Schmidt #include <sys/mutex.h>
4113014ca0SSøren Schmidt #include <sys/sema.h>
4213014ca0SSøren Schmidt #include <sys/taskqueue.h>
4313014ca0SSøren Schmidt #include <vm/uma.h>
4413014ca0SSøren Schmidt #include <machine/stdarg.h>
4513014ca0SSøren Schmidt #include <machine/resource.h>
4613014ca0SSøren Schmidt #include <machine/bus.h>
4713014ca0SSøren Schmidt #include <sys/rman.h>
4813014ca0SSøren Schmidt #include <dev/pci/pcivar.h>
4913014ca0SSøren Schmidt #include <dev/pci/pcireg.h>
5013014ca0SSøren Schmidt #include <dev/ata/ata-all.h>
5113014ca0SSøren Schmidt #include <dev/ata/ata-pci.h>
5213014ca0SSøren Schmidt #include <ata_if.h>
5313014ca0SSøren Schmidt 
5413014ca0SSøren Schmidt /* local prototypes */
5513014ca0SSøren Schmidt static int ata_netcell_chipinit(device_t dev);
5613014ca0SSøren Schmidt static int ata_netcell_allocate(device_t dev);
5713014ca0SSøren Schmidt static void ata_netcell_setmode(device_t dev, int mode);
5813014ca0SSøren Schmidt 
5913014ca0SSøren Schmidt 
6013014ca0SSøren Schmidt /*
6113014ca0SSøren Schmidt  * NetCell chipset support functions
6213014ca0SSøren Schmidt  */
6313014ca0SSøren Schmidt static int
6413014ca0SSøren Schmidt ata_netcell_probe(device_t dev)
6513014ca0SSøren Schmidt {
6613014ca0SSøren Schmidt     struct ata_pci_controller *ctlr = device_get_softc(dev);
6713014ca0SSøren Schmidt 
6813014ca0SSøren Schmidt     if (pci_get_devid(dev) == ATA_NETCELL_SR) {
6913014ca0SSøren Schmidt 	device_set_desc(dev, "Netcell SyncRAID SR3000/5000 RAID Controller");
7013014ca0SSøren Schmidt 	ctlr->chipinit = ata_netcell_chipinit;
7113014ca0SSøren Schmidt 	return 0;
7213014ca0SSøren Schmidt     }
7313014ca0SSøren Schmidt     return ENXIO;
7413014ca0SSøren Schmidt }
7513014ca0SSøren Schmidt 
7613014ca0SSøren Schmidt static int
7713014ca0SSøren Schmidt ata_netcell_chipinit(device_t dev)
7813014ca0SSøren Schmidt {
7913014ca0SSøren Schmidt     struct ata_pci_controller *ctlr = device_get_softc(dev);
8013014ca0SSøren Schmidt 
8113014ca0SSøren Schmidt     if (ata_setup_interrupt(dev, ata_generic_intr))
8213014ca0SSøren Schmidt         return ENXIO;
8313014ca0SSøren Schmidt 
8413014ca0SSøren Schmidt     ctlr->allocate = ata_netcell_allocate;
8513014ca0SSøren Schmidt     ctlr->setmode = ata_netcell_setmode;
8613014ca0SSøren Schmidt     return 0;
8713014ca0SSøren Schmidt }
8813014ca0SSøren Schmidt 
8913014ca0SSøren Schmidt static int
9013014ca0SSøren Schmidt ata_netcell_allocate(device_t dev)
9113014ca0SSøren Schmidt {
9213014ca0SSøren Schmidt     struct ata_channel *ch = device_get_softc(dev);
9313014ca0SSøren Schmidt 
9413014ca0SSøren Schmidt     /* setup the usual register normal pci style */
9513014ca0SSøren Schmidt     if (ata_pci_allocate(dev))
9613014ca0SSøren Schmidt 	return ENXIO;
9713014ca0SSøren Schmidt 
9813014ca0SSøren Schmidt     /* the NetCell only supports 16 bit PIO transfers */
9913014ca0SSøren Schmidt     ch->flags |= ATA_USE_16BIT;
10013014ca0SSøren Schmidt 
10113014ca0SSøren Schmidt     return 0;
10213014ca0SSøren Schmidt }
10313014ca0SSøren Schmidt 
10413014ca0SSøren Schmidt static void
10513014ca0SSøren Schmidt ata_netcell_setmode(device_t dev, int mode)
10613014ca0SSøren Schmidt {
10713014ca0SSøren Schmidt     struct ata_device *atadev = device_get_softc(dev);
10813014ca0SSøren Schmidt 
10913014ca0SSøren Schmidt     mode = ata_limit_mode(dev, mode, ATA_UDMA2);
11013014ca0SSøren Schmidt     mode = ata_check_80pin(dev, mode);
11113014ca0SSøren Schmidt     if (!ata_controlcmd(dev, ATA_SETFEATURES, ATA_SF_SETXFER, 0, mode))
11213014ca0SSøren Schmidt         atadev->mode = mode;
11313014ca0SSøren Schmidt }
11413014ca0SSøren Schmidt 
11513014ca0SSøren Schmidt ATA_DECLARE_DRIVER(ata_netcell);
116