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 *
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld * You can obtain a copy of the license at
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld * http://www.opensource.org/licenses/cddl1.txt.
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/*
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld * Copyright (c) 2004-2011 Emulex. All rights reserved.
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan * Use is subject to license terms.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan#include <emlxs.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* Required for EMLXS_CONTEXT in EMLXS_MSGF calls */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn ForteEMLXS_MSG_DEF(EMLXS_NODE_C);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeldstatic void emlxs_node_add(emlxs_port_t *, NODELIST *);
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeldstatic int emlxs_node_match_did(emlxs_port_t *, NODELIST *, uint32_t);
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan/* Timeout == -1 will enable the offline timer */
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan/* Timeout not -1 will apply the timeout */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern void
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathanemlxs_node_close(emlxs_port_t *port, NODELIST *ndlp, uint32_t channelno,
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan int32_t timeout)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte emlxs_hba_t *hba = HBA;
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan emlxs_config_t *cfg = &CFG;
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan CHANNEL *cp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NODELIST *prev;
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan uint32_t offline = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan /* If node is on a channel service queue, then remove it */
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan mutex_enter(&EMLXS_TX_CHANNEL_LOCK);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Return if node destroyed */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!ndlp || !ndlp->nlp_active) {
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan mutex_exit(&EMLXS_TX_CHANNEL_LOCK);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan /* Check offline support */
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan if (timeout == -1) {
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan if (cfg[CFG_OFFLINE_TIMEOUT].current) {
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan timeout = cfg[CFG_OFFLINE_TIMEOUT].current;
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan offline = 1;
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan } else {
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan timeout = 0;
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan }
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan }
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan if (channelno == hba->channel_ip) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Clear IP XRI */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ndlp->nlp_Xri = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Check if node is already closed */
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan if (ndlp->nlp_flag[channelno] & NLP_CLOSED) {
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan if (ndlp->nlp_flag[channelno] & NLP_OFFLINE) {
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan mutex_exit(&EMLXS_TX_CHANNEL_LOCK);
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan return;
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan }
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan if (offline) {
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan ndlp->nlp_tics[channelno] = hba->timer_tics + timeout;
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan ndlp->nlp_flag[channelno] |= NLP_OFFLINE;
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan mutex_exit(&EMLXS_TX_CHANNEL_LOCK);
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_node_closed_msg,
fe199829b492e6b3aa36dd76af597360bb4af121Sukumar Swaminathan "node=%p did=%06x channel=%d. offline=%d update.",
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan ndlp, ndlp->nlp_DID, channelno, timeout);
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan } else if (timeout) {
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan ndlp->nlp_tics[channelno] = hba->timer_tics + timeout;
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan mutex_exit(&EMLXS_TX_CHANNEL_LOCK);
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_node_closed_msg,
fe199829b492e6b3aa36dd76af597360bb4af121Sukumar Swaminathan "node=%p did=%06x channel=%d. timeout=%d update.",
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan ndlp, ndlp->nlp_DID, channelno, timeout);
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan } else {
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan mutex_exit(&EMLXS_TX_CHANNEL_LOCK);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Set the node closed */
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan ndlp->nlp_flag[channelno] |= NLP_CLOSED;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan if (offline) {
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan ndlp->nlp_tics[channelno] = hba->timer_tics + timeout;
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan ndlp->nlp_flag[channelno] |= NLP_OFFLINE;
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan
fe199829b492e6b3aa36dd76af597360bb4af121Sukumar Swaminathan EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_node_closed_msg,
fe199829b492e6b3aa36dd76af597360bb4af121Sukumar Swaminathan "node=%p did=%06x channel=%d. offline=%d set.",
fe199829b492e6b3aa36dd76af597360bb4af121Sukumar Swaminathan ndlp, ndlp->nlp_DID, channelno, timeout);
fe199829b492e6b3aa36dd76af597360bb4af121Sukumar Swaminathan
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan } else if (timeout) {
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan ndlp->nlp_tics[channelno] = hba->timer_tics + timeout;
fe199829b492e6b3aa36dd76af597360bb4af121Sukumar Swaminathan
fe199829b492e6b3aa36dd76af597360bb4af121Sukumar Swaminathan EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_node_closed_msg,
fe199829b492e6b3aa36dd76af597360bb4af121Sukumar Swaminathan "node=%p did=%06x channel=%d. timeout=%d set.",
fe199829b492e6b3aa36dd76af597360bb4af121Sukumar Swaminathan ndlp, ndlp->nlp_DID, channelno, timeout);
fe199829b492e6b3aa36dd76af597360bb4af121Sukumar Swaminathan } else {
fe199829b492e6b3aa36dd76af597360bb4af121Sukumar Swaminathan EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_node_closed_msg,
fe199829b492e6b3aa36dd76af597360bb4af121Sukumar Swaminathan "node=%p did=%06x channel=%d.",
fe199829b492e6b3aa36dd76af597360bb4af121Sukumar Swaminathan ndlp, ndlp->nlp_DID, channelno);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan /*
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan * ndlp->nlp_next[] and cp->nodeq list have to be updated
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan * simulaneously
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan */
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan if (ndlp->nlp_next[channelno]) {
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan /* Remove node from channel queue */
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan cp = &hba->chan[channelno];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* If this is the only node on list */
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan if (cp->nodeq.q_first == (void *)ndlp &&
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan cp->nodeq.q_last == (void *)ndlp) {
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan cp->nodeq.q_last = NULL;
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan cp->nodeq.q_first = NULL;
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan cp->nodeq.q_cnt = 0;
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan } else if (cp->nodeq.q_first == (void *)ndlp) {
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan cp->nodeq.q_first = ndlp->nlp_next[channelno];
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan ((NODELIST *)cp->nodeq.q_last)->nlp_next[channelno] =
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan cp->nodeq.q_first;
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan cp->nodeq.q_cnt--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else { /* This is a little more difficult */
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan /* Find the previous node in circular channel queue */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte prev = ndlp;
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan while (prev->nlp_next[channelno] != ndlp) {
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan prev = prev->nlp_next[channelno];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan prev->nlp_next[channelno] = ndlp->nlp_next[channelno];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan if (cp->nodeq.q_last == (void *)ndlp) {
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan cp->nodeq.q_last = (void *)prev;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan cp->nodeq.q_cnt--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Clear node */
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan ndlp->nlp_next[channelno] = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan mutex_exit(&EMLXS_TX_CHANNEL_LOCK);
728bdc9be5faf84b5dca42f545967bd4910d608eSukumar Swaminathan
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan return;
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan} /* emlxs_node_close() */
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan/* Called by emlxs_timer_check_nodes() */
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathanextern void
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathanemlxs_node_timeout(emlxs_port_t *port, NODELIST *ndlp, uint32_t channelno)
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan{
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan emlxs_hba_t *hba = HBA;
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan /* If node needs servicing, then add it to the channel queues */
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan mutex_enter(&EMLXS_TX_CHANNEL_LOCK);
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan /* Return if node destroyed */
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan if (!ndlp || !ndlp->nlp_active) {
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan mutex_exit(&EMLXS_TX_CHANNEL_LOCK);
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan return;
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan }
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan /* Open the node if not offline */
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan if (!(ndlp->nlp_flag[channelno] & NLP_OFFLINE)) {
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan mutex_exit(&EMLXS_TX_CHANNEL_LOCK);
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_node_timeout_msg,
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan "node=%p did=%06x channel=%d Opening.", ndlp, ndlp->nlp_DID,
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan channelno);
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan emlxs_node_open(port, ndlp, channelno);
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan return;
728bdc9be5faf84b5dca42f545967bd4910d608eSukumar Swaminathan }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan /* OFFLINE TIMEOUT OCCURRED! */
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan /* Clear the timer */
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan ndlp->nlp_tics[channelno] = 0;
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan mutex_exit(&EMLXS_TX_CHANNEL_LOCK);
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_node_timeout_msg,
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore "node=%p did=%06x channel=%d. Flushing.", ndlp, ndlp->nlp_DID,
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan channelno);
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan /* Flush tx queue for this channel */
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan (void) emlxs_tx_node_flush(port, ndlp, &hba->chan[channelno], 0, 0);
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan /* Flush chip queue for this channel */
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan (void) emlxs_chipq_node_flush(port, &hba->chan[channelno], ndlp, 0);
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan} /* emlxs_node_timeout() */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern void
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathanemlxs_node_open(emlxs_port_t *port, NODELIST *ndlp, uint32_t channelno)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte emlxs_hba_t *hba = HBA;
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan CHANNEL *cp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t found;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NODELIST *nlp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte MAILBOXQ *mbox;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t i;
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan int rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan /* If node needs servicing, then add it to the channel queues */
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan mutex_enter(&EMLXS_TX_CHANNEL_LOCK);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Return if node destroyed */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!ndlp || !ndlp->nlp_active) {
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan mutex_exit(&EMLXS_TX_CHANNEL_LOCK);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Return if node already open */
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan if (!(ndlp->nlp_flag[channelno] & NLP_CLOSED)) {
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan mutex_exit(&EMLXS_TX_CHANNEL_LOCK);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan /* Set the node open (not closed) */
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan ndlp->nlp_flag[channelno] &= ~(NLP_CLOSED|NLP_OFFLINE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Clear the timer */
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan ndlp->nlp_tics[channelno] = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan * If the ptx or the tx queue needs servicing and
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan * the node is not already on the channel queue
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan if ((ndlp->nlp_ptx[channelno].q_first ||
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan ndlp->nlp_tx[channelno].q_first) && !ndlp->nlp_next[channelno]) {
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan cp = &hba->chan[channelno];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan /* If so, then add it to the channel queue */
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan if (cp->nodeq.q_first) {
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan ((NODELIST *)cp->nodeq.q_last)->nlp_next[channelno] =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (uint8_t *)ndlp;
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan ndlp->nlp_next[channelno] = cp->nodeq.q_first;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan /* If this is not the base node then */
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan /* add it to the tail */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!ndlp->nlp_base) {
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan cp->nodeq.q_last = (uint8_t *)ndlp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else { /* Otherwise, add it to the head */
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* The command node always gets priority */
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan cp->nodeq.q_first = (uint8_t *)ndlp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan cp->nodeq.q_cnt++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan cp->nodeq.q_first = (uint8_t *)ndlp;
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan cp->nodeq.q_last = (uint8_t *)ndlp;
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan ndlp->nlp_next[channelno] = ndlp;
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan cp->nodeq.q_cnt = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan mutex_exit(&EMLXS_TX_CHANNEL_LOCK);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_node_opened_msg,
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld "node=%p did=%06x rpi=%d channel=%d", ndlp, ndlp->nlp_DID,
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore ndlp->nlp_Rpi, channelno);
728bdc9be5faf84b5dca42f545967bd4910d608eSukumar Swaminathan
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* If link attention needs to be cleared */
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan if ((hba->state == FC_LINK_UP) && (channelno == hba->channel_fcp)) {
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan if (hba->sli_mode == EMLXS_HBA_SLI4_MODE) {
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan goto done;
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Scan to see if any FCP2 devices are still closed */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte found = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_enter(&port->node_rwlock, RW_READER);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < EMLXS_NUM_HASH_QUES; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nlp = port->node_table[i];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (nlp != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((nlp->nlp_fcp_info & NLP_FCP_2_DEVICE) &&
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan (nlp->nlp_flag[hba->channel_fcp] &
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan NLP_CLOSED)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte found = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nlp = nlp->nlp_list_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (found) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_exit(&port->node_rwlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!found) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Clear link attention */
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan if ((mbox = (MAILBOXQ *)emlxs_mem_get(hba,
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld MEM_MBOX))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&EMLXS_PORT_LOCK);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan * If state is not FC_LINK_UP, then either the
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan * link has gone down or a FC_CLEAR_LA has
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan * already been issued
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (hba->state != FC_LINK_UP) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&EMLXS_PORT_LOCK);
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore emlxs_mem_put(hba, MEM_MBOX,
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore (void *)mbox);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan EMLXS_STATE_CHANGE_LOCKED(hba, FC_CLEAR_LA);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hba->discovery_timer = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&EMLXS_PORT_LOCK);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan emlxs_mb_clear_la(hba, mbox);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan rc = EMLXS_SLI_ISSUE_MBOX_CMD(hba,
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan mbox, MBX_NOWAIT, 0);
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore emlxs_mem_put(hba, MEM_MBOX,
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore (void *)mbox);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan /* Close the node and try again */
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan /* in a few seconds */
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan emlxs_node_close(port, ndlp, channelno, 5);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortedone:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Wake any sleeping threads */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&EMLXS_PKT_LOCK);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_broadcast(&EMLXS_PKT_CV);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&EMLXS_PKT_LOCK);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan} /* emlxs_node_open() */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteemlxs_node_match_did(emlxs_port_t *port, NODELIST *ndlp, uint32_t did)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte D_ID mydid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte D_ID odid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte D_ID ndid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan if (ndlp->nlp_DID == did)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Next check for area/domain == 0 match
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mydid.un.word = port->did;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ndid.un.word = did;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte odid.un.word = ndlp->nlp_DID;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ndid.un.b.id == odid.un.b.id) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((mydid.un.b.domain == ndid.un.b.domain) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (mydid.un.b.area == ndid.un.b.area)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ndid.un.word = ndlp->nlp_DID;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte odid.un.word = did;
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan if ((ndid.un.b.domain == 0) && (ndid.un.b.area == 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ndid.un.word = ndlp->nlp_DID;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((mydid.un.b.domain == ndid.un.b.domain) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (mydid.un.b.area == ndid.un.b.area)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte odid.un.word = ndlp->nlp_DID;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ndid.un.word = did;
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan if ((ndid.un.b.domain == 0) && (ndid.un.b.area == 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteout:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld} /* emlxs_node_match_did() */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern NODELIST *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteemlxs_node_find_mac(emlxs_port_t *port, uint8_t *mac)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NODELIST *nlp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_enter(&port->node_rwlock, RW_READER);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < EMLXS_NUM_HASH_QUES; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nlp = port->node_table[i];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (nlp != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan * If portname matches mac address,
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan * return NODELIST entry
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((nlp->nlp_portname.IEEE[0] == mac[0])) {
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan if ((nlp->nlp_DID != BCAST_DID) &&
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan ((nlp->nlp_DID & FABRIC_DID_MASK) ==
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan FABRIC_DID_MASK)) {
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan nlp = (NODELIST *)nlp->nlp_list_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((nlp->nlp_portname.IEEE[1] == mac[1]) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (nlp->nlp_portname.IEEE[2] == mac[2]) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (nlp->nlp_portname.IEEE[3] == mac[3]) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (nlp->nlp_portname.IEEE[4] == mac[4]) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (nlp->nlp_portname.IEEE[5] == mac[5])) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_exit(&port->node_rwlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (nlp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan nlp = (NODELIST *)nlp->nlp_list_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_exit(&port->node_rwlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_node_not_found_msg,
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan "find: MAC=%02x%02x%02x%02x%02x%02x", mac[0], mac[1], mac[2],
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan mac[3], mac[4], mac[5]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan} /* emlxs_node_find_mac() */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern NODELIST *
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeldemlxs_node_find_did(emlxs_port_t *port, uint32_t did, uint32_t lock)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte emlxs_hba_t *hba = HBA;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NODELIST *nlp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t hash;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Check for invalid node ids */
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan if ((did == 0) && (!(hba->flag & FC_LOOPBACK_MODE))) {
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan return ((NODELIST *)0);
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan }
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan if (did & 0xff000000) {
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan return ((NODELIST *)0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Check for bcast node */
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan if (did == BCAST_DID) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Use the base node here */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (&port->node_base);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef MENLO_SUPPORT
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Check for menlo node */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (did == EMLXS_MENLO_DID) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Use the base node here */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (&port->node_base);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan#endif /* MENLO_SUPPORT */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Check for host node */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (did == port->did && !(hba->flag & FC_LOOPBACK_MODE)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Use the base node here */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (&port->node_base);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan * Convert well known fabric addresses to the FABRIC_DID,
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan * since we don't login to some of them
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((did == SCR_DID)) {
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan did = FABRIC_DID;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld if (lock) {
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld rw_enter(&port->node_rwlock, RW_READER);
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hash = EMLXS_DID_HASH(did);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nlp = port->node_table[hash];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (nlp != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Check for obvious match */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (nlp->nlp_DID == did) {
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld if (lock) {
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld rw_exit(&port->node_rwlock);
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (nlp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Check for detailed match */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else if (emlxs_node_match_did(port, nlp, did)) {
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld if (lock) {
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld rw_exit(&port->node_rwlock);
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (nlp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan nlp = (NODELIST *)nlp->nlp_list_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld if (lock) {
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld rw_exit(&port->node_rwlock);
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_node_not_found_msg, "find: did=%x",
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan did);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* no match found */
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan return ((NODELIST *)0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan} /* emlxs_node_find_did() */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern NODELIST *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteemlxs_node_find_rpi(emlxs_port_t *port, uint32_t rpi)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NODELIST *nlp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_enter(&port->node_rwlock, RW_READER);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < EMLXS_NUM_HASH_QUES; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nlp = port->node_table[i];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (nlp != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (nlp->nlp_Rpi == rpi) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_exit(&port->node_rwlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (nlp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan nlp = (NODELIST *)nlp->nlp_list_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_exit(&port->node_rwlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_node_not_found_msg, "find: rpi=%d",
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan rpi);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* no match found */
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan return ((NODELIST *)0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan} /* emlxs_node_find_rpi() */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern NODELIST *
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeldemlxs_node_find_wwpn(emlxs_port_t *port, uint8_t *wwpn, uint32_t lock)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NODELIST *nlp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t j;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *bptr1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *bptr2;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld if (lock) {
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld rw_enter(&port->node_rwlock, RW_READER);
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld }
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < EMLXS_NUM_HASH_QUES; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nlp = port->node_table[i];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (nlp != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bptr1 = (uint8_t *)&nlp->nlp_portname;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bptr1 += 7;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bptr2 = (uint8_t *)wwpn;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bptr2 += 7;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (j = 0; j < 8; j++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (*bptr1-- != *bptr2--) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (j == 8) {
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld if (lock) {
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld rw_exit(&port->node_rwlock);
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (nlp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan nlp = (NODELIST *)nlp->nlp_list_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld if (lock) {
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld rw_exit(&port->node_rwlock);
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_node_not_found_msg,
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan "find: wwpn=%02x%02x%02x%02x%02x%02x%02x%02x", wwpn[0], wwpn[1],
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan wwpn[2], wwpn[3], wwpn[4], wwpn[5], wwpn[6], wwpn[7]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* no match found */
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan return ((NODELIST *)0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan} /* emlxs_node_find_wwpn() */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern NODELIST *
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathanemlxs_node_find_index(emlxs_port_t *port, uint32_t index,
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan uint32_t nports_only)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NODELIST *nlp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t count;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_enter(&port->node_rwlock, RW_READER);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (index > port->node_count - 1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_exit(&port->node_rwlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte count = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < EMLXS_NUM_HASH_QUES; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nlp = port->node_table[i];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (nlp != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Skip fabric ports if requested */
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan if (nports_only &&
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan (nlp->nlp_DID & 0xFFF000) == 0xFFF000) {
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan nlp = (NODELIST *)nlp->nlp_list_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (count == index) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_exit(&port->node_rwlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (nlp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan nlp = (NODELIST *)nlp->nlp_list_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte count++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_exit(&port->node_rwlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_node_not_found_msg, "find: index=%d",
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* no match found */
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan return ((NODELIST *)0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore} /* emlxs_node_find_index() */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern uint32_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteemlxs_nport_count(emlxs_port_t *port)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NODELIST *nlp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t nport_count = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_enter(&port->node_rwlock, RW_READER);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < EMLXS_NUM_HASH_QUES; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nlp = port->node_table[i];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (nlp != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((nlp->nlp_DID & 0xFFF000) != 0xFFF000) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nport_count++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan nlp = (NODELIST *)nlp->nlp_list_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_exit(&port->node_rwlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (nport_count);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan} /* emlxs_nport_count() */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteemlxs_node_destroy_all(emlxs_port_t *port)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte emlxs_hba_t *hba = HBA;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NODELIST *next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NODELIST *ndlp;
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore RPIobj_t *rpip;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *wwn;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Flush and free the nodes */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_enter(&port->node_rwlock, RW_WRITER);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < EMLXS_NUM_HASH_QUES; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ndlp = port->node_table[i];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte port->node_table[i] = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (ndlp != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte next = ndlp->nlp_list_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ndlp->nlp_list_next = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ndlp->nlp_list_prev = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ndlp->nlp_active = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (port->node_count) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte port->node_count--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wwn = (uint8_t *)&ndlp->nlp_portname;
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan EMLXS_MSGF(EMLXS_CONTEXT,
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan &emlxs_node_destroy_msg, "did=%06x "
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld "rpi=%d wwpn=%02x%02x%02x%02x%02x%02x%02x%02x "
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan "count=%d", ndlp->nlp_DID, ndlp->nlp_Rpi, wwn[0],
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan wwn[1], wwn[2], wwn[3], wwn[4], wwn[5], wwn[6],
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan wwn[7], port->node_count);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) emlxs_tx_node_flush(port, ndlp, 0, 0, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan /* Break Node/RPI binding */
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore if (ndlp->rpip) {
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore rpip = ndlp->rpip;
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore ndlp->rpip = NULL;
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore rpip->node = NULL;
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore (void) emlxs_rpi_free_notify(port, rpip);
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan }
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore emlxs_mem_put(hba, MEM_NLP, (void *)ndlp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ndlp = next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte port->node_count = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_exit(&port->node_rwlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Clean the base node */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&EMLXS_PORT_LOCK);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte port->node_base.nlp_list_next = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte port->node_base.nlp_list_prev = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte port->node_base.nlp_active = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&EMLXS_PORT_LOCK);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Flush the base node */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) emlxs_tx_node_flush(port, &port->node_base, 0, 1, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) emlxs_chipq_node_flush(port, 0, &port->node_base, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan} /* emlxs_node_destroy_all() */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amoreextern NODELIST *
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amoreemlxs_node_create(emlxs_port_t *port, uint32_t did, uint32_t rpi, SERV_PARM *sp)
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore{
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore emlxs_hba_t *hba = HBA;
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld NODELIST *ndlp, *ndlp_wwn;
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore uint8_t *wwn;
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore emlxs_vvl_fmt_t vvl;
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore RPIobj_t *rpip;
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld rw_enter(&port->node_rwlock, RW_WRITER);
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld ndlp = emlxs_node_find_did(port, did, 0);
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld ndlp_wwn = emlxs_node_find_wwpn(port, (uint8_t *)&sp->portName, 0);
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld /* Zero out the stale node worldwide names */
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld if (ndlp_wwn && (ndlp != ndlp_wwn)) {
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld bzero((uint8_t *)&ndlp_wwn->nlp_nodename, sizeof (NAME_TYPE));
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld bzero((uint8_t *)&ndlp_wwn->nlp_portname, sizeof (NAME_TYPE));
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld }
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore /* Update the node */
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore if (ndlp) {
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore ndlp->nlp_Rpi = (uint16_t)rpi;
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore ndlp->nlp_DID = did;
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore bcopy((uint8_t *)sp, (uint8_t *)&ndlp->sparm,
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore sizeof (SERV_PARM));
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore bcopy((uint8_t *)&sp->nodeName,
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore (uint8_t *)&ndlp->nlp_nodename,
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore sizeof (NAME_TYPE));
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore bcopy((uint8_t *)&sp->portName,
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore (uint8_t *)&ndlp->nlp_portname,
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore sizeof (NAME_TYPE));
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore /* Add Node/RPI binding */
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore if (hba->sli_mode == EMLXS_HBA_SLI4_MODE) {
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore rpip = emlxs_rpi_find(port, rpi);
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore if (rpip) {
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore rpip->node = ndlp;
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore ndlp->rpip = rpip;
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore } else {
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore ndlp->rpip = NULL;
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore EMLXS_MSGF(EMLXS_CONTEXT,
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore &emlxs_node_create_msg,
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld "Unable to find RPI. did=%x rpi=%d",
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore did, rpi);
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore }
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore } else {
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore ndlp->rpip = NULL;
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore }
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore wwn = (uint8_t *)&ndlp->nlp_portname;
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_node_update_msg,
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld "node=%p did=%06x rpi=%d "
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore "wwpn=%02x%02x%02x%02x%02x%02x%02x%02x",
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore ndlp, ndlp->nlp_DID, ndlp->nlp_Rpi, wwn[0],
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore wwn[1], wwn[2], wwn[3], wwn[4], wwn[5], wwn[6], wwn[7]);
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore goto done;
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore }
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore /* Allocate a new node */
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld ndlp = (NODELIST *)emlxs_mem_get(hba, MEM_NLP);
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore if (ndlp) {
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore ndlp->nlp_Rpi = (uint16_t)rpi;
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore ndlp->nlp_DID = did;
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore bcopy((uint8_t *)sp, (uint8_t *)&ndlp->sparm,
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore sizeof (SERV_PARM));
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore bcopy((uint8_t *)&sp->nodeName,
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore (uint8_t *)&ndlp->nlp_nodename,
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore sizeof (NAME_TYPE));
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore bcopy((uint8_t *)&sp->portName,
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore (uint8_t *)&ndlp->nlp_portname,
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore sizeof (NAME_TYPE));
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore ndlp->nlp_active = 1;
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore ndlp->nlp_flag[hba->channel_ct] |= NLP_CLOSED;
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore ndlp->nlp_flag[hba->channel_els] |= NLP_CLOSED;
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore ndlp->nlp_flag[hba->channel_fcp] |= NLP_CLOSED;
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore ndlp->nlp_flag[hba->channel_ip] |= NLP_CLOSED;
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore /* Add Node/RPI binding */
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore if (hba->sli_mode == EMLXS_HBA_SLI4_MODE) {
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore rpip = emlxs_rpi_find(port, rpi);
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore if (rpip) {
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore rpip->node = ndlp;
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore ndlp->rpip = rpip;
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore } else {
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore ndlp->rpip = NULL;
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore EMLXS_MSGF(EMLXS_CONTEXT,
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore &emlxs_node_create_msg,
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld "Unable to find RPI. did=%x rpi=%d",
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore did, rpi);
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore }
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore } else {
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore ndlp->rpip = NULL;
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore }
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld#ifdef NODE_THROTTLE_SUPPORT
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld emlxs_node_throttle_set(port, ndlp);
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld#endif /* NODE_THROTTLE_SUPPORT */
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore /* Add the node */
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore emlxs_node_add(port, ndlp);
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore goto done;
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore }
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld rw_exit(&port->node_rwlock);
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore wwn = (uint8_t *)&sp->portName;
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore EMLXS_MSGF(EMLXS_CONTEXT,
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore &emlxs_node_create_failed_msg,
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore "Unable to allocate node. did=%06x "
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore "wwpn=%02x%02x%02x%02x%02x%02x%02x%02x",
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore did, wwn[0], wwn[1], wwn[2],
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore wwn[3], wwn[4], wwn[5], wwn[6], wwn[7]);
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore return (NULL);
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amoredone:
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld rw_exit(&port->node_rwlock);
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore if (sp->VALID_VENDOR_VERSION) {
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore bcopy((caddr_t *)&sp->vendorVersion[0],
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore (caddr_t *)&vvl, sizeof (emlxs_vvl_fmt_t));
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore vvl.un0.word0 = LE_SWAP32(vvl.un0.word0);
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore vvl.un1.word1 = LE_SWAP32(vvl.un1.word1);
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore if ((vvl.un0.w0.oui == 0x0000C9) &&
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore (vvl.un1.w1.vport)) {
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore ndlp->nlp_fcp_info |= NLP_EMLX_VPORT;
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore }
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore }
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore /* Open the node */
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore emlxs_node_open(port, ndlp, hba->channel_ct);
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore emlxs_node_open(port, ndlp, hba->channel_els);
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore emlxs_node_open(port, ndlp, hba->channel_ip);
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore emlxs_node_open(port, ndlp, hba->channel_fcp);
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld EMLXS_SET_DFC_STATE(ndlp, NODE_LOGIN);
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore return (ndlp);
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore} /* emlxs_node_create() */
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld/* node_rwlock must be held when calling this routine */
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeldstatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteemlxs_node_add(emlxs_port_t *port, NODELIST *ndlp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NODELIST *np;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *wwn;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t hash;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hash = EMLXS_DID_HASH(ndlp->nlp_DID);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte np = port->node_table[hash];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Insert node pointer to the head
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte port->node_table[hash] = ndlp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!np) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ndlp->nlp_list_next = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ndlp->nlp_list_next = np;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte port->node_count++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wwn = (uint8_t *)&ndlp->nlp_portname;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_node_create_msg,
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld "node=%p did=%06x rpi=%d wwpn=%02x%02x%02x%02x%02x%02x%02x%02x "
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan "count=%d", ndlp, ndlp->nlp_DID, ndlp->nlp_Rpi, wwn[0], wwn[1],
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan wwn[2], wwn[3], wwn[4], wwn[5], wwn[6], wwn[7], port->node_count);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan} /* emlxs_node_add() */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteemlxs_node_rm(emlxs_port_t *port, NODELIST *ndlp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte emlxs_hba_t *hba = HBA;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NODELIST *np;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NODELIST *prevp;
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore RPIobj_t *rpip;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *wwn;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t hash;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_enter(&port->node_rwlock, RW_WRITER);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hash = EMLXS_DID_HASH(ndlp->nlp_DID);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte np = port->node_table[hash];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte prevp = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (np != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (np->nlp_DID == ndlp->nlp_DID) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (prevp == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte port->node_table[hash] = np->nlp_list_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte prevp->nlp_list_next = np->nlp_list_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (port->node_count) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte port->node_count--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wwn = (uint8_t *)&ndlp->nlp_portname;
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan EMLXS_MSGF(EMLXS_CONTEXT,
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan &emlxs_node_destroy_msg, "did=%06x "
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld "rpi=%d wwpn=%02x%02x%02x%02x%02x%02x%02x%02x "
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan "count=%d", ndlp->nlp_DID, ndlp->nlp_Rpi, wwn[0],
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan wwn[1], wwn[2], wwn[3], wwn[4], wwn[5], wwn[6],
291a2b48b9adcd7b3666c34e80ba6411929afe7fSukumar Swaminathan wwn[7], port->node_count);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) emlxs_tx_node_flush(port, ndlp, 0, 1, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ndlp->nlp_active = 0;
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan /* Break Node/RPI binding */
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore if (ndlp->rpip) {
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore rpip = ndlp->rpip;
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore ndlp->rpip = NULL;
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore rpip->node = NULL;
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore (void) emlxs_rpi_free_notify(port, rpip);
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan }
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan
a9800beb32c1006bb21c8da39e0180ea440b7badGarrett D'Amore emlxs_mem_put(hba, MEM_NLP, (void *)ndlp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte prevp = np;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte np = np->nlp_list_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_exit(&port->node_rwlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
825277341c15b6b0d2c4b8b622ae7b1d2bdc0390Sukumar Swaminathan} /* emlxs_node_rm() */
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeldextern void
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeldemlxs_node_throttle_set(emlxs_port_t *port, NODELIST *ndlp)
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld{
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld emlxs_hba_t *hba = HBA;
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld emlxs_config_t *cfg = &CFG;
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld char prop[64];
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld char buf1[32];
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld uint32_t throttle;
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld /* Set global default */
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld throttle = (ndlp->nlp_fcp_info & NLP_FCP_TGT_DEVICE)?
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld cfg[CFG_TGT_DEPTH].current:0;
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld /* Check per wwpn default */
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld (void) snprintf(prop, sizeof (prop), "w%s-depth",
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld emlxs_wwn_xlate(buf1, sizeof (buf1),
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld (uint8_t *)&ndlp->nlp_portname));
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld throttle = (uint32_t)ddi_prop_get_int(DDI_DEV_T_ANY,
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld (void *)hba->dip, DDI_PROP_DONTPASS, prop, throttle);
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld /* Check per driver/wwpn default */
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld (void) snprintf(prop, sizeof (prop), "%s%d-w%s-depth", DRIVER_NAME,
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld hba->ddiinst, emlxs_wwn_xlate(buf1, sizeof (buf1),
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld (uint8_t *)&ndlp->nlp_portname));
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld throttle = (uint32_t)ddi_prop_get_int(DDI_DEV_T_ANY,
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld (void *)hba->dip, DDI_PROP_DONTPASS, prop, throttle);
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld /* Check limit */
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld throttle = MIN(throttle, MAX_NODE_THROTTLE);
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld ndlp->io_throttle = throttle;
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld return;
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld
8f23e9fa8abcb5857661066b954e63400d589b65Hans Rosenfeld} /* emlxs_node_throttle_set() */