Commit | Line | Data |
---|---|---|
7725ccfd JH |
1 | /* |
2 | * Copyright (c) 2005-2009 Brocade Communications Systems, Inc. | |
3 | * All rights reserved | |
4 | * www.brocade.com | |
5 | * | |
6 | * Linux driver for Brocade Fibre Channel Host Bus Adapter. | |
7 | * | |
8 | * This program is free software; you can redistribute it and/or modify it | |
9 | * under the terms of the GNU General Public License (GPL) Version 2 as | |
10 | * published by the Free Software Foundation | |
11 | * | |
12 | * This program is distributed in the hope that it will be useful, but | |
13 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | * General Public License for more details. | |
16 | */ | |
17 | ||
18 | /** | |
19 | * port_loop.c vport private loop implementation. | |
20 | */ | |
21 | #include <bfa.h> | |
22 | #include <bfa_svc.h> | |
23 | #include "fcs_lport.h" | |
24 | #include "fcs_rport.h" | |
25 | #include "fcs_trcmod.h" | |
26 | #include "lport_priv.h" | |
27 | ||
28 | BFA_TRC_FILE(FCS, LOOP); | |
29 | ||
30 | /** | |
31 | * ALPA to LIXA bitmap mapping | |
32 | * | |
33 | * ALPA 0x00 (Word 0, Bit 30) is invalid for N_Ports. Also Word 0 Bit 31 | |
34 | * is for L_bit (login required) and is filled as ALPA 0x00 here. | |
35 | */ | |
36 | static const u8 port_loop_alpa_map[] = { | |
37 | 0xEF, 0xE8, 0xE4, 0xE2, 0xE1, 0xE0, 0xDC, 0xDA, /* Word 3 Bits 0..7 */ | |
38 | 0xD9, 0xD6, 0xD5, 0xD4, 0xD3, 0xD2, 0xD1, 0xCE, /* Word 3 Bits 8..15 */ | |
39 | 0xCD, 0xCC, 0xCB, 0xCA, 0xC9, 0xC7, 0xC6, 0xC5, /* Word 3 Bits 16..23 */ | |
40 | 0xC3, 0xBC, 0xBA, 0xB9, 0xB6, 0xB5, 0xB4, 0xB3, /* Word 3 Bits 24..31 */ | |
41 | ||
42 | 0xB2, 0xB1, 0xAE, 0xAD, 0xAC, 0xAB, 0xAA, 0xA9, /* Word 2 Bits 0..7 */ | |
43 | 0xA7, 0xA6, 0xA5, 0xA3, 0x9F, 0x9E, 0x9D, 0x9B, /* Word 2 Bits 8..15 */ | |
44 | 0x98, 0x97, 0x90, 0x8F, 0x88, 0x84, 0x82, 0x81, /* Word 2 Bits 16..23 */ | |
45 | 0x80, 0x7C, 0x7A, 0x79, 0x76, 0x75, 0x74, 0x73, /* Word 2 Bits 24..31 */ | |
46 | ||
47 | 0x72, 0x71, 0x6E, 0x6D, 0x6C, 0x6B, 0x6A, 0x69, /* Word 1 Bits 0..7 */ | |
48 | 0x67, 0x66, 0x65, 0x63, 0x5C, 0x5A, 0x59, 0x56, /* Word 1 Bits 8..15 */ | |
49 | 0x55, 0x54, 0x53, 0x52, 0x51, 0x4E, 0x4D, 0x4C, /* Word 1 Bits 16..23 */ | |
50 | 0x4B, 0x4A, 0x49, 0x47, 0x46, 0x45, 0x43, 0x3C, /* Word 1 Bits 24..31 */ | |
51 | ||
52 | 0x3A, 0x39, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31, /* Word 0 Bits 0..7 */ | |
53 | 0x2E, 0x2D, 0x2C, 0x2B, 0x2A, 0x29, 0x27, 0x26, /* Word 0 Bits 8..15 */ | |
54 | 0x25, 0x23, 0x1F, 0x1E, 0x1D, 0x1B, 0x18, 0x17, /* Word 0 Bits 16..23 */ | |
55 | 0x10, 0x0F, 0x08, 0x04, 0x02, 0x01, 0x00, 0x00, /* Word 0 Bits 24..31 */ | |
56 | }; | |
57 | ||
58 | /* | |
59 | * Local Functions | |
60 | */ | |
f8ceafde JH |
61 | static bfa_status_t bfa_fcs_port_loop_send_plogi(struct bfa_fcs_port_s *port, |
62 | u8 alpa); | |
63 | ||
64 | static void bfa_fcs_port_loop_plogi_response(void *fcsarg, | |
65 | struct bfa_fcxp_s *fcxp, | |
66 | void *cbarg, | |
67 | bfa_status_t req_status, | |
68 | u32 rsp_len, | |
69 | u32 resid_len, | |
70 | struct fchs_s *rsp_fchs); | |
7725ccfd JH |
71 | /** |
72 | * Called by port to initializar in provate LOOP topology. | |
73 | */ | |
74 | void | |
75 | bfa_fcs_port_loop_init(struct bfa_fcs_port_s *port) | |
76 | { | |
77 | } | |
78 | ||
79 | /** | |
80 | * Called by port to notify transition to online state. | |
81 | */ | |
82 | void | |
83 | bfa_fcs_port_loop_online(struct bfa_fcs_port_s *port) | |
84 | { | |
85 | ||
86 | u8 num_alpa = port->port_topo.ploop.num_alpa; | |
87 | u8 *alpa_pos_map = port->port_topo.ploop.alpa_pos_map; | |
88 | struct bfa_fcs_rport_s *r_port; | |
89 | int ii = 0; | |
90 | ||
91 | /* | |
92 | * If the port role is Initiator Mode, create Rports. | |
93 | */ | |
94 | if (port->port_cfg.roles == BFA_PORT_ROLE_FCP_IM) { | |
95 | /* | |
96 | * Check if the ALPA positional bitmap is available. | |
97 | * if not, we send PLOGI to all possible ALPAs. | |
98 | */ | |
99 | if (num_alpa > 0) { | |
100 | for (ii = 0; ii < num_alpa; ii++) { | |
101 | /* | |
102 | * ignore ALPA of bfa port | |
103 | */ | |
104 | if (alpa_pos_map[ii] != port->pid) { | |
105 | r_port = bfa_fcs_rport_create(port, | |
106 | alpa_pos_map[ii]); | |
107 | } | |
108 | } | |
109 | } else { | |
110 | for (ii = 0; ii < MAX_ALPA_COUNT; ii++) { | |
111 | /* | |
112 | * ignore ALPA of bfa port | |
113 | */ | |
114 | if ((port_loop_alpa_map[ii] > 0) | |
115 | && (port_loop_alpa_map[ii] != port->pid)) | |
116 | bfa_fcs_port_loop_send_plogi(port, | |
117 | port_loop_alpa_map[ii]); | |
118 | /**TBD */ | |
119 | } | |
120 | } | |
121 | } else { | |
122 | /* | |
123 | * TBD Target Mode ?? | |
124 | */ | |
125 | } | |
126 | ||
127 | } | |
128 | ||
129 | /** | |
130 | * Called by port to notify transition to offline state. | |
131 | */ | |
132 | void | |
133 | bfa_fcs_port_loop_offline(struct bfa_fcs_port_s *port) | |
134 | { | |
135 | ||
136 | } | |
137 | ||
138 | /** | |
139 | * Called by port to notify a LIP on the loop. | |
140 | */ | |
141 | void | |
142 | bfa_fcs_port_loop_lip(struct bfa_fcs_port_s *port) | |
143 | { | |
144 | } | |
145 | ||
146 | /** | |
147 | * Local Functions. | |
148 | */ | |
f8ceafde | 149 | static bfa_status_t |
7725ccfd JH |
150 | bfa_fcs_port_loop_send_plogi(struct bfa_fcs_port_s *port, u8 alpa) |
151 | { | |
152 | struct fchs_s fchs; | |
153 | struct bfa_fcxp_s *fcxp = NULL; | |
154 | int len; | |
155 | ||
156 | bfa_trc(port->fcs, alpa); | |
157 | ||
158 | fcxp = bfa_fcxp_alloc(NULL, port->fcs->bfa, 0, 0, NULL, NULL, NULL, | |
159 | NULL); | |
160 | bfa_assert(fcxp); | |
161 | ||
162 | len = fc_plogi_build(&fchs, bfa_fcxp_get_reqbuf(fcxp), alpa, | |
163 | bfa_fcs_port_get_fcid(port), 0, | |
164 | port->port_cfg.pwwn, port->port_cfg.nwwn, | |
165 | bfa_pport_get_maxfrsize(port->fcs->bfa)); | |
166 | ||
167 | bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE, | |
168 | FC_CLASS_3, len, &fchs, | |
169 | bfa_fcs_port_loop_plogi_response, (void *)port, | |
170 | FC_MAX_PDUSZ, FC_RA_TOV); | |
171 | ||
172 | return BFA_STATUS_OK; | |
173 | } | |
174 | ||
175 | /** | |
176 | * Called by fcxp to notify the Plogi response | |
177 | */ | |
f8ceafde | 178 | static void |
7725ccfd JH |
179 | bfa_fcs_port_loop_plogi_response(void *fcsarg, struct bfa_fcxp_s *fcxp, |
180 | void *cbarg, bfa_status_t req_status, | |
181 | u32 rsp_len, u32 resid_len, | |
182 | struct fchs_s *rsp_fchs) | |
183 | { | |
184 | struct bfa_fcs_port_s *port = (struct bfa_fcs_port_s *) cbarg; | |
185 | struct fc_logi_s *plogi_resp; | |
186 | struct fc_els_cmd_s *els_cmd; | |
187 | ||
188 | bfa_trc(port->fcs, req_status); | |
189 | ||
190 | /* | |
191 | * Sanity Checks | |
192 | */ | |
193 | if (req_status != BFA_STATUS_OK) { | |
194 | bfa_trc(port->fcs, req_status); | |
195 | /* | |
196 | * @todo | |
197 | * This could mean that the device with this APLA does not | |
198 | * exist on the loop. | |
199 | */ | |
200 | ||
201 | return; | |
202 | } | |
203 | ||
204 | els_cmd = (struct fc_els_cmd_s *) BFA_FCXP_RSP_PLD(fcxp); | |
205 | plogi_resp = (struct fc_logi_s *) els_cmd; | |
206 | ||
207 | if (els_cmd->els_code == FC_ELS_ACC) { | |
208 | bfa_fcs_rport_start(port, rsp_fchs, plogi_resp); | |
209 | } else { | |
210 | bfa_trc(port->fcs, plogi_resp->els_cmd.els_code); | |
211 | bfa_assert(0); | |
212 | } | |
213 | } |