blob: 84cce36b7a5f5a23b206782f5b6dfffc6532d1de [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Andrew Vasquezfa90c542005-10-27 11:10:08 -07002 * QLogic Fibre Channel HBA Driver
Saurav Kashyap1e633952013-02-08 01:57:54 -05003 * Copyright (c) 2003-2013 QLogic Corporation
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Andrew Vasquezfa90c542005-10-27 11:10:08 -07005 * See LICENSE.qla2xxx for copyright and licensing details.
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 */
7#include "qla_def.h"
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04008#include "qla_target.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -07009
Linus Torvalds1da177e2005-04-16 15:20:36 -070010static int qla2x00_sns_ga_nxt(scsi_qla_host_t *, fc_port_t *);
11static int qla2x00_sns_gid_pt(scsi_qla_host_t *, sw_info_t *);
12static int qla2x00_sns_gpn_id(scsi_qla_host_t *, sw_info_t *);
13static int qla2x00_sns_gnn_id(scsi_qla_host_t *, sw_info_t *);
14static int qla2x00_sns_rft_id(scsi_qla_host_t *);
15static int qla2x00_sns_rnn_id(scsi_qla_host_t *);
16
17/**
Andrew Vasquez8c958a92005-07-06 10:30:47 -070018 * qla2x00_prep_ms_iocb() - Prepare common MS/CT IOCB fields for SNS CT query.
Linus Torvalds1da177e2005-04-16 15:20:36 -070019 * @ha: HA context
20 * @req_size: request size in bytes
21 * @rsp_size: response size in bytes
22 *
23 * Returns a pointer to the @ha's ms_iocb.
24 */
Andrew Vasquez8c958a92005-07-06 10:30:47 -070025void *
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080026qla2x00_prep_ms_iocb(scsi_qla_host_t *vha, uint32_t req_size, uint32_t rsp_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -070027{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080028 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -070029 ms_iocb_entry_t *ms_pkt;
30
31 ms_pkt = ha->ms_iocb;
32 memset(ms_pkt, 0, sizeof(ms_iocb_entry_t));
33
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);
Andrew Vasquez00a537b2008-02-28 14:06:11 -080038 ms_pkt->timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 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);
43
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;
47
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;
51
52 return (ms_pkt);
53}
54
55/**
Andrew Vasquez8c958a92005-07-06 10:30:47 -070056 * qla24xx_prep_ms_iocb() - Prepare common CT IOCB fields for SNS CT query.
57 * @ha: HA context
58 * @req_size: request size in bytes
59 * @rsp_size: response size in bytes
60 *
61 * Returns a pointer to the @ha's ms_iocb.
62 */
63void *
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080064qla24xx_prep_ms_iocb(scsi_qla_host_t *vha, uint32_t req_size, uint32_t rsp_size)
Andrew Vasquez8c958a92005-07-06 10:30:47 -070065{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080066 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez8c958a92005-07-06 10:30:47 -070067 struct ct_entry_24xx *ct_pkt;
68
69 ct_pkt = (struct ct_entry_24xx *)ha->ms_iocb;
70 memset(ct_pkt, 0, sizeof(struct ct_entry_24xx));
71
72 ct_pkt->entry_type = CT_IOCB_TYPE;
73 ct_pkt->entry_count = 1;
74 ct_pkt->nport_handle = __constant_cpu_to_le16(NPH_SNS);
Andrew Vasquez00a537b2008-02-28 14:06:11 -080075 ct_pkt->timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
Andrew Vasquez8c958a92005-07-06 10:30:47 -070076 ct_pkt->cmd_dsd_count = __constant_cpu_to_le16(1);
77 ct_pkt->rsp_dsd_count = __constant_cpu_to_le16(1);
78 ct_pkt->rsp_byte_count = cpu_to_le32(rsp_size);
79 ct_pkt->cmd_byte_count = cpu_to_le32(req_size);
80
81 ct_pkt->dseg_0_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
82 ct_pkt->dseg_0_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
83 ct_pkt->dseg_0_len = ct_pkt->cmd_byte_count;
84
85 ct_pkt->dseg_1_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
86 ct_pkt->dseg_1_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
87 ct_pkt->dseg_1_len = ct_pkt->rsp_byte_count;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080088 ct_pkt->vp_index = vha->vp_idx;
Andrew Vasquez8c958a92005-07-06 10:30:47 -070089
90 return (ct_pkt);
91}
92
93/**
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 * qla2x00_prep_ct_req() - Prepare common CT request fields for SNS query.
95 * @ct_req: CT request buffer
96 * @cmd: GS command
97 * @rsp_size: response size in bytes
98 *
99 * Returns a pointer to the intitialized @ct_req.
100 */
101static inline struct ct_sns_req *
Bart Van Assche6ec6f902013-06-25 11:27:28 -0400102qla2x00_prep_ct_req(struct ct_sns_pkt *p, uint16_t cmd, uint16_t rsp_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103{
Bart Van Assche6ec6f902013-06-25 11:27:28 -0400104 memset(p, 0, sizeof(struct ct_sns_pkt));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105
Bart Van Assche6ec6f902013-06-25 11:27:28 -0400106 p->p.req.header.revision = 0x01;
107 p->p.req.header.gs_type = 0xFC;
108 p->p.req.header.gs_subtype = 0x02;
109 p->p.req.command = cpu_to_be16(cmd);
110 p->p.req.max_rsp_size = cpu_to_be16((rsp_size - 16) / 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111
Bart Van Assche6ec6f902013-06-25 11:27:28 -0400112 return &p->p.req;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113}
114
Andrew Vasquez8c958a92005-07-06 10:30:47 -0700115static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800116qla2x00_chk_ms_status(scsi_qla_host_t *vha, ms_iocb_entry_t *ms_pkt,
Andrew Vasquez8c958a92005-07-06 10:30:47 -0700117 struct ct_sns_rsp *ct_rsp, const char *routine)
118{
119 int rval;
120 uint16_t comp_status;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800121 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez8c958a92005-07-06 10:30:47 -0700122
123 rval = QLA_FUNCTION_FAILED;
124 if (ms_pkt->entry_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700125 ql_dbg(ql_dbg_disc, vha, 0x2031,
126 "%s failed, error status (%x) on port_id: %02x%02x%02x.\n",
127 routine, ms_pkt->entry_status, vha->d_id.b.domain,
128 vha->d_id.b.area, vha->d_id.b.al_pa);
Andrew Vasquez8c958a92005-07-06 10:30:47 -0700129 } else {
Andrew Vasqueze4289242007-07-19 15:05:56 -0700130 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquezcdfc82a2006-12-13 19:20:26 -0800131 comp_status = le16_to_cpu(
132 ((struct ct_entry_24xx *)ms_pkt)->comp_status);
Andrew Vasquez8c958a92005-07-06 10:30:47 -0700133 else
134 comp_status = le16_to_cpu(ms_pkt->status);
135 switch (comp_status) {
136 case CS_COMPLETE:
137 case CS_DATA_UNDERRUN:
138 case CS_DATA_OVERRUN: /* Overrun? */
139 if (ct_rsp->header.response !=
140 __constant_cpu_to_be16(CT_ACCEPT_RESPONSE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700141 ql_dbg(ql_dbg_disc + ql_dbg_buffer, vha, 0x2077,
142 "%s failed rejected request on port_id: "
143 "%02x%02x%02x.\n", routine,
Giridhar Malavalicf2d7712011-02-23 15:27:09 -0800144 vha->d_id.b.domain, vha->d_id.b.area,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700145 vha->d_id.b.al_pa);
146 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha,
147 0x2078, (uint8_t *)&ct_rsp->header,
148 sizeof(struct ct_rsp_hdr));
Andrew Vasquez4346b142006-12-13 19:20:28 -0800149 rval = QLA_INVALID_COMMAND;
Andrew Vasquez8c958a92005-07-06 10:30:47 -0700150 } else
151 rval = QLA_SUCCESS;
152 break;
153 default:
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700154 ql_dbg(ql_dbg_disc, vha, 0x2033,
155 "%s failed, completion status (%x) on port_id: "
156 "%02x%02x%02x.\n", routine, comp_status,
Giridhar Malavalicf2d7712011-02-23 15:27:09 -0800157 vha->d_id.b.domain, vha->d_id.b.area,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700158 vha->d_id.b.al_pa);
Andrew Vasquez8c958a92005-07-06 10:30:47 -0700159 break;
160 }
161 }
162 return rval;
163}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164
165/**
166 * qla2x00_ga_nxt() - SNS scan for fabric devices via GA_NXT command.
167 * @ha: HA context
168 * @fcport: fcport entry to updated
169 *
170 * Returns 0 on success.
171 */
172int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800173qla2x00_ga_nxt(scsi_qla_host_t *vha, fc_port_t *fcport)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174{
175 int rval;
176
177 ms_iocb_entry_t *ms_pkt;
178 struct ct_sns_req *ct_req;
179 struct ct_sns_rsp *ct_rsp;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800180 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800182 if (IS_QLA2100(ha) || IS_QLA2200(ha))
183 return qla2x00_sns_ga_nxt(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184
185 /* Issue GA_NXT */
186 /* Prepare common MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800187 ms_pkt = ha->isp_ops->prep_ms_iocb(vha, GA_NXT_REQ_SIZE,
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700188 GA_NXT_RSP_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189
190 /* Prepare CT request */
Bart Van Assche6ec6f902013-06-25 11:27:28 -0400191 ct_req = qla2x00_prep_ct_req(ha->ct_sns, GA_NXT_CMD,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 GA_NXT_RSP_SIZE);
193 ct_rsp = &ha->ct_sns->p.rsp;
194
195 /* Prepare CT arguments -- port_id */
196 ct_req->req.port_id.port_id[0] = fcport->d_id.b.domain;
197 ct_req->req.port_id.port_id[1] = fcport->d_id.b.area;
198 ct_req->req.port_id.port_id[2] = fcport->d_id.b.al_pa;
199
200 /* Execute MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800201 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 sizeof(ms_iocb_entry_t));
203 if (rval != QLA_SUCCESS) {
204 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700205 ql_dbg(ql_dbg_disc, vha, 0x2062,
206 "GA_NXT issue IOCB failed (%d).\n", rval);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800207 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, "GA_NXT") !=
Andrew Vasquez8c958a92005-07-06 10:30:47 -0700208 QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 rval = QLA_FUNCTION_FAILED;
210 } else {
211 /* Populate fc_port_t entry. */
212 fcport->d_id.b.domain = ct_rsp->rsp.ga_nxt.port_id[0];
213 fcport->d_id.b.area = ct_rsp->rsp.ga_nxt.port_id[1];
214 fcport->d_id.b.al_pa = ct_rsp->rsp.ga_nxt.port_id[2];
215
216 memcpy(fcport->node_name, ct_rsp->rsp.ga_nxt.node_name,
217 WWN_SIZE);
218 memcpy(fcport->port_name, ct_rsp->rsp.ga_nxt.port_name,
219 WWN_SIZE);
220
Armen Baloyana72b9902012-11-21 02:40:30 -0500221 fcport->fc4_type = (ct_rsp->rsp.ga_nxt.fc4_types[2] & BIT_0) ?
222 FC4_TYPE_FCP_SCSI : FC4_TYPE_OTHER;
223
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 if (ct_rsp->rsp.ga_nxt.port_type != NS_N_PORT_TYPE &&
225 ct_rsp->rsp.ga_nxt.port_type != NS_NL_PORT_TYPE)
226 fcport->d_id.b.domain = 0xf0;
227
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700228 ql_dbg(ql_dbg_disc, vha, 0x2063,
Oleksandr Khoshaba7b833552013-08-27 01:37:27 -0400229 "GA_NXT entry - nn %8phN pn %8phN "
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700230 "port_id=%02x%02x%02x.\n",
Oleksandr Khoshaba7b833552013-08-27 01:37:27 -0400231 fcport->node_name, fcport->port_name,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 fcport->d_id.b.domain, fcport->d_id.b.area,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700233 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 }
235
236 return (rval);
237}
238
Chad Dupuis642ef982012-02-09 11:15:57 -0800239static inline int
240qla2x00_gid_pt_rsp_size(scsi_qla_host_t *vha)
241{
242 return vha->hw->max_fibre_devices * 4 + 16;
243}
244
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245/**
246 * qla2x00_gid_pt() - SNS scan for fabric devices via GID_PT command.
247 * @ha: HA context
248 * @list: switch info entries to populate
249 *
250 * NOTE: Non-Nx_Ports are not requested.
251 *
252 * Returns 0 on success.
253 */
254int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800255qla2x00_gid_pt(scsi_qla_host_t *vha, sw_info_t *list)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256{
257 int rval;
258 uint16_t i;
259
260 ms_iocb_entry_t *ms_pkt;
261 struct ct_sns_req *ct_req;
262 struct ct_sns_rsp *ct_rsp;
263
264 struct ct_sns_gid_pt_data *gid_data;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800265 struct qla_hw_data *ha = vha->hw;
Chad Dupuis642ef982012-02-09 11:15:57 -0800266 uint16_t gid_pt_rsp_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800268 if (IS_QLA2100(ha) || IS_QLA2200(ha))
269 return qla2x00_sns_gid_pt(vha, list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270
271 gid_data = NULL;
Chad Dupuis642ef982012-02-09 11:15:57 -0800272 gid_pt_rsp_size = qla2x00_gid_pt_rsp_size(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 /* Issue GID_PT */
274 /* Prepare common MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800275 ms_pkt = ha->isp_ops->prep_ms_iocb(vha, GID_PT_REQ_SIZE,
Chad Dupuis642ef982012-02-09 11:15:57 -0800276 gid_pt_rsp_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277
278 /* Prepare CT request */
Bart Van Assche6ec6f902013-06-25 11:27:28 -0400279 ct_req = qla2x00_prep_ct_req(ha->ct_sns, GID_PT_CMD, gid_pt_rsp_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 ct_rsp = &ha->ct_sns->p.rsp;
281
282 /* Prepare CT arguments -- port_type */
283 ct_req->req.gid_pt.port_type = NS_NX_PORT_TYPE;
284
285 /* Execute MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800286 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 sizeof(ms_iocb_entry_t));
288 if (rval != QLA_SUCCESS) {
289 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700290 ql_dbg(ql_dbg_disc, vha, 0x2055,
291 "GID_PT issue IOCB failed (%d).\n", rval);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800292 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, "GID_PT") !=
Andrew Vasquez8c958a92005-07-06 10:30:47 -0700293 QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 rval = QLA_FUNCTION_FAILED;
295 } else {
296 /* Set port IDs in switch info list. */
Chad Dupuis642ef982012-02-09 11:15:57 -0800297 for (i = 0; i < ha->max_fibre_devices; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 gid_data = &ct_rsp->rsp.gid_pt.entries[i];
299 list[i].d_id.b.domain = gid_data->port_id[0];
300 list[i].d_id.b.area = gid_data->port_id[1];
301 list[i].d_id.b.al_pa = gid_data->port_id[2];
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -0700302 memset(list[i].fabric_port_name, 0, WWN_SIZE);
303 list[i].fp_speed = PORT_SPEED_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304
305 /* Last one exit. */
306 if (gid_data->control_byte & BIT_7) {
307 list[i].d_id.b.rsvd_1 = gid_data->control_byte;
308 break;
309 }
310 }
311
312 /*
313 * If we've used all available slots, then the switch is
314 * reporting back more devices than we can handle with this
315 * single call. Return a failed status, and let GA_NXT handle
316 * the overload.
317 */
Chad Dupuis642ef982012-02-09 11:15:57 -0800318 if (i == ha->max_fibre_devices)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 rval = QLA_FUNCTION_FAILED;
320 }
321
322 return (rval);
323}
324
325/**
326 * qla2x00_gpn_id() - SNS Get Port Name (GPN_ID) query.
327 * @ha: HA context
328 * @list: switch info entries to populate
329 *
330 * Returns 0 on success.
331 */
332int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800333qla2x00_gpn_id(scsi_qla_host_t *vha, sw_info_t *list)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334{
Chad Dupuis642ef982012-02-09 11:15:57 -0800335 int rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 uint16_t i;
337
338 ms_iocb_entry_t *ms_pkt;
339 struct ct_sns_req *ct_req;
340 struct ct_sns_rsp *ct_rsp;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800341 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800343 if (IS_QLA2100(ha) || IS_QLA2200(ha))
344 return qla2x00_sns_gpn_id(vha, list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345
Chad Dupuis642ef982012-02-09 11:15:57 -0800346 for (i = 0; i < ha->max_fibre_devices; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 /* Issue GPN_ID */
348 /* Prepare common MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800349 ms_pkt = ha->isp_ops->prep_ms_iocb(vha, GPN_ID_REQ_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 GPN_ID_RSP_SIZE);
351
352 /* Prepare CT request */
Bart Van Assche6ec6f902013-06-25 11:27:28 -0400353 ct_req = qla2x00_prep_ct_req(ha->ct_sns, GPN_ID_CMD,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 GPN_ID_RSP_SIZE);
355 ct_rsp = &ha->ct_sns->p.rsp;
356
357 /* Prepare CT arguments -- port_id */
358 ct_req->req.port_id.port_id[0] = list[i].d_id.b.domain;
359 ct_req->req.port_id.port_id[1] = list[i].d_id.b.area;
360 ct_req->req.port_id.port_id[2] = list[i].d_id.b.al_pa;
361
362 /* Execute MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800363 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 sizeof(ms_iocb_entry_t));
365 if (rval != QLA_SUCCESS) {
366 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700367 ql_dbg(ql_dbg_disc, vha, 0x2056,
368 "GPN_ID issue IOCB failed (%d).\n", rval);
Arun Easidafdf892012-02-09 11:16:00 -0800369 break;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800370 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp,
Andrew Vasquez8c958a92005-07-06 10:30:47 -0700371 "GPN_ID") != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 rval = QLA_FUNCTION_FAILED;
Arun Easidafdf892012-02-09 11:16:00 -0800373 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 } else {
375 /* Save portname */
376 memcpy(list[i].port_name,
377 ct_rsp->rsp.gpn_id.port_name, WWN_SIZE);
378 }
379
380 /* Last device exit. */
381 if (list[i].d_id.b.rsvd_1 != 0)
382 break;
383 }
384
385 return (rval);
386}
387
388/**
389 * qla2x00_gnn_id() - SNS Get Node Name (GNN_ID) query.
390 * @ha: HA context
391 * @list: switch info entries to populate
392 *
393 * Returns 0 on success.
394 */
395int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800396qla2x00_gnn_id(scsi_qla_host_t *vha, sw_info_t *list)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397{
Chad Dupuis642ef982012-02-09 11:15:57 -0800398 int rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 uint16_t i;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800400 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 ms_iocb_entry_t *ms_pkt;
402 struct ct_sns_req *ct_req;
403 struct ct_sns_rsp *ct_rsp;
404
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800405 if (IS_QLA2100(ha) || IS_QLA2200(ha))
406 return qla2x00_sns_gnn_id(vha, list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407
Chad Dupuis642ef982012-02-09 11:15:57 -0800408 for (i = 0; i < ha->max_fibre_devices; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 /* Issue GNN_ID */
410 /* Prepare common MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800411 ms_pkt = ha->isp_ops->prep_ms_iocb(vha, GNN_ID_REQ_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 GNN_ID_RSP_SIZE);
413
414 /* Prepare CT request */
Bart Van Assche6ec6f902013-06-25 11:27:28 -0400415 ct_req = qla2x00_prep_ct_req(ha->ct_sns, GNN_ID_CMD,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 GNN_ID_RSP_SIZE);
417 ct_rsp = &ha->ct_sns->p.rsp;
418
419 /* Prepare CT arguments -- port_id */
420 ct_req->req.port_id.port_id[0] = list[i].d_id.b.domain;
421 ct_req->req.port_id.port_id[1] = list[i].d_id.b.area;
422 ct_req->req.port_id.port_id[2] = list[i].d_id.b.al_pa;
423
424 /* Execute MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800425 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 sizeof(ms_iocb_entry_t));
427 if (rval != QLA_SUCCESS) {
428 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700429 ql_dbg(ql_dbg_disc, vha, 0x2057,
430 "GNN_ID issue IOCB failed (%d).\n", rval);
Arun Easidafdf892012-02-09 11:16:00 -0800431 break;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800432 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp,
Andrew Vasquez8c958a92005-07-06 10:30:47 -0700433 "GNN_ID") != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 rval = QLA_FUNCTION_FAILED;
Arun Easidafdf892012-02-09 11:16:00 -0800435 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 } else {
437 /* Save nodename */
438 memcpy(list[i].node_name,
439 ct_rsp->rsp.gnn_id.node_name, WWN_SIZE);
440
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700441 ql_dbg(ql_dbg_disc, vha, 0x2058,
Oleksandr Khoshaba7b833552013-08-27 01:37:27 -0400442 "GID_PT entry - nn %8phN pn %8phN "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 "portid=%02x%02x%02x.\n",
Oleksandr Khoshaba7b833552013-08-27 01:37:27 -0400444 list[i].node_name, list[i].port_name,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 list[i].d_id.b.domain, list[i].d_id.b.area,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700446 list[i].d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 }
448
449 /* Last device exit. */
450 if (list[i].d_id.b.rsvd_1 != 0)
451 break;
452 }
453
454 return (rval);
455}
456
457/**
458 * qla2x00_rft_id() - SNS Register FC-4 TYPEs (RFT_ID) supported by the HBA.
459 * @ha: HA context
460 *
461 * Returns 0 on success.
462 */
463int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800464qla2x00_rft_id(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465{
466 int rval;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800467 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 ms_iocb_entry_t *ms_pkt;
469 struct ct_sns_req *ct_req;
470 struct ct_sns_rsp *ct_rsp;
471
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800472 if (IS_QLA2100(ha) || IS_QLA2200(ha))
473 return qla2x00_sns_rft_id(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474
475 /* Issue RFT_ID */
476 /* Prepare common MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800477 ms_pkt = ha->isp_ops->prep_ms_iocb(vha, RFT_ID_REQ_SIZE,
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700478 RFT_ID_RSP_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479
480 /* Prepare CT request */
Bart Van Assche6ec6f902013-06-25 11:27:28 -0400481 ct_req = qla2x00_prep_ct_req(ha->ct_sns, RFT_ID_CMD,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 RFT_ID_RSP_SIZE);
483 ct_rsp = &ha->ct_sns->p.rsp;
484
485 /* Prepare CT arguments -- port_id, FC-4 types */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800486 ct_req->req.rft_id.port_id[0] = vha->d_id.b.domain;
487 ct_req->req.rft_id.port_id[1] = vha->d_id.b.area;
488 ct_req->req.rft_id.port_id[2] = vha->d_id.b.al_pa;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489
490 ct_req->req.rft_id.fc4_types[2] = 0x01; /* FCP-3 */
491
492 /* Execute MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800493 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 sizeof(ms_iocb_entry_t));
495 if (rval != QLA_SUCCESS) {
496 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700497 ql_dbg(ql_dbg_disc, vha, 0x2043,
498 "RFT_ID issue IOCB failed (%d).\n", rval);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800499 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, "RFT_ID") !=
Andrew Vasquez8c958a92005-07-06 10:30:47 -0700500 QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 rval = QLA_FUNCTION_FAILED;
502 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700503 ql_dbg(ql_dbg_disc, vha, 0x2044,
504 "RFT_ID exiting normally.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 }
506
507 return (rval);
508}
509
510/**
511 * qla2x00_rff_id() - SNS Register FC-4 Features (RFF_ID) supported by the HBA.
512 * @ha: HA context
513 *
514 * Returns 0 on success.
515 */
516int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800517qla2x00_rff_id(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518{
519 int rval;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800520 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 ms_iocb_entry_t *ms_pkt;
522 struct ct_sns_req *ct_req;
523 struct ct_sns_rsp *ct_rsp;
524
525 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700526 ql_dbg(ql_dbg_disc, vha, 0x2046,
527 "RFF_ID call not supported on ISP2100/ISP2200.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 return (QLA_SUCCESS);
529 }
530
531 /* Issue RFF_ID */
532 /* Prepare common MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800533 ms_pkt = ha->isp_ops->prep_ms_iocb(vha, RFF_ID_REQ_SIZE,
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700534 RFF_ID_RSP_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535
536 /* Prepare CT request */
Bart Van Assche6ec6f902013-06-25 11:27:28 -0400537 ct_req = qla2x00_prep_ct_req(ha->ct_sns, RFF_ID_CMD,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 RFF_ID_RSP_SIZE);
539 ct_rsp = &ha->ct_sns->p.rsp;
540
541 /* Prepare CT arguments -- port_id, FC-4 feature, FC-4 type */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800542 ct_req->req.rff_id.port_id[0] = vha->d_id.b.domain;
543 ct_req->req.rff_id.port_id[1] = vha->d_id.b.area;
544 ct_req->req.rff_id.port_id[2] = vha->d_id.b.al_pa;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400546 qlt_rff_id(vha, ct_req);
547
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 ct_req->req.rff_id.fc4_type = 0x08; /* SCSI - FCP */
549
550 /* Execute MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800551 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 sizeof(ms_iocb_entry_t));
553 if (rval != QLA_SUCCESS) {
554 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700555 ql_dbg(ql_dbg_disc, vha, 0x2047,
556 "RFF_ID issue IOCB failed (%d).\n", rval);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800557 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, "RFF_ID") !=
Andrew Vasquez8c958a92005-07-06 10:30:47 -0700558 QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 rval = QLA_FUNCTION_FAILED;
560 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700561 ql_dbg(ql_dbg_disc, vha, 0x2048,
562 "RFF_ID exiting normally.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 }
564
565 return (rval);
566}
567
568/**
569 * qla2x00_rnn_id() - SNS Register Node Name (RNN_ID) of the HBA.
570 * @ha: HA context
571 *
572 * Returns 0 on success.
573 */
574int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800575qla2x00_rnn_id(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576{
577 int rval;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800578 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 ms_iocb_entry_t *ms_pkt;
580 struct ct_sns_req *ct_req;
581 struct ct_sns_rsp *ct_rsp;
582
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800583 if (IS_QLA2100(ha) || IS_QLA2200(ha))
584 return qla2x00_sns_rnn_id(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585
586 /* Issue RNN_ID */
587 /* Prepare common MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800588 ms_pkt = ha->isp_ops->prep_ms_iocb(vha, RNN_ID_REQ_SIZE,
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700589 RNN_ID_RSP_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590
591 /* Prepare CT request */
Bart Van Assche6ec6f902013-06-25 11:27:28 -0400592 ct_req = qla2x00_prep_ct_req(ha->ct_sns, RNN_ID_CMD, RNN_ID_RSP_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 ct_rsp = &ha->ct_sns->p.rsp;
594
595 /* Prepare CT arguments -- port_id, node_name */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800596 ct_req->req.rnn_id.port_id[0] = vha->d_id.b.domain;
597 ct_req->req.rnn_id.port_id[1] = vha->d_id.b.area;
598 ct_req->req.rnn_id.port_id[2] = vha->d_id.b.al_pa;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800600 memcpy(ct_req->req.rnn_id.node_name, vha->node_name, WWN_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601
602 /* Execute MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800603 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 sizeof(ms_iocb_entry_t));
605 if (rval != QLA_SUCCESS) {
606 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700607 ql_dbg(ql_dbg_disc, vha, 0x204d,
608 "RNN_ID issue IOCB failed (%d).\n", rval);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800609 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, "RNN_ID") !=
Andrew Vasquez8c958a92005-07-06 10:30:47 -0700610 QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 rval = QLA_FUNCTION_FAILED;
612 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700613 ql_dbg(ql_dbg_disc, vha, 0x204e,
614 "RNN_ID exiting normally.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 }
616
617 return (rval);
618}
619
Andrew Vasquez1620f7c2006-10-02 12:00:44 -0700620void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800621qla2x00_get_sym_node_name(scsi_qla_host_t *vha, uint8_t *snn)
Andrew Vasquez1620f7c2006-10-02 12:00:44 -0700622{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800623 struct qla_hw_data *ha = vha->hw;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400624
625 if (IS_QLAFX00(ha))
626 sprintf(snn, "%s FW:v%s DVR:v%s", ha->model_number,
627 ha->mr.fw_version, qla2x00_version_str);
628 else
629 sprintf(snn, "%s FW:v%d.%02d.%02d DVR:v%s", ha->model_number,
630 ha->fw_major_version, ha->fw_minor_version,
631 ha->fw_subminor_version, qla2x00_version_str);
Andrew Vasquez1620f7c2006-10-02 12:00:44 -0700632}
633
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634/**
635 * qla2x00_rsnn_nn() - SNS Register Symbolic Node Name (RSNN_NN) of the HBA.
636 * @ha: HA context
637 *
638 * Returns 0 on success.
639 */
640int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800641qla2x00_rsnn_nn(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642{
643 int rval;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800644 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 ms_iocb_entry_t *ms_pkt;
646 struct ct_sns_req *ct_req;
647 struct ct_sns_rsp *ct_rsp;
648
649 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700650 ql_dbg(ql_dbg_disc, vha, 0x2050,
651 "RSNN_ID call unsupported on ISP2100/ISP2200.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 return (QLA_SUCCESS);
653 }
654
655 /* Issue RSNN_NN */
656 /* Prepare common MS IOCB */
657 /* Request size adjusted after CT preparation */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800658 ms_pkt = ha->isp_ops->prep_ms_iocb(vha, 0, RSNN_NN_RSP_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659
660 /* Prepare CT request */
Bart Van Assche6ec6f902013-06-25 11:27:28 -0400661 ct_req = qla2x00_prep_ct_req(ha->ct_sns, RSNN_NN_CMD,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 RSNN_NN_RSP_SIZE);
663 ct_rsp = &ha->ct_sns->p.rsp;
664
665 /* Prepare CT arguments -- node_name, symbolic node_name, size */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800666 memcpy(ct_req->req.rsnn_nn.node_name, vha->node_name, WWN_SIZE);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700667
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 /* Prepare the Symbolic Node Name */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800669 qla2x00_get_sym_node_name(vha, ct_req->req.rsnn_nn.sym_node_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670
671 /* Calculate SNN length */
Andrew Vasquez1620f7c2006-10-02 12:00:44 -0700672 ct_req->req.rsnn_nn.name_len =
673 (uint8_t)strlen(ct_req->req.rsnn_nn.sym_node_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674
675 /* Update MS IOCB request */
676 ms_pkt->req_bytecount =
677 cpu_to_le32(24 + 1 + ct_req->req.rsnn_nn.name_len);
678 ms_pkt->dseg_req_length = ms_pkt->req_bytecount;
679
680 /* Execute MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800681 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 sizeof(ms_iocb_entry_t));
683 if (rval != QLA_SUCCESS) {
684 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700685 ql_dbg(ql_dbg_disc, vha, 0x2051,
686 "RSNN_NN issue IOCB failed (%d).\n", rval);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800687 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, "RSNN_NN") !=
Andrew Vasquez8c958a92005-07-06 10:30:47 -0700688 QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 rval = QLA_FUNCTION_FAILED;
690 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700691 ql_dbg(ql_dbg_disc, vha, 0x2052,
692 "RSNN_NN exiting normally.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 }
694
695 return (rval);
696}
697
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698/**
699 * qla2x00_prep_sns_cmd() - Prepare common SNS command request fields for query.
700 * @ha: HA context
701 * @cmd: GS command
702 * @scmd_len: Subcommand length
703 * @data_size: response size in bytes
704 *
705 * Returns a pointer to the @ha's sns_cmd.
706 */
707static inline struct sns_cmd_pkt *
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800708qla2x00_prep_sns_cmd(scsi_qla_host_t *vha, uint16_t cmd, uint16_t scmd_len,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 uint16_t data_size)
710{
711 uint16_t wc;
712 struct sns_cmd_pkt *sns_cmd;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800713 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714
715 sns_cmd = ha->sns_cmd;
716 memset(sns_cmd, 0, sizeof(struct sns_cmd_pkt));
717 wc = data_size / 2; /* Size in 16bit words. */
718 sns_cmd->p.cmd.buffer_length = cpu_to_le16(wc);
719 sns_cmd->p.cmd.buffer_address[0] = cpu_to_le32(LSD(ha->sns_cmd_dma));
720 sns_cmd->p.cmd.buffer_address[1] = cpu_to_le32(MSD(ha->sns_cmd_dma));
721 sns_cmd->p.cmd.subcommand_length = cpu_to_le16(scmd_len);
722 sns_cmd->p.cmd.subcommand = cpu_to_le16(cmd);
723 wc = (data_size - 16) / 4; /* Size in 32bit words. */
724 sns_cmd->p.cmd.size = cpu_to_le16(wc);
725
726 return (sns_cmd);
727}
728
729/**
730 * qla2x00_sns_ga_nxt() - SNS scan for fabric devices via GA_NXT command.
731 * @ha: HA context
732 * @fcport: fcport entry to updated
733 *
734 * This command uses the old Exectute SNS Command mailbox routine.
735 *
736 * Returns 0 on success.
737 */
738static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800739qla2x00_sns_ga_nxt(scsi_qla_host_t *vha, fc_port_t *fcport)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740{
Chad Dupuis642ef982012-02-09 11:15:57 -0800741 int rval = QLA_SUCCESS;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800742 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743 struct sns_cmd_pkt *sns_cmd;
744
745 /* Issue GA_NXT. */
746 /* Prepare SNS command request. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800747 sns_cmd = qla2x00_prep_sns_cmd(vha, GA_NXT_CMD, GA_NXT_SNS_SCMD_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 GA_NXT_SNS_DATA_SIZE);
749
750 /* Prepare SNS command arguments -- port_id. */
751 sns_cmd->p.cmd.param[0] = fcport->d_id.b.al_pa;
752 sns_cmd->p.cmd.param[1] = fcport->d_id.b.area;
753 sns_cmd->p.cmd.param[2] = fcport->d_id.b.domain;
754
755 /* Execute SNS command. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800756 rval = qla2x00_send_sns(vha, ha->sns_cmd_dma, GA_NXT_SNS_CMD_SIZE / 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 sizeof(struct sns_cmd_pkt));
758 if (rval != QLA_SUCCESS) {
759 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700760 ql_dbg(ql_dbg_disc, vha, 0x205f,
761 "GA_NXT Send SNS failed (%d).\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762 } else if (sns_cmd->p.gan_data[8] != 0x80 ||
763 sns_cmd->p.gan_data[9] != 0x02) {
Chad Dupuiscfb09192011-11-18 09:03:07 -0800764 ql_dbg(ql_dbg_disc + ql_dbg_buffer, vha, 0x2084,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700765 "GA_NXT failed, rejected request ga_nxt_rsp:\n");
766 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2074,
767 sns_cmd->p.gan_data, 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768 rval = QLA_FUNCTION_FAILED;
769 } else {
770 /* Populate fc_port_t entry. */
771 fcport->d_id.b.domain = sns_cmd->p.gan_data[17];
772 fcport->d_id.b.area = sns_cmd->p.gan_data[18];
773 fcport->d_id.b.al_pa = sns_cmd->p.gan_data[19];
774
775 memcpy(fcport->node_name, &sns_cmd->p.gan_data[284], WWN_SIZE);
776 memcpy(fcport->port_name, &sns_cmd->p.gan_data[20], WWN_SIZE);
777
778 if (sns_cmd->p.gan_data[16] != NS_N_PORT_TYPE &&
779 sns_cmd->p.gan_data[16] != NS_NL_PORT_TYPE)
780 fcport->d_id.b.domain = 0xf0;
781
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700782 ql_dbg(ql_dbg_disc, vha, 0x2061,
Oleksandr Khoshaba7b833552013-08-27 01:37:27 -0400783 "GA_NXT entry - nn %8phN pn %8phN "
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700784 "port_id=%02x%02x%02x.\n",
Oleksandr Khoshaba7b833552013-08-27 01:37:27 -0400785 fcport->node_name, fcport->port_name,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 fcport->d_id.b.domain, fcport->d_id.b.area,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700787 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788 }
789
790 return (rval);
791}
792
793/**
794 * qla2x00_sns_gid_pt() - SNS scan for fabric devices via GID_PT command.
795 * @ha: HA context
796 * @list: switch info entries to populate
797 *
798 * This command uses the old Exectute SNS Command mailbox routine.
799 *
800 * NOTE: Non-Nx_Ports are not requested.
801 *
802 * Returns 0 on success.
803 */
804static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800805qla2x00_sns_gid_pt(scsi_qla_host_t *vha, sw_info_t *list)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806{
807 int rval;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800808 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 uint16_t i;
810 uint8_t *entry;
811 struct sns_cmd_pkt *sns_cmd;
Chad Dupuis642ef982012-02-09 11:15:57 -0800812 uint16_t gid_pt_sns_data_size;
813
814 gid_pt_sns_data_size = qla2x00_gid_pt_rsp_size(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815
816 /* Issue GID_PT. */
817 /* Prepare SNS command request. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800818 sns_cmd = qla2x00_prep_sns_cmd(vha, GID_PT_CMD, GID_PT_SNS_SCMD_LEN,
Chad Dupuis642ef982012-02-09 11:15:57 -0800819 gid_pt_sns_data_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820
821 /* Prepare SNS command arguments -- port_type. */
822 sns_cmd->p.cmd.param[0] = NS_NX_PORT_TYPE;
823
824 /* Execute SNS command. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800825 rval = qla2x00_send_sns(vha, ha->sns_cmd_dma, GID_PT_SNS_CMD_SIZE / 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826 sizeof(struct sns_cmd_pkt));
827 if (rval != QLA_SUCCESS) {
828 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700829 ql_dbg(ql_dbg_disc, vha, 0x206d,
830 "GID_PT Send SNS failed (%d).\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831 } else if (sns_cmd->p.gid_data[8] != 0x80 ||
832 sns_cmd->p.gid_data[9] != 0x02) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700833 ql_dbg(ql_dbg_disc, vha, 0x202f,
834 "GID_PT failed, rejected request, gid_rsp:\n");
835 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2081,
836 sns_cmd->p.gid_data, 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837 rval = QLA_FUNCTION_FAILED;
838 } else {
839 /* Set port IDs in switch info list. */
Chad Dupuis642ef982012-02-09 11:15:57 -0800840 for (i = 0; i < ha->max_fibre_devices; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841 entry = &sns_cmd->p.gid_data[(i * 4) + 16];
842 list[i].d_id.b.domain = entry[1];
843 list[i].d_id.b.area = entry[2];
844 list[i].d_id.b.al_pa = entry[3];
845
846 /* Last one exit. */
847 if (entry[0] & BIT_7) {
848 list[i].d_id.b.rsvd_1 = entry[0];
849 break;
850 }
851 }
852
853 /*
854 * If we've used all available slots, then the switch is
855 * reporting back more devices that we can handle with this
856 * single call. Return a failed status, and let GA_NXT handle
857 * the overload.
858 */
Chad Dupuis642ef982012-02-09 11:15:57 -0800859 if (i == ha->max_fibre_devices)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 rval = QLA_FUNCTION_FAILED;
861 }
862
863 return (rval);
864}
865
866/**
867 * qla2x00_sns_gpn_id() - SNS Get Port Name (GPN_ID) query.
868 * @ha: HA context
869 * @list: switch info entries to populate
870 *
871 * This command uses the old Exectute SNS Command mailbox routine.
872 *
873 * Returns 0 on success.
874 */
875static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800876qla2x00_sns_gpn_id(scsi_qla_host_t *vha, sw_info_t *list)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877{
Chad Dupuis642ef982012-02-09 11:15:57 -0800878 int rval = QLA_SUCCESS;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800879 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880 uint16_t i;
881 struct sns_cmd_pkt *sns_cmd;
882
Chad Dupuis642ef982012-02-09 11:15:57 -0800883 for (i = 0; i < ha->max_fibre_devices; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884 /* Issue GPN_ID */
885 /* Prepare SNS command request. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800886 sns_cmd = qla2x00_prep_sns_cmd(vha, GPN_ID_CMD,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887 GPN_ID_SNS_SCMD_LEN, GPN_ID_SNS_DATA_SIZE);
888
889 /* Prepare SNS command arguments -- port_id. */
890 sns_cmd->p.cmd.param[0] = list[i].d_id.b.al_pa;
891 sns_cmd->p.cmd.param[1] = list[i].d_id.b.area;
892 sns_cmd->p.cmd.param[2] = list[i].d_id.b.domain;
893
894 /* Execute SNS command. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800895 rval = qla2x00_send_sns(vha, ha->sns_cmd_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896 GPN_ID_SNS_CMD_SIZE / 2, sizeof(struct sns_cmd_pkt));
897 if (rval != QLA_SUCCESS) {
898 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700899 ql_dbg(ql_dbg_disc, vha, 0x2032,
900 "GPN_ID Send SNS failed (%d).\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901 } else if (sns_cmd->p.gpn_data[8] != 0x80 ||
902 sns_cmd->p.gpn_data[9] != 0x02) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700903 ql_dbg(ql_dbg_disc + ql_dbg_buffer, vha, 0x207e,
904 "GPN_ID failed, rejected request, gpn_rsp:\n");
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400905 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x207f,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700906 sns_cmd->p.gpn_data, 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907 rval = QLA_FUNCTION_FAILED;
908 } else {
909 /* Save portname */
910 memcpy(list[i].port_name, &sns_cmd->p.gpn_data[16],
911 WWN_SIZE);
912 }
913
914 /* Last device exit. */
915 if (list[i].d_id.b.rsvd_1 != 0)
916 break;
917 }
918
919 return (rval);
920}
921
922/**
923 * qla2x00_sns_gnn_id() - SNS Get Node Name (GNN_ID) query.
924 * @ha: HA context
925 * @list: switch info entries to populate
926 *
927 * This command uses the old Exectute SNS Command mailbox routine.
928 *
929 * Returns 0 on success.
930 */
931static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800932qla2x00_sns_gnn_id(scsi_qla_host_t *vha, sw_info_t *list)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933{
Chad Dupuis642ef982012-02-09 11:15:57 -0800934 int rval = QLA_SUCCESS;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800935 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936 uint16_t i;
937 struct sns_cmd_pkt *sns_cmd;
938
Chad Dupuis642ef982012-02-09 11:15:57 -0800939 for (i = 0; i < ha->max_fibre_devices; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940 /* Issue GNN_ID */
941 /* Prepare SNS command request. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800942 sns_cmd = qla2x00_prep_sns_cmd(vha, GNN_ID_CMD,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943 GNN_ID_SNS_SCMD_LEN, GNN_ID_SNS_DATA_SIZE);
944
945 /* Prepare SNS command arguments -- port_id. */
946 sns_cmd->p.cmd.param[0] = list[i].d_id.b.al_pa;
947 sns_cmd->p.cmd.param[1] = list[i].d_id.b.area;
948 sns_cmd->p.cmd.param[2] = list[i].d_id.b.domain;
949
950 /* Execute SNS command. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800951 rval = qla2x00_send_sns(vha, ha->sns_cmd_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952 GNN_ID_SNS_CMD_SIZE / 2, sizeof(struct sns_cmd_pkt));
953 if (rval != QLA_SUCCESS) {
954 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700955 ql_dbg(ql_dbg_disc, vha, 0x203f,
956 "GNN_ID Send SNS failed (%d).\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957 } else if (sns_cmd->p.gnn_data[8] != 0x80 ||
958 sns_cmd->p.gnn_data[9] != 0x02) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700959 ql_dbg(ql_dbg_disc + ql_dbg_buffer, vha, 0x2082,
960 "GNN_ID failed, rejected request, gnn_rsp:\n");
961 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x207a,
962 sns_cmd->p.gnn_data, 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963 rval = QLA_FUNCTION_FAILED;
964 } else {
965 /* Save nodename */
966 memcpy(list[i].node_name, &sns_cmd->p.gnn_data[16],
967 WWN_SIZE);
968
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700969 ql_dbg(ql_dbg_disc, vha, 0x206e,
Oleksandr Khoshaba7b833552013-08-27 01:37:27 -0400970 "GID_PT entry - nn %8phN pn %8phN "
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700971 "port_id=%02x%02x%02x.\n",
Oleksandr Khoshaba7b833552013-08-27 01:37:27 -0400972 list[i].node_name, list[i].port_name,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973 list[i].d_id.b.domain, list[i].d_id.b.area,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700974 list[i].d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 }
976
977 /* Last device exit. */
978 if (list[i].d_id.b.rsvd_1 != 0)
979 break;
980 }
981
982 return (rval);
983}
984
985/**
986 * qla2x00_snd_rft_id() - SNS Register FC-4 TYPEs (RFT_ID) supported by the HBA.
987 * @ha: HA context
988 *
989 * This command uses the old Exectute SNS Command mailbox routine.
990 *
991 * Returns 0 on success.
992 */
993static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800994qla2x00_sns_rft_id(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995{
996 int rval;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800997 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998 struct sns_cmd_pkt *sns_cmd;
999
1000 /* Issue RFT_ID. */
1001 /* Prepare SNS command request. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001002 sns_cmd = qla2x00_prep_sns_cmd(vha, RFT_ID_CMD, RFT_ID_SNS_SCMD_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003 RFT_ID_SNS_DATA_SIZE);
1004
1005 /* Prepare SNS command arguments -- port_id, FC-4 types */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001006 sns_cmd->p.cmd.param[0] = vha->d_id.b.al_pa;
1007 sns_cmd->p.cmd.param[1] = vha->d_id.b.area;
1008 sns_cmd->p.cmd.param[2] = vha->d_id.b.domain;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009
1010 sns_cmd->p.cmd.param[5] = 0x01; /* FCP-3 */
1011
1012 /* Execute SNS command. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001013 rval = qla2x00_send_sns(vha, ha->sns_cmd_dma, RFT_ID_SNS_CMD_SIZE / 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014 sizeof(struct sns_cmd_pkt));
1015 if (rval != QLA_SUCCESS) {
1016 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001017 ql_dbg(ql_dbg_disc, vha, 0x2060,
1018 "RFT_ID Send SNS failed (%d).\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019 } else if (sns_cmd->p.rft_data[8] != 0x80 ||
1020 sns_cmd->p.rft_data[9] != 0x02) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001021 ql_dbg(ql_dbg_disc + ql_dbg_buffer, vha, 0x2083,
1022 "RFT_ID failed, rejected request rft_rsp:\n");
1023 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2080,
1024 sns_cmd->p.rft_data, 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025 rval = QLA_FUNCTION_FAILED;
1026 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001027 ql_dbg(ql_dbg_disc, vha, 0x2073,
1028 "RFT_ID exiting normally.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029 }
1030
1031 return (rval);
1032}
1033
1034/**
1035 * qla2x00_sns_rnn_id() - SNS Register Node Name (RNN_ID) of the HBA.
1036 * HBA.
1037 * @ha: HA context
1038 *
1039 * This command uses the old Exectute SNS Command mailbox routine.
1040 *
1041 * Returns 0 on success.
1042 */
1043static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001044qla2x00_sns_rnn_id(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045{
1046 int rval;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001047 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048 struct sns_cmd_pkt *sns_cmd;
1049
1050 /* Issue RNN_ID. */
1051 /* Prepare SNS command request. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001052 sns_cmd = qla2x00_prep_sns_cmd(vha, RNN_ID_CMD, RNN_ID_SNS_SCMD_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053 RNN_ID_SNS_DATA_SIZE);
1054
1055 /* Prepare SNS command arguments -- port_id, nodename. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001056 sns_cmd->p.cmd.param[0] = vha->d_id.b.al_pa;
1057 sns_cmd->p.cmd.param[1] = vha->d_id.b.area;
1058 sns_cmd->p.cmd.param[2] = vha->d_id.b.domain;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001060 sns_cmd->p.cmd.param[4] = vha->node_name[7];
1061 sns_cmd->p.cmd.param[5] = vha->node_name[6];
1062 sns_cmd->p.cmd.param[6] = vha->node_name[5];
1063 sns_cmd->p.cmd.param[7] = vha->node_name[4];
1064 sns_cmd->p.cmd.param[8] = vha->node_name[3];
1065 sns_cmd->p.cmd.param[9] = vha->node_name[2];
1066 sns_cmd->p.cmd.param[10] = vha->node_name[1];
1067 sns_cmd->p.cmd.param[11] = vha->node_name[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068
1069 /* Execute SNS command. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001070 rval = qla2x00_send_sns(vha, ha->sns_cmd_dma, RNN_ID_SNS_CMD_SIZE / 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071 sizeof(struct sns_cmd_pkt));
1072 if (rval != QLA_SUCCESS) {
1073 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001074 ql_dbg(ql_dbg_disc, vha, 0x204a,
1075 "RNN_ID Send SNS failed (%d).\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076 } else if (sns_cmd->p.rnn_data[8] != 0x80 ||
1077 sns_cmd->p.rnn_data[9] != 0x02) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001078 ql_dbg(ql_dbg_disc + ql_dbg_buffer, vha, 0x207b,
1079 "RNN_ID failed, rejected request, rnn_rsp:\n");
1080 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x207c,
1081 sns_cmd->p.rnn_data, 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082 rval = QLA_FUNCTION_FAILED;
1083 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001084 ql_dbg(ql_dbg_disc, vha, 0x204c,
1085 "RNN_ID exiting normally.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086 }
1087
1088 return (rval);
1089}
Andrew Vasquezcca53352005-08-26 19:08:30 -07001090
1091/**
Joe Perchesb1c11812008-02-03 17:28:22 +02001092 * qla2x00_mgmt_svr_login() - Login to fabric Management Service.
Andrew Vasquezcca53352005-08-26 19:08:30 -07001093 * @ha: HA context
1094 *
1095 * Returns 0 on success.
1096 */
1097static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001098qla2x00_mgmt_svr_login(scsi_qla_host_t *vha)
Andrew Vasquezcca53352005-08-26 19:08:30 -07001099{
Chad Dupuis0b91d112012-02-09 11:15:42 -08001100 int ret, rval;
Andrew Vasquezcca53352005-08-26 19:08:30 -07001101 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001102 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezcca53352005-08-26 19:08:30 -07001103 ret = QLA_SUCCESS;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001104 if (vha->flags.management_server_logged_in)
Andrew Vasquezcca53352005-08-26 19:08:30 -07001105 return ret;
1106
Chad Dupuis0b91d112012-02-09 11:15:42 -08001107 rval = ha->isp_ops->fabric_login(vha, vha->mgmt_svr_loop_id, 0xff, 0xff,
Andrew Vasquez58570ac2012-08-22 14:21:18 -04001108 0xfa, mb, BIT_1);
Chad Dupuis0b91d112012-02-09 11:15:42 -08001109 if (rval != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
1110 if (rval == QLA_MEMORY_ALLOC_FAILED)
1111 ql_dbg(ql_dbg_disc, vha, 0x2085,
1112 "Failed management_server login: loopid=%x "
1113 "rval=%d\n", vha->mgmt_svr_loop_id, rval);
1114 else
1115 ql_dbg(ql_dbg_disc, vha, 0x2024,
1116 "Failed management_server login: loopid=%x "
1117 "mb[0]=%x mb[1]=%x mb[2]=%x mb[6]=%x mb[7]=%x.\n",
1118 vha->mgmt_svr_loop_id, mb[0], mb[1], mb[2], mb[6],
1119 mb[7]);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001120 ret = QLA_FUNCTION_FAILED;
1121 } else
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001122 vha->flags.management_server_logged_in = 1;
Andrew Vasquezcca53352005-08-26 19:08:30 -07001123
1124 return ret;
1125}
1126
1127/**
1128 * qla2x00_prep_ms_fdmi_iocb() - Prepare common MS IOCB fields for FDMI query.
1129 * @ha: HA context
1130 * @req_size: request size in bytes
1131 * @rsp_size: response size in bytes
1132 *
1133 * Returns a pointer to the @ha's ms_iocb.
1134 */
1135void *
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001136qla2x00_prep_ms_fdmi_iocb(scsi_qla_host_t *vha, uint32_t req_size,
Andrew Vasquezcca53352005-08-26 19:08:30 -07001137 uint32_t rsp_size)
1138{
1139 ms_iocb_entry_t *ms_pkt;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001140 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezcca53352005-08-26 19:08:30 -07001141 ms_pkt = ha->ms_iocb;
1142 memset(ms_pkt, 0, sizeof(ms_iocb_entry_t));
1143
1144 ms_pkt->entry_type = MS_IOCB_TYPE;
1145 ms_pkt->entry_count = 1;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001146 SET_TARGET_ID(ha, ms_pkt->loop_id, vha->mgmt_svr_loop_id);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001147 ms_pkt->control_flags = __constant_cpu_to_le16(CF_READ | CF_HEAD_TAG);
Andrew Vasquez00a537b2008-02-28 14:06:11 -08001148 ms_pkt->timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001149 ms_pkt->cmd_dsd_count = __constant_cpu_to_le16(1);
1150 ms_pkt->total_dsd_count = __constant_cpu_to_le16(2);
1151 ms_pkt->rsp_bytecount = cpu_to_le32(rsp_size);
1152 ms_pkt->req_bytecount = cpu_to_le32(req_size);
1153
1154 ms_pkt->dseg_req_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
1155 ms_pkt->dseg_req_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
1156 ms_pkt->dseg_req_length = ms_pkt->req_bytecount;
1157
1158 ms_pkt->dseg_rsp_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
1159 ms_pkt->dseg_rsp_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
1160 ms_pkt->dseg_rsp_length = ms_pkt->rsp_bytecount;
1161
1162 return ms_pkt;
1163}
1164
1165/**
1166 * qla24xx_prep_ms_fdmi_iocb() - Prepare common MS IOCB fields for FDMI query.
1167 * @ha: HA context
1168 * @req_size: request size in bytes
1169 * @rsp_size: response size in bytes
1170 *
1171 * Returns a pointer to the @ha's ms_iocb.
1172 */
1173void *
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001174qla24xx_prep_ms_fdmi_iocb(scsi_qla_host_t *vha, uint32_t req_size,
Andrew Vasquezcca53352005-08-26 19:08:30 -07001175 uint32_t rsp_size)
1176{
1177 struct ct_entry_24xx *ct_pkt;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001178 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezcca53352005-08-26 19:08:30 -07001179
1180 ct_pkt = (struct ct_entry_24xx *)ha->ms_iocb;
1181 memset(ct_pkt, 0, sizeof(struct ct_entry_24xx));
1182
1183 ct_pkt->entry_type = CT_IOCB_TYPE;
1184 ct_pkt->entry_count = 1;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001185 ct_pkt->nport_handle = cpu_to_le16(vha->mgmt_svr_loop_id);
Andrew Vasquez00a537b2008-02-28 14:06:11 -08001186 ct_pkt->timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001187 ct_pkt->cmd_dsd_count = __constant_cpu_to_le16(1);
1188 ct_pkt->rsp_dsd_count = __constant_cpu_to_le16(1);
1189 ct_pkt->rsp_byte_count = cpu_to_le32(rsp_size);
1190 ct_pkt->cmd_byte_count = cpu_to_le32(req_size);
1191
1192 ct_pkt->dseg_0_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
1193 ct_pkt->dseg_0_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
1194 ct_pkt->dseg_0_len = ct_pkt->cmd_byte_count;
1195
1196 ct_pkt->dseg_1_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
1197 ct_pkt->dseg_1_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
1198 ct_pkt->dseg_1_len = ct_pkt->rsp_byte_count;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001199 ct_pkt->vp_index = vha->vp_idx;
Andrew Vasquezcca53352005-08-26 19:08:30 -07001200
1201 return ct_pkt;
1202}
1203
1204static inline ms_iocb_entry_t *
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001205qla2x00_update_ms_fdmi_iocb(scsi_qla_host_t *vha, uint32_t req_size)
Andrew Vasquezcca53352005-08-26 19:08:30 -07001206{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001207 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezcca53352005-08-26 19:08:30 -07001208 ms_iocb_entry_t *ms_pkt = ha->ms_iocb;
1209 struct ct_entry_24xx *ct_pkt = (struct ct_entry_24xx *)ha->ms_iocb;
1210
Andrew Vasqueze4289242007-07-19 15:05:56 -07001211 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquezcca53352005-08-26 19:08:30 -07001212 ct_pkt->cmd_byte_count = cpu_to_le32(req_size);
1213 ct_pkt->dseg_0_len = ct_pkt->cmd_byte_count;
1214 } else {
1215 ms_pkt->req_bytecount = cpu_to_le32(req_size);
1216 ms_pkt->dseg_req_length = ms_pkt->req_bytecount;
1217 }
1218
1219 return ms_pkt;
1220}
1221
1222/**
1223 * qla2x00_prep_ct_req() - Prepare common CT request fields for SNS query.
1224 * @ct_req: CT request buffer
1225 * @cmd: GS command
1226 * @rsp_size: response size in bytes
1227 *
1228 * Returns a pointer to the intitialized @ct_req.
1229 */
1230static inline struct ct_sns_req *
Bart Van Assche6ec6f902013-06-25 11:27:28 -04001231qla2x00_prep_ct_fdmi_req(struct ct_sns_pkt *p, uint16_t cmd,
Andrew Vasquezcca53352005-08-26 19:08:30 -07001232 uint16_t rsp_size)
1233{
Bart Van Assche6ec6f902013-06-25 11:27:28 -04001234 memset(p, 0, sizeof(struct ct_sns_pkt));
Andrew Vasquezcca53352005-08-26 19:08:30 -07001235
Bart Van Assche6ec6f902013-06-25 11:27:28 -04001236 p->p.req.header.revision = 0x01;
1237 p->p.req.header.gs_type = 0xFA;
1238 p->p.req.header.gs_subtype = 0x10;
1239 p->p.req.command = cpu_to_be16(cmd);
1240 p->p.req.max_rsp_size = cpu_to_be16((rsp_size - 16) / 4);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001241
Bart Van Assche6ec6f902013-06-25 11:27:28 -04001242 return &p->p.req;
Andrew Vasquezcca53352005-08-26 19:08:30 -07001243}
1244
1245/**
1246 * qla2x00_fdmi_rhba() -
1247 * @ha: HA context
1248 *
1249 * Returns 0 on success.
1250 */
1251static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001252qla2x00_fdmi_rhba(scsi_qla_host_t *vha)
Andrew Vasquezcca53352005-08-26 19:08:30 -07001253{
1254 int rval, alen;
1255 uint32_t size, sn;
1256
1257 ms_iocb_entry_t *ms_pkt;
1258 struct ct_sns_req *ct_req;
1259 struct ct_sns_rsp *ct_rsp;
1260 uint8_t *entries;
1261 struct ct_fdmi_hba_attr *eiter;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001262 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezcca53352005-08-26 19:08:30 -07001263
1264 /* Issue RHBA */
1265 /* Prepare common MS IOCB */
1266 /* Request size adjusted after CT preparation */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001267 ms_pkt = ha->isp_ops->prep_ms_fdmi_iocb(vha, 0, RHBA_RSP_SIZE);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001268
1269 /* Prepare CT request */
Bart Van Assche6ec6f902013-06-25 11:27:28 -04001270 ct_req = qla2x00_prep_ct_fdmi_req(ha->ct_sns, RHBA_CMD, RHBA_RSP_SIZE);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001271 ct_rsp = &ha->ct_sns->p.rsp;
1272
1273 /* Prepare FDMI command arguments -- attribute block, attributes. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001274 memcpy(ct_req->req.rhba.hba_identifier, vha->port_name, WWN_SIZE);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001275 ct_req->req.rhba.entry_count = __constant_cpu_to_be32(1);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001276 memcpy(ct_req->req.rhba.port_name, vha->port_name, WWN_SIZE);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001277 size = 2 * WWN_SIZE + 4 + 4;
1278
1279 /* Attributes */
1280 ct_req->req.rhba.attrs.count =
1281 __constant_cpu_to_be32(FDMI_HBA_ATTR_COUNT);
1282 entries = ct_req->req.rhba.hba_identifier;
1283
1284 /* Nodename. */
1285 eiter = (struct ct_fdmi_hba_attr *) (entries + size);
1286 eiter->type = __constant_cpu_to_be16(FDMI_HBA_NODE_NAME);
1287 eiter->len = __constant_cpu_to_be16(4 + WWN_SIZE);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001288 memcpy(eiter->a.node_name, vha->node_name, WWN_SIZE);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001289 size += 4 + WWN_SIZE;
1290
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001291 ql_dbg(ql_dbg_disc, vha, 0x2025,
Oleksandr Khoshaba7b833552013-08-27 01:37:27 -04001292 "NodeName = %8phN.\n", eiter->a.node_name);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001293
1294 /* Manufacturer. */
1295 eiter = (struct ct_fdmi_hba_attr *) (entries + size);
1296 eiter->type = __constant_cpu_to_be16(FDMI_HBA_MANUFACTURER);
Paul Bollef24b6972013-02-08 01:57:55 -05001297 alen = strlen(QLA2XXX_MANUFACTURER);
1298 strncpy(eiter->a.manufacturer, QLA2XXX_MANUFACTURER, alen + 1);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001299 alen += (alen & 3) ? (4 - (alen & 3)) : 4;
1300 eiter->len = cpu_to_be16(4 + alen);
1301 size += 4 + alen;
1302
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001303 ql_dbg(ql_dbg_disc, vha, 0x2026,
1304 "Manufacturer = %s.\n", eiter->a.manufacturer);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001305
1306 /* Serial number. */
1307 eiter = (struct ct_fdmi_hba_attr *) (entries + size);
1308 eiter->type = __constant_cpu_to_be16(FDMI_HBA_SERIAL_NUMBER);
1309 sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
1310 sprintf(eiter->a.serial_num, "%c%05d", 'A' + sn / 100000, sn % 100000);
1311 alen = strlen(eiter->a.serial_num);
1312 alen += (alen & 3) ? (4 - (alen & 3)) : 4;
1313 eiter->len = cpu_to_be16(4 + alen);
1314 size += 4 + alen;
1315
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001316 ql_dbg(ql_dbg_disc, vha, 0x2027,
1317 "Serial no. = %s.\n", eiter->a.serial_num);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001318
1319 /* Model name. */
1320 eiter = (struct ct_fdmi_hba_attr *) (entries + size);
1321 eiter->type = __constant_cpu_to_be16(FDMI_HBA_MODEL);
1322 strcpy(eiter->a.model, ha->model_number);
1323 alen = strlen(eiter->a.model);
1324 alen += (alen & 3) ? (4 - (alen & 3)) : 4;
1325 eiter->len = cpu_to_be16(4 + alen);
1326 size += 4 + alen;
1327
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001328 ql_dbg(ql_dbg_disc, vha, 0x2028,
1329 "Model Name = %s.\n", eiter->a.model);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001330
1331 /* Model description. */
1332 eiter = (struct ct_fdmi_hba_attr *) (entries + size);
1333 eiter->type = __constant_cpu_to_be16(FDMI_HBA_MODEL_DESCRIPTION);
Bart Van Asschec5dcfaa2013-06-25 11:27:25 -04001334 strncpy(eiter->a.model_desc, ha->model_desc, 80);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001335 alen = strlen(eiter->a.model_desc);
1336 alen += (alen & 3) ? (4 - (alen & 3)) : 4;
1337 eiter->len = cpu_to_be16(4 + alen);
1338 size += 4 + alen;
1339
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001340 ql_dbg(ql_dbg_disc, vha, 0x2029,
1341 "Model Desc = %s.\n", eiter->a.model_desc);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001342
1343 /* Hardware version. */
1344 eiter = (struct ct_fdmi_hba_attr *) (entries + size);
1345 eiter->type = __constant_cpu_to_be16(FDMI_HBA_HARDWARE_VERSION);
1346 strcpy(eiter->a.hw_version, ha->adapter_id);
1347 alen = strlen(eiter->a.hw_version);
1348 alen += (alen & 3) ? (4 - (alen & 3)) : 4;
1349 eiter->len = cpu_to_be16(4 + alen);
1350 size += 4 + alen;
1351
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001352 ql_dbg(ql_dbg_disc, vha, 0x202a,
1353 "Hardware ver = %s.\n", eiter->a.hw_version);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001354
1355 /* Driver version. */
1356 eiter = (struct ct_fdmi_hba_attr *) (entries + size);
1357 eiter->type = __constant_cpu_to_be16(FDMI_HBA_DRIVER_VERSION);
1358 strcpy(eiter->a.driver_version, qla2x00_version_str);
1359 alen = strlen(eiter->a.driver_version);
1360 alen += (alen & 3) ? (4 - (alen & 3)) : 4;
1361 eiter->len = cpu_to_be16(4 + alen);
1362 size += 4 + alen;
1363
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001364 ql_dbg(ql_dbg_disc, vha, 0x202b,
1365 "Driver ver = %s.\n", eiter->a.driver_version);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001366
1367 /* Option ROM version. */
1368 eiter = (struct ct_fdmi_hba_attr *) (entries + size);
1369 eiter->type = __constant_cpu_to_be16(FDMI_HBA_OPTION_ROM_VERSION);
1370 strcpy(eiter->a.orom_version, "0.00");
1371 alen = strlen(eiter->a.orom_version);
1372 alen += (alen & 3) ? (4 - (alen & 3)) : 4;
1373 eiter->len = cpu_to_be16(4 + alen);
1374 size += 4 + alen;
1375
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001376 ql_dbg(ql_dbg_disc, vha , 0x202c,
1377 "Optrom vers = %s.\n", eiter->a.orom_version);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001378
1379 /* Firmware version */
1380 eiter = (struct ct_fdmi_hba_attr *) (entries + size);
1381 eiter->type = __constant_cpu_to_be16(FDMI_HBA_FIRMWARE_VERSION);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001382 ha->isp_ops->fw_version_str(vha, eiter->a.fw_version);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001383 alen = strlen(eiter->a.fw_version);
1384 alen += (alen & 3) ? (4 - (alen & 3)) : 4;
1385 eiter->len = cpu_to_be16(4 + alen);
1386 size += 4 + alen;
1387
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001388 ql_dbg(ql_dbg_disc, vha, 0x202d,
1389 "Firmware vers = %s.\n", eiter->a.fw_version);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001390
1391 /* Update MS request size. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001392 qla2x00_update_ms_fdmi_iocb(vha, size + 16);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001393
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001394 ql_dbg(ql_dbg_disc, vha, 0x202e,
Oleksandr Khoshaba7b833552013-08-27 01:37:27 -04001395 "RHBA identifier = %8phN size=%d.\n",
1396 ct_req->req.rhba.hba_identifier, size);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001397 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2076,
1398 entries, size);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001399
1400 /* Execute MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001401 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
Andrew Vasquezcca53352005-08-26 19:08:30 -07001402 sizeof(ms_iocb_entry_t));
1403 if (rval != QLA_SUCCESS) {
1404 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001405 ql_dbg(ql_dbg_disc, vha, 0x2030,
1406 "RHBA issue IOCB failed (%d).\n", rval);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001407 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, "RHBA") !=
Andrew Vasquezcca53352005-08-26 19:08:30 -07001408 QLA_SUCCESS) {
1409 rval = QLA_FUNCTION_FAILED;
1410 if (ct_rsp->header.reason_code == CT_REASON_CANNOT_PERFORM &&
1411 ct_rsp->header.explanation_code ==
1412 CT_EXPL_ALREADY_REGISTERED) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001413 ql_dbg(ql_dbg_disc, vha, 0x2034,
1414 "HBA already registered.\n");
Andrew Vasquezcca53352005-08-26 19:08:30 -07001415 rval = QLA_ALREADY_REGISTERED;
1416 }
1417 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001418 ql_dbg(ql_dbg_disc, vha, 0x2035,
1419 "RHBA exiting normally.\n");
Andrew Vasquezcca53352005-08-26 19:08:30 -07001420 }
1421
1422 return rval;
1423}
1424
1425/**
1426 * qla2x00_fdmi_dhba() -
1427 * @ha: HA context
1428 *
1429 * Returns 0 on success.
1430 */
1431static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001432qla2x00_fdmi_dhba(scsi_qla_host_t *vha)
Andrew Vasquezcca53352005-08-26 19:08:30 -07001433{
1434 int rval;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001435 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezcca53352005-08-26 19:08:30 -07001436 ms_iocb_entry_t *ms_pkt;
1437 struct ct_sns_req *ct_req;
1438 struct ct_sns_rsp *ct_rsp;
1439
1440 /* Issue RPA */
1441 /* Prepare common MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001442 ms_pkt = ha->isp_ops->prep_ms_fdmi_iocb(vha, DHBA_REQ_SIZE,
Andrew Vasquezcca53352005-08-26 19:08:30 -07001443 DHBA_RSP_SIZE);
1444
1445 /* Prepare CT request */
Bart Van Assche6ec6f902013-06-25 11:27:28 -04001446 ct_req = qla2x00_prep_ct_fdmi_req(ha->ct_sns, DHBA_CMD, DHBA_RSP_SIZE);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001447 ct_rsp = &ha->ct_sns->p.rsp;
1448
1449 /* Prepare FDMI command arguments -- portname. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001450 memcpy(ct_req->req.dhba.port_name, vha->port_name, WWN_SIZE);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001451
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001452 ql_dbg(ql_dbg_disc, vha, 0x2036,
Oleksandr Khoshaba7b833552013-08-27 01:37:27 -04001453 "DHBA portname = %8phN.\n", ct_req->req.dhba.port_name);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001454
1455 /* Execute MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001456 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
Andrew Vasquezcca53352005-08-26 19:08:30 -07001457 sizeof(ms_iocb_entry_t));
1458 if (rval != QLA_SUCCESS) {
1459 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001460 ql_dbg(ql_dbg_disc, vha, 0x2037,
1461 "DHBA issue IOCB failed (%d).\n", rval);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001462 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, "DHBA") !=
Andrew Vasquezcca53352005-08-26 19:08:30 -07001463 QLA_SUCCESS) {
1464 rval = QLA_FUNCTION_FAILED;
1465 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001466 ql_dbg(ql_dbg_disc, vha, 0x2038,
1467 "DHBA exiting normally.\n");
Andrew Vasquezcca53352005-08-26 19:08:30 -07001468 }
1469
1470 return rval;
1471}
1472
1473/**
1474 * qla2x00_fdmi_rpa() -
1475 * @ha: HA context
1476 *
1477 * Returns 0 on success.
1478 */
1479static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001480qla2x00_fdmi_rpa(scsi_qla_host_t *vha)
Andrew Vasquezcca53352005-08-26 19:08:30 -07001481{
1482 int rval, alen;
1483 uint32_t size, max_frame_size;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001484 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezcca53352005-08-26 19:08:30 -07001485 ms_iocb_entry_t *ms_pkt;
1486 struct ct_sns_req *ct_req;
1487 struct ct_sns_rsp *ct_rsp;
1488 uint8_t *entries;
1489 struct ct_fdmi_port_attr *eiter;
1490 struct init_cb_24xx *icb24 = (struct init_cb_24xx *)ha->init_cb;
1491
1492 /* Issue RPA */
1493 /* Prepare common MS IOCB */
1494 /* Request size adjusted after CT preparation */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001495 ms_pkt = ha->isp_ops->prep_ms_fdmi_iocb(vha, 0, RPA_RSP_SIZE);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001496
1497 /* Prepare CT request */
Bart Van Assche6ec6f902013-06-25 11:27:28 -04001498 ct_req = qla2x00_prep_ct_fdmi_req(ha->ct_sns, RPA_CMD, RPA_RSP_SIZE);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001499 ct_rsp = &ha->ct_sns->p.rsp;
1500
1501 /* Prepare FDMI command arguments -- attribute block, attributes. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001502 memcpy(ct_req->req.rpa.port_name, vha->port_name, WWN_SIZE);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001503 size = WWN_SIZE + 4;
1504
1505 /* Attributes */
1506 ct_req->req.rpa.attrs.count =
Andrew Vasquez8a85e1712007-09-20 14:07:41 -07001507 __constant_cpu_to_be32(FDMI_PORT_ATTR_COUNT - 1);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001508 entries = ct_req->req.rpa.port_name;
1509
1510 /* FC4 types. */
1511 eiter = (struct ct_fdmi_port_attr *) (entries + size);
1512 eiter->type = __constant_cpu_to_be16(FDMI_PORT_FC4_TYPES);
1513 eiter->len = __constant_cpu_to_be16(4 + 32);
1514 eiter->a.fc4_types[2] = 0x01;
1515 size += 4 + 32;
1516
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001517 ql_dbg(ql_dbg_disc, vha, 0x2039,
1518 "FC4_TYPES=%02x %02x.\n",
1519 eiter->a.fc4_types[2],
1520 eiter->a.fc4_types[1]);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001521
1522 /* Supported speed. */
1523 eiter = (struct ct_fdmi_port_attr *) (entries + size);
1524 eiter->type = __constant_cpu_to_be16(FDMI_PORT_SUPPORT_SPEED);
1525 eiter->len = __constant_cpu_to_be16(4 + 4);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001526 if (IS_CNA_CAPABLE(ha))
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001527 eiter->a.sup_speed = __constant_cpu_to_be32(
1528 FDMI_PORT_SPEED_10GB);
1529 else if (IS_QLA25XX(ha))
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001530 eiter->a.sup_speed = __constant_cpu_to_be32(
1531 FDMI_PORT_SPEED_1GB|FDMI_PORT_SPEED_2GB|
1532 FDMI_PORT_SPEED_4GB|FDMI_PORT_SPEED_8GB);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001533 else if (IS_QLA24XX_TYPE(ha))
Andrew Vasquez58815692007-07-19 15:05:58 -07001534 eiter->a.sup_speed = __constant_cpu_to_be32(
1535 FDMI_PORT_SPEED_1GB|FDMI_PORT_SPEED_2GB|
1536 FDMI_PORT_SPEED_4GB);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001537 else if (IS_QLA23XX(ha))
Andrew Vasquez58815692007-07-19 15:05:58 -07001538 eiter->a.sup_speed =__constant_cpu_to_be32(
1539 FDMI_PORT_SPEED_1GB|FDMI_PORT_SPEED_2GB);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001540 else
Andrew Vasquez58815692007-07-19 15:05:58 -07001541 eiter->a.sup_speed = __constant_cpu_to_be32(
1542 FDMI_PORT_SPEED_1GB);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001543 size += 4 + 4;
1544
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001545 ql_dbg(ql_dbg_disc, vha, 0x203a,
1546 "Supported_Speed=%x.\n", eiter->a.sup_speed);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001547
1548 /* Current speed. */
1549 eiter = (struct ct_fdmi_port_attr *) (entries + size);
1550 eiter->type = __constant_cpu_to_be16(FDMI_PORT_CURRENT_SPEED);
1551 eiter->len = __constant_cpu_to_be16(4 + 4);
1552 switch (ha->link_data_rate) {
Andrew Vasquez58815692007-07-19 15:05:58 -07001553 case PORT_SPEED_1GB:
1554 eiter->a.cur_speed =
1555 __constant_cpu_to_be32(FDMI_PORT_SPEED_1GB);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001556 break;
Andrew Vasquez58815692007-07-19 15:05:58 -07001557 case PORT_SPEED_2GB:
1558 eiter->a.cur_speed =
1559 __constant_cpu_to_be32(FDMI_PORT_SPEED_2GB);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001560 break;
Andrew Vasquez58815692007-07-19 15:05:58 -07001561 case PORT_SPEED_4GB:
1562 eiter->a.cur_speed =
1563 __constant_cpu_to_be32(FDMI_PORT_SPEED_4GB);
1564 break;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001565 case PORT_SPEED_8GB:
1566 eiter->a.cur_speed =
1567 __constant_cpu_to_be32(FDMI_PORT_SPEED_8GB);
1568 break;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001569 case PORT_SPEED_10GB:
1570 eiter->a.cur_speed =
1571 __constant_cpu_to_be32(FDMI_PORT_SPEED_10GB);
1572 break;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001573 case PORT_SPEED_16GB:
1574 eiter->a.cur_speed =
1575 __constant_cpu_to_be32(FDMI_PORT_SPEED_16GB);
1576 break;
Andrew Vasquez58815692007-07-19 15:05:58 -07001577 default:
1578 eiter->a.cur_speed =
1579 __constant_cpu_to_be32(FDMI_PORT_SPEED_UNKNOWN);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001580 break;
1581 }
1582 size += 4 + 4;
1583
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001584 ql_dbg(ql_dbg_disc, vha, 0x203b,
1585 "Current_Speed=%x.\n", eiter->a.cur_speed);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001586
1587 /* Max frame size. */
1588 eiter = (struct ct_fdmi_port_attr *) (entries + size);
1589 eiter->type = __constant_cpu_to_be16(FDMI_PORT_MAX_FRAME_SIZE);
1590 eiter->len = __constant_cpu_to_be16(4 + 4);
Andrew Vasqueze4289242007-07-19 15:05:56 -07001591 max_frame_size = IS_FWI2_CAPABLE(ha) ?
Seokmann Juc6852c42008-04-24 15:21:29 -07001592 le16_to_cpu(icb24->frame_payload_size):
1593 le16_to_cpu(ha->init_cb->frame_payload_size);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001594 eiter->a.max_frame_size = cpu_to_be32(max_frame_size);
1595 size += 4 + 4;
1596
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001597 ql_dbg(ql_dbg_disc, vha, 0x203c,
1598 "Max_Frame_Size=%x.\n", eiter->a.max_frame_size);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001599
1600 /* OS device name. */
1601 eiter = (struct ct_fdmi_port_attr *) (entries + size);
1602 eiter->type = __constant_cpu_to_be16(FDMI_PORT_OS_DEVICE_NAME);
Paul Bollef24b6972013-02-08 01:57:55 -05001603 alen = strlen(QLA2XXX_DRIVER_NAME);
1604 strncpy(eiter->a.os_dev_name, QLA2XXX_DRIVER_NAME, alen + 1);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001605 alen += (alen & 3) ? (4 - (alen & 3)) : 4;
1606 eiter->len = cpu_to_be16(4 + alen);
1607 size += 4 + alen;
1608
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001609 ql_dbg(ql_dbg_disc, vha, 0x204b,
1610 "OS_Device_Name=%s.\n", eiter->a.os_dev_name);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001611
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07001612 /* Hostname. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001613 if (strlen(fc_host_system_hostname(vha->host))) {
Andrew Vasquez8a85e1712007-09-20 14:07:41 -07001614 ct_req->req.rpa.attrs.count =
1615 __constant_cpu_to_be32(FDMI_PORT_ATTR_COUNT);
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07001616 eiter = (struct ct_fdmi_port_attr *) (entries + size);
1617 eiter->type = __constant_cpu_to_be16(FDMI_PORT_HOST_NAME);
1618 snprintf(eiter->a.host_name, sizeof(eiter->a.host_name),
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001619 "%s", fc_host_system_hostname(vha->host));
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07001620 alen = strlen(eiter->a.host_name);
1621 alen += (alen & 3) ? (4 - (alen & 3)) : 4;
1622 eiter->len = cpu_to_be16(4 + alen);
1623 size += 4 + alen;
1624
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001625 ql_dbg(ql_dbg_disc, vha, 0x203d,
1626 "HostName=%s.\n", eiter->a.host_name);
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07001627 }
1628
Andrew Vasquezcca53352005-08-26 19:08:30 -07001629 /* Update MS request size. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001630 qla2x00_update_ms_fdmi_iocb(vha, size + 16);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001631
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001632 ql_dbg(ql_dbg_disc, vha, 0x203e,
Oleksandr Khoshaba7b833552013-08-27 01:37:27 -04001633 "RPA portname= %8phN size=%d.\n", ct_req->req.rpa.port_name, size);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001634 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2079,
1635 entries, size);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001636
1637 /* Execute MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001638 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
Andrew Vasquezcca53352005-08-26 19:08:30 -07001639 sizeof(ms_iocb_entry_t));
1640 if (rval != QLA_SUCCESS) {
1641 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001642 ql_dbg(ql_dbg_disc, vha, 0x2040,
1643 "RPA issue IOCB failed (%d).\n", rval);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001644 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, "RPA") !=
Andrew Vasquezcca53352005-08-26 19:08:30 -07001645 QLA_SUCCESS) {
1646 rval = QLA_FUNCTION_FAILED;
1647 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001648 ql_dbg(ql_dbg_disc, vha, 0x2041,
1649 "RPA exiting nornally.\n");
Andrew Vasquezcca53352005-08-26 19:08:30 -07001650 }
1651
1652 return rval;
1653}
1654
1655/**
1656 * qla2x00_fdmi_register() -
1657 * @ha: HA context
1658 *
1659 * Returns 0 on success.
1660 */
1661int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001662qla2x00_fdmi_register(scsi_qla_host_t *vha)
Andrew Vasquezcca53352005-08-26 19:08:30 -07001663{
1664 int rval;
Andrew Vasquez80de7ef2009-07-31 15:09:33 -07001665 struct qla_hw_data *ha = vha->hw;
1666
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001667 if (IS_QLA2100(ha) || IS_QLA2200(ha) ||
1668 IS_QLAFX00(ha))
Andrew Vasquez80de7ef2009-07-31 15:09:33 -07001669 return QLA_FUNCTION_FAILED;
Andrew Vasquezcca53352005-08-26 19:08:30 -07001670
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001671 rval = qla2x00_mgmt_svr_login(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001672 if (rval)
1673 return rval;
1674
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001675 rval = qla2x00_fdmi_rhba(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001676 if (rval) {
1677 if (rval != QLA_ALREADY_REGISTERED)
1678 return rval;
1679
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001680 rval = qla2x00_fdmi_dhba(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001681 if (rval)
1682 return rval;
1683
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001684 rval = qla2x00_fdmi_rhba(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001685 if (rval)
1686 return rval;
1687 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001688 rval = qla2x00_fdmi_rpa(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001689
1690 return rval;
1691}
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001692
1693/**
1694 * qla2x00_gfpn_id() - SNS Get Fabric Port Name (GFPN_ID) query.
1695 * @ha: HA context
1696 * @list: switch info entries to populate
1697 *
1698 * Returns 0 on success.
1699 */
1700int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001701qla2x00_gfpn_id(scsi_qla_host_t *vha, sw_info_t *list)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001702{
Chad Dupuis642ef982012-02-09 11:15:57 -08001703 int rval = QLA_SUCCESS;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001704 uint16_t i;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001705 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001706 ms_iocb_entry_t *ms_pkt;
1707 struct ct_sns_req *ct_req;
1708 struct ct_sns_rsp *ct_rsp;
1709
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07001710 if (!IS_IIDMA_CAPABLE(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001711 return QLA_FUNCTION_FAILED;
1712
Chad Dupuis642ef982012-02-09 11:15:57 -08001713 for (i = 0; i < ha->max_fibre_devices; i++) {
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001714 /* Issue GFPN_ID */
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001715 /* Prepare common MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001716 ms_pkt = ha->isp_ops->prep_ms_iocb(vha, GFPN_ID_REQ_SIZE,
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001717 GFPN_ID_RSP_SIZE);
1718
1719 /* Prepare CT request */
Bart Van Assche6ec6f902013-06-25 11:27:28 -04001720 ct_req = qla2x00_prep_ct_req(ha->ct_sns, GFPN_ID_CMD,
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001721 GFPN_ID_RSP_SIZE);
1722 ct_rsp = &ha->ct_sns->p.rsp;
1723
1724 /* Prepare CT arguments -- port_id */
1725 ct_req->req.port_id.port_id[0] = list[i].d_id.b.domain;
1726 ct_req->req.port_id.port_id[1] = list[i].d_id.b.area;
1727 ct_req->req.port_id.port_id[2] = list[i].d_id.b.al_pa;
1728
1729 /* Execute MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001730 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001731 sizeof(ms_iocb_entry_t));
1732 if (rval != QLA_SUCCESS) {
1733 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001734 ql_dbg(ql_dbg_disc, vha, 0x2023,
1735 "GFPN_ID issue IOCB failed (%d).\n", rval);
Arun Easidafdf892012-02-09 11:16:00 -08001736 break;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001737 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp,
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001738 "GFPN_ID") != QLA_SUCCESS) {
1739 rval = QLA_FUNCTION_FAILED;
Arun Easidafdf892012-02-09 11:16:00 -08001740 break;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001741 } else {
1742 /* Save fabric portname */
1743 memcpy(list[i].fabric_port_name,
1744 ct_rsp->rsp.gfpn_id.port_name, WWN_SIZE);
1745 }
1746
1747 /* Last device exit. */
1748 if (list[i].d_id.b.rsvd_1 != 0)
1749 break;
1750 }
1751
1752 return (rval);
1753}
1754
1755static inline void *
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001756qla24xx_prep_ms_fm_iocb(scsi_qla_host_t *vha, uint32_t req_size,
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001757 uint32_t rsp_size)
1758{
1759 struct ct_entry_24xx *ct_pkt;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001760 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001761 ct_pkt = (struct ct_entry_24xx *)ha->ms_iocb;
1762 memset(ct_pkt, 0, sizeof(struct ct_entry_24xx));
1763
1764 ct_pkt->entry_type = CT_IOCB_TYPE;
1765 ct_pkt->entry_count = 1;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001766 ct_pkt->nport_handle = cpu_to_le16(vha->mgmt_svr_loop_id);
Andrew Vasquez00a537b2008-02-28 14:06:11 -08001767 ct_pkt->timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001768 ct_pkt->cmd_dsd_count = __constant_cpu_to_le16(1);
1769 ct_pkt->rsp_dsd_count = __constant_cpu_to_le16(1);
1770 ct_pkt->rsp_byte_count = cpu_to_le32(rsp_size);
1771 ct_pkt->cmd_byte_count = cpu_to_le32(req_size);
1772
1773 ct_pkt->dseg_0_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
1774 ct_pkt->dseg_0_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
1775 ct_pkt->dseg_0_len = ct_pkt->cmd_byte_count;
1776
1777 ct_pkt->dseg_1_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
1778 ct_pkt->dseg_1_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
1779 ct_pkt->dseg_1_len = ct_pkt->rsp_byte_count;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001780 ct_pkt->vp_index = vha->vp_idx;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001781
1782 return ct_pkt;
1783}
1784
1785
1786static inline struct ct_sns_req *
Bart Van Assche6ec6f902013-06-25 11:27:28 -04001787qla24xx_prep_ct_fm_req(struct ct_sns_pkt *p, uint16_t cmd,
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001788 uint16_t rsp_size)
1789{
Bart Van Assche6ec6f902013-06-25 11:27:28 -04001790 memset(p, 0, sizeof(struct ct_sns_pkt));
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001791
Bart Van Assche6ec6f902013-06-25 11:27:28 -04001792 p->p.req.header.revision = 0x01;
1793 p->p.req.header.gs_type = 0xFA;
1794 p->p.req.header.gs_subtype = 0x01;
1795 p->p.req.command = cpu_to_be16(cmd);
1796 p->p.req.max_rsp_size = cpu_to_be16((rsp_size - 16) / 4);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001797
Bart Van Assche6ec6f902013-06-25 11:27:28 -04001798 return &p->p.req;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001799}
1800
1801/**
1802 * qla2x00_gpsc() - FCS Get Port Speed Capabilities (GPSC) query.
1803 * @ha: HA context
1804 * @list: switch info entries to populate
1805 *
1806 * Returns 0 on success.
1807 */
1808int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001809qla2x00_gpsc(scsi_qla_host_t *vha, sw_info_t *list)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001810{
1811 int rval;
1812 uint16_t i;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001813 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001814 ms_iocb_entry_t *ms_pkt;
1815 struct ct_sns_req *ct_req;
1816 struct ct_sns_rsp *ct_rsp;
1817
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07001818 if (!IS_IIDMA_CAPABLE(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001819 return QLA_FUNCTION_FAILED;
Andrew Vasquez4346b142006-12-13 19:20:28 -08001820 if (!ha->flags.gpsc_supported)
1821 return QLA_FUNCTION_FAILED;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001822
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001823 rval = qla2x00_mgmt_svr_login(vha);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001824 if (rval)
1825 return rval;
1826
Chad Dupuis642ef982012-02-09 11:15:57 -08001827 for (i = 0; i < ha->max_fibre_devices; i++) {
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001828 /* Issue GFPN_ID */
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001829 /* Prepare common MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001830 ms_pkt = qla24xx_prep_ms_fm_iocb(vha, GPSC_REQ_SIZE,
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001831 GPSC_RSP_SIZE);
1832
1833 /* Prepare CT request */
Bart Van Assche6ec6f902013-06-25 11:27:28 -04001834 ct_req = qla24xx_prep_ct_fm_req(ha->ct_sns, GPSC_CMD,
1835 GPSC_RSP_SIZE);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001836 ct_rsp = &ha->ct_sns->p.rsp;
1837
1838 /* Prepare CT arguments -- port_name */
1839 memcpy(ct_req->req.gpsc.port_name, list[i].fabric_port_name,
1840 WWN_SIZE);
1841
1842 /* Execute MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001843 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001844 sizeof(ms_iocb_entry_t));
1845 if (rval != QLA_SUCCESS) {
1846 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001847 ql_dbg(ql_dbg_disc, vha, 0x2059,
1848 "GPSC issue IOCB failed (%d).\n", rval);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001849 } else if ((rval = qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp,
Andrew Vasquez4346b142006-12-13 19:20:28 -08001850 "GPSC")) != QLA_SUCCESS) {
1851 /* FM command unsupported? */
1852 if (rval == QLA_INVALID_COMMAND &&
Andrew Vasquez3fe7cfb2008-04-03 13:13:23 -07001853 (ct_rsp->header.reason_code ==
1854 CT_REASON_INVALID_COMMAND_CODE ||
1855 ct_rsp->header.reason_code ==
1856 CT_REASON_COMMAND_UNSUPPORTED)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001857 ql_dbg(ql_dbg_disc, vha, 0x205a,
1858 "GPSC command unsupported, disabling "
1859 "query.\n");
Andrew Vasquez4346b142006-12-13 19:20:28 -08001860 ha->flags.gpsc_supported = 0;
1861 rval = QLA_FUNCTION_FAILED;
1862 break;
1863 }
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001864 rval = QLA_FUNCTION_FAILED;
1865 } else {
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07001866 /* Save port-speed */
1867 switch (be16_to_cpu(ct_rsp->rsp.gpsc.speed)) {
1868 case BIT_15:
1869 list[i].fp_speed = PORT_SPEED_1GB;
1870 break;
1871 case BIT_14:
1872 list[i].fp_speed = PORT_SPEED_2GB;
1873 break;
1874 case BIT_13:
1875 list[i].fp_speed = PORT_SPEED_4GB;
1876 break;
Andrew Vasquez9f8fdde2009-06-03 09:55:22 -07001877 case BIT_12:
1878 list[i].fp_speed = PORT_SPEED_10GB;
1879 break;
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07001880 case BIT_11:
1881 list[i].fp_speed = PORT_SPEED_8GB;
1882 break;
Joe Carnuccioc53dfac2012-11-21 02:40:39 -05001883 case BIT_10:
1884 list[i].fp_speed = PORT_SPEED_16GB;
1885 break;
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07001886 }
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001887
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001888 ql_dbg(ql_dbg_disc, vha, 0x205b,
1889 "GPSC ext entry - fpn "
Oleksandr Khoshaba7b833552013-08-27 01:37:27 -04001890 "%8phN speeds=%04x speed=%04x.\n",
1891 list[i].fabric_port_name,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07001892 be16_to_cpu(ct_rsp->rsp.gpsc.speeds),
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001893 be16_to_cpu(ct_rsp->rsp.gpsc.speed));
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001894 }
1895
1896 /* Last device exit. */
1897 if (list[i].d_id.b.rsvd_1 != 0)
1898 break;
1899 }
1900
1901 return (rval);
1902}
Chad Dupuise8c72ba2010-07-23 15:28:25 +05001903
1904/**
1905 * qla2x00_gff_id() - SNS Get FC-4 Features (GFF_ID) query.
1906 *
1907 * @ha: HA context
1908 * @list: switch info entries to populate
1909 *
1910 */
1911void
1912qla2x00_gff_id(scsi_qla_host_t *vha, sw_info_t *list)
1913{
1914 int rval;
1915 uint16_t i;
1916
1917 ms_iocb_entry_t *ms_pkt;
1918 struct ct_sns_req *ct_req;
1919 struct ct_sns_rsp *ct_rsp;
1920 struct qla_hw_data *ha = vha->hw;
1921 uint8_t fcp_scsi_features = 0;
1922
Chad Dupuis642ef982012-02-09 11:15:57 -08001923 for (i = 0; i < ha->max_fibre_devices; i++) {
Chad Dupuise8c72ba2010-07-23 15:28:25 +05001924 /* Set default FC4 Type as UNKNOWN so the default is to
1925 * Process this port */
1926 list[i].fc4_type = FC4_TYPE_UNKNOWN;
1927
1928 /* Do not attempt GFF_ID if we are not FWI_2 capable */
1929 if (!IS_FWI2_CAPABLE(ha))
1930 continue;
1931
1932 /* Prepare common MS IOCB */
1933 ms_pkt = ha->isp_ops->prep_ms_iocb(vha, GFF_ID_REQ_SIZE,
1934 GFF_ID_RSP_SIZE);
1935
1936 /* Prepare CT request */
Bart Van Assche6ec6f902013-06-25 11:27:28 -04001937 ct_req = qla2x00_prep_ct_req(ha->ct_sns, GFF_ID_CMD,
Chad Dupuise8c72ba2010-07-23 15:28:25 +05001938 GFF_ID_RSP_SIZE);
1939 ct_rsp = &ha->ct_sns->p.rsp;
1940
1941 /* Prepare CT arguments -- port_id */
1942 ct_req->req.port_id.port_id[0] = list[i].d_id.b.domain;
1943 ct_req->req.port_id.port_id[1] = list[i].d_id.b.area;
1944 ct_req->req.port_id.port_id[2] = list[i].d_id.b.al_pa;
1945
1946 /* Execute MS IOCB */
1947 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
1948 sizeof(ms_iocb_entry_t));
1949
1950 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001951 ql_dbg(ql_dbg_disc, vha, 0x205c,
1952 "GFF_ID issue IOCB failed (%d).\n", rval);
Chad Dupuise8c72ba2010-07-23 15:28:25 +05001953 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp,
Andrew Vasquez7a78ced2011-02-23 15:27:12 -08001954 "GFF_ID") != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001955 ql_dbg(ql_dbg_disc, vha, 0x205d,
1956 "GFF_ID IOCB status had a failure status code.\n");
Chad Dupuise8c72ba2010-07-23 15:28:25 +05001957 } else {
1958 fcp_scsi_features =
1959 ct_rsp->rsp.gff_id.fc4_features[GFF_FCP_SCSI_OFFSET];
1960 fcp_scsi_features &= 0x0f;
1961
1962 if (fcp_scsi_features)
1963 list[i].fc4_type = FC4_TYPE_FCP_SCSI;
1964 else
1965 list[i].fc4_type = FC4_TYPE_OTHER;
1966 }
1967
1968 /* Last device exit. */
1969 if (list[i].d_id.b.rsvd_1 != 0)
1970 break;
1971 }
1972}