x86, cpufeature: If we disable CLFLUSH, we should disable CLFLUSHOPT
[linux/fpc-iii.git] / drivers / scsi / qla2xxx / qla_gs.c
blobcd47f1b32d9ae4ab237debf52647fad210b98bee
1 /*
2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2013 QLogic Corporation
5 * See LICENSE.qla2xxx for copyright and licensing details.
6 */
7 #include "qla_def.h"
8 #include "qla_target.h"
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 *);
17 /**
18 * qla2x00_prep_ms_iocb() - Prepare common MS/CT IOCB fields for SNS CT query.
19 * @ha: HA context
20 * @req_size: request size in bytes
21 * @rsp_size: response size in bytes
23 * Returns a pointer to the @ha's ms_iocb.
25 void *
26 qla2x00_prep_ms_iocb(scsi_qla_host_t *vha, uint32_t req_size, uint32_t rsp_size)
28 struct qla_hw_data *ha = vha->hw;
29 ms_iocb_entry_t *ms_pkt;
31 ms_pkt = ha->ms_iocb;
32 memset(ms_pkt, 0, sizeof(ms_iocb_entry_t));
34 ms_pkt->entry_type = MS_IOCB_TYPE;
35 ms_pkt->entry_count = 1;
36 SET_TARGET_ID(ha, ms_pkt->loop_id, SIMPLE_NAME_SERVER);
37 ms_pkt->control_flags = __constant_cpu_to_le16(CF_READ | CF_HEAD_TAG);
38 ms_pkt->timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
39 ms_pkt->cmd_dsd_count = __constant_cpu_to_le16(1);
40 ms_pkt->total_dsd_count = __constant_cpu_to_le16(2);
41 ms_pkt->rsp_bytecount = cpu_to_le32(rsp_size);
42 ms_pkt->req_bytecount = cpu_to_le32(req_size);
44 ms_pkt->dseg_req_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
45 ms_pkt->dseg_req_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
46 ms_pkt->dseg_req_length = ms_pkt->req_bytecount;
48 ms_pkt->dseg_rsp_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
49 ms_pkt->dseg_rsp_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
50 ms_pkt->dseg_rsp_length = ms_pkt->rsp_bytecount;
52 vha->qla_stats.control_requests++;
54 return (ms_pkt);
57 /**
58 * qla24xx_prep_ms_iocb() - Prepare common CT IOCB fields for SNS CT query.
59 * @ha: HA context
60 * @req_size: request size in bytes
61 * @rsp_size: response size in bytes
63 * Returns a pointer to the @ha's ms_iocb.
65 void *
66 qla24xx_prep_ms_iocb(scsi_qla_host_t *vha, uint32_t req_size, uint32_t rsp_size)
68 struct qla_hw_data *ha = vha->hw;
69 struct ct_entry_24xx *ct_pkt;
71 ct_pkt = (struct ct_entry_24xx *)ha->ms_iocb;
72 memset(ct_pkt, 0, sizeof(struct ct_entry_24xx));
74 ct_pkt->entry_type = CT_IOCB_TYPE;
75 ct_pkt->entry_count = 1;
76 ct_pkt->nport_handle = __constant_cpu_to_le16(NPH_SNS);
77 ct_pkt->timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
78 ct_pkt->cmd_dsd_count = __constant_cpu_to_le16(1);
79 ct_pkt->rsp_dsd_count = __constant_cpu_to_le16(1);
80 ct_pkt->rsp_byte_count = cpu_to_le32(rsp_size);
81 ct_pkt->cmd_byte_count = cpu_to_le32(req_size);
83 ct_pkt->dseg_0_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
84 ct_pkt->dseg_0_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
85 ct_pkt->dseg_0_len = ct_pkt->cmd_byte_count;
87 ct_pkt->dseg_1_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
88 ct_pkt->dseg_1_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
89 ct_pkt->dseg_1_len = ct_pkt->rsp_byte_count;
90 ct_pkt->vp_index = vha->vp_idx;
92 vha->qla_stats.control_requests++;
94 return (ct_pkt);
97 /**
98 * qla2x00_prep_ct_req() - Prepare common CT request fields for SNS query.
99 * @ct_req: CT request buffer
100 * @cmd: GS command
101 * @rsp_size: response size in bytes
103 * Returns a pointer to the intitialized @ct_req.
105 static inline struct ct_sns_req *
106 qla2x00_prep_ct_req(struct ct_sns_pkt *p, uint16_t cmd, uint16_t rsp_size)
108 memset(p, 0, sizeof(struct ct_sns_pkt));
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);
116 return &p->p.req;
119 static int
120 qla2x00_chk_ms_status(scsi_qla_host_t *vha, ms_iocb_entry_t *ms_pkt,
121 struct ct_sns_rsp *ct_rsp, const char *routine)
123 int rval;
124 uint16_t comp_status;
125 struct qla_hw_data *ha = vha->hw;
127 rval = QLA_FUNCTION_FAILED;
128 if (ms_pkt->entry_status != 0) {
129 ql_dbg(ql_dbg_disc, vha, 0x2031,
130 "%s failed, error status (%x) on port_id: %02x%02x%02x.\n",
131 routine, ms_pkt->entry_status, vha->d_id.b.domain,
132 vha->d_id.b.area, vha->d_id.b.al_pa);
133 } else {
134 if (IS_FWI2_CAPABLE(ha))
135 comp_status = le16_to_cpu(
136 ((struct ct_entry_24xx *)ms_pkt)->comp_status);
137 else
138 comp_status = le16_to_cpu(ms_pkt->status);
139 switch (comp_status) {
140 case CS_COMPLETE:
141 case CS_DATA_UNDERRUN:
142 case CS_DATA_OVERRUN: /* Overrun? */
143 if (ct_rsp->header.response !=
144 __constant_cpu_to_be16(CT_ACCEPT_RESPONSE)) {
145 ql_dbg(ql_dbg_disc + ql_dbg_buffer, vha, 0x2077,
146 "%s failed rejected request on port_id: "
147 "%02x%02x%02x.\n", routine,
148 vha->d_id.b.domain, vha->d_id.b.area,
149 vha->d_id.b.al_pa);
150 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha,
151 0x2078, (uint8_t *)&ct_rsp->header,
152 sizeof(struct ct_rsp_hdr));
153 rval = QLA_INVALID_COMMAND;
154 } else
155 rval = QLA_SUCCESS;
156 break;
157 default:
158 ql_dbg(ql_dbg_disc, vha, 0x2033,
159 "%s failed, completion status (%x) on port_id: "
160 "%02x%02x%02x.\n", routine, comp_status,
161 vha->d_id.b.domain, vha->d_id.b.area,
162 vha->d_id.b.al_pa);
163 break;
166 return rval;
170 * qla2x00_ga_nxt() - SNS scan for fabric devices via GA_NXT command.
171 * @ha: HA context
172 * @fcport: fcport entry to updated
174 * Returns 0 on success.
177 qla2x00_ga_nxt(scsi_qla_host_t *vha, fc_port_t *fcport)
179 int rval;
181 ms_iocb_entry_t *ms_pkt;
182 struct ct_sns_req *ct_req;
183 struct ct_sns_rsp *ct_rsp;
184 struct qla_hw_data *ha = vha->hw;
186 if (IS_QLA2100(ha) || IS_QLA2200(ha))
187 return qla2x00_sns_ga_nxt(vha, fcport);
189 /* Issue GA_NXT */
190 /* Prepare common MS IOCB */
191 ms_pkt = ha->isp_ops->prep_ms_iocb(vha, GA_NXT_REQ_SIZE,
192 GA_NXT_RSP_SIZE);
194 /* Prepare CT request */
195 ct_req = qla2x00_prep_ct_req(ha->ct_sns, GA_NXT_CMD,
196 GA_NXT_RSP_SIZE);
197 ct_rsp = &ha->ct_sns->p.rsp;
199 /* Prepare CT arguments -- port_id */
200 ct_req->req.port_id.port_id[0] = fcport->d_id.b.domain;
201 ct_req->req.port_id.port_id[1] = fcport->d_id.b.area;
202 ct_req->req.port_id.port_id[2] = fcport->d_id.b.al_pa;
204 /* Execute MS IOCB */
205 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
206 sizeof(ms_iocb_entry_t));
207 if (rval != QLA_SUCCESS) {
208 /*EMPTY*/
209 ql_dbg(ql_dbg_disc, vha, 0x2062,
210 "GA_NXT issue IOCB failed (%d).\n", rval);
211 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, "GA_NXT") !=
212 QLA_SUCCESS) {
213 rval = QLA_FUNCTION_FAILED;
214 } else {
215 /* Populate fc_port_t entry. */
216 fcport->d_id.b.domain = ct_rsp->rsp.ga_nxt.port_id[0];
217 fcport->d_id.b.area = ct_rsp->rsp.ga_nxt.port_id[1];
218 fcport->d_id.b.al_pa = ct_rsp->rsp.ga_nxt.port_id[2];
220 memcpy(fcport->node_name, ct_rsp->rsp.ga_nxt.node_name,
221 WWN_SIZE);
222 memcpy(fcport->port_name, ct_rsp->rsp.ga_nxt.port_name,
223 WWN_SIZE);
225 fcport->fc4_type = (ct_rsp->rsp.ga_nxt.fc4_types[2] & BIT_0) ?
226 FC4_TYPE_FCP_SCSI : FC4_TYPE_OTHER;
228 if (ct_rsp->rsp.ga_nxt.port_type != NS_N_PORT_TYPE &&
229 ct_rsp->rsp.ga_nxt.port_type != NS_NL_PORT_TYPE)
230 fcport->d_id.b.domain = 0xf0;
232 ql_dbg(ql_dbg_disc, vha, 0x2063,
233 "GA_NXT entry - nn %8phN pn %8phN "
234 "port_id=%02x%02x%02x.\n",
235 fcport->node_name, fcport->port_name,
236 fcport->d_id.b.domain, fcport->d_id.b.area,
237 fcport->d_id.b.al_pa);
240 return (rval);
243 static inline int
244 qla2x00_gid_pt_rsp_size(scsi_qla_host_t *vha)
246 return vha->hw->max_fibre_devices * 4 + 16;
250 * qla2x00_gid_pt() - SNS scan for fabric devices via GID_PT command.
251 * @ha: HA context
252 * @list: switch info entries to populate
254 * NOTE: Non-Nx_Ports are not requested.
256 * Returns 0 on success.
259 qla2x00_gid_pt(scsi_qla_host_t *vha, sw_info_t *list)
261 int rval;
262 uint16_t i;
264 ms_iocb_entry_t *ms_pkt;
265 struct ct_sns_req *ct_req;
266 struct ct_sns_rsp *ct_rsp;
268 struct ct_sns_gid_pt_data *gid_data;
269 struct qla_hw_data *ha = vha->hw;
270 uint16_t gid_pt_rsp_size;
272 if (IS_QLA2100(ha) || IS_QLA2200(ha))
273 return qla2x00_sns_gid_pt(vha, list);
275 gid_data = NULL;
276 gid_pt_rsp_size = qla2x00_gid_pt_rsp_size(vha);
277 /* Issue GID_PT */
278 /* Prepare common MS IOCB */
279 ms_pkt = ha->isp_ops->prep_ms_iocb(vha, GID_PT_REQ_SIZE,
280 gid_pt_rsp_size);
282 /* Prepare CT request */
283 ct_req = qla2x00_prep_ct_req(ha->ct_sns, GID_PT_CMD, gid_pt_rsp_size);
284 ct_rsp = &ha->ct_sns->p.rsp;
286 /* Prepare CT arguments -- port_type */
287 ct_req->req.gid_pt.port_type = NS_NX_PORT_TYPE;
289 /* Execute MS IOCB */
290 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
291 sizeof(ms_iocb_entry_t));
292 if (rval != QLA_SUCCESS) {
293 /*EMPTY*/
294 ql_dbg(ql_dbg_disc, vha, 0x2055,
295 "GID_PT issue IOCB failed (%d).\n", rval);
296 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, "GID_PT") !=
297 QLA_SUCCESS) {
298 rval = QLA_FUNCTION_FAILED;
299 } else {
300 /* Set port IDs in switch info list. */
301 for (i = 0; i < ha->max_fibre_devices; i++) {
302 gid_data = &ct_rsp->rsp.gid_pt.entries[i];
303 list[i].d_id.b.domain = gid_data->port_id[0];
304 list[i].d_id.b.area = gid_data->port_id[1];
305 list[i].d_id.b.al_pa = gid_data->port_id[2];
306 memset(list[i].fabric_port_name, 0, WWN_SIZE);
307 list[i].fp_speed = PORT_SPEED_UNKNOWN;
309 /* Last one exit. */
310 if (gid_data->control_byte & BIT_7) {
311 list[i].d_id.b.rsvd_1 = gid_data->control_byte;
312 break;
317 * If we've used all available slots, then the switch is
318 * reporting back more devices than we can handle with this
319 * single call. Return a failed status, and let GA_NXT handle
320 * the overload.
322 if (i == ha->max_fibre_devices)
323 rval = QLA_FUNCTION_FAILED;
326 return (rval);
330 * qla2x00_gpn_id() - SNS Get Port Name (GPN_ID) query.
331 * @ha: HA context
332 * @list: switch info entries to populate
334 * Returns 0 on success.
337 qla2x00_gpn_id(scsi_qla_host_t *vha, sw_info_t *list)
339 int rval = QLA_SUCCESS;
340 uint16_t i;
342 ms_iocb_entry_t *ms_pkt;
343 struct ct_sns_req *ct_req;
344 struct ct_sns_rsp *ct_rsp;
345 struct qla_hw_data *ha = vha->hw;
347 if (IS_QLA2100(ha) || IS_QLA2200(ha))
348 return qla2x00_sns_gpn_id(vha, list);
350 for (i = 0; i < ha->max_fibre_devices; i++) {
351 /* Issue GPN_ID */
352 /* Prepare common MS IOCB */
353 ms_pkt = ha->isp_ops->prep_ms_iocb(vha, GPN_ID_REQ_SIZE,
354 GPN_ID_RSP_SIZE);
356 /* Prepare CT request */
357 ct_req = qla2x00_prep_ct_req(ha->ct_sns, GPN_ID_CMD,
358 GPN_ID_RSP_SIZE);
359 ct_rsp = &ha->ct_sns->p.rsp;
361 /* Prepare CT arguments -- port_id */
362 ct_req->req.port_id.port_id[0] = list[i].d_id.b.domain;
363 ct_req->req.port_id.port_id[1] = list[i].d_id.b.area;
364 ct_req->req.port_id.port_id[2] = list[i].d_id.b.al_pa;
366 /* Execute MS IOCB */
367 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
368 sizeof(ms_iocb_entry_t));
369 if (rval != QLA_SUCCESS) {
370 /*EMPTY*/
371 ql_dbg(ql_dbg_disc, vha, 0x2056,
372 "GPN_ID issue IOCB failed (%d).\n", rval);
373 break;
374 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp,
375 "GPN_ID") != QLA_SUCCESS) {
376 rval = QLA_FUNCTION_FAILED;
377 break;
378 } else {
379 /* Save portname */
380 memcpy(list[i].port_name,
381 ct_rsp->rsp.gpn_id.port_name, WWN_SIZE);
384 /* Last device exit. */
385 if (list[i].d_id.b.rsvd_1 != 0)
386 break;
389 return (rval);
393 * qla2x00_gnn_id() - SNS Get Node Name (GNN_ID) query.
394 * @ha: HA context
395 * @list: switch info entries to populate
397 * Returns 0 on success.
400 qla2x00_gnn_id(scsi_qla_host_t *vha, sw_info_t *list)
402 int rval = QLA_SUCCESS;
403 uint16_t i;
404 struct qla_hw_data *ha = vha->hw;
405 ms_iocb_entry_t *ms_pkt;
406 struct ct_sns_req *ct_req;
407 struct ct_sns_rsp *ct_rsp;
409 if (IS_QLA2100(ha) || IS_QLA2200(ha))
410 return qla2x00_sns_gnn_id(vha, list);
412 for (i = 0; i < ha->max_fibre_devices; i++) {
413 /* Issue GNN_ID */
414 /* Prepare common MS IOCB */
415 ms_pkt = ha->isp_ops->prep_ms_iocb(vha, GNN_ID_REQ_SIZE,
416 GNN_ID_RSP_SIZE);
418 /* Prepare CT request */
419 ct_req = qla2x00_prep_ct_req(ha->ct_sns, GNN_ID_CMD,
420 GNN_ID_RSP_SIZE);
421 ct_rsp = &ha->ct_sns->p.rsp;
423 /* Prepare CT arguments -- port_id */
424 ct_req->req.port_id.port_id[0] = list[i].d_id.b.domain;
425 ct_req->req.port_id.port_id[1] = list[i].d_id.b.area;
426 ct_req->req.port_id.port_id[2] = list[i].d_id.b.al_pa;
428 /* Execute MS IOCB */
429 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
430 sizeof(ms_iocb_entry_t));
431 if (rval != QLA_SUCCESS) {
432 /*EMPTY*/
433 ql_dbg(ql_dbg_disc, vha, 0x2057,
434 "GNN_ID issue IOCB failed (%d).\n", rval);
435 break;
436 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp,
437 "GNN_ID") != QLA_SUCCESS) {
438 rval = QLA_FUNCTION_FAILED;
439 break;
440 } else {
441 /* Save nodename */
442 memcpy(list[i].node_name,
443 ct_rsp->rsp.gnn_id.node_name, WWN_SIZE);
445 ql_dbg(ql_dbg_disc, vha, 0x2058,
446 "GID_PT entry - nn %8phN pn %8phN "
447 "portid=%02x%02x%02x.\n",
448 list[i].node_name, list[i].port_name,
449 list[i].d_id.b.domain, list[i].d_id.b.area,
450 list[i].d_id.b.al_pa);
453 /* Last device exit. */
454 if (list[i].d_id.b.rsvd_1 != 0)
455 break;
458 return (rval);
462 * qla2x00_rft_id() - SNS Register FC-4 TYPEs (RFT_ID) supported by the HBA.
463 * @ha: HA context
465 * Returns 0 on success.
468 qla2x00_rft_id(scsi_qla_host_t *vha)
470 int rval;
471 struct qla_hw_data *ha = vha->hw;
472 ms_iocb_entry_t *ms_pkt;
473 struct ct_sns_req *ct_req;
474 struct ct_sns_rsp *ct_rsp;
476 if (IS_QLA2100(ha) || IS_QLA2200(ha))
477 return qla2x00_sns_rft_id(vha);
479 /* Issue RFT_ID */
480 /* Prepare common MS IOCB */
481 ms_pkt = ha->isp_ops->prep_ms_iocb(vha, RFT_ID_REQ_SIZE,
482 RFT_ID_RSP_SIZE);
484 /* Prepare CT request */
485 ct_req = qla2x00_prep_ct_req(ha->ct_sns, RFT_ID_CMD,
486 RFT_ID_RSP_SIZE);
487 ct_rsp = &ha->ct_sns->p.rsp;
489 /* Prepare CT arguments -- port_id, FC-4 types */
490 ct_req->req.rft_id.port_id[0] = vha->d_id.b.domain;
491 ct_req->req.rft_id.port_id[1] = vha->d_id.b.area;
492 ct_req->req.rft_id.port_id[2] = vha->d_id.b.al_pa;
494 ct_req->req.rft_id.fc4_types[2] = 0x01; /* FCP-3 */
496 /* Execute MS IOCB */
497 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
498 sizeof(ms_iocb_entry_t));
499 if (rval != QLA_SUCCESS) {
500 /*EMPTY*/
501 ql_dbg(ql_dbg_disc, vha, 0x2043,
502 "RFT_ID issue IOCB failed (%d).\n", rval);
503 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, "RFT_ID") !=
504 QLA_SUCCESS) {
505 rval = QLA_FUNCTION_FAILED;
506 } else {
507 ql_dbg(ql_dbg_disc, vha, 0x2044,
508 "RFT_ID exiting normally.\n");
511 return (rval);
515 * qla2x00_rff_id() - SNS Register FC-4 Features (RFF_ID) supported by the HBA.
516 * @ha: HA context
518 * Returns 0 on success.
521 qla2x00_rff_id(scsi_qla_host_t *vha)
523 int rval;
524 struct qla_hw_data *ha = vha->hw;
525 ms_iocb_entry_t *ms_pkt;
526 struct ct_sns_req *ct_req;
527 struct ct_sns_rsp *ct_rsp;
529 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
530 ql_dbg(ql_dbg_disc, vha, 0x2046,
531 "RFF_ID call not supported on ISP2100/ISP2200.\n");
532 return (QLA_SUCCESS);
535 /* Issue RFF_ID */
536 /* Prepare common MS IOCB */
537 ms_pkt = ha->isp_ops->prep_ms_iocb(vha, RFF_ID_REQ_SIZE,
538 RFF_ID_RSP_SIZE);
540 /* Prepare CT request */
541 ct_req = qla2x00_prep_ct_req(ha->ct_sns, RFF_ID_CMD,
542 RFF_ID_RSP_SIZE);
543 ct_rsp = &ha->ct_sns->p.rsp;
545 /* Prepare CT arguments -- port_id, FC-4 feature, FC-4 type */
546 ct_req->req.rff_id.port_id[0] = vha->d_id.b.domain;
547 ct_req->req.rff_id.port_id[1] = vha->d_id.b.area;
548 ct_req->req.rff_id.port_id[2] = vha->d_id.b.al_pa;
550 qlt_rff_id(vha, ct_req);
552 ct_req->req.rff_id.fc4_type = 0x08; /* SCSI - FCP */
554 /* Execute MS IOCB */
555 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
556 sizeof(ms_iocb_entry_t));
557 if (rval != QLA_SUCCESS) {
558 /*EMPTY*/
559 ql_dbg(ql_dbg_disc, vha, 0x2047,
560 "RFF_ID issue IOCB failed (%d).\n", rval);
561 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, "RFF_ID") !=
562 QLA_SUCCESS) {
563 rval = QLA_FUNCTION_FAILED;
564 } else {
565 ql_dbg(ql_dbg_disc, vha, 0x2048,
566 "RFF_ID exiting normally.\n");
569 return (rval);
573 * qla2x00_rnn_id() - SNS Register Node Name (RNN_ID) of the HBA.
574 * @ha: HA context
576 * Returns 0 on success.
579 qla2x00_rnn_id(scsi_qla_host_t *vha)
581 int rval;
582 struct qla_hw_data *ha = vha->hw;
583 ms_iocb_entry_t *ms_pkt;
584 struct ct_sns_req *ct_req;
585 struct ct_sns_rsp *ct_rsp;
587 if (IS_QLA2100(ha) || IS_QLA2200(ha))
588 return qla2x00_sns_rnn_id(vha);
590 /* Issue RNN_ID */
591 /* Prepare common MS IOCB */
592 ms_pkt = ha->isp_ops->prep_ms_iocb(vha, RNN_ID_REQ_SIZE,
593 RNN_ID_RSP_SIZE);
595 /* Prepare CT request */
596 ct_req = qla2x00_prep_ct_req(ha->ct_sns, RNN_ID_CMD, RNN_ID_RSP_SIZE);
597 ct_rsp = &ha->ct_sns->p.rsp;
599 /* Prepare CT arguments -- port_id, node_name */
600 ct_req->req.rnn_id.port_id[0] = vha->d_id.b.domain;
601 ct_req->req.rnn_id.port_id[1] = vha->d_id.b.area;
602 ct_req->req.rnn_id.port_id[2] = vha->d_id.b.al_pa;
604 memcpy(ct_req->req.rnn_id.node_name, vha->node_name, WWN_SIZE);
606 /* Execute MS IOCB */
607 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
608 sizeof(ms_iocb_entry_t));
609 if (rval != QLA_SUCCESS) {
610 /*EMPTY*/
611 ql_dbg(ql_dbg_disc, vha, 0x204d,
612 "RNN_ID issue IOCB failed (%d).\n", rval);
613 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, "RNN_ID") !=
614 QLA_SUCCESS) {
615 rval = QLA_FUNCTION_FAILED;
616 } else {
617 ql_dbg(ql_dbg_disc, vha, 0x204e,
618 "RNN_ID exiting normally.\n");
621 return (rval);
624 void
625 qla2x00_get_sym_node_name(scsi_qla_host_t *vha, uint8_t *snn)
627 struct qla_hw_data *ha = vha->hw;
629 if (IS_QLAFX00(ha))
630 sprintf(snn, "%s FW:v%s DVR:v%s", ha->model_number,
631 ha->mr.fw_version, qla2x00_version_str);
632 else
633 sprintf(snn, "%s FW:v%d.%02d.%02d DVR:v%s", ha->model_number,
634 ha->fw_major_version, ha->fw_minor_version,
635 ha->fw_subminor_version, qla2x00_version_str);
639 * qla2x00_rsnn_nn() - SNS Register Symbolic Node Name (RSNN_NN) of the HBA.
640 * @ha: HA context
642 * Returns 0 on success.
645 qla2x00_rsnn_nn(scsi_qla_host_t *vha)
647 int rval;
648 struct qla_hw_data *ha = vha->hw;
649 ms_iocb_entry_t *ms_pkt;
650 struct ct_sns_req *ct_req;
651 struct ct_sns_rsp *ct_rsp;
653 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
654 ql_dbg(ql_dbg_disc, vha, 0x2050,
655 "RSNN_ID call unsupported on ISP2100/ISP2200.\n");
656 return (QLA_SUCCESS);
659 /* Issue RSNN_NN */
660 /* Prepare common MS IOCB */
661 /* Request size adjusted after CT preparation */
662 ms_pkt = ha->isp_ops->prep_ms_iocb(vha, 0, RSNN_NN_RSP_SIZE);
664 /* Prepare CT request */
665 ct_req = qla2x00_prep_ct_req(ha->ct_sns, RSNN_NN_CMD,
666 RSNN_NN_RSP_SIZE);
667 ct_rsp = &ha->ct_sns->p.rsp;
669 /* Prepare CT arguments -- node_name, symbolic node_name, size */
670 memcpy(ct_req->req.rsnn_nn.node_name, vha->node_name, WWN_SIZE);
672 /* Prepare the Symbolic Node Name */
673 qla2x00_get_sym_node_name(vha, ct_req->req.rsnn_nn.sym_node_name);
675 /* Calculate SNN length */
676 ct_req->req.rsnn_nn.name_len =
677 (uint8_t)strlen(ct_req->req.rsnn_nn.sym_node_name);
679 /* Update MS IOCB request */
680 ms_pkt->req_bytecount =
681 cpu_to_le32(24 + 1 + ct_req->req.rsnn_nn.name_len);
682 ms_pkt->dseg_req_length = ms_pkt->req_bytecount;
684 /* Execute MS IOCB */
685 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
686 sizeof(ms_iocb_entry_t));
687 if (rval != QLA_SUCCESS) {
688 /*EMPTY*/
689 ql_dbg(ql_dbg_disc, vha, 0x2051,
690 "RSNN_NN issue IOCB failed (%d).\n", rval);
691 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, "RSNN_NN") !=
692 QLA_SUCCESS) {
693 rval = QLA_FUNCTION_FAILED;
694 } else {
695 ql_dbg(ql_dbg_disc, vha, 0x2052,
696 "RSNN_NN exiting normally.\n");
699 return (rval);
703 * qla2x00_prep_sns_cmd() - Prepare common SNS command request fields for query.
704 * @ha: HA context
705 * @cmd: GS command
706 * @scmd_len: Subcommand length
707 * @data_size: response size in bytes
709 * Returns a pointer to the @ha's sns_cmd.
711 static inline struct sns_cmd_pkt *
712 qla2x00_prep_sns_cmd(scsi_qla_host_t *vha, uint16_t cmd, uint16_t scmd_len,
713 uint16_t data_size)
715 uint16_t wc;
716 struct sns_cmd_pkt *sns_cmd;
717 struct qla_hw_data *ha = vha->hw;
719 sns_cmd = ha->sns_cmd;
720 memset(sns_cmd, 0, sizeof(struct sns_cmd_pkt));
721 wc = data_size / 2; /* Size in 16bit words. */
722 sns_cmd->p.cmd.buffer_length = cpu_to_le16(wc);
723 sns_cmd->p.cmd.buffer_address[0] = cpu_to_le32(LSD(ha->sns_cmd_dma));
724 sns_cmd->p.cmd.buffer_address[1] = cpu_to_le32(MSD(ha->sns_cmd_dma));
725 sns_cmd->p.cmd.subcommand_length = cpu_to_le16(scmd_len);
726 sns_cmd->p.cmd.subcommand = cpu_to_le16(cmd);
727 wc = (data_size - 16) / 4; /* Size in 32bit words. */
728 sns_cmd->p.cmd.size = cpu_to_le16(wc);
730 vha->qla_stats.control_requests++;
732 return (sns_cmd);
736 * qla2x00_sns_ga_nxt() - SNS scan for fabric devices via GA_NXT command.
737 * @ha: HA context
738 * @fcport: fcport entry to updated
740 * This command uses the old Exectute SNS Command mailbox routine.
742 * Returns 0 on success.
744 static int
745 qla2x00_sns_ga_nxt(scsi_qla_host_t *vha, fc_port_t *fcport)
747 int rval = QLA_SUCCESS;
748 struct qla_hw_data *ha = vha->hw;
749 struct sns_cmd_pkt *sns_cmd;
751 /* Issue GA_NXT. */
752 /* Prepare SNS command request. */
753 sns_cmd = qla2x00_prep_sns_cmd(vha, GA_NXT_CMD, GA_NXT_SNS_SCMD_LEN,
754 GA_NXT_SNS_DATA_SIZE);
756 /* Prepare SNS command arguments -- port_id. */
757 sns_cmd->p.cmd.param[0] = fcport->d_id.b.al_pa;
758 sns_cmd->p.cmd.param[1] = fcport->d_id.b.area;
759 sns_cmd->p.cmd.param[2] = fcport->d_id.b.domain;
761 /* Execute SNS command. */
762 rval = qla2x00_send_sns(vha, ha->sns_cmd_dma, GA_NXT_SNS_CMD_SIZE / 2,
763 sizeof(struct sns_cmd_pkt));
764 if (rval != QLA_SUCCESS) {
765 /*EMPTY*/
766 ql_dbg(ql_dbg_disc, vha, 0x205f,
767 "GA_NXT Send SNS failed (%d).\n", rval);
768 } else if (sns_cmd->p.gan_data[8] != 0x80 ||
769 sns_cmd->p.gan_data[9] != 0x02) {
770 ql_dbg(ql_dbg_disc + ql_dbg_buffer, vha, 0x2084,
771 "GA_NXT failed, rejected request ga_nxt_rsp:\n");
772 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2074,
773 sns_cmd->p.gan_data, 16);
774 rval = QLA_FUNCTION_FAILED;
775 } else {
776 /* Populate fc_port_t entry. */
777 fcport->d_id.b.domain = sns_cmd->p.gan_data[17];
778 fcport->d_id.b.area = sns_cmd->p.gan_data[18];
779 fcport->d_id.b.al_pa = sns_cmd->p.gan_data[19];
781 memcpy(fcport->node_name, &sns_cmd->p.gan_data[284], WWN_SIZE);
782 memcpy(fcport->port_name, &sns_cmd->p.gan_data[20], WWN_SIZE);
784 if (sns_cmd->p.gan_data[16] != NS_N_PORT_TYPE &&
785 sns_cmd->p.gan_data[16] != NS_NL_PORT_TYPE)
786 fcport->d_id.b.domain = 0xf0;
788 ql_dbg(ql_dbg_disc, vha, 0x2061,
789 "GA_NXT entry - nn %8phN pn %8phN "
790 "port_id=%02x%02x%02x.\n",
791 fcport->node_name, fcport->port_name,
792 fcport->d_id.b.domain, fcport->d_id.b.area,
793 fcport->d_id.b.al_pa);
796 return (rval);
800 * qla2x00_sns_gid_pt() - SNS scan for fabric devices via GID_PT command.
801 * @ha: HA context
802 * @list: switch info entries to populate
804 * This command uses the old Exectute SNS Command mailbox routine.
806 * NOTE: Non-Nx_Ports are not requested.
808 * Returns 0 on success.
810 static int
811 qla2x00_sns_gid_pt(scsi_qla_host_t *vha, sw_info_t *list)
813 int rval;
814 struct qla_hw_data *ha = vha->hw;
815 uint16_t i;
816 uint8_t *entry;
817 struct sns_cmd_pkt *sns_cmd;
818 uint16_t gid_pt_sns_data_size;
820 gid_pt_sns_data_size = qla2x00_gid_pt_rsp_size(vha);
822 /* Issue GID_PT. */
823 /* Prepare SNS command request. */
824 sns_cmd = qla2x00_prep_sns_cmd(vha, GID_PT_CMD, GID_PT_SNS_SCMD_LEN,
825 gid_pt_sns_data_size);
827 /* Prepare SNS command arguments -- port_type. */
828 sns_cmd->p.cmd.param[0] = NS_NX_PORT_TYPE;
830 /* Execute SNS command. */
831 rval = qla2x00_send_sns(vha, ha->sns_cmd_dma, GID_PT_SNS_CMD_SIZE / 2,
832 sizeof(struct sns_cmd_pkt));
833 if (rval != QLA_SUCCESS) {
834 /*EMPTY*/
835 ql_dbg(ql_dbg_disc, vha, 0x206d,
836 "GID_PT Send SNS failed (%d).\n", rval);
837 } else if (sns_cmd->p.gid_data[8] != 0x80 ||
838 sns_cmd->p.gid_data[9] != 0x02) {
839 ql_dbg(ql_dbg_disc, vha, 0x202f,
840 "GID_PT failed, rejected request, gid_rsp:\n");
841 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2081,
842 sns_cmd->p.gid_data, 16);
843 rval = QLA_FUNCTION_FAILED;
844 } else {
845 /* Set port IDs in switch info list. */
846 for (i = 0; i < ha->max_fibre_devices; i++) {
847 entry = &sns_cmd->p.gid_data[(i * 4) + 16];
848 list[i].d_id.b.domain = entry[1];
849 list[i].d_id.b.area = entry[2];
850 list[i].d_id.b.al_pa = entry[3];
852 /* Last one exit. */
853 if (entry[0] & BIT_7) {
854 list[i].d_id.b.rsvd_1 = entry[0];
855 break;
860 * If we've used all available slots, then the switch is
861 * reporting back more devices that we can handle with this
862 * single call. Return a failed status, and let GA_NXT handle
863 * the overload.
865 if (i == ha->max_fibre_devices)
866 rval = QLA_FUNCTION_FAILED;
869 return (rval);
873 * qla2x00_sns_gpn_id() - SNS Get Port Name (GPN_ID) query.
874 * @ha: HA context
875 * @list: switch info entries to populate
877 * This command uses the old Exectute SNS Command mailbox routine.
879 * Returns 0 on success.
881 static int
882 qla2x00_sns_gpn_id(scsi_qla_host_t *vha, sw_info_t *list)
884 int rval = QLA_SUCCESS;
885 struct qla_hw_data *ha = vha->hw;
886 uint16_t i;
887 struct sns_cmd_pkt *sns_cmd;
889 for (i = 0; i < ha->max_fibre_devices; i++) {
890 /* Issue GPN_ID */
891 /* Prepare SNS command request. */
892 sns_cmd = qla2x00_prep_sns_cmd(vha, GPN_ID_CMD,
893 GPN_ID_SNS_SCMD_LEN, GPN_ID_SNS_DATA_SIZE);
895 /* Prepare SNS command arguments -- port_id. */
896 sns_cmd->p.cmd.param[0] = list[i].d_id.b.al_pa;
897 sns_cmd->p.cmd.param[1] = list[i].d_id.b.area;
898 sns_cmd->p.cmd.param[2] = list[i].d_id.b.domain;
900 /* Execute SNS command. */
901 rval = qla2x00_send_sns(vha, ha->sns_cmd_dma,
902 GPN_ID_SNS_CMD_SIZE / 2, sizeof(struct sns_cmd_pkt));
903 if (rval != QLA_SUCCESS) {
904 /*EMPTY*/
905 ql_dbg(ql_dbg_disc, vha, 0x2032,
906 "GPN_ID Send SNS failed (%d).\n", rval);
907 } else if (sns_cmd->p.gpn_data[8] != 0x80 ||
908 sns_cmd->p.gpn_data[9] != 0x02) {
909 ql_dbg(ql_dbg_disc + ql_dbg_buffer, vha, 0x207e,
910 "GPN_ID failed, rejected request, gpn_rsp:\n");
911 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x207f,
912 sns_cmd->p.gpn_data, 16);
913 rval = QLA_FUNCTION_FAILED;
914 } else {
915 /* Save portname */
916 memcpy(list[i].port_name, &sns_cmd->p.gpn_data[16],
917 WWN_SIZE);
920 /* Last device exit. */
921 if (list[i].d_id.b.rsvd_1 != 0)
922 break;
925 return (rval);
929 * qla2x00_sns_gnn_id() - SNS Get Node Name (GNN_ID) query.
930 * @ha: HA context
931 * @list: switch info entries to populate
933 * This command uses the old Exectute SNS Command mailbox routine.
935 * Returns 0 on success.
937 static int
938 qla2x00_sns_gnn_id(scsi_qla_host_t *vha, sw_info_t *list)
940 int rval = QLA_SUCCESS;
941 struct qla_hw_data *ha = vha->hw;
942 uint16_t i;
943 struct sns_cmd_pkt *sns_cmd;
945 for (i = 0; i < ha->max_fibre_devices; i++) {
946 /* Issue GNN_ID */
947 /* Prepare SNS command request. */
948 sns_cmd = qla2x00_prep_sns_cmd(vha, GNN_ID_CMD,
949 GNN_ID_SNS_SCMD_LEN, GNN_ID_SNS_DATA_SIZE);
951 /* Prepare SNS command arguments -- port_id. */
952 sns_cmd->p.cmd.param[0] = list[i].d_id.b.al_pa;
953 sns_cmd->p.cmd.param[1] = list[i].d_id.b.area;
954 sns_cmd->p.cmd.param[2] = list[i].d_id.b.domain;
956 /* Execute SNS command. */
957 rval = qla2x00_send_sns(vha, ha->sns_cmd_dma,
958 GNN_ID_SNS_CMD_SIZE / 2, sizeof(struct sns_cmd_pkt));
959 if (rval != QLA_SUCCESS) {
960 /*EMPTY*/
961 ql_dbg(ql_dbg_disc, vha, 0x203f,
962 "GNN_ID Send SNS failed (%d).\n", rval);
963 } else if (sns_cmd->p.gnn_data[8] != 0x80 ||
964 sns_cmd->p.gnn_data[9] != 0x02) {
965 ql_dbg(ql_dbg_disc + ql_dbg_buffer, vha, 0x2082,
966 "GNN_ID failed, rejected request, gnn_rsp:\n");
967 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x207a,
968 sns_cmd->p.gnn_data, 16);
969 rval = QLA_FUNCTION_FAILED;
970 } else {
971 /* Save nodename */
972 memcpy(list[i].node_name, &sns_cmd->p.gnn_data[16],
973 WWN_SIZE);
975 ql_dbg(ql_dbg_disc, vha, 0x206e,
976 "GID_PT entry - nn %8phN pn %8phN "
977 "port_id=%02x%02x%02x.\n",
978 list[i].node_name, list[i].port_name,
979 list[i].d_id.b.domain, list[i].d_id.b.area,
980 list[i].d_id.b.al_pa);
983 /* Last device exit. */
984 if (list[i].d_id.b.rsvd_1 != 0)
985 break;
988 return (rval);
992 * qla2x00_snd_rft_id() - SNS Register FC-4 TYPEs (RFT_ID) supported by the HBA.
993 * @ha: HA context
995 * This command uses the old Exectute SNS Command mailbox routine.
997 * Returns 0 on success.
999 static int
1000 qla2x00_sns_rft_id(scsi_qla_host_t *vha)
1002 int rval;
1003 struct qla_hw_data *ha = vha->hw;
1004 struct sns_cmd_pkt *sns_cmd;
1006 /* Issue RFT_ID. */
1007 /* Prepare SNS command request. */
1008 sns_cmd = qla2x00_prep_sns_cmd(vha, RFT_ID_CMD, RFT_ID_SNS_SCMD_LEN,
1009 RFT_ID_SNS_DATA_SIZE);
1011 /* Prepare SNS command arguments -- port_id, FC-4 types */
1012 sns_cmd->p.cmd.param[0] = vha->d_id.b.al_pa;
1013 sns_cmd->p.cmd.param[1] = vha->d_id.b.area;
1014 sns_cmd->p.cmd.param[2] = vha->d_id.b.domain;
1016 sns_cmd->p.cmd.param[5] = 0x01; /* FCP-3 */
1018 /* Execute SNS command. */
1019 rval = qla2x00_send_sns(vha, ha->sns_cmd_dma, RFT_ID_SNS_CMD_SIZE / 2,
1020 sizeof(struct sns_cmd_pkt));
1021 if (rval != QLA_SUCCESS) {
1022 /*EMPTY*/
1023 ql_dbg(ql_dbg_disc, vha, 0x2060,
1024 "RFT_ID Send SNS failed (%d).\n", rval);
1025 } else if (sns_cmd->p.rft_data[8] != 0x80 ||
1026 sns_cmd->p.rft_data[9] != 0x02) {
1027 ql_dbg(ql_dbg_disc + ql_dbg_buffer, vha, 0x2083,
1028 "RFT_ID failed, rejected request rft_rsp:\n");
1029 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2080,
1030 sns_cmd->p.rft_data, 16);
1031 rval = QLA_FUNCTION_FAILED;
1032 } else {
1033 ql_dbg(ql_dbg_disc, vha, 0x2073,
1034 "RFT_ID exiting normally.\n");
1037 return (rval);
1041 * qla2x00_sns_rnn_id() - SNS Register Node Name (RNN_ID) of the HBA.
1042 * HBA.
1043 * @ha: HA context
1045 * This command uses the old Exectute SNS Command mailbox routine.
1047 * Returns 0 on success.
1049 static int
1050 qla2x00_sns_rnn_id(scsi_qla_host_t *vha)
1052 int rval;
1053 struct qla_hw_data *ha = vha->hw;
1054 struct sns_cmd_pkt *sns_cmd;
1056 /* Issue RNN_ID. */
1057 /* Prepare SNS command request. */
1058 sns_cmd = qla2x00_prep_sns_cmd(vha, RNN_ID_CMD, RNN_ID_SNS_SCMD_LEN,
1059 RNN_ID_SNS_DATA_SIZE);
1061 /* Prepare SNS command arguments -- port_id, nodename. */
1062 sns_cmd->p.cmd.param[0] = vha->d_id.b.al_pa;
1063 sns_cmd->p.cmd.param[1] = vha->d_id.b.area;
1064 sns_cmd->p.cmd.param[2] = vha->d_id.b.domain;
1066 sns_cmd->p.cmd.param[4] = vha->node_name[7];
1067 sns_cmd->p.cmd.param[5] = vha->node_name[6];
1068 sns_cmd->p.cmd.param[6] = vha->node_name[5];
1069 sns_cmd->p.cmd.param[7] = vha->node_name[4];
1070 sns_cmd->p.cmd.param[8] = vha->node_name[3];
1071 sns_cmd->p.cmd.param[9] = vha->node_name[2];
1072 sns_cmd->p.cmd.param[10] = vha->node_name[1];
1073 sns_cmd->p.cmd.param[11] = vha->node_name[0];
1075 /* Execute SNS command. */
1076 rval = qla2x00_send_sns(vha, ha->sns_cmd_dma, RNN_ID_SNS_CMD_SIZE / 2,
1077 sizeof(struct sns_cmd_pkt));
1078 if (rval != QLA_SUCCESS) {
1079 /*EMPTY*/
1080 ql_dbg(ql_dbg_disc, vha, 0x204a,
1081 "RNN_ID Send SNS failed (%d).\n", rval);
1082 } else if (sns_cmd->p.rnn_data[8] != 0x80 ||
1083 sns_cmd->p.rnn_data[9] != 0x02) {
1084 ql_dbg(ql_dbg_disc + ql_dbg_buffer, vha, 0x207b,
1085 "RNN_ID failed, rejected request, rnn_rsp:\n");
1086 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x207c,
1087 sns_cmd->p.rnn_data, 16);
1088 rval = QLA_FUNCTION_FAILED;
1089 } else {
1090 ql_dbg(ql_dbg_disc, vha, 0x204c,
1091 "RNN_ID exiting normally.\n");
1094 return (rval);
1098 * qla2x00_mgmt_svr_login() - Login to fabric Management Service.
1099 * @ha: HA context
1101 * Returns 0 on success.
1103 static int
1104 qla2x00_mgmt_svr_login(scsi_qla_host_t *vha)
1106 int ret, rval;
1107 uint16_t mb[MAILBOX_REGISTER_COUNT];
1108 struct qla_hw_data *ha = vha->hw;
1109 ret = QLA_SUCCESS;
1110 if (vha->flags.management_server_logged_in)
1111 return ret;
1113 rval = ha->isp_ops->fabric_login(vha, vha->mgmt_svr_loop_id, 0xff, 0xff,
1114 0xfa, mb, BIT_1);
1115 if (rval != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
1116 if (rval == QLA_MEMORY_ALLOC_FAILED)
1117 ql_dbg(ql_dbg_disc, vha, 0x2085,
1118 "Failed management_server login: loopid=%x "
1119 "rval=%d\n", vha->mgmt_svr_loop_id, rval);
1120 else
1121 ql_dbg(ql_dbg_disc, vha, 0x2024,
1122 "Failed management_server login: loopid=%x "
1123 "mb[0]=%x mb[1]=%x mb[2]=%x mb[6]=%x mb[7]=%x.\n",
1124 vha->mgmt_svr_loop_id, mb[0], mb[1], mb[2], mb[6],
1125 mb[7]);
1126 ret = QLA_FUNCTION_FAILED;
1127 } else
1128 vha->flags.management_server_logged_in = 1;
1130 return ret;
1134 * qla2x00_prep_ms_fdmi_iocb() - Prepare common MS IOCB fields for FDMI query.
1135 * @ha: HA context
1136 * @req_size: request size in bytes
1137 * @rsp_size: response size in bytes
1139 * Returns a pointer to the @ha's ms_iocb.
1141 void *
1142 qla2x00_prep_ms_fdmi_iocb(scsi_qla_host_t *vha, uint32_t req_size,
1143 uint32_t rsp_size)
1145 ms_iocb_entry_t *ms_pkt;
1146 struct qla_hw_data *ha = vha->hw;
1147 ms_pkt = ha->ms_iocb;
1148 memset(ms_pkt, 0, sizeof(ms_iocb_entry_t));
1150 ms_pkt->entry_type = MS_IOCB_TYPE;
1151 ms_pkt->entry_count = 1;
1152 SET_TARGET_ID(ha, ms_pkt->loop_id, vha->mgmt_svr_loop_id);
1153 ms_pkt->control_flags = __constant_cpu_to_le16(CF_READ | CF_HEAD_TAG);
1154 ms_pkt->timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
1155 ms_pkt->cmd_dsd_count = __constant_cpu_to_le16(1);
1156 ms_pkt->total_dsd_count = __constant_cpu_to_le16(2);
1157 ms_pkt->rsp_bytecount = cpu_to_le32(rsp_size);
1158 ms_pkt->req_bytecount = cpu_to_le32(req_size);
1160 ms_pkt->dseg_req_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
1161 ms_pkt->dseg_req_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
1162 ms_pkt->dseg_req_length = ms_pkt->req_bytecount;
1164 ms_pkt->dseg_rsp_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
1165 ms_pkt->dseg_rsp_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
1166 ms_pkt->dseg_rsp_length = ms_pkt->rsp_bytecount;
1168 return ms_pkt;
1172 * qla24xx_prep_ms_fdmi_iocb() - Prepare common MS IOCB fields for FDMI query.
1173 * @ha: HA context
1174 * @req_size: request size in bytes
1175 * @rsp_size: response size in bytes
1177 * Returns a pointer to the @ha's ms_iocb.
1179 void *
1180 qla24xx_prep_ms_fdmi_iocb(scsi_qla_host_t *vha, uint32_t req_size,
1181 uint32_t rsp_size)
1183 struct ct_entry_24xx *ct_pkt;
1184 struct qla_hw_data *ha = vha->hw;
1186 ct_pkt = (struct ct_entry_24xx *)ha->ms_iocb;
1187 memset(ct_pkt, 0, sizeof(struct ct_entry_24xx));
1189 ct_pkt->entry_type = CT_IOCB_TYPE;
1190 ct_pkt->entry_count = 1;
1191 ct_pkt->nport_handle = cpu_to_le16(vha->mgmt_svr_loop_id);
1192 ct_pkt->timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
1193 ct_pkt->cmd_dsd_count = __constant_cpu_to_le16(1);
1194 ct_pkt->rsp_dsd_count = __constant_cpu_to_le16(1);
1195 ct_pkt->rsp_byte_count = cpu_to_le32(rsp_size);
1196 ct_pkt->cmd_byte_count = cpu_to_le32(req_size);
1198 ct_pkt->dseg_0_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
1199 ct_pkt->dseg_0_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
1200 ct_pkt->dseg_0_len = ct_pkt->cmd_byte_count;
1202 ct_pkt->dseg_1_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
1203 ct_pkt->dseg_1_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
1204 ct_pkt->dseg_1_len = ct_pkt->rsp_byte_count;
1205 ct_pkt->vp_index = vha->vp_idx;
1207 return ct_pkt;
1210 static inline ms_iocb_entry_t *
1211 qla2x00_update_ms_fdmi_iocb(scsi_qla_host_t *vha, uint32_t req_size)
1213 struct qla_hw_data *ha = vha->hw;
1214 ms_iocb_entry_t *ms_pkt = ha->ms_iocb;
1215 struct ct_entry_24xx *ct_pkt = (struct ct_entry_24xx *)ha->ms_iocb;
1217 if (IS_FWI2_CAPABLE(ha)) {
1218 ct_pkt->cmd_byte_count = cpu_to_le32(req_size);
1219 ct_pkt->dseg_0_len = ct_pkt->cmd_byte_count;
1220 } else {
1221 ms_pkt->req_bytecount = cpu_to_le32(req_size);
1222 ms_pkt->dseg_req_length = ms_pkt->req_bytecount;
1225 return ms_pkt;
1229 * qla2x00_prep_ct_req() - Prepare common CT request fields for SNS query.
1230 * @ct_req: CT request buffer
1231 * @cmd: GS command
1232 * @rsp_size: response size in bytes
1234 * Returns a pointer to the intitialized @ct_req.
1236 static inline struct ct_sns_req *
1237 qla2x00_prep_ct_fdmi_req(struct ct_sns_pkt *p, uint16_t cmd,
1238 uint16_t rsp_size)
1240 memset(p, 0, sizeof(struct ct_sns_pkt));
1242 p->p.req.header.revision = 0x01;
1243 p->p.req.header.gs_type = 0xFA;
1244 p->p.req.header.gs_subtype = 0x10;
1245 p->p.req.command = cpu_to_be16(cmd);
1246 p->p.req.max_rsp_size = cpu_to_be16((rsp_size - 16) / 4);
1248 return &p->p.req;
1252 * qla2x00_fdmi_rhba() -
1253 * @ha: HA context
1255 * Returns 0 on success.
1257 static int
1258 qla2x00_fdmi_rhba(scsi_qla_host_t *vha)
1260 int rval, alen;
1261 uint32_t size, sn;
1263 ms_iocb_entry_t *ms_pkt;
1264 struct ct_sns_req *ct_req;
1265 struct ct_sns_rsp *ct_rsp;
1266 uint8_t *entries;
1267 struct ct_fdmi_hba_attr *eiter;
1268 struct qla_hw_data *ha = vha->hw;
1270 /* Issue RHBA */
1271 /* Prepare common MS IOCB */
1272 /* Request size adjusted after CT preparation */
1273 ms_pkt = ha->isp_ops->prep_ms_fdmi_iocb(vha, 0, RHBA_RSP_SIZE);
1275 /* Prepare CT request */
1276 ct_req = qla2x00_prep_ct_fdmi_req(ha->ct_sns, RHBA_CMD, RHBA_RSP_SIZE);
1277 ct_rsp = &ha->ct_sns->p.rsp;
1279 /* Prepare FDMI command arguments -- attribute block, attributes. */
1280 memcpy(ct_req->req.rhba.hba_identifier, vha->port_name, WWN_SIZE);
1281 ct_req->req.rhba.entry_count = __constant_cpu_to_be32(1);
1282 memcpy(ct_req->req.rhba.port_name, vha->port_name, WWN_SIZE);
1283 size = 2 * WWN_SIZE + 4 + 4;
1285 /* Attributes */
1286 ct_req->req.rhba.attrs.count =
1287 __constant_cpu_to_be32(FDMI_HBA_ATTR_COUNT);
1288 entries = ct_req->req.rhba.hba_identifier;
1290 /* Nodename. */
1291 eiter = (struct ct_fdmi_hba_attr *) (entries + size);
1292 eiter->type = __constant_cpu_to_be16(FDMI_HBA_NODE_NAME);
1293 eiter->len = __constant_cpu_to_be16(4 + WWN_SIZE);
1294 memcpy(eiter->a.node_name, vha->node_name, WWN_SIZE);
1295 size += 4 + WWN_SIZE;
1297 ql_dbg(ql_dbg_disc, vha, 0x2025,
1298 "NodeName = %8phN.\n", eiter->a.node_name);
1300 /* Manufacturer. */
1301 eiter = (struct ct_fdmi_hba_attr *) (entries + size);
1302 eiter->type = __constant_cpu_to_be16(FDMI_HBA_MANUFACTURER);
1303 alen = strlen(QLA2XXX_MANUFACTURER);
1304 strncpy(eiter->a.manufacturer, QLA2XXX_MANUFACTURER, alen + 1);
1305 alen += (alen & 3) ? (4 - (alen & 3)) : 4;
1306 eiter->len = cpu_to_be16(4 + alen);
1307 size += 4 + alen;
1309 ql_dbg(ql_dbg_disc, vha, 0x2026,
1310 "Manufacturer = %s.\n", eiter->a.manufacturer);
1312 /* Serial number. */
1313 eiter = (struct ct_fdmi_hba_attr *) (entries + size);
1314 eiter->type = __constant_cpu_to_be16(FDMI_HBA_SERIAL_NUMBER);
1315 sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
1316 sprintf(eiter->a.serial_num, "%c%05d", 'A' + sn / 100000, sn % 100000);
1317 alen = strlen(eiter->a.serial_num);
1318 alen += (alen & 3) ? (4 - (alen & 3)) : 4;
1319 eiter->len = cpu_to_be16(4 + alen);
1320 size += 4 + alen;
1322 ql_dbg(ql_dbg_disc, vha, 0x2027,
1323 "Serial no. = %s.\n", eiter->a.serial_num);
1325 /* Model name. */
1326 eiter = (struct ct_fdmi_hba_attr *) (entries + size);
1327 eiter->type = __constant_cpu_to_be16(FDMI_HBA_MODEL);
1328 strcpy(eiter->a.model, ha->model_number);
1329 alen = strlen(eiter->a.model);
1330 alen += (alen & 3) ? (4 - (alen & 3)) : 4;
1331 eiter->len = cpu_to_be16(4 + alen);
1332 size += 4 + alen;
1334 ql_dbg(ql_dbg_disc, vha, 0x2028,
1335 "Model Name = %s.\n", eiter->a.model);
1337 /* Model description. */
1338 eiter = (struct ct_fdmi_hba_attr *) (entries + size);
1339 eiter->type = __constant_cpu_to_be16(FDMI_HBA_MODEL_DESCRIPTION);
1340 strncpy(eiter->a.model_desc, ha->model_desc, 80);
1341 alen = strlen(eiter->a.model_desc);
1342 alen += (alen & 3) ? (4 - (alen & 3)) : 4;
1343 eiter->len = cpu_to_be16(4 + alen);
1344 size += 4 + alen;
1346 ql_dbg(ql_dbg_disc, vha, 0x2029,
1347 "Model Desc = %s.\n", eiter->a.model_desc);
1349 /* Hardware version. */
1350 eiter = (struct ct_fdmi_hba_attr *) (entries + size);
1351 eiter->type = __constant_cpu_to_be16(FDMI_HBA_HARDWARE_VERSION);
1352 strcpy(eiter->a.hw_version, ha->adapter_id);
1353 alen = strlen(eiter->a.hw_version);
1354 alen += (alen & 3) ? (4 - (alen & 3)) : 4;
1355 eiter->len = cpu_to_be16(4 + alen);
1356 size += 4 + alen;
1358 ql_dbg(ql_dbg_disc, vha, 0x202a,
1359 "Hardware ver = %s.\n", eiter->a.hw_version);
1361 /* Driver version. */
1362 eiter = (struct ct_fdmi_hba_attr *) (entries + size);
1363 eiter->type = __constant_cpu_to_be16(FDMI_HBA_DRIVER_VERSION);
1364 strcpy(eiter->a.driver_version, qla2x00_version_str);
1365 alen = strlen(eiter->a.driver_version);
1366 alen += (alen & 3) ? (4 - (alen & 3)) : 4;
1367 eiter->len = cpu_to_be16(4 + alen);
1368 size += 4 + alen;
1370 ql_dbg(ql_dbg_disc, vha, 0x202b,
1371 "Driver ver = %s.\n", eiter->a.driver_version);
1373 /* Option ROM version. */
1374 eiter = (struct ct_fdmi_hba_attr *) (entries + size);
1375 eiter->type = __constant_cpu_to_be16(FDMI_HBA_OPTION_ROM_VERSION);
1376 strcpy(eiter->a.orom_version, "0.00");
1377 alen = strlen(eiter->a.orom_version);
1378 alen += (alen & 3) ? (4 - (alen & 3)) : 4;
1379 eiter->len = cpu_to_be16(4 + alen);
1380 size += 4 + alen;
1382 ql_dbg(ql_dbg_disc, vha , 0x202c,
1383 "Optrom vers = %s.\n", eiter->a.orom_version);
1385 /* Firmware version */
1386 eiter = (struct ct_fdmi_hba_attr *) (entries + size);
1387 eiter->type = __constant_cpu_to_be16(FDMI_HBA_FIRMWARE_VERSION);
1388 ha->isp_ops->fw_version_str(vha, eiter->a.fw_version);
1389 alen = strlen(eiter->a.fw_version);
1390 alen += (alen & 3) ? (4 - (alen & 3)) : 4;
1391 eiter->len = cpu_to_be16(4 + alen);
1392 size += 4 + alen;
1394 ql_dbg(ql_dbg_disc, vha, 0x202d,
1395 "Firmware vers = %s.\n", eiter->a.fw_version);
1397 /* Update MS request size. */
1398 qla2x00_update_ms_fdmi_iocb(vha, size + 16);
1400 ql_dbg(ql_dbg_disc, vha, 0x202e,
1401 "RHBA identifier = %8phN size=%d.\n",
1402 ct_req->req.rhba.hba_identifier, size);
1403 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2076,
1404 entries, size);
1406 /* Execute MS IOCB */
1407 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
1408 sizeof(ms_iocb_entry_t));
1409 if (rval != QLA_SUCCESS) {
1410 /*EMPTY*/
1411 ql_dbg(ql_dbg_disc, vha, 0x2030,
1412 "RHBA issue IOCB failed (%d).\n", rval);
1413 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, "RHBA") !=
1414 QLA_SUCCESS) {
1415 rval = QLA_FUNCTION_FAILED;
1416 if (ct_rsp->header.reason_code == CT_REASON_CANNOT_PERFORM &&
1417 ct_rsp->header.explanation_code ==
1418 CT_EXPL_ALREADY_REGISTERED) {
1419 ql_dbg(ql_dbg_disc, vha, 0x2034,
1420 "HBA already registered.\n");
1421 rval = QLA_ALREADY_REGISTERED;
1423 } else {
1424 ql_dbg(ql_dbg_disc, vha, 0x2035,
1425 "RHBA exiting normally.\n");
1428 return rval;
1432 * qla2x00_fdmi_dhba() -
1433 * @ha: HA context
1435 * Returns 0 on success.
1437 static int
1438 qla2x00_fdmi_dhba(scsi_qla_host_t *vha)
1440 int rval;
1441 struct qla_hw_data *ha = vha->hw;
1442 ms_iocb_entry_t *ms_pkt;
1443 struct ct_sns_req *ct_req;
1444 struct ct_sns_rsp *ct_rsp;
1446 /* Issue RPA */
1447 /* Prepare common MS IOCB */
1448 ms_pkt = ha->isp_ops->prep_ms_fdmi_iocb(vha, DHBA_REQ_SIZE,
1449 DHBA_RSP_SIZE);
1451 /* Prepare CT request */
1452 ct_req = qla2x00_prep_ct_fdmi_req(ha->ct_sns, DHBA_CMD, DHBA_RSP_SIZE);
1453 ct_rsp = &ha->ct_sns->p.rsp;
1455 /* Prepare FDMI command arguments -- portname. */
1456 memcpy(ct_req->req.dhba.port_name, vha->port_name, WWN_SIZE);
1458 ql_dbg(ql_dbg_disc, vha, 0x2036,
1459 "DHBA portname = %8phN.\n", ct_req->req.dhba.port_name);
1461 /* Execute MS IOCB */
1462 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
1463 sizeof(ms_iocb_entry_t));
1464 if (rval != QLA_SUCCESS) {
1465 /*EMPTY*/
1466 ql_dbg(ql_dbg_disc, vha, 0x2037,
1467 "DHBA issue IOCB failed (%d).\n", rval);
1468 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, "DHBA") !=
1469 QLA_SUCCESS) {
1470 rval = QLA_FUNCTION_FAILED;
1471 } else {
1472 ql_dbg(ql_dbg_disc, vha, 0x2038,
1473 "DHBA exiting normally.\n");
1476 return rval;
1480 * qla2x00_fdmi_rpa() -
1481 * @ha: HA context
1483 * Returns 0 on success.
1485 static int
1486 qla2x00_fdmi_rpa(scsi_qla_host_t *vha)
1488 int rval, alen;
1489 uint32_t size, max_frame_size;
1490 struct qla_hw_data *ha = vha->hw;
1491 ms_iocb_entry_t *ms_pkt;
1492 struct ct_sns_req *ct_req;
1493 struct ct_sns_rsp *ct_rsp;
1494 uint8_t *entries;
1495 struct ct_fdmi_port_attr *eiter;
1496 struct init_cb_24xx *icb24 = (struct init_cb_24xx *)ha->init_cb;
1498 /* Issue RPA */
1499 /* Prepare common MS IOCB */
1500 /* Request size adjusted after CT preparation */
1501 ms_pkt = ha->isp_ops->prep_ms_fdmi_iocb(vha, 0, RPA_RSP_SIZE);
1503 /* Prepare CT request */
1504 ct_req = qla2x00_prep_ct_fdmi_req(ha->ct_sns, RPA_CMD, RPA_RSP_SIZE);
1505 ct_rsp = &ha->ct_sns->p.rsp;
1507 /* Prepare FDMI command arguments -- attribute block, attributes. */
1508 memcpy(ct_req->req.rpa.port_name, vha->port_name, WWN_SIZE);
1509 size = WWN_SIZE + 4;
1511 /* Attributes */
1512 ct_req->req.rpa.attrs.count =
1513 __constant_cpu_to_be32(FDMI_PORT_ATTR_COUNT - 1);
1514 entries = ct_req->req.rpa.port_name;
1516 /* FC4 types. */
1517 eiter = (struct ct_fdmi_port_attr *) (entries + size);
1518 eiter->type = __constant_cpu_to_be16(FDMI_PORT_FC4_TYPES);
1519 eiter->len = __constant_cpu_to_be16(4 + 32);
1520 eiter->a.fc4_types[2] = 0x01;
1521 size += 4 + 32;
1523 ql_dbg(ql_dbg_disc, vha, 0x2039,
1524 "FC4_TYPES=%02x %02x.\n",
1525 eiter->a.fc4_types[2],
1526 eiter->a.fc4_types[1]);
1528 /* Supported speed. */
1529 eiter = (struct ct_fdmi_port_attr *) (entries + size);
1530 eiter->type = __constant_cpu_to_be16(FDMI_PORT_SUPPORT_SPEED);
1531 eiter->len = __constant_cpu_to_be16(4 + 4);
1532 if (IS_CNA_CAPABLE(ha))
1533 eiter->a.sup_speed = __constant_cpu_to_be32(
1534 FDMI_PORT_SPEED_10GB);
1535 else if (IS_QLA25XX(ha))
1536 eiter->a.sup_speed = __constant_cpu_to_be32(
1537 FDMI_PORT_SPEED_1GB|FDMI_PORT_SPEED_2GB|
1538 FDMI_PORT_SPEED_4GB|FDMI_PORT_SPEED_8GB);
1539 else if (IS_QLA24XX_TYPE(ha))
1540 eiter->a.sup_speed = __constant_cpu_to_be32(
1541 FDMI_PORT_SPEED_1GB|FDMI_PORT_SPEED_2GB|
1542 FDMI_PORT_SPEED_4GB);
1543 else if (IS_QLA23XX(ha))
1544 eiter->a.sup_speed =__constant_cpu_to_be32(
1545 FDMI_PORT_SPEED_1GB|FDMI_PORT_SPEED_2GB);
1546 else
1547 eiter->a.sup_speed = __constant_cpu_to_be32(
1548 FDMI_PORT_SPEED_1GB);
1549 size += 4 + 4;
1551 ql_dbg(ql_dbg_disc, vha, 0x203a,
1552 "Supported_Speed=%x.\n", eiter->a.sup_speed);
1554 /* Current speed. */
1555 eiter = (struct ct_fdmi_port_attr *) (entries + size);
1556 eiter->type = __constant_cpu_to_be16(FDMI_PORT_CURRENT_SPEED);
1557 eiter->len = __constant_cpu_to_be16(4 + 4);
1558 switch (ha->link_data_rate) {
1559 case PORT_SPEED_1GB:
1560 eiter->a.cur_speed =
1561 __constant_cpu_to_be32(FDMI_PORT_SPEED_1GB);
1562 break;
1563 case PORT_SPEED_2GB:
1564 eiter->a.cur_speed =
1565 __constant_cpu_to_be32(FDMI_PORT_SPEED_2GB);
1566 break;
1567 case PORT_SPEED_4GB:
1568 eiter->a.cur_speed =
1569 __constant_cpu_to_be32(FDMI_PORT_SPEED_4GB);
1570 break;
1571 case PORT_SPEED_8GB:
1572 eiter->a.cur_speed =
1573 __constant_cpu_to_be32(FDMI_PORT_SPEED_8GB);
1574 break;
1575 case PORT_SPEED_10GB:
1576 eiter->a.cur_speed =
1577 __constant_cpu_to_be32(FDMI_PORT_SPEED_10GB);
1578 break;
1579 case PORT_SPEED_16GB:
1580 eiter->a.cur_speed =
1581 __constant_cpu_to_be32(FDMI_PORT_SPEED_16GB);
1582 break;
1583 default:
1584 eiter->a.cur_speed =
1585 __constant_cpu_to_be32(FDMI_PORT_SPEED_UNKNOWN);
1586 break;
1588 size += 4 + 4;
1590 ql_dbg(ql_dbg_disc, vha, 0x203b,
1591 "Current_Speed=%x.\n", eiter->a.cur_speed);
1593 /* Max frame size. */
1594 eiter = (struct ct_fdmi_port_attr *) (entries + size);
1595 eiter->type = __constant_cpu_to_be16(FDMI_PORT_MAX_FRAME_SIZE);
1596 eiter->len = __constant_cpu_to_be16(4 + 4);
1597 max_frame_size = IS_FWI2_CAPABLE(ha) ?
1598 le16_to_cpu(icb24->frame_payload_size):
1599 le16_to_cpu(ha->init_cb->frame_payload_size);
1600 eiter->a.max_frame_size = cpu_to_be32(max_frame_size);
1601 size += 4 + 4;
1603 ql_dbg(ql_dbg_disc, vha, 0x203c,
1604 "Max_Frame_Size=%x.\n", eiter->a.max_frame_size);
1606 /* OS device name. */
1607 eiter = (struct ct_fdmi_port_attr *) (entries + size);
1608 eiter->type = __constant_cpu_to_be16(FDMI_PORT_OS_DEVICE_NAME);
1609 alen = strlen(QLA2XXX_DRIVER_NAME);
1610 strncpy(eiter->a.os_dev_name, QLA2XXX_DRIVER_NAME, alen + 1);
1611 alen += (alen & 3) ? (4 - (alen & 3)) : 4;
1612 eiter->len = cpu_to_be16(4 + alen);
1613 size += 4 + alen;
1615 ql_dbg(ql_dbg_disc, vha, 0x204b,
1616 "OS_Device_Name=%s.\n", eiter->a.os_dev_name);
1618 /* Hostname. */
1619 if (strlen(fc_host_system_hostname(vha->host))) {
1620 ct_req->req.rpa.attrs.count =
1621 __constant_cpu_to_be32(FDMI_PORT_ATTR_COUNT);
1622 eiter = (struct ct_fdmi_port_attr *) (entries + size);
1623 eiter->type = __constant_cpu_to_be16(FDMI_PORT_HOST_NAME);
1624 snprintf(eiter->a.host_name, sizeof(eiter->a.host_name),
1625 "%s", fc_host_system_hostname(vha->host));
1626 alen = strlen(eiter->a.host_name);
1627 alen += (alen & 3) ? (4 - (alen & 3)) : 4;
1628 eiter->len = cpu_to_be16(4 + alen);
1629 size += 4 + alen;
1631 ql_dbg(ql_dbg_disc, vha, 0x203d,
1632 "HostName=%s.\n", eiter->a.host_name);
1635 /* Update MS request size. */
1636 qla2x00_update_ms_fdmi_iocb(vha, size + 16);
1638 ql_dbg(ql_dbg_disc, vha, 0x203e,
1639 "RPA portname= %8phN size=%d.\n", ct_req->req.rpa.port_name, size);
1640 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2079,
1641 entries, size);
1643 /* Execute MS IOCB */
1644 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
1645 sizeof(ms_iocb_entry_t));
1646 if (rval != QLA_SUCCESS) {
1647 /*EMPTY*/
1648 ql_dbg(ql_dbg_disc, vha, 0x2040,
1649 "RPA issue IOCB failed (%d).\n", rval);
1650 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, "RPA") !=
1651 QLA_SUCCESS) {
1652 rval = QLA_FUNCTION_FAILED;
1653 } else {
1654 ql_dbg(ql_dbg_disc, vha, 0x2041,
1655 "RPA exiting nornally.\n");
1658 return rval;
1662 * qla2x00_fdmi_register() -
1663 * @ha: HA context
1665 * Returns 0 on success.
1668 qla2x00_fdmi_register(scsi_qla_host_t *vha)
1670 int rval;
1671 struct qla_hw_data *ha = vha->hw;
1673 if (IS_QLA2100(ha) || IS_QLA2200(ha) ||
1674 IS_QLAFX00(ha))
1675 return QLA_FUNCTION_FAILED;
1677 rval = qla2x00_mgmt_svr_login(vha);
1678 if (rval)
1679 return rval;
1681 rval = qla2x00_fdmi_rhba(vha);
1682 if (rval) {
1683 if (rval != QLA_ALREADY_REGISTERED)
1684 return rval;
1686 rval = qla2x00_fdmi_dhba(vha);
1687 if (rval)
1688 return rval;
1690 rval = qla2x00_fdmi_rhba(vha);
1691 if (rval)
1692 return rval;
1694 rval = qla2x00_fdmi_rpa(vha);
1696 return rval;
1700 * qla2x00_gfpn_id() - SNS Get Fabric Port Name (GFPN_ID) query.
1701 * @ha: HA context
1702 * @list: switch info entries to populate
1704 * Returns 0 on success.
1707 qla2x00_gfpn_id(scsi_qla_host_t *vha, sw_info_t *list)
1709 int rval = QLA_SUCCESS;
1710 uint16_t i;
1711 struct qla_hw_data *ha = vha->hw;
1712 ms_iocb_entry_t *ms_pkt;
1713 struct ct_sns_req *ct_req;
1714 struct ct_sns_rsp *ct_rsp;
1716 if (!IS_IIDMA_CAPABLE(ha))
1717 return QLA_FUNCTION_FAILED;
1719 for (i = 0; i < ha->max_fibre_devices; i++) {
1720 /* Issue GFPN_ID */
1721 /* Prepare common MS IOCB */
1722 ms_pkt = ha->isp_ops->prep_ms_iocb(vha, GFPN_ID_REQ_SIZE,
1723 GFPN_ID_RSP_SIZE);
1725 /* Prepare CT request */
1726 ct_req = qla2x00_prep_ct_req(ha->ct_sns, GFPN_ID_CMD,
1727 GFPN_ID_RSP_SIZE);
1728 ct_rsp = &ha->ct_sns->p.rsp;
1730 /* Prepare CT arguments -- port_id */
1731 ct_req->req.port_id.port_id[0] = list[i].d_id.b.domain;
1732 ct_req->req.port_id.port_id[1] = list[i].d_id.b.area;
1733 ct_req->req.port_id.port_id[2] = list[i].d_id.b.al_pa;
1735 /* Execute MS IOCB */
1736 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
1737 sizeof(ms_iocb_entry_t));
1738 if (rval != QLA_SUCCESS) {
1739 /*EMPTY*/
1740 ql_dbg(ql_dbg_disc, vha, 0x2023,
1741 "GFPN_ID issue IOCB failed (%d).\n", rval);
1742 break;
1743 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp,
1744 "GFPN_ID") != QLA_SUCCESS) {
1745 rval = QLA_FUNCTION_FAILED;
1746 break;
1747 } else {
1748 /* Save fabric portname */
1749 memcpy(list[i].fabric_port_name,
1750 ct_rsp->rsp.gfpn_id.port_name, WWN_SIZE);
1753 /* Last device exit. */
1754 if (list[i].d_id.b.rsvd_1 != 0)
1755 break;
1758 return (rval);
1761 static inline void *
1762 qla24xx_prep_ms_fm_iocb(scsi_qla_host_t *vha, uint32_t req_size,
1763 uint32_t rsp_size)
1765 struct ct_entry_24xx *ct_pkt;
1766 struct qla_hw_data *ha = vha->hw;
1767 ct_pkt = (struct ct_entry_24xx *)ha->ms_iocb;
1768 memset(ct_pkt, 0, sizeof(struct ct_entry_24xx));
1770 ct_pkt->entry_type = CT_IOCB_TYPE;
1771 ct_pkt->entry_count = 1;
1772 ct_pkt->nport_handle = cpu_to_le16(vha->mgmt_svr_loop_id);
1773 ct_pkt->timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
1774 ct_pkt->cmd_dsd_count = __constant_cpu_to_le16(1);
1775 ct_pkt->rsp_dsd_count = __constant_cpu_to_le16(1);
1776 ct_pkt->rsp_byte_count = cpu_to_le32(rsp_size);
1777 ct_pkt->cmd_byte_count = cpu_to_le32(req_size);
1779 ct_pkt->dseg_0_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
1780 ct_pkt->dseg_0_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
1781 ct_pkt->dseg_0_len = ct_pkt->cmd_byte_count;
1783 ct_pkt->dseg_1_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
1784 ct_pkt->dseg_1_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
1785 ct_pkt->dseg_1_len = ct_pkt->rsp_byte_count;
1786 ct_pkt->vp_index = vha->vp_idx;
1788 return ct_pkt;
1792 static inline struct ct_sns_req *
1793 qla24xx_prep_ct_fm_req(struct ct_sns_pkt *p, uint16_t cmd,
1794 uint16_t rsp_size)
1796 memset(p, 0, sizeof(struct ct_sns_pkt));
1798 p->p.req.header.revision = 0x01;
1799 p->p.req.header.gs_type = 0xFA;
1800 p->p.req.header.gs_subtype = 0x01;
1801 p->p.req.command = cpu_to_be16(cmd);
1802 p->p.req.max_rsp_size = cpu_to_be16((rsp_size - 16) / 4);
1804 return &p->p.req;
1808 * qla2x00_gpsc() - FCS Get Port Speed Capabilities (GPSC) query.
1809 * @ha: HA context
1810 * @list: switch info entries to populate
1812 * Returns 0 on success.
1815 qla2x00_gpsc(scsi_qla_host_t *vha, sw_info_t *list)
1817 int rval;
1818 uint16_t i;
1819 struct qla_hw_data *ha = vha->hw;
1820 ms_iocb_entry_t *ms_pkt;
1821 struct ct_sns_req *ct_req;
1822 struct ct_sns_rsp *ct_rsp;
1824 if (!IS_IIDMA_CAPABLE(ha))
1825 return QLA_FUNCTION_FAILED;
1826 if (!ha->flags.gpsc_supported)
1827 return QLA_FUNCTION_FAILED;
1829 rval = qla2x00_mgmt_svr_login(vha);
1830 if (rval)
1831 return rval;
1833 for (i = 0; i < ha->max_fibre_devices; i++) {
1834 /* Issue GFPN_ID */
1835 /* Prepare common MS IOCB */
1836 ms_pkt = qla24xx_prep_ms_fm_iocb(vha, GPSC_REQ_SIZE,
1837 GPSC_RSP_SIZE);
1839 /* Prepare CT request */
1840 ct_req = qla24xx_prep_ct_fm_req(ha->ct_sns, GPSC_CMD,
1841 GPSC_RSP_SIZE);
1842 ct_rsp = &ha->ct_sns->p.rsp;
1844 /* Prepare CT arguments -- port_name */
1845 memcpy(ct_req->req.gpsc.port_name, list[i].fabric_port_name,
1846 WWN_SIZE);
1848 /* Execute MS IOCB */
1849 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
1850 sizeof(ms_iocb_entry_t));
1851 if (rval != QLA_SUCCESS) {
1852 /*EMPTY*/
1853 ql_dbg(ql_dbg_disc, vha, 0x2059,
1854 "GPSC issue IOCB failed (%d).\n", rval);
1855 } else if ((rval = qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp,
1856 "GPSC")) != QLA_SUCCESS) {
1857 /* FM command unsupported? */
1858 if (rval == QLA_INVALID_COMMAND &&
1859 (ct_rsp->header.reason_code ==
1860 CT_REASON_INVALID_COMMAND_CODE ||
1861 ct_rsp->header.reason_code ==
1862 CT_REASON_COMMAND_UNSUPPORTED)) {
1863 ql_dbg(ql_dbg_disc, vha, 0x205a,
1864 "GPSC command unsupported, disabling "
1865 "query.\n");
1866 ha->flags.gpsc_supported = 0;
1867 rval = QLA_FUNCTION_FAILED;
1868 break;
1870 rval = QLA_FUNCTION_FAILED;
1871 } else {
1872 /* Save port-speed */
1873 switch (be16_to_cpu(ct_rsp->rsp.gpsc.speed)) {
1874 case BIT_15:
1875 list[i].fp_speed = PORT_SPEED_1GB;
1876 break;
1877 case BIT_14:
1878 list[i].fp_speed = PORT_SPEED_2GB;
1879 break;
1880 case BIT_13:
1881 list[i].fp_speed = PORT_SPEED_4GB;
1882 break;
1883 case BIT_12:
1884 list[i].fp_speed = PORT_SPEED_10GB;
1885 break;
1886 case BIT_11:
1887 list[i].fp_speed = PORT_SPEED_8GB;
1888 break;
1889 case BIT_10:
1890 list[i].fp_speed = PORT_SPEED_16GB;
1891 break;
1894 ql_dbg(ql_dbg_disc, vha, 0x205b,
1895 "GPSC ext entry - fpn "
1896 "%8phN speeds=%04x speed=%04x.\n",
1897 list[i].fabric_port_name,
1898 be16_to_cpu(ct_rsp->rsp.gpsc.speeds),
1899 be16_to_cpu(ct_rsp->rsp.gpsc.speed));
1902 /* Last device exit. */
1903 if (list[i].d_id.b.rsvd_1 != 0)
1904 break;
1907 return (rval);
1911 * qla2x00_gff_id() - SNS Get FC-4 Features (GFF_ID) query.
1913 * @ha: HA context
1914 * @list: switch info entries to populate
1917 void
1918 qla2x00_gff_id(scsi_qla_host_t *vha, sw_info_t *list)
1920 int rval;
1921 uint16_t i;
1923 ms_iocb_entry_t *ms_pkt;
1924 struct ct_sns_req *ct_req;
1925 struct ct_sns_rsp *ct_rsp;
1926 struct qla_hw_data *ha = vha->hw;
1927 uint8_t fcp_scsi_features = 0;
1929 for (i = 0; i < ha->max_fibre_devices; i++) {
1930 /* Set default FC4 Type as UNKNOWN so the default is to
1931 * Process this port */
1932 list[i].fc4_type = FC4_TYPE_UNKNOWN;
1934 /* Do not attempt GFF_ID if we are not FWI_2 capable */
1935 if (!IS_FWI2_CAPABLE(ha))
1936 continue;
1938 /* Prepare common MS IOCB */
1939 ms_pkt = ha->isp_ops->prep_ms_iocb(vha, GFF_ID_REQ_SIZE,
1940 GFF_ID_RSP_SIZE);
1942 /* Prepare CT request */
1943 ct_req = qla2x00_prep_ct_req(ha->ct_sns, GFF_ID_CMD,
1944 GFF_ID_RSP_SIZE);
1945 ct_rsp = &ha->ct_sns->p.rsp;
1947 /* Prepare CT arguments -- port_id */
1948 ct_req->req.port_id.port_id[0] = list[i].d_id.b.domain;
1949 ct_req->req.port_id.port_id[1] = list[i].d_id.b.area;
1950 ct_req->req.port_id.port_id[2] = list[i].d_id.b.al_pa;
1952 /* Execute MS IOCB */
1953 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
1954 sizeof(ms_iocb_entry_t));
1956 if (rval != QLA_SUCCESS) {
1957 ql_dbg(ql_dbg_disc, vha, 0x205c,
1958 "GFF_ID issue IOCB failed (%d).\n", rval);
1959 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp,
1960 "GFF_ID") != QLA_SUCCESS) {
1961 ql_dbg(ql_dbg_disc, vha, 0x205d,
1962 "GFF_ID IOCB status had a failure status code.\n");
1963 } else {
1964 fcp_scsi_features =
1965 ct_rsp->rsp.gff_id.fc4_features[GFF_FCP_SCSI_OFFSET];
1966 fcp_scsi_features &= 0x0f;
1968 if (fcp_scsi_features)
1969 list[i].fc4_type = FC4_TYPE_FCP_SCSI;
1970 else
1971 list[i].fc4_type = FC4_TYPE_OTHER;
1974 /* Last device exit. */
1975 if (list[i].d_id.b.rsvd_1 != 0)
1976 break;