blob: 8cd9066ad90663e676a2a97d878cb644aeb0c47e [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) {
Giridhar Malavalicf2d7712011-02-23 15:27:09 -0800124 DEBUG2_3(printk(KERN_WARNING "scsi(%ld): %s failed, error status "
125 "(%x) on port_id: %02x%02x%02x.\n",
126 vha->host_no, routine, ms_pkt->entry_status,
127 vha->d_id.b.domain, vha->d_id.b.area,
128 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)) {
141 DEBUG2_3(printk("scsi(%ld): %s failed, "
Giridhar Malavalicf2d7712011-02-23 15:27:09 -0800142 "rejected request on port_id: %02x%02x%02x\n",
143 vha->host_no, routine,
144 vha->d_id.b.domain, vha->d_id.b.area,
145 vha->d_id.b.al_pa));
Andrew Vasquez8c958a92005-07-06 10:30:47 -0700146 DEBUG2_3(qla2x00_dump_buffer(
147 (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:
154 DEBUG2_3(printk("scsi(%ld): %s failed, completion "
Giridhar Malavalicf2d7712011-02-23 15:27:09 -0800155 "status (%x) on port_id: %02x%02x%02x.\n",
156 vha->host_no, routine, comp_status,
157 vha->d_id.b.domain, vha->d_id.b.area,
158 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 */
191 ct_req = qla2x00_prep_ct_req(&ha->ct_sns->p.req, GA_NXT_CMD,
192 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*/
205 DEBUG2_3(printk("scsi(%ld): GA_NXT issue IOCB failed (%d).\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800206 vha->host_no, rval));
207 } 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
221 if (ct_rsp->rsp.ga_nxt.port_type != NS_N_PORT_TYPE &&
222 ct_rsp->rsp.ga_nxt.port_type != NS_NL_PORT_TYPE)
223 fcport->d_id.b.domain = 0xf0;
224
225 DEBUG2_3(printk("scsi(%ld): GA_NXT entry - "
226 "nn %02x%02x%02x%02x%02x%02x%02x%02x "
227 "pn %02x%02x%02x%02x%02x%02x%02x%02x "
228 "portid=%02x%02x%02x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800229 vha->host_no,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 fcport->node_name[0], fcport->node_name[1],
231 fcport->node_name[2], fcport->node_name[3],
232 fcport->node_name[4], fcport->node_name[5],
233 fcport->node_name[6], fcport->node_name[7],
234 fcport->port_name[0], fcport->port_name[1],
235 fcport->port_name[2], fcport->port_name[3],
236 fcport->port_name[4], fcport->port_name[5],
237 fcport->port_name[6], fcport->port_name[7],
238 fcport->d_id.b.domain, fcport->d_id.b.area,
239 fcport->d_id.b.al_pa));
240 }
241
242 return (rval);
243}
244
245/**
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;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800267 if (IS_QLA2100(ha) || IS_QLA2200(ha))
268 return qla2x00_sns_gid_pt(vha, list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269
270 gid_data = NULL;
271
272 /* Issue GID_PT */
273 /* Prepare common MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800274 ms_pkt = ha->isp_ops->prep_ms_iocb(vha, GID_PT_REQ_SIZE,
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700275 GID_PT_RSP_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276
277 /* Prepare CT request */
278 ct_req = qla2x00_prep_ct_req(&ha->ct_sns->p.req, GID_PT_CMD,
279 GID_PT_RSP_SIZE);
280 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*/
290 DEBUG2_3(printk("scsi(%ld): GID_PT issue IOCB failed (%d).\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800291 vha->host_no, rval));
292 } 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. */
297 for (i = 0; i < MAX_FIBRE_DEVICES; i++) {
298 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 */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700318 if (i == 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{
335 int rval;
336 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
346 for (i = 0; i < MAX_FIBRE_DEVICES; i++) {
347 /* 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 */
353 ct_req = qla2x00_prep_ct_req(&ha->ct_sns->p.req, GPN_ID_CMD,
354 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*/
367 DEBUG2_3(printk("scsi(%ld): GPN_ID issue IOCB failed "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800368 "(%d).\n", vha->host_no, rval));
369 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp,
Andrew Vasquez8c958a92005-07-06 10:30:47 -0700370 "GPN_ID") != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 rval = QLA_FUNCTION_FAILED;
372 } else {
373 /* Save portname */
374 memcpy(list[i].port_name,
375 ct_rsp->rsp.gpn_id.port_name, WWN_SIZE);
376 }
377
378 /* Last device exit. */
379 if (list[i].d_id.b.rsvd_1 != 0)
380 break;
381 }
382
383 return (rval);
384}
385
386/**
387 * qla2x00_gnn_id() - SNS Get Node Name (GNN_ID) query.
388 * @ha: HA context
389 * @list: switch info entries to populate
390 *
391 * Returns 0 on success.
392 */
393int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800394qla2x00_gnn_id(scsi_qla_host_t *vha, sw_info_t *list)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395{
396 int rval;
397 uint16_t i;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800398 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 ms_iocb_entry_t *ms_pkt;
400 struct ct_sns_req *ct_req;
401 struct ct_sns_rsp *ct_rsp;
402
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800403 if (IS_QLA2100(ha) || IS_QLA2200(ha))
404 return qla2x00_sns_gnn_id(vha, list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405
406 for (i = 0; i < MAX_FIBRE_DEVICES; i++) {
407 /* Issue GNN_ID */
408 /* Prepare common MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800409 ms_pkt = ha->isp_ops->prep_ms_iocb(vha, GNN_ID_REQ_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 GNN_ID_RSP_SIZE);
411
412 /* Prepare CT request */
413 ct_req = qla2x00_prep_ct_req(&ha->ct_sns->p.req, GNN_ID_CMD,
414 GNN_ID_RSP_SIZE);
415 ct_rsp = &ha->ct_sns->p.rsp;
416
417 /* Prepare CT arguments -- port_id */
418 ct_req->req.port_id.port_id[0] = list[i].d_id.b.domain;
419 ct_req->req.port_id.port_id[1] = list[i].d_id.b.area;
420 ct_req->req.port_id.port_id[2] = list[i].d_id.b.al_pa;
421
422 /* Execute MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800423 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 sizeof(ms_iocb_entry_t));
425 if (rval != QLA_SUCCESS) {
426 /*EMPTY*/
427 DEBUG2_3(printk("scsi(%ld): GNN_ID issue IOCB failed "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800428 "(%d).\n", vha->host_no, rval));
429 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp,
Andrew Vasquez8c958a92005-07-06 10:30:47 -0700430 "GNN_ID") != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 rval = QLA_FUNCTION_FAILED;
432 } else {
433 /* Save nodename */
434 memcpy(list[i].node_name,
435 ct_rsp->rsp.gnn_id.node_name, WWN_SIZE);
436
437 DEBUG2_3(printk("scsi(%ld): GID_PT entry - "
438 "nn %02x%02x%02x%02x%02x%02x%02x%02x "
439 "pn %02x%02x%02x%02x%02x%02x%02x%02x "
440 "portid=%02x%02x%02x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800441 vha->host_no,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 list[i].node_name[0], list[i].node_name[1],
443 list[i].node_name[2], list[i].node_name[3],
444 list[i].node_name[4], list[i].node_name[5],
445 list[i].node_name[6], list[i].node_name[7],
446 list[i].port_name[0], list[i].port_name[1],
447 list[i].port_name[2], list[i].port_name[3],
448 list[i].port_name[4], list[i].port_name[5],
449 list[i].port_name[6], list[i].port_name[7],
450 list[i].d_id.b.domain, list[i].d_id.b.area,
451 list[i].d_id.b.al_pa));
452 }
453
454 /* Last device exit. */
455 if (list[i].d_id.b.rsvd_1 != 0)
456 break;
457 }
458
459 return (rval);
460}
461
462/**
463 * qla2x00_rft_id() - SNS Register FC-4 TYPEs (RFT_ID) supported by the HBA.
464 * @ha: HA context
465 *
466 * Returns 0 on success.
467 */
468int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800469qla2x00_rft_id(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470{
471 int rval;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800472 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 ms_iocb_entry_t *ms_pkt;
474 struct ct_sns_req *ct_req;
475 struct ct_sns_rsp *ct_rsp;
476
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800477 if (IS_QLA2100(ha) || IS_QLA2200(ha))
478 return qla2x00_sns_rft_id(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479
480 /* Issue RFT_ID */
481 /* Prepare common MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800482 ms_pkt = ha->isp_ops->prep_ms_iocb(vha, RFT_ID_REQ_SIZE,
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700483 RFT_ID_RSP_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484
485 /* Prepare CT request */
486 ct_req = qla2x00_prep_ct_req(&ha->ct_sns->p.req, RFT_ID_CMD,
487 RFT_ID_RSP_SIZE);
488 ct_rsp = &ha->ct_sns->p.rsp;
489
490 /* Prepare CT arguments -- port_id, FC-4 types */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800491 ct_req->req.rft_id.port_id[0] = vha->d_id.b.domain;
492 ct_req->req.rft_id.port_id[1] = vha->d_id.b.area;
493 ct_req->req.rft_id.port_id[2] = vha->d_id.b.al_pa;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494
495 ct_req->req.rft_id.fc4_types[2] = 0x01; /* FCP-3 */
496
497 /* Execute MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800498 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 sizeof(ms_iocb_entry_t));
500 if (rval != QLA_SUCCESS) {
501 /*EMPTY*/
502 DEBUG2_3(printk("scsi(%ld): RFT_ID issue IOCB failed (%d).\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800503 vha->host_no, rval));
504 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, "RFT_ID") !=
Andrew Vasquez8c958a92005-07-06 10:30:47 -0700505 QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 rval = QLA_FUNCTION_FAILED;
507 } else {
508 DEBUG2(printk("scsi(%ld): RFT_ID exiting normally.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800509 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 }
511
512 return (rval);
513}
514
515/**
516 * qla2x00_rff_id() - SNS Register FC-4 Features (RFF_ID) supported by the HBA.
517 * @ha: HA context
518 *
519 * Returns 0 on success.
520 */
521int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800522qla2x00_rff_id(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523{
524 int rval;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800525 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 ms_iocb_entry_t *ms_pkt;
527 struct ct_sns_req *ct_req;
528 struct ct_sns_rsp *ct_rsp;
529
530 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
531 DEBUG2(printk("scsi(%ld): RFF_ID call unsupported on "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800532 "ISP2100/ISP2200.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 return (QLA_SUCCESS);
534 }
535
536 /* Issue RFF_ID */
537 /* Prepare common MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800538 ms_pkt = ha->isp_ops->prep_ms_iocb(vha, RFF_ID_REQ_SIZE,
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700539 RFF_ID_RSP_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540
541 /* Prepare CT request */
542 ct_req = qla2x00_prep_ct_req(&ha->ct_sns->p.req, RFF_ID_CMD,
543 RFF_ID_RSP_SIZE);
544 ct_rsp = &ha->ct_sns->p.rsp;
545
546 /* Prepare CT arguments -- port_id, FC-4 feature, FC-4 type */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800547 ct_req->req.rff_id.port_id[0] = vha->d_id.b.domain;
548 ct_req->req.rff_id.port_id[1] = vha->d_id.b.area;
549 ct_req->req.rff_id.port_id[2] = vha->d_id.b.al_pa;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550
andrew.vasquez@qlogic.com94036882006-01-13 17:04:54 -0800551 ct_req->req.rff_id.fc4_feature = BIT_1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 ct_req->req.rff_id.fc4_type = 0x08; /* SCSI - FCP */
553
554 /* Execute MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800555 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 sizeof(ms_iocb_entry_t));
557 if (rval != QLA_SUCCESS) {
558 /*EMPTY*/
559 DEBUG2_3(printk("scsi(%ld): RFF_ID issue IOCB failed (%d).\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800560 vha->host_no, rval));
561 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, "RFF_ID") !=
Andrew Vasquez8c958a92005-07-06 10:30:47 -0700562 QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 rval = QLA_FUNCTION_FAILED;
564 } else {
565 DEBUG2(printk("scsi(%ld): RFF_ID exiting normally.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800566 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 }
568
569 return (rval);
570}
571
572/**
573 * qla2x00_rnn_id() - SNS Register Node Name (RNN_ID) of the HBA.
574 * @ha: HA context
575 *
576 * Returns 0 on success.
577 */
578int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800579qla2x00_rnn_id(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580{
581 int rval;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800582 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 ms_iocb_entry_t *ms_pkt;
584 struct ct_sns_req *ct_req;
585 struct ct_sns_rsp *ct_rsp;
586
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800587 if (IS_QLA2100(ha) || IS_QLA2200(ha))
588 return qla2x00_sns_rnn_id(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589
590 /* Issue RNN_ID */
591 /* Prepare common MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800592 ms_pkt = ha->isp_ops->prep_ms_iocb(vha, RNN_ID_REQ_SIZE,
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700593 RNN_ID_RSP_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594
595 /* Prepare CT request */
596 ct_req = qla2x00_prep_ct_req(&ha->ct_sns->p.req, RNN_ID_CMD,
597 RNN_ID_RSP_SIZE);
598 ct_rsp = &ha->ct_sns->p.rsp;
599
600 /* Prepare CT arguments -- port_id, node_name */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800601 ct_req->req.rnn_id.port_id[0] = vha->d_id.b.domain;
602 ct_req->req.rnn_id.port_id[1] = vha->d_id.b.area;
603 ct_req->req.rnn_id.port_id[2] = vha->d_id.b.al_pa;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800605 memcpy(ct_req->req.rnn_id.node_name, vha->node_name, WWN_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606
607 /* Execute MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800608 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 sizeof(ms_iocb_entry_t));
610 if (rval != QLA_SUCCESS) {
611 /*EMPTY*/
612 DEBUG2_3(printk("scsi(%ld): RNN_ID issue IOCB failed (%d).\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800613 vha->host_no, rval));
614 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, "RNN_ID") !=
Andrew Vasquez8c958a92005-07-06 10:30:47 -0700615 QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 rval = QLA_FUNCTION_FAILED;
617 } else {
618 DEBUG2(printk("scsi(%ld): RNN_ID exiting normally.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800619 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 }
621
622 return (rval);
623}
624
Andrew Vasquez1620f7c2006-10-02 12:00:44 -0700625void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800626qla2x00_get_sym_node_name(scsi_qla_host_t *vha, uint8_t *snn)
Andrew Vasquez1620f7c2006-10-02 12:00:44 -0700627{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800628 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez1620f7c2006-10-02 12:00:44 -0700629 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);
632}
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)) {
650 DEBUG2(printk("scsi(%ld): RSNN_ID call unsupported on "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800651 "ISP2100/ISP2200.\n", vha->host_no));
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 */
661 ct_req = qla2x00_prep_ct_req(&ha->ct_sns->p.req, RSNN_NN_CMD,
662 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*/
685 DEBUG2_3(printk("scsi(%ld): RSNN_NN issue IOCB failed (%d).\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800686 vha->host_no, rval));
687 } 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 {
691 DEBUG2(printk("scsi(%ld): RSNN_NN exiting normally.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800692 vha->host_no));
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{
741 int rval;
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*/
760 DEBUG2_3(printk("scsi(%ld): GA_NXT Send SNS failed (%d).\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800761 vha->host_no, 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) {
764 DEBUG2_3(printk("scsi(%ld): GA_NXT failed, rejected request, "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800765 "ga_nxt_rsp:\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766 DEBUG2_3(qla2x00_dump_buffer(sns_cmd->p.gan_data, 16));
767 rval = QLA_FUNCTION_FAILED;
768 } else {
769 /* Populate fc_port_t entry. */
770 fcport->d_id.b.domain = sns_cmd->p.gan_data[17];
771 fcport->d_id.b.area = sns_cmd->p.gan_data[18];
772 fcport->d_id.b.al_pa = sns_cmd->p.gan_data[19];
773
774 memcpy(fcport->node_name, &sns_cmd->p.gan_data[284], WWN_SIZE);
775 memcpy(fcport->port_name, &sns_cmd->p.gan_data[20], WWN_SIZE);
776
777 if (sns_cmd->p.gan_data[16] != NS_N_PORT_TYPE &&
778 sns_cmd->p.gan_data[16] != NS_NL_PORT_TYPE)
779 fcport->d_id.b.domain = 0xf0;
780
781 DEBUG2_3(printk("scsi(%ld): GA_NXT entry - "
782 "nn %02x%02x%02x%02x%02x%02x%02x%02x "
783 "pn %02x%02x%02x%02x%02x%02x%02x%02x "
784 "portid=%02x%02x%02x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800785 vha->host_no,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 fcport->node_name[0], fcport->node_name[1],
787 fcport->node_name[2], fcport->node_name[3],
788 fcport->node_name[4], fcport->node_name[5],
789 fcport->node_name[6], fcport->node_name[7],
790 fcport->port_name[0], fcport->port_name[1],
791 fcport->port_name[2], fcport->port_name[3],
792 fcport->port_name[4], fcport->port_name[5],
793 fcport->port_name[6], fcport->port_name[7],
794 fcport->d_id.b.domain, fcport->d_id.b.area,
795 fcport->d_id.b.al_pa));
796 }
797
798 return (rval);
799}
800
801/**
802 * qla2x00_sns_gid_pt() - SNS scan for fabric devices via GID_PT command.
803 * @ha: HA context
804 * @list: switch info entries to populate
805 *
806 * This command uses the old Exectute SNS Command mailbox routine.
807 *
808 * NOTE: Non-Nx_Ports are not requested.
809 *
810 * Returns 0 on success.
811 */
812static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800813qla2x00_sns_gid_pt(scsi_qla_host_t *vha, sw_info_t *list)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814{
815 int rval;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800816 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817 uint16_t i;
818 uint8_t *entry;
819 struct sns_cmd_pkt *sns_cmd;
820
821 /* Issue GID_PT. */
822 /* Prepare SNS command request. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800823 sns_cmd = qla2x00_prep_sns_cmd(vha, GID_PT_CMD, GID_PT_SNS_SCMD_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 GID_PT_SNS_DATA_SIZE);
825
826 /* Prepare SNS command arguments -- port_type. */
827 sns_cmd->p.cmd.param[0] = NS_NX_PORT_TYPE;
828
829 /* Execute SNS command. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800830 rval = qla2x00_send_sns(vha, ha->sns_cmd_dma, GID_PT_SNS_CMD_SIZE / 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831 sizeof(struct sns_cmd_pkt));
832 if (rval != QLA_SUCCESS) {
833 /*EMPTY*/
834 DEBUG2_3(printk("scsi(%ld): GID_PT Send SNS failed (%d).\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800835 vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836 } else if (sns_cmd->p.gid_data[8] != 0x80 ||
837 sns_cmd->p.gid_data[9] != 0x02) {
838 DEBUG2_3(printk("scsi(%ld): GID_PT failed, rejected request, "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800839 "gid_rsp:\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840 DEBUG2_3(qla2x00_dump_buffer(sns_cmd->p.gid_data, 16));
841 rval = QLA_FUNCTION_FAILED;
842 } else {
843 /* Set port IDs in switch info list. */
844 for (i = 0; i < MAX_FIBRE_DEVICES; i++) {
845 entry = &sns_cmd->p.gid_data[(i * 4) + 16];
846 list[i].d_id.b.domain = entry[1];
847 list[i].d_id.b.area = entry[2];
848 list[i].d_id.b.al_pa = entry[3];
849
850 /* Last one exit. */
851 if (entry[0] & BIT_7) {
852 list[i].d_id.b.rsvd_1 = entry[0];
853 break;
854 }
855 }
856
857 /*
858 * If we've used all available slots, then the switch is
859 * reporting back more devices that we can handle with this
860 * single call. Return a failed status, and let GA_NXT handle
861 * the overload.
862 */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700863 if (i == MAX_FIBRE_DEVICES)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 rval = QLA_FUNCTION_FAILED;
865 }
866
867 return (rval);
868}
869
870/**
871 * qla2x00_sns_gpn_id() - SNS Get Port Name (GPN_ID) query.
872 * @ha: HA context
873 * @list: switch info entries to populate
874 *
875 * This command uses the old Exectute SNS Command mailbox routine.
876 *
877 * Returns 0 on success.
878 */
879static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800880qla2x00_sns_gpn_id(scsi_qla_host_t *vha, sw_info_t *list)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881{
882 int rval;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800883 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884 uint16_t i;
885 struct sns_cmd_pkt *sns_cmd;
886
887 for (i = 0; i < MAX_FIBRE_DEVICES; i++) {
888 /* Issue GPN_ID */
889 /* Prepare SNS command request. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800890 sns_cmd = qla2x00_prep_sns_cmd(vha, GPN_ID_CMD,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891 GPN_ID_SNS_SCMD_LEN, GPN_ID_SNS_DATA_SIZE);
892
893 /* Prepare SNS command arguments -- port_id. */
894 sns_cmd->p.cmd.param[0] = list[i].d_id.b.al_pa;
895 sns_cmd->p.cmd.param[1] = list[i].d_id.b.area;
896 sns_cmd->p.cmd.param[2] = list[i].d_id.b.domain;
897
898 /* Execute SNS command. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800899 rval = qla2x00_send_sns(vha, ha->sns_cmd_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900 GPN_ID_SNS_CMD_SIZE / 2, sizeof(struct sns_cmd_pkt));
901 if (rval != QLA_SUCCESS) {
902 /*EMPTY*/
903 DEBUG2_3(printk("scsi(%ld): GPN_ID Send SNS failed "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800904 "(%d).\n", vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905 } else if (sns_cmd->p.gpn_data[8] != 0x80 ||
906 sns_cmd->p.gpn_data[9] != 0x02) {
907 DEBUG2_3(printk("scsi(%ld): GPN_ID failed, rejected "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800908 "request, gpn_rsp:\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909 DEBUG2_3(qla2x00_dump_buffer(sns_cmd->p.gpn_data, 16));
910 rval = QLA_FUNCTION_FAILED;
911 } else {
912 /* Save portname */
913 memcpy(list[i].port_name, &sns_cmd->p.gpn_data[16],
914 WWN_SIZE);
915 }
916
917 /* Last device exit. */
918 if (list[i].d_id.b.rsvd_1 != 0)
919 break;
920 }
921
922 return (rval);
923}
924
925/**
926 * qla2x00_sns_gnn_id() - SNS Get Node Name (GNN_ID) query.
927 * @ha: HA context
928 * @list: switch info entries to populate
929 *
930 * This command uses the old Exectute SNS Command mailbox routine.
931 *
932 * Returns 0 on success.
933 */
934static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800935qla2x00_sns_gnn_id(scsi_qla_host_t *vha, sw_info_t *list)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936{
937 int rval;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800938 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939 uint16_t i;
940 struct sns_cmd_pkt *sns_cmd;
941
942 for (i = 0; i < MAX_FIBRE_DEVICES; i++) {
943 /* Issue GNN_ID */
944 /* Prepare SNS command request. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800945 sns_cmd = qla2x00_prep_sns_cmd(vha, GNN_ID_CMD,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946 GNN_ID_SNS_SCMD_LEN, GNN_ID_SNS_DATA_SIZE);
947
948 /* Prepare SNS command arguments -- port_id. */
949 sns_cmd->p.cmd.param[0] = list[i].d_id.b.al_pa;
950 sns_cmd->p.cmd.param[1] = list[i].d_id.b.area;
951 sns_cmd->p.cmd.param[2] = list[i].d_id.b.domain;
952
953 /* Execute SNS command. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800954 rval = qla2x00_send_sns(vha, ha->sns_cmd_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955 GNN_ID_SNS_CMD_SIZE / 2, sizeof(struct sns_cmd_pkt));
956 if (rval != QLA_SUCCESS) {
957 /*EMPTY*/
958 DEBUG2_3(printk("scsi(%ld): GNN_ID Send SNS failed "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800959 "(%d).\n", vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960 } else if (sns_cmd->p.gnn_data[8] != 0x80 ||
961 sns_cmd->p.gnn_data[9] != 0x02) {
962 DEBUG2_3(printk("scsi(%ld): GNN_ID failed, rejected "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800963 "request, gnn_rsp:\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964 DEBUG2_3(qla2x00_dump_buffer(sns_cmd->p.gnn_data, 16));
965 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
971 DEBUG2_3(printk("scsi(%ld): GID_PT entry - "
972 "nn %02x%02x%02x%02x%02x%02x%02x%02x "
973 "pn %02x%02x%02x%02x%02x%02x%02x%02x "
974 "portid=%02x%02x%02x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800975 vha->host_no,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976 list[i].node_name[0], list[i].node_name[1],
977 list[i].node_name[2], list[i].node_name[3],
978 list[i].node_name[4], list[i].node_name[5],
979 list[i].node_name[6], list[i].node_name[7],
980 list[i].port_name[0], list[i].port_name[1],
981 list[i].port_name[2], list[i].port_name[3],
982 list[i].port_name[4], list[i].port_name[5],
983 list[i].port_name[6], list[i].port_name[7],
984 list[i].d_id.b.domain, list[i].d_id.b.area,
985 list[i].d_id.b.al_pa));
986 }
987
988 /* Last device exit. */
989 if (list[i].d_id.b.rsvd_1 != 0)
990 break;
991 }
992
993 return (rval);
994}
995
996/**
997 * qla2x00_snd_rft_id() - SNS Register FC-4 TYPEs (RFT_ID) supported by the HBA.
998 * @ha: HA context
999 *
1000 * This command uses the old Exectute SNS Command mailbox routine.
1001 *
1002 * Returns 0 on success.
1003 */
1004static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001005qla2x00_sns_rft_id(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006{
1007 int rval;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001008 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009 struct sns_cmd_pkt *sns_cmd;
1010
1011 /* Issue RFT_ID. */
1012 /* Prepare SNS command request. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001013 sns_cmd = qla2x00_prep_sns_cmd(vha, RFT_ID_CMD, RFT_ID_SNS_SCMD_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014 RFT_ID_SNS_DATA_SIZE);
1015
1016 /* Prepare SNS command arguments -- port_id, FC-4 types */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001017 sns_cmd->p.cmd.param[0] = vha->d_id.b.al_pa;
1018 sns_cmd->p.cmd.param[1] = vha->d_id.b.area;
1019 sns_cmd->p.cmd.param[2] = vha->d_id.b.domain;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020
1021 sns_cmd->p.cmd.param[5] = 0x01; /* FCP-3 */
1022
1023 /* Execute SNS command. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001024 rval = qla2x00_send_sns(vha, ha->sns_cmd_dma, RFT_ID_SNS_CMD_SIZE / 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025 sizeof(struct sns_cmd_pkt));
1026 if (rval != QLA_SUCCESS) {
1027 /*EMPTY*/
1028 DEBUG2_3(printk("scsi(%ld): RFT_ID Send SNS failed (%d).\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001029 vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 } else if (sns_cmd->p.rft_data[8] != 0x80 ||
1031 sns_cmd->p.rft_data[9] != 0x02) {
1032 DEBUG2_3(printk("scsi(%ld): RFT_ID failed, rejected request, "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001033 "rft_rsp:\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034 DEBUG2_3(qla2x00_dump_buffer(sns_cmd->p.rft_data, 16));
1035 rval = QLA_FUNCTION_FAILED;
1036 } else {
1037 DEBUG2(printk("scsi(%ld): RFT_ID exiting normally.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001038 vha->host_no));
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*/
1084 DEBUG2_3(printk("scsi(%ld): RNN_ID Send SNS failed (%d).\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001085 vha->host_no, 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) {
1088 DEBUG2_3(printk("scsi(%ld): RNN_ID failed, rejected request, "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001089 "rnn_rsp:\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090 DEBUG2_3(qla2x00_dump_buffer(sns_cmd->p.rnn_data, 16));
1091 rval = QLA_FUNCTION_FAILED;
1092 } else {
1093 DEBUG2(printk("scsi(%ld): RNN_ID exiting normally.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001094 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095 }
1096
1097 return (rval);
1098}
Andrew Vasquezcca53352005-08-26 19:08:30 -07001099
1100/**
Joe Perchesb1c11812008-02-03 17:28:22 +02001101 * qla2x00_mgmt_svr_login() - Login to fabric Management Service.
Andrew Vasquezcca53352005-08-26 19:08:30 -07001102 * @ha: HA context
1103 *
1104 * Returns 0 on success.
1105 */
1106static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001107qla2x00_mgmt_svr_login(scsi_qla_host_t *vha)
Andrew Vasquezcca53352005-08-26 19:08:30 -07001108{
1109 int ret;
1110 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001111 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezcca53352005-08-26 19:08:30 -07001112 ret = QLA_SUCCESS;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001113 if (vha->flags.management_server_logged_in)
Andrew Vasquezcca53352005-08-26 19:08:30 -07001114 return ret;
1115
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001116 ha->isp_ops->fabric_login(vha, vha->mgmt_svr_loop_id, 0xff, 0xff, 0xfa,
Joe Carnuccioe1f91602009-04-06 22:33:46 -07001117 mb, BIT_1|BIT_0);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001118 if (mb[0] != MBS_COMMAND_COMPLETE) {
1119 DEBUG2_13(printk("%s(%ld): Failed MANAGEMENT_SERVER login: "
1120 "loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[6]=%x mb[7]=%x\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001121 __func__, vha->host_no, vha->mgmt_svr_loop_id, mb[0], mb[1],
Andrew Vasquezcca53352005-08-26 19:08:30 -07001122 mb[2], mb[6], mb[7]));
1123 ret = QLA_FUNCTION_FAILED;
1124 } else
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001125 vha->flags.management_server_logged_in = 1;
Andrew Vasquezcca53352005-08-26 19:08:30 -07001126
1127 return ret;
1128}
1129
1130/**
1131 * qla2x00_prep_ms_fdmi_iocb() - Prepare common MS IOCB fields for FDMI query.
1132 * @ha: HA context
1133 * @req_size: request size in bytes
1134 * @rsp_size: response size in bytes
1135 *
1136 * Returns a pointer to the @ha's ms_iocb.
1137 */
1138void *
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001139qla2x00_prep_ms_fdmi_iocb(scsi_qla_host_t *vha, uint32_t req_size,
Andrew Vasquezcca53352005-08-26 19:08:30 -07001140 uint32_t rsp_size)
1141{
1142 ms_iocb_entry_t *ms_pkt;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001143 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezcca53352005-08-26 19:08:30 -07001144 ms_pkt = ha->ms_iocb;
1145 memset(ms_pkt, 0, sizeof(ms_iocb_entry_t));
1146
1147 ms_pkt->entry_type = MS_IOCB_TYPE;
1148 ms_pkt->entry_count = 1;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001149 SET_TARGET_ID(ha, ms_pkt->loop_id, vha->mgmt_svr_loop_id);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001150 ms_pkt->control_flags = __constant_cpu_to_le16(CF_READ | CF_HEAD_TAG);
Andrew Vasquez00a537b2008-02-28 14:06:11 -08001151 ms_pkt->timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001152 ms_pkt->cmd_dsd_count = __constant_cpu_to_le16(1);
1153 ms_pkt->total_dsd_count = __constant_cpu_to_le16(2);
1154 ms_pkt->rsp_bytecount = cpu_to_le32(rsp_size);
1155 ms_pkt->req_bytecount = cpu_to_le32(req_size);
1156
1157 ms_pkt->dseg_req_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
1158 ms_pkt->dseg_req_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
1159 ms_pkt->dseg_req_length = ms_pkt->req_bytecount;
1160
1161 ms_pkt->dseg_rsp_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
1162 ms_pkt->dseg_rsp_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
1163 ms_pkt->dseg_rsp_length = ms_pkt->rsp_bytecount;
1164
1165 return ms_pkt;
1166}
1167
1168/**
1169 * qla24xx_prep_ms_fdmi_iocb() - Prepare common MS IOCB fields for FDMI query.
1170 * @ha: HA context
1171 * @req_size: request size in bytes
1172 * @rsp_size: response size in bytes
1173 *
1174 * Returns a pointer to the @ha's ms_iocb.
1175 */
1176void *
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001177qla24xx_prep_ms_fdmi_iocb(scsi_qla_host_t *vha, uint32_t req_size,
Andrew Vasquezcca53352005-08-26 19:08:30 -07001178 uint32_t rsp_size)
1179{
1180 struct ct_entry_24xx *ct_pkt;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001181 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezcca53352005-08-26 19:08:30 -07001182
1183 ct_pkt = (struct ct_entry_24xx *)ha->ms_iocb;
1184 memset(ct_pkt, 0, sizeof(struct ct_entry_24xx));
1185
1186 ct_pkt->entry_type = CT_IOCB_TYPE;
1187 ct_pkt->entry_count = 1;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001188 ct_pkt->nport_handle = cpu_to_le16(vha->mgmt_svr_loop_id);
Andrew Vasquez00a537b2008-02-28 14:06:11 -08001189 ct_pkt->timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001190 ct_pkt->cmd_dsd_count = __constant_cpu_to_le16(1);
1191 ct_pkt->rsp_dsd_count = __constant_cpu_to_le16(1);
1192 ct_pkt->rsp_byte_count = cpu_to_le32(rsp_size);
1193 ct_pkt->cmd_byte_count = cpu_to_le32(req_size);
1194
1195 ct_pkt->dseg_0_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
1196 ct_pkt->dseg_0_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
1197 ct_pkt->dseg_0_len = ct_pkt->cmd_byte_count;
1198
1199 ct_pkt->dseg_1_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
1200 ct_pkt->dseg_1_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
1201 ct_pkt->dseg_1_len = ct_pkt->rsp_byte_count;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001202 ct_pkt->vp_index = vha->vp_idx;
Andrew Vasquezcca53352005-08-26 19:08:30 -07001203
1204 return ct_pkt;
1205}
1206
1207static inline ms_iocb_entry_t *
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001208qla2x00_update_ms_fdmi_iocb(scsi_qla_host_t *vha, uint32_t req_size)
Andrew Vasquezcca53352005-08-26 19:08:30 -07001209{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001210 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezcca53352005-08-26 19:08:30 -07001211 ms_iocb_entry_t *ms_pkt = ha->ms_iocb;
1212 struct ct_entry_24xx *ct_pkt = (struct ct_entry_24xx *)ha->ms_iocb;
1213
Andrew Vasqueze4289242007-07-19 15:05:56 -07001214 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquezcca53352005-08-26 19:08:30 -07001215 ct_pkt->cmd_byte_count = cpu_to_le32(req_size);
1216 ct_pkt->dseg_0_len = ct_pkt->cmd_byte_count;
1217 } else {
1218 ms_pkt->req_bytecount = cpu_to_le32(req_size);
1219 ms_pkt->dseg_req_length = ms_pkt->req_bytecount;
1220 }
1221
1222 return ms_pkt;
1223}
1224
1225/**
1226 * qla2x00_prep_ct_req() - Prepare common CT request fields for SNS query.
1227 * @ct_req: CT request buffer
1228 * @cmd: GS command
1229 * @rsp_size: response size in bytes
1230 *
1231 * Returns a pointer to the intitialized @ct_req.
1232 */
1233static inline struct ct_sns_req *
1234qla2x00_prep_ct_fdmi_req(struct ct_sns_req *ct_req, uint16_t cmd,
1235 uint16_t rsp_size)
1236{
1237 memset(ct_req, 0, sizeof(struct ct_sns_pkt));
1238
1239 ct_req->header.revision = 0x01;
1240 ct_req->header.gs_type = 0xFA;
1241 ct_req->header.gs_subtype = 0x10;
1242 ct_req->command = cpu_to_be16(cmd);
1243 ct_req->max_rsp_size = cpu_to_be16((rsp_size - 16) / 4);
1244
1245 return ct_req;
1246}
1247
1248/**
1249 * qla2x00_fdmi_rhba() -
1250 * @ha: HA context
1251 *
1252 * Returns 0 on success.
1253 */
1254static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001255qla2x00_fdmi_rhba(scsi_qla_host_t *vha)
Andrew Vasquezcca53352005-08-26 19:08:30 -07001256{
1257 int rval, alen;
1258 uint32_t size, sn;
1259
1260 ms_iocb_entry_t *ms_pkt;
1261 struct ct_sns_req *ct_req;
1262 struct ct_sns_rsp *ct_rsp;
1263 uint8_t *entries;
1264 struct ct_fdmi_hba_attr *eiter;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001265 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezcca53352005-08-26 19:08:30 -07001266
1267 /* Issue RHBA */
1268 /* Prepare common MS IOCB */
1269 /* Request size adjusted after CT preparation */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001270 ms_pkt = ha->isp_ops->prep_ms_fdmi_iocb(vha, 0, RHBA_RSP_SIZE);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001271
1272 /* Prepare CT request */
1273 ct_req = qla2x00_prep_ct_fdmi_req(&ha->ct_sns->p.req, RHBA_CMD,
1274 RHBA_RSP_SIZE);
1275 ct_rsp = &ha->ct_sns->p.rsp;
1276
1277 /* Prepare FDMI command arguments -- attribute block, attributes. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001278 memcpy(ct_req->req.rhba.hba_identifier, vha->port_name, WWN_SIZE);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001279 ct_req->req.rhba.entry_count = __constant_cpu_to_be32(1);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001280 memcpy(ct_req->req.rhba.port_name, vha->port_name, WWN_SIZE);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001281 size = 2 * WWN_SIZE + 4 + 4;
1282
1283 /* Attributes */
1284 ct_req->req.rhba.attrs.count =
1285 __constant_cpu_to_be32(FDMI_HBA_ATTR_COUNT);
1286 entries = ct_req->req.rhba.hba_identifier;
1287
1288 /* Nodename. */
1289 eiter = (struct ct_fdmi_hba_attr *) (entries + size);
1290 eiter->type = __constant_cpu_to_be16(FDMI_HBA_NODE_NAME);
1291 eiter->len = __constant_cpu_to_be16(4 + WWN_SIZE);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001292 memcpy(eiter->a.node_name, vha->node_name, WWN_SIZE);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001293 size += 4 + WWN_SIZE;
1294
1295 DEBUG13(printk("%s(%ld): NODENAME=%02x%02x%02x%02x%02x%02x%02x%02x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001296 __func__, vha->host_no,
Andrew Vasquezcca53352005-08-26 19:08:30 -07001297 eiter->a.node_name[0], eiter->a.node_name[1], eiter->a.node_name[2],
1298 eiter->a.node_name[3], eiter->a.node_name[4], eiter->a.node_name[5],
1299 eiter->a.node_name[6], eiter->a.node_name[7]));
1300
1301 /* Manufacturer. */
1302 eiter = (struct ct_fdmi_hba_attr *) (entries + size);
1303 eiter->type = __constant_cpu_to_be16(FDMI_HBA_MANUFACTURER);
1304 strcpy(eiter->a.manufacturer, "QLogic Corporation");
1305 alen = strlen(eiter->a.manufacturer);
1306 alen += (alen & 3) ? (4 - (alen & 3)) : 4;
1307 eiter->len = cpu_to_be16(4 + alen);
1308 size += 4 + alen;
1309
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001310 DEBUG13(printk("%s(%ld): MANUFACTURER=%s.\n", __func__, vha->host_no,
Andrew Vasquezcca53352005-08-26 19:08:30 -07001311 eiter->a.manufacturer));
1312
1313 /* Serial number. */
1314 eiter = (struct ct_fdmi_hba_attr *) (entries + size);
1315 eiter->type = __constant_cpu_to_be16(FDMI_HBA_SERIAL_NUMBER);
1316 sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
1317 sprintf(eiter->a.serial_num, "%c%05d", 'A' + sn / 100000, sn % 100000);
1318 alen = strlen(eiter->a.serial_num);
1319 alen += (alen & 3) ? (4 - (alen & 3)) : 4;
1320 eiter->len = cpu_to_be16(4 + alen);
1321 size += 4 + alen;
1322
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001323 DEBUG13(printk("%s(%ld): SERIALNO=%s.\n", __func__, vha->host_no,
Andrew Vasquezcca53352005-08-26 19:08:30 -07001324 eiter->a.serial_num));
1325
1326 /* Model name. */
1327 eiter = (struct ct_fdmi_hba_attr *) (entries + size);
1328 eiter->type = __constant_cpu_to_be16(FDMI_HBA_MODEL);
1329 strcpy(eiter->a.model, ha->model_number);
1330 alen = strlen(eiter->a.model);
1331 alen += (alen & 3) ? (4 - (alen & 3)) : 4;
1332 eiter->len = cpu_to_be16(4 + alen);
1333 size += 4 + alen;
1334
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001335 DEBUG13(printk("%s(%ld): MODEL_NAME=%s.\n", __func__, vha->host_no,
Andrew Vasquezcca53352005-08-26 19:08:30 -07001336 eiter->a.model));
1337
1338 /* Model description. */
1339 eiter = (struct ct_fdmi_hba_attr *) (entries + size);
1340 eiter->type = __constant_cpu_to_be16(FDMI_HBA_MODEL_DESCRIPTION);
1341 if (ha->model_desc)
1342 strncpy(eiter->a.model_desc, ha->model_desc, 80);
1343 alen = strlen(eiter->a.model_desc);
1344 alen += (alen & 3) ? (4 - (alen & 3)) : 4;
1345 eiter->len = cpu_to_be16(4 + alen);
1346 size += 4 + alen;
1347
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001348 DEBUG13(printk("%s(%ld): MODEL_DESC=%s.\n", __func__, vha->host_no,
Andrew Vasquezcca53352005-08-26 19:08:30 -07001349 eiter->a.model_desc));
1350
1351 /* Hardware version. */
1352 eiter = (struct ct_fdmi_hba_attr *) (entries + size);
1353 eiter->type = __constant_cpu_to_be16(FDMI_HBA_HARDWARE_VERSION);
1354 strcpy(eiter->a.hw_version, ha->adapter_id);
1355 alen = strlen(eiter->a.hw_version);
1356 alen += (alen & 3) ? (4 - (alen & 3)) : 4;
1357 eiter->len = cpu_to_be16(4 + alen);
1358 size += 4 + alen;
1359
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001360 DEBUG13(printk("%s(%ld): HARDWAREVER=%s.\n", __func__, vha->host_no,
Andrew Vasquezcca53352005-08-26 19:08:30 -07001361 eiter->a.hw_version));
1362
1363 /* Driver version. */
1364 eiter = (struct ct_fdmi_hba_attr *) (entries + size);
1365 eiter->type = __constant_cpu_to_be16(FDMI_HBA_DRIVER_VERSION);
1366 strcpy(eiter->a.driver_version, qla2x00_version_str);
1367 alen = strlen(eiter->a.driver_version);
1368 alen += (alen & 3) ? (4 - (alen & 3)) : 4;
1369 eiter->len = cpu_to_be16(4 + alen);
1370 size += 4 + alen;
1371
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001372 DEBUG13(printk("%s(%ld): DRIVERVER=%s.\n", __func__, vha->host_no,
Andrew Vasquezcca53352005-08-26 19:08:30 -07001373 eiter->a.driver_version));
1374
1375 /* Option ROM version. */
1376 eiter = (struct ct_fdmi_hba_attr *) (entries + size);
1377 eiter->type = __constant_cpu_to_be16(FDMI_HBA_OPTION_ROM_VERSION);
1378 strcpy(eiter->a.orom_version, "0.00");
1379 alen = strlen(eiter->a.orom_version);
1380 alen += (alen & 3) ? (4 - (alen & 3)) : 4;
1381 eiter->len = cpu_to_be16(4 + alen);
1382 size += 4 + alen;
1383
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001384 DEBUG13(printk("%s(%ld): OPTROMVER=%s.\n", __func__, vha->host_no,
Andrew Vasquezcca53352005-08-26 19:08:30 -07001385 eiter->a.orom_version));
1386
1387 /* Firmware version */
1388 eiter = (struct ct_fdmi_hba_attr *) (entries + size);
1389 eiter->type = __constant_cpu_to_be16(FDMI_HBA_FIRMWARE_VERSION);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001390 ha->isp_ops->fw_version_str(vha, eiter->a.fw_version);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001391 alen = strlen(eiter->a.fw_version);
1392 alen += (alen & 3) ? (4 - (alen & 3)) : 4;
1393 eiter->len = cpu_to_be16(4 + alen);
1394 size += 4 + alen;
1395
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001396 DEBUG13(printk("%s(%ld): FIRMWAREVER=%s.\n", __func__, vha->host_no,
Andrew Vasquezcca53352005-08-26 19:08:30 -07001397 eiter->a.fw_version));
1398
1399 /* Update MS request size. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001400 qla2x00_update_ms_fdmi_iocb(vha, size + 16);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001401
1402 DEBUG13(printk("%s(%ld): RHBA identifier="
1403 "%02x%02x%02x%02x%02x%02x%02x%02x size=%d.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001404 vha->host_no, ct_req->req.rhba.hba_identifier[0],
Andrew Vasquezcca53352005-08-26 19:08:30 -07001405 ct_req->req.rhba.hba_identifier[1],
1406 ct_req->req.rhba.hba_identifier[2],
1407 ct_req->req.rhba.hba_identifier[3],
1408 ct_req->req.rhba.hba_identifier[4],
1409 ct_req->req.rhba.hba_identifier[5],
1410 ct_req->req.rhba.hba_identifier[6],
1411 ct_req->req.rhba.hba_identifier[7], size));
1412 DEBUG13(qla2x00_dump_buffer(entries, size));
1413
1414 /* Execute MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001415 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
Andrew Vasquezcca53352005-08-26 19:08:30 -07001416 sizeof(ms_iocb_entry_t));
1417 if (rval != QLA_SUCCESS) {
1418 /*EMPTY*/
1419 DEBUG2_3(printk("scsi(%ld): RHBA issue IOCB failed (%d).\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001420 vha->host_no, rval));
1421 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, "RHBA") !=
Andrew Vasquezcca53352005-08-26 19:08:30 -07001422 QLA_SUCCESS) {
1423 rval = QLA_FUNCTION_FAILED;
1424 if (ct_rsp->header.reason_code == CT_REASON_CANNOT_PERFORM &&
1425 ct_rsp->header.explanation_code ==
1426 CT_EXPL_ALREADY_REGISTERED) {
1427 DEBUG2_13(printk("%s(%ld): HBA already registered.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001428 __func__, vha->host_no));
Andrew Vasquezcca53352005-08-26 19:08:30 -07001429 rval = QLA_ALREADY_REGISTERED;
1430 }
1431 } else {
1432 DEBUG2(printk("scsi(%ld): RHBA exiting normally.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001433 vha->host_no));
Andrew Vasquezcca53352005-08-26 19:08:30 -07001434 }
1435
1436 return rval;
1437}
1438
1439/**
1440 * qla2x00_fdmi_dhba() -
1441 * @ha: HA context
1442 *
1443 * Returns 0 on success.
1444 */
1445static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001446qla2x00_fdmi_dhba(scsi_qla_host_t *vha)
Andrew Vasquezcca53352005-08-26 19:08:30 -07001447{
1448 int rval;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001449 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezcca53352005-08-26 19:08:30 -07001450 ms_iocb_entry_t *ms_pkt;
1451 struct ct_sns_req *ct_req;
1452 struct ct_sns_rsp *ct_rsp;
1453
1454 /* Issue RPA */
1455 /* Prepare common MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001456 ms_pkt = ha->isp_ops->prep_ms_fdmi_iocb(vha, DHBA_REQ_SIZE,
Andrew Vasquezcca53352005-08-26 19:08:30 -07001457 DHBA_RSP_SIZE);
1458
1459 /* Prepare CT request */
1460 ct_req = qla2x00_prep_ct_fdmi_req(&ha->ct_sns->p.req, DHBA_CMD,
1461 DHBA_RSP_SIZE);
1462 ct_rsp = &ha->ct_sns->p.rsp;
1463
1464 /* Prepare FDMI command arguments -- portname. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001465 memcpy(ct_req->req.dhba.port_name, vha->port_name, WWN_SIZE);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001466
1467 DEBUG13(printk("%s(%ld): DHBA portname="
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001468 "%02x%02x%02x%02x%02x%02x%02x%02x.\n", __func__, vha->host_no,
Andrew Vasquezcca53352005-08-26 19:08:30 -07001469 ct_req->req.dhba.port_name[0], ct_req->req.dhba.port_name[1],
1470 ct_req->req.dhba.port_name[2], ct_req->req.dhba.port_name[3],
1471 ct_req->req.dhba.port_name[4], ct_req->req.dhba.port_name[5],
1472 ct_req->req.dhba.port_name[6], ct_req->req.dhba.port_name[7]));
1473
1474 /* Execute MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001475 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
Andrew Vasquezcca53352005-08-26 19:08:30 -07001476 sizeof(ms_iocb_entry_t));
1477 if (rval != QLA_SUCCESS) {
1478 /*EMPTY*/
1479 DEBUG2_3(printk("scsi(%ld): DHBA issue IOCB failed (%d).\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001480 vha->host_no, rval));
1481 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, "DHBA") !=
Andrew Vasquezcca53352005-08-26 19:08:30 -07001482 QLA_SUCCESS) {
1483 rval = QLA_FUNCTION_FAILED;
1484 } else {
1485 DEBUG2(printk("scsi(%ld): DHBA exiting normally.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001486 vha->host_no));
Andrew Vasquezcca53352005-08-26 19:08:30 -07001487 }
1488
1489 return rval;
1490}
1491
1492/**
1493 * qla2x00_fdmi_rpa() -
1494 * @ha: HA context
1495 *
1496 * Returns 0 on success.
1497 */
1498static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001499qla2x00_fdmi_rpa(scsi_qla_host_t *vha)
Andrew Vasquezcca53352005-08-26 19:08:30 -07001500{
1501 int rval, alen;
1502 uint32_t size, max_frame_size;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001503 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezcca53352005-08-26 19:08:30 -07001504 ms_iocb_entry_t *ms_pkt;
1505 struct ct_sns_req *ct_req;
1506 struct ct_sns_rsp *ct_rsp;
1507 uint8_t *entries;
1508 struct ct_fdmi_port_attr *eiter;
1509 struct init_cb_24xx *icb24 = (struct init_cb_24xx *)ha->init_cb;
1510
1511 /* Issue RPA */
1512 /* Prepare common MS IOCB */
1513 /* Request size adjusted after CT preparation */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001514 ms_pkt = ha->isp_ops->prep_ms_fdmi_iocb(vha, 0, RPA_RSP_SIZE);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001515
1516 /* Prepare CT request */
1517 ct_req = qla2x00_prep_ct_fdmi_req(&ha->ct_sns->p.req, RPA_CMD,
1518 RPA_RSP_SIZE);
1519 ct_rsp = &ha->ct_sns->p.rsp;
1520
1521 /* Prepare FDMI command arguments -- attribute block, attributes. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001522 memcpy(ct_req->req.rpa.port_name, vha->port_name, WWN_SIZE);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001523 size = WWN_SIZE + 4;
1524
1525 /* Attributes */
1526 ct_req->req.rpa.attrs.count =
Andrew Vasquez8a85e172007-09-20 14:07:41 -07001527 __constant_cpu_to_be32(FDMI_PORT_ATTR_COUNT - 1);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001528 entries = ct_req->req.rpa.port_name;
1529
1530 /* FC4 types. */
1531 eiter = (struct ct_fdmi_port_attr *) (entries + size);
1532 eiter->type = __constant_cpu_to_be16(FDMI_PORT_FC4_TYPES);
1533 eiter->len = __constant_cpu_to_be16(4 + 32);
1534 eiter->a.fc4_types[2] = 0x01;
1535 size += 4 + 32;
1536
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001537 DEBUG13(printk("%s(%ld): FC4_TYPES=%02x %02x.\n", __func__,
1538 vha->host_no, eiter->a.fc4_types[2],
1539 eiter->a.fc4_types[1]));
Andrew Vasquezcca53352005-08-26 19:08:30 -07001540
1541 /* Supported speed. */
1542 eiter = (struct ct_fdmi_port_attr *) (entries + size);
1543 eiter->type = __constant_cpu_to_be16(FDMI_PORT_SUPPORT_SPEED);
1544 eiter->len = __constant_cpu_to_be16(4 + 4);
Giridhar Malavalia9083012010-04-12 17:59:55 -07001545 if (IS_QLA8XXX_TYPE(ha))
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001546 eiter->a.sup_speed = __constant_cpu_to_be32(
1547 FDMI_PORT_SPEED_10GB);
1548 else if (IS_QLA25XX(ha))
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001549 eiter->a.sup_speed = __constant_cpu_to_be32(
1550 FDMI_PORT_SPEED_1GB|FDMI_PORT_SPEED_2GB|
1551 FDMI_PORT_SPEED_4GB|FDMI_PORT_SPEED_8GB);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001552 else if (IS_QLA24XX_TYPE(ha))
Andrew Vasquez58815692007-07-19 15:05:58 -07001553 eiter->a.sup_speed = __constant_cpu_to_be32(
1554 FDMI_PORT_SPEED_1GB|FDMI_PORT_SPEED_2GB|
1555 FDMI_PORT_SPEED_4GB);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001556 else if (IS_QLA23XX(ha))
Andrew Vasquez58815692007-07-19 15:05:58 -07001557 eiter->a.sup_speed =__constant_cpu_to_be32(
1558 FDMI_PORT_SPEED_1GB|FDMI_PORT_SPEED_2GB);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001559 else
Andrew Vasquez58815692007-07-19 15:05:58 -07001560 eiter->a.sup_speed = __constant_cpu_to_be32(
1561 FDMI_PORT_SPEED_1GB);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001562 size += 4 + 4;
1563
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001564 DEBUG13(printk("%s(%ld): SUPPORTED_SPEED=%x.\n", __func__, vha->host_no,
Andrew Vasquezcca53352005-08-26 19:08:30 -07001565 eiter->a.sup_speed));
1566
1567 /* Current speed. */
1568 eiter = (struct ct_fdmi_port_attr *) (entries + size);
1569 eiter->type = __constant_cpu_to_be16(FDMI_PORT_CURRENT_SPEED);
1570 eiter->len = __constant_cpu_to_be16(4 + 4);
1571 switch (ha->link_data_rate) {
Andrew Vasquez58815692007-07-19 15:05:58 -07001572 case PORT_SPEED_1GB:
1573 eiter->a.cur_speed =
1574 __constant_cpu_to_be32(FDMI_PORT_SPEED_1GB);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001575 break;
Andrew Vasquez58815692007-07-19 15:05:58 -07001576 case PORT_SPEED_2GB:
1577 eiter->a.cur_speed =
1578 __constant_cpu_to_be32(FDMI_PORT_SPEED_2GB);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001579 break;
Andrew Vasquez58815692007-07-19 15:05:58 -07001580 case PORT_SPEED_4GB:
1581 eiter->a.cur_speed =
1582 __constant_cpu_to_be32(FDMI_PORT_SPEED_4GB);
1583 break;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001584 case PORT_SPEED_8GB:
1585 eiter->a.cur_speed =
1586 __constant_cpu_to_be32(FDMI_PORT_SPEED_8GB);
1587 break;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001588 case PORT_SPEED_10GB:
1589 eiter->a.cur_speed =
1590 __constant_cpu_to_be32(FDMI_PORT_SPEED_10GB);
1591 break;
Andrew Vasquez58815692007-07-19 15:05:58 -07001592 default:
1593 eiter->a.cur_speed =
1594 __constant_cpu_to_be32(FDMI_PORT_SPEED_UNKNOWN);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001595 break;
1596 }
1597 size += 4 + 4;
1598
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001599 DEBUG13(printk("%s(%ld): CURRENT_SPEED=%x.\n", __func__, vha->host_no,
Andrew Vasquezcca53352005-08-26 19:08:30 -07001600 eiter->a.cur_speed));
1601
1602 /* Max frame size. */
1603 eiter = (struct ct_fdmi_port_attr *) (entries + size);
1604 eiter->type = __constant_cpu_to_be16(FDMI_PORT_MAX_FRAME_SIZE);
1605 eiter->len = __constant_cpu_to_be16(4 + 4);
Andrew Vasqueze4289242007-07-19 15:05:56 -07001606 max_frame_size = IS_FWI2_CAPABLE(ha) ?
Seokmann Juc6852c42008-04-24 15:21:29 -07001607 le16_to_cpu(icb24->frame_payload_size):
1608 le16_to_cpu(ha->init_cb->frame_payload_size);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001609 eiter->a.max_frame_size = cpu_to_be32(max_frame_size);
1610 size += 4 + 4;
1611
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001612 DEBUG13(printk("%s(%ld): MAX_FRAME_SIZE=%x.\n", __func__, vha->host_no,
Andrew Vasquezcca53352005-08-26 19:08:30 -07001613 eiter->a.max_frame_size));
1614
1615 /* OS device name. */
1616 eiter = (struct ct_fdmi_port_attr *) (entries + size);
1617 eiter->type = __constant_cpu_to_be16(FDMI_PORT_OS_DEVICE_NAME);
Andrew Vasquez8a85e172007-09-20 14:07:41 -07001618 strcpy(eiter->a.os_dev_name, QLA2XXX_DRIVER_NAME);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001619 alen = strlen(eiter->a.os_dev_name);
1620 alen += (alen & 3) ? (4 - (alen & 3)) : 4;
1621 eiter->len = cpu_to_be16(4 + alen);
1622 size += 4 + alen;
1623
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001624 DEBUG13(printk("%s(%ld): OS_DEVICE_NAME=%s.\n", __func__, vha->host_no,
Andrew Vasquezcca53352005-08-26 19:08:30 -07001625 eiter->a.os_dev_name));
1626
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07001627 /* Hostname. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001628 if (strlen(fc_host_system_hostname(vha->host))) {
Andrew Vasquez8a85e172007-09-20 14:07:41 -07001629 ct_req->req.rpa.attrs.count =
1630 __constant_cpu_to_be32(FDMI_PORT_ATTR_COUNT);
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07001631 eiter = (struct ct_fdmi_port_attr *) (entries + size);
1632 eiter->type = __constant_cpu_to_be16(FDMI_PORT_HOST_NAME);
1633 snprintf(eiter->a.host_name, sizeof(eiter->a.host_name),
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001634 "%s", fc_host_system_hostname(vha->host));
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07001635 alen = strlen(eiter->a.host_name);
1636 alen += (alen & 3) ? (4 - (alen & 3)) : 4;
1637 eiter->len = cpu_to_be16(4 + alen);
1638 size += 4 + alen;
1639
1640 DEBUG13(printk("%s(%ld): HOSTNAME=%s.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001641 vha->host_no, eiter->a.host_name));
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07001642 }
1643
Andrew Vasquezcca53352005-08-26 19:08:30 -07001644 /* Update MS request size. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001645 qla2x00_update_ms_fdmi_iocb(vha, size + 16);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001646
1647 DEBUG13(printk("%s(%ld): RPA portname="
1648 "%02x%02x%02x%02x%02x%02x%02x%02x size=%d.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001649 vha->host_no, ct_req->req.rpa.port_name[0],
Andrew Vasquezcca53352005-08-26 19:08:30 -07001650 ct_req->req.rpa.port_name[1], ct_req->req.rpa.port_name[2],
1651 ct_req->req.rpa.port_name[3], ct_req->req.rpa.port_name[4],
1652 ct_req->req.rpa.port_name[5], ct_req->req.rpa.port_name[6],
1653 ct_req->req.rpa.port_name[7], size));
1654 DEBUG13(qla2x00_dump_buffer(entries, size));
1655
1656 /* Execute MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001657 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
Andrew Vasquezcca53352005-08-26 19:08:30 -07001658 sizeof(ms_iocb_entry_t));
1659 if (rval != QLA_SUCCESS) {
1660 /*EMPTY*/
1661 DEBUG2_3(printk("scsi(%ld): RPA issue IOCB failed (%d).\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001662 vha->host_no, rval));
1663 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, "RPA") !=
Andrew Vasquezcca53352005-08-26 19:08:30 -07001664 QLA_SUCCESS) {
1665 rval = QLA_FUNCTION_FAILED;
1666 } else {
1667 DEBUG2(printk("scsi(%ld): RPA exiting normally.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001668 vha->host_no));
Andrew Vasquezcca53352005-08-26 19:08:30 -07001669 }
1670
1671 return rval;
1672}
1673
1674/**
1675 * qla2x00_fdmi_register() -
1676 * @ha: HA context
1677 *
1678 * Returns 0 on success.
1679 */
1680int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001681qla2x00_fdmi_register(scsi_qla_host_t *vha)
Andrew Vasquezcca53352005-08-26 19:08:30 -07001682{
1683 int rval;
Andrew Vasquez80de7ef2009-07-31 15:09:33 -07001684 struct qla_hw_data *ha = vha->hw;
1685
1686 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1687 return QLA_FUNCTION_FAILED;
Andrew Vasquezcca53352005-08-26 19:08:30 -07001688
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001689 rval = qla2x00_mgmt_svr_login(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001690 if (rval)
1691 return rval;
1692
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001693 rval = qla2x00_fdmi_rhba(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001694 if (rval) {
1695 if (rval != QLA_ALREADY_REGISTERED)
1696 return rval;
1697
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001698 rval = qla2x00_fdmi_dhba(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001699 if (rval)
1700 return rval;
1701
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001702 rval = qla2x00_fdmi_rhba(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001703 if (rval)
1704 return rval;
1705 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001706 rval = qla2x00_fdmi_rpa(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001707
1708 return rval;
1709}
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001710
1711/**
1712 * qla2x00_gfpn_id() - SNS Get Fabric Port Name (GFPN_ID) query.
1713 * @ha: HA context
1714 * @list: switch info entries to populate
1715 *
1716 * Returns 0 on success.
1717 */
1718int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001719qla2x00_gfpn_id(scsi_qla_host_t *vha, sw_info_t *list)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001720{
1721 int rval;
1722 uint16_t i;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001723 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001724 ms_iocb_entry_t *ms_pkt;
1725 struct ct_sns_req *ct_req;
1726 struct ct_sns_rsp *ct_rsp;
1727
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07001728 if (!IS_IIDMA_CAPABLE(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001729 return QLA_FUNCTION_FAILED;
1730
1731 for (i = 0; i < MAX_FIBRE_DEVICES; i++) {
1732 /* Issue GFPN_ID */
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001733 /* Prepare common MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001734 ms_pkt = ha->isp_ops->prep_ms_iocb(vha, GFPN_ID_REQ_SIZE,
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001735 GFPN_ID_RSP_SIZE);
1736
1737 /* Prepare CT request */
1738 ct_req = qla2x00_prep_ct_req(&ha->ct_sns->p.req, GFPN_ID_CMD,
1739 GFPN_ID_RSP_SIZE);
1740 ct_rsp = &ha->ct_sns->p.rsp;
1741
1742 /* Prepare CT arguments -- port_id */
1743 ct_req->req.port_id.port_id[0] = list[i].d_id.b.domain;
1744 ct_req->req.port_id.port_id[1] = list[i].d_id.b.area;
1745 ct_req->req.port_id.port_id[2] = list[i].d_id.b.al_pa;
1746
1747 /* Execute MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001748 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001749 sizeof(ms_iocb_entry_t));
1750 if (rval != QLA_SUCCESS) {
1751 /*EMPTY*/
1752 DEBUG2_3(printk("scsi(%ld): GFPN_ID issue IOCB "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001753 "failed (%d).\n", vha->host_no, rval));
1754 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp,
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001755 "GFPN_ID") != QLA_SUCCESS) {
1756 rval = QLA_FUNCTION_FAILED;
1757 } else {
1758 /* Save fabric portname */
1759 memcpy(list[i].fabric_port_name,
1760 ct_rsp->rsp.gfpn_id.port_name, WWN_SIZE);
1761 }
1762
1763 /* Last device exit. */
1764 if (list[i].d_id.b.rsvd_1 != 0)
1765 break;
1766 }
1767
1768 return (rval);
1769}
1770
1771static inline void *
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001772qla24xx_prep_ms_fm_iocb(scsi_qla_host_t *vha, uint32_t req_size,
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001773 uint32_t rsp_size)
1774{
1775 struct ct_entry_24xx *ct_pkt;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001776 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001777 ct_pkt = (struct ct_entry_24xx *)ha->ms_iocb;
1778 memset(ct_pkt, 0, sizeof(struct ct_entry_24xx));
1779
1780 ct_pkt->entry_type = CT_IOCB_TYPE;
1781 ct_pkt->entry_count = 1;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001782 ct_pkt->nport_handle = cpu_to_le16(vha->mgmt_svr_loop_id);
Andrew Vasquez00a537b2008-02-28 14:06:11 -08001783 ct_pkt->timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001784 ct_pkt->cmd_dsd_count = __constant_cpu_to_le16(1);
1785 ct_pkt->rsp_dsd_count = __constant_cpu_to_le16(1);
1786 ct_pkt->rsp_byte_count = cpu_to_le32(rsp_size);
1787 ct_pkt->cmd_byte_count = cpu_to_le32(req_size);
1788
1789 ct_pkt->dseg_0_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
1790 ct_pkt->dseg_0_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
1791 ct_pkt->dseg_0_len = ct_pkt->cmd_byte_count;
1792
1793 ct_pkt->dseg_1_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
1794 ct_pkt->dseg_1_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
1795 ct_pkt->dseg_1_len = ct_pkt->rsp_byte_count;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001796 ct_pkt->vp_index = vha->vp_idx;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001797
1798 return ct_pkt;
1799}
1800
1801
1802static inline struct ct_sns_req *
1803qla24xx_prep_ct_fm_req(struct ct_sns_req *ct_req, uint16_t cmd,
1804 uint16_t rsp_size)
1805{
1806 memset(ct_req, 0, sizeof(struct ct_sns_pkt));
1807
1808 ct_req->header.revision = 0x01;
1809 ct_req->header.gs_type = 0xFA;
1810 ct_req->header.gs_subtype = 0x01;
1811 ct_req->command = cpu_to_be16(cmd);
1812 ct_req->max_rsp_size = cpu_to_be16((rsp_size - 16) / 4);
1813
1814 return ct_req;
1815}
1816
1817/**
1818 * qla2x00_gpsc() - FCS Get Port Speed Capabilities (GPSC) query.
1819 * @ha: HA context
1820 * @list: switch info entries to populate
1821 *
1822 * Returns 0 on success.
1823 */
1824int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001825qla2x00_gpsc(scsi_qla_host_t *vha, sw_info_t *list)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001826{
1827 int rval;
1828 uint16_t i;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001829 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001830 ms_iocb_entry_t *ms_pkt;
1831 struct ct_sns_req *ct_req;
1832 struct ct_sns_rsp *ct_rsp;
1833
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07001834 if (!IS_IIDMA_CAPABLE(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001835 return QLA_FUNCTION_FAILED;
Andrew Vasquez4346b142006-12-13 19:20:28 -08001836 if (!ha->flags.gpsc_supported)
1837 return QLA_FUNCTION_FAILED;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001838
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001839 rval = qla2x00_mgmt_svr_login(vha);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001840 if (rval)
1841 return rval;
1842
1843 for (i = 0; i < MAX_FIBRE_DEVICES; i++) {
1844 /* Issue GFPN_ID */
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001845 /* Prepare common MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001846 ms_pkt = qla24xx_prep_ms_fm_iocb(vha, GPSC_REQ_SIZE,
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001847 GPSC_RSP_SIZE);
1848
1849 /* Prepare CT request */
1850 ct_req = qla24xx_prep_ct_fm_req(&ha->ct_sns->p.req,
1851 GPSC_CMD, GPSC_RSP_SIZE);
1852 ct_rsp = &ha->ct_sns->p.rsp;
1853
1854 /* Prepare CT arguments -- port_name */
1855 memcpy(ct_req->req.gpsc.port_name, list[i].fabric_port_name,
1856 WWN_SIZE);
1857
1858 /* Execute MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001859 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001860 sizeof(ms_iocb_entry_t));
1861 if (rval != QLA_SUCCESS) {
1862 /*EMPTY*/
1863 DEBUG2_3(printk("scsi(%ld): GPSC issue IOCB "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001864 "failed (%d).\n", vha->host_no, rval));
1865 } else if ((rval = qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp,
Andrew Vasquez4346b142006-12-13 19:20:28 -08001866 "GPSC")) != QLA_SUCCESS) {
1867 /* FM command unsupported? */
1868 if (rval == QLA_INVALID_COMMAND &&
Andrew Vasquez3fe7cfb2008-04-03 13:13:23 -07001869 (ct_rsp->header.reason_code ==
1870 CT_REASON_INVALID_COMMAND_CODE ||
1871 ct_rsp->header.reason_code ==
1872 CT_REASON_COMMAND_UNSUPPORTED)) {
Andrew Vasquez4346b142006-12-13 19:20:28 -08001873 DEBUG2(printk("scsi(%ld): GPSC command "
1874 "unsupported, disabling query...\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001875 vha->host_no));
Andrew Vasquez4346b142006-12-13 19:20:28 -08001876 ha->flags.gpsc_supported = 0;
1877 rval = QLA_FUNCTION_FAILED;
1878 break;
1879 }
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001880 rval = QLA_FUNCTION_FAILED;
1881 } else {
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07001882 /* Save port-speed */
1883 switch (be16_to_cpu(ct_rsp->rsp.gpsc.speed)) {
1884 case BIT_15:
1885 list[i].fp_speed = PORT_SPEED_1GB;
1886 break;
1887 case BIT_14:
1888 list[i].fp_speed = PORT_SPEED_2GB;
1889 break;
1890 case BIT_13:
1891 list[i].fp_speed = PORT_SPEED_4GB;
1892 break;
Andrew Vasquez9f8fdde2009-06-03 09:55:22 -07001893 case BIT_12:
1894 list[i].fp_speed = PORT_SPEED_10GB;
1895 break;
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07001896 case BIT_11:
1897 list[i].fp_speed = PORT_SPEED_8GB;
1898 break;
1899 }
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001900
1901 DEBUG2_3(printk("scsi(%ld): GPSC ext entry - "
1902 "fpn %02x%02x%02x%02x%02x%02x%02x%02x speeds=%04x "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001903 "speed=%04x.\n", vha->host_no,
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001904 list[i].fabric_port_name[0],
1905 list[i].fabric_port_name[1],
1906 list[i].fabric_port_name[2],
1907 list[i].fabric_port_name[3],
1908 list[i].fabric_port_name[4],
1909 list[i].fabric_port_name[5],
1910 list[i].fabric_port_name[6],
1911 list[i].fabric_port_name[7],
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07001912 be16_to_cpu(ct_rsp->rsp.gpsc.speeds),
1913 be16_to_cpu(ct_rsp->rsp.gpsc.speed)));
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001914 }
1915
1916 /* Last device exit. */
1917 if (list[i].d_id.b.rsvd_1 != 0)
1918 break;
1919 }
1920
1921 return (rval);
1922}
Chad Dupuise8c72ba2010-07-23 15:28:25 +05001923
1924/**
1925 * qla2x00_gff_id() - SNS Get FC-4 Features (GFF_ID) query.
1926 *
1927 * @ha: HA context
1928 * @list: switch info entries to populate
1929 *
1930 */
1931void
1932qla2x00_gff_id(scsi_qla_host_t *vha, sw_info_t *list)
1933{
1934 int rval;
1935 uint16_t i;
1936
1937 ms_iocb_entry_t *ms_pkt;
1938 struct ct_sns_req *ct_req;
1939 struct ct_sns_rsp *ct_rsp;
1940 struct qla_hw_data *ha = vha->hw;
1941 uint8_t fcp_scsi_features = 0;
1942
1943 for (i = 0; i < MAX_FIBRE_DEVICES; i++) {
1944 /* Set default FC4 Type as UNKNOWN so the default is to
1945 * Process this port */
1946 list[i].fc4_type = FC4_TYPE_UNKNOWN;
1947
1948 /* Do not attempt GFF_ID if we are not FWI_2 capable */
1949 if (!IS_FWI2_CAPABLE(ha))
1950 continue;
1951
1952 /* Prepare common MS IOCB */
1953 ms_pkt = ha->isp_ops->prep_ms_iocb(vha, GFF_ID_REQ_SIZE,
1954 GFF_ID_RSP_SIZE);
1955
1956 /* Prepare CT request */
1957 ct_req = qla2x00_prep_ct_req(&ha->ct_sns->p.req, GFF_ID_CMD,
1958 GFF_ID_RSP_SIZE);
1959 ct_rsp = &ha->ct_sns->p.rsp;
1960
1961 /* Prepare CT arguments -- port_id */
1962 ct_req->req.port_id.port_id[0] = list[i].d_id.b.domain;
1963 ct_req->req.port_id.port_id[1] = list[i].d_id.b.area;
1964 ct_req->req.port_id.port_id[2] = list[i].d_id.b.al_pa;
1965
1966 /* Execute MS IOCB */
1967 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
1968 sizeof(ms_iocb_entry_t));
1969
1970 if (rval != QLA_SUCCESS) {
1971 DEBUG2_3(printk(KERN_INFO
1972 "scsi(%ld): GFF_ID issue IOCB failed "
1973 "(%d).\n", vha->host_no, rval));
1974 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp,
Andrew Vasquez7a78ced2011-02-23 15:27:12 -08001975 "GFF_ID") != QLA_SUCCESS) {
Chad Dupuise8c72ba2010-07-23 15:28:25 +05001976 DEBUG2_3(printk(KERN_INFO
1977 "scsi(%ld): GFF_ID IOCB status had a "
1978 "failure status code\n", vha->host_no));
1979 } else {
1980 fcp_scsi_features =
1981 ct_rsp->rsp.gff_id.fc4_features[GFF_FCP_SCSI_OFFSET];
1982 fcp_scsi_features &= 0x0f;
1983
1984 if (fcp_scsi_features)
1985 list[i].fc4_type = FC4_TYPE_FCP_SCSI;
1986 else
1987 list[i].fc4_type = FC4_TYPE_OTHER;
1988 }
1989
1990 /* Last device exit. */
1991 if (list[i].d_id.b.rsvd_1 != 0)
1992 break;
1993 }
1994}