loop.c 5.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
/*
 * Copyright (c) 2005-2009 Brocade Communications Systems, Inc.
 * All rights reserved
 * www.brocade.com
 *
 * Linux driver for Brocade Fibre Channel Host Bus Adapter.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License (GPL) Version 2 as
 * published by the Free Software Foundation
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 */

/**
 *  port_loop.c vport private loop implementation.
 */
#include <bfa.h>
#include <bfa_svc.h>
#include "fcs_lport.h"
#include "fcs_rport.h"
#include "fcs_trcmod.h"
#include "lport_priv.h"

BFA_TRC_FILE(FCS, LOOP);

/**
 *   ALPA to LIXA bitmap mapping
 *
 *   ALPA 0x00 (Word 0, Bit 30) is invalid for N_Ports. Also Word 0 Bit 31
 * is for L_bit (login required) and is filled as ALPA 0x00 here.
 */
static const u8   port_loop_alpa_map[] = {
	0xEF, 0xE8, 0xE4, 0xE2, 0xE1, 0xE0, 0xDC, 0xDA,	/* Word 3 Bits 0..7 */
	0xD9, 0xD6, 0xD5, 0xD4, 0xD3, 0xD2, 0xD1, 0xCE,	/* Word 3 Bits 8..15 */
	0xCD, 0xCC, 0xCB, 0xCA, 0xC9, 0xC7, 0xC6, 0xC5,	/* Word 3 Bits 16..23 */
	0xC3, 0xBC, 0xBA, 0xB9, 0xB6, 0xB5, 0xB4, 0xB3,	/* Word 3 Bits 24..31 */

	0xB2, 0xB1, 0xAE, 0xAD, 0xAC, 0xAB, 0xAA, 0xA9,	/* Word 2 Bits 0..7 */
	0xA7, 0xA6, 0xA5, 0xA3, 0x9F, 0x9E, 0x9D, 0x9B,	/* Word 2 Bits 8..15 */
	0x98, 0x97, 0x90, 0x8F, 0x88, 0x84, 0x82, 0x81,	/* Word 2 Bits 16..23 */
	0x80, 0x7C, 0x7A, 0x79, 0x76, 0x75, 0x74, 0x73,	/* Word 2 Bits 24..31 */

	0x72, 0x71, 0x6E, 0x6D, 0x6C, 0x6B, 0x6A, 0x69,	/* Word 1 Bits 0..7 */
	0x67, 0x66, 0x65, 0x63, 0x5C, 0x5A, 0x59, 0x56,	/* Word 1 Bits 8..15 */
	0x55, 0x54, 0x53, 0x52, 0x51, 0x4E, 0x4D, 0x4C,	/* Word 1 Bits 16..23 */
	0x4B, 0x4A, 0x49, 0x47, 0x46, 0x45, 0x43, 0x3C,	/* Word 1 Bits 24..31 */

	0x3A, 0x39, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31,	/* Word 0 Bits 0..7 */
	0x2E, 0x2D, 0x2C, 0x2B, 0x2A, 0x29, 0x27, 0x26,	/* Word 0 Bits 8..15 */
	0x25, 0x23, 0x1F, 0x1E, 0x1D, 0x1B, 0x18, 0x17,	/* Word 0 Bits 16..23 */
	0x10, 0x0F, 0x08, 0x04, 0x02, 0x01, 0x00, 0x00,	/* Word 0 Bits 24..31 */
};

/*
 * Local Functions
 */
61 62 63 64 65 66 67 68 69 70
static bfa_status_t bfa_fcs_port_loop_send_plogi(struct bfa_fcs_port_s *port,
					u8 alpa);

static void bfa_fcs_port_loop_plogi_response(void *fcsarg,
					struct bfa_fcxp_s *fcxp,
					void *cbarg,
					bfa_status_t req_status,
					u32 rsp_len,
					u32 resid_len,
					struct fchs_s *rsp_fchs);
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
/**
 *   Called by port to initializar in provate LOOP topology.
 */
void
bfa_fcs_port_loop_init(struct bfa_fcs_port_s *port)
{
}

/**
 *   Called by port to notify transition to online state.
 */
void
bfa_fcs_port_loop_online(struct bfa_fcs_port_s *port)
{

	u8         num_alpa = port->port_topo.ploop.num_alpa;
	u8        *alpa_pos_map = port->port_topo.ploop.alpa_pos_map;
	struct bfa_fcs_rport_s *r_port;
	int             ii = 0;

	/*
	 * If the port role is Initiator Mode, create Rports.
	 */
	if (port->port_cfg.roles == BFA_PORT_ROLE_FCP_IM) {
		/*
		 * Check if the ALPA positional bitmap is available.
		 * if not, we send PLOGI to all possible ALPAs.
		 */
		if (num_alpa > 0) {
			for (ii = 0; ii < num_alpa; ii++) {
				/*
				 * ignore ALPA of bfa port
				 */
				if (alpa_pos_map[ii] != port->pid) {
					r_port = bfa_fcs_rport_create(port,
						alpa_pos_map[ii]);
				}
			}
		} else {
			for (ii = 0; ii < MAX_ALPA_COUNT; ii++) {
				/*
				 * ignore ALPA of bfa port
				 */
				if ((port_loop_alpa_map[ii] > 0)
				    && (port_loop_alpa_map[ii] != port->pid))
					bfa_fcs_port_loop_send_plogi(port,
						port_loop_alpa_map[ii]);
				/**TBD */
			}
		}
	} else {
		/*
		 * TBD Target Mode ??
		 */
	}

}

/**
 *   Called by port to notify transition to offline state.
 */
void
bfa_fcs_port_loop_offline(struct bfa_fcs_port_s *port)
{

}

/**
 *   Called by port to notify a LIP on the loop.
 */
void
bfa_fcs_port_loop_lip(struct bfa_fcs_port_s *port)
{
}

/**
 * Local Functions.
 */
149
static bfa_status_t
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
bfa_fcs_port_loop_send_plogi(struct bfa_fcs_port_s *port, u8 alpa)
{
	struct fchs_s          fchs;
	struct bfa_fcxp_s *fcxp = NULL;
	int             len;

	bfa_trc(port->fcs, alpa);

	fcxp = bfa_fcxp_alloc(NULL, port->fcs->bfa, 0, 0, NULL, NULL, NULL,
				  NULL);
	bfa_assert(fcxp);

	len = fc_plogi_build(&fchs, bfa_fcxp_get_reqbuf(fcxp), alpa,
			     bfa_fcs_port_get_fcid(port), 0,
			     port->port_cfg.pwwn, port->port_cfg.nwwn,
165
				 bfa_fcport_get_maxfrsize(port->fcs->bfa));
166 167 168 169 170 171 172 173 174 175 176 177

	bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
			  FC_CLASS_3, len, &fchs,
			  bfa_fcs_port_loop_plogi_response, (void *)port,
			  FC_MAX_PDUSZ, FC_RA_TOV);

	return BFA_STATUS_OK;
}

/**
 *   Called by fcxp to notify the Plogi response
 */
178
static void
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
bfa_fcs_port_loop_plogi_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
				 void *cbarg, bfa_status_t req_status,
				 u32 rsp_len, u32 resid_len,
				 struct fchs_s *rsp_fchs)
{
	struct bfa_fcs_port_s *port = (struct bfa_fcs_port_s *) cbarg;
	struct fc_logi_s     *plogi_resp;
	struct fc_els_cmd_s   *els_cmd;

	bfa_trc(port->fcs, req_status);

	/*
	 * Sanity Checks
	 */
	if (req_status != BFA_STATUS_OK) {
		bfa_trc(port->fcs, req_status);
		/*
		 * @todo
		 * This could mean that the device with this APLA does not
		 * exist on the loop.
		 */

		return;
	}

	els_cmd = (struct fc_els_cmd_s *) BFA_FCXP_RSP_PLD(fcxp);
	plogi_resp = (struct fc_logi_s *) els_cmd;

	if (els_cmd->els_code == FC_ELS_ACC) {
		bfa_fcs_rport_start(port, rsp_fchs, plogi_resp);
	} else {
		bfa_trc(port->fcs, plogi_resp->els_cmd.els_code);
		bfa_assert(0);
	}
}