]>
Commit | Line | Data |
---|---|---|
77adf3f0 | 1 | // SPDX-License-Identifier: GPL-2.0-only |
1da177e4 | 2 | /* |
fa90c54f | 3 | * QLogic Fibre Channel HBA Driver |
bd21eaf9 | 4 | * Copyright (c) 2003-2014 QLogic Corporation |
1da177e4 LT |
5 | */ |
6 | #include "qla_def.h" | |
2d70c103 | 7 | #include "qla_target.h" |
df57caba | 8 | #include <linux/utsname.h> |
1da177e4 | 9 | |
1da177e4 LT |
10 | static int qla2x00_sns_ga_nxt(scsi_qla_host_t *, fc_port_t *); |
11 | static int qla2x00_sns_gid_pt(scsi_qla_host_t *, sw_info_t *); | |
12 | static int qla2x00_sns_gpn_id(scsi_qla_host_t *, sw_info_t *); | |
13 | static int qla2x00_sns_gnn_id(scsi_qla_host_t *, sw_info_t *); | |
14 | static int qla2x00_sns_rft_id(scsi_qla_host_t *); | |
15 | static int qla2x00_sns_rnn_id(scsi_qla_host_t *); | |
e374f9f5 QT |
16 | static int qla_async_rftid(scsi_qla_host_t *, port_id_t *); |
17 | static int qla_async_rffid(scsi_qla_host_t *, port_id_t *, u8, u8); | |
18 | static int qla_async_rnnid(scsi_qla_host_t *, port_id_t *, u8*); | |
19 | static int qla_async_rsnn_nn(scsi_qla_host_t *); | |
1da177e4 | 20 | |
52bfb089 JC |
21 | |
22 | ||
1da177e4 | 23 | /** |
8c958a99 | 24 | * qla2x00_prep_ms_iocb() - Prepare common MS/CT IOCB fields for SNS CT query. |
2db6228d BVA |
25 | * @vha: HA context |
26 | * @arg: CT arguments | |
1da177e4 | 27 | * |
2db6228d | 28 | * Returns a pointer to the @vha's ms_iocb. |
1da177e4 | 29 | */ |
8c958a99 | 30 | void * |
726b8548 | 31 | qla2x00_prep_ms_iocb(scsi_qla_host_t *vha, struct ct_arg *arg) |
1da177e4 | 32 | { |
7b867cf7 | 33 | struct qla_hw_data *ha = vha->hw; |
1da177e4 LT |
34 | ms_iocb_entry_t *ms_pkt; |
35 | ||
726b8548 | 36 | ms_pkt = (ms_iocb_entry_t *)arg->iocb; |
1da177e4 LT |
37 | memset(ms_pkt, 0, sizeof(ms_iocb_entry_t)); |
38 | ||
39 | ms_pkt->entry_type = MS_IOCB_TYPE; | |
40 | ms_pkt->entry_count = 1; | |
41 | SET_TARGET_ID(ha, ms_pkt->loop_id, SIMPLE_NAME_SERVER); | |
ad950360 | 42 | ms_pkt->control_flags = cpu_to_le16(CF_READ | CF_HEAD_TAG); |
00a537b8 | 43 | ms_pkt->timeout = cpu_to_le16(ha->r_a_tov / 10 * 2); |
ad950360 BVA |
44 | ms_pkt->cmd_dsd_count = cpu_to_le16(1); |
45 | ms_pkt->total_dsd_count = cpu_to_le16(2); | |
726b8548 QT |
46 | ms_pkt->rsp_bytecount = cpu_to_le32(arg->rsp_size); |
47 | ms_pkt->req_bytecount = cpu_to_le32(arg->req_size); | |
1da177e4 | 48 | |
15b7a68c BVA |
49 | put_unaligned_le64(arg->req_dma, &ms_pkt->req_dsd.address); |
50 | ms_pkt->req_dsd.length = ms_pkt->req_bytecount; | |
1da177e4 | 51 | |
15b7a68c BVA |
52 | put_unaligned_le64(arg->rsp_dma, &ms_pkt->rsp_dsd.address); |
53 | ms_pkt->rsp_dsd.length = ms_pkt->rsp_bytecount; | |
1da177e4 | 54 | |
fabbb8df JC |
55 | vha->qla_stats.control_requests++; |
56 | ||
1da177e4 LT |
57 | return (ms_pkt); |
58 | } | |
59 | ||
8c958a99 AV |
60 | /** |
61 | * qla24xx_prep_ms_iocb() - Prepare common CT IOCB fields for SNS CT query. | |
2db6228d BVA |
62 | * @vha: HA context |
63 | * @arg: CT arguments | |
8c958a99 AV |
64 | * |
65 | * Returns a pointer to the @ha's ms_iocb. | |
66 | */ | |
67 | void * | |
726b8548 | 68 | qla24xx_prep_ms_iocb(scsi_qla_host_t *vha, struct ct_arg *arg) |
8c958a99 | 69 | { |
7b867cf7 | 70 | struct qla_hw_data *ha = vha->hw; |
8c958a99 AV |
71 | struct ct_entry_24xx *ct_pkt; |
72 | ||
726b8548 | 73 | ct_pkt = (struct ct_entry_24xx *)arg->iocb; |
8c958a99 AV |
74 | memset(ct_pkt, 0, sizeof(struct ct_entry_24xx)); |
75 | ||
76 | ct_pkt->entry_type = CT_IOCB_TYPE; | |
77 | ct_pkt->entry_count = 1; | |
726b8548 | 78 | ct_pkt->nport_handle = cpu_to_le16(arg->nport_handle); |
00a537b8 | 79 | ct_pkt->timeout = cpu_to_le16(ha->r_a_tov / 10 * 2); |
ad950360 BVA |
80 | ct_pkt->cmd_dsd_count = cpu_to_le16(1); |
81 | ct_pkt->rsp_dsd_count = cpu_to_le16(1); | |
726b8548 QT |
82 | ct_pkt->rsp_byte_count = cpu_to_le32(arg->rsp_size); |
83 | ct_pkt->cmd_byte_count = cpu_to_le32(arg->req_size); | |
8c958a99 | 84 | |
15b7a68c BVA |
85 | put_unaligned_le64(arg->req_dma, &ct_pkt->dsd[0].address); |
86 | ct_pkt->dsd[0].length = ct_pkt->cmd_byte_count; | |
8c958a99 | 87 | |
15b7a68c BVA |
88 | put_unaligned_le64(arg->rsp_dma, &ct_pkt->dsd[1].address); |
89 | ct_pkt->dsd[1].length = ct_pkt->rsp_byte_count; | |
7b867cf7 | 90 | ct_pkt->vp_index = vha->vp_idx; |
8c958a99 | 91 | |
fabbb8df JC |
92 | vha->qla_stats.control_requests++; |
93 | ||
8c958a99 AV |
94 | return (ct_pkt); |
95 | } | |
96 | ||
1da177e4 LT |
97 | /** |
98 | * qla2x00_prep_ct_req() - Prepare common CT request fields for SNS query. | |
2db6228d | 99 | * @p: CT request buffer |
1da177e4 LT |
100 | * @cmd: GS command |
101 | * @rsp_size: response size in bytes | |
102 | * | |
103 | * Returns a pointer to the intitialized @ct_req. | |
104 | */ | |
105 | static inline struct ct_sns_req * | |
6ec6f909 | 106 | qla2x00_prep_ct_req(struct ct_sns_pkt *p, uint16_t cmd, uint16_t rsp_size) |
1da177e4 | 107 | { |
6ec6f909 | 108 | memset(p, 0, sizeof(struct ct_sns_pkt)); |
1da177e4 | 109 | |
6ec6f909 BVA |
110 | p->p.req.header.revision = 0x01; |
111 | p->p.req.header.gs_type = 0xFC; | |
112 | p->p.req.header.gs_subtype = 0x02; | |
113 | p->p.req.command = cpu_to_be16(cmd); | |
114 | p->p.req.max_rsp_size = cpu_to_be16((rsp_size - 16) / 4); | |
1da177e4 | 115 | |
6ec6f909 | 116 | return &p->p.req; |
1da177e4 LT |
117 | } |
118 | ||
726b8548 | 119 | int |
7b867cf7 | 120 | qla2x00_chk_ms_status(scsi_qla_host_t *vha, ms_iocb_entry_t *ms_pkt, |
8c958a99 AV |
121 | struct ct_sns_rsp *ct_rsp, const char *routine) |
122 | { | |
123 | int rval; | |
124 | uint16_t comp_status; | |
7b867cf7 | 125 | struct qla_hw_data *ha = vha->hw; |
b98ae0d7 | 126 | bool lid_is_sns = false; |
8c958a99 AV |
127 | |
128 | rval = QLA_FUNCTION_FAILED; | |
129 | if (ms_pkt->entry_status != 0) { | |
7c3df132 SK |
130 | ql_dbg(ql_dbg_disc, vha, 0x2031, |
131 | "%s failed, error status (%x) on port_id: %02x%02x%02x.\n", | |
132 | routine, ms_pkt->entry_status, vha->d_id.b.domain, | |
133 | vha->d_id.b.area, vha->d_id.b.al_pa); | |
8c958a99 | 134 | } else { |
e428924c | 135 | if (IS_FWI2_CAPABLE(ha)) |
cdfc82ad AV |
136 | comp_status = le16_to_cpu( |
137 | ((struct ct_entry_24xx *)ms_pkt)->comp_status); | |
8c958a99 AV |
138 | else |
139 | comp_status = le16_to_cpu(ms_pkt->status); | |
140 | switch (comp_status) { | |
141 | case CS_COMPLETE: | |
142 | case CS_DATA_UNDERRUN: | |
143 | case CS_DATA_OVERRUN: /* Overrun? */ | |
144 | if (ct_rsp->header.response != | |
ad950360 | 145 | cpu_to_be16(CT_ACCEPT_RESPONSE)) { |
7c3df132 | 146 | ql_dbg(ql_dbg_disc + ql_dbg_buffer, vha, 0x2077, |
5a68a1c2 | 147 | "%s failed rejected request on port_id: %02x%02x%02x Completion status 0x%x, response 0x%x\n", |
df57caba HM |
148 | routine, vha->d_id.b.domain, |
149 | vha->d_id.b.area, vha->d_id.b.al_pa, | |
150 | comp_status, ct_rsp->header.response); | |
7c3df132 | 151 | ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, |
f8f97b0c JC |
152 | 0x2078, ct_rsp, |
153 | offsetof(typeof(*ct_rsp), rsp)); | |
4346b149 | 154 | rval = QLA_INVALID_COMMAND; |
8c958a99 AV |
155 | } else |
156 | rval = QLA_SUCCESS; | |
157 | break; | |
b98ae0d7 QT |
158 | case CS_PORT_LOGGED_OUT: |
159 | if (IS_FWI2_CAPABLE(ha)) { | |
160 | if (le16_to_cpu(ms_pkt->loop_id.extended) == | |
161 | NPH_SNS) | |
162 | lid_is_sns = true; | |
163 | } else { | |
164 | if (le16_to_cpu(ms_pkt->loop_id.extended) == | |
165 | SIMPLE_NAME_SERVER) | |
166 | lid_is_sns = true; | |
167 | } | |
168 | if (lid_is_sns) { | |
169 | ql_dbg(ql_dbg_async, vha, 0x502b, | |
170 | "%s failed, Name server has logged out", | |
171 | routine); | |
172 | rval = QLA_NOT_LOGGED_IN; | |
173 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); | |
174 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); | |
175 | } | |
176 | break; | |
25ad76b7 QT |
177 | case CS_TIMEOUT: |
178 | rval = QLA_FUNCTION_TIMEOUT; | |
df561f66 | 179 | fallthrough; |
8c958a99 | 180 | default: |
7c3df132 SK |
181 | ql_dbg(ql_dbg_disc, vha, 0x2033, |
182 | "%s failed, completion status (%x) on port_id: " | |
183 | "%02x%02x%02x.\n", routine, comp_status, | |
cf2d7712 | 184 | vha->d_id.b.domain, vha->d_id.b.area, |
7c3df132 | 185 | vha->d_id.b.al_pa); |
8c958a99 AV |
186 | break; |
187 | } | |
188 | } | |
189 | return rval; | |
190 | } | |
1da177e4 LT |
191 | |
192 | /** | |
193 | * qla2x00_ga_nxt() - SNS scan for fabric devices via GA_NXT command. | |
2db6228d | 194 | * @vha: HA context |
1da177e4 LT |
195 | * @fcport: fcport entry to updated |
196 | * | |
197 | * Returns 0 on success. | |
198 | */ | |
199 | int | |
7b867cf7 | 200 | qla2x00_ga_nxt(scsi_qla_host_t *vha, fc_port_t *fcport) |
1da177e4 LT |
201 | { |
202 | int rval; | |
203 | ||
204 | ms_iocb_entry_t *ms_pkt; | |
205 | struct ct_sns_req *ct_req; | |
206 | struct ct_sns_rsp *ct_rsp; | |
7b867cf7 | 207 | struct qla_hw_data *ha = vha->hw; |
726b8548 | 208 | struct ct_arg arg; |
1da177e4 | 209 | |
7b867cf7 AC |
210 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) |
211 | return qla2x00_sns_ga_nxt(vha, fcport); | |
1da177e4 | 212 | |
726b8548 QT |
213 | arg.iocb = ha->ms_iocb; |
214 | arg.req_dma = ha->ct_sns_dma; | |
215 | arg.rsp_dma = ha->ct_sns_dma; | |
216 | arg.req_size = GA_NXT_REQ_SIZE; | |
217 | arg.rsp_size = GA_NXT_RSP_SIZE; | |
218 | arg.nport_handle = NPH_SNS; | |
219 | ||
1da177e4 LT |
220 | /* Issue GA_NXT */ |
221 | /* Prepare common MS IOCB */ | |
726b8548 | 222 | ms_pkt = ha->isp_ops->prep_ms_iocb(vha, &arg); |
1da177e4 LT |
223 | |
224 | /* Prepare CT request */ | |
6ec6f909 | 225 | ct_req = qla2x00_prep_ct_req(ha->ct_sns, GA_NXT_CMD, |
1da177e4 LT |
226 | GA_NXT_RSP_SIZE); |
227 | ct_rsp = &ha->ct_sns->p.rsp; | |
228 | ||
229 | /* Prepare CT arguments -- port_id */ | |
df95f39a | 230 | ct_req->req.port_id.port_id = port_id_to_be_id(fcport->d_id); |
1da177e4 LT |
231 | |
232 | /* Execute MS IOCB */ | |
7b867cf7 | 233 | rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma, |
1da177e4 LT |
234 | sizeof(ms_iocb_entry_t)); |
235 | if (rval != QLA_SUCCESS) { | |
236 | /*EMPTY*/ | |
7c3df132 SK |
237 | ql_dbg(ql_dbg_disc, vha, 0x2062, |
238 | "GA_NXT issue IOCB failed (%d).\n", rval); | |
7b867cf7 | 239 | } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, "GA_NXT") != |
8c958a99 | 240 | QLA_SUCCESS) { |
1da177e4 LT |
241 | rval = QLA_FUNCTION_FAILED; |
242 | } else { | |
243 | /* Populate fc_port_t entry. */ | |
df95f39a | 244 | fcport->d_id = be_to_port_id(ct_rsp->rsp.ga_nxt.port_id); |
1da177e4 LT |
245 | |
246 | memcpy(fcport->node_name, ct_rsp->rsp.ga_nxt.node_name, | |
247 | WWN_SIZE); | |
248 | memcpy(fcport->port_name, ct_rsp->rsp.ga_nxt.port_name, | |
249 | WWN_SIZE); | |
250 | ||
a72b9900 | 251 | fcport->fc4_type = (ct_rsp->rsp.ga_nxt.fc4_types[2] & BIT_0) ? |
84ed362a | 252 | FS_FC4TYPE_FCP : FC4_TYPE_OTHER; |
a72b9900 | 253 | |
1da177e4 LT |
254 | if (ct_rsp->rsp.ga_nxt.port_type != NS_N_PORT_TYPE && |
255 | ct_rsp->rsp.ga_nxt.port_type != NS_NL_PORT_TYPE) | |
256 | fcport->d_id.b.domain = 0xf0; | |
257 | ||
7c3df132 | 258 | ql_dbg(ql_dbg_disc, vha, 0x2063, |
7b833558 | 259 | "GA_NXT entry - nn %8phN pn %8phN " |
7c3df132 | 260 | "port_id=%02x%02x%02x.\n", |
7b833558 | 261 | fcport->node_name, fcport->port_name, |
1da177e4 | 262 | fcport->d_id.b.domain, fcport->d_id.b.area, |
7c3df132 | 263 | fcport->d_id.b.al_pa); |
1da177e4 LT |
264 | } |
265 | ||
266 | return (rval); | |
267 | } | |
268 | ||
642ef983 CD |
269 | static inline int |
270 | qla2x00_gid_pt_rsp_size(scsi_qla_host_t *vha) | |
271 | { | |
272 | return vha->hw->max_fibre_devices * 4 + 16; | |
273 | } | |
274 | ||
1da177e4 LT |
275 | /** |
276 | * qla2x00_gid_pt() - SNS scan for fabric devices via GID_PT command. | |
2db6228d | 277 | * @vha: HA context |
1da177e4 LT |
278 | * @list: switch info entries to populate |
279 | * | |
280 | * NOTE: Non-Nx_Ports are not requested. | |
281 | * | |
282 | * Returns 0 on success. | |
283 | */ | |
284 | int | |
7b867cf7 | 285 | qla2x00_gid_pt(scsi_qla_host_t *vha, sw_info_t *list) |
1da177e4 LT |
286 | { |
287 | int rval; | |
288 | uint16_t i; | |
289 | ||
290 | ms_iocb_entry_t *ms_pkt; | |
291 | struct ct_sns_req *ct_req; | |
292 | struct ct_sns_rsp *ct_rsp; | |
293 | ||
294 | struct ct_sns_gid_pt_data *gid_data; | |
7b867cf7 | 295 | struct qla_hw_data *ha = vha->hw; |
642ef983 | 296 | uint16_t gid_pt_rsp_size; |
726b8548 | 297 | struct ct_arg arg; |
1da177e4 | 298 | |
7b867cf7 AC |
299 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) |
300 | return qla2x00_sns_gid_pt(vha, list); | |
1da177e4 LT |
301 | |
302 | gid_data = NULL; | |
642ef983 | 303 | gid_pt_rsp_size = qla2x00_gid_pt_rsp_size(vha); |
726b8548 QT |
304 | |
305 | arg.iocb = ha->ms_iocb; | |
306 | arg.req_dma = ha->ct_sns_dma; | |
307 | arg.rsp_dma = ha->ct_sns_dma; | |
308 | arg.req_size = GID_PT_REQ_SIZE; | |
309 | arg.rsp_size = gid_pt_rsp_size; | |
310 | arg.nport_handle = NPH_SNS; | |
311 | ||
1da177e4 LT |
312 | /* Issue GID_PT */ |
313 | /* Prepare common MS IOCB */ | |
726b8548 | 314 | ms_pkt = ha->isp_ops->prep_ms_iocb(vha, &arg); |
1da177e4 LT |
315 | |
316 | /* Prepare CT request */ | |
6ec6f909 | 317 | ct_req = qla2x00_prep_ct_req(ha->ct_sns, GID_PT_CMD, gid_pt_rsp_size); |
1da177e4 LT |
318 | ct_rsp = &ha->ct_sns->p.rsp; |
319 | ||
320 | /* Prepare CT arguments -- port_type */ | |
321 | ct_req->req.gid_pt.port_type = NS_NX_PORT_TYPE; | |
322 | ||
323 | /* Execute MS IOCB */ | |
7b867cf7 | 324 | rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma, |
1da177e4 LT |
325 | sizeof(ms_iocb_entry_t)); |
326 | if (rval != QLA_SUCCESS) { | |
327 | /*EMPTY*/ | |
7c3df132 SK |
328 | ql_dbg(ql_dbg_disc, vha, 0x2055, |
329 | "GID_PT issue IOCB failed (%d).\n", rval); | |
7b867cf7 | 330 | } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, "GID_PT") != |
8c958a99 | 331 | QLA_SUCCESS) { |
1da177e4 LT |
332 | rval = QLA_FUNCTION_FAILED; |
333 | } else { | |
334 | /* Set port IDs in switch info list. */ | |
642ef983 | 335 | for (i = 0; i < ha->max_fibre_devices; i++) { |
1da177e4 | 336 | gid_data = &ct_rsp->rsp.gid_pt.entries[i]; |
df95f39a | 337 | list[i].d_id = be_to_port_id(gid_data->port_id); |
a3cbdfad AV |
338 | memset(list[i].fabric_port_name, 0, WWN_SIZE); |
339 | list[i].fp_speed = PORT_SPEED_UNKNOWN; | |
1da177e4 LT |
340 | |
341 | /* Last one exit. */ | |
342 | if (gid_data->control_byte & BIT_7) { | |
343 | list[i].d_id.b.rsvd_1 = gid_data->control_byte; | |
344 | break; | |
345 | } | |
346 | } | |
347 | ||
348 | /* | |
349 | * If we've used all available slots, then the switch is | |
350 | * reporting back more devices than we can handle with this | |
351 | * single call. Return a failed status, and let GA_NXT handle | |
352 | * the overload. | |
353 | */ | |
642ef983 | 354 | if (i == ha->max_fibre_devices) |
1da177e4 LT |
355 | rval = QLA_FUNCTION_FAILED; |
356 | } | |
357 | ||
358 | return (rval); | |
359 | } | |
360 | ||
361 | /** | |
362 | * qla2x00_gpn_id() - SNS Get Port Name (GPN_ID) query. | |
2db6228d | 363 | * @vha: HA context |
1da177e4 LT |
364 | * @list: switch info entries to populate |
365 | * | |
366 | * Returns 0 on success. | |
367 | */ | |
368 | int | |
7b867cf7 | 369 | qla2x00_gpn_id(scsi_qla_host_t *vha, sw_info_t *list) |
1da177e4 | 370 | { |
642ef983 | 371 | int rval = QLA_SUCCESS; |
1da177e4 LT |
372 | uint16_t i; |
373 | ||
374 | ms_iocb_entry_t *ms_pkt; | |
375 | struct ct_sns_req *ct_req; | |
376 | struct ct_sns_rsp *ct_rsp; | |
7b867cf7 | 377 | struct qla_hw_data *ha = vha->hw; |
726b8548 | 378 | struct ct_arg arg; |
1da177e4 | 379 | |
7b867cf7 AC |
380 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) |
381 | return qla2x00_sns_gpn_id(vha, list); | |
1da177e4 | 382 | |
726b8548 QT |
383 | arg.iocb = ha->ms_iocb; |
384 | arg.req_dma = ha->ct_sns_dma; | |
385 | arg.rsp_dma = ha->ct_sns_dma; | |
386 | arg.req_size = GPN_ID_REQ_SIZE; | |
387 | arg.rsp_size = GPN_ID_RSP_SIZE; | |
388 | arg.nport_handle = NPH_SNS; | |
389 | ||
642ef983 | 390 | for (i = 0; i < ha->max_fibre_devices; i++) { |
1da177e4 LT |
391 | /* Issue GPN_ID */ |
392 | /* Prepare common MS IOCB */ | |
726b8548 | 393 | ms_pkt = ha->isp_ops->prep_ms_iocb(vha, &arg); |
1da177e4 LT |
394 | |
395 | /* Prepare CT request */ | |
6ec6f909 | 396 | ct_req = qla2x00_prep_ct_req(ha->ct_sns, GPN_ID_CMD, |
1da177e4 LT |
397 | GPN_ID_RSP_SIZE); |
398 | ct_rsp = &ha->ct_sns->p.rsp; | |
399 | ||
400 | /* Prepare CT arguments -- port_id */ | |
df95f39a | 401 | ct_req->req.port_id.port_id = port_id_to_be_id(list[i].d_id); |
1da177e4 LT |
402 | |
403 | /* Execute MS IOCB */ | |
7b867cf7 | 404 | rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma, |
1da177e4 LT |
405 | sizeof(ms_iocb_entry_t)); |
406 | if (rval != QLA_SUCCESS) { | |
407 | /*EMPTY*/ | |
7c3df132 SK |
408 | ql_dbg(ql_dbg_disc, vha, 0x2056, |
409 | "GPN_ID issue IOCB failed (%d).\n", rval); | |
dafdf892 | 410 | break; |
7b867cf7 | 411 | } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, |
8c958a99 | 412 | "GPN_ID") != QLA_SUCCESS) { |
1da177e4 | 413 | rval = QLA_FUNCTION_FAILED; |
dafdf892 | 414 | break; |
1da177e4 LT |
415 | } else { |
416 | /* Save portname */ | |
417 | memcpy(list[i].port_name, | |
418 | ct_rsp->rsp.gpn_id.port_name, WWN_SIZE); | |
419 | } | |
420 | ||
421 | /* Last device exit. */ | |
422 | if (list[i].d_id.b.rsvd_1 != 0) | |
423 | break; | |
424 | } | |
425 | ||
426 | return (rval); | |
427 | } | |
428 | ||
429 | /** | |
430 | * qla2x00_gnn_id() - SNS Get Node Name (GNN_ID) query. | |
2db6228d | 431 | * @vha: HA context |
1da177e4 LT |
432 | * @list: switch info entries to populate |
433 | * | |
434 | * Returns 0 on success. | |
435 | */ | |
436 | int | |
7b867cf7 | 437 | qla2x00_gnn_id(scsi_qla_host_t *vha, sw_info_t *list) |
1da177e4 | 438 | { |
642ef983 | 439 | int rval = QLA_SUCCESS; |
1da177e4 | 440 | uint16_t i; |
7b867cf7 | 441 | struct qla_hw_data *ha = vha->hw; |
1da177e4 LT |
442 | ms_iocb_entry_t *ms_pkt; |
443 | struct ct_sns_req *ct_req; | |
444 | struct ct_sns_rsp *ct_rsp; | |
726b8548 | 445 | struct ct_arg arg; |
1da177e4 | 446 | |
7b867cf7 AC |
447 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) |
448 | return qla2x00_sns_gnn_id(vha, list); | |
1da177e4 | 449 | |
726b8548 QT |
450 | arg.iocb = ha->ms_iocb; |
451 | arg.req_dma = ha->ct_sns_dma; | |
452 | arg.rsp_dma = ha->ct_sns_dma; | |
453 | arg.req_size = GNN_ID_REQ_SIZE; | |
454 | arg.rsp_size = GNN_ID_RSP_SIZE; | |
455 | arg.nport_handle = NPH_SNS; | |
456 | ||
642ef983 | 457 | for (i = 0; i < ha->max_fibre_devices; i++) { |
1da177e4 LT |
458 | /* Issue GNN_ID */ |
459 | /* Prepare common MS IOCB */ | |
726b8548 | 460 | ms_pkt = ha->isp_ops->prep_ms_iocb(vha, &arg); |
1da177e4 LT |
461 | |
462 | /* Prepare CT request */ | |
6ec6f909 | 463 | ct_req = qla2x00_prep_ct_req(ha->ct_sns, GNN_ID_CMD, |
1da177e4 LT |
464 | GNN_ID_RSP_SIZE); |
465 | ct_rsp = &ha->ct_sns->p.rsp; | |
466 | ||
467 | /* Prepare CT arguments -- port_id */ | |
df95f39a | 468 | ct_req->req.port_id.port_id = port_id_to_be_id(list[i].d_id); |
1da177e4 LT |
469 | |
470 | /* Execute MS IOCB */ | |
7b867cf7 | 471 | rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma, |
1da177e4 LT |
472 | sizeof(ms_iocb_entry_t)); |
473 | if (rval != QLA_SUCCESS) { | |
474 | /*EMPTY*/ | |
7c3df132 SK |
475 | ql_dbg(ql_dbg_disc, vha, 0x2057, |
476 | "GNN_ID issue IOCB failed (%d).\n", rval); | |
dafdf892 | 477 | break; |
7b867cf7 | 478 | } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, |
8c958a99 | 479 | "GNN_ID") != QLA_SUCCESS) { |
1da177e4 | 480 | rval = QLA_FUNCTION_FAILED; |
dafdf892 | 481 | break; |
1da177e4 LT |
482 | } else { |
483 | /* Save nodename */ | |
484 | memcpy(list[i].node_name, | |
485 | ct_rsp->rsp.gnn_id.node_name, WWN_SIZE); | |
486 | ||
7c3df132 | 487 | ql_dbg(ql_dbg_disc, vha, 0x2058, |
7b833558 | 488 | "GID_PT entry - nn %8phN pn %8phN " |
1da177e4 | 489 | "portid=%02x%02x%02x.\n", |
7b833558 | 490 | list[i].node_name, list[i].port_name, |
1da177e4 | 491 | list[i].d_id.b.domain, list[i].d_id.b.area, |
7c3df132 | 492 | list[i].d_id.b.al_pa); |
1da177e4 LT |
493 | } |
494 | ||
495 | /* Last device exit. */ | |
496 | if (list[i].d_id.b.rsvd_1 != 0) | |
497 | break; | |
498 | } | |
499 | ||
500 | return (rval); | |
501 | } | |
502 | ||
6c18a43e | 503 | static void qla2x00_async_sns_sp_done(srb_t *sp, int rc) |
e374f9f5 | 504 | { |
e374f9f5 QT |
505 | struct scsi_qla_host *vha = sp->vha; |
506 | struct ct_sns_pkt *ct_sns; | |
507 | struct qla_work_evt *e; | |
508 | ||
509 | sp->rc = rc; | |
510 | if (rc == QLA_SUCCESS) { | |
511 | ql_dbg(ql_dbg_disc, vha, 0x204f, | |
512 | "Async done-%s exiting normally.\n", | |
513 | sp->name); | |
514 | } else if (rc == QLA_FUNCTION_TIMEOUT) { | |
515 | ql_dbg(ql_dbg_disc, vha, 0x204f, | |
516 | "Async done-%s timeout\n", sp->name); | |
517 | } else { | |
518 | ct_sns = (struct ct_sns_pkt *)sp->u.iocb_cmd.u.ctarg.rsp; | |
519 | memset(ct_sns, 0, sizeof(*ct_sns)); | |
520 | sp->retry_count++; | |
521 | if (sp->retry_count > 3) | |
522 | goto err; | |
523 | ||
524 | ql_dbg(ql_dbg_disc, vha, 0x204f, | |
525 | "Async done-%s fail rc %x. Retry count %d\n", | |
526 | sp->name, rc, sp->retry_count); | |
527 | ||
528 | e = qla2x00_alloc_work(vha, QLA_EVT_SP_RETRY); | |
529 | if (!e) | |
530 | goto err2; | |
531 | ||
e374f9f5 QT |
532 | e->u.iosb.sp = sp; |
533 | qla2x00_post_work(vha, e); | |
534 | return; | |
535 | } | |
536 | ||
537 | err: | |
538 | e = qla2x00_alloc_work(vha, QLA_EVT_UNMAP); | |
539 | err2: | |
540 | if (!e) { | |
541 | /* please ignore kernel warning. otherwise, we have mem leak. */ | |
542 | if (sp->u.iocb_cmd.u.ctarg.req) { | |
543 | dma_free_coherent(&vha->hw->pdev->dev, | |
b5f3bc39 | 544 | sp->u.iocb_cmd.u.ctarg.req_allocated_size, |
e374f9f5 QT |
545 | sp->u.iocb_cmd.u.ctarg.req, |
546 | sp->u.iocb_cmd.u.ctarg.req_dma); | |
547 | sp->u.iocb_cmd.u.ctarg.req = NULL; | |
548 | } | |
549 | ||
550 | if (sp->u.iocb_cmd.u.ctarg.rsp) { | |
551 | dma_free_coherent(&vha->hw->pdev->dev, | |
b5f3bc39 | 552 | sp->u.iocb_cmd.u.ctarg.rsp_allocated_size, |
e374f9f5 QT |
553 | sp->u.iocb_cmd.u.ctarg.rsp, |
554 | sp->u.iocb_cmd.u.ctarg.rsp_dma); | |
555 | sp->u.iocb_cmd.u.ctarg.rsp = NULL; | |
556 | } | |
557 | ||
ee7bd382 SK |
558 | /* ref: INIT */ |
559 | kref_put(&sp->cmd_kref, qla2x00_sp_release); | |
e374f9f5 QT |
560 | return; |
561 | } | |
562 | ||
563 | e->u.iosb.sp = sp; | |
564 | qla2x00_post_work(vha, e); | |
565 | } | |
566 | ||
1da177e4 LT |
567 | /** |
568 | * qla2x00_rft_id() - SNS Register FC-4 TYPEs (RFT_ID) supported by the HBA. | |
2db6228d | 569 | * @vha: HA context |
1da177e4 LT |
570 | * |
571 | * Returns 0 on success. | |
572 | */ | |
573 | int | |
7b867cf7 | 574 | qla2x00_rft_id(scsi_qla_host_t *vha) |
1da177e4 | 575 | { |
7b867cf7 | 576 | struct qla_hw_data *ha = vha->hw; |
1da177e4 | 577 | |
7b867cf7 AC |
578 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) |
579 | return qla2x00_sns_rft_id(vha); | |
1da177e4 | 580 | |
e374f9f5 QT |
581 | return qla_async_rftid(vha, &vha->d_id); |
582 | } | |
726b8548 | 583 | |
e374f9f5 QT |
584 | static int qla_async_rftid(scsi_qla_host_t *vha, port_id_t *d_id) |
585 | { | |
586 | int rval = QLA_MEMORY_ALLOC_FAILED; | |
587 | struct ct_sns_req *ct_req; | |
588 | srb_t *sp; | |
589 | struct ct_sns_pkt *ct_sns; | |
590 | ||
591 | if (!vha->flags.online) | |
592 | goto done; | |
593 | ||
ee7bd382 | 594 | /* ref: INIT */ |
e374f9f5 QT |
595 | sp = qla2x00_get_sp(vha, NULL, GFP_KERNEL); |
596 | if (!sp) | |
597 | goto done; | |
598 | ||
599 | sp->type = SRB_CT_PTHRU_CMD; | |
600 | sp->name = "rft_id"; | |
75a1d041 DW |
601 | qla2x00_init_async_sp(sp, qla2x00_get_async_timeout(vha) + 2, |
602 | qla2x00_async_sns_sp_done); | |
e374f9f5 QT |
603 | |
604 | sp->u.iocb_cmd.u.ctarg.req = dma_alloc_coherent(&vha->hw->pdev->dev, | |
605 | sizeof(struct ct_sns_pkt), &sp->u.iocb_cmd.u.ctarg.req_dma, | |
606 | GFP_KERNEL); | |
b5f3bc39 | 607 | sp->u.iocb_cmd.u.ctarg.req_allocated_size = sizeof(struct ct_sns_pkt); |
e374f9f5 QT |
608 | if (!sp->u.iocb_cmd.u.ctarg.req) { |
609 | ql_log(ql_log_warn, vha, 0xd041, | |
610 | "%s: Failed to allocate ct_sns request.\n", | |
611 | __func__); | |
612 | goto done_free_sp; | |
613 | } | |
614 | ||
615 | sp->u.iocb_cmd.u.ctarg.rsp = dma_alloc_coherent(&vha->hw->pdev->dev, | |
616 | sizeof(struct ct_sns_pkt), &sp->u.iocb_cmd.u.ctarg.rsp_dma, | |
617 | GFP_KERNEL); | |
b5f3bc39 | 618 | sp->u.iocb_cmd.u.ctarg.rsp_allocated_size = sizeof(struct ct_sns_pkt); |
e374f9f5 QT |
619 | if (!sp->u.iocb_cmd.u.ctarg.rsp) { |
620 | ql_log(ql_log_warn, vha, 0xd042, | |
621 | "%s: Failed to allocate ct_sns request.\n", | |
622 | __func__); | |
623 | goto done_free_sp; | |
624 | } | |
625 | ct_sns = (struct ct_sns_pkt *)sp->u.iocb_cmd.u.ctarg.rsp; | |
626 | memset(ct_sns, 0, sizeof(*ct_sns)); | |
627 | ct_sns = (struct ct_sns_pkt *)sp->u.iocb_cmd.u.ctarg.req; | |
1da177e4 LT |
628 | |
629 | /* Prepare CT request */ | |
e374f9f5 | 630 | ct_req = qla2x00_prep_ct_req(ct_sns, RFT_ID_CMD, RFT_ID_RSP_SIZE); |
1da177e4 LT |
631 | |
632 | /* Prepare CT arguments -- port_id, FC-4 types */ | |
df95f39a | 633 | ct_req->req.rft_id.port_id = port_id_to_be_id(vha->d_id); |
1da177e4 LT |
634 | ct_req->req.rft_id.fc4_types[2] = 0x01; /* FCP-3 */ |
635 | ||
44d01857 | 636 | if (vha->flags.nvme_enabled && qla_ini_mode_enabled(vha)) |
d3bae931 | 637 | ct_req->req.rft_id.fc4_types[6] = 1; /* NVMe type 28h */ |
e374f9f5 QT |
638 | |
639 | sp->u.iocb_cmd.u.ctarg.req_size = RFT_ID_REQ_SIZE; | |
640 | sp->u.iocb_cmd.u.ctarg.rsp_size = RFT_ID_RSP_SIZE; | |
641 | sp->u.iocb_cmd.u.ctarg.nport_handle = NPH_SNS; | |
e374f9f5 | 642 | |
f233e8c0 BK |
643 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
644 | "Async-%s - hdl=%x portid %06x.\n", | |
645 | sp->name, sp->handle, d_id->b24); | |
646 | ||
e374f9f5 | 647 | rval = qla2x00_start_sp(sp); |
1da177e4 | 648 | if (rval != QLA_SUCCESS) { |
7c3df132 SK |
649 | ql_dbg(ql_dbg_disc, vha, 0x2043, |
650 | "RFT_ID issue IOCB failed (%d).\n", rval); | |
e374f9f5 | 651 | goto done_free_sp; |
1da177e4 | 652 | } |
e374f9f5 QT |
653 | return rval; |
654 | done_free_sp: | |
ee7bd382 SK |
655 | /* ref: INIT */ |
656 | kref_put(&sp->cmd_kref, qla2x00_sp_release); | |
e374f9f5 QT |
657 | done: |
658 | return rval; | |
1da177e4 LT |
659 | } |
660 | ||
661 | /** | |
662 | * qla2x00_rff_id() - SNS Register FC-4 Features (RFF_ID) supported by the HBA. | |
2db6228d BVA |
663 | * @vha: HA context |
664 | * @type: not used | |
1da177e4 LT |
665 | * |
666 | * Returns 0 on success. | |
667 | */ | |
668 | int | |
d3bae931 | 669 | qla2x00_rff_id(scsi_qla_host_t *vha, u8 type) |
1da177e4 | 670 | { |
7b867cf7 | 671 | struct qla_hw_data *ha = vha->hw; |
1da177e4 LT |
672 | |
673 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) { | |
7c3df132 SK |
674 | ql_dbg(ql_dbg_disc, vha, 0x2046, |
675 | "RFF_ID call not supported on ISP2100/ISP2200.\n"); | |
1da177e4 LT |
676 | return (QLA_SUCCESS); |
677 | } | |
678 | ||
0db54e9e | 679 | return qla_async_rffid(vha, &vha->d_id, qlt_rff_id(vha), type); |
e374f9f5 | 680 | } |
726b8548 | 681 | |
e374f9f5 QT |
682 | static int qla_async_rffid(scsi_qla_host_t *vha, port_id_t *d_id, |
683 | u8 fc4feature, u8 fc4type) | |
684 | { | |
685 | int rval = QLA_MEMORY_ALLOC_FAILED; | |
686 | struct ct_sns_req *ct_req; | |
687 | srb_t *sp; | |
688 | struct ct_sns_pkt *ct_sns; | |
1da177e4 | 689 | |
ee7bd382 | 690 | /* ref: INIT */ |
e374f9f5 QT |
691 | sp = qla2x00_get_sp(vha, NULL, GFP_KERNEL); |
692 | if (!sp) | |
693 | goto done; | |
1da177e4 | 694 | |
e374f9f5 QT |
695 | sp->type = SRB_CT_PTHRU_CMD; |
696 | sp->name = "rff_id"; | |
75a1d041 DW |
697 | qla2x00_init_async_sp(sp, qla2x00_get_async_timeout(vha) + 2, |
698 | qla2x00_async_sns_sp_done); | |
e374f9f5 QT |
699 | |
700 | sp->u.iocb_cmd.u.ctarg.req = dma_alloc_coherent(&vha->hw->pdev->dev, | |
701 | sizeof(struct ct_sns_pkt), &sp->u.iocb_cmd.u.ctarg.req_dma, | |
702 | GFP_KERNEL); | |
b5f3bc39 | 703 | sp->u.iocb_cmd.u.ctarg.req_allocated_size = sizeof(struct ct_sns_pkt); |
e374f9f5 QT |
704 | if (!sp->u.iocb_cmd.u.ctarg.req) { |
705 | ql_log(ql_log_warn, vha, 0xd041, | |
706 | "%s: Failed to allocate ct_sns request.\n", | |
707 | __func__); | |
708 | goto done_free_sp; | |
709 | } | |
1da177e4 | 710 | |
e374f9f5 QT |
711 | sp->u.iocb_cmd.u.ctarg.rsp = dma_alloc_coherent(&vha->hw->pdev->dev, |
712 | sizeof(struct ct_sns_pkt), &sp->u.iocb_cmd.u.ctarg.rsp_dma, | |
713 | GFP_KERNEL); | |
b5f3bc39 | 714 | sp->u.iocb_cmd.u.ctarg.rsp_allocated_size = sizeof(struct ct_sns_pkt); |
e374f9f5 QT |
715 | if (!sp->u.iocb_cmd.u.ctarg.rsp) { |
716 | ql_log(ql_log_warn, vha, 0xd042, | |
717 | "%s: Failed to allocate ct_sns request.\n", | |
718 | __func__); | |
719 | goto done_free_sp; | |
720 | } | |
721 | ct_sns = (struct ct_sns_pkt *)sp->u.iocb_cmd.u.ctarg.rsp; | |
722 | memset(ct_sns, 0, sizeof(*ct_sns)); | |
723 | ct_sns = (struct ct_sns_pkt *)sp->u.iocb_cmd.u.ctarg.req; | |
2d70c103 | 724 | |
e374f9f5 QT |
725 | /* Prepare CT request */ |
726 | ct_req = qla2x00_prep_ct_req(ct_sns, RFF_ID_CMD, RFF_ID_RSP_SIZE); | |
1da177e4 | 727 | |
e374f9f5 | 728 | /* Prepare CT arguments -- port_id, FC-4 feature, FC-4 type */ |
df95f39a | 729 | ct_req->req.rff_id.port_id = port_id_to_be_id(*d_id); |
e374f9f5 | 730 | ct_req->req.rff_id.fc4_feature = fc4feature; |
0db54e9e | 731 | ct_req->req.rff_id.fc4_type = fc4type; /* SCSI-FCP or FC-NVMe */ |
e374f9f5 QT |
732 | |
733 | sp->u.iocb_cmd.u.ctarg.req_size = RFF_ID_REQ_SIZE; | |
734 | sp->u.iocb_cmd.u.ctarg.rsp_size = RFF_ID_RSP_SIZE; | |
735 | sp->u.iocb_cmd.u.ctarg.nport_handle = NPH_SNS; | |
e374f9f5 | 736 | |
f233e8c0 BK |
737 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
738 | "Async-%s - hdl=%x portid %06x feature %x type %x.\n", | |
739 | sp->name, sp->handle, d_id->b24, fc4feature, fc4type); | |
740 | ||
e374f9f5 | 741 | rval = qla2x00_start_sp(sp); |
1da177e4 | 742 | if (rval != QLA_SUCCESS) { |
7c3df132 SK |
743 | ql_dbg(ql_dbg_disc, vha, 0x2047, |
744 | "RFF_ID issue IOCB failed (%d).\n", rval); | |
e374f9f5 | 745 | goto done_free_sp; |
1da177e4 LT |
746 | } |
747 | ||
e374f9f5 QT |
748 | return rval; |
749 | ||
750 | done_free_sp: | |
ee7bd382 SK |
751 | /* ref: INIT */ |
752 | kref_put(&sp->cmd_kref, qla2x00_sp_release); | |
e374f9f5 QT |
753 | done: |
754 | return rval; | |
1da177e4 LT |
755 | } |
756 | ||
757 | /** | |
758 | * qla2x00_rnn_id() - SNS Register Node Name (RNN_ID) of the HBA. | |
2db6228d | 759 | * @vha: HA context |
1da177e4 LT |
760 | * |
761 | * Returns 0 on success. | |
762 | */ | |
763 | int | |
7b867cf7 | 764 | qla2x00_rnn_id(scsi_qla_host_t *vha) |
1da177e4 | 765 | { |
7b867cf7 | 766 | struct qla_hw_data *ha = vha->hw; |
1da177e4 | 767 | |
7b867cf7 AC |
768 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) |
769 | return qla2x00_sns_rnn_id(vha); | |
1da177e4 | 770 | |
e374f9f5 QT |
771 | return qla_async_rnnid(vha, &vha->d_id, vha->node_name); |
772 | } | |
726b8548 | 773 | |
e374f9f5 QT |
774 | static int qla_async_rnnid(scsi_qla_host_t *vha, port_id_t *d_id, |
775 | u8 *node_name) | |
776 | { | |
777 | int rval = QLA_MEMORY_ALLOC_FAILED; | |
778 | struct ct_sns_req *ct_req; | |
779 | srb_t *sp; | |
780 | struct ct_sns_pkt *ct_sns; | |
781 | ||
ee7bd382 | 782 | /* ref: INIT */ |
e374f9f5 QT |
783 | sp = qla2x00_get_sp(vha, NULL, GFP_KERNEL); |
784 | if (!sp) | |
785 | goto done; | |
786 | ||
787 | sp->type = SRB_CT_PTHRU_CMD; | |
788 | sp->name = "rnid"; | |
75a1d041 DW |
789 | qla2x00_init_async_sp(sp, qla2x00_get_async_timeout(vha) + 2, |
790 | qla2x00_async_sns_sp_done); | |
e374f9f5 QT |
791 | |
792 | sp->u.iocb_cmd.u.ctarg.req = dma_alloc_coherent(&vha->hw->pdev->dev, | |
793 | sizeof(struct ct_sns_pkt), &sp->u.iocb_cmd.u.ctarg.req_dma, | |
794 | GFP_KERNEL); | |
b5f3bc39 | 795 | sp->u.iocb_cmd.u.ctarg.req_allocated_size = sizeof(struct ct_sns_pkt); |
e374f9f5 QT |
796 | if (!sp->u.iocb_cmd.u.ctarg.req) { |
797 | ql_log(ql_log_warn, vha, 0xd041, | |
798 | "%s: Failed to allocate ct_sns request.\n", | |
799 | __func__); | |
800 | goto done_free_sp; | |
801 | } | |
802 | ||
803 | sp->u.iocb_cmd.u.ctarg.rsp = dma_alloc_coherent(&vha->hw->pdev->dev, | |
804 | sizeof(struct ct_sns_pkt), &sp->u.iocb_cmd.u.ctarg.rsp_dma, | |
805 | GFP_KERNEL); | |
b5f3bc39 | 806 | sp->u.iocb_cmd.u.ctarg.rsp_allocated_size = sizeof(struct ct_sns_pkt); |
e374f9f5 QT |
807 | if (!sp->u.iocb_cmd.u.ctarg.rsp) { |
808 | ql_log(ql_log_warn, vha, 0xd042, | |
809 | "%s: Failed to allocate ct_sns request.\n", | |
810 | __func__); | |
811 | goto done_free_sp; | |
812 | } | |
813 | ct_sns = (struct ct_sns_pkt *)sp->u.iocb_cmd.u.ctarg.rsp; | |
814 | memset(ct_sns, 0, sizeof(*ct_sns)); | |
815 | ct_sns = (struct ct_sns_pkt *)sp->u.iocb_cmd.u.ctarg.req; | |
1da177e4 LT |
816 | |
817 | /* Prepare CT request */ | |
e374f9f5 | 818 | ct_req = qla2x00_prep_ct_req(ct_sns, RNN_ID_CMD, RNN_ID_RSP_SIZE); |
1da177e4 LT |
819 | |
820 | /* Prepare CT arguments -- port_id, node_name */ | |
df95f39a | 821 | ct_req->req.rnn_id.port_id = port_id_to_be_id(vha->d_id); |
7b867cf7 | 822 | memcpy(ct_req->req.rnn_id.node_name, vha->node_name, WWN_SIZE); |
1da177e4 | 823 | |
e374f9f5 QT |
824 | sp->u.iocb_cmd.u.ctarg.req_size = RNN_ID_REQ_SIZE; |
825 | sp->u.iocb_cmd.u.ctarg.rsp_size = RNN_ID_RSP_SIZE; | |
826 | sp->u.iocb_cmd.u.ctarg.nport_handle = NPH_SNS; | |
827 | ||
f233e8c0 BK |
828 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
829 | "Async-%s - hdl=%x portid %06x\n", | |
830 | sp->name, sp->handle, d_id->b24); | |
831 | ||
e374f9f5 | 832 | rval = qla2x00_start_sp(sp); |
1da177e4 | 833 | if (rval != QLA_SUCCESS) { |
7c3df132 SK |
834 | ql_dbg(ql_dbg_disc, vha, 0x204d, |
835 | "RNN_ID issue IOCB failed (%d).\n", rval); | |
e374f9f5 | 836 | goto done_free_sp; |
1da177e4 LT |
837 | } |
838 | ||
e374f9f5 QT |
839 | return rval; |
840 | ||
841 | done_free_sp: | |
ee7bd382 SK |
842 | /* ref: INIT */ |
843 | kref_put(&sp->cmd_kref, qla2x00_sp_release); | |
e374f9f5 QT |
844 | done: |
845 | return rval; | |
1da177e4 LT |
846 | } |
847 | ||
818c7f87 | 848 | size_t |
df57caba | 849 | qla2x00_get_sym_node_name(scsi_qla_host_t *vha, uint8_t *snn, size_t size) |
1620f7c2 | 850 | { |
7b867cf7 | 851 | struct qla_hw_data *ha = vha->hw; |
8ae6d9c7 GM |
852 | |
853 | if (IS_QLAFX00(ha)) | |
818c7f87 JC |
854 | return scnprintf(snn, size, "%s FW:v%s DVR:v%s", |
855 | ha->model_number, ha->mr.fw_version, qla2x00_version_str); | |
856 | ||
857 | return scnprintf(snn, size, "%s FW:v%d.%02d.%02d DVR:v%s", | |
858 | ha->model_number, ha->fw_major_version, ha->fw_minor_version, | |
859 | ha->fw_subminor_version, qla2x00_version_str); | |
1620f7c2 AV |
860 | } |
861 | ||
1da177e4 LT |
862 | /** |
863 | * qla2x00_rsnn_nn() - SNS Register Symbolic Node Name (RSNN_NN) of the HBA. | |
2db6228d | 864 | * @vha: HA context |
1da177e4 LT |
865 | * |
866 | * Returns 0 on success. | |
867 | */ | |
868 | int | |
7b867cf7 | 869 | qla2x00_rsnn_nn(scsi_qla_host_t *vha) |
1da177e4 | 870 | { |
7b867cf7 | 871 | struct qla_hw_data *ha = vha->hw; |
1da177e4 LT |
872 | |
873 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) { | |
7c3df132 SK |
874 | ql_dbg(ql_dbg_disc, vha, 0x2050, |
875 | "RSNN_ID call unsupported on ISP2100/ISP2200.\n"); | |
1da177e4 LT |
876 | return (QLA_SUCCESS); |
877 | } | |
878 | ||
e374f9f5 QT |
879 | return qla_async_rsnn_nn(vha); |
880 | } | |
726b8548 | 881 | |
e374f9f5 QT |
882 | static int qla_async_rsnn_nn(scsi_qla_host_t *vha) |
883 | { | |
884 | int rval = QLA_MEMORY_ALLOC_FAILED; | |
885 | struct ct_sns_req *ct_req; | |
886 | srb_t *sp; | |
887 | struct ct_sns_pkt *ct_sns; | |
888 | ||
ee7bd382 | 889 | /* ref: INIT */ |
e374f9f5 QT |
890 | sp = qla2x00_get_sp(vha, NULL, GFP_KERNEL); |
891 | if (!sp) | |
892 | goto done; | |
893 | ||
894 | sp->type = SRB_CT_PTHRU_CMD; | |
895 | sp->name = "rsnn_nn"; | |
75a1d041 DW |
896 | qla2x00_init_async_sp(sp, qla2x00_get_async_timeout(vha) + 2, |
897 | qla2x00_async_sns_sp_done); | |
e374f9f5 QT |
898 | |
899 | sp->u.iocb_cmd.u.ctarg.req = dma_alloc_coherent(&vha->hw->pdev->dev, | |
900 | sizeof(struct ct_sns_pkt), &sp->u.iocb_cmd.u.ctarg.req_dma, | |
901 | GFP_KERNEL); | |
b5f3bc39 | 902 | sp->u.iocb_cmd.u.ctarg.req_allocated_size = sizeof(struct ct_sns_pkt); |
e374f9f5 QT |
903 | if (!sp->u.iocb_cmd.u.ctarg.req) { |
904 | ql_log(ql_log_warn, vha, 0xd041, | |
905 | "%s: Failed to allocate ct_sns request.\n", | |
906 | __func__); | |
907 | goto done_free_sp; | |
908 | } | |
909 | ||
910 | sp->u.iocb_cmd.u.ctarg.rsp = dma_alloc_coherent(&vha->hw->pdev->dev, | |
911 | sizeof(struct ct_sns_pkt), &sp->u.iocb_cmd.u.ctarg.rsp_dma, | |
912 | GFP_KERNEL); | |
b5f3bc39 | 913 | sp->u.iocb_cmd.u.ctarg.rsp_allocated_size = sizeof(struct ct_sns_pkt); |
e374f9f5 QT |
914 | if (!sp->u.iocb_cmd.u.ctarg.rsp) { |
915 | ql_log(ql_log_warn, vha, 0xd042, | |
916 | "%s: Failed to allocate ct_sns request.\n", | |
917 | __func__); | |
918 | goto done_free_sp; | |
919 | } | |
920 | ct_sns = (struct ct_sns_pkt *)sp->u.iocb_cmd.u.ctarg.rsp; | |
921 | memset(ct_sns, 0, sizeof(*ct_sns)); | |
922 | ct_sns = (struct ct_sns_pkt *)sp->u.iocb_cmd.u.ctarg.req; | |
1da177e4 LT |
923 | |
924 | /* Prepare CT request */ | |
e374f9f5 | 925 | ct_req = qla2x00_prep_ct_req(ct_sns, RSNN_NN_CMD, RSNN_NN_RSP_SIZE); |
1da177e4 LT |
926 | |
927 | /* Prepare CT arguments -- node_name, symbolic node_name, size */ | |
7b867cf7 | 928 | memcpy(ct_req->req.rsnn_nn.node_name, vha->node_name, WWN_SIZE); |
fa2a1ce5 | 929 | |
1da177e4 | 930 | /* Prepare the Symbolic Node Name */ |
df57caba HM |
931 | qla2x00_get_sym_node_name(vha, ct_req->req.rsnn_nn.sym_node_name, |
932 | sizeof(ct_req->req.rsnn_nn.sym_node_name)); | |
1620f7c2 AV |
933 | ct_req->req.rsnn_nn.name_len = |
934 | (uint8_t)strlen(ct_req->req.rsnn_nn.sym_node_name); | |
1da177e4 | 935 | |
1da177e4 | 936 | |
e374f9f5 QT |
937 | sp->u.iocb_cmd.u.ctarg.req_size = 24 + 1 + ct_req->req.rsnn_nn.name_len; |
938 | sp->u.iocb_cmd.u.ctarg.rsp_size = RSNN_NN_RSP_SIZE; | |
939 | sp->u.iocb_cmd.u.ctarg.nport_handle = NPH_SNS; | |
940 | ||
f233e8c0 BK |
941 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
942 | "Async-%s - hdl=%x.\n", | |
943 | sp->name, sp->handle); | |
944 | ||
e374f9f5 | 945 | rval = qla2x00_start_sp(sp); |
1da177e4 | 946 | if (rval != QLA_SUCCESS) { |
e374f9f5 QT |
947 | ql_dbg(ql_dbg_disc, vha, 0x2043, |
948 | "RFT_ID issue IOCB failed (%d).\n", rval); | |
949 | goto done_free_sp; | |
1da177e4 LT |
950 | } |
951 | ||
e374f9f5 QT |
952 | return rval; |
953 | ||
954 | done_free_sp: | |
ee7bd382 SK |
955 | /* ref: INIT */ |
956 | kref_put(&sp->cmd_kref, qla2x00_sp_release); | |
e374f9f5 QT |
957 | done: |
958 | return rval; | |
1da177e4 LT |
959 | } |
960 | ||
1da177e4 LT |
961 | /** |
962 | * qla2x00_prep_sns_cmd() - Prepare common SNS command request fields for query. | |
2db6228d | 963 | * @vha: HA context |
1da177e4 LT |
964 | * @cmd: GS command |
965 | * @scmd_len: Subcommand length | |
966 | * @data_size: response size in bytes | |
967 | * | |
968 | * Returns a pointer to the @ha's sns_cmd. | |
969 | */ | |
970 | static inline struct sns_cmd_pkt * | |
7b867cf7 | 971 | qla2x00_prep_sns_cmd(scsi_qla_host_t *vha, uint16_t cmd, uint16_t scmd_len, |
1da177e4 LT |
972 | uint16_t data_size) |
973 | { | |
974 | uint16_t wc; | |
975 | struct sns_cmd_pkt *sns_cmd; | |
7b867cf7 | 976 | struct qla_hw_data *ha = vha->hw; |
1da177e4 LT |
977 | |
978 | sns_cmd = ha->sns_cmd; | |
979 | memset(sns_cmd, 0, sizeof(struct sns_cmd_pkt)); | |
980 | wc = data_size / 2; /* Size in 16bit words. */ | |
981 | sns_cmd->p.cmd.buffer_length = cpu_to_le16(wc); | |
d4556a49 | 982 | put_unaligned_le64(ha->sns_cmd_dma, &sns_cmd->p.cmd.buffer_address); |
1da177e4 LT |
983 | sns_cmd->p.cmd.subcommand_length = cpu_to_le16(scmd_len); |
984 | sns_cmd->p.cmd.subcommand = cpu_to_le16(cmd); | |
985 | wc = (data_size - 16) / 4; /* Size in 32bit words. */ | |
986 | sns_cmd->p.cmd.size = cpu_to_le16(wc); | |
987 | ||
fabbb8df JC |
988 | vha->qla_stats.control_requests++; |
989 | ||
1da177e4 LT |
990 | return (sns_cmd); |
991 | } | |
992 | ||
993 | /** | |
994 | * qla2x00_sns_ga_nxt() - SNS scan for fabric devices via GA_NXT command. | |
2db6228d | 995 | * @vha: HA context |
1da177e4 LT |
996 | * @fcport: fcport entry to updated |
997 | * | |
998 | * This command uses the old Exectute SNS Command mailbox routine. | |
999 | * | |
1000 | * Returns 0 on success. | |
1001 | */ | |
1002 | static int | |
7b867cf7 | 1003 | qla2x00_sns_ga_nxt(scsi_qla_host_t *vha, fc_port_t *fcport) |
1da177e4 | 1004 | { |
642ef983 | 1005 | int rval = QLA_SUCCESS; |
7b867cf7 | 1006 | struct qla_hw_data *ha = vha->hw; |
1da177e4 LT |
1007 | struct sns_cmd_pkt *sns_cmd; |
1008 | ||
1009 | /* Issue GA_NXT. */ | |
1010 | /* Prepare SNS command request. */ | |
7b867cf7 | 1011 | sns_cmd = qla2x00_prep_sns_cmd(vha, GA_NXT_CMD, GA_NXT_SNS_SCMD_LEN, |
1da177e4 LT |
1012 | GA_NXT_SNS_DATA_SIZE); |
1013 | ||
1014 | /* Prepare SNS command arguments -- port_id. */ | |
1015 | sns_cmd->p.cmd.param[0] = fcport->d_id.b.al_pa; | |
1016 | sns_cmd->p.cmd.param[1] = fcport->d_id.b.area; | |
1017 | sns_cmd->p.cmd.param[2] = fcport->d_id.b.domain; | |
1018 | ||
1019 | /* Execute SNS command. */ | |
7b867cf7 | 1020 | rval = qla2x00_send_sns(vha, ha->sns_cmd_dma, GA_NXT_SNS_CMD_SIZE / 2, |
1da177e4 LT |
1021 | sizeof(struct sns_cmd_pkt)); |
1022 | if (rval != QLA_SUCCESS) { | |
1023 | /*EMPTY*/ | |
7c3df132 SK |
1024 | ql_dbg(ql_dbg_disc, vha, 0x205f, |
1025 | "GA_NXT Send SNS failed (%d).\n", rval); | |
1da177e4 LT |
1026 | } else if (sns_cmd->p.gan_data[8] != 0x80 || |
1027 | sns_cmd->p.gan_data[9] != 0x02) { | |
cfb0919c | 1028 | ql_dbg(ql_dbg_disc + ql_dbg_buffer, vha, 0x2084, |
7c3df132 SK |
1029 | "GA_NXT failed, rejected request ga_nxt_rsp:\n"); |
1030 | ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2074, | |
1031 | sns_cmd->p.gan_data, 16); | |
1da177e4 LT |
1032 | rval = QLA_FUNCTION_FAILED; |
1033 | } else { | |
1034 | /* Populate fc_port_t entry. */ | |
1035 | fcport->d_id.b.domain = sns_cmd->p.gan_data[17]; | |
1036 | fcport->d_id.b.area = sns_cmd->p.gan_data[18]; | |
1037 | fcport->d_id.b.al_pa = sns_cmd->p.gan_data[19]; | |
1038 | ||
1039 | memcpy(fcport->node_name, &sns_cmd->p.gan_data[284], WWN_SIZE); | |
1040 | memcpy(fcport->port_name, &sns_cmd->p.gan_data[20], WWN_SIZE); | |
1041 | ||
1042 | if (sns_cmd->p.gan_data[16] != NS_N_PORT_TYPE && | |
1043 | sns_cmd->p.gan_data[16] != NS_NL_PORT_TYPE) | |
1044 | fcport->d_id.b.domain = 0xf0; | |
1045 | ||
7c3df132 | 1046 | ql_dbg(ql_dbg_disc, vha, 0x2061, |
7b833558 | 1047 | "GA_NXT entry - nn %8phN pn %8phN " |
7c3df132 | 1048 | "port_id=%02x%02x%02x.\n", |
7b833558 | 1049 | fcport->node_name, fcport->port_name, |
1da177e4 | 1050 | fcport->d_id.b.domain, fcport->d_id.b.area, |
7c3df132 | 1051 | fcport->d_id.b.al_pa); |
1da177e4 LT |
1052 | } |
1053 | ||
1054 | return (rval); | |
1055 | } | |
1056 | ||
1057 | /** | |
1058 | * qla2x00_sns_gid_pt() - SNS scan for fabric devices via GID_PT command. | |
2db6228d | 1059 | * @vha: HA context |
1da177e4 LT |
1060 | * @list: switch info entries to populate |
1061 | * | |
1062 | * This command uses the old Exectute SNS Command mailbox routine. | |
1063 | * | |
1064 | * NOTE: Non-Nx_Ports are not requested. | |
1065 | * | |
1066 | * Returns 0 on success. | |
1067 | */ | |
1068 | static int | |
7b867cf7 | 1069 | qla2x00_sns_gid_pt(scsi_qla_host_t *vha, sw_info_t *list) |
1da177e4 LT |
1070 | { |
1071 | int rval; | |
7b867cf7 | 1072 | struct qla_hw_data *ha = vha->hw; |
1da177e4 LT |
1073 | uint16_t i; |
1074 | uint8_t *entry; | |
1075 | struct sns_cmd_pkt *sns_cmd; | |
642ef983 CD |
1076 | uint16_t gid_pt_sns_data_size; |
1077 | ||
1078 | gid_pt_sns_data_size = qla2x00_gid_pt_rsp_size(vha); | |
1da177e4 LT |
1079 | |
1080 | /* Issue GID_PT. */ | |
1081 | /* Prepare SNS command request. */ | |
7b867cf7 | 1082 | sns_cmd = qla2x00_prep_sns_cmd(vha, GID_PT_CMD, GID_PT_SNS_SCMD_LEN, |
642ef983 | 1083 | gid_pt_sns_data_size); |
1da177e4 LT |
1084 | |
1085 | /* Prepare SNS command arguments -- port_type. */ | |
1086 | sns_cmd->p.cmd.param[0] = NS_NX_PORT_TYPE; | |
1087 | ||
1088 | /* Execute SNS command. */ | |
7b867cf7 | 1089 | rval = qla2x00_send_sns(vha, ha->sns_cmd_dma, GID_PT_SNS_CMD_SIZE / 2, |
1da177e4 LT |
1090 | sizeof(struct sns_cmd_pkt)); |
1091 | if (rval != QLA_SUCCESS) { | |
1092 | /*EMPTY*/ | |
7c3df132 SK |
1093 | ql_dbg(ql_dbg_disc, vha, 0x206d, |
1094 | "GID_PT Send SNS failed (%d).\n", rval); | |
1da177e4 LT |
1095 | } else if (sns_cmd->p.gid_data[8] != 0x80 || |
1096 | sns_cmd->p.gid_data[9] != 0x02) { | |
7c3df132 SK |
1097 | ql_dbg(ql_dbg_disc, vha, 0x202f, |
1098 | "GID_PT failed, rejected request, gid_rsp:\n"); | |
1099 | ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2081, | |
1100 | sns_cmd->p.gid_data, 16); | |
1da177e4 LT |
1101 | rval = QLA_FUNCTION_FAILED; |
1102 | } else { | |
1103 | /* Set port IDs in switch info list. */ | |
642ef983 | 1104 | for (i = 0; i < ha->max_fibre_devices; i++) { |
1da177e4 LT |
1105 | entry = &sns_cmd->p.gid_data[(i * 4) + 16]; |
1106 | list[i].d_id.b.domain = entry[1]; | |
1107 | list[i].d_id.b.area = entry[2]; | |
1108 | list[i].d_id.b.al_pa = entry[3]; | |
1109 | ||
1110 | /* Last one exit. */ | |
1111 | if (entry[0] & BIT_7) { | |
1112 | list[i].d_id.b.rsvd_1 = entry[0]; | |
1113 | break; | |
1114 | } | |
1115 | } | |
1116 | ||
1117 | /* | |
1118 | * If we've used all available slots, then the switch is | |
1119 | * reporting back more devices that we can handle with this | |
1120 | * single call. Return a failed status, and let GA_NXT handle | |
1121 | * the overload. | |
1122 | */ | |
642ef983 | 1123 | if (i == ha->max_fibre_devices) |
1da177e4 LT |
1124 | rval = QLA_FUNCTION_FAILED; |
1125 | } | |
1126 | ||
1127 | return (rval); | |
1128 | } | |
1129 | ||
1130 | /** | |
1131 | * qla2x00_sns_gpn_id() - SNS Get Port Name (GPN_ID) query. | |
2db6228d | 1132 | * @vha: HA context |
1da177e4 LT |
1133 | * @list: switch info entries to populate |
1134 | * | |
1135 | * This command uses the old Exectute SNS Command mailbox routine. | |
1136 | * | |
1137 | * Returns 0 on success. | |
1138 | */ | |
1139 | static int | |
7b867cf7 | 1140 | qla2x00_sns_gpn_id(scsi_qla_host_t *vha, sw_info_t *list) |
1da177e4 | 1141 | { |
642ef983 | 1142 | int rval = QLA_SUCCESS; |
7b867cf7 | 1143 | struct qla_hw_data *ha = vha->hw; |
1da177e4 LT |
1144 | uint16_t i; |
1145 | struct sns_cmd_pkt *sns_cmd; | |
1146 | ||
642ef983 | 1147 | for (i = 0; i < ha->max_fibre_devices; i++) { |
1da177e4 LT |
1148 | /* Issue GPN_ID */ |
1149 | /* Prepare SNS command request. */ | |
7b867cf7 | 1150 | sns_cmd = qla2x00_prep_sns_cmd(vha, GPN_ID_CMD, |
1da177e4 LT |
1151 | GPN_ID_SNS_SCMD_LEN, GPN_ID_SNS_DATA_SIZE); |
1152 | ||
1153 | /* Prepare SNS command arguments -- port_id. */ | |
1154 | sns_cmd->p.cmd.param[0] = list[i].d_id.b.al_pa; | |
1155 | sns_cmd->p.cmd.param[1] = list[i].d_id.b.area; | |
1156 | sns_cmd->p.cmd.param[2] = list[i].d_id.b.domain; | |
1157 | ||
1158 | /* Execute SNS command. */ | |
7b867cf7 | 1159 | rval = qla2x00_send_sns(vha, ha->sns_cmd_dma, |
1da177e4 LT |
1160 | GPN_ID_SNS_CMD_SIZE / 2, sizeof(struct sns_cmd_pkt)); |
1161 | if (rval != QLA_SUCCESS) { | |
1162 | /*EMPTY*/ | |
7c3df132 SK |
1163 | ql_dbg(ql_dbg_disc, vha, 0x2032, |
1164 | "GPN_ID Send SNS failed (%d).\n", rval); | |
1da177e4 LT |
1165 | } else if (sns_cmd->p.gpn_data[8] != 0x80 || |
1166 | sns_cmd->p.gpn_data[9] != 0x02) { | |
7c3df132 SK |
1167 | ql_dbg(ql_dbg_disc + ql_dbg_buffer, vha, 0x207e, |
1168 | "GPN_ID failed, rejected request, gpn_rsp:\n"); | |
8ae6d9c7 | 1169 | ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x207f, |
7c3df132 | 1170 | sns_cmd->p.gpn_data, 16); |
1da177e4 LT |
1171 | rval = QLA_FUNCTION_FAILED; |
1172 | } else { | |
1173 | /* Save portname */ | |
1174 | memcpy(list[i].port_name, &sns_cmd->p.gpn_data[16], | |
1175 | WWN_SIZE); | |
1176 | } | |
1177 | ||
1178 | /* Last device exit. */ | |
1179 | if (list[i].d_id.b.rsvd_1 != 0) | |
1180 | break; | |
1181 | } | |
1182 | ||
1183 | return (rval); | |
1184 | } | |
1185 | ||
1186 | /** | |
1187 | * qla2x00_sns_gnn_id() - SNS Get Node Name (GNN_ID) query. | |
2db6228d | 1188 | * @vha: HA context |
1da177e4 LT |
1189 | * @list: switch info entries to populate |
1190 | * | |
1191 | * This command uses the old Exectute SNS Command mailbox routine. | |
1192 | * | |
1193 | * Returns 0 on success. | |
1194 | */ | |
1195 | static int | |
7b867cf7 | 1196 | qla2x00_sns_gnn_id(scsi_qla_host_t *vha, sw_info_t *list) |
1da177e4 | 1197 | { |
642ef983 | 1198 | int rval = QLA_SUCCESS; |
7b867cf7 | 1199 | struct qla_hw_data *ha = vha->hw; |
1da177e4 LT |
1200 | uint16_t i; |
1201 | struct sns_cmd_pkt *sns_cmd; | |
1202 | ||
642ef983 | 1203 | for (i = 0; i < ha->max_fibre_devices; i++) { |
1da177e4 LT |
1204 | /* Issue GNN_ID */ |
1205 | /* Prepare SNS command request. */ | |
7b867cf7 | 1206 | sns_cmd = qla2x00_prep_sns_cmd(vha, GNN_ID_CMD, |
1da177e4 LT |
1207 | GNN_ID_SNS_SCMD_LEN, GNN_ID_SNS_DATA_SIZE); |
1208 | ||
1209 | /* Prepare SNS command arguments -- port_id. */ | |
1210 | sns_cmd->p.cmd.param[0] = list[i].d_id.b.al_pa; | |
1211 | sns_cmd->p.cmd.param[1] = list[i].d_id.b.area; | |
1212 | sns_cmd->p.cmd.param[2] = list[i].d_id.b.domain; | |
1213 | ||
1214 | /* Execute SNS command. */ | |
7b867cf7 | 1215 | rval = qla2x00_send_sns(vha, ha->sns_cmd_dma, |
1da177e4 LT |
1216 | GNN_ID_SNS_CMD_SIZE / 2, sizeof(struct sns_cmd_pkt)); |
1217 | if (rval != QLA_SUCCESS) { | |
1218 | /*EMPTY*/ | |
7c3df132 SK |
1219 | ql_dbg(ql_dbg_disc, vha, 0x203f, |
1220 | "GNN_ID Send SNS failed (%d).\n", rval); | |
1da177e4 LT |
1221 | } else if (sns_cmd->p.gnn_data[8] != 0x80 || |
1222 | sns_cmd->p.gnn_data[9] != 0x02) { | |
7c3df132 SK |
1223 | ql_dbg(ql_dbg_disc + ql_dbg_buffer, vha, 0x2082, |
1224 | "GNN_ID failed, rejected request, gnn_rsp:\n"); | |
1225 | ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x207a, | |
1226 | sns_cmd->p.gnn_data, 16); | |
1da177e4 LT |
1227 | rval = QLA_FUNCTION_FAILED; |
1228 | } else { | |
1229 | /* Save nodename */ | |
1230 | memcpy(list[i].node_name, &sns_cmd->p.gnn_data[16], | |
1231 | WWN_SIZE); | |
1232 | ||
7c3df132 | 1233 | ql_dbg(ql_dbg_disc, vha, 0x206e, |
7b833558 | 1234 | "GID_PT entry - nn %8phN pn %8phN " |
7c3df132 | 1235 | "port_id=%02x%02x%02x.\n", |
7b833558 | 1236 | list[i].node_name, list[i].port_name, |
1da177e4 | 1237 | list[i].d_id.b.domain, list[i].d_id.b.area, |
7c3df132 | 1238 | list[i].d_id.b.al_pa); |
1da177e4 LT |
1239 | } |
1240 | ||
1241 | /* Last device exit. */ | |
1242 | if (list[i].d_id.b.rsvd_1 != 0) | |
1243 | break; | |
1244 | } | |
1245 | ||
1246 | return (rval); | |
1247 | } | |
1248 | ||
1249 | /** | |
f11c8b42 | 1250 | * qla2x00_sns_rft_id() - SNS Register FC-4 TYPEs (RFT_ID) supported by the HBA. |
2db6228d | 1251 | * @vha: HA context |
1da177e4 LT |
1252 | * |
1253 | * This command uses the old Exectute SNS Command mailbox routine. | |
1254 | * | |
1255 | * Returns 0 on success. | |
1256 | */ | |
1257 | static int | |
7b867cf7 | 1258 | qla2x00_sns_rft_id(scsi_qla_host_t *vha) |
1da177e4 LT |
1259 | { |
1260 | int rval; | |
7b867cf7 | 1261 | struct qla_hw_data *ha = vha->hw; |
1da177e4 LT |
1262 | struct sns_cmd_pkt *sns_cmd; |
1263 | ||
1264 | /* Issue RFT_ID. */ | |
1265 | /* Prepare SNS command request. */ | |
7b867cf7 | 1266 | sns_cmd = qla2x00_prep_sns_cmd(vha, RFT_ID_CMD, RFT_ID_SNS_SCMD_LEN, |
1da177e4 LT |
1267 | RFT_ID_SNS_DATA_SIZE); |
1268 | ||
1269 | /* Prepare SNS command arguments -- port_id, FC-4 types */ | |
7b867cf7 AC |
1270 | sns_cmd->p.cmd.param[0] = vha->d_id.b.al_pa; |
1271 | sns_cmd->p.cmd.param[1] = vha->d_id.b.area; | |
1272 | sns_cmd->p.cmd.param[2] = vha->d_id.b.domain; | |
1da177e4 LT |
1273 | |
1274 | sns_cmd->p.cmd.param[5] = 0x01; /* FCP-3 */ | |
1275 | ||
1276 | /* Execute SNS command. */ | |
7b867cf7 | 1277 | rval = qla2x00_send_sns(vha, ha->sns_cmd_dma, RFT_ID_SNS_CMD_SIZE / 2, |
1da177e4 LT |
1278 | sizeof(struct sns_cmd_pkt)); |
1279 | if (rval != QLA_SUCCESS) { | |
1280 | /*EMPTY*/ | |
7c3df132 SK |
1281 | ql_dbg(ql_dbg_disc, vha, 0x2060, |
1282 | "RFT_ID Send SNS failed (%d).\n", rval); | |
1da177e4 LT |
1283 | } else if (sns_cmd->p.rft_data[8] != 0x80 || |
1284 | sns_cmd->p.rft_data[9] != 0x02) { | |
7c3df132 SK |
1285 | ql_dbg(ql_dbg_disc + ql_dbg_buffer, vha, 0x2083, |
1286 | "RFT_ID failed, rejected request rft_rsp:\n"); | |
1287 | ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2080, | |
1288 | sns_cmd->p.rft_data, 16); | |
1da177e4 LT |
1289 | rval = QLA_FUNCTION_FAILED; |
1290 | } else { | |
7c3df132 SK |
1291 | ql_dbg(ql_dbg_disc, vha, 0x2073, |
1292 | "RFT_ID exiting normally.\n"); | |
1da177e4 LT |
1293 | } |
1294 | ||
1295 | return (rval); | |
1296 | } | |
1297 | ||
1298 | /** | |
1299 | * qla2x00_sns_rnn_id() - SNS Register Node Name (RNN_ID) of the HBA. | |
2db6228d | 1300 | * @vha: HA context |
1da177e4 LT |
1301 | * |
1302 | * This command uses the old Exectute SNS Command mailbox routine. | |
1303 | * | |
1304 | * Returns 0 on success. | |
1305 | */ | |
1306 | static int | |
7b867cf7 | 1307 | qla2x00_sns_rnn_id(scsi_qla_host_t *vha) |
1da177e4 LT |
1308 | { |
1309 | int rval; | |
7b867cf7 | 1310 | struct qla_hw_data *ha = vha->hw; |
1da177e4 LT |
1311 | struct sns_cmd_pkt *sns_cmd; |
1312 | ||
1313 | /* Issue RNN_ID. */ | |
1314 | /* Prepare SNS command request. */ | |
7b867cf7 | 1315 | sns_cmd = qla2x00_prep_sns_cmd(vha, RNN_ID_CMD, RNN_ID_SNS_SCMD_LEN, |
1da177e4 LT |
1316 | RNN_ID_SNS_DATA_SIZE); |
1317 | ||
1318 | /* Prepare SNS command arguments -- port_id, nodename. */ | |
7b867cf7 AC |
1319 | sns_cmd->p.cmd.param[0] = vha->d_id.b.al_pa; |
1320 | sns_cmd->p.cmd.param[1] = vha->d_id.b.area; | |
1321 | sns_cmd->p.cmd.param[2] = vha->d_id.b.domain; | |
1322 | ||
1323 | sns_cmd->p.cmd.param[4] = vha->node_name[7]; | |
1324 | sns_cmd->p.cmd.param[5] = vha->node_name[6]; | |
1325 | sns_cmd->p.cmd.param[6] = vha->node_name[5]; | |
1326 | sns_cmd->p.cmd.param[7] = vha->node_name[4]; | |
1327 | sns_cmd->p.cmd.param[8] = vha->node_name[3]; | |
1328 | sns_cmd->p.cmd.param[9] = vha->node_name[2]; | |
1329 | sns_cmd->p.cmd.param[10] = vha->node_name[1]; | |
1330 | sns_cmd->p.cmd.param[11] = vha->node_name[0]; | |
1da177e4 LT |
1331 | |
1332 | /* Execute SNS command. */ | |
7b867cf7 | 1333 | rval = qla2x00_send_sns(vha, ha->sns_cmd_dma, RNN_ID_SNS_CMD_SIZE / 2, |
1da177e4 LT |
1334 | sizeof(struct sns_cmd_pkt)); |
1335 | if (rval != QLA_SUCCESS) { | |
1336 | /*EMPTY*/ | |
7c3df132 SK |
1337 | ql_dbg(ql_dbg_disc, vha, 0x204a, |
1338 | "RNN_ID Send SNS failed (%d).\n", rval); | |
1da177e4 LT |
1339 | } else if (sns_cmd->p.rnn_data[8] != 0x80 || |
1340 | sns_cmd->p.rnn_data[9] != 0x02) { | |
7c3df132 SK |
1341 | ql_dbg(ql_dbg_disc + ql_dbg_buffer, vha, 0x207b, |
1342 | "RNN_ID failed, rejected request, rnn_rsp:\n"); | |
1343 | ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x207c, | |
1344 | sns_cmd->p.rnn_data, 16); | |
1da177e4 LT |
1345 | rval = QLA_FUNCTION_FAILED; |
1346 | } else { | |
7c3df132 SK |
1347 | ql_dbg(ql_dbg_disc, vha, 0x204c, |
1348 | "RNN_ID exiting normally.\n"); | |
1da177e4 LT |
1349 | } |
1350 | ||
1351 | return (rval); | |
1352 | } | |
cca5335c AV |
1353 | |
1354 | /** | |
b1c11812 | 1355 | * qla2x00_mgmt_svr_login() - Login to fabric Management Service. |
2db6228d | 1356 | * @vha: HA context |
cca5335c AV |
1357 | * |
1358 | * Returns 0 on success. | |
1359 | */ | |
726b8548 | 1360 | int |
7b867cf7 | 1361 | qla2x00_mgmt_svr_login(scsi_qla_host_t *vha) |
cca5335c | 1362 | { |
0b91d116 | 1363 | int ret, rval; |
cca5335c | 1364 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
7b867cf7 | 1365 | struct qla_hw_data *ha = vha->hw; |
bd432bb5 | 1366 | |
cca5335c | 1367 | ret = QLA_SUCCESS; |
7b867cf7 | 1368 | if (vha->flags.management_server_logged_in) |
cca5335c AV |
1369 | return ret; |
1370 | ||
0b91d116 | 1371 | rval = ha->isp_ops->fabric_login(vha, vha->mgmt_svr_loop_id, 0xff, 0xff, |
58570ac5 | 1372 | 0xfa, mb, BIT_1); |
0b91d116 CD |
1373 | if (rval != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) { |
1374 | if (rval == QLA_MEMORY_ALLOC_FAILED) | |
1375 | ql_dbg(ql_dbg_disc, vha, 0x2085, | |
1376 | "Failed management_server login: loopid=%x " | |
1377 | "rval=%d\n", vha->mgmt_svr_loop_id, rval); | |
1378 | else | |
1379 | ql_dbg(ql_dbg_disc, vha, 0x2024, | |
1380 | "Failed management_server login: loopid=%x " | |
1381 | "mb[0]=%x mb[1]=%x mb[2]=%x mb[6]=%x mb[7]=%x.\n", | |
1382 | vha->mgmt_svr_loop_id, mb[0], mb[1], mb[2], mb[6], | |
1383 | mb[7]); | |
cca5335c AV |
1384 | ret = QLA_FUNCTION_FAILED; |
1385 | } else | |
7b867cf7 | 1386 | vha->flags.management_server_logged_in = 1; |
cca5335c AV |
1387 | |
1388 | return ret; | |
1389 | } | |
1390 | ||
1391 | /** | |
1392 | * qla2x00_prep_ms_fdmi_iocb() - Prepare common MS IOCB fields for FDMI query. | |
2db6228d | 1393 | * @vha: HA context |
cca5335c AV |
1394 | * @req_size: request size in bytes |
1395 | * @rsp_size: response size in bytes | |
1396 | * | |
1397 | * Returns a pointer to the @ha's ms_iocb. | |
1398 | */ | |
1399 | void * | |
7b867cf7 | 1400 | qla2x00_prep_ms_fdmi_iocb(scsi_qla_host_t *vha, uint32_t req_size, |
cca5335c AV |
1401 | uint32_t rsp_size) |
1402 | { | |
1403 | ms_iocb_entry_t *ms_pkt; | |
7b867cf7 | 1404 | struct qla_hw_data *ha = vha->hw; |
bd432bb5 | 1405 | |
cca5335c AV |
1406 | ms_pkt = ha->ms_iocb; |
1407 | memset(ms_pkt, 0, sizeof(ms_iocb_entry_t)); | |
1408 | ||
1409 | ms_pkt->entry_type = MS_IOCB_TYPE; | |
1410 | ms_pkt->entry_count = 1; | |
7b867cf7 | 1411 | SET_TARGET_ID(ha, ms_pkt->loop_id, vha->mgmt_svr_loop_id); |
ad950360 | 1412 | ms_pkt->control_flags = cpu_to_le16(CF_READ | CF_HEAD_TAG); |
00a537b8 | 1413 | ms_pkt->timeout = cpu_to_le16(ha->r_a_tov / 10 * 2); |
ad950360 BVA |
1414 | ms_pkt->cmd_dsd_count = cpu_to_le16(1); |
1415 | ms_pkt->total_dsd_count = cpu_to_le16(2); | |
cca5335c AV |
1416 | ms_pkt->rsp_bytecount = cpu_to_le32(rsp_size); |
1417 | ms_pkt->req_bytecount = cpu_to_le32(req_size); | |
1418 | ||
15b7a68c BVA |
1419 | put_unaligned_le64(ha->ct_sns_dma, &ms_pkt->req_dsd.address); |
1420 | ms_pkt->req_dsd.length = ms_pkt->req_bytecount; | |
cca5335c | 1421 | |
15b7a68c BVA |
1422 | put_unaligned_le64(ha->ct_sns_dma, &ms_pkt->rsp_dsd.address); |
1423 | ms_pkt->rsp_dsd.length = ms_pkt->rsp_bytecount; | |
cca5335c AV |
1424 | |
1425 | return ms_pkt; | |
1426 | } | |
1427 | ||
1428 | /** | |
1429 | * qla24xx_prep_ms_fdmi_iocb() - Prepare common MS IOCB fields for FDMI query. | |
2db6228d | 1430 | * @vha: HA context |
cca5335c AV |
1431 | * @req_size: request size in bytes |
1432 | * @rsp_size: response size in bytes | |
1433 | * | |
1434 | * Returns a pointer to the @ha's ms_iocb. | |
1435 | */ | |
1436 | void * | |
7b867cf7 | 1437 | qla24xx_prep_ms_fdmi_iocb(scsi_qla_host_t *vha, uint32_t req_size, |
cca5335c AV |
1438 | uint32_t rsp_size) |
1439 | { | |
1440 | struct ct_entry_24xx *ct_pkt; | |
7b867cf7 | 1441 | struct qla_hw_data *ha = vha->hw; |
cca5335c AV |
1442 | |
1443 | ct_pkt = (struct ct_entry_24xx *)ha->ms_iocb; | |
1444 | memset(ct_pkt, 0, sizeof(struct ct_entry_24xx)); | |
1445 | ||
1446 | ct_pkt->entry_type = CT_IOCB_TYPE; | |
1447 | ct_pkt->entry_count = 1; | |
7b867cf7 | 1448 | ct_pkt->nport_handle = cpu_to_le16(vha->mgmt_svr_loop_id); |
00a537b8 | 1449 | ct_pkt->timeout = cpu_to_le16(ha->r_a_tov / 10 * 2); |
ad950360 BVA |
1450 | ct_pkt->cmd_dsd_count = cpu_to_le16(1); |
1451 | ct_pkt->rsp_dsd_count = cpu_to_le16(1); | |
cca5335c AV |
1452 | ct_pkt->rsp_byte_count = cpu_to_le32(rsp_size); |
1453 | ct_pkt->cmd_byte_count = cpu_to_le32(req_size); | |
1454 | ||
15b7a68c BVA |
1455 | put_unaligned_le64(ha->ct_sns_dma, &ct_pkt->dsd[0].address); |
1456 | ct_pkt->dsd[0].length = ct_pkt->cmd_byte_count; | |
cca5335c | 1457 | |
15b7a68c BVA |
1458 | put_unaligned_le64(ha->ct_sns_dma, &ct_pkt->dsd[1].address); |
1459 | ct_pkt->dsd[1].length = ct_pkt->rsp_byte_count; | |
7b867cf7 | 1460 | ct_pkt->vp_index = vha->vp_idx; |
cca5335c AV |
1461 | |
1462 | return ct_pkt; | |
1463 | } | |
1464 | ||
909c1d14 | 1465 | static void |
7b867cf7 | 1466 | qla2x00_update_ms_fdmi_iocb(scsi_qla_host_t *vha, uint32_t req_size) |
cca5335c | 1467 | { |
7b867cf7 | 1468 | struct qla_hw_data *ha = vha->hw; |
cca5335c AV |
1469 | ms_iocb_entry_t *ms_pkt = ha->ms_iocb; |
1470 | struct ct_entry_24xx *ct_pkt = (struct ct_entry_24xx *)ha->ms_iocb; | |
1471 | ||
e428924c | 1472 | if (IS_FWI2_CAPABLE(ha)) { |
cca5335c | 1473 | ct_pkt->cmd_byte_count = cpu_to_le32(req_size); |
15b7a68c | 1474 | ct_pkt->dsd[0].length = ct_pkt->cmd_byte_count; |
cca5335c AV |
1475 | } else { |
1476 | ms_pkt->req_bytecount = cpu_to_le32(req_size); | |
15b7a68c | 1477 | ms_pkt->req_dsd.length = ms_pkt->req_bytecount; |
cca5335c | 1478 | } |
cca5335c AV |
1479 | } |
1480 | ||
1481 | /** | |
f11c8b42 | 1482 | * qla2x00_prep_ct_fdmi_req() - Prepare common CT request fields for SNS query. |
2db6228d | 1483 | * @p: CT request buffer |
cca5335c AV |
1484 | * @cmd: GS command |
1485 | * @rsp_size: response size in bytes | |
1486 | * | |
1487 | * Returns a pointer to the intitialized @ct_req. | |
1488 | */ | |
1489 | static inline struct ct_sns_req * | |
6ec6f909 | 1490 | qla2x00_prep_ct_fdmi_req(struct ct_sns_pkt *p, uint16_t cmd, |
cca5335c AV |
1491 | uint16_t rsp_size) |
1492 | { | |
6ec6f909 | 1493 | memset(p, 0, sizeof(struct ct_sns_pkt)); |
cca5335c | 1494 | |
6ec6f909 BVA |
1495 | p->p.req.header.revision = 0x01; |
1496 | p->p.req.header.gs_type = 0xFA; | |
1497 | p->p.req.header.gs_subtype = 0x10; | |
1498 | p->p.req.command = cpu_to_be16(cmd); | |
1499 | p->p.req.max_rsp_size = cpu_to_be16((rsp_size - 16) / 4); | |
cca5335c | 1500 | |
6ec6f909 | 1501 | return &p->p.req; |
cca5335c AV |
1502 | } |
1503 | ||
d68930ba | 1504 | uint |
52bfb089 JC |
1505 | qla25xx_fdmi_port_speed_capability(struct qla_hw_data *ha) |
1506 | { | |
4709272f QT |
1507 | uint speeds = 0; |
1508 | ||
52bfb089 JC |
1509 | if (IS_CNA_CAPABLE(ha)) |
1510 | return FDMI_PORT_SPEED_10GB; | |
1511 | if (IS_QLA28XX(ha) || IS_QLA27XX(ha)) { | |
52bfb089 JC |
1512 | if (ha->max_supported_speed == 2) { |
1513 | if (ha->min_supported_speed <= 6) | |
1514 | speeds |= FDMI_PORT_SPEED_64GB; | |
1515 | } | |
1516 | if (ha->max_supported_speed == 2 || | |
1517 | ha->max_supported_speed == 1) { | |
1518 | if (ha->min_supported_speed <= 5) | |
1519 | speeds |= FDMI_PORT_SPEED_32GB; | |
1520 | } | |
1521 | if (ha->max_supported_speed == 2 || | |
1522 | ha->max_supported_speed == 1 || | |
1523 | ha->max_supported_speed == 0) { | |
1524 | if (ha->min_supported_speed <= 4) | |
1525 | speeds |= FDMI_PORT_SPEED_16GB; | |
1526 | } | |
1527 | if (ha->max_supported_speed == 1 || | |
1528 | ha->max_supported_speed == 0) { | |
1529 | if (ha->min_supported_speed <= 3) | |
1530 | speeds |= FDMI_PORT_SPEED_8GB; | |
1531 | } | |
1532 | if (ha->max_supported_speed == 0) { | |
1533 | if (ha->min_supported_speed <= 2) | |
1534 | speeds |= FDMI_PORT_SPEED_4GB; | |
1535 | } | |
1536 | return speeds; | |
1537 | } | |
4709272f QT |
1538 | if (IS_QLA2031(ha)) { |
1539 | if ((ha->pdev->subsystem_vendor == 0x103C) && | |
1540 | (ha->pdev->subsystem_device == 0x8002)) { | |
1541 | speeds = FDMI_PORT_SPEED_16GB; | |
1542 | } else { | |
1543 | speeds = FDMI_PORT_SPEED_16GB|FDMI_PORT_SPEED_8GB| | |
1544 | FDMI_PORT_SPEED_4GB; | |
1545 | } | |
1546 | return speeds; | |
1547 | } | |
d68930ba | 1548 | if (IS_QLA25XX(ha) || IS_QLAFX00(ha)) |
52bfb089 JC |
1549 | return FDMI_PORT_SPEED_8GB|FDMI_PORT_SPEED_4GB| |
1550 | FDMI_PORT_SPEED_2GB|FDMI_PORT_SPEED_1GB; | |
1551 | if (IS_QLA24XX_TYPE(ha)) | |
1552 | return FDMI_PORT_SPEED_4GB|FDMI_PORT_SPEED_2GB| | |
1553 | FDMI_PORT_SPEED_1GB; | |
1554 | if (IS_QLA23XX(ha)) | |
1555 | return FDMI_PORT_SPEED_2GB|FDMI_PORT_SPEED_1GB; | |
1556 | return FDMI_PORT_SPEED_1GB; | |
1557 | } | |
d68930ba QT |
1558 | |
1559 | uint | |
52bfb089 JC |
1560 | qla25xx_fdmi_port_speed_currently(struct qla_hw_data *ha) |
1561 | { | |
1562 | switch (ha->link_data_rate) { | |
1563 | case PORT_SPEED_1GB: | |
1564 | return FDMI_PORT_SPEED_1GB; | |
1565 | case PORT_SPEED_2GB: | |
1566 | return FDMI_PORT_SPEED_2GB; | |
1567 | case PORT_SPEED_4GB: | |
1568 | return FDMI_PORT_SPEED_4GB; | |
1569 | case PORT_SPEED_8GB: | |
1570 | return FDMI_PORT_SPEED_8GB; | |
1571 | case PORT_SPEED_10GB: | |
1572 | return FDMI_PORT_SPEED_10GB; | |
1573 | case PORT_SPEED_16GB: | |
1574 | return FDMI_PORT_SPEED_16GB; | |
1575 | case PORT_SPEED_32GB: | |
1576 | return FDMI_PORT_SPEED_32GB; | |
1577 | case PORT_SPEED_64GB: | |
1578 | return FDMI_PORT_SPEED_64GB; | |
1579 | default: | |
1580 | return FDMI_PORT_SPEED_UNKNOWN; | |
1581 | } | |
1582 | } | |
1583 | ||
cca5335c | 1584 | /** |
f11c8b42 | 1585 | * qla2x00_hba_attributes() - perform HBA attributes registration |
2db6228d | 1586 | * @vha: HA context |
52bfb089 JC |
1587 | * @entries: number of entries to use |
1588 | * @callopt: Option to issue extended or standard FDMI | |
1589 | * command parameter | |
cca5335c AV |
1590 | * |
1591 | * Returns 0 on success. | |
1592 | */ | |
52bfb089 JC |
1593 | static unsigned long |
1594 | qla2x00_hba_attributes(scsi_qla_host_t *vha, void *entries, | |
1595 | unsigned int callopt) | |
cca5335c | 1596 | { |
7b867cf7 | 1597 | struct qla_hw_data *ha = vha->hw; |
52bfb089 JC |
1598 | struct init_cb_24xx *icb24 = (void *)ha->init_cb; |
1599 | struct new_utsname *p_sysid = utsname(); | |
1600 | struct ct_fdmi_hba_attr *eiter; | |
1601 | uint16_t alen; | |
1602 | unsigned long size = 0; | |
cca5335c AV |
1603 | |
1604 | /* Nodename. */ | |
df57caba | 1605 | eiter = entries + size; |
ad950360 | 1606 | eiter->type = cpu_to_be16(FDMI_HBA_NODE_NAME); |
52bfb089 JC |
1607 | memcpy(eiter->a.node_name, vha->node_name, sizeof(eiter->a.node_name)); |
1608 | alen = sizeof(eiter->a.node_name); | |
1609 | alen += FDMI_ATTR_TYPELEN(eiter); | |
1610 | eiter->len = cpu_to_be16(alen); | |
1611 | size += alen; | |
1612 | ql_dbg(ql_dbg_disc, vha, 0x20a0, | |
1613 | "NODENAME = %016llx.\n", wwn_to_u64(eiter->a.node_name)); | |
cca5335c | 1614 | /* Manufacturer. */ |
df57caba | 1615 | eiter = entries + size; |
ad950360 | 1616 | eiter->type = cpu_to_be16(FDMI_HBA_MANUFACTURER); |
52bfb089 JC |
1617 | alen = scnprintf( |
1618 | eiter->a.manufacturer, sizeof(eiter->a.manufacturer), | |
1619 | "%s", "QLogic Corporation"); | |
1620 | alen += FDMI_ATTR_ALIGNMENT(alen); | |
1621 | alen += FDMI_ATTR_TYPELEN(eiter); | |
1622 | eiter->len = cpu_to_be16(alen); | |
1623 | size += alen; | |
1624 | ql_dbg(ql_dbg_disc, vha, 0x20a1, | |
1625 | "MANUFACTURER = %s.\n", eiter->a.manufacturer); | |
cca5335c | 1626 | /* Serial number. */ |
df57caba | 1627 | eiter = entries + size; |
ad950360 | 1628 | eiter->type = cpu_to_be16(FDMI_HBA_SERIAL_NUMBER); |
52bfb089 JC |
1629 | alen = 0; |
1630 | if (IS_FWI2_CAPABLE(ha)) { | |
1631 | alen = qla2xxx_get_vpd_field(vha, "SN", | |
1632 | eiter->a.serial_num, sizeof(eiter->a.serial_num)); | |
1633 | } | |
1634 | if (!alen) { | |
1635 | uint32_t sn = ((ha->serial0 & 0x1f) << 16) | | |
df57caba | 1636 | (ha->serial2 << 8) | ha->serial1; |
52bfb089 JC |
1637 | alen = scnprintf( |
1638 | eiter->a.serial_num, sizeof(eiter->a.serial_num), | |
1639 | "%c%05d", 'A' + sn / 100000, sn % 100000); | |
df57caba | 1640 | } |
52bfb089 JC |
1641 | alen += FDMI_ATTR_ALIGNMENT(alen); |
1642 | alen += FDMI_ATTR_TYPELEN(eiter); | |
1643 | eiter->len = cpu_to_be16(alen); | |
1644 | size += alen; | |
1645 | ql_dbg(ql_dbg_disc, vha, 0x20a2, | |
1646 | "SERIAL NUMBER = %s.\n", eiter->a.serial_num); | |
cca5335c | 1647 | /* Model name. */ |
df57caba | 1648 | eiter = entries + size; |
ad950360 | 1649 | eiter->type = cpu_to_be16(FDMI_HBA_MODEL); |
52bfb089 JC |
1650 | alen = scnprintf( |
1651 | eiter->a.model, sizeof(eiter->a.model), | |
1652 | "%s", ha->model_number); | |
1653 | alen += FDMI_ATTR_ALIGNMENT(alen); | |
1654 | alen += FDMI_ATTR_TYPELEN(eiter); | |
1655 | eiter->len = cpu_to_be16(alen); | |
1656 | size += alen; | |
1657 | ql_dbg(ql_dbg_disc, vha, 0x20a3, | |
1658 | "MODEL NAME = %s.\n", eiter->a.model); | |
cca5335c | 1659 | /* Model description. */ |
df57caba | 1660 | eiter = entries + size; |
ad950360 | 1661 | eiter->type = cpu_to_be16(FDMI_HBA_MODEL_DESCRIPTION); |
52bfb089 JC |
1662 | alen = scnprintf( |
1663 | eiter->a.model_desc, sizeof(eiter->a.model_desc), | |
1664 | "%s", ha->model_desc); | |
1665 | alen += FDMI_ATTR_ALIGNMENT(alen); | |
1666 | alen += FDMI_ATTR_TYPELEN(eiter); | |
1667 | eiter->len = cpu_to_be16(alen); | |
1668 | size += alen; | |
1669 | ql_dbg(ql_dbg_disc, vha, 0x20a4, | |
1670 | "MODEL DESCRIPTION = %s.\n", eiter->a.model_desc); | |
cca5335c | 1671 | /* Hardware version. */ |
df57caba | 1672 | eiter = entries + size; |
ad950360 | 1673 | eiter->type = cpu_to_be16(FDMI_HBA_HARDWARE_VERSION); |
52bfb089 JC |
1674 | alen = 0; |
1675 | if (IS_FWI2_CAPABLE(ha)) { | |
1676 | if (!alen) { | |
1677 | alen = qla2xxx_get_vpd_field(vha, "MN", | |
1678 | eiter->a.hw_version, sizeof(eiter->a.hw_version)); | |
1679 | } | |
1680 | if (!alen) { | |
1681 | alen = qla2xxx_get_vpd_field(vha, "EC", | |
1682 | eiter->a.hw_version, sizeof(eiter->a.hw_version)); | |
1683 | } | |
df57caba | 1684 | } |
52bfb089 JC |
1685 | if (!alen) { |
1686 | alen = scnprintf( | |
1687 | eiter->a.hw_version, sizeof(eiter->a.hw_version), | |
1688 | "HW:%s", ha->adapter_id); | |
1689 | } | |
1690 | alen += FDMI_ATTR_ALIGNMENT(alen); | |
1691 | alen += FDMI_ATTR_TYPELEN(eiter); | |
1692 | eiter->len = cpu_to_be16(alen); | |
1693 | size += alen; | |
1694 | ql_dbg(ql_dbg_disc, vha, 0x20a5, | |
1695 | "HARDWARE VERSION = %s.\n", eiter->a.hw_version); | |
cca5335c | 1696 | /* Driver version. */ |
df57caba | 1697 | eiter = entries + size; |
ad950360 | 1698 | eiter->type = cpu_to_be16(FDMI_HBA_DRIVER_VERSION); |
52bfb089 JC |
1699 | alen = scnprintf( |
1700 | eiter->a.driver_version, sizeof(eiter->a.driver_version), | |
1701 | "%s", qla2x00_version_str); | |
1702 | alen += FDMI_ATTR_ALIGNMENT(alen); | |
1703 | alen += FDMI_ATTR_TYPELEN(eiter); | |
1704 | eiter->len = cpu_to_be16(alen); | |
1705 | size += alen; | |
1706 | ql_dbg(ql_dbg_disc, vha, 0x20a6, | |
1707 | "DRIVER VERSION = %s.\n", eiter->a.driver_version); | |
cca5335c | 1708 | /* Option ROM version. */ |
df57caba | 1709 | eiter = entries + size; |
ad950360 | 1710 | eiter->type = cpu_to_be16(FDMI_HBA_OPTION_ROM_VERSION); |
52bfb089 JC |
1711 | alen = scnprintf( |
1712 | eiter->a.orom_version, sizeof(eiter->a.orom_version), | |
1713 | "%d.%02d", ha->bios_revision[1], ha->bios_revision[0]); | |
1714 | alen += FDMI_ATTR_ALIGNMENT(alen); | |
1715 | alen += FDMI_ATTR_TYPELEN(eiter); | |
1716 | eiter->len = cpu_to_be16(alen); | |
1717 | size += alen; | |
cca5335c | 1718 | |
52bfb089 JC |
1719 | ql_dbg(ql_dbg_disc, vha, 0x20a7, |
1720 | "OPTROM VERSION = %d.%02d.\n", | |
1721 | eiter->a.orom_version[1], eiter->a.orom_version[0]); | |
cca5335c | 1722 | /* Firmware version */ |
df57caba | 1723 | eiter = entries + size; |
ad950360 | 1724 | eiter->type = cpu_to_be16(FDMI_HBA_FIRMWARE_VERSION); |
df57caba HM |
1725 | ha->isp_ops->fw_version_str(vha, eiter->a.fw_version, |
1726 | sizeof(eiter->a.fw_version)); | |
52bfb089 JC |
1727 | alen += FDMI_ATTR_ALIGNMENT(alen); |
1728 | alen += FDMI_ATTR_TYPELEN(eiter); | |
1729 | eiter->len = cpu_to_be16(alen); | |
1730 | size += alen; | |
1731 | ql_dbg(ql_dbg_disc, vha, 0x20a8, | |
1732 | "FIRMWARE VERSION = %s.\n", eiter->a.fw_version); | |
52bfb089 JC |
1733 | /* OS Name and Version */ |
1734 | eiter = entries + size; | |
1735 | eiter->type = cpu_to_be16(FDMI_HBA_OS_NAME_AND_VERSION); | |
1736 | alen = 0; | |
1737 | if (p_sysid) { | |
1738 | alen = scnprintf( | |
1739 | eiter->a.os_version, sizeof(eiter->a.os_version), | |
1740 | "%s %s %s", | |
1741 | p_sysid->sysname, p_sysid->release, p_sysid->machine); | |
cca5335c | 1742 | } |
52bfb089 JC |
1743 | if (!alen) { |
1744 | alen = scnprintf( | |
1745 | eiter->a.os_version, sizeof(eiter->a.os_version), | |
1746 | "%s %s", | |
1747 | "Linux", fc_host_system_hostname(vha->host)); | |
1748 | } | |
1749 | alen += FDMI_ATTR_ALIGNMENT(alen); | |
1750 | alen += FDMI_ATTR_TYPELEN(eiter); | |
1751 | eiter->len = cpu_to_be16(alen); | |
1752 | size += alen; | |
1753 | ql_dbg(ql_dbg_disc, vha, 0x20a9, | |
1754 | "OS VERSION = %s.\n", eiter->a.os_version); | |
137316ba AE |
1755 | if (callopt == CALLOPT_FDMI1) |
1756 | goto done; | |
52bfb089 JC |
1757 | /* MAX CT Payload Length */ |
1758 | eiter = entries + size; | |
1759 | eiter->type = cpu_to_be16(FDMI_HBA_MAXIMUM_CT_PAYLOAD_LENGTH); | |
1760 | eiter->a.max_ct_len = cpu_to_be32(le16_to_cpu(IS_FWI2_CAPABLE(ha) ? | |
1761 | icb24->frame_payload_size : ha->init_cb->frame_payload_size)); | |
1762 | alen = sizeof(eiter->a.max_ct_len); | |
1763 | alen += FDMI_ATTR_TYPELEN(eiter); | |
1764 | eiter->len = cpu_to_be16(alen); | |
1765 | size += alen; | |
1766 | ql_dbg(ql_dbg_disc, vha, 0x20aa, | |
1767 | "CT PAYLOAD LENGTH = 0x%x.\n", be32_to_cpu(eiter->a.max_ct_len)); | |
1768 | /* Node Sybolic Name */ | |
1769 | eiter = entries + size; | |
1770 | eiter->type = cpu_to_be16(FDMI_HBA_NODE_SYMBOLIC_NAME); | |
1771 | alen = qla2x00_get_sym_node_name(vha, eiter->a.sym_name, | |
1772 | sizeof(eiter->a.sym_name)); | |
1773 | alen += FDMI_ATTR_ALIGNMENT(alen); | |
1774 | alen += FDMI_ATTR_TYPELEN(eiter); | |
1775 | eiter->len = cpu_to_be16(alen); | |
1776 | size += alen; | |
1777 | ql_dbg(ql_dbg_disc, vha, 0x20ab, | |
1778 | "SYMBOLIC NAME = %s.\n", eiter->a.sym_name); | |
1779 | /* Vendor Specific information */ | |
1780 | eiter = entries + size; | |
1781 | eiter->type = cpu_to_be16(FDMI_HBA_VENDOR_SPECIFIC_INFO); | |
1782 | eiter->a.vendor_specific_info = cpu_to_be32(PCI_VENDOR_ID_QLOGIC); | |
1783 | alen = sizeof(eiter->a.vendor_specific_info); | |
1784 | alen += FDMI_ATTR_TYPELEN(eiter); | |
1785 | eiter->len = cpu_to_be16(alen); | |
1786 | size += alen; | |
1787 | ql_dbg(ql_dbg_disc, vha, 0x20ac, | |
1788 | "VENDOR SPECIFIC INFO = 0x%x.\n", | |
1789 | be32_to_cpu(eiter->a.vendor_specific_info)); | |
1790 | /* Num Ports */ | |
1791 | eiter = entries + size; | |
1792 | eiter->type = cpu_to_be16(FDMI_HBA_NUM_PORTS); | |
1793 | eiter->a.num_ports = cpu_to_be32(1); | |
1794 | alen = sizeof(eiter->a.num_ports); | |
1795 | alen += FDMI_ATTR_TYPELEN(eiter); | |
1796 | eiter->len = cpu_to_be16(alen); | |
1797 | size += alen; | |
1798 | ql_dbg(ql_dbg_disc, vha, 0x20ad, | |
1799 | "PORT COUNT = %x.\n", be32_to_cpu(eiter->a.num_ports)); | |
1800 | /* Fabric Name */ | |
1801 | eiter = entries + size; | |
1802 | eiter->type = cpu_to_be16(FDMI_HBA_FABRIC_NAME); | |
1803 | memcpy(eiter->a.fabric_name, vha->fabric_node_name, | |
1804 | sizeof(eiter->a.fabric_name)); | |
1805 | alen = sizeof(eiter->a.fabric_name); | |
1806 | alen += FDMI_ATTR_TYPELEN(eiter); | |
1807 | eiter->len = cpu_to_be16(alen); | |
1808 | size += alen; | |
1809 | ql_dbg(ql_dbg_disc, vha, 0x20ae, | |
1810 | "FABRIC NAME = %016llx.\n", wwn_to_u64(eiter->a.fabric_name)); | |
1811 | /* BIOS Version */ | |
1812 | eiter = entries + size; | |
1813 | eiter->type = cpu_to_be16(FDMI_HBA_BOOT_BIOS_NAME); | |
1814 | alen = scnprintf( | |
1815 | eiter->a.bios_name, sizeof(eiter->a.bios_name), | |
1816 | "BIOS %d.%02d", ha->bios_revision[1], ha->bios_revision[0]); | |
1817 | alen += FDMI_ATTR_ALIGNMENT(alen); | |
1818 | alen += FDMI_ATTR_TYPELEN(eiter); | |
1819 | eiter->len = cpu_to_be16(alen); | |
1820 | size += alen; | |
1821 | ql_dbg(ql_dbg_disc, vha, 0x20af, | |
1822 | "BIOS NAME = %s\n", eiter->a.bios_name); | |
1823 | /* Vendor Identifier */ | |
1824 | eiter = entries + size; | |
1825 | eiter->type = cpu_to_be16(FDMI_HBA_VENDOR_IDENTIFIER); | |
1826 | alen = scnprintf( | |
1827 | eiter->a.vendor_identifier, sizeof(eiter->a.vendor_identifier), | |
1828 | "%s", "QLGC"); | |
1829 | alen += FDMI_ATTR_ALIGNMENT(alen); | |
1830 | alen += FDMI_ATTR_TYPELEN(eiter); | |
1831 | eiter->len = cpu_to_be16(alen); | |
1832 | size += alen; | |
1833 | ql_dbg(ql_dbg_disc, vha, 0x20b0, | |
1834 | "VENDOR IDENTIFIER = %s.\n", eiter->a.vendor_identifier); | |
1835 | done: | |
1836 | return size; | |
cca5335c AV |
1837 | } |
1838 | ||
df57caba | 1839 | /** |
f11c8b42 | 1840 | * qla2x00_port_attributes() - perform Port attributes registration |
2db6228d | 1841 | * @vha: HA context |
52bfb089 JC |
1842 | * @entries: number of entries to use |
1843 | * @callopt: Option to issue extended or standard FDMI | |
1844 | * command parameter | |
df57caba HM |
1845 | * |
1846 | * Returns 0 on success. | |
1847 | */ | |
52bfb089 JC |
1848 | static unsigned long |
1849 | qla2x00_port_attributes(scsi_qla_host_t *vha, void *entries, | |
1850 | unsigned int callopt) | |
df57caba | 1851 | { |
df57caba | 1852 | struct qla_hw_data *ha = vha->hw; |
52bfb089 JC |
1853 | struct init_cb_24xx *icb24 = (void *)ha->init_cb; |
1854 | struct new_utsname *p_sysid = utsname(); | |
1855 | char *hostname = p_sysid ? | |
1856 | p_sysid->nodename : fc_host_system_hostname(vha->host); | |
df57caba | 1857 | struct ct_fdmi_port_attr *eiter; |
52bfb089 JC |
1858 | uint16_t alen; |
1859 | unsigned long size = 0; | |
df57caba HM |
1860 | |
1861 | /* FC4 types. */ | |
1862 | eiter = entries + size; | |
1863 | eiter->type = cpu_to_be16(FDMI_PORT_FC4_TYPES); | |
52bfb089 JC |
1864 | eiter->a.fc4_types[0] = 0x00; |
1865 | eiter->a.fc4_types[1] = 0x00; | |
df57caba | 1866 | eiter->a.fc4_types[2] = 0x01; |
52bfb089 JC |
1867 | eiter->a.fc4_types[3] = 0x00; |
1868 | alen = sizeof(eiter->a.fc4_types); | |
1869 | alen += FDMI_ATTR_TYPELEN(eiter); | |
1870 | eiter->len = cpu_to_be16(alen); | |
1871 | size += alen; | |
1872 | ql_dbg(ql_dbg_disc, vha, 0x20c0, | |
1873 | "FC4 TYPES = %016llx.\n", *(uint64_t *)eiter->a.fc4_types); | |
1874 | if (vha->flags.nvme_enabled) { | |
1875 | eiter->a.fc4_types[6] = 1; /* NVMe type 28h */ | |
1876 | ql_dbg(ql_dbg_disc, vha, 0x211f, | |
1877 | "NVME FC4 Type = %02x 0x0 0x0 0x0 0x0 0x0.\n", | |
1878 | eiter->a.fc4_types[6]); | |
1879 | } | |
df57caba HM |
1880 | /* Supported speed. */ |
1881 | eiter = entries + size; | |
1882 | eiter->type = cpu_to_be16(FDMI_PORT_SUPPORT_SPEED); | |
52bfb089 JC |
1883 | eiter->a.sup_speed = cpu_to_be32( |
1884 | qla25xx_fdmi_port_speed_capability(ha)); | |
1885 | alen = sizeof(eiter->a.sup_speed); | |
1886 | alen += FDMI_ATTR_TYPELEN(eiter); | |
1887 | eiter->len = cpu_to_be16(alen); | |
1888 | size += alen; | |
1889 | ql_dbg(ql_dbg_disc, vha, 0x20c1, | |
1890 | "SUPPORTED SPEED = %x.\n", be32_to_cpu(eiter->a.sup_speed)); | |
df57caba HM |
1891 | /* Current speed. */ |
1892 | eiter = entries + size; | |
1893 | eiter->type = cpu_to_be16(FDMI_PORT_CURRENT_SPEED); | |
52bfb089 JC |
1894 | eiter->a.cur_speed = cpu_to_be32( |
1895 | qla25xx_fdmi_port_speed_currently(ha)); | |
1896 | alen = sizeof(eiter->a.cur_speed); | |
1897 | alen += FDMI_ATTR_TYPELEN(eiter); | |
1898 | eiter->len = cpu_to_be16(alen); | |
1899 | size += alen; | |
1900 | ql_dbg(ql_dbg_disc, vha, 0x20c2, | |
1901 | "CURRENT SPEED = %x.\n", be32_to_cpu(eiter->a.cur_speed)); | |
df57caba HM |
1902 | /* Max frame size. */ |
1903 | eiter = entries + size; | |
1904 | eiter->type = cpu_to_be16(FDMI_PORT_MAX_FRAME_SIZE); | |
52bfb089 JC |
1905 | eiter->a.max_frame_size = cpu_to_be32(le16_to_cpu(IS_FWI2_CAPABLE(ha) ? |
1906 | icb24->frame_payload_size : ha->init_cb->frame_payload_size)); | |
1907 | alen = sizeof(eiter->a.max_frame_size); | |
1908 | alen += FDMI_ATTR_TYPELEN(eiter); | |
1909 | eiter->len = cpu_to_be16(alen); | |
1910 | size += alen; | |
1911 | ql_dbg(ql_dbg_disc, vha, 0x20c3, | |
1912 | "MAX FRAME SIZE = %x.\n", be32_to_cpu(eiter->a.max_frame_size)); | |
df57caba HM |
1913 | /* OS device name. */ |
1914 | eiter = entries + size; | |
1915 | eiter->type = cpu_to_be16(FDMI_PORT_OS_DEVICE_NAME); | |
52bfb089 JC |
1916 | alen = scnprintf( |
1917 | eiter->a.os_dev_name, sizeof(eiter->a.os_dev_name), | |
1918 | "%s:host%lu", QLA2XXX_DRIVER_NAME, vha->host_no); | |
1919 | alen += FDMI_ATTR_ALIGNMENT(alen); | |
1920 | alen += FDMI_ATTR_TYPELEN(eiter); | |
1921 | eiter->len = cpu_to_be16(alen); | |
1922 | size += alen; | |
1923 | ql_dbg(ql_dbg_disc, vha, 0x20c4, | |
1924 | "OS DEVICE NAME = %s.\n", eiter->a.os_dev_name); | |
df57caba HM |
1925 | /* Hostname. */ |
1926 | eiter = entries + size; | |
1927 | eiter->type = cpu_to_be16(FDMI_PORT_HOST_NAME); | |
52bfb089 JC |
1928 | if (!*hostname || !strncmp(hostname, "(none)", 6)) |
1929 | hostname = "Linux-default"; | |
1930 | alen = scnprintf( | |
1931 | eiter->a.host_name, sizeof(eiter->a.host_name), | |
1932 | "%s", hostname); | |
1933 | alen += FDMI_ATTR_ALIGNMENT(alen); | |
1934 | alen += FDMI_ATTR_TYPELEN(eiter); | |
1935 | eiter->len = cpu_to_be16(alen); | |
1936 | size += alen; | |
1937 | ql_dbg(ql_dbg_disc, vha, 0x20c5, | |
1938 | "HOSTNAME = %s.\n", eiter->a.host_name); | |
df57caba | 1939 | |
52bfb089 JC |
1940 | if (callopt == CALLOPT_FDMI1) |
1941 | goto done; | |
df57caba | 1942 | |
52bfb089 JC |
1943 | /* Node Name */ |
1944 | eiter = entries + size; | |
1945 | eiter->type = cpu_to_be16(FDMI_PORT_NODE_NAME); | |
1946 | memcpy(eiter->a.node_name, vha->node_name, sizeof(eiter->a.node_name)); | |
1947 | alen = sizeof(eiter->a.node_name); | |
1948 | alen += FDMI_ATTR_TYPELEN(eiter); | |
1949 | eiter->len = cpu_to_be16(alen); | |
1950 | size += alen; | |
1951 | ql_dbg(ql_dbg_disc, vha, 0x20c6, | |
1952 | "NODENAME = %016llx.\n", wwn_to_u64(eiter->a.node_name)); | |
df57caba | 1953 | |
52bfb089 JC |
1954 | /* Port Name */ |
1955 | eiter = entries + size; | |
1956 | eiter->type = cpu_to_be16(FDMI_PORT_NAME); | |
1957 | memcpy(eiter->a.port_name, vha->port_name, sizeof(eiter->a.port_name)); | |
1958 | alen = sizeof(eiter->a.port_name); | |
1959 | alen += FDMI_ATTR_TYPELEN(eiter); | |
1960 | eiter->len = cpu_to_be16(alen); | |
1961 | size += alen; | |
1962 | ql_dbg(ql_dbg_disc, vha, 0x20c7, | |
1963 | "PORTNAME = %016llx.\n", wwn_to_u64(eiter->a.port_name)); | |
df57caba | 1964 | |
52bfb089 JC |
1965 | /* Port Symbolic Name */ |
1966 | eiter = entries + size; | |
1967 | eiter->type = cpu_to_be16(FDMI_PORT_SYM_NAME); | |
1968 | alen = qla2x00_get_sym_node_name(vha, eiter->a.port_sym_name, | |
1969 | sizeof(eiter->a.port_sym_name)); | |
1970 | alen += FDMI_ATTR_ALIGNMENT(alen); | |
1971 | alen += FDMI_ATTR_TYPELEN(eiter); | |
1972 | eiter->len = cpu_to_be16(alen); | |
1973 | size += alen; | |
1974 | ql_dbg(ql_dbg_disc, vha, 0x20c8, | |
1975 | "PORT SYMBOLIC NAME = %s\n", eiter->a.port_sym_name); | |
df57caba | 1976 | |
52bfb089 JC |
1977 | /* Port Type */ |
1978 | eiter = entries + size; | |
1979 | eiter->type = cpu_to_be16(FDMI_PORT_TYPE); | |
1980 | eiter->a.port_type = cpu_to_be32(NS_NX_PORT_TYPE); | |
1981 | alen = sizeof(eiter->a.port_type); | |
1982 | alen += FDMI_ATTR_TYPELEN(eiter); | |
1983 | eiter->len = cpu_to_be16(alen); | |
1984 | size += alen; | |
1985 | ql_dbg(ql_dbg_disc, vha, 0x20c9, | |
1986 | "PORT TYPE = %x.\n", be32_to_cpu(eiter->a.port_type)); | |
1987 | ||
1988 | /* Supported Class of Service */ | |
1989 | eiter = entries + size; | |
1990 | eiter->type = cpu_to_be16(FDMI_PORT_SUPP_COS); | |
1991 | eiter->a.port_supported_cos = cpu_to_be32(FC_CLASS_3); | |
1992 | alen = sizeof(eiter->a.port_supported_cos); | |
1993 | alen += FDMI_ATTR_TYPELEN(eiter); | |
1994 | eiter->len = cpu_to_be16(alen); | |
1995 | size += alen; | |
1996 | ql_dbg(ql_dbg_disc, vha, 0x20ca, | |
1997 | "SUPPORTED COS = %08x\n", be32_to_cpu(eiter->a.port_supported_cos)); | |
df57caba | 1998 | |
52bfb089 JC |
1999 | /* Port Fabric Name */ |
2000 | eiter = entries + size; | |
2001 | eiter->type = cpu_to_be16(FDMI_PORT_FABRIC_NAME); | |
2002 | memcpy(eiter->a.fabric_name, vha->fabric_node_name, | |
2003 | sizeof(eiter->a.fabric_name)); | |
2004 | alen = sizeof(eiter->a.fabric_name); | |
2005 | alen += FDMI_ATTR_TYPELEN(eiter); | |
2006 | eiter->len = cpu_to_be16(alen); | |
2007 | size += alen; | |
2008 | ql_dbg(ql_dbg_disc, vha, 0x20cb, | |
2009 | "FABRIC NAME = %016llx.\n", wwn_to_u64(eiter->a.fabric_name)); | |
2010 | ||
2011 | /* FC4_type */ | |
2012 | eiter = entries + size; | |
2013 | eiter->type = cpu_to_be16(FDMI_PORT_FC4_TYPE); | |
2014 | eiter->a.port_fc4_type[0] = 0x00; | |
2015 | eiter->a.port_fc4_type[1] = 0x00; | |
2016 | eiter->a.port_fc4_type[2] = 0x01; | |
2017 | eiter->a.port_fc4_type[3] = 0x00; | |
2018 | alen = sizeof(eiter->a.port_fc4_type); | |
2019 | alen += FDMI_ATTR_TYPELEN(eiter); | |
2020 | eiter->len = cpu_to_be16(alen); | |
2021 | size += alen; | |
2022 | ql_dbg(ql_dbg_disc, vha, 0x20cc, | |
2023 | "PORT ACTIVE FC4 TYPE = %016llx.\n", | |
2024 | *(uint64_t *)eiter->a.port_fc4_type); | |
2025 | ||
2026 | /* Port State */ | |
2027 | eiter = entries + size; | |
2028 | eiter->type = cpu_to_be16(FDMI_PORT_STATE); | |
2029 | eiter->a.port_state = cpu_to_be32(2); | |
2030 | alen = sizeof(eiter->a.port_state); | |
2031 | alen += FDMI_ATTR_TYPELEN(eiter); | |
2032 | eiter->len = cpu_to_be16(alen); | |
2033 | size += alen; | |
2034 | ql_dbg(ql_dbg_disc, vha, 0x20cd, | |
2035 | "PORT_STATE = %x.\n", be32_to_cpu(eiter->a.port_state)); | |
2036 | ||
2037 | /* Number of Ports */ | |
2038 | eiter = entries + size; | |
2039 | eiter->type = cpu_to_be16(FDMI_PORT_COUNT); | |
2040 | eiter->a.num_ports = cpu_to_be32(1); | |
2041 | alen = sizeof(eiter->a.num_ports); | |
2042 | alen += FDMI_ATTR_TYPELEN(eiter); | |
2043 | eiter->len = cpu_to_be16(alen); | |
2044 | size += alen; | |
2045 | ql_dbg(ql_dbg_disc, vha, 0x20ce, | |
2046 | "PORT COUNT = %x.\n", be32_to_cpu(eiter->a.num_ports)); | |
2047 | ||
2048 | /* Port Identifier */ | |
2049 | eiter = entries + size; | |
2050 | eiter->type = cpu_to_be16(FDMI_PORT_IDENTIFIER); | |
2051 | eiter->a.port_id = cpu_to_be32(vha->d_id.b24); | |
2052 | alen = sizeof(eiter->a.port_id); | |
2053 | alen += FDMI_ATTR_TYPELEN(eiter); | |
2054 | eiter->len = cpu_to_be16(alen); | |
2055 | size += alen; | |
2056 | ql_dbg(ql_dbg_disc, vha, 0x20cf, | |
2057 | "PORT ID = %x.\n", be32_to_cpu(eiter->a.port_id)); | |
2058 | ||
2059 | if (callopt == CALLOPT_FDMI2 || !ql2xsmartsan) | |
2060 | goto done; | |
2061 | ||
2062 | /* Smart SAN Service Category (Populate Smart SAN Initiator)*/ | |
2063 | eiter = entries + size; | |
2064 | eiter->type = cpu_to_be16(FDMI_SMARTSAN_SERVICE); | |
2065 | alen = scnprintf( | |
2066 | eiter->a.smartsan_service, sizeof(eiter->a.smartsan_service), | |
2067 | "%s", "Smart SAN Initiator"); | |
2068 | alen += FDMI_ATTR_ALIGNMENT(alen); | |
2069 | alen += FDMI_ATTR_TYPELEN(eiter); | |
2070 | eiter->len = cpu_to_be16(alen); | |
2071 | size += alen; | |
2072 | ql_dbg(ql_dbg_disc, vha, 0x20d0, | |
2073 | "SMARTSAN SERVICE CATEGORY = %s.\n", eiter->a.smartsan_service); | |
2074 | ||
2075 | /* Smart SAN GUID (NWWN+PWWN) */ | |
2076 | eiter = entries + size; | |
2077 | eiter->type = cpu_to_be16(FDMI_SMARTSAN_GUID); | |
2078 | memcpy(eiter->a.smartsan_guid, vha->node_name, WWN_SIZE); | |
2079 | memcpy(eiter->a.smartsan_guid + WWN_SIZE, vha->port_name, WWN_SIZE); | |
2080 | alen = sizeof(eiter->a.smartsan_guid); | |
2081 | alen += FDMI_ATTR_TYPELEN(eiter); | |
2082 | eiter->len = cpu_to_be16(alen); | |
2083 | size += alen; | |
2084 | ql_dbg(ql_dbg_disc, vha, 0x20d1, | |
2085 | "Smart SAN GUID = %016llx-%016llx\n", | |
2086 | wwn_to_u64(eiter->a.smartsan_guid), | |
2087 | wwn_to_u64(eiter->a.smartsan_guid + WWN_SIZE)); | |
2088 | ||
2089 | /* Smart SAN Version (populate "Smart SAN Version 1.0") */ | |
2090 | eiter = entries + size; | |
2091 | eiter->type = cpu_to_be16(FDMI_SMARTSAN_VERSION); | |
2092 | alen = scnprintf( | |
2093 | eiter->a.smartsan_version, sizeof(eiter->a.smartsan_version), | |
2094 | "%s", "Smart SAN Version 2.0"); | |
2095 | alen += FDMI_ATTR_ALIGNMENT(alen); | |
2096 | alen += FDMI_ATTR_TYPELEN(eiter); | |
2097 | eiter->len = cpu_to_be16(alen); | |
2098 | size += alen; | |
2099 | ql_dbg(ql_dbg_disc, vha, 0x20d2, | |
2100 | "SMARTSAN VERSION = %s\n", eiter->a.smartsan_version); | |
2101 | ||
2102 | /* Smart SAN Product Name (Specify Adapter Model No) */ | |
2103 | eiter = entries + size; | |
2104 | eiter->type = cpu_to_be16(FDMI_SMARTSAN_PROD_NAME); | |
2105 | alen = scnprintf(eiter->a.smartsan_prod_name, | |
2106 | sizeof(eiter->a.smartsan_prod_name), | |
2107 | "ISP%04x", ha->pdev->device); | |
2108 | alen += FDMI_ATTR_ALIGNMENT(alen); | |
2109 | alen += FDMI_ATTR_TYPELEN(eiter); | |
2110 | eiter->len = cpu_to_be16(alen); | |
2111 | size += alen; | |
2112 | ql_dbg(ql_dbg_disc, vha, 0x20d3, | |
2113 | "SMARTSAN PRODUCT NAME = %s\n", eiter->a.smartsan_prod_name); | |
2114 | ||
2115 | /* Smart SAN Port Info (specify: 1=Physical, 2=NPIV, 3=SRIOV) */ | |
2116 | eiter = entries + size; | |
2117 | eiter->type = cpu_to_be16(FDMI_SMARTSAN_PORT_INFO); | |
2118 | eiter->a.smartsan_port_info = cpu_to_be32(vha->vp_idx ? 2 : 1); | |
2119 | alen = sizeof(eiter->a.smartsan_port_info); | |
2120 | alen += FDMI_ATTR_TYPELEN(eiter); | |
2121 | eiter->len = cpu_to_be16(alen); | |
2122 | size += alen; | |
2123 | ql_dbg(ql_dbg_disc, vha, 0x20d4, | |
2124 | "SMARTSAN PORT INFO = %x\n", eiter->a.smartsan_port_info); | |
2125 | ||
2126 | /* Smart SAN Security Support */ | |
2127 | eiter = entries + size; | |
2128 | eiter->type = cpu_to_be16(FDMI_SMARTSAN_SECURITY_SUPPORT); | |
2129 | eiter->a.smartsan_security_support = cpu_to_be32(1); | |
2130 | alen = sizeof(eiter->a.smartsan_security_support); | |
2131 | alen += FDMI_ATTR_TYPELEN(eiter); | |
2132 | eiter->len = cpu_to_be16(alen); | |
2133 | size += alen; | |
2134 | ql_dbg(ql_dbg_disc, vha, 0x20d6, | |
2135 | "SMARTSAN SECURITY SUPPORT = %d\n", | |
2136 | be32_to_cpu(eiter->a.smartsan_security_support)); | |
2137 | ||
2138 | done: | |
2139 | return size; | |
df57caba HM |
2140 | } |
2141 | ||
2142 | /** | |
52bfb089 | 2143 | * qla2x00_fdmi_rhba() - perform RHBA FDMI registration |
2db6228d | 2144 | * @vha: HA context |
52bfb089 | 2145 | * @callopt: Option to issue FDMI registration |
df57caba HM |
2146 | * |
2147 | * Returns 0 on success. | |
2148 | */ | |
2149 | static int | |
52bfb089 | 2150 | qla2x00_fdmi_rhba(scsi_qla_host_t *vha, unsigned int callopt) |
df57caba | 2151 | { |
52bfb089 JC |
2152 | struct qla_hw_data *ha = vha->hw; |
2153 | unsigned long size = 0; | |
2154 | unsigned int rval, count; | |
df57caba HM |
2155 | ms_iocb_entry_t *ms_pkt; |
2156 | struct ct_sns_req *ct_req; | |
2157 | struct ct_sns_rsp *ct_rsp; | |
2158 | void *entries; | |
df57caba | 2159 | |
52bfb089 JC |
2160 | count = callopt != CALLOPT_FDMI1 ? |
2161 | FDMI2_HBA_ATTR_COUNT : FDMI1_HBA_ATTR_COUNT; | |
2162 | ||
2163 | size = RHBA_RSP_SIZE; | |
2164 | ||
2165 | ql_dbg(ql_dbg_disc, vha, 0x20e0, | |
2166 | "RHBA (callopt=%x count=%u size=%lu).\n", callopt, count, size); | |
2167 | ||
df57caba | 2168 | /* Request size adjusted after CT preparation */ |
52bfb089 | 2169 | ms_pkt = ha->isp_ops->prep_ms_fdmi_iocb(vha, 0, size); |
df57caba HM |
2170 | |
2171 | /* Prepare CT request */ | |
52bfb089 | 2172 | ct_req = qla2x00_prep_ct_fdmi_req(ha->ct_sns, RHBA_CMD, size); |
df57caba HM |
2173 | ct_rsp = &ha->ct_sns->p.rsp; |
2174 | ||
52bfb089 JC |
2175 | /* Prepare FDMI command entries */ |
2176 | memcpy(ct_req->req.rhba.hba_identifier, vha->port_name, | |
2177 | sizeof(ct_req->req.rhba.hba_identifier)); | |
2178 | size += sizeof(ct_req->req.rhba.hba_identifier); | |
df57caba | 2179 | |
52bfb089 JC |
2180 | ct_req->req.rhba.entry_count = cpu_to_be32(1); |
2181 | size += sizeof(ct_req->req.rhba.entry_count); | |
df57caba | 2182 | |
52bfb089 JC |
2183 | memcpy(ct_req->req.rhba.port_name, vha->port_name, |
2184 | sizeof(ct_req->req.rhba.port_name)); | |
2185 | size += sizeof(ct_req->req.rhba.port_name); | |
df57caba | 2186 | |
52bfb089 JC |
2187 | /* Attribute count */ |
2188 | ct_req->req.rhba.attrs.count = cpu_to_be32(count); | |
2189 | size += sizeof(ct_req->req.rhba.attrs.count); | |
df57caba | 2190 | |
52bfb089 JC |
2191 | /* Attribute block */ |
2192 | entries = &ct_req->req.rhba.attrs.entry; | |
df57caba | 2193 | |
52bfb089 | 2194 | size += qla2x00_hba_attributes(vha, entries, callopt); |
df57caba HM |
2195 | |
2196 | /* Update MS request size. */ | |
2197 | qla2x00_update_ms_fdmi_iocb(vha, size + 16); | |
2198 | ||
52bfb089 JC |
2199 | ql_dbg(ql_dbg_disc, vha, 0x20e1, |
2200 | "RHBA %016llx %016llx.\n", | |
2201 | wwn_to_u64(ct_req->req.rhba.hba_identifier), | |
2202 | wwn_to_u64(ct_req->req.rhba.port_name)); | |
2203 | ||
2204 | ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x20e2, | |
df57caba HM |
2205 | entries, size); |
2206 | ||
2207 | /* Execute MS IOCB */ | |
2208 | rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma, | |
52bfb089 JC |
2209 | sizeof(*ha->ms_iocb)); |
2210 | if (rval) { | |
2211 | ql_dbg(ql_dbg_disc, vha, 0x20e3, | |
2212 | "RHBA iocb failed (%d).\n", rval); | |
2213 | return rval; | |
2214 | } | |
df57caba | 2215 | |
52bfb089 JC |
2216 | rval = qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, "RHBA"); |
2217 | if (rval) { | |
df57caba HM |
2218 | if (ct_rsp->header.reason_code == CT_REASON_CANNOT_PERFORM && |
2219 | ct_rsp->header.explanation_code == | |
2220 | CT_EXPL_ALREADY_REGISTERED) { | |
52bfb089 JC |
2221 | ql_dbg(ql_dbg_disc, vha, 0x20e4, |
2222 | "RHBA already registered.\n"); | |
2223 | return QLA_ALREADY_REGISTERED; | |
df57caba | 2224 | } |
52bfb089 JC |
2225 | |
2226 | ql_dbg(ql_dbg_disc, vha, 0x20e5, | |
2227 | "RHBA failed, CT Reason %#x, CT Explanation %#x\n", | |
2228 | ct_rsp->header.reason_code, | |
2229 | ct_rsp->header.explanation_code); | |
2230 | return rval; | |
df57caba HM |
2231 | } |
2232 | ||
52bfb089 | 2233 | ql_dbg(ql_dbg_disc, vha, 0x20e6, "RHBA exiting normally.\n"); |
df57caba HM |
2234 | return rval; |
2235 | } | |
2236 | ||
52bfb089 | 2237 | |
cca5335c | 2238 | static int |
7b867cf7 | 2239 | qla2x00_fdmi_dhba(scsi_qla_host_t *vha) |
cca5335c AV |
2240 | { |
2241 | int rval; | |
7b867cf7 | 2242 | struct qla_hw_data *ha = vha->hw; |
cca5335c AV |
2243 | ms_iocb_entry_t *ms_pkt; |
2244 | struct ct_sns_req *ct_req; | |
2245 | struct ct_sns_rsp *ct_rsp; | |
cca5335c AV |
2246 | /* Issue RPA */ |
2247 | /* Prepare common MS IOCB */ | |
7b867cf7 | 2248 | ms_pkt = ha->isp_ops->prep_ms_fdmi_iocb(vha, DHBA_REQ_SIZE, |
cca5335c | 2249 | DHBA_RSP_SIZE); |
cca5335c | 2250 | /* Prepare CT request */ |
6ec6f909 | 2251 | ct_req = qla2x00_prep_ct_fdmi_req(ha->ct_sns, DHBA_CMD, DHBA_RSP_SIZE); |
cca5335c | 2252 | ct_rsp = &ha->ct_sns->p.rsp; |
cca5335c | 2253 | /* Prepare FDMI command arguments -- portname. */ |
7b867cf7 | 2254 | memcpy(ct_req->req.dhba.port_name, vha->port_name, WWN_SIZE); |
7c3df132 | 2255 | ql_dbg(ql_dbg_disc, vha, 0x2036, |
7b833558 | 2256 | "DHBA portname = %8phN.\n", ct_req->req.dhba.port_name); |
cca5335c | 2257 | /* Execute MS IOCB */ |
7b867cf7 | 2258 | rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma, |
cca5335c AV |
2259 | sizeof(ms_iocb_entry_t)); |
2260 | if (rval != QLA_SUCCESS) { | |
2261 | /*EMPTY*/ | |
7c3df132 SK |
2262 | ql_dbg(ql_dbg_disc, vha, 0x2037, |
2263 | "DHBA issue IOCB failed (%d).\n", rval); | |
7b867cf7 | 2264 | } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, "DHBA") != |
cca5335c AV |
2265 | QLA_SUCCESS) { |
2266 | rval = QLA_FUNCTION_FAILED; | |
2267 | } else { | |
7c3df132 SK |
2268 | ql_dbg(ql_dbg_disc, vha, 0x2038, |
2269 | "DHBA exiting normally.\n"); | |
cca5335c | 2270 | } |
cca5335c AV |
2271 | return rval; |
2272 | } | |
2273 | ||
2274 | /** | |
f11c8b42 | 2275 | * qla2x00_fdmi_rprt() - perform RPRT registration |
2db6228d | 2276 | * @vha: HA context |
52bfb089 JC |
2277 | * @callopt: Option to issue extended or standard FDMI |
2278 | * command parameter | |
cca5335c AV |
2279 | * |
2280 | * Returns 0 on success. | |
2281 | */ | |
2282 | static int | |
52bfb089 | 2283 | qla2x00_fdmi_rprt(scsi_qla_host_t *vha, int callopt) |
cca5335c | 2284 | { |
52bfb089 | 2285 | struct scsi_qla_host *base_vha = pci_get_drvdata(vha->hw->pdev); |
7b867cf7 | 2286 | struct qla_hw_data *ha = vha->hw; |
52bfb089 JC |
2287 | ulong size = 0; |
2288 | uint rval, count; | |
cca5335c AV |
2289 | ms_iocb_entry_t *ms_pkt; |
2290 | struct ct_sns_req *ct_req; | |
2291 | struct ct_sns_rsp *ct_rsp; | |
df57caba | 2292 | void *entries; |
52bfb089 JC |
2293 | count = callopt == CALLOPT_FDMI2_SMARTSAN && ql2xsmartsan ? |
2294 | FDMI2_SMARTSAN_PORT_ATTR_COUNT : | |
2295 | callopt != CALLOPT_FDMI1 ? | |
2296 | FDMI2_PORT_ATTR_COUNT : FDMI1_PORT_ATTR_COUNT; | |
2297 | ||
2298 | size = RPRT_RSP_SIZE; | |
2299 | ql_dbg(ql_dbg_disc, vha, 0x20e8, | |
2300 | "RPRT (callopt=%x count=%u size=%lu).\n", callopt, count, size); | |
2301 | /* Request size adjusted after CT preparation */ | |
2302 | ms_pkt = ha->isp_ops->prep_ms_fdmi_iocb(vha, 0, size); | |
cca5335c | 2303 | /* Prepare CT request */ |
52bfb089 | 2304 | ct_req = qla2x00_prep_ct_fdmi_req(ha->ct_sns, RPRT_CMD, size); |
cca5335c | 2305 | ct_rsp = &ha->ct_sns->p.rsp; |
52bfb089 JC |
2306 | /* Prepare FDMI command entries */ |
2307 | memcpy(ct_req->req.rprt.hba_identifier, base_vha->port_name, | |
2308 | sizeof(ct_req->req.rprt.hba_identifier)); | |
2309 | size += sizeof(ct_req->req.rprt.hba_identifier); | |
2310 | memcpy(ct_req->req.rprt.port_name, vha->port_name, | |
2311 | sizeof(ct_req->req.rprt.port_name)); | |
2312 | size += sizeof(ct_req->req.rprt.port_name); | |
2313 | /* Attribute count */ | |
2314 | ct_req->req.rprt.attrs.count = cpu_to_be32(count); | |
2315 | size += sizeof(ct_req->req.rprt.attrs.count); | |
2316 | /* Attribute block */ | |
2317 | entries = ct_req->req.rprt.attrs.entry; | |
2318 | size += qla2x00_port_attributes(vha, entries, callopt); | |
2319 | /* Update MS request size. */ | |
2320 | qla2x00_update_ms_fdmi_iocb(vha, size + 16); | |
2321 | ql_dbg(ql_dbg_disc, vha, 0x20e9, | |
2322 | "RPRT %016llx %016llx.\n", | |
2323 | wwn_to_u64(ct_req->req.rprt.port_name), | |
2324 | wwn_to_u64(ct_req->req.rprt.port_name)); | |
2325 | ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x20ea, | |
2326 | entries, size); | |
2327 | /* Execute MS IOCB */ | |
2328 | rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma, | |
2329 | sizeof(*ha->ms_iocb)); | |
2330 | if (rval) { | |
2331 | ql_dbg(ql_dbg_disc, vha, 0x20eb, | |
2332 | "RPRT iocb failed (%d).\n", rval); | |
2333 | return rval; | |
cca5335c | 2334 | } |
52bfb089 JC |
2335 | rval = qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, "RPRT"); |
2336 | if (rval) { | |
2337 | if (ct_rsp->header.reason_code == CT_REASON_CANNOT_PERFORM && | |
2338 | ct_rsp->header.explanation_code == | |
2339 | CT_EXPL_ALREADY_REGISTERED) { | |
2340 | ql_dbg(ql_dbg_disc, vha, 0x20ec, | |
2341 | "RPRT already registered.\n"); | |
2342 | return QLA_ALREADY_REGISTERED; | |
2343 | } | |
cca5335c | 2344 | |
52bfb089 JC |
2345 | ql_dbg(ql_dbg_disc, vha, 0x20ed, |
2346 | "RPRT failed, CT Reason code: %#x, CT Explanation %#x\n", | |
2347 | ct_rsp->header.reason_code, | |
2348 | ct_rsp->header.explanation_code); | |
2349 | return rval; | |
a740a3f0 | 2350 | } |
52bfb089 JC |
2351 | ql_dbg(ql_dbg_disc, vha, 0x20ee, "RPRT exiting normally.\n"); |
2352 | return rval; | |
2353 | } | |
df57caba | 2354 | |
52bfb089 JC |
2355 | /** |
2356 | * qla2x00_fdmi_rpa() - perform RPA registration | |
2357 | * @vha: HA context | |
2358 | * @callopt: Option to issue FDMI registration | |
2359 | * | |
2360 | * Returns 0 on success. | |
2361 | */ | |
2362 | static int | |
2363 | qla2x00_fdmi_rpa(scsi_qla_host_t *vha, uint callopt) | |
2364 | { | |
2365 | struct qla_hw_data *ha = vha->hw; | |
2366 | ulong size = 0; | |
2367 | uint rval, count; | |
2368 | ms_iocb_entry_t *ms_pkt; | |
2369 | struct ct_sns_req *ct_req; | |
2370 | struct ct_sns_rsp *ct_rsp; | |
2371 | void *entries; | |
df57caba | 2372 | |
52bfb089 JC |
2373 | count = |
2374 | callopt == CALLOPT_FDMI2_SMARTSAN && ql2xsmartsan ? | |
2375 | FDMI2_SMARTSAN_PORT_ATTR_COUNT : | |
2376 | callopt != CALLOPT_FDMI1 ? | |
2377 | FDMI2_PORT_ATTR_COUNT : FDMI1_PORT_ATTR_COUNT; | |
df57caba | 2378 | |
52bfb089 JC |
2379 | size = |
2380 | callopt != CALLOPT_FDMI1 ? | |
2381 | SMARTSAN_RPA_RSP_SIZE : RPA_RSP_SIZE; | |
df57caba | 2382 | |
52bfb089 JC |
2383 | ql_dbg(ql_dbg_disc, vha, 0x20f0, |
2384 | "RPA (callopt=%x count=%u size=%lu).\n", callopt, count, size); | |
7d236480 | 2385 | |
52bfb089 JC |
2386 | /* Request size adjusted after CT preparation */ |
2387 | ms_pkt = ha->isp_ops->prep_ms_fdmi_iocb(vha, 0, size); | |
df57caba | 2388 | |
52bfb089 JC |
2389 | /* Prepare CT request */ |
2390 | ct_req = qla2x00_prep_ct_fdmi_req(ha->ct_sns, RPA_CMD, size); | |
2391 | ct_rsp = &ha->ct_sns->p.rsp; | |
df57caba | 2392 | |
52bfb089 JC |
2393 | /* Prepare FDMI command entries. */ |
2394 | memcpy(ct_req->req.rpa.port_name, vha->port_name, | |
2395 | sizeof(ct_req->req.rpa.port_name)); | |
2396 | size += sizeof(ct_req->req.rpa.port_name); | |
df57caba | 2397 | |
52bfb089 JC |
2398 | /* Attribute count */ |
2399 | ct_req->req.rpa.attrs.count = cpu_to_be32(count); | |
2400 | size += sizeof(ct_req->req.rpa.attrs.count); | |
df57caba | 2401 | |
52bfb089 JC |
2402 | /* Attribute block */ |
2403 | entries = ct_req->req.rpa.attrs.entry; | |
df57caba | 2404 | |
52bfb089 | 2405 | size += qla2x00_port_attributes(vha, entries, callopt); |
a740a3f0 | 2406 | |
cca5335c | 2407 | /* Update MS request size. */ |
7b867cf7 | 2408 | qla2x00_update_ms_fdmi_iocb(vha, size + 16); |
cca5335c | 2409 | |
52bfb089 JC |
2410 | ql_dbg(ql_dbg_disc, vha, 0x20f1, |
2411 | "RPA %016llx.\n", wwn_to_u64(ct_req->req.rpa.port_name)); | |
2412 | ||
2413 | ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x20f2, | |
7c3df132 | 2414 | entries, size); |
cca5335c AV |
2415 | |
2416 | /* Execute MS IOCB */ | |
7b867cf7 | 2417 | rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma, |
52bfb089 JC |
2418 | sizeof(*ha->ms_iocb)); |
2419 | if (rval) { | |
2420 | ql_dbg(ql_dbg_disc, vha, 0x20f3, | |
2421 | "RPA iocb failed (%d).\n", rval); | |
2422 | return rval; | |
2423 | } | |
2424 | ||
2425 | rval = qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, "RPA"); | |
2426 | if (rval) { | |
df57caba HM |
2427 | if (ct_rsp->header.reason_code == CT_REASON_CANNOT_PERFORM && |
2428 | ct_rsp->header.explanation_code == | |
2429 | CT_EXPL_ALREADY_REGISTERED) { | |
52bfb089 JC |
2430 | ql_dbg(ql_dbg_disc, vha, 0x20f4, |
2431 | "RPA already registered.\n"); | |
2432 | return QLA_ALREADY_REGISTERED; | |
df57caba | 2433 | } |
52bfb089 JC |
2434 | |
2435 | ql_dbg(ql_dbg_disc, vha, 0x20f5, | |
2436 | "RPA failed, CT Reason code: %#x, CT Explanation %#x\n", | |
2437 | ct_rsp->header.reason_code, | |
2438 | ct_rsp->header.explanation_code); | |
2439 | return rval; | |
cca5335c AV |
2440 | } |
2441 | ||
52bfb089 | 2442 | ql_dbg(ql_dbg_disc, vha, 0x20f6, "RPA exiting normally.\n"); |
cca5335c AV |
2443 | return rval; |
2444 | } | |
2445 | ||
2446 | /** | |
2447 | * qla2x00_fdmi_register() - | |
2db6228d | 2448 | * @vha: HA context |
cca5335c AV |
2449 | * |
2450 | * Returns 0 on success. | |
2451 | */ | |
2452 | int | |
7b867cf7 | 2453 | qla2x00_fdmi_register(scsi_qla_host_t *vha) |
cca5335c | 2454 | { |
52bfb089 | 2455 | int rval = QLA_SUCCESS; |
df57caba | 2456 | struct qla_hw_data *ha = vha->hw; |
80de7efa | 2457 | |
8ae6d9c7 GM |
2458 | if (IS_QLA2100(ha) || IS_QLA2200(ha) || |
2459 | IS_QLAFX00(ha)) | |
52bfb089 | 2460 | return rval; |
cca5335c | 2461 | |
7b867cf7 | 2462 | rval = qla2x00_mgmt_svr_login(vha); |
cca5335c AV |
2463 | if (rval) |
2464 | return rval; | |
2465 | ||
52bfb089 JC |
2466 | /* For npiv/vport send rprt only */ |
2467 | if (vha->vp_idx) { | |
2468 | if (ql2xsmartsan) | |
2469 | rval = qla2x00_fdmi_rprt(vha, CALLOPT_FDMI2_SMARTSAN); | |
2470 | if (rval || !ql2xsmartsan) | |
2471 | rval = qla2x00_fdmi_rprt(vha, CALLOPT_FDMI2); | |
2472 | if (rval) | |
2473 | rval = qla2x00_fdmi_rprt(vha, CALLOPT_FDMI1); | |
2474 | ||
2475 | return rval; | |
2476 | } | |
2477 | ||
2478 | /* Try fdmi2 first, if fails then try fdmi1 */ | |
2479 | rval = qla2x00_fdmi_rhba(vha, CALLOPT_FDMI2); | |
df57caba HM |
2480 | if (rval) { |
2481 | if (rval != QLA_ALREADY_REGISTERED) | |
2482 | goto try_fdmi; | |
2483 | ||
2484 | rval = qla2x00_fdmi_dhba(vha); | |
2485 | if (rval) | |
2486 | goto try_fdmi; | |
2487 | ||
52bfb089 | 2488 | rval = qla2x00_fdmi_rhba(vha, CALLOPT_FDMI2); |
df57caba HM |
2489 | if (rval) |
2490 | goto try_fdmi; | |
2491 | } | |
52bfb089 JC |
2492 | |
2493 | if (ql2xsmartsan) | |
2494 | rval = qla2x00_fdmi_rpa(vha, CALLOPT_FDMI2_SMARTSAN); | |
2495 | if (rval || !ql2xsmartsan) | |
2496 | rval = qla2x00_fdmi_rpa(vha, CALLOPT_FDMI2); | |
df57caba HM |
2497 | if (rval) |
2498 | goto try_fdmi; | |
2499 | ||
52bfb089 | 2500 | return rval; |
df57caba HM |
2501 | |
2502 | try_fdmi: | |
52bfb089 | 2503 | rval = qla2x00_fdmi_rhba(vha, CALLOPT_FDMI1); |
cca5335c AV |
2504 | if (rval) { |
2505 | if (rval != QLA_ALREADY_REGISTERED) | |
2506 | return rval; | |
2507 | ||
7b867cf7 | 2508 | rval = qla2x00_fdmi_dhba(vha); |
cca5335c AV |
2509 | if (rval) |
2510 | return rval; | |
2511 | ||
52bfb089 | 2512 | rval = qla2x00_fdmi_rhba(vha, CALLOPT_FDMI1); |
cca5335c AV |
2513 | if (rval) |
2514 | return rval; | |
2515 | } | |
52bfb089 JC |
2516 | |
2517 | rval = qla2x00_fdmi_rpa(vha, CALLOPT_FDMI1); | |
2518 | ||
cca5335c AV |
2519 | return rval; |
2520 | } | |
d8b45213 AV |
2521 | |
2522 | /** | |
2523 | * qla2x00_gfpn_id() - SNS Get Fabric Port Name (GFPN_ID) query. | |
2db6228d | 2524 | * @vha: HA context |
d8b45213 AV |
2525 | * @list: switch info entries to populate |
2526 | * | |
2527 | * Returns 0 on success. | |
2528 | */ | |
2529 | int | |
7b867cf7 | 2530 | qla2x00_gfpn_id(scsi_qla_host_t *vha, sw_info_t *list) |
d8b45213 | 2531 | { |
642ef983 | 2532 | int rval = QLA_SUCCESS; |
d8b45213 | 2533 | uint16_t i; |
7b867cf7 | 2534 | struct qla_hw_data *ha = vha->hw; |
d8b45213 AV |
2535 | ms_iocb_entry_t *ms_pkt; |
2536 | struct ct_sns_req *ct_req; | |
2537 | struct ct_sns_rsp *ct_rsp; | |
726b8548 | 2538 | struct ct_arg arg; |
d8b45213 | 2539 | |
c76f2c01 | 2540 | if (!IS_IIDMA_CAPABLE(ha)) |
d8b45213 AV |
2541 | return QLA_FUNCTION_FAILED; |
2542 | ||
726b8548 QT |
2543 | arg.iocb = ha->ms_iocb; |
2544 | arg.req_dma = ha->ct_sns_dma; | |
2545 | arg.rsp_dma = ha->ct_sns_dma; | |
2546 | arg.req_size = GFPN_ID_REQ_SIZE; | |
2547 | arg.rsp_size = GFPN_ID_RSP_SIZE; | |
2548 | arg.nport_handle = NPH_SNS; | |
2549 | ||
642ef983 | 2550 | for (i = 0; i < ha->max_fibre_devices; i++) { |
d8b45213 | 2551 | /* Issue GFPN_ID */ |
d8b45213 | 2552 | /* Prepare common MS IOCB */ |
726b8548 | 2553 | ms_pkt = ha->isp_ops->prep_ms_iocb(vha, &arg); |
d8b45213 AV |
2554 | |
2555 | /* Prepare CT request */ | |
6ec6f909 | 2556 | ct_req = qla2x00_prep_ct_req(ha->ct_sns, GFPN_ID_CMD, |
d8b45213 AV |
2557 | GFPN_ID_RSP_SIZE); |
2558 | ct_rsp = &ha->ct_sns->p.rsp; | |
2559 | ||
2560 | /* Prepare CT arguments -- port_id */ | |
df95f39a | 2561 | ct_req->req.port_id.port_id = port_id_to_be_id(list[i].d_id); |
d8b45213 AV |
2562 | |
2563 | /* Execute MS IOCB */ | |
7b867cf7 | 2564 | rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma, |
d8b45213 AV |
2565 | sizeof(ms_iocb_entry_t)); |
2566 | if (rval != QLA_SUCCESS) { | |
2567 | /*EMPTY*/ | |
7c3df132 SK |
2568 | ql_dbg(ql_dbg_disc, vha, 0x2023, |
2569 | "GFPN_ID issue IOCB failed (%d).\n", rval); | |
dafdf892 | 2570 | break; |
7b867cf7 | 2571 | } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, |
d8b45213 AV |
2572 | "GFPN_ID") != QLA_SUCCESS) { |
2573 | rval = QLA_FUNCTION_FAILED; | |
dafdf892 | 2574 | break; |
d8b45213 AV |
2575 | } else { |
2576 | /* Save fabric portname */ | |
2577 | memcpy(list[i].fabric_port_name, | |
2578 | ct_rsp->rsp.gfpn_id.port_name, WWN_SIZE); | |
2579 | } | |
2580 | ||
2581 | /* Last device exit. */ | |
2582 | if (list[i].d_id.b.rsvd_1 != 0) | |
2583 | break; | |
2584 | } | |
2585 | ||
2586 | return (rval); | |
2587 | } | |
2588 | ||
d8b45213 AV |
2589 | |
2590 | static inline struct ct_sns_req * | |
6ec6f909 | 2591 | qla24xx_prep_ct_fm_req(struct ct_sns_pkt *p, uint16_t cmd, |
d8b45213 AV |
2592 | uint16_t rsp_size) |
2593 | { | |
6ec6f909 | 2594 | memset(p, 0, sizeof(struct ct_sns_pkt)); |
d8b45213 | 2595 | |
6ec6f909 BVA |
2596 | p->p.req.header.revision = 0x01; |
2597 | p->p.req.header.gs_type = 0xFA; | |
2598 | p->p.req.header.gs_subtype = 0x01; | |
2599 | p->p.req.command = cpu_to_be16(cmd); | |
2600 | p->p.req.max_rsp_size = cpu_to_be16((rsp_size - 16) / 4); | |
d8b45213 | 2601 | |
6ec6f909 | 2602 | return &p->p.req; |
d8b45213 AV |
2603 | } |
2604 | ||
2a3192a3 JC |
2605 | static uint16_t |
2606 | qla2x00_port_speed_capability(uint16_t speed) | |
2607 | { | |
2608 | switch (speed) { | |
2609 | case BIT_15: | |
2610 | return PORT_SPEED_1GB; | |
2611 | case BIT_14: | |
2612 | return PORT_SPEED_2GB; | |
2613 | case BIT_13: | |
2614 | return PORT_SPEED_4GB; | |
2615 | case BIT_12: | |
2616 | return PORT_SPEED_10GB; | |
2617 | case BIT_11: | |
2618 | return PORT_SPEED_8GB; | |
2619 | case BIT_10: | |
2620 | return PORT_SPEED_16GB; | |
2621 | case BIT_8: | |
2622 | return PORT_SPEED_32GB; | |
2623 | case BIT_7: | |
2624 | return PORT_SPEED_64GB; | |
2625 | default: | |
2626 | return PORT_SPEED_UNKNOWN; | |
2627 | } | |
2628 | } | |
2629 | ||
d8b45213 AV |
2630 | /** |
2631 | * qla2x00_gpsc() - FCS Get Port Speed Capabilities (GPSC) query. | |
2db6228d | 2632 | * @vha: HA context |
d8b45213 AV |
2633 | * @list: switch info entries to populate |
2634 | * | |
2635 | * Returns 0 on success. | |
2636 | */ | |
2637 | int | |
7b867cf7 | 2638 | qla2x00_gpsc(scsi_qla_host_t *vha, sw_info_t *list) |
d8b45213 AV |
2639 | { |
2640 | int rval; | |
2641 | uint16_t i; | |
7b867cf7 | 2642 | struct qla_hw_data *ha = vha->hw; |
726b8548 | 2643 | ms_iocb_entry_t *ms_pkt; |
d8b45213 AV |
2644 | struct ct_sns_req *ct_req; |
2645 | struct ct_sns_rsp *ct_rsp; | |
726b8548 | 2646 | struct ct_arg arg; |
d8b45213 | 2647 | |
c76f2c01 | 2648 | if (!IS_IIDMA_CAPABLE(ha)) |
d8b45213 | 2649 | return QLA_FUNCTION_FAILED; |
4346b149 AV |
2650 | if (!ha->flags.gpsc_supported) |
2651 | return QLA_FUNCTION_FAILED; | |
d8b45213 | 2652 | |
7b867cf7 | 2653 | rval = qla2x00_mgmt_svr_login(vha); |
d8b45213 AV |
2654 | if (rval) |
2655 | return rval; | |
2656 | ||
726b8548 QT |
2657 | arg.iocb = ha->ms_iocb; |
2658 | arg.req_dma = ha->ct_sns_dma; | |
2659 | arg.rsp_dma = ha->ct_sns_dma; | |
2660 | arg.req_size = GPSC_REQ_SIZE; | |
2661 | arg.rsp_size = GPSC_RSP_SIZE; | |
2662 | arg.nport_handle = vha->mgmt_svr_loop_id; | |
2663 | ||
642ef983 | 2664 | for (i = 0; i < ha->max_fibre_devices; i++) { |
d8b45213 | 2665 | /* Issue GFPN_ID */ |
d8b45213 | 2666 | /* Prepare common MS IOCB */ |
726b8548 | 2667 | ms_pkt = qla24xx_prep_ms_iocb(vha, &arg); |
d8b45213 AV |
2668 | |
2669 | /* Prepare CT request */ | |
6ec6f909 BVA |
2670 | ct_req = qla24xx_prep_ct_fm_req(ha->ct_sns, GPSC_CMD, |
2671 | GPSC_RSP_SIZE); | |
d8b45213 AV |
2672 | ct_rsp = &ha->ct_sns->p.rsp; |
2673 | ||
2674 | /* Prepare CT arguments -- port_name */ | |
2675 | memcpy(ct_req->req.gpsc.port_name, list[i].fabric_port_name, | |
2676 | WWN_SIZE); | |
2677 | ||
2678 | /* Execute MS IOCB */ | |
7b867cf7 | 2679 | rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma, |
d8b45213 AV |
2680 | sizeof(ms_iocb_entry_t)); |
2681 | if (rval != QLA_SUCCESS) { | |
2682 | /*EMPTY*/ | |
7c3df132 SK |
2683 | ql_dbg(ql_dbg_disc, vha, 0x2059, |
2684 | "GPSC issue IOCB failed (%d).\n", rval); | |
7b867cf7 | 2685 | } else if ((rval = qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, |
4346b149 AV |
2686 | "GPSC")) != QLA_SUCCESS) { |
2687 | /* FM command unsupported? */ | |
2688 | if (rval == QLA_INVALID_COMMAND && | |
3fe7cfb9 AV |
2689 | (ct_rsp->header.reason_code == |
2690 | CT_REASON_INVALID_COMMAND_CODE || | |
2691 | ct_rsp->header.reason_code == | |
2692 | CT_REASON_COMMAND_UNSUPPORTED)) { | |
7c3df132 SK |
2693 | ql_dbg(ql_dbg_disc, vha, 0x205a, |
2694 | "GPSC command unsupported, disabling " | |
2695 | "query.\n"); | |
4346b149 AV |
2696 | ha->flags.gpsc_supported = 0; |
2697 | rval = QLA_FUNCTION_FAILED; | |
2698 | break; | |
2699 | } | |
d8b45213 AV |
2700 | rval = QLA_FUNCTION_FAILED; |
2701 | } else { | |
2a3192a3 JC |
2702 | list->fp_speed = qla2x00_port_speed_capability( |
2703 | be16_to_cpu(ct_rsp->rsp.gpsc.speed)); | |
7c3df132 SK |
2704 | ql_dbg(ql_dbg_disc, vha, 0x205b, |
2705 | "GPSC ext entry - fpn " | |
7b833558 OK |
2706 | "%8phN speeds=%04x speed=%04x.\n", |
2707 | list[i].fabric_port_name, | |
a3cbdfad | 2708 | be16_to_cpu(ct_rsp->rsp.gpsc.speeds), |
7c3df132 | 2709 | be16_to_cpu(ct_rsp->rsp.gpsc.speed)); |
d8b45213 AV |
2710 | } |
2711 | ||
2712 | /* Last device exit. */ | |
2713 | if (list[i].d_id.b.rsvd_1 != 0) | |
2714 | break; | |
2715 | } | |
2716 | ||
2717 | return (rval); | |
2718 | } | |
e8c72ba5 CD |
2719 | |
2720 | /** | |
2721 | * qla2x00_gff_id() - SNS Get FC-4 Features (GFF_ID) query. | |
2722 | * | |
2db6228d | 2723 | * @vha: HA context |
e8c72ba5 CD |
2724 | * @list: switch info entries to populate |
2725 | * | |
2726 | */ | |
2727 | void | |
2728 | qla2x00_gff_id(scsi_qla_host_t *vha, sw_info_t *list) | |
2729 | { | |
2730 | int rval; | |
2731 | uint16_t i; | |
2732 | ||
2733 | ms_iocb_entry_t *ms_pkt; | |
2734 | struct ct_sns_req *ct_req; | |
2735 | struct ct_sns_rsp *ct_rsp; | |
2736 | struct qla_hw_data *ha = vha->hw; | |
84ed362a | 2737 | uint8_t fcp_scsi_features = 0, nvme_features = 0; |
726b8548 | 2738 | struct ct_arg arg; |
e8c72ba5 | 2739 | |
642ef983 | 2740 | for (i = 0; i < ha->max_fibre_devices; i++) { |
e8c72ba5 CD |
2741 | /* Set default FC4 Type as UNKNOWN so the default is to |
2742 | * Process this port */ | |
8e0e063a | 2743 | list[i].fc4_type = 0; |
e8c72ba5 CD |
2744 | |
2745 | /* Do not attempt GFF_ID if we are not FWI_2 capable */ | |
2746 | if (!IS_FWI2_CAPABLE(ha)) | |
2747 | continue; | |
2748 | ||
726b8548 QT |
2749 | arg.iocb = ha->ms_iocb; |
2750 | arg.req_dma = ha->ct_sns_dma; | |
2751 | arg.rsp_dma = ha->ct_sns_dma; | |
2752 | arg.req_size = GFF_ID_REQ_SIZE; | |
2753 | arg.rsp_size = GFF_ID_RSP_SIZE; | |
2754 | arg.nport_handle = NPH_SNS; | |
2755 | ||
e8c72ba5 | 2756 | /* Prepare common MS IOCB */ |
726b8548 | 2757 | ms_pkt = ha->isp_ops->prep_ms_iocb(vha, &arg); |
e8c72ba5 CD |
2758 | |
2759 | /* Prepare CT request */ | |
6ec6f909 | 2760 | ct_req = qla2x00_prep_ct_req(ha->ct_sns, GFF_ID_CMD, |
e8c72ba5 CD |
2761 | GFF_ID_RSP_SIZE); |
2762 | ct_rsp = &ha->ct_sns->p.rsp; | |
2763 | ||
2764 | /* Prepare CT arguments -- port_id */ | |
df95f39a | 2765 | ct_req->req.port_id.port_id = port_id_to_be_id(list[i].d_id); |
e8c72ba5 CD |
2766 | |
2767 | /* Execute MS IOCB */ | |
2768 | rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma, | |
2769 | sizeof(ms_iocb_entry_t)); | |
2770 | ||
2771 | if (rval != QLA_SUCCESS) { | |
7c3df132 SK |
2772 | ql_dbg(ql_dbg_disc, vha, 0x205c, |
2773 | "GFF_ID issue IOCB failed (%d).\n", rval); | |
e8c72ba5 | 2774 | } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, |
7a78ceda | 2775 | "GFF_ID") != QLA_SUCCESS) { |
7c3df132 SK |
2776 | ql_dbg(ql_dbg_disc, vha, 0x205d, |
2777 | "GFF_ID IOCB status had a failure status code.\n"); | |
e8c72ba5 CD |
2778 | } else { |
2779 | fcp_scsi_features = | |
2780 | ct_rsp->rsp.gff_id.fc4_features[GFF_FCP_SCSI_OFFSET]; | |
2781 | fcp_scsi_features &= 0x0f; | |
2782 | ||
84ed362a MH |
2783 | if (fcp_scsi_features) { |
2784 | list[i].fc4_type = FS_FC4TYPE_FCP; | |
2785 | list[i].fc4_features = fcp_scsi_features; | |
2786 | } | |
d3bae931 | 2787 | |
84ed362a | 2788 | nvme_features = |
d3bae931 | 2789 | ct_rsp->rsp.gff_id.fc4_features[GFF_NVME_OFFSET]; |
84ed362a MH |
2790 | nvme_features &= 0xf; |
2791 | ||
2792 | if (nvme_features) { | |
2793 | list[i].fc4_type |= FS_FC4TYPE_NVME; | |
2794 | list[i].fc4_features = nvme_features; | |
2795 | } | |
e8c72ba5 CD |
2796 | } |
2797 | ||
2798 | /* Last device exit. */ | |
2799 | if (list[i].d_id.b.rsvd_1 != 0) | |
2800 | break; | |
2801 | } | |
2802 | } | |
726b8548 | 2803 | |
726b8548 QT |
2804 | int qla24xx_post_gpsc_work(struct scsi_qla_host *vha, fc_port_t *fcport) |
2805 | { | |
2806 | struct qla_work_evt *e; | |
2807 | ||
2808 | e = qla2x00_alloc_work(vha, QLA_EVT_GPSC); | |
2809 | if (!e) | |
2810 | return QLA_FUNCTION_FAILED; | |
2811 | ||
2812 | e->u.fcport.fcport = fcport; | |
2813 | return qla2x00_post_work(vha, e); | |
2814 | } | |
2815 | ||
a4239945 QT |
2816 | void qla24xx_handle_gpsc_event(scsi_qla_host_t *vha, struct event_arg *ea) |
2817 | { | |
2818 | struct fc_port *fcport = ea->fcport; | |
2819 | ||
2820 | ql_dbg(ql_dbg_disc, vha, 0x20d8, | |
f352eeb7 | 2821 | "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d lid %d\n", |
a4239945 | 2822 | __func__, fcport->port_name, fcport->disc_state, |
f352eeb7 QT |
2823 | fcport->fw_login_state, ea->rc, ea->sp->gen2, fcport->login_gen, |
2824 | ea->sp->gen2, fcport->rscn_gen|ea->sp->gen1, fcport->loop_id); | |
a4239945 QT |
2825 | |
2826 | if (fcport->disc_state == DSC_DELETE_PEND) | |
2827 | return; | |
2828 | ||
9efea843 QT |
2829 | /* We will figure-out what happen after AUTH completes */ |
2830 | if (fcport->disc_state == DSC_LOGIN_AUTH_PEND) | |
2831 | return; | |
2832 | ||
a4239945 QT |
2833 | if (ea->sp->gen2 != fcport->login_gen) { |
2834 | /* target side must have changed it. */ | |
2835 | ql_dbg(ql_dbg_disc, vha, 0x20d3, | |
f352eeb7 QT |
2836 | "%s %8phC generation changed\n", |
2837 | __func__, fcport->port_name); | |
a4239945 QT |
2838 | return; |
2839 | } else if (ea->sp->gen1 != fcport->rscn_gen) { | |
a4239945 QT |
2840 | return; |
2841 | } | |
2842 | ||
cc28e0ac | 2843 | qla_post_iidma_work(vha, fcport); |
a4239945 QT |
2844 | } |
2845 | ||
6c18a43e | 2846 | static void qla24xx_async_gpsc_sp_done(srb_t *sp, int res) |
726b8548 | 2847 | { |
25ff6af1 | 2848 | struct scsi_qla_host *vha = sp->vha; |
726b8548 | 2849 | struct qla_hw_data *ha = vha->hw; |
726b8548 QT |
2850 | fc_port_t *fcport = sp->fcport; |
2851 | struct ct_sns_rsp *ct_rsp; | |
2852 | struct event_arg ea; | |
2853 | ||
2854 | ct_rsp = &fcport->ct_desc.ct_sns->p.rsp; | |
2855 | ||
83548fe2 | 2856 | ql_dbg(ql_dbg_disc, vha, 0x2053, |
726b8548 QT |
2857 | "Async done-%s res %x, WWPN %8phC \n", |
2858 | sp->name, res, fcport->port_name); | |
2859 | ||
0257eda0 GM |
2860 | fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE); |
2861 | ||
bcc71cc3 | 2862 | if (res == QLA_FUNCTION_TIMEOUT) |
af2a0c51 | 2863 | goto done; |
bcc71cc3 | 2864 | |
726b8548 QT |
2865 | if (res == (DID_ERROR << 16)) { |
2866 | /* entry status error */ | |
2867 | goto done; | |
2868 | } else if (res) { | |
2869 | if ((ct_rsp->header.reason_code == | |
2870 | CT_REASON_INVALID_COMMAND_CODE) || | |
2871 | (ct_rsp->header.reason_code == | |
83548fe2 QT |
2872 | CT_REASON_COMMAND_UNSUPPORTED)) { |
2873 | ql_dbg(ql_dbg_disc, vha, 0x2019, | |
2874 | "GPSC command unsupported, disabling query.\n"); | |
726b8548 | 2875 | ha->flags.gpsc_supported = 0; |
8d9bf0a9 | 2876 | goto done; |
726b8548 QT |
2877 | } |
2878 | } else { | |
2a3192a3 JC |
2879 | fcport->fp_speed = qla2x00_port_speed_capability( |
2880 | be16_to_cpu(ct_rsp->rsp.gpsc.speed)); | |
726b8548 | 2881 | |
83548fe2 QT |
2882 | ql_dbg(ql_dbg_disc, vha, 0x2054, |
2883 | "Async-%s OUT WWPN %8phC speeds=%04x speed=%04x.\n", | |
2884 | sp->name, fcport->fabric_port_name, | |
2885 | be16_to_cpu(ct_rsp->rsp.gpsc.speeds), | |
2886 | be16_to_cpu(ct_rsp->rsp.gpsc.speed)); | |
726b8548 | 2887 | } |
726b8548 | 2888 | memset(&ea, 0, sizeof(ea)); |
726b8548 QT |
2889 | ea.rc = res; |
2890 | ea.fcport = fcport; | |
a4239945 | 2891 | ea.sp = sp; |
897def20 | 2892 | qla24xx_handle_gpsc_event(vha, &ea); |
726b8548 | 2893 | |
8d9bf0a9 | 2894 | done: |
ee7bd382 SK |
2895 | /* ref: INIT */ |
2896 | kref_put(&sp->cmd_kref, qla2x00_sp_release); | |
726b8548 QT |
2897 | } |
2898 | ||
2899 | int qla24xx_async_gpsc(scsi_qla_host_t *vha, fc_port_t *fcport) | |
2900 | { | |
2901 | int rval = QLA_FUNCTION_FAILED; | |
2902 | struct ct_sns_req *ct_req; | |
2903 | srb_t *sp; | |
2904 | ||
3dbec59b QT |
2905 | if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT)) |
2906 | return rval; | |
726b8548 | 2907 | |
ee7bd382 | 2908 | /* ref: INIT */ |
726b8548 QT |
2909 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
2910 | if (!sp) | |
2911 | goto done; | |
2912 | ||
2913 | sp->type = SRB_CT_PTHRU_CMD; | |
2914 | sp->name = "gpsc"; | |
2915 | sp->gen1 = fcport->rscn_gen; | |
2916 | sp->gen2 = fcport->login_gen; | |
75a1d041 DW |
2917 | qla2x00_init_async_sp(sp, qla2x00_get_async_timeout(vha) + 2, |
2918 | qla24xx_async_gpsc_sp_done); | |
726b8548 QT |
2919 | |
2920 | /* CT_IU preamble */ | |
2921 | ct_req = qla24xx_prep_ct_fm_req(fcport->ct_desc.ct_sns, GPSC_CMD, | |
2922 | GPSC_RSP_SIZE); | |
2923 | ||
2924 | /* GPSC req */ | |
b2e8ae3f | 2925 | memcpy(ct_req->req.gpsc.port_name, fcport->fabric_port_name, |
726b8548 QT |
2926 | WWN_SIZE); |
2927 | ||
2928 | sp->u.iocb_cmd.u.ctarg.req = fcport->ct_desc.ct_sns; | |
2929 | sp->u.iocb_cmd.u.ctarg.req_dma = fcport->ct_desc.ct_sns_dma; | |
2930 | sp->u.iocb_cmd.u.ctarg.rsp = fcport->ct_desc.ct_sns; | |
2931 | sp->u.iocb_cmd.u.ctarg.rsp_dma = fcport->ct_desc.ct_sns_dma; | |
2932 | sp->u.iocb_cmd.u.ctarg.req_size = GPSC_REQ_SIZE; | |
2933 | sp->u.iocb_cmd.u.ctarg.rsp_size = GPSC_RSP_SIZE; | |
2934 | sp->u.iocb_cmd.u.ctarg.nport_handle = vha->mgmt_svr_loop_id; | |
2935 | ||
83548fe2 QT |
2936 | ql_dbg(ql_dbg_disc, vha, 0x205e, |
2937 | "Async-%s %8phC hdl=%x loopid=%x portid=%02x%02x%02x.\n", | |
2938 | sp->name, fcport->port_name, sp->handle, | |
2939 | fcport->loop_id, fcport->d_id.b.domain, | |
2940 | fcport->d_id.b.area, fcport->d_id.b.al_pa); | |
9fe278f4 GM |
2941 | |
2942 | rval = qla2x00_start_sp(sp); | |
2943 | if (rval != QLA_SUCCESS) | |
2944 | goto done_free_sp; | |
726b8548 QT |
2945 | return rval; |
2946 | ||
2947 | done_free_sp: | |
ee7bd382 SK |
2948 | /* ref: INIT */ |
2949 | kref_put(&sp->cmd_kref, qla2x00_sp_release); | |
3dbec59b | 2950 | done: |
726b8548 QT |
2951 | return rval; |
2952 | } | |
2953 | ||
2954 | int qla24xx_post_gpnid_work(struct scsi_qla_host *vha, port_id_t *id) | |
2955 | { | |
2956 | struct qla_work_evt *e; | |
2957 | ||
f5187b7d QT |
2958 | if (test_bit(UNLOADING, &vha->dpc_flags) || |
2959 | (vha->vp_idx && test_bit(VPORT_DELETE, &vha->dpc_flags))) | |
726b8548 QT |
2960 | return 0; |
2961 | ||
2962 | e = qla2x00_alloc_work(vha, QLA_EVT_GPNID); | |
2963 | if (!e) | |
2964 | return QLA_FUNCTION_FAILED; | |
2965 | ||
2966 | e->u.gpnid.id = *id; | |
2967 | return qla2x00_post_work(vha, e); | |
2968 | } | |
2969 | ||
e374f9f5 | 2970 | void qla24xx_sp_unmap(scsi_qla_host_t *vha, srb_t *sp) |
726b8548 | 2971 | { |
8777e431 QT |
2972 | struct srb_iocb *c = &sp->u.iocb_cmd; |
2973 | ||
2974 | switch (sp->type) { | |
2975 | case SRB_ELS_DCMD: | |
c6e58160 | 2976 | qla2x00_els_dcmd2_free(vha, &c->u.els_plogi); |
8777e431 QT |
2977 | break; |
2978 | case SRB_CT_PTHRU_CMD: | |
2979 | default: | |
2980 | if (sp->u.iocb_cmd.u.ctarg.req) { | |
2981 | dma_free_coherent(&vha->hw->pdev->dev, | |
72f02ba6 | 2982 | sp->u.iocb_cmd.u.ctarg.req_allocated_size, |
8777e431 QT |
2983 | sp->u.iocb_cmd.u.ctarg.req, |
2984 | sp->u.iocb_cmd.u.ctarg.req_dma); | |
2985 | sp->u.iocb_cmd.u.ctarg.req = NULL; | |
2986 | } | |
2987 | ||
2988 | if (sp->u.iocb_cmd.u.ctarg.rsp) { | |
2989 | dma_free_coherent(&vha->hw->pdev->dev, | |
72f02ba6 | 2990 | sp->u.iocb_cmd.u.ctarg.rsp_allocated_size, |
8777e431 QT |
2991 | sp->u.iocb_cmd.u.ctarg.rsp, |
2992 | sp->u.iocb_cmd.u.ctarg.rsp_dma); | |
2993 | sp->u.iocb_cmd.u.ctarg.rsp = NULL; | |
2994 | } | |
2995 | break; | |
726b8548 QT |
2996 | } |
2997 | ||
ee7bd382 SK |
2998 | /* ref: INIT */ |
2999 | kref_put(&sp->cmd_kref, qla2x00_sp_release); | |
726b8548 QT |
3000 | } |
3001 | ||
3002 | void qla24xx_handle_gpnid_event(scsi_qla_host_t *vha, struct event_arg *ea) | |
3003 | { | |
5ef696aa | 3004 | fc_port_t *fcport, *conflict, *t; |
f13515ac | 3005 | u16 data[2]; |
726b8548 | 3006 | |
5ef696aa QT |
3007 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
3008 | "%s %d port_id: %06x\n", | |
3009 | __func__, __LINE__, ea->id.b24); | |
726b8548 | 3010 | |
5ef696aa QT |
3011 | if (ea->rc) { |
3012 | /* cable is disconnected */ | |
3013 | list_for_each_entry_safe(fcport, t, &vha->vp_fcports, list) { | |
050e0ced | 3014 | if (fcport->d_id.b24 == ea->id.b24) |
5ef696aa | 3015 | fcport->scan_state = QLA_FCPORT_SCAN; |
050e0ced QT |
3016 | |
3017 | qlt_schedule_sess_for_deletion(fcport); | |
66ee0fec | 3018 | } |
726b8548 | 3019 | } else { |
5ef696aa QT |
3020 | /* cable is connected */ |
3021 | fcport = qla2x00_find_fcport_by_wwpn(vha, ea->port_name, 1); | |
3022 | if (fcport) { | |
3023 | list_for_each_entry_safe(conflict, t, &vha->vp_fcports, | |
3024 | list) { | |
3025 | if ((conflict->d_id.b24 == ea->id.b24) && | |
050e0ced QT |
3026 | (fcport != conflict)) |
3027 | /* | |
3028 | * 2 fcports with conflict Nport ID or | |
5ef696aa QT |
3029 | * an existing fcport is having nport ID |
3030 | * conflict with new fcport. | |
3031 | */ | |
3032 | ||
5ef696aa | 3033 | conflict->scan_state = QLA_FCPORT_SCAN; |
050e0ced QT |
3034 | |
3035 | qlt_schedule_sess_for_deletion(conflict); | |
5ef696aa | 3036 | } |
726b8548 | 3037 | |
d4f7a16a | 3038 | fcport->scan_needed = 0; |
5ef696aa QT |
3039 | fcport->rscn_gen++; |
3040 | fcport->scan_state = QLA_FCPORT_FOUND; | |
3041 | fcport->flags |= FCF_FABRIC_DEVICE; | |
23dd98a6 QT |
3042 | if (fcport->login_retry == 0) { |
3043 | fcport->login_retry = | |
3044 | vha->hw->login_retry_count; | |
3045 | ql_dbg(ql_dbg_disc, vha, 0xffff, | |
3046 | "Port login retry %8phN, lid 0x%04x cnt=%d.\n", | |
3047 | fcport->port_name, fcport->loop_id, | |
3048 | fcport->login_retry); | |
3049 | } | |
5ef696aa QT |
3050 | switch (fcport->disc_state) { |
3051 | case DSC_LOGIN_COMPLETE: | |
3052 | /* recheck session is still intact. */ | |
3053 | ql_dbg(ql_dbg_disc, vha, 0x210d, | |
3054 | "%s %d %8phC revalidate session with ADISC\n", | |
3055 | __func__, __LINE__, fcport->port_name); | |
f13515ac QT |
3056 | data[0] = data[1] = 0; |
3057 | qla2x00_post_async_adisc_work(vha, fcport, | |
3058 | data); | |
5ef696aa QT |
3059 | break; |
3060 | case DSC_DELETED: | |
3061 | ql_dbg(ql_dbg_disc, vha, 0x210d, | |
3062 | "%s %d %8phC login\n", __func__, __LINE__, | |
3063 | fcport->port_name); | |
3064 | fcport->d_id = ea->id; | |
3065 | qla24xx_fcport_handle_login(vha, fcport); | |
3066 | break; | |
3067 | case DSC_DELETE_PEND: | |
3068 | fcport->d_id = ea->id; | |
3069 | break; | |
3070 | default: | |
3071 | fcport->d_id = ea->id; | |
3072 | break; | |
3073 | } | |
3074 | } else { | |
3075 | list_for_each_entry_safe(conflict, t, &vha->vp_fcports, | |
3076 | list) { | |
3077 | if (conflict->d_id.b24 == ea->id.b24) { | |
3078 | /* 2 fcports with conflict Nport ID or | |
3079 | * an existing fcport is having nport ID | |
3080 | * conflict with new fcport. | |
3081 | */ | |
3082 | ql_dbg(ql_dbg_disc, vha, 0xffff, | |
3083 | "%s %d %8phC DS %d\n", | |
3084 | __func__, __LINE__, | |
3085 | conflict->port_name, | |
3086 | conflict->disc_state); | |
3087 | ||
3088 | conflict->scan_state = QLA_FCPORT_SCAN; | |
050e0ced | 3089 | qlt_schedule_sess_for_deletion(conflict); |
5ef696aa QT |
3090 | } |
3091 | } | |
3092 | ||
3093 | /* create new fcport */ | |
3094 | ql_dbg(ql_dbg_disc, vha, 0x2065, | |
3095 | "%s %d %8phC post new sess\n", | |
3096 | __func__, __LINE__, ea->port_name); | |
3097 | qla24xx_post_newsess_work(vha, &ea->id, | |
8e0e063a | 3098 | ea->port_name, NULL, NULL, 0); |
5ef696aa | 3099 | } |
726b8548 QT |
3100 | } |
3101 | } | |
3102 | ||
6c18a43e | 3103 | static void qla2x00_async_gpnid_sp_done(srb_t *sp, int res) |
726b8548 | 3104 | { |
25ff6af1 | 3105 | struct scsi_qla_host *vha = sp->vha; |
726b8548 QT |
3106 | struct ct_sns_req *ct_req = |
3107 | (struct ct_sns_req *)sp->u.iocb_cmd.u.ctarg.req; | |
3108 | struct ct_sns_rsp *ct_rsp = | |
3109 | (struct ct_sns_rsp *)sp->u.iocb_cmd.u.ctarg.rsp; | |
3110 | struct event_arg ea; | |
3111 | struct qla_work_evt *e; | |
2d73ac61 | 3112 | unsigned long flags; |
726b8548 | 3113 | |
a084fd68 QT |
3114 | if (res) |
3115 | ql_dbg(ql_dbg_disc, vha, 0x2066, | |
2d73ac61 | 3116 | "Async done-%s fail res %x rscn gen %d ID %3phC. %8phC\n", |
df95f39a | 3117 | sp->name, res, sp->gen1, &ct_req->req.port_id.port_id, |
a084fd68 QT |
3118 | ct_rsp->rsp.gpn_id.port_name); |
3119 | else | |
3120 | ql_dbg(ql_dbg_disc, vha, 0x2066, | |
2d73ac61 | 3121 | "Async done-%s good rscn gen %d ID %3phC. %8phC\n", |
df95f39a | 3122 | sp->name, sp->gen1, &ct_req->req.port_id.port_id, |
a084fd68 | 3123 | ct_rsp->rsp.gpn_id.port_name); |
726b8548 QT |
3124 | |
3125 | memset(&ea, 0, sizeof(ea)); | |
3126 | memcpy(ea.port_name, ct_rsp->rsp.gpn_id.port_name, WWN_SIZE); | |
3127 | ea.sp = sp; | |
df95f39a | 3128 | ea.id = be_to_port_id(ct_req->req.port_id.port_id); |
726b8548 | 3129 | ea.rc = res; |
726b8548 | 3130 | |
2d73ac61 QT |
3131 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
3132 | list_del(&sp->elem); | |
3133 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); | |
3134 | ||
25ad76b7 | 3135 | if (res) { |
5ef696aa | 3136 | if (res == QLA_FUNCTION_TIMEOUT) { |
25ad76b7 | 3137 | qla24xx_post_gpnid_work(sp->vha, &ea.id); |
ee7bd382 SK |
3138 | /* ref: INIT */ |
3139 | kref_put(&sp->cmd_kref, qla2x00_sp_release); | |
5ef696aa QT |
3140 | return; |
3141 | } | |
2d73ac61 | 3142 | } else if (sp->gen1) { |
5ef696aa | 3143 | /* There was another RSCN for this Nport ID */ |
2d73ac61 | 3144 | qla24xx_post_gpnid_work(sp->vha, &ea.id); |
ee7bd382 SK |
3145 | /* ref: INIT */ |
3146 | kref_put(&sp->cmd_kref, qla2x00_sp_release); | |
2d73ac61 | 3147 | return; |
25ad76b7 QT |
3148 | } |
3149 | ||
897def20 | 3150 | qla24xx_handle_gpnid_event(vha, &ea); |
726b8548 | 3151 | |
e374f9f5 | 3152 | e = qla2x00_alloc_work(vha, QLA_EVT_UNMAP); |
726b8548 QT |
3153 | if (!e) { |
3154 | /* please ignore kernel warning. otherwise, we have mem leak. */ | |
1778a0e7 BVA |
3155 | dma_free_coherent(&vha->hw->pdev->dev, |
3156 | sp->u.iocb_cmd.u.ctarg.req_allocated_size, | |
3157 | sp->u.iocb_cmd.u.ctarg.req, | |
3158 | sp->u.iocb_cmd.u.ctarg.req_dma); | |
3159 | sp->u.iocb_cmd.u.ctarg.req = NULL; | |
3160 | ||
3161 | dma_free_coherent(&vha->hw->pdev->dev, | |
3162 | sp->u.iocb_cmd.u.ctarg.rsp_allocated_size, | |
3163 | sp->u.iocb_cmd.u.ctarg.rsp, | |
3164 | sp->u.iocb_cmd.u.ctarg.rsp_dma); | |
3165 | sp->u.iocb_cmd.u.ctarg.rsp = NULL; | |
726b8548 | 3166 | |
ee7bd382 SK |
3167 | /* ref: INIT */ |
3168 | kref_put(&sp->cmd_kref, qla2x00_sp_release); | |
726b8548 QT |
3169 | return; |
3170 | } | |
3171 | ||
3172 | e->u.iosb.sp = sp; | |
3173 | qla2x00_post_work(vha, e); | |
3174 | } | |
3175 | ||
3176 | /* Get WWPN with Nport ID. */ | |
3177 | int qla24xx_async_gpnid(scsi_qla_host_t *vha, port_id_t *id) | |
3178 | { | |
3179 | int rval = QLA_FUNCTION_FAILED; | |
3180 | struct ct_sns_req *ct_req; | |
2d73ac61 | 3181 | srb_t *sp, *tsp; |
726b8548 | 3182 | struct ct_sns_pkt *ct_sns; |
2d73ac61 | 3183 | unsigned long flags; |
726b8548 QT |
3184 | |
3185 | if (!vha->flags.online) | |
3186 | goto done; | |
3187 | ||
ee7bd382 | 3188 | /* ref: INIT */ |
726b8548 QT |
3189 | sp = qla2x00_get_sp(vha, NULL, GFP_KERNEL); |
3190 | if (!sp) | |
3191 | goto done; | |
3192 | ||
3193 | sp->type = SRB_CT_PTHRU_CMD; | |
3194 | sp->name = "gpnid"; | |
2d73ac61 QT |
3195 | sp->u.iocb_cmd.u.ctarg.id = *id; |
3196 | sp->gen1 = 0; | |
75a1d041 DW |
3197 | qla2x00_init_async_sp(sp, qla2x00_get_async_timeout(vha) + 2, |
3198 | qla2x00_async_gpnid_sp_done); | |
726b8548 | 3199 | |
2d73ac61 QT |
3200 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
3201 | list_for_each_entry(tsp, &vha->gpnid_list, elem) { | |
3202 | if (tsp->u.iocb_cmd.u.ctarg.id.b24 == id->b24) { | |
3203 | tsp->gen1++; | |
3204 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); | |
ee7bd382 SK |
3205 | /* ref: INIT */ |
3206 | kref_put(&sp->cmd_kref, qla2x00_sp_release); | |
2d73ac61 QT |
3207 | goto done; |
3208 | } | |
3209 | } | |
3210 | list_add_tail(&sp->elem, &vha->gpnid_list); | |
3211 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); | |
3212 | ||
726b8548 QT |
3213 | sp->u.iocb_cmd.u.ctarg.req = dma_alloc_coherent(&vha->hw->pdev->dev, |
3214 | sizeof(struct ct_sns_pkt), &sp->u.iocb_cmd.u.ctarg.req_dma, | |
3215 | GFP_KERNEL); | |
b5f3bc39 | 3216 | sp->u.iocb_cmd.u.ctarg.req_allocated_size = sizeof(struct ct_sns_pkt); |
726b8548 | 3217 | if (!sp->u.iocb_cmd.u.ctarg.req) { |
83548fe2 QT |
3218 | ql_log(ql_log_warn, vha, 0xd041, |
3219 | "Failed to allocate ct_sns request.\n"); | |
726b8548 QT |
3220 | goto done_free_sp; |
3221 | } | |
3222 | ||
3223 | sp->u.iocb_cmd.u.ctarg.rsp = dma_alloc_coherent(&vha->hw->pdev->dev, | |
3224 | sizeof(struct ct_sns_pkt), &sp->u.iocb_cmd.u.ctarg.rsp_dma, | |
3225 | GFP_KERNEL); | |
b5f3bc39 | 3226 | sp->u.iocb_cmd.u.ctarg.rsp_allocated_size = sizeof(struct ct_sns_pkt); |
726b8548 | 3227 | if (!sp->u.iocb_cmd.u.ctarg.rsp) { |
83548fe2 QT |
3228 | ql_log(ql_log_warn, vha, 0xd042, |
3229 | "Failed to allocate ct_sns request.\n"); | |
726b8548 QT |
3230 | goto done_free_sp; |
3231 | } | |
3232 | ||
3233 | ct_sns = (struct ct_sns_pkt *)sp->u.iocb_cmd.u.ctarg.rsp; | |
3234 | memset(ct_sns, 0, sizeof(*ct_sns)); | |
3235 | ||
3236 | ct_sns = (struct ct_sns_pkt *)sp->u.iocb_cmd.u.ctarg.req; | |
3237 | /* CT_IU preamble */ | |
3238 | ct_req = qla2x00_prep_ct_req(ct_sns, GPN_ID_CMD, GPN_ID_RSP_SIZE); | |
3239 | ||
3240 | /* GPN_ID req */ | |
df95f39a | 3241 | ct_req->req.port_id.port_id = port_id_to_be_id(*id); |
726b8548 QT |
3242 | |
3243 | sp->u.iocb_cmd.u.ctarg.req_size = GPN_ID_REQ_SIZE; | |
3244 | sp->u.iocb_cmd.u.ctarg.rsp_size = GPN_ID_RSP_SIZE; | |
3245 | sp->u.iocb_cmd.u.ctarg.nport_handle = NPH_SNS; | |
3246 | ||
9fe278f4 GM |
3247 | ql_dbg(ql_dbg_disc, vha, 0x2067, |
3248 | "Async-%s hdl=%x ID %3phC.\n", sp->name, | |
df95f39a | 3249 | sp->handle, &ct_req->req.port_id.port_id); |
9fe278f4 | 3250 | |
726b8548 QT |
3251 | rval = qla2x00_start_sp(sp); |
3252 | if (rval != QLA_SUCCESS) | |
3253 | goto done_free_sp; | |
3254 | ||
726b8548 QT |
3255 | return rval; |
3256 | ||
3257 | done_free_sp: | |
e3dde080 QT |
3258 | spin_lock_irqsave(&vha->hw->vport_slock, flags); |
3259 | list_del(&sp->elem); | |
3260 | spin_unlock_irqrestore(&vha->hw->vport_slock, flags); | |
3261 | ||
726b8548 QT |
3262 | if (sp->u.iocb_cmd.u.ctarg.req) { |
3263 | dma_free_coherent(&vha->hw->pdev->dev, | |
3264 | sizeof(struct ct_sns_pkt), | |
3265 | sp->u.iocb_cmd.u.ctarg.req, | |
3266 | sp->u.iocb_cmd.u.ctarg.req_dma); | |
3267 | sp->u.iocb_cmd.u.ctarg.req = NULL; | |
3268 | } | |
3269 | if (sp->u.iocb_cmd.u.ctarg.rsp) { | |
3270 | dma_free_coherent(&vha->hw->pdev->dev, | |
3271 | sizeof(struct ct_sns_pkt), | |
3272 | sp->u.iocb_cmd.u.ctarg.rsp, | |
3273 | sp->u.iocb_cmd.u.ctarg.rsp_dma); | |
3274 | sp->u.iocb_cmd.u.ctarg.rsp = NULL; | |
3275 | } | |
ee7bd382 SK |
3276 | /* ref: INIT */ |
3277 | kref_put(&sp->cmd_kref, qla2x00_sp_release); | |
726b8548 QT |
3278 | done: |
3279 | return rval; | |
3280 | } | |
d3bae931 DG |
3281 | |
3282 | void qla24xx_handle_gffid_event(scsi_qla_host_t *vha, struct event_arg *ea) | |
3283 | { | |
0184793d | 3284 | fc_port_t *fcport = ea->fcport; |
d3bae931 | 3285 | |
0184793d | 3286 | qla24xx_post_gnl_work(vha, fcport); |
d3bae931 DG |
3287 | } |
3288 | ||
6c18a43e | 3289 | void qla24xx_async_gffid_sp_done(srb_t *sp, int res) |
d3bae931 | 3290 | { |
0184793d BVA |
3291 | struct scsi_qla_host *vha = sp->vha; |
3292 | fc_port_t *fcport = sp->fcport; | |
3293 | struct ct_sns_rsp *ct_rsp; | |
3294 | struct event_arg ea; | |
84ed362a MH |
3295 | uint8_t fc4_scsi_feat; |
3296 | uint8_t fc4_nvme_feat; | |
0184793d BVA |
3297 | |
3298 | ql_dbg(ql_dbg_disc, vha, 0x2133, | |
3299 | "Async done-%s res %x ID %x. %8phC\n", | |
3300 | sp->name, res, fcport->d_id.b24, fcport->port_name); | |
d3bae931 | 3301 | |
0184793d BVA |
3302 | fcport->flags &= ~FCF_ASYNC_SENT; |
3303 | ct_rsp = &fcport->ct_desc.ct_sns->p.rsp; | |
84ed362a MH |
3304 | fc4_scsi_feat = ct_rsp->rsp.gff_id.fc4_features[GFF_FCP_SCSI_OFFSET]; |
3305 | fc4_nvme_feat = ct_rsp->rsp.gff_id.fc4_features[GFF_NVME_OFFSET]; | |
3306 | ||
0184793d BVA |
3307 | /* |
3308 | * FC-GS-7, 5.2.3.12 FC-4 Features - format | |
3309 | * The format of the FC-4 Features object, as defined by the FC-4, | |
3310 | * Shall be an array of 4-bit values, one for each type code value | |
3311 | */ | |
3312 | if (!res) { | |
84ed362a | 3313 | if (fc4_scsi_feat & 0xf) { |
0184793d | 3314 | /* w1 b00:03 */ |
84ed362a MH |
3315 | fcport->fc4_type = FS_FC4TYPE_FCP; |
3316 | fcport->fc4_features = fc4_scsi_feat & 0xf; | |
3317 | } | |
d3bae931 | 3318 | |
84ed362a | 3319 | if (fc4_nvme_feat & 0xf) { |
0184793d | 3320 | /* w5 [00:03]/28h */ |
84ed362a MH |
3321 | fcport->fc4_type |= FS_FC4TYPE_NVME; |
3322 | fcport->fc4_features = fc4_nvme_feat & 0xf; | |
0184793d BVA |
3323 | } |
3324 | } | |
d3bae931 | 3325 | |
0184793d BVA |
3326 | memset(&ea, 0, sizeof(ea)); |
3327 | ea.sp = sp; | |
3328 | ea.fcport = sp->fcport; | |
3329 | ea.rc = res; | |
0184793d | 3330 | |
897def20 | 3331 | qla24xx_handle_gffid_event(vha, &ea); |
ee7bd382 SK |
3332 | /* ref: INIT */ |
3333 | kref_put(&sp->cmd_kref, qla2x00_sp_release); | |
d3bae931 DG |
3334 | } |
3335 | ||
3336 | /* Get FC4 Feature with Nport ID. */ | |
3337 | int qla24xx_async_gffid(scsi_qla_host_t *vha, fc_port_t *fcport) | |
3338 | { | |
3339 | int rval = QLA_FUNCTION_FAILED; | |
3340 | struct ct_sns_req *ct_req; | |
3341 | srb_t *sp; | |
3342 | ||
3dbec59b | 3343 | if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT)) |
d3bae931 DG |
3344 | return rval; |
3345 | ||
ee7bd382 | 3346 | /* ref: INIT */ |
d3bae931 DG |
3347 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
3348 | if (!sp) | |
3349 | return rval; | |
3350 | ||
3351 | fcport->flags |= FCF_ASYNC_SENT; | |
3352 | sp->type = SRB_CT_PTHRU_CMD; | |
3353 | sp->name = "gffid"; | |
3354 | sp->gen1 = fcport->rscn_gen; | |
3355 | sp->gen2 = fcport->login_gen; | |
75a1d041 DW |
3356 | qla2x00_init_async_sp(sp, qla2x00_get_async_timeout(vha) + 2, |
3357 | qla24xx_async_gffid_sp_done); | |
d3bae931 DG |
3358 | |
3359 | /* CT_IU preamble */ | |
3360 | ct_req = qla2x00_prep_ct_req(fcport->ct_desc.ct_sns, GFF_ID_CMD, | |
3361 | GFF_ID_RSP_SIZE); | |
3362 | ||
3363 | ct_req->req.gff_id.port_id[0] = fcport->d_id.b.domain; | |
3364 | ct_req->req.gff_id.port_id[1] = fcport->d_id.b.area; | |
3365 | ct_req->req.gff_id.port_id[2] = fcport->d_id.b.al_pa; | |
3366 | ||
3367 | sp->u.iocb_cmd.u.ctarg.req = fcport->ct_desc.ct_sns; | |
3368 | sp->u.iocb_cmd.u.ctarg.req_dma = fcport->ct_desc.ct_sns_dma; | |
3369 | sp->u.iocb_cmd.u.ctarg.rsp = fcport->ct_desc.ct_sns; | |
3370 | sp->u.iocb_cmd.u.ctarg.rsp_dma = fcport->ct_desc.ct_sns_dma; | |
3371 | sp->u.iocb_cmd.u.ctarg.req_size = GFF_ID_REQ_SIZE; | |
3372 | sp->u.iocb_cmd.u.ctarg.rsp_size = GFF_ID_RSP_SIZE; | |
3373 | sp->u.iocb_cmd.u.ctarg.nport_handle = NPH_SNS; | |
3374 | ||
d3bae931 DG |
3375 | ql_dbg(ql_dbg_disc, vha, 0x2132, |
3376 | "Async-%s hdl=%x %8phC.\n", sp->name, | |
3377 | sp->handle, fcport->port_name); | |
3378 | ||
f233e8c0 BK |
3379 | rval = qla2x00_start_sp(sp); |
3380 | if (rval != QLA_SUCCESS) | |
3381 | goto done_free_sp; | |
3382 | ||
d3bae931 DG |
3383 | return rval; |
3384 | done_free_sp: | |
ee7bd382 SK |
3385 | /* ref: INIT */ |
3386 | kref_put(&sp->cmd_kref, qla2x00_sp_release); | |
d3bae931 DG |
3387 | fcport->flags &= ~FCF_ASYNC_SENT; |
3388 | return rval; | |
3389 | } | |
a4239945 QT |
3390 | |
3391 | /* GPN_FT + GNN_FT*/ | |
3392 | static int qla2x00_is_a_vp(scsi_qla_host_t *vha, u64 wwn) | |
3393 | { | |
3394 | struct qla_hw_data *ha = vha->hw; | |
3395 | scsi_qla_host_t *vp; | |
3396 | unsigned long flags; | |
3397 | u64 twwn; | |
3398 | int rc = 0; | |
3399 | ||
3400 | if (!ha->num_vhosts) | |
3401 | return 0; | |
3402 | ||
3403 | spin_lock_irqsave(&ha->vport_slock, flags); | |
3404 | list_for_each_entry(vp, &ha->vp_list, list) { | |
3405 | twwn = wwn_to_u64(vp->port_name); | |
3406 | if (wwn == twwn) { | |
3407 | rc = 1; | |
3408 | break; | |
3409 | } | |
3410 | } | |
3411 | spin_unlock_irqrestore(&ha->vport_slock, flags); | |
3412 | ||
3413 | return rc; | |
3414 | } | |
3415 | ||
3416 | void qla24xx_async_gnnft_done(scsi_qla_host_t *vha, srb_t *sp) | |
3417 | { | |
3418 | fc_port_t *fcport; | |
3419 | u32 i, rc; | |
3420 | bool found; | |
f3a03ee1 | 3421 | struct fab_scan_rp *rp, *trp; |
f352eeb7 | 3422 | unsigned long flags; |
bee8b846 | 3423 | u8 recheck = 0; |
f3a03ee1 | 3424 | u16 dup = 0, dup_cnt = 0; |
a4239945 | 3425 | |
45c96e44 | 3426 | ql_dbg(ql_dbg_disc + ql_dbg_verbose, vha, 0xffff, |
a4239945 QT |
3427 | "%s enter\n", __func__); |
3428 | ||
3429 | if (sp->gen1 != vha->hw->base_qpair->chip_reset) { | |
3430 | ql_dbg(ql_dbg_disc, vha, 0xffff, | |
3431 | "%s scan stop due to chip reset %x/%x\n", | |
3432 | sp->name, sp->gen1, vha->hw->base_qpair->chip_reset); | |
3433 | goto out; | |
3434 | } | |
3435 | ||
3436 | rc = sp->rc; | |
3437 | if (rc) { | |
6944dccb QT |
3438 | vha->scan.scan_retry++; |
3439 | if (vha->scan.scan_retry < MAX_SCAN_RETRIES) { | |
3440 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); | |
3441 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); | |
c8a34793 | 3442 | goto out; |
6944dccb | 3443 | } else { |
c8a34793 | 3444 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
45c96e44 HM |
3445 | "%s: Fabric scan failed for %d retries.\n", |
3446 | __func__, vha->scan.scan_retry); | |
c8a34793 MW |
3447 | /* |
3448 | * Unable to scan any rports. logout loop below | |
3449 | * will unregister all sessions. | |
3450 | */ | |
3451 | list_for_each_entry(fcport, &vha->vp_fcports, list) { | |
3452 | if ((fcport->flags & FCF_FABRIC_DEVICE) != 0) { | |
3453 | fcport->scan_state = QLA_FCPORT_SCAN; | |
022a2d21 QT |
3454 | if (fcport->loop_id == FC_NO_LOOP_ID) |
3455 | fcport->logout_on_delete = 0; | |
3456 | else | |
3457 | fcport->logout_on_delete = 1; | |
c8a34793 MW |
3458 | } |
3459 | } | |
3460 | goto login_logout; | |
6944dccb | 3461 | } |
a4239945 | 3462 | } |
6944dccb | 3463 | vha->scan.scan_retry = 0; |
a4239945 QT |
3464 | |
3465 | list_for_each_entry(fcport, &vha->vp_fcports, list) | |
3466 | fcport->scan_state = QLA_FCPORT_SCAN; | |
3467 | ||
3468 | for (i = 0; i < vha->hw->max_fibre_devices; i++) { | |
3469 | u64 wwn; | |
f3a03ee1 | 3470 | int k; |
a4239945 QT |
3471 | |
3472 | rp = &vha->scan.l[i]; | |
3473 | found = false; | |
3474 | ||
3475 | wwn = wwn_to_u64(rp->port_name); | |
3476 | if (wwn == 0) | |
3477 | continue; | |
3478 | ||
f3a03ee1 QT |
3479 | /* Remove duplicate NPORT ID entries from switch data base */ |
3480 | for (k = i + 1; k < vha->hw->max_fibre_devices; k++) { | |
3481 | trp = &vha->scan.l[k]; | |
3482 | if (rp->id.b24 == trp->id.b24) { | |
3483 | dup = 1; | |
3484 | dup_cnt++; | |
3485 | ql_dbg(ql_dbg_disc + ql_dbg_verbose, | |
3486 | vha, 0xffff, | |
3487 | "Detected duplicate NPORT ID from switch data base: ID %06x WWN %8phN WWN %8phN\n", | |
3488 | rp->id.b24, rp->port_name, trp->port_name); | |
3489 | memset(trp, 0, sizeof(*trp)); | |
3490 | } | |
3491 | } | |
3492 | ||
a4239945 QT |
3493 | if (!memcmp(rp->port_name, vha->port_name, WWN_SIZE)) |
3494 | continue; | |
3495 | ||
3496 | /* Bypass reserved domain fields. */ | |
3497 | if ((rp->id.b.domain & 0xf0) == 0xf0) | |
3498 | continue; | |
3499 | ||
3500 | /* Bypass virtual ports of the same host. */ | |
3501 | if (qla2x00_is_a_vp(vha, wwn)) | |
3502 | continue; | |
3503 | ||
3504 | list_for_each_entry(fcport, &vha->vp_fcports, list) { | |
3505 | if (memcmp(rp->port_name, fcport->port_name, WWN_SIZE)) | |
3506 | continue; | |
3507 | fcport->scan_state = QLA_FCPORT_FOUND; | |
d26a8982 | 3508 | fcport->last_rscn_gen = fcport->rscn_gen; |
f6e327fc | 3509 | fcport->fc4_type = rp->fc4type; |
a4239945 | 3510 | found = true; |
f8844457 QT |
3511 | |
3512 | if (fcport->scan_needed) { | |
3513 | if (NVME_PRIORITY(vha->hw, fcport)) | |
3514 | fcport->do_prli_nvme = 1; | |
3515 | else | |
3516 | fcport->do_prli_nvme = 0; | |
3517 | } | |
3518 | ||
a4239945 QT |
3519 | /* |
3520 | * If device was not a fabric device before. | |
3521 | */ | |
3522 | if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) { | |
3523 | qla2x00_clear_loop_id(fcport); | |
3524 | fcport->flags |= FCF_FABRIC_DEVICE; | |
2037ce49 | 3525 | } else if (fcport->d_id.b24 != rp->id.b24 || |
632f24f0 RB |
3526 | (fcport->scan_needed && |
3527 | fcport->port_type != FCT_INITIATOR && | |
3528 | fcport->port_type != FCT_NVME_INITIATOR)) { | |
1d317b21 | 3529 | qlt_schedule_sess_for_deletion(fcport); |
a4239945 | 3530 | } |
1d317b21 | 3531 | fcport->d_id.b24 = rp->id.b24; |
2037ce49 | 3532 | fcport->scan_needed = 0; |
a4239945 QT |
3533 | break; |
3534 | } | |
3535 | ||
3536 | if (!found) { | |
3537 | ql_dbg(ql_dbg_disc, vha, 0xffff, | |
3538 | "%s %d %8phC post new sess\n", | |
3539 | __func__, __LINE__, rp->port_name); | |
3540 | qla24xx_post_newsess_work(vha, &rp->id, rp->port_name, | |
33b28357 | 3541 | rp->node_name, NULL, rp->fc4type); |
a4239945 QT |
3542 | } |
3543 | } | |
3544 | ||
f3a03ee1 QT |
3545 | if (dup) { |
3546 | ql_log(ql_log_warn, vha, 0xffff, | |
3547 | "Detected %d duplicate NPORT ID(s) from switch data base\n", | |
3548 | dup_cnt); | |
3549 | } | |
3550 | ||
c8a34793 | 3551 | login_logout: |
a4239945 QT |
3552 | /* |
3553 | * Logout all previous fabric dev marked lost, except FCP2 devices. | |
3554 | */ | |
3555 | list_for_each_entry(fcport, &vha->vp_fcports, list) { | |
bee8b846 | 3556 | if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) { |
cb873ba4 | 3557 | fcport->scan_needed = 0; |
a4239945 | 3558 | continue; |
bee8b846 | 3559 | } |
a4239945 | 3560 | |
f352eeb7 | 3561 | if (fcport->scan_state != QLA_FCPORT_FOUND) { |
abb31aea QT |
3562 | bool do_delete = false; |
3563 | ||
3564 | if (fcport->scan_needed && | |
3565 | fcport->disc_state == DSC_LOGIN_PEND) { | |
3566 | /* Cable got disconnected after we sent | |
3567 | * a login. Do delete to prevent timeout. | |
3568 | */ | |
3569 | fcport->logout_on_delete = 1; | |
3570 | do_delete = true; | |
3571 | } | |
3572 | ||
cb873ba4 | 3573 | fcport->scan_needed = 0; |
abb31aea QT |
3574 | if (((qla_dual_mode_enabled(vha) || |
3575 | qla_ini_mode_enabled(vha)) && | |
3576 | atomic_read(&fcport->state) == FCS_ONLINE) || | |
3577 | do_delete) { | |
0aca7784 QT |
3578 | if (fcport->loop_id != FC_NO_LOOP_ID) { |
3579 | if (fcport->flags & FCF_FCP2_DEVICE) | |
3580 | fcport->logout_on_delete = 0; | |
f352eeb7 | 3581 | |
c1599657 SK |
3582 | ql_log(ql_log_warn, vha, 0x20f0, |
3583 | "%s %d %8phC post del sess\n", | |
3584 | __func__, __LINE__, | |
3585 | fcport->port_name); | |
a4239945 | 3586 | |
dbf1f53c | 3587 | fcport->tgt_link_down_time = 0; |
d8630bb9 | 3588 | qlt_schedule_sess_for_deletion(fcport); |
a4239945 QT |
3589 | continue; |
3590 | } | |
3591 | } | |
bee8b846 | 3592 | } else { |
cb873ba4 | 3593 | if (fcport->scan_needed || |
bee8b846 | 3594 | fcport->disc_state != DSC_LOGIN_COMPLETE) { |
23dd98a6 QT |
3595 | if (fcport->login_retry == 0) { |
3596 | fcport->login_retry = | |
3597 | vha->hw->login_retry_count; | |
3598 | ql_dbg(ql_dbg_disc, vha, 0x20a3, | |
3599 | "Port login retry %8phN, lid 0x%04x retry cnt=%d.\n", | |
3600 | fcport->port_name, fcport->loop_id, | |
3601 | fcport->login_retry); | |
3602 | } | |
cb873ba4 | 3603 | fcport->scan_needed = 0; |
bee8b846 QT |
3604 | qla24xx_fcport_handle_login(vha, fcport); |
3605 | } | |
3606 | } | |
a4239945 QT |
3607 | } |
3608 | ||
bee8b846 | 3609 | recheck = 1; |
a4239945 | 3610 | out: |
e374f9f5 | 3611 | qla24xx_sp_unmap(vha, sp); |
f352eeb7 QT |
3612 | spin_lock_irqsave(&vha->work_lock, flags); |
3613 | vha->scan.scan_flags &= ~SF_SCANNING; | |
3614 | spin_unlock_irqrestore(&vha->work_lock, flags); | |
bee8b846 QT |
3615 | |
3616 | if (recheck) { | |
3617 | list_for_each_entry(fcport, &vha->vp_fcports, list) { | |
cb873ba4 | 3618 | if (fcport->scan_needed) { |
bee8b846 QT |
3619 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
3620 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); | |
3621 | break; | |
3622 | } | |
3623 | } | |
3624 | } | |
a4239945 QT |
3625 | } |
3626 | ||
9ba1cb25 QT |
3627 | static int qla2x00_post_gnnft_gpnft_done_work(struct scsi_qla_host *vha, |
3628 | srb_t *sp, int cmd) | |
3629 | { | |
3630 | struct qla_work_evt *e; | |
3631 | ||
3632 | if (cmd != QLA_EVT_GPNFT_DONE && cmd != QLA_EVT_GNNFT_DONE) | |
3633 | return QLA_PARAMETER_ERROR; | |
3634 | ||
3635 | e = qla2x00_alloc_work(vha, cmd); | |
3636 | if (!e) | |
3637 | return QLA_FUNCTION_FAILED; | |
3638 | ||
3639 | e->u.iosb.sp = sp; | |
3640 | ||
3641 | return qla2x00_post_work(vha, e); | |
3642 | } | |
3643 | ||
a110af85 | 3644 | static int qla2x00_post_nvme_gpnft_work(struct scsi_qla_host *vha, |
9ba1cb25 QT |
3645 | srb_t *sp, int cmd) |
3646 | { | |
3647 | struct qla_work_evt *e; | |
3648 | ||
3649 | if (cmd != QLA_EVT_GPNFT) | |
3650 | return QLA_PARAMETER_ERROR; | |
3651 | ||
3652 | e = qla2x00_alloc_work(vha, cmd); | |
3653 | if (!e) | |
3654 | return QLA_FUNCTION_FAILED; | |
3655 | ||
3656 | e->u.gpnft.fc4_type = FC4_TYPE_NVME; | |
3657 | e->u.gpnft.sp = sp; | |
3658 | ||
3659 | return qla2x00_post_work(vha, e); | |
3660 | } | |
3661 | ||
33b28357 QT |
3662 | static void qla2x00_find_free_fcp_nvme_slot(struct scsi_qla_host *vha, |
3663 | struct srb *sp) | |
a4239945 | 3664 | { |
33b28357 QT |
3665 | struct qla_hw_data *ha = vha->hw; |
3666 | int num_fibre_dev = ha->max_fibre_devices; | |
a4239945 QT |
3667 | struct ct_sns_req *ct_req = |
3668 | (struct ct_sns_req *)sp->u.iocb_cmd.u.ctarg.req; | |
3669 | struct ct_sns_gpnft_rsp *ct_rsp = | |
3670 | (struct ct_sns_gpnft_rsp *)sp->u.iocb_cmd.u.ctarg.rsp; | |
8b569180 | 3671 | struct ct_sns_gpn_ft_data *d; |
a4239945 | 3672 | struct fab_scan_rp *rp; |
33b28357 QT |
3673 | u16 cmd = be16_to_cpu(ct_req->command); |
3674 | u8 fc4_type = sp->gen2; | |
a4239945 | 3675 | int i, j, k; |
33b28357 QT |
3676 | port_id_t id; |
3677 | u8 found; | |
3678 | u64 wwn; | |
3679 | ||
3680 | j = 0; | |
3681 | for (i = 0; i < num_fibre_dev; i++) { | |
3682 | d = &ct_rsp->entries[i]; | |
3683 | ||
3684 | id.b.rsvd_1 = 0; | |
3685 | id.b.domain = d->port_id[0]; | |
3686 | id.b.area = d->port_id[1]; | |
3687 | id.b.al_pa = d->port_id[2]; | |
3688 | wwn = wwn_to_u64(d->port_name); | |
3689 | ||
3690 | if (id.b24 == 0 || wwn == 0) | |
3691 | continue; | |
3692 | ||
3693 | if (fc4_type == FC4_TYPE_FCP_SCSI) { | |
3694 | if (cmd == GPN_FT_CMD) { | |
3695 | rp = &vha->scan.l[j]; | |
3696 | rp->id = id; | |
3697 | memcpy(rp->port_name, d->port_name, 8); | |
3698 | j++; | |
3699 | rp->fc4type = FS_FC4TYPE_FCP; | |
3700 | } else { | |
3701 | for (k = 0; k < num_fibre_dev; k++) { | |
3702 | rp = &vha->scan.l[k]; | |
3703 | if (id.b24 == rp->id.b24) { | |
3704 | memcpy(rp->node_name, | |
3705 | d->port_name, 8); | |
3706 | break; | |
3707 | } | |
3708 | } | |
3709 | } | |
3710 | } else { | |
3711 | /* Search if the fibre device supports FC4_TYPE_NVME */ | |
3712 | if (cmd == GPN_FT_CMD) { | |
3713 | found = 0; | |
3714 | ||
3715 | for (k = 0; k < num_fibre_dev; k++) { | |
3716 | rp = &vha->scan.l[k]; | |
3717 | if (!memcmp(rp->port_name, | |
3718 | d->port_name, 8)) { | |
3719 | /* | |
3720 | * Supports FC-NVMe & FCP | |
3721 | */ | |
3722 | rp->fc4type |= FS_FC4TYPE_NVME; | |
3723 | found = 1; | |
3724 | break; | |
3725 | } | |
3726 | } | |
3727 | ||
3728 | /* We found new FC-NVMe only port */ | |
3729 | if (!found) { | |
3730 | for (k = 0; k < num_fibre_dev; k++) { | |
3731 | rp = &vha->scan.l[k]; | |
3732 | if (wwn_to_u64(rp->port_name)) { | |
3733 | continue; | |
3734 | } else { | |
3735 | rp->id = id; | |
3736 | memcpy(rp->port_name, | |
3737 | d->port_name, 8); | |
3738 | rp->fc4type = | |
3739 | FS_FC4TYPE_NVME; | |
3740 | break; | |
3741 | } | |
3742 | } | |
3743 | } | |
3744 | } else { | |
3745 | for (k = 0; k < num_fibre_dev; k++) { | |
3746 | rp = &vha->scan.l[k]; | |
3747 | if (id.b24 == rp->id.b24) { | |
3748 | memcpy(rp->node_name, | |
3749 | d->port_name, 8); | |
3750 | break; | |
3751 | } | |
3752 | } | |
3753 | } | |
3754 | } | |
3755 | } | |
3756 | } | |
3757 | ||
6c18a43e | 3758 | static void qla2x00_async_gpnft_gnnft_sp_done(srb_t *sp, int res) |
33b28357 | 3759 | { |
33b28357 | 3760 | struct scsi_qla_host *vha = sp->vha; |
33b28357 QT |
3761 | struct ct_sns_req *ct_req = |
3762 | (struct ct_sns_req *)sp->u.iocb_cmd.u.ctarg.req; | |
a4239945 | 3763 | u16 cmd = be16_to_cpu(ct_req->command); |
33b28357 QT |
3764 | u8 fc4_type = sp->gen2; |
3765 | unsigned long flags; | |
9ba1cb25 | 3766 | int rc; |
a4239945 QT |
3767 | |
3768 | /* gen2 field is holding the fc4type */ | |
3769 | ql_dbg(ql_dbg_disc, vha, 0xffff, | |
3770 | "Async done-%s res %x FC4Type %x\n", | |
3771 | sp->name, res, sp->gen2); | |
3772 | ||
9ba1cb25 | 3773 | sp->rc = res; |
cf055fb0 QT |
3774 | if (res) { |
3775 | unsigned long flags; | |
9ba1cb25 QT |
3776 | const char *name = sp->name; |
3777 | ||
10ae30ba QT |
3778 | if (res == QLA_OS_TIMER_EXPIRED) { |
3779 | /* switch is ignoring all commands. | |
3780 | * This might be a zone disable behavior. | |
3781 | * This means we hit 64s timeout. | |
3782 | * 22s GPNFT + 44s Abort = 64s | |
3783 | */ | |
3784 | ql_dbg(ql_dbg_disc, vha, 0xffff, | |
3785 | "%s: Switch Zone check please .\n", | |
3786 | name); | |
3787 | qla2x00_mark_all_devices_lost(vha); | |
3788 | } | |
3789 | ||
9ba1cb25 QT |
3790 | /* |
3791 | * We are in an Interrupt context, queue up this | |
3792 | * sp for GNNFT_DONE work. This will allow all | |
3793 | * the resource to get freed up. | |
3794 | */ | |
3795 | rc = qla2x00_post_gnnft_gpnft_done_work(vha, sp, | |
3796 | QLA_EVT_GNNFT_DONE); | |
3797 | if (rc) { | |
3798 | /* Cleanup here to prevent memory leak */ | |
3799 | qla24xx_sp_unmap(vha, sp); | |
cf055fb0 | 3800 | |
a110af85 QT |
3801 | spin_lock_irqsave(&vha->work_lock, flags); |
3802 | vha->scan.scan_flags &= ~SF_SCANNING; | |
3803 | vha->scan.scan_retry++; | |
3804 | spin_unlock_irqrestore(&vha->work_lock, flags); | |
6944dccb | 3805 | |
a110af85 QT |
3806 | if (vha->scan.scan_retry < MAX_SCAN_RETRIES) { |
3807 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); | |
3808 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); | |
3809 | qla2xxx_wake_dpc(vha); | |
3810 | } else { | |
3811 | ql_dbg(ql_dbg_disc, vha, 0xffff, | |
3812 | "Async done-%s rescan failed on all retries.\n", | |
3813 | name); | |
3814 | } | |
6944dccb | 3815 | } |
cf055fb0 QT |
3816 | return; |
3817 | } | |
3818 | ||
a110af85 | 3819 | qla2x00_find_free_fcp_nvme_slot(vha, sp); |
a4239945 | 3820 | |
33b28357 QT |
3821 | if ((fc4_type == FC4_TYPE_FCP_SCSI) && vha->flags.nvme_enabled && |
3822 | cmd == GNN_FT_CMD) { | |
33b28357 QT |
3823 | spin_lock_irqsave(&vha->work_lock, flags); |
3824 | vha->scan.scan_flags &= ~SF_SCANNING; | |
3825 | spin_unlock_irqrestore(&vha->work_lock, flags); | |
a4239945 | 3826 | |
9ba1cb25 | 3827 | sp->rc = res; |
a110af85 | 3828 | rc = qla2x00_post_nvme_gpnft_work(vha, sp, QLA_EVT_GPNFT); |
0aca7784 | 3829 | if (rc) { |
9ba1cb25 | 3830 | qla24xx_sp_unmap(vha, sp); |
33b28357 QT |
3831 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
3832 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); | |
a4239945 | 3833 | } |
0aca7784 | 3834 | return; |
a4239945 QT |
3835 | } |
3836 | ||
e112761a | 3837 | if (cmd == GPN_FT_CMD) { |
9ba1cb25 QT |
3838 | rc = qla2x00_post_gnnft_gpnft_done_work(vha, sp, |
3839 | QLA_EVT_GPNFT_DONE); | |
e112761a | 3840 | } else { |
9ba1cb25 QT |
3841 | rc = qla2x00_post_gnnft_gpnft_done_work(vha, sp, |
3842 | QLA_EVT_GNNFT_DONE); | |
e112761a QT |
3843 | } |
3844 | ||
9ba1cb25 QT |
3845 | if (rc) { |
3846 | qla24xx_sp_unmap(vha, sp); | |
cf055fb0 | 3847 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
a4239945 QT |
3848 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
3849 | return; | |
3850 | } | |
a4239945 QT |
3851 | } |
3852 | ||
3853 | /* | |
3854 | * Get WWNN list for fc4_type | |
3855 | * | |
3856 | * It is assumed the same SRB is re-used from GPNFT to avoid | |
3857 | * mem free & re-alloc | |
3858 | */ | |
3859 | static int qla24xx_async_gnnft(scsi_qla_host_t *vha, struct srb *sp, | |
3860 | u8 fc4_type) | |
3861 | { | |
3862 | int rval = QLA_FUNCTION_FAILED; | |
3863 | struct ct_sns_req *ct_req; | |
3864 | struct ct_sns_pkt *ct_sns; | |
33b28357 | 3865 | unsigned long flags; |
a4239945 | 3866 | |
f352eeb7 | 3867 | if (!vha->flags.online) { |
33b28357 | 3868 | spin_lock_irqsave(&vha->work_lock, flags); |
f352eeb7 | 3869 | vha->scan.scan_flags &= ~SF_SCANNING; |
33b28357 | 3870 | spin_unlock_irqrestore(&vha->work_lock, flags); |
a4239945 | 3871 | goto done_free_sp; |
f352eeb7 | 3872 | } |
a4239945 QT |
3873 | |
3874 | if (!sp->u.iocb_cmd.u.ctarg.req || !sp->u.iocb_cmd.u.ctarg.rsp) { | |
3875 | ql_log(ql_log_warn, vha, 0xffff, | |
3876 | "%s: req %p rsp %p are not setup\n", | |
3877 | __func__, sp->u.iocb_cmd.u.ctarg.req, | |
3878 | sp->u.iocb_cmd.u.ctarg.rsp); | |
33b28357 | 3879 | spin_lock_irqsave(&vha->work_lock, flags); |
f352eeb7 | 3880 | vha->scan.scan_flags &= ~SF_SCANNING; |
33b28357 | 3881 | spin_unlock_irqrestore(&vha->work_lock, flags); |
a4239945 | 3882 | WARN_ON(1); |
0aca7784 QT |
3883 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
3884 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); | |
a4239945 QT |
3885 | goto done_free_sp; |
3886 | } | |
33b28357 QT |
3887 | |
3888 | ql_dbg(ql_dbg_disc, vha, 0xfffff, | |
0b1b1d88 | 3889 | "%s: FC4Type %x, CT-PASSTHRU %s command ctarg rsp size %d, ctarg req size %d\n", |
33b28357 QT |
3890 | __func__, fc4_type, sp->name, sp->u.iocb_cmd.u.ctarg.rsp_size, |
3891 | sp->u.iocb_cmd.u.ctarg.req_size); | |
3892 | ||
a4239945 QT |
3893 | sp->type = SRB_CT_PTHRU_CMD; |
3894 | sp->name = "gnnft"; | |
3895 | sp->gen1 = vha->hw->base_qpair->chip_reset; | |
3896 | sp->gen2 = fc4_type; | |
75a1d041 DW |
3897 | qla2x00_init_async_sp(sp, qla2x00_get_async_timeout(vha) + 2, |
3898 | qla2x00_async_gpnft_gnnft_sp_done); | |
a4239945 QT |
3899 | |
3900 | memset(sp->u.iocb_cmd.u.ctarg.rsp, 0, sp->u.iocb_cmd.u.ctarg.rsp_size); | |
3901 | memset(sp->u.iocb_cmd.u.ctarg.req, 0, sp->u.iocb_cmd.u.ctarg.req_size); | |
3902 | ||
3903 | ct_sns = (struct ct_sns_pkt *)sp->u.iocb_cmd.u.ctarg.req; | |
3904 | /* CT_IU preamble */ | |
3905 | ct_req = qla2x00_prep_ct_req(ct_sns, GNN_FT_CMD, | |
3906 | sp->u.iocb_cmd.u.ctarg.rsp_size); | |
3907 | ||
3908 | /* GPN_FT req */ | |
3909 | ct_req->req.gpn_ft.port_type = fc4_type; | |
3910 | ||
3911 | sp->u.iocb_cmd.u.ctarg.req_size = GNN_FT_REQ_SIZE; | |
3912 | sp->u.iocb_cmd.u.ctarg.nport_handle = NPH_SNS; | |
3913 | ||
f233e8c0 BK |
3914 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
3915 | "Async-%s hdl=%x FC4Type %x.\n", sp->name, | |
3916 | sp->handle, ct_req->req.gpn_ft.port_type); | |
3917 | ||
a4239945 | 3918 | rval = qla2x00_start_sp(sp); |
0aca7784 | 3919 | if (rval != QLA_SUCCESS) { |
a4239945 | 3920 | goto done_free_sp; |
0aca7784 | 3921 | } |
a4239945 | 3922 | |
a4239945 QT |
3923 | return rval; |
3924 | ||
3925 | done_free_sp: | |
3926 | if (sp->u.iocb_cmd.u.ctarg.req) { | |
3927 | dma_free_coherent(&vha->hw->pdev->dev, | |
b5f3bc39 | 3928 | sp->u.iocb_cmd.u.ctarg.req_allocated_size, |
a4239945 QT |
3929 | sp->u.iocb_cmd.u.ctarg.req, |
3930 | sp->u.iocb_cmd.u.ctarg.req_dma); | |
3931 | sp->u.iocb_cmd.u.ctarg.req = NULL; | |
3932 | } | |
3933 | if (sp->u.iocb_cmd.u.ctarg.rsp) { | |
3934 | dma_free_coherent(&vha->hw->pdev->dev, | |
b5f3bc39 | 3935 | sp->u.iocb_cmd.u.ctarg.rsp_allocated_size, |
a4239945 QT |
3936 | sp->u.iocb_cmd.u.ctarg.rsp, |
3937 | sp->u.iocb_cmd.u.ctarg.rsp_dma); | |
3938 | sp->u.iocb_cmd.u.ctarg.rsp = NULL; | |
3939 | } | |
ee7bd382 SK |
3940 | /* ref: INIT */ |
3941 | kref_put(&sp->cmd_kref, qla2x00_sp_release); | |
a4239945 | 3942 | |
f0cecc1e QT |
3943 | spin_lock_irqsave(&vha->work_lock, flags); |
3944 | vha->scan.scan_flags &= ~SF_SCANNING; | |
3945 | if (vha->scan.scan_flags == 0) { | |
3946 | ql_dbg(ql_dbg_disc, vha, 0xffff, | |
3947 | "%s: schedule\n", __func__); | |
3948 | vha->scan.scan_flags |= SF_QUEUED; | |
3949 | schedule_delayed_work(&vha->scan.scan_work, 5); | |
3950 | } | |
3951 | spin_unlock_irqrestore(&vha->work_lock, flags); | |
3952 | ||
3953 | ||
a4239945 QT |
3954 | return rval; |
3955 | } /* GNNFT */ | |
3956 | ||
3957 | void qla24xx_async_gpnft_done(scsi_qla_host_t *vha, srb_t *sp) | |
3958 | { | |
45c96e44 | 3959 | ql_dbg(ql_dbg_disc + ql_dbg_verbose, vha, 0xffff, |
a4239945 | 3960 | "%s enter\n", __func__); |
a4239945 QT |
3961 | qla24xx_async_gnnft(vha, sp, sp->gen2); |
3962 | } | |
3963 | ||
3964 | /* Get WWPN list for certain fc4_type */ | |
33b28357 | 3965 | int qla24xx_async_gpnft(scsi_qla_host_t *vha, u8 fc4_type, srb_t *sp) |
a4239945 QT |
3966 | { |
3967 | int rval = QLA_FUNCTION_FAILED; | |
3968 | struct ct_sns_req *ct_req; | |
a4239945 QT |
3969 | struct ct_sns_pkt *ct_sns; |
3970 | u32 rspsz; | |
f352eeb7 | 3971 | unsigned long flags; |
a4239945 | 3972 | |
45c96e44 | 3973 | ql_dbg(ql_dbg_disc + ql_dbg_verbose, vha, 0xffff, |
33b28357 QT |
3974 | "%s enter\n", __func__); |
3975 | ||
a4239945 QT |
3976 | if (!vha->flags.online) |
3977 | return rval; | |
3978 | ||
f352eeb7 QT |
3979 | spin_lock_irqsave(&vha->work_lock, flags); |
3980 | if (vha->scan.scan_flags & SF_SCANNING) { | |
3981 | spin_unlock_irqrestore(&vha->work_lock, flags); | |
45c96e44 HM |
3982 | ql_dbg(ql_dbg_disc + ql_dbg_verbose, vha, 0xffff, |
3983 | "%s: scan active\n", __func__); | |
a4239945 | 3984 | return rval; |
f352eeb7 QT |
3985 | } |
3986 | vha->scan.scan_flags |= SF_SCANNING; | |
3987 | spin_unlock_irqrestore(&vha->work_lock, flags); | |
a4239945 | 3988 | |
33b28357 | 3989 | if (fc4_type == FC4_TYPE_FCP_SCSI) { |
45c96e44 | 3990 | ql_dbg(ql_dbg_disc + ql_dbg_verbose, vha, 0xffff, |
33b28357 QT |
3991 | "%s: Performing FCP Scan\n", __func__); |
3992 | ||
ee7bd382 SK |
3993 | if (sp) { |
3994 | /* ref: INIT */ | |
3995 | kref_put(&sp->cmd_kref, qla2x00_sp_release); | |
3996 | } | |
33b28357 | 3997 | |
ee7bd382 | 3998 | /* ref: INIT */ |
33b28357 QT |
3999 | sp = qla2x00_get_sp(vha, NULL, GFP_KERNEL); |
4000 | if (!sp) { | |
4001 | spin_lock_irqsave(&vha->work_lock, flags); | |
4002 | vha->scan.scan_flags &= ~SF_SCANNING; | |
4003 | spin_unlock_irqrestore(&vha->work_lock, flags); | |
4004 | return rval; | |
4005 | } | |
4006 | ||
750afb08 LC |
4007 | sp->u.iocb_cmd.u.ctarg.req = dma_alloc_coherent(&vha->hw->pdev->dev, |
4008 | sizeof(struct ct_sns_pkt), | |
4009 | &sp->u.iocb_cmd.u.ctarg.req_dma, | |
4010 | GFP_KERNEL); | |
b5f3bc39 | 4011 | sp->u.iocb_cmd.u.ctarg.req_allocated_size = sizeof(struct ct_sns_pkt); |
33b28357 QT |
4012 | if (!sp->u.iocb_cmd.u.ctarg.req) { |
4013 | ql_log(ql_log_warn, vha, 0xffff, | |
4014 | "Failed to allocate ct_sns request.\n"); | |
4015 | spin_lock_irqsave(&vha->work_lock, flags); | |
4016 | vha->scan.scan_flags &= ~SF_SCANNING; | |
4017 | spin_unlock_irqrestore(&vha->work_lock, flags); | |
5e85f6df QT |
4018 | qla2x00_rel_sp(sp); |
4019 | return rval; | |
33b28357 QT |
4020 | } |
4021 | sp->u.iocb_cmd.u.ctarg.req_size = GPN_FT_REQ_SIZE; | |
4022 | ||
4023 | rspsz = sizeof(struct ct_sns_gpnft_rsp) + | |
4024 | ((vha->hw->max_fibre_devices - 1) * | |
4025 | sizeof(struct ct_sns_gpn_ft_data)); | |
4026 | ||
750afb08 LC |
4027 | sp->u.iocb_cmd.u.ctarg.rsp = dma_alloc_coherent(&vha->hw->pdev->dev, |
4028 | rspsz, | |
4029 | &sp->u.iocb_cmd.u.ctarg.rsp_dma, | |
4030 | GFP_KERNEL); | |
d376dbda | 4031 | sp->u.iocb_cmd.u.ctarg.rsp_allocated_size = rspsz; |
33b28357 QT |
4032 | if (!sp->u.iocb_cmd.u.ctarg.rsp) { |
4033 | ql_log(ql_log_warn, vha, 0xffff, | |
4034 | "Failed to allocate ct_sns request.\n"); | |
4035 | spin_lock_irqsave(&vha->work_lock, flags); | |
4036 | vha->scan.scan_flags &= ~SF_SCANNING; | |
4037 | spin_unlock_irqrestore(&vha->work_lock, flags); | |
5e85f6df QT |
4038 | dma_free_coherent(&vha->hw->pdev->dev, |
4039 | sp->u.iocb_cmd.u.ctarg.req_allocated_size, | |
4040 | sp->u.iocb_cmd.u.ctarg.req, | |
4041 | sp->u.iocb_cmd.u.ctarg.req_dma); | |
4042 | sp->u.iocb_cmd.u.ctarg.req = NULL; | |
ee7bd382 | 4043 | /* ref: INIT */ |
5e85f6df QT |
4044 | qla2x00_rel_sp(sp); |
4045 | return rval; | |
33b28357 QT |
4046 | } |
4047 | sp->u.iocb_cmd.u.ctarg.rsp_size = rspsz; | |
4048 | ||
45c96e44 | 4049 | ql_dbg(ql_dbg_disc + ql_dbg_verbose, vha, 0xffff, |
33b28357 QT |
4050 | "%s scan list size %d\n", __func__, vha->scan.size); |
4051 | ||
4052 | memset(vha->scan.l, 0, vha->scan.size); | |
4053 | } else if (!sp) { | |
4054 | ql_dbg(ql_dbg_disc, vha, 0xffff, | |
4055 | "NVME scan did not provide SP\n"); | |
f352eeb7 QT |
4056 | return rval; |
4057 | } | |
a4239945 QT |
4058 | |
4059 | sp->type = SRB_CT_PTHRU_CMD; | |
4060 | sp->name = "gpnft"; | |
4061 | sp->gen1 = vha->hw->base_qpair->chip_reset; | |
4062 | sp->gen2 = fc4_type; | |
75a1d041 DW |
4063 | qla2x00_init_async_sp(sp, qla2x00_get_async_timeout(vha) + 2, |
4064 | qla2x00_async_gpnft_gnnft_sp_done); | |
a4239945 | 4065 | |
732ee9a9 QT |
4066 | rspsz = sp->u.iocb_cmd.u.ctarg.rsp_size; |
4067 | memset(sp->u.iocb_cmd.u.ctarg.rsp, 0, sp->u.iocb_cmd.u.ctarg.rsp_size); | |
4068 | memset(sp->u.iocb_cmd.u.ctarg.req, 0, sp->u.iocb_cmd.u.ctarg.req_size); | |
a4239945 | 4069 | |
a4239945 QT |
4070 | ct_sns = (struct ct_sns_pkt *)sp->u.iocb_cmd.u.ctarg.req; |
4071 | /* CT_IU preamble */ | |
4072 | ct_req = qla2x00_prep_ct_req(ct_sns, GPN_FT_CMD, rspsz); | |
4073 | ||
4074 | /* GPN_FT req */ | |
4075 | ct_req->req.gpn_ft.port_type = fc4_type; | |
4076 | ||
a4239945 QT |
4077 | sp->u.iocb_cmd.u.ctarg.nport_handle = NPH_SNS; |
4078 | ||
f233e8c0 BK |
4079 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
4080 | "Async-%s hdl=%x FC4Type %x.\n", sp->name, | |
4081 | sp->handle, ct_req->req.gpn_ft.port_type); | |
4082 | ||
a4239945 | 4083 | rval = qla2x00_start_sp(sp); |
f352eeb7 | 4084 | if (rval != QLA_SUCCESS) { |
a4239945 | 4085 | goto done_free_sp; |
f352eeb7 | 4086 | } |
a4239945 | 4087 | |
a4239945 QT |
4088 | return rval; |
4089 | ||
4090 | done_free_sp: | |
4091 | if (sp->u.iocb_cmd.u.ctarg.req) { | |
4092 | dma_free_coherent(&vha->hw->pdev->dev, | |
b5f3bc39 | 4093 | sp->u.iocb_cmd.u.ctarg.req_allocated_size, |
a4239945 QT |
4094 | sp->u.iocb_cmd.u.ctarg.req, |
4095 | sp->u.iocb_cmd.u.ctarg.req_dma); | |
4096 | sp->u.iocb_cmd.u.ctarg.req = NULL; | |
4097 | } | |
4098 | if (sp->u.iocb_cmd.u.ctarg.rsp) { | |
4099 | dma_free_coherent(&vha->hw->pdev->dev, | |
b5f3bc39 | 4100 | sp->u.iocb_cmd.u.ctarg.rsp_allocated_size, |
a4239945 QT |
4101 | sp->u.iocb_cmd.u.ctarg.rsp, |
4102 | sp->u.iocb_cmd.u.ctarg.rsp_dma); | |
4103 | sp->u.iocb_cmd.u.ctarg.rsp = NULL; | |
4104 | } | |
4105 | ||
ee7bd382 SK |
4106 | /* ref: INIT */ |
4107 | kref_put(&sp->cmd_kref, qla2x00_sp_release); | |
a4239945 | 4108 | |
f0cecc1e QT |
4109 | spin_lock_irqsave(&vha->work_lock, flags); |
4110 | vha->scan.scan_flags &= ~SF_SCANNING; | |
4111 | if (vha->scan.scan_flags == 0) { | |
45c96e44 HM |
4112 | ql_dbg(ql_dbg_disc + ql_dbg_verbose, vha, 0xffff, |
4113 | "%s: Scan scheduled.\n", __func__); | |
f0cecc1e QT |
4114 | vha->scan.scan_flags |= SF_QUEUED; |
4115 | schedule_delayed_work(&vha->scan.scan_work, 5); | |
4116 | } | |
4117 | spin_unlock_irqrestore(&vha->work_lock, flags); | |
4118 | ||
4119 | ||
a4239945 QT |
4120 | return rval; |
4121 | } | |
4122 | ||
f352eeb7 QT |
4123 | void qla_scan_work_fn(struct work_struct *work) |
4124 | { | |
4125 | struct fab_scan *s = container_of(to_delayed_work(work), | |
4126 | struct fab_scan, scan_work); | |
4127 | struct scsi_qla_host *vha = container_of(s, struct scsi_qla_host, | |
4128 | scan); | |
4129 | unsigned long flags; | |
4130 | ||
4131 | ql_dbg(ql_dbg_disc, vha, 0xffff, | |
4132 | "%s: schedule loop resync\n", __func__); | |
4133 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); | |
4134 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); | |
4135 | qla2xxx_wake_dpc(vha); | |
4136 | spin_lock_irqsave(&vha->work_lock, flags); | |
4137 | vha->scan.scan_flags &= ~SF_QUEUED; | |
4138 | spin_unlock_irqrestore(&vha->work_lock, flags); | |
4139 | } | |
4140 | ||
a4239945 QT |
4141 | /* GNN_ID */ |
4142 | void qla24xx_handle_gnnid_event(scsi_qla_host_t *vha, struct event_arg *ea) | |
4143 | { | |
4144 | qla24xx_post_gnl_work(vha, ea->fcport); | |
4145 | } | |
4146 | ||
6c18a43e | 4147 | static void qla2x00_async_gnnid_sp_done(srb_t *sp, int res) |
a4239945 | 4148 | { |
a4239945 QT |
4149 | struct scsi_qla_host *vha = sp->vha; |
4150 | fc_port_t *fcport = sp->fcport; | |
4151 | u8 *node_name = fcport->ct_desc.ct_sns->p.rsp.rsp.gnn_id.node_name; | |
4152 | struct event_arg ea; | |
4153 | u64 wwnn; | |
4154 | ||
4155 | fcport->flags &= ~FCF_ASYNC_SENT; | |
4156 | wwnn = wwn_to_u64(node_name); | |
4157 | if (wwnn) | |
4158 | memcpy(fcport->node_name, node_name, WWN_SIZE); | |
4159 | ||
4160 | memset(&ea, 0, sizeof(ea)); | |
4161 | ea.fcport = fcport; | |
4162 | ea.sp = sp; | |
4163 | ea.rc = res; | |
a4239945 QT |
4164 | |
4165 | ql_dbg(ql_dbg_disc, vha, 0x204f, | |
4166 | "Async done-%s res %x, WWPN %8phC %8phC\n", | |
4167 | sp->name, res, fcport->port_name, fcport->node_name); | |
4168 | ||
897def20 | 4169 | qla24xx_handle_gnnid_event(vha, &ea); |
a4239945 | 4170 | |
ee7bd382 SK |
4171 | /* ref: INIT */ |
4172 | kref_put(&sp->cmd_kref, qla2x00_sp_release); | |
a4239945 QT |
4173 | } |
4174 | ||
4175 | int qla24xx_async_gnnid(scsi_qla_host_t *vha, fc_port_t *fcport) | |
4176 | { | |
4177 | int rval = QLA_FUNCTION_FAILED; | |
4178 | struct ct_sns_req *ct_req; | |
4179 | srb_t *sp; | |
4180 | ||
3dbec59b QT |
4181 | if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT)) |
4182 | return rval; | |
a4239945 | 4183 | |
27258a57 | 4184 | qla2x00_set_fcport_disc_state(fcport, DSC_GNN_ID); |
ee7bd382 | 4185 | /* ref: INIT */ |
a4239945 QT |
4186 | sp = qla2x00_get_sp(vha, fcport, GFP_ATOMIC); |
4187 | if (!sp) | |
4188 | goto done; | |
4189 | ||
3dbec59b | 4190 | fcport->flags |= FCF_ASYNC_SENT; |
a4239945 QT |
4191 | sp->type = SRB_CT_PTHRU_CMD; |
4192 | sp->name = "gnnid"; | |
4193 | sp->gen1 = fcport->rscn_gen; | |
4194 | sp->gen2 = fcport->login_gen; | |
75a1d041 DW |
4195 | qla2x00_init_async_sp(sp, qla2x00_get_async_timeout(vha) + 2, |
4196 | qla2x00_async_gnnid_sp_done); | |
a4239945 QT |
4197 | |
4198 | /* CT_IU preamble */ | |
4199 | ct_req = qla2x00_prep_ct_req(fcport->ct_desc.ct_sns, GNN_ID_CMD, | |
4200 | GNN_ID_RSP_SIZE); | |
4201 | ||
4202 | /* GNN_ID req */ | |
df95f39a | 4203 | ct_req->req.port_id.port_id = port_id_to_be_id(fcport->d_id); |
a4239945 QT |
4204 | |
4205 | ||
4206 | /* req & rsp use the same buffer */ | |
4207 | sp->u.iocb_cmd.u.ctarg.req = fcport->ct_desc.ct_sns; | |
4208 | sp->u.iocb_cmd.u.ctarg.req_dma = fcport->ct_desc.ct_sns_dma; | |
4209 | sp->u.iocb_cmd.u.ctarg.rsp = fcport->ct_desc.ct_sns; | |
4210 | sp->u.iocb_cmd.u.ctarg.rsp_dma = fcport->ct_desc.ct_sns_dma; | |
4211 | sp->u.iocb_cmd.u.ctarg.req_size = GNN_ID_REQ_SIZE; | |
4212 | sp->u.iocb_cmd.u.ctarg.rsp_size = GNN_ID_RSP_SIZE; | |
4213 | sp->u.iocb_cmd.u.ctarg.nport_handle = NPH_SNS; | |
4214 | ||
a4239945 QT |
4215 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
4216 | "Async-%s - %8phC hdl=%x loopid=%x portid %06x.\n", | |
4217 | sp->name, fcport->port_name, | |
4218 | sp->handle, fcport->loop_id, fcport->d_id.b24); | |
f233e8c0 BK |
4219 | |
4220 | rval = qla2x00_start_sp(sp); | |
4221 | if (rval != QLA_SUCCESS) | |
4222 | goto done_free_sp; | |
a4239945 QT |
4223 | return rval; |
4224 | ||
4225 | done_free_sp: | |
ee7bd382 SK |
4226 | /* ref: INIT */ |
4227 | kref_put(&sp->cmd_kref, qla2x00_sp_release); | |
0257eda0 | 4228 | fcport->flags &= ~FCF_ASYNC_SENT; |
3dbec59b | 4229 | done: |
a4239945 QT |
4230 | return rval; |
4231 | } | |
4232 | ||
4233 | int qla24xx_post_gnnid_work(struct scsi_qla_host *vha, fc_port_t *fcport) | |
4234 | { | |
4235 | struct qla_work_evt *e; | |
4236 | int ls; | |
4237 | ||
4238 | ls = atomic_read(&vha->loop_state); | |
4239 | if (((ls != LOOP_READY) && (ls != LOOP_UP)) || | |
4240 | test_bit(UNLOADING, &vha->dpc_flags)) | |
4241 | return 0; | |
4242 | ||
4243 | e = qla2x00_alloc_work(vha, QLA_EVT_GNNID); | |
4244 | if (!e) | |
4245 | return QLA_FUNCTION_FAILED; | |
4246 | ||
4247 | e->u.fcport.fcport = fcport; | |
4248 | return qla2x00_post_work(vha, e); | |
4249 | } | |
4250 | ||
4251 | /* GPFN_ID */ | |
4252 | void qla24xx_handle_gfpnid_event(scsi_qla_host_t *vha, struct event_arg *ea) | |
4253 | { | |
4254 | fc_port_t *fcport = ea->fcport; | |
4255 | ||
4256 | ql_dbg(ql_dbg_disc, vha, 0xffff, | |
f352eeb7 QT |
4257 | "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d fcpcnt %d\n", |
4258 | __func__, fcport->port_name, fcport->disc_state, | |
4259 | fcport->fw_login_state, ea->rc, fcport->login_gen, ea->sp->gen2, | |
4260 | fcport->rscn_gen, ea->sp->gen1, vha->fcport_count); | |
a4239945 QT |
4261 | |
4262 | if (fcport->disc_state == DSC_DELETE_PEND) | |
4263 | return; | |
4264 | ||
4265 | if (ea->sp->gen2 != fcport->login_gen) { | |
4266 | /* target side must have changed it. */ | |
4267 | ql_dbg(ql_dbg_disc, vha, 0x20d3, | |
f352eeb7 QT |
4268 | "%s %8phC generation changed\n", |
4269 | __func__, fcport->port_name); | |
a4239945 QT |
4270 | return; |
4271 | } else if (ea->sp->gen1 != fcport->rscn_gen) { | |
a4239945 QT |
4272 | return; |
4273 | } | |
4274 | ||
4275 | qla24xx_post_gpsc_work(vha, fcport); | |
4276 | } | |
4277 | ||
6c18a43e | 4278 | static void qla2x00_async_gfpnid_sp_done(srb_t *sp, int res) |
a4239945 | 4279 | { |
a4239945 QT |
4280 | struct scsi_qla_host *vha = sp->vha; |
4281 | fc_port_t *fcport = sp->fcport; | |
4282 | u8 *fpn = fcport->ct_desc.ct_sns->p.rsp.rsp.gfpn_id.port_name; | |
4283 | struct event_arg ea; | |
4284 | u64 wwn; | |
4285 | ||
a4239945 QT |
4286 | wwn = wwn_to_u64(fpn); |
4287 | if (wwn) | |
4288 | memcpy(fcport->fabric_port_name, fpn, WWN_SIZE); | |
4289 | ||
4290 | memset(&ea, 0, sizeof(ea)); | |
4291 | ea.fcport = fcport; | |
4292 | ea.sp = sp; | |
4293 | ea.rc = res; | |
a4239945 QT |
4294 | |
4295 | ql_dbg(ql_dbg_disc, vha, 0x204f, | |
4296 | "Async done-%s res %x, WWPN %8phC %8phC\n", | |
4297 | sp->name, res, fcport->port_name, fcport->fabric_port_name); | |
4298 | ||
897def20 | 4299 | qla24xx_handle_gfpnid_event(vha, &ea); |
a4239945 | 4300 | |
ee7bd382 SK |
4301 | /* ref: INIT */ |
4302 | kref_put(&sp->cmd_kref, qla2x00_sp_release); | |
a4239945 QT |
4303 | } |
4304 | ||
4305 | int qla24xx_async_gfpnid(scsi_qla_host_t *vha, fc_port_t *fcport) | |
4306 | { | |
4307 | int rval = QLA_FUNCTION_FAILED; | |
4308 | struct ct_sns_req *ct_req; | |
4309 | srb_t *sp; | |
4310 | ||
3dbec59b QT |
4311 | if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT)) |
4312 | return rval; | |
a4239945 | 4313 | |
ee7bd382 | 4314 | /* ref: INIT */ |
a4239945 QT |
4315 | sp = qla2x00_get_sp(vha, fcport, GFP_ATOMIC); |
4316 | if (!sp) | |
4317 | goto done; | |
4318 | ||
4319 | sp->type = SRB_CT_PTHRU_CMD; | |
4320 | sp->name = "gfpnid"; | |
4321 | sp->gen1 = fcport->rscn_gen; | |
4322 | sp->gen2 = fcport->login_gen; | |
75a1d041 DW |
4323 | qla2x00_init_async_sp(sp, qla2x00_get_async_timeout(vha) + 2, |
4324 | qla2x00_async_gfpnid_sp_done); | |
a4239945 QT |
4325 | |
4326 | /* CT_IU preamble */ | |
4327 | ct_req = qla2x00_prep_ct_req(fcport->ct_desc.ct_sns, GFPN_ID_CMD, | |
4328 | GFPN_ID_RSP_SIZE); | |
4329 | ||
4330 | /* GFPN_ID req */ | |
df95f39a | 4331 | ct_req->req.port_id.port_id = port_id_to_be_id(fcport->d_id); |
a4239945 QT |
4332 | |
4333 | ||
4334 | /* req & rsp use the same buffer */ | |
4335 | sp->u.iocb_cmd.u.ctarg.req = fcport->ct_desc.ct_sns; | |
4336 | sp->u.iocb_cmd.u.ctarg.req_dma = fcport->ct_desc.ct_sns_dma; | |
4337 | sp->u.iocb_cmd.u.ctarg.rsp = fcport->ct_desc.ct_sns; | |
4338 | sp->u.iocb_cmd.u.ctarg.rsp_dma = fcport->ct_desc.ct_sns_dma; | |
4339 | sp->u.iocb_cmd.u.ctarg.req_size = GFPN_ID_REQ_SIZE; | |
4340 | sp->u.iocb_cmd.u.ctarg.rsp_size = GFPN_ID_RSP_SIZE; | |
4341 | sp->u.iocb_cmd.u.ctarg.nport_handle = NPH_SNS; | |
4342 | ||
a4239945 QT |
4343 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
4344 | "Async-%s - %8phC hdl=%x loopid=%x portid %06x.\n", | |
4345 | sp->name, fcport->port_name, | |
4346 | sp->handle, fcport->loop_id, fcport->d_id.b24); | |
f233e8c0 BK |
4347 | |
4348 | rval = qla2x00_start_sp(sp); | |
4349 | if (rval != QLA_SUCCESS) | |
4350 | goto done_free_sp; | |
4351 | ||
a4239945 QT |
4352 | return rval; |
4353 | ||
4354 | done_free_sp: | |
ee7bd382 SK |
4355 | /* ref: INIT */ |
4356 | kref_put(&sp->cmd_kref, qla2x00_sp_release); | |
3dbec59b | 4357 | done: |
a4239945 QT |
4358 | return rval; |
4359 | } | |
4360 | ||
4361 | int qla24xx_post_gfpnid_work(struct scsi_qla_host *vha, fc_port_t *fcport) | |
4362 | { | |
4363 | struct qla_work_evt *e; | |
4364 | int ls; | |
4365 | ||
4366 | ls = atomic_read(&vha->loop_state); | |
4367 | if (((ls != LOOP_READY) && (ls != LOOP_UP)) || | |
4368 | test_bit(UNLOADING, &vha->dpc_flags)) | |
4369 | return 0; | |
4370 | ||
4371 | e = qla2x00_alloc_work(vha, QLA_EVT_GFPNID); | |
4372 | if (!e) | |
4373 | return QLA_FUNCTION_FAILED; | |
4374 | ||
4375 | e->u.fcport.fcport = fcport; | |
4376 | return qla2x00_post_work(vha, e); | |
4377 | } |