blob: 59ecc4eda6cdec096d53927b3a994262141f9cd3 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Andrew Vasquezfa90c542005-10-27 11:10:08 -07002 * QLogic Fibre Channel HBA Driver
Armen Baloyanbd21eaf2014-04-11 16:54:24 -04003 * Copyright (c) 2003-2014 QLogic Corporation
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Andrew Vasquezfa90c542005-10-27 11:10:08 -07005 * See LICENSE.qla2xxx for copyright and licensing details.
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 */
7#include "qla_def.h"
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04008#include "qla_target.h"
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04009#include <linux/utsname.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010
Linus Torvalds1da177e2005-04-16 15:20:36 -070011static int qla2x00_sns_ga_nxt(scsi_qla_host_t *, fc_port_t *);
12static int qla2x00_sns_gid_pt(scsi_qla_host_t *, sw_info_t *);
13static int qla2x00_sns_gpn_id(scsi_qla_host_t *, sw_info_t *);
14static int qla2x00_sns_gnn_id(scsi_qla_host_t *, sw_info_t *);
15static int qla2x00_sns_rft_id(scsi_qla_host_t *);
16static int qla2x00_sns_rnn_id(scsi_qla_host_t *);
17
18/**
Andrew Vasquez8c958a92005-07-06 10:30:47 -070019 * qla2x00_prep_ms_iocb() - Prepare common MS/CT IOCB fields for SNS CT query.
Linus Torvalds1da177e2005-04-16 15:20:36 -070020 * @ha: HA context
21 * @req_size: request size in bytes
22 * @rsp_size: response size in bytes
23 *
24 * Returns a pointer to the @ha's ms_iocb.
25 */
Andrew Vasquez8c958a92005-07-06 10:30:47 -070026void *
Quinn Tran726b8542017-01-19 22:28:00 -080027qla2x00_prep_ms_iocb(scsi_qla_host_t *vha, struct ct_arg *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -070028{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080029 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -070030 ms_iocb_entry_t *ms_pkt;
31
Quinn Tran726b8542017-01-19 22:28:00 -080032 ms_pkt = (ms_iocb_entry_t *)arg->iocb;
Linus Torvalds1da177e2005-04-16 15:20:36 -070033 memset(ms_pkt, 0, sizeof(ms_iocb_entry_t));
34
35 ms_pkt->entry_type = MS_IOCB_TYPE;
36 ms_pkt->entry_count = 1;
37 SET_TARGET_ID(ha, ms_pkt->loop_id, SIMPLE_NAME_SERVER);
Bart Van Asschead950362015-07-09 07:24:08 -070038 ms_pkt->control_flags = cpu_to_le16(CF_READ | CF_HEAD_TAG);
Andrew Vasquez00a537b2008-02-28 14:06:11 -080039 ms_pkt->timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
Bart Van Asschead950362015-07-09 07:24:08 -070040 ms_pkt->cmd_dsd_count = cpu_to_le16(1);
41 ms_pkt->total_dsd_count = cpu_to_le16(2);
Quinn Tran726b8542017-01-19 22:28:00 -080042 ms_pkt->rsp_bytecount = cpu_to_le32(arg->rsp_size);
43 ms_pkt->req_bytecount = cpu_to_le32(arg->req_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
Quinn Tran726b8542017-01-19 22:28:00 -080045 ms_pkt->dseg_req_address[0] = cpu_to_le32(LSD(arg->req_dma));
46 ms_pkt->dseg_req_address[1] = cpu_to_le32(MSD(arg->req_dma));
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 ms_pkt->dseg_req_length = ms_pkt->req_bytecount;
48
Quinn Tran726b8542017-01-19 22:28:00 -080049 ms_pkt->dseg_rsp_address[0] = cpu_to_le32(LSD(arg->rsp_dma));
50 ms_pkt->dseg_rsp_address[1] = cpu_to_le32(MSD(arg->rsp_dma));
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 ms_pkt->dseg_rsp_length = ms_pkt->rsp_bytecount;
52
Joe Carnucciofabbb8d2013-08-27 01:37:40 -040053 vha->qla_stats.control_requests++;
54
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 return (ms_pkt);
56}
57
58/**
Andrew Vasquez8c958a92005-07-06 10:30:47 -070059 * qla24xx_prep_ms_iocb() - Prepare common CT IOCB fields for SNS CT query.
60 * @ha: HA context
61 * @req_size: request size in bytes
62 * @rsp_size: response size in bytes
63 *
64 * Returns a pointer to the @ha's ms_iocb.
65 */
66void *
Quinn Tran726b8542017-01-19 22:28:00 -080067qla24xx_prep_ms_iocb(scsi_qla_host_t *vha, struct ct_arg *arg)
Andrew Vasquez8c958a92005-07-06 10:30:47 -070068{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080069 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez8c958a92005-07-06 10:30:47 -070070 struct ct_entry_24xx *ct_pkt;
71
Quinn Tran726b8542017-01-19 22:28:00 -080072 ct_pkt = (struct ct_entry_24xx *)arg->iocb;
Andrew Vasquez8c958a92005-07-06 10:30:47 -070073 memset(ct_pkt, 0, sizeof(struct ct_entry_24xx));
74
75 ct_pkt->entry_type = CT_IOCB_TYPE;
76 ct_pkt->entry_count = 1;
Quinn Tran726b8542017-01-19 22:28:00 -080077 ct_pkt->nport_handle = cpu_to_le16(arg->nport_handle);
Andrew Vasquez00a537b2008-02-28 14:06:11 -080078 ct_pkt->timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
Bart Van Asschead950362015-07-09 07:24:08 -070079 ct_pkt->cmd_dsd_count = cpu_to_le16(1);
80 ct_pkt->rsp_dsd_count = cpu_to_le16(1);
Quinn Tran726b8542017-01-19 22:28:00 -080081 ct_pkt->rsp_byte_count = cpu_to_le32(arg->rsp_size);
82 ct_pkt->cmd_byte_count = cpu_to_le32(arg->req_size);
Andrew Vasquez8c958a92005-07-06 10:30:47 -070083
Quinn Tran726b8542017-01-19 22:28:00 -080084 ct_pkt->dseg_0_address[0] = cpu_to_le32(LSD(arg->req_dma));
85 ct_pkt->dseg_0_address[1] = cpu_to_le32(MSD(arg->req_dma));
Andrew Vasquez8c958a92005-07-06 10:30:47 -070086 ct_pkt->dseg_0_len = ct_pkt->cmd_byte_count;
87
Quinn Tran726b8542017-01-19 22:28:00 -080088 ct_pkt->dseg_1_address[0] = cpu_to_le32(LSD(arg->rsp_dma));
89 ct_pkt->dseg_1_address[1] = cpu_to_le32(MSD(arg->rsp_dma));
Andrew Vasquez8c958a92005-07-06 10:30:47 -070090 ct_pkt->dseg_1_len = ct_pkt->rsp_byte_count;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080091 ct_pkt->vp_index = vha->vp_idx;
Andrew Vasquez8c958a92005-07-06 10:30:47 -070092
Joe Carnucciofabbb8d2013-08-27 01:37:40 -040093 vha->qla_stats.control_requests++;
94
Andrew Vasquez8c958a92005-07-06 10:30:47 -070095 return (ct_pkt);
96}
97
98/**
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 * qla2x00_prep_ct_req() - Prepare common CT request fields for SNS query.
100 * @ct_req: CT request buffer
101 * @cmd: GS command
102 * @rsp_size: response size in bytes
103 *
104 * Returns a pointer to the intitialized @ct_req.
105 */
106static inline struct ct_sns_req *
Bart Van Assche6ec6f902013-06-25 11:27:28 -0400107qla2x00_prep_ct_req(struct ct_sns_pkt *p, uint16_t cmd, uint16_t rsp_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108{
Bart Van Assche6ec6f902013-06-25 11:27:28 -0400109 memset(p, 0, sizeof(struct ct_sns_pkt));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
Bart Van Assche6ec6f902013-06-25 11:27:28 -0400111 p->p.req.header.revision = 0x01;
112 p->p.req.header.gs_type = 0xFC;
113 p->p.req.header.gs_subtype = 0x02;
114 p->p.req.command = cpu_to_be16(cmd);
115 p->p.req.max_rsp_size = cpu_to_be16((rsp_size - 16) / 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
Bart Van Assche6ec6f902013-06-25 11:27:28 -0400117 return &p->p.req;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118}
119
Quinn Tran726b8542017-01-19 22:28:00 -0800120int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800121qla2x00_chk_ms_status(scsi_qla_host_t *vha, ms_iocb_entry_t *ms_pkt,
Andrew Vasquez8c958a92005-07-06 10:30:47 -0700122 struct ct_sns_rsp *ct_rsp, const char *routine)
123{
124 int rval;
125 uint16_t comp_status;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800126 struct qla_hw_data *ha = vha->hw;
Quinn Tranb98ae0d2017-06-02 09:12:00 -0700127 bool lid_is_sns = false;
Andrew Vasquez8c958a92005-07-06 10:30:47 -0700128
129 rval = QLA_FUNCTION_FAILED;
130 if (ms_pkt->entry_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700131 ql_dbg(ql_dbg_disc, vha, 0x2031,
132 "%s failed, error status (%x) on port_id: %02x%02x%02x.\n",
133 routine, ms_pkt->entry_status, vha->d_id.b.domain,
134 vha->d_id.b.area, vha->d_id.b.al_pa);
Andrew Vasquez8c958a92005-07-06 10:30:47 -0700135 } else {
Andrew Vasqueze4289242007-07-19 15:05:56 -0700136 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquezcdfc82a2006-12-13 19:20:26 -0800137 comp_status = le16_to_cpu(
138 ((struct ct_entry_24xx *)ms_pkt)->comp_status);
Andrew Vasquez8c958a92005-07-06 10:30:47 -0700139 else
140 comp_status = le16_to_cpu(ms_pkt->status);
141 switch (comp_status) {
142 case CS_COMPLETE:
143 case CS_DATA_UNDERRUN:
144 case CS_DATA_OVERRUN: /* Overrun? */
145 if (ct_rsp->header.response !=
Bart Van Asschead950362015-07-09 07:24:08 -0700146 cpu_to_be16(CT_ACCEPT_RESPONSE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700147 ql_dbg(ql_dbg_disc + ql_dbg_buffer, vha, 0x2077,
Milan P Gandhi5a68a1c2017-03-31 14:37:04 -0700148 "%s failed rejected request on port_id: %02x%02x%02x Completion status 0x%x, response 0x%x\n",
Himanshu Madhanidf57cab2014-09-25 05:16:46 -0400149 routine, vha->d_id.b.domain,
150 vha->d_id.b.area, vha->d_id.b.al_pa,
151 comp_status, ct_rsp->header.response);
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700152 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha,
153 0x2078, (uint8_t *)&ct_rsp->header,
154 sizeof(struct ct_rsp_hdr));
Andrew Vasquez4346b142006-12-13 19:20:28 -0800155 rval = QLA_INVALID_COMMAND;
Andrew Vasquez8c958a92005-07-06 10:30:47 -0700156 } else
157 rval = QLA_SUCCESS;
158 break;
Quinn Tranb98ae0d2017-06-02 09:12:00 -0700159 case CS_PORT_LOGGED_OUT:
160 if (IS_FWI2_CAPABLE(ha)) {
161 if (le16_to_cpu(ms_pkt->loop_id.extended) ==
162 NPH_SNS)
163 lid_is_sns = true;
164 } else {
165 if (le16_to_cpu(ms_pkt->loop_id.extended) ==
166 SIMPLE_NAME_SERVER)
167 lid_is_sns = true;
168 }
169 if (lid_is_sns) {
170 ql_dbg(ql_dbg_async, vha, 0x502b,
171 "%s failed, Name server has logged out",
172 routine);
173 rval = QLA_NOT_LOGGED_IN;
174 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
175 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
176 }
177 break;
Quinn Tran25ad76b2017-12-04 14:45:01 -0800178 case CS_TIMEOUT:
179 rval = QLA_FUNCTION_TIMEOUT;
180 /* drop through */
Andrew Vasquez8c958a92005-07-06 10:30:47 -0700181 default:
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700182 ql_dbg(ql_dbg_disc, vha, 0x2033,
183 "%s failed, completion status (%x) on port_id: "
184 "%02x%02x%02x.\n", routine, comp_status,
Giridhar Malavalicf2d7712011-02-23 15:27:09 -0800185 vha->d_id.b.domain, vha->d_id.b.area,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700186 vha->d_id.b.al_pa);
Andrew Vasquez8c958a92005-07-06 10:30:47 -0700187 break;
188 }
189 }
190 return rval;
191}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192
193/**
194 * qla2x00_ga_nxt() - SNS scan for fabric devices via GA_NXT command.
195 * @ha: HA context
196 * @fcport: fcport entry to updated
197 *
198 * Returns 0 on success.
199 */
200int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800201qla2x00_ga_nxt(scsi_qla_host_t *vha, fc_port_t *fcport)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202{
203 int rval;
204
205 ms_iocb_entry_t *ms_pkt;
206 struct ct_sns_req *ct_req;
207 struct ct_sns_rsp *ct_rsp;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800208 struct qla_hw_data *ha = vha->hw;
Quinn Tran726b8542017-01-19 22:28:00 -0800209 struct ct_arg arg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800211 if (IS_QLA2100(ha) || IS_QLA2200(ha))
212 return qla2x00_sns_ga_nxt(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213
Quinn Tran726b8542017-01-19 22:28:00 -0800214 arg.iocb = ha->ms_iocb;
215 arg.req_dma = ha->ct_sns_dma;
216 arg.rsp_dma = ha->ct_sns_dma;
217 arg.req_size = GA_NXT_REQ_SIZE;
218 arg.rsp_size = GA_NXT_RSP_SIZE;
219 arg.nport_handle = NPH_SNS;
220
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 /* Issue GA_NXT */
222 /* Prepare common MS IOCB */
Quinn Tran726b8542017-01-19 22:28:00 -0800223 ms_pkt = ha->isp_ops->prep_ms_iocb(vha, &arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224
225 /* Prepare CT request */
Bart Van Assche6ec6f902013-06-25 11:27:28 -0400226 ct_req = qla2x00_prep_ct_req(ha->ct_sns, GA_NXT_CMD,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 GA_NXT_RSP_SIZE);
228 ct_rsp = &ha->ct_sns->p.rsp;
229
230 /* Prepare CT arguments -- port_id */
231 ct_req->req.port_id.port_id[0] = fcport->d_id.b.domain;
232 ct_req->req.port_id.port_id[1] = fcport->d_id.b.area;
233 ct_req->req.port_id.port_id[2] = fcport->d_id.b.al_pa;
234
235 /* Execute MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800236 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 sizeof(ms_iocb_entry_t));
238 if (rval != QLA_SUCCESS) {
239 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700240 ql_dbg(ql_dbg_disc, vha, 0x2062,
241 "GA_NXT issue IOCB failed (%d).\n", rval);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800242 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, "GA_NXT") !=
Andrew Vasquez8c958a92005-07-06 10:30:47 -0700243 QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 rval = QLA_FUNCTION_FAILED;
245 } else {
246 /* Populate fc_port_t entry. */
247 fcport->d_id.b.domain = ct_rsp->rsp.ga_nxt.port_id[0];
248 fcport->d_id.b.area = ct_rsp->rsp.ga_nxt.port_id[1];
249 fcport->d_id.b.al_pa = ct_rsp->rsp.ga_nxt.port_id[2];
250
251 memcpy(fcport->node_name, ct_rsp->rsp.ga_nxt.node_name,
252 WWN_SIZE);
253 memcpy(fcport->port_name, ct_rsp->rsp.ga_nxt.port_name,
254 WWN_SIZE);
255
Armen Baloyana72b9902012-11-21 02:40:30 -0500256 fcport->fc4_type = (ct_rsp->rsp.ga_nxt.fc4_types[2] & BIT_0) ?
257 FC4_TYPE_FCP_SCSI : FC4_TYPE_OTHER;
258
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 if (ct_rsp->rsp.ga_nxt.port_type != NS_N_PORT_TYPE &&
260 ct_rsp->rsp.ga_nxt.port_type != NS_NL_PORT_TYPE)
261 fcport->d_id.b.domain = 0xf0;
262
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700263 ql_dbg(ql_dbg_disc, vha, 0x2063,
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -0400264 "GA_NXT entry - nn %8phN pn %8phN "
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700265 "port_id=%02x%02x%02x.\n",
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -0400266 fcport->node_name, fcport->port_name,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 fcport->d_id.b.domain, fcport->d_id.b.area,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700268 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 }
270
271 return (rval);
272}
273
Chad Dupuis642ef982012-02-09 11:15:57 -0800274static inline int
275qla2x00_gid_pt_rsp_size(scsi_qla_host_t *vha)
276{
277 return vha->hw->max_fibre_devices * 4 + 16;
278}
279
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280/**
281 * qla2x00_gid_pt() - SNS scan for fabric devices via GID_PT command.
282 * @ha: HA context
283 * @list: switch info entries to populate
284 *
285 * NOTE: Non-Nx_Ports are not requested.
286 *
287 * Returns 0 on success.
288 */
289int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800290qla2x00_gid_pt(scsi_qla_host_t *vha, sw_info_t *list)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291{
292 int rval;
293 uint16_t i;
294
295 ms_iocb_entry_t *ms_pkt;
296 struct ct_sns_req *ct_req;
297 struct ct_sns_rsp *ct_rsp;
298
299 struct ct_sns_gid_pt_data *gid_data;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800300 struct qla_hw_data *ha = vha->hw;
Chad Dupuis642ef982012-02-09 11:15:57 -0800301 uint16_t gid_pt_rsp_size;
Quinn Tran726b8542017-01-19 22:28:00 -0800302 struct ct_arg arg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800304 if (IS_QLA2100(ha) || IS_QLA2200(ha))
305 return qla2x00_sns_gid_pt(vha, list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306
307 gid_data = NULL;
Chad Dupuis642ef982012-02-09 11:15:57 -0800308 gid_pt_rsp_size = qla2x00_gid_pt_rsp_size(vha);
Quinn Tran726b8542017-01-19 22:28:00 -0800309
310 arg.iocb = ha->ms_iocb;
311 arg.req_dma = ha->ct_sns_dma;
312 arg.rsp_dma = ha->ct_sns_dma;
313 arg.req_size = GID_PT_REQ_SIZE;
314 arg.rsp_size = gid_pt_rsp_size;
315 arg.nport_handle = NPH_SNS;
316
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 /* Issue GID_PT */
318 /* Prepare common MS IOCB */
Quinn Tran726b8542017-01-19 22:28:00 -0800319 ms_pkt = ha->isp_ops->prep_ms_iocb(vha, &arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320
321 /* Prepare CT request */
Bart Van Assche6ec6f902013-06-25 11:27:28 -0400322 ct_req = qla2x00_prep_ct_req(ha->ct_sns, GID_PT_CMD, gid_pt_rsp_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 ct_rsp = &ha->ct_sns->p.rsp;
324
325 /* Prepare CT arguments -- port_type */
326 ct_req->req.gid_pt.port_type = NS_NX_PORT_TYPE;
327
328 /* Execute MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800329 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 sizeof(ms_iocb_entry_t));
331 if (rval != QLA_SUCCESS) {
332 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700333 ql_dbg(ql_dbg_disc, vha, 0x2055,
334 "GID_PT issue IOCB failed (%d).\n", rval);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800335 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, "GID_PT") !=
Andrew Vasquez8c958a92005-07-06 10:30:47 -0700336 QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 rval = QLA_FUNCTION_FAILED;
338 } else {
339 /* Set port IDs in switch info list. */
Chad Dupuis642ef982012-02-09 11:15:57 -0800340 for (i = 0; i < ha->max_fibre_devices; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 gid_data = &ct_rsp->rsp.gid_pt.entries[i];
342 list[i].d_id.b.domain = gid_data->port_id[0];
343 list[i].d_id.b.area = gid_data->port_id[1];
344 list[i].d_id.b.al_pa = gid_data->port_id[2];
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -0700345 memset(list[i].fabric_port_name, 0, WWN_SIZE);
346 list[i].fp_speed = PORT_SPEED_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347
348 /* Last one exit. */
349 if (gid_data->control_byte & BIT_7) {
350 list[i].d_id.b.rsvd_1 = gid_data->control_byte;
351 break;
352 }
353 }
354
355 /*
356 * If we've used all available slots, then the switch is
357 * reporting back more devices than we can handle with this
358 * single call. Return a failed status, and let GA_NXT handle
359 * the overload.
360 */
Chad Dupuis642ef982012-02-09 11:15:57 -0800361 if (i == ha->max_fibre_devices)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 rval = QLA_FUNCTION_FAILED;
363 }
364
365 return (rval);
366}
367
368/**
369 * qla2x00_gpn_id() - SNS Get Port Name (GPN_ID) query.
370 * @ha: HA context
371 * @list: switch info entries to populate
372 *
373 * Returns 0 on success.
374 */
375int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800376qla2x00_gpn_id(scsi_qla_host_t *vha, sw_info_t *list)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377{
Chad Dupuis642ef982012-02-09 11:15:57 -0800378 int rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 uint16_t i;
380
381 ms_iocb_entry_t *ms_pkt;
382 struct ct_sns_req *ct_req;
383 struct ct_sns_rsp *ct_rsp;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800384 struct qla_hw_data *ha = vha->hw;
Quinn Tran726b8542017-01-19 22:28:00 -0800385 struct ct_arg arg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800387 if (IS_QLA2100(ha) || IS_QLA2200(ha))
388 return qla2x00_sns_gpn_id(vha, list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389
Quinn Tran726b8542017-01-19 22:28:00 -0800390 arg.iocb = ha->ms_iocb;
391 arg.req_dma = ha->ct_sns_dma;
392 arg.rsp_dma = ha->ct_sns_dma;
393 arg.req_size = GPN_ID_REQ_SIZE;
394 arg.rsp_size = GPN_ID_RSP_SIZE;
395 arg.nport_handle = NPH_SNS;
396
Chad Dupuis642ef982012-02-09 11:15:57 -0800397 for (i = 0; i < ha->max_fibre_devices; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 /* Issue GPN_ID */
399 /* Prepare common MS IOCB */
Quinn Tran726b8542017-01-19 22:28:00 -0800400 ms_pkt = ha->isp_ops->prep_ms_iocb(vha, &arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401
402 /* Prepare CT request */
Bart Van Assche6ec6f902013-06-25 11:27:28 -0400403 ct_req = qla2x00_prep_ct_req(ha->ct_sns, GPN_ID_CMD,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 GPN_ID_RSP_SIZE);
405 ct_rsp = &ha->ct_sns->p.rsp;
406
407 /* Prepare CT arguments -- port_id */
408 ct_req->req.port_id.port_id[0] = list[i].d_id.b.domain;
409 ct_req->req.port_id.port_id[1] = list[i].d_id.b.area;
410 ct_req->req.port_id.port_id[2] = list[i].d_id.b.al_pa;
411
412 /* Execute MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800413 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 sizeof(ms_iocb_entry_t));
415 if (rval != QLA_SUCCESS) {
416 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700417 ql_dbg(ql_dbg_disc, vha, 0x2056,
418 "GPN_ID issue IOCB failed (%d).\n", rval);
Arun Easidafdf892012-02-09 11:16:00 -0800419 break;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800420 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp,
Andrew Vasquez8c958a92005-07-06 10:30:47 -0700421 "GPN_ID") != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 rval = QLA_FUNCTION_FAILED;
Arun Easidafdf892012-02-09 11:16:00 -0800423 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 } else {
425 /* Save portname */
426 memcpy(list[i].port_name,
427 ct_rsp->rsp.gpn_id.port_name, WWN_SIZE);
428 }
429
430 /* Last device exit. */
431 if (list[i].d_id.b.rsvd_1 != 0)
432 break;
433 }
434
435 return (rval);
436}
437
438/**
439 * qla2x00_gnn_id() - SNS Get Node Name (GNN_ID) query.
440 * @ha: HA context
441 * @list: switch info entries to populate
442 *
443 * Returns 0 on success.
444 */
445int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800446qla2x00_gnn_id(scsi_qla_host_t *vha, sw_info_t *list)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447{
Chad Dupuis642ef982012-02-09 11:15:57 -0800448 int rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 uint16_t i;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800450 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 ms_iocb_entry_t *ms_pkt;
452 struct ct_sns_req *ct_req;
453 struct ct_sns_rsp *ct_rsp;
Quinn Tran726b8542017-01-19 22:28:00 -0800454 struct ct_arg arg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800456 if (IS_QLA2100(ha) || IS_QLA2200(ha))
457 return qla2x00_sns_gnn_id(vha, list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458
Quinn Tran726b8542017-01-19 22:28:00 -0800459 arg.iocb = ha->ms_iocb;
460 arg.req_dma = ha->ct_sns_dma;
461 arg.rsp_dma = ha->ct_sns_dma;
462 arg.req_size = GNN_ID_REQ_SIZE;
463 arg.rsp_size = GNN_ID_RSP_SIZE;
464 arg.nport_handle = NPH_SNS;
465
Chad Dupuis642ef982012-02-09 11:15:57 -0800466 for (i = 0; i < ha->max_fibre_devices; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 /* Issue GNN_ID */
468 /* Prepare common MS IOCB */
Quinn Tran726b8542017-01-19 22:28:00 -0800469 ms_pkt = ha->isp_ops->prep_ms_iocb(vha, &arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470
471 /* Prepare CT request */
Bart Van Assche6ec6f902013-06-25 11:27:28 -0400472 ct_req = qla2x00_prep_ct_req(ha->ct_sns, GNN_ID_CMD,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 GNN_ID_RSP_SIZE);
474 ct_rsp = &ha->ct_sns->p.rsp;
475
476 /* Prepare CT arguments -- port_id */
477 ct_req->req.port_id.port_id[0] = list[i].d_id.b.domain;
478 ct_req->req.port_id.port_id[1] = list[i].d_id.b.area;
479 ct_req->req.port_id.port_id[2] = list[i].d_id.b.al_pa;
480
481 /* Execute MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800482 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 sizeof(ms_iocb_entry_t));
484 if (rval != QLA_SUCCESS) {
485 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700486 ql_dbg(ql_dbg_disc, vha, 0x2057,
487 "GNN_ID issue IOCB failed (%d).\n", rval);
Arun Easidafdf892012-02-09 11:16:00 -0800488 break;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800489 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp,
Andrew Vasquez8c958a92005-07-06 10:30:47 -0700490 "GNN_ID") != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 rval = QLA_FUNCTION_FAILED;
Arun Easidafdf892012-02-09 11:16:00 -0800492 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 } else {
494 /* Save nodename */
495 memcpy(list[i].node_name,
496 ct_rsp->rsp.gnn_id.node_name, WWN_SIZE);
497
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700498 ql_dbg(ql_dbg_disc, vha, 0x2058,
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -0400499 "GID_PT entry - nn %8phN pn %8phN "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 "portid=%02x%02x%02x.\n",
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -0400501 list[i].node_name, list[i].port_name,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 list[i].d_id.b.domain, list[i].d_id.b.area,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700503 list[i].d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 }
505
506 /* Last device exit. */
507 if (list[i].d_id.b.rsvd_1 != 0)
508 break;
509 }
510
511 return (rval);
512}
513
514/**
515 * qla2x00_rft_id() - SNS Register FC-4 TYPEs (RFT_ID) supported by the HBA.
516 * @ha: HA context
517 *
518 * Returns 0 on success.
519 */
520int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800521qla2x00_rft_id(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522{
523 int rval;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800524 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 ms_iocb_entry_t *ms_pkt;
526 struct ct_sns_req *ct_req;
527 struct ct_sns_rsp *ct_rsp;
Quinn Tran726b8542017-01-19 22:28:00 -0800528 struct ct_arg arg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800530 if (IS_QLA2100(ha) || IS_QLA2200(ha))
531 return qla2x00_sns_rft_id(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532
Quinn Tran726b8542017-01-19 22:28:00 -0800533 arg.iocb = ha->ms_iocb;
534 arg.req_dma = ha->ct_sns_dma;
535 arg.rsp_dma = ha->ct_sns_dma;
536 arg.req_size = RFT_ID_REQ_SIZE;
537 arg.rsp_size = RFT_ID_RSP_SIZE;
538 arg.nport_handle = NPH_SNS;
539
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 /* Issue RFT_ID */
541 /* Prepare common MS IOCB */
Quinn Tran726b8542017-01-19 22:28:00 -0800542 ms_pkt = ha->isp_ops->prep_ms_iocb(vha, &arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543
544 /* Prepare CT request */
Bart Van Assche6ec6f902013-06-25 11:27:28 -0400545 ct_req = qla2x00_prep_ct_req(ha->ct_sns, RFT_ID_CMD,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 RFT_ID_RSP_SIZE);
547 ct_rsp = &ha->ct_sns->p.rsp;
548
549 /* Prepare CT arguments -- port_id, FC-4 types */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800550 ct_req->req.rft_id.port_id[0] = vha->d_id.b.domain;
551 ct_req->req.rft_id.port_id[1] = vha->d_id.b.area;
552 ct_req->req.rft_id.port_id[2] = vha->d_id.b.al_pa;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553
554 ct_req->req.rft_id.fc4_types[2] = 0x01; /* FCP-3 */
555
Duane Grigsbyd3bae932017-06-21 13:48:44 -0700556 if (vha->flags.nvme_enabled)
557 ct_req->req.rft_id.fc4_types[6] = 1; /* NVMe type 28h */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 /* Execute MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800559 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 sizeof(ms_iocb_entry_t));
561 if (rval != QLA_SUCCESS) {
562 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700563 ql_dbg(ql_dbg_disc, vha, 0x2043,
564 "RFT_ID issue IOCB failed (%d).\n", rval);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800565 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, "RFT_ID") !=
Andrew Vasquez8c958a92005-07-06 10:30:47 -0700566 QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 rval = QLA_FUNCTION_FAILED;
568 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700569 ql_dbg(ql_dbg_disc, vha, 0x2044,
570 "RFT_ID exiting normally.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 }
572
573 return (rval);
574}
575
576/**
577 * qla2x00_rff_id() - SNS Register FC-4 Features (RFF_ID) supported by the HBA.
578 * @ha: HA context
579 *
580 * Returns 0 on success.
581 */
582int
Duane Grigsbyd3bae932017-06-21 13:48:44 -0700583qla2x00_rff_id(scsi_qla_host_t *vha, u8 type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584{
585 int rval;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800586 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 ms_iocb_entry_t *ms_pkt;
588 struct ct_sns_req *ct_req;
589 struct ct_sns_rsp *ct_rsp;
Quinn Tran726b8542017-01-19 22:28:00 -0800590 struct ct_arg arg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591
592 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700593 ql_dbg(ql_dbg_disc, vha, 0x2046,
594 "RFF_ID call not supported on ISP2100/ISP2200.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 return (QLA_SUCCESS);
596 }
597
Quinn Tran726b8542017-01-19 22:28:00 -0800598 arg.iocb = ha->ms_iocb;
599 arg.req_dma = ha->ct_sns_dma;
600 arg.rsp_dma = ha->ct_sns_dma;
601 arg.req_size = RFF_ID_REQ_SIZE;
602 arg.rsp_size = RFF_ID_RSP_SIZE;
603 arg.nport_handle = NPH_SNS;
604
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 /* Issue RFF_ID */
606 /* Prepare common MS IOCB */
Quinn Tran726b8542017-01-19 22:28:00 -0800607 ms_pkt = ha->isp_ops->prep_ms_iocb(vha, &arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608
609 /* Prepare CT request */
Bart Van Assche6ec6f902013-06-25 11:27:28 -0400610 ct_req = qla2x00_prep_ct_req(ha->ct_sns, RFF_ID_CMD,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 RFF_ID_RSP_SIZE);
612 ct_rsp = &ha->ct_sns->p.rsp;
613
614 /* Prepare CT arguments -- port_id, FC-4 feature, FC-4 type */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800615 ct_req->req.rff_id.port_id[0] = vha->d_id.b.domain;
616 ct_req->req.rff_id.port_id[1] = vha->d_id.b.area;
617 ct_req->req.rff_id.port_id[2] = vha->d_id.b.al_pa;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400619 qlt_rff_id(vha, ct_req);
620
Duane Grigsbyd3bae932017-06-21 13:48:44 -0700621 ct_req->req.rff_id.fc4_type = type; /* SCSI - FCP */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622
623 /* Execute MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800624 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 sizeof(ms_iocb_entry_t));
626 if (rval != QLA_SUCCESS) {
627 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700628 ql_dbg(ql_dbg_disc, vha, 0x2047,
629 "RFF_ID issue IOCB failed (%d).\n", rval);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800630 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, "RFF_ID") !=
Andrew Vasquez8c958a92005-07-06 10:30:47 -0700631 QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 rval = QLA_FUNCTION_FAILED;
633 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700634 ql_dbg(ql_dbg_disc, vha, 0x2048,
635 "RFF_ID exiting normally.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 }
637
638 return (rval);
639}
640
641/**
642 * qla2x00_rnn_id() - SNS Register Node Name (RNN_ID) of the HBA.
643 * @ha: HA context
644 *
645 * Returns 0 on success.
646 */
647int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800648qla2x00_rnn_id(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649{
650 int rval;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800651 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 ms_iocb_entry_t *ms_pkt;
653 struct ct_sns_req *ct_req;
654 struct ct_sns_rsp *ct_rsp;
Quinn Tran726b8542017-01-19 22:28:00 -0800655 struct ct_arg arg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800657 if (IS_QLA2100(ha) || IS_QLA2200(ha))
658 return qla2x00_sns_rnn_id(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659
Quinn Tran726b8542017-01-19 22:28:00 -0800660 arg.iocb = ha->ms_iocb;
661 arg.req_dma = ha->ct_sns_dma;
662 arg.rsp_dma = ha->ct_sns_dma;
663 arg.req_size = RNN_ID_REQ_SIZE;
664 arg.rsp_size = RNN_ID_RSP_SIZE;
665 arg.nport_handle = NPH_SNS;
666
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 /* Issue RNN_ID */
668 /* Prepare common MS IOCB */
Quinn Tran726b8542017-01-19 22:28:00 -0800669 ms_pkt = ha->isp_ops->prep_ms_iocb(vha, &arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670
671 /* Prepare CT request */
Bart Van Assche6ec6f902013-06-25 11:27:28 -0400672 ct_req = qla2x00_prep_ct_req(ha->ct_sns, RNN_ID_CMD, RNN_ID_RSP_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 ct_rsp = &ha->ct_sns->p.rsp;
674
675 /* Prepare CT arguments -- port_id, node_name */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800676 ct_req->req.rnn_id.port_id[0] = vha->d_id.b.domain;
677 ct_req->req.rnn_id.port_id[1] = vha->d_id.b.area;
678 ct_req->req.rnn_id.port_id[2] = vha->d_id.b.al_pa;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800680 memcpy(ct_req->req.rnn_id.node_name, vha->node_name, WWN_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681
682 /* Execute MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800683 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 sizeof(ms_iocb_entry_t));
685 if (rval != QLA_SUCCESS) {
686 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700687 ql_dbg(ql_dbg_disc, vha, 0x204d,
688 "RNN_ID issue IOCB failed (%d).\n", rval);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800689 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, "RNN_ID") !=
Andrew Vasquez8c958a92005-07-06 10:30:47 -0700690 QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 rval = QLA_FUNCTION_FAILED;
692 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700693 ql_dbg(ql_dbg_disc, vha, 0x204e,
694 "RNN_ID exiting normally.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 }
696
697 return (rval);
698}
699
Andrew Vasquez1620f7c2006-10-02 12:00:44 -0700700void
Himanshu Madhanidf57cab2014-09-25 05:16:46 -0400701qla2x00_get_sym_node_name(scsi_qla_host_t *vha, uint8_t *snn, size_t size)
Andrew Vasquez1620f7c2006-10-02 12:00:44 -0700702{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800703 struct qla_hw_data *ha = vha->hw;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400704
705 if (IS_QLAFX00(ha))
Himanshu Madhanidf57cab2014-09-25 05:16:46 -0400706 snprintf(snn, size, "%s FW:v%s DVR:v%s", ha->model_number,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400707 ha->mr.fw_version, qla2x00_version_str);
708 else
Himanshu Madhanidf57cab2014-09-25 05:16:46 -0400709 snprintf(snn, size,
710 "%s FW:v%d.%02d.%02d DVR:v%s", ha->model_number,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400711 ha->fw_major_version, ha->fw_minor_version,
712 ha->fw_subminor_version, qla2x00_version_str);
Andrew Vasquez1620f7c2006-10-02 12:00:44 -0700713}
714
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715/**
716 * qla2x00_rsnn_nn() - SNS Register Symbolic Node Name (RSNN_NN) of the HBA.
717 * @ha: HA context
718 *
719 * Returns 0 on success.
720 */
721int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800722qla2x00_rsnn_nn(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723{
724 int rval;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800725 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 ms_iocb_entry_t *ms_pkt;
727 struct ct_sns_req *ct_req;
728 struct ct_sns_rsp *ct_rsp;
Quinn Tran726b8542017-01-19 22:28:00 -0800729 struct ct_arg arg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730
731 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700732 ql_dbg(ql_dbg_disc, vha, 0x2050,
733 "RSNN_ID call unsupported on ISP2100/ISP2200.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 return (QLA_SUCCESS);
735 }
736
Quinn Tran726b8542017-01-19 22:28:00 -0800737 arg.iocb = ha->ms_iocb;
738 arg.req_dma = ha->ct_sns_dma;
739 arg.rsp_dma = ha->ct_sns_dma;
740 arg.req_size = 0;
741 arg.rsp_size = RSNN_NN_RSP_SIZE;
742 arg.nport_handle = NPH_SNS;
743
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 /* Issue RSNN_NN */
745 /* Prepare common MS IOCB */
746 /* Request size adjusted after CT preparation */
Quinn Tran726b8542017-01-19 22:28:00 -0800747 ms_pkt = ha->isp_ops->prep_ms_iocb(vha, &arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748
749 /* Prepare CT request */
Bart Van Assche6ec6f902013-06-25 11:27:28 -0400750 ct_req = qla2x00_prep_ct_req(ha->ct_sns, RSNN_NN_CMD,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 RSNN_NN_RSP_SIZE);
752 ct_rsp = &ha->ct_sns->p.rsp;
753
754 /* Prepare CT arguments -- node_name, symbolic node_name, size */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800755 memcpy(ct_req->req.rsnn_nn.node_name, vha->node_name, WWN_SIZE);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700756
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 /* Prepare the Symbolic Node Name */
Himanshu Madhanidf57cab2014-09-25 05:16:46 -0400758 qla2x00_get_sym_node_name(vha, ct_req->req.rsnn_nn.sym_node_name,
759 sizeof(ct_req->req.rsnn_nn.sym_node_name));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760
761 /* Calculate SNN length */
Andrew Vasquez1620f7c2006-10-02 12:00:44 -0700762 ct_req->req.rsnn_nn.name_len =
763 (uint8_t)strlen(ct_req->req.rsnn_nn.sym_node_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764
765 /* Update MS IOCB request */
766 ms_pkt->req_bytecount =
767 cpu_to_le32(24 + 1 + ct_req->req.rsnn_nn.name_len);
768 ms_pkt->dseg_req_length = ms_pkt->req_bytecount;
769
770 /* Execute MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800771 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 sizeof(ms_iocb_entry_t));
773 if (rval != QLA_SUCCESS) {
774 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700775 ql_dbg(ql_dbg_disc, vha, 0x2051,
776 "RSNN_NN issue IOCB failed (%d).\n", rval);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800777 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, "RSNN_NN") !=
Andrew Vasquez8c958a92005-07-06 10:30:47 -0700778 QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779 rval = QLA_FUNCTION_FAILED;
780 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700781 ql_dbg(ql_dbg_disc, vha, 0x2052,
782 "RSNN_NN exiting normally.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783 }
784
785 return (rval);
786}
787
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788/**
789 * qla2x00_prep_sns_cmd() - Prepare common SNS command request fields for query.
790 * @ha: HA context
791 * @cmd: GS command
792 * @scmd_len: Subcommand length
793 * @data_size: response size in bytes
794 *
795 * Returns a pointer to the @ha's sns_cmd.
796 */
797static inline struct sns_cmd_pkt *
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800798qla2x00_prep_sns_cmd(scsi_qla_host_t *vha, uint16_t cmd, uint16_t scmd_len,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 uint16_t data_size)
800{
801 uint16_t wc;
802 struct sns_cmd_pkt *sns_cmd;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800803 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804
805 sns_cmd = ha->sns_cmd;
806 memset(sns_cmd, 0, sizeof(struct sns_cmd_pkt));
807 wc = data_size / 2; /* Size in 16bit words. */
808 sns_cmd->p.cmd.buffer_length = cpu_to_le16(wc);
809 sns_cmd->p.cmd.buffer_address[0] = cpu_to_le32(LSD(ha->sns_cmd_dma));
810 sns_cmd->p.cmd.buffer_address[1] = cpu_to_le32(MSD(ha->sns_cmd_dma));
811 sns_cmd->p.cmd.subcommand_length = cpu_to_le16(scmd_len);
812 sns_cmd->p.cmd.subcommand = cpu_to_le16(cmd);
813 wc = (data_size - 16) / 4; /* Size in 32bit words. */
814 sns_cmd->p.cmd.size = cpu_to_le16(wc);
815
Joe Carnucciofabbb8d2013-08-27 01:37:40 -0400816 vha->qla_stats.control_requests++;
817
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 return (sns_cmd);
819}
820
821/**
822 * qla2x00_sns_ga_nxt() - SNS scan for fabric devices via GA_NXT command.
823 * @ha: HA context
824 * @fcport: fcport entry to updated
825 *
826 * This command uses the old Exectute SNS Command mailbox routine.
827 *
828 * Returns 0 on success.
829 */
830static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800831qla2x00_sns_ga_nxt(scsi_qla_host_t *vha, fc_port_t *fcport)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832{
Chad Dupuis642ef982012-02-09 11:15:57 -0800833 int rval = QLA_SUCCESS;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800834 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 struct sns_cmd_pkt *sns_cmd;
836
837 /* Issue GA_NXT. */
838 /* Prepare SNS command request. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800839 sns_cmd = qla2x00_prep_sns_cmd(vha, GA_NXT_CMD, GA_NXT_SNS_SCMD_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840 GA_NXT_SNS_DATA_SIZE);
841
842 /* Prepare SNS command arguments -- port_id. */
843 sns_cmd->p.cmd.param[0] = fcport->d_id.b.al_pa;
844 sns_cmd->p.cmd.param[1] = fcport->d_id.b.area;
845 sns_cmd->p.cmd.param[2] = fcport->d_id.b.domain;
846
847 /* Execute SNS command. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800848 rval = qla2x00_send_sns(vha, ha->sns_cmd_dma, GA_NXT_SNS_CMD_SIZE / 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 sizeof(struct sns_cmd_pkt));
850 if (rval != QLA_SUCCESS) {
851 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700852 ql_dbg(ql_dbg_disc, vha, 0x205f,
853 "GA_NXT Send SNS failed (%d).\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854 } else if (sns_cmd->p.gan_data[8] != 0x80 ||
855 sns_cmd->p.gan_data[9] != 0x02) {
Chad Dupuiscfb09192011-11-18 09:03:07 -0800856 ql_dbg(ql_dbg_disc + ql_dbg_buffer, vha, 0x2084,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700857 "GA_NXT failed, rejected request ga_nxt_rsp:\n");
858 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2074,
859 sns_cmd->p.gan_data, 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 rval = QLA_FUNCTION_FAILED;
861 } else {
862 /* Populate fc_port_t entry. */
863 fcport->d_id.b.domain = sns_cmd->p.gan_data[17];
864 fcport->d_id.b.area = sns_cmd->p.gan_data[18];
865 fcport->d_id.b.al_pa = sns_cmd->p.gan_data[19];
866
867 memcpy(fcport->node_name, &sns_cmd->p.gan_data[284], WWN_SIZE);
868 memcpy(fcport->port_name, &sns_cmd->p.gan_data[20], WWN_SIZE);
869
870 if (sns_cmd->p.gan_data[16] != NS_N_PORT_TYPE &&
871 sns_cmd->p.gan_data[16] != NS_NL_PORT_TYPE)
872 fcport->d_id.b.domain = 0xf0;
873
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700874 ql_dbg(ql_dbg_disc, vha, 0x2061,
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -0400875 "GA_NXT entry - nn %8phN pn %8phN "
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700876 "port_id=%02x%02x%02x.\n",
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -0400877 fcport->node_name, fcport->port_name,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878 fcport->d_id.b.domain, fcport->d_id.b.area,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700879 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880 }
881
882 return (rval);
883}
884
885/**
886 * qla2x00_sns_gid_pt() - SNS scan for fabric devices via GID_PT command.
887 * @ha: HA context
888 * @list: switch info entries to populate
889 *
890 * This command uses the old Exectute SNS Command mailbox routine.
891 *
892 * NOTE: Non-Nx_Ports are not requested.
893 *
894 * Returns 0 on success.
895 */
896static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800897qla2x00_sns_gid_pt(scsi_qla_host_t *vha, sw_info_t *list)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898{
899 int rval;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800900 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901 uint16_t i;
902 uint8_t *entry;
903 struct sns_cmd_pkt *sns_cmd;
Chad Dupuis642ef982012-02-09 11:15:57 -0800904 uint16_t gid_pt_sns_data_size;
905
906 gid_pt_sns_data_size = qla2x00_gid_pt_rsp_size(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907
908 /* Issue GID_PT. */
909 /* Prepare SNS command request. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800910 sns_cmd = qla2x00_prep_sns_cmd(vha, GID_PT_CMD, GID_PT_SNS_SCMD_LEN,
Chad Dupuis642ef982012-02-09 11:15:57 -0800911 gid_pt_sns_data_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912
913 /* Prepare SNS command arguments -- port_type. */
914 sns_cmd->p.cmd.param[0] = NS_NX_PORT_TYPE;
915
916 /* Execute SNS command. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800917 rval = qla2x00_send_sns(vha, ha->sns_cmd_dma, GID_PT_SNS_CMD_SIZE / 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918 sizeof(struct sns_cmd_pkt));
919 if (rval != QLA_SUCCESS) {
920 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700921 ql_dbg(ql_dbg_disc, vha, 0x206d,
922 "GID_PT Send SNS failed (%d).\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923 } else if (sns_cmd->p.gid_data[8] != 0x80 ||
924 sns_cmd->p.gid_data[9] != 0x02) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700925 ql_dbg(ql_dbg_disc, vha, 0x202f,
926 "GID_PT failed, rejected request, gid_rsp:\n");
927 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2081,
928 sns_cmd->p.gid_data, 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929 rval = QLA_FUNCTION_FAILED;
930 } else {
931 /* Set port IDs in switch info list. */
Chad Dupuis642ef982012-02-09 11:15:57 -0800932 for (i = 0; i < ha->max_fibre_devices; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933 entry = &sns_cmd->p.gid_data[(i * 4) + 16];
934 list[i].d_id.b.domain = entry[1];
935 list[i].d_id.b.area = entry[2];
936 list[i].d_id.b.al_pa = entry[3];
937
938 /* Last one exit. */
939 if (entry[0] & BIT_7) {
940 list[i].d_id.b.rsvd_1 = entry[0];
941 break;
942 }
943 }
944
945 /*
946 * If we've used all available slots, then the switch is
947 * reporting back more devices that we can handle with this
948 * single call. Return a failed status, and let GA_NXT handle
949 * the overload.
950 */
Chad Dupuis642ef982012-02-09 11:15:57 -0800951 if (i == ha->max_fibre_devices)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952 rval = QLA_FUNCTION_FAILED;
953 }
954
955 return (rval);
956}
957
958/**
959 * qla2x00_sns_gpn_id() - SNS Get Port Name (GPN_ID) query.
960 * @ha: HA context
961 * @list: switch info entries to populate
962 *
963 * This command uses the old Exectute SNS Command mailbox routine.
964 *
965 * Returns 0 on success.
966 */
967static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800968qla2x00_sns_gpn_id(scsi_qla_host_t *vha, sw_info_t *list)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969{
Chad Dupuis642ef982012-02-09 11:15:57 -0800970 int rval = QLA_SUCCESS;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800971 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972 uint16_t i;
973 struct sns_cmd_pkt *sns_cmd;
974
Chad Dupuis642ef982012-02-09 11:15:57 -0800975 for (i = 0; i < ha->max_fibre_devices; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976 /* Issue GPN_ID */
977 /* Prepare SNS command request. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800978 sns_cmd = qla2x00_prep_sns_cmd(vha, GPN_ID_CMD,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979 GPN_ID_SNS_SCMD_LEN, GPN_ID_SNS_DATA_SIZE);
980
981 /* Prepare SNS command arguments -- port_id. */
982 sns_cmd->p.cmd.param[0] = list[i].d_id.b.al_pa;
983 sns_cmd->p.cmd.param[1] = list[i].d_id.b.area;
984 sns_cmd->p.cmd.param[2] = list[i].d_id.b.domain;
985
986 /* Execute SNS command. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800987 rval = qla2x00_send_sns(vha, ha->sns_cmd_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988 GPN_ID_SNS_CMD_SIZE / 2, sizeof(struct sns_cmd_pkt));
989 if (rval != QLA_SUCCESS) {
990 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700991 ql_dbg(ql_dbg_disc, vha, 0x2032,
992 "GPN_ID Send SNS failed (%d).\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993 } else if (sns_cmd->p.gpn_data[8] != 0x80 ||
994 sns_cmd->p.gpn_data[9] != 0x02) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700995 ql_dbg(ql_dbg_disc + ql_dbg_buffer, vha, 0x207e,
996 "GPN_ID failed, rejected request, gpn_rsp:\n");
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400997 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x207f,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700998 sns_cmd->p.gpn_data, 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999 rval = QLA_FUNCTION_FAILED;
1000 } else {
1001 /* Save portname */
1002 memcpy(list[i].port_name, &sns_cmd->p.gpn_data[16],
1003 WWN_SIZE);
1004 }
1005
1006 /* Last device exit. */
1007 if (list[i].d_id.b.rsvd_1 != 0)
1008 break;
1009 }
1010
1011 return (rval);
1012}
1013
1014/**
1015 * qla2x00_sns_gnn_id() - SNS Get Node Name (GNN_ID) query.
1016 * @ha: HA context
1017 * @list: switch info entries to populate
1018 *
1019 * This command uses the old Exectute SNS Command mailbox routine.
1020 *
1021 * Returns 0 on success.
1022 */
1023static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001024qla2x00_sns_gnn_id(scsi_qla_host_t *vha, sw_info_t *list)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025{
Chad Dupuis642ef982012-02-09 11:15:57 -08001026 int rval = QLA_SUCCESS;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001027 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028 uint16_t i;
1029 struct sns_cmd_pkt *sns_cmd;
1030
Chad Dupuis642ef982012-02-09 11:15:57 -08001031 for (i = 0; i < ha->max_fibre_devices; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032 /* Issue GNN_ID */
1033 /* Prepare SNS command request. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001034 sns_cmd = qla2x00_prep_sns_cmd(vha, GNN_ID_CMD,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035 GNN_ID_SNS_SCMD_LEN, GNN_ID_SNS_DATA_SIZE);
1036
1037 /* Prepare SNS command arguments -- port_id. */
1038 sns_cmd->p.cmd.param[0] = list[i].d_id.b.al_pa;
1039 sns_cmd->p.cmd.param[1] = list[i].d_id.b.area;
1040 sns_cmd->p.cmd.param[2] = list[i].d_id.b.domain;
1041
1042 /* Execute SNS command. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001043 rval = qla2x00_send_sns(vha, ha->sns_cmd_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044 GNN_ID_SNS_CMD_SIZE / 2, sizeof(struct sns_cmd_pkt));
1045 if (rval != QLA_SUCCESS) {
1046 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001047 ql_dbg(ql_dbg_disc, vha, 0x203f,
1048 "GNN_ID Send SNS failed (%d).\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049 } else if (sns_cmd->p.gnn_data[8] != 0x80 ||
1050 sns_cmd->p.gnn_data[9] != 0x02) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001051 ql_dbg(ql_dbg_disc + ql_dbg_buffer, vha, 0x2082,
1052 "GNN_ID failed, rejected request, gnn_rsp:\n");
1053 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x207a,
1054 sns_cmd->p.gnn_data, 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055 rval = QLA_FUNCTION_FAILED;
1056 } else {
1057 /* Save nodename */
1058 memcpy(list[i].node_name, &sns_cmd->p.gnn_data[16],
1059 WWN_SIZE);
1060
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001061 ql_dbg(ql_dbg_disc, vha, 0x206e,
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -04001062 "GID_PT entry - nn %8phN pn %8phN "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001063 "port_id=%02x%02x%02x.\n",
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -04001064 list[i].node_name, list[i].port_name,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065 list[i].d_id.b.domain, list[i].d_id.b.area,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001066 list[i].d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067 }
1068
1069 /* Last device exit. */
1070 if (list[i].d_id.b.rsvd_1 != 0)
1071 break;
1072 }
1073
1074 return (rval);
1075}
1076
1077/**
1078 * qla2x00_snd_rft_id() - SNS Register FC-4 TYPEs (RFT_ID) supported by the HBA.
1079 * @ha: HA context
1080 *
1081 * This command uses the old Exectute SNS Command mailbox routine.
1082 *
1083 * Returns 0 on success.
1084 */
1085static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001086qla2x00_sns_rft_id(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087{
1088 int rval;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001089 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090 struct sns_cmd_pkt *sns_cmd;
1091
1092 /* Issue RFT_ID. */
1093 /* Prepare SNS command request. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001094 sns_cmd = qla2x00_prep_sns_cmd(vha, RFT_ID_CMD, RFT_ID_SNS_SCMD_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095 RFT_ID_SNS_DATA_SIZE);
1096
1097 /* Prepare SNS command arguments -- port_id, FC-4 types */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001098 sns_cmd->p.cmd.param[0] = vha->d_id.b.al_pa;
1099 sns_cmd->p.cmd.param[1] = vha->d_id.b.area;
1100 sns_cmd->p.cmd.param[2] = vha->d_id.b.domain;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101
1102 sns_cmd->p.cmd.param[5] = 0x01; /* FCP-3 */
1103
1104 /* Execute SNS command. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001105 rval = qla2x00_send_sns(vha, ha->sns_cmd_dma, RFT_ID_SNS_CMD_SIZE / 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106 sizeof(struct sns_cmd_pkt));
1107 if (rval != QLA_SUCCESS) {
1108 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001109 ql_dbg(ql_dbg_disc, vha, 0x2060,
1110 "RFT_ID Send SNS failed (%d).\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111 } else if (sns_cmd->p.rft_data[8] != 0x80 ||
1112 sns_cmd->p.rft_data[9] != 0x02) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001113 ql_dbg(ql_dbg_disc + ql_dbg_buffer, vha, 0x2083,
1114 "RFT_ID failed, rejected request rft_rsp:\n");
1115 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2080,
1116 sns_cmd->p.rft_data, 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117 rval = QLA_FUNCTION_FAILED;
1118 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001119 ql_dbg(ql_dbg_disc, vha, 0x2073,
1120 "RFT_ID exiting normally.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121 }
1122
1123 return (rval);
1124}
1125
1126/**
1127 * qla2x00_sns_rnn_id() - SNS Register Node Name (RNN_ID) of the HBA.
1128 * HBA.
1129 * @ha: HA context
1130 *
1131 * This command uses the old Exectute SNS Command mailbox routine.
1132 *
1133 * Returns 0 on success.
1134 */
1135static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001136qla2x00_sns_rnn_id(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137{
1138 int rval;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001139 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140 struct sns_cmd_pkt *sns_cmd;
1141
1142 /* Issue RNN_ID. */
1143 /* Prepare SNS command request. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001144 sns_cmd = qla2x00_prep_sns_cmd(vha, RNN_ID_CMD, RNN_ID_SNS_SCMD_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145 RNN_ID_SNS_DATA_SIZE);
1146
1147 /* Prepare SNS command arguments -- port_id, nodename. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001148 sns_cmd->p.cmd.param[0] = vha->d_id.b.al_pa;
1149 sns_cmd->p.cmd.param[1] = vha->d_id.b.area;
1150 sns_cmd->p.cmd.param[2] = vha->d_id.b.domain;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001152 sns_cmd->p.cmd.param[4] = vha->node_name[7];
1153 sns_cmd->p.cmd.param[5] = vha->node_name[6];
1154 sns_cmd->p.cmd.param[6] = vha->node_name[5];
1155 sns_cmd->p.cmd.param[7] = vha->node_name[4];
1156 sns_cmd->p.cmd.param[8] = vha->node_name[3];
1157 sns_cmd->p.cmd.param[9] = vha->node_name[2];
1158 sns_cmd->p.cmd.param[10] = vha->node_name[1];
1159 sns_cmd->p.cmd.param[11] = vha->node_name[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160
1161 /* Execute SNS command. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001162 rval = qla2x00_send_sns(vha, ha->sns_cmd_dma, RNN_ID_SNS_CMD_SIZE / 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163 sizeof(struct sns_cmd_pkt));
1164 if (rval != QLA_SUCCESS) {
1165 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001166 ql_dbg(ql_dbg_disc, vha, 0x204a,
1167 "RNN_ID Send SNS failed (%d).\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168 } else if (sns_cmd->p.rnn_data[8] != 0x80 ||
1169 sns_cmd->p.rnn_data[9] != 0x02) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001170 ql_dbg(ql_dbg_disc + ql_dbg_buffer, vha, 0x207b,
1171 "RNN_ID failed, rejected request, rnn_rsp:\n");
1172 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x207c,
1173 sns_cmd->p.rnn_data, 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174 rval = QLA_FUNCTION_FAILED;
1175 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001176 ql_dbg(ql_dbg_disc, vha, 0x204c,
1177 "RNN_ID exiting normally.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178 }
1179
1180 return (rval);
1181}
Andrew Vasquezcca53352005-08-26 19:08:30 -07001182
1183/**
Joe Perchesb1c11812008-02-03 17:28:22 +02001184 * qla2x00_mgmt_svr_login() - Login to fabric Management Service.
Andrew Vasquezcca53352005-08-26 19:08:30 -07001185 * @ha: HA context
1186 *
1187 * Returns 0 on success.
1188 */
Quinn Tran726b8542017-01-19 22:28:00 -08001189int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001190qla2x00_mgmt_svr_login(scsi_qla_host_t *vha)
Andrew Vasquezcca53352005-08-26 19:08:30 -07001191{
Chad Dupuis0b91d112012-02-09 11:15:42 -08001192 int ret, rval;
Andrew Vasquezcca53352005-08-26 19:08:30 -07001193 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001194 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezcca53352005-08-26 19:08:30 -07001195 ret = QLA_SUCCESS;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001196 if (vha->flags.management_server_logged_in)
Andrew Vasquezcca53352005-08-26 19:08:30 -07001197 return ret;
1198
Chad Dupuis0b91d112012-02-09 11:15:42 -08001199 rval = ha->isp_ops->fabric_login(vha, vha->mgmt_svr_loop_id, 0xff, 0xff,
Andrew Vasquez58570ac2012-08-22 14:21:18 -04001200 0xfa, mb, BIT_1);
Chad Dupuis0b91d112012-02-09 11:15:42 -08001201 if (rval != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
1202 if (rval == QLA_MEMORY_ALLOC_FAILED)
1203 ql_dbg(ql_dbg_disc, vha, 0x2085,
1204 "Failed management_server login: loopid=%x "
1205 "rval=%d\n", vha->mgmt_svr_loop_id, rval);
1206 else
1207 ql_dbg(ql_dbg_disc, vha, 0x2024,
1208 "Failed management_server login: loopid=%x "
1209 "mb[0]=%x mb[1]=%x mb[2]=%x mb[6]=%x mb[7]=%x.\n",
1210 vha->mgmt_svr_loop_id, mb[0], mb[1], mb[2], mb[6],
1211 mb[7]);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001212 ret = QLA_FUNCTION_FAILED;
1213 } else
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001214 vha->flags.management_server_logged_in = 1;
Andrew Vasquezcca53352005-08-26 19:08:30 -07001215
1216 return ret;
1217}
1218
1219/**
1220 * qla2x00_prep_ms_fdmi_iocb() - Prepare common MS IOCB fields for FDMI query.
1221 * @ha: HA context
1222 * @req_size: request size in bytes
1223 * @rsp_size: response size in bytes
1224 *
1225 * Returns a pointer to the @ha's ms_iocb.
1226 */
1227void *
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001228qla2x00_prep_ms_fdmi_iocb(scsi_qla_host_t *vha, uint32_t req_size,
Andrew Vasquezcca53352005-08-26 19:08:30 -07001229 uint32_t rsp_size)
1230{
1231 ms_iocb_entry_t *ms_pkt;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001232 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezcca53352005-08-26 19:08:30 -07001233 ms_pkt = ha->ms_iocb;
1234 memset(ms_pkt, 0, sizeof(ms_iocb_entry_t));
1235
1236 ms_pkt->entry_type = MS_IOCB_TYPE;
1237 ms_pkt->entry_count = 1;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001238 SET_TARGET_ID(ha, ms_pkt->loop_id, vha->mgmt_svr_loop_id);
Bart Van Asschead950362015-07-09 07:24:08 -07001239 ms_pkt->control_flags = cpu_to_le16(CF_READ | CF_HEAD_TAG);
Andrew Vasquez00a537b2008-02-28 14:06:11 -08001240 ms_pkt->timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
Bart Van Asschead950362015-07-09 07:24:08 -07001241 ms_pkt->cmd_dsd_count = cpu_to_le16(1);
1242 ms_pkt->total_dsd_count = cpu_to_le16(2);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001243 ms_pkt->rsp_bytecount = cpu_to_le32(rsp_size);
1244 ms_pkt->req_bytecount = cpu_to_le32(req_size);
1245
1246 ms_pkt->dseg_req_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
1247 ms_pkt->dseg_req_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
1248 ms_pkt->dseg_req_length = ms_pkt->req_bytecount;
1249
1250 ms_pkt->dseg_rsp_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
1251 ms_pkt->dseg_rsp_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
1252 ms_pkt->dseg_rsp_length = ms_pkt->rsp_bytecount;
1253
1254 return ms_pkt;
1255}
1256
1257/**
1258 * qla24xx_prep_ms_fdmi_iocb() - Prepare common MS IOCB fields for FDMI query.
1259 * @ha: HA context
1260 * @req_size: request size in bytes
1261 * @rsp_size: response size in bytes
1262 *
1263 * Returns a pointer to the @ha's ms_iocb.
1264 */
1265void *
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001266qla24xx_prep_ms_fdmi_iocb(scsi_qla_host_t *vha, uint32_t req_size,
Andrew Vasquezcca53352005-08-26 19:08:30 -07001267 uint32_t rsp_size)
1268{
1269 struct ct_entry_24xx *ct_pkt;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001270 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezcca53352005-08-26 19:08:30 -07001271
1272 ct_pkt = (struct ct_entry_24xx *)ha->ms_iocb;
1273 memset(ct_pkt, 0, sizeof(struct ct_entry_24xx));
1274
1275 ct_pkt->entry_type = CT_IOCB_TYPE;
1276 ct_pkt->entry_count = 1;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001277 ct_pkt->nport_handle = cpu_to_le16(vha->mgmt_svr_loop_id);
Andrew Vasquez00a537b2008-02-28 14:06:11 -08001278 ct_pkt->timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
Bart Van Asschead950362015-07-09 07:24:08 -07001279 ct_pkt->cmd_dsd_count = cpu_to_le16(1);
1280 ct_pkt->rsp_dsd_count = cpu_to_le16(1);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001281 ct_pkt->rsp_byte_count = cpu_to_le32(rsp_size);
1282 ct_pkt->cmd_byte_count = cpu_to_le32(req_size);
1283
1284 ct_pkt->dseg_0_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
1285 ct_pkt->dseg_0_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
1286 ct_pkt->dseg_0_len = ct_pkt->cmd_byte_count;
1287
1288 ct_pkt->dseg_1_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
1289 ct_pkt->dseg_1_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
1290 ct_pkt->dseg_1_len = ct_pkt->rsp_byte_count;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001291 ct_pkt->vp_index = vha->vp_idx;
Andrew Vasquezcca53352005-08-26 19:08:30 -07001292
1293 return ct_pkt;
1294}
1295
1296static inline ms_iocb_entry_t *
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001297qla2x00_update_ms_fdmi_iocb(scsi_qla_host_t *vha, uint32_t req_size)
Andrew Vasquezcca53352005-08-26 19:08:30 -07001298{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001299 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezcca53352005-08-26 19:08:30 -07001300 ms_iocb_entry_t *ms_pkt = ha->ms_iocb;
1301 struct ct_entry_24xx *ct_pkt = (struct ct_entry_24xx *)ha->ms_iocb;
1302
Andrew Vasqueze4289242007-07-19 15:05:56 -07001303 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquezcca53352005-08-26 19:08:30 -07001304 ct_pkt->cmd_byte_count = cpu_to_le32(req_size);
1305 ct_pkt->dseg_0_len = ct_pkt->cmd_byte_count;
1306 } else {
1307 ms_pkt->req_bytecount = cpu_to_le32(req_size);
1308 ms_pkt->dseg_req_length = ms_pkt->req_bytecount;
1309 }
1310
1311 return ms_pkt;
1312}
1313
1314/**
1315 * qla2x00_prep_ct_req() - Prepare common CT request fields for SNS query.
1316 * @ct_req: CT request buffer
1317 * @cmd: GS command
1318 * @rsp_size: response size in bytes
1319 *
1320 * Returns a pointer to the intitialized @ct_req.
1321 */
1322static inline struct ct_sns_req *
Bart Van Assche6ec6f902013-06-25 11:27:28 -04001323qla2x00_prep_ct_fdmi_req(struct ct_sns_pkt *p, uint16_t cmd,
Andrew Vasquezcca53352005-08-26 19:08:30 -07001324 uint16_t rsp_size)
1325{
Bart Van Assche6ec6f902013-06-25 11:27:28 -04001326 memset(p, 0, sizeof(struct ct_sns_pkt));
Andrew Vasquezcca53352005-08-26 19:08:30 -07001327
Bart Van Assche6ec6f902013-06-25 11:27:28 -04001328 p->p.req.header.revision = 0x01;
1329 p->p.req.header.gs_type = 0xFA;
1330 p->p.req.header.gs_subtype = 0x10;
1331 p->p.req.command = cpu_to_be16(cmd);
1332 p->p.req.max_rsp_size = cpu_to_be16((rsp_size - 16) / 4);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001333
Bart Van Assche6ec6f902013-06-25 11:27:28 -04001334 return &p->p.req;
Andrew Vasquezcca53352005-08-26 19:08:30 -07001335}
1336
1337/**
1338 * qla2x00_fdmi_rhba() -
1339 * @ha: HA context
1340 *
1341 * Returns 0 on success.
1342 */
1343static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001344qla2x00_fdmi_rhba(scsi_qla_host_t *vha)
Andrew Vasquezcca53352005-08-26 19:08:30 -07001345{
1346 int rval, alen;
1347 uint32_t size, sn;
1348
1349 ms_iocb_entry_t *ms_pkt;
1350 struct ct_sns_req *ct_req;
1351 struct ct_sns_rsp *ct_rsp;
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04001352 void *entries;
Andrew Vasquezcca53352005-08-26 19:08:30 -07001353 struct ct_fdmi_hba_attr *eiter;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001354 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezcca53352005-08-26 19:08:30 -07001355
1356 /* Issue RHBA */
1357 /* Prepare common MS IOCB */
1358 /* Request size adjusted after CT preparation */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001359 ms_pkt = ha->isp_ops->prep_ms_fdmi_iocb(vha, 0, RHBA_RSP_SIZE);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001360
1361 /* Prepare CT request */
Bart Van Assche6ec6f902013-06-25 11:27:28 -04001362 ct_req = qla2x00_prep_ct_fdmi_req(ha->ct_sns, RHBA_CMD, RHBA_RSP_SIZE);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001363 ct_rsp = &ha->ct_sns->p.rsp;
1364
1365 /* Prepare FDMI command arguments -- attribute block, attributes. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001366 memcpy(ct_req->req.rhba.hba_identifier, vha->port_name, WWN_SIZE);
Bart Van Asschead950362015-07-09 07:24:08 -07001367 ct_req->req.rhba.entry_count = cpu_to_be32(1);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001368 memcpy(ct_req->req.rhba.port_name, vha->port_name, WWN_SIZE);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001369 size = 2 * WWN_SIZE + 4 + 4;
1370
1371 /* Attributes */
1372 ct_req->req.rhba.attrs.count =
Bart Van Asschead950362015-07-09 07:24:08 -07001373 cpu_to_be32(FDMI_HBA_ATTR_COUNT);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001374 entries = ct_req->req.rhba.hba_identifier;
1375
1376 /* Nodename. */
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04001377 eiter = entries + size;
Bart Van Asschead950362015-07-09 07:24:08 -07001378 eiter->type = cpu_to_be16(FDMI_HBA_NODE_NAME);
1379 eiter->len = cpu_to_be16(4 + WWN_SIZE);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001380 memcpy(eiter->a.node_name, vha->node_name, WWN_SIZE);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001381 size += 4 + WWN_SIZE;
1382
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001383 ql_dbg(ql_dbg_disc, vha, 0x2025,
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -04001384 "NodeName = %8phN.\n", eiter->a.node_name);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001385
1386 /* Manufacturer. */
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04001387 eiter = entries + size;
Bart Van Asschead950362015-07-09 07:24:08 -07001388 eiter->type = cpu_to_be16(FDMI_HBA_MANUFACTURER);
Paul Bollef24b6972013-02-08 01:57:55 -05001389 alen = strlen(QLA2XXX_MANUFACTURER);
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04001390 snprintf(eiter->a.manufacturer, sizeof(eiter->a.manufacturer),
1391 "%s", "QLogic Corporation");
1392 alen += 4 - (alen & 3);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001393 eiter->len = cpu_to_be16(4 + alen);
1394 size += 4 + alen;
1395
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001396 ql_dbg(ql_dbg_disc, vha, 0x2026,
1397 "Manufacturer = %s.\n", eiter->a.manufacturer);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001398
1399 /* Serial number. */
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04001400 eiter = entries + size;
Bart Van Asschead950362015-07-09 07:24:08 -07001401 eiter->type = cpu_to_be16(FDMI_HBA_SERIAL_NUMBER);
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04001402 if (IS_FWI2_CAPABLE(ha))
1403 qla2xxx_get_vpd_field(vha, "SN", eiter->a.serial_num,
1404 sizeof(eiter->a.serial_num));
1405 else {
1406 sn = ((ha->serial0 & 0x1f) << 16) |
1407 (ha->serial2 << 8) | ha->serial1;
1408 snprintf(eiter->a.serial_num, sizeof(eiter->a.serial_num),
1409 "%c%05d", 'A' + sn / 100000, sn % 100000);
1410 }
Andrew Vasquezcca53352005-08-26 19:08:30 -07001411 alen = strlen(eiter->a.serial_num);
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04001412 alen += 4 - (alen & 3);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001413 eiter->len = cpu_to_be16(4 + alen);
1414 size += 4 + alen;
1415
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001416 ql_dbg(ql_dbg_disc, vha, 0x2027,
1417 "Serial no. = %s.\n", eiter->a.serial_num);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001418
1419 /* Model name. */
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04001420 eiter = entries + size;
Bart Van Asschead950362015-07-09 07:24:08 -07001421 eiter->type = cpu_to_be16(FDMI_HBA_MODEL);
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04001422 snprintf(eiter->a.model, sizeof(eiter->a.model),
1423 "%s", ha->model_number);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001424 alen = strlen(eiter->a.model);
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04001425 alen += 4 - (alen & 3);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001426 eiter->len = cpu_to_be16(4 + alen);
1427 size += 4 + alen;
1428
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001429 ql_dbg(ql_dbg_disc, vha, 0x2028,
1430 "Model Name = %s.\n", eiter->a.model);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001431
1432 /* Model description. */
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04001433 eiter = entries + size;
Bart Van Asschead950362015-07-09 07:24:08 -07001434 eiter->type = cpu_to_be16(FDMI_HBA_MODEL_DESCRIPTION);
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04001435 snprintf(eiter->a.model_desc, sizeof(eiter->a.model_desc),
1436 "%s", ha->model_desc);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001437 alen = strlen(eiter->a.model_desc);
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04001438 alen += 4 - (alen & 3);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001439 eiter->len = cpu_to_be16(4 + alen);
1440 size += 4 + alen;
1441
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001442 ql_dbg(ql_dbg_disc, vha, 0x2029,
1443 "Model Desc = %s.\n", eiter->a.model_desc);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001444
1445 /* Hardware version. */
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04001446 eiter = entries + size;
Bart Van Asschead950362015-07-09 07:24:08 -07001447 eiter->type = cpu_to_be16(FDMI_HBA_HARDWARE_VERSION);
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04001448 if (!IS_FWI2_CAPABLE(ha)) {
1449 snprintf(eiter->a.hw_version, sizeof(eiter->a.hw_version),
1450 "HW:%s", ha->adapter_id);
1451 } else if (qla2xxx_get_vpd_field(vha, "MN", eiter->a.hw_version,
1452 sizeof(eiter->a.hw_version))) {
1453 ;
1454 } else if (qla2xxx_get_vpd_field(vha, "EC", eiter->a.hw_version,
1455 sizeof(eiter->a.hw_version))) {
1456 ;
1457 } else {
1458 snprintf(eiter->a.hw_version, sizeof(eiter->a.hw_version),
1459 "HW:%s", ha->adapter_id);
1460 }
Andrew Vasquezcca53352005-08-26 19:08:30 -07001461 alen = strlen(eiter->a.hw_version);
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04001462 alen += 4 - (alen & 3);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001463 eiter->len = cpu_to_be16(4 + alen);
1464 size += 4 + alen;
1465
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001466 ql_dbg(ql_dbg_disc, vha, 0x202a,
1467 "Hardware ver = %s.\n", eiter->a.hw_version);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001468
1469 /* Driver version. */
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04001470 eiter = entries + size;
Bart Van Asschead950362015-07-09 07:24:08 -07001471 eiter->type = cpu_to_be16(FDMI_HBA_DRIVER_VERSION);
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04001472 snprintf(eiter->a.driver_version, sizeof(eiter->a.driver_version),
1473 "%s", qla2x00_version_str);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001474 alen = strlen(eiter->a.driver_version);
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04001475 alen += 4 - (alen & 3);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001476 eiter->len = cpu_to_be16(4 + alen);
1477 size += 4 + alen;
1478
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001479 ql_dbg(ql_dbg_disc, vha, 0x202b,
1480 "Driver ver = %s.\n", eiter->a.driver_version);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001481
1482 /* Option ROM version. */
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04001483 eiter = entries + size;
Bart Van Asschead950362015-07-09 07:24:08 -07001484 eiter->type = cpu_to_be16(FDMI_HBA_OPTION_ROM_VERSION);
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04001485 snprintf(eiter->a.orom_version, sizeof(eiter->a.orom_version),
1486 "%d.%02d", ha->bios_revision[1], ha->bios_revision[0]);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001487 alen = strlen(eiter->a.orom_version);
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04001488 alen += 4 - (alen & 3);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001489 eiter->len = cpu_to_be16(4 + alen);
1490 size += 4 + alen;
1491
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001492 ql_dbg(ql_dbg_disc, vha , 0x202c,
1493 "Optrom vers = %s.\n", eiter->a.orom_version);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001494
1495 /* Firmware version */
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04001496 eiter = entries + size;
Bart Van Asschead950362015-07-09 07:24:08 -07001497 eiter->type = cpu_to_be16(FDMI_HBA_FIRMWARE_VERSION);
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04001498 ha->isp_ops->fw_version_str(vha, eiter->a.fw_version,
1499 sizeof(eiter->a.fw_version));
Andrew Vasquezcca53352005-08-26 19:08:30 -07001500 alen = strlen(eiter->a.fw_version);
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04001501 alen += 4 - (alen & 3);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001502 eiter->len = cpu_to_be16(4 + alen);
1503 size += 4 + alen;
1504
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001505 ql_dbg(ql_dbg_disc, vha, 0x202d,
1506 "Firmware vers = %s.\n", eiter->a.fw_version);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001507
1508 /* Update MS request size. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001509 qla2x00_update_ms_fdmi_iocb(vha, size + 16);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001510
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001511 ql_dbg(ql_dbg_disc, vha, 0x202e,
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -04001512 "RHBA identifier = %8phN size=%d.\n",
1513 ct_req->req.rhba.hba_identifier, size);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001514 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2076,
1515 entries, size);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001516
1517 /* Execute MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001518 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
Andrew Vasquezcca53352005-08-26 19:08:30 -07001519 sizeof(ms_iocb_entry_t));
1520 if (rval != QLA_SUCCESS) {
1521 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001522 ql_dbg(ql_dbg_disc, vha, 0x2030,
1523 "RHBA issue IOCB failed (%d).\n", rval);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001524 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, "RHBA") !=
Andrew Vasquezcca53352005-08-26 19:08:30 -07001525 QLA_SUCCESS) {
1526 rval = QLA_FUNCTION_FAILED;
1527 if (ct_rsp->header.reason_code == CT_REASON_CANNOT_PERFORM &&
1528 ct_rsp->header.explanation_code ==
1529 CT_EXPL_ALREADY_REGISTERED) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001530 ql_dbg(ql_dbg_disc, vha, 0x2034,
1531 "HBA already registered.\n");
Andrew Vasquezcca53352005-08-26 19:08:30 -07001532 rval = QLA_ALREADY_REGISTERED;
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04001533 } else {
1534 ql_dbg(ql_dbg_disc, vha, 0x20ad,
1535 "RHBA FDMI registration failed, CT Reason code: 0x%x, CT Explanation 0x%x\n",
1536 ct_rsp->header.reason_code,
1537 ct_rsp->header.explanation_code);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001538 }
1539 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001540 ql_dbg(ql_dbg_disc, vha, 0x2035,
1541 "RHBA exiting normally.\n");
Andrew Vasquezcca53352005-08-26 19:08:30 -07001542 }
1543
1544 return rval;
1545}
1546
1547/**
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04001548 * qla2x00_fdmi_rpa() -
1549 * @ha: HA context
1550 *
1551 * Returns 0 on success.
1552 */
1553static int
1554qla2x00_fdmi_rpa(scsi_qla_host_t *vha)
1555{
1556 int rval, alen;
1557 uint32_t size;
1558 struct qla_hw_data *ha = vha->hw;
1559 ms_iocb_entry_t *ms_pkt;
1560 struct ct_sns_req *ct_req;
1561 struct ct_sns_rsp *ct_rsp;
1562 void *entries;
1563 struct ct_fdmi_port_attr *eiter;
1564 struct init_cb_24xx *icb24 = (struct init_cb_24xx *)ha->init_cb;
1565 struct new_utsname *p_sysid = NULL;
1566
1567 /* Issue RPA */
1568 /* Prepare common MS IOCB */
1569 /* Request size adjusted after CT preparation */
1570 ms_pkt = ha->isp_ops->prep_ms_fdmi_iocb(vha, 0, RPA_RSP_SIZE);
1571
1572 /* Prepare CT request */
1573 ct_req = qla2x00_prep_ct_fdmi_req(ha->ct_sns, RPA_CMD,
1574 RPA_RSP_SIZE);
1575 ct_rsp = &ha->ct_sns->p.rsp;
1576
1577 /* Prepare FDMI command arguments -- attribute block, attributes. */
1578 memcpy(ct_req->req.rpa.port_name, vha->port_name, WWN_SIZE);
1579 size = WWN_SIZE + 4;
1580
1581 /* Attributes */
1582 ct_req->req.rpa.attrs.count = cpu_to_be32(FDMI_PORT_ATTR_COUNT);
1583 entries = ct_req->req.rpa.port_name;
1584
1585 /* FC4 types. */
1586 eiter = entries + size;
1587 eiter->type = cpu_to_be16(FDMI_PORT_FC4_TYPES);
1588 eiter->len = cpu_to_be16(4 + 32);
1589 eiter->a.fc4_types[2] = 0x01;
1590 size += 4 + 32;
1591
1592 ql_dbg(ql_dbg_disc, vha, 0x2039,
1593 "FC4_TYPES=%02x %02x.\n",
1594 eiter->a.fc4_types[2],
1595 eiter->a.fc4_types[1]);
1596
1597 /* Supported speed. */
1598 eiter = entries + size;
1599 eiter->type = cpu_to_be16(FDMI_PORT_SUPPORT_SPEED);
1600 eiter->len = cpu_to_be16(4 + 4);
1601 if (IS_CNA_CAPABLE(ha))
1602 eiter->a.sup_speed = cpu_to_be32(
1603 FDMI_PORT_SPEED_10GB);
1604 else if (IS_QLA27XX(ha))
1605 eiter->a.sup_speed = cpu_to_be32(
1606 FDMI_PORT_SPEED_32GB|
1607 FDMI_PORT_SPEED_16GB|
1608 FDMI_PORT_SPEED_8GB);
1609 else if (IS_QLA2031(ha))
1610 eiter->a.sup_speed = cpu_to_be32(
1611 FDMI_PORT_SPEED_16GB|
1612 FDMI_PORT_SPEED_8GB|
1613 FDMI_PORT_SPEED_4GB);
1614 else if (IS_QLA25XX(ha))
1615 eiter->a.sup_speed = cpu_to_be32(
1616 FDMI_PORT_SPEED_8GB|
1617 FDMI_PORT_SPEED_4GB|
1618 FDMI_PORT_SPEED_2GB|
1619 FDMI_PORT_SPEED_1GB);
1620 else if (IS_QLA24XX_TYPE(ha))
1621 eiter->a.sup_speed = cpu_to_be32(
1622 FDMI_PORT_SPEED_4GB|
1623 FDMI_PORT_SPEED_2GB|
1624 FDMI_PORT_SPEED_1GB);
1625 else if (IS_QLA23XX(ha))
1626 eiter->a.sup_speed = cpu_to_be32(
1627 FDMI_PORT_SPEED_2GB|
1628 FDMI_PORT_SPEED_1GB);
1629 else
1630 eiter->a.sup_speed = cpu_to_be32(
1631 FDMI_PORT_SPEED_1GB);
1632 size += 4 + 4;
1633
1634 ql_dbg(ql_dbg_disc, vha, 0x203a,
1635 "Supported_Speed=%x.\n", eiter->a.sup_speed);
1636
1637 /* Current speed. */
1638 eiter = entries + size;
1639 eiter->type = cpu_to_be16(FDMI_PORT_CURRENT_SPEED);
1640 eiter->len = cpu_to_be16(4 + 4);
1641 switch (ha->link_data_rate) {
1642 case PORT_SPEED_1GB:
1643 eiter->a.cur_speed =
1644 cpu_to_be32(FDMI_PORT_SPEED_1GB);
1645 break;
1646 case PORT_SPEED_2GB:
1647 eiter->a.cur_speed =
1648 cpu_to_be32(FDMI_PORT_SPEED_2GB);
1649 break;
1650 case PORT_SPEED_4GB:
1651 eiter->a.cur_speed =
1652 cpu_to_be32(FDMI_PORT_SPEED_4GB);
1653 break;
1654 case PORT_SPEED_8GB:
1655 eiter->a.cur_speed =
1656 cpu_to_be32(FDMI_PORT_SPEED_8GB);
1657 break;
1658 case PORT_SPEED_10GB:
1659 eiter->a.cur_speed =
1660 cpu_to_be32(FDMI_PORT_SPEED_10GB);
1661 break;
1662 case PORT_SPEED_16GB:
1663 eiter->a.cur_speed =
1664 cpu_to_be32(FDMI_PORT_SPEED_16GB);
1665 break;
1666 case PORT_SPEED_32GB:
1667 eiter->a.cur_speed =
1668 cpu_to_be32(FDMI_PORT_SPEED_32GB);
1669 break;
1670 default:
1671 eiter->a.cur_speed =
1672 cpu_to_be32(FDMI_PORT_SPEED_UNKNOWN);
1673 break;
1674 }
1675 size += 4 + 4;
1676
1677 ql_dbg(ql_dbg_disc, vha, 0x203b,
1678 "Current_Speed=%x.\n", eiter->a.cur_speed);
1679
1680 /* Max frame size. */
1681 eiter = entries + size;
1682 eiter->type = cpu_to_be16(FDMI_PORT_MAX_FRAME_SIZE);
1683 eiter->len = cpu_to_be16(4 + 4);
1684 eiter->a.max_frame_size = IS_FWI2_CAPABLE(ha) ?
1685 le16_to_cpu(icb24->frame_payload_size) :
1686 le16_to_cpu(ha->init_cb->frame_payload_size);
1687 eiter->a.max_frame_size = cpu_to_be32(eiter->a.max_frame_size);
1688 size += 4 + 4;
1689
1690 ql_dbg(ql_dbg_disc, vha, 0x203c,
1691 "Max_Frame_Size=%x.\n", eiter->a.max_frame_size);
1692
1693 /* OS device name. */
1694 eiter = entries + size;
1695 eiter->type = cpu_to_be16(FDMI_PORT_OS_DEVICE_NAME);
1696 snprintf(eiter->a.os_dev_name, sizeof(eiter->a.os_dev_name),
1697 "%s:host%lu", QLA2XXX_DRIVER_NAME, vha->host_no);
1698 alen = strlen(eiter->a.os_dev_name);
1699 alen += 4 - (alen & 3);
1700 eiter->len = cpu_to_be16(4 + alen);
1701 size += 4 + alen;
1702
1703 ql_dbg(ql_dbg_disc, vha, 0x204b,
1704 "OS_Device_Name=%s.\n", eiter->a.os_dev_name);
1705
1706 /* Hostname. */
1707 eiter = entries + size;
1708 eiter->type = cpu_to_be16(FDMI_PORT_HOST_NAME);
1709 p_sysid = utsname();
1710 if (p_sysid) {
1711 snprintf(eiter->a.host_name, sizeof(eiter->a.host_name),
1712 "%s", p_sysid->nodename);
1713 } else {
1714 snprintf(eiter->a.host_name, sizeof(eiter->a.host_name),
1715 "%s", fc_host_system_hostname(vha->host));
1716 }
1717 alen = strlen(eiter->a.host_name);
1718 alen += 4 - (alen & 3);
1719 eiter->len = cpu_to_be16(4 + alen);
1720 size += 4 + alen;
1721
1722 ql_dbg(ql_dbg_disc, vha, 0x203d, "HostName=%s.\n", eiter->a.host_name);
1723
1724 /* Update MS request size. */
1725 qla2x00_update_ms_fdmi_iocb(vha, size + 16);
1726
1727 ql_dbg(ql_dbg_disc, vha, 0x203e,
1728 "RPA portname %016llx, size = %d.\n",
1729 wwn_to_u64(ct_req->req.rpa.port_name), size);
1730 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2079,
1731 entries, size);
1732
1733 /* Execute MS IOCB */
1734 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
1735 sizeof(ms_iocb_entry_t));
1736 if (rval != QLA_SUCCESS) {
1737 /*EMPTY*/
1738 ql_dbg(ql_dbg_disc, vha, 0x2040,
1739 "RPA issue IOCB failed (%d).\n", rval);
1740 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, "RPA") !=
1741 QLA_SUCCESS) {
1742 rval = QLA_FUNCTION_FAILED;
1743 if (ct_rsp->header.reason_code == CT_REASON_CANNOT_PERFORM &&
1744 ct_rsp->header.explanation_code ==
1745 CT_EXPL_ALREADY_REGISTERED) {
1746 ql_dbg(ql_dbg_disc, vha, 0x20cd,
1747 "RPA already registered.\n");
1748 rval = QLA_ALREADY_REGISTERED;
1749 }
1750
1751 } else {
1752 ql_dbg(ql_dbg_disc, vha, 0x2041,
1753 "RPA exiting normally.\n");
1754 }
1755
1756 return rval;
1757}
1758
1759/**
1760 * qla2x00_fdmiv2_rhba() -
1761 * @ha: HA context
1762 *
1763 * Returns 0 on success.
1764 */
1765static int
1766qla2x00_fdmiv2_rhba(scsi_qla_host_t *vha)
1767{
1768 int rval, alen;
1769 uint32_t size, sn;
1770 ms_iocb_entry_t *ms_pkt;
1771 struct ct_sns_req *ct_req;
1772 struct ct_sns_rsp *ct_rsp;
1773 void *entries;
1774 struct ct_fdmiv2_hba_attr *eiter;
1775 struct qla_hw_data *ha = vha->hw;
1776 struct init_cb_24xx *icb24 = (struct init_cb_24xx *)ha->init_cb;
1777 struct new_utsname *p_sysid = NULL;
1778
1779 /* Issue RHBA */
1780 /* Prepare common MS IOCB */
1781 /* Request size adjusted after CT preparation */
1782 ms_pkt = ha->isp_ops->prep_ms_fdmi_iocb(vha, 0, RHBA_RSP_SIZE);
1783
1784 /* Prepare CT request */
1785 ct_req = qla2x00_prep_ct_fdmi_req(ha->ct_sns, RHBA_CMD,
1786 RHBA_RSP_SIZE);
1787 ct_rsp = &ha->ct_sns->p.rsp;
1788
1789 /* Prepare FDMI command arguments -- attribute block, attributes. */
1790 memcpy(ct_req->req.rhba2.hba_identifier, vha->port_name, WWN_SIZE);
1791 ct_req->req.rhba2.entry_count = cpu_to_be32(1);
1792 memcpy(ct_req->req.rhba2.port_name, vha->port_name, WWN_SIZE);
1793 size = 2 * WWN_SIZE + 4 + 4;
1794
1795 /* Attributes */
1796 ct_req->req.rhba2.attrs.count = cpu_to_be32(FDMIV2_HBA_ATTR_COUNT);
1797 entries = ct_req->req.rhba2.hba_identifier;
1798
1799 /* Nodename. */
1800 eiter = entries + size;
1801 eiter->type = cpu_to_be16(FDMI_HBA_NODE_NAME);
1802 eiter->len = cpu_to_be16(4 + WWN_SIZE);
1803 memcpy(eiter->a.node_name, vha->node_name, WWN_SIZE);
1804 size += 4 + WWN_SIZE;
1805
1806 ql_dbg(ql_dbg_disc, vha, 0x207d,
1807 "NodeName = %016llx.\n", wwn_to_u64(eiter->a.node_name));
1808
1809 /* Manufacturer. */
1810 eiter = entries + size;
1811 eiter->type = cpu_to_be16(FDMI_HBA_MANUFACTURER);
1812 snprintf(eiter->a.manufacturer, sizeof(eiter->a.manufacturer),
1813 "%s", "QLogic Corporation");
1814 eiter->a.manufacturer[strlen("QLogic Corporation")] = '\0';
1815 alen = strlen(eiter->a.manufacturer);
1816 alen += 4 - (alen & 3);
1817 eiter->len = cpu_to_be16(4 + alen);
1818 size += 4 + alen;
1819
1820 ql_dbg(ql_dbg_disc, vha, 0x20a5,
1821 "Manufacturer = %s.\n", eiter->a.manufacturer);
1822
1823 /* Serial number. */
1824 eiter = entries + size;
1825 eiter->type = cpu_to_be16(FDMI_HBA_SERIAL_NUMBER);
1826 if (IS_FWI2_CAPABLE(ha))
1827 qla2xxx_get_vpd_field(vha, "SN", eiter->a.serial_num,
1828 sizeof(eiter->a.serial_num));
1829 else {
1830 sn = ((ha->serial0 & 0x1f) << 16) |
1831 (ha->serial2 << 8) | ha->serial1;
1832 snprintf(eiter->a.serial_num, sizeof(eiter->a.serial_num),
1833 "%c%05d", 'A' + sn / 100000, sn % 100000);
1834 }
1835 alen = strlen(eiter->a.serial_num);
1836 alen += 4 - (alen & 3);
1837 eiter->len = cpu_to_be16(4 + alen);
1838 size += 4 + alen;
1839
1840 ql_dbg(ql_dbg_disc, vha, 0x20a6,
1841 "Serial no. = %s.\n", eiter->a.serial_num);
1842
1843 /* Model name. */
1844 eiter = entries + size;
1845 eiter->type = cpu_to_be16(FDMI_HBA_MODEL);
1846 snprintf(eiter->a.model, sizeof(eiter->a.model),
1847 "%s", ha->model_number);
1848 alen = strlen(eiter->a.model);
1849 alen += 4 - (alen & 3);
1850 eiter->len = cpu_to_be16(4 + alen);
1851 size += 4 + alen;
1852
1853 ql_dbg(ql_dbg_disc, vha, 0x20a7,
1854 "Model Name = %s.\n", eiter->a.model);
1855
1856 /* Model description. */
1857 eiter = entries + size;
1858 eiter->type = cpu_to_be16(FDMI_HBA_MODEL_DESCRIPTION);
1859 snprintf(eiter->a.model_desc, sizeof(eiter->a.model_desc),
1860 "%s", ha->model_desc);
1861 alen = strlen(eiter->a.model_desc);
1862 alen += 4 - (alen & 3);
1863 eiter->len = cpu_to_be16(4 + alen);
1864 size += 4 + alen;
1865
1866 ql_dbg(ql_dbg_disc, vha, 0x20a8,
1867 "Model Desc = %s.\n", eiter->a.model_desc);
1868
1869 /* Hardware version. */
1870 eiter = entries + size;
1871 eiter->type = cpu_to_be16(FDMI_HBA_HARDWARE_VERSION);
1872 if (!IS_FWI2_CAPABLE(ha)) {
1873 snprintf(eiter->a.hw_version, sizeof(eiter->a.hw_version),
1874 "HW:%s", ha->adapter_id);
1875 } else if (qla2xxx_get_vpd_field(vha, "MN", eiter->a.hw_version,
1876 sizeof(eiter->a.hw_version))) {
1877 ;
1878 } else if (qla2xxx_get_vpd_field(vha, "EC", eiter->a.hw_version,
1879 sizeof(eiter->a.hw_version))) {
1880 ;
1881 } else {
1882 snprintf(eiter->a.hw_version, sizeof(eiter->a.hw_version),
1883 "HW:%s", ha->adapter_id);
1884 }
1885 alen = strlen(eiter->a.hw_version);
1886 alen += 4 - (alen & 3);
1887 eiter->len = cpu_to_be16(4 + alen);
1888 size += 4 + alen;
1889
1890 ql_dbg(ql_dbg_disc, vha, 0x20a9,
1891 "Hardware ver = %s.\n", eiter->a.hw_version);
1892
1893 /* Driver version. */
1894 eiter = entries + size;
1895 eiter->type = cpu_to_be16(FDMI_HBA_DRIVER_VERSION);
1896 snprintf(eiter->a.driver_version, sizeof(eiter->a.driver_version),
1897 "%s", qla2x00_version_str);
1898 alen = strlen(eiter->a.driver_version);
1899 alen += 4 - (alen & 3);
1900 eiter->len = cpu_to_be16(4 + alen);
1901 size += 4 + alen;
1902
1903 ql_dbg(ql_dbg_disc, vha, 0x20aa,
1904 "Driver ver = %s.\n", eiter->a.driver_version);
1905
1906 /* Option ROM version. */
1907 eiter = entries + size;
1908 eiter->type = cpu_to_be16(FDMI_HBA_OPTION_ROM_VERSION);
1909 snprintf(eiter->a.orom_version, sizeof(eiter->a.orom_version),
1910 "%d.%02d", ha->bios_revision[1], ha->bios_revision[0]);
1911 alen = strlen(eiter->a.orom_version);
1912 alen += 4 - (alen & 3);
1913 eiter->len = cpu_to_be16(4 + alen);
1914 size += 4 + alen;
1915
1916 ql_dbg(ql_dbg_disc, vha , 0x20ab,
1917 "Optrom version = %d.%02d.\n", eiter->a.orom_version[1],
1918 eiter->a.orom_version[0]);
1919
1920 /* Firmware version */
1921 eiter = entries + size;
1922 eiter->type = cpu_to_be16(FDMI_HBA_FIRMWARE_VERSION);
1923 ha->isp_ops->fw_version_str(vha, eiter->a.fw_version,
1924 sizeof(eiter->a.fw_version));
1925 alen = strlen(eiter->a.fw_version);
1926 alen += 4 - (alen & 3);
1927 eiter->len = cpu_to_be16(4 + alen);
1928 size += 4 + alen;
1929
1930 ql_dbg(ql_dbg_disc, vha, 0x20ac,
1931 "Firmware vers = %s.\n", eiter->a.fw_version);
1932
1933 /* OS Name and Version */
1934 eiter = entries + size;
1935 eiter->type = cpu_to_be16(FDMI_HBA_OS_NAME_AND_VERSION);
1936 p_sysid = utsname();
1937 if (p_sysid) {
1938 snprintf(eiter->a.os_version, sizeof(eiter->a.os_version),
1939 "%s %s %s",
1940 p_sysid->sysname, p_sysid->release, p_sysid->version);
1941 } else {
1942 snprintf(eiter->a.os_version, sizeof(eiter->a.os_version),
1943 "%s %s", "Linux", fc_host_system_hostname(vha->host));
1944 }
1945 alen = strlen(eiter->a.os_version);
1946 alen += 4 - (alen & 3);
1947 eiter->len = cpu_to_be16(4 + alen);
1948 size += 4 + alen;
1949
1950 ql_dbg(ql_dbg_disc, vha, 0x20ae,
1951 "OS Name and Version = %s.\n", eiter->a.os_version);
1952
1953 /* MAX CT Payload Length */
1954 eiter = entries + size;
1955 eiter->type = cpu_to_be16(FDMI_HBA_MAXIMUM_CT_PAYLOAD_LENGTH);
1956 eiter->a.max_ct_len = IS_FWI2_CAPABLE(ha) ?
1957 le16_to_cpu(icb24->frame_payload_size) :
1958 le16_to_cpu(ha->init_cb->frame_payload_size);
1959 eiter->a.max_ct_len = cpu_to_be32(eiter->a.max_ct_len);
1960 eiter->len = cpu_to_be16(4 + 4);
1961 size += 4 + 4;
1962
1963 ql_dbg(ql_dbg_disc, vha, 0x20af,
1964 "CT Payload Length = 0x%x.\n", eiter->a.max_ct_len);
1965
1966 /* Node Sybolic Name */
1967 eiter = entries + size;
1968 eiter->type = cpu_to_be16(FDMI_HBA_NODE_SYMBOLIC_NAME);
1969 qla2x00_get_sym_node_name(vha, eiter->a.sym_name,
1970 sizeof(eiter->a.sym_name));
1971 alen = strlen(eiter->a.sym_name);
1972 alen += 4 - (alen & 3);
1973 eiter->len = cpu_to_be16(4 + alen);
1974 size += 4 + alen;
1975
1976 ql_dbg(ql_dbg_disc, vha, 0x20b0,
1977 "Symbolic Name = %s.\n", eiter->a.sym_name);
1978
1979 /* Vendor Id */
1980 eiter = entries + size;
1981 eiter->type = cpu_to_be16(FDMI_HBA_VENDOR_ID);
1982 eiter->a.vendor_id = cpu_to_be32(0x1077);
1983 eiter->len = cpu_to_be16(4 + 4);
1984 size += 4 + 4;
1985
1986 ql_dbg(ql_dbg_disc, vha, 0x20b1,
1987 "Vendor Id = %x.\n", eiter->a.vendor_id);
1988
1989 /* Num Ports */
1990 eiter = entries + size;
1991 eiter->type = cpu_to_be16(FDMI_HBA_NUM_PORTS);
1992 eiter->a.num_ports = cpu_to_be32(1);
1993 eiter->len = cpu_to_be16(4 + 4);
1994 size += 4 + 4;
1995
1996 ql_dbg(ql_dbg_disc, vha, 0x20b2,
1997 "Port Num = %x.\n", eiter->a.num_ports);
1998
1999 /* Fabric Name */
2000 eiter = entries + size;
2001 eiter->type = cpu_to_be16(FDMI_HBA_FABRIC_NAME);
2002 memcpy(eiter->a.fabric_name, vha->fabric_node_name, WWN_SIZE);
2003 eiter->len = cpu_to_be16(4 + WWN_SIZE);
2004 size += 4 + WWN_SIZE;
2005
2006 ql_dbg(ql_dbg_disc, vha, 0x20b3,
2007 "Fabric Name = %016llx.\n", wwn_to_u64(eiter->a.fabric_name));
2008
2009 /* BIOS Version */
2010 eiter = entries + size;
2011 eiter->type = cpu_to_be16(FDMI_HBA_BOOT_BIOS_NAME);
2012 snprintf(eiter->a.bios_name, sizeof(eiter->a.bios_name),
2013 "BIOS %d.%02d", ha->bios_revision[1], ha->bios_revision[0]);
2014 alen = strlen(eiter->a.bios_name);
2015 alen += 4 - (alen & 3);
2016 eiter->len = cpu_to_be16(4 + alen);
2017 size += 4 + alen;
2018
2019 ql_dbg(ql_dbg_disc, vha, 0x20b4,
2020 "BIOS Name = %s\n", eiter->a.bios_name);
2021
2022 /* Vendor Identifier */
2023 eiter = entries + size;
2024 eiter->type = cpu_to_be16(FDMI_HBA_TYPE_VENDOR_IDENTIFIER);
Colin Ian King577419f2016-12-29 22:20:38 +00002025 snprintf(eiter->a.vendor_identifier, sizeof(eiter->a.vendor_identifier),
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002026 "%s", "QLGC");
Colin Ian King577419f2016-12-29 22:20:38 +00002027 alen = strlen(eiter->a.vendor_identifier);
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002028 alen += 4 - (alen & 3);
2029 eiter->len = cpu_to_be16(4 + alen);
2030 size += 4 + alen;
2031
Quinn Tran83548fe2017-06-02 09:12:01 -07002032 ql_dbg(ql_dbg_disc, vha, 0x201b,
Colin Ian King577419f2016-12-29 22:20:38 +00002033 "Vendor Identifier = %s.\n", eiter->a.vendor_identifier);
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002034
2035 /* Update MS request size. */
2036 qla2x00_update_ms_fdmi_iocb(vha, size + 16);
2037
2038 ql_dbg(ql_dbg_disc, vha, 0x20b5,
2039 "RHBA identifier = %016llx.\n",
2040 wwn_to_u64(ct_req->req.rhba2.hba_identifier));
2041 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x20b6,
2042 entries, size);
2043
2044 /* Execute MS IOCB */
2045 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
2046 sizeof(ms_iocb_entry_t));
2047 if (rval != QLA_SUCCESS) {
2048 /*EMPTY*/
2049 ql_dbg(ql_dbg_disc, vha, 0x20b7,
2050 "RHBA issue IOCB failed (%d).\n", rval);
2051 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, "RHBA") !=
2052 QLA_SUCCESS) {
2053 rval = QLA_FUNCTION_FAILED;
2054
2055 if (ct_rsp->header.reason_code == CT_REASON_CANNOT_PERFORM &&
2056 ct_rsp->header.explanation_code ==
2057 CT_EXPL_ALREADY_REGISTERED) {
2058 ql_dbg(ql_dbg_disc, vha, 0x20b8,
2059 "HBA already registered.\n");
2060 rval = QLA_ALREADY_REGISTERED;
2061 } else {
2062 ql_dbg(ql_dbg_disc, vha, 0x2016,
2063 "RHBA FDMI v2 failed, CT Reason code: 0x%x, CT Explanation 0x%x\n",
2064 ct_rsp->header.reason_code,
2065 ct_rsp->header.explanation_code);
2066 }
2067 } else {
2068 ql_dbg(ql_dbg_disc, vha, 0x20b9,
2069 "RHBA FDMI V2 exiting normally.\n");
2070 }
2071
2072 return rval;
2073}
2074
2075/**
Andrew Vasquezcca53352005-08-26 19:08:30 -07002076 * qla2x00_fdmi_dhba() -
2077 * @ha: HA context
2078 *
2079 * Returns 0 on success.
2080 */
2081static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002082qla2x00_fdmi_dhba(scsi_qla_host_t *vha)
Andrew Vasquezcca53352005-08-26 19:08:30 -07002083{
2084 int rval;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002085 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezcca53352005-08-26 19:08:30 -07002086 ms_iocb_entry_t *ms_pkt;
2087 struct ct_sns_req *ct_req;
2088 struct ct_sns_rsp *ct_rsp;
2089
2090 /* Issue RPA */
2091 /* Prepare common MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002092 ms_pkt = ha->isp_ops->prep_ms_fdmi_iocb(vha, DHBA_REQ_SIZE,
Andrew Vasquezcca53352005-08-26 19:08:30 -07002093 DHBA_RSP_SIZE);
2094
2095 /* Prepare CT request */
Bart Van Assche6ec6f902013-06-25 11:27:28 -04002096 ct_req = qla2x00_prep_ct_fdmi_req(ha->ct_sns, DHBA_CMD, DHBA_RSP_SIZE);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002097 ct_rsp = &ha->ct_sns->p.rsp;
2098
2099 /* Prepare FDMI command arguments -- portname. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002100 memcpy(ct_req->req.dhba.port_name, vha->port_name, WWN_SIZE);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002101
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002102 ql_dbg(ql_dbg_disc, vha, 0x2036,
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -04002103 "DHBA portname = %8phN.\n", ct_req->req.dhba.port_name);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002104
2105 /* Execute MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002106 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
Andrew Vasquezcca53352005-08-26 19:08:30 -07002107 sizeof(ms_iocb_entry_t));
2108 if (rval != QLA_SUCCESS) {
2109 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002110 ql_dbg(ql_dbg_disc, vha, 0x2037,
2111 "DHBA issue IOCB failed (%d).\n", rval);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002112 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, "DHBA") !=
Andrew Vasquezcca53352005-08-26 19:08:30 -07002113 QLA_SUCCESS) {
2114 rval = QLA_FUNCTION_FAILED;
2115 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002116 ql_dbg(ql_dbg_disc, vha, 0x2038,
2117 "DHBA exiting normally.\n");
Andrew Vasquezcca53352005-08-26 19:08:30 -07002118 }
2119
2120 return rval;
2121}
2122
2123/**
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002124 * qla2x00_fdmiv2_rpa() -
Andrew Vasquezcca53352005-08-26 19:08:30 -07002125 * @ha: HA context
2126 *
2127 * Returns 0 on success.
2128 */
2129static int
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002130qla2x00_fdmiv2_rpa(scsi_qla_host_t *vha)
Andrew Vasquezcca53352005-08-26 19:08:30 -07002131{
2132 int rval, alen;
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002133 uint32_t size;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002134 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezcca53352005-08-26 19:08:30 -07002135 ms_iocb_entry_t *ms_pkt;
2136 struct ct_sns_req *ct_req;
2137 struct ct_sns_rsp *ct_rsp;
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002138 void *entries;
2139 struct ct_fdmiv2_port_attr *eiter;
Andrew Vasquezcca53352005-08-26 19:08:30 -07002140 struct init_cb_24xx *icb24 = (struct init_cb_24xx *)ha->init_cb;
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002141 struct new_utsname *p_sysid = NULL;
Andrew Vasquezcca53352005-08-26 19:08:30 -07002142
2143 /* Issue RPA */
2144 /* Prepare common MS IOCB */
2145 /* Request size adjusted after CT preparation */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002146 ms_pkt = ha->isp_ops->prep_ms_fdmi_iocb(vha, 0, RPA_RSP_SIZE);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002147
2148 /* Prepare CT request */
Bart Van Assche6ec6f902013-06-25 11:27:28 -04002149 ct_req = qla2x00_prep_ct_fdmi_req(ha->ct_sns, RPA_CMD, RPA_RSP_SIZE);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002150 ct_rsp = &ha->ct_sns->p.rsp;
2151
2152 /* Prepare FDMI command arguments -- attribute block, attributes. */
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002153 memcpy(ct_req->req.rpa2.port_name, vha->port_name, WWN_SIZE);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002154 size = WWN_SIZE + 4;
2155
2156 /* Attributes */
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002157 ct_req->req.rpa2.attrs.count = cpu_to_be32(FDMIV2_PORT_ATTR_COUNT);
2158 entries = ct_req->req.rpa2.port_name;
Andrew Vasquezcca53352005-08-26 19:08:30 -07002159
2160 /* FC4 types. */
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002161 eiter = entries + size;
2162 eiter->type = cpu_to_be16(FDMI_PORT_FC4_TYPES);
2163 eiter->len = cpu_to_be16(4 + 32);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002164 eiter->a.fc4_types[2] = 0x01;
2165 size += 4 + 32;
2166
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002167 ql_dbg(ql_dbg_disc, vha, 0x20ba,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002168 "FC4_TYPES=%02x %02x.\n",
2169 eiter->a.fc4_types[2],
2170 eiter->a.fc4_types[1]);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002171
Duane Grigsby7d236482017-06-21 13:48:45 -07002172 if (vha->flags.nvme_enabled) {
2173 eiter->a.fc4_types[6] = 1; /* NVMe type 28h */
2174 ql_dbg(ql_dbg_disc, vha, 0x211f,
2175 "NVME FC4 Type = %02x 0x0 0x0 0x0 0x0 0x0.\n",
2176 eiter->a.fc4_types[6]);
2177 }
2178
Andrew Vasquezcca53352005-08-26 19:08:30 -07002179 /* Supported speed. */
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002180 eiter = entries + size;
2181 eiter->type = cpu_to_be16(FDMI_PORT_SUPPORT_SPEED);
2182 eiter->len = cpu_to_be16(4 + 4);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002183 if (IS_CNA_CAPABLE(ha))
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002184 eiter->a.sup_speed = cpu_to_be32(
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002185 FDMI_PORT_SPEED_10GB);
Chad Dupuisf73cb692014-02-26 04:15:06 -05002186 else if (IS_QLA27XX(ha))
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002187 eiter->a.sup_speed = cpu_to_be32(
2188 FDMI_PORT_SPEED_32GB|
2189 FDMI_PORT_SPEED_16GB|
Chad Dupuisf73cb692014-02-26 04:15:06 -05002190 FDMI_PORT_SPEED_8GB);
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002191 else if (IS_QLA2031(ha))
2192 eiter->a.sup_speed = cpu_to_be32(
2193 FDMI_PORT_SPEED_16GB|
2194 FDMI_PORT_SPEED_8GB|
Andrew Vasquez58815692007-07-19 15:05:58 -07002195 FDMI_PORT_SPEED_4GB);
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002196 else if (IS_QLA25XX(ha))
2197 eiter->a.sup_speed = cpu_to_be32(
2198 FDMI_PORT_SPEED_8GB|
2199 FDMI_PORT_SPEED_4GB|
2200 FDMI_PORT_SPEED_2GB|
2201 FDMI_PORT_SPEED_1GB);
2202 else if (IS_QLA24XX_TYPE(ha))
2203 eiter->a.sup_speed = cpu_to_be32(
2204 FDMI_PORT_SPEED_4GB|
2205 FDMI_PORT_SPEED_2GB|
2206 FDMI_PORT_SPEED_1GB);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002207 else if (IS_QLA23XX(ha))
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002208 eiter->a.sup_speed = cpu_to_be32(
2209 FDMI_PORT_SPEED_2GB|
2210 FDMI_PORT_SPEED_1GB);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002211 else
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002212 eiter->a.sup_speed = cpu_to_be32(
Andrew Vasquez58815692007-07-19 15:05:58 -07002213 FDMI_PORT_SPEED_1GB);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002214 size += 4 + 4;
2215
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002216 ql_dbg(ql_dbg_disc, vha, 0x20bb,
2217 "Supported Port Speed = %x.\n", eiter->a.sup_speed);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002218
2219 /* Current speed. */
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002220 eiter = entries + size;
2221 eiter->type = cpu_to_be16(FDMI_PORT_CURRENT_SPEED);
2222 eiter->len = cpu_to_be16(4 + 4);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002223 switch (ha->link_data_rate) {
Andrew Vasquez58815692007-07-19 15:05:58 -07002224 case PORT_SPEED_1GB:
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002225 eiter->a.cur_speed = cpu_to_be32(FDMI_PORT_SPEED_1GB);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002226 break;
Andrew Vasquez58815692007-07-19 15:05:58 -07002227 case PORT_SPEED_2GB:
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002228 eiter->a.cur_speed = cpu_to_be32(FDMI_PORT_SPEED_2GB);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002229 break;
Andrew Vasquez58815692007-07-19 15:05:58 -07002230 case PORT_SPEED_4GB:
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002231 eiter->a.cur_speed = cpu_to_be32(FDMI_PORT_SPEED_4GB);
Andrew Vasquez58815692007-07-19 15:05:58 -07002232 break;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002233 case PORT_SPEED_8GB:
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002234 eiter->a.cur_speed = cpu_to_be32(FDMI_PORT_SPEED_8GB);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002235 break;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002236 case PORT_SPEED_10GB:
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002237 eiter->a.cur_speed = cpu_to_be32(FDMI_PORT_SPEED_10GB);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002238 break;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002239 case PORT_SPEED_16GB:
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002240 eiter->a.cur_speed = cpu_to_be32(FDMI_PORT_SPEED_16GB);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002241 break;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002242 case PORT_SPEED_32GB:
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002243 eiter->a.cur_speed = cpu_to_be32(FDMI_PORT_SPEED_32GB);
Chad Dupuisf73cb692014-02-26 04:15:06 -05002244 break;
Andrew Vasquez58815692007-07-19 15:05:58 -07002245 default:
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002246 eiter->a.cur_speed = cpu_to_be32(FDMI_PORT_SPEED_UNKNOWN);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002247 break;
2248 }
2249 size += 4 + 4;
2250
Quinn Tran83548fe2017-06-02 09:12:01 -07002251 ql_dbg(ql_dbg_disc, vha, 0x2017,
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002252 "Current_Speed = %x.\n", eiter->a.cur_speed);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002253
2254 /* Max frame size. */
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002255 eiter = entries + size;
2256 eiter->type = cpu_to_be16(FDMI_PORT_MAX_FRAME_SIZE);
2257 eiter->len = cpu_to_be16(4 + 4);
2258 eiter->a.max_frame_size = IS_FWI2_CAPABLE(ha) ?
Seokmann Juc6852c42008-04-24 15:21:29 -07002259 le16_to_cpu(icb24->frame_payload_size):
2260 le16_to_cpu(ha->init_cb->frame_payload_size);
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002261 eiter->a.max_frame_size = cpu_to_be32(eiter->a.max_frame_size);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002262 size += 4 + 4;
2263
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002264 ql_dbg(ql_dbg_disc, vha, 0x20bc,
2265 "Max_Frame_Size = %x.\n", eiter->a.max_frame_size);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002266
2267 /* OS device name. */
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002268 eiter = entries + size;
2269 eiter->type = cpu_to_be16(FDMI_PORT_OS_DEVICE_NAME);
Paul Bollef24b6972013-02-08 01:57:55 -05002270 alen = strlen(QLA2XXX_DRIVER_NAME);
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002271 snprintf(eiter->a.os_dev_name, sizeof(eiter->a.os_dev_name),
2272 "%s:host%lu", QLA2XXX_DRIVER_NAME, vha->host_no);
2273 alen += 4 - (alen & 3);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002274 eiter->len = cpu_to_be16(4 + alen);
2275 size += 4 + alen;
2276
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002277 ql_dbg(ql_dbg_disc, vha, 0x20be,
2278 "OS_Device_Name = %s.\n", eiter->a.os_dev_name);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002279
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07002280 /* Hostname. */
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002281 eiter = entries + size;
2282 eiter->type = cpu_to_be16(FDMI_PORT_HOST_NAME);
2283 p_sysid = utsname();
2284 if (p_sysid) {
2285 snprintf(eiter->a.host_name, sizeof(eiter->a.host_name),
2286 "%s", p_sysid->nodename);
2287 } else {
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07002288 snprintf(eiter->a.host_name, sizeof(eiter->a.host_name),
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002289 "%s", fc_host_system_hostname(vha->host));
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07002290 }
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002291 alen = strlen(eiter->a.host_name);
2292 alen += 4 - (alen & 3);
2293 eiter->len = cpu_to_be16(4 + alen);
2294 size += 4 + alen;
2295
Quinn Tran83548fe2017-06-02 09:12:01 -07002296 ql_dbg(ql_dbg_disc, vha, 0x201a,
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002297 "HostName=%s.\n", eiter->a.host_name);
2298
2299 /* Node Name */
2300 eiter = entries + size;
2301 eiter->type = cpu_to_be16(FDMI_PORT_NODE_NAME);
2302 memcpy(eiter->a.node_name, vha->node_name, WWN_SIZE);
2303 eiter->len = cpu_to_be16(4 + WWN_SIZE);
2304 size += 4 + WWN_SIZE;
2305
2306 ql_dbg(ql_dbg_disc, vha, 0x20c0,
2307 "Node Name = %016llx.\n", wwn_to_u64(eiter->a.node_name));
2308
2309 /* Port Name */
2310 eiter = entries + size;
2311 eiter->type = cpu_to_be16(FDMI_PORT_NAME);
2312 memcpy(eiter->a.port_name, vha->port_name, WWN_SIZE);
2313 eiter->len = cpu_to_be16(4 + WWN_SIZE);
2314 size += 4 + WWN_SIZE;
2315
2316 ql_dbg(ql_dbg_disc, vha, 0x20c1,
2317 "Port Name = %016llx.\n", wwn_to_u64(eiter->a.port_name));
2318
2319 /* Port Symbolic Name */
2320 eiter = entries + size;
2321 eiter->type = cpu_to_be16(FDMI_PORT_SYM_NAME);
2322 qla2x00_get_sym_node_name(vha, eiter->a.port_sym_name,
2323 sizeof(eiter->a.port_sym_name));
2324 alen = strlen(eiter->a.port_sym_name);
2325 alen += 4 - (alen & 3);
2326 eiter->len = cpu_to_be16(4 + alen);
2327 size += 4 + alen;
2328
2329 ql_dbg(ql_dbg_disc, vha, 0x20c2,
2330 "port symbolic name = %s\n", eiter->a.port_sym_name);
2331
2332 /* Port Type */
2333 eiter = entries + size;
2334 eiter->type = cpu_to_be16(FDMI_PORT_TYPE);
2335 eiter->a.port_type = cpu_to_be32(NS_NX_PORT_TYPE);
2336 eiter->len = cpu_to_be16(4 + 4);
2337 size += 4 + 4;
2338
2339 ql_dbg(ql_dbg_disc, vha, 0x20c3,
2340 "Port Type = %x.\n", eiter->a.port_type);
2341
2342 /* Class of Service */
2343 eiter = entries + size;
2344 eiter->type = cpu_to_be16(FDMI_PORT_SUPP_COS);
2345 eiter->a.port_supported_cos = cpu_to_be32(FC_CLASS_3);
2346 eiter->len = cpu_to_be16(4 + 4);
2347 size += 4 + 4;
2348
2349 ql_dbg(ql_dbg_disc, vha, 0x20c4,
2350 "Supported COS = %08x\n", eiter->a.port_supported_cos);
2351
2352 /* Port Fabric Name */
2353 eiter = entries + size;
2354 eiter->type = cpu_to_be16(FDMI_PORT_FABRIC_NAME);
2355 memcpy(eiter->a.fabric_name, vha->fabric_node_name, WWN_SIZE);
2356 eiter->len = cpu_to_be16(4 + WWN_SIZE);
2357 size += 4 + WWN_SIZE;
2358
2359 ql_dbg(ql_dbg_disc, vha, 0x20c5,
2360 "Fabric Name = %016llx.\n", wwn_to_u64(eiter->a.fabric_name));
2361
2362 /* FC4_type */
2363 eiter = entries + size;
2364 eiter->type = cpu_to_be16(FDMI_PORT_FC4_TYPE);
2365 eiter->a.port_fc4_type[0] = 0;
2366 eiter->a.port_fc4_type[1] = 0;
2367 eiter->a.port_fc4_type[2] = 1;
2368 eiter->a.port_fc4_type[3] = 0;
2369 eiter->len = cpu_to_be16(4 + 32);
2370 size += 4 + 32;
2371
2372 ql_dbg(ql_dbg_disc, vha, 0x20c6,
2373 "Port Active FC4 Type = %02x %02x.\n",
2374 eiter->a.port_fc4_type[2], eiter->a.port_fc4_type[1]);
2375
Duane Grigsby7d236482017-06-21 13:48:45 -07002376 if (vha->flags.nvme_enabled) {
2377 eiter->a.port_fc4_type[4] = 0;
2378 eiter->a.port_fc4_type[5] = 0;
2379 eiter->a.port_fc4_type[6] = 1; /* NVMe type 28h */
2380 ql_dbg(ql_dbg_disc, vha, 0x2120,
2381 "NVME Port Active FC4 Type = %02x 0x0 0x0 0x0 0x0 0x0.\n",
2382 eiter->a.port_fc4_type[6]);
2383 }
2384
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002385 /* Port State */
2386 eiter = entries + size;
2387 eiter->type = cpu_to_be16(FDMI_PORT_STATE);
2388 eiter->a.port_state = cpu_to_be32(1);
2389 eiter->len = cpu_to_be16(4 + 4);
2390 size += 4 + 4;
2391
2392 ql_dbg(ql_dbg_disc, vha, 0x20c7,
2393 "Port State = %x.\n", eiter->a.port_state);
2394
2395 /* Number of Ports */
2396 eiter = entries + size;
2397 eiter->type = cpu_to_be16(FDMI_PORT_COUNT);
2398 eiter->a.num_ports = cpu_to_be32(1);
2399 eiter->len = cpu_to_be16(4 + 4);
2400 size += 4 + 4;
2401
2402 ql_dbg(ql_dbg_disc, vha, 0x20c8,
2403 "Number of ports = %x.\n", eiter->a.num_ports);
2404
2405 /* Port Id */
2406 eiter = entries + size;
2407 eiter->type = cpu_to_be16(FDMI_PORT_ID);
2408 eiter->a.port_id = cpu_to_be32(vha->d_id.b24);
2409 eiter->len = cpu_to_be16(4 + 4);
2410 size += 4 + 4;
2411
Quinn Tran83548fe2017-06-02 09:12:01 -07002412 ql_dbg(ql_dbg_disc, vha, 0x201c,
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002413 "Port Id = %x.\n", eiter->a.port_id);
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07002414
Andrew Vasquezcca53352005-08-26 19:08:30 -07002415 /* Update MS request size. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002416 qla2x00_update_ms_fdmi_iocb(vha, size + 16);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002417
Quinn Tran83548fe2017-06-02 09:12:01 -07002418 ql_dbg(ql_dbg_disc, vha, 0x2018,
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -04002419 "RPA portname= %8phN size=%d.\n", ct_req->req.rpa.port_name, size);
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002420 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x20ca,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002421 entries, size);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002422
2423 /* Execute MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002424 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
Andrew Vasquezcca53352005-08-26 19:08:30 -07002425 sizeof(ms_iocb_entry_t));
2426 if (rval != QLA_SUCCESS) {
2427 /*EMPTY*/
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002428 ql_dbg(ql_dbg_disc, vha, 0x20cb,
2429 "RPA FDMI v2 issue IOCB failed (%d).\n", rval);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002430 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, "RPA") !=
Andrew Vasquezcca53352005-08-26 19:08:30 -07002431 QLA_SUCCESS) {
2432 rval = QLA_FUNCTION_FAILED;
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002433 if (ct_rsp->header.reason_code == CT_REASON_CANNOT_PERFORM &&
2434 ct_rsp->header.explanation_code ==
2435 CT_EXPL_ALREADY_REGISTERED) {
2436 ql_dbg(ql_dbg_disc, vha, 0x20ce,
2437 "RPA FDMI v2 already registered\n");
2438 rval = QLA_ALREADY_REGISTERED;
2439 } else {
2440 ql_dbg(ql_dbg_disc, vha, 0x2020,
2441 "RPA FDMI v2 failed, CT Reason code: 0x%x, CT Explanation 0x%x\n",
2442 ct_rsp->header.reason_code,
2443 ct_rsp->header.explanation_code);
2444 }
Andrew Vasquezcca53352005-08-26 19:08:30 -07002445 } else {
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002446 ql_dbg(ql_dbg_disc, vha, 0x20cc,
2447 "RPA FDMI V2 exiting normally.\n");
Andrew Vasquezcca53352005-08-26 19:08:30 -07002448 }
2449
2450 return rval;
2451}
2452
2453/**
2454 * qla2x00_fdmi_register() -
2455 * @ha: HA context
2456 *
2457 * Returns 0 on success.
2458 */
2459int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002460qla2x00_fdmi_register(scsi_qla_host_t *vha)
Andrew Vasquezcca53352005-08-26 19:08:30 -07002461{
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002462 int rval = QLA_FUNCTION_FAILED;
2463 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez80de7ef2009-07-31 15:09:33 -07002464
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002465 if (IS_QLA2100(ha) || IS_QLA2200(ha) ||
2466 IS_QLAFX00(ha))
Andrew Vasquez80de7ef2009-07-31 15:09:33 -07002467 return QLA_FUNCTION_FAILED;
Andrew Vasquezcca53352005-08-26 19:08:30 -07002468
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002469 rval = qla2x00_mgmt_svr_login(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002470 if (rval)
2471 return rval;
2472
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002473 rval = qla2x00_fdmiv2_rhba(vha);
2474 if (rval) {
2475 if (rval != QLA_ALREADY_REGISTERED)
2476 goto try_fdmi;
2477
2478 rval = qla2x00_fdmi_dhba(vha);
2479 if (rval)
2480 goto try_fdmi;
2481
2482 rval = qla2x00_fdmiv2_rhba(vha);
2483 if (rval)
2484 goto try_fdmi;
2485 }
2486 rval = qla2x00_fdmiv2_rpa(vha);
2487 if (rval)
2488 goto try_fdmi;
2489
2490 goto out;
2491
2492try_fdmi:
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002493 rval = qla2x00_fdmi_rhba(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002494 if (rval) {
2495 if (rval != QLA_ALREADY_REGISTERED)
2496 return rval;
2497
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002498 rval = qla2x00_fdmi_dhba(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002499 if (rval)
2500 return rval;
2501
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002502 rval = qla2x00_fdmi_rhba(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002503 if (rval)
2504 return rval;
2505 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002506 rval = qla2x00_fdmi_rpa(vha);
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002507out:
Andrew Vasquezcca53352005-08-26 19:08:30 -07002508 return rval;
2509}
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002510
2511/**
2512 * qla2x00_gfpn_id() - SNS Get Fabric Port Name (GFPN_ID) query.
2513 * @ha: HA context
2514 * @list: switch info entries to populate
2515 *
2516 * Returns 0 on success.
2517 */
2518int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002519qla2x00_gfpn_id(scsi_qla_host_t *vha, sw_info_t *list)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002520{
Chad Dupuis642ef982012-02-09 11:15:57 -08002521 int rval = QLA_SUCCESS;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002522 uint16_t i;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002523 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002524 ms_iocb_entry_t *ms_pkt;
2525 struct ct_sns_req *ct_req;
2526 struct ct_sns_rsp *ct_rsp;
Quinn Tran726b8542017-01-19 22:28:00 -08002527 struct ct_arg arg;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002528
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002529 if (!IS_IIDMA_CAPABLE(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002530 return QLA_FUNCTION_FAILED;
2531
Quinn Tran726b8542017-01-19 22:28:00 -08002532 arg.iocb = ha->ms_iocb;
2533 arg.req_dma = ha->ct_sns_dma;
2534 arg.rsp_dma = ha->ct_sns_dma;
2535 arg.req_size = GFPN_ID_REQ_SIZE;
2536 arg.rsp_size = GFPN_ID_RSP_SIZE;
2537 arg.nport_handle = NPH_SNS;
2538
Chad Dupuis642ef982012-02-09 11:15:57 -08002539 for (i = 0; i < ha->max_fibre_devices; i++) {
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002540 /* Issue GFPN_ID */
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002541 /* Prepare common MS IOCB */
Quinn Tran726b8542017-01-19 22:28:00 -08002542 ms_pkt = ha->isp_ops->prep_ms_iocb(vha, &arg);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002543
2544 /* Prepare CT request */
Bart Van Assche6ec6f902013-06-25 11:27:28 -04002545 ct_req = qla2x00_prep_ct_req(ha->ct_sns, GFPN_ID_CMD,
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002546 GFPN_ID_RSP_SIZE);
2547 ct_rsp = &ha->ct_sns->p.rsp;
2548
2549 /* Prepare CT arguments -- port_id */
2550 ct_req->req.port_id.port_id[0] = list[i].d_id.b.domain;
2551 ct_req->req.port_id.port_id[1] = list[i].d_id.b.area;
2552 ct_req->req.port_id.port_id[2] = list[i].d_id.b.al_pa;
2553
2554 /* Execute MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002555 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002556 sizeof(ms_iocb_entry_t));
2557 if (rval != QLA_SUCCESS) {
2558 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002559 ql_dbg(ql_dbg_disc, vha, 0x2023,
2560 "GFPN_ID issue IOCB failed (%d).\n", rval);
Arun Easidafdf892012-02-09 11:16:00 -08002561 break;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002562 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp,
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002563 "GFPN_ID") != QLA_SUCCESS) {
2564 rval = QLA_FUNCTION_FAILED;
Arun Easidafdf892012-02-09 11:16:00 -08002565 break;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002566 } else {
2567 /* Save fabric portname */
2568 memcpy(list[i].fabric_port_name,
2569 ct_rsp->rsp.gfpn_id.port_name, WWN_SIZE);
2570 }
2571
2572 /* Last device exit. */
2573 if (list[i].d_id.b.rsvd_1 != 0)
2574 break;
2575 }
2576
2577 return (rval);
2578}
2579
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002580
2581static inline struct ct_sns_req *
Bart Van Assche6ec6f902013-06-25 11:27:28 -04002582qla24xx_prep_ct_fm_req(struct ct_sns_pkt *p, uint16_t cmd,
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002583 uint16_t rsp_size)
2584{
Bart Van Assche6ec6f902013-06-25 11:27:28 -04002585 memset(p, 0, sizeof(struct ct_sns_pkt));
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002586
Bart Van Assche6ec6f902013-06-25 11:27:28 -04002587 p->p.req.header.revision = 0x01;
2588 p->p.req.header.gs_type = 0xFA;
2589 p->p.req.header.gs_subtype = 0x01;
2590 p->p.req.command = cpu_to_be16(cmd);
2591 p->p.req.max_rsp_size = cpu_to_be16((rsp_size - 16) / 4);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002592
Bart Van Assche6ec6f902013-06-25 11:27:28 -04002593 return &p->p.req;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002594}
2595
2596/**
2597 * qla2x00_gpsc() - FCS Get Port Speed Capabilities (GPSC) query.
2598 * @ha: HA context
2599 * @list: switch info entries to populate
2600 *
2601 * Returns 0 on success.
2602 */
2603int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002604qla2x00_gpsc(scsi_qla_host_t *vha, sw_info_t *list)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002605{
2606 int rval;
2607 uint16_t i;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002608 struct qla_hw_data *ha = vha->hw;
Quinn Tran726b8542017-01-19 22:28:00 -08002609 ms_iocb_entry_t *ms_pkt;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002610 struct ct_sns_req *ct_req;
2611 struct ct_sns_rsp *ct_rsp;
Quinn Tran726b8542017-01-19 22:28:00 -08002612 struct ct_arg arg;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002613
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002614 if (!IS_IIDMA_CAPABLE(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002615 return QLA_FUNCTION_FAILED;
Andrew Vasquez4346b142006-12-13 19:20:28 -08002616 if (!ha->flags.gpsc_supported)
2617 return QLA_FUNCTION_FAILED;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002618
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002619 rval = qla2x00_mgmt_svr_login(vha);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002620 if (rval)
2621 return rval;
2622
Quinn Tran726b8542017-01-19 22:28:00 -08002623 arg.iocb = ha->ms_iocb;
2624 arg.req_dma = ha->ct_sns_dma;
2625 arg.rsp_dma = ha->ct_sns_dma;
2626 arg.req_size = GPSC_REQ_SIZE;
2627 arg.rsp_size = GPSC_RSP_SIZE;
2628 arg.nport_handle = vha->mgmt_svr_loop_id;
2629
Chad Dupuis642ef982012-02-09 11:15:57 -08002630 for (i = 0; i < ha->max_fibre_devices; i++) {
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002631 /* Issue GFPN_ID */
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002632 /* Prepare common MS IOCB */
Quinn Tran726b8542017-01-19 22:28:00 -08002633 ms_pkt = qla24xx_prep_ms_iocb(vha, &arg);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002634
2635 /* Prepare CT request */
Bart Van Assche6ec6f902013-06-25 11:27:28 -04002636 ct_req = qla24xx_prep_ct_fm_req(ha->ct_sns, GPSC_CMD,
2637 GPSC_RSP_SIZE);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002638 ct_rsp = &ha->ct_sns->p.rsp;
2639
2640 /* Prepare CT arguments -- port_name */
2641 memcpy(ct_req->req.gpsc.port_name, list[i].fabric_port_name,
2642 WWN_SIZE);
2643
2644 /* Execute MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002645 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002646 sizeof(ms_iocb_entry_t));
2647 if (rval != QLA_SUCCESS) {
2648 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002649 ql_dbg(ql_dbg_disc, vha, 0x2059,
2650 "GPSC issue IOCB failed (%d).\n", rval);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002651 } else if ((rval = qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp,
Andrew Vasquez4346b142006-12-13 19:20:28 -08002652 "GPSC")) != QLA_SUCCESS) {
2653 /* FM command unsupported? */
2654 if (rval == QLA_INVALID_COMMAND &&
Andrew Vasquez3fe7cfb2008-04-03 13:13:23 -07002655 (ct_rsp->header.reason_code ==
2656 CT_REASON_INVALID_COMMAND_CODE ||
2657 ct_rsp->header.reason_code ==
2658 CT_REASON_COMMAND_UNSUPPORTED)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002659 ql_dbg(ql_dbg_disc, vha, 0x205a,
2660 "GPSC command unsupported, disabling "
2661 "query.\n");
Andrew Vasquez4346b142006-12-13 19:20:28 -08002662 ha->flags.gpsc_supported = 0;
2663 rval = QLA_FUNCTION_FAILED;
2664 break;
2665 }
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002666 rval = QLA_FUNCTION_FAILED;
2667 } else {
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002668 /* Save port-speed */
2669 switch (be16_to_cpu(ct_rsp->rsp.gpsc.speed)) {
2670 case BIT_15:
2671 list[i].fp_speed = PORT_SPEED_1GB;
2672 break;
2673 case BIT_14:
2674 list[i].fp_speed = PORT_SPEED_2GB;
2675 break;
2676 case BIT_13:
2677 list[i].fp_speed = PORT_SPEED_4GB;
2678 break;
Andrew Vasquez9f8fdde2009-06-03 09:55:22 -07002679 case BIT_12:
2680 list[i].fp_speed = PORT_SPEED_10GB;
2681 break;
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002682 case BIT_11:
2683 list[i].fp_speed = PORT_SPEED_8GB;
2684 break;
Joe Carnuccioc53dfac2012-11-21 02:40:39 -05002685 case BIT_10:
2686 list[i].fp_speed = PORT_SPEED_16GB;
2687 break;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002688 case BIT_8:
2689 list[i].fp_speed = PORT_SPEED_32GB;
2690 break;
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002691 }
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002692
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002693 ql_dbg(ql_dbg_disc, vha, 0x205b,
2694 "GPSC ext entry - fpn "
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -04002695 "%8phN speeds=%04x speed=%04x.\n",
2696 list[i].fabric_port_name,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002697 be16_to_cpu(ct_rsp->rsp.gpsc.speeds),
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002698 be16_to_cpu(ct_rsp->rsp.gpsc.speed));
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002699 }
2700
2701 /* Last device exit. */
2702 if (list[i].d_id.b.rsvd_1 != 0)
2703 break;
2704 }
2705
2706 return (rval);
2707}
Chad Dupuise8c72ba2010-07-23 15:28:25 +05002708
2709/**
2710 * qla2x00_gff_id() - SNS Get FC-4 Features (GFF_ID) query.
2711 *
2712 * @ha: HA context
2713 * @list: switch info entries to populate
2714 *
2715 */
2716void
2717qla2x00_gff_id(scsi_qla_host_t *vha, sw_info_t *list)
2718{
2719 int rval;
2720 uint16_t i;
2721
2722 ms_iocb_entry_t *ms_pkt;
2723 struct ct_sns_req *ct_req;
2724 struct ct_sns_rsp *ct_rsp;
2725 struct qla_hw_data *ha = vha->hw;
2726 uint8_t fcp_scsi_features = 0;
Quinn Tran726b8542017-01-19 22:28:00 -08002727 struct ct_arg arg;
Chad Dupuise8c72ba2010-07-23 15:28:25 +05002728
Chad Dupuis642ef982012-02-09 11:15:57 -08002729 for (i = 0; i < ha->max_fibre_devices; i++) {
Chad Dupuise8c72ba2010-07-23 15:28:25 +05002730 /* Set default FC4 Type as UNKNOWN so the default is to
2731 * Process this port */
2732 list[i].fc4_type = FC4_TYPE_UNKNOWN;
2733
2734 /* Do not attempt GFF_ID if we are not FWI_2 capable */
2735 if (!IS_FWI2_CAPABLE(ha))
2736 continue;
2737
Quinn Tran726b8542017-01-19 22:28:00 -08002738 arg.iocb = ha->ms_iocb;
2739 arg.req_dma = ha->ct_sns_dma;
2740 arg.rsp_dma = ha->ct_sns_dma;
2741 arg.req_size = GFF_ID_REQ_SIZE;
2742 arg.rsp_size = GFF_ID_RSP_SIZE;
2743 arg.nport_handle = NPH_SNS;
2744
Chad Dupuise8c72ba2010-07-23 15:28:25 +05002745 /* Prepare common MS IOCB */
Quinn Tran726b8542017-01-19 22:28:00 -08002746 ms_pkt = ha->isp_ops->prep_ms_iocb(vha, &arg);
Chad Dupuise8c72ba2010-07-23 15:28:25 +05002747
2748 /* Prepare CT request */
Bart Van Assche6ec6f902013-06-25 11:27:28 -04002749 ct_req = qla2x00_prep_ct_req(ha->ct_sns, GFF_ID_CMD,
Chad Dupuise8c72ba2010-07-23 15:28:25 +05002750 GFF_ID_RSP_SIZE);
2751 ct_rsp = &ha->ct_sns->p.rsp;
2752
2753 /* Prepare CT arguments -- port_id */
2754 ct_req->req.port_id.port_id[0] = list[i].d_id.b.domain;
2755 ct_req->req.port_id.port_id[1] = list[i].d_id.b.area;
2756 ct_req->req.port_id.port_id[2] = list[i].d_id.b.al_pa;
2757
2758 /* Execute MS IOCB */
2759 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
2760 sizeof(ms_iocb_entry_t));
2761
2762 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002763 ql_dbg(ql_dbg_disc, vha, 0x205c,
2764 "GFF_ID issue IOCB failed (%d).\n", rval);
Chad Dupuise8c72ba2010-07-23 15:28:25 +05002765 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp,
Andrew Vasquez7a78ced2011-02-23 15:27:12 -08002766 "GFF_ID") != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002767 ql_dbg(ql_dbg_disc, vha, 0x205d,
2768 "GFF_ID IOCB status had a failure status code.\n");
Chad Dupuise8c72ba2010-07-23 15:28:25 +05002769 } else {
2770 fcp_scsi_features =
2771 ct_rsp->rsp.gff_id.fc4_features[GFF_FCP_SCSI_OFFSET];
2772 fcp_scsi_features &= 0x0f;
2773
2774 if (fcp_scsi_features)
2775 list[i].fc4_type = FC4_TYPE_FCP_SCSI;
2776 else
2777 list[i].fc4_type = FC4_TYPE_OTHER;
Duane Grigsbyd3bae932017-06-21 13:48:44 -07002778
2779 list[i].fc4f_nvme =
2780 ct_rsp->rsp.gff_id.fc4_features[GFF_NVME_OFFSET];
2781 list[i].fc4f_nvme &= 0xf;
Chad Dupuise8c72ba2010-07-23 15:28:25 +05002782 }
2783
2784 /* Last device exit. */
2785 if (list[i].d_id.b.rsvd_1 != 0)
2786 break;
2787 }
2788}
Quinn Tran726b8542017-01-19 22:28:00 -08002789
2790/* GID_PN completion processing. */
2791void qla24xx_handle_gidpn_event(scsi_qla_host_t *vha, struct event_arg *ea)
2792{
2793 fc_port_t *fcport = ea->fcport;
2794
Quinn Tran83548fe2017-06-02 09:12:01 -07002795 ql_dbg(ql_dbg_disc, vha, 0x201d,
2796 "%s %8phC login state %d\n",
2797 __func__, fcport->port_name, fcport->fw_login_state);
Quinn Tran726b8542017-01-19 22:28:00 -08002798
2799 if (ea->sp->gen2 != fcport->login_gen) {
2800 /* PLOGI/PRLI/LOGO came in while cmd was out.*/
Quinn Tran83548fe2017-06-02 09:12:01 -07002801 ql_dbg(ql_dbg_disc, vha, 0x201e,
Quinn Tran726b8542017-01-19 22:28:00 -08002802 "%s %8phC generation changed rscn %d|%d login %d|%d \n",
2803 __func__, fcport->port_name, fcport->last_rscn_gen,
2804 fcport->rscn_gen, fcport->last_login_gen, fcport->login_gen);
2805 return;
2806 }
2807
2808 if (!ea->rc) {
2809 if (ea->sp->gen1 == fcport->rscn_gen) {
2810 fcport->scan_state = QLA_FCPORT_FOUND;
2811 fcport->flags |= FCF_FABRIC_DEVICE;
2812
2813 if (fcport->d_id.b24 == ea->id.b24) {
2814 /* cable plugged into the same place */
2815 switch (vha->host->active_mode) {
2816 case MODE_TARGET:
2817 /* NOOP. let the other guy login to us.*/
2818 break;
2819 case MODE_INITIATOR:
2820 case MODE_DUAL:
2821 default:
Quinn Trana07fc0a2017-08-23 15:05:21 -07002822 ql_dbg(ql_dbg_disc, vha, 0x201f,
2823 "%s %d %8phC post %s\n", __func__,
2824 __LINE__, fcport->port_name,
2825 (atomic_read(&fcport->state) ==
2826 FCS_ONLINE) ? "gpdb" : "gnl");
2827
Quinn Tran726b8542017-01-19 22:28:00 -08002828 if (atomic_read(&fcport->state) ==
2829 FCS_ONLINE)
Quinn Trana07fc0a2017-08-23 15:05:21 -07002830 qla24xx_post_gpdb_work(vha,
2831 fcport, PDO_FORCE_ADISC);
2832 else
2833 qla24xx_post_gnl_work(vha,
2834 fcport);
Quinn Tran726b8542017-01-19 22:28:00 -08002835 break;
2836 }
2837 } else { /* fcport->d_id.b24 != ea->id.b24 */
2838 fcport->d_id.b24 = ea->id.b24;
Quinn Trana084fd62017-12-04 14:45:00 -08002839 if (fcport->deleted != QLA_SESS_DELETED) {
Quinn Tran83548fe2017-06-02 09:12:01 -07002840 ql_dbg(ql_dbg_disc, vha, 0x2021,
Quinn Tran726b8542017-01-19 22:28:00 -08002841 "%s %d %8phC post del sess\n",
2842 __func__, __LINE__, fcport->port_name);
2843 qlt_schedule_sess_for_deletion_lock(fcport);
2844 }
2845 }
2846 } else { /* ea->sp->gen1 != fcport->rscn_gen */
Quinn Tran83548fe2017-06-02 09:12:01 -07002847 ql_dbg(ql_dbg_disc, vha, 0x2022,
Quinn Tran726b8542017-01-19 22:28:00 -08002848 "%s %d %8phC post gidpn\n",
2849 __func__, __LINE__, fcport->port_name);
2850 /* rscn came in while cmd was out */
2851 qla24xx_post_gidpn_work(vha, fcport);
2852 }
2853 } else { /* ea->rc */
2854 /* cable pulled */
2855 if (ea->sp->gen1 == fcport->rscn_gen) {
2856 if (ea->sp->gen2 == fcport->login_gen) {
Quinn Tran83548fe2017-06-02 09:12:01 -07002857 ql_dbg(ql_dbg_disc, vha, 0x2042,
Quinn Tran726b8542017-01-19 22:28:00 -08002858 "%s %d %8phC post del sess\n", __func__,
2859 __LINE__, fcport->port_name);
2860 qlt_schedule_sess_for_deletion_lock(fcport);
2861 } else {
Quinn Tran83548fe2017-06-02 09:12:01 -07002862 ql_dbg(ql_dbg_disc, vha, 0x2045,
Quinn Tran726b8542017-01-19 22:28:00 -08002863 "%s %d %8phC login\n", __func__, __LINE__,
2864 fcport->port_name);
2865 qla24xx_fcport_handle_login(vha, fcport);
2866 }
2867 } else {
Quinn Tran83548fe2017-06-02 09:12:01 -07002868 ql_dbg(ql_dbg_disc, vha, 0x2049,
Quinn Tran726b8542017-01-19 22:28:00 -08002869 "%s %d %8phC post gidpn\n", __func__, __LINE__,
2870 fcport->port_name);
2871 qla24xx_post_gidpn_work(vha, fcport);
2872 }
2873 }
2874} /* gidpn_event */
2875
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08002876static void qla2x00_async_gidpn_sp_done(void *s, int res)
Quinn Tran726b8542017-01-19 22:28:00 -08002877{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08002878 struct srb *sp = s;
2879 struct scsi_qla_host *vha = sp->vha;
Quinn Tran726b8542017-01-19 22:28:00 -08002880 fc_port_t *fcport = sp->fcport;
2881 u8 *id = fcport->ct_desc.ct_sns->p.rsp.rsp.gid_pn.port_id;
2882 struct event_arg ea;
2883
2884 fcport->flags &= ~FCF_ASYNC_SENT;
2885
2886 memset(&ea, 0, sizeof(ea));
2887 ea.fcport = fcport;
2888 ea.id.b.domain = id[0];
2889 ea.id.b.area = id[1];
2890 ea.id.b.al_pa = id[2];
2891 ea.sp = sp;
2892 ea.rc = res;
2893 ea.event = FCME_GIDPN_DONE;
2894
Quinn Tran25ad76b2017-12-04 14:45:01 -08002895 if (res == QLA_FUNCTION_TIMEOUT) {
2896 ql_dbg(ql_dbg_disc, sp->vha, 0xffff,
2897 "Async done-%s WWPN %8phC timed out.\n",
2898 sp->name, fcport->port_name);
2899 qla24xx_post_gidpn_work(sp->vha, fcport);
2900 sp->free(sp);
2901 return;
2902 } else if (res) {
2903 ql_dbg(ql_dbg_disc, sp->vha, 0xffff,
2904 "Async done-%s fail res %x, WWPN %8phC\n",
2905 sp->name, res, fcport->port_name);
2906 } else {
2907 ql_dbg(ql_dbg_disc, vha, 0x204f,
2908 "Async done-%s good WWPN %8phC ID %3phC\n",
2909 sp->name, fcport->port_name, id);
2910 }
Quinn Tran726b8542017-01-19 22:28:00 -08002911
2912 qla2x00_fcport_event_handler(vha, &ea);
2913
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08002914 sp->free(sp);
Quinn Tran726b8542017-01-19 22:28:00 -08002915}
2916
2917int qla24xx_async_gidpn(scsi_qla_host_t *vha, fc_port_t *fcport)
2918{
2919 int rval = QLA_FUNCTION_FAILED;
2920 struct ct_sns_req *ct_req;
2921 srb_t *sp;
2922
2923 if (!vha->flags.online)
2924 goto done;
2925
2926 fcport->flags |= FCF_ASYNC_SENT;
2927 fcport->disc_state = DSC_GID_PN;
2928 fcport->scan_state = QLA_FCPORT_SCAN;
2929 sp = qla2x00_get_sp(vha, fcport, GFP_ATOMIC);
2930 if (!sp)
2931 goto done;
2932
2933 sp->type = SRB_CT_PTHRU_CMD;
2934 sp->name = "gidpn";
2935 sp->gen1 = fcport->rscn_gen;
2936 sp->gen2 = fcport->login_gen;
2937
2938 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
2939
2940 /* CT_IU preamble */
2941 ct_req = qla2x00_prep_ct_req(fcport->ct_desc.ct_sns, GID_PN_CMD,
2942 GID_PN_RSP_SIZE);
2943
2944 /* GIDPN req */
2945 memcpy(ct_req->req.gid_pn.port_name, fcport->port_name,
2946 WWN_SIZE);
2947
2948 /* req & rsp use the same buffer */
2949 sp->u.iocb_cmd.u.ctarg.req = fcport->ct_desc.ct_sns;
2950 sp->u.iocb_cmd.u.ctarg.req_dma = fcport->ct_desc.ct_sns_dma;
2951 sp->u.iocb_cmd.u.ctarg.rsp = fcport->ct_desc.ct_sns;
2952 sp->u.iocb_cmd.u.ctarg.rsp_dma = fcport->ct_desc.ct_sns_dma;
2953 sp->u.iocb_cmd.u.ctarg.req_size = GID_PN_REQ_SIZE;
2954 sp->u.iocb_cmd.u.ctarg.rsp_size = GID_PN_RSP_SIZE;
2955 sp->u.iocb_cmd.u.ctarg.nport_handle = NPH_SNS;
2956
2957 sp->u.iocb_cmd.timeout = qla2x00_async_iocb_timeout;
2958 sp->done = qla2x00_async_gidpn_sp_done;
2959
2960 rval = qla2x00_start_sp(sp);
2961 if (rval != QLA_SUCCESS)
2962 goto done_free_sp;
2963
Quinn Tran83548fe2017-06-02 09:12:01 -07002964 ql_dbg(ql_dbg_disc, vha, 0x20a4,
2965 "Async-%s - %8phC hdl=%x loopid=%x portid %02x%02x%02x.\n",
2966 sp->name, fcport->port_name,
2967 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
2968 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Quinn Tran726b8542017-01-19 22:28:00 -08002969 return rval;
2970
2971done_free_sp:
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08002972 sp->free(sp);
Quinn Tran726b8542017-01-19 22:28:00 -08002973done:
2974 fcport->flags &= ~FCF_ASYNC_SENT;
2975 return rval;
2976}
2977
2978int qla24xx_post_gidpn_work(struct scsi_qla_host *vha, fc_port_t *fcport)
2979{
2980 struct qla_work_evt *e;
Quinn Tran41dc5292017-01-19 22:28:03 -08002981 int ls;
Quinn Tran726b8542017-01-19 22:28:00 -08002982
Quinn Tran41dc5292017-01-19 22:28:03 -08002983 ls = atomic_read(&vha->loop_state);
2984 if (((ls != LOOP_READY) && (ls != LOOP_UP)) ||
Quinn Tran726b8542017-01-19 22:28:00 -08002985 test_bit(UNLOADING, &vha->dpc_flags))
2986 return 0;
2987
2988 e = qla2x00_alloc_work(vha, QLA_EVT_GIDPN);
2989 if (!e)
2990 return QLA_FUNCTION_FAILED;
2991
2992 e->u.fcport.fcport = fcport;
2993 return qla2x00_post_work(vha, e);
2994}
2995
2996int qla24xx_post_gpsc_work(struct scsi_qla_host *vha, fc_port_t *fcport)
2997{
2998 struct qla_work_evt *e;
2999
3000 e = qla2x00_alloc_work(vha, QLA_EVT_GPSC);
3001 if (!e)
3002 return QLA_FUNCTION_FAILED;
3003
3004 e->u.fcport.fcport = fcport;
3005 return qla2x00_post_work(vha, e);
3006}
3007
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08003008static void qla24xx_async_gpsc_sp_done(void *s, int res)
Quinn Tran726b8542017-01-19 22:28:00 -08003009{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08003010 struct srb *sp = s;
3011 struct scsi_qla_host *vha = sp->vha;
Quinn Tran726b8542017-01-19 22:28:00 -08003012 struct qla_hw_data *ha = vha->hw;
Quinn Tran726b8542017-01-19 22:28:00 -08003013 fc_port_t *fcport = sp->fcport;
3014 struct ct_sns_rsp *ct_rsp;
3015 struct event_arg ea;
3016
3017 ct_rsp = &fcport->ct_desc.ct_sns->p.rsp;
3018
Quinn Tran83548fe2017-06-02 09:12:01 -07003019 ql_dbg(ql_dbg_disc, vha, 0x2053,
Quinn Tran726b8542017-01-19 22:28:00 -08003020 "Async done-%s res %x, WWPN %8phC \n",
3021 sp->name, res, fcport->port_name);
3022
3023 fcport->flags &= ~FCF_ASYNC_SENT;
3024
3025 if (res == (DID_ERROR << 16)) {
3026 /* entry status error */
3027 goto done;
3028 } else if (res) {
3029 if ((ct_rsp->header.reason_code ==
3030 CT_REASON_INVALID_COMMAND_CODE) ||
3031 (ct_rsp->header.reason_code ==
Quinn Tran83548fe2017-06-02 09:12:01 -07003032 CT_REASON_COMMAND_UNSUPPORTED)) {
3033 ql_dbg(ql_dbg_disc, vha, 0x2019,
3034 "GPSC command unsupported, disabling query.\n");
Quinn Tran726b8542017-01-19 22:28:00 -08003035 ha->flags.gpsc_supported = 0;
3036 res = QLA_SUCCESS;
3037 }
3038 } else {
3039 switch (be16_to_cpu(ct_rsp->rsp.gpsc.speed)) {
3040 case BIT_15:
3041 fcport->fp_speed = PORT_SPEED_1GB;
3042 break;
3043 case BIT_14:
3044 fcport->fp_speed = PORT_SPEED_2GB;
3045 break;
3046 case BIT_13:
3047 fcport->fp_speed = PORT_SPEED_4GB;
3048 break;
3049 case BIT_12:
3050 fcport->fp_speed = PORT_SPEED_10GB;
3051 break;
3052 case BIT_11:
3053 fcport->fp_speed = PORT_SPEED_8GB;
3054 break;
3055 case BIT_10:
3056 fcport->fp_speed = PORT_SPEED_16GB;
3057 break;
3058 case BIT_8:
3059 fcport->fp_speed = PORT_SPEED_32GB;
3060 break;
3061 }
3062
Quinn Tran83548fe2017-06-02 09:12:01 -07003063 ql_dbg(ql_dbg_disc, vha, 0x2054,
3064 "Async-%s OUT WWPN %8phC speeds=%04x speed=%04x.\n",
3065 sp->name, fcport->fabric_port_name,
3066 be16_to_cpu(ct_rsp->rsp.gpsc.speeds),
3067 be16_to_cpu(ct_rsp->rsp.gpsc.speed));
Quinn Tran726b8542017-01-19 22:28:00 -08003068 }
3069done:
3070 memset(&ea, 0, sizeof(ea));
3071 ea.event = FCME_GPSC_DONE;
3072 ea.rc = res;
3073 ea.fcport = fcport;
3074 qla2x00_fcport_event_handler(vha, &ea);
3075
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08003076 sp->free(sp);
Quinn Tran726b8542017-01-19 22:28:00 -08003077}
3078
3079int qla24xx_async_gpsc(scsi_qla_host_t *vha, fc_port_t *fcport)
3080{
3081 int rval = QLA_FUNCTION_FAILED;
3082 struct ct_sns_req *ct_req;
3083 srb_t *sp;
3084
3085 if (!vha->flags.online)
3086 goto done;
3087
3088 fcport->flags |= FCF_ASYNC_SENT;
3089 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
3090 if (!sp)
3091 goto done;
3092
3093 sp->type = SRB_CT_PTHRU_CMD;
3094 sp->name = "gpsc";
3095 sp->gen1 = fcport->rscn_gen;
3096 sp->gen2 = fcport->login_gen;
3097
3098 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
3099
3100 /* CT_IU preamble */
3101 ct_req = qla24xx_prep_ct_fm_req(fcport->ct_desc.ct_sns, GPSC_CMD,
3102 GPSC_RSP_SIZE);
3103
3104 /* GPSC req */
Quinn Tranb2e8ae32017-08-23 15:05:06 -07003105 memcpy(ct_req->req.gpsc.port_name, fcport->fabric_port_name,
Quinn Tran726b8542017-01-19 22:28:00 -08003106 WWN_SIZE);
3107
3108 sp->u.iocb_cmd.u.ctarg.req = fcport->ct_desc.ct_sns;
3109 sp->u.iocb_cmd.u.ctarg.req_dma = fcport->ct_desc.ct_sns_dma;
3110 sp->u.iocb_cmd.u.ctarg.rsp = fcport->ct_desc.ct_sns;
3111 sp->u.iocb_cmd.u.ctarg.rsp_dma = fcport->ct_desc.ct_sns_dma;
3112 sp->u.iocb_cmd.u.ctarg.req_size = GPSC_REQ_SIZE;
3113 sp->u.iocb_cmd.u.ctarg.rsp_size = GPSC_RSP_SIZE;
3114 sp->u.iocb_cmd.u.ctarg.nport_handle = vha->mgmt_svr_loop_id;
3115
3116 sp->u.iocb_cmd.timeout = qla2x00_async_iocb_timeout;
3117 sp->done = qla24xx_async_gpsc_sp_done;
3118
3119 rval = qla2x00_start_sp(sp);
3120 if (rval != QLA_SUCCESS)
3121 goto done_free_sp;
3122
Quinn Tran83548fe2017-06-02 09:12:01 -07003123 ql_dbg(ql_dbg_disc, vha, 0x205e,
3124 "Async-%s %8phC hdl=%x loopid=%x portid=%02x%02x%02x.\n",
3125 sp->name, fcport->port_name, sp->handle,
3126 fcport->loop_id, fcport->d_id.b.domain,
3127 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Quinn Tran726b8542017-01-19 22:28:00 -08003128 return rval;
3129
3130done_free_sp:
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08003131 sp->free(sp);
Quinn Tran726b8542017-01-19 22:28:00 -08003132done:
3133 fcport->flags &= ~FCF_ASYNC_SENT;
3134 return rval;
3135}
3136
3137int qla24xx_post_gpnid_work(struct scsi_qla_host *vha, port_id_t *id)
3138{
3139 struct qla_work_evt *e;
3140
3141 if (test_bit(UNLOADING, &vha->dpc_flags))
3142 return 0;
3143
3144 e = qla2x00_alloc_work(vha, QLA_EVT_GPNID);
3145 if (!e)
3146 return QLA_FUNCTION_FAILED;
3147
3148 e->u.gpnid.id = *id;
3149 return qla2x00_post_work(vha, e);
3150}
3151
3152void qla24xx_async_gpnid_done(scsi_qla_host_t *vha, srb_t *sp)
3153{
3154 if (sp->u.iocb_cmd.u.ctarg.req) {
3155 dma_free_coherent(&vha->hw->pdev->dev,
3156 sizeof(struct ct_sns_pkt),
3157 sp->u.iocb_cmd.u.ctarg.req,
3158 sp->u.iocb_cmd.u.ctarg.req_dma);
3159 sp->u.iocb_cmd.u.ctarg.req = NULL;
3160 }
3161 if (sp->u.iocb_cmd.u.ctarg.rsp) {
3162 dma_free_coherent(&vha->hw->pdev->dev,
3163 sizeof(struct ct_sns_pkt),
3164 sp->u.iocb_cmd.u.ctarg.rsp,
3165 sp->u.iocb_cmd.u.ctarg.rsp_dma);
3166 sp->u.iocb_cmd.u.ctarg.rsp = NULL;
3167 }
3168
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08003169 sp->free(sp);
Quinn Tran726b8542017-01-19 22:28:00 -08003170}
3171
3172void qla24xx_handle_gpnid_event(scsi_qla_host_t *vha, struct event_arg *ea)
3173{
3174 fc_port_t *fcport;
3175 unsigned long flags;
3176
3177 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
3178 fcport = qla2x00_find_fcport_by_wwpn(vha, ea->port_name, 1);
3179 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
3180
3181 if (fcport) {
3182 /* cable moved. just plugged in */
Quinn Tran726b8542017-01-19 22:28:00 -08003183 fcport->rscn_gen++;
3184 fcport->d_id = ea->id;
3185 fcport->scan_state = QLA_FCPORT_FOUND;
3186 fcport->flags |= FCF_FABRIC_DEVICE;
3187
Quinn Tran66ee0fe2017-06-02 09:11:56 -07003188 switch (fcport->disc_state) {
3189 case DSC_DELETED:
3190 ql_dbg(ql_dbg_disc, vha, 0x210d,
3191 "%s %d %8phC login\n", __func__, __LINE__,
3192 fcport->port_name);
3193 qla24xx_fcport_handle_login(vha, fcport);
3194 break;
3195 case DSC_DELETE_PEND:
3196 break;
3197 default:
3198 ql_dbg(ql_dbg_disc, vha, 0x2064,
3199 "%s %d %8phC post del sess\n",
3200 __func__, __LINE__, fcport->port_name);
3201 qlt_schedule_sess_for_deletion_lock(fcport);
3202 break;
3203 }
Quinn Tran726b8542017-01-19 22:28:00 -08003204 } else {
3205 /* create new fcport */
Quinn Tran83548fe2017-06-02 09:12:01 -07003206 ql_dbg(ql_dbg_disc, vha, 0x2065,
3207 "%s %d %8phC post new sess\n",
3208 __func__, __LINE__, ea->port_name);
Quinn Tran726b8542017-01-19 22:28:00 -08003209
3210 qla24xx_post_newsess_work(vha, &ea->id, ea->port_name, NULL);
3211 }
3212}
3213
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08003214static void qla2x00_async_gpnid_sp_done(void *s, int res)
Quinn Tran726b8542017-01-19 22:28:00 -08003215{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08003216 struct srb *sp = s;
3217 struct scsi_qla_host *vha = sp->vha;
Quinn Tran726b8542017-01-19 22:28:00 -08003218 struct ct_sns_req *ct_req =
3219 (struct ct_sns_req *)sp->u.iocb_cmd.u.ctarg.req;
3220 struct ct_sns_rsp *ct_rsp =
3221 (struct ct_sns_rsp *)sp->u.iocb_cmd.u.ctarg.rsp;
3222 struct event_arg ea;
3223 struct qla_work_evt *e;
Quinn Tran2d73ac62017-12-04 14:45:02 -08003224 unsigned long flags;
Quinn Tran726b8542017-01-19 22:28:00 -08003225
Quinn Trana084fd62017-12-04 14:45:00 -08003226 if (res)
3227 ql_dbg(ql_dbg_disc, vha, 0x2066,
Quinn Tran2d73ac62017-12-04 14:45:02 -08003228 "Async done-%s fail res %x rscn gen %d ID %3phC. %8phC\n",
3229 sp->name, res, sp->gen1, ct_req->req.port_id.port_id,
Quinn Trana084fd62017-12-04 14:45:00 -08003230 ct_rsp->rsp.gpn_id.port_name);
3231 else
3232 ql_dbg(ql_dbg_disc, vha, 0x2066,
Quinn Tran2d73ac62017-12-04 14:45:02 -08003233 "Async done-%s good rscn gen %d ID %3phC. %8phC\n",
3234 sp->name, sp->gen1, ct_req->req.port_id.port_id,
Quinn Trana084fd62017-12-04 14:45:00 -08003235 ct_rsp->rsp.gpn_id.port_name);
Quinn Tran726b8542017-01-19 22:28:00 -08003236
3237 memset(&ea, 0, sizeof(ea));
3238 memcpy(ea.port_name, ct_rsp->rsp.gpn_id.port_name, WWN_SIZE);
3239 ea.sp = sp;
3240 ea.id.b.domain = ct_req->req.port_id.port_id[0];
3241 ea.id.b.area = ct_req->req.port_id.port_id[1];
3242 ea.id.b.al_pa = ct_req->req.port_id.port_id[2];
3243 ea.rc = res;
3244 ea.event = FCME_GPNID_DONE;
3245
Quinn Tran2d73ac62017-12-04 14:45:02 -08003246 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
3247 list_del(&sp->elem);
3248 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
3249
Quinn Tran25ad76b2017-12-04 14:45:01 -08003250 if (res) {
3251 if (res == QLA_FUNCTION_TIMEOUT)
3252 qla24xx_post_gpnid_work(sp->vha, &ea.id);
3253 sp->free(sp);
3254 return;
Quinn Tran2d73ac62017-12-04 14:45:02 -08003255 } else if (sp->gen1) {
3256 /* There was anoter RSNC for this Nport ID */
3257 qla24xx_post_gpnid_work(sp->vha, &ea.id);
3258 sp->free(sp);
3259 return;
Quinn Tran25ad76b2017-12-04 14:45:01 -08003260 }
3261
Quinn Tran726b8542017-01-19 22:28:00 -08003262 qla2x00_fcport_event_handler(vha, &ea);
3263
3264 e = qla2x00_alloc_work(vha, QLA_EVT_GPNID_DONE);
3265 if (!e) {
3266 /* please ignore kernel warning. otherwise, we have mem leak. */
3267 if (sp->u.iocb_cmd.u.ctarg.req) {
3268 dma_free_coherent(&vha->hw->pdev->dev,
3269 sizeof(struct ct_sns_pkt),
3270 sp->u.iocb_cmd.u.ctarg.req,
3271 sp->u.iocb_cmd.u.ctarg.req_dma);
3272 sp->u.iocb_cmd.u.ctarg.req = NULL;
3273 }
3274 if (sp->u.iocb_cmd.u.ctarg.rsp) {
3275 dma_free_coherent(&vha->hw->pdev->dev,
3276 sizeof(struct ct_sns_pkt),
3277 sp->u.iocb_cmd.u.ctarg.rsp,
3278 sp->u.iocb_cmd.u.ctarg.rsp_dma);
3279 sp->u.iocb_cmd.u.ctarg.rsp = NULL;
3280 }
3281
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08003282 sp->free(sp);
Quinn Tran726b8542017-01-19 22:28:00 -08003283 return;
3284 }
3285
3286 e->u.iosb.sp = sp;
3287 qla2x00_post_work(vha, e);
3288}
3289
3290/* Get WWPN with Nport ID. */
3291int qla24xx_async_gpnid(scsi_qla_host_t *vha, port_id_t *id)
3292{
3293 int rval = QLA_FUNCTION_FAILED;
3294 struct ct_sns_req *ct_req;
Quinn Tran2d73ac62017-12-04 14:45:02 -08003295 srb_t *sp, *tsp;
Quinn Tran726b8542017-01-19 22:28:00 -08003296 struct ct_sns_pkt *ct_sns;
Quinn Tran2d73ac62017-12-04 14:45:02 -08003297 unsigned long flags;
Quinn Tran726b8542017-01-19 22:28:00 -08003298
3299 if (!vha->flags.online)
3300 goto done;
3301
3302 sp = qla2x00_get_sp(vha, NULL, GFP_KERNEL);
3303 if (!sp)
3304 goto done;
3305
3306 sp->type = SRB_CT_PTHRU_CMD;
3307 sp->name = "gpnid";
Quinn Tran2d73ac62017-12-04 14:45:02 -08003308 sp->u.iocb_cmd.u.ctarg.id = *id;
3309 sp->gen1 = 0;
Quinn Tran726b8542017-01-19 22:28:00 -08003310 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
3311
Quinn Tran2d73ac62017-12-04 14:45:02 -08003312 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
3313 list_for_each_entry(tsp, &vha->gpnid_list, elem) {
3314 if (tsp->u.iocb_cmd.u.ctarg.id.b24 == id->b24) {
3315 tsp->gen1++;
3316 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
3317 sp->free(sp);
3318 goto done;
3319 }
3320 }
3321 list_add_tail(&sp->elem, &vha->gpnid_list);
3322 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
3323
Quinn Tran726b8542017-01-19 22:28:00 -08003324 sp->u.iocb_cmd.u.ctarg.req = dma_alloc_coherent(&vha->hw->pdev->dev,
3325 sizeof(struct ct_sns_pkt), &sp->u.iocb_cmd.u.ctarg.req_dma,
3326 GFP_KERNEL);
3327 if (!sp->u.iocb_cmd.u.ctarg.req) {
Quinn Tran83548fe2017-06-02 09:12:01 -07003328 ql_log(ql_log_warn, vha, 0xd041,
3329 "Failed to allocate ct_sns request.\n");
Quinn Tran726b8542017-01-19 22:28:00 -08003330 goto done_free_sp;
3331 }
3332
3333 sp->u.iocb_cmd.u.ctarg.rsp = dma_alloc_coherent(&vha->hw->pdev->dev,
3334 sizeof(struct ct_sns_pkt), &sp->u.iocb_cmd.u.ctarg.rsp_dma,
3335 GFP_KERNEL);
3336 if (!sp->u.iocb_cmd.u.ctarg.rsp) {
Quinn Tran83548fe2017-06-02 09:12:01 -07003337 ql_log(ql_log_warn, vha, 0xd042,
3338 "Failed to allocate ct_sns request.\n");
Quinn Tran726b8542017-01-19 22:28:00 -08003339 goto done_free_sp;
3340 }
3341
3342 ct_sns = (struct ct_sns_pkt *)sp->u.iocb_cmd.u.ctarg.rsp;
3343 memset(ct_sns, 0, sizeof(*ct_sns));
3344
3345 ct_sns = (struct ct_sns_pkt *)sp->u.iocb_cmd.u.ctarg.req;
3346 /* CT_IU preamble */
3347 ct_req = qla2x00_prep_ct_req(ct_sns, GPN_ID_CMD, GPN_ID_RSP_SIZE);
3348
3349 /* GPN_ID req */
3350 ct_req->req.port_id.port_id[0] = id->b.domain;
3351 ct_req->req.port_id.port_id[1] = id->b.area;
3352 ct_req->req.port_id.port_id[2] = id->b.al_pa;
3353
3354 sp->u.iocb_cmd.u.ctarg.req_size = GPN_ID_REQ_SIZE;
3355 sp->u.iocb_cmd.u.ctarg.rsp_size = GPN_ID_RSP_SIZE;
3356 sp->u.iocb_cmd.u.ctarg.nport_handle = NPH_SNS;
3357
3358 sp->u.iocb_cmd.timeout = qla2x00_async_iocb_timeout;
3359 sp->done = qla2x00_async_gpnid_sp_done;
3360
3361 rval = qla2x00_start_sp(sp);
3362 if (rval != QLA_SUCCESS)
3363 goto done_free_sp;
3364
Quinn Tran83548fe2017-06-02 09:12:01 -07003365 ql_dbg(ql_dbg_disc, vha, 0x2067,
3366 "Async-%s hdl=%x ID %3phC.\n", sp->name,
3367 sp->handle, ct_req->req.port_id.port_id);
Quinn Tran726b8542017-01-19 22:28:00 -08003368 return rval;
3369
3370done_free_sp:
3371 if (sp->u.iocb_cmd.u.ctarg.req) {
3372 dma_free_coherent(&vha->hw->pdev->dev,
3373 sizeof(struct ct_sns_pkt),
3374 sp->u.iocb_cmd.u.ctarg.req,
3375 sp->u.iocb_cmd.u.ctarg.req_dma);
3376 sp->u.iocb_cmd.u.ctarg.req = NULL;
3377 }
3378 if (sp->u.iocb_cmd.u.ctarg.rsp) {
3379 dma_free_coherent(&vha->hw->pdev->dev,
3380 sizeof(struct ct_sns_pkt),
3381 sp->u.iocb_cmd.u.ctarg.rsp,
3382 sp->u.iocb_cmd.u.ctarg.rsp_dma);
3383 sp->u.iocb_cmd.u.ctarg.rsp = NULL;
3384 }
3385
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08003386 sp->free(sp);
Quinn Tran726b8542017-01-19 22:28:00 -08003387done:
3388 return rval;
3389}
Duane Grigsbyd3bae932017-06-21 13:48:44 -07003390
3391void qla24xx_handle_gffid_event(scsi_qla_host_t *vha, struct event_arg *ea)
3392{
3393 fc_port_t *fcport = ea->fcport;
3394
3395 qla24xx_post_gnl_work(vha, fcport);
3396}
3397
3398void qla24xx_async_gffid_sp_done(void *s, int res)
3399{
3400 struct srb *sp = s;
3401 struct scsi_qla_host *vha = sp->vha;
3402 fc_port_t *fcport = sp->fcport;
3403 struct ct_sns_rsp *ct_rsp;
3404 struct event_arg ea;
3405
3406 ql_dbg(ql_dbg_disc, vha, 0x2133,
3407 "Async done-%s res %x ID %x. %8phC\n",
3408 sp->name, res, fcport->d_id.b24, fcport->port_name);
3409
3410 fcport->flags &= ~FCF_ASYNC_SENT;
3411 ct_rsp = &fcport->ct_desc.ct_sns->p.rsp;
3412 /*
3413 * FC-GS-7, 5.2.3.12 FC-4 Features - format
3414 * The format of the FC-4 Features object, as defined by the FC-4,
3415 * Shall be an array of 4-bit values, one for each type code value
3416 */
3417 if (!res) {
3418 if (ct_rsp->rsp.gff_id.fc4_features[GFF_FCP_SCSI_OFFSET] & 0xf) {
3419 /* w1 b00:03 */
3420 fcport->fc4_type =
3421 ct_rsp->rsp.gff_id.fc4_features[GFF_FCP_SCSI_OFFSET];
3422 fcport->fc4_type &= 0xf;
3423 }
3424
3425 if (ct_rsp->rsp.gff_id.fc4_features[GFF_NVME_OFFSET] & 0xf) {
3426 /* w5 [00:03]/28h */
3427 fcport->fc4f_nvme =
3428 ct_rsp->rsp.gff_id.fc4_features[GFF_NVME_OFFSET];
3429 fcport->fc4f_nvme &= 0xf;
3430 }
3431 }
3432
3433 memset(&ea, 0, sizeof(ea));
3434 ea.sp = sp;
3435 ea.fcport = sp->fcport;
3436 ea.rc = res;
3437 ea.event = FCME_GFFID_DONE;
3438
3439 qla2x00_fcport_event_handler(vha, &ea);
3440 sp->free(sp);
3441}
3442
3443/* Get FC4 Feature with Nport ID. */
3444int qla24xx_async_gffid(scsi_qla_host_t *vha, fc_port_t *fcport)
3445{
3446 int rval = QLA_FUNCTION_FAILED;
3447 struct ct_sns_req *ct_req;
3448 srb_t *sp;
3449
3450 if (!vha->flags.online)
3451 return rval;
3452
3453 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
3454 if (!sp)
3455 return rval;
3456
3457 fcport->flags |= FCF_ASYNC_SENT;
3458 sp->type = SRB_CT_PTHRU_CMD;
3459 sp->name = "gffid";
3460 sp->gen1 = fcport->rscn_gen;
3461 sp->gen2 = fcport->login_gen;
3462
3463 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
3464
3465 /* CT_IU preamble */
3466 ct_req = qla2x00_prep_ct_req(fcport->ct_desc.ct_sns, GFF_ID_CMD,
3467 GFF_ID_RSP_SIZE);
3468
3469 ct_req->req.gff_id.port_id[0] = fcport->d_id.b.domain;
3470 ct_req->req.gff_id.port_id[1] = fcport->d_id.b.area;
3471 ct_req->req.gff_id.port_id[2] = fcport->d_id.b.al_pa;
3472
3473 sp->u.iocb_cmd.u.ctarg.req = fcport->ct_desc.ct_sns;
3474 sp->u.iocb_cmd.u.ctarg.req_dma = fcport->ct_desc.ct_sns_dma;
3475 sp->u.iocb_cmd.u.ctarg.rsp = fcport->ct_desc.ct_sns;
3476 sp->u.iocb_cmd.u.ctarg.rsp_dma = fcport->ct_desc.ct_sns_dma;
3477 sp->u.iocb_cmd.u.ctarg.req_size = GFF_ID_REQ_SIZE;
3478 sp->u.iocb_cmd.u.ctarg.rsp_size = GFF_ID_RSP_SIZE;
3479 sp->u.iocb_cmd.u.ctarg.nport_handle = NPH_SNS;
3480
3481 sp->u.iocb_cmd.timeout = qla2x00_async_iocb_timeout;
3482 sp->done = qla24xx_async_gffid_sp_done;
3483
3484 rval = qla2x00_start_sp(sp);
3485 if (rval != QLA_SUCCESS)
3486 goto done_free_sp;
3487
3488 ql_dbg(ql_dbg_disc, vha, 0x2132,
3489 "Async-%s hdl=%x %8phC.\n", sp->name,
3490 sp->handle, fcport->port_name);
3491
3492 return rval;
3493done_free_sp:
3494 sp->free(sp);
3495 fcport->flags &= ~FCF_ASYNC_SENT;
3496 return rval;
3497}