Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1 | /* |
Anil Gurumurthy | 889d0d4 | 2015-11-26 03:54:45 -0500 | [diff] [blame] | 2 | * Copyright (c) 2005-2014 Brocade Communications Systems, Inc. |
| 3 | * Copyright (c) 2014- QLogic Corporation. |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 4 | * All rights reserved |
Anil Gurumurthy | 889d0d4 | 2015-11-26 03:54:45 -0500 | [diff] [blame] | 5 | * www.qlogic.com |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 6 | * |
Anil Gurumurthy | 31e1d56 | 2015-11-26 03:54:46 -0500 | [diff] [blame] | 7 | * Linux driver for QLogic BR-series Fibre Channel Host Bus Adapter. |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify it |
| 10 | * under the terms of the GNU General Public License (GPL) Version 2 as |
| 11 | * published by the Free Software Foundation |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, but |
| 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | * General Public License for more details. |
| 17 | */ |
| 18 | /* |
| 19 | * fcbuild.c - FC link service frame building and parsing routines |
| 20 | */ |
| 21 | |
Maggie Zhang | f16a175 | 2010-12-09 19:12:32 -0800 | [diff] [blame] | 22 | #include "bfad_drv.h" |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 23 | #include "bfa_fcbuild.h" |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 24 | |
| 25 | /* |
| 26 | * static build functions |
| 27 | */ |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 28 | static void fc_els_rsp_build(struct fchs_s *fchs, u32 d_id, u32 s_id, |
Maggie | 50444a3 | 2010-11-29 18:26:32 -0800 | [diff] [blame] | 29 | __be16 ox_id); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 30 | static void fc_bls_rsp_build(struct fchs_s *fchs, u32 d_id, u32 s_id, |
Maggie | 50444a3 | 2010-11-29 18:26:32 -0800 | [diff] [blame] | 31 | __be16 ox_id); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 32 | static struct fchs_s fc_els_req_tmpl; |
| 33 | static struct fchs_s fc_els_rsp_tmpl; |
| 34 | static struct fchs_s fc_bls_req_tmpl; |
| 35 | static struct fchs_s fc_bls_rsp_tmpl; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 36 | static struct fc_ba_acc_s ba_acc_tmpl; |
| 37 | static struct fc_logi_s plogi_tmpl; |
| 38 | static struct fc_prli_s prli_tmpl; |
| 39 | static struct fc_rrq_s rrq_tmpl; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 40 | static struct fchs_s fcp_fchs_tmpl; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 41 | |
| 42 | void |
| 43 | fcbuild_init(void) |
| 44 | { |
| 45 | /* |
| 46 | * fc_els_req_tmpl |
| 47 | */ |
| 48 | fc_els_req_tmpl.routing = FC_RTG_EXT_LINK; |
| 49 | fc_els_req_tmpl.cat_info = FC_CAT_LD_REQUEST; |
| 50 | fc_els_req_tmpl.type = FC_TYPE_ELS; |
| 51 | fc_els_req_tmpl.f_ctl = |
Maggie Zhang | f16a175 | 2010-12-09 19:12:32 -0800 | [diff] [blame] | 52 | bfa_hton3b(FCTL_SEQ_INI | FCTL_FS_EXCH | FCTL_END_SEQ | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 53 | FCTL_SI_XFER); |
| 54 | fc_els_req_tmpl.rx_id = FC_RXID_ANY; |
| 55 | |
| 56 | /* |
| 57 | * fc_els_rsp_tmpl |
| 58 | */ |
| 59 | fc_els_rsp_tmpl.routing = FC_RTG_EXT_LINK; |
| 60 | fc_els_rsp_tmpl.cat_info = FC_CAT_LD_REPLY; |
| 61 | fc_els_rsp_tmpl.type = FC_TYPE_ELS; |
| 62 | fc_els_rsp_tmpl.f_ctl = |
Maggie Zhang | f16a175 | 2010-12-09 19:12:32 -0800 | [diff] [blame] | 63 | bfa_hton3b(FCTL_EC_RESP | FCTL_SEQ_INI | FCTL_LS_EXCH | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 64 | FCTL_END_SEQ | FCTL_SI_XFER); |
| 65 | fc_els_rsp_tmpl.rx_id = FC_RXID_ANY; |
| 66 | |
| 67 | /* |
| 68 | * fc_bls_req_tmpl |
| 69 | */ |
| 70 | fc_bls_req_tmpl.routing = FC_RTG_BASIC_LINK; |
| 71 | fc_bls_req_tmpl.type = FC_TYPE_BLS; |
Maggie Zhang | f16a175 | 2010-12-09 19:12:32 -0800 | [diff] [blame] | 72 | fc_bls_req_tmpl.f_ctl = bfa_hton3b(FCTL_END_SEQ | FCTL_SI_XFER); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 73 | fc_bls_req_tmpl.rx_id = FC_RXID_ANY; |
| 74 | |
| 75 | /* |
| 76 | * fc_bls_rsp_tmpl |
| 77 | */ |
| 78 | fc_bls_rsp_tmpl.routing = FC_RTG_BASIC_LINK; |
| 79 | fc_bls_rsp_tmpl.cat_info = FC_CAT_BA_ACC; |
| 80 | fc_bls_rsp_tmpl.type = FC_TYPE_BLS; |
| 81 | fc_bls_rsp_tmpl.f_ctl = |
Maggie Zhang | f16a175 | 2010-12-09 19:12:32 -0800 | [diff] [blame] | 82 | bfa_hton3b(FCTL_EC_RESP | FCTL_SEQ_INI | FCTL_LS_EXCH | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 83 | FCTL_END_SEQ | FCTL_SI_XFER); |
| 84 | fc_bls_rsp_tmpl.rx_id = FC_RXID_ANY; |
| 85 | |
| 86 | /* |
| 87 | * ba_acc_tmpl |
| 88 | */ |
| 89 | ba_acc_tmpl.seq_id_valid = 0; |
| 90 | ba_acc_tmpl.low_seq_cnt = 0; |
| 91 | ba_acc_tmpl.high_seq_cnt = 0xFFFF; |
| 92 | |
| 93 | /* |
| 94 | * plogi_tmpl |
| 95 | */ |
| 96 | plogi_tmpl.csp.verhi = FC_PH_VER_PH_3; |
| 97 | plogi_tmpl.csp.verlo = FC_PH_VER_4_3; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 98 | plogi_tmpl.csp.ciro = 0x1; |
| 99 | plogi_tmpl.csp.cisc = 0x0; |
| 100 | plogi_tmpl.csp.altbbcred = 0x0; |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 101 | plogi_tmpl.csp.conseq = cpu_to_be16(0x00FF); |
| 102 | plogi_tmpl.csp.ro_bitmap = cpu_to_be16(0x0002); |
| 103 | plogi_tmpl.csp.e_d_tov = cpu_to_be32(2000); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 104 | |
| 105 | plogi_tmpl.class3.class_valid = 1; |
| 106 | plogi_tmpl.class3.sequential = 1; |
| 107 | plogi_tmpl.class3.conseq = 0xFF; |
| 108 | plogi_tmpl.class3.ospx = 1; |
| 109 | |
| 110 | /* |
| 111 | * prli_tmpl |
| 112 | */ |
| 113 | prli_tmpl.command = FC_ELS_PRLI; |
| 114 | prli_tmpl.pglen = 0x10; |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 115 | prli_tmpl.pagebytes = cpu_to_be16(0x0014); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 116 | prli_tmpl.parampage.type = FC_TYPE_FCP; |
| 117 | prli_tmpl.parampage.imagepair = 1; |
| 118 | prli_tmpl.parampage.servparams.rxrdisab = 1; |
| 119 | |
| 120 | /* |
| 121 | * rrq_tmpl |
| 122 | */ |
| 123 | rrq_tmpl.els_cmd.els_code = FC_ELS_RRQ; |
| 124 | |
| 125 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 126 | * fcp_struct fchs_s mpl |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 127 | */ |
| 128 | fcp_fchs_tmpl.routing = FC_RTG_FC4_DEV_DATA; |
| 129 | fcp_fchs_tmpl.cat_info = FC_CAT_UNSOLICIT_CMD; |
| 130 | fcp_fchs_tmpl.type = FC_TYPE_FCP; |
| 131 | fcp_fchs_tmpl.f_ctl = |
Maggie Zhang | f16a175 | 2010-12-09 19:12:32 -0800 | [diff] [blame] | 132 | bfa_hton3b(FCTL_FS_EXCH | FCTL_END_SEQ | FCTL_SI_XFER); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 133 | fcp_fchs_tmpl.seq_id = 1; |
| 134 | fcp_fchs_tmpl.rx_id = FC_RXID_ANY; |
| 135 | } |
| 136 | |
| 137 | static void |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 138 | fc_gs_fchdr_build(struct fchs_s *fchs, u32 d_id, u32 s_id, u32 ox_id) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 139 | { |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 140 | memset(fchs, 0, sizeof(struct fchs_s)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 141 | |
| 142 | fchs->routing = FC_RTG_FC4_DEV_DATA; |
| 143 | fchs->cat_info = FC_CAT_UNSOLICIT_CTRL; |
| 144 | fchs->type = FC_TYPE_SERVICES; |
| 145 | fchs->f_ctl = |
Maggie Zhang | f16a175 | 2010-12-09 19:12:32 -0800 | [diff] [blame] | 146 | bfa_hton3b(FCTL_SEQ_INI | FCTL_FS_EXCH | FCTL_END_SEQ | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 147 | FCTL_SI_XFER); |
| 148 | fchs->rx_id = FC_RXID_ANY; |
| 149 | fchs->d_id = (d_id); |
| 150 | fchs->s_id = (s_id); |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 151 | fchs->ox_id = cpu_to_be16(ox_id); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 152 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 153 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 154 | * @todo no need to set ox_id for request |
| 155 | * no need to set rx_id for response |
| 156 | */ |
| 157 | } |
| 158 | |
Krishna Gudipati | d7be54c | 2011-06-24 20:24:52 -0700 | [diff] [blame] | 159 | static void |
| 160 | fc_gsresp_fchdr_build(struct fchs_s *fchs, u32 d_id, u32 s_id, u16 ox_id) |
| 161 | { |
| 162 | memset(fchs, 0, sizeof(struct fchs_s)); |
| 163 | |
| 164 | fchs->routing = FC_RTG_FC4_DEV_DATA; |
| 165 | fchs->cat_info = FC_CAT_SOLICIT_CTRL; |
| 166 | fchs->type = FC_TYPE_SERVICES; |
| 167 | fchs->f_ctl = |
| 168 | bfa_hton3b(FCTL_EC_RESP | FCTL_SEQ_INI | FCTL_LS_EXCH | |
| 169 | FCTL_END_SEQ | FCTL_SI_XFER); |
| 170 | fchs->d_id = d_id; |
| 171 | fchs->s_id = s_id; |
| 172 | fchs->ox_id = ox_id; |
| 173 | } |
| 174 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 175 | void |
Maggie | 50444a3 | 2010-11-29 18:26:32 -0800 | [diff] [blame] | 176 | fc_els_req_build(struct fchs_s *fchs, u32 d_id, u32 s_id, __be16 ox_id) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 177 | { |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 178 | memcpy(fchs, &fc_els_req_tmpl, sizeof(struct fchs_s)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 179 | fchs->d_id = (d_id); |
| 180 | fchs->s_id = (s_id); |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 181 | fchs->ox_id = cpu_to_be16(ox_id); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | static void |
Maggie | 50444a3 | 2010-11-29 18:26:32 -0800 | [diff] [blame] | 185 | fc_els_rsp_build(struct fchs_s *fchs, u32 d_id, u32 s_id, __be16 ox_id) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 186 | { |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 187 | memcpy(fchs, &fc_els_rsp_tmpl, sizeof(struct fchs_s)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 188 | fchs->d_id = d_id; |
| 189 | fchs->s_id = s_id; |
| 190 | fchs->ox_id = ox_id; |
| 191 | } |
| 192 | |
| 193 | enum fc_parse_status |
| 194 | fc_els_rsp_parse(struct fchs_s *fchs, int len) |
| 195 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 196 | struct fc_els_cmd_s *els_cmd = (struct fc_els_cmd_s *) (fchs + 1); |
| 197 | struct fc_ls_rjt_s *ls_rjt = (struct fc_ls_rjt_s *) els_cmd; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 198 | |
| 199 | len = len; |
| 200 | |
| 201 | switch (els_cmd->els_code) { |
| 202 | case FC_ELS_LS_RJT: |
| 203 | if (ls_rjt->reason_code == FC_LS_RJT_RSN_LOGICAL_BUSY) |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 204 | return FC_PARSE_BUSY; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 205 | else |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 206 | return FC_PARSE_FAILURE; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 207 | |
| 208 | case FC_ELS_ACC: |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 209 | return FC_PARSE_OK; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 210 | } |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 211 | return FC_PARSE_OK; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | static void |
Maggie | 50444a3 | 2010-11-29 18:26:32 -0800 | [diff] [blame] | 215 | fc_bls_rsp_build(struct fchs_s *fchs, u32 d_id, u32 s_id, __be16 ox_id) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 216 | { |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 217 | memcpy(fchs, &fc_bls_rsp_tmpl, sizeof(struct fchs_s)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 218 | fchs->d_id = d_id; |
| 219 | fchs->s_id = s_id; |
| 220 | fchs->ox_id = ox_id; |
| 221 | } |
| 222 | |
| 223 | static u16 |
| 224 | fc_plogi_x_build(struct fchs_s *fchs, void *pld, u32 d_id, u32 s_id, |
Maggie | 50444a3 | 2010-11-29 18:26:32 -0800 | [diff] [blame] | 225 | __be16 ox_id, wwn_t port_name, wwn_t node_name, |
Krishna Gudipati | be540a9 | 2011-06-13 15:53:04 -0700 | [diff] [blame] | 226 | u16 pdu_size, u16 bb_cr, u8 els_code) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 227 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 228 | struct fc_logi_s *plogi = (struct fc_logi_s *) (pld); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 229 | |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 230 | memcpy(plogi, &plogi_tmpl, sizeof(struct fc_logi_s)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 231 | |
Krishna Gudipati | bc0e2c2 | 2012-09-21 17:23:59 -0700 | [diff] [blame] | 232 | /* For FC AL bb_cr is 0 and altbbcred is 1 */ |
| 233 | if (!bb_cr) |
| 234 | plogi->csp.altbbcred = 1; |
| 235 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 236 | plogi->els_cmd.els_code = els_code; |
| 237 | if (els_code == FC_ELS_PLOGI) |
| 238 | fc_els_req_build(fchs, d_id, s_id, ox_id); |
| 239 | else |
| 240 | fc_els_rsp_build(fchs, d_id, s_id, ox_id); |
| 241 | |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 242 | plogi->csp.rxsz = plogi->class3.rxsz = cpu_to_be16(pdu_size); |
Krishna Gudipati | be540a9 | 2011-06-13 15:53:04 -0700 | [diff] [blame] | 243 | plogi->csp.bbcred = cpu_to_be16(bb_cr); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 244 | |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 245 | memcpy(&plogi->port_name, &port_name, sizeof(wwn_t)); |
| 246 | memcpy(&plogi->node_name, &node_name, sizeof(wwn_t)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 247 | |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 248 | return sizeof(struct fc_logi_s); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | u16 |
| 252 | fc_flogi_build(struct fchs_s *fchs, struct fc_logi_s *flogi, u32 s_id, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 253 | u16 ox_id, wwn_t port_name, wwn_t node_name, u16 pdu_size, |
| 254 | u8 set_npiv, u8 set_auth, u16 local_bb_credits) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 255 | { |
Maggie Zhang | f16a175 | 2010-12-09 19:12:32 -0800 | [diff] [blame] | 256 | u32 d_id = bfa_hton3b(FC_FABRIC_PORT); |
Maggie | 50444a3 | 2010-11-29 18:26:32 -0800 | [diff] [blame] | 257 | __be32 *vvl_info; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 258 | |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 259 | memcpy(flogi, &plogi_tmpl, sizeof(struct fc_logi_s)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 260 | |
| 261 | flogi->els_cmd.els_code = FC_ELS_FLOGI; |
| 262 | fc_els_req_build(fchs, d_id, s_id, ox_id); |
| 263 | |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 264 | flogi->csp.rxsz = flogi->class3.rxsz = cpu_to_be16(pdu_size); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 265 | flogi->port_name = port_name; |
| 266 | flogi->node_name = node_name; |
| 267 | |
| 268 | /* |
| 269 | * Set the NPIV Capability Bit ( word 1, bit 31) of Common |
| 270 | * Service Parameters. |
| 271 | */ |
| 272 | flogi->csp.ciro = set_npiv; |
| 273 | |
| 274 | /* set AUTH capability */ |
| 275 | flogi->csp.security = set_auth; |
| 276 | |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 277 | flogi->csp.bbcred = cpu_to_be16(local_bb_credits); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 278 | |
| 279 | /* Set brcd token in VVL */ |
| 280 | vvl_info = (u32 *)&flogi->vvl[0]; |
| 281 | |
| 282 | /* set the flag to indicate the presence of VVL */ |
| 283 | flogi->csp.npiv_supp = 1; /* @todo. field name is not correct */ |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 284 | vvl_info[0] = cpu_to_be32(FLOGI_VVL_BRCD); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 285 | |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 286 | return sizeof(struct fc_logi_s); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | u16 |
| 290 | fc_flogi_acc_build(struct fchs_s *fchs, struct fc_logi_s *flogi, u32 s_id, |
Maggie | 50444a3 | 2010-11-29 18:26:32 -0800 | [diff] [blame] | 291 | __be16 ox_id, wwn_t port_name, wwn_t node_name, |
Krishna Gudipati | be540a9 | 2011-06-13 15:53:04 -0700 | [diff] [blame] | 292 | u16 pdu_size, u16 local_bb_credits, u8 bb_scn) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 293 | { |
| 294 | u32 d_id = 0; |
Krishna Gudipati | be540a9 | 2011-06-13 15:53:04 -0700 | [diff] [blame] | 295 | u16 bbscn_rxsz = (bb_scn << 12) | pdu_size; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 296 | |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 297 | memcpy(flogi, &plogi_tmpl, sizeof(struct fc_logi_s)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 298 | fc_els_rsp_build(fchs, d_id, s_id, ox_id); |
| 299 | |
| 300 | flogi->els_cmd.els_code = FC_ELS_ACC; |
Krishna Gudipati | be540a9 | 2011-06-13 15:53:04 -0700 | [diff] [blame] | 301 | flogi->class3.rxsz = cpu_to_be16(pdu_size); |
| 302 | flogi->csp.rxsz = cpu_to_be16(bbscn_rxsz); /* bb_scn/rxsz */ |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 303 | flogi->port_name = port_name; |
| 304 | flogi->node_name = node_name; |
| 305 | |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 306 | flogi->csp.bbcred = cpu_to_be16(local_bb_credits); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 307 | |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 308 | return sizeof(struct fc_logi_s); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | u16 |
| 312 | fc_fdisc_build(struct fchs_s *fchs, struct fc_logi_s *flogi, u32 s_id, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 313 | u16 ox_id, wwn_t port_name, wwn_t node_name, u16 pdu_size) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 314 | { |
Maggie Zhang | f16a175 | 2010-12-09 19:12:32 -0800 | [diff] [blame] | 315 | u32 d_id = bfa_hton3b(FC_FABRIC_PORT); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 316 | |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 317 | memcpy(flogi, &plogi_tmpl, sizeof(struct fc_logi_s)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 318 | |
| 319 | flogi->els_cmd.els_code = FC_ELS_FDISC; |
| 320 | fc_els_req_build(fchs, d_id, s_id, ox_id); |
| 321 | |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 322 | flogi->csp.rxsz = flogi->class3.rxsz = cpu_to_be16(pdu_size); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 323 | flogi->port_name = port_name; |
| 324 | flogi->node_name = node_name; |
| 325 | |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 326 | return sizeof(struct fc_logi_s); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | u16 |
| 330 | fc_plogi_build(struct fchs_s *fchs, void *pld, u32 d_id, u32 s_id, |
| 331 | u16 ox_id, wwn_t port_name, wwn_t node_name, |
Krishna Gudipati | be540a9 | 2011-06-13 15:53:04 -0700 | [diff] [blame] | 332 | u16 pdu_size, u16 bb_cr) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 333 | { |
| 334 | return fc_plogi_x_build(fchs, pld, d_id, s_id, ox_id, port_name, |
Krishna Gudipati | be540a9 | 2011-06-13 15:53:04 -0700 | [diff] [blame] | 335 | node_name, pdu_size, bb_cr, FC_ELS_PLOGI); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 336 | } |
| 337 | |
| 338 | u16 |
| 339 | fc_plogi_acc_build(struct fchs_s *fchs, void *pld, u32 d_id, u32 s_id, |
| 340 | u16 ox_id, wwn_t port_name, wwn_t node_name, |
Krishna Gudipati | be540a9 | 2011-06-13 15:53:04 -0700 | [diff] [blame] | 341 | u16 pdu_size, u16 bb_cr) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 342 | { |
| 343 | return fc_plogi_x_build(fchs, pld, d_id, s_id, ox_id, port_name, |
Krishna Gudipati | be540a9 | 2011-06-13 15:53:04 -0700 | [diff] [blame] | 344 | node_name, pdu_size, bb_cr, FC_ELS_ACC); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | enum fc_parse_status |
| 348 | fc_plogi_rsp_parse(struct fchs_s *fchs, int len, wwn_t port_name) |
| 349 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 350 | struct fc_els_cmd_s *els_cmd = (struct fc_els_cmd_s *) (fchs + 1); |
| 351 | struct fc_logi_s *plogi; |
| 352 | struct fc_ls_rjt_s *ls_rjt; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 353 | |
| 354 | switch (els_cmd->els_code) { |
| 355 | case FC_ELS_LS_RJT: |
| 356 | ls_rjt = (struct fc_ls_rjt_s *) (fchs + 1); |
| 357 | if (ls_rjt->reason_code == FC_LS_RJT_RSN_LOGICAL_BUSY) |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 358 | return FC_PARSE_BUSY; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 359 | else |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 360 | return FC_PARSE_FAILURE; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 361 | case FC_ELS_ACC: |
| 362 | plogi = (struct fc_logi_s *) (fchs + 1); |
| 363 | if (len < sizeof(struct fc_logi_s)) |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 364 | return FC_PARSE_FAILURE; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 365 | |
| 366 | if (!wwn_is_equal(plogi->port_name, port_name)) |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 367 | return FC_PARSE_FAILURE; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 368 | |
| 369 | if (!plogi->class3.class_valid) |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 370 | return FC_PARSE_FAILURE; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 371 | |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 372 | if (be16_to_cpu(plogi->class3.rxsz) < (FC_MIN_PDUSZ)) |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 373 | return FC_PARSE_FAILURE; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 374 | |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 375 | return FC_PARSE_OK; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 376 | default: |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 377 | return FC_PARSE_FAILURE; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 378 | } |
| 379 | } |
| 380 | |
| 381 | enum fc_parse_status |
| 382 | fc_plogi_parse(struct fchs_s *fchs) |
| 383 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 384 | struct fc_logi_s *plogi = (struct fc_logi_s *) (fchs + 1); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 385 | |
| 386 | if (plogi->class3.class_valid != 1) |
| 387 | return FC_PARSE_FAILURE; |
| 388 | |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 389 | if ((be16_to_cpu(plogi->class3.rxsz) < FC_MIN_PDUSZ) |
| 390 | || (be16_to_cpu(plogi->class3.rxsz) > FC_MAX_PDUSZ) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 391 | || (plogi->class3.rxsz == 0)) |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 392 | return FC_PARSE_FAILURE; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 393 | |
| 394 | return FC_PARSE_OK; |
| 395 | } |
| 396 | |
| 397 | u16 |
| 398 | fc_prli_build(struct fchs_s *fchs, void *pld, u32 d_id, u32 s_id, |
| 399 | u16 ox_id) |
| 400 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 401 | struct fc_prli_s *prli = (struct fc_prli_s *) (pld); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 402 | |
| 403 | fc_els_req_build(fchs, d_id, s_id, ox_id); |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 404 | memcpy(prli, &prli_tmpl, sizeof(struct fc_prli_s)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 405 | |
| 406 | prli->command = FC_ELS_PRLI; |
| 407 | prli->parampage.servparams.initiator = 1; |
| 408 | prli->parampage.servparams.retry = 1; |
| 409 | prli->parampage.servparams.rec_support = 1; |
| 410 | prli->parampage.servparams.task_retry_id = 0; |
| 411 | prli->parampage.servparams.confirm = 1; |
| 412 | |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 413 | return sizeof(struct fc_prli_s); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | u16 |
| 417 | fc_prli_acc_build(struct fchs_s *fchs, void *pld, u32 d_id, u32 s_id, |
Maggie | 50444a3 | 2010-11-29 18:26:32 -0800 | [diff] [blame] | 418 | __be16 ox_id, enum bfa_lport_role role) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 419 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 420 | struct fc_prli_s *prli = (struct fc_prli_s *) (pld); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 421 | |
| 422 | fc_els_rsp_build(fchs, d_id, s_id, ox_id); |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 423 | memcpy(prli, &prli_tmpl, sizeof(struct fc_prli_s)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 424 | |
| 425 | prli->command = FC_ELS_ACC; |
| 426 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 427 | prli->parampage.servparams.initiator = 1; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 428 | |
| 429 | prli->parampage.rspcode = FC_PRLI_ACC_XQTD; |
| 430 | |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 431 | return sizeof(struct fc_prli_s); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 432 | } |
| 433 | |
| 434 | enum fc_parse_status |
| 435 | fc_prli_rsp_parse(struct fc_prli_s *prli, int len) |
| 436 | { |
| 437 | if (len < sizeof(struct fc_prli_s)) |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 438 | return FC_PARSE_FAILURE; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 439 | |
| 440 | if (prli->command != FC_ELS_ACC) |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 441 | return FC_PARSE_FAILURE; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 442 | |
| 443 | if ((prli->parampage.rspcode != FC_PRLI_ACC_XQTD) |
| 444 | && (prli->parampage.rspcode != FC_PRLI_ACC_PREDEF_IMG)) |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 445 | return FC_PARSE_FAILURE; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 446 | |
| 447 | if (prli->parampage.servparams.target != 1) |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 448 | return FC_PARSE_FAILURE; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 449 | |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 450 | return FC_PARSE_OK; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 451 | } |
| 452 | |
| 453 | enum fc_parse_status |
| 454 | fc_prli_parse(struct fc_prli_s *prli) |
| 455 | { |
| 456 | if (prli->parampage.type != FC_TYPE_FCP) |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 457 | return FC_PARSE_FAILURE; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 458 | |
| 459 | if (!prli->parampage.imagepair) |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 460 | return FC_PARSE_FAILURE; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 461 | |
| 462 | if (!prli->parampage.servparams.initiator) |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 463 | return FC_PARSE_FAILURE; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 464 | |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 465 | return FC_PARSE_OK; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 466 | } |
| 467 | |
| 468 | u16 |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 469 | fc_logo_build(struct fchs_s *fchs, struct fc_logo_s *logo, u32 d_id, u32 s_id, |
| 470 | u16 ox_id, wwn_t port_name) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 471 | { |
| 472 | fc_els_req_build(fchs, d_id, s_id, ox_id); |
| 473 | |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 474 | memset(logo, '\0', sizeof(struct fc_logo_s)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 475 | logo->els_cmd.els_code = FC_ELS_LOGO; |
| 476 | logo->nport_id = (s_id); |
| 477 | logo->orig_port_name = port_name; |
| 478 | |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 479 | return sizeof(struct fc_logo_s); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 480 | } |
| 481 | |
Maggie Zhang | da99dcc | 2010-12-09 19:13:20 -0800 | [diff] [blame] | 482 | static u16 |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 483 | fc_adisc_x_build(struct fchs_s *fchs, struct fc_adisc_s *adisc, u32 d_id, |
Maggie | 50444a3 | 2010-11-29 18:26:32 -0800 | [diff] [blame] | 484 | u32 s_id, __be16 ox_id, wwn_t port_name, |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 485 | wwn_t node_name, u8 els_code) |
| 486 | { |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 487 | memset(adisc, '\0', sizeof(struct fc_adisc_s)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 488 | |
| 489 | adisc->els_cmd.els_code = els_code; |
| 490 | |
| 491 | if (els_code == FC_ELS_ADISC) |
| 492 | fc_els_req_build(fchs, d_id, s_id, ox_id); |
| 493 | else |
| 494 | fc_els_rsp_build(fchs, d_id, s_id, ox_id); |
| 495 | |
| 496 | adisc->orig_HA = 0; |
| 497 | adisc->orig_port_name = port_name; |
| 498 | adisc->orig_node_name = node_name; |
| 499 | adisc->nport_id = (s_id); |
| 500 | |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 501 | return sizeof(struct fc_adisc_s); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 502 | } |
| 503 | |
| 504 | u16 |
| 505 | fc_adisc_build(struct fchs_s *fchs, struct fc_adisc_s *adisc, u32 d_id, |
Maggie | 50444a3 | 2010-11-29 18:26:32 -0800 | [diff] [blame] | 506 | u32 s_id, __be16 ox_id, wwn_t port_name, wwn_t node_name) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 507 | { |
| 508 | return fc_adisc_x_build(fchs, adisc, d_id, s_id, ox_id, port_name, |
| 509 | node_name, FC_ELS_ADISC); |
| 510 | } |
| 511 | |
| 512 | u16 |
| 513 | fc_adisc_acc_build(struct fchs_s *fchs, struct fc_adisc_s *adisc, u32 d_id, |
Maggie | 50444a3 | 2010-11-29 18:26:32 -0800 | [diff] [blame] | 514 | u32 s_id, __be16 ox_id, wwn_t port_name, |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 515 | wwn_t node_name) |
| 516 | { |
| 517 | return fc_adisc_x_build(fchs, adisc, d_id, s_id, ox_id, port_name, |
| 518 | node_name, FC_ELS_ACC); |
| 519 | } |
| 520 | |
| 521 | enum fc_parse_status |
| 522 | fc_adisc_rsp_parse(struct fc_adisc_s *adisc, int len, wwn_t port_name, |
| 523 | wwn_t node_name) |
| 524 | { |
| 525 | |
| 526 | if (len < sizeof(struct fc_adisc_s)) |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 527 | return FC_PARSE_FAILURE; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 528 | |
| 529 | if (adisc->els_cmd.els_code != FC_ELS_ACC) |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 530 | return FC_PARSE_FAILURE; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 531 | |
| 532 | if (!wwn_is_equal(adisc->orig_port_name, port_name)) |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 533 | return FC_PARSE_FAILURE; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 534 | |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 535 | return FC_PARSE_OK; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 536 | } |
| 537 | |
| 538 | enum fc_parse_status |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 539 | fc_adisc_parse(struct fchs_s *fchs, void *pld, u32 host_dap, wwn_t node_name, |
| 540 | wwn_t port_name) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 541 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 542 | struct fc_adisc_s *adisc = (struct fc_adisc_s *) pld; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 543 | |
| 544 | if (adisc->els_cmd.els_code != FC_ELS_ACC) |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 545 | return FC_PARSE_FAILURE; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 546 | |
| 547 | if ((adisc->nport_id == (host_dap)) |
| 548 | && wwn_is_equal(adisc->orig_port_name, port_name) |
| 549 | && wwn_is_equal(adisc->orig_node_name, node_name)) |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 550 | return FC_PARSE_OK; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 551 | |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 552 | return FC_PARSE_FAILURE; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 553 | } |
| 554 | |
| 555 | enum fc_parse_status |
| 556 | fc_pdisc_parse(struct fchs_s *fchs, wwn_t node_name, wwn_t port_name) |
| 557 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 558 | struct fc_logi_s *pdisc = (struct fc_logi_s *) (fchs + 1); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 559 | |
| 560 | if (pdisc->class3.class_valid != 1) |
| 561 | return FC_PARSE_FAILURE; |
| 562 | |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 563 | if ((be16_to_cpu(pdisc->class3.rxsz) < |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 564 | (FC_MIN_PDUSZ - sizeof(struct fchs_s))) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 565 | || (pdisc->class3.rxsz == 0)) |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 566 | return FC_PARSE_FAILURE; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 567 | |
| 568 | if (!wwn_is_equal(pdisc->port_name, port_name)) |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 569 | return FC_PARSE_FAILURE; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 570 | |
| 571 | if (!wwn_is_equal(pdisc->node_name, node_name)) |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 572 | return FC_PARSE_FAILURE; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 573 | |
| 574 | return FC_PARSE_OK; |
| 575 | } |
| 576 | |
| 577 | u16 |
| 578 | fc_abts_build(struct fchs_s *fchs, u32 d_id, u32 s_id, u16 ox_id) |
| 579 | { |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 580 | memcpy(fchs, &fc_bls_req_tmpl, sizeof(struct fchs_s)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 581 | fchs->cat_info = FC_CAT_ABTS; |
| 582 | fchs->d_id = (d_id); |
| 583 | fchs->s_id = (s_id); |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 584 | fchs->ox_id = cpu_to_be16(ox_id); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 585 | |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 586 | return sizeof(struct fchs_s); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 587 | } |
| 588 | |
| 589 | enum fc_parse_status |
| 590 | fc_abts_rsp_parse(struct fchs_s *fchs, int len) |
| 591 | { |
| 592 | if ((fchs->cat_info == FC_CAT_BA_ACC) |
| 593 | || (fchs->cat_info == FC_CAT_BA_RJT)) |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 594 | return FC_PARSE_OK; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 595 | |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 596 | return FC_PARSE_FAILURE; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 597 | } |
| 598 | |
| 599 | u16 |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 600 | fc_rrq_build(struct fchs_s *fchs, struct fc_rrq_s *rrq, u32 d_id, u32 s_id, |
| 601 | u16 ox_id, u16 rrq_oxid) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 602 | { |
| 603 | fc_els_req_build(fchs, d_id, s_id, ox_id); |
| 604 | |
| 605 | /* |
| 606 | * build rrq payload |
| 607 | */ |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 608 | memcpy(rrq, &rrq_tmpl, sizeof(struct fc_rrq_s)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 609 | rrq->s_id = (s_id); |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 610 | rrq->ox_id = cpu_to_be16(rrq_oxid); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 611 | rrq->rx_id = FC_RXID_ANY; |
| 612 | |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 613 | return sizeof(struct fc_rrq_s); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 614 | } |
| 615 | |
| 616 | u16 |
| 617 | fc_logo_acc_build(struct fchs_s *fchs, void *pld, u32 d_id, u32 s_id, |
Maggie | 50444a3 | 2010-11-29 18:26:32 -0800 | [diff] [blame] | 618 | __be16 ox_id) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 619 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 620 | struct fc_els_cmd_s *acc = pld; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 621 | |
| 622 | fc_els_rsp_build(fchs, d_id, s_id, ox_id); |
| 623 | |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 624 | memset(acc, 0, sizeof(struct fc_els_cmd_s)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 625 | acc->els_code = FC_ELS_ACC; |
| 626 | |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 627 | return sizeof(struct fc_els_cmd_s); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 628 | } |
| 629 | |
| 630 | u16 |
| 631 | fc_ls_rjt_build(struct fchs_s *fchs, struct fc_ls_rjt_s *ls_rjt, u32 d_id, |
Maggie | 50444a3 | 2010-11-29 18:26:32 -0800 | [diff] [blame] | 632 | u32 s_id, __be16 ox_id, u8 reason_code, |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 633 | u8 reason_code_expl) |
| 634 | { |
| 635 | fc_els_rsp_build(fchs, d_id, s_id, ox_id); |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 636 | memset(ls_rjt, 0, sizeof(struct fc_ls_rjt_s)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 637 | |
| 638 | ls_rjt->els_cmd.els_code = FC_ELS_LS_RJT; |
| 639 | ls_rjt->reason_code = reason_code; |
| 640 | ls_rjt->reason_code_expl = reason_code_expl; |
| 641 | ls_rjt->vendor_unique = 0x00; |
| 642 | |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 643 | return sizeof(struct fc_ls_rjt_s); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 644 | } |
| 645 | |
| 646 | u16 |
| 647 | fc_ba_acc_build(struct fchs_s *fchs, struct fc_ba_acc_s *ba_acc, u32 d_id, |
Maggie | 50444a3 | 2010-11-29 18:26:32 -0800 | [diff] [blame] | 648 | u32 s_id, __be16 ox_id, u16 rx_id) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 649 | { |
| 650 | fc_bls_rsp_build(fchs, d_id, s_id, ox_id); |
| 651 | |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 652 | memcpy(ba_acc, &ba_acc_tmpl, sizeof(struct fc_ba_acc_s)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 653 | |
| 654 | fchs->rx_id = rx_id; |
| 655 | |
| 656 | ba_acc->ox_id = fchs->ox_id; |
| 657 | ba_acc->rx_id = fchs->rx_id; |
| 658 | |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 659 | return sizeof(struct fc_ba_acc_s); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 660 | } |
| 661 | |
| 662 | u16 |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 663 | fc_ls_acc_build(struct fchs_s *fchs, struct fc_els_cmd_s *els_cmd, u32 d_id, |
Maggie | 50444a3 | 2010-11-29 18:26:32 -0800 | [diff] [blame] | 664 | u32 s_id, __be16 ox_id) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 665 | { |
| 666 | fc_els_rsp_build(fchs, d_id, s_id, ox_id); |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 667 | memset(els_cmd, 0, sizeof(struct fc_els_cmd_s)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 668 | els_cmd->els_code = FC_ELS_ACC; |
| 669 | |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 670 | return sizeof(struct fc_els_cmd_s); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 671 | } |
| 672 | |
| 673 | int |
| 674 | fc_logout_params_pages(struct fchs_s *fc_frame, u8 els_code) |
| 675 | { |
| 676 | int num_pages = 0; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 677 | struct fc_prlo_s *prlo; |
| 678 | struct fc_tprlo_s *tprlo; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 679 | |
| 680 | if (els_code == FC_ELS_PRLO) { |
| 681 | prlo = (struct fc_prlo_s *) (fc_frame + 1); |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 682 | num_pages = (be16_to_cpu(prlo->payload_len) - 4) / 16; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 683 | } else { |
| 684 | tprlo = (struct fc_tprlo_s *) (fc_frame + 1); |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 685 | num_pages = (be16_to_cpu(tprlo->payload_len) - 4) / 16; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 686 | } |
| 687 | return num_pages; |
| 688 | } |
| 689 | |
| 690 | u16 |
| 691 | fc_tprlo_acc_build(struct fchs_s *fchs, struct fc_tprlo_acc_s *tprlo_acc, |
Maggie | 50444a3 | 2010-11-29 18:26:32 -0800 | [diff] [blame] | 692 | u32 d_id, u32 s_id, __be16 ox_id, int num_pages) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 693 | { |
| 694 | int page; |
| 695 | |
| 696 | fc_els_rsp_build(fchs, d_id, s_id, ox_id); |
| 697 | |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 698 | memset(tprlo_acc, 0, (num_pages * 16) + 4); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 699 | tprlo_acc->command = FC_ELS_ACC; |
| 700 | |
| 701 | tprlo_acc->page_len = 0x10; |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 702 | tprlo_acc->payload_len = cpu_to_be16((num_pages * 16) + 4); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 703 | |
| 704 | for (page = 0; page < num_pages; page++) { |
| 705 | tprlo_acc->tprlo_acc_params[page].opa_valid = 0; |
| 706 | tprlo_acc->tprlo_acc_params[page].rpa_valid = 0; |
| 707 | tprlo_acc->tprlo_acc_params[page].fc4type_csp = FC_TYPE_FCP; |
| 708 | tprlo_acc->tprlo_acc_params[page].orig_process_assc = 0; |
| 709 | tprlo_acc->tprlo_acc_params[page].resp_process_assc = 0; |
| 710 | } |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 711 | return be16_to_cpu(tprlo_acc->payload_len); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 712 | } |
| 713 | |
| 714 | u16 |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 715 | fc_prlo_acc_build(struct fchs_s *fchs, struct fc_prlo_acc_s *prlo_acc, u32 d_id, |
Maggie | 50444a3 | 2010-11-29 18:26:32 -0800 | [diff] [blame] | 716 | u32 s_id, __be16 ox_id, int num_pages) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 717 | { |
| 718 | int page; |
| 719 | |
| 720 | fc_els_rsp_build(fchs, d_id, s_id, ox_id); |
| 721 | |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 722 | memset(prlo_acc, 0, (num_pages * 16) + 4); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 723 | prlo_acc->command = FC_ELS_ACC; |
| 724 | prlo_acc->page_len = 0x10; |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 725 | prlo_acc->payload_len = cpu_to_be16((num_pages * 16) + 4); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 726 | |
| 727 | for (page = 0; page < num_pages; page++) { |
| 728 | prlo_acc->prlo_acc_params[page].opa_valid = 0; |
| 729 | prlo_acc->prlo_acc_params[page].rpa_valid = 0; |
| 730 | prlo_acc->prlo_acc_params[page].fc4type_csp = FC_TYPE_FCP; |
| 731 | prlo_acc->prlo_acc_params[page].orig_process_assc = 0; |
| 732 | prlo_acc->prlo_acc_params[page].resp_process_assc = 0; |
| 733 | } |
| 734 | |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 735 | return be16_to_cpu(prlo_acc->payload_len); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 736 | } |
| 737 | |
| 738 | u16 |
| 739 | fc_rnid_build(struct fchs_s *fchs, struct fc_rnid_cmd_s *rnid, u32 d_id, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 740 | u32 s_id, u16 ox_id, u32 data_format) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 741 | { |
| 742 | fc_els_req_build(fchs, d_id, s_id, ox_id); |
| 743 | |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 744 | memset(rnid, 0, sizeof(struct fc_rnid_cmd_s)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 745 | |
| 746 | rnid->els_cmd.els_code = FC_ELS_RNID; |
| 747 | rnid->node_id_data_format = data_format; |
| 748 | |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 749 | return sizeof(struct fc_rnid_cmd_s); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 750 | } |
| 751 | |
| 752 | u16 |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 753 | fc_rnid_acc_build(struct fchs_s *fchs, struct fc_rnid_acc_s *rnid_acc, u32 d_id, |
Maggie | 50444a3 | 2010-11-29 18:26:32 -0800 | [diff] [blame] | 754 | u32 s_id, __be16 ox_id, u32 data_format, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 755 | struct fc_rnid_common_id_data_s *common_id_data, |
| 756 | struct fc_rnid_general_topology_data_s *gen_topo_data) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 757 | { |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 758 | memset(rnid_acc, 0, sizeof(struct fc_rnid_acc_s)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 759 | |
| 760 | fc_els_rsp_build(fchs, d_id, s_id, ox_id); |
| 761 | |
| 762 | rnid_acc->els_cmd.els_code = FC_ELS_ACC; |
| 763 | rnid_acc->node_id_data_format = data_format; |
| 764 | rnid_acc->common_id_data_length = |
| 765 | sizeof(struct fc_rnid_common_id_data_s); |
| 766 | rnid_acc->common_id_data = *common_id_data; |
| 767 | |
| 768 | if (data_format == RNID_NODEID_DATA_FORMAT_DISCOVERY) { |
| 769 | rnid_acc->specific_id_data_length = |
| 770 | sizeof(struct fc_rnid_general_topology_data_s); |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 771 | rnid_acc->gen_topology_data = *gen_topo_data; |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 772 | return sizeof(struct fc_rnid_acc_s); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 773 | } else { |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 774 | return sizeof(struct fc_rnid_acc_s) - |
| 775 | sizeof(struct fc_rnid_general_topology_data_s); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 776 | } |
| 777 | |
| 778 | } |
| 779 | |
| 780 | u16 |
| 781 | fc_rpsc_build(struct fchs_s *fchs, struct fc_rpsc_cmd_s *rpsc, u32 d_id, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 782 | u32 s_id, u16 ox_id) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 783 | { |
| 784 | fc_els_req_build(fchs, d_id, s_id, ox_id); |
| 785 | |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 786 | memset(rpsc, 0, sizeof(struct fc_rpsc_cmd_s)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 787 | |
| 788 | rpsc->els_cmd.els_code = FC_ELS_RPSC; |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 789 | return sizeof(struct fc_rpsc_cmd_s); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 790 | } |
| 791 | |
| 792 | u16 |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 793 | fc_rpsc2_build(struct fchs_s *fchs, struct fc_rpsc2_cmd_s *rpsc2, u32 d_id, |
| 794 | u32 s_id, u32 *pid_list, u16 npids) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 795 | { |
Maggie Zhang | f16a175 | 2010-12-09 19:12:32 -0800 | [diff] [blame] | 796 | u32 dctlr_id = FC_DOMAIN_CTRLR(bfa_hton3b(d_id)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 797 | int i = 0; |
| 798 | |
Maggie Zhang | f16a175 | 2010-12-09 19:12:32 -0800 | [diff] [blame] | 799 | fc_els_req_build(fchs, bfa_hton3b(dctlr_id), s_id, 0); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 800 | |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 801 | memset(rpsc2, 0, sizeof(struct fc_rpsc2_cmd_s)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 802 | |
| 803 | rpsc2->els_cmd.els_code = FC_ELS_RPSC; |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 804 | rpsc2->token = cpu_to_be32(FC_BRCD_TOKEN); |
| 805 | rpsc2->num_pids = cpu_to_be16(npids); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 806 | for (i = 0; i < npids; i++) |
| 807 | rpsc2->pid_list[i].pid = pid_list[i]; |
| 808 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 809 | return sizeof(struct fc_rpsc2_cmd_s) + ((npids - 1) * (sizeof(u32))); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 810 | } |
| 811 | |
| 812 | u16 |
| 813 | fc_rpsc_acc_build(struct fchs_s *fchs, struct fc_rpsc_acc_s *rpsc_acc, |
Maggie | 50444a3 | 2010-11-29 18:26:32 -0800 | [diff] [blame] | 814 | u32 d_id, u32 s_id, __be16 ox_id, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 815 | struct fc_rpsc_speed_info_s *oper_speed) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 816 | { |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 817 | memset(rpsc_acc, 0, sizeof(struct fc_rpsc_acc_s)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 818 | |
| 819 | fc_els_rsp_build(fchs, d_id, s_id, ox_id); |
| 820 | |
| 821 | rpsc_acc->command = FC_ELS_ACC; |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 822 | rpsc_acc->num_entries = cpu_to_be16(1); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 823 | |
| 824 | rpsc_acc->speed_info[0].port_speed_cap = |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 825 | cpu_to_be16(oper_speed->port_speed_cap); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 826 | |
| 827 | rpsc_acc->speed_info[0].port_op_speed = |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 828 | cpu_to_be16(oper_speed->port_op_speed); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 829 | |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 830 | return sizeof(struct fc_rpsc_acc_s); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 831 | } |
| 832 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 833 | u16 |
| 834 | fc_logo_rsp_parse(struct fchs_s *fchs, int len) |
| 835 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 836 | struct fc_els_cmd_s *els_cmd = (struct fc_els_cmd_s *) (fchs + 1); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 837 | |
| 838 | len = len; |
| 839 | if (els_cmd->els_code != FC_ELS_ACC) |
| 840 | return FC_PARSE_FAILURE; |
| 841 | |
| 842 | return FC_PARSE_OK; |
| 843 | } |
| 844 | |
| 845 | u16 |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 846 | fc_pdisc_build(struct fchs_s *fchs, u32 d_id, u32 s_id, u16 ox_id, |
| 847 | wwn_t port_name, wwn_t node_name, u16 pdu_size) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 848 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 849 | struct fc_logi_s *pdisc = (struct fc_logi_s *) (fchs + 1); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 850 | |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 851 | memcpy(pdisc, &plogi_tmpl, sizeof(struct fc_logi_s)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 852 | |
| 853 | pdisc->els_cmd.els_code = FC_ELS_PDISC; |
| 854 | fc_els_req_build(fchs, d_id, s_id, ox_id); |
| 855 | |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 856 | pdisc->csp.rxsz = pdisc->class3.rxsz = cpu_to_be16(pdu_size); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 857 | pdisc->port_name = port_name; |
| 858 | pdisc->node_name = node_name; |
| 859 | |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 860 | return sizeof(struct fc_logi_s); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 861 | } |
| 862 | |
| 863 | u16 |
| 864 | fc_pdisc_rsp_parse(struct fchs_s *fchs, int len, wwn_t port_name) |
| 865 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 866 | struct fc_logi_s *pdisc = (struct fc_logi_s *) (fchs + 1); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 867 | |
| 868 | if (len < sizeof(struct fc_logi_s)) |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 869 | return FC_PARSE_LEN_INVAL; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 870 | |
| 871 | if (pdisc->els_cmd.els_code != FC_ELS_ACC) |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 872 | return FC_PARSE_ACC_INVAL; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 873 | |
| 874 | if (!wwn_is_equal(pdisc->port_name, port_name)) |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 875 | return FC_PARSE_PWWN_NOT_EQUAL; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 876 | |
| 877 | if (!pdisc->class3.class_valid) |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 878 | return FC_PARSE_NWWN_NOT_EQUAL; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 879 | |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 880 | if (be16_to_cpu(pdisc->class3.rxsz) < (FC_MIN_PDUSZ)) |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 881 | return FC_PARSE_RXSZ_INVAL; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 882 | |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 883 | return FC_PARSE_OK; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 884 | } |
| 885 | |
| 886 | u16 |
| 887 | fc_prlo_build(struct fchs_s *fchs, u32 d_id, u32 s_id, u16 ox_id, |
| 888 | int num_pages) |
| 889 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 890 | struct fc_prlo_s *prlo = (struct fc_prlo_s *) (fchs + 1); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 891 | int page; |
| 892 | |
| 893 | fc_els_req_build(fchs, d_id, s_id, ox_id); |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 894 | memset(prlo, 0, (num_pages * 16) + 4); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 895 | prlo->command = FC_ELS_PRLO; |
| 896 | prlo->page_len = 0x10; |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 897 | prlo->payload_len = cpu_to_be16((num_pages * 16) + 4); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 898 | |
| 899 | for (page = 0; page < num_pages; page++) { |
| 900 | prlo->prlo_params[page].type = FC_TYPE_FCP; |
| 901 | prlo->prlo_params[page].opa_valid = 0; |
| 902 | prlo->prlo_params[page].rpa_valid = 0; |
| 903 | prlo->prlo_params[page].orig_process_assc = 0; |
| 904 | prlo->prlo_params[page].resp_process_assc = 0; |
| 905 | } |
| 906 | |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 907 | return be16_to_cpu(prlo->payload_len); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 908 | } |
| 909 | |
| 910 | u16 |
| 911 | fc_prlo_rsp_parse(struct fchs_s *fchs, int len) |
| 912 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 913 | struct fc_prlo_acc_s *prlo = (struct fc_prlo_acc_s *) (fchs + 1); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 914 | int num_pages = 0; |
| 915 | int page = 0; |
| 916 | |
| 917 | len = len; |
| 918 | |
| 919 | if (prlo->command != FC_ELS_ACC) |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 920 | return FC_PARSE_FAILURE; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 921 | |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 922 | num_pages = ((be16_to_cpu(prlo->payload_len)) - 4) / 16; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 923 | |
| 924 | for (page = 0; page < num_pages; page++) { |
| 925 | if (prlo->prlo_acc_params[page].type != FC_TYPE_FCP) |
| 926 | return FC_PARSE_FAILURE; |
| 927 | |
| 928 | if (prlo->prlo_acc_params[page].opa_valid != 0) |
| 929 | return FC_PARSE_FAILURE; |
| 930 | |
| 931 | if (prlo->prlo_acc_params[page].rpa_valid != 0) |
| 932 | return FC_PARSE_FAILURE; |
| 933 | |
| 934 | if (prlo->prlo_acc_params[page].orig_process_assc != 0) |
| 935 | return FC_PARSE_FAILURE; |
| 936 | |
| 937 | if (prlo->prlo_acc_params[page].resp_process_assc != 0) |
| 938 | return FC_PARSE_FAILURE; |
| 939 | } |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 940 | return FC_PARSE_OK; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 941 | |
| 942 | } |
| 943 | |
| 944 | u16 |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 945 | fc_tprlo_build(struct fchs_s *fchs, u32 d_id, u32 s_id, u16 ox_id, |
| 946 | int num_pages, enum fc_tprlo_type tprlo_type, u32 tpr_id) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 947 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 948 | struct fc_tprlo_s *tprlo = (struct fc_tprlo_s *) (fchs + 1); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 949 | int page; |
| 950 | |
| 951 | fc_els_req_build(fchs, d_id, s_id, ox_id); |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 952 | memset(tprlo, 0, (num_pages * 16) + 4); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 953 | tprlo->command = FC_ELS_TPRLO; |
| 954 | tprlo->page_len = 0x10; |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 955 | tprlo->payload_len = cpu_to_be16((num_pages * 16) + 4); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 956 | |
| 957 | for (page = 0; page < num_pages; page++) { |
| 958 | tprlo->tprlo_params[page].type = FC_TYPE_FCP; |
| 959 | tprlo->tprlo_params[page].opa_valid = 0; |
| 960 | tprlo->tprlo_params[page].rpa_valid = 0; |
| 961 | tprlo->tprlo_params[page].orig_process_assc = 0; |
| 962 | tprlo->tprlo_params[page].resp_process_assc = 0; |
| 963 | if (tprlo_type == FC_GLOBAL_LOGO) { |
| 964 | tprlo->tprlo_params[page].global_process_logout = 1; |
| 965 | } else if (tprlo_type == FC_TPR_LOGO) { |
| 966 | tprlo->tprlo_params[page].tpo_nport_valid = 1; |
| 967 | tprlo->tprlo_params[page].tpo_nport_id = (tpr_id); |
| 968 | } |
| 969 | } |
| 970 | |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 971 | return be16_to_cpu(tprlo->payload_len); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 972 | } |
| 973 | |
| 974 | u16 |
| 975 | fc_tprlo_rsp_parse(struct fchs_s *fchs, int len) |
| 976 | { |
| 977 | struct fc_tprlo_acc_s *tprlo = (struct fc_tprlo_acc_s *) (fchs + 1); |
| 978 | int num_pages = 0; |
| 979 | int page = 0; |
| 980 | |
| 981 | len = len; |
| 982 | |
| 983 | if (tprlo->command != FC_ELS_ACC) |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 984 | return FC_PARSE_ACC_INVAL; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 985 | |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 986 | num_pages = (be16_to_cpu(tprlo->payload_len) - 4) / 16; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 987 | |
| 988 | for (page = 0; page < num_pages; page++) { |
| 989 | if (tprlo->tprlo_acc_params[page].type != FC_TYPE_FCP) |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 990 | return FC_PARSE_NOT_FCP; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 991 | if (tprlo->tprlo_acc_params[page].opa_valid != 0) |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 992 | return FC_PARSE_OPAFLAG_INVAL; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 993 | if (tprlo->tprlo_acc_params[page].rpa_valid != 0) |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 994 | return FC_PARSE_RPAFLAG_INVAL; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 995 | if (tprlo->tprlo_acc_params[page].orig_process_assc != 0) |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 996 | return FC_PARSE_OPA_INVAL; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 997 | if (tprlo->tprlo_acc_params[page].resp_process_assc != 0) |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 998 | return FC_PARSE_RPA_INVAL; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 999 | } |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 1000 | return FC_PARSE_OK; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1001 | } |
| 1002 | |
| 1003 | enum fc_parse_status |
| 1004 | fc_rrq_rsp_parse(struct fchs_s *fchs, int len) |
| 1005 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1006 | struct fc_els_cmd_s *els_cmd = (struct fc_els_cmd_s *) (fchs + 1); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1007 | |
| 1008 | len = len; |
| 1009 | if (els_cmd->els_code != FC_ELS_ACC) |
| 1010 | return FC_PARSE_FAILURE; |
| 1011 | |
| 1012 | return FC_PARSE_OK; |
| 1013 | } |
| 1014 | |
| 1015 | u16 |
Maggie | 50444a3 | 2010-11-29 18:26:32 -0800 | [diff] [blame] | 1016 | fc_ba_rjt_build(struct fchs_s *fchs, u32 d_id, u32 s_id, __be16 ox_id, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1017 | u32 reason_code, u32 reason_expl) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1018 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1019 | struct fc_ba_rjt_s *ba_rjt = (struct fc_ba_rjt_s *) (fchs + 1); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1020 | |
| 1021 | fc_bls_rsp_build(fchs, d_id, s_id, ox_id); |
| 1022 | |
| 1023 | fchs->cat_info = FC_CAT_BA_RJT; |
| 1024 | ba_rjt->reason_code = reason_code; |
| 1025 | ba_rjt->reason_expl = reason_expl; |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 1026 | return sizeof(struct fc_ba_rjt_s); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1027 | } |
| 1028 | |
| 1029 | static void |
| 1030 | fc_gs_cthdr_build(struct ct_hdr_s *cthdr, u32 s_id, u16 cmd_code) |
| 1031 | { |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 1032 | memset(cthdr, 0, sizeof(struct ct_hdr_s)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1033 | cthdr->rev_id = CT_GS3_REVISION; |
| 1034 | cthdr->gs_type = CT_GSTYPE_DIRSERVICE; |
| 1035 | cthdr->gs_sub_type = CT_GSSUBTYPE_NAMESERVER; |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 1036 | cthdr->cmd_rsp_code = cpu_to_be16(cmd_code); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1037 | } |
| 1038 | |
| 1039 | static void |
| 1040 | fc_gs_fdmi_cthdr_build(struct ct_hdr_s *cthdr, u32 s_id, u16 cmd_code) |
| 1041 | { |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 1042 | memset(cthdr, 0, sizeof(struct ct_hdr_s)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1043 | cthdr->rev_id = CT_GS3_REVISION; |
| 1044 | cthdr->gs_type = CT_GSTYPE_MGMTSERVICE; |
| 1045 | cthdr->gs_sub_type = CT_GSSUBTYPE_HBA_MGMTSERVER; |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 1046 | cthdr->cmd_rsp_code = cpu_to_be16(cmd_code); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1047 | } |
| 1048 | |
| 1049 | static void |
| 1050 | fc_gs_ms_cthdr_build(struct ct_hdr_s *cthdr, u32 s_id, u16 cmd_code, |
| 1051 | u8 sub_type) |
| 1052 | { |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 1053 | memset(cthdr, 0, sizeof(struct ct_hdr_s)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1054 | cthdr->rev_id = CT_GS3_REVISION; |
| 1055 | cthdr->gs_type = CT_GSTYPE_MGMTSERVICE; |
| 1056 | cthdr->gs_sub_type = sub_type; |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 1057 | cthdr->cmd_rsp_code = cpu_to_be16(cmd_code); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1058 | } |
| 1059 | |
| 1060 | u16 |
| 1061 | fc_gidpn_build(struct fchs_s *fchs, void *pyld, u32 s_id, u16 ox_id, |
| 1062 | wwn_t port_name) |
| 1063 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1064 | struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld; |
| 1065 | struct fcgs_gidpn_req_s *gidpn = (struct fcgs_gidpn_req_s *)(cthdr + 1); |
Maggie Zhang | f16a175 | 2010-12-09 19:12:32 -0800 | [diff] [blame] | 1066 | u32 d_id = bfa_hton3b(FC_NAME_SERVER); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1067 | |
| 1068 | fc_gs_fchdr_build(fchs, d_id, s_id, ox_id); |
| 1069 | fc_gs_cthdr_build(cthdr, s_id, GS_GID_PN); |
| 1070 | |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 1071 | memset(gidpn, 0, sizeof(struct fcgs_gidpn_req_s)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1072 | gidpn->port_name = port_name; |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 1073 | return sizeof(struct fcgs_gidpn_req_s) + sizeof(struct ct_hdr_s); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1074 | } |
| 1075 | |
| 1076 | u16 |
| 1077 | fc_gpnid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u16 ox_id, |
| 1078 | u32 port_id) |
| 1079 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1080 | struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1081 | fcgs_gpnid_req_t *gpnid = (fcgs_gpnid_req_t *) (cthdr + 1); |
Maggie Zhang | f16a175 | 2010-12-09 19:12:32 -0800 | [diff] [blame] | 1082 | u32 d_id = bfa_hton3b(FC_NAME_SERVER); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1083 | |
| 1084 | fc_gs_fchdr_build(fchs, d_id, s_id, ox_id); |
| 1085 | fc_gs_cthdr_build(cthdr, s_id, GS_GPN_ID); |
| 1086 | |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 1087 | memset(gpnid, 0, sizeof(fcgs_gpnid_req_t)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1088 | gpnid->dap = port_id; |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 1089 | return sizeof(fcgs_gpnid_req_t) + sizeof(struct ct_hdr_s); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1090 | } |
| 1091 | |
| 1092 | u16 |
| 1093 | fc_gnnid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u16 ox_id, |
| 1094 | u32 port_id) |
| 1095 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1096 | struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1097 | fcgs_gnnid_req_t *gnnid = (fcgs_gnnid_req_t *) (cthdr + 1); |
Maggie Zhang | f16a175 | 2010-12-09 19:12:32 -0800 | [diff] [blame] | 1098 | u32 d_id = bfa_hton3b(FC_NAME_SERVER); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1099 | |
| 1100 | fc_gs_fchdr_build(fchs, d_id, s_id, ox_id); |
| 1101 | fc_gs_cthdr_build(cthdr, s_id, GS_GNN_ID); |
| 1102 | |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 1103 | memset(gnnid, 0, sizeof(fcgs_gnnid_req_t)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1104 | gnnid->dap = port_id; |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 1105 | return sizeof(fcgs_gnnid_req_t) + sizeof(struct ct_hdr_s); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1106 | } |
| 1107 | |
| 1108 | u16 |
| 1109 | fc_ct_rsp_parse(struct ct_hdr_s *cthdr) |
| 1110 | { |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 1111 | if (be16_to_cpu(cthdr->cmd_rsp_code) != CT_RSP_ACCEPT) { |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1112 | if (cthdr->reason_code == CT_RSN_LOGICAL_BUSY) |
| 1113 | return FC_PARSE_BUSY; |
| 1114 | else |
| 1115 | return FC_PARSE_FAILURE; |
| 1116 | } |
| 1117 | |
| 1118 | return FC_PARSE_OK; |
| 1119 | } |
| 1120 | |
| 1121 | u16 |
Krishna Gudipati | d7be54c | 2011-06-24 20:24:52 -0700 | [diff] [blame] | 1122 | fc_gs_rjt_build(struct fchs_s *fchs, struct ct_hdr_s *cthdr, |
| 1123 | u32 d_id, u32 s_id, u16 ox_id, u8 reason_code, |
| 1124 | u8 reason_code_expl) |
| 1125 | { |
| 1126 | fc_gsresp_fchdr_build(fchs, d_id, s_id, ox_id); |
| 1127 | |
| 1128 | cthdr->cmd_rsp_code = cpu_to_be16(CT_RSP_REJECT); |
| 1129 | cthdr->rev_id = CT_GS3_REVISION; |
| 1130 | |
| 1131 | cthdr->reason_code = reason_code; |
| 1132 | cthdr->exp_code = reason_code_expl; |
| 1133 | return sizeof(struct ct_hdr_s); |
| 1134 | } |
| 1135 | |
| 1136 | u16 |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1137 | fc_scr_build(struct fchs_s *fchs, struct fc_scr_s *scr, |
| 1138 | u8 set_br_reg, u32 s_id, u16 ox_id) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1139 | { |
Maggie Zhang | f16a175 | 2010-12-09 19:12:32 -0800 | [diff] [blame] | 1140 | u32 d_id = bfa_hton3b(FC_FABRIC_CONTROLLER); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1141 | |
| 1142 | fc_els_req_build(fchs, d_id, s_id, ox_id); |
| 1143 | |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 1144 | memset(scr, 0, sizeof(struct fc_scr_s)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1145 | scr->command = FC_ELS_SCR; |
| 1146 | scr->reg_func = FC_SCR_REG_FUNC_FULL; |
| 1147 | if (set_br_reg) |
| 1148 | scr->vu_reg_func = FC_VU_SCR_REG_FUNC_FABRIC_NAME_CHANGE; |
| 1149 | |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 1150 | return sizeof(struct fc_scr_s); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1151 | } |
| 1152 | |
| 1153 | u16 |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1154 | fc_rscn_build(struct fchs_s *fchs, struct fc_rscn_pl_s *rscn, |
| 1155 | u32 s_id, u16 ox_id) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1156 | { |
Maggie Zhang | f16a175 | 2010-12-09 19:12:32 -0800 | [diff] [blame] | 1157 | u32 d_id = bfa_hton3b(FC_FABRIC_CONTROLLER); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1158 | u16 payldlen; |
| 1159 | |
| 1160 | fc_els_req_build(fchs, d_id, s_id, ox_id); |
| 1161 | rscn->command = FC_ELS_RSCN; |
| 1162 | rscn->pagelen = sizeof(rscn->event[0]); |
| 1163 | |
| 1164 | payldlen = sizeof(u32) + rscn->pagelen; |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 1165 | rscn->payldlen = cpu_to_be16(payldlen); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1166 | |
| 1167 | rscn->event[0].format = FC_RSCN_FORMAT_PORTID; |
| 1168 | rscn->event[0].portid = s_id; |
| 1169 | |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 1170 | return sizeof(struct fc_rscn_pl_s); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1171 | } |
| 1172 | |
| 1173 | u16 |
| 1174 | fc_rftid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u16 ox_id, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1175 | enum bfa_lport_role roles) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1176 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1177 | struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld; |
| 1178 | struct fcgs_rftid_req_s *rftid = (struct fcgs_rftid_req_s *)(cthdr + 1); |
Maggie Zhang | f16a175 | 2010-12-09 19:12:32 -0800 | [diff] [blame] | 1179 | u32 type_value, d_id = bfa_hton3b(FC_NAME_SERVER); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1180 | u8 index; |
| 1181 | |
| 1182 | fc_gs_fchdr_build(fchs, d_id, s_id, ox_id); |
| 1183 | fc_gs_cthdr_build(cthdr, s_id, GS_RFT_ID); |
| 1184 | |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 1185 | memset(rftid, 0, sizeof(struct fcgs_rftid_req_s)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1186 | |
| 1187 | rftid->dap = s_id; |
| 1188 | |
| 1189 | /* By default, FCP FC4 Type is registered */ |
| 1190 | index = FC_TYPE_FCP >> 5; |
| 1191 | type_value = 1 << (FC_TYPE_FCP % 32); |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 1192 | rftid->fc4_type[index] = cpu_to_be32(type_value); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1193 | |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 1194 | return sizeof(struct fcgs_rftid_req_s) + sizeof(struct ct_hdr_s); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1195 | } |
| 1196 | |
| 1197 | u16 |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1198 | fc_rftid_build_sol(struct fchs_s *fchs, void *pyld, u32 s_id, u16 ox_id, |
| 1199 | u8 *fc4_bitmap, u32 bitmap_size) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1200 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1201 | struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld; |
| 1202 | struct fcgs_rftid_req_s *rftid = (struct fcgs_rftid_req_s *)(cthdr + 1); |
Maggie Zhang | f16a175 | 2010-12-09 19:12:32 -0800 | [diff] [blame] | 1203 | u32 d_id = bfa_hton3b(FC_NAME_SERVER); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1204 | |
| 1205 | fc_gs_fchdr_build(fchs, d_id, s_id, ox_id); |
| 1206 | fc_gs_cthdr_build(cthdr, s_id, GS_RFT_ID); |
| 1207 | |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 1208 | memset(rftid, 0, sizeof(struct fcgs_rftid_req_s)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1209 | |
| 1210 | rftid->dap = s_id; |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 1211 | memcpy((void *)rftid->fc4_type, (void *)fc4_bitmap, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1212 | (bitmap_size < 32 ? bitmap_size : 32)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1213 | |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 1214 | return sizeof(struct fcgs_rftid_req_s) + sizeof(struct ct_hdr_s); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1215 | } |
| 1216 | |
| 1217 | u16 |
| 1218 | fc_rffid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u16 ox_id, |
| 1219 | u8 fc4_type, u8 fc4_ftrs) |
| 1220 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1221 | struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld; |
| 1222 | struct fcgs_rffid_req_s *rffid = (struct fcgs_rffid_req_s *)(cthdr + 1); |
Maggie Zhang | f16a175 | 2010-12-09 19:12:32 -0800 | [diff] [blame] | 1223 | u32 d_id = bfa_hton3b(FC_NAME_SERVER); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1224 | |
| 1225 | fc_gs_fchdr_build(fchs, d_id, s_id, ox_id); |
| 1226 | fc_gs_cthdr_build(cthdr, s_id, GS_RFF_ID); |
| 1227 | |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 1228 | memset(rffid, 0, sizeof(struct fcgs_rffid_req_s)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1229 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1230 | rffid->dap = s_id; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1231 | rffid->fc4ftr_bits = fc4_ftrs; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1232 | rffid->fc4_type = fc4_type; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1233 | |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 1234 | return sizeof(struct fcgs_rffid_req_s) + sizeof(struct ct_hdr_s); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1235 | } |
| 1236 | |
| 1237 | u16 |
| 1238 | fc_rspnid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u16 ox_id, |
| 1239 | u8 *name) |
| 1240 | { |
| 1241 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1242 | struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1243 | struct fcgs_rspnid_req_s *rspnid = |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1244 | (struct fcgs_rspnid_req_s *)(cthdr + 1); |
Maggie Zhang | f16a175 | 2010-12-09 19:12:32 -0800 | [diff] [blame] | 1245 | u32 d_id = bfa_hton3b(FC_NAME_SERVER); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1246 | |
| 1247 | fc_gs_fchdr_build(fchs, d_id, s_id, ox_id); |
| 1248 | fc_gs_cthdr_build(cthdr, s_id, GS_RSPN_ID); |
| 1249 | |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 1250 | memset(rspnid, 0, sizeof(struct fcgs_rspnid_req_s)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1251 | |
| 1252 | rspnid->dap = s_id; |
| 1253 | rspnid->spn_len = (u8) strlen((char *)name); |
| 1254 | strncpy((char *)rspnid->spn, (char *)name, rspnid->spn_len); |
| 1255 | |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 1256 | return sizeof(struct fcgs_rspnid_req_s) + sizeof(struct ct_hdr_s); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1257 | } |
| 1258 | |
| 1259 | u16 |
Krishna Gudipati | ce7242b | 2012-08-22 19:52:43 -0700 | [diff] [blame] | 1260 | fc_rsnn_nn_build(struct fchs_s *fchs, void *pyld, u32 s_id, |
| 1261 | wwn_t node_name, u8 *name) |
| 1262 | { |
| 1263 | struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld; |
| 1264 | struct fcgs_rsnn_nn_req_s *rsnn_nn = |
| 1265 | (struct fcgs_rsnn_nn_req_s *) (cthdr + 1); |
| 1266 | u32 d_id = bfa_hton3b(FC_NAME_SERVER); |
| 1267 | |
| 1268 | fc_gs_fchdr_build(fchs, d_id, s_id, 0); |
| 1269 | fc_gs_cthdr_build(cthdr, s_id, GS_RSNN_NN); |
| 1270 | |
| 1271 | memset(rsnn_nn, 0, sizeof(struct fcgs_rsnn_nn_req_s)); |
| 1272 | |
| 1273 | rsnn_nn->node_name = node_name; |
| 1274 | rsnn_nn->snn_len = (u8) strlen((char *)name); |
| 1275 | strncpy((char *)rsnn_nn->snn, (char *)name, rsnn_nn->snn_len); |
| 1276 | |
| 1277 | return sizeof(struct fcgs_rsnn_nn_req_s) + sizeof(struct ct_hdr_s); |
| 1278 | } |
| 1279 | |
| 1280 | u16 |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1281 | fc_gid_ft_build(struct fchs_s *fchs, void *pyld, u32 s_id, u8 fc4_type) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1282 | { |
| 1283 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1284 | struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld; |
| 1285 | struct fcgs_gidft_req_s *gidft = (struct fcgs_gidft_req_s *)(cthdr + 1); |
Maggie Zhang | f16a175 | 2010-12-09 19:12:32 -0800 | [diff] [blame] | 1286 | u32 d_id = bfa_hton3b(FC_NAME_SERVER); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1287 | |
| 1288 | fc_gs_fchdr_build(fchs, d_id, s_id, 0); |
| 1289 | |
| 1290 | fc_gs_cthdr_build(cthdr, s_id, GS_GID_FT); |
| 1291 | |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 1292 | memset(gidft, 0, sizeof(struct fcgs_gidft_req_s)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1293 | gidft->fc4_type = fc4_type; |
| 1294 | gidft->domain_id = 0; |
| 1295 | gidft->area_id = 0; |
| 1296 | |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 1297 | return sizeof(struct fcgs_gidft_req_s) + sizeof(struct ct_hdr_s); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1298 | } |
| 1299 | |
| 1300 | u16 |
| 1301 | fc_rpnid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u32 port_id, |
| 1302 | wwn_t port_name) |
| 1303 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1304 | struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld; |
| 1305 | struct fcgs_rpnid_req_s *rpnid = (struct fcgs_rpnid_req_s *)(cthdr + 1); |
Maggie Zhang | f16a175 | 2010-12-09 19:12:32 -0800 | [diff] [blame] | 1306 | u32 d_id = bfa_hton3b(FC_NAME_SERVER); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1307 | |
| 1308 | fc_gs_fchdr_build(fchs, d_id, s_id, 0); |
| 1309 | fc_gs_cthdr_build(cthdr, s_id, GS_RPN_ID); |
| 1310 | |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 1311 | memset(rpnid, 0, sizeof(struct fcgs_rpnid_req_s)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1312 | rpnid->port_id = port_id; |
| 1313 | rpnid->port_name = port_name; |
| 1314 | |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 1315 | return sizeof(struct fcgs_rpnid_req_s) + sizeof(struct ct_hdr_s); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1316 | } |
| 1317 | |
| 1318 | u16 |
| 1319 | fc_rnnid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u32 port_id, |
| 1320 | wwn_t node_name) |
| 1321 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1322 | struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld; |
| 1323 | struct fcgs_rnnid_req_s *rnnid = (struct fcgs_rnnid_req_s *)(cthdr + 1); |
Maggie Zhang | f16a175 | 2010-12-09 19:12:32 -0800 | [diff] [blame] | 1324 | u32 d_id = bfa_hton3b(FC_NAME_SERVER); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1325 | |
| 1326 | fc_gs_fchdr_build(fchs, d_id, s_id, 0); |
| 1327 | fc_gs_cthdr_build(cthdr, s_id, GS_RNN_ID); |
| 1328 | |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 1329 | memset(rnnid, 0, sizeof(struct fcgs_rnnid_req_s)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1330 | rnnid->port_id = port_id; |
| 1331 | rnnid->node_name = node_name; |
| 1332 | |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 1333 | return sizeof(struct fcgs_rnnid_req_s) + sizeof(struct ct_hdr_s); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1334 | } |
| 1335 | |
| 1336 | u16 |
| 1337 | fc_rcsid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u32 port_id, |
| 1338 | u32 cos) |
| 1339 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1340 | struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1341 | struct fcgs_rcsid_req_s *rcsid = |
| 1342 | (struct fcgs_rcsid_req_s *) (cthdr + 1); |
Maggie Zhang | f16a175 | 2010-12-09 19:12:32 -0800 | [diff] [blame] | 1343 | u32 d_id = bfa_hton3b(FC_NAME_SERVER); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1344 | |
| 1345 | fc_gs_fchdr_build(fchs, d_id, s_id, 0); |
| 1346 | fc_gs_cthdr_build(cthdr, s_id, GS_RCS_ID); |
| 1347 | |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 1348 | memset(rcsid, 0, sizeof(struct fcgs_rcsid_req_s)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1349 | rcsid->port_id = port_id; |
| 1350 | rcsid->cos = cos; |
| 1351 | |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 1352 | return sizeof(struct fcgs_rcsid_req_s) + sizeof(struct ct_hdr_s); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1353 | } |
| 1354 | |
| 1355 | u16 |
| 1356 | fc_rptid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u32 port_id, |
| 1357 | u8 port_type) |
| 1358 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1359 | struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld; |
| 1360 | struct fcgs_rptid_req_s *rptid = (struct fcgs_rptid_req_s *)(cthdr + 1); |
Maggie Zhang | f16a175 | 2010-12-09 19:12:32 -0800 | [diff] [blame] | 1361 | u32 d_id = bfa_hton3b(FC_NAME_SERVER); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1362 | |
| 1363 | fc_gs_fchdr_build(fchs, d_id, s_id, 0); |
| 1364 | fc_gs_cthdr_build(cthdr, s_id, GS_RPT_ID); |
| 1365 | |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 1366 | memset(rptid, 0, sizeof(struct fcgs_rptid_req_s)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1367 | rptid->port_id = port_id; |
| 1368 | rptid->port_type = port_type; |
| 1369 | |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 1370 | return sizeof(struct fcgs_rptid_req_s) + sizeof(struct ct_hdr_s); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1371 | } |
| 1372 | |
| 1373 | u16 |
| 1374 | fc_ganxt_build(struct fchs_s *fchs, void *pyld, u32 s_id, u32 port_id) |
| 1375 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1376 | struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld; |
| 1377 | struct fcgs_ganxt_req_s *ganxt = (struct fcgs_ganxt_req_s *)(cthdr + 1); |
Maggie Zhang | f16a175 | 2010-12-09 19:12:32 -0800 | [diff] [blame] | 1378 | u32 d_id = bfa_hton3b(FC_NAME_SERVER); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1379 | |
| 1380 | fc_gs_fchdr_build(fchs, d_id, s_id, 0); |
| 1381 | fc_gs_cthdr_build(cthdr, s_id, GS_GA_NXT); |
| 1382 | |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 1383 | memset(ganxt, 0, sizeof(struct fcgs_ganxt_req_s)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1384 | ganxt->port_id = port_id; |
| 1385 | |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 1386 | return sizeof(struct ct_hdr_s) + sizeof(struct fcgs_ganxt_req_s); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1387 | } |
| 1388 | |
| 1389 | /* |
| 1390 | * Builds fc hdr and ct hdr for FDMI requests. |
| 1391 | */ |
| 1392 | u16 |
| 1393 | fc_fdmi_reqhdr_build(struct fchs_s *fchs, void *pyld, u32 s_id, |
| 1394 | u16 cmd_code) |
| 1395 | { |
| 1396 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1397 | struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld; |
Maggie Zhang | f16a175 | 2010-12-09 19:12:32 -0800 | [diff] [blame] | 1398 | u32 d_id = bfa_hton3b(FC_MGMT_SERVER); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1399 | |
| 1400 | fc_gs_fchdr_build(fchs, d_id, s_id, 0); |
| 1401 | fc_gs_fdmi_cthdr_build(cthdr, s_id, cmd_code); |
| 1402 | |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 1403 | return sizeof(struct ct_hdr_s); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1404 | } |
| 1405 | |
| 1406 | /* |
| 1407 | * Given a FC4 Type, this function returns a fc4 type bitmask |
| 1408 | */ |
| 1409 | void |
| 1410 | fc_get_fc4type_bitmask(u8 fc4_type, u8 *bit_mask) |
| 1411 | { |
| 1412 | u8 index; |
Maggie | 50444a3 | 2010-11-29 18:26:32 -0800 | [diff] [blame] | 1413 | __be32 *ptr = (__be32 *) bit_mask; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1414 | u32 type_value; |
| 1415 | |
| 1416 | /* |
| 1417 | * @todo : Check for bitmask size |
| 1418 | */ |
| 1419 | |
| 1420 | index = fc4_type >> 5; |
| 1421 | type_value = 1 << (fc4_type % 32); |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 1422 | ptr[index] = cpu_to_be32(type_value); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1423 | |
| 1424 | } |
| 1425 | |
| 1426 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1427 | * GMAL Request |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1428 | */ |
| 1429 | u16 |
| 1430 | fc_gmal_req_build(struct fchs_s *fchs, void *pyld, u32 s_id, wwn_t wwn) |
| 1431 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1432 | struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1433 | fcgs_gmal_req_t *gmal = (fcgs_gmal_req_t *) (cthdr + 1); |
Maggie Zhang | f16a175 | 2010-12-09 19:12:32 -0800 | [diff] [blame] | 1434 | u32 d_id = bfa_hton3b(FC_MGMT_SERVER); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1435 | |
| 1436 | fc_gs_fchdr_build(fchs, d_id, s_id, 0); |
| 1437 | fc_gs_ms_cthdr_build(cthdr, s_id, GS_FC_GMAL_CMD, |
| 1438 | CT_GSSUBTYPE_CFGSERVER); |
| 1439 | |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 1440 | memset(gmal, 0, sizeof(fcgs_gmal_req_t)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1441 | gmal->wwn = wwn; |
| 1442 | |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 1443 | return sizeof(struct ct_hdr_s) + sizeof(fcgs_gmal_req_t); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1444 | } |
| 1445 | |
| 1446 | /* |
| 1447 | * GFN (Get Fabric Name) Request |
| 1448 | */ |
| 1449 | u16 |
| 1450 | fc_gfn_req_build(struct fchs_s *fchs, void *pyld, u32 s_id, wwn_t wwn) |
| 1451 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1452 | struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1453 | fcgs_gfn_req_t *gfn = (fcgs_gfn_req_t *) (cthdr + 1); |
Maggie Zhang | f16a175 | 2010-12-09 19:12:32 -0800 | [diff] [blame] | 1454 | u32 d_id = bfa_hton3b(FC_MGMT_SERVER); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1455 | |
| 1456 | fc_gs_fchdr_build(fchs, d_id, s_id, 0); |
| 1457 | fc_gs_ms_cthdr_build(cthdr, s_id, GS_FC_GFN_CMD, |
| 1458 | CT_GSSUBTYPE_CFGSERVER); |
| 1459 | |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 1460 | memset(gfn, 0, sizeof(fcgs_gfn_req_t)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1461 | gfn->wwn = wwn; |
| 1462 | |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 1463 | return sizeof(struct ct_hdr_s) + sizeof(fcgs_gfn_req_t); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1464 | } |