11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds * Product specific probe and attach routines for:
31da177e4SLinus Torvalds * 3940, 2940, aic7895, aic7890, aic7880,
41da177e4SLinus Torvalds * aic7870, aic7860 and aic7850 SCSI controllers
51da177e4SLinus Torvalds *
61da177e4SLinus Torvalds * Copyright (c) 1994-2001 Justin T. Gibbs.
71da177e4SLinus Torvalds * Copyright (c) 2000-2001 Adaptec Inc.
81da177e4SLinus Torvalds * All rights reserved.
91da177e4SLinus Torvalds *
101da177e4SLinus Torvalds * Redistribution and use in source and binary forms, with or without
111da177e4SLinus Torvalds * modification, are permitted provided that the following conditions
121da177e4SLinus Torvalds * are met:
131da177e4SLinus Torvalds * 1. Redistributions of source code must retain the above copyright
141da177e4SLinus Torvalds * notice, this list of conditions, and the following disclaimer,
151da177e4SLinus Torvalds * without modification.
161da177e4SLinus Torvalds * 2. Redistributions in binary form must reproduce at minimum a disclaimer
171da177e4SLinus Torvalds * substantially similar to the "NO WARRANTY" disclaimer below
181da177e4SLinus Torvalds * ("Disclaimer") and any redistribution must be conditioned upon
191da177e4SLinus Torvalds * including a substantially similar Disclaimer requirement for further
201da177e4SLinus Torvalds * binary redistribution.
211da177e4SLinus Torvalds * 3. Neither the names of the above-listed copyright holders nor the names
221da177e4SLinus Torvalds * of any contributors may be used to endorse or promote products derived
231da177e4SLinus Torvalds * from this software without specific prior written permission.
241da177e4SLinus Torvalds *
251da177e4SLinus Torvalds * Alternatively, this software may be distributed under the terms of the
261da177e4SLinus Torvalds * GNU General Public License ("GPL") version 2 as published by the Free
271da177e4SLinus Torvalds * Software Foundation.
281da177e4SLinus Torvalds *
291da177e4SLinus Torvalds * NO WARRANTY
301da177e4SLinus Torvalds * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
311da177e4SLinus Torvalds * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
321da177e4SLinus Torvalds * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
331da177e4SLinus Torvalds * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
341da177e4SLinus Torvalds * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
351da177e4SLinus Torvalds * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
361da177e4SLinus Torvalds * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
371da177e4SLinus Torvalds * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
381da177e4SLinus Torvalds * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
391da177e4SLinus Torvalds * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
401da177e4SLinus Torvalds * POSSIBILITY OF SUCH DAMAGES.
411da177e4SLinus Torvalds *
425e46631bSHannes Reinecke * $Id: //depot/aic7xxx/aic7xxx/aic7xxx_pci.c#79 $
431da177e4SLinus Torvalds */
441da177e4SLinus Torvalds
451da177e4SLinus Torvalds #include "aic7xxx_osm.h"
461da177e4SLinus Torvalds #include "aic7xxx_inline.h"
471da177e4SLinus Torvalds #include "aic7xxx_93cx6.h"
481da177e4SLinus Torvalds #include "aic7xxx_pci.h"
491da177e4SLinus Torvalds
501beb6fa8SHarvey Harrison static inline uint64_t
ahc_compose_id(u_int device,u_int vendor,u_int subdevice,u_int subvendor)511da177e4SLinus Torvalds ahc_compose_id(u_int device, u_int vendor, u_int subdevice, u_int subvendor)
521da177e4SLinus Torvalds {
531da177e4SLinus Torvalds uint64_t id;
541da177e4SLinus Torvalds
551da177e4SLinus Torvalds id = subvendor
561da177e4SLinus Torvalds | (subdevice << 16)
571da177e4SLinus Torvalds | ((uint64_t)vendor << 32)
581da177e4SLinus Torvalds | ((uint64_t)device << 48);
591da177e4SLinus Torvalds
601da177e4SLinus Torvalds return (id);
611da177e4SLinus Torvalds }
621da177e4SLinus Torvalds
631da177e4SLinus Torvalds #define AHC_PCI_IOADDR PCIR_MAPS /* I/O Address */
641da177e4SLinus Torvalds #define AHC_PCI_MEMADDR (PCIR_MAPS + 4) /* Mem I/O Address */
651da177e4SLinus Torvalds
661da177e4SLinus Torvalds #define DEVID_9005_TYPE(id) ((id) & 0xF)
671da177e4SLinus Torvalds #define DEVID_9005_TYPE_HBA 0x0 /* Standard Card */
681da177e4SLinus Torvalds #define DEVID_9005_TYPE_AAA 0x3 /* RAID Card */
691da177e4SLinus Torvalds #define DEVID_9005_TYPE_SISL 0x5 /* Container ROMB */
701da177e4SLinus Torvalds #define DEVID_9005_TYPE_MB 0xF /* On Motherboard */
711da177e4SLinus Torvalds
721da177e4SLinus Torvalds #define DEVID_9005_MAXRATE(id) (((id) & 0x30) >> 4)
731da177e4SLinus Torvalds #define DEVID_9005_MAXRATE_U160 0x0
741da177e4SLinus Torvalds #define DEVID_9005_MAXRATE_ULTRA2 0x1
751da177e4SLinus Torvalds #define DEVID_9005_MAXRATE_ULTRA 0x2
761da177e4SLinus Torvalds #define DEVID_9005_MAXRATE_FAST 0x3
771da177e4SLinus Torvalds
781da177e4SLinus Torvalds #define DEVID_9005_MFUNC(id) (((id) & 0x40) >> 6)
791da177e4SLinus Torvalds
801da177e4SLinus Torvalds #define DEVID_9005_CLASS(id) (((id) & 0xFF00) >> 8)
811da177e4SLinus Torvalds #define DEVID_9005_CLASS_SPI 0x0 /* Parallel SCSI */
821da177e4SLinus Torvalds
831da177e4SLinus Torvalds #define SUBID_9005_TYPE(id) ((id) & 0xF)
841da177e4SLinus Torvalds #define SUBID_9005_TYPE_MB 0xF /* On Motherboard */
851da177e4SLinus Torvalds #define SUBID_9005_TYPE_CARD 0x0 /* Standard Card */
861da177e4SLinus Torvalds #define SUBID_9005_TYPE_LCCARD 0x1 /* Low Cost Card */
871da177e4SLinus Torvalds #define SUBID_9005_TYPE_RAID 0x3 /* Combined with Raid */
881da177e4SLinus Torvalds
891da177e4SLinus Torvalds #define SUBID_9005_TYPE_KNOWN(id) \
901da177e4SLinus Torvalds ((((id) & 0xF) == SUBID_9005_TYPE_MB) \
911da177e4SLinus Torvalds || (((id) & 0xF) == SUBID_9005_TYPE_CARD) \
921da177e4SLinus Torvalds || (((id) & 0xF) == SUBID_9005_TYPE_LCCARD) \
931da177e4SLinus Torvalds || (((id) & 0xF) == SUBID_9005_TYPE_RAID))
941da177e4SLinus Torvalds
951da177e4SLinus Torvalds #define SUBID_9005_MAXRATE(id) (((id) & 0x30) >> 4)
961da177e4SLinus Torvalds #define SUBID_9005_MAXRATE_ULTRA2 0x0
971da177e4SLinus Torvalds #define SUBID_9005_MAXRATE_ULTRA 0x1
981da177e4SLinus Torvalds #define SUBID_9005_MAXRATE_U160 0x2
991da177e4SLinus Torvalds #define SUBID_9005_MAXRATE_RESERVED 0x3
1001da177e4SLinus Torvalds
1011da177e4SLinus Torvalds #define SUBID_9005_SEEPTYPE(id) \
1021da177e4SLinus Torvalds ((SUBID_9005_TYPE(id) == SUBID_9005_TYPE_MB) \
1031da177e4SLinus Torvalds ? ((id) & 0xC0) >> 6 \
1041da177e4SLinus Torvalds : ((id) & 0x300) >> 8)
1051da177e4SLinus Torvalds #define SUBID_9005_SEEPTYPE_NONE 0x0
1061da177e4SLinus Torvalds #define SUBID_9005_SEEPTYPE_1K 0x1
1071da177e4SLinus Torvalds #define SUBID_9005_SEEPTYPE_2K_4K 0x2
1081da177e4SLinus Torvalds #define SUBID_9005_SEEPTYPE_RESERVED 0x3
1091da177e4SLinus Torvalds #define SUBID_9005_AUTOTERM(id) \
1101da177e4SLinus Torvalds ((SUBID_9005_TYPE(id) == SUBID_9005_TYPE_MB) \
1111da177e4SLinus Torvalds ? (((id) & 0x400) >> 10) == 0 \
1121da177e4SLinus Torvalds : (((id) & 0x40) >> 6) == 0)
1131da177e4SLinus Torvalds
1141da177e4SLinus Torvalds #define SUBID_9005_NUMCHAN(id) \
1151da177e4SLinus Torvalds ((SUBID_9005_TYPE(id) == SUBID_9005_TYPE_MB) \
1161da177e4SLinus Torvalds ? ((id) & 0x300) >> 8 \
1171da177e4SLinus Torvalds : ((id) & 0xC00) >> 10)
1181da177e4SLinus Torvalds
1191da177e4SLinus Torvalds #define SUBID_9005_LEGACYCONN(id) \
1201da177e4SLinus Torvalds ((SUBID_9005_TYPE(id) == SUBID_9005_TYPE_MB) \
1211da177e4SLinus Torvalds ? 0 \
1221da177e4SLinus Torvalds : ((id) & 0x80) >> 7)
1231da177e4SLinus Torvalds
1241da177e4SLinus Torvalds #define SUBID_9005_MFUNCENB(id) \
1251da177e4SLinus Torvalds ((SUBID_9005_TYPE(id) == SUBID_9005_TYPE_MB) \
1261da177e4SLinus Torvalds ? ((id) & 0x800) >> 11 \
1271da177e4SLinus Torvalds : ((id) & 0x1000) >> 12)
1281da177e4SLinus Torvalds /*
1291da177e4SLinus Torvalds * Informational only. Should use chip register to be
1301da177e4SLinus Torvalds * certain, but may be use in identification strings.
1311da177e4SLinus Torvalds */
1321da177e4SLinus Torvalds #define SUBID_9005_CARD_SCSIWIDTH_MASK 0x2000
1331da177e4SLinus Torvalds #define SUBID_9005_CARD_PCIWIDTH_MASK 0x4000
1341da177e4SLinus Torvalds #define SUBID_9005_CARD_SEDIFF_MASK 0x8000
1351da177e4SLinus Torvalds
1361da177e4SLinus Torvalds static ahc_device_setup_t ahc_aic785X_setup;
1371da177e4SLinus Torvalds static ahc_device_setup_t ahc_aic7860_setup;
1381da177e4SLinus Torvalds static ahc_device_setup_t ahc_apa1480_setup;
1391da177e4SLinus Torvalds static ahc_device_setup_t ahc_aic7870_setup;
140b2d8bfe1SJames Bottomley static ahc_device_setup_t ahc_aic7870h_setup;
1411da177e4SLinus Torvalds static ahc_device_setup_t ahc_aha394X_setup;
142b2d8bfe1SJames Bottomley static ahc_device_setup_t ahc_aha394Xh_setup;
1431da177e4SLinus Torvalds static ahc_device_setup_t ahc_aha494X_setup;
144b2d8bfe1SJames Bottomley static ahc_device_setup_t ahc_aha494Xh_setup;
1451da177e4SLinus Torvalds static ahc_device_setup_t ahc_aha398X_setup;
1461da177e4SLinus Torvalds static ahc_device_setup_t ahc_aic7880_setup;
147b2d8bfe1SJames Bottomley static ahc_device_setup_t ahc_aic7880h_setup;
1481da177e4SLinus Torvalds static ahc_device_setup_t ahc_aha2940Pro_setup;
1491da177e4SLinus Torvalds static ahc_device_setup_t ahc_aha394XU_setup;
150b2d8bfe1SJames Bottomley static ahc_device_setup_t ahc_aha394XUh_setup;
1511da177e4SLinus Torvalds static ahc_device_setup_t ahc_aha398XU_setup;
1521da177e4SLinus Torvalds static ahc_device_setup_t ahc_aic7890_setup;
1531da177e4SLinus Torvalds static ahc_device_setup_t ahc_aic7892_setup;
1541da177e4SLinus Torvalds static ahc_device_setup_t ahc_aic7895_setup;
155b2d8bfe1SJames Bottomley static ahc_device_setup_t ahc_aic7895h_setup;
1561da177e4SLinus Torvalds static ahc_device_setup_t ahc_aic7896_setup;
1571da177e4SLinus Torvalds static ahc_device_setup_t ahc_aic7899_setup;
1581da177e4SLinus Torvalds static ahc_device_setup_t ahc_aha29160C_setup;
1591da177e4SLinus Torvalds static ahc_device_setup_t ahc_raid_setup;
1601da177e4SLinus Torvalds static ahc_device_setup_t ahc_aha394XX_setup;
1611da177e4SLinus Torvalds static ahc_device_setup_t ahc_aha494XX_setup;
1621da177e4SLinus Torvalds static ahc_device_setup_t ahc_aha398XX_setup;
1631da177e4SLinus Torvalds
164980b306aSDenys Vlasenko static const struct ahc_pci_identity ahc_pci_ident_table[] = {
1651da177e4SLinus Torvalds /* aic7850 based controllers */
1661da177e4SLinus Torvalds {
1671da177e4SLinus Torvalds ID_AHA_2902_04_10_15_20C_30C,
1681da177e4SLinus Torvalds ID_ALL_MASK,
1691da177e4SLinus Torvalds "Adaptec 2902/04/10/15/20C/30C SCSI adapter",
1701da177e4SLinus Torvalds ahc_aic785X_setup
1711da177e4SLinus Torvalds },
1721da177e4SLinus Torvalds /* aic7860 based controllers */
1731da177e4SLinus Torvalds {
1741da177e4SLinus Torvalds ID_AHA_2930CU,
1751da177e4SLinus Torvalds ID_ALL_MASK,
1761da177e4SLinus Torvalds "Adaptec 2930CU SCSI adapter",
1771da177e4SLinus Torvalds ahc_aic7860_setup
1781da177e4SLinus Torvalds },
1791da177e4SLinus Torvalds {
1801da177e4SLinus Torvalds ID_AHA_1480A & ID_DEV_VENDOR_MASK,
1811da177e4SLinus Torvalds ID_DEV_VENDOR_MASK,
1821da177e4SLinus Torvalds "Adaptec 1480A Ultra SCSI adapter",
1831da177e4SLinus Torvalds ahc_apa1480_setup
1841da177e4SLinus Torvalds },
1851da177e4SLinus Torvalds {
1861da177e4SLinus Torvalds ID_AHA_2940AU_0 & ID_DEV_VENDOR_MASK,
1871da177e4SLinus Torvalds ID_DEV_VENDOR_MASK,
1881da177e4SLinus Torvalds "Adaptec 2940A Ultra SCSI adapter",
1891da177e4SLinus Torvalds ahc_aic7860_setup
1901da177e4SLinus Torvalds },
1911da177e4SLinus Torvalds {
1921da177e4SLinus Torvalds ID_AHA_2940AU_CN & ID_DEV_VENDOR_MASK,
1931da177e4SLinus Torvalds ID_DEV_VENDOR_MASK,
1941da177e4SLinus Torvalds "Adaptec 2940A/CN Ultra SCSI adapter",
1951da177e4SLinus Torvalds ahc_aic7860_setup
1961da177e4SLinus Torvalds },
1971da177e4SLinus Torvalds {
1981da177e4SLinus Torvalds ID_AHA_2930C_VAR & ID_DEV_VENDOR_MASK,
1991da177e4SLinus Torvalds ID_DEV_VENDOR_MASK,
2001da177e4SLinus Torvalds "Adaptec 2930C Ultra SCSI adapter (VAR)",
2011da177e4SLinus Torvalds ahc_aic7860_setup
2021da177e4SLinus Torvalds },
2031da177e4SLinus Torvalds /* aic7870 based controllers */
2041da177e4SLinus Torvalds {
2051da177e4SLinus Torvalds ID_AHA_2940,
2061da177e4SLinus Torvalds ID_ALL_MASK,
2071da177e4SLinus Torvalds "Adaptec 2940 SCSI adapter",
2081da177e4SLinus Torvalds ahc_aic7870_setup
2091da177e4SLinus Torvalds },
2101da177e4SLinus Torvalds {
2111da177e4SLinus Torvalds ID_AHA_3940,
2121da177e4SLinus Torvalds ID_ALL_MASK,
2131da177e4SLinus Torvalds "Adaptec 3940 SCSI adapter",
2141da177e4SLinus Torvalds ahc_aha394X_setup
2151da177e4SLinus Torvalds },
2161da177e4SLinus Torvalds {
2171da177e4SLinus Torvalds ID_AHA_398X,
2181da177e4SLinus Torvalds ID_ALL_MASK,
2191da177e4SLinus Torvalds "Adaptec 398X SCSI RAID adapter",
2201da177e4SLinus Torvalds ahc_aha398X_setup
2211da177e4SLinus Torvalds },
2221da177e4SLinus Torvalds {
2231da177e4SLinus Torvalds ID_AHA_2944,
2241da177e4SLinus Torvalds ID_ALL_MASK,
2251da177e4SLinus Torvalds "Adaptec 2944 SCSI adapter",
226b2d8bfe1SJames Bottomley ahc_aic7870h_setup
2271da177e4SLinus Torvalds },
2281da177e4SLinus Torvalds {
2291da177e4SLinus Torvalds ID_AHA_3944,
2301da177e4SLinus Torvalds ID_ALL_MASK,
2311da177e4SLinus Torvalds "Adaptec 3944 SCSI adapter",
232b2d8bfe1SJames Bottomley ahc_aha394Xh_setup
2331da177e4SLinus Torvalds },
2341da177e4SLinus Torvalds {
2351da177e4SLinus Torvalds ID_AHA_4944,
2361da177e4SLinus Torvalds ID_ALL_MASK,
2371da177e4SLinus Torvalds "Adaptec 4944 SCSI adapter",
238b2d8bfe1SJames Bottomley ahc_aha494Xh_setup
2391da177e4SLinus Torvalds },
2401da177e4SLinus Torvalds /* aic7880 based controllers */
2411da177e4SLinus Torvalds {
2421da177e4SLinus Torvalds ID_AHA_2940U & ID_DEV_VENDOR_MASK,
2431da177e4SLinus Torvalds ID_DEV_VENDOR_MASK,
2441da177e4SLinus Torvalds "Adaptec 2940 Ultra SCSI adapter",
2451da177e4SLinus Torvalds ahc_aic7880_setup
2461da177e4SLinus Torvalds },
2471da177e4SLinus Torvalds {
2481da177e4SLinus Torvalds ID_AHA_3940U & ID_DEV_VENDOR_MASK,
2491da177e4SLinus Torvalds ID_DEV_VENDOR_MASK,
2501da177e4SLinus Torvalds "Adaptec 3940 Ultra SCSI adapter",
2511da177e4SLinus Torvalds ahc_aha394XU_setup
2521da177e4SLinus Torvalds },
2531da177e4SLinus Torvalds {
2541da177e4SLinus Torvalds ID_AHA_2944U & ID_DEV_VENDOR_MASK,
2551da177e4SLinus Torvalds ID_DEV_VENDOR_MASK,
2561da177e4SLinus Torvalds "Adaptec 2944 Ultra SCSI adapter",
257b2d8bfe1SJames Bottomley ahc_aic7880h_setup
2581da177e4SLinus Torvalds },
2591da177e4SLinus Torvalds {
2601da177e4SLinus Torvalds ID_AHA_3944U & ID_DEV_VENDOR_MASK,
2611da177e4SLinus Torvalds ID_DEV_VENDOR_MASK,
2621da177e4SLinus Torvalds "Adaptec 3944 Ultra SCSI adapter",
263b2d8bfe1SJames Bottomley ahc_aha394XUh_setup
2641da177e4SLinus Torvalds },
2651da177e4SLinus Torvalds {
2661da177e4SLinus Torvalds ID_AHA_398XU & ID_DEV_VENDOR_MASK,
2671da177e4SLinus Torvalds ID_DEV_VENDOR_MASK,
2681da177e4SLinus Torvalds "Adaptec 398X Ultra SCSI RAID adapter",
2691da177e4SLinus Torvalds ahc_aha398XU_setup
2701da177e4SLinus Torvalds },
2711da177e4SLinus Torvalds {
2721da177e4SLinus Torvalds /*
2731da177e4SLinus Torvalds * XXX Don't know the slot numbers
2741da177e4SLinus Torvalds * so we can't identify channels
2751da177e4SLinus Torvalds */
2761da177e4SLinus Torvalds ID_AHA_4944U & ID_DEV_VENDOR_MASK,
2771da177e4SLinus Torvalds ID_DEV_VENDOR_MASK,
2781da177e4SLinus Torvalds "Adaptec 4944 Ultra SCSI adapter",
279b2d8bfe1SJames Bottomley ahc_aic7880h_setup
2801da177e4SLinus Torvalds },
2811da177e4SLinus Torvalds {
2821da177e4SLinus Torvalds ID_AHA_2930U & ID_DEV_VENDOR_MASK,
2831da177e4SLinus Torvalds ID_DEV_VENDOR_MASK,
2841da177e4SLinus Torvalds "Adaptec 2930 Ultra SCSI adapter",
2851da177e4SLinus Torvalds ahc_aic7880_setup
2861da177e4SLinus Torvalds },
2871da177e4SLinus Torvalds {
2881da177e4SLinus Torvalds ID_AHA_2940U_PRO & ID_DEV_VENDOR_MASK,
2891da177e4SLinus Torvalds ID_DEV_VENDOR_MASK,
2901da177e4SLinus Torvalds "Adaptec 2940 Pro Ultra SCSI adapter",
2911da177e4SLinus Torvalds ahc_aha2940Pro_setup
2921da177e4SLinus Torvalds },
2931da177e4SLinus Torvalds {
2941da177e4SLinus Torvalds ID_AHA_2940U_CN & ID_DEV_VENDOR_MASK,
2951da177e4SLinus Torvalds ID_DEV_VENDOR_MASK,
2961da177e4SLinus Torvalds "Adaptec 2940/CN Ultra SCSI adapter",
2971da177e4SLinus Torvalds ahc_aic7880_setup
2981da177e4SLinus Torvalds },
2991da177e4SLinus Torvalds /* Ignore all SISL (AAC on MB) based controllers. */
3001da177e4SLinus Torvalds {
3011da177e4SLinus Torvalds ID_9005_SISL_ID,
3021da177e4SLinus Torvalds ID_9005_SISL_MASK,
3031da177e4SLinus Torvalds NULL,
3041da177e4SLinus Torvalds NULL
3051da177e4SLinus Torvalds },
3061da177e4SLinus Torvalds /* aic7890 based controllers */
3071da177e4SLinus Torvalds {
3081da177e4SLinus Torvalds ID_AHA_2930U2,
3091da177e4SLinus Torvalds ID_ALL_MASK,
3101da177e4SLinus Torvalds "Adaptec 2930 Ultra2 SCSI adapter",
3111da177e4SLinus Torvalds ahc_aic7890_setup
3121da177e4SLinus Torvalds },
3131da177e4SLinus Torvalds {
3141da177e4SLinus Torvalds ID_AHA_2940U2B,
3151da177e4SLinus Torvalds ID_ALL_MASK,
3161da177e4SLinus Torvalds "Adaptec 2940B Ultra2 SCSI adapter",
3171da177e4SLinus Torvalds ahc_aic7890_setup
3181da177e4SLinus Torvalds },
3191da177e4SLinus Torvalds {
3201da177e4SLinus Torvalds ID_AHA_2940U2_OEM,
3211da177e4SLinus Torvalds ID_ALL_MASK,
3221da177e4SLinus Torvalds "Adaptec 2940 Ultra2 SCSI adapter (OEM)",
3231da177e4SLinus Torvalds ahc_aic7890_setup
3241da177e4SLinus Torvalds },
3251da177e4SLinus Torvalds {
3261da177e4SLinus Torvalds ID_AHA_2940U2,
3271da177e4SLinus Torvalds ID_ALL_MASK,
3281da177e4SLinus Torvalds "Adaptec 2940 Ultra2 SCSI adapter",
3291da177e4SLinus Torvalds ahc_aic7890_setup
3301da177e4SLinus Torvalds },
3311da177e4SLinus Torvalds {
3321da177e4SLinus Torvalds ID_AHA_2950U2B,
3331da177e4SLinus Torvalds ID_ALL_MASK,
3341da177e4SLinus Torvalds "Adaptec 2950 Ultra2 SCSI adapter",
3351da177e4SLinus Torvalds ahc_aic7890_setup
3361da177e4SLinus Torvalds },
3371da177e4SLinus Torvalds {
3381da177e4SLinus Torvalds ID_AIC7890_ARO,
3391da177e4SLinus Torvalds ID_ALL_MASK,
3401da177e4SLinus Torvalds "Adaptec aic7890/91 Ultra2 SCSI adapter (ARO)",
3411da177e4SLinus Torvalds ahc_aic7890_setup
3421da177e4SLinus Torvalds },
3431da177e4SLinus Torvalds {
3441da177e4SLinus Torvalds ID_AAA_131U2,
3451da177e4SLinus Torvalds ID_ALL_MASK,
3461da177e4SLinus Torvalds "Adaptec AAA-131 Ultra2 RAID adapter",
3471da177e4SLinus Torvalds ahc_aic7890_setup
3481da177e4SLinus Torvalds },
3491da177e4SLinus Torvalds /* aic7892 based controllers */
3501da177e4SLinus Torvalds {
3511da177e4SLinus Torvalds ID_AHA_29160,
3521da177e4SLinus Torvalds ID_ALL_MASK,
3531da177e4SLinus Torvalds "Adaptec 29160 Ultra160 SCSI adapter",
3541da177e4SLinus Torvalds ahc_aic7892_setup
3551da177e4SLinus Torvalds },
3561da177e4SLinus Torvalds {
3571da177e4SLinus Torvalds ID_AHA_29160_CPQ,
3581da177e4SLinus Torvalds ID_ALL_MASK,
3591da177e4SLinus Torvalds "Adaptec (Compaq OEM) 29160 Ultra160 SCSI adapter",
3601da177e4SLinus Torvalds ahc_aic7892_setup
3611da177e4SLinus Torvalds },
3621da177e4SLinus Torvalds {
3631da177e4SLinus Torvalds ID_AHA_29160N,
3641da177e4SLinus Torvalds ID_ALL_MASK,
3651da177e4SLinus Torvalds "Adaptec 29160N Ultra160 SCSI adapter",
3661da177e4SLinus Torvalds ahc_aic7892_setup
3671da177e4SLinus Torvalds },
3681da177e4SLinus Torvalds {
3691da177e4SLinus Torvalds ID_AHA_29160C,
3701da177e4SLinus Torvalds ID_ALL_MASK,
3711da177e4SLinus Torvalds "Adaptec 29160C Ultra160 SCSI adapter",
3721da177e4SLinus Torvalds ahc_aha29160C_setup
3731da177e4SLinus Torvalds },
3741da177e4SLinus Torvalds {
3751da177e4SLinus Torvalds ID_AHA_29160B,
3761da177e4SLinus Torvalds ID_ALL_MASK,
3771da177e4SLinus Torvalds "Adaptec 29160B Ultra160 SCSI adapter",
3781da177e4SLinus Torvalds ahc_aic7892_setup
3791da177e4SLinus Torvalds },
3801da177e4SLinus Torvalds {
3811da177e4SLinus Torvalds ID_AHA_19160B,
3821da177e4SLinus Torvalds ID_ALL_MASK,
3831da177e4SLinus Torvalds "Adaptec 19160B Ultra160 SCSI adapter",
3841da177e4SLinus Torvalds ahc_aic7892_setup
3851da177e4SLinus Torvalds },
3861da177e4SLinus Torvalds {
3871da177e4SLinus Torvalds ID_AIC7892_ARO,
3881da177e4SLinus Torvalds ID_ALL_MASK,
3891da177e4SLinus Torvalds "Adaptec aic7892 Ultra160 SCSI adapter (ARO)",
3901da177e4SLinus Torvalds ahc_aic7892_setup
3911da177e4SLinus Torvalds },
3925e46631bSHannes Reinecke {
3935e46631bSHannes Reinecke ID_AHA_2915_30LP,
3945e46631bSHannes Reinecke ID_ALL_MASK,
3955e46631bSHannes Reinecke "Adaptec 2915/30LP Ultra160 SCSI adapter",
3965e46631bSHannes Reinecke ahc_aic7892_setup
3975e46631bSHannes Reinecke },
3981da177e4SLinus Torvalds /* aic7895 based controllers */
3991da177e4SLinus Torvalds {
4001da177e4SLinus Torvalds ID_AHA_2940U_DUAL,
4011da177e4SLinus Torvalds ID_ALL_MASK,
4021da177e4SLinus Torvalds "Adaptec 2940/DUAL Ultra SCSI adapter",
4031da177e4SLinus Torvalds ahc_aic7895_setup
4041da177e4SLinus Torvalds },
4051da177e4SLinus Torvalds {
4061da177e4SLinus Torvalds ID_AHA_3940AU,
4071da177e4SLinus Torvalds ID_ALL_MASK,
4081da177e4SLinus Torvalds "Adaptec 3940A Ultra SCSI adapter",
4091da177e4SLinus Torvalds ahc_aic7895_setup
4101da177e4SLinus Torvalds },
4111da177e4SLinus Torvalds {
4121da177e4SLinus Torvalds ID_AHA_3944AU,
4131da177e4SLinus Torvalds ID_ALL_MASK,
4141da177e4SLinus Torvalds "Adaptec 3944A Ultra SCSI adapter",
415b2d8bfe1SJames Bottomley ahc_aic7895h_setup
4161da177e4SLinus Torvalds },
4171da177e4SLinus Torvalds {
4181da177e4SLinus Torvalds ID_AIC7895_ARO,
4191da177e4SLinus Torvalds ID_AIC7895_ARO_MASK,
4201da177e4SLinus Torvalds "Adaptec aic7895 Ultra SCSI adapter (ARO)",
4211da177e4SLinus Torvalds ahc_aic7895_setup
4221da177e4SLinus Torvalds },
4231da177e4SLinus Torvalds /* aic7896/97 based controllers */
4241da177e4SLinus Torvalds {
4251da177e4SLinus Torvalds ID_AHA_3950U2B_0,
4261da177e4SLinus Torvalds ID_ALL_MASK,
4271da177e4SLinus Torvalds "Adaptec 3950B Ultra2 SCSI adapter",
4281da177e4SLinus Torvalds ahc_aic7896_setup
4291da177e4SLinus Torvalds },
4301da177e4SLinus Torvalds {
4311da177e4SLinus Torvalds ID_AHA_3950U2B_1,
4321da177e4SLinus Torvalds ID_ALL_MASK,
4331da177e4SLinus Torvalds "Adaptec 3950B Ultra2 SCSI adapter",
4341da177e4SLinus Torvalds ahc_aic7896_setup
4351da177e4SLinus Torvalds },
4361da177e4SLinus Torvalds {
4371da177e4SLinus Torvalds ID_AHA_3950U2D_0,
4381da177e4SLinus Torvalds ID_ALL_MASK,
4391da177e4SLinus Torvalds "Adaptec 3950D Ultra2 SCSI adapter",
4401da177e4SLinus Torvalds ahc_aic7896_setup
4411da177e4SLinus Torvalds },
4421da177e4SLinus Torvalds {
4431da177e4SLinus Torvalds ID_AHA_3950U2D_1,
4441da177e4SLinus Torvalds ID_ALL_MASK,
4451da177e4SLinus Torvalds "Adaptec 3950D Ultra2 SCSI adapter",
4461da177e4SLinus Torvalds ahc_aic7896_setup
4471da177e4SLinus Torvalds },
4481da177e4SLinus Torvalds {
4491da177e4SLinus Torvalds ID_AIC7896_ARO,
4501da177e4SLinus Torvalds ID_ALL_MASK,
4511da177e4SLinus Torvalds "Adaptec aic7896/97 Ultra2 SCSI adapter (ARO)",
4521da177e4SLinus Torvalds ahc_aic7896_setup
4531da177e4SLinus Torvalds },
4541da177e4SLinus Torvalds /* aic7899 based controllers */
4551da177e4SLinus Torvalds {
4561da177e4SLinus Torvalds ID_AHA_3960D,
4571da177e4SLinus Torvalds ID_ALL_MASK,
4581da177e4SLinus Torvalds "Adaptec 3960D Ultra160 SCSI adapter",
4591da177e4SLinus Torvalds ahc_aic7899_setup
4601da177e4SLinus Torvalds },
4611da177e4SLinus Torvalds {
4621da177e4SLinus Torvalds ID_AHA_3960D_CPQ,
4631da177e4SLinus Torvalds ID_ALL_MASK,
4641da177e4SLinus Torvalds "Adaptec (Compaq OEM) 3960D Ultra160 SCSI adapter",
4651da177e4SLinus Torvalds ahc_aic7899_setup
4661da177e4SLinus Torvalds },
4671da177e4SLinus Torvalds {
4681da177e4SLinus Torvalds ID_AIC7899_ARO,
4691da177e4SLinus Torvalds ID_ALL_MASK,
4701da177e4SLinus Torvalds "Adaptec aic7899 Ultra160 SCSI adapter (ARO)",
4711da177e4SLinus Torvalds ahc_aic7899_setup
4721da177e4SLinus Torvalds },
4731da177e4SLinus Torvalds /* Generic chip probes for devices we don't know 'exactly' */
4741da177e4SLinus Torvalds {
4751da177e4SLinus Torvalds ID_AIC7850 & ID_DEV_VENDOR_MASK,
4761da177e4SLinus Torvalds ID_DEV_VENDOR_MASK,
4771da177e4SLinus Torvalds "Adaptec aic7850 SCSI adapter",
4781da177e4SLinus Torvalds ahc_aic785X_setup
4791da177e4SLinus Torvalds },
4801da177e4SLinus Torvalds {
4811da177e4SLinus Torvalds ID_AIC7855 & ID_DEV_VENDOR_MASK,
4821da177e4SLinus Torvalds ID_DEV_VENDOR_MASK,
4831da177e4SLinus Torvalds "Adaptec aic7855 SCSI adapter",
4841da177e4SLinus Torvalds ahc_aic785X_setup
4851da177e4SLinus Torvalds },
4861da177e4SLinus Torvalds {
4871da177e4SLinus Torvalds ID_AIC7859 & ID_DEV_VENDOR_MASK,
4881da177e4SLinus Torvalds ID_DEV_VENDOR_MASK,
4891da177e4SLinus Torvalds "Adaptec aic7859 SCSI adapter",
4901da177e4SLinus Torvalds ahc_aic7860_setup
4911da177e4SLinus Torvalds },
4921da177e4SLinus Torvalds {
4931da177e4SLinus Torvalds ID_AIC7860 & ID_DEV_VENDOR_MASK,
4941da177e4SLinus Torvalds ID_DEV_VENDOR_MASK,
4951da177e4SLinus Torvalds "Adaptec aic7860 Ultra SCSI adapter",
4961da177e4SLinus Torvalds ahc_aic7860_setup
4971da177e4SLinus Torvalds },
4981da177e4SLinus Torvalds {
4991da177e4SLinus Torvalds ID_AIC7870 & ID_DEV_VENDOR_MASK,
5001da177e4SLinus Torvalds ID_DEV_VENDOR_MASK,
5011da177e4SLinus Torvalds "Adaptec aic7870 SCSI adapter",
5021da177e4SLinus Torvalds ahc_aic7870_setup
5031da177e4SLinus Torvalds },
5041da177e4SLinus Torvalds {
5051da177e4SLinus Torvalds ID_AIC7880 & ID_DEV_VENDOR_MASK,
5061da177e4SLinus Torvalds ID_DEV_VENDOR_MASK,
5071da177e4SLinus Torvalds "Adaptec aic7880 Ultra SCSI adapter",
5081da177e4SLinus Torvalds ahc_aic7880_setup
5091da177e4SLinus Torvalds },
5101da177e4SLinus Torvalds {
5111da177e4SLinus Torvalds ID_AIC7890 & ID_9005_GENERIC_MASK,
5121da177e4SLinus Torvalds ID_9005_GENERIC_MASK,
5131da177e4SLinus Torvalds "Adaptec aic7890/91 Ultra2 SCSI adapter",
5141da177e4SLinus Torvalds ahc_aic7890_setup
5151da177e4SLinus Torvalds },
5161da177e4SLinus Torvalds {
5171da177e4SLinus Torvalds ID_AIC7892 & ID_9005_GENERIC_MASK,
5181da177e4SLinus Torvalds ID_9005_GENERIC_MASK,
5191da177e4SLinus Torvalds "Adaptec aic7892 Ultra160 SCSI adapter",
5201da177e4SLinus Torvalds ahc_aic7892_setup
5211da177e4SLinus Torvalds },
5221da177e4SLinus Torvalds {
5231da177e4SLinus Torvalds ID_AIC7895 & ID_DEV_VENDOR_MASK,
5241da177e4SLinus Torvalds ID_DEV_VENDOR_MASK,
5251da177e4SLinus Torvalds "Adaptec aic7895 Ultra SCSI adapter",
5261da177e4SLinus Torvalds ahc_aic7895_setup
5271da177e4SLinus Torvalds },
5281da177e4SLinus Torvalds {
5291da177e4SLinus Torvalds ID_AIC7896 & ID_9005_GENERIC_MASK,
5301da177e4SLinus Torvalds ID_9005_GENERIC_MASK,
5311da177e4SLinus Torvalds "Adaptec aic7896/97 Ultra2 SCSI adapter",
5321da177e4SLinus Torvalds ahc_aic7896_setup
5331da177e4SLinus Torvalds },
5341da177e4SLinus Torvalds {
5351da177e4SLinus Torvalds ID_AIC7899 & ID_9005_GENERIC_MASK,
5361da177e4SLinus Torvalds ID_9005_GENERIC_MASK,
5371da177e4SLinus Torvalds "Adaptec aic7899 Ultra160 SCSI adapter",
5381da177e4SLinus Torvalds ahc_aic7899_setup
5391da177e4SLinus Torvalds },
5401da177e4SLinus Torvalds {
5411da177e4SLinus Torvalds ID_AIC7810 & ID_DEV_VENDOR_MASK,
5421da177e4SLinus Torvalds ID_DEV_VENDOR_MASK,
5431da177e4SLinus Torvalds "Adaptec aic7810 RAID memory controller",
5441da177e4SLinus Torvalds ahc_raid_setup
5451da177e4SLinus Torvalds },
5461da177e4SLinus Torvalds {
5471da177e4SLinus Torvalds ID_AIC7815 & ID_DEV_VENDOR_MASK,
5481da177e4SLinus Torvalds ID_DEV_VENDOR_MASK,
5491da177e4SLinus Torvalds "Adaptec aic7815 RAID memory controller",
5501da177e4SLinus Torvalds ahc_raid_setup
5511da177e4SLinus Torvalds }
5521da177e4SLinus Torvalds };
5531da177e4SLinus Torvalds
554289fe5b1SAdrian Bunk static const u_int ahc_num_pci_devs = ARRAY_SIZE(ahc_pci_ident_table);
5551da177e4SLinus Torvalds
5561da177e4SLinus Torvalds #define AHC_394X_SLOT_CHANNEL_A 4
5571da177e4SLinus Torvalds #define AHC_394X_SLOT_CHANNEL_B 5
5581da177e4SLinus Torvalds
5591da177e4SLinus Torvalds #define AHC_398X_SLOT_CHANNEL_A 4
5601da177e4SLinus Torvalds #define AHC_398X_SLOT_CHANNEL_B 8
5611da177e4SLinus Torvalds #define AHC_398X_SLOT_CHANNEL_C 12
5621da177e4SLinus Torvalds
5631da177e4SLinus Torvalds #define AHC_494X_SLOT_CHANNEL_A 4
5641da177e4SLinus Torvalds #define AHC_494X_SLOT_CHANNEL_B 5
5651da177e4SLinus Torvalds #define AHC_494X_SLOT_CHANNEL_C 6
5661da177e4SLinus Torvalds #define AHC_494X_SLOT_CHANNEL_D 7
5671da177e4SLinus Torvalds
5681da177e4SLinus Torvalds #define DEVCONFIG 0x40
5691da177e4SLinus Torvalds #define PCIERRGENDIS 0x80000000ul
5701da177e4SLinus Torvalds #define SCBSIZE32 0x00010000ul /* aic789X only */
5711da177e4SLinus Torvalds #define REXTVALID 0x00001000ul /* ultra cards only */
5721da177e4SLinus Torvalds #define MPORTMODE 0x00000400ul /* aic7870+ only */
5731da177e4SLinus Torvalds #define RAMPSM 0x00000200ul /* aic7870+ only */
5741da177e4SLinus Torvalds #define VOLSENSE 0x00000100ul
5751da177e4SLinus Torvalds #define PCI64BIT 0x00000080ul /* 64Bit PCI bus (Ultra2 Only)*/
5761da177e4SLinus Torvalds #define SCBRAMSEL 0x00000080ul
5771da177e4SLinus Torvalds #define MRDCEN 0x00000040ul
5781da177e4SLinus Torvalds #define EXTSCBTIME 0x00000020ul /* aic7870 only */
5791da177e4SLinus Torvalds #define EXTSCBPEN 0x00000010ul /* aic7870 only */
5801da177e4SLinus Torvalds #define BERREN 0x00000008ul
5811da177e4SLinus Torvalds #define DACEN 0x00000004ul
5821da177e4SLinus Torvalds #define STPWLEVEL 0x00000002ul
5831da177e4SLinus Torvalds #define DIFACTNEGEN 0x00000001ul /* aic7870 only */
5841da177e4SLinus Torvalds
5851da177e4SLinus Torvalds #define CSIZE_LATTIME 0x0c
5861da177e4SLinus Torvalds #define CACHESIZE 0x0000003ful /* only 5 bits */
5871da177e4SLinus Torvalds #define LATTIME 0x0000ff00ul
5881da177e4SLinus Torvalds
5891da177e4SLinus Torvalds /* PCI STATUS definitions */
5901da177e4SLinus Torvalds #define DPE 0x80
5911da177e4SLinus Torvalds #define SSE 0x40
5921da177e4SLinus Torvalds #define RMA 0x20
5931da177e4SLinus Torvalds #define RTA 0x10
5941da177e4SLinus Torvalds #define STA 0x08
5951da177e4SLinus Torvalds #define DPR 0x01
5961da177e4SLinus Torvalds
5977ecaeaffSColin Ian King static int ahc_9005_subdevinfo_valid(uint16_t device, uint16_t vendor,
5987ecaeaffSColin Ian King uint16_t subdevice, uint16_t subvendor);
5991da177e4SLinus Torvalds static int ahc_ext_scbram_present(struct ahc_softc *ahc);
6001da177e4SLinus Torvalds static void ahc_scbram_config(struct ahc_softc *ahc, int enable,
6011da177e4SLinus Torvalds int pcheck, int fast, int large);
6021da177e4SLinus Torvalds static void ahc_probe_ext_scbram(struct ahc_softc *ahc);
6031da177e4SLinus Torvalds static void check_extport(struct ahc_softc *ahc, u_int *sxfrctl1);
6041da177e4SLinus Torvalds static void ahc_parse_pci_eeprom(struct ahc_softc *ahc,
6051da177e4SLinus Torvalds struct seeprom_config *sc);
6061da177e4SLinus Torvalds static void configure_termination(struct ahc_softc *ahc,
6071da177e4SLinus Torvalds struct seeprom_descriptor *sd,
6081da177e4SLinus Torvalds u_int adapter_control,
6091da177e4SLinus Torvalds u_int *sxfrctl1);
6101da177e4SLinus Torvalds
6111da177e4SLinus Torvalds static void ahc_new_term_detect(struct ahc_softc *ahc,
6121da177e4SLinus Torvalds int *enableSEC_low,
6131da177e4SLinus Torvalds int *enableSEC_high,
6141da177e4SLinus Torvalds int *enablePRI_low,
6151da177e4SLinus Torvalds int *enablePRI_high,
6161da177e4SLinus Torvalds int *eeprom_present);
6171da177e4SLinus Torvalds static void aic787X_cable_detect(struct ahc_softc *ahc, int *internal50_present,
6181da177e4SLinus Torvalds int *internal68_present,
6191da177e4SLinus Torvalds int *externalcable_present,
6201da177e4SLinus Torvalds int *eeprom_present);
6211da177e4SLinus Torvalds static void aic785X_cable_detect(struct ahc_softc *ahc, int *internal50_present,
6221da177e4SLinus Torvalds int *externalcable_present,
6231da177e4SLinus Torvalds int *eeprom_present);
6241da177e4SLinus Torvalds static void write_brdctl(struct ahc_softc *ahc, uint8_t value);
6251da177e4SLinus Torvalds static uint8_t read_brdctl(struct ahc_softc *ahc);
6261da177e4SLinus Torvalds static void ahc_pci_intr(struct ahc_softc *ahc);
6271da177e4SLinus Torvalds static int ahc_pci_chip_init(struct ahc_softc *ahc);
6281da177e4SLinus Torvalds
6291da177e4SLinus Torvalds static int
ahc_9005_subdevinfo_valid(uint16_t device,uint16_t vendor,uint16_t subdevice,uint16_t subvendor)6301da177e4SLinus Torvalds ahc_9005_subdevinfo_valid(uint16_t device, uint16_t vendor,
6311da177e4SLinus Torvalds uint16_t subdevice, uint16_t subvendor)
6321da177e4SLinus Torvalds {
6331da177e4SLinus Torvalds int result;
6341da177e4SLinus Torvalds
6351da177e4SLinus Torvalds /* Default to invalid. */
6361da177e4SLinus Torvalds result = 0;
6371da177e4SLinus Torvalds if (vendor == 0x9005
6381da177e4SLinus Torvalds && subvendor == 0x9005
6391da177e4SLinus Torvalds && subdevice != device
6401da177e4SLinus Torvalds && SUBID_9005_TYPE_KNOWN(subdevice) != 0) {
6411da177e4SLinus Torvalds
6421da177e4SLinus Torvalds switch (SUBID_9005_TYPE(subdevice)) {
6431da177e4SLinus Torvalds case SUBID_9005_TYPE_MB:
6441da177e4SLinus Torvalds break;
6451da177e4SLinus Torvalds case SUBID_9005_TYPE_CARD:
6461da177e4SLinus Torvalds case SUBID_9005_TYPE_LCCARD:
6471da177e4SLinus Torvalds /*
6481da177e4SLinus Torvalds * Currently only trust Adaptec cards to
6491da177e4SLinus Torvalds * get the sub device info correct.
6501da177e4SLinus Torvalds */
6511da177e4SLinus Torvalds if (DEVID_9005_TYPE(device) == DEVID_9005_TYPE_HBA)
6521da177e4SLinus Torvalds result = 1;
6531da177e4SLinus Torvalds break;
6541da177e4SLinus Torvalds case SUBID_9005_TYPE_RAID:
6551da177e4SLinus Torvalds break;
6561da177e4SLinus Torvalds default:
6571da177e4SLinus Torvalds break;
6581da177e4SLinus Torvalds }
6591da177e4SLinus Torvalds }
6601da177e4SLinus Torvalds return (result);
6611da177e4SLinus Torvalds }
6621da177e4SLinus Torvalds
663980b306aSDenys Vlasenko const struct ahc_pci_identity *
ahc_find_pci_device(ahc_dev_softc_t pci)6641da177e4SLinus Torvalds ahc_find_pci_device(ahc_dev_softc_t pci)
6651da177e4SLinus Torvalds {
6661da177e4SLinus Torvalds uint64_t full_id;
6671da177e4SLinus Torvalds uint16_t device;
6681da177e4SLinus Torvalds uint16_t vendor;
6691da177e4SLinus Torvalds uint16_t subdevice;
6701da177e4SLinus Torvalds uint16_t subvendor;
671980b306aSDenys Vlasenko const struct ahc_pci_identity *entry;
6721da177e4SLinus Torvalds u_int i;
6731da177e4SLinus Torvalds
6741da177e4SLinus Torvalds vendor = ahc_pci_read_config(pci, PCIR_DEVVENDOR, /*bytes*/2);
6751da177e4SLinus Torvalds device = ahc_pci_read_config(pci, PCIR_DEVICE, /*bytes*/2);
676*37a9bd70STom Rix subvendor = ahc_pci_read_config(pci, PCI_SUBSYSTEM_VENDOR_ID, /*bytes*/2);
677*37a9bd70STom Rix subdevice = ahc_pci_read_config(pci, PCI_SUBSYSTEM_ID, /*bytes*/2);
6781da177e4SLinus Torvalds full_id = ahc_compose_id(device, vendor, subdevice, subvendor);
6791da177e4SLinus Torvalds
6801da177e4SLinus Torvalds /*
6811da177e4SLinus Torvalds * If the second function is not hooked up, ignore it.
6821da177e4SLinus Torvalds * Unfortunately, not all MB vendors implement the
6831da177e4SLinus Torvalds * subdevice ID as per the Adaptec spec, so do our best
6841da177e4SLinus Torvalds * to sanity check it prior to accepting the subdevice
6851da177e4SLinus Torvalds * ID as valid.
6861da177e4SLinus Torvalds */
6871da177e4SLinus Torvalds if (ahc_get_pci_function(pci) > 0
6886f8f8e4dSDave Jones && ahc_9005_subdevinfo_valid(device, vendor, subdevice, subvendor)
6891da177e4SLinus Torvalds && SUBID_9005_MFUNCENB(subdevice) == 0)
6901da177e4SLinus Torvalds return (NULL);
6911da177e4SLinus Torvalds
6921da177e4SLinus Torvalds for (i = 0; i < ahc_num_pci_devs; i++) {
6931da177e4SLinus Torvalds entry = &ahc_pci_ident_table[i];
6941da177e4SLinus Torvalds if (entry->full_id == (full_id & entry->id_mask)) {
6951da177e4SLinus Torvalds /* Honor exclusion entries. */
6961da177e4SLinus Torvalds if (entry->name == NULL)
6971da177e4SLinus Torvalds return (NULL);
6981da177e4SLinus Torvalds return (entry);
6991da177e4SLinus Torvalds }
7001da177e4SLinus Torvalds }
7011da177e4SLinus Torvalds return (NULL);
7021da177e4SLinus Torvalds }
7031da177e4SLinus Torvalds
7041da177e4SLinus Torvalds int
ahc_pci_config(struct ahc_softc * ahc,const struct ahc_pci_identity * entry)705980b306aSDenys Vlasenko ahc_pci_config(struct ahc_softc *ahc, const struct ahc_pci_identity *entry)
7061da177e4SLinus Torvalds {
7071da177e4SLinus Torvalds u_int command;
7081da177e4SLinus Torvalds u_int our_id;
7091da177e4SLinus Torvalds u_int sxfrctl1;
7101da177e4SLinus Torvalds u_int scsiseq;
7111da177e4SLinus Torvalds u_int dscommand0;
7121da177e4SLinus Torvalds uint32_t devconfig;
7131da177e4SLinus Torvalds int error;
7141da177e4SLinus Torvalds uint8_t sblkctl;
7151da177e4SLinus Torvalds
7161da177e4SLinus Torvalds our_id = 0;
7171da177e4SLinus Torvalds error = entry->setup(ahc);
7181da177e4SLinus Torvalds if (error != 0)
7191da177e4SLinus Torvalds return (error);
7201da177e4SLinus Torvalds ahc->chip |= AHC_PCI;
7211da177e4SLinus Torvalds ahc->description = entry->name;
7221da177e4SLinus Torvalds
7231da177e4SLinus Torvalds pci_set_power_state(ahc->dev_softc, AHC_POWER_STATE_D0);
7241da177e4SLinus Torvalds
7251da177e4SLinus Torvalds error = ahc_pci_map_registers(ahc);
7261da177e4SLinus Torvalds if (error != 0)
7271da177e4SLinus Torvalds return (error);
7281da177e4SLinus Torvalds
7291da177e4SLinus Torvalds /*
7301da177e4SLinus Torvalds * Before we continue probing the card, ensure that
7311da177e4SLinus Torvalds * its interrupts are *disabled*. We don't want
7321da177e4SLinus Torvalds * a misstep to hang the machine in an interrupt
7331da177e4SLinus Torvalds * storm.
7341da177e4SLinus Torvalds */
7351da177e4SLinus Torvalds ahc_intr_enable(ahc, FALSE);
7361da177e4SLinus Torvalds
7371da177e4SLinus Torvalds devconfig = ahc_pci_read_config(ahc->dev_softc, DEVCONFIG, /*bytes*/4);
7381da177e4SLinus Torvalds
7391da177e4SLinus Torvalds /*
7401da177e4SLinus Torvalds * If we need to support high memory, enable dual
7411da177e4SLinus Torvalds * address cycles. This bit must be set to enable
7421da177e4SLinus Torvalds * high address bit generation even if we are on a
7431da177e4SLinus Torvalds * 64bit bus (PCI64BIT set in devconfig).
7441da177e4SLinus Torvalds */
7451da177e4SLinus Torvalds if ((ahc->flags & AHC_39BIT_ADDRESSING) != 0) {
7461da177e4SLinus Torvalds
7471da177e4SLinus Torvalds if (bootverbose)
74848813cf9SPekka Enberg printk("%s: Enabling 39Bit Addressing\n",
7491da177e4SLinus Torvalds ahc_name(ahc));
7501da177e4SLinus Torvalds devconfig |= DACEN;
7511da177e4SLinus Torvalds }
7521da177e4SLinus Torvalds
7531da177e4SLinus Torvalds /* Ensure that pci error generation, a test feature, is disabled. */
7541da177e4SLinus Torvalds devconfig |= PCIERRGENDIS;
7551da177e4SLinus Torvalds
7561da177e4SLinus Torvalds ahc_pci_write_config(ahc->dev_softc, DEVCONFIG, devconfig, /*bytes*/4);
7571da177e4SLinus Torvalds
7581da177e4SLinus Torvalds /* Ensure busmastering is enabled */
7591da177e4SLinus Torvalds command = ahc_pci_read_config(ahc->dev_softc, PCIR_COMMAND, /*bytes*/2);
7601da177e4SLinus Torvalds command |= PCIM_CMD_BUSMASTEREN;
7611da177e4SLinus Torvalds
7621da177e4SLinus Torvalds ahc_pci_write_config(ahc->dev_softc, PCIR_COMMAND, command, /*bytes*/2);
7631da177e4SLinus Torvalds
7641da177e4SLinus Torvalds /* On all PCI adapters, we allow SCB paging */
7651da177e4SLinus Torvalds ahc->flags |= AHC_PAGESCBS;
7661da177e4SLinus Torvalds
7671da177e4SLinus Torvalds error = ahc_softc_init(ahc);
7681da177e4SLinus Torvalds if (error != 0)
7691da177e4SLinus Torvalds return (error);
7701da177e4SLinus Torvalds
7711da177e4SLinus Torvalds /*
7721da177e4SLinus Torvalds * Disable PCI parity error checking. Users typically
7731da177e4SLinus Torvalds * do this to work around broken PCI chipsets that get
7741da177e4SLinus Torvalds * the parity timing wrong and thus generate lots of spurious
7751da177e4SLinus Torvalds * errors. The chip only allows us to disable *all* parity
7761da177e4SLinus Torvalds * error reporting when doing this, so CIO bus, scb ram, and
7771da177e4SLinus Torvalds * scratch ram parity errors will be ignored too.
7781da177e4SLinus Torvalds */
7791da177e4SLinus Torvalds if ((ahc->flags & AHC_DISABLE_PCI_PERR) != 0)
7801da177e4SLinus Torvalds ahc->seqctl |= FAILDIS;
7811da177e4SLinus Torvalds
7821da177e4SLinus Torvalds ahc->bus_intr = ahc_pci_intr;
7831da177e4SLinus Torvalds ahc->bus_chip_init = ahc_pci_chip_init;
7841da177e4SLinus Torvalds
78525985edcSLucas De Marchi /* Remember how the card was setup in case there is no SEEPROM */
7861da177e4SLinus Torvalds if ((ahc_inb(ahc, HCNTRL) & POWRDN) == 0) {
7871da177e4SLinus Torvalds ahc_pause(ahc);
7881da177e4SLinus Torvalds if ((ahc->features & AHC_ULTRA2) != 0)
7891da177e4SLinus Torvalds our_id = ahc_inb(ahc, SCSIID_ULTRA2) & OID;
7901da177e4SLinus Torvalds else
7911da177e4SLinus Torvalds our_id = ahc_inb(ahc, SCSIID) & OID;
7921da177e4SLinus Torvalds sxfrctl1 = ahc_inb(ahc, SXFRCTL1) & STPWEN;
7931da177e4SLinus Torvalds scsiseq = ahc_inb(ahc, SCSISEQ);
7941da177e4SLinus Torvalds } else {
7951da177e4SLinus Torvalds sxfrctl1 = STPWEN;
7961da177e4SLinus Torvalds our_id = 7;
7971da177e4SLinus Torvalds scsiseq = 0;
7981da177e4SLinus Torvalds }
7991da177e4SLinus Torvalds
8001da177e4SLinus Torvalds error = ahc_reset(ahc, /*reinit*/FALSE);
8011da177e4SLinus Torvalds if (error != 0)
8021da177e4SLinus Torvalds return (ENXIO);
8031da177e4SLinus Torvalds
8041da177e4SLinus Torvalds if ((ahc->features & AHC_DT) != 0) {
8051da177e4SLinus Torvalds u_int sfunct;
8061da177e4SLinus Torvalds
8071da177e4SLinus Torvalds /* Perform ALT-Mode Setup */
8081da177e4SLinus Torvalds sfunct = ahc_inb(ahc, SFUNCT) & ~ALT_MODE;
8091da177e4SLinus Torvalds ahc_outb(ahc, SFUNCT, sfunct | ALT_MODE);
8101da177e4SLinus Torvalds ahc_outb(ahc, OPTIONMODE,
8111da177e4SLinus Torvalds OPTIONMODE_DEFAULTS|AUTOACKEN|BUSFREEREV|EXPPHASEDIS);
8121da177e4SLinus Torvalds ahc_outb(ahc, SFUNCT, sfunct);
8131da177e4SLinus Torvalds
8141da177e4SLinus Torvalds /* Normal mode setup */
8151da177e4SLinus Torvalds ahc_outb(ahc, CRCCONTROL1, CRCVALCHKEN|CRCENDCHKEN|CRCREQCHKEN
8161da177e4SLinus Torvalds |TARGCRCENDEN);
8171da177e4SLinus Torvalds }
8181da177e4SLinus Torvalds
8191da177e4SLinus Torvalds dscommand0 = ahc_inb(ahc, DSCOMMAND0);
8201da177e4SLinus Torvalds dscommand0 |= MPARCKEN|CACHETHEN;
8211da177e4SLinus Torvalds if ((ahc->features & AHC_ULTRA2) != 0) {
8221da177e4SLinus Torvalds
8231da177e4SLinus Torvalds /*
8241da177e4SLinus Torvalds * DPARCKEN doesn't work correctly on
8251da177e4SLinus Torvalds * some MBs so don't use it.
8261da177e4SLinus Torvalds */
8271da177e4SLinus Torvalds dscommand0 &= ~DPARCKEN;
8281da177e4SLinus Torvalds }
8291da177e4SLinus Torvalds
8301da177e4SLinus Torvalds /*
8311da177e4SLinus Torvalds * Handle chips that must have cache line
8321da177e4SLinus Torvalds * streaming (dis/en)abled.
8331da177e4SLinus Torvalds */
8341da177e4SLinus Torvalds if ((ahc->bugs & AHC_CACHETHEN_DIS_BUG) != 0)
8351da177e4SLinus Torvalds dscommand0 |= CACHETHEN;
8361da177e4SLinus Torvalds
8371da177e4SLinus Torvalds if ((ahc->bugs & AHC_CACHETHEN_BUG) != 0)
8381da177e4SLinus Torvalds dscommand0 &= ~CACHETHEN;
8391da177e4SLinus Torvalds
8401da177e4SLinus Torvalds ahc_outb(ahc, DSCOMMAND0, dscommand0);
8411da177e4SLinus Torvalds
8421da177e4SLinus Torvalds ahc->pci_cachesize =
8431da177e4SLinus Torvalds ahc_pci_read_config(ahc->dev_softc, CSIZE_LATTIME,
8441da177e4SLinus Torvalds /*bytes*/1) & CACHESIZE;
8451da177e4SLinus Torvalds ahc->pci_cachesize *= 4;
8461da177e4SLinus Torvalds
8471da177e4SLinus Torvalds if ((ahc->bugs & AHC_PCI_2_1_RETRY_BUG) != 0
8481da177e4SLinus Torvalds && ahc->pci_cachesize == 4) {
8491da177e4SLinus Torvalds
8501da177e4SLinus Torvalds ahc_pci_write_config(ahc->dev_softc, CSIZE_LATTIME,
8511da177e4SLinus Torvalds 0, /*bytes*/1);
8521da177e4SLinus Torvalds ahc->pci_cachesize = 0;
8531da177e4SLinus Torvalds }
8541da177e4SLinus Torvalds
8551da177e4SLinus Torvalds /*
85625985edcSLucas De Marchi * We cannot perform ULTRA speeds without the presence
8571da177e4SLinus Torvalds * of the external precision resistor.
8581da177e4SLinus Torvalds */
8591da177e4SLinus Torvalds if ((ahc->features & AHC_ULTRA) != 0) {
8601da177e4SLinus Torvalds uint32_t devconfig;
8611da177e4SLinus Torvalds
8621da177e4SLinus Torvalds devconfig = ahc_pci_read_config(ahc->dev_softc,
8631da177e4SLinus Torvalds DEVCONFIG, /*bytes*/4);
8641da177e4SLinus Torvalds if ((devconfig & REXTVALID) == 0)
8651da177e4SLinus Torvalds ahc->features &= ~AHC_ULTRA;
8661da177e4SLinus Torvalds }
8671da177e4SLinus Torvalds
8681da177e4SLinus Torvalds /* See if we have a SEEPROM and perform auto-term */
8691da177e4SLinus Torvalds check_extport(ahc, &sxfrctl1);
8701da177e4SLinus Torvalds
8711da177e4SLinus Torvalds /*
8721da177e4SLinus Torvalds * Take the LED out of diagnostic mode
8731da177e4SLinus Torvalds */
8741da177e4SLinus Torvalds sblkctl = ahc_inb(ahc, SBLKCTL);
8751da177e4SLinus Torvalds ahc_outb(ahc, SBLKCTL, (sblkctl & ~(DIAGLEDEN|DIAGLEDON)));
8761da177e4SLinus Torvalds
8771da177e4SLinus Torvalds if ((ahc->features & AHC_ULTRA2) != 0) {
8781da177e4SLinus Torvalds ahc_outb(ahc, DFF_THRSH, RD_DFTHRSH_MAX|WR_DFTHRSH_MAX);
8791da177e4SLinus Torvalds } else {
8801da177e4SLinus Torvalds ahc_outb(ahc, DSPCISTATUS, DFTHRSH_100);
8811da177e4SLinus Torvalds }
8821da177e4SLinus Torvalds
8831da177e4SLinus Torvalds if (ahc->flags & AHC_USEDEFAULTS) {
8841da177e4SLinus Torvalds /*
8851da177e4SLinus Torvalds * PCI Adapter default setup
8861da177e4SLinus Torvalds * Should only be used if the adapter does not have
8871da177e4SLinus Torvalds * a SEEPROM.
8881da177e4SLinus Torvalds */
8891da177e4SLinus Torvalds /* See if someone else set us up already */
8901da177e4SLinus Torvalds if ((ahc->flags & AHC_NO_BIOS_INIT) == 0
8911da177e4SLinus Torvalds && scsiseq != 0) {
89248813cf9SPekka Enberg printk("%s: Using left over BIOS settings\n",
8931da177e4SLinus Torvalds ahc_name(ahc));
8941da177e4SLinus Torvalds ahc->flags &= ~AHC_USEDEFAULTS;
8951da177e4SLinus Torvalds ahc->flags |= AHC_BIOS_ENABLED;
8961da177e4SLinus Torvalds } else {
8971da177e4SLinus Torvalds /*
8981da177e4SLinus Torvalds * Assume only one connector and always turn
8991da177e4SLinus Torvalds * on termination.
9001da177e4SLinus Torvalds */
9011da177e4SLinus Torvalds our_id = 0x07;
9021da177e4SLinus Torvalds sxfrctl1 = STPWEN;
9031da177e4SLinus Torvalds }
9041da177e4SLinus Torvalds ahc_outb(ahc, SCSICONF, our_id|ENSPCHK|RESET_SCSI);
9051da177e4SLinus Torvalds
9061da177e4SLinus Torvalds ahc->our_id = our_id;
9071da177e4SLinus Torvalds }
9081da177e4SLinus Torvalds
9091da177e4SLinus Torvalds /*
9101da177e4SLinus Torvalds * Take a look to see if we have external SRAM.
9111da177e4SLinus Torvalds * We currently do not attempt to use SRAM that is
9121da177e4SLinus Torvalds * shared among multiple controllers.
9131da177e4SLinus Torvalds */
9141da177e4SLinus Torvalds ahc_probe_ext_scbram(ahc);
9151da177e4SLinus Torvalds
9161da177e4SLinus Torvalds /*
9171da177e4SLinus Torvalds * Record our termination setting for the
9181da177e4SLinus Torvalds * generic initialization routine.
9191da177e4SLinus Torvalds */
9201da177e4SLinus Torvalds if ((sxfrctl1 & STPWEN) != 0)
9211da177e4SLinus Torvalds ahc->flags |= AHC_TERM_ENB_A;
9221da177e4SLinus Torvalds
9231da177e4SLinus Torvalds /*
9241da177e4SLinus Torvalds * Save chip register configuration data for chip resets
9251da177e4SLinus Torvalds * that occur during runtime and resume events.
9261da177e4SLinus Torvalds */
9271da177e4SLinus Torvalds ahc->bus_softc.pci_softc.devconfig =
9281da177e4SLinus Torvalds ahc_pci_read_config(ahc->dev_softc, DEVCONFIG, /*bytes*/4);
9291da177e4SLinus Torvalds ahc->bus_softc.pci_softc.command =
9301da177e4SLinus Torvalds ahc_pci_read_config(ahc->dev_softc, PCIR_COMMAND, /*bytes*/1);
9311da177e4SLinus Torvalds ahc->bus_softc.pci_softc.csize_lattime =
9321da177e4SLinus Torvalds ahc_pci_read_config(ahc->dev_softc, CSIZE_LATTIME, /*bytes*/1);
9331da177e4SLinus Torvalds ahc->bus_softc.pci_softc.dscommand0 = ahc_inb(ahc, DSCOMMAND0);
9341da177e4SLinus Torvalds ahc->bus_softc.pci_softc.dspcistatus = ahc_inb(ahc, DSPCISTATUS);
9351da177e4SLinus Torvalds if ((ahc->features & AHC_DT) != 0) {
9361da177e4SLinus Torvalds u_int sfunct;
9371da177e4SLinus Torvalds
9381da177e4SLinus Torvalds sfunct = ahc_inb(ahc, SFUNCT) & ~ALT_MODE;
9391da177e4SLinus Torvalds ahc_outb(ahc, SFUNCT, sfunct | ALT_MODE);
9401da177e4SLinus Torvalds ahc->bus_softc.pci_softc.optionmode = ahc_inb(ahc, OPTIONMODE);
9411da177e4SLinus Torvalds ahc->bus_softc.pci_softc.targcrccnt = ahc_inw(ahc, TARGCRCCNT);
9421da177e4SLinus Torvalds ahc_outb(ahc, SFUNCT, sfunct);
9431da177e4SLinus Torvalds ahc->bus_softc.pci_softc.crccontrol1 =
9441da177e4SLinus Torvalds ahc_inb(ahc, CRCCONTROL1);
9451da177e4SLinus Torvalds }
9461da177e4SLinus Torvalds if ((ahc->features & AHC_MULTI_FUNC) != 0)
9471da177e4SLinus Torvalds ahc->bus_softc.pci_softc.scbbaddr = ahc_inb(ahc, SCBBADDR);
9481da177e4SLinus Torvalds
9491da177e4SLinus Torvalds if ((ahc->features & AHC_ULTRA2) != 0)
9501da177e4SLinus Torvalds ahc->bus_softc.pci_softc.dff_thrsh = ahc_inb(ahc, DFF_THRSH);
9511da177e4SLinus Torvalds
9521da177e4SLinus Torvalds /* Core initialization */
9531da177e4SLinus Torvalds error = ahc_init(ahc);
9541da177e4SLinus Torvalds if (error != 0)
9551da177e4SLinus Torvalds return (error);
956a2f5bfcfSHannes Reinecke ahc->init_level++;
9571da177e4SLinus Torvalds
9581da177e4SLinus Torvalds /*
9591da177e4SLinus Torvalds * Allow interrupts now that we are completely setup.
9601da177e4SLinus Torvalds */
961a2f5bfcfSHannes Reinecke return ahc_pci_map_int(ahc);
9621da177e4SLinus Torvalds }
9631da177e4SLinus Torvalds
9641da177e4SLinus Torvalds /*
96525985edcSLucas De Marchi * Test for the presence of external sram in an
9661da177e4SLinus Torvalds * "unshared" configuration.
9671da177e4SLinus Torvalds */
9681da177e4SLinus Torvalds static int
ahc_ext_scbram_present(struct ahc_softc * ahc)9691da177e4SLinus Torvalds ahc_ext_scbram_present(struct ahc_softc *ahc)
9701da177e4SLinus Torvalds {
9711da177e4SLinus Torvalds u_int chip;
9721da177e4SLinus Torvalds int ramps;
9731da177e4SLinus Torvalds int single_user;
9741da177e4SLinus Torvalds uint32_t devconfig;
9751da177e4SLinus Torvalds
9761da177e4SLinus Torvalds chip = ahc->chip & AHC_CHIPID_MASK;
9771da177e4SLinus Torvalds devconfig = ahc_pci_read_config(ahc->dev_softc,
9781da177e4SLinus Torvalds DEVCONFIG, /*bytes*/4);
9791da177e4SLinus Torvalds single_user = (devconfig & MPORTMODE) != 0;
9801da177e4SLinus Torvalds
9811da177e4SLinus Torvalds if ((ahc->features & AHC_ULTRA2) != 0)
9821da177e4SLinus Torvalds ramps = (ahc_inb(ahc, DSCOMMAND0) & RAMPS) != 0;
9831da177e4SLinus Torvalds else if (chip == AHC_AIC7895 || chip == AHC_AIC7895C)
9841da177e4SLinus Torvalds /*
9851da177e4SLinus Torvalds * External SCBRAM arbitration is flakey
9861da177e4SLinus Torvalds * on these chips. Unfortunately this means
9871da177e4SLinus Torvalds * we don't use the extra SCB ram space on the
9881da177e4SLinus Torvalds * 3940AUW.
9891da177e4SLinus Torvalds */
9901da177e4SLinus Torvalds ramps = 0;
9911da177e4SLinus Torvalds else if (chip >= AHC_AIC7870)
9921da177e4SLinus Torvalds ramps = (devconfig & RAMPSM) != 0;
9931da177e4SLinus Torvalds else
9941da177e4SLinus Torvalds ramps = 0;
9951da177e4SLinus Torvalds
9961da177e4SLinus Torvalds if (ramps && single_user)
9971da177e4SLinus Torvalds return (1);
9981da177e4SLinus Torvalds return (0);
9991da177e4SLinus Torvalds }
10001da177e4SLinus Torvalds
10011da177e4SLinus Torvalds /*
10021da177e4SLinus Torvalds * Enable external scbram.
10031da177e4SLinus Torvalds */
10041da177e4SLinus Torvalds static void
ahc_scbram_config(struct ahc_softc * ahc,int enable,int pcheck,int fast,int large)10051da177e4SLinus Torvalds ahc_scbram_config(struct ahc_softc *ahc, int enable, int pcheck,
10061da177e4SLinus Torvalds int fast, int large)
10071da177e4SLinus Torvalds {
10081da177e4SLinus Torvalds uint32_t devconfig;
10091da177e4SLinus Torvalds
10101da177e4SLinus Torvalds if (ahc->features & AHC_MULTI_FUNC) {
10111da177e4SLinus Torvalds /*
10121da177e4SLinus Torvalds * Set the SCB Base addr (highest address bit)
10131da177e4SLinus Torvalds * depending on which channel we are.
10141da177e4SLinus Torvalds */
10151da177e4SLinus Torvalds ahc_outb(ahc, SCBBADDR, ahc_get_pci_function(ahc->dev_softc));
10161da177e4SLinus Torvalds }
10171da177e4SLinus Torvalds
10181da177e4SLinus Torvalds ahc->flags &= ~AHC_LSCBS_ENABLED;
10191da177e4SLinus Torvalds if (large)
10201da177e4SLinus Torvalds ahc->flags |= AHC_LSCBS_ENABLED;
10211da177e4SLinus Torvalds devconfig = ahc_pci_read_config(ahc->dev_softc, DEVCONFIG, /*bytes*/4);
10221da177e4SLinus Torvalds if ((ahc->features & AHC_ULTRA2) != 0) {
10231da177e4SLinus Torvalds u_int dscommand0;
10241da177e4SLinus Torvalds
10251da177e4SLinus Torvalds dscommand0 = ahc_inb(ahc, DSCOMMAND0);
10261da177e4SLinus Torvalds if (enable)
10271da177e4SLinus Torvalds dscommand0 &= ~INTSCBRAMSEL;
10281da177e4SLinus Torvalds else
10291da177e4SLinus Torvalds dscommand0 |= INTSCBRAMSEL;
10301da177e4SLinus Torvalds if (large)
10311da177e4SLinus Torvalds dscommand0 &= ~USCBSIZE32;
10321da177e4SLinus Torvalds else
10331da177e4SLinus Torvalds dscommand0 |= USCBSIZE32;
10341da177e4SLinus Torvalds ahc_outb(ahc, DSCOMMAND0, dscommand0);
10351da177e4SLinus Torvalds } else {
10361da177e4SLinus Torvalds if (fast)
10371da177e4SLinus Torvalds devconfig &= ~EXTSCBTIME;
10381da177e4SLinus Torvalds else
10391da177e4SLinus Torvalds devconfig |= EXTSCBTIME;
10401da177e4SLinus Torvalds if (enable)
10411da177e4SLinus Torvalds devconfig &= ~SCBRAMSEL;
10421da177e4SLinus Torvalds else
10431da177e4SLinus Torvalds devconfig |= SCBRAMSEL;
10441da177e4SLinus Torvalds if (large)
10451da177e4SLinus Torvalds devconfig &= ~SCBSIZE32;
10461da177e4SLinus Torvalds else
10471da177e4SLinus Torvalds devconfig |= SCBSIZE32;
10481da177e4SLinus Torvalds }
10491da177e4SLinus Torvalds if (pcheck)
10501da177e4SLinus Torvalds devconfig |= EXTSCBPEN;
10511da177e4SLinus Torvalds else
10521da177e4SLinus Torvalds devconfig &= ~EXTSCBPEN;
10531da177e4SLinus Torvalds
10541da177e4SLinus Torvalds ahc_pci_write_config(ahc->dev_softc, DEVCONFIG, devconfig, /*bytes*/4);
10551da177e4SLinus Torvalds }
10561da177e4SLinus Torvalds
10571da177e4SLinus Torvalds /*
10581da177e4SLinus Torvalds * Take a look to see if we have external SRAM.
10591da177e4SLinus Torvalds * We currently do not attempt to use SRAM that is
10601da177e4SLinus Torvalds * shared among multiple controllers.
10611da177e4SLinus Torvalds */
10621da177e4SLinus Torvalds static void
ahc_probe_ext_scbram(struct ahc_softc * ahc)10631da177e4SLinus Torvalds ahc_probe_ext_scbram(struct ahc_softc *ahc)
10641da177e4SLinus Torvalds {
10651da177e4SLinus Torvalds int num_scbs;
10661da177e4SLinus Torvalds int test_num_scbs;
10671da177e4SLinus Torvalds int enable;
10681da177e4SLinus Torvalds int pcheck;
10691da177e4SLinus Torvalds int fast;
10701da177e4SLinus Torvalds int large;
10711da177e4SLinus Torvalds
10721da177e4SLinus Torvalds enable = FALSE;
10731da177e4SLinus Torvalds pcheck = FALSE;
10741da177e4SLinus Torvalds fast = FALSE;
10751da177e4SLinus Torvalds large = FALSE;
10761da177e4SLinus Torvalds num_scbs = 0;
10771da177e4SLinus Torvalds
10781da177e4SLinus Torvalds if (ahc_ext_scbram_present(ahc) == 0)
10791da177e4SLinus Torvalds goto done;
10801da177e4SLinus Torvalds
10811da177e4SLinus Torvalds /*
10821da177e4SLinus Torvalds * Probe for the best parameters to use.
10831da177e4SLinus Torvalds */
10841da177e4SLinus Torvalds ahc_scbram_config(ahc, /*enable*/TRUE, pcheck, fast, large);
10851da177e4SLinus Torvalds num_scbs = ahc_probe_scbs(ahc);
10861da177e4SLinus Torvalds if (num_scbs == 0) {
10871da177e4SLinus Torvalds /* The SRAM wasn't really present. */
10881da177e4SLinus Torvalds goto done;
10891da177e4SLinus Torvalds }
10901da177e4SLinus Torvalds enable = TRUE;
10911da177e4SLinus Torvalds
10921da177e4SLinus Torvalds /*
10931da177e4SLinus Torvalds * Clear any outstanding parity error
10941da177e4SLinus Torvalds * and ensure that parity error reporting
10951da177e4SLinus Torvalds * is enabled.
10961da177e4SLinus Torvalds */
10971da177e4SLinus Torvalds ahc_outb(ahc, SEQCTL, 0);
10981da177e4SLinus Torvalds ahc_outb(ahc, CLRINT, CLRPARERR);
10991da177e4SLinus Torvalds ahc_outb(ahc, CLRINT, CLRBRKADRINT);
11001da177e4SLinus Torvalds
11011da177e4SLinus Torvalds /* Now see if we can do parity */
11021da177e4SLinus Torvalds ahc_scbram_config(ahc, enable, /*pcheck*/TRUE, fast, large);
11031da177e4SLinus Torvalds num_scbs = ahc_probe_scbs(ahc);
11041da177e4SLinus Torvalds if ((ahc_inb(ahc, INTSTAT) & BRKADRINT) == 0
11051da177e4SLinus Torvalds || (ahc_inb(ahc, ERROR) & MPARERR) == 0)
11061da177e4SLinus Torvalds pcheck = TRUE;
11071da177e4SLinus Torvalds
11081da177e4SLinus Torvalds /* Clear any resulting parity error */
11091da177e4SLinus Torvalds ahc_outb(ahc, CLRINT, CLRPARERR);
11101da177e4SLinus Torvalds ahc_outb(ahc, CLRINT, CLRBRKADRINT);
11111da177e4SLinus Torvalds
11121da177e4SLinus Torvalds /* Now see if we can do fast timing */
11131da177e4SLinus Torvalds ahc_scbram_config(ahc, enable, pcheck, /*fast*/TRUE, large);
11141da177e4SLinus Torvalds test_num_scbs = ahc_probe_scbs(ahc);
11151da177e4SLinus Torvalds if (test_num_scbs == num_scbs
11161da177e4SLinus Torvalds && ((ahc_inb(ahc, INTSTAT) & BRKADRINT) == 0
11171da177e4SLinus Torvalds || (ahc_inb(ahc, ERROR) & MPARERR) == 0))
11181da177e4SLinus Torvalds fast = TRUE;
11191da177e4SLinus Torvalds
11201da177e4SLinus Torvalds /*
11211da177e4SLinus Torvalds * See if we can use large SCBs and still maintain
11221da177e4SLinus Torvalds * the same overall count of SCBs.
11231da177e4SLinus Torvalds */
11241da177e4SLinus Torvalds if ((ahc->features & AHC_LARGE_SCBS) != 0) {
11251da177e4SLinus Torvalds ahc_scbram_config(ahc, enable, pcheck, fast, /*large*/TRUE);
11261da177e4SLinus Torvalds test_num_scbs = ahc_probe_scbs(ahc);
11271da177e4SLinus Torvalds if (test_num_scbs >= num_scbs) {
11281da177e4SLinus Torvalds large = TRUE;
11291da177e4SLinus Torvalds num_scbs = test_num_scbs;
11301da177e4SLinus Torvalds if (num_scbs >= 64) {
11311da177e4SLinus Torvalds /*
11321da177e4SLinus Torvalds * We have enough space to move the
11331da177e4SLinus Torvalds * "busy targets table" into SCB space
11341da177e4SLinus Torvalds * and make it qualify all the way to the
11351da177e4SLinus Torvalds * lun level.
11361da177e4SLinus Torvalds */
11371da177e4SLinus Torvalds ahc->flags |= AHC_SCB_BTT;
11381da177e4SLinus Torvalds }
11391da177e4SLinus Torvalds }
11401da177e4SLinus Torvalds }
11411da177e4SLinus Torvalds done:
11421da177e4SLinus Torvalds /*
11431da177e4SLinus Torvalds * Disable parity error reporting until we
11441da177e4SLinus Torvalds * can load instruction ram.
11451da177e4SLinus Torvalds */
11461da177e4SLinus Torvalds ahc_outb(ahc, SEQCTL, PERRORDIS|FAILDIS);
11471da177e4SLinus Torvalds /* Clear any latched parity error */
11481da177e4SLinus Torvalds ahc_outb(ahc, CLRINT, CLRPARERR);
11491da177e4SLinus Torvalds ahc_outb(ahc, CLRINT, CLRBRKADRINT);
11501da177e4SLinus Torvalds if (bootverbose && enable) {
115148813cf9SPekka Enberg printk("%s: External SRAM, %s access%s, %dbytes/SCB\n",
11521da177e4SLinus Torvalds ahc_name(ahc), fast ? "fast" : "slow",
11531da177e4SLinus Torvalds pcheck ? ", parity checking enabled" : "",
11541da177e4SLinus Torvalds large ? 64 : 32);
11551da177e4SLinus Torvalds }
11561da177e4SLinus Torvalds ahc_scbram_config(ahc, enable, pcheck, fast, large);
11571da177e4SLinus Torvalds }
11581da177e4SLinus Torvalds
11591da177e4SLinus Torvalds /*
11601da177e4SLinus Torvalds * Perform some simple tests that should catch situations where
11611da177e4SLinus Torvalds * our registers are invalidly mapped.
11621da177e4SLinus Torvalds */
11631da177e4SLinus Torvalds int
ahc_pci_test_register_access(struct ahc_softc * ahc)11641da177e4SLinus Torvalds ahc_pci_test_register_access(struct ahc_softc *ahc)
11651da177e4SLinus Torvalds {
11661da177e4SLinus Torvalds int error;
11671da177e4SLinus Torvalds u_int status1;
11681da177e4SLinus Torvalds uint32_t cmd;
11691da177e4SLinus Torvalds uint8_t hcntrl;
11701da177e4SLinus Torvalds
11711da177e4SLinus Torvalds error = EIO;
11721da177e4SLinus Torvalds
11731da177e4SLinus Torvalds /*
11741da177e4SLinus Torvalds * Enable PCI error interrupt status, but suppress NMIs
11751da177e4SLinus Torvalds * generated by SERR raised due to target aborts.
11761da177e4SLinus Torvalds */
11771da177e4SLinus Torvalds cmd = ahc_pci_read_config(ahc->dev_softc, PCIR_COMMAND, /*bytes*/2);
11781da177e4SLinus Torvalds ahc_pci_write_config(ahc->dev_softc, PCIR_COMMAND,
11791da177e4SLinus Torvalds cmd & ~PCIM_CMD_SERRESPEN, /*bytes*/2);
11801da177e4SLinus Torvalds
11811da177e4SLinus Torvalds /*
11821da177e4SLinus Torvalds * First a simple test to see if any
11831da177e4SLinus Torvalds * registers can be read. Reading
11841da177e4SLinus Torvalds * HCNTRL has no side effects and has
11851da177e4SLinus Torvalds * at least one bit that is guaranteed to
11861da177e4SLinus Torvalds * be zero so it is a good register to
11871da177e4SLinus Torvalds * use for this test.
11881da177e4SLinus Torvalds */
11891da177e4SLinus Torvalds hcntrl = ahc_inb(ahc, HCNTRL);
11905e46631bSHannes Reinecke
11911da177e4SLinus Torvalds if (hcntrl == 0xFF)
11921da177e4SLinus Torvalds goto fail;
11931da177e4SLinus Torvalds
11945e46631bSHannes Reinecke if ((hcntrl & CHIPRST) != 0) {
11955e46631bSHannes Reinecke /*
11965e46631bSHannes Reinecke * The chip has not been initialized since
11975e46631bSHannes Reinecke * PCI/EISA/VLB bus reset. Don't trust
11985e46631bSHannes Reinecke * "left over BIOS data".
11995e46631bSHannes Reinecke */
12005e46631bSHannes Reinecke ahc->flags |= AHC_NO_BIOS_INIT;
12015e46631bSHannes Reinecke }
12025e46631bSHannes Reinecke
12031da177e4SLinus Torvalds /*
12041da177e4SLinus Torvalds * Next create a situation where write combining
12051da177e4SLinus Torvalds * or read prefetching could be initiated by the
12061da177e4SLinus Torvalds * CPU or host bridge. Our device does not support
12071da177e4SLinus Torvalds * either, so look for data corruption and/or flagged
12081da177e4SLinus Torvalds * PCI errors. First pause without causing another
12091da177e4SLinus Torvalds * chip reset.
12101da177e4SLinus Torvalds */
12111da177e4SLinus Torvalds hcntrl &= ~CHIPRST;
12121da177e4SLinus Torvalds ahc_outb(ahc, HCNTRL, hcntrl|PAUSE);
12131da177e4SLinus Torvalds while (ahc_is_paused(ahc) == 0)
12141da177e4SLinus Torvalds ;
12151da177e4SLinus Torvalds
12161da177e4SLinus Torvalds /* Clear any PCI errors that occurred before our driver attached. */
12171da177e4SLinus Torvalds status1 = ahc_pci_read_config(ahc->dev_softc,
12181da177e4SLinus Torvalds PCIR_STATUS + 1, /*bytes*/1);
12191da177e4SLinus Torvalds ahc_pci_write_config(ahc->dev_softc, PCIR_STATUS + 1,
12201da177e4SLinus Torvalds status1, /*bytes*/1);
12211da177e4SLinus Torvalds ahc_outb(ahc, CLRINT, CLRPARERR);
12221da177e4SLinus Torvalds
12231da177e4SLinus Torvalds ahc_outb(ahc, SEQCTL, PERRORDIS);
12241da177e4SLinus Torvalds ahc_outb(ahc, SCBPTR, 0);
12251da177e4SLinus Torvalds ahc_outl(ahc, SCB_BASE, 0x5aa555aa);
12261da177e4SLinus Torvalds if (ahc_inl(ahc, SCB_BASE) != 0x5aa555aa)
12271da177e4SLinus Torvalds goto fail;
12281da177e4SLinus Torvalds
12291da177e4SLinus Torvalds status1 = ahc_pci_read_config(ahc->dev_softc,
12301da177e4SLinus Torvalds PCIR_STATUS + 1, /*bytes*/1);
12311da177e4SLinus Torvalds if ((status1 & STA) != 0)
12321da177e4SLinus Torvalds goto fail;
12331da177e4SLinus Torvalds
12341da177e4SLinus Torvalds error = 0;
12351da177e4SLinus Torvalds
12361da177e4SLinus Torvalds fail:
12371da177e4SLinus Torvalds /* Silently clear any latched errors. */
12381da177e4SLinus Torvalds status1 = ahc_pci_read_config(ahc->dev_softc,
12391da177e4SLinus Torvalds PCIR_STATUS + 1, /*bytes*/1);
12401da177e4SLinus Torvalds ahc_pci_write_config(ahc->dev_softc, PCIR_STATUS + 1,
12411da177e4SLinus Torvalds status1, /*bytes*/1);
12421da177e4SLinus Torvalds ahc_outb(ahc, CLRINT, CLRPARERR);
12431da177e4SLinus Torvalds ahc_outb(ahc, SEQCTL, PERRORDIS|FAILDIS);
12441da177e4SLinus Torvalds ahc_pci_write_config(ahc->dev_softc, PCIR_COMMAND, cmd, /*bytes*/2);
12451da177e4SLinus Torvalds return (error);
12461da177e4SLinus Torvalds }
12471da177e4SLinus Torvalds
12481da177e4SLinus Torvalds /*
12491da177e4SLinus Torvalds * Check the external port logic for a serial eeprom
12501da177e4SLinus Torvalds * and termination/cable detection contrls.
12511da177e4SLinus Torvalds */
12521da177e4SLinus Torvalds static void
check_extport(struct ahc_softc * ahc,u_int * sxfrctl1)12531da177e4SLinus Torvalds check_extport(struct ahc_softc *ahc, u_int *sxfrctl1)
12541da177e4SLinus Torvalds {
12551da177e4SLinus Torvalds struct seeprom_descriptor sd;
12561da177e4SLinus Torvalds struct seeprom_config *sc;
12571da177e4SLinus Torvalds int have_seeprom;
12581da177e4SLinus Torvalds int have_autoterm;
12591da177e4SLinus Torvalds
12601da177e4SLinus Torvalds sd.sd_ahc = ahc;
12611da177e4SLinus Torvalds sd.sd_control_offset = SEECTL;
12621da177e4SLinus Torvalds sd.sd_status_offset = SEECTL;
12631da177e4SLinus Torvalds sd.sd_dataout_offset = SEECTL;
12641da177e4SLinus Torvalds sc = ahc->seep_config;
12651da177e4SLinus Torvalds
12661da177e4SLinus Torvalds /*
12671da177e4SLinus Torvalds * For some multi-channel devices, the c46 is simply too
12681da177e4SLinus Torvalds * small to work. For the other controller types, we can
12691da177e4SLinus Torvalds * get our information from either SEEPROM type. Set the
12701da177e4SLinus Torvalds * type to start our probe with accordingly.
12711da177e4SLinus Torvalds */
12721da177e4SLinus Torvalds if (ahc->flags & AHC_LARGE_SEEPROM)
12731da177e4SLinus Torvalds sd.sd_chip = C56_66;
12741da177e4SLinus Torvalds else
12751da177e4SLinus Torvalds sd.sd_chip = C46;
12761da177e4SLinus Torvalds
12771da177e4SLinus Torvalds sd.sd_MS = SEEMS;
12781da177e4SLinus Torvalds sd.sd_RDY = SEERDY;
12791da177e4SLinus Torvalds sd.sd_CS = SEECS;
12801da177e4SLinus Torvalds sd.sd_CK = SEECK;
12811da177e4SLinus Torvalds sd.sd_DO = SEEDO;
12821da177e4SLinus Torvalds sd.sd_DI = SEEDI;
12831da177e4SLinus Torvalds
12841da177e4SLinus Torvalds have_seeprom = ahc_acquire_seeprom(ahc, &sd);
12851da177e4SLinus Torvalds if (have_seeprom) {
12861da177e4SLinus Torvalds
12871da177e4SLinus Torvalds if (bootverbose)
128848813cf9SPekka Enberg printk("%s: Reading SEEPROM...", ahc_name(ahc));
12891da177e4SLinus Torvalds
12901da177e4SLinus Torvalds for (;;) {
12911da177e4SLinus Torvalds u_int start_addr;
12921da177e4SLinus Torvalds
12931da177e4SLinus Torvalds start_addr = 32 * (ahc->channel - 'A');
12941da177e4SLinus Torvalds
12951da177e4SLinus Torvalds have_seeprom = ahc_read_seeprom(&sd, (uint16_t *)sc,
12961da177e4SLinus Torvalds start_addr,
12971da177e4SLinus Torvalds sizeof(*sc)/2);
12981da177e4SLinus Torvalds
12991da177e4SLinus Torvalds if (have_seeprom)
13001da177e4SLinus Torvalds have_seeprom = ahc_verify_cksum(sc);
13011da177e4SLinus Torvalds
13021da177e4SLinus Torvalds if (have_seeprom != 0 || sd.sd_chip == C56_66) {
13031da177e4SLinus Torvalds if (bootverbose) {
13041da177e4SLinus Torvalds if (have_seeprom == 0)
130548813cf9SPekka Enberg printk ("checksum error\n");
13061da177e4SLinus Torvalds else
130748813cf9SPekka Enberg printk ("done.\n");
13081da177e4SLinus Torvalds }
13091da177e4SLinus Torvalds break;
13101da177e4SLinus Torvalds }
13111da177e4SLinus Torvalds sd.sd_chip = C56_66;
13121da177e4SLinus Torvalds }
13131da177e4SLinus Torvalds ahc_release_seeprom(&sd);
13145e46631bSHannes Reinecke
13155e46631bSHannes Reinecke /* Remember the SEEPROM type for later */
13165e46631bSHannes Reinecke if (sd.sd_chip == C56_66)
13175e46631bSHannes Reinecke ahc->flags |= AHC_LARGE_SEEPROM;
13181da177e4SLinus Torvalds }
13191da177e4SLinus Torvalds
13201da177e4SLinus Torvalds if (!have_seeprom) {
13211da177e4SLinus Torvalds /*
13221da177e4SLinus Torvalds * Pull scratch ram settings and treat them as
13231da177e4SLinus Torvalds * if they are the contents of an seeprom if
13241da177e4SLinus Torvalds * the 'ADPT' signature is found in SCB2.
13251da177e4SLinus Torvalds * We manually compose the data as 16bit values
13261da177e4SLinus Torvalds * to avoid endian issues.
13271da177e4SLinus Torvalds */
13281da177e4SLinus Torvalds ahc_outb(ahc, SCBPTR, 2);
13291da177e4SLinus Torvalds if (ahc_inb(ahc, SCB_BASE) == 'A'
13301da177e4SLinus Torvalds && ahc_inb(ahc, SCB_BASE + 1) == 'D'
13311da177e4SLinus Torvalds && ahc_inb(ahc, SCB_BASE + 2) == 'P'
13321da177e4SLinus Torvalds && ahc_inb(ahc, SCB_BASE + 3) == 'T') {
13331da177e4SLinus Torvalds uint16_t *sc_data;
13341da177e4SLinus Torvalds int i;
13351da177e4SLinus Torvalds
13361da177e4SLinus Torvalds sc_data = (uint16_t *)sc;
13371da177e4SLinus Torvalds for (i = 0; i < 32; i++, sc_data++) {
13381da177e4SLinus Torvalds int j;
13391da177e4SLinus Torvalds
13401da177e4SLinus Torvalds j = i * 2;
13411da177e4SLinus Torvalds *sc_data = ahc_inb(ahc, SRAM_BASE + j)
13421da177e4SLinus Torvalds | ahc_inb(ahc, SRAM_BASE + j + 1) << 8;
13431da177e4SLinus Torvalds }
13441da177e4SLinus Torvalds have_seeprom = ahc_verify_cksum(sc);
13451da177e4SLinus Torvalds if (have_seeprom)
13461da177e4SLinus Torvalds ahc->flags |= AHC_SCB_CONFIG_USED;
13471da177e4SLinus Torvalds }
13481da177e4SLinus Torvalds /*
13491da177e4SLinus Torvalds * Clear any SCB parity errors in case this data and
13501da177e4SLinus Torvalds * its associated parity was not initialized by the BIOS
13511da177e4SLinus Torvalds */
13521da177e4SLinus Torvalds ahc_outb(ahc, CLRINT, CLRPARERR);
13531da177e4SLinus Torvalds ahc_outb(ahc, CLRINT, CLRBRKADRINT);
13541da177e4SLinus Torvalds }
13551da177e4SLinus Torvalds
13561da177e4SLinus Torvalds if (!have_seeprom) {
13571da177e4SLinus Torvalds if (bootverbose)
135848813cf9SPekka Enberg printk("%s: No SEEPROM available.\n", ahc_name(ahc));
13591da177e4SLinus Torvalds ahc->flags |= AHC_USEDEFAULTS;
136048813cf9SPekka Enberg kfree(ahc->seep_config);
13611da177e4SLinus Torvalds ahc->seep_config = NULL;
13621da177e4SLinus Torvalds sc = NULL;
13631da177e4SLinus Torvalds } else {
13641da177e4SLinus Torvalds ahc_parse_pci_eeprom(ahc, sc);
13651da177e4SLinus Torvalds }
13661da177e4SLinus Torvalds
13671da177e4SLinus Torvalds /*
13681da177e4SLinus Torvalds * Cards that have the external logic necessary to talk to
13691da177e4SLinus Torvalds * a SEEPROM, are almost certain to have the remaining logic
13701da177e4SLinus Torvalds * necessary for auto-termination control. This assumption
13711da177e4SLinus Torvalds * hasn't failed yet...
13721da177e4SLinus Torvalds */
13731da177e4SLinus Torvalds have_autoterm = have_seeprom;
13741da177e4SLinus Torvalds
13751da177e4SLinus Torvalds /*
13761da177e4SLinus Torvalds * Some low-cost chips have SEEPROM and auto-term control built
13771da177e4SLinus Torvalds * in, instead of using a GAL. They can tell us directly
13781da177e4SLinus Torvalds * if the termination logic is enabled.
13791da177e4SLinus Torvalds */
13801da177e4SLinus Torvalds if ((ahc->features & AHC_SPIOCAP) != 0) {
13811da177e4SLinus Torvalds if ((ahc_inb(ahc, SPIOCAP) & SSPIOCPS) == 0)
13821da177e4SLinus Torvalds have_autoterm = FALSE;
13831da177e4SLinus Torvalds }
13841da177e4SLinus Torvalds
13851da177e4SLinus Torvalds if (have_autoterm) {
13861da177e4SLinus Torvalds ahc->flags |= AHC_HAS_TERM_LOGIC;
13871da177e4SLinus Torvalds ahc_acquire_seeprom(ahc, &sd);
13881da177e4SLinus Torvalds configure_termination(ahc, &sd, sc->adapter_control, sxfrctl1);
13891da177e4SLinus Torvalds ahc_release_seeprom(&sd);
13901da177e4SLinus Torvalds } else if (have_seeprom) {
13911da177e4SLinus Torvalds *sxfrctl1 &= ~STPWEN;
13921da177e4SLinus Torvalds if ((sc->adapter_control & CFSTERM) != 0)
13931da177e4SLinus Torvalds *sxfrctl1 |= STPWEN;
13941da177e4SLinus Torvalds if (bootverbose)
139548813cf9SPekka Enberg printk("%s: Low byte termination %sabled\n",
13961da177e4SLinus Torvalds ahc_name(ahc),
13971da177e4SLinus Torvalds (*sxfrctl1 & STPWEN) ? "en" : "dis");
13981da177e4SLinus Torvalds }
13991da177e4SLinus Torvalds }
14001da177e4SLinus Torvalds
14011da177e4SLinus Torvalds static void
ahc_parse_pci_eeprom(struct ahc_softc * ahc,struct seeprom_config * sc)14021da177e4SLinus Torvalds ahc_parse_pci_eeprom(struct ahc_softc *ahc, struct seeprom_config *sc)
14031da177e4SLinus Torvalds {
14041da177e4SLinus Torvalds /*
14051da177e4SLinus Torvalds * Put the data we've collected down into SRAM
14061da177e4SLinus Torvalds * where ahc_init will find it.
14071da177e4SLinus Torvalds */
14081da177e4SLinus Torvalds int i;
14091da177e4SLinus Torvalds int max_targ = sc->max_targets & CFMAXTARG;
14101da177e4SLinus Torvalds u_int scsi_conf;
14111da177e4SLinus Torvalds uint16_t discenable;
14121da177e4SLinus Torvalds uint16_t ultraenb;
14131da177e4SLinus Torvalds
14141da177e4SLinus Torvalds discenable = 0;
14151da177e4SLinus Torvalds ultraenb = 0;
14161da177e4SLinus Torvalds if ((sc->adapter_control & CFULTRAEN) != 0) {
14171da177e4SLinus Torvalds /*
14181da177e4SLinus Torvalds * Determine if this adapter has a "newstyle"
14191da177e4SLinus Torvalds * SEEPROM format.
14201da177e4SLinus Torvalds */
14211da177e4SLinus Torvalds for (i = 0; i < max_targ; i++) {
14221da177e4SLinus Torvalds if ((sc->device_flags[i] & CFSYNCHISULTRA) != 0) {
14231da177e4SLinus Torvalds ahc->flags |= AHC_NEWEEPROM_FMT;
14241da177e4SLinus Torvalds break;
14251da177e4SLinus Torvalds }
14261da177e4SLinus Torvalds }
14271da177e4SLinus Torvalds }
14281da177e4SLinus Torvalds
14291da177e4SLinus Torvalds for (i = 0; i < max_targ; i++) {
14301da177e4SLinus Torvalds u_int scsirate;
14311da177e4SLinus Torvalds uint16_t target_mask;
14321da177e4SLinus Torvalds
14331da177e4SLinus Torvalds target_mask = 0x01 << i;
14341da177e4SLinus Torvalds if (sc->device_flags[i] & CFDISC)
14351da177e4SLinus Torvalds discenable |= target_mask;
14361da177e4SLinus Torvalds if ((ahc->flags & AHC_NEWEEPROM_FMT) != 0) {
14371da177e4SLinus Torvalds if ((sc->device_flags[i] & CFSYNCHISULTRA) != 0)
14381da177e4SLinus Torvalds ultraenb |= target_mask;
14391da177e4SLinus Torvalds } else if ((sc->adapter_control & CFULTRAEN) != 0) {
14401da177e4SLinus Torvalds ultraenb |= target_mask;
14411da177e4SLinus Torvalds }
14421da177e4SLinus Torvalds if ((sc->device_flags[i] & CFXFER) == 0x04
14431da177e4SLinus Torvalds && (ultraenb & target_mask) != 0) {
14441da177e4SLinus Torvalds /* Treat 10MHz as a non-ultra speed */
14451da177e4SLinus Torvalds sc->device_flags[i] &= ~CFXFER;
14461da177e4SLinus Torvalds ultraenb &= ~target_mask;
14471da177e4SLinus Torvalds }
14481da177e4SLinus Torvalds if ((ahc->features & AHC_ULTRA2) != 0) {
14491da177e4SLinus Torvalds u_int offset;
14501da177e4SLinus Torvalds
14511da177e4SLinus Torvalds if (sc->device_flags[i] & CFSYNCH)
14521da177e4SLinus Torvalds offset = MAX_OFFSET_ULTRA2;
14531da177e4SLinus Torvalds else
14541da177e4SLinus Torvalds offset = 0;
14551da177e4SLinus Torvalds ahc_outb(ahc, TARG_OFFSET + i, offset);
14561da177e4SLinus Torvalds
14571da177e4SLinus Torvalds /*
14581da177e4SLinus Torvalds * The ultra enable bits contain the
14591da177e4SLinus Torvalds * high bit of the ultra2 sync rate
14601da177e4SLinus Torvalds * field.
14611da177e4SLinus Torvalds */
14621da177e4SLinus Torvalds scsirate = (sc->device_flags[i] & CFXFER)
14631da177e4SLinus Torvalds | ((ultraenb & target_mask) ? 0x8 : 0x0);
14641da177e4SLinus Torvalds if (sc->device_flags[i] & CFWIDEB)
14651da177e4SLinus Torvalds scsirate |= WIDEXFER;
14661da177e4SLinus Torvalds } else {
14671da177e4SLinus Torvalds scsirate = (sc->device_flags[i] & CFXFER) << 4;
14681da177e4SLinus Torvalds if (sc->device_flags[i] & CFSYNCH)
14691da177e4SLinus Torvalds scsirate |= SOFS;
14701da177e4SLinus Torvalds if (sc->device_flags[i] & CFWIDEB)
14711da177e4SLinus Torvalds scsirate |= WIDEXFER;
14721da177e4SLinus Torvalds }
14731da177e4SLinus Torvalds ahc_outb(ahc, TARG_SCSIRATE + i, scsirate);
14741da177e4SLinus Torvalds }
14751da177e4SLinus Torvalds ahc->our_id = sc->brtime_id & CFSCSIID;
14761da177e4SLinus Torvalds
14771da177e4SLinus Torvalds scsi_conf = (ahc->our_id & 0x7);
14781da177e4SLinus Torvalds if (sc->adapter_control & CFSPARITY)
14791da177e4SLinus Torvalds scsi_conf |= ENSPCHK;
14801da177e4SLinus Torvalds if (sc->adapter_control & CFRESETB)
14811da177e4SLinus Torvalds scsi_conf |= RESET_SCSI;
14821da177e4SLinus Torvalds
14831da177e4SLinus Torvalds ahc->flags |= (sc->adapter_control & CFBOOTCHAN) >> CFBOOTCHANSHIFT;
14841da177e4SLinus Torvalds
14851da177e4SLinus Torvalds if (sc->bios_control & CFEXTEND)
14861da177e4SLinus Torvalds ahc->flags |= AHC_EXTENDED_TRANS_A;
14871da177e4SLinus Torvalds
14881da177e4SLinus Torvalds if (sc->bios_control & CFBIOSEN)
14891da177e4SLinus Torvalds ahc->flags |= AHC_BIOS_ENABLED;
14901da177e4SLinus Torvalds if (ahc->features & AHC_ULTRA
14911da177e4SLinus Torvalds && (ahc->flags & AHC_NEWEEPROM_FMT) == 0) {
14921da177e4SLinus Torvalds /* Should we enable Ultra mode? */
14931da177e4SLinus Torvalds if (!(sc->adapter_control & CFULTRAEN))
14941da177e4SLinus Torvalds /* Treat us as a non-ultra card */
14951da177e4SLinus Torvalds ultraenb = 0;
14961da177e4SLinus Torvalds }
14971da177e4SLinus Torvalds
14981da177e4SLinus Torvalds if (sc->signature == CFSIGNATURE
14991da177e4SLinus Torvalds || sc->signature == CFSIGNATURE2) {
15001da177e4SLinus Torvalds uint32_t devconfig;
15011da177e4SLinus Torvalds
15021da177e4SLinus Torvalds /* Honor the STPWLEVEL settings */
15031da177e4SLinus Torvalds devconfig = ahc_pci_read_config(ahc->dev_softc,
15041da177e4SLinus Torvalds DEVCONFIG, /*bytes*/4);
15051da177e4SLinus Torvalds devconfig &= ~STPWLEVEL;
15061da177e4SLinus Torvalds if ((sc->bios_control & CFSTPWLEVEL) != 0)
15071da177e4SLinus Torvalds devconfig |= STPWLEVEL;
15081da177e4SLinus Torvalds ahc_pci_write_config(ahc->dev_softc, DEVCONFIG,
15091da177e4SLinus Torvalds devconfig, /*bytes*/4);
15101da177e4SLinus Torvalds }
15111da177e4SLinus Torvalds /* Set SCSICONF info */
15121da177e4SLinus Torvalds ahc_outb(ahc, SCSICONF, scsi_conf);
15131da177e4SLinus Torvalds ahc_outb(ahc, DISC_DSB, ~(discenable & 0xff));
15141da177e4SLinus Torvalds ahc_outb(ahc, DISC_DSB + 1, ~((discenable >> 8) & 0xff));
15151da177e4SLinus Torvalds ahc_outb(ahc, ULTRA_ENB, ultraenb & 0xff);
15161da177e4SLinus Torvalds ahc_outb(ahc, ULTRA_ENB + 1, (ultraenb >> 8) & 0xff);
15171da177e4SLinus Torvalds }
15181da177e4SLinus Torvalds
15191da177e4SLinus Torvalds static void
configure_termination(struct ahc_softc * ahc,struct seeprom_descriptor * sd,u_int adapter_control,u_int * sxfrctl1)15201da177e4SLinus Torvalds configure_termination(struct ahc_softc *ahc,
15211da177e4SLinus Torvalds struct seeprom_descriptor *sd,
15221da177e4SLinus Torvalds u_int adapter_control,
15231da177e4SLinus Torvalds u_int *sxfrctl1)
15241da177e4SLinus Torvalds {
15251da177e4SLinus Torvalds uint8_t brddat;
15261da177e4SLinus Torvalds
15271da177e4SLinus Torvalds brddat = 0;
15281da177e4SLinus Torvalds
15291da177e4SLinus Torvalds /*
15301da177e4SLinus Torvalds * Update the settings in sxfrctl1 to match the
15311da177e4SLinus Torvalds * termination settings
15321da177e4SLinus Torvalds */
15331da177e4SLinus Torvalds *sxfrctl1 = 0;
15341da177e4SLinus Torvalds
15351da177e4SLinus Torvalds /*
15361da177e4SLinus Torvalds * SEECS must be on for the GALS to latch
15371da177e4SLinus Torvalds * the data properly. Be sure to leave MS
15381da177e4SLinus Torvalds * on or we will release the seeprom.
15391da177e4SLinus Torvalds */
15401da177e4SLinus Torvalds SEEPROM_OUTB(sd, sd->sd_MS | sd->sd_CS);
15411da177e4SLinus Torvalds if ((adapter_control & CFAUTOTERM) != 0
15421da177e4SLinus Torvalds || (ahc->features & AHC_NEW_TERMCTL) != 0) {
15431da177e4SLinus Torvalds int internal50_present;
15441da177e4SLinus Torvalds int internal68_present;
15451da177e4SLinus Torvalds int externalcable_present;
15461da177e4SLinus Torvalds int eeprom_present;
15471da177e4SLinus Torvalds int enableSEC_low;
15481da177e4SLinus Torvalds int enableSEC_high;
15491da177e4SLinus Torvalds int enablePRI_low;
15501da177e4SLinus Torvalds int enablePRI_high;
15511da177e4SLinus Torvalds int sum;
15521da177e4SLinus Torvalds
15531da177e4SLinus Torvalds enableSEC_low = 0;
15541da177e4SLinus Torvalds enableSEC_high = 0;
15551da177e4SLinus Torvalds enablePRI_low = 0;
15561da177e4SLinus Torvalds enablePRI_high = 0;
15571da177e4SLinus Torvalds if ((ahc->features & AHC_NEW_TERMCTL) != 0) {
15581da177e4SLinus Torvalds ahc_new_term_detect(ahc, &enableSEC_low,
15591da177e4SLinus Torvalds &enableSEC_high,
15601da177e4SLinus Torvalds &enablePRI_low,
15611da177e4SLinus Torvalds &enablePRI_high,
15621da177e4SLinus Torvalds &eeprom_present);
15631da177e4SLinus Torvalds if ((adapter_control & CFSEAUTOTERM) == 0) {
15641da177e4SLinus Torvalds if (bootverbose)
156548813cf9SPekka Enberg printk("%s: Manual SE Termination\n",
15661da177e4SLinus Torvalds ahc_name(ahc));
15671da177e4SLinus Torvalds enableSEC_low = (adapter_control & CFSELOWTERM);
15681da177e4SLinus Torvalds enableSEC_high =
15691da177e4SLinus Torvalds (adapter_control & CFSEHIGHTERM);
15701da177e4SLinus Torvalds }
15711da177e4SLinus Torvalds if ((adapter_control & CFAUTOTERM) == 0) {
15721da177e4SLinus Torvalds if (bootverbose)
157348813cf9SPekka Enberg printk("%s: Manual LVD Termination\n",
15741da177e4SLinus Torvalds ahc_name(ahc));
15751da177e4SLinus Torvalds enablePRI_low = (adapter_control & CFSTERM);
15761da177e4SLinus Torvalds enablePRI_high = (adapter_control & CFWSTERM);
15771da177e4SLinus Torvalds }
15781da177e4SLinus Torvalds /* Make the table calculations below happy */
15791da177e4SLinus Torvalds internal50_present = 0;
15801da177e4SLinus Torvalds internal68_present = 1;
15811da177e4SLinus Torvalds externalcable_present = 1;
15821da177e4SLinus Torvalds } else if ((ahc->features & AHC_SPIOCAP) != 0) {
15831da177e4SLinus Torvalds aic785X_cable_detect(ahc, &internal50_present,
15841da177e4SLinus Torvalds &externalcable_present,
15851da177e4SLinus Torvalds &eeprom_present);
15861da177e4SLinus Torvalds /* Can never support a wide connector. */
15871da177e4SLinus Torvalds internal68_present = 0;
15881da177e4SLinus Torvalds } else {
15891da177e4SLinus Torvalds aic787X_cable_detect(ahc, &internal50_present,
15901da177e4SLinus Torvalds &internal68_present,
15911da177e4SLinus Torvalds &externalcable_present,
15921da177e4SLinus Torvalds &eeprom_present);
15931da177e4SLinus Torvalds }
15941da177e4SLinus Torvalds
15951da177e4SLinus Torvalds if ((ahc->features & AHC_WIDE) == 0)
15961da177e4SLinus Torvalds internal68_present = 0;
15971da177e4SLinus Torvalds
15981da177e4SLinus Torvalds if (bootverbose
15991da177e4SLinus Torvalds && (ahc->features & AHC_ULTRA2) == 0) {
160048813cf9SPekka Enberg printk("%s: internal 50 cable %s present",
16011da177e4SLinus Torvalds ahc_name(ahc),
16021da177e4SLinus Torvalds internal50_present ? "is":"not");
16031da177e4SLinus Torvalds
16041da177e4SLinus Torvalds if ((ahc->features & AHC_WIDE) != 0)
160548813cf9SPekka Enberg printk(", internal 68 cable %s present",
16061da177e4SLinus Torvalds internal68_present ? "is":"not");
160748813cf9SPekka Enberg printk("\n%s: external cable %s present\n",
16081da177e4SLinus Torvalds ahc_name(ahc),
16091da177e4SLinus Torvalds externalcable_present ? "is":"not");
16101da177e4SLinus Torvalds }
16111da177e4SLinus Torvalds if (bootverbose)
161248813cf9SPekka Enberg printk("%s: BIOS eeprom %s present\n",
16131da177e4SLinus Torvalds ahc_name(ahc), eeprom_present ? "is" : "not");
16141da177e4SLinus Torvalds
16151da177e4SLinus Torvalds if ((ahc->flags & AHC_INT50_SPEEDFLEX) != 0) {
16161da177e4SLinus Torvalds /*
16171da177e4SLinus Torvalds * The 50 pin connector is a separate bus,
16181da177e4SLinus Torvalds * so force it to always be terminated.
16191da177e4SLinus Torvalds * In the future, perform current sensing
16201da177e4SLinus Torvalds * to determine if we are in the middle of
16211da177e4SLinus Torvalds * a properly terminated bus.
16221da177e4SLinus Torvalds */
16231da177e4SLinus Torvalds internal50_present = 0;
16241da177e4SLinus Torvalds }
16251da177e4SLinus Torvalds
16261da177e4SLinus Torvalds /*
16271da177e4SLinus Torvalds * Now set the termination based on what
16281da177e4SLinus Torvalds * we found.
16291da177e4SLinus Torvalds * Flash Enable = BRDDAT7
16301da177e4SLinus Torvalds * Secondary High Term Enable = BRDDAT6
16311da177e4SLinus Torvalds * Secondary Low Term Enable = BRDDAT5 (7890)
16321da177e4SLinus Torvalds * Primary High Term Enable = BRDDAT4 (7890)
16331da177e4SLinus Torvalds */
16341da177e4SLinus Torvalds if ((ahc->features & AHC_ULTRA2) == 0
16351da177e4SLinus Torvalds && (internal50_present != 0)
16361da177e4SLinus Torvalds && (internal68_present != 0)
16371da177e4SLinus Torvalds && (externalcable_present != 0)) {
163848813cf9SPekka Enberg printk("%s: Illegal cable configuration!!. "
16391da177e4SLinus Torvalds "Only two connectors on the "
16401da177e4SLinus Torvalds "adapter may be used at a "
16411da177e4SLinus Torvalds "time!\n", ahc_name(ahc));
16421da177e4SLinus Torvalds
16431da177e4SLinus Torvalds /*
16441da177e4SLinus Torvalds * Pretend there are no cables in the hope
16451da177e4SLinus Torvalds * that having all of the termination on
16461da177e4SLinus Torvalds * gives us a more stable bus.
16471da177e4SLinus Torvalds */
16481da177e4SLinus Torvalds internal50_present = 0;
16491da177e4SLinus Torvalds internal68_present = 0;
16501da177e4SLinus Torvalds externalcable_present = 0;
16511da177e4SLinus Torvalds }
16521da177e4SLinus Torvalds
16531da177e4SLinus Torvalds if ((ahc->features & AHC_WIDE) != 0
16541da177e4SLinus Torvalds && ((externalcable_present == 0)
16551da177e4SLinus Torvalds || (internal68_present == 0)
16561da177e4SLinus Torvalds || (enableSEC_high != 0))) {
16571da177e4SLinus Torvalds brddat |= BRDDAT6;
16581da177e4SLinus Torvalds if (bootverbose) {
16591da177e4SLinus Torvalds if ((ahc->flags & AHC_INT50_SPEEDFLEX) != 0)
166048813cf9SPekka Enberg printk("%s: 68 pin termination "
16611da177e4SLinus Torvalds "Enabled\n", ahc_name(ahc));
16621da177e4SLinus Torvalds else
166348813cf9SPekka Enberg printk("%s: %sHigh byte termination "
16641da177e4SLinus Torvalds "Enabled\n", ahc_name(ahc),
16651da177e4SLinus Torvalds enableSEC_high ? "Secondary "
16661da177e4SLinus Torvalds : "");
16671da177e4SLinus Torvalds }
16681da177e4SLinus Torvalds }
16691da177e4SLinus Torvalds
16701da177e4SLinus Torvalds sum = internal50_present + internal68_present
16711da177e4SLinus Torvalds + externalcable_present;
16721da177e4SLinus Torvalds if (sum < 2 || (enableSEC_low != 0)) {
16731da177e4SLinus Torvalds if ((ahc->features & AHC_ULTRA2) != 0)
16741da177e4SLinus Torvalds brddat |= BRDDAT5;
16751da177e4SLinus Torvalds else
16761da177e4SLinus Torvalds *sxfrctl1 |= STPWEN;
16771da177e4SLinus Torvalds if (bootverbose) {
16781da177e4SLinus Torvalds if ((ahc->flags & AHC_INT50_SPEEDFLEX) != 0)
167948813cf9SPekka Enberg printk("%s: 50 pin termination "
16801da177e4SLinus Torvalds "Enabled\n", ahc_name(ahc));
16811da177e4SLinus Torvalds else
168248813cf9SPekka Enberg printk("%s: %sLow byte termination "
16831da177e4SLinus Torvalds "Enabled\n", ahc_name(ahc),
16841da177e4SLinus Torvalds enableSEC_low ? "Secondary "
16851da177e4SLinus Torvalds : "");
16861da177e4SLinus Torvalds }
16871da177e4SLinus Torvalds }
16881da177e4SLinus Torvalds
16891da177e4SLinus Torvalds if (enablePRI_low != 0) {
16901da177e4SLinus Torvalds *sxfrctl1 |= STPWEN;
16911da177e4SLinus Torvalds if (bootverbose)
169248813cf9SPekka Enberg printk("%s: Primary Low Byte termination "
16931da177e4SLinus Torvalds "Enabled\n", ahc_name(ahc));
16941da177e4SLinus Torvalds }
16951da177e4SLinus Torvalds
16961da177e4SLinus Torvalds /*
16971da177e4SLinus Torvalds * Setup STPWEN before setting up the rest of
16981da177e4SLinus Torvalds * the termination per the tech note on the U160 cards.
16991da177e4SLinus Torvalds */
17001da177e4SLinus Torvalds ahc_outb(ahc, SXFRCTL1, *sxfrctl1);
17011da177e4SLinus Torvalds
17021da177e4SLinus Torvalds if (enablePRI_high != 0) {
17031da177e4SLinus Torvalds brddat |= BRDDAT4;
17041da177e4SLinus Torvalds if (bootverbose)
170548813cf9SPekka Enberg printk("%s: Primary High Byte "
17061da177e4SLinus Torvalds "termination Enabled\n",
17071da177e4SLinus Torvalds ahc_name(ahc));
17081da177e4SLinus Torvalds }
17091da177e4SLinus Torvalds
17101da177e4SLinus Torvalds write_brdctl(ahc, brddat);
17111da177e4SLinus Torvalds
17121da177e4SLinus Torvalds } else {
17131da177e4SLinus Torvalds if ((adapter_control & CFSTERM) != 0) {
17141da177e4SLinus Torvalds *sxfrctl1 |= STPWEN;
17151da177e4SLinus Torvalds
17161da177e4SLinus Torvalds if (bootverbose)
171748813cf9SPekka Enberg printk("%s: %sLow byte termination Enabled\n",
17181da177e4SLinus Torvalds ahc_name(ahc),
17191da177e4SLinus Torvalds (ahc->features & AHC_ULTRA2) ? "Primary "
17201da177e4SLinus Torvalds : "");
17211da177e4SLinus Torvalds }
17221da177e4SLinus Torvalds
17231da177e4SLinus Torvalds if ((adapter_control & CFWSTERM) != 0
17241da177e4SLinus Torvalds && (ahc->features & AHC_WIDE) != 0) {
17251da177e4SLinus Torvalds brddat |= BRDDAT6;
17261da177e4SLinus Torvalds if (bootverbose)
172748813cf9SPekka Enberg printk("%s: %sHigh byte termination Enabled\n",
17281da177e4SLinus Torvalds ahc_name(ahc),
17291da177e4SLinus Torvalds (ahc->features & AHC_ULTRA2)
17301da177e4SLinus Torvalds ? "Secondary " : "");
17311da177e4SLinus Torvalds }
17321da177e4SLinus Torvalds
17331da177e4SLinus Torvalds /*
17341da177e4SLinus Torvalds * Setup STPWEN before setting up the rest of
17351da177e4SLinus Torvalds * the termination per the tech note on the U160 cards.
17361da177e4SLinus Torvalds */
17371da177e4SLinus Torvalds ahc_outb(ahc, SXFRCTL1, *sxfrctl1);
17381da177e4SLinus Torvalds
17391da177e4SLinus Torvalds if ((ahc->features & AHC_WIDE) != 0)
17401da177e4SLinus Torvalds write_brdctl(ahc, brddat);
17411da177e4SLinus Torvalds }
17421da177e4SLinus Torvalds SEEPROM_OUTB(sd, sd->sd_MS); /* Clear CS */
17431da177e4SLinus Torvalds }
17441da177e4SLinus Torvalds
17451da177e4SLinus Torvalds static void
ahc_new_term_detect(struct ahc_softc * ahc,int * enableSEC_low,int * enableSEC_high,int * enablePRI_low,int * enablePRI_high,int * eeprom_present)17461da177e4SLinus Torvalds ahc_new_term_detect(struct ahc_softc *ahc, int *enableSEC_low,
17471da177e4SLinus Torvalds int *enableSEC_high, int *enablePRI_low,
17481da177e4SLinus Torvalds int *enablePRI_high, int *eeprom_present)
17491da177e4SLinus Torvalds {
17501da177e4SLinus Torvalds uint8_t brdctl;
17511da177e4SLinus Torvalds
17521da177e4SLinus Torvalds /*
17531da177e4SLinus Torvalds * BRDDAT7 = Eeprom
17541da177e4SLinus Torvalds * BRDDAT6 = Enable Secondary High Byte termination
17551da177e4SLinus Torvalds * BRDDAT5 = Enable Secondary Low Byte termination
17561da177e4SLinus Torvalds * BRDDAT4 = Enable Primary high byte termination
17571da177e4SLinus Torvalds * BRDDAT3 = Enable Primary low byte termination
17581da177e4SLinus Torvalds */
17591da177e4SLinus Torvalds brdctl = read_brdctl(ahc);
17601da177e4SLinus Torvalds *eeprom_present = brdctl & BRDDAT7;
17611da177e4SLinus Torvalds *enableSEC_high = (brdctl & BRDDAT6);
17621da177e4SLinus Torvalds *enableSEC_low = (brdctl & BRDDAT5);
17631da177e4SLinus Torvalds *enablePRI_high = (brdctl & BRDDAT4);
17641da177e4SLinus Torvalds *enablePRI_low = (brdctl & BRDDAT3);
17651da177e4SLinus Torvalds }
17661da177e4SLinus Torvalds
17671da177e4SLinus Torvalds static void
aic787X_cable_detect(struct ahc_softc * ahc,int * internal50_present,int * internal68_present,int * externalcable_present,int * eeprom_present)17681da177e4SLinus Torvalds aic787X_cable_detect(struct ahc_softc *ahc, int *internal50_present,
17691da177e4SLinus Torvalds int *internal68_present, int *externalcable_present,
17701da177e4SLinus Torvalds int *eeprom_present)
17711da177e4SLinus Torvalds {
17721da177e4SLinus Torvalds uint8_t brdctl;
17731da177e4SLinus Torvalds
17741da177e4SLinus Torvalds /*
17751da177e4SLinus Torvalds * First read the status of our cables.
17761da177e4SLinus Torvalds * Set the rom bank to 0 since the
17771da177e4SLinus Torvalds * bank setting serves as a multiplexor
17781da177e4SLinus Torvalds * for the cable detection logic.
17791da177e4SLinus Torvalds * BRDDAT5 controls the bank switch.
17801da177e4SLinus Torvalds */
17811da177e4SLinus Torvalds write_brdctl(ahc, 0);
17821da177e4SLinus Torvalds
17831da177e4SLinus Torvalds /*
17841da177e4SLinus Torvalds * Now read the state of the internal
17851da177e4SLinus Torvalds * connectors. BRDDAT6 is INT50 and
17861da177e4SLinus Torvalds * BRDDAT7 is INT68.
17871da177e4SLinus Torvalds */
17881da177e4SLinus Torvalds brdctl = read_brdctl(ahc);
17891da177e4SLinus Torvalds *internal50_present = (brdctl & BRDDAT6) ? 0 : 1;
17901da177e4SLinus Torvalds *internal68_present = (brdctl & BRDDAT7) ? 0 : 1;
17911da177e4SLinus Torvalds
17921da177e4SLinus Torvalds /*
17931da177e4SLinus Torvalds * Set the rom bank to 1 and determine
17941da177e4SLinus Torvalds * the other signals.
17951da177e4SLinus Torvalds */
17961da177e4SLinus Torvalds write_brdctl(ahc, BRDDAT5);
17971da177e4SLinus Torvalds
17981da177e4SLinus Torvalds /*
17991da177e4SLinus Torvalds * Now read the state of the external
18001da177e4SLinus Torvalds * connectors. BRDDAT6 is EXT68 and
18011da177e4SLinus Torvalds * BRDDAT7 is EPROMPS.
18021da177e4SLinus Torvalds */
18031da177e4SLinus Torvalds brdctl = read_brdctl(ahc);
18041da177e4SLinus Torvalds *externalcable_present = (brdctl & BRDDAT6) ? 0 : 1;
18051da177e4SLinus Torvalds *eeprom_present = (brdctl & BRDDAT7) ? 1 : 0;
18061da177e4SLinus Torvalds }
18071da177e4SLinus Torvalds
18081da177e4SLinus Torvalds static void
aic785X_cable_detect(struct ahc_softc * ahc,int * internal50_present,int * externalcable_present,int * eeprom_present)18091da177e4SLinus Torvalds aic785X_cable_detect(struct ahc_softc *ahc, int *internal50_present,
18101da177e4SLinus Torvalds int *externalcable_present, int *eeprom_present)
18111da177e4SLinus Torvalds {
18121da177e4SLinus Torvalds uint8_t brdctl;
18131da177e4SLinus Torvalds uint8_t spiocap;
18141da177e4SLinus Torvalds
18151da177e4SLinus Torvalds spiocap = ahc_inb(ahc, SPIOCAP);
18161da177e4SLinus Torvalds spiocap &= ~SOFTCMDEN;
18171da177e4SLinus Torvalds spiocap |= EXT_BRDCTL;
18181da177e4SLinus Torvalds ahc_outb(ahc, SPIOCAP, spiocap);
18191da177e4SLinus Torvalds ahc_outb(ahc, BRDCTL, BRDRW|BRDCS);
18201da177e4SLinus Torvalds ahc_flush_device_writes(ahc);
18211da177e4SLinus Torvalds ahc_delay(500);
18221da177e4SLinus Torvalds ahc_outb(ahc, BRDCTL, 0);
18231da177e4SLinus Torvalds ahc_flush_device_writes(ahc);
18241da177e4SLinus Torvalds ahc_delay(500);
18251da177e4SLinus Torvalds brdctl = ahc_inb(ahc, BRDCTL);
18261da177e4SLinus Torvalds *internal50_present = (brdctl & BRDDAT5) ? 0 : 1;
18271da177e4SLinus Torvalds *externalcable_present = (brdctl & BRDDAT6) ? 0 : 1;
18281da177e4SLinus Torvalds *eeprom_present = (ahc_inb(ahc, SPIOCAP) & EEPROM) ? 1 : 0;
18291da177e4SLinus Torvalds }
18301da177e4SLinus Torvalds
18311da177e4SLinus Torvalds int
ahc_acquire_seeprom(struct ahc_softc * ahc,struct seeprom_descriptor * sd)18321da177e4SLinus Torvalds ahc_acquire_seeprom(struct ahc_softc *ahc, struct seeprom_descriptor *sd)
18331da177e4SLinus Torvalds {
18341da177e4SLinus Torvalds int wait;
18351da177e4SLinus Torvalds
18361da177e4SLinus Torvalds if ((ahc->features & AHC_SPIOCAP) != 0
18371da177e4SLinus Torvalds && (ahc_inb(ahc, SPIOCAP) & SEEPROM) == 0)
18381da177e4SLinus Torvalds return (0);
18391da177e4SLinus Torvalds
18401da177e4SLinus Torvalds /*
18411da177e4SLinus Torvalds * Request access of the memory port. When access is
18421da177e4SLinus Torvalds * granted, SEERDY will go high. We use a 1 second
18431da177e4SLinus Torvalds * timeout which should be near 1 second more than
18441da177e4SLinus Torvalds * is needed. Reason: after the chip reset, there
18451da177e4SLinus Torvalds * should be no contention.
18461da177e4SLinus Torvalds */
18471da177e4SLinus Torvalds SEEPROM_OUTB(sd, sd->sd_MS);
18481da177e4SLinus Torvalds wait = 1000; /* 1 second timeout in msec */
18491da177e4SLinus Torvalds while (--wait && ((SEEPROM_STATUS_INB(sd) & sd->sd_RDY) == 0)) {
18501da177e4SLinus Torvalds ahc_delay(1000); /* delay 1 msec */
18511da177e4SLinus Torvalds }
18521da177e4SLinus Torvalds if ((SEEPROM_STATUS_INB(sd) & sd->sd_RDY) == 0) {
18531da177e4SLinus Torvalds SEEPROM_OUTB(sd, 0);
18541da177e4SLinus Torvalds return (0);
18551da177e4SLinus Torvalds }
18561da177e4SLinus Torvalds return(1);
18571da177e4SLinus Torvalds }
18581da177e4SLinus Torvalds
18591da177e4SLinus Torvalds void
ahc_release_seeprom(struct seeprom_descriptor * sd)18601da177e4SLinus Torvalds ahc_release_seeprom(struct seeprom_descriptor *sd)
18611da177e4SLinus Torvalds {
18621da177e4SLinus Torvalds /* Release access to the memory port and the serial EEPROM. */
18631da177e4SLinus Torvalds SEEPROM_OUTB(sd, 0);
18641da177e4SLinus Torvalds }
18651da177e4SLinus Torvalds
18661da177e4SLinus Torvalds static void
write_brdctl(struct ahc_softc * ahc,uint8_t value)18671da177e4SLinus Torvalds write_brdctl(struct ahc_softc *ahc, uint8_t value)
18681da177e4SLinus Torvalds {
18691da177e4SLinus Torvalds uint8_t brdctl;
18701da177e4SLinus Torvalds
18711da177e4SLinus Torvalds if ((ahc->chip & AHC_CHIPID_MASK) == AHC_AIC7895) {
18721da177e4SLinus Torvalds brdctl = BRDSTB;
18731da177e4SLinus Torvalds if (ahc->channel == 'B')
18741da177e4SLinus Torvalds brdctl |= BRDCS;
18751da177e4SLinus Torvalds } else if ((ahc->features & AHC_ULTRA2) != 0) {
18761da177e4SLinus Torvalds brdctl = 0;
18771da177e4SLinus Torvalds } else {
18781da177e4SLinus Torvalds brdctl = BRDSTB|BRDCS;
18791da177e4SLinus Torvalds }
18801da177e4SLinus Torvalds ahc_outb(ahc, BRDCTL, brdctl);
18811da177e4SLinus Torvalds ahc_flush_device_writes(ahc);
18821da177e4SLinus Torvalds brdctl |= value;
18831da177e4SLinus Torvalds ahc_outb(ahc, BRDCTL, brdctl);
18841da177e4SLinus Torvalds ahc_flush_device_writes(ahc);
18851da177e4SLinus Torvalds if ((ahc->features & AHC_ULTRA2) != 0)
18861da177e4SLinus Torvalds brdctl |= BRDSTB_ULTRA2;
18871da177e4SLinus Torvalds else
18881da177e4SLinus Torvalds brdctl &= ~BRDSTB;
18891da177e4SLinus Torvalds ahc_outb(ahc, BRDCTL, brdctl);
18901da177e4SLinus Torvalds ahc_flush_device_writes(ahc);
18911da177e4SLinus Torvalds if ((ahc->features & AHC_ULTRA2) != 0)
18921da177e4SLinus Torvalds brdctl = 0;
18931da177e4SLinus Torvalds else
18941da177e4SLinus Torvalds brdctl &= ~BRDCS;
18951da177e4SLinus Torvalds ahc_outb(ahc, BRDCTL, brdctl);
18961da177e4SLinus Torvalds }
18971da177e4SLinus Torvalds
18981da177e4SLinus Torvalds static uint8_t
read_brdctl(struct ahc_softc * ahc)18991da177e4SLinus Torvalds read_brdctl(struct ahc_softc *ahc)
19001da177e4SLinus Torvalds {
19011da177e4SLinus Torvalds uint8_t brdctl;
19021da177e4SLinus Torvalds uint8_t value;
19031da177e4SLinus Torvalds
19041da177e4SLinus Torvalds if ((ahc->chip & AHC_CHIPID_MASK) == AHC_AIC7895) {
19051da177e4SLinus Torvalds brdctl = BRDRW;
19061da177e4SLinus Torvalds if (ahc->channel == 'B')
19071da177e4SLinus Torvalds brdctl |= BRDCS;
19081da177e4SLinus Torvalds } else if ((ahc->features & AHC_ULTRA2) != 0) {
19091da177e4SLinus Torvalds brdctl = BRDRW_ULTRA2;
19101da177e4SLinus Torvalds } else {
19111da177e4SLinus Torvalds brdctl = BRDRW|BRDCS;
19121da177e4SLinus Torvalds }
19131da177e4SLinus Torvalds ahc_outb(ahc, BRDCTL, brdctl);
19141da177e4SLinus Torvalds ahc_flush_device_writes(ahc);
19151da177e4SLinus Torvalds value = ahc_inb(ahc, BRDCTL);
19161da177e4SLinus Torvalds ahc_outb(ahc, BRDCTL, 0);
19171da177e4SLinus Torvalds return (value);
19181da177e4SLinus Torvalds }
19191da177e4SLinus Torvalds
19201da177e4SLinus Torvalds static void
ahc_pci_intr(struct ahc_softc * ahc)19211da177e4SLinus Torvalds ahc_pci_intr(struct ahc_softc *ahc)
19221da177e4SLinus Torvalds {
19231da177e4SLinus Torvalds u_int error;
19241da177e4SLinus Torvalds u_int status1;
19251da177e4SLinus Torvalds
19261da177e4SLinus Torvalds error = ahc_inb(ahc, ERROR);
19271da177e4SLinus Torvalds if ((error & PCIERRSTAT) == 0)
19281da177e4SLinus Torvalds return;
19291da177e4SLinus Torvalds
19301da177e4SLinus Torvalds status1 = ahc_pci_read_config(ahc->dev_softc,
19311da177e4SLinus Torvalds PCIR_STATUS + 1, /*bytes*/1);
19321da177e4SLinus Torvalds
193348813cf9SPekka Enberg printk("%s: PCI error Interrupt at seqaddr = 0x%x\n",
19341da177e4SLinus Torvalds ahc_name(ahc),
19351da177e4SLinus Torvalds ahc_inb(ahc, SEQADDR0) | (ahc_inb(ahc, SEQADDR1) << 8));
19361da177e4SLinus Torvalds
19371da177e4SLinus Torvalds if (status1 & DPE) {
19381da177e4SLinus Torvalds ahc->pci_target_perr_count++;
193948813cf9SPekka Enberg printk("%s: Data Parity Error Detected during address "
19401da177e4SLinus Torvalds "or write data phase\n", ahc_name(ahc));
19411da177e4SLinus Torvalds }
19421da177e4SLinus Torvalds if (status1 & SSE) {
194348813cf9SPekka Enberg printk("%s: Signal System Error Detected\n", ahc_name(ahc));
19441da177e4SLinus Torvalds }
19451da177e4SLinus Torvalds if (status1 & RMA) {
194648813cf9SPekka Enberg printk("%s: Received a Master Abort\n", ahc_name(ahc));
19471da177e4SLinus Torvalds }
19481da177e4SLinus Torvalds if (status1 & RTA) {
194948813cf9SPekka Enberg printk("%s: Received a Target Abort\n", ahc_name(ahc));
19501da177e4SLinus Torvalds }
19511da177e4SLinus Torvalds if (status1 & STA) {
195248813cf9SPekka Enberg printk("%s: Signaled a Target Abort\n", ahc_name(ahc));
19531da177e4SLinus Torvalds }
19541da177e4SLinus Torvalds if (status1 & DPR) {
195548813cf9SPekka Enberg printk("%s: Data Parity Error has been reported via PERR#\n",
19561da177e4SLinus Torvalds ahc_name(ahc));
19571da177e4SLinus Torvalds }
19581da177e4SLinus Torvalds
19591da177e4SLinus Torvalds /* Clear latched errors. */
19601da177e4SLinus Torvalds ahc_pci_write_config(ahc->dev_softc, PCIR_STATUS + 1,
19611da177e4SLinus Torvalds status1, /*bytes*/1);
19621da177e4SLinus Torvalds
19631da177e4SLinus Torvalds if ((status1 & (DPE|SSE|RMA|RTA|STA|DPR)) == 0) {
196448813cf9SPekka Enberg printk("%s: Latched PCIERR interrupt with "
19651da177e4SLinus Torvalds "no status bits set\n", ahc_name(ahc));
19661da177e4SLinus Torvalds } else {
19671da177e4SLinus Torvalds ahc_outb(ahc, CLRINT, CLRPARERR);
19681da177e4SLinus Torvalds }
19691da177e4SLinus Torvalds
19701da177e4SLinus Torvalds if (ahc->pci_target_perr_count > AHC_PCI_TARGET_PERR_THRESH) {
197148813cf9SPekka Enberg printk(
19721da177e4SLinus Torvalds "%s: WARNING WARNING WARNING WARNING\n"
19731da177e4SLinus Torvalds "%s: Too many PCI parity errors observed as a target.\n"
19741da177e4SLinus Torvalds "%s: Some device on this bus is generating bad parity.\n"
19751da177e4SLinus Torvalds "%s: This is an error *observed by*, not *generated by*, this controller.\n"
19761da177e4SLinus Torvalds "%s: PCI parity error checking has been disabled.\n"
19771da177e4SLinus Torvalds "%s: WARNING WARNING WARNING WARNING\n",
19781da177e4SLinus Torvalds ahc_name(ahc), ahc_name(ahc), ahc_name(ahc),
19791da177e4SLinus Torvalds ahc_name(ahc), ahc_name(ahc), ahc_name(ahc));
19801da177e4SLinus Torvalds ahc->seqctl |= FAILDIS;
19811da177e4SLinus Torvalds ahc_outb(ahc, SEQCTL, ahc->seqctl);
19821da177e4SLinus Torvalds }
19831da177e4SLinus Torvalds ahc_unpause(ahc);
19841da177e4SLinus Torvalds }
19851da177e4SLinus Torvalds
19861da177e4SLinus Torvalds static int
ahc_pci_chip_init(struct ahc_softc * ahc)19871da177e4SLinus Torvalds ahc_pci_chip_init(struct ahc_softc *ahc)
19881da177e4SLinus Torvalds {
19891da177e4SLinus Torvalds ahc_outb(ahc, DSCOMMAND0, ahc->bus_softc.pci_softc.dscommand0);
19901da177e4SLinus Torvalds ahc_outb(ahc, DSPCISTATUS, ahc->bus_softc.pci_softc.dspcistatus);
19911da177e4SLinus Torvalds if ((ahc->features & AHC_DT) != 0) {
19921da177e4SLinus Torvalds u_int sfunct;
19931da177e4SLinus Torvalds
19941da177e4SLinus Torvalds sfunct = ahc_inb(ahc, SFUNCT) & ~ALT_MODE;
19951da177e4SLinus Torvalds ahc_outb(ahc, SFUNCT, sfunct | ALT_MODE);
19961da177e4SLinus Torvalds ahc_outb(ahc, OPTIONMODE, ahc->bus_softc.pci_softc.optionmode);
19971da177e4SLinus Torvalds ahc_outw(ahc, TARGCRCCNT, ahc->bus_softc.pci_softc.targcrccnt);
19981da177e4SLinus Torvalds ahc_outb(ahc, SFUNCT, sfunct);
19991da177e4SLinus Torvalds ahc_outb(ahc, CRCCONTROL1,
20001da177e4SLinus Torvalds ahc->bus_softc.pci_softc.crccontrol1);
20011da177e4SLinus Torvalds }
20021da177e4SLinus Torvalds if ((ahc->features & AHC_MULTI_FUNC) != 0)
20031da177e4SLinus Torvalds ahc_outb(ahc, SCBBADDR, ahc->bus_softc.pci_softc.scbbaddr);
20041da177e4SLinus Torvalds
20051da177e4SLinus Torvalds if ((ahc->features & AHC_ULTRA2) != 0)
20061da177e4SLinus Torvalds ahc_outb(ahc, DFF_THRSH, ahc->bus_softc.pci_softc.dff_thrsh);
20071da177e4SLinus Torvalds
20081da177e4SLinus Torvalds return (ahc_chip_init(ahc));
20091da177e4SLinus Torvalds }
20101da177e4SLinus Torvalds
20116897b9a1SVaibhav Gupta void __maybe_unused
ahc_pci_resume(struct ahc_softc * ahc)20121da177e4SLinus Torvalds ahc_pci_resume(struct ahc_softc *ahc)
20131da177e4SLinus Torvalds {
20141da177e4SLinus Torvalds /*
20151da177e4SLinus Torvalds * We assume that the OS has restored our register
20161da177e4SLinus Torvalds * mappings, etc. Just update the config space registers
20171da177e4SLinus Torvalds * that the OS doesn't know about and rely on our chip
20181da177e4SLinus Torvalds * reset handler to handle the rest.
20191da177e4SLinus Torvalds */
2020c42bcefbSDenis Vlasenko ahc_pci_write_config(ahc->dev_softc, DEVCONFIG,
2021c42bcefbSDenis Vlasenko ahc->bus_softc.pci_softc.devconfig, /*bytes*/4);
2022c42bcefbSDenis Vlasenko ahc_pci_write_config(ahc->dev_softc, PCIR_COMMAND,
2023c42bcefbSDenis Vlasenko ahc->bus_softc.pci_softc.command, /*bytes*/1);
2024c42bcefbSDenis Vlasenko ahc_pci_write_config(ahc->dev_softc, CSIZE_LATTIME,
2025c42bcefbSDenis Vlasenko ahc->bus_softc.pci_softc.csize_lattime, /*bytes*/1);
20261da177e4SLinus Torvalds if ((ahc->flags & AHC_HAS_TERM_LOGIC) != 0) {
20271da177e4SLinus Torvalds struct seeprom_descriptor sd;
20281da177e4SLinus Torvalds u_int sxfrctl1;
20291da177e4SLinus Torvalds
20301da177e4SLinus Torvalds sd.sd_ahc = ahc;
20311da177e4SLinus Torvalds sd.sd_control_offset = SEECTL;
20321da177e4SLinus Torvalds sd.sd_status_offset = SEECTL;
20331da177e4SLinus Torvalds sd.sd_dataout_offset = SEECTL;
20341da177e4SLinus Torvalds
20351da177e4SLinus Torvalds ahc_acquire_seeprom(ahc, &sd);
20361da177e4SLinus Torvalds configure_termination(ahc, &sd,
20371da177e4SLinus Torvalds ahc->seep_config->adapter_control,
20381da177e4SLinus Torvalds &sxfrctl1);
20391da177e4SLinus Torvalds ahc_release_seeprom(&sd);
20401da177e4SLinus Torvalds }
20411da177e4SLinus Torvalds }
20421da177e4SLinus Torvalds
20431da177e4SLinus Torvalds static int
ahc_aic785X_setup(struct ahc_softc * ahc)20441da177e4SLinus Torvalds ahc_aic785X_setup(struct ahc_softc *ahc)
20451da177e4SLinus Torvalds {
20461da177e4SLinus Torvalds ahc_dev_softc_t pci;
20471da177e4SLinus Torvalds uint8_t rev;
20481da177e4SLinus Torvalds
20491da177e4SLinus Torvalds pci = ahc->dev_softc;
20501da177e4SLinus Torvalds ahc->channel = 'A';
20511da177e4SLinus Torvalds ahc->chip = AHC_AIC7850;
20521da177e4SLinus Torvalds ahc->features = AHC_AIC7850_FE;
20531da177e4SLinus Torvalds ahc->bugs |= AHC_TMODE_WIDEODD_BUG|AHC_CACHETHEN_BUG|AHC_PCI_MWI_BUG;
20541da177e4SLinus Torvalds rev = ahc_pci_read_config(pci, PCIR_REVID, /*bytes*/1);
20551da177e4SLinus Torvalds if (rev >= 1)
20561da177e4SLinus Torvalds ahc->bugs |= AHC_PCI_2_1_RETRY_BUG;
20571da177e4SLinus Torvalds ahc->instruction_ram_size = 512;
20581da177e4SLinus Torvalds return (0);
20591da177e4SLinus Torvalds }
20601da177e4SLinus Torvalds
20611da177e4SLinus Torvalds static int
ahc_aic7860_setup(struct ahc_softc * ahc)20621da177e4SLinus Torvalds ahc_aic7860_setup(struct ahc_softc *ahc)
20631da177e4SLinus Torvalds {
20641da177e4SLinus Torvalds ahc_dev_softc_t pci;
20651da177e4SLinus Torvalds uint8_t rev;
20661da177e4SLinus Torvalds
20671da177e4SLinus Torvalds pci = ahc->dev_softc;
20681da177e4SLinus Torvalds ahc->channel = 'A';
20691da177e4SLinus Torvalds ahc->chip = AHC_AIC7860;
20701da177e4SLinus Torvalds ahc->features = AHC_AIC7860_FE;
20711da177e4SLinus Torvalds ahc->bugs |= AHC_TMODE_WIDEODD_BUG|AHC_CACHETHEN_BUG|AHC_PCI_MWI_BUG;
20721da177e4SLinus Torvalds rev = ahc_pci_read_config(pci, PCIR_REVID, /*bytes*/1);
20731da177e4SLinus Torvalds if (rev >= 1)
20741da177e4SLinus Torvalds ahc->bugs |= AHC_PCI_2_1_RETRY_BUG;
20751da177e4SLinus Torvalds ahc->instruction_ram_size = 512;
20761da177e4SLinus Torvalds return (0);
20771da177e4SLinus Torvalds }
20781da177e4SLinus Torvalds
20791da177e4SLinus Torvalds static int
ahc_apa1480_setup(struct ahc_softc * ahc)20801da177e4SLinus Torvalds ahc_apa1480_setup(struct ahc_softc *ahc)
20811da177e4SLinus Torvalds {
20821da177e4SLinus Torvalds int error;
20831da177e4SLinus Torvalds
20841da177e4SLinus Torvalds error = ahc_aic7860_setup(ahc);
20851da177e4SLinus Torvalds if (error != 0)
20861da177e4SLinus Torvalds return (error);
20871da177e4SLinus Torvalds ahc->features |= AHC_REMOVABLE;
20881da177e4SLinus Torvalds return (0);
20891da177e4SLinus Torvalds }
20901da177e4SLinus Torvalds
20911da177e4SLinus Torvalds static int
ahc_aic7870_setup(struct ahc_softc * ahc)20921da177e4SLinus Torvalds ahc_aic7870_setup(struct ahc_softc *ahc)
20931da177e4SLinus Torvalds {
20941da177e4SLinus Torvalds
20951da177e4SLinus Torvalds ahc->channel = 'A';
20961da177e4SLinus Torvalds ahc->chip = AHC_AIC7870;
20971da177e4SLinus Torvalds ahc->features = AHC_AIC7870_FE;
20981da177e4SLinus Torvalds ahc->bugs |= AHC_TMODE_WIDEODD_BUG|AHC_CACHETHEN_BUG|AHC_PCI_MWI_BUG;
20991da177e4SLinus Torvalds ahc->instruction_ram_size = 512;
21001da177e4SLinus Torvalds return (0);
21011da177e4SLinus Torvalds }
21021da177e4SLinus Torvalds
21031da177e4SLinus Torvalds static int
ahc_aic7870h_setup(struct ahc_softc * ahc)2104b2d8bfe1SJames Bottomley ahc_aic7870h_setup(struct ahc_softc *ahc)
2105b2d8bfe1SJames Bottomley {
2106b2d8bfe1SJames Bottomley int error = ahc_aic7870_setup(ahc);
2107b2d8bfe1SJames Bottomley
2108b2d8bfe1SJames Bottomley ahc->features |= AHC_HVD;
2109b2d8bfe1SJames Bottomley
2110b2d8bfe1SJames Bottomley return error;
2111b2d8bfe1SJames Bottomley }
2112b2d8bfe1SJames Bottomley
2113b2d8bfe1SJames Bottomley static int
ahc_aha394X_setup(struct ahc_softc * ahc)21141da177e4SLinus Torvalds ahc_aha394X_setup(struct ahc_softc *ahc)
21151da177e4SLinus Torvalds {
21161da177e4SLinus Torvalds int error;
21171da177e4SLinus Torvalds
21181da177e4SLinus Torvalds error = ahc_aic7870_setup(ahc);
21191da177e4SLinus Torvalds if (error == 0)
21201da177e4SLinus Torvalds error = ahc_aha394XX_setup(ahc);
21211da177e4SLinus Torvalds return (error);
21221da177e4SLinus Torvalds }
21231da177e4SLinus Torvalds
21241da177e4SLinus Torvalds static int
ahc_aha394Xh_setup(struct ahc_softc * ahc)2125b2d8bfe1SJames Bottomley ahc_aha394Xh_setup(struct ahc_softc *ahc)
2126b2d8bfe1SJames Bottomley {
2127b2d8bfe1SJames Bottomley int error = ahc_aha394X_setup(ahc);
2128b2d8bfe1SJames Bottomley
2129b2d8bfe1SJames Bottomley ahc->features |= AHC_HVD;
2130b2d8bfe1SJames Bottomley
2131b2d8bfe1SJames Bottomley return error;
2132b2d8bfe1SJames Bottomley }
2133b2d8bfe1SJames Bottomley
2134b2d8bfe1SJames Bottomley static int
ahc_aha398X_setup(struct ahc_softc * ahc)21351da177e4SLinus Torvalds ahc_aha398X_setup(struct ahc_softc *ahc)
21361da177e4SLinus Torvalds {
21371da177e4SLinus Torvalds int error;
21381da177e4SLinus Torvalds
21391da177e4SLinus Torvalds error = ahc_aic7870_setup(ahc);
21401da177e4SLinus Torvalds if (error == 0)
21411da177e4SLinus Torvalds error = ahc_aha398XX_setup(ahc);
21421da177e4SLinus Torvalds return (error);
21431da177e4SLinus Torvalds }
21441da177e4SLinus Torvalds
21451da177e4SLinus Torvalds static int
ahc_aha494X_setup(struct ahc_softc * ahc)21461da177e4SLinus Torvalds ahc_aha494X_setup(struct ahc_softc *ahc)
21471da177e4SLinus Torvalds {
21481da177e4SLinus Torvalds int error;
21491da177e4SLinus Torvalds
21501da177e4SLinus Torvalds error = ahc_aic7870_setup(ahc);
21511da177e4SLinus Torvalds if (error == 0)
21521da177e4SLinus Torvalds error = ahc_aha494XX_setup(ahc);
21531da177e4SLinus Torvalds return (error);
21541da177e4SLinus Torvalds }
21551da177e4SLinus Torvalds
21561da177e4SLinus Torvalds static int
ahc_aha494Xh_setup(struct ahc_softc * ahc)2157b2d8bfe1SJames Bottomley ahc_aha494Xh_setup(struct ahc_softc *ahc)
2158b2d8bfe1SJames Bottomley {
2159b2d8bfe1SJames Bottomley int error = ahc_aha494X_setup(ahc);
2160b2d8bfe1SJames Bottomley
2161b2d8bfe1SJames Bottomley ahc->features |= AHC_HVD;
2162b2d8bfe1SJames Bottomley
2163b2d8bfe1SJames Bottomley return error;
2164b2d8bfe1SJames Bottomley }
2165b2d8bfe1SJames Bottomley
2166b2d8bfe1SJames Bottomley static int
ahc_aic7880_setup(struct ahc_softc * ahc)21671da177e4SLinus Torvalds ahc_aic7880_setup(struct ahc_softc *ahc)
21681da177e4SLinus Torvalds {
21691da177e4SLinus Torvalds ahc_dev_softc_t pci;
21701da177e4SLinus Torvalds uint8_t rev;
21711da177e4SLinus Torvalds
21721da177e4SLinus Torvalds pci = ahc->dev_softc;
21731da177e4SLinus Torvalds ahc->channel = 'A';
21741da177e4SLinus Torvalds ahc->chip = AHC_AIC7880;
21751da177e4SLinus Torvalds ahc->features = AHC_AIC7880_FE;
21761da177e4SLinus Torvalds ahc->bugs |= AHC_TMODE_WIDEODD_BUG;
21771da177e4SLinus Torvalds rev = ahc_pci_read_config(pci, PCIR_REVID, /*bytes*/1);
21781da177e4SLinus Torvalds if (rev >= 1) {
21791da177e4SLinus Torvalds ahc->bugs |= AHC_PCI_2_1_RETRY_BUG;
21801da177e4SLinus Torvalds } else {
21811da177e4SLinus Torvalds ahc->bugs |= AHC_CACHETHEN_BUG|AHC_PCI_MWI_BUG;
21821da177e4SLinus Torvalds }
21831da177e4SLinus Torvalds ahc->instruction_ram_size = 512;
21841da177e4SLinus Torvalds return (0);
21851da177e4SLinus Torvalds }
21861da177e4SLinus Torvalds
21871da177e4SLinus Torvalds static int
ahc_aic7880h_setup(struct ahc_softc * ahc)2188b2d8bfe1SJames Bottomley ahc_aic7880h_setup(struct ahc_softc *ahc)
2189b2d8bfe1SJames Bottomley {
2190b2d8bfe1SJames Bottomley int error = ahc_aic7880_setup(ahc);
2191b2d8bfe1SJames Bottomley
2192b2d8bfe1SJames Bottomley ahc->features |= AHC_HVD;
2193b2d8bfe1SJames Bottomley
2194b2d8bfe1SJames Bottomley return error;
2195b2d8bfe1SJames Bottomley }
2196b2d8bfe1SJames Bottomley
2197b2d8bfe1SJames Bottomley
2198b2d8bfe1SJames Bottomley static int
ahc_aha2940Pro_setup(struct ahc_softc * ahc)21991da177e4SLinus Torvalds ahc_aha2940Pro_setup(struct ahc_softc *ahc)
22001da177e4SLinus Torvalds {
22011da177e4SLinus Torvalds
22021da177e4SLinus Torvalds ahc->flags |= AHC_INT50_SPEEDFLEX;
22031da177e4SLinus Torvalds return (ahc_aic7880_setup(ahc));
22041da177e4SLinus Torvalds }
22051da177e4SLinus Torvalds
22061da177e4SLinus Torvalds static int
ahc_aha394XU_setup(struct ahc_softc * ahc)22071da177e4SLinus Torvalds ahc_aha394XU_setup(struct ahc_softc *ahc)
22081da177e4SLinus Torvalds {
22091da177e4SLinus Torvalds int error;
22101da177e4SLinus Torvalds
22111da177e4SLinus Torvalds error = ahc_aic7880_setup(ahc);
22121da177e4SLinus Torvalds if (error == 0)
22131da177e4SLinus Torvalds error = ahc_aha394XX_setup(ahc);
22141da177e4SLinus Torvalds return (error);
22151da177e4SLinus Torvalds }
22161da177e4SLinus Torvalds
22171da177e4SLinus Torvalds static int
ahc_aha394XUh_setup(struct ahc_softc * ahc)2218b2d8bfe1SJames Bottomley ahc_aha394XUh_setup(struct ahc_softc *ahc)
2219b2d8bfe1SJames Bottomley {
2220b2d8bfe1SJames Bottomley int error = ahc_aha394XU_setup(ahc);
2221b2d8bfe1SJames Bottomley
2222b2d8bfe1SJames Bottomley ahc->features |= AHC_HVD;
2223b2d8bfe1SJames Bottomley
2224b2d8bfe1SJames Bottomley return error;
2225b2d8bfe1SJames Bottomley }
2226b2d8bfe1SJames Bottomley
2227b2d8bfe1SJames Bottomley static int
ahc_aha398XU_setup(struct ahc_softc * ahc)22281da177e4SLinus Torvalds ahc_aha398XU_setup(struct ahc_softc *ahc)
22291da177e4SLinus Torvalds {
22301da177e4SLinus Torvalds int error;
22311da177e4SLinus Torvalds
22321da177e4SLinus Torvalds error = ahc_aic7880_setup(ahc);
22331da177e4SLinus Torvalds if (error == 0)
22341da177e4SLinus Torvalds error = ahc_aha398XX_setup(ahc);
22351da177e4SLinus Torvalds return (error);
22361da177e4SLinus Torvalds }
22371da177e4SLinus Torvalds
22381da177e4SLinus Torvalds static int
ahc_aic7890_setup(struct ahc_softc * ahc)22391da177e4SLinus Torvalds ahc_aic7890_setup(struct ahc_softc *ahc)
22401da177e4SLinus Torvalds {
22411da177e4SLinus Torvalds ahc_dev_softc_t pci;
22421da177e4SLinus Torvalds uint8_t rev;
22431da177e4SLinus Torvalds
22441da177e4SLinus Torvalds pci = ahc->dev_softc;
22451da177e4SLinus Torvalds ahc->channel = 'A';
22461da177e4SLinus Torvalds ahc->chip = AHC_AIC7890;
22471da177e4SLinus Torvalds ahc->features = AHC_AIC7890_FE;
22481da177e4SLinus Torvalds ahc->flags |= AHC_NEWEEPROM_FMT;
22491da177e4SLinus Torvalds rev = ahc_pci_read_config(pci, PCIR_REVID, /*bytes*/1);
22501da177e4SLinus Torvalds if (rev == 0)
22511da177e4SLinus Torvalds ahc->bugs |= AHC_AUTOFLUSH_BUG|AHC_CACHETHEN_BUG;
22521da177e4SLinus Torvalds ahc->instruction_ram_size = 768;
22531da177e4SLinus Torvalds return (0);
22541da177e4SLinus Torvalds }
22551da177e4SLinus Torvalds
22561da177e4SLinus Torvalds static int
ahc_aic7892_setup(struct ahc_softc * ahc)22571da177e4SLinus Torvalds ahc_aic7892_setup(struct ahc_softc *ahc)
22581da177e4SLinus Torvalds {
22591da177e4SLinus Torvalds
22601da177e4SLinus Torvalds ahc->channel = 'A';
22611da177e4SLinus Torvalds ahc->chip = AHC_AIC7892;
22621da177e4SLinus Torvalds ahc->features = AHC_AIC7892_FE;
22631da177e4SLinus Torvalds ahc->flags |= AHC_NEWEEPROM_FMT;
22641da177e4SLinus Torvalds ahc->bugs |= AHC_SCBCHAN_UPLOAD_BUG;
22651da177e4SLinus Torvalds ahc->instruction_ram_size = 1024;
22661da177e4SLinus Torvalds return (0);
22671da177e4SLinus Torvalds }
22681da177e4SLinus Torvalds
22691da177e4SLinus Torvalds static int
ahc_aic7895_setup(struct ahc_softc * ahc)22701da177e4SLinus Torvalds ahc_aic7895_setup(struct ahc_softc *ahc)
22711da177e4SLinus Torvalds {
22721da177e4SLinus Torvalds ahc_dev_softc_t pci;
22731da177e4SLinus Torvalds uint8_t rev;
22741da177e4SLinus Torvalds
22751da177e4SLinus Torvalds pci = ahc->dev_softc;
22761da177e4SLinus Torvalds ahc->channel = ahc_get_pci_function(pci) == 1 ? 'B' : 'A';
22771da177e4SLinus Torvalds /*
22781da177e4SLinus Torvalds * The 'C' revision of the aic7895 has a few additional features.
22791da177e4SLinus Torvalds */
22801da177e4SLinus Torvalds rev = ahc_pci_read_config(pci, PCIR_REVID, /*bytes*/1);
22811da177e4SLinus Torvalds if (rev >= 4) {
22821da177e4SLinus Torvalds ahc->chip = AHC_AIC7895C;
22831da177e4SLinus Torvalds ahc->features = AHC_AIC7895C_FE;
22841da177e4SLinus Torvalds } else {
22851da177e4SLinus Torvalds u_int command;
22861da177e4SLinus Torvalds
22871da177e4SLinus Torvalds ahc->chip = AHC_AIC7895;
22881da177e4SLinus Torvalds ahc->features = AHC_AIC7895_FE;
22891da177e4SLinus Torvalds
22901da177e4SLinus Torvalds /*
22911da177e4SLinus Torvalds * The BIOS disables the use of MWI transactions
22921da177e4SLinus Torvalds * since it does not have the MWI bug work around
22931da177e4SLinus Torvalds * we have. Disabling MWI reduces performance, so
22941da177e4SLinus Torvalds * turn it on again.
22951da177e4SLinus Torvalds */
22961da177e4SLinus Torvalds command = ahc_pci_read_config(pci, PCIR_COMMAND, /*bytes*/1);
22971da177e4SLinus Torvalds command |= PCIM_CMD_MWRICEN;
22981da177e4SLinus Torvalds ahc_pci_write_config(pci, PCIR_COMMAND, command, /*bytes*/1);
22991da177e4SLinus Torvalds ahc->bugs |= AHC_PCI_MWI_BUG;
23001da177e4SLinus Torvalds }
23011da177e4SLinus Torvalds /*
23021da177e4SLinus Torvalds * XXX Does CACHETHEN really not work??? What about PCI retry?
23031da177e4SLinus Torvalds * on C level chips. Need to test, but for now, play it safe.
23041da177e4SLinus Torvalds */
23051da177e4SLinus Torvalds ahc->bugs |= AHC_TMODE_WIDEODD_BUG|AHC_PCI_2_1_RETRY_BUG
23061da177e4SLinus Torvalds | AHC_CACHETHEN_BUG;
23071da177e4SLinus Torvalds
23081da177e4SLinus Torvalds #if 0
23091da177e4SLinus Torvalds uint32_t devconfig;
23101da177e4SLinus Torvalds
23111da177e4SLinus Torvalds /*
23121da177e4SLinus Torvalds * Cachesize must also be zero due to stray DAC
23131da177e4SLinus Torvalds * problem when sitting behind some bridges.
23141da177e4SLinus Torvalds */
23151da177e4SLinus Torvalds ahc_pci_write_config(pci, CSIZE_LATTIME, 0, /*bytes*/1);
23161da177e4SLinus Torvalds devconfig = ahc_pci_read_config(pci, DEVCONFIG, /*bytes*/1);
23171da177e4SLinus Torvalds devconfig |= MRDCEN;
23181da177e4SLinus Torvalds ahc_pci_write_config(pci, DEVCONFIG, devconfig, /*bytes*/1);
23191da177e4SLinus Torvalds #endif
23201da177e4SLinus Torvalds ahc->flags |= AHC_NEWEEPROM_FMT;
23211da177e4SLinus Torvalds ahc->instruction_ram_size = 512;
23221da177e4SLinus Torvalds return (0);
23231da177e4SLinus Torvalds }
23241da177e4SLinus Torvalds
23251da177e4SLinus Torvalds static int
ahc_aic7895h_setup(struct ahc_softc * ahc)2326b2d8bfe1SJames Bottomley ahc_aic7895h_setup(struct ahc_softc *ahc)
2327b2d8bfe1SJames Bottomley {
2328b2d8bfe1SJames Bottomley int error = ahc_aic7895_setup(ahc);
2329b2d8bfe1SJames Bottomley
2330b2d8bfe1SJames Bottomley ahc->features |= AHC_HVD;
2331b2d8bfe1SJames Bottomley
2332b2d8bfe1SJames Bottomley return error;
2333b2d8bfe1SJames Bottomley }
2334b2d8bfe1SJames Bottomley
2335b2d8bfe1SJames Bottomley static int
ahc_aic7896_setup(struct ahc_softc * ahc)23361da177e4SLinus Torvalds ahc_aic7896_setup(struct ahc_softc *ahc)
23371da177e4SLinus Torvalds {
23381da177e4SLinus Torvalds ahc_dev_softc_t pci;
23391da177e4SLinus Torvalds
23401da177e4SLinus Torvalds pci = ahc->dev_softc;
23411da177e4SLinus Torvalds ahc->channel = ahc_get_pci_function(pci) == 1 ? 'B' : 'A';
23421da177e4SLinus Torvalds ahc->chip = AHC_AIC7896;
23431da177e4SLinus Torvalds ahc->features = AHC_AIC7896_FE;
23441da177e4SLinus Torvalds ahc->flags |= AHC_NEWEEPROM_FMT;
23451da177e4SLinus Torvalds ahc->bugs |= AHC_CACHETHEN_DIS_BUG;
23461da177e4SLinus Torvalds ahc->instruction_ram_size = 768;
23471da177e4SLinus Torvalds return (0);
23481da177e4SLinus Torvalds }
23491da177e4SLinus Torvalds
23501da177e4SLinus Torvalds static int
ahc_aic7899_setup(struct ahc_softc * ahc)23511da177e4SLinus Torvalds ahc_aic7899_setup(struct ahc_softc *ahc)
23521da177e4SLinus Torvalds {
23531da177e4SLinus Torvalds ahc_dev_softc_t pci;
23541da177e4SLinus Torvalds
23551da177e4SLinus Torvalds pci = ahc->dev_softc;
23561da177e4SLinus Torvalds ahc->channel = ahc_get_pci_function(pci) == 1 ? 'B' : 'A';
23571da177e4SLinus Torvalds ahc->chip = AHC_AIC7899;
23581da177e4SLinus Torvalds ahc->features = AHC_AIC7899_FE;
23591da177e4SLinus Torvalds ahc->flags |= AHC_NEWEEPROM_FMT;
23601da177e4SLinus Torvalds ahc->bugs |= AHC_SCBCHAN_UPLOAD_BUG;
23611da177e4SLinus Torvalds ahc->instruction_ram_size = 1024;
23621da177e4SLinus Torvalds return (0);
23631da177e4SLinus Torvalds }
23641da177e4SLinus Torvalds
23651da177e4SLinus Torvalds static int
ahc_aha29160C_setup(struct ahc_softc * ahc)23661da177e4SLinus Torvalds ahc_aha29160C_setup(struct ahc_softc *ahc)
23671da177e4SLinus Torvalds {
23681da177e4SLinus Torvalds int error;
23691da177e4SLinus Torvalds
23701da177e4SLinus Torvalds error = ahc_aic7899_setup(ahc);
23711da177e4SLinus Torvalds if (error != 0)
23721da177e4SLinus Torvalds return (error);
23731da177e4SLinus Torvalds ahc->features |= AHC_REMOVABLE;
23741da177e4SLinus Torvalds return (0);
23751da177e4SLinus Torvalds }
23761da177e4SLinus Torvalds
23771da177e4SLinus Torvalds static int
ahc_raid_setup(struct ahc_softc * ahc)23781da177e4SLinus Torvalds ahc_raid_setup(struct ahc_softc *ahc)
23791da177e4SLinus Torvalds {
238048813cf9SPekka Enberg printk("RAID functionality unsupported\n");
23811da177e4SLinus Torvalds return (ENXIO);
23821da177e4SLinus Torvalds }
23831da177e4SLinus Torvalds
23841da177e4SLinus Torvalds static int
ahc_aha394XX_setup(struct ahc_softc * ahc)23851da177e4SLinus Torvalds ahc_aha394XX_setup(struct ahc_softc *ahc)
23861da177e4SLinus Torvalds {
23871da177e4SLinus Torvalds ahc_dev_softc_t pci;
23881da177e4SLinus Torvalds
23891da177e4SLinus Torvalds pci = ahc->dev_softc;
23901da177e4SLinus Torvalds switch (ahc_get_pci_slot(pci)) {
23911da177e4SLinus Torvalds case AHC_394X_SLOT_CHANNEL_A:
23921da177e4SLinus Torvalds ahc->channel = 'A';
23931da177e4SLinus Torvalds break;
23941da177e4SLinus Torvalds case AHC_394X_SLOT_CHANNEL_B:
23951da177e4SLinus Torvalds ahc->channel = 'B';
23961da177e4SLinus Torvalds break;
23971da177e4SLinus Torvalds default:
239848813cf9SPekka Enberg printk("adapter at unexpected slot %d\n"
23991da177e4SLinus Torvalds "unable to map to a channel\n",
24001da177e4SLinus Torvalds ahc_get_pci_slot(pci));
24011da177e4SLinus Torvalds ahc->channel = 'A';
24021da177e4SLinus Torvalds }
24031da177e4SLinus Torvalds return (0);
24041da177e4SLinus Torvalds }
24051da177e4SLinus Torvalds
24061da177e4SLinus Torvalds static int
ahc_aha398XX_setup(struct ahc_softc * ahc)24071da177e4SLinus Torvalds ahc_aha398XX_setup(struct ahc_softc *ahc)
24081da177e4SLinus Torvalds {
24091da177e4SLinus Torvalds ahc_dev_softc_t pci;
24101da177e4SLinus Torvalds
24111da177e4SLinus Torvalds pci = ahc->dev_softc;
24121da177e4SLinus Torvalds switch (ahc_get_pci_slot(pci)) {
24131da177e4SLinus Torvalds case AHC_398X_SLOT_CHANNEL_A:
24141da177e4SLinus Torvalds ahc->channel = 'A';
24151da177e4SLinus Torvalds break;
24161da177e4SLinus Torvalds case AHC_398X_SLOT_CHANNEL_B:
24171da177e4SLinus Torvalds ahc->channel = 'B';
24181da177e4SLinus Torvalds break;
24191da177e4SLinus Torvalds case AHC_398X_SLOT_CHANNEL_C:
24201da177e4SLinus Torvalds ahc->channel = 'C';
24211da177e4SLinus Torvalds break;
24221da177e4SLinus Torvalds default:
242348813cf9SPekka Enberg printk("adapter at unexpected slot %d\n"
24241da177e4SLinus Torvalds "unable to map to a channel\n",
24251da177e4SLinus Torvalds ahc_get_pci_slot(pci));
24261da177e4SLinus Torvalds ahc->channel = 'A';
24271da177e4SLinus Torvalds break;
24281da177e4SLinus Torvalds }
24291da177e4SLinus Torvalds ahc->flags |= AHC_LARGE_SEEPROM;
24301da177e4SLinus Torvalds return (0);
24311da177e4SLinus Torvalds }
24321da177e4SLinus Torvalds
24331da177e4SLinus Torvalds static int
ahc_aha494XX_setup(struct ahc_softc * ahc)24341da177e4SLinus Torvalds ahc_aha494XX_setup(struct ahc_softc *ahc)
24351da177e4SLinus Torvalds {
24361da177e4SLinus Torvalds ahc_dev_softc_t pci;
24371da177e4SLinus Torvalds
24381da177e4SLinus Torvalds pci = ahc->dev_softc;
24391da177e4SLinus Torvalds switch (ahc_get_pci_slot(pci)) {
24401da177e4SLinus Torvalds case AHC_494X_SLOT_CHANNEL_A:
24411da177e4SLinus Torvalds ahc->channel = 'A';
24421da177e4SLinus Torvalds break;
24431da177e4SLinus Torvalds case AHC_494X_SLOT_CHANNEL_B:
24441da177e4SLinus Torvalds ahc->channel = 'B';
24451da177e4SLinus Torvalds break;
24461da177e4SLinus Torvalds case AHC_494X_SLOT_CHANNEL_C:
24471da177e4SLinus Torvalds ahc->channel = 'C';
24481da177e4SLinus Torvalds break;
24491da177e4SLinus Torvalds case AHC_494X_SLOT_CHANNEL_D:
24501da177e4SLinus Torvalds ahc->channel = 'D';
24511da177e4SLinus Torvalds break;
24521da177e4SLinus Torvalds default:
245348813cf9SPekka Enberg printk("adapter at unexpected slot %d\n"
24541da177e4SLinus Torvalds "unable to map to a channel\n",
24551da177e4SLinus Torvalds ahc_get_pci_slot(pci));
24561da177e4SLinus Torvalds ahc->channel = 'A';
24571da177e4SLinus Torvalds }
24581da177e4SLinus Torvalds ahc->flags |= AHC_LARGE_SEEPROM;
24591da177e4SLinus Torvalds return (0);
24601da177e4SLinus Torvalds }
2461