fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER START
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The contents of this file are subject to the terms of the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Common Development and Distribution License (the "License").
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You may not use this file except in compliance with the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or http://www.opensolaris.org/os/licensing.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See the License for the specific language governing permissions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and limitations under the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * When distributing Covered Code, include this CDDL HEADER in each
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If applicable, add the following below this CDDL HEADER, with the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fields enclosed by brackets "[]" replaced with your own identifying
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * information: Portions Copyright [yyyy] [name of copyright owner]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER END
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use is subject to license terms.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * I18N message number ranges
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This file: 4500 - 4999
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Shared common messages: 1 - 1999
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <fcntl.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <limits.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <setjmp.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <signal.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <siginfo.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <stdio.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <stdlib.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <string.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <strings.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <unistd.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <ctype.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <dirent.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/exec.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/exechdr.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/mman.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/stat.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/types.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/fibre-channel/fcio.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/socalreg.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The following define is not to
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * include sys/fc4/fcal_linkapp.h
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * file from sys/socalio.h, since it
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * has same structure defines as in
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sys/fibre-channel/fcio.h.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define _SYS_FC4_FCAL_LINKAPP_H
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/socalio.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/time.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <nl_types.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <errno.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <stgcom.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <gfc.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <l_common.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "luxadm.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* Defines */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define FEPROM_SIZE 256*1024
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define FEPROM_MAX_PROGRAM 25
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define FEPROM_MAX_ERASE 1000
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define FEPROM_READ_MEMORY 0x00
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define FEPROM_ERASE 0x20
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define FEPROM_ERASE_VERIFY 0xa0
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define FEPROM_PROGRAM 0x40
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define FEPROM_PROGRAM_VERIFY 0xc0
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define FEPROM_RESET 0xff
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define HBA_MAX 128
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define FOUND 0
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define NOT_FOUND 1
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define PROM_SIZ 0x20010
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define MAX_RETRIES 3
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define MAX_WAIT_TIME 30
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The next define is to work around a problem with sbusmem driver not
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * able to round up mmap() requests that are not around page boundaries.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define PROM_SIZ_ROUNDED 0x22000
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SAMPLE_SIZ 0x100
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define REG_OFFSET 0x20000
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define FEPROM_WWN_OFFSET 0x3fe00
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define FEPROM_SUN_WWN 0x50200200
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * We'll leave this on leadville, as the onboard
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * isn't allowed to be zapped by luxadm
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define ONBOARD_SOCAL "SUNW,socal@d"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SOCAL_STR "SUNW,socal"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SOCAL_STR_LEN 10
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic uchar_t buffer[FEPROM_SIZE];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic char sbus_list[HBA_MAX][PATH_MAX];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic char sbussoc_list[HBA_MAX][PATH_MAX];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic char bootpath[PATH_MAX];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic char version[MAXNAMELEN];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic uint_t getsbuslist(void);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int load_file(char *, caddr_t, volatile socal_reg_t *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void usec_delay(int);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void getbootdev(unsigned int);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void getsocpath(char *, int *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int loadsocpath(const char *, int *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int warn(void);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int findversion(int, uchar_t *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int write_feprom(uchar_t *, uchar_t *, volatile socal_reg_t *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int feprom_erase(volatile uchar_t *, volatile socal_reg_t *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic struct exec exec;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortefcal_update(unsigned int verbose, char *file)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*ARGSUSED*/
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint fd, strfound = 0, retval = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint fbuf_idx, fd1, bytes_read;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortecaddr_t addr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteuint_t i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteuint_t fflag = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteuint_t vflag = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteuint_t numslots;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevolatile socal_reg_t *regs;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortechar *slotname, socal[MAXNAMELEN];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortechar fbuf[BUFSIZ];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!file)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vflag++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fflag++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((fd1 = open(file, O_RDONLY)) == -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte MSGSTR(4500,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Error: open() failed on file "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "%s\n"), file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * We will just make a check to see if it the file
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * has the "SUNW,socal" strings in it
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * We cannot use strstr() here because we are operating on
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * binary data and so is very likely to have embedded NULLs
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (!strfound && ((bytes_read = read(fd1,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fbuf, BUFSIZ)) > 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (fbuf_idx = 0; fbuf_idx < bytes_read;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fbuf_idx++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* First check for the SUNW,socal string */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strncmp((fbuf + fbuf_idx), SOCAL_STR,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SOCAL_STR_LEN) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strfound = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!strfound) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte MSGSTR(4501,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Error: %s is not a "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "FC100/S Fcode file\n"), file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Get count of, and names of SBus slots using the SBus memory
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * interface.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) getbootdev(verbose);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (getenv("_LUX_D_DEBUG") != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, " Bootpath: %s\n", bootpath);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte numslots = getsbuslist();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte MSGSTR(4503, "\n Found Path to %d FC100/S Cards\n"), numslots);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < numslots; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Open SBus memory for this slot.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte slotname = &sbus_list[i][0];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (fflag && (strcmp(slotname, bootpath) == 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte MSGSTR(4504, " Ignoring %s (bootpath)\n"), slotname);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sprintf(socal, "%s:0", &sbussoc_list[i][0]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((fd = open(socal, O_RDWR)) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sprintf(socal, "%s:1", &sbussoc_list[i][0]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((fd = open(socal, O_RDWR)) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte MSGSTR(4505, "Could not open %s\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &sbussoc_list[i][0]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte MSGSTR(4506, "Ignoring %s\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &sbussoc_list[i][0]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte retval++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (verbose) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, "\n ");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte MSGSTR(85, "Opening %s\n"), slotname);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fd = open(slotname, O_RDWR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (fd < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte perror(MSGSTR(4507, "open of slotname"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte retval++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Mmap that SBus memory into my memory space.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte addr = mmap((caddr_t)0, PROM_SIZ_ROUNDED, PROT_READ|PROT_WRITE,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte MAP_SHARED, fd, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (addr == MAP_FAILED) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte perror(MSGSTR(46, "mmap"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte retval++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((int)addr == -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte perror(MSGSTR(46, "mmap"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte retval++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte regs = (socal_reg_t *)((int)addr + REG_OFFSET);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte MSGSTR(4508, "\n Device: %s\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &sbussoc_list[i][0]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Load the New FCode
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (fflag) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!warn())
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte retval += load_file(file, addr, regs);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (vflag) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (findversion(i, (uchar_t *)&version[0]) == FOUND) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte MSGSTR(4509,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte " Detected FC100/S Version: %s\n"), version);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (munmap(addr, PROM_SIZ) == -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte perror(MSGSTR(4510, "munmap"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte retval++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, " ");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, MSGSTR(125, "Complete\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (retval);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortefindversion(int index, uchar_t *version)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*ARGSUSED*/
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint fd, ntries;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestruct socal_fm_version *buffer;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortechar socal[MAXNAMELEN];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortechar fp[MAXNAMELEN];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortechar prom_ver[100];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortechar mcode_ver[100];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteuint_t dev_type;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortefcio_t fcio;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortechar fw_rev[FC_FW_REV_SIZE + 1];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((dev_type = g_get_path_type(&sbussoc_list[index][0])) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_INVALID_PATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dev_type & FC4_FCA_MASK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte P_DPRINTF("findversion: found an FC4 path\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sprintf(socal, "%s:0", &sbussoc_list[index][0]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((fd = open(socal, O_RDWR)) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sprintf(socal, "%s:1", &sbussoc_list[index][0]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((fd = open(socal, O_RDWR)) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte MSGSTR(4511, "Could not open %s\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &sbussoc_list[index][0]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NOT_FOUND);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((buffer = (struct socal_fm_version *)malloc(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (struct socal_fm_version))) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, MSGSTR(10,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte " Error: Unable to allocate memory."));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, "\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NOT_FOUND);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte buffer->fcode_ver = (char *)version;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte buffer->mcode_ver = mcode_ver;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte buffer->prom_ver = prom_ver;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte buffer->fcode_ver_len = MAXNAMELEN - 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte buffer->mcode_ver_len = 100;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte buffer->prom_ver_len = 100;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ioctl(fd, FCIO_FCODE_MCODE_VERSION, buffer) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, MSGSTR(4512,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "fcal_s_download: could not get"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte " fcode version.\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) free(buffer);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NOT_FOUND);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte version[buffer->fcode_ver_len] = '\0';
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(buffer);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (dev_type & FC_FCA_MASK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Get the fcode and prom's fw version
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * using new ioctls. Currently, we pass
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * only the fcode version to the calling function
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and ignore the FW version (using the existing
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * implementation). The function definition
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * might be changed in future to pass both the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fcode and FW revisions to the calling function, if
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * needed by the calling function.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte P_DPRINTF("findversion: found an FC path\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sprintf(fp, "%s/fp@0,0:devctl",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &sbussoc_list[index][0]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((fd = open(fp, O_RDWR)) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sprintf(fp, "%s/fp@1,0:devctl",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &sbussoc_list[index][0]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((fd = open(fp, O_RDWR)) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte MSGSTR(4511, "Could not open %s\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &sbussoc_list[index][0]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NOT_FOUND);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Get the fcode version */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(version, sizeof (version));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_cmd = FCIO_GET_FCODE_REV;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Information read operation */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_xfer = FCIO_XFER_READ;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_obuf = (caddr_t)version;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_olen = MAXNAMELEN;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (ntries = 0; ntries < MAX_RETRIES; ntries++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ioctl(fd, FCIO_CMD, &fcio) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((errno == EAGAIN) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (ntries+1 < MAX_RETRIES)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* wait 30 secs */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sleep(MAX_WAIT_TIME);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte I_DPRINTF("ioctl FCIO_GET_FCODE_REV failed.\n"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Error: %s\n", strerror(errno));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_FCIO_GET_FCODE_REV_FAIL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte version[MAXNAMELEN-1] = '\0';
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Get the FW revision */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(fw_rev, sizeof (fw_rev));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_cmd = FCIO_GET_FW_REV;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Information read operation */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_xfer = FCIO_XFER_READ;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_obuf = (caddr_t)fw_rev;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fcio.fcio_olen = FC_FW_REV_SIZE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (ntries = 0; ntries < MAX_RETRIES; ntries++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ioctl(fd, FCIO_CMD, &fcio) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((errno == EAGAIN) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (ntries+1 < MAX_RETRIES)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* wait 30 secs */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sleep(MAX_WAIT_TIME);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte I_DPRINTF(" FCIO_GET_FW_REV ioctl failed.\n"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte " Error: %s\n", strerror(errno));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (L_FCIO_GET_FW_REV_FAIL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (FOUND);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * program an FEprom with data from 'source_address'.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * program the FEprom with zeroes,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * erase it,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * program it with the real data.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortefeprom_program(uchar_t *source_address, uchar_t *dest_address,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte volatile socal_reg_t *regs)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, MSGSTR(4513, "Filling with zeroes...\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!write_feprom((uchar_t *)0, dest_address, regs)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte MSGSTR(4514, "FEprom at 0x%x: zero fill failed\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (int)dest_address);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, MSGSTR(4515, "Erasing...\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < FEPROM_MAX_ERASE; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (feprom_erase(dest_address, regs))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (i >= FEPROM_MAX_ERASE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte MSGSTR(4516, "FEprom at 0x%x: failed to erase\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (int)dest_address);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (i > 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (i == 1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, MSGSTR(4517,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "FEprom erased after %d attempt\n"), i);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, MSGSTR(4518,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "FEprom erased after %d attempts\n"), i);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, MSGSTR(4519, "Programming...\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(write_feprom(source_address, dest_address, regs))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte MSGSTR(4520, "FEprom at 0x%x: write failed\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (int)dest_address);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* select the zeroth bank at end so we can read it */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte regs->socal_cr.w &= ~(0x30000);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, MSGSTR(4521, "Programming done\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * program an FEprom one byte at a time using hot electron injection.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortewrite_feprom(uchar_t *source_address, uchar_t *dest_address,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte volatile socal_reg_t *regs)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int pulse, i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uchar_t *s = source_address;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte volatile uchar_t *d;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < FEPROM_SIZE; i++, s++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((i & 0xffff) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte MSGSTR(4522, "selecting bank %d\n"), i>>16);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte regs->socal_cr.w &= ~(0x30000);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte regs->socal_cr.w |= i & 0x30000;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte d = dest_address + (i & 0xffff);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (pulse = 0; pulse < FEPROM_MAX_PROGRAM; pulse++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *d = FEPROM_PROGRAM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *d = source_address ? *s : 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte usec_delay(50);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *d = FEPROM_PROGRAM_VERIFY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte usec_delay(30);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (*d == (source_address ? *s : 0))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (pulse >= FEPROM_MAX_PROGRAM) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *dest_address = FEPROM_RESET;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *dest_address = FEPROM_RESET;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * erase an FEprom using Fowler-Nordheim tunneling.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortefeprom_erase(volatile uchar_t *dest_address, volatile socal_reg_t *regs)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte volatile uchar_t *d = dest_address;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *d = FEPROM_ERASE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte usec_delay(50);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *d = FEPROM_ERASE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte usec_delay(10000); /* wait 10ms while FEprom erases */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < FEPROM_SIZE; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((i & 0xffff) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte regs->socal_cr.w &= ~(0x30000);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte regs->socal_cr.w |= i & 0x30000;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte d = dest_address + (i & 0xffff);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *d = FEPROM_ERASE_VERIFY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte usec_delay(50);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (*d != 0xff) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *dest_address = FEPROM_RESET;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *dest_address = FEPROM_RESET;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteusec_delay(int s)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hrtime_t now, then;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte now = gethrtime();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte then = now + s*1000;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte do {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte now = gethrtime();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } while (now < then);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic uint_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortegetsbuslist(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int devcnt = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char devpath[PATH_MAX];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* We're searching the /devices directory, so... */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcpy(devpath, "/devices");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* get the directory entries under /devices for socal sbusmem */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) getsocpath(devpath, (int *)&devcnt);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (devcnt);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortegetbootdev(unsigned int verbose)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *df = "df /";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte FILE *ptr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *p, *p1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char bootdev[PATH_MAX];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char buf[BUFSIZ];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int foundroot = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ptr = popen(df, "r")) != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (fgets(buf, BUFSIZ, ptr) != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (p = strstr(buf, "/dev/dsk/")) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) memset((char *)&bootdev[0], 0,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte PATH_MAX);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p1 = p;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (*p1 != '\0') {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!isalnum(*p1) && (*p1 != '/'))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *p1 = ' ';
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p1++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sscanf(p, "%s", bootdev);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte foundroot = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!foundroot) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (verbose)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, MSGSTR(44,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "root is not on a local disk!\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) memset((char *)&bootpath[0], 0, PATH_MAX);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) pclose(ptr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (bootdev[0]) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *ls;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *p1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *p2 = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *sbusmem = "/sbusmem@";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *slot = ",0:slot";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ls = (char *)malloc(PATH_MAX);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) memset((char *)ls, NULL, PATH_MAX);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcpy(ls, "ls -l ");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcat(ls, bootdev);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ptr = popen(ls, "r")) != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (fgets(buf, BUFSIZ, ptr) != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (p = strstr(buf, "/devices")) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (p1 = strstr(buf, "sbus")) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (*p1 != '/')
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p1++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p2 = strstr(p1, "@");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ++p2;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *p1 = '\0';
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (p1 = strstr(buf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SOCAL_STR)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p2 = strstr(p1, "@");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ++p2;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte --p1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *p1 = '\0';
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) pclose(ptr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) memset((char *)&bootdev[0], 0, PATH_MAX);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sscanf(p, "%s", bootdev);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) memset((char *)&bootpath[0], 0, PATH_MAX);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcat(bootpath, bootdev);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcat(bootpath, sbusmem);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (p2) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncat(bootpath, p2, 1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcat(bootpath, slot);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncat(bootpath, p2, 1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This function reads "size" bytes from the FC100/S PROM.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * source_address: PROM address
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * dest_address: local memeory
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * offset: Location in PROM to start reading from.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortefeprom_read(uchar_t *source_address, uchar_t *dest_address,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int offset, int size, volatile socal_reg_t *regs)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteuchar_t *s = source_address;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteuchar_t *d = dest_address;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint i = offset;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (getenv("_LUX_D_DEBUG") != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte " feprom_read: selecting bank %d\n",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (i&0xf0000)>>16);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (size <= 8) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, " Data read: ");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte regs->socal_cr.w = i & 0xf0000;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte s = source_address + (i & 0xffff);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *s = FEPROM_READ_MEMORY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte usec_delay(6);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (; s < source_address + (i & 0xffff) + size; d++, s++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *d = *s;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((getenv("_LUX_D_DEBUG") != NULL) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (size <= 8)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, "0x%x ", *d);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((getenv("_LUX_D_DEBUG") != NULL) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (size <= 8)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, "\n From offset: 0x%x\n",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte offset);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteload_file(char *file, caddr_t prom, volatile socal_reg_t *regs)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteuint_t wwn_d8, wwn_lo;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteuint_t wwn_hi;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint ffd = open(file, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wwn_hi = FEPROM_SUN_WWN;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ffd < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte perror(MSGSTR(4524, "open of file"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, MSGSTR(4525, "Loading FCode: %s\n"), file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (read(ffd, &exec, sizeof (exec)) != sizeof (exec)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte perror(MSGSTR(4526, "read exec"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (exec.a_trsize || exec.a_drsize) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte MSGSTR(4527, "%s: is relocatable\n"), file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (exec.a_data || exec.a_bss) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte MSGSTR(4528, "%s: has data or bss\n"), file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (exec.a_machtype != M_SPARC) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte MSGSTR(4529, "%s: not for SPARC\n"), file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout, MSGSTR(4530,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Loading 0x%x bytes from %s at offset 0x%x\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (int)exec.a_text, file, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (read(ffd, &buffer, exec.a_text) != exec.a_text) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte perror(MSGSTR(4531, "read"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(ffd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte feprom_read((uchar_t *)prom, (uchar_t *)&wwn_d8,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte FEPROM_WWN_OFFSET, 4, regs);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte feprom_read((uchar_t *)prom, (uchar_t *)&wwn_lo,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte FEPROM_WWN_OFFSET + 4, 4, regs);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wwn_hi |= wwn_d8 & 0x0f; /* only last digit is interesting */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (getenv("_LUX_D_DEBUG") != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stdout,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte " load_file: Writing WWN hi:0x%x lo:0x%x "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "to the FC100/S PROM\n", wwn_hi, wwn_lo);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* put wwn into buffer location */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy((const void *)&wwn_hi,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void *)&buffer[FEPROM_WWN_OFFSET],
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (wwn_hi));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy((const void *)&wwn_lo,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void *)&buffer[FEPROM_WWN_OFFSET + 4],
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (wwn_lo));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy((const void *)&wwn_hi,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void *)&buffer[FEPROM_WWN_OFFSET + 8],
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (wwn_hi));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy((const void *)&wwn_lo,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void *)&buffer[FEPROM_WWN_OFFSET + 0xc],
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (wwn_lo));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (feprom_program((uchar_t *)buffer, (uchar_t *)prom, regs) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* here 0 means failure */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortewarn(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char input[1024];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte input[0] = '\0';
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, MSGSTR(4532,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte"\nWARNING!! This program will update the FCode in this FC100/S Sbus Card.\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, MSGSTR(4533,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte"This may take a few (5) minutes. Please be patient.\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteloop1:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, MSGSTR(4534,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Do you wish to continue ? (y/n) "));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) gets(input);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((strcmp(input, MSGSTR(4535, "y")) == 0) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (strcmp(input, MSGSTR(40, "yes")) == 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (FOUND);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if ((strcmp(input, MSGSTR(4536, "n")) == 0) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (strcmp(input, MSGSTR(45, "no")) == 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, MSGSTR(4537, "Not Downloading FCode\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NOT_FOUND);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, MSGSTR(4538, "Invalid input\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto loop1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * getsocpath():
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Searches the /devices directory recursively returning all soc_name
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * entries in sbussoc_list (global). This excludes port entries and
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * onboard socal (which leaves only directory entries with
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * soc_name included). devcnt is updated to reflect number of soc_name
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * devices found.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortegetsocpath(char *devpath, int *devcnt)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct stat statbuf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct dirent *dirp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DIR *dp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *ptr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (lstat(devpath, &statbuf) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte MSGSTR(4539, "Error: %s lstat() error\n"), devpath);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (S_ISDIR(statbuf.st_mode) == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * not a directory so
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * we don't care about it - return
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strstr(devpath, ONBOARD_SOCAL))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strstr(devpath, SOCAL_STR)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* It's a keeper - call the load function */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((loadsocpath(devpath, devcnt)) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte MSGSTR(4540, "Error: Cannot set device list\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte devpath);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if socal directory - return,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * nothing else to see here
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * It's a directory. Call ourself to
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * traverse the path(s)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ptr = devpath + strlen(devpath);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *ptr++ = '/';
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *ptr = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Forget the /devices/pseudo/ directory */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strcmp(devpath, "/devices/pseudo/") == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((dp = opendir(devpath)) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte MSGSTR(4541, "Error: %s Can't read directory\n"), devpath);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while ((dirp = readdir(dp)) != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strcmp(dirp->d_name, ".") == 0 ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strcmp(dirp->d_name, "..") == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcpy(ptr, dirp->d_name); /* append name */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte getsocpath(devpath, devcnt);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (closedir(dp) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte MSGSTR(4542, "Error: %s Can't close directory\n"), devpath);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteloadsocpath(const char *pathname, int *devcnt)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int len_tmp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *sp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *sp_tmp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char buffer[PATH_MAX];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Okay we found a device, now let's load it in to sbussoc_list
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and load the sbusmem file into sbus_list
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (pathname != NULL && *devcnt < HBA_MAX) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcpy(sbussoc_list[*devcnt], pathname);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sp_tmp = strstr(sbussoc_list[*devcnt], SOCAL_STR)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sp = sp_tmp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* len_tmp will be len of "SUNW,socal@" */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte len_tmp = SOCAL_STR_LEN + 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte len = strlen(sbussoc_list[*devcnt]) - strlen(sp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(buffer, sbussoc_list[*devcnt], len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte buffer[len] = '\0';
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sp += len_tmp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sprintf(sbus_list[*devcnt], "%ssbusmem@%c,0:slot%c",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte buffer, sp[0], sp[0]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *devcnt += 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}