fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER START
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 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See the License for the specific language governing permissions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and limitations under the License.
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 * CDDL HEADER END
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use is subject to license terms.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int parse_line(char *line, char *path, char *wwn, char *filename);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int create_ap_instance(char *ap_id, char *wwn_string,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void log_error(char *msg_id, char *input_tmplt, ...);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic char ctoi(char c);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Simple wrapper for syslog error messages.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Allows easy addition of syserr output if desired.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *msg_template = "ID[luxadm.create_fabric_device.%s] %s";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * First %s for msg_id in merged msg.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Second %s is for input merged_msg
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* insert caller's args */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) vsprintf(input_merged_msg, input_tmplt, ap);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte merged_msg = (char *)malloc(strlen(msg_template) +
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "ID[luxadm.create_fabric_device.2317] "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sprintf(merged_msg, msg_template, msg_id, input_merged_msg);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* first insert msg_id */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) puts(merged_msg); /* also print message */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Routines for reading tapestry repository file
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (repos_filename == NULL || *repos_filename == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "filename missing for -f option of "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "luxadm -e create_fabric_device");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "fopen failed: cannot open repository file %s. %d",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "stat failed on file %s. %s",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Failed to mmap file %s. %s",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (bytes_read < filesize && *tmp_ptr != '\n') {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* If the line is a comment, read another line */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = parse_line(line, path, wwn, repos_filename);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Input is paramater 1 - a line from repository
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Output is other parameters, the path to the attachment point,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and the port wwn are parsed from the repository
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * "/devices/pci..../fp@1,0:fc::wwn"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If controller name is missing, that's okay. Other fields
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * must be present
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Return 0 on success or -1 on failure; all failures logged to syslog.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteparse_line(char *line, char *path, char *wwn, char *filename)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Invalid line (%s) in file %s.", line, filename);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strlcpy(path, p_path, MAXPATHLEN) >= MAXPATHLEN) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Path too long (%s) in file %s.", p_path, filename);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Now look for the blank delimiter before the controller
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This is just the case when there may be a controller #
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * after the attachment point and WWN. For example -
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * /devices/pci@b,2000/pci@2/SUNW,qlc@4/fp@0,0:fc::220000203707f4f1 c4
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* now p_delim points to blank */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * "string" is Input and "port_wwn" has the output
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This function converts a string to WWN.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * For example a string like
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * "220000203707F4F1" gets converted to 0x220000203707F4F1 ...
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * port_wwn[0] = 0x22,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * port_wwn[1] = 0x00,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * port_wwn[2] = 0x00,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * port_wwn[3] = 0x20,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * port_wwn[4] = 0x37,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * port_wwn[5] = 0x07,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * port_wwn[6] = 0xF4, and
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * port_wwn[7] = 0xF1
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestring_to_wwn(const uchar_t *string, uchar_t *port_wwn)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Internal error to process line (%s) "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "in file: %s. %s",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * g_string_to_wwn() has not been used here because it
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * prepends 2 NULLs.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (string_to_wwn((uchar_t *)wwn_string, wwn_array) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Internal error to process line (%s) "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "in file: %s. %s",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((bus_handle = devctl_bus_acquire(ap_id, 0)) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Internal error to process line (%s) "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "in file: %s. %s",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte devctl_bus_dev_create(bus_handle, ddef_handle, 0, &dev_handle)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "configuration failed for line (%s) "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "in file: %s. %s",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);