blob: 69243036529749aa2545526547ba6b4f57a957e0 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Andrew Vasquezfa90c542005-10-27 11:10:08 -07002 * QLogic Fibre Channel HBA Driver
Andrew Vasquez07e264b2011-03-30 11:46:23 -07003 * Copyright (c) 2003-2011 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"
8
Linus Torvalds1da177e2005-04-16 15:20:36 -07009static int qla2x00_sns_ga_nxt(scsi_qla_host_t *, fc_port_t *);
10static int qla2x00_sns_gid_pt(scsi_qla_host_t *, sw_info_t *);
11static int qla2x00_sns_gpn_id(scsi_qla_host_t *, sw_info_t *);
12static int qla2x00_sns_gnn_id(scsi_qla_host_t *, sw_info_t *);
13static int qla2x00_sns_rft_id(scsi_qla_host_t *);
14static int qla2x00_sns_rnn_id(scsi_qla_host_t *);
15
16/**
Andrew Vasquez8c958a92005-07-06 10:30:47 -070017 * qla2x00_prep_ms_iocb() - Prepare common MS/CT IOCB fields for SNS CT query.
Linus Torvalds1da177e2005-04-16 15:20:36 -070018 * @ha: HA context
19 * @req_size: request size in bytes
20 * @rsp_size: response size in bytes
21 *
22 * Returns a pointer to the @ha's ms_iocb.
23 */
Andrew Vasquez8c958a92005-07-06 10:30:47 -070024void *
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080025qla2x00_prep_ms_iocb(scsi_qla_host_t *vha, uint32_t req_size, uint32_t rsp_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -070026{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080027 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -070028 ms_iocb_entry_t *ms_pkt;
29
30 ms_pkt = ha->ms_iocb;
31 memset(ms_pkt, 0, sizeof(ms_iocb_entry_t));
32
33 ms_pkt->entry_type = MS_IOCB_TYPE;
34 ms_pkt->entry_count = 1;
35 SET_TARGET_ID(ha, ms_pkt->loop_id, SIMPLE_NAME_SERVER);
36 ms_pkt->control_flags = __constant_cpu_to_le16(CF_READ | CF_HEAD_TAG);
Andrew Vasquez00a537b2008-02-28 14:06:11 -080037 ms_pkt->timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 ms_pkt->cmd_dsd_count = __constant_cpu_to_le16(1);
39 ms_pkt->total_dsd_count = __constant_cpu_to_le16(2);
40 ms_pkt->rsp_bytecount = cpu_to_le32(rsp_size);
41 ms_pkt->req_bytecount = cpu_to_le32(req_size);
42
43 ms_pkt->dseg_req_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
44 ms_pkt->dseg_req_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
45 ms_pkt->dseg_req_length = ms_pkt->req_bytecount;
46
47 ms_pkt->dseg_rsp_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
48 ms_pkt->dseg_rsp_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
49 ms_pkt->dseg_rsp_length = ms_pkt->rsp_bytecount;
50
51 return (ms_pkt);
52}
53
54/**
Andrew Vasquez8c958a92005-07-06 10:30:47 -070055 * qla24xx_prep_ms_iocb() - Prepare common CT IOCB fields for SNS CT query.
56 * @ha: HA context
57 * @req_size: request size in bytes
58 * @rsp_size: response size in bytes
59 *
60 * Returns a pointer to the @ha's ms_iocb.
61 */
62void *
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080063qla24xx_prep_ms_iocb(scsi_qla_host_t *vha, uint32_t req_size, uint32_t rsp_size)
Andrew Vasquez8c958a92005-07-06 10:30:47 -070064{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080065 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez8c958a92005-07-06 10:30:47 -070066 struct ct_entry_24xx *ct_pkt;
67
68 ct_pkt = (struct ct_entry_24xx *)ha->ms_iocb;
69 memset(ct_pkt, 0, sizeof(struct ct_entry_24xx));
70
71 ct_pkt->entry_type = CT_IOCB_TYPE;
72 ct_pkt->entry_count = 1;
73 ct_pkt->nport_handle = __constant_cpu_to_le16(NPH_SNS);
Andrew Vasquez00a537b2008-02-28 14:06:11 -080074 ct_pkt->timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
Andrew Vasquez8c958a92005-07-06 10:30:47 -070075 ct_pkt->cmd_dsd_count = __constant_cpu_to_le16(1);
76 ct_pkt->rsp_dsd_count = __constant_cpu_to_le16(1);
77 ct_pkt->rsp_byte_count = cpu_to_le32(rsp_size);
78 ct_pkt->cmd_byte_count = cpu_to_le32(req_size);
79
80 ct_pkt->dseg_0_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
81 ct_pkt->dseg_0_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
82 ct_pkt->dseg_0_len = ct_pkt->cmd_byte_count;
83
84 ct_pkt->dseg_1_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
85 ct_pkt->dseg_1_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
86 ct_pkt->dseg_1_len = ct_pkt->rsp_byte_count;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080087 ct_pkt->vp_index = vha->vp_idx;
Andrew Vasquez8c958a92005-07-06 10:30:47 -070088
89 return (ct_pkt);
90}
91
92/**
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 * qla2x00_prep_ct_req() - Prepare common CT request fields for SNS query.
94 * @ct_req: CT request buffer
95 * @cmd: GS command
96 * @rsp_size: response size in bytes
97 *
98 * Returns a pointer to the intitialized @ct_req.
99 */
100static inline struct ct_sns_req *
101qla2x00_prep_ct_req(struct ct_sns_req *ct_req, uint16_t cmd, uint16_t rsp_size)
102{
103 memset(ct_req, 0, sizeof(struct ct_sns_pkt));
104
105 ct_req->header.revision = 0x01;
106 ct_req->header.gs_type = 0xFC;
107 ct_req->header.gs_subtype = 0x02;
108 ct_req->command = cpu_to_be16(cmd);
109 ct_req->max_rsp_size = cpu_to_be16((rsp_size - 16) / 4);
110
111 return (ct_req);
112}
113
Andrew Vasquez8c958a92005-07-06 10:30:47 -0700114static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800115qla2x00_chk_ms_status(scsi_qla_host_t *vha, ms_iocb_entry_t *ms_pkt,
Andrew Vasquez8c958a92005-07-06 10:30:47 -0700116 struct ct_sns_rsp *ct_rsp, const char *routine)
117{
118 int rval;
119 uint16_t comp_status;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800120 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez8c958a92005-07-06 10:30:47 -0700121
122 rval = QLA_FUNCTION_FAILED;
123 if (ms_pkt->entry_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700124 ql_dbg(ql_dbg_disc, vha, 0x2031,
125 "%s failed, error status (%x) on port_id: %02x%02x%02x.\n",
126 routine, ms_pkt->entry_status, vha->d_id.b.domain,
127 vha->d_id.b.area, vha->d_id.b.al_pa);
Andrew Vasquez8c958a92005-07-06 10:30:47 -0700128 } else {
Andrew Vasqueze4289242007-07-19 15:05:56 -0700129 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquezcdfc82a2006-12-13 19:20:26 -0800130 comp_status = le16_to_cpu(
131 ((struct ct_entry_24xx *)ms_pkt)->comp_status);
Andrew Vasquez8c958a92005-07-06 10:30:47 -0700132 else
133 comp_status = le16_to_cpu(ms_pkt->status);
134 switch (comp_status) {
135 case CS_COMPLETE:
136 case CS_DATA_UNDERRUN:
137 case CS_DATA_OVERRUN: /* Overrun? */
138 if (ct_rsp->header.response !=
139 __constant_cpu_to_be16(CT_ACCEPT_RESPONSE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700140 ql_dbg(ql_dbg_disc + ql_dbg_buffer, vha, 0x2077,
141 "%s failed rejected request on port_id: "
142 "%02x%02x%02x.\n", routine,
Giridhar Malavalicf2d7712011-02-23 15:27:09 -0800143 vha->d_id.b.domain, vha->d_id.b.area,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700144 vha->d_id.b.al_pa);
145 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha,
146 0x2078, (uint8_t *)&ct_rsp->header,
147 sizeof(struct ct_rsp_hdr));
Andrew Vasquez4346b142006-12-13 19:20:28 -0800148 rval = QLA_INVALID_COMMAND;
Andrew Vasquez8c958a92005-07-06 10:30:47 -0700149 } else
150 rval = QLA_SUCCESS;
151 break;
152 default:
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700153 ql_dbg(ql_dbg_disc, vha, 0x2033,
154 "%s failed, completion status (%x) on port_id: "
155 "%02x%02x%02x.\n", routine, comp_status,
Giridhar Malavalicf2d7712011-02-23 15:27:09 -0800156 vha->d_id.b.domain, vha->d_id.b.area,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700157 vha->d_id.b.al_pa);
Andrew Vasquez8c958a92005-07-06 10:30:47 -0700158 break;
159 }
160 }
161 return rval;
162}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163
164/**
165 * qla2x00_ga_nxt() - SNS scan for fabric devices via GA_NXT command.
166 * @ha: HA context
167 * @fcport: fcport entry to updated
168 *
169 * Returns 0 on success.
170 */
171int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800172qla2x00_ga_nxt(scsi_qla_host_t *vha, fc_port_t *fcport)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173{
174 int rval;
175
176 ms_iocb_entry_t *ms_pkt;
177 struct ct_sns_req *ct_req;
178 struct ct_sns_rsp *ct_rsp;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800179 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800181 if (IS_QLA2100(ha) || IS_QLA2200(ha))
182 return qla2x00_sns_ga_nxt(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183
184 /* Issue GA_NXT */
185 /* Prepare common MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800186 ms_pkt = ha->isp_ops->prep_ms_iocb(vha, GA_NXT_REQ_SIZE,
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700187 GA_NXT_RSP_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188
189 /* Prepare CT request */
190 ct_req = qla2x00_prep_ct_req(&ha->ct_sns->p.req, GA_NXT_CMD,
191 GA_NXT_RSP_SIZE);
192 ct_rsp = &ha->ct_sns->p.rsp;
193
194 /* Prepare CT arguments -- port_id */
195 ct_req->req.port_id.port_id[0] = fcport->d_id.b.domain;
196 ct_req->req.port_id.port_id[1] = fcport->d_id.b.area;
197 ct_req->req.port_id.port_id[2] = fcport->d_id.b.al_pa;
198
199 /* Execute MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800200 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 sizeof(ms_iocb_entry_t));
202 if (rval != QLA_SUCCESS) {
203 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700204 ql_dbg(ql_dbg_disc, vha, 0x2062,
205 "GA_NXT issue IOCB failed (%d).\n", rval);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800206 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, "GA_NXT") !=
Andrew Vasquez8c958a92005-07-06 10:30:47 -0700207 QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 rval = QLA_FUNCTION_FAILED;
209 } else {
210 /* Populate fc_port_t entry. */
211 fcport->d_id.b.domain = ct_rsp->rsp.ga_nxt.port_id[0];
212 fcport->d_id.b.area = ct_rsp->rsp.ga_nxt.port_id[1];
213 fcport->d_id.b.al_pa = ct_rsp->rsp.ga_nxt.port_id[2];
214
215 memcpy(fcport->node_name, ct_rsp->rsp.ga_nxt.node_name,
216 WWN_SIZE);
217 memcpy(fcport->port_name, ct_rsp->rsp.ga_nxt.port_name,
218 WWN_SIZE);
219
220 if (ct_rsp->rsp.ga_nxt.port_type != NS_N_PORT_TYPE &&
221 ct_rsp->rsp.ga_nxt.port_type != NS_NL_PORT_TYPE)
222 fcport->d_id.b.domain = 0xf0;
223
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700224 ql_dbg(ql_dbg_disc, vha, 0x2063,
225 "GA_NXT entry - nn %02x%02x%02x%02x%02x%02x%02x%02x "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 "pn %02x%02x%02x%02x%02x%02x%02x%02x "
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700227 "port_id=%02x%02x%02x.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 fcport->node_name[0], fcport->node_name[1],
229 fcport->node_name[2], fcport->node_name[3],
230 fcport->node_name[4], fcport->node_name[5],
231 fcport->node_name[6], fcport->node_name[7],
232 fcport->port_name[0], fcport->port_name[1],
233 fcport->port_name[2], fcport->port_name[3],
234 fcport->port_name[4], fcport->port_name[5],
235 fcport->port_name[6], fcport->port_name[7],
236 fcport->d_id.b.domain, fcport->d_id.b.area,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700237 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 }
239
240 return (rval);
241}
242
243/**
244 * qla2x00_gid_pt() - SNS scan for fabric devices via GID_PT command.
245 * @ha: HA context
246 * @list: switch info entries to populate
247 *
248 * NOTE: Non-Nx_Ports are not requested.
249 *
250 * Returns 0 on success.
251 */
252int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800253qla2x00_gid_pt(scsi_qla_host_t *vha, sw_info_t *list)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254{
255 int rval;
256 uint16_t i;
257
258 ms_iocb_entry_t *ms_pkt;
259 struct ct_sns_req *ct_req;
260 struct ct_sns_rsp *ct_rsp;
261
262 struct ct_sns_gid_pt_data *gid_data;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800263 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800265 if (IS_QLA2100(ha) || IS_QLA2200(ha))
266 return qla2x00_sns_gid_pt(vha, list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267
268 gid_data = NULL;
269
270 /* Issue GID_PT */
271 /* Prepare common MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800272 ms_pkt = ha->isp_ops->prep_ms_iocb(vha, GID_PT_REQ_SIZE,
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700273 GID_PT_RSP_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274
275 /* Prepare CT request */
276 ct_req = qla2x00_prep_ct_req(&ha->ct_sns->p.req, GID_PT_CMD,
277 GID_PT_RSP_SIZE);
278 ct_rsp = &ha->ct_sns->p.rsp;
279
280 /* Prepare CT arguments -- port_type */
281 ct_req->req.gid_pt.port_type = NS_NX_PORT_TYPE;
282
283 /* Execute MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800284 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 sizeof(ms_iocb_entry_t));
286 if (rval != QLA_SUCCESS) {
287 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700288 ql_dbg(ql_dbg_disc, vha, 0x2055,
289 "GID_PT issue IOCB failed (%d).\n", rval);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800290 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, "GID_PT") !=
Andrew Vasquez8c958a92005-07-06 10:30:47 -0700291 QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 rval = QLA_FUNCTION_FAILED;
293 } else {
294 /* Set port IDs in switch info list. */
295 for (i = 0; i < MAX_FIBRE_DEVICES; i++) {
296 gid_data = &ct_rsp->rsp.gid_pt.entries[i];
297 list[i].d_id.b.domain = gid_data->port_id[0];
298 list[i].d_id.b.area = gid_data->port_id[1];
299 list[i].d_id.b.al_pa = gid_data->port_id[2];
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -0700300 memset(list[i].fabric_port_name, 0, WWN_SIZE);
301 list[i].fp_speed = PORT_SPEED_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302
303 /* Last one exit. */
304 if (gid_data->control_byte & BIT_7) {
305 list[i].d_id.b.rsvd_1 = gid_data->control_byte;
306 break;
307 }
308 }
309
310 /*
311 * If we've used all available slots, then the switch is
312 * reporting back more devices than we can handle with this
313 * single call. Return a failed status, and let GA_NXT handle
314 * the overload.
315 */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700316 if (i == MAX_FIBRE_DEVICES)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 rval = QLA_FUNCTION_FAILED;
318 }
319
320 return (rval);
321}
322
323/**
324 * qla2x00_gpn_id() - SNS Get Port Name (GPN_ID) query.
325 * @ha: HA context
326 * @list: switch info entries to populate
327 *
328 * Returns 0 on success.
329 */
330int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800331qla2x00_gpn_id(scsi_qla_host_t *vha, sw_info_t *list)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332{
333 int rval;
334 uint16_t i;
335
336 ms_iocb_entry_t *ms_pkt;
337 struct ct_sns_req *ct_req;
338 struct ct_sns_rsp *ct_rsp;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800339 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800341 if (IS_QLA2100(ha) || IS_QLA2200(ha))
342 return qla2x00_sns_gpn_id(vha, list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343
344 for (i = 0; i < MAX_FIBRE_DEVICES; i++) {
345 /* Issue GPN_ID */
346 /* Prepare common MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800347 ms_pkt = ha->isp_ops->prep_ms_iocb(vha, GPN_ID_REQ_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 GPN_ID_RSP_SIZE);
349
350 /* Prepare CT request */
351 ct_req = qla2x00_prep_ct_req(&ha->ct_sns->p.req, GPN_ID_CMD,
352 GPN_ID_RSP_SIZE);
353 ct_rsp = &ha->ct_sns->p.rsp;
354
355 /* Prepare CT arguments -- port_id */
356 ct_req->req.port_id.port_id[0] = list[i].d_id.b.domain;
357 ct_req->req.port_id.port_id[1] = list[i].d_id.b.area;
358 ct_req->req.port_id.port_id[2] = list[i].d_id.b.al_pa;
359
360 /* Execute MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800361 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 sizeof(ms_iocb_entry_t));
363 if (rval != QLA_SUCCESS) {
364 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700365 ql_dbg(ql_dbg_disc, vha, 0x2056,
366 "GPN_ID issue IOCB failed (%d).\n", rval);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800367 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp,
Andrew Vasquez8c958a92005-07-06 10:30:47 -0700368 "GPN_ID") != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 rval = QLA_FUNCTION_FAILED;
370 } else {
371 /* Save portname */
372 memcpy(list[i].port_name,
373 ct_rsp->rsp.gpn_id.port_name, WWN_SIZE);
374 }
375
376 /* Last device exit. */
377 if (list[i].d_id.b.rsvd_1 != 0)
378 break;
379 }
380
381 return (rval);
382}
383
384/**
385 * qla2x00_gnn_id() - SNS Get Node Name (GNN_ID) query.
386 * @ha: HA context
387 * @list: switch info entries to populate
388 *
389 * Returns 0 on success.
390 */
391int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800392qla2x00_gnn_id(scsi_qla_host_t *vha, sw_info_t *list)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393{
394 int rval;
395 uint16_t i;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800396 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 ms_iocb_entry_t *ms_pkt;
398 struct ct_sns_req *ct_req;
399 struct ct_sns_rsp *ct_rsp;
400
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800401 if (IS_QLA2100(ha) || IS_QLA2200(ha))
402 return qla2x00_sns_gnn_id(vha, list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403
404 for (i = 0; i < MAX_FIBRE_DEVICES; i++) {
405 /* Issue GNN_ID */
406 /* Prepare common MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800407 ms_pkt = ha->isp_ops->prep_ms_iocb(vha, GNN_ID_REQ_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 GNN_ID_RSP_SIZE);
409
410 /* Prepare CT request */
411 ct_req = qla2x00_prep_ct_req(&ha->ct_sns->p.req, GNN_ID_CMD,
412 GNN_ID_RSP_SIZE);
413 ct_rsp = &ha->ct_sns->p.rsp;
414
415 /* Prepare CT arguments -- port_id */
416 ct_req->req.port_id.port_id[0] = list[i].d_id.b.domain;
417 ct_req->req.port_id.port_id[1] = list[i].d_id.b.area;
418 ct_req->req.port_id.port_id[2] = list[i].d_id.b.al_pa;
419
420 /* Execute MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800421 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 sizeof(ms_iocb_entry_t));
423 if (rval != QLA_SUCCESS) {
424 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700425 ql_dbg(ql_dbg_disc, vha, 0x2057,
426 "GNN_ID issue IOCB failed (%d).\n", rval);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800427 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp,
Andrew Vasquez8c958a92005-07-06 10:30:47 -0700428 "GNN_ID") != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 rval = QLA_FUNCTION_FAILED;
430 } else {
431 /* Save nodename */
432 memcpy(list[i].node_name,
433 ct_rsp->rsp.gnn_id.node_name, WWN_SIZE);
434
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700435 ql_dbg(ql_dbg_disc, vha, 0x2058,
436 "GID_PT entry - nn %02x%02x%02x%02x%02x%02x%02X%02x "
437 "pn %02x%02x%02x%02x%02x%02x%02X%02x "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 "portid=%02x%02x%02x.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 list[i].node_name[0], list[i].node_name[1],
440 list[i].node_name[2], list[i].node_name[3],
441 list[i].node_name[4], list[i].node_name[5],
442 list[i].node_name[6], list[i].node_name[7],
443 list[i].port_name[0], list[i].port_name[1],
444 list[i].port_name[2], list[i].port_name[3],
445 list[i].port_name[4], list[i].port_name[5],
446 list[i].port_name[6], list[i].port_name[7],
447 list[i].d_id.b.domain, list[i].d_id.b.area,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700448 list[i].d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 }
450
451 /* Last device exit. */
452 if (list[i].d_id.b.rsvd_1 != 0)
453 break;
454 }
455
456 return (rval);
457}
458
459/**
460 * qla2x00_rft_id() - SNS Register FC-4 TYPEs (RFT_ID) supported by the HBA.
461 * @ha: HA context
462 *
463 * Returns 0 on success.
464 */
465int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800466qla2x00_rft_id(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467{
468 int rval;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800469 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 ms_iocb_entry_t *ms_pkt;
471 struct ct_sns_req *ct_req;
472 struct ct_sns_rsp *ct_rsp;
473
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800474 if (IS_QLA2100(ha) || IS_QLA2200(ha))
475 return qla2x00_sns_rft_id(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476
477 /* Issue RFT_ID */
478 /* Prepare common MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800479 ms_pkt = ha->isp_ops->prep_ms_iocb(vha, RFT_ID_REQ_SIZE,
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700480 RFT_ID_RSP_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481
482 /* Prepare CT request */
483 ct_req = qla2x00_prep_ct_req(&ha->ct_sns->p.req, RFT_ID_CMD,
484 RFT_ID_RSP_SIZE);
485 ct_rsp = &ha->ct_sns->p.rsp;
486
487 /* Prepare CT arguments -- port_id, FC-4 types */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800488 ct_req->req.rft_id.port_id[0] = vha->d_id.b.domain;
489 ct_req->req.rft_id.port_id[1] = vha->d_id.b.area;
490 ct_req->req.rft_id.port_id[2] = vha->d_id.b.al_pa;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491
492 ct_req->req.rft_id.fc4_types[2] = 0x01; /* FCP-3 */
493
494 /* Execute MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800495 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 sizeof(ms_iocb_entry_t));
497 if (rval != QLA_SUCCESS) {
498 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700499 ql_dbg(ql_dbg_disc, vha, 0x2043,
500 "RFT_ID issue IOCB failed (%d).\n", rval);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800501 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, "RFT_ID") !=
Andrew Vasquez8c958a92005-07-06 10:30:47 -0700502 QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 rval = QLA_FUNCTION_FAILED;
504 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700505 ql_dbg(ql_dbg_disc, vha, 0x2044,
506 "RFT_ID exiting normally.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 }
508
509 return (rval);
510}
511
512/**
513 * qla2x00_rff_id() - SNS Register FC-4 Features (RFF_ID) supported by the HBA.
514 * @ha: HA context
515 *
516 * Returns 0 on success.
517 */
518int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800519qla2x00_rff_id(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520{
521 int rval;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800522 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 ms_iocb_entry_t *ms_pkt;
524 struct ct_sns_req *ct_req;
525 struct ct_sns_rsp *ct_rsp;
526
527 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700528 ql_dbg(ql_dbg_disc, vha, 0x2046,
529 "RFF_ID call not supported on ISP2100/ISP2200.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 return (QLA_SUCCESS);
531 }
532
533 /* Issue RFF_ID */
534 /* Prepare common MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800535 ms_pkt = ha->isp_ops->prep_ms_iocb(vha, RFF_ID_REQ_SIZE,
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700536 RFF_ID_RSP_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537
538 /* Prepare CT request */
539 ct_req = qla2x00_prep_ct_req(&ha->ct_sns->p.req, RFF_ID_CMD,
540 RFF_ID_RSP_SIZE);
541 ct_rsp = &ha->ct_sns->p.rsp;
542
543 /* Prepare CT arguments -- port_id, FC-4 feature, FC-4 type */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800544 ct_req->req.rff_id.port_id[0] = vha->d_id.b.domain;
545 ct_req->req.rff_id.port_id[1] = vha->d_id.b.area;
546 ct_req->req.rff_id.port_id[2] = vha->d_id.b.al_pa;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547
andrew.vasquez@qlogic.com94036882006-01-13 17:04:54 -0800548 ct_req->req.rff_id.fc4_feature = BIT_1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 ct_req->req.rff_id.fc4_type = 0x08; /* SCSI - FCP */
550
551 /* Execute MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800552 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 sizeof(ms_iocb_entry_t));
554 if (rval != QLA_SUCCESS) {
555 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700556 ql_dbg(ql_dbg_disc, vha, 0x2047,
557 "RFF_ID issue IOCB failed (%d).\n", rval);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800558 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, "RFF_ID") !=
Andrew Vasquez8c958a92005-07-06 10:30:47 -0700559 QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 rval = QLA_FUNCTION_FAILED;
561 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700562 ql_dbg(ql_dbg_disc, vha, 0x2048,
563 "RFF_ID exiting normally.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 }
565
566 return (rval);
567}
568
569/**
570 * qla2x00_rnn_id() - SNS Register Node Name (RNN_ID) of the HBA.
571 * @ha: HA context
572 *
573 * Returns 0 on success.
574 */
575int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800576qla2x00_rnn_id(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577{
578 int rval;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800579 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 ms_iocb_entry_t *ms_pkt;
581 struct ct_sns_req *ct_req;
582 struct ct_sns_rsp *ct_rsp;
583
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800584 if (IS_QLA2100(ha) || IS_QLA2200(ha))
585 return qla2x00_sns_rnn_id(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586
587 /* Issue RNN_ID */
588 /* Prepare common MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800589 ms_pkt = ha->isp_ops->prep_ms_iocb(vha, RNN_ID_REQ_SIZE,
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700590 RNN_ID_RSP_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591
592 /* Prepare CT request */
593 ct_req = qla2x00_prep_ct_req(&ha->ct_sns->p.req, RNN_ID_CMD,
594 RNN_ID_RSP_SIZE);
595 ct_rsp = &ha->ct_sns->p.rsp;
596
597 /* Prepare CT arguments -- port_id, node_name */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800598 ct_req->req.rnn_id.port_id[0] = vha->d_id.b.domain;
599 ct_req->req.rnn_id.port_id[1] = vha->d_id.b.area;
600 ct_req->req.rnn_id.port_id[2] = vha->d_id.b.al_pa;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800602 memcpy(ct_req->req.rnn_id.node_name, vha->node_name, WWN_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603
604 /* Execute MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800605 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 sizeof(ms_iocb_entry_t));
607 if (rval != QLA_SUCCESS) {
608 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700609 ql_dbg(ql_dbg_disc, vha, 0x204d,
610 "RNN_ID issue IOCB failed (%d).\n", rval);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800611 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, "RNN_ID") !=
Andrew Vasquez8c958a92005-07-06 10:30:47 -0700612 QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 rval = QLA_FUNCTION_FAILED;
614 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700615 ql_dbg(ql_dbg_disc, vha, 0x204e,
616 "RNN_ID exiting normally.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 }
618
619 return (rval);
620}
621
Andrew Vasquez1620f7c2006-10-02 12:00:44 -0700622void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800623qla2x00_get_sym_node_name(scsi_qla_host_t *vha, uint8_t *snn)
Andrew Vasquez1620f7c2006-10-02 12:00:44 -0700624{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800625 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez1620f7c2006-10-02 12:00:44 -0700626 sprintf(snn, "%s FW:v%d.%02d.%02d DVR:v%s",ha->model_number,
627 ha->fw_major_version, ha->fw_minor_version,
628 ha->fw_subminor_version, qla2x00_version_str);
629}
630
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631/**
632 * qla2x00_rsnn_nn() - SNS Register Symbolic Node Name (RSNN_NN) of the HBA.
633 * @ha: HA context
634 *
635 * Returns 0 on success.
636 */
637int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800638qla2x00_rsnn_nn(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639{
640 int rval;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800641 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 ms_iocb_entry_t *ms_pkt;
643 struct ct_sns_req *ct_req;
644 struct ct_sns_rsp *ct_rsp;
645
646 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700647 ql_dbg(ql_dbg_disc, vha, 0x2050,
648 "RSNN_ID call unsupported on ISP2100/ISP2200.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 return (QLA_SUCCESS);
650 }
651
652 /* Issue RSNN_NN */
653 /* Prepare common MS IOCB */
654 /* Request size adjusted after CT preparation */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800655 ms_pkt = ha->isp_ops->prep_ms_iocb(vha, 0, RSNN_NN_RSP_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656
657 /* Prepare CT request */
658 ct_req = qla2x00_prep_ct_req(&ha->ct_sns->p.req, RSNN_NN_CMD,
659 RSNN_NN_RSP_SIZE);
660 ct_rsp = &ha->ct_sns->p.rsp;
661
662 /* Prepare CT arguments -- node_name, symbolic node_name, size */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800663 memcpy(ct_req->req.rsnn_nn.node_name, vha->node_name, WWN_SIZE);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700664
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 /* Prepare the Symbolic Node Name */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800666 qla2x00_get_sym_node_name(vha, ct_req->req.rsnn_nn.sym_node_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667
668 /* Calculate SNN length */
Andrew Vasquez1620f7c2006-10-02 12:00:44 -0700669 ct_req->req.rsnn_nn.name_len =
670 (uint8_t)strlen(ct_req->req.rsnn_nn.sym_node_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671
672 /* Update MS IOCB request */
673 ms_pkt->req_bytecount =
674 cpu_to_le32(24 + 1 + ct_req->req.rsnn_nn.name_len);
675 ms_pkt->dseg_req_length = ms_pkt->req_bytecount;
676
677 /* Execute MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800678 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679 sizeof(ms_iocb_entry_t));
680 if (rval != QLA_SUCCESS) {
681 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700682 ql_dbg(ql_dbg_disc, vha, 0x2051,
683 "RSNN_NN issue IOCB failed (%d).\n", rval);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800684 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, "RSNN_NN") !=
Andrew Vasquez8c958a92005-07-06 10:30:47 -0700685 QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 rval = QLA_FUNCTION_FAILED;
687 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700688 ql_dbg(ql_dbg_disc, vha, 0x2052,
689 "RSNN_NN exiting normally.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 }
691
692 return (rval);
693}
694
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695/**
696 * qla2x00_prep_sns_cmd() - Prepare common SNS command request fields for query.
697 * @ha: HA context
698 * @cmd: GS command
699 * @scmd_len: Subcommand length
700 * @data_size: response size in bytes
701 *
702 * Returns a pointer to the @ha's sns_cmd.
703 */
704static inline struct sns_cmd_pkt *
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800705qla2x00_prep_sns_cmd(scsi_qla_host_t *vha, uint16_t cmd, uint16_t scmd_len,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 uint16_t data_size)
707{
708 uint16_t wc;
709 struct sns_cmd_pkt *sns_cmd;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800710 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711
712 sns_cmd = ha->sns_cmd;
713 memset(sns_cmd, 0, sizeof(struct sns_cmd_pkt));
714 wc = data_size / 2; /* Size in 16bit words. */
715 sns_cmd->p.cmd.buffer_length = cpu_to_le16(wc);
716 sns_cmd->p.cmd.buffer_address[0] = cpu_to_le32(LSD(ha->sns_cmd_dma));
717 sns_cmd->p.cmd.buffer_address[1] = cpu_to_le32(MSD(ha->sns_cmd_dma));
718 sns_cmd->p.cmd.subcommand_length = cpu_to_le16(scmd_len);
719 sns_cmd->p.cmd.subcommand = cpu_to_le16(cmd);
720 wc = (data_size - 16) / 4; /* Size in 32bit words. */
721 sns_cmd->p.cmd.size = cpu_to_le16(wc);
722
723 return (sns_cmd);
724}
725
726/**
727 * qla2x00_sns_ga_nxt() - SNS scan for fabric devices via GA_NXT command.
728 * @ha: HA context
729 * @fcport: fcport entry to updated
730 *
731 * This command uses the old Exectute SNS Command mailbox routine.
732 *
733 * Returns 0 on success.
734 */
735static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800736qla2x00_sns_ga_nxt(scsi_qla_host_t *vha, fc_port_t *fcport)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737{
738 int rval;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800739 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 struct sns_cmd_pkt *sns_cmd;
741
742 /* Issue GA_NXT. */
743 /* Prepare SNS command request. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800744 sns_cmd = qla2x00_prep_sns_cmd(vha, GA_NXT_CMD, GA_NXT_SNS_SCMD_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 GA_NXT_SNS_DATA_SIZE);
746
747 /* Prepare SNS command arguments -- port_id. */
748 sns_cmd->p.cmd.param[0] = fcport->d_id.b.al_pa;
749 sns_cmd->p.cmd.param[1] = fcport->d_id.b.area;
750 sns_cmd->p.cmd.param[2] = fcport->d_id.b.domain;
751
752 /* Execute SNS command. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800753 rval = qla2x00_send_sns(vha, ha->sns_cmd_dma, GA_NXT_SNS_CMD_SIZE / 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754 sizeof(struct sns_cmd_pkt));
755 if (rval != QLA_SUCCESS) {
756 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700757 ql_dbg(ql_dbg_disc, vha, 0x205f,
758 "GA_NXT Send SNS failed (%d).\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759 } else if (sns_cmd->p.gan_data[8] != 0x80 ||
760 sns_cmd->p.gan_data[9] != 0x02) {
Chad Dupuiscfb09192011-11-18 09:03:07 -0800761 ql_dbg(ql_dbg_disc + ql_dbg_buffer, vha, 0x2084,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700762 "GA_NXT failed, rejected request ga_nxt_rsp:\n");
763 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2074,
764 sns_cmd->p.gan_data, 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765 rval = QLA_FUNCTION_FAILED;
766 } else {
767 /* Populate fc_port_t entry. */
768 fcport->d_id.b.domain = sns_cmd->p.gan_data[17];
769 fcport->d_id.b.area = sns_cmd->p.gan_data[18];
770 fcport->d_id.b.al_pa = sns_cmd->p.gan_data[19];
771
772 memcpy(fcport->node_name, &sns_cmd->p.gan_data[284], WWN_SIZE);
773 memcpy(fcport->port_name, &sns_cmd->p.gan_data[20], WWN_SIZE);
774
775 if (sns_cmd->p.gan_data[16] != NS_N_PORT_TYPE &&
776 sns_cmd->p.gan_data[16] != NS_NL_PORT_TYPE)
777 fcport->d_id.b.domain = 0xf0;
778
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700779 ql_dbg(ql_dbg_disc, vha, 0x2061,
780 "GA_NXT entry - nn %02x%02x%02x%02x%02x%02x%02x%02x "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781 "pn %02x%02x%02x%02x%02x%02x%02x%02x "
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700782 "port_id=%02x%02x%02x.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783 fcport->node_name[0], fcport->node_name[1],
784 fcport->node_name[2], fcport->node_name[3],
785 fcport->node_name[4], fcport->node_name[5],
786 fcport->node_name[6], fcport->node_name[7],
787 fcport->port_name[0], fcport->port_name[1],
788 fcport->port_name[2], fcport->port_name[3],
789 fcport->port_name[4], fcport->port_name[5],
790 fcport->port_name[6], fcport->port_name[7],
791 fcport->d_id.b.domain, fcport->d_id.b.area,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700792 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793 }
794
795 return (rval);
796}
797
798/**
799 * qla2x00_sns_gid_pt() - SNS scan for fabric devices via GID_PT command.
800 * @ha: HA context
801 * @list: switch info entries to populate
802 *
803 * This command uses the old Exectute SNS Command mailbox routine.
804 *
805 * NOTE: Non-Nx_Ports are not requested.
806 *
807 * Returns 0 on success.
808 */
809static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800810qla2x00_sns_gid_pt(scsi_qla_host_t *vha, sw_info_t *list)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811{
812 int rval;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800813 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 uint16_t i;
815 uint8_t *entry;
816 struct sns_cmd_pkt *sns_cmd;
817
818 /* Issue GID_PT. */
819 /* Prepare SNS command request. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800820 sns_cmd = qla2x00_prep_sns_cmd(vha, GID_PT_CMD, GID_PT_SNS_SCMD_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 GID_PT_SNS_DATA_SIZE);
822
823 /* Prepare SNS command arguments -- port_type. */
824 sns_cmd->p.cmd.param[0] = NS_NX_PORT_TYPE;
825
826 /* Execute SNS command. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800827 rval = qla2x00_send_sns(vha, ha->sns_cmd_dma, GID_PT_SNS_CMD_SIZE / 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 sizeof(struct sns_cmd_pkt));
829 if (rval != QLA_SUCCESS) {
830 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700831 ql_dbg(ql_dbg_disc, vha, 0x206d,
832 "GID_PT Send SNS failed (%d).\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 } else if (sns_cmd->p.gid_data[8] != 0x80 ||
834 sns_cmd->p.gid_data[9] != 0x02) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700835 ql_dbg(ql_dbg_disc, vha, 0x202f,
836 "GID_PT failed, rejected request, gid_rsp:\n");
837 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2081,
838 sns_cmd->p.gid_data, 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839 rval = QLA_FUNCTION_FAILED;
840 } else {
841 /* Set port IDs in switch info list. */
842 for (i = 0; i < MAX_FIBRE_DEVICES; i++) {
843 entry = &sns_cmd->p.gid_data[(i * 4) + 16];
844 list[i].d_id.b.domain = entry[1];
845 list[i].d_id.b.area = entry[2];
846 list[i].d_id.b.al_pa = entry[3];
847
848 /* Last one exit. */
849 if (entry[0] & BIT_7) {
850 list[i].d_id.b.rsvd_1 = entry[0];
851 break;
852 }
853 }
854
855 /*
856 * If we've used all available slots, then the switch is
857 * reporting back more devices that we can handle with this
858 * single call. Return a failed status, and let GA_NXT handle
859 * the overload.
860 */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700861 if (i == MAX_FIBRE_DEVICES)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 rval = QLA_FUNCTION_FAILED;
863 }
864
865 return (rval);
866}
867
868/**
869 * qla2x00_sns_gpn_id() - SNS Get Port Name (GPN_ID) query.
870 * @ha: HA context
871 * @list: switch info entries to populate
872 *
873 * This command uses the old Exectute SNS Command mailbox routine.
874 *
875 * Returns 0 on success.
876 */
877static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800878qla2x00_sns_gpn_id(scsi_qla_host_t *vha, sw_info_t *list)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879{
880 int rval;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800881 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882 uint16_t i;
883 struct sns_cmd_pkt *sns_cmd;
884
885 for (i = 0; i < MAX_FIBRE_DEVICES; i++) {
886 /* Issue GPN_ID */
887 /* Prepare SNS command request. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800888 sns_cmd = qla2x00_prep_sns_cmd(vha, GPN_ID_CMD,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889 GPN_ID_SNS_SCMD_LEN, GPN_ID_SNS_DATA_SIZE);
890
891 /* Prepare SNS command arguments -- port_id. */
892 sns_cmd->p.cmd.param[0] = list[i].d_id.b.al_pa;
893 sns_cmd->p.cmd.param[1] = list[i].d_id.b.area;
894 sns_cmd->p.cmd.param[2] = list[i].d_id.b.domain;
895
896 /* Execute SNS command. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800897 rval = qla2x00_send_sns(vha, ha->sns_cmd_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 GPN_ID_SNS_CMD_SIZE / 2, sizeof(struct sns_cmd_pkt));
899 if (rval != QLA_SUCCESS) {
900 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700901 ql_dbg(ql_dbg_disc, vha, 0x2032,
902 "GPN_ID Send SNS failed (%d).\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903 } else if (sns_cmd->p.gpn_data[8] != 0x80 ||
904 sns_cmd->p.gpn_data[9] != 0x02) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700905 ql_dbg(ql_dbg_disc + ql_dbg_buffer, vha, 0x207e,
906 "GPN_ID failed, rejected request, gpn_rsp:\n");
907 ql_dump_buffer(ql_dbg_disc, vha, 0x207f,
908 sns_cmd->p.gpn_data, 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909 rval = QLA_FUNCTION_FAILED;
910 } else {
911 /* Save portname */
912 memcpy(list[i].port_name, &sns_cmd->p.gpn_data[16],
913 WWN_SIZE);
914 }
915
916 /* Last device exit. */
917 if (list[i].d_id.b.rsvd_1 != 0)
918 break;
919 }
920
921 return (rval);
922}
923
924/**
925 * qla2x00_sns_gnn_id() - SNS Get Node Name (GNN_ID) query.
926 * @ha: HA context
927 * @list: switch info entries to populate
928 *
929 * This command uses the old Exectute SNS Command mailbox routine.
930 *
931 * Returns 0 on success.
932 */
933static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800934qla2x00_sns_gnn_id(scsi_qla_host_t *vha, sw_info_t *list)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935{
936 int rval;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800937 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938 uint16_t i;
939 struct sns_cmd_pkt *sns_cmd;
940
941 for (i = 0; i < MAX_FIBRE_DEVICES; i++) {
942 /* Issue GNN_ID */
943 /* Prepare SNS command request. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800944 sns_cmd = qla2x00_prep_sns_cmd(vha, GNN_ID_CMD,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945 GNN_ID_SNS_SCMD_LEN, GNN_ID_SNS_DATA_SIZE);
946
947 /* Prepare SNS command arguments -- port_id. */
948 sns_cmd->p.cmd.param[0] = list[i].d_id.b.al_pa;
949 sns_cmd->p.cmd.param[1] = list[i].d_id.b.area;
950 sns_cmd->p.cmd.param[2] = list[i].d_id.b.domain;
951
952 /* Execute SNS command. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800953 rval = qla2x00_send_sns(vha, ha->sns_cmd_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954 GNN_ID_SNS_CMD_SIZE / 2, sizeof(struct sns_cmd_pkt));
955 if (rval != QLA_SUCCESS) {
956 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700957 ql_dbg(ql_dbg_disc, vha, 0x203f,
958 "GNN_ID Send SNS failed (%d).\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959 } else if (sns_cmd->p.gnn_data[8] != 0x80 ||
960 sns_cmd->p.gnn_data[9] != 0x02) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700961 ql_dbg(ql_dbg_disc + ql_dbg_buffer, vha, 0x2082,
962 "GNN_ID failed, rejected request, gnn_rsp:\n");
963 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x207a,
964 sns_cmd->p.gnn_data, 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965 rval = QLA_FUNCTION_FAILED;
966 } else {
967 /* Save nodename */
968 memcpy(list[i].node_name, &sns_cmd->p.gnn_data[16],
969 WWN_SIZE);
970
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700971 ql_dbg(ql_dbg_disc, vha, 0x206e,
972 "GID_PT entry - nn %02x%02x%02x%02x%02x%02x%02x%02x "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973 "pn %02x%02x%02x%02x%02x%02x%02x%02x "
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700974 "port_id=%02x%02x%02x.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 list[i].node_name[0], list[i].node_name[1],
976 list[i].node_name[2], list[i].node_name[3],
977 list[i].node_name[4], list[i].node_name[5],
978 list[i].node_name[6], list[i].node_name[7],
979 list[i].port_name[0], list[i].port_name[1],
980 list[i].port_name[2], list[i].port_name[3],
981 list[i].port_name[4], list[i].port_name[5],
982 list[i].port_name[6], list[i].port_name[7],
983 list[i].d_id.b.domain, list[i].d_id.b.area,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700984 list[i].d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985 }
986
987 /* Last device exit. */
988 if (list[i].d_id.b.rsvd_1 != 0)
989 break;
990 }
991
992 return (rval);
993}
994
995/**
996 * qla2x00_snd_rft_id() - SNS Register FC-4 TYPEs (RFT_ID) supported by the HBA.
997 * @ha: HA context
998 *
999 * This command uses the old Exectute SNS Command mailbox routine.
1000 *
1001 * Returns 0 on success.
1002 */
1003static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001004qla2x00_sns_rft_id(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005{
1006 int rval;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001007 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008 struct sns_cmd_pkt *sns_cmd;
1009
1010 /* Issue RFT_ID. */
1011 /* Prepare SNS command request. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001012 sns_cmd = qla2x00_prep_sns_cmd(vha, RFT_ID_CMD, RFT_ID_SNS_SCMD_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013 RFT_ID_SNS_DATA_SIZE);
1014
1015 /* Prepare SNS command arguments -- port_id, FC-4 types */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001016 sns_cmd->p.cmd.param[0] = vha->d_id.b.al_pa;
1017 sns_cmd->p.cmd.param[1] = vha->d_id.b.area;
1018 sns_cmd->p.cmd.param[2] = vha->d_id.b.domain;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019
1020 sns_cmd->p.cmd.param[5] = 0x01; /* FCP-3 */
1021
1022 /* Execute SNS command. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001023 rval = qla2x00_send_sns(vha, ha->sns_cmd_dma, RFT_ID_SNS_CMD_SIZE / 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 sizeof(struct sns_cmd_pkt));
1025 if (rval != QLA_SUCCESS) {
1026 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001027 ql_dbg(ql_dbg_disc, vha, 0x2060,
1028 "RFT_ID Send SNS failed (%d).\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029 } else if (sns_cmd->p.rft_data[8] != 0x80 ||
1030 sns_cmd->p.rft_data[9] != 0x02) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001031 ql_dbg(ql_dbg_disc + ql_dbg_buffer, vha, 0x2083,
1032 "RFT_ID failed, rejected request rft_rsp:\n");
1033 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2080,
1034 sns_cmd->p.rft_data, 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035 rval = QLA_FUNCTION_FAILED;
1036 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001037 ql_dbg(ql_dbg_disc, vha, 0x2073,
1038 "RFT_ID exiting normally.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 }
1040
1041 return (rval);
1042}
1043
1044/**
1045 * qla2x00_sns_rnn_id() - SNS Register Node Name (RNN_ID) of the HBA.
1046 * HBA.
1047 * @ha: HA context
1048 *
1049 * This command uses the old Exectute SNS Command mailbox routine.
1050 *
1051 * Returns 0 on success.
1052 */
1053static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001054qla2x00_sns_rnn_id(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055{
1056 int rval;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001057 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058 struct sns_cmd_pkt *sns_cmd;
1059
1060 /* Issue RNN_ID. */
1061 /* Prepare SNS command request. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001062 sns_cmd = qla2x00_prep_sns_cmd(vha, RNN_ID_CMD, RNN_ID_SNS_SCMD_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063 RNN_ID_SNS_DATA_SIZE);
1064
1065 /* Prepare SNS command arguments -- port_id, nodename. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001066 sns_cmd->p.cmd.param[0] = vha->d_id.b.al_pa;
1067 sns_cmd->p.cmd.param[1] = vha->d_id.b.area;
1068 sns_cmd->p.cmd.param[2] = vha->d_id.b.domain;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001070 sns_cmd->p.cmd.param[4] = vha->node_name[7];
1071 sns_cmd->p.cmd.param[5] = vha->node_name[6];
1072 sns_cmd->p.cmd.param[6] = vha->node_name[5];
1073 sns_cmd->p.cmd.param[7] = vha->node_name[4];
1074 sns_cmd->p.cmd.param[8] = vha->node_name[3];
1075 sns_cmd->p.cmd.param[9] = vha->node_name[2];
1076 sns_cmd->p.cmd.param[10] = vha->node_name[1];
1077 sns_cmd->p.cmd.param[11] = vha->node_name[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078
1079 /* Execute SNS command. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001080 rval = qla2x00_send_sns(vha, ha->sns_cmd_dma, RNN_ID_SNS_CMD_SIZE / 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081 sizeof(struct sns_cmd_pkt));
1082 if (rval != QLA_SUCCESS) {
1083 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001084 ql_dbg(ql_dbg_disc, vha, 0x204a,
1085 "RNN_ID Send SNS failed (%d).\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086 } else if (sns_cmd->p.rnn_data[8] != 0x80 ||
1087 sns_cmd->p.rnn_data[9] != 0x02) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001088 ql_dbg(ql_dbg_disc + ql_dbg_buffer, vha, 0x207b,
1089 "RNN_ID failed, rejected request, rnn_rsp:\n");
1090 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x207c,
1091 sns_cmd->p.rnn_data, 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092 rval = QLA_FUNCTION_FAILED;
1093 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001094 ql_dbg(ql_dbg_disc, vha, 0x204c,
1095 "RNN_ID exiting normally.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096 }
1097
1098 return (rval);
1099}
Andrew Vasquezcca53352005-08-26 19:08:30 -07001100
1101/**
Joe Perchesb1c11812008-02-03 17:28:22 +02001102 * qla2x00_mgmt_svr_login() - Login to fabric Management Service.
Andrew Vasquezcca53352005-08-26 19:08:30 -07001103 * @ha: HA context
1104 *
1105 * Returns 0 on success.
1106 */
1107static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001108qla2x00_mgmt_svr_login(scsi_qla_host_t *vha)
Andrew Vasquezcca53352005-08-26 19:08:30 -07001109{
Chad Dupuis0b91d112012-02-09 11:15:42 -08001110 int ret, rval;
Andrew Vasquezcca53352005-08-26 19:08:30 -07001111 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001112 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezcca53352005-08-26 19:08:30 -07001113 ret = QLA_SUCCESS;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001114 if (vha->flags.management_server_logged_in)
Andrew Vasquezcca53352005-08-26 19:08:30 -07001115 return ret;
1116
Chad Dupuis0b91d112012-02-09 11:15:42 -08001117 rval = ha->isp_ops->fabric_login(vha, vha->mgmt_svr_loop_id, 0xff, 0xff,
1118 0xfa, mb, BIT_1|BIT_0);
1119 if (rval != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
1120 if (rval == QLA_MEMORY_ALLOC_FAILED)
1121 ql_dbg(ql_dbg_disc, vha, 0x2085,
1122 "Failed management_server login: loopid=%x "
1123 "rval=%d\n", vha->mgmt_svr_loop_id, rval);
1124 else
1125 ql_dbg(ql_dbg_disc, vha, 0x2024,
1126 "Failed management_server login: loopid=%x "
1127 "mb[0]=%x mb[1]=%x mb[2]=%x mb[6]=%x mb[7]=%x.\n",
1128 vha->mgmt_svr_loop_id, mb[0], mb[1], mb[2], mb[6],
1129 mb[7]);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001130 ret = QLA_FUNCTION_FAILED;
1131 } else
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001132 vha->flags.management_server_logged_in = 1;
Andrew Vasquezcca53352005-08-26 19:08:30 -07001133
1134 return ret;
1135}
1136
1137/**
1138 * qla2x00_prep_ms_fdmi_iocb() - Prepare common MS IOCB fields for FDMI query.
1139 * @ha: HA context
1140 * @req_size: request size in bytes
1141 * @rsp_size: response size in bytes
1142 *
1143 * Returns a pointer to the @ha's ms_iocb.
1144 */
1145void *
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001146qla2x00_prep_ms_fdmi_iocb(scsi_qla_host_t *vha, uint32_t req_size,
Andrew Vasquezcca53352005-08-26 19:08:30 -07001147 uint32_t rsp_size)
1148{
1149 ms_iocb_entry_t *ms_pkt;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001150 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezcca53352005-08-26 19:08:30 -07001151 ms_pkt = ha->ms_iocb;
1152 memset(ms_pkt, 0, sizeof(ms_iocb_entry_t));
1153
1154 ms_pkt->entry_type = MS_IOCB_TYPE;
1155 ms_pkt->entry_count = 1;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001156 SET_TARGET_ID(ha, ms_pkt->loop_id, vha->mgmt_svr_loop_id);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001157 ms_pkt->control_flags = __constant_cpu_to_le16(CF_READ | CF_HEAD_TAG);
Andrew Vasquez00a537b2008-02-28 14:06:11 -08001158 ms_pkt->timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001159 ms_pkt->cmd_dsd_count = __constant_cpu_to_le16(1);
1160 ms_pkt->total_dsd_count = __constant_cpu_to_le16(2);
1161 ms_pkt->rsp_bytecount = cpu_to_le32(rsp_size);
1162 ms_pkt->req_bytecount = cpu_to_le32(req_size);
1163
1164 ms_pkt->dseg_req_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
1165 ms_pkt->dseg_req_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
1166 ms_pkt->dseg_req_length = ms_pkt->req_bytecount;
1167
1168 ms_pkt->dseg_rsp_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
1169 ms_pkt->dseg_rsp_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
1170 ms_pkt->dseg_rsp_length = ms_pkt->rsp_bytecount;
1171
1172 return ms_pkt;
1173}
1174
1175/**
1176 * qla24xx_prep_ms_fdmi_iocb() - Prepare common MS IOCB fields for FDMI query.
1177 * @ha: HA context
1178 * @req_size: request size in bytes
1179 * @rsp_size: response size in bytes
1180 *
1181 * Returns a pointer to the @ha's ms_iocb.
1182 */
1183void *
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001184qla24xx_prep_ms_fdmi_iocb(scsi_qla_host_t *vha, uint32_t req_size,
Andrew Vasquezcca53352005-08-26 19:08:30 -07001185 uint32_t rsp_size)
1186{
1187 struct ct_entry_24xx *ct_pkt;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001188 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezcca53352005-08-26 19:08:30 -07001189
1190 ct_pkt = (struct ct_entry_24xx *)ha->ms_iocb;
1191 memset(ct_pkt, 0, sizeof(struct ct_entry_24xx));
1192
1193 ct_pkt->entry_type = CT_IOCB_TYPE;
1194 ct_pkt->entry_count = 1;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001195 ct_pkt->nport_handle = cpu_to_le16(vha->mgmt_svr_loop_id);
Andrew Vasquez00a537b2008-02-28 14:06:11 -08001196 ct_pkt->timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001197 ct_pkt->cmd_dsd_count = __constant_cpu_to_le16(1);
1198 ct_pkt->rsp_dsd_count = __constant_cpu_to_le16(1);
1199 ct_pkt->rsp_byte_count = cpu_to_le32(rsp_size);
1200 ct_pkt->cmd_byte_count = cpu_to_le32(req_size);
1201
1202 ct_pkt->dseg_0_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
1203 ct_pkt->dseg_0_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
1204 ct_pkt->dseg_0_len = ct_pkt->cmd_byte_count;
1205
1206 ct_pkt->dseg_1_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
1207 ct_pkt->dseg_1_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
1208 ct_pkt->dseg_1_len = ct_pkt->rsp_byte_count;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001209 ct_pkt->vp_index = vha->vp_idx;
Andrew Vasquezcca53352005-08-26 19:08:30 -07001210
1211 return ct_pkt;
1212}
1213
1214static inline ms_iocb_entry_t *
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001215qla2x00_update_ms_fdmi_iocb(scsi_qla_host_t *vha, uint32_t req_size)
Andrew Vasquezcca53352005-08-26 19:08:30 -07001216{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001217 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezcca53352005-08-26 19:08:30 -07001218 ms_iocb_entry_t *ms_pkt = ha->ms_iocb;
1219 struct ct_entry_24xx *ct_pkt = (struct ct_entry_24xx *)ha->ms_iocb;
1220
Andrew Vasqueze4289242007-07-19 15:05:56 -07001221 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquezcca53352005-08-26 19:08:30 -07001222 ct_pkt->cmd_byte_count = cpu_to_le32(req_size);
1223 ct_pkt->dseg_0_len = ct_pkt->cmd_byte_count;
1224 } else {
1225 ms_pkt->req_bytecount = cpu_to_le32(req_size);
1226 ms_pkt->dseg_req_length = ms_pkt->req_bytecount;
1227 }
1228
1229 return ms_pkt;
1230}
1231
1232/**
1233 * qla2x00_prep_ct_req() - Prepare common CT request fields for SNS query.
1234 * @ct_req: CT request buffer
1235 * @cmd: GS command
1236 * @rsp_size: response size in bytes
1237 *
1238 * Returns a pointer to the intitialized @ct_req.
1239 */
1240static inline struct ct_sns_req *
1241qla2x00_prep_ct_fdmi_req(struct ct_sns_req *ct_req, uint16_t cmd,
1242 uint16_t rsp_size)
1243{
1244 memset(ct_req, 0, sizeof(struct ct_sns_pkt));
1245
1246 ct_req->header.revision = 0x01;
1247 ct_req->header.gs_type = 0xFA;
1248 ct_req->header.gs_subtype = 0x10;
1249 ct_req->command = cpu_to_be16(cmd);
1250 ct_req->max_rsp_size = cpu_to_be16((rsp_size - 16) / 4);
1251
1252 return ct_req;
1253}
1254
1255/**
1256 * qla2x00_fdmi_rhba() -
1257 * @ha: HA context
1258 *
1259 * Returns 0 on success.
1260 */
1261static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001262qla2x00_fdmi_rhba(scsi_qla_host_t *vha)
Andrew Vasquezcca53352005-08-26 19:08:30 -07001263{
1264 int rval, alen;
1265 uint32_t size, sn;
1266
1267 ms_iocb_entry_t *ms_pkt;
1268 struct ct_sns_req *ct_req;
1269 struct ct_sns_rsp *ct_rsp;
1270 uint8_t *entries;
1271 struct ct_fdmi_hba_attr *eiter;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001272 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezcca53352005-08-26 19:08:30 -07001273
1274 /* Issue RHBA */
1275 /* Prepare common MS IOCB */
1276 /* Request size adjusted after CT preparation */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001277 ms_pkt = ha->isp_ops->prep_ms_fdmi_iocb(vha, 0, RHBA_RSP_SIZE);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001278
1279 /* Prepare CT request */
1280 ct_req = qla2x00_prep_ct_fdmi_req(&ha->ct_sns->p.req, RHBA_CMD,
1281 RHBA_RSP_SIZE);
1282 ct_rsp = &ha->ct_sns->p.rsp;
1283
1284 /* Prepare FDMI command arguments -- attribute block, attributes. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001285 memcpy(ct_req->req.rhba.hba_identifier, vha->port_name, WWN_SIZE);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001286 ct_req->req.rhba.entry_count = __constant_cpu_to_be32(1);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001287 memcpy(ct_req->req.rhba.port_name, vha->port_name, WWN_SIZE);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001288 size = 2 * WWN_SIZE + 4 + 4;
1289
1290 /* Attributes */
1291 ct_req->req.rhba.attrs.count =
1292 __constant_cpu_to_be32(FDMI_HBA_ATTR_COUNT);
1293 entries = ct_req->req.rhba.hba_identifier;
1294
1295 /* Nodename. */
1296 eiter = (struct ct_fdmi_hba_attr *) (entries + size);
1297 eiter->type = __constant_cpu_to_be16(FDMI_HBA_NODE_NAME);
1298 eiter->len = __constant_cpu_to_be16(4 + WWN_SIZE);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001299 memcpy(eiter->a.node_name, vha->node_name, WWN_SIZE);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001300 size += 4 + WWN_SIZE;
1301
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001302 ql_dbg(ql_dbg_disc, vha, 0x2025,
1303 "NodeName = %02x%02x%02x%02x%02x%02x%02x%02x.\n",
1304 eiter->a.node_name[0], eiter->a.node_name[1],
1305 eiter->a.node_name[2], eiter->a.node_name[3],
1306 eiter->a.node_name[4], eiter->a.node_name[5],
1307 eiter->a.node_name[6], eiter->a.node_name[7]);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001308
1309 /* Manufacturer. */
1310 eiter = (struct ct_fdmi_hba_attr *) (entries + size);
1311 eiter->type = __constant_cpu_to_be16(FDMI_HBA_MANUFACTURER);
1312 strcpy(eiter->a.manufacturer, "QLogic Corporation");
1313 alen = strlen(eiter->a.manufacturer);
1314 alen += (alen & 3) ? (4 - (alen & 3)) : 4;
1315 eiter->len = cpu_to_be16(4 + alen);
1316 size += 4 + alen;
1317
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001318 ql_dbg(ql_dbg_disc, vha, 0x2026,
1319 "Manufacturer = %s.\n", eiter->a.manufacturer);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001320
1321 /* Serial number. */
1322 eiter = (struct ct_fdmi_hba_attr *) (entries + size);
1323 eiter->type = __constant_cpu_to_be16(FDMI_HBA_SERIAL_NUMBER);
1324 sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
1325 sprintf(eiter->a.serial_num, "%c%05d", 'A' + sn / 100000, sn % 100000);
1326 alen = strlen(eiter->a.serial_num);
1327 alen += (alen & 3) ? (4 - (alen & 3)) : 4;
1328 eiter->len = cpu_to_be16(4 + alen);
1329 size += 4 + alen;
1330
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001331 ql_dbg(ql_dbg_disc, vha, 0x2027,
1332 "Serial no. = %s.\n", eiter->a.serial_num);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001333
1334 /* Model name. */
1335 eiter = (struct ct_fdmi_hba_attr *) (entries + size);
1336 eiter->type = __constant_cpu_to_be16(FDMI_HBA_MODEL);
1337 strcpy(eiter->a.model, ha->model_number);
1338 alen = strlen(eiter->a.model);
1339 alen += (alen & 3) ? (4 - (alen & 3)) : 4;
1340 eiter->len = cpu_to_be16(4 + alen);
1341 size += 4 + alen;
1342
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001343 ql_dbg(ql_dbg_disc, vha, 0x2028,
1344 "Model Name = %s.\n", eiter->a.model);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001345
1346 /* Model description. */
1347 eiter = (struct ct_fdmi_hba_attr *) (entries + size);
1348 eiter->type = __constant_cpu_to_be16(FDMI_HBA_MODEL_DESCRIPTION);
1349 if (ha->model_desc)
1350 strncpy(eiter->a.model_desc, ha->model_desc, 80);
1351 alen = strlen(eiter->a.model_desc);
1352 alen += (alen & 3) ? (4 - (alen & 3)) : 4;
1353 eiter->len = cpu_to_be16(4 + alen);
1354 size += 4 + alen;
1355
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001356 ql_dbg(ql_dbg_disc, vha, 0x2029,
1357 "Model Desc = %s.\n", eiter->a.model_desc);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001358
1359 /* Hardware version. */
1360 eiter = (struct ct_fdmi_hba_attr *) (entries + size);
1361 eiter->type = __constant_cpu_to_be16(FDMI_HBA_HARDWARE_VERSION);
1362 strcpy(eiter->a.hw_version, ha->adapter_id);
1363 alen = strlen(eiter->a.hw_version);
1364 alen += (alen & 3) ? (4 - (alen & 3)) : 4;
1365 eiter->len = cpu_to_be16(4 + alen);
1366 size += 4 + alen;
1367
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001368 ql_dbg(ql_dbg_disc, vha, 0x202a,
1369 "Hardware ver = %s.\n", eiter->a.hw_version);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001370
1371 /* Driver version. */
1372 eiter = (struct ct_fdmi_hba_attr *) (entries + size);
1373 eiter->type = __constant_cpu_to_be16(FDMI_HBA_DRIVER_VERSION);
1374 strcpy(eiter->a.driver_version, qla2x00_version_str);
1375 alen = strlen(eiter->a.driver_version);
1376 alen += (alen & 3) ? (4 - (alen & 3)) : 4;
1377 eiter->len = cpu_to_be16(4 + alen);
1378 size += 4 + alen;
1379
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001380 ql_dbg(ql_dbg_disc, vha, 0x202b,
1381 "Driver ver = %s.\n", eiter->a.driver_version);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001382
1383 /* Option ROM version. */
1384 eiter = (struct ct_fdmi_hba_attr *) (entries + size);
1385 eiter->type = __constant_cpu_to_be16(FDMI_HBA_OPTION_ROM_VERSION);
1386 strcpy(eiter->a.orom_version, "0.00");
1387 alen = strlen(eiter->a.orom_version);
1388 alen += (alen & 3) ? (4 - (alen & 3)) : 4;
1389 eiter->len = cpu_to_be16(4 + alen);
1390 size += 4 + alen;
1391
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001392 ql_dbg(ql_dbg_disc, vha , 0x202c,
1393 "Optrom vers = %s.\n", eiter->a.orom_version);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001394
1395 /* Firmware version */
1396 eiter = (struct ct_fdmi_hba_attr *) (entries + size);
1397 eiter->type = __constant_cpu_to_be16(FDMI_HBA_FIRMWARE_VERSION);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001398 ha->isp_ops->fw_version_str(vha, eiter->a.fw_version);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001399 alen = strlen(eiter->a.fw_version);
1400 alen += (alen & 3) ? (4 - (alen & 3)) : 4;
1401 eiter->len = cpu_to_be16(4 + alen);
1402 size += 4 + alen;
1403
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001404 ql_dbg(ql_dbg_disc, vha, 0x202d,
1405 "Firmware vers = %s.\n", eiter->a.fw_version);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001406
1407 /* Update MS request size. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001408 qla2x00_update_ms_fdmi_iocb(vha, size + 16);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001409
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001410 ql_dbg(ql_dbg_disc, vha, 0x202e,
1411 "RHBA identifier = "
1412 "%02x%02x%02x%02x%02x%02x%02x%02x size=%d.\n",
1413 ct_req->req.rhba.hba_identifier[0],
Andrew Vasquezcca53352005-08-26 19:08:30 -07001414 ct_req->req.rhba.hba_identifier[1],
1415 ct_req->req.rhba.hba_identifier[2],
1416 ct_req->req.rhba.hba_identifier[3],
1417 ct_req->req.rhba.hba_identifier[4],
1418 ct_req->req.rhba.hba_identifier[5],
1419 ct_req->req.rhba.hba_identifier[6],
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001420 ct_req->req.rhba.hba_identifier[7], size);
1421 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2076,
1422 entries, size);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001423
1424 /* Execute MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001425 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
Andrew Vasquezcca53352005-08-26 19:08:30 -07001426 sizeof(ms_iocb_entry_t));
1427 if (rval != QLA_SUCCESS) {
1428 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001429 ql_dbg(ql_dbg_disc, vha, 0x2030,
1430 "RHBA issue IOCB failed (%d).\n", rval);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001431 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, "RHBA") !=
Andrew Vasquezcca53352005-08-26 19:08:30 -07001432 QLA_SUCCESS) {
1433 rval = QLA_FUNCTION_FAILED;
1434 if (ct_rsp->header.reason_code == CT_REASON_CANNOT_PERFORM &&
1435 ct_rsp->header.explanation_code ==
1436 CT_EXPL_ALREADY_REGISTERED) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001437 ql_dbg(ql_dbg_disc, vha, 0x2034,
1438 "HBA already registered.\n");
Andrew Vasquezcca53352005-08-26 19:08:30 -07001439 rval = QLA_ALREADY_REGISTERED;
1440 }
1441 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001442 ql_dbg(ql_dbg_disc, vha, 0x2035,
1443 "RHBA exiting normally.\n");
Andrew Vasquezcca53352005-08-26 19:08:30 -07001444 }
1445
1446 return rval;
1447}
1448
1449/**
1450 * qla2x00_fdmi_dhba() -
1451 * @ha: HA context
1452 *
1453 * Returns 0 on success.
1454 */
1455static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001456qla2x00_fdmi_dhba(scsi_qla_host_t *vha)
Andrew Vasquezcca53352005-08-26 19:08:30 -07001457{
1458 int rval;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001459 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezcca53352005-08-26 19:08:30 -07001460 ms_iocb_entry_t *ms_pkt;
1461 struct ct_sns_req *ct_req;
1462 struct ct_sns_rsp *ct_rsp;
1463
1464 /* Issue RPA */
1465 /* Prepare common MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001466 ms_pkt = ha->isp_ops->prep_ms_fdmi_iocb(vha, DHBA_REQ_SIZE,
Andrew Vasquezcca53352005-08-26 19:08:30 -07001467 DHBA_RSP_SIZE);
1468
1469 /* Prepare CT request */
1470 ct_req = qla2x00_prep_ct_fdmi_req(&ha->ct_sns->p.req, DHBA_CMD,
1471 DHBA_RSP_SIZE);
1472 ct_rsp = &ha->ct_sns->p.rsp;
1473
1474 /* Prepare FDMI command arguments -- portname. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001475 memcpy(ct_req->req.dhba.port_name, vha->port_name, WWN_SIZE);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001476
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001477 ql_dbg(ql_dbg_disc, vha, 0x2036,
1478 "DHBA portname = %02x%02x%02x%02x%02x%02x%02x%02x.\n",
Andrew Vasquezcca53352005-08-26 19:08:30 -07001479 ct_req->req.dhba.port_name[0], ct_req->req.dhba.port_name[1],
1480 ct_req->req.dhba.port_name[2], ct_req->req.dhba.port_name[3],
1481 ct_req->req.dhba.port_name[4], ct_req->req.dhba.port_name[5],
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001482 ct_req->req.dhba.port_name[6], ct_req->req.dhba.port_name[7]);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001483
1484 /* Execute MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001485 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
Andrew Vasquezcca53352005-08-26 19:08:30 -07001486 sizeof(ms_iocb_entry_t));
1487 if (rval != QLA_SUCCESS) {
1488 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001489 ql_dbg(ql_dbg_disc, vha, 0x2037,
1490 "DHBA issue IOCB failed (%d).\n", rval);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001491 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, "DHBA") !=
Andrew Vasquezcca53352005-08-26 19:08:30 -07001492 QLA_SUCCESS) {
1493 rval = QLA_FUNCTION_FAILED;
1494 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001495 ql_dbg(ql_dbg_disc, vha, 0x2038,
1496 "DHBA exiting normally.\n");
Andrew Vasquezcca53352005-08-26 19:08:30 -07001497 }
1498
1499 return rval;
1500}
1501
1502/**
1503 * qla2x00_fdmi_rpa() -
1504 * @ha: HA context
1505 *
1506 * Returns 0 on success.
1507 */
1508static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001509qla2x00_fdmi_rpa(scsi_qla_host_t *vha)
Andrew Vasquezcca53352005-08-26 19:08:30 -07001510{
1511 int rval, alen;
1512 uint32_t size, max_frame_size;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001513 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezcca53352005-08-26 19:08:30 -07001514 ms_iocb_entry_t *ms_pkt;
1515 struct ct_sns_req *ct_req;
1516 struct ct_sns_rsp *ct_rsp;
1517 uint8_t *entries;
1518 struct ct_fdmi_port_attr *eiter;
1519 struct init_cb_24xx *icb24 = (struct init_cb_24xx *)ha->init_cb;
1520
1521 /* Issue RPA */
1522 /* Prepare common MS IOCB */
1523 /* Request size adjusted after CT preparation */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001524 ms_pkt = ha->isp_ops->prep_ms_fdmi_iocb(vha, 0, RPA_RSP_SIZE);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001525
1526 /* Prepare CT request */
1527 ct_req = qla2x00_prep_ct_fdmi_req(&ha->ct_sns->p.req, RPA_CMD,
1528 RPA_RSP_SIZE);
1529 ct_rsp = &ha->ct_sns->p.rsp;
1530
1531 /* Prepare FDMI command arguments -- attribute block, attributes. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001532 memcpy(ct_req->req.rpa.port_name, vha->port_name, WWN_SIZE);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001533 size = WWN_SIZE + 4;
1534
1535 /* Attributes */
1536 ct_req->req.rpa.attrs.count =
Andrew Vasquez8a85e172007-09-20 14:07:41 -07001537 __constant_cpu_to_be32(FDMI_PORT_ATTR_COUNT - 1);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001538 entries = ct_req->req.rpa.port_name;
1539
1540 /* FC4 types. */
1541 eiter = (struct ct_fdmi_port_attr *) (entries + size);
1542 eiter->type = __constant_cpu_to_be16(FDMI_PORT_FC4_TYPES);
1543 eiter->len = __constant_cpu_to_be16(4 + 32);
1544 eiter->a.fc4_types[2] = 0x01;
1545 size += 4 + 32;
1546
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001547 ql_dbg(ql_dbg_disc, vha, 0x2039,
1548 "FC4_TYPES=%02x %02x.\n",
1549 eiter->a.fc4_types[2],
1550 eiter->a.fc4_types[1]);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001551
1552 /* Supported speed. */
1553 eiter = (struct ct_fdmi_port_attr *) (entries + size);
1554 eiter->type = __constant_cpu_to_be16(FDMI_PORT_SUPPORT_SPEED);
1555 eiter->len = __constant_cpu_to_be16(4 + 4);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001556 if (IS_CNA_CAPABLE(ha))
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001557 eiter->a.sup_speed = __constant_cpu_to_be32(
1558 FDMI_PORT_SPEED_10GB);
1559 else if (IS_QLA25XX(ha))
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001560 eiter->a.sup_speed = __constant_cpu_to_be32(
1561 FDMI_PORT_SPEED_1GB|FDMI_PORT_SPEED_2GB|
1562 FDMI_PORT_SPEED_4GB|FDMI_PORT_SPEED_8GB);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001563 else if (IS_QLA24XX_TYPE(ha))
Andrew Vasquez58815692007-07-19 15:05:58 -07001564 eiter->a.sup_speed = __constant_cpu_to_be32(
1565 FDMI_PORT_SPEED_1GB|FDMI_PORT_SPEED_2GB|
1566 FDMI_PORT_SPEED_4GB);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001567 else if (IS_QLA23XX(ha))
Andrew Vasquez58815692007-07-19 15:05:58 -07001568 eiter->a.sup_speed =__constant_cpu_to_be32(
1569 FDMI_PORT_SPEED_1GB|FDMI_PORT_SPEED_2GB);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001570 else
Andrew Vasquez58815692007-07-19 15:05:58 -07001571 eiter->a.sup_speed = __constant_cpu_to_be32(
1572 FDMI_PORT_SPEED_1GB);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001573 size += 4 + 4;
1574
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001575 ql_dbg(ql_dbg_disc, vha, 0x203a,
1576 "Supported_Speed=%x.\n", eiter->a.sup_speed);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001577
1578 /* Current speed. */
1579 eiter = (struct ct_fdmi_port_attr *) (entries + size);
1580 eiter->type = __constant_cpu_to_be16(FDMI_PORT_CURRENT_SPEED);
1581 eiter->len = __constant_cpu_to_be16(4 + 4);
1582 switch (ha->link_data_rate) {
Andrew Vasquez58815692007-07-19 15:05:58 -07001583 case PORT_SPEED_1GB:
1584 eiter->a.cur_speed =
1585 __constant_cpu_to_be32(FDMI_PORT_SPEED_1GB);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001586 break;
Andrew Vasquez58815692007-07-19 15:05:58 -07001587 case PORT_SPEED_2GB:
1588 eiter->a.cur_speed =
1589 __constant_cpu_to_be32(FDMI_PORT_SPEED_2GB);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001590 break;
Andrew Vasquez58815692007-07-19 15:05:58 -07001591 case PORT_SPEED_4GB:
1592 eiter->a.cur_speed =
1593 __constant_cpu_to_be32(FDMI_PORT_SPEED_4GB);
1594 break;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001595 case PORT_SPEED_8GB:
1596 eiter->a.cur_speed =
1597 __constant_cpu_to_be32(FDMI_PORT_SPEED_8GB);
1598 break;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001599 case PORT_SPEED_10GB:
1600 eiter->a.cur_speed =
1601 __constant_cpu_to_be32(FDMI_PORT_SPEED_10GB);
1602 break;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001603 case PORT_SPEED_16GB:
1604 eiter->a.cur_speed =
1605 __constant_cpu_to_be32(FDMI_PORT_SPEED_16GB);
1606 break;
Andrew Vasquez58815692007-07-19 15:05:58 -07001607 default:
1608 eiter->a.cur_speed =
1609 __constant_cpu_to_be32(FDMI_PORT_SPEED_UNKNOWN);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001610 break;
1611 }
1612 size += 4 + 4;
1613
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001614 ql_dbg(ql_dbg_disc, vha, 0x203b,
1615 "Current_Speed=%x.\n", eiter->a.cur_speed);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001616
1617 /* Max frame size. */
1618 eiter = (struct ct_fdmi_port_attr *) (entries + size);
1619 eiter->type = __constant_cpu_to_be16(FDMI_PORT_MAX_FRAME_SIZE);
1620 eiter->len = __constant_cpu_to_be16(4 + 4);
Andrew Vasqueze4289242007-07-19 15:05:56 -07001621 max_frame_size = IS_FWI2_CAPABLE(ha) ?
Seokmann Juc6852c42008-04-24 15:21:29 -07001622 le16_to_cpu(icb24->frame_payload_size):
1623 le16_to_cpu(ha->init_cb->frame_payload_size);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001624 eiter->a.max_frame_size = cpu_to_be32(max_frame_size);
1625 size += 4 + 4;
1626
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001627 ql_dbg(ql_dbg_disc, vha, 0x203c,
1628 "Max_Frame_Size=%x.\n", eiter->a.max_frame_size);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001629
1630 /* OS device name. */
1631 eiter = (struct ct_fdmi_port_attr *) (entries + size);
1632 eiter->type = __constant_cpu_to_be16(FDMI_PORT_OS_DEVICE_NAME);
Andrew Vasquez8a85e172007-09-20 14:07:41 -07001633 strcpy(eiter->a.os_dev_name, QLA2XXX_DRIVER_NAME);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001634 alen = strlen(eiter->a.os_dev_name);
1635 alen += (alen & 3) ? (4 - (alen & 3)) : 4;
1636 eiter->len = cpu_to_be16(4 + alen);
1637 size += 4 + alen;
1638
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001639 ql_dbg(ql_dbg_disc, vha, 0x204b,
1640 "OS_Device_Name=%s.\n", eiter->a.os_dev_name);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001641
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07001642 /* Hostname. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001643 if (strlen(fc_host_system_hostname(vha->host))) {
Andrew Vasquez8a85e172007-09-20 14:07:41 -07001644 ct_req->req.rpa.attrs.count =
1645 __constant_cpu_to_be32(FDMI_PORT_ATTR_COUNT);
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07001646 eiter = (struct ct_fdmi_port_attr *) (entries + size);
1647 eiter->type = __constant_cpu_to_be16(FDMI_PORT_HOST_NAME);
1648 snprintf(eiter->a.host_name, sizeof(eiter->a.host_name),
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001649 "%s", fc_host_system_hostname(vha->host));
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07001650 alen = strlen(eiter->a.host_name);
1651 alen += (alen & 3) ? (4 - (alen & 3)) : 4;
1652 eiter->len = cpu_to_be16(4 + alen);
1653 size += 4 + alen;
1654
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001655 ql_dbg(ql_dbg_disc, vha, 0x203d,
1656 "HostName=%s.\n", eiter->a.host_name);
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07001657 }
1658
Andrew Vasquezcca53352005-08-26 19:08:30 -07001659 /* Update MS request size. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001660 qla2x00_update_ms_fdmi_iocb(vha, size + 16);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001661
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001662 ql_dbg(ql_dbg_disc, vha, 0x203e,
1663 "RPA portname= %02x%02x%02x%02x%02X%02x%02x%02x size=%d.\n",
1664 ct_req->req.rpa.port_name[0], ct_req->req.rpa.port_name[1],
1665 ct_req->req.rpa.port_name[2], ct_req->req.rpa.port_name[3],
1666 ct_req->req.rpa.port_name[4], ct_req->req.rpa.port_name[5],
1667 ct_req->req.rpa.port_name[6], ct_req->req.rpa.port_name[7],
1668 size);
1669 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2079,
1670 entries, size);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001671
1672 /* Execute MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001673 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
Andrew Vasquezcca53352005-08-26 19:08:30 -07001674 sizeof(ms_iocb_entry_t));
1675 if (rval != QLA_SUCCESS) {
1676 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001677 ql_dbg(ql_dbg_disc, vha, 0x2040,
1678 "RPA issue IOCB failed (%d).\n", rval);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001679 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, "RPA") !=
Andrew Vasquezcca53352005-08-26 19:08:30 -07001680 QLA_SUCCESS) {
1681 rval = QLA_FUNCTION_FAILED;
1682 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001683 ql_dbg(ql_dbg_disc, vha, 0x2041,
1684 "RPA exiting nornally.\n");
Andrew Vasquezcca53352005-08-26 19:08:30 -07001685 }
1686
1687 return rval;
1688}
1689
1690/**
1691 * qla2x00_fdmi_register() -
1692 * @ha: HA context
1693 *
1694 * Returns 0 on success.
1695 */
1696int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001697qla2x00_fdmi_register(scsi_qla_host_t *vha)
Andrew Vasquezcca53352005-08-26 19:08:30 -07001698{
1699 int rval;
Andrew Vasquez80de7ef2009-07-31 15:09:33 -07001700 struct qla_hw_data *ha = vha->hw;
1701
1702 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1703 return QLA_FUNCTION_FAILED;
Andrew Vasquezcca53352005-08-26 19:08:30 -07001704
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001705 rval = qla2x00_mgmt_svr_login(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001706 if (rval)
1707 return rval;
1708
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001709 rval = qla2x00_fdmi_rhba(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001710 if (rval) {
1711 if (rval != QLA_ALREADY_REGISTERED)
1712 return rval;
1713
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001714 rval = qla2x00_fdmi_dhba(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001715 if (rval)
1716 return rval;
1717
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001718 rval = qla2x00_fdmi_rhba(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001719 if (rval)
1720 return rval;
1721 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001722 rval = qla2x00_fdmi_rpa(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001723
1724 return rval;
1725}
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001726
1727/**
1728 * qla2x00_gfpn_id() - SNS Get Fabric Port Name (GFPN_ID) query.
1729 * @ha: HA context
1730 * @list: switch info entries to populate
1731 *
1732 * Returns 0 on success.
1733 */
1734int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001735qla2x00_gfpn_id(scsi_qla_host_t *vha, sw_info_t *list)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001736{
1737 int rval;
1738 uint16_t i;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001739 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001740 ms_iocb_entry_t *ms_pkt;
1741 struct ct_sns_req *ct_req;
1742 struct ct_sns_rsp *ct_rsp;
1743
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07001744 if (!IS_IIDMA_CAPABLE(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001745 return QLA_FUNCTION_FAILED;
1746
1747 for (i = 0; i < MAX_FIBRE_DEVICES; i++) {
1748 /* Issue GFPN_ID */
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001749 /* Prepare common MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001750 ms_pkt = ha->isp_ops->prep_ms_iocb(vha, GFPN_ID_REQ_SIZE,
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001751 GFPN_ID_RSP_SIZE);
1752
1753 /* Prepare CT request */
1754 ct_req = qla2x00_prep_ct_req(&ha->ct_sns->p.req, GFPN_ID_CMD,
1755 GFPN_ID_RSP_SIZE);
1756 ct_rsp = &ha->ct_sns->p.rsp;
1757
1758 /* Prepare CT arguments -- port_id */
1759 ct_req->req.port_id.port_id[0] = list[i].d_id.b.domain;
1760 ct_req->req.port_id.port_id[1] = list[i].d_id.b.area;
1761 ct_req->req.port_id.port_id[2] = list[i].d_id.b.al_pa;
1762
1763 /* Execute MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001764 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001765 sizeof(ms_iocb_entry_t));
1766 if (rval != QLA_SUCCESS) {
1767 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001768 ql_dbg(ql_dbg_disc, vha, 0x2023,
1769 "GFPN_ID issue IOCB failed (%d).\n", rval);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001770 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp,
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001771 "GFPN_ID") != QLA_SUCCESS) {
1772 rval = QLA_FUNCTION_FAILED;
1773 } else {
1774 /* Save fabric portname */
1775 memcpy(list[i].fabric_port_name,
1776 ct_rsp->rsp.gfpn_id.port_name, WWN_SIZE);
1777 }
1778
1779 /* Last device exit. */
1780 if (list[i].d_id.b.rsvd_1 != 0)
1781 break;
1782 }
1783
1784 return (rval);
1785}
1786
1787static inline void *
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001788qla24xx_prep_ms_fm_iocb(scsi_qla_host_t *vha, uint32_t req_size,
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001789 uint32_t rsp_size)
1790{
1791 struct ct_entry_24xx *ct_pkt;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001792 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001793 ct_pkt = (struct ct_entry_24xx *)ha->ms_iocb;
1794 memset(ct_pkt, 0, sizeof(struct ct_entry_24xx));
1795
1796 ct_pkt->entry_type = CT_IOCB_TYPE;
1797 ct_pkt->entry_count = 1;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001798 ct_pkt->nport_handle = cpu_to_le16(vha->mgmt_svr_loop_id);
Andrew Vasquez00a537b2008-02-28 14:06:11 -08001799 ct_pkt->timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001800 ct_pkt->cmd_dsd_count = __constant_cpu_to_le16(1);
1801 ct_pkt->rsp_dsd_count = __constant_cpu_to_le16(1);
1802 ct_pkt->rsp_byte_count = cpu_to_le32(rsp_size);
1803 ct_pkt->cmd_byte_count = cpu_to_le32(req_size);
1804
1805 ct_pkt->dseg_0_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
1806 ct_pkt->dseg_0_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
1807 ct_pkt->dseg_0_len = ct_pkt->cmd_byte_count;
1808
1809 ct_pkt->dseg_1_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
1810 ct_pkt->dseg_1_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
1811 ct_pkt->dseg_1_len = ct_pkt->rsp_byte_count;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001812 ct_pkt->vp_index = vha->vp_idx;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001813
1814 return ct_pkt;
1815}
1816
1817
1818static inline struct ct_sns_req *
1819qla24xx_prep_ct_fm_req(struct ct_sns_req *ct_req, uint16_t cmd,
1820 uint16_t rsp_size)
1821{
1822 memset(ct_req, 0, sizeof(struct ct_sns_pkt));
1823
1824 ct_req->header.revision = 0x01;
1825 ct_req->header.gs_type = 0xFA;
1826 ct_req->header.gs_subtype = 0x01;
1827 ct_req->command = cpu_to_be16(cmd);
1828 ct_req->max_rsp_size = cpu_to_be16((rsp_size - 16) / 4);
1829
1830 return ct_req;
1831}
1832
1833/**
1834 * qla2x00_gpsc() - FCS Get Port Speed Capabilities (GPSC) query.
1835 * @ha: HA context
1836 * @list: switch info entries to populate
1837 *
1838 * Returns 0 on success.
1839 */
1840int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001841qla2x00_gpsc(scsi_qla_host_t *vha, sw_info_t *list)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001842{
1843 int rval;
1844 uint16_t i;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001845 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001846 ms_iocb_entry_t *ms_pkt;
1847 struct ct_sns_req *ct_req;
1848 struct ct_sns_rsp *ct_rsp;
1849
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07001850 if (!IS_IIDMA_CAPABLE(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001851 return QLA_FUNCTION_FAILED;
Andrew Vasquez4346b142006-12-13 19:20:28 -08001852 if (!ha->flags.gpsc_supported)
1853 return QLA_FUNCTION_FAILED;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001854
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001855 rval = qla2x00_mgmt_svr_login(vha);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001856 if (rval)
1857 return rval;
1858
1859 for (i = 0; i < MAX_FIBRE_DEVICES; i++) {
1860 /* Issue GFPN_ID */
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001861 /* Prepare common MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001862 ms_pkt = qla24xx_prep_ms_fm_iocb(vha, GPSC_REQ_SIZE,
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001863 GPSC_RSP_SIZE);
1864
1865 /* Prepare CT request */
1866 ct_req = qla24xx_prep_ct_fm_req(&ha->ct_sns->p.req,
1867 GPSC_CMD, GPSC_RSP_SIZE);
1868 ct_rsp = &ha->ct_sns->p.rsp;
1869
1870 /* Prepare CT arguments -- port_name */
1871 memcpy(ct_req->req.gpsc.port_name, list[i].fabric_port_name,
1872 WWN_SIZE);
1873
1874 /* Execute MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001875 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001876 sizeof(ms_iocb_entry_t));
1877 if (rval != QLA_SUCCESS) {
1878 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001879 ql_dbg(ql_dbg_disc, vha, 0x2059,
1880 "GPSC issue IOCB failed (%d).\n", rval);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001881 } else if ((rval = qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp,
Andrew Vasquez4346b142006-12-13 19:20:28 -08001882 "GPSC")) != QLA_SUCCESS) {
1883 /* FM command unsupported? */
1884 if (rval == QLA_INVALID_COMMAND &&
Andrew Vasquez3fe7cfb2008-04-03 13:13:23 -07001885 (ct_rsp->header.reason_code ==
1886 CT_REASON_INVALID_COMMAND_CODE ||
1887 ct_rsp->header.reason_code ==
1888 CT_REASON_COMMAND_UNSUPPORTED)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001889 ql_dbg(ql_dbg_disc, vha, 0x205a,
1890 "GPSC command unsupported, disabling "
1891 "query.\n");
Andrew Vasquez4346b142006-12-13 19:20:28 -08001892 ha->flags.gpsc_supported = 0;
1893 rval = QLA_FUNCTION_FAILED;
1894 break;
1895 }
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001896 rval = QLA_FUNCTION_FAILED;
1897 } else {
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07001898 /* Save port-speed */
1899 switch (be16_to_cpu(ct_rsp->rsp.gpsc.speed)) {
1900 case BIT_15:
1901 list[i].fp_speed = PORT_SPEED_1GB;
1902 break;
1903 case BIT_14:
1904 list[i].fp_speed = PORT_SPEED_2GB;
1905 break;
1906 case BIT_13:
1907 list[i].fp_speed = PORT_SPEED_4GB;
1908 break;
Andrew Vasquez9f8fdde2009-06-03 09:55:22 -07001909 case BIT_12:
1910 list[i].fp_speed = PORT_SPEED_10GB;
1911 break;
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07001912 case BIT_11:
1913 list[i].fp_speed = PORT_SPEED_8GB;
1914 break;
1915 }
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001916
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001917 ql_dbg(ql_dbg_disc, vha, 0x205b,
1918 "GPSC ext entry - fpn "
1919 "%02x%02x%02x%02x%02x%02x%02x%02x speeds=%04x "
1920 "speed=%04x.\n",
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001921 list[i].fabric_port_name[0],
1922 list[i].fabric_port_name[1],
1923 list[i].fabric_port_name[2],
1924 list[i].fabric_port_name[3],
1925 list[i].fabric_port_name[4],
1926 list[i].fabric_port_name[5],
1927 list[i].fabric_port_name[6],
1928 list[i].fabric_port_name[7],
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07001929 be16_to_cpu(ct_rsp->rsp.gpsc.speeds),
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001930 be16_to_cpu(ct_rsp->rsp.gpsc.speed));
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001931 }
1932
1933 /* Last device exit. */
1934 if (list[i].d_id.b.rsvd_1 != 0)
1935 break;
1936 }
1937
1938 return (rval);
1939}
Chad Dupuise8c72ba2010-07-23 15:28:25 +05001940
1941/**
1942 * qla2x00_gff_id() - SNS Get FC-4 Features (GFF_ID) query.
1943 *
1944 * @ha: HA context
1945 * @list: switch info entries to populate
1946 *
1947 */
1948void
1949qla2x00_gff_id(scsi_qla_host_t *vha, sw_info_t *list)
1950{
1951 int rval;
1952 uint16_t i;
1953
1954 ms_iocb_entry_t *ms_pkt;
1955 struct ct_sns_req *ct_req;
1956 struct ct_sns_rsp *ct_rsp;
1957 struct qla_hw_data *ha = vha->hw;
1958 uint8_t fcp_scsi_features = 0;
1959
1960 for (i = 0; i < MAX_FIBRE_DEVICES; i++) {
1961 /* Set default FC4 Type as UNKNOWN so the default is to
1962 * Process this port */
1963 list[i].fc4_type = FC4_TYPE_UNKNOWN;
1964
1965 /* Do not attempt GFF_ID if we are not FWI_2 capable */
1966 if (!IS_FWI2_CAPABLE(ha))
1967 continue;
1968
1969 /* Prepare common MS IOCB */
1970 ms_pkt = ha->isp_ops->prep_ms_iocb(vha, GFF_ID_REQ_SIZE,
1971 GFF_ID_RSP_SIZE);
1972
1973 /* Prepare CT request */
1974 ct_req = qla2x00_prep_ct_req(&ha->ct_sns->p.req, GFF_ID_CMD,
1975 GFF_ID_RSP_SIZE);
1976 ct_rsp = &ha->ct_sns->p.rsp;
1977
1978 /* Prepare CT arguments -- port_id */
1979 ct_req->req.port_id.port_id[0] = list[i].d_id.b.domain;
1980 ct_req->req.port_id.port_id[1] = list[i].d_id.b.area;
1981 ct_req->req.port_id.port_id[2] = list[i].d_id.b.al_pa;
1982
1983 /* Execute MS IOCB */
1984 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
1985 sizeof(ms_iocb_entry_t));
1986
1987 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001988 ql_dbg(ql_dbg_disc, vha, 0x205c,
1989 "GFF_ID issue IOCB failed (%d).\n", rval);
Chad Dupuise8c72ba2010-07-23 15:28:25 +05001990 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp,
Andrew Vasquez7a78ced2011-02-23 15:27:12 -08001991 "GFF_ID") != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001992 ql_dbg(ql_dbg_disc, vha, 0x205d,
1993 "GFF_ID IOCB status had a failure status code.\n");
Chad Dupuise8c72ba2010-07-23 15:28:25 +05001994 } else {
1995 fcp_scsi_features =
1996 ct_rsp->rsp.gff_id.fc4_features[GFF_FCP_SCSI_OFFSET];
1997 fcp_scsi_features &= 0x0f;
1998
1999 if (fcp_scsi_features)
2000 list[i].fc4_type = FC4_TYPE_FCP_SCSI;
2001 else
2002 list[i].fc4_type = FC4_TYPE_OTHER;
2003 }
2004
2005 /* Last device exit. */
2006 if (list[i].d_id.b.rsvd_1 != 0)
2007 break;
2008 }
2009}