The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/dev/aic7xxx/aic7770.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*-
    2  * Product specific probe and attach routines for:
    3  *      27/284X and aic7770 motherboard SCSI controllers
    4  *
    5  * Copyright (c) 1994-1998, 2000, 2001 Justin T. Gibbs.
    6  * All rights reserved.
    7  *
    8  * Redistribution and use in source and binary forms, with or without
    9  * modification, are permitted provided that the following conditions
   10  * are met:
   11  * 1. Redistributions of source code must retain the above copyright
   12  *    notice, this list of conditions, and the following disclaimer,
   13  *    without modification.
   14  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
   15  *    substantially similar to the "NO WARRANTY" disclaimer below
   16  *    ("Disclaimer") and any redistribution must be conditioned upon
   17  *    including a substantially similar Disclaimer requirement for further
   18  *    binary redistribution.
   19  * 3. Neither the names of the above-listed copyright holders nor the names
   20  *    of any contributors may be used to endorse or promote products derived
   21  *    from this software without specific prior written permission.
   22  *
   23  * Alternatively, this software may be distributed under the terms of the
   24  * GNU General Public License ("GPL") version 2 as published by the Free
   25  * Software Foundation.
   26  *
   27  * NO WARRANTY
   28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   30  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
   31  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
   32  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   33  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   34  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   35  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
   36  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
   37  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   38  * POSSIBILITY OF SUCH DAMAGES.
   39  *
   40  * $Id: //depot/aic7xxx/aic7xxx/aic7770.c#34 $
   41  */
   42 
   43 #ifdef __linux__
   44 #include "aic7xxx_osm.h"
   45 #include "aic7xxx_inline.h"
   46 #include "aic7xxx_93cx6.h"
   47 #else
   48 #include <sys/cdefs.h>
   49 __FBSDID("$FreeBSD: releng/8.0/sys/dev/aic7xxx/aic7770.c 168807 2007-04-17 06:26:25Z scottl $");
   50 #include <dev/aic7xxx/aic7xxx_osm.h>
   51 #include <dev/aic7xxx/aic7xxx_inline.h>
   52 #include <dev/aic7xxx/aic7xxx_93cx6.h>
   53 #endif
   54 
   55 #define ID_AIC7770      0x04907770
   56 #define ID_AHA_274x     0x04907771
   57 #define ID_AHA_284xB    0x04907756 /* BIOS enabled */
   58 #define ID_AHA_284x     0x04907757 /* BIOS disabled*/
   59 #define ID_OLV_274x     0x04907782 /* Olivetti OEM */
   60 #define ID_OLV_274xD    0x04907783 /* Olivetti OEM (Differential) */
   61 
   62 static int aic7770_chip_init(struct ahc_softc *ahc);
   63 static int aic7770_suspend(struct ahc_softc *ahc);
   64 static int aic7770_resume(struct ahc_softc *ahc);
   65 static int aha2840_load_seeprom(struct ahc_softc *ahc);
   66 static ahc_device_setup_t ahc_aic7770_VL_setup;
   67 static ahc_device_setup_t ahc_aic7770_EISA_setup;
   68 static ahc_device_setup_t ahc_aic7770_setup;
   69 
   70 struct aic7770_identity aic7770_ident_table[] =
   71 {
   72         {
   73                 ID_AHA_274x,
   74                 0xFFFFFFFF,
   75                 "Adaptec 274X SCSI adapter",
   76                 ahc_aic7770_EISA_setup
   77         },
   78         {
   79                 ID_AHA_284xB,
   80                 0xFFFFFFFE,
   81                 "Adaptec 284X SCSI adapter",
   82                 ahc_aic7770_VL_setup
   83         },
   84         {
   85                 ID_AHA_284x,
   86                 0xFFFFFFFE,
   87                 "Adaptec 284X SCSI adapter (BIOS Disabled)",
   88                 ahc_aic7770_VL_setup
   89         },
   90         {
   91                 ID_OLV_274x,
   92                 0xFFFFFFFF,
   93                 "Adaptec (Olivetti OEM) 274X SCSI adapter",
   94                 ahc_aic7770_EISA_setup
   95         },
   96         {
   97                 ID_OLV_274xD,
   98                 0xFFFFFFFF,
   99                 "Adaptec (Olivetti OEM) 274X Differential SCSI adapter",
  100                 ahc_aic7770_EISA_setup
  101         },
  102         /* Generic chip probes for devices we don't know 'exactly' */
  103         {
  104                 ID_AIC7770,
  105                 0xFFFFFFFF,
  106                 "Adaptec aic7770 SCSI adapter",
  107                 ahc_aic7770_EISA_setup
  108         }
  109 };
  110 const int ahc_num_aic7770_devs = NUM_ELEMENTS(aic7770_ident_table);
  111 
  112 struct aic7770_identity *
  113 aic7770_find_device(uint32_t id)
  114 {
  115         struct  aic7770_identity *entry;
  116         int     i;
  117 
  118         for (i = 0; i < ahc_num_aic7770_devs; i++) {
  119                 entry = &aic7770_ident_table[i];
  120                 if (entry->full_id == (id & entry->id_mask))
  121                         return (entry);
  122         }
  123         return (NULL);
  124 }
  125 
  126 int
  127 aic7770_config(struct ahc_softc *ahc, struct aic7770_identity *entry, u_int io)
  128 {
  129         int     error;
  130         int     have_seeprom;
  131         u_int   hostconf;
  132         u_int   irq;
  133         u_int   intdef;
  134 
  135         error = entry->setup(ahc);
  136         have_seeprom = 0;
  137         if (error != 0)
  138                 return (error);
  139 
  140         error = aic7770_map_registers(ahc, io);
  141         if (error != 0)
  142                 return (error);
  143 
  144         /*
  145          * Before we continue probing the card, ensure that
  146          * its interrupts are *disabled*.  We don't want
  147          * a misstep to hang the machine in an interrupt
  148          * storm.
  149          */
  150         ahc_intr_enable(ahc, FALSE);
  151 
  152         ahc->description = entry->name;
  153         error = ahc_softc_init(ahc);
  154         if (error != 0)
  155                 return (error);
  156 
  157         ahc->bus_chip_init = aic7770_chip_init;
  158         ahc->bus_suspend = aic7770_suspend;
  159         ahc->bus_resume = aic7770_resume;
  160 
  161         error = ahc_reset(ahc, /*reinit*/FALSE);
  162         if (error != 0)
  163                 return (error);
  164 
  165         /* Make sure we have a valid interrupt vector */
  166         intdef = ahc_inb(ahc, INTDEF);
  167         irq = intdef & VECTOR;
  168         switch (irq) {
  169         case 9:
  170         case 10:
  171         case 11:
  172         case 12:
  173         case 14:
  174         case 15:
  175                 break;
  176         default:
  177                 printf("aic7770_config: invalid irq setting %d\n", intdef);
  178                 return (ENXIO);
  179         }
  180 
  181         if ((intdef & EDGE_TRIG) != 0)
  182                 ahc->flags |= AHC_EDGE_INTERRUPT;
  183 
  184         switch (ahc->chip & (AHC_EISA|AHC_VL)) {
  185         case AHC_EISA:
  186         {
  187                 u_int biosctrl;
  188                 u_int scsiconf;
  189                 u_int scsiconf1;
  190 
  191                 biosctrl = ahc_inb(ahc, HA_274_BIOSCTRL);
  192                 scsiconf = ahc_inb(ahc, SCSICONF);
  193                 scsiconf1 = ahc_inb(ahc, SCSICONF + 1);
  194 
  195                 /* Get the primary channel information */
  196                 if ((biosctrl & CHANNEL_B_PRIMARY) != 0)
  197                         ahc->flags |= 1;
  198 
  199                 if ((biosctrl & BIOSMODE) == BIOSDISABLED) {
  200                         ahc->flags |= AHC_USEDEFAULTS;
  201                 } else {
  202                         if ((ahc->features & AHC_WIDE) != 0) {
  203                                 ahc->our_id = scsiconf1 & HWSCSIID;
  204                                 if (scsiconf & TERM_ENB)
  205                                         ahc->flags |= AHC_TERM_ENB_A;
  206                         } else {
  207                                 ahc->our_id = scsiconf & HSCSIID;
  208                                 ahc->our_id_b = scsiconf1 & HSCSIID;
  209                                 if (scsiconf & TERM_ENB)
  210                                         ahc->flags |= AHC_TERM_ENB_A;
  211                                 if (scsiconf1 & TERM_ENB)
  212                                         ahc->flags |= AHC_TERM_ENB_B;
  213                         }
  214                 }
  215                 if ((ahc_inb(ahc, HA_274_BIOSGLOBAL) & HA_274_EXTENDED_TRANS))
  216                         ahc->flags |= AHC_EXTENDED_TRANS_A|AHC_EXTENDED_TRANS_B;
  217                 break;
  218         }
  219         case AHC_VL:
  220         {
  221                 have_seeprom = aha2840_load_seeprom(ahc);
  222                 break;
  223         }
  224         default:
  225                 break;
  226         }
  227         if (have_seeprom == 0) {
  228                 free(ahc->seep_config, M_DEVBUF);
  229                 ahc->seep_config = NULL;
  230         }
  231 
  232         /*
  233          * Ensure autoflush is enabled
  234          */
  235         ahc_outb(ahc, SBLKCTL, ahc_inb(ahc, SBLKCTL) & ~AUTOFLUSHDIS);
  236 
  237         /* Setup the FIFO threshold and the bus off time */
  238         hostconf = ahc_inb(ahc, HOSTCONF);
  239         ahc_outb(ahc, BUSSPD, hostconf & DFTHRSH);
  240         ahc_outb(ahc, BUSTIME, (hostconf << 2) & BOFF);
  241 
  242         ahc->bus_softc.aic7770_softc.busspd = hostconf & DFTHRSH;
  243         ahc->bus_softc.aic7770_softc.bustime = (hostconf << 2) & BOFF;
  244 
  245         /*
  246          * Generic aic7xxx initialization.
  247          */
  248         error = ahc_init(ahc);
  249         if (error != 0)
  250                 return (error);
  251 
  252         error = aic7770_map_int(ahc, irq);
  253         if (error != 0)
  254                 return (error);
  255 
  256         ahc_lock(ahc);
  257         /*
  258          * Link this softc in with all other ahc instances.
  259          */
  260         ahc_softc_insert(ahc);
  261 
  262         /*
  263          * Enable the board's BUS drivers
  264          */
  265         ahc_outb(ahc, BCTL, ENABLE);
  266 
  267         ahc_unlock(ahc);
  268 
  269         return (0);
  270 }
  271 
  272 static int
  273 aic7770_chip_init(struct ahc_softc *ahc)
  274 {
  275         ahc_outb(ahc, BUSSPD, ahc->bus_softc.aic7770_softc.busspd);
  276         ahc_outb(ahc, BUSTIME, ahc->bus_softc.aic7770_softc.bustime);
  277         ahc_outb(ahc, SBLKCTL, ahc_inb(ahc, SBLKCTL) & ~AUTOFLUSHDIS);
  278         ahc_outb(ahc, BCTL, ENABLE);
  279         return (ahc_chip_init(ahc));
  280 }
  281 
  282 static int
  283 aic7770_suspend(struct ahc_softc *ahc)
  284 {
  285         return (ahc_suspend(ahc));
  286 }
  287 
  288 static int
  289 aic7770_resume(struct ahc_softc *ahc)
  290 {
  291         return (ahc_resume(ahc));
  292 }
  293 
  294 /*
  295  * Read the 284x SEEPROM.
  296  */
  297 static int
  298 aha2840_load_seeprom(struct ahc_softc *ahc)
  299 {
  300         struct  seeprom_descriptor sd;
  301         struct  seeprom_config *sc;
  302         int     have_seeprom;
  303         uint8_t scsi_conf;
  304 
  305         sd.sd_ahc = ahc;
  306         sd.sd_control_offset = SEECTL_2840;
  307         sd.sd_status_offset = STATUS_2840;
  308         sd.sd_dataout_offset = STATUS_2840;             
  309         sd.sd_chip = C46;
  310         sd.sd_MS = 0;
  311         sd.sd_RDY = EEPROM_TF;
  312         sd.sd_CS = CS_2840;
  313         sd.sd_CK = CK_2840;
  314         sd.sd_DO = DO_2840;
  315         sd.sd_DI = DI_2840;
  316         sc = ahc->seep_config;
  317 
  318         if (bootverbose)
  319                 printf("%s: Reading SEEPROM...", ahc_name(ahc));
  320         have_seeprom = ahc_read_seeprom(&sd, (uint16_t *)sc,
  321                                         /*start_addr*/0, sizeof(*sc)/2);
  322 
  323         if (have_seeprom) {
  324 
  325                 if (ahc_verify_cksum(sc) == 0) {
  326                         if(bootverbose)
  327                                 printf ("checksum error\n");
  328                         have_seeprom = 0;
  329                 } else if (bootverbose) {
  330                         printf("done.\n");
  331                 }
  332         }
  333 
  334         if (!have_seeprom) {
  335                 if (bootverbose)
  336                         printf("%s: No SEEPROM available\n", ahc_name(ahc));
  337                 ahc->flags |= AHC_USEDEFAULTS;
  338         } else {
  339                 /*
  340                  * Put the data we've collected down into SRAM
  341                  * where ahc_init will find it.
  342                  */
  343                 int      i;
  344                 int      max_targ;
  345                 uint16_t discenable;
  346 
  347                 max_targ = (ahc->features & AHC_WIDE) != 0 ? 16 : 8;
  348                 discenable = 0;
  349                 for (i = 0; i < max_targ; i++){
  350                         uint8_t target_settings;
  351 
  352                         target_settings = (sc->device_flags[i] & CFXFER) << 4;
  353                         if (sc->device_flags[i] & CFSYNCH)
  354                                 target_settings |= SOFS;
  355                         if (sc->device_flags[i] & CFWIDEB)
  356                                 target_settings |= WIDEXFER;
  357                         if (sc->device_flags[i] & CFDISC)
  358                                 discenable |= (0x01 << i);
  359                         ahc_outb(ahc, TARG_SCSIRATE + i, target_settings);
  360                 }
  361                 ahc_outb(ahc, DISC_DSB, ~(discenable & 0xff));
  362                 ahc_outb(ahc, DISC_DSB + 1, ~((discenable >> 8) & 0xff));
  363 
  364                 ahc->our_id = sc->brtime_id & CFSCSIID;
  365 
  366                 scsi_conf = (ahc->our_id & 0x7);
  367                 if (sc->adapter_control & CFSPARITY)
  368                         scsi_conf |= ENSPCHK;
  369                 if (sc->adapter_control & CFRESETB)
  370                         scsi_conf |= RESET_SCSI;
  371 
  372                 if (sc->bios_control & CF284XEXTEND)            
  373                         ahc->flags |= AHC_EXTENDED_TRANS_A;
  374                 /* Set SCSICONF info */
  375                 ahc_outb(ahc, SCSICONF, scsi_conf);
  376 
  377                 if (sc->adapter_control & CF284XSTERM)
  378                         ahc->flags |= AHC_TERM_ENB_A;
  379         }
  380         return (have_seeprom);
  381 }
  382 
  383 static int
  384 ahc_aic7770_VL_setup(struct ahc_softc *ahc)
  385 {
  386         int error;
  387 
  388         error = ahc_aic7770_setup(ahc);
  389         ahc->chip |= AHC_VL;
  390         return (error);
  391 }
  392 
  393 static int
  394 ahc_aic7770_EISA_setup(struct ahc_softc *ahc)
  395 {
  396         int error;
  397 
  398         error = ahc_aic7770_setup(ahc);
  399         ahc->chip |= AHC_EISA;
  400         return (error);
  401 }
  402 
  403 static int
  404 ahc_aic7770_setup(struct ahc_softc *ahc)
  405 {
  406         ahc->channel = 'A';
  407         ahc->channel_b = 'B';
  408         ahc->chip = AHC_AIC7770;
  409         ahc->features = AHC_AIC7770_FE;
  410         ahc->bugs |= AHC_TMODE_WIDEODD_BUG;
  411         ahc->flags |= AHC_PAGESCBS;
  412         ahc->instruction_ram_size = 448;
  413         return (0);
  414 }

Cache object: 95eb0bc0efd678f6a853077df1d4afdd


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.