blob: 963ebcb7cf2ca07f40d8f5cc830b4a2ec018f501 [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 *);
Quinn Trane374f9f2017-12-28 12:33:31 -080017static int qla_async_rftid(scsi_qla_host_t *, port_id_t *);
18static int qla_async_rffid(scsi_qla_host_t *, port_id_t *, u8, u8);
19static int qla_async_rnnid(scsi_qla_host_t *, port_id_t *, u8*);
20static int qla_async_rsnn_nn(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
22/**
Andrew Vasquez8c958a92005-07-06 10:30:47 -070023 * qla2x00_prep_ms_iocb() - Prepare common MS/CT IOCB fields for SNS CT query.
Linus Torvalds1da177e2005-04-16 15:20:36 -070024 * @ha: HA context
25 * @req_size: request size in bytes
26 * @rsp_size: response size in bytes
27 *
28 * Returns a pointer to the @ha's ms_iocb.
29 */
Andrew Vasquez8c958a92005-07-06 10:30:47 -070030void *
Quinn Tran726b8542017-01-19 22:28:00 -080031qla2x00_prep_ms_iocb(scsi_qla_host_t *vha, struct ct_arg *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -070032{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080033 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -070034 ms_iocb_entry_t *ms_pkt;
35
Quinn Tran726b8542017-01-19 22:28:00 -080036 ms_pkt = (ms_iocb_entry_t *)arg->iocb;
Linus Torvalds1da177e2005-04-16 15:20:36 -070037 memset(ms_pkt, 0, sizeof(ms_iocb_entry_t));
38
39 ms_pkt->entry_type = MS_IOCB_TYPE;
40 ms_pkt->entry_count = 1;
41 SET_TARGET_ID(ha, ms_pkt->loop_id, SIMPLE_NAME_SERVER);
Bart Van Asschead950362015-07-09 07:24:08 -070042 ms_pkt->control_flags = cpu_to_le16(CF_READ | CF_HEAD_TAG);
Andrew Vasquez00a537b2008-02-28 14:06:11 -080043 ms_pkt->timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
Bart Van Asschead950362015-07-09 07:24:08 -070044 ms_pkt->cmd_dsd_count = cpu_to_le16(1);
45 ms_pkt->total_dsd_count = cpu_to_le16(2);
Quinn Tran726b8542017-01-19 22:28:00 -080046 ms_pkt->rsp_bytecount = cpu_to_le32(arg->rsp_size);
47 ms_pkt->req_bytecount = cpu_to_le32(arg->req_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
Quinn Tran726b8542017-01-19 22:28:00 -080049 ms_pkt->dseg_req_address[0] = cpu_to_le32(LSD(arg->req_dma));
50 ms_pkt->dseg_req_address[1] = cpu_to_le32(MSD(arg->req_dma));
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 ms_pkt->dseg_req_length = ms_pkt->req_bytecount;
52
Quinn Tran726b8542017-01-19 22:28:00 -080053 ms_pkt->dseg_rsp_address[0] = cpu_to_le32(LSD(arg->rsp_dma));
54 ms_pkt->dseg_rsp_address[1] = cpu_to_le32(MSD(arg->rsp_dma));
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 ms_pkt->dseg_rsp_length = ms_pkt->rsp_bytecount;
56
Joe Carnucciofabbb8d2013-08-27 01:37:40 -040057 vha->qla_stats.control_requests++;
58
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 return (ms_pkt);
60}
61
62/**
Andrew Vasquez8c958a92005-07-06 10:30:47 -070063 * qla24xx_prep_ms_iocb() - Prepare common CT IOCB fields for SNS CT query.
64 * @ha: HA context
65 * @req_size: request size in bytes
66 * @rsp_size: response size in bytes
67 *
68 * Returns a pointer to the @ha's ms_iocb.
69 */
70void *
Quinn Tran726b8542017-01-19 22:28:00 -080071qla24xx_prep_ms_iocb(scsi_qla_host_t *vha, struct ct_arg *arg)
Andrew Vasquez8c958a92005-07-06 10:30:47 -070072{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080073 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez8c958a92005-07-06 10:30:47 -070074 struct ct_entry_24xx *ct_pkt;
75
Quinn Tran726b8542017-01-19 22:28:00 -080076 ct_pkt = (struct ct_entry_24xx *)arg->iocb;
Andrew Vasquez8c958a92005-07-06 10:30:47 -070077 memset(ct_pkt, 0, sizeof(struct ct_entry_24xx));
78
79 ct_pkt->entry_type = CT_IOCB_TYPE;
80 ct_pkt->entry_count = 1;
Quinn Tran726b8542017-01-19 22:28:00 -080081 ct_pkt->nport_handle = cpu_to_le16(arg->nport_handle);
Andrew Vasquez00a537b2008-02-28 14:06:11 -080082 ct_pkt->timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
Bart Van Asschead950362015-07-09 07:24:08 -070083 ct_pkt->cmd_dsd_count = cpu_to_le16(1);
84 ct_pkt->rsp_dsd_count = cpu_to_le16(1);
Quinn Tran726b8542017-01-19 22:28:00 -080085 ct_pkt->rsp_byte_count = cpu_to_le32(arg->rsp_size);
86 ct_pkt->cmd_byte_count = cpu_to_le32(arg->req_size);
Andrew Vasquez8c958a92005-07-06 10:30:47 -070087
Quinn Tran726b8542017-01-19 22:28:00 -080088 ct_pkt->dseg_0_address[0] = cpu_to_le32(LSD(arg->req_dma));
89 ct_pkt->dseg_0_address[1] = cpu_to_le32(MSD(arg->req_dma));
Andrew Vasquez8c958a92005-07-06 10:30:47 -070090 ct_pkt->dseg_0_len = ct_pkt->cmd_byte_count;
91
Quinn Tran726b8542017-01-19 22:28:00 -080092 ct_pkt->dseg_1_address[0] = cpu_to_le32(LSD(arg->rsp_dma));
93 ct_pkt->dseg_1_address[1] = cpu_to_le32(MSD(arg->rsp_dma));
Andrew Vasquez8c958a92005-07-06 10:30:47 -070094 ct_pkt->dseg_1_len = ct_pkt->rsp_byte_count;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080095 ct_pkt->vp_index = vha->vp_idx;
Andrew Vasquez8c958a92005-07-06 10:30:47 -070096
Joe Carnucciofabbb8d2013-08-27 01:37:40 -040097 vha->qla_stats.control_requests++;
98
Andrew Vasquez8c958a92005-07-06 10:30:47 -070099 return (ct_pkt);
100}
101
102/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 * qla2x00_prep_ct_req() - Prepare common CT request fields for SNS query.
104 * @ct_req: CT request buffer
105 * @cmd: GS command
106 * @rsp_size: response size in bytes
107 *
108 * Returns a pointer to the intitialized @ct_req.
109 */
110static inline struct ct_sns_req *
Bart Van Assche6ec6f902013-06-25 11:27:28 -0400111qla2x00_prep_ct_req(struct ct_sns_pkt *p, uint16_t cmd, uint16_t rsp_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112{
Bart Van Assche6ec6f902013-06-25 11:27:28 -0400113 memset(p, 0, sizeof(struct ct_sns_pkt));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114
Bart Van Assche6ec6f902013-06-25 11:27:28 -0400115 p->p.req.header.revision = 0x01;
116 p->p.req.header.gs_type = 0xFC;
117 p->p.req.header.gs_subtype = 0x02;
118 p->p.req.command = cpu_to_be16(cmd);
119 p->p.req.max_rsp_size = cpu_to_be16((rsp_size - 16) / 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120
Bart Van Assche6ec6f902013-06-25 11:27:28 -0400121 return &p->p.req;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122}
123
Quinn Tran726b8542017-01-19 22:28:00 -0800124int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800125qla2x00_chk_ms_status(scsi_qla_host_t *vha, ms_iocb_entry_t *ms_pkt,
Andrew Vasquez8c958a92005-07-06 10:30:47 -0700126 struct ct_sns_rsp *ct_rsp, const char *routine)
127{
128 int rval;
129 uint16_t comp_status;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800130 struct qla_hw_data *ha = vha->hw;
Quinn Tranb98ae0d2017-06-02 09:12:00 -0700131 bool lid_is_sns = false;
Andrew Vasquez8c958a92005-07-06 10:30:47 -0700132
133 rval = QLA_FUNCTION_FAILED;
134 if (ms_pkt->entry_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700135 ql_dbg(ql_dbg_disc, vha, 0x2031,
136 "%s failed, error status (%x) on port_id: %02x%02x%02x.\n",
137 routine, ms_pkt->entry_status, vha->d_id.b.domain,
138 vha->d_id.b.area, vha->d_id.b.al_pa);
Andrew Vasquez8c958a92005-07-06 10:30:47 -0700139 } else {
Andrew Vasqueze4289242007-07-19 15:05:56 -0700140 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquezcdfc82a2006-12-13 19:20:26 -0800141 comp_status = le16_to_cpu(
142 ((struct ct_entry_24xx *)ms_pkt)->comp_status);
Andrew Vasquez8c958a92005-07-06 10:30:47 -0700143 else
144 comp_status = le16_to_cpu(ms_pkt->status);
145 switch (comp_status) {
146 case CS_COMPLETE:
147 case CS_DATA_UNDERRUN:
148 case CS_DATA_OVERRUN: /* Overrun? */
149 if (ct_rsp->header.response !=
Bart Van Asschead950362015-07-09 07:24:08 -0700150 cpu_to_be16(CT_ACCEPT_RESPONSE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700151 ql_dbg(ql_dbg_disc + ql_dbg_buffer, vha, 0x2077,
Milan P Gandhi5a68a1c2017-03-31 14:37:04 -0700152 "%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 -0400153 routine, vha->d_id.b.domain,
154 vha->d_id.b.area, vha->d_id.b.al_pa,
155 comp_status, ct_rsp->header.response);
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700156 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha,
157 0x2078, (uint8_t *)&ct_rsp->header,
158 sizeof(struct ct_rsp_hdr));
Andrew Vasquez4346b142006-12-13 19:20:28 -0800159 rval = QLA_INVALID_COMMAND;
Andrew Vasquez8c958a92005-07-06 10:30:47 -0700160 } else
161 rval = QLA_SUCCESS;
162 break;
Quinn Tranb98ae0d2017-06-02 09:12:00 -0700163 case CS_PORT_LOGGED_OUT:
164 if (IS_FWI2_CAPABLE(ha)) {
165 if (le16_to_cpu(ms_pkt->loop_id.extended) ==
166 NPH_SNS)
167 lid_is_sns = true;
168 } else {
169 if (le16_to_cpu(ms_pkt->loop_id.extended) ==
170 SIMPLE_NAME_SERVER)
171 lid_is_sns = true;
172 }
173 if (lid_is_sns) {
174 ql_dbg(ql_dbg_async, vha, 0x502b,
175 "%s failed, Name server has logged out",
176 routine);
177 rval = QLA_NOT_LOGGED_IN;
178 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
179 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
180 }
181 break;
Quinn Tran25ad76b2017-12-04 14:45:01 -0800182 case CS_TIMEOUT:
183 rval = QLA_FUNCTION_TIMEOUT;
Bart Van Assche81881862017-12-07 16:02:46 -0800184 /* fall through */
Andrew Vasquez8c958a92005-07-06 10:30:47 -0700185 default:
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700186 ql_dbg(ql_dbg_disc, vha, 0x2033,
187 "%s failed, completion status (%x) on port_id: "
188 "%02x%02x%02x.\n", routine, comp_status,
Giridhar Malavalicf2d7712011-02-23 15:27:09 -0800189 vha->d_id.b.domain, vha->d_id.b.area,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700190 vha->d_id.b.al_pa);
Andrew Vasquez8c958a92005-07-06 10:30:47 -0700191 break;
192 }
193 }
194 return rval;
195}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196
197/**
198 * qla2x00_ga_nxt() - SNS scan for fabric devices via GA_NXT command.
199 * @ha: HA context
200 * @fcport: fcport entry to updated
201 *
202 * Returns 0 on success.
203 */
204int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800205qla2x00_ga_nxt(scsi_qla_host_t *vha, fc_port_t *fcport)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206{
207 int rval;
208
209 ms_iocb_entry_t *ms_pkt;
210 struct ct_sns_req *ct_req;
211 struct ct_sns_rsp *ct_rsp;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800212 struct qla_hw_data *ha = vha->hw;
Quinn Tran726b8542017-01-19 22:28:00 -0800213 struct ct_arg arg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800215 if (IS_QLA2100(ha) || IS_QLA2200(ha))
216 return qla2x00_sns_ga_nxt(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217
Quinn Tran726b8542017-01-19 22:28:00 -0800218 arg.iocb = ha->ms_iocb;
219 arg.req_dma = ha->ct_sns_dma;
220 arg.rsp_dma = ha->ct_sns_dma;
221 arg.req_size = GA_NXT_REQ_SIZE;
222 arg.rsp_size = GA_NXT_RSP_SIZE;
223 arg.nport_handle = NPH_SNS;
224
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 /* Issue GA_NXT */
226 /* Prepare common MS IOCB */
Quinn Tran726b8542017-01-19 22:28:00 -0800227 ms_pkt = ha->isp_ops->prep_ms_iocb(vha, &arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228
229 /* Prepare CT request */
Bart Van Assche6ec6f902013-06-25 11:27:28 -0400230 ct_req = qla2x00_prep_ct_req(ha->ct_sns, GA_NXT_CMD,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 GA_NXT_RSP_SIZE);
232 ct_rsp = &ha->ct_sns->p.rsp;
233
234 /* Prepare CT arguments -- port_id */
235 ct_req->req.port_id.port_id[0] = fcport->d_id.b.domain;
236 ct_req->req.port_id.port_id[1] = fcport->d_id.b.area;
237 ct_req->req.port_id.port_id[2] = fcport->d_id.b.al_pa;
238
239 /* Execute MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800240 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 sizeof(ms_iocb_entry_t));
242 if (rval != QLA_SUCCESS) {
243 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700244 ql_dbg(ql_dbg_disc, vha, 0x2062,
245 "GA_NXT issue IOCB failed (%d).\n", rval);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800246 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, "GA_NXT") !=
Andrew Vasquez8c958a92005-07-06 10:30:47 -0700247 QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 rval = QLA_FUNCTION_FAILED;
249 } else {
250 /* Populate fc_port_t entry. */
251 fcport->d_id.b.domain = ct_rsp->rsp.ga_nxt.port_id[0];
252 fcport->d_id.b.area = ct_rsp->rsp.ga_nxt.port_id[1];
253 fcport->d_id.b.al_pa = ct_rsp->rsp.ga_nxt.port_id[2];
254
255 memcpy(fcport->node_name, ct_rsp->rsp.ga_nxt.node_name,
256 WWN_SIZE);
257 memcpy(fcport->port_name, ct_rsp->rsp.ga_nxt.port_name,
258 WWN_SIZE);
259
Armen Baloyana72b9902012-11-21 02:40:30 -0500260 fcport->fc4_type = (ct_rsp->rsp.ga_nxt.fc4_types[2] & BIT_0) ?
261 FC4_TYPE_FCP_SCSI : FC4_TYPE_OTHER;
262
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 if (ct_rsp->rsp.ga_nxt.port_type != NS_N_PORT_TYPE &&
264 ct_rsp->rsp.ga_nxt.port_type != NS_NL_PORT_TYPE)
265 fcport->d_id.b.domain = 0xf0;
266
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700267 ql_dbg(ql_dbg_disc, vha, 0x2063,
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -0400268 "GA_NXT entry - nn %8phN pn %8phN "
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700269 "port_id=%02x%02x%02x.\n",
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -0400270 fcport->node_name, fcport->port_name,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 fcport->d_id.b.domain, fcport->d_id.b.area,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700272 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 }
274
275 return (rval);
276}
277
Chad Dupuis642ef982012-02-09 11:15:57 -0800278static inline int
279qla2x00_gid_pt_rsp_size(scsi_qla_host_t *vha)
280{
281 return vha->hw->max_fibre_devices * 4 + 16;
282}
283
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284/**
285 * qla2x00_gid_pt() - SNS scan for fabric devices via GID_PT command.
286 * @ha: HA context
287 * @list: switch info entries to populate
288 *
289 * NOTE: Non-Nx_Ports are not requested.
290 *
291 * Returns 0 on success.
292 */
293int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800294qla2x00_gid_pt(scsi_qla_host_t *vha, sw_info_t *list)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295{
296 int rval;
297 uint16_t i;
298
299 ms_iocb_entry_t *ms_pkt;
300 struct ct_sns_req *ct_req;
301 struct ct_sns_rsp *ct_rsp;
302
303 struct ct_sns_gid_pt_data *gid_data;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800304 struct qla_hw_data *ha = vha->hw;
Chad Dupuis642ef982012-02-09 11:15:57 -0800305 uint16_t gid_pt_rsp_size;
Quinn Tran726b8542017-01-19 22:28:00 -0800306 struct ct_arg arg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800308 if (IS_QLA2100(ha) || IS_QLA2200(ha))
309 return qla2x00_sns_gid_pt(vha, list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310
311 gid_data = NULL;
Chad Dupuis642ef982012-02-09 11:15:57 -0800312 gid_pt_rsp_size = qla2x00_gid_pt_rsp_size(vha);
Quinn Tran726b8542017-01-19 22:28:00 -0800313
314 arg.iocb = ha->ms_iocb;
315 arg.req_dma = ha->ct_sns_dma;
316 arg.rsp_dma = ha->ct_sns_dma;
317 arg.req_size = GID_PT_REQ_SIZE;
318 arg.rsp_size = gid_pt_rsp_size;
319 arg.nport_handle = NPH_SNS;
320
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321 /* Issue GID_PT */
322 /* Prepare common MS IOCB */
Quinn Tran726b8542017-01-19 22:28:00 -0800323 ms_pkt = ha->isp_ops->prep_ms_iocb(vha, &arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324
325 /* Prepare CT request */
Bart Van Assche6ec6f902013-06-25 11:27:28 -0400326 ct_req = qla2x00_prep_ct_req(ha->ct_sns, GID_PT_CMD, gid_pt_rsp_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 ct_rsp = &ha->ct_sns->p.rsp;
328
329 /* Prepare CT arguments -- port_type */
330 ct_req->req.gid_pt.port_type = NS_NX_PORT_TYPE;
331
332 /* Execute MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800333 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 sizeof(ms_iocb_entry_t));
335 if (rval != QLA_SUCCESS) {
336 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700337 ql_dbg(ql_dbg_disc, vha, 0x2055,
338 "GID_PT issue IOCB failed (%d).\n", rval);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800339 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, "GID_PT") !=
Andrew Vasquez8c958a92005-07-06 10:30:47 -0700340 QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 rval = QLA_FUNCTION_FAILED;
342 } else {
343 /* Set port IDs in switch info list. */
Chad Dupuis642ef982012-02-09 11:15:57 -0800344 for (i = 0; i < ha->max_fibre_devices; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 gid_data = &ct_rsp->rsp.gid_pt.entries[i];
346 list[i].d_id.b.domain = gid_data->port_id[0];
347 list[i].d_id.b.area = gid_data->port_id[1];
348 list[i].d_id.b.al_pa = gid_data->port_id[2];
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -0700349 memset(list[i].fabric_port_name, 0, WWN_SIZE);
350 list[i].fp_speed = PORT_SPEED_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351
352 /* Last one exit. */
353 if (gid_data->control_byte & BIT_7) {
354 list[i].d_id.b.rsvd_1 = gid_data->control_byte;
355 break;
356 }
357 }
358
359 /*
360 * If we've used all available slots, then the switch is
361 * reporting back more devices than we can handle with this
362 * single call. Return a failed status, and let GA_NXT handle
363 * the overload.
364 */
Chad Dupuis642ef982012-02-09 11:15:57 -0800365 if (i == ha->max_fibre_devices)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 rval = QLA_FUNCTION_FAILED;
367 }
368
369 return (rval);
370}
371
372/**
373 * qla2x00_gpn_id() - SNS Get Port Name (GPN_ID) query.
374 * @ha: HA context
375 * @list: switch info entries to populate
376 *
377 * Returns 0 on success.
378 */
379int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800380qla2x00_gpn_id(scsi_qla_host_t *vha, sw_info_t *list)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381{
Chad Dupuis642ef982012-02-09 11:15:57 -0800382 int rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 uint16_t i;
384
385 ms_iocb_entry_t *ms_pkt;
386 struct ct_sns_req *ct_req;
387 struct ct_sns_rsp *ct_rsp;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800388 struct qla_hw_data *ha = vha->hw;
Quinn Tran726b8542017-01-19 22:28:00 -0800389 struct ct_arg arg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800391 if (IS_QLA2100(ha) || IS_QLA2200(ha))
392 return qla2x00_sns_gpn_id(vha, list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393
Quinn Tran726b8542017-01-19 22:28:00 -0800394 arg.iocb = ha->ms_iocb;
395 arg.req_dma = ha->ct_sns_dma;
396 arg.rsp_dma = ha->ct_sns_dma;
397 arg.req_size = GPN_ID_REQ_SIZE;
398 arg.rsp_size = GPN_ID_RSP_SIZE;
399 arg.nport_handle = NPH_SNS;
400
Chad Dupuis642ef982012-02-09 11:15:57 -0800401 for (i = 0; i < ha->max_fibre_devices; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 /* Issue GPN_ID */
403 /* Prepare common MS IOCB */
Quinn Tran726b8542017-01-19 22:28:00 -0800404 ms_pkt = ha->isp_ops->prep_ms_iocb(vha, &arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405
406 /* Prepare CT request */
Bart Van Assche6ec6f902013-06-25 11:27:28 -0400407 ct_req = qla2x00_prep_ct_req(ha->ct_sns, GPN_ID_CMD,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 GPN_ID_RSP_SIZE);
409 ct_rsp = &ha->ct_sns->p.rsp;
410
411 /* Prepare CT arguments -- port_id */
412 ct_req->req.port_id.port_id[0] = list[i].d_id.b.domain;
413 ct_req->req.port_id.port_id[1] = list[i].d_id.b.area;
414 ct_req->req.port_id.port_id[2] = list[i].d_id.b.al_pa;
415
416 /* Execute MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800417 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 sizeof(ms_iocb_entry_t));
419 if (rval != QLA_SUCCESS) {
420 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700421 ql_dbg(ql_dbg_disc, vha, 0x2056,
422 "GPN_ID issue IOCB failed (%d).\n", rval);
Arun Easidafdf892012-02-09 11:16:00 -0800423 break;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800424 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp,
Andrew Vasquez8c958a92005-07-06 10:30:47 -0700425 "GPN_ID") != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 rval = QLA_FUNCTION_FAILED;
Arun Easidafdf892012-02-09 11:16:00 -0800427 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 } else {
429 /* Save portname */
430 memcpy(list[i].port_name,
431 ct_rsp->rsp.gpn_id.port_name, WWN_SIZE);
432 }
433
434 /* Last device exit. */
435 if (list[i].d_id.b.rsvd_1 != 0)
436 break;
437 }
438
439 return (rval);
440}
441
442/**
443 * qla2x00_gnn_id() - SNS Get Node Name (GNN_ID) query.
444 * @ha: HA context
445 * @list: switch info entries to populate
446 *
447 * Returns 0 on success.
448 */
449int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800450qla2x00_gnn_id(scsi_qla_host_t *vha, sw_info_t *list)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451{
Chad Dupuis642ef982012-02-09 11:15:57 -0800452 int rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 uint16_t i;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800454 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 ms_iocb_entry_t *ms_pkt;
456 struct ct_sns_req *ct_req;
457 struct ct_sns_rsp *ct_rsp;
Quinn Tran726b8542017-01-19 22:28:00 -0800458 struct ct_arg arg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800460 if (IS_QLA2100(ha) || IS_QLA2200(ha))
461 return qla2x00_sns_gnn_id(vha, list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462
Quinn Tran726b8542017-01-19 22:28:00 -0800463 arg.iocb = ha->ms_iocb;
464 arg.req_dma = ha->ct_sns_dma;
465 arg.rsp_dma = ha->ct_sns_dma;
466 arg.req_size = GNN_ID_REQ_SIZE;
467 arg.rsp_size = GNN_ID_RSP_SIZE;
468 arg.nport_handle = NPH_SNS;
469
Chad Dupuis642ef982012-02-09 11:15:57 -0800470 for (i = 0; i < ha->max_fibre_devices; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 /* Issue GNN_ID */
472 /* Prepare common MS IOCB */
Quinn Tran726b8542017-01-19 22:28:00 -0800473 ms_pkt = ha->isp_ops->prep_ms_iocb(vha, &arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474
475 /* Prepare CT request */
Bart Van Assche6ec6f902013-06-25 11:27:28 -0400476 ct_req = qla2x00_prep_ct_req(ha->ct_sns, GNN_ID_CMD,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 GNN_ID_RSP_SIZE);
478 ct_rsp = &ha->ct_sns->p.rsp;
479
480 /* Prepare CT arguments -- port_id */
481 ct_req->req.port_id.port_id[0] = list[i].d_id.b.domain;
482 ct_req->req.port_id.port_id[1] = list[i].d_id.b.area;
483 ct_req->req.port_id.port_id[2] = list[i].d_id.b.al_pa;
484
485 /* Execute MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800486 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 sizeof(ms_iocb_entry_t));
488 if (rval != QLA_SUCCESS) {
489 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700490 ql_dbg(ql_dbg_disc, vha, 0x2057,
491 "GNN_ID issue IOCB failed (%d).\n", rval);
Arun Easidafdf892012-02-09 11:16:00 -0800492 break;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800493 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp,
Andrew Vasquez8c958a92005-07-06 10:30:47 -0700494 "GNN_ID") != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 rval = QLA_FUNCTION_FAILED;
Arun Easidafdf892012-02-09 11:16:00 -0800496 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 } else {
498 /* Save nodename */
499 memcpy(list[i].node_name,
500 ct_rsp->rsp.gnn_id.node_name, WWN_SIZE);
501
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700502 ql_dbg(ql_dbg_disc, vha, 0x2058,
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -0400503 "GID_PT entry - nn %8phN pn %8phN "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 "portid=%02x%02x%02x.\n",
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -0400505 list[i].node_name, list[i].port_name,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 list[i].d_id.b.domain, list[i].d_id.b.area,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700507 list[i].d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 }
509
510 /* Last device exit. */
511 if (list[i].d_id.b.rsvd_1 != 0)
512 break;
513 }
514
515 return (rval);
516}
517
Quinn Trane374f9f2017-12-28 12:33:31 -0800518static void qla2x00_async_sns_sp_done(void *s, int rc)
519{
520 struct srb *sp = s;
521 struct scsi_qla_host *vha = sp->vha;
522 struct ct_sns_pkt *ct_sns;
523 struct qla_work_evt *e;
524
525 sp->rc = rc;
526 if (rc == QLA_SUCCESS) {
527 ql_dbg(ql_dbg_disc, vha, 0x204f,
528 "Async done-%s exiting normally.\n",
529 sp->name);
530 } else if (rc == QLA_FUNCTION_TIMEOUT) {
531 ql_dbg(ql_dbg_disc, vha, 0x204f,
532 "Async done-%s timeout\n", sp->name);
533 } else {
534 ct_sns = (struct ct_sns_pkt *)sp->u.iocb_cmd.u.ctarg.rsp;
535 memset(ct_sns, 0, sizeof(*ct_sns));
536 sp->retry_count++;
537 if (sp->retry_count > 3)
538 goto err;
539
540 ql_dbg(ql_dbg_disc, vha, 0x204f,
541 "Async done-%s fail rc %x. Retry count %d\n",
542 sp->name, rc, sp->retry_count);
543
544 e = qla2x00_alloc_work(vha, QLA_EVT_SP_RETRY);
545 if (!e)
546 goto err2;
547
548 del_timer(&sp->u.iocb_cmd.timer);
549 e->u.iosb.sp = sp;
550 qla2x00_post_work(vha, e);
551 return;
552 }
553
554err:
555 e = qla2x00_alloc_work(vha, QLA_EVT_UNMAP);
556err2:
557 if (!e) {
558 /* please ignore kernel warning. otherwise, we have mem leak. */
559 if (sp->u.iocb_cmd.u.ctarg.req) {
560 dma_free_coherent(&vha->hw->pdev->dev,
561 sizeof(struct ct_sns_pkt),
562 sp->u.iocb_cmd.u.ctarg.req,
563 sp->u.iocb_cmd.u.ctarg.req_dma);
564 sp->u.iocb_cmd.u.ctarg.req = NULL;
565 }
566
567 if (sp->u.iocb_cmd.u.ctarg.rsp) {
568 dma_free_coherent(&vha->hw->pdev->dev,
569 sizeof(struct ct_sns_pkt),
570 sp->u.iocb_cmd.u.ctarg.rsp,
571 sp->u.iocb_cmd.u.ctarg.rsp_dma);
572 sp->u.iocb_cmd.u.ctarg.rsp = NULL;
573 }
574
575 sp->free(sp);
576
577 return;
578 }
579
580 e->u.iosb.sp = sp;
581 qla2x00_post_work(vha, e);
582}
583
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584/**
585 * qla2x00_rft_id() - SNS Register FC-4 TYPEs (RFT_ID) supported by the HBA.
586 * @ha: HA context
587 *
588 * Returns 0 on success.
589 */
590int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800591qla2x00_rft_id(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800593 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800595 if (IS_QLA2100(ha) || IS_QLA2200(ha))
596 return qla2x00_sns_rft_id(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597
Quinn Trane374f9f2017-12-28 12:33:31 -0800598 return qla_async_rftid(vha, &vha->d_id);
599}
Quinn Tran726b8542017-01-19 22:28:00 -0800600
Quinn Trane374f9f2017-12-28 12:33:31 -0800601static int qla_async_rftid(scsi_qla_host_t *vha, port_id_t *d_id)
602{
603 int rval = QLA_MEMORY_ALLOC_FAILED;
604 struct ct_sns_req *ct_req;
605 srb_t *sp;
606 struct ct_sns_pkt *ct_sns;
607
608 if (!vha->flags.online)
609 goto done;
610
611 sp = qla2x00_get_sp(vha, NULL, GFP_KERNEL);
612 if (!sp)
613 goto done;
614
615 sp->type = SRB_CT_PTHRU_CMD;
616 sp->name = "rft_id";
617 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
618
619 sp->u.iocb_cmd.u.ctarg.req = dma_alloc_coherent(&vha->hw->pdev->dev,
620 sizeof(struct ct_sns_pkt), &sp->u.iocb_cmd.u.ctarg.req_dma,
621 GFP_KERNEL);
622 if (!sp->u.iocb_cmd.u.ctarg.req) {
623 ql_log(ql_log_warn, vha, 0xd041,
624 "%s: Failed to allocate ct_sns request.\n",
625 __func__);
626 goto done_free_sp;
627 }
628
629 sp->u.iocb_cmd.u.ctarg.rsp = dma_alloc_coherent(&vha->hw->pdev->dev,
630 sizeof(struct ct_sns_pkt), &sp->u.iocb_cmd.u.ctarg.rsp_dma,
631 GFP_KERNEL);
632 if (!sp->u.iocb_cmd.u.ctarg.rsp) {
633 ql_log(ql_log_warn, vha, 0xd042,
634 "%s: Failed to allocate ct_sns request.\n",
635 __func__);
636 goto done_free_sp;
637 }
638 ct_sns = (struct ct_sns_pkt *)sp->u.iocb_cmd.u.ctarg.rsp;
639 memset(ct_sns, 0, sizeof(*ct_sns));
640 ct_sns = (struct ct_sns_pkt *)sp->u.iocb_cmd.u.ctarg.req;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641
642 /* Prepare CT request */
Quinn Trane374f9f2017-12-28 12:33:31 -0800643 ct_req = qla2x00_prep_ct_req(ct_sns, RFT_ID_CMD, RFT_ID_RSP_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644
645 /* Prepare CT arguments -- port_id, FC-4 types */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800646 ct_req->req.rft_id.port_id[0] = vha->d_id.b.domain;
647 ct_req->req.rft_id.port_id[1] = vha->d_id.b.area;
648 ct_req->req.rft_id.port_id[2] = vha->d_id.b.al_pa;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 ct_req->req.rft_id.fc4_types[2] = 0x01; /* FCP-3 */
650
Duane Grigsbyd3bae932017-06-21 13:48:44 -0700651 if (vha->flags.nvme_enabled)
652 ct_req->req.rft_id.fc4_types[6] = 1; /* NVMe type 28h */
Quinn Trane374f9f2017-12-28 12:33:31 -0800653
654 sp->u.iocb_cmd.u.ctarg.req_size = RFT_ID_REQ_SIZE;
655 sp->u.iocb_cmd.u.ctarg.rsp_size = RFT_ID_RSP_SIZE;
656 sp->u.iocb_cmd.u.ctarg.nport_handle = NPH_SNS;
657 sp->u.iocb_cmd.timeout = qla2x00_async_iocb_timeout;
658 sp->done = qla2x00_async_sns_sp_done;
659
660 rval = qla2x00_start_sp(sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700662 ql_dbg(ql_dbg_disc, vha, 0x2043,
663 "RFT_ID issue IOCB failed (%d).\n", rval);
Quinn Trane374f9f2017-12-28 12:33:31 -0800664 goto done_free_sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 }
Quinn Trane374f9f2017-12-28 12:33:31 -0800666 ql_dbg(ql_dbg_disc, vha, 0xffff,
667 "Async-%s - hdl=%x portid %06x.\n",
668 sp->name, sp->handle, d_id->b24);
669 return rval;
670done_free_sp:
671 sp->free(sp);
672done:
673 return rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674}
675
676/**
677 * qla2x00_rff_id() - SNS Register FC-4 Features (RFF_ID) supported by the HBA.
678 * @ha: HA context
679 *
680 * Returns 0 on success.
681 */
682int
Duane Grigsbyd3bae932017-06-21 13:48:44 -0700683qla2x00_rff_id(scsi_qla_host_t *vha, u8 type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800685 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686
687 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700688 ql_dbg(ql_dbg_disc, vha, 0x2046,
689 "RFF_ID call not supported on ISP2100/ISP2200.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 return (QLA_SUCCESS);
691 }
692
Quinn Trane374f9f2017-12-28 12:33:31 -0800693 return qla_async_rffid(vha, &vha->d_id, qlt_rff_id(vha),
694 FC4_TYPE_FCP_SCSI);
695}
Quinn Tran726b8542017-01-19 22:28:00 -0800696
Quinn Trane374f9f2017-12-28 12:33:31 -0800697static int qla_async_rffid(scsi_qla_host_t *vha, port_id_t *d_id,
698 u8 fc4feature, u8 fc4type)
699{
700 int rval = QLA_MEMORY_ALLOC_FAILED;
701 struct ct_sns_req *ct_req;
702 srb_t *sp;
703 struct ct_sns_pkt *ct_sns;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704
Quinn Trane374f9f2017-12-28 12:33:31 -0800705 sp = qla2x00_get_sp(vha, NULL, GFP_KERNEL);
706 if (!sp)
707 goto done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708
Quinn Trane374f9f2017-12-28 12:33:31 -0800709 sp->type = SRB_CT_PTHRU_CMD;
710 sp->name = "rff_id";
711 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712
Quinn Trane374f9f2017-12-28 12:33:31 -0800713 sp->u.iocb_cmd.u.ctarg.req = dma_alloc_coherent(&vha->hw->pdev->dev,
714 sizeof(struct ct_sns_pkt), &sp->u.iocb_cmd.u.ctarg.req_dma,
715 GFP_KERNEL);
716 if (!sp->u.iocb_cmd.u.ctarg.req) {
717 ql_log(ql_log_warn, vha, 0xd041,
718 "%s: Failed to allocate ct_sns request.\n",
719 __func__);
720 goto done_free_sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 }
722
Quinn Trane374f9f2017-12-28 12:33:31 -0800723 sp->u.iocb_cmd.u.ctarg.rsp = dma_alloc_coherent(&vha->hw->pdev->dev,
724 sizeof(struct ct_sns_pkt), &sp->u.iocb_cmd.u.ctarg.rsp_dma,
725 GFP_KERNEL);
726 if (!sp->u.iocb_cmd.u.ctarg.rsp) {
727 ql_log(ql_log_warn, vha, 0xd042,
728 "%s: Failed to allocate ct_sns request.\n",
729 __func__);
730 goto done_free_sp;
731 }
732 ct_sns = (struct ct_sns_pkt *)sp->u.iocb_cmd.u.ctarg.rsp;
733 memset(ct_sns, 0, sizeof(*ct_sns));
734 ct_sns = (struct ct_sns_pkt *)sp->u.iocb_cmd.u.ctarg.req;
735
736 /* Prepare CT request */
737 ct_req = qla2x00_prep_ct_req(ct_sns, RFF_ID_CMD, RFF_ID_RSP_SIZE);
738
739 /* Prepare CT arguments -- port_id, FC-4 feature, FC-4 type */
740 ct_req->req.rff_id.port_id[0] = d_id->b.domain;
741 ct_req->req.rff_id.port_id[1] = d_id->b.area;
742 ct_req->req.rff_id.port_id[2] = d_id->b.al_pa;
743 ct_req->req.rff_id.fc4_feature = fc4feature;
744 ct_req->req.rff_id.fc4_type = fc4type; /* SCSI - FCP */
745
746 sp->u.iocb_cmd.u.ctarg.req_size = RFF_ID_REQ_SIZE;
747 sp->u.iocb_cmd.u.ctarg.rsp_size = RFF_ID_RSP_SIZE;
748 sp->u.iocb_cmd.u.ctarg.nport_handle = NPH_SNS;
749 sp->u.iocb_cmd.timeout = qla2x00_async_iocb_timeout;
750 sp->done = qla2x00_async_sns_sp_done;
751
752 rval = qla2x00_start_sp(sp);
753 if (rval != QLA_SUCCESS) {
754 ql_dbg(ql_dbg_disc, vha, 0x2047,
755 "RFF_ID issue IOCB failed (%d).\n", rval);
756 goto done_free_sp;
757 }
758
759 ql_dbg(ql_dbg_disc, vha, 0xffff,
760 "Async-%s - hdl=%x portid %06x feature %x type %x.\n",
761 sp->name, sp->handle, d_id->b24, fc4feature, fc4type);
762 return rval;
763
764done_free_sp:
765 sp->free(sp);
766done:
767 return rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768}
769
770/**
771 * qla2x00_rnn_id() - SNS Register Node Name (RNN_ID) of the HBA.
772 * @ha: HA context
773 *
774 * Returns 0 on success.
775 */
776int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800777qla2x00_rnn_id(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800779 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800781 if (IS_QLA2100(ha) || IS_QLA2200(ha))
782 return qla2x00_sns_rnn_id(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783
Quinn Trane374f9f2017-12-28 12:33:31 -0800784 return qla_async_rnnid(vha, &vha->d_id, vha->node_name);
785}
Quinn Tran726b8542017-01-19 22:28:00 -0800786
Quinn Trane374f9f2017-12-28 12:33:31 -0800787static int qla_async_rnnid(scsi_qla_host_t *vha, port_id_t *d_id,
788 u8 *node_name)
789{
790 int rval = QLA_MEMORY_ALLOC_FAILED;
791 struct ct_sns_req *ct_req;
792 srb_t *sp;
793 struct ct_sns_pkt *ct_sns;
794
795 sp = qla2x00_get_sp(vha, NULL, GFP_KERNEL);
796 if (!sp)
797 goto done;
798
799 sp->type = SRB_CT_PTHRU_CMD;
800 sp->name = "rnid";
801 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
802
803 sp->u.iocb_cmd.u.ctarg.req = dma_alloc_coherent(&vha->hw->pdev->dev,
804 sizeof(struct ct_sns_pkt), &sp->u.iocb_cmd.u.ctarg.req_dma,
805 GFP_KERNEL);
806 if (!sp->u.iocb_cmd.u.ctarg.req) {
807 ql_log(ql_log_warn, vha, 0xd041,
808 "%s: Failed to allocate ct_sns request.\n",
809 __func__);
810 goto done_free_sp;
811 }
812
813 sp->u.iocb_cmd.u.ctarg.rsp = dma_alloc_coherent(&vha->hw->pdev->dev,
814 sizeof(struct ct_sns_pkt), &sp->u.iocb_cmd.u.ctarg.rsp_dma,
815 GFP_KERNEL);
816 if (!sp->u.iocb_cmd.u.ctarg.rsp) {
817 ql_log(ql_log_warn, vha, 0xd042,
818 "%s: Failed to allocate ct_sns request.\n",
819 __func__);
820 goto done_free_sp;
821 }
822 ct_sns = (struct ct_sns_pkt *)sp->u.iocb_cmd.u.ctarg.rsp;
823 memset(ct_sns, 0, sizeof(*ct_sns));
824 ct_sns = (struct ct_sns_pkt *)sp->u.iocb_cmd.u.ctarg.req;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825
826 /* Prepare CT request */
Quinn Trane374f9f2017-12-28 12:33:31 -0800827 ct_req = qla2x00_prep_ct_req(ct_sns, RNN_ID_CMD, RNN_ID_RSP_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828
829 /* Prepare CT arguments -- port_id, node_name */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800830 ct_req->req.rnn_id.port_id[0] = vha->d_id.b.domain;
831 ct_req->req.rnn_id.port_id[1] = vha->d_id.b.area;
832 ct_req->req.rnn_id.port_id[2] = vha->d_id.b.al_pa;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800833 memcpy(ct_req->req.rnn_id.node_name, vha->node_name, WWN_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834
Quinn Trane374f9f2017-12-28 12:33:31 -0800835 sp->u.iocb_cmd.u.ctarg.req_size = RNN_ID_REQ_SIZE;
836 sp->u.iocb_cmd.u.ctarg.rsp_size = RNN_ID_RSP_SIZE;
837 sp->u.iocb_cmd.u.ctarg.nport_handle = NPH_SNS;
838
839 sp->u.iocb_cmd.timeout = qla2x00_async_iocb_timeout;
840 sp->done = qla2x00_async_sns_sp_done;
841
842 rval = qla2x00_start_sp(sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700844 ql_dbg(ql_dbg_disc, vha, 0x204d,
845 "RNN_ID issue IOCB failed (%d).\n", rval);
Quinn Trane374f9f2017-12-28 12:33:31 -0800846 goto done_free_sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847 }
Quinn Trane374f9f2017-12-28 12:33:31 -0800848 ql_dbg(ql_dbg_disc, vha, 0xffff,
849 "Async-%s - hdl=%x portid %06x\n",
850 sp->name, sp->handle, d_id->b24);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851
Quinn Trane374f9f2017-12-28 12:33:31 -0800852 return rval;
853
854done_free_sp:
855 sp->free(sp);
856done:
857 return rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858}
859
Andrew Vasquez1620f7c2006-10-02 12:00:44 -0700860void
Himanshu Madhanidf57cab2014-09-25 05:16:46 -0400861qla2x00_get_sym_node_name(scsi_qla_host_t *vha, uint8_t *snn, size_t size)
Andrew Vasquez1620f7c2006-10-02 12:00:44 -0700862{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800863 struct qla_hw_data *ha = vha->hw;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400864
865 if (IS_QLAFX00(ha))
Himanshu Madhanidf57cab2014-09-25 05:16:46 -0400866 snprintf(snn, size, "%s FW:v%s DVR:v%s", ha->model_number,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400867 ha->mr.fw_version, qla2x00_version_str);
868 else
Himanshu Madhanidf57cab2014-09-25 05:16:46 -0400869 snprintf(snn, size,
870 "%s FW:v%d.%02d.%02d DVR:v%s", ha->model_number,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400871 ha->fw_major_version, ha->fw_minor_version,
872 ha->fw_subminor_version, qla2x00_version_str);
Andrew Vasquez1620f7c2006-10-02 12:00:44 -0700873}
874
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875/**
876 * qla2x00_rsnn_nn() - SNS Register Symbolic Node Name (RSNN_NN) of the HBA.
877 * @ha: HA context
878 *
879 * Returns 0 on success.
880 */
881int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800882qla2x00_rsnn_nn(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800884 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885
886 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700887 ql_dbg(ql_dbg_disc, vha, 0x2050,
888 "RSNN_ID call unsupported on ISP2100/ISP2200.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889 return (QLA_SUCCESS);
890 }
891
Quinn Trane374f9f2017-12-28 12:33:31 -0800892 return qla_async_rsnn_nn(vha);
893}
Quinn Tran726b8542017-01-19 22:28:00 -0800894
Quinn Trane374f9f2017-12-28 12:33:31 -0800895static int qla_async_rsnn_nn(scsi_qla_host_t *vha)
896{
897 int rval = QLA_MEMORY_ALLOC_FAILED;
898 struct ct_sns_req *ct_req;
899 srb_t *sp;
900 struct ct_sns_pkt *ct_sns;
901
902 sp = qla2x00_get_sp(vha, NULL, GFP_KERNEL);
903 if (!sp)
904 goto done;
905
906 sp->type = SRB_CT_PTHRU_CMD;
907 sp->name = "rsnn_nn";
908 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
909
910 sp->u.iocb_cmd.u.ctarg.req = dma_alloc_coherent(&vha->hw->pdev->dev,
911 sizeof(struct ct_sns_pkt), &sp->u.iocb_cmd.u.ctarg.req_dma,
912 GFP_KERNEL);
913 if (!sp->u.iocb_cmd.u.ctarg.req) {
914 ql_log(ql_log_warn, vha, 0xd041,
915 "%s: Failed to allocate ct_sns request.\n",
916 __func__);
917 goto done_free_sp;
918 }
919
920 sp->u.iocb_cmd.u.ctarg.rsp = dma_alloc_coherent(&vha->hw->pdev->dev,
921 sizeof(struct ct_sns_pkt), &sp->u.iocb_cmd.u.ctarg.rsp_dma,
922 GFP_KERNEL);
923 if (!sp->u.iocb_cmd.u.ctarg.rsp) {
924 ql_log(ql_log_warn, vha, 0xd042,
925 "%s: Failed to allocate ct_sns request.\n",
926 __func__);
927 goto done_free_sp;
928 }
929 ct_sns = (struct ct_sns_pkt *)sp->u.iocb_cmd.u.ctarg.rsp;
930 memset(ct_sns, 0, sizeof(*ct_sns));
931 ct_sns = (struct ct_sns_pkt *)sp->u.iocb_cmd.u.ctarg.req;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932
933 /* Prepare CT request */
Quinn Trane374f9f2017-12-28 12:33:31 -0800934 ct_req = qla2x00_prep_ct_req(ct_sns, RSNN_NN_CMD, RSNN_NN_RSP_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935
936 /* Prepare CT arguments -- node_name, symbolic node_name, size */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800937 memcpy(ct_req->req.rsnn_nn.node_name, vha->node_name, WWN_SIZE);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700938
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939 /* Prepare the Symbolic Node Name */
Himanshu Madhanidf57cab2014-09-25 05:16:46 -0400940 qla2x00_get_sym_node_name(vha, ct_req->req.rsnn_nn.sym_node_name,
941 sizeof(ct_req->req.rsnn_nn.sym_node_name));
Andrew Vasquez1620f7c2006-10-02 12:00:44 -0700942 ct_req->req.rsnn_nn.name_len =
943 (uint8_t)strlen(ct_req->req.rsnn_nn.sym_node_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945
Quinn Trane374f9f2017-12-28 12:33:31 -0800946 sp->u.iocb_cmd.u.ctarg.req_size = 24 + 1 + ct_req->req.rsnn_nn.name_len;
947 sp->u.iocb_cmd.u.ctarg.rsp_size = RSNN_NN_RSP_SIZE;
948 sp->u.iocb_cmd.u.ctarg.nport_handle = NPH_SNS;
949
950 sp->u.iocb_cmd.timeout = qla2x00_async_iocb_timeout;
951 sp->done = qla2x00_async_sns_sp_done;
952
953 rval = qla2x00_start_sp(sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954 if (rval != QLA_SUCCESS) {
Quinn Trane374f9f2017-12-28 12:33:31 -0800955 ql_dbg(ql_dbg_disc, vha, 0x2043,
956 "RFT_ID issue IOCB failed (%d).\n", rval);
957 goto done_free_sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958 }
Quinn Trane374f9f2017-12-28 12:33:31 -0800959 ql_dbg(ql_dbg_disc, vha, 0xffff,
960 "Async-%s - hdl=%x.\n",
961 sp->name, sp->handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962
Quinn Trane374f9f2017-12-28 12:33:31 -0800963 return rval;
964
965done_free_sp:
966 sp->free(sp);
967done:
968 return rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969}
970
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971/**
972 * qla2x00_prep_sns_cmd() - Prepare common SNS command request fields for query.
973 * @ha: HA context
974 * @cmd: GS command
975 * @scmd_len: Subcommand length
976 * @data_size: response size in bytes
977 *
978 * Returns a pointer to the @ha's sns_cmd.
979 */
980static inline struct sns_cmd_pkt *
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800981qla2x00_prep_sns_cmd(scsi_qla_host_t *vha, uint16_t cmd, uint16_t scmd_len,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982 uint16_t data_size)
983{
984 uint16_t wc;
985 struct sns_cmd_pkt *sns_cmd;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800986 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987
988 sns_cmd = ha->sns_cmd;
989 memset(sns_cmd, 0, sizeof(struct sns_cmd_pkt));
990 wc = data_size / 2; /* Size in 16bit words. */
991 sns_cmd->p.cmd.buffer_length = cpu_to_le16(wc);
992 sns_cmd->p.cmd.buffer_address[0] = cpu_to_le32(LSD(ha->sns_cmd_dma));
993 sns_cmd->p.cmd.buffer_address[1] = cpu_to_le32(MSD(ha->sns_cmd_dma));
994 sns_cmd->p.cmd.subcommand_length = cpu_to_le16(scmd_len);
995 sns_cmd->p.cmd.subcommand = cpu_to_le16(cmd);
996 wc = (data_size - 16) / 4; /* Size in 32bit words. */
997 sns_cmd->p.cmd.size = cpu_to_le16(wc);
998
Joe Carnucciofabbb8d2013-08-27 01:37:40 -0400999 vha->qla_stats.control_requests++;
1000
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001 return (sns_cmd);
1002}
1003
1004/**
1005 * qla2x00_sns_ga_nxt() - SNS scan for fabric devices via GA_NXT command.
1006 * @ha: HA context
1007 * @fcport: fcport entry to updated
1008 *
1009 * This command uses the old Exectute SNS Command mailbox routine.
1010 *
1011 * Returns 0 on success.
1012 */
1013static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001014qla2x00_sns_ga_nxt(scsi_qla_host_t *vha, fc_port_t *fcport)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015{
Chad Dupuis642ef982012-02-09 11:15:57 -08001016 int rval = QLA_SUCCESS;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001017 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018 struct sns_cmd_pkt *sns_cmd;
1019
1020 /* Issue GA_NXT. */
1021 /* Prepare SNS command request. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001022 sns_cmd = qla2x00_prep_sns_cmd(vha, GA_NXT_CMD, GA_NXT_SNS_SCMD_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 GA_NXT_SNS_DATA_SIZE);
1024
1025 /* Prepare SNS command arguments -- port_id. */
1026 sns_cmd->p.cmd.param[0] = fcport->d_id.b.al_pa;
1027 sns_cmd->p.cmd.param[1] = fcport->d_id.b.area;
1028 sns_cmd->p.cmd.param[2] = fcport->d_id.b.domain;
1029
1030 /* Execute SNS command. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001031 rval = qla2x00_send_sns(vha, ha->sns_cmd_dma, GA_NXT_SNS_CMD_SIZE / 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032 sizeof(struct sns_cmd_pkt));
1033 if (rval != QLA_SUCCESS) {
1034 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001035 ql_dbg(ql_dbg_disc, vha, 0x205f,
1036 "GA_NXT Send SNS failed (%d).\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 } else if (sns_cmd->p.gan_data[8] != 0x80 ||
1038 sns_cmd->p.gan_data[9] != 0x02) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08001039 ql_dbg(ql_dbg_disc + ql_dbg_buffer, vha, 0x2084,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001040 "GA_NXT failed, rejected request ga_nxt_rsp:\n");
1041 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2074,
1042 sns_cmd->p.gan_data, 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043 rval = QLA_FUNCTION_FAILED;
1044 } else {
1045 /* Populate fc_port_t entry. */
1046 fcport->d_id.b.domain = sns_cmd->p.gan_data[17];
1047 fcport->d_id.b.area = sns_cmd->p.gan_data[18];
1048 fcport->d_id.b.al_pa = sns_cmd->p.gan_data[19];
1049
1050 memcpy(fcport->node_name, &sns_cmd->p.gan_data[284], WWN_SIZE);
1051 memcpy(fcport->port_name, &sns_cmd->p.gan_data[20], WWN_SIZE);
1052
1053 if (sns_cmd->p.gan_data[16] != NS_N_PORT_TYPE &&
1054 sns_cmd->p.gan_data[16] != NS_NL_PORT_TYPE)
1055 fcport->d_id.b.domain = 0xf0;
1056
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001057 ql_dbg(ql_dbg_disc, vha, 0x2061,
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -04001058 "GA_NXT entry - nn %8phN pn %8phN "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001059 "port_id=%02x%02x%02x.\n",
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -04001060 fcport->node_name, fcport->port_name,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061 fcport->d_id.b.domain, fcport->d_id.b.area,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001062 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063 }
1064
1065 return (rval);
1066}
1067
1068/**
1069 * qla2x00_sns_gid_pt() - SNS scan for fabric devices via GID_PT command.
1070 * @ha: HA context
1071 * @list: switch info entries to populate
1072 *
1073 * This command uses the old Exectute SNS Command mailbox routine.
1074 *
1075 * NOTE: Non-Nx_Ports are not requested.
1076 *
1077 * Returns 0 on success.
1078 */
1079static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001080qla2x00_sns_gid_pt(scsi_qla_host_t *vha, sw_info_t *list)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081{
1082 int rval;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001083 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084 uint16_t i;
1085 uint8_t *entry;
1086 struct sns_cmd_pkt *sns_cmd;
Chad Dupuis642ef982012-02-09 11:15:57 -08001087 uint16_t gid_pt_sns_data_size;
1088
1089 gid_pt_sns_data_size = qla2x00_gid_pt_rsp_size(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090
1091 /* Issue GID_PT. */
1092 /* Prepare SNS command request. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001093 sns_cmd = qla2x00_prep_sns_cmd(vha, GID_PT_CMD, GID_PT_SNS_SCMD_LEN,
Chad Dupuis642ef982012-02-09 11:15:57 -08001094 gid_pt_sns_data_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095
1096 /* Prepare SNS command arguments -- port_type. */
1097 sns_cmd->p.cmd.param[0] = NS_NX_PORT_TYPE;
1098
1099 /* Execute SNS command. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001100 rval = qla2x00_send_sns(vha, ha->sns_cmd_dma, GID_PT_SNS_CMD_SIZE / 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101 sizeof(struct sns_cmd_pkt));
1102 if (rval != QLA_SUCCESS) {
1103 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001104 ql_dbg(ql_dbg_disc, vha, 0x206d,
1105 "GID_PT Send SNS failed (%d).\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106 } else if (sns_cmd->p.gid_data[8] != 0x80 ||
1107 sns_cmd->p.gid_data[9] != 0x02) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001108 ql_dbg(ql_dbg_disc, vha, 0x202f,
1109 "GID_PT failed, rejected request, gid_rsp:\n");
1110 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2081,
1111 sns_cmd->p.gid_data, 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112 rval = QLA_FUNCTION_FAILED;
1113 } else {
1114 /* Set port IDs in switch info list. */
Chad Dupuis642ef982012-02-09 11:15:57 -08001115 for (i = 0; i < ha->max_fibre_devices; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116 entry = &sns_cmd->p.gid_data[(i * 4) + 16];
1117 list[i].d_id.b.domain = entry[1];
1118 list[i].d_id.b.area = entry[2];
1119 list[i].d_id.b.al_pa = entry[3];
1120
1121 /* Last one exit. */
1122 if (entry[0] & BIT_7) {
1123 list[i].d_id.b.rsvd_1 = entry[0];
1124 break;
1125 }
1126 }
1127
1128 /*
1129 * If we've used all available slots, then the switch is
1130 * reporting back more devices that we can handle with this
1131 * single call. Return a failed status, and let GA_NXT handle
1132 * the overload.
1133 */
Chad Dupuis642ef982012-02-09 11:15:57 -08001134 if (i == ha->max_fibre_devices)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135 rval = QLA_FUNCTION_FAILED;
1136 }
1137
1138 return (rval);
1139}
1140
1141/**
1142 * qla2x00_sns_gpn_id() - SNS Get Port Name (GPN_ID) query.
1143 * @ha: HA context
1144 * @list: switch info entries to populate
1145 *
1146 * This command uses the old Exectute SNS Command mailbox routine.
1147 *
1148 * Returns 0 on success.
1149 */
1150static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001151qla2x00_sns_gpn_id(scsi_qla_host_t *vha, sw_info_t *list)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152{
Chad Dupuis642ef982012-02-09 11:15:57 -08001153 int rval = QLA_SUCCESS;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001154 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155 uint16_t i;
1156 struct sns_cmd_pkt *sns_cmd;
1157
Chad Dupuis642ef982012-02-09 11:15:57 -08001158 for (i = 0; i < ha->max_fibre_devices; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159 /* Issue GPN_ID */
1160 /* Prepare SNS command request. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001161 sns_cmd = qla2x00_prep_sns_cmd(vha, GPN_ID_CMD,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162 GPN_ID_SNS_SCMD_LEN, GPN_ID_SNS_DATA_SIZE);
1163
1164 /* Prepare SNS command arguments -- port_id. */
1165 sns_cmd->p.cmd.param[0] = list[i].d_id.b.al_pa;
1166 sns_cmd->p.cmd.param[1] = list[i].d_id.b.area;
1167 sns_cmd->p.cmd.param[2] = list[i].d_id.b.domain;
1168
1169 /* Execute SNS command. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001170 rval = qla2x00_send_sns(vha, ha->sns_cmd_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171 GPN_ID_SNS_CMD_SIZE / 2, sizeof(struct sns_cmd_pkt));
1172 if (rval != QLA_SUCCESS) {
1173 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001174 ql_dbg(ql_dbg_disc, vha, 0x2032,
1175 "GPN_ID Send SNS failed (%d).\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176 } else if (sns_cmd->p.gpn_data[8] != 0x80 ||
1177 sns_cmd->p.gpn_data[9] != 0x02) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001178 ql_dbg(ql_dbg_disc + ql_dbg_buffer, vha, 0x207e,
1179 "GPN_ID failed, rejected request, gpn_rsp:\n");
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001180 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x207f,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001181 sns_cmd->p.gpn_data, 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182 rval = QLA_FUNCTION_FAILED;
1183 } else {
1184 /* Save portname */
1185 memcpy(list[i].port_name, &sns_cmd->p.gpn_data[16],
1186 WWN_SIZE);
1187 }
1188
1189 /* Last device exit. */
1190 if (list[i].d_id.b.rsvd_1 != 0)
1191 break;
1192 }
1193
1194 return (rval);
1195}
1196
1197/**
1198 * qla2x00_sns_gnn_id() - SNS Get Node Name (GNN_ID) query.
1199 * @ha: HA context
1200 * @list: switch info entries to populate
1201 *
1202 * This command uses the old Exectute SNS Command mailbox routine.
1203 *
1204 * Returns 0 on success.
1205 */
1206static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001207qla2x00_sns_gnn_id(scsi_qla_host_t *vha, sw_info_t *list)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208{
Chad Dupuis642ef982012-02-09 11:15:57 -08001209 int rval = QLA_SUCCESS;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001210 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211 uint16_t i;
1212 struct sns_cmd_pkt *sns_cmd;
1213
Chad Dupuis642ef982012-02-09 11:15:57 -08001214 for (i = 0; i < ha->max_fibre_devices; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215 /* Issue GNN_ID */
1216 /* Prepare SNS command request. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001217 sns_cmd = qla2x00_prep_sns_cmd(vha, GNN_ID_CMD,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218 GNN_ID_SNS_SCMD_LEN, GNN_ID_SNS_DATA_SIZE);
1219
1220 /* Prepare SNS command arguments -- port_id. */
1221 sns_cmd->p.cmd.param[0] = list[i].d_id.b.al_pa;
1222 sns_cmd->p.cmd.param[1] = list[i].d_id.b.area;
1223 sns_cmd->p.cmd.param[2] = list[i].d_id.b.domain;
1224
1225 /* Execute SNS command. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001226 rval = qla2x00_send_sns(vha, ha->sns_cmd_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227 GNN_ID_SNS_CMD_SIZE / 2, sizeof(struct sns_cmd_pkt));
1228 if (rval != QLA_SUCCESS) {
1229 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001230 ql_dbg(ql_dbg_disc, vha, 0x203f,
1231 "GNN_ID Send SNS failed (%d).\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232 } else if (sns_cmd->p.gnn_data[8] != 0x80 ||
1233 sns_cmd->p.gnn_data[9] != 0x02) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001234 ql_dbg(ql_dbg_disc + ql_dbg_buffer, vha, 0x2082,
1235 "GNN_ID failed, rejected request, gnn_rsp:\n");
1236 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x207a,
1237 sns_cmd->p.gnn_data, 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001238 rval = QLA_FUNCTION_FAILED;
1239 } else {
1240 /* Save nodename */
1241 memcpy(list[i].node_name, &sns_cmd->p.gnn_data[16],
1242 WWN_SIZE);
1243
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001244 ql_dbg(ql_dbg_disc, vha, 0x206e,
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -04001245 "GID_PT entry - nn %8phN pn %8phN "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001246 "port_id=%02x%02x%02x.\n",
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -04001247 list[i].node_name, list[i].port_name,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248 list[i].d_id.b.domain, list[i].d_id.b.area,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001249 list[i].d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250 }
1251
1252 /* Last device exit. */
1253 if (list[i].d_id.b.rsvd_1 != 0)
1254 break;
1255 }
1256
1257 return (rval);
1258}
1259
1260/**
1261 * qla2x00_snd_rft_id() - SNS Register FC-4 TYPEs (RFT_ID) supported by the HBA.
1262 * @ha: HA context
1263 *
1264 * This command uses the old Exectute SNS Command mailbox routine.
1265 *
1266 * Returns 0 on success.
1267 */
1268static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001269qla2x00_sns_rft_id(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270{
1271 int rval;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001272 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273 struct sns_cmd_pkt *sns_cmd;
1274
1275 /* Issue RFT_ID. */
1276 /* Prepare SNS command request. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001277 sns_cmd = qla2x00_prep_sns_cmd(vha, RFT_ID_CMD, RFT_ID_SNS_SCMD_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278 RFT_ID_SNS_DATA_SIZE);
1279
1280 /* Prepare SNS command arguments -- port_id, FC-4 types */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001281 sns_cmd->p.cmd.param[0] = vha->d_id.b.al_pa;
1282 sns_cmd->p.cmd.param[1] = vha->d_id.b.area;
1283 sns_cmd->p.cmd.param[2] = vha->d_id.b.domain;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284
1285 sns_cmd->p.cmd.param[5] = 0x01; /* FCP-3 */
1286
1287 /* Execute SNS command. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001288 rval = qla2x00_send_sns(vha, ha->sns_cmd_dma, RFT_ID_SNS_CMD_SIZE / 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289 sizeof(struct sns_cmd_pkt));
1290 if (rval != QLA_SUCCESS) {
1291 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001292 ql_dbg(ql_dbg_disc, vha, 0x2060,
1293 "RFT_ID Send SNS failed (%d).\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294 } else if (sns_cmd->p.rft_data[8] != 0x80 ||
1295 sns_cmd->p.rft_data[9] != 0x02) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001296 ql_dbg(ql_dbg_disc + ql_dbg_buffer, vha, 0x2083,
1297 "RFT_ID failed, rejected request rft_rsp:\n");
1298 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2080,
1299 sns_cmd->p.rft_data, 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300 rval = QLA_FUNCTION_FAILED;
1301 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001302 ql_dbg(ql_dbg_disc, vha, 0x2073,
1303 "RFT_ID exiting normally.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304 }
1305
1306 return (rval);
1307}
1308
1309/**
1310 * qla2x00_sns_rnn_id() - SNS Register Node Name (RNN_ID) of the HBA.
1311 * HBA.
1312 * @ha: HA context
1313 *
1314 * This command uses the old Exectute SNS Command mailbox routine.
1315 *
1316 * Returns 0 on success.
1317 */
1318static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001319qla2x00_sns_rnn_id(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320{
1321 int rval;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001322 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323 struct sns_cmd_pkt *sns_cmd;
1324
1325 /* Issue RNN_ID. */
1326 /* Prepare SNS command request. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001327 sns_cmd = qla2x00_prep_sns_cmd(vha, RNN_ID_CMD, RNN_ID_SNS_SCMD_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328 RNN_ID_SNS_DATA_SIZE);
1329
1330 /* Prepare SNS command arguments -- port_id, nodename. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001331 sns_cmd->p.cmd.param[0] = vha->d_id.b.al_pa;
1332 sns_cmd->p.cmd.param[1] = vha->d_id.b.area;
1333 sns_cmd->p.cmd.param[2] = vha->d_id.b.domain;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001335 sns_cmd->p.cmd.param[4] = vha->node_name[7];
1336 sns_cmd->p.cmd.param[5] = vha->node_name[6];
1337 sns_cmd->p.cmd.param[6] = vha->node_name[5];
1338 sns_cmd->p.cmd.param[7] = vha->node_name[4];
1339 sns_cmd->p.cmd.param[8] = vha->node_name[3];
1340 sns_cmd->p.cmd.param[9] = vha->node_name[2];
1341 sns_cmd->p.cmd.param[10] = vha->node_name[1];
1342 sns_cmd->p.cmd.param[11] = vha->node_name[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343
1344 /* Execute SNS command. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001345 rval = qla2x00_send_sns(vha, ha->sns_cmd_dma, RNN_ID_SNS_CMD_SIZE / 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346 sizeof(struct sns_cmd_pkt));
1347 if (rval != QLA_SUCCESS) {
1348 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001349 ql_dbg(ql_dbg_disc, vha, 0x204a,
1350 "RNN_ID Send SNS failed (%d).\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351 } else if (sns_cmd->p.rnn_data[8] != 0x80 ||
1352 sns_cmd->p.rnn_data[9] != 0x02) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001353 ql_dbg(ql_dbg_disc + ql_dbg_buffer, vha, 0x207b,
1354 "RNN_ID failed, rejected request, rnn_rsp:\n");
1355 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x207c,
1356 sns_cmd->p.rnn_data, 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357 rval = QLA_FUNCTION_FAILED;
1358 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001359 ql_dbg(ql_dbg_disc, vha, 0x204c,
1360 "RNN_ID exiting normally.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361 }
1362
1363 return (rval);
1364}
Andrew Vasquezcca53352005-08-26 19:08:30 -07001365
1366/**
Joe Perchesb1c11812008-02-03 17:28:22 +02001367 * qla2x00_mgmt_svr_login() - Login to fabric Management Service.
Andrew Vasquezcca53352005-08-26 19:08:30 -07001368 * @ha: HA context
1369 *
1370 * Returns 0 on success.
1371 */
Quinn Tran726b8542017-01-19 22:28:00 -08001372int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001373qla2x00_mgmt_svr_login(scsi_qla_host_t *vha)
Andrew Vasquezcca53352005-08-26 19:08:30 -07001374{
Chad Dupuis0b91d112012-02-09 11:15:42 -08001375 int ret, rval;
Andrew Vasquezcca53352005-08-26 19:08:30 -07001376 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001377 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezcca53352005-08-26 19:08:30 -07001378 ret = QLA_SUCCESS;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001379 if (vha->flags.management_server_logged_in)
Andrew Vasquezcca53352005-08-26 19:08:30 -07001380 return ret;
1381
Chad Dupuis0b91d112012-02-09 11:15:42 -08001382 rval = ha->isp_ops->fabric_login(vha, vha->mgmt_svr_loop_id, 0xff, 0xff,
Andrew Vasquez58570ac2012-08-22 14:21:18 -04001383 0xfa, mb, BIT_1);
Chad Dupuis0b91d112012-02-09 11:15:42 -08001384 if (rval != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
1385 if (rval == QLA_MEMORY_ALLOC_FAILED)
1386 ql_dbg(ql_dbg_disc, vha, 0x2085,
1387 "Failed management_server login: loopid=%x "
1388 "rval=%d\n", vha->mgmt_svr_loop_id, rval);
1389 else
1390 ql_dbg(ql_dbg_disc, vha, 0x2024,
1391 "Failed management_server login: loopid=%x "
1392 "mb[0]=%x mb[1]=%x mb[2]=%x mb[6]=%x mb[7]=%x.\n",
1393 vha->mgmt_svr_loop_id, mb[0], mb[1], mb[2], mb[6],
1394 mb[7]);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001395 ret = QLA_FUNCTION_FAILED;
1396 } else
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001397 vha->flags.management_server_logged_in = 1;
Andrew Vasquezcca53352005-08-26 19:08:30 -07001398
1399 return ret;
1400}
1401
1402/**
1403 * qla2x00_prep_ms_fdmi_iocb() - Prepare common MS IOCB fields for FDMI query.
1404 * @ha: HA context
1405 * @req_size: request size in bytes
1406 * @rsp_size: response size in bytes
1407 *
1408 * Returns a pointer to the @ha's ms_iocb.
1409 */
1410void *
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001411qla2x00_prep_ms_fdmi_iocb(scsi_qla_host_t *vha, uint32_t req_size,
Andrew Vasquezcca53352005-08-26 19:08:30 -07001412 uint32_t rsp_size)
1413{
1414 ms_iocb_entry_t *ms_pkt;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001415 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezcca53352005-08-26 19:08:30 -07001416 ms_pkt = ha->ms_iocb;
1417 memset(ms_pkt, 0, sizeof(ms_iocb_entry_t));
1418
1419 ms_pkt->entry_type = MS_IOCB_TYPE;
1420 ms_pkt->entry_count = 1;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001421 SET_TARGET_ID(ha, ms_pkt->loop_id, vha->mgmt_svr_loop_id);
Bart Van Asschead950362015-07-09 07:24:08 -07001422 ms_pkt->control_flags = cpu_to_le16(CF_READ | CF_HEAD_TAG);
Andrew Vasquez00a537b2008-02-28 14:06:11 -08001423 ms_pkt->timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
Bart Van Asschead950362015-07-09 07:24:08 -07001424 ms_pkt->cmd_dsd_count = cpu_to_le16(1);
1425 ms_pkt->total_dsd_count = cpu_to_le16(2);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001426 ms_pkt->rsp_bytecount = cpu_to_le32(rsp_size);
1427 ms_pkt->req_bytecount = cpu_to_le32(req_size);
1428
1429 ms_pkt->dseg_req_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
1430 ms_pkt->dseg_req_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
1431 ms_pkt->dseg_req_length = ms_pkt->req_bytecount;
1432
1433 ms_pkt->dseg_rsp_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
1434 ms_pkt->dseg_rsp_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
1435 ms_pkt->dseg_rsp_length = ms_pkt->rsp_bytecount;
1436
1437 return ms_pkt;
1438}
1439
1440/**
1441 * qla24xx_prep_ms_fdmi_iocb() - Prepare common MS IOCB fields for FDMI query.
1442 * @ha: HA context
1443 * @req_size: request size in bytes
1444 * @rsp_size: response size in bytes
1445 *
1446 * Returns a pointer to the @ha's ms_iocb.
1447 */
1448void *
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001449qla24xx_prep_ms_fdmi_iocb(scsi_qla_host_t *vha, uint32_t req_size,
Andrew Vasquezcca53352005-08-26 19:08:30 -07001450 uint32_t rsp_size)
1451{
1452 struct ct_entry_24xx *ct_pkt;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001453 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezcca53352005-08-26 19:08:30 -07001454
1455 ct_pkt = (struct ct_entry_24xx *)ha->ms_iocb;
1456 memset(ct_pkt, 0, sizeof(struct ct_entry_24xx));
1457
1458 ct_pkt->entry_type = CT_IOCB_TYPE;
1459 ct_pkt->entry_count = 1;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001460 ct_pkt->nport_handle = cpu_to_le16(vha->mgmt_svr_loop_id);
Andrew Vasquez00a537b2008-02-28 14:06:11 -08001461 ct_pkt->timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
Bart Van Asschead950362015-07-09 07:24:08 -07001462 ct_pkt->cmd_dsd_count = cpu_to_le16(1);
1463 ct_pkt->rsp_dsd_count = cpu_to_le16(1);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001464 ct_pkt->rsp_byte_count = cpu_to_le32(rsp_size);
1465 ct_pkt->cmd_byte_count = cpu_to_le32(req_size);
1466
1467 ct_pkt->dseg_0_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
1468 ct_pkt->dseg_0_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
1469 ct_pkt->dseg_0_len = ct_pkt->cmd_byte_count;
1470
1471 ct_pkt->dseg_1_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
1472 ct_pkt->dseg_1_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
1473 ct_pkt->dseg_1_len = ct_pkt->rsp_byte_count;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001474 ct_pkt->vp_index = vha->vp_idx;
Andrew Vasquezcca53352005-08-26 19:08:30 -07001475
1476 return ct_pkt;
1477}
1478
1479static inline ms_iocb_entry_t *
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001480qla2x00_update_ms_fdmi_iocb(scsi_qla_host_t *vha, uint32_t req_size)
Andrew Vasquezcca53352005-08-26 19:08:30 -07001481{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001482 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezcca53352005-08-26 19:08:30 -07001483 ms_iocb_entry_t *ms_pkt = ha->ms_iocb;
1484 struct ct_entry_24xx *ct_pkt = (struct ct_entry_24xx *)ha->ms_iocb;
1485
Andrew Vasqueze4289242007-07-19 15:05:56 -07001486 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquezcca53352005-08-26 19:08:30 -07001487 ct_pkt->cmd_byte_count = cpu_to_le32(req_size);
1488 ct_pkt->dseg_0_len = ct_pkt->cmd_byte_count;
1489 } else {
1490 ms_pkt->req_bytecount = cpu_to_le32(req_size);
1491 ms_pkt->dseg_req_length = ms_pkt->req_bytecount;
1492 }
1493
1494 return ms_pkt;
1495}
1496
1497/**
1498 * qla2x00_prep_ct_req() - Prepare common CT request fields for SNS query.
1499 * @ct_req: CT request buffer
1500 * @cmd: GS command
1501 * @rsp_size: response size in bytes
1502 *
1503 * Returns a pointer to the intitialized @ct_req.
1504 */
1505static inline struct ct_sns_req *
Bart Van Assche6ec6f902013-06-25 11:27:28 -04001506qla2x00_prep_ct_fdmi_req(struct ct_sns_pkt *p, uint16_t cmd,
Andrew Vasquezcca53352005-08-26 19:08:30 -07001507 uint16_t rsp_size)
1508{
Bart Van Assche6ec6f902013-06-25 11:27:28 -04001509 memset(p, 0, sizeof(struct ct_sns_pkt));
Andrew Vasquezcca53352005-08-26 19:08:30 -07001510
Bart Van Assche6ec6f902013-06-25 11:27:28 -04001511 p->p.req.header.revision = 0x01;
1512 p->p.req.header.gs_type = 0xFA;
1513 p->p.req.header.gs_subtype = 0x10;
1514 p->p.req.command = cpu_to_be16(cmd);
1515 p->p.req.max_rsp_size = cpu_to_be16((rsp_size - 16) / 4);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001516
Bart Van Assche6ec6f902013-06-25 11:27:28 -04001517 return &p->p.req;
Andrew Vasquezcca53352005-08-26 19:08:30 -07001518}
1519
1520/**
1521 * qla2x00_fdmi_rhba() -
1522 * @ha: HA context
1523 *
1524 * Returns 0 on success.
1525 */
1526static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001527qla2x00_fdmi_rhba(scsi_qla_host_t *vha)
Andrew Vasquezcca53352005-08-26 19:08:30 -07001528{
1529 int rval, alen;
1530 uint32_t size, sn;
1531
1532 ms_iocb_entry_t *ms_pkt;
1533 struct ct_sns_req *ct_req;
1534 struct ct_sns_rsp *ct_rsp;
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04001535 void *entries;
Andrew Vasquezcca53352005-08-26 19:08:30 -07001536 struct ct_fdmi_hba_attr *eiter;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001537 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezcca53352005-08-26 19:08:30 -07001538
1539 /* Issue RHBA */
1540 /* Prepare common MS IOCB */
1541 /* Request size adjusted after CT preparation */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001542 ms_pkt = ha->isp_ops->prep_ms_fdmi_iocb(vha, 0, RHBA_RSP_SIZE);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001543
1544 /* Prepare CT request */
Bart Van Assche6ec6f902013-06-25 11:27:28 -04001545 ct_req = qla2x00_prep_ct_fdmi_req(ha->ct_sns, RHBA_CMD, RHBA_RSP_SIZE);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001546 ct_rsp = &ha->ct_sns->p.rsp;
1547
1548 /* Prepare FDMI command arguments -- attribute block, attributes. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001549 memcpy(ct_req->req.rhba.hba_identifier, vha->port_name, WWN_SIZE);
Bart Van Asschead950362015-07-09 07:24:08 -07001550 ct_req->req.rhba.entry_count = cpu_to_be32(1);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001551 memcpy(ct_req->req.rhba.port_name, vha->port_name, WWN_SIZE);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001552 size = 2 * WWN_SIZE + 4 + 4;
1553
1554 /* Attributes */
1555 ct_req->req.rhba.attrs.count =
Bart Van Asschead950362015-07-09 07:24:08 -07001556 cpu_to_be32(FDMI_HBA_ATTR_COUNT);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001557 entries = ct_req->req.rhba.hba_identifier;
1558
1559 /* Nodename. */
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04001560 eiter = entries + size;
Bart Van Asschead950362015-07-09 07:24:08 -07001561 eiter->type = cpu_to_be16(FDMI_HBA_NODE_NAME);
1562 eiter->len = cpu_to_be16(4 + WWN_SIZE);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001563 memcpy(eiter->a.node_name, vha->node_name, WWN_SIZE);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001564 size += 4 + WWN_SIZE;
1565
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001566 ql_dbg(ql_dbg_disc, vha, 0x2025,
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -04001567 "NodeName = %8phN.\n", eiter->a.node_name);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001568
1569 /* Manufacturer. */
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04001570 eiter = entries + size;
Bart Van Asschead950362015-07-09 07:24:08 -07001571 eiter->type = cpu_to_be16(FDMI_HBA_MANUFACTURER);
Paul Bollef24b6972013-02-08 01:57:55 -05001572 alen = strlen(QLA2XXX_MANUFACTURER);
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04001573 snprintf(eiter->a.manufacturer, sizeof(eiter->a.manufacturer),
1574 "%s", "QLogic Corporation");
1575 alen += 4 - (alen & 3);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001576 eiter->len = cpu_to_be16(4 + alen);
1577 size += 4 + alen;
1578
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001579 ql_dbg(ql_dbg_disc, vha, 0x2026,
1580 "Manufacturer = %s.\n", eiter->a.manufacturer);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001581
1582 /* Serial number. */
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04001583 eiter = entries + size;
Bart Van Asschead950362015-07-09 07:24:08 -07001584 eiter->type = cpu_to_be16(FDMI_HBA_SERIAL_NUMBER);
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04001585 if (IS_FWI2_CAPABLE(ha))
1586 qla2xxx_get_vpd_field(vha, "SN", eiter->a.serial_num,
1587 sizeof(eiter->a.serial_num));
1588 else {
1589 sn = ((ha->serial0 & 0x1f) << 16) |
1590 (ha->serial2 << 8) | ha->serial1;
1591 snprintf(eiter->a.serial_num, sizeof(eiter->a.serial_num),
1592 "%c%05d", 'A' + sn / 100000, sn % 100000);
1593 }
Andrew Vasquezcca53352005-08-26 19:08:30 -07001594 alen = strlen(eiter->a.serial_num);
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04001595 alen += 4 - (alen & 3);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001596 eiter->len = cpu_to_be16(4 + alen);
1597 size += 4 + alen;
1598
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001599 ql_dbg(ql_dbg_disc, vha, 0x2027,
1600 "Serial no. = %s.\n", eiter->a.serial_num);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001601
1602 /* Model name. */
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04001603 eiter = entries + size;
Bart Van Asschead950362015-07-09 07:24:08 -07001604 eiter->type = cpu_to_be16(FDMI_HBA_MODEL);
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04001605 snprintf(eiter->a.model, sizeof(eiter->a.model),
1606 "%s", ha->model_number);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001607 alen = strlen(eiter->a.model);
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04001608 alen += 4 - (alen & 3);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001609 eiter->len = cpu_to_be16(4 + alen);
1610 size += 4 + alen;
1611
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001612 ql_dbg(ql_dbg_disc, vha, 0x2028,
1613 "Model Name = %s.\n", eiter->a.model);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001614
1615 /* Model description. */
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04001616 eiter = entries + size;
Bart Van Asschead950362015-07-09 07:24:08 -07001617 eiter->type = cpu_to_be16(FDMI_HBA_MODEL_DESCRIPTION);
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04001618 snprintf(eiter->a.model_desc, sizeof(eiter->a.model_desc),
1619 "%s", ha->model_desc);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001620 alen = strlen(eiter->a.model_desc);
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04001621 alen += 4 - (alen & 3);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001622 eiter->len = cpu_to_be16(4 + alen);
1623 size += 4 + alen;
1624
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001625 ql_dbg(ql_dbg_disc, vha, 0x2029,
1626 "Model Desc = %s.\n", eiter->a.model_desc);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001627
1628 /* Hardware version. */
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04001629 eiter = entries + size;
Bart Van Asschead950362015-07-09 07:24:08 -07001630 eiter->type = cpu_to_be16(FDMI_HBA_HARDWARE_VERSION);
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04001631 if (!IS_FWI2_CAPABLE(ha)) {
1632 snprintf(eiter->a.hw_version, sizeof(eiter->a.hw_version),
1633 "HW:%s", ha->adapter_id);
1634 } else if (qla2xxx_get_vpd_field(vha, "MN", eiter->a.hw_version,
1635 sizeof(eiter->a.hw_version))) {
1636 ;
1637 } else if (qla2xxx_get_vpd_field(vha, "EC", eiter->a.hw_version,
1638 sizeof(eiter->a.hw_version))) {
1639 ;
1640 } else {
1641 snprintf(eiter->a.hw_version, sizeof(eiter->a.hw_version),
1642 "HW:%s", ha->adapter_id);
1643 }
Andrew Vasquezcca53352005-08-26 19:08:30 -07001644 alen = strlen(eiter->a.hw_version);
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04001645 alen += 4 - (alen & 3);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001646 eiter->len = cpu_to_be16(4 + alen);
1647 size += 4 + alen;
1648
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001649 ql_dbg(ql_dbg_disc, vha, 0x202a,
1650 "Hardware ver = %s.\n", eiter->a.hw_version);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001651
1652 /* Driver version. */
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04001653 eiter = entries + size;
Bart Van Asschead950362015-07-09 07:24:08 -07001654 eiter->type = cpu_to_be16(FDMI_HBA_DRIVER_VERSION);
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04001655 snprintf(eiter->a.driver_version, sizeof(eiter->a.driver_version),
1656 "%s", qla2x00_version_str);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001657 alen = strlen(eiter->a.driver_version);
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04001658 alen += 4 - (alen & 3);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001659 eiter->len = cpu_to_be16(4 + alen);
1660 size += 4 + alen;
1661
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001662 ql_dbg(ql_dbg_disc, vha, 0x202b,
1663 "Driver ver = %s.\n", eiter->a.driver_version);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001664
1665 /* Option ROM version. */
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04001666 eiter = entries + size;
Bart Van Asschead950362015-07-09 07:24:08 -07001667 eiter->type = cpu_to_be16(FDMI_HBA_OPTION_ROM_VERSION);
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04001668 snprintf(eiter->a.orom_version, sizeof(eiter->a.orom_version),
1669 "%d.%02d", ha->bios_revision[1], ha->bios_revision[0]);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001670 alen = strlen(eiter->a.orom_version);
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04001671 alen += 4 - (alen & 3);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001672 eiter->len = cpu_to_be16(4 + alen);
1673 size += 4 + alen;
1674
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001675 ql_dbg(ql_dbg_disc, vha , 0x202c,
1676 "Optrom vers = %s.\n", eiter->a.orom_version);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001677
1678 /* Firmware version */
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04001679 eiter = entries + size;
Bart Van Asschead950362015-07-09 07:24:08 -07001680 eiter->type = cpu_to_be16(FDMI_HBA_FIRMWARE_VERSION);
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04001681 ha->isp_ops->fw_version_str(vha, eiter->a.fw_version,
1682 sizeof(eiter->a.fw_version));
Andrew Vasquezcca53352005-08-26 19:08:30 -07001683 alen = strlen(eiter->a.fw_version);
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04001684 alen += 4 - (alen & 3);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001685 eiter->len = cpu_to_be16(4 + alen);
1686 size += 4 + alen;
1687
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001688 ql_dbg(ql_dbg_disc, vha, 0x202d,
1689 "Firmware vers = %s.\n", eiter->a.fw_version);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001690
1691 /* Update MS request size. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001692 qla2x00_update_ms_fdmi_iocb(vha, size + 16);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001693
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001694 ql_dbg(ql_dbg_disc, vha, 0x202e,
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -04001695 "RHBA identifier = %8phN size=%d.\n",
1696 ct_req->req.rhba.hba_identifier, size);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001697 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2076,
1698 entries, size);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001699
1700 /* Execute MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001701 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
Andrew Vasquezcca53352005-08-26 19:08:30 -07001702 sizeof(ms_iocb_entry_t));
1703 if (rval != QLA_SUCCESS) {
1704 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001705 ql_dbg(ql_dbg_disc, vha, 0x2030,
1706 "RHBA issue IOCB failed (%d).\n", rval);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001707 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, "RHBA") !=
Andrew Vasquezcca53352005-08-26 19:08:30 -07001708 QLA_SUCCESS) {
1709 rval = QLA_FUNCTION_FAILED;
1710 if (ct_rsp->header.reason_code == CT_REASON_CANNOT_PERFORM &&
1711 ct_rsp->header.explanation_code ==
1712 CT_EXPL_ALREADY_REGISTERED) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001713 ql_dbg(ql_dbg_disc, vha, 0x2034,
1714 "HBA already registered.\n");
Andrew Vasquezcca53352005-08-26 19:08:30 -07001715 rval = QLA_ALREADY_REGISTERED;
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04001716 } else {
1717 ql_dbg(ql_dbg_disc, vha, 0x20ad,
1718 "RHBA FDMI registration failed, CT Reason code: 0x%x, CT Explanation 0x%x\n",
1719 ct_rsp->header.reason_code,
1720 ct_rsp->header.explanation_code);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001721 }
1722 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001723 ql_dbg(ql_dbg_disc, vha, 0x2035,
1724 "RHBA exiting normally.\n");
Andrew Vasquezcca53352005-08-26 19:08:30 -07001725 }
1726
1727 return rval;
1728}
1729
1730/**
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04001731 * qla2x00_fdmi_rpa() -
1732 * @ha: HA context
1733 *
1734 * Returns 0 on success.
1735 */
1736static int
1737qla2x00_fdmi_rpa(scsi_qla_host_t *vha)
1738{
1739 int rval, alen;
1740 uint32_t size;
1741 struct qla_hw_data *ha = vha->hw;
1742 ms_iocb_entry_t *ms_pkt;
1743 struct ct_sns_req *ct_req;
1744 struct ct_sns_rsp *ct_rsp;
1745 void *entries;
1746 struct ct_fdmi_port_attr *eiter;
1747 struct init_cb_24xx *icb24 = (struct init_cb_24xx *)ha->init_cb;
1748 struct new_utsname *p_sysid = NULL;
1749
1750 /* Issue RPA */
1751 /* Prepare common MS IOCB */
1752 /* Request size adjusted after CT preparation */
1753 ms_pkt = ha->isp_ops->prep_ms_fdmi_iocb(vha, 0, RPA_RSP_SIZE);
1754
1755 /* Prepare CT request */
1756 ct_req = qla2x00_prep_ct_fdmi_req(ha->ct_sns, RPA_CMD,
1757 RPA_RSP_SIZE);
1758 ct_rsp = &ha->ct_sns->p.rsp;
1759
1760 /* Prepare FDMI command arguments -- attribute block, attributes. */
1761 memcpy(ct_req->req.rpa.port_name, vha->port_name, WWN_SIZE);
1762 size = WWN_SIZE + 4;
1763
1764 /* Attributes */
1765 ct_req->req.rpa.attrs.count = cpu_to_be32(FDMI_PORT_ATTR_COUNT);
1766 entries = ct_req->req.rpa.port_name;
1767
1768 /* FC4 types. */
1769 eiter = entries + size;
1770 eiter->type = cpu_to_be16(FDMI_PORT_FC4_TYPES);
1771 eiter->len = cpu_to_be16(4 + 32);
1772 eiter->a.fc4_types[2] = 0x01;
1773 size += 4 + 32;
1774
1775 ql_dbg(ql_dbg_disc, vha, 0x2039,
1776 "FC4_TYPES=%02x %02x.\n",
1777 eiter->a.fc4_types[2],
1778 eiter->a.fc4_types[1]);
1779
1780 /* Supported speed. */
1781 eiter = entries + size;
1782 eiter->type = cpu_to_be16(FDMI_PORT_SUPPORT_SPEED);
1783 eiter->len = cpu_to_be16(4 + 4);
1784 if (IS_CNA_CAPABLE(ha))
1785 eiter->a.sup_speed = cpu_to_be32(
1786 FDMI_PORT_SPEED_10GB);
1787 else if (IS_QLA27XX(ha))
1788 eiter->a.sup_speed = cpu_to_be32(
1789 FDMI_PORT_SPEED_32GB|
1790 FDMI_PORT_SPEED_16GB|
1791 FDMI_PORT_SPEED_8GB);
1792 else if (IS_QLA2031(ha))
1793 eiter->a.sup_speed = cpu_to_be32(
1794 FDMI_PORT_SPEED_16GB|
1795 FDMI_PORT_SPEED_8GB|
1796 FDMI_PORT_SPEED_4GB);
1797 else if (IS_QLA25XX(ha))
1798 eiter->a.sup_speed = cpu_to_be32(
1799 FDMI_PORT_SPEED_8GB|
1800 FDMI_PORT_SPEED_4GB|
1801 FDMI_PORT_SPEED_2GB|
1802 FDMI_PORT_SPEED_1GB);
1803 else if (IS_QLA24XX_TYPE(ha))
1804 eiter->a.sup_speed = cpu_to_be32(
1805 FDMI_PORT_SPEED_4GB|
1806 FDMI_PORT_SPEED_2GB|
1807 FDMI_PORT_SPEED_1GB);
1808 else if (IS_QLA23XX(ha))
1809 eiter->a.sup_speed = cpu_to_be32(
1810 FDMI_PORT_SPEED_2GB|
1811 FDMI_PORT_SPEED_1GB);
1812 else
1813 eiter->a.sup_speed = cpu_to_be32(
1814 FDMI_PORT_SPEED_1GB);
1815 size += 4 + 4;
1816
1817 ql_dbg(ql_dbg_disc, vha, 0x203a,
1818 "Supported_Speed=%x.\n", eiter->a.sup_speed);
1819
1820 /* Current speed. */
1821 eiter = entries + size;
1822 eiter->type = cpu_to_be16(FDMI_PORT_CURRENT_SPEED);
1823 eiter->len = cpu_to_be16(4 + 4);
1824 switch (ha->link_data_rate) {
1825 case PORT_SPEED_1GB:
1826 eiter->a.cur_speed =
1827 cpu_to_be32(FDMI_PORT_SPEED_1GB);
1828 break;
1829 case PORT_SPEED_2GB:
1830 eiter->a.cur_speed =
1831 cpu_to_be32(FDMI_PORT_SPEED_2GB);
1832 break;
1833 case PORT_SPEED_4GB:
1834 eiter->a.cur_speed =
1835 cpu_to_be32(FDMI_PORT_SPEED_4GB);
1836 break;
1837 case PORT_SPEED_8GB:
1838 eiter->a.cur_speed =
1839 cpu_to_be32(FDMI_PORT_SPEED_8GB);
1840 break;
1841 case PORT_SPEED_10GB:
1842 eiter->a.cur_speed =
1843 cpu_to_be32(FDMI_PORT_SPEED_10GB);
1844 break;
1845 case PORT_SPEED_16GB:
1846 eiter->a.cur_speed =
1847 cpu_to_be32(FDMI_PORT_SPEED_16GB);
1848 break;
1849 case PORT_SPEED_32GB:
1850 eiter->a.cur_speed =
1851 cpu_to_be32(FDMI_PORT_SPEED_32GB);
1852 break;
1853 default:
1854 eiter->a.cur_speed =
1855 cpu_to_be32(FDMI_PORT_SPEED_UNKNOWN);
1856 break;
1857 }
1858 size += 4 + 4;
1859
1860 ql_dbg(ql_dbg_disc, vha, 0x203b,
1861 "Current_Speed=%x.\n", eiter->a.cur_speed);
1862
1863 /* Max frame size. */
1864 eiter = entries + size;
1865 eiter->type = cpu_to_be16(FDMI_PORT_MAX_FRAME_SIZE);
1866 eiter->len = cpu_to_be16(4 + 4);
1867 eiter->a.max_frame_size = IS_FWI2_CAPABLE(ha) ?
1868 le16_to_cpu(icb24->frame_payload_size) :
1869 le16_to_cpu(ha->init_cb->frame_payload_size);
1870 eiter->a.max_frame_size = cpu_to_be32(eiter->a.max_frame_size);
1871 size += 4 + 4;
1872
1873 ql_dbg(ql_dbg_disc, vha, 0x203c,
1874 "Max_Frame_Size=%x.\n", eiter->a.max_frame_size);
1875
1876 /* OS device name. */
1877 eiter = entries + size;
1878 eiter->type = cpu_to_be16(FDMI_PORT_OS_DEVICE_NAME);
1879 snprintf(eiter->a.os_dev_name, sizeof(eiter->a.os_dev_name),
1880 "%s:host%lu", QLA2XXX_DRIVER_NAME, vha->host_no);
1881 alen = strlen(eiter->a.os_dev_name);
1882 alen += 4 - (alen & 3);
1883 eiter->len = cpu_to_be16(4 + alen);
1884 size += 4 + alen;
1885
1886 ql_dbg(ql_dbg_disc, vha, 0x204b,
1887 "OS_Device_Name=%s.\n", eiter->a.os_dev_name);
1888
1889 /* Hostname. */
1890 eiter = entries + size;
1891 eiter->type = cpu_to_be16(FDMI_PORT_HOST_NAME);
1892 p_sysid = utsname();
1893 if (p_sysid) {
1894 snprintf(eiter->a.host_name, sizeof(eiter->a.host_name),
1895 "%s", p_sysid->nodename);
1896 } else {
1897 snprintf(eiter->a.host_name, sizeof(eiter->a.host_name),
1898 "%s", fc_host_system_hostname(vha->host));
1899 }
1900 alen = strlen(eiter->a.host_name);
1901 alen += 4 - (alen & 3);
1902 eiter->len = cpu_to_be16(4 + alen);
1903 size += 4 + alen;
1904
1905 ql_dbg(ql_dbg_disc, vha, 0x203d, "HostName=%s.\n", eiter->a.host_name);
1906
1907 /* Update MS request size. */
1908 qla2x00_update_ms_fdmi_iocb(vha, size + 16);
1909
1910 ql_dbg(ql_dbg_disc, vha, 0x203e,
1911 "RPA portname %016llx, size = %d.\n",
1912 wwn_to_u64(ct_req->req.rpa.port_name), size);
1913 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2079,
1914 entries, size);
1915
1916 /* Execute MS IOCB */
1917 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
1918 sizeof(ms_iocb_entry_t));
1919 if (rval != QLA_SUCCESS) {
1920 /*EMPTY*/
1921 ql_dbg(ql_dbg_disc, vha, 0x2040,
1922 "RPA issue IOCB failed (%d).\n", rval);
1923 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, "RPA") !=
1924 QLA_SUCCESS) {
1925 rval = QLA_FUNCTION_FAILED;
1926 if (ct_rsp->header.reason_code == CT_REASON_CANNOT_PERFORM &&
1927 ct_rsp->header.explanation_code ==
1928 CT_EXPL_ALREADY_REGISTERED) {
1929 ql_dbg(ql_dbg_disc, vha, 0x20cd,
1930 "RPA already registered.\n");
1931 rval = QLA_ALREADY_REGISTERED;
1932 }
1933
1934 } else {
1935 ql_dbg(ql_dbg_disc, vha, 0x2041,
1936 "RPA exiting normally.\n");
1937 }
1938
1939 return rval;
1940}
1941
1942/**
1943 * qla2x00_fdmiv2_rhba() -
1944 * @ha: HA context
1945 *
1946 * Returns 0 on success.
1947 */
1948static int
1949qla2x00_fdmiv2_rhba(scsi_qla_host_t *vha)
1950{
1951 int rval, alen;
1952 uint32_t size, sn;
1953 ms_iocb_entry_t *ms_pkt;
1954 struct ct_sns_req *ct_req;
1955 struct ct_sns_rsp *ct_rsp;
1956 void *entries;
1957 struct ct_fdmiv2_hba_attr *eiter;
1958 struct qla_hw_data *ha = vha->hw;
1959 struct init_cb_24xx *icb24 = (struct init_cb_24xx *)ha->init_cb;
1960 struct new_utsname *p_sysid = NULL;
1961
1962 /* Issue RHBA */
1963 /* Prepare common MS IOCB */
1964 /* Request size adjusted after CT preparation */
1965 ms_pkt = ha->isp_ops->prep_ms_fdmi_iocb(vha, 0, RHBA_RSP_SIZE);
1966
1967 /* Prepare CT request */
1968 ct_req = qla2x00_prep_ct_fdmi_req(ha->ct_sns, RHBA_CMD,
1969 RHBA_RSP_SIZE);
1970 ct_rsp = &ha->ct_sns->p.rsp;
1971
1972 /* Prepare FDMI command arguments -- attribute block, attributes. */
1973 memcpy(ct_req->req.rhba2.hba_identifier, vha->port_name, WWN_SIZE);
1974 ct_req->req.rhba2.entry_count = cpu_to_be32(1);
1975 memcpy(ct_req->req.rhba2.port_name, vha->port_name, WWN_SIZE);
1976 size = 2 * WWN_SIZE + 4 + 4;
1977
1978 /* Attributes */
1979 ct_req->req.rhba2.attrs.count = cpu_to_be32(FDMIV2_HBA_ATTR_COUNT);
1980 entries = ct_req->req.rhba2.hba_identifier;
1981
1982 /* Nodename. */
1983 eiter = entries + size;
1984 eiter->type = cpu_to_be16(FDMI_HBA_NODE_NAME);
1985 eiter->len = cpu_to_be16(4 + WWN_SIZE);
1986 memcpy(eiter->a.node_name, vha->node_name, WWN_SIZE);
1987 size += 4 + WWN_SIZE;
1988
1989 ql_dbg(ql_dbg_disc, vha, 0x207d,
1990 "NodeName = %016llx.\n", wwn_to_u64(eiter->a.node_name));
1991
1992 /* Manufacturer. */
1993 eiter = entries + size;
1994 eiter->type = cpu_to_be16(FDMI_HBA_MANUFACTURER);
1995 snprintf(eiter->a.manufacturer, sizeof(eiter->a.manufacturer),
1996 "%s", "QLogic Corporation");
1997 eiter->a.manufacturer[strlen("QLogic Corporation")] = '\0';
1998 alen = strlen(eiter->a.manufacturer);
1999 alen += 4 - (alen & 3);
2000 eiter->len = cpu_to_be16(4 + alen);
2001 size += 4 + alen;
2002
2003 ql_dbg(ql_dbg_disc, vha, 0x20a5,
2004 "Manufacturer = %s.\n", eiter->a.manufacturer);
2005
2006 /* Serial number. */
2007 eiter = entries + size;
2008 eiter->type = cpu_to_be16(FDMI_HBA_SERIAL_NUMBER);
2009 if (IS_FWI2_CAPABLE(ha))
2010 qla2xxx_get_vpd_field(vha, "SN", eiter->a.serial_num,
2011 sizeof(eiter->a.serial_num));
2012 else {
2013 sn = ((ha->serial0 & 0x1f) << 16) |
2014 (ha->serial2 << 8) | ha->serial1;
2015 snprintf(eiter->a.serial_num, sizeof(eiter->a.serial_num),
2016 "%c%05d", 'A' + sn / 100000, sn % 100000);
2017 }
2018 alen = strlen(eiter->a.serial_num);
2019 alen += 4 - (alen & 3);
2020 eiter->len = cpu_to_be16(4 + alen);
2021 size += 4 + alen;
2022
2023 ql_dbg(ql_dbg_disc, vha, 0x20a6,
2024 "Serial no. = %s.\n", eiter->a.serial_num);
2025
2026 /* Model name. */
2027 eiter = entries + size;
2028 eiter->type = cpu_to_be16(FDMI_HBA_MODEL);
2029 snprintf(eiter->a.model, sizeof(eiter->a.model),
2030 "%s", ha->model_number);
2031 alen = strlen(eiter->a.model);
2032 alen += 4 - (alen & 3);
2033 eiter->len = cpu_to_be16(4 + alen);
2034 size += 4 + alen;
2035
2036 ql_dbg(ql_dbg_disc, vha, 0x20a7,
2037 "Model Name = %s.\n", eiter->a.model);
2038
2039 /* Model description. */
2040 eiter = entries + size;
2041 eiter->type = cpu_to_be16(FDMI_HBA_MODEL_DESCRIPTION);
2042 snprintf(eiter->a.model_desc, sizeof(eiter->a.model_desc),
2043 "%s", ha->model_desc);
2044 alen = strlen(eiter->a.model_desc);
2045 alen += 4 - (alen & 3);
2046 eiter->len = cpu_to_be16(4 + alen);
2047 size += 4 + alen;
2048
2049 ql_dbg(ql_dbg_disc, vha, 0x20a8,
2050 "Model Desc = %s.\n", eiter->a.model_desc);
2051
2052 /* Hardware version. */
2053 eiter = entries + size;
2054 eiter->type = cpu_to_be16(FDMI_HBA_HARDWARE_VERSION);
2055 if (!IS_FWI2_CAPABLE(ha)) {
2056 snprintf(eiter->a.hw_version, sizeof(eiter->a.hw_version),
2057 "HW:%s", ha->adapter_id);
2058 } else if (qla2xxx_get_vpd_field(vha, "MN", eiter->a.hw_version,
2059 sizeof(eiter->a.hw_version))) {
2060 ;
2061 } else if (qla2xxx_get_vpd_field(vha, "EC", eiter->a.hw_version,
2062 sizeof(eiter->a.hw_version))) {
2063 ;
2064 } else {
2065 snprintf(eiter->a.hw_version, sizeof(eiter->a.hw_version),
2066 "HW:%s", ha->adapter_id);
2067 }
2068 alen = strlen(eiter->a.hw_version);
2069 alen += 4 - (alen & 3);
2070 eiter->len = cpu_to_be16(4 + alen);
2071 size += 4 + alen;
2072
2073 ql_dbg(ql_dbg_disc, vha, 0x20a9,
2074 "Hardware ver = %s.\n", eiter->a.hw_version);
2075
2076 /* Driver version. */
2077 eiter = entries + size;
2078 eiter->type = cpu_to_be16(FDMI_HBA_DRIVER_VERSION);
2079 snprintf(eiter->a.driver_version, sizeof(eiter->a.driver_version),
2080 "%s", qla2x00_version_str);
2081 alen = strlen(eiter->a.driver_version);
2082 alen += 4 - (alen & 3);
2083 eiter->len = cpu_to_be16(4 + alen);
2084 size += 4 + alen;
2085
2086 ql_dbg(ql_dbg_disc, vha, 0x20aa,
2087 "Driver ver = %s.\n", eiter->a.driver_version);
2088
2089 /* Option ROM version. */
2090 eiter = entries + size;
2091 eiter->type = cpu_to_be16(FDMI_HBA_OPTION_ROM_VERSION);
2092 snprintf(eiter->a.orom_version, sizeof(eiter->a.orom_version),
2093 "%d.%02d", ha->bios_revision[1], ha->bios_revision[0]);
2094 alen = strlen(eiter->a.orom_version);
2095 alen += 4 - (alen & 3);
2096 eiter->len = cpu_to_be16(4 + alen);
2097 size += 4 + alen;
2098
2099 ql_dbg(ql_dbg_disc, vha , 0x20ab,
2100 "Optrom version = %d.%02d.\n", eiter->a.orom_version[1],
2101 eiter->a.orom_version[0]);
2102
2103 /* Firmware version */
2104 eiter = entries + size;
2105 eiter->type = cpu_to_be16(FDMI_HBA_FIRMWARE_VERSION);
2106 ha->isp_ops->fw_version_str(vha, eiter->a.fw_version,
2107 sizeof(eiter->a.fw_version));
2108 alen = strlen(eiter->a.fw_version);
2109 alen += 4 - (alen & 3);
2110 eiter->len = cpu_to_be16(4 + alen);
2111 size += 4 + alen;
2112
2113 ql_dbg(ql_dbg_disc, vha, 0x20ac,
2114 "Firmware vers = %s.\n", eiter->a.fw_version);
2115
2116 /* OS Name and Version */
2117 eiter = entries + size;
2118 eiter->type = cpu_to_be16(FDMI_HBA_OS_NAME_AND_VERSION);
2119 p_sysid = utsname();
2120 if (p_sysid) {
2121 snprintf(eiter->a.os_version, sizeof(eiter->a.os_version),
2122 "%s %s %s",
2123 p_sysid->sysname, p_sysid->release, p_sysid->version);
2124 } else {
2125 snprintf(eiter->a.os_version, sizeof(eiter->a.os_version),
2126 "%s %s", "Linux", fc_host_system_hostname(vha->host));
2127 }
2128 alen = strlen(eiter->a.os_version);
2129 alen += 4 - (alen & 3);
2130 eiter->len = cpu_to_be16(4 + alen);
2131 size += 4 + alen;
2132
2133 ql_dbg(ql_dbg_disc, vha, 0x20ae,
2134 "OS Name and Version = %s.\n", eiter->a.os_version);
2135
2136 /* MAX CT Payload Length */
2137 eiter = entries + size;
2138 eiter->type = cpu_to_be16(FDMI_HBA_MAXIMUM_CT_PAYLOAD_LENGTH);
2139 eiter->a.max_ct_len = IS_FWI2_CAPABLE(ha) ?
2140 le16_to_cpu(icb24->frame_payload_size) :
2141 le16_to_cpu(ha->init_cb->frame_payload_size);
2142 eiter->a.max_ct_len = cpu_to_be32(eiter->a.max_ct_len);
2143 eiter->len = cpu_to_be16(4 + 4);
2144 size += 4 + 4;
2145
2146 ql_dbg(ql_dbg_disc, vha, 0x20af,
2147 "CT Payload Length = 0x%x.\n", eiter->a.max_ct_len);
2148
2149 /* Node Sybolic Name */
2150 eiter = entries + size;
2151 eiter->type = cpu_to_be16(FDMI_HBA_NODE_SYMBOLIC_NAME);
2152 qla2x00_get_sym_node_name(vha, eiter->a.sym_name,
2153 sizeof(eiter->a.sym_name));
2154 alen = strlen(eiter->a.sym_name);
2155 alen += 4 - (alen & 3);
2156 eiter->len = cpu_to_be16(4 + alen);
2157 size += 4 + alen;
2158
2159 ql_dbg(ql_dbg_disc, vha, 0x20b0,
2160 "Symbolic Name = %s.\n", eiter->a.sym_name);
2161
2162 /* Vendor Id */
2163 eiter = entries + size;
2164 eiter->type = cpu_to_be16(FDMI_HBA_VENDOR_ID);
2165 eiter->a.vendor_id = cpu_to_be32(0x1077);
2166 eiter->len = cpu_to_be16(4 + 4);
2167 size += 4 + 4;
2168
2169 ql_dbg(ql_dbg_disc, vha, 0x20b1,
2170 "Vendor Id = %x.\n", eiter->a.vendor_id);
2171
2172 /* Num Ports */
2173 eiter = entries + size;
2174 eiter->type = cpu_to_be16(FDMI_HBA_NUM_PORTS);
2175 eiter->a.num_ports = cpu_to_be32(1);
2176 eiter->len = cpu_to_be16(4 + 4);
2177 size += 4 + 4;
2178
2179 ql_dbg(ql_dbg_disc, vha, 0x20b2,
2180 "Port Num = %x.\n", eiter->a.num_ports);
2181
2182 /* Fabric Name */
2183 eiter = entries + size;
2184 eiter->type = cpu_to_be16(FDMI_HBA_FABRIC_NAME);
2185 memcpy(eiter->a.fabric_name, vha->fabric_node_name, WWN_SIZE);
2186 eiter->len = cpu_to_be16(4 + WWN_SIZE);
2187 size += 4 + WWN_SIZE;
2188
2189 ql_dbg(ql_dbg_disc, vha, 0x20b3,
2190 "Fabric Name = %016llx.\n", wwn_to_u64(eiter->a.fabric_name));
2191
2192 /* BIOS Version */
2193 eiter = entries + size;
2194 eiter->type = cpu_to_be16(FDMI_HBA_BOOT_BIOS_NAME);
2195 snprintf(eiter->a.bios_name, sizeof(eiter->a.bios_name),
2196 "BIOS %d.%02d", ha->bios_revision[1], ha->bios_revision[0]);
2197 alen = strlen(eiter->a.bios_name);
2198 alen += 4 - (alen & 3);
2199 eiter->len = cpu_to_be16(4 + alen);
2200 size += 4 + alen;
2201
2202 ql_dbg(ql_dbg_disc, vha, 0x20b4,
2203 "BIOS Name = %s\n", eiter->a.bios_name);
2204
2205 /* Vendor Identifier */
2206 eiter = entries + size;
2207 eiter->type = cpu_to_be16(FDMI_HBA_TYPE_VENDOR_IDENTIFIER);
Colin Ian King577419f2016-12-29 22:20:38 +00002208 snprintf(eiter->a.vendor_identifier, sizeof(eiter->a.vendor_identifier),
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002209 "%s", "QLGC");
Colin Ian King577419f2016-12-29 22:20:38 +00002210 alen = strlen(eiter->a.vendor_identifier);
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002211 alen += 4 - (alen & 3);
2212 eiter->len = cpu_to_be16(4 + alen);
2213 size += 4 + alen;
2214
Quinn Tran83548fe2017-06-02 09:12:01 -07002215 ql_dbg(ql_dbg_disc, vha, 0x201b,
Colin Ian King577419f2016-12-29 22:20:38 +00002216 "Vendor Identifier = %s.\n", eiter->a.vendor_identifier);
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002217
2218 /* Update MS request size. */
2219 qla2x00_update_ms_fdmi_iocb(vha, size + 16);
2220
2221 ql_dbg(ql_dbg_disc, vha, 0x20b5,
2222 "RHBA identifier = %016llx.\n",
2223 wwn_to_u64(ct_req->req.rhba2.hba_identifier));
2224 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x20b6,
2225 entries, size);
2226
2227 /* Execute MS IOCB */
2228 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
2229 sizeof(ms_iocb_entry_t));
2230 if (rval != QLA_SUCCESS) {
2231 /*EMPTY*/
2232 ql_dbg(ql_dbg_disc, vha, 0x20b7,
2233 "RHBA issue IOCB failed (%d).\n", rval);
2234 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, "RHBA") !=
2235 QLA_SUCCESS) {
2236 rval = QLA_FUNCTION_FAILED;
2237
2238 if (ct_rsp->header.reason_code == CT_REASON_CANNOT_PERFORM &&
2239 ct_rsp->header.explanation_code ==
2240 CT_EXPL_ALREADY_REGISTERED) {
2241 ql_dbg(ql_dbg_disc, vha, 0x20b8,
2242 "HBA already registered.\n");
2243 rval = QLA_ALREADY_REGISTERED;
2244 } else {
2245 ql_dbg(ql_dbg_disc, vha, 0x2016,
2246 "RHBA FDMI v2 failed, CT Reason code: 0x%x, CT Explanation 0x%x\n",
2247 ct_rsp->header.reason_code,
2248 ct_rsp->header.explanation_code);
2249 }
2250 } else {
2251 ql_dbg(ql_dbg_disc, vha, 0x20b9,
2252 "RHBA FDMI V2 exiting normally.\n");
2253 }
2254
2255 return rval;
2256}
2257
2258/**
Andrew Vasquezcca53352005-08-26 19:08:30 -07002259 * qla2x00_fdmi_dhba() -
2260 * @ha: HA context
2261 *
2262 * Returns 0 on success.
2263 */
2264static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002265qla2x00_fdmi_dhba(scsi_qla_host_t *vha)
Andrew Vasquezcca53352005-08-26 19:08:30 -07002266{
2267 int rval;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002268 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezcca53352005-08-26 19:08:30 -07002269 ms_iocb_entry_t *ms_pkt;
2270 struct ct_sns_req *ct_req;
2271 struct ct_sns_rsp *ct_rsp;
2272
2273 /* Issue RPA */
2274 /* Prepare common MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002275 ms_pkt = ha->isp_ops->prep_ms_fdmi_iocb(vha, DHBA_REQ_SIZE,
Andrew Vasquezcca53352005-08-26 19:08:30 -07002276 DHBA_RSP_SIZE);
2277
2278 /* Prepare CT request */
Bart Van Assche6ec6f902013-06-25 11:27:28 -04002279 ct_req = qla2x00_prep_ct_fdmi_req(ha->ct_sns, DHBA_CMD, DHBA_RSP_SIZE);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002280 ct_rsp = &ha->ct_sns->p.rsp;
2281
2282 /* Prepare FDMI command arguments -- portname. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002283 memcpy(ct_req->req.dhba.port_name, vha->port_name, WWN_SIZE);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002284
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002285 ql_dbg(ql_dbg_disc, vha, 0x2036,
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -04002286 "DHBA portname = %8phN.\n", ct_req->req.dhba.port_name);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002287
2288 /* Execute MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002289 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
Andrew Vasquezcca53352005-08-26 19:08:30 -07002290 sizeof(ms_iocb_entry_t));
2291 if (rval != QLA_SUCCESS) {
2292 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002293 ql_dbg(ql_dbg_disc, vha, 0x2037,
2294 "DHBA issue IOCB failed (%d).\n", rval);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002295 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, "DHBA") !=
Andrew Vasquezcca53352005-08-26 19:08:30 -07002296 QLA_SUCCESS) {
2297 rval = QLA_FUNCTION_FAILED;
2298 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002299 ql_dbg(ql_dbg_disc, vha, 0x2038,
2300 "DHBA exiting normally.\n");
Andrew Vasquezcca53352005-08-26 19:08:30 -07002301 }
2302
2303 return rval;
2304}
2305
2306/**
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002307 * qla2x00_fdmiv2_rpa() -
Andrew Vasquezcca53352005-08-26 19:08:30 -07002308 * @ha: HA context
2309 *
2310 * Returns 0 on success.
2311 */
2312static int
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002313qla2x00_fdmiv2_rpa(scsi_qla_host_t *vha)
Andrew Vasquezcca53352005-08-26 19:08:30 -07002314{
2315 int rval, alen;
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002316 uint32_t size;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002317 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezcca53352005-08-26 19:08:30 -07002318 ms_iocb_entry_t *ms_pkt;
2319 struct ct_sns_req *ct_req;
2320 struct ct_sns_rsp *ct_rsp;
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002321 void *entries;
2322 struct ct_fdmiv2_port_attr *eiter;
Andrew Vasquezcca53352005-08-26 19:08:30 -07002323 struct init_cb_24xx *icb24 = (struct init_cb_24xx *)ha->init_cb;
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002324 struct new_utsname *p_sysid = NULL;
Andrew Vasquezcca53352005-08-26 19:08:30 -07002325
2326 /* Issue RPA */
2327 /* Prepare common MS IOCB */
2328 /* Request size adjusted after CT preparation */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002329 ms_pkt = ha->isp_ops->prep_ms_fdmi_iocb(vha, 0, RPA_RSP_SIZE);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002330
2331 /* Prepare CT request */
Bart Van Assche6ec6f902013-06-25 11:27:28 -04002332 ct_req = qla2x00_prep_ct_fdmi_req(ha->ct_sns, RPA_CMD, RPA_RSP_SIZE);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002333 ct_rsp = &ha->ct_sns->p.rsp;
2334
2335 /* Prepare FDMI command arguments -- attribute block, attributes. */
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002336 memcpy(ct_req->req.rpa2.port_name, vha->port_name, WWN_SIZE);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002337 size = WWN_SIZE + 4;
2338
2339 /* Attributes */
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002340 ct_req->req.rpa2.attrs.count = cpu_to_be32(FDMIV2_PORT_ATTR_COUNT);
2341 entries = ct_req->req.rpa2.port_name;
Andrew Vasquezcca53352005-08-26 19:08:30 -07002342
2343 /* FC4 types. */
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002344 eiter = entries + size;
2345 eiter->type = cpu_to_be16(FDMI_PORT_FC4_TYPES);
2346 eiter->len = cpu_to_be16(4 + 32);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002347 eiter->a.fc4_types[2] = 0x01;
2348 size += 4 + 32;
2349
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002350 ql_dbg(ql_dbg_disc, vha, 0x20ba,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002351 "FC4_TYPES=%02x %02x.\n",
2352 eiter->a.fc4_types[2],
2353 eiter->a.fc4_types[1]);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002354
Duane Grigsby7d236482017-06-21 13:48:45 -07002355 if (vha->flags.nvme_enabled) {
2356 eiter->a.fc4_types[6] = 1; /* NVMe type 28h */
2357 ql_dbg(ql_dbg_disc, vha, 0x211f,
2358 "NVME FC4 Type = %02x 0x0 0x0 0x0 0x0 0x0.\n",
2359 eiter->a.fc4_types[6]);
2360 }
2361
Andrew Vasquezcca53352005-08-26 19:08:30 -07002362 /* Supported speed. */
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002363 eiter = entries + size;
2364 eiter->type = cpu_to_be16(FDMI_PORT_SUPPORT_SPEED);
2365 eiter->len = cpu_to_be16(4 + 4);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002366 if (IS_CNA_CAPABLE(ha))
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002367 eiter->a.sup_speed = cpu_to_be32(
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002368 FDMI_PORT_SPEED_10GB);
Chad Dupuisf73cb692014-02-26 04:15:06 -05002369 else if (IS_QLA27XX(ha))
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002370 eiter->a.sup_speed = cpu_to_be32(
2371 FDMI_PORT_SPEED_32GB|
2372 FDMI_PORT_SPEED_16GB|
Chad Dupuisf73cb692014-02-26 04:15:06 -05002373 FDMI_PORT_SPEED_8GB);
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002374 else if (IS_QLA2031(ha))
2375 eiter->a.sup_speed = cpu_to_be32(
2376 FDMI_PORT_SPEED_16GB|
2377 FDMI_PORT_SPEED_8GB|
Andrew Vasquez58815692007-07-19 15:05:58 -07002378 FDMI_PORT_SPEED_4GB);
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002379 else if (IS_QLA25XX(ha))
2380 eiter->a.sup_speed = cpu_to_be32(
2381 FDMI_PORT_SPEED_8GB|
2382 FDMI_PORT_SPEED_4GB|
2383 FDMI_PORT_SPEED_2GB|
2384 FDMI_PORT_SPEED_1GB);
2385 else if (IS_QLA24XX_TYPE(ha))
2386 eiter->a.sup_speed = cpu_to_be32(
2387 FDMI_PORT_SPEED_4GB|
2388 FDMI_PORT_SPEED_2GB|
2389 FDMI_PORT_SPEED_1GB);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002390 else if (IS_QLA23XX(ha))
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002391 eiter->a.sup_speed = cpu_to_be32(
2392 FDMI_PORT_SPEED_2GB|
2393 FDMI_PORT_SPEED_1GB);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002394 else
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002395 eiter->a.sup_speed = cpu_to_be32(
Andrew Vasquez58815692007-07-19 15:05:58 -07002396 FDMI_PORT_SPEED_1GB);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002397 size += 4 + 4;
2398
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002399 ql_dbg(ql_dbg_disc, vha, 0x20bb,
2400 "Supported Port Speed = %x.\n", eiter->a.sup_speed);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002401
2402 /* Current speed. */
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002403 eiter = entries + size;
2404 eiter->type = cpu_to_be16(FDMI_PORT_CURRENT_SPEED);
2405 eiter->len = cpu_to_be16(4 + 4);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002406 switch (ha->link_data_rate) {
Andrew Vasquez58815692007-07-19 15:05:58 -07002407 case PORT_SPEED_1GB:
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002408 eiter->a.cur_speed = cpu_to_be32(FDMI_PORT_SPEED_1GB);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002409 break;
Andrew Vasquez58815692007-07-19 15:05:58 -07002410 case PORT_SPEED_2GB:
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002411 eiter->a.cur_speed = cpu_to_be32(FDMI_PORT_SPEED_2GB);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002412 break;
Andrew Vasquez58815692007-07-19 15:05:58 -07002413 case PORT_SPEED_4GB:
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002414 eiter->a.cur_speed = cpu_to_be32(FDMI_PORT_SPEED_4GB);
Andrew Vasquez58815692007-07-19 15:05:58 -07002415 break;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002416 case PORT_SPEED_8GB:
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002417 eiter->a.cur_speed = cpu_to_be32(FDMI_PORT_SPEED_8GB);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002418 break;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002419 case PORT_SPEED_10GB:
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002420 eiter->a.cur_speed = cpu_to_be32(FDMI_PORT_SPEED_10GB);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002421 break;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002422 case PORT_SPEED_16GB:
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002423 eiter->a.cur_speed = cpu_to_be32(FDMI_PORT_SPEED_16GB);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002424 break;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002425 case PORT_SPEED_32GB:
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002426 eiter->a.cur_speed = cpu_to_be32(FDMI_PORT_SPEED_32GB);
Chad Dupuisf73cb692014-02-26 04:15:06 -05002427 break;
Andrew Vasquez58815692007-07-19 15:05:58 -07002428 default:
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002429 eiter->a.cur_speed = cpu_to_be32(FDMI_PORT_SPEED_UNKNOWN);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002430 break;
2431 }
2432 size += 4 + 4;
2433
Quinn Tran83548fe2017-06-02 09:12:01 -07002434 ql_dbg(ql_dbg_disc, vha, 0x2017,
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002435 "Current_Speed = %x.\n", eiter->a.cur_speed);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002436
2437 /* Max frame size. */
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002438 eiter = entries + size;
2439 eiter->type = cpu_to_be16(FDMI_PORT_MAX_FRAME_SIZE);
2440 eiter->len = cpu_to_be16(4 + 4);
2441 eiter->a.max_frame_size = IS_FWI2_CAPABLE(ha) ?
Seokmann Juc6852c42008-04-24 15:21:29 -07002442 le16_to_cpu(icb24->frame_payload_size):
2443 le16_to_cpu(ha->init_cb->frame_payload_size);
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002444 eiter->a.max_frame_size = cpu_to_be32(eiter->a.max_frame_size);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002445 size += 4 + 4;
2446
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002447 ql_dbg(ql_dbg_disc, vha, 0x20bc,
2448 "Max_Frame_Size = %x.\n", eiter->a.max_frame_size);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002449
2450 /* OS device name. */
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002451 eiter = entries + size;
2452 eiter->type = cpu_to_be16(FDMI_PORT_OS_DEVICE_NAME);
Paul Bollef24b6972013-02-08 01:57:55 -05002453 alen = strlen(QLA2XXX_DRIVER_NAME);
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002454 snprintf(eiter->a.os_dev_name, sizeof(eiter->a.os_dev_name),
2455 "%s:host%lu", QLA2XXX_DRIVER_NAME, vha->host_no);
2456 alen += 4 - (alen & 3);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002457 eiter->len = cpu_to_be16(4 + alen);
2458 size += 4 + alen;
2459
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002460 ql_dbg(ql_dbg_disc, vha, 0x20be,
2461 "OS_Device_Name = %s.\n", eiter->a.os_dev_name);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002462
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07002463 /* Hostname. */
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002464 eiter = entries + size;
2465 eiter->type = cpu_to_be16(FDMI_PORT_HOST_NAME);
2466 p_sysid = utsname();
2467 if (p_sysid) {
2468 snprintf(eiter->a.host_name, sizeof(eiter->a.host_name),
2469 "%s", p_sysid->nodename);
2470 } else {
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07002471 snprintf(eiter->a.host_name, sizeof(eiter->a.host_name),
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002472 "%s", fc_host_system_hostname(vha->host));
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07002473 }
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002474 alen = strlen(eiter->a.host_name);
2475 alen += 4 - (alen & 3);
2476 eiter->len = cpu_to_be16(4 + alen);
2477 size += 4 + alen;
2478
Quinn Tran83548fe2017-06-02 09:12:01 -07002479 ql_dbg(ql_dbg_disc, vha, 0x201a,
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002480 "HostName=%s.\n", eiter->a.host_name);
2481
2482 /* Node Name */
2483 eiter = entries + size;
2484 eiter->type = cpu_to_be16(FDMI_PORT_NODE_NAME);
2485 memcpy(eiter->a.node_name, vha->node_name, WWN_SIZE);
2486 eiter->len = cpu_to_be16(4 + WWN_SIZE);
2487 size += 4 + WWN_SIZE;
2488
2489 ql_dbg(ql_dbg_disc, vha, 0x20c0,
2490 "Node Name = %016llx.\n", wwn_to_u64(eiter->a.node_name));
2491
2492 /* Port Name */
2493 eiter = entries + size;
2494 eiter->type = cpu_to_be16(FDMI_PORT_NAME);
2495 memcpy(eiter->a.port_name, vha->port_name, WWN_SIZE);
2496 eiter->len = cpu_to_be16(4 + WWN_SIZE);
2497 size += 4 + WWN_SIZE;
2498
2499 ql_dbg(ql_dbg_disc, vha, 0x20c1,
2500 "Port Name = %016llx.\n", wwn_to_u64(eiter->a.port_name));
2501
2502 /* Port Symbolic Name */
2503 eiter = entries + size;
2504 eiter->type = cpu_to_be16(FDMI_PORT_SYM_NAME);
2505 qla2x00_get_sym_node_name(vha, eiter->a.port_sym_name,
2506 sizeof(eiter->a.port_sym_name));
2507 alen = strlen(eiter->a.port_sym_name);
2508 alen += 4 - (alen & 3);
2509 eiter->len = cpu_to_be16(4 + alen);
2510 size += 4 + alen;
2511
2512 ql_dbg(ql_dbg_disc, vha, 0x20c2,
2513 "port symbolic name = %s\n", eiter->a.port_sym_name);
2514
2515 /* Port Type */
2516 eiter = entries + size;
2517 eiter->type = cpu_to_be16(FDMI_PORT_TYPE);
2518 eiter->a.port_type = cpu_to_be32(NS_NX_PORT_TYPE);
2519 eiter->len = cpu_to_be16(4 + 4);
2520 size += 4 + 4;
2521
2522 ql_dbg(ql_dbg_disc, vha, 0x20c3,
2523 "Port Type = %x.\n", eiter->a.port_type);
2524
2525 /* Class of Service */
2526 eiter = entries + size;
2527 eiter->type = cpu_to_be16(FDMI_PORT_SUPP_COS);
2528 eiter->a.port_supported_cos = cpu_to_be32(FC_CLASS_3);
2529 eiter->len = cpu_to_be16(4 + 4);
2530 size += 4 + 4;
2531
2532 ql_dbg(ql_dbg_disc, vha, 0x20c4,
2533 "Supported COS = %08x\n", eiter->a.port_supported_cos);
2534
2535 /* Port Fabric Name */
2536 eiter = entries + size;
2537 eiter->type = cpu_to_be16(FDMI_PORT_FABRIC_NAME);
2538 memcpy(eiter->a.fabric_name, vha->fabric_node_name, WWN_SIZE);
2539 eiter->len = cpu_to_be16(4 + WWN_SIZE);
2540 size += 4 + WWN_SIZE;
2541
2542 ql_dbg(ql_dbg_disc, vha, 0x20c5,
2543 "Fabric Name = %016llx.\n", wwn_to_u64(eiter->a.fabric_name));
2544
2545 /* FC4_type */
2546 eiter = entries + size;
2547 eiter->type = cpu_to_be16(FDMI_PORT_FC4_TYPE);
2548 eiter->a.port_fc4_type[0] = 0;
2549 eiter->a.port_fc4_type[1] = 0;
2550 eiter->a.port_fc4_type[2] = 1;
2551 eiter->a.port_fc4_type[3] = 0;
2552 eiter->len = cpu_to_be16(4 + 32);
2553 size += 4 + 32;
2554
2555 ql_dbg(ql_dbg_disc, vha, 0x20c6,
2556 "Port Active FC4 Type = %02x %02x.\n",
2557 eiter->a.port_fc4_type[2], eiter->a.port_fc4_type[1]);
2558
Duane Grigsby7d236482017-06-21 13:48:45 -07002559 if (vha->flags.nvme_enabled) {
2560 eiter->a.port_fc4_type[4] = 0;
2561 eiter->a.port_fc4_type[5] = 0;
2562 eiter->a.port_fc4_type[6] = 1; /* NVMe type 28h */
2563 ql_dbg(ql_dbg_disc, vha, 0x2120,
2564 "NVME Port Active FC4 Type = %02x 0x0 0x0 0x0 0x0 0x0.\n",
2565 eiter->a.port_fc4_type[6]);
2566 }
2567
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002568 /* Port State */
2569 eiter = entries + size;
2570 eiter->type = cpu_to_be16(FDMI_PORT_STATE);
2571 eiter->a.port_state = cpu_to_be32(1);
2572 eiter->len = cpu_to_be16(4 + 4);
2573 size += 4 + 4;
2574
2575 ql_dbg(ql_dbg_disc, vha, 0x20c7,
2576 "Port State = %x.\n", eiter->a.port_state);
2577
2578 /* Number of Ports */
2579 eiter = entries + size;
2580 eiter->type = cpu_to_be16(FDMI_PORT_COUNT);
2581 eiter->a.num_ports = cpu_to_be32(1);
2582 eiter->len = cpu_to_be16(4 + 4);
2583 size += 4 + 4;
2584
2585 ql_dbg(ql_dbg_disc, vha, 0x20c8,
2586 "Number of ports = %x.\n", eiter->a.num_ports);
2587
2588 /* Port Id */
2589 eiter = entries + size;
2590 eiter->type = cpu_to_be16(FDMI_PORT_ID);
2591 eiter->a.port_id = cpu_to_be32(vha->d_id.b24);
2592 eiter->len = cpu_to_be16(4 + 4);
2593 size += 4 + 4;
2594
Quinn Tran83548fe2017-06-02 09:12:01 -07002595 ql_dbg(ql_dbg_disc, vha, 0x201c,
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002596 "Port Id = %x.\n", eiter->a.port_id);
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07002597
Andrew Vasquezcca53352005-08-26 19:08:30 -07002598 /* Update MS request size. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002599 qla2x00_update_ms_fdmi_iocb(vha, size + 16);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002600
Quinn Tran83548fe2017-06-02 09:12:01 -07002601 ql_dbg(ql_dbg_disc, vha, 0x2018,
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -04002602 "RPA portname= %8phN size=%d.\n", ct_req->req.rpa.port_name, size);
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002603 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x20ca,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002604 entries, size);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002605
2606 /* Execute MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002607 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
Andrew Vasquezcca53352005-08-26 19:08:30 -07002608 sizeof(ms_iocb_entry_t));
2609 if (rval != QLA_SUCCESS) {
2610 /*EMPTY*/
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002611 ql_dbg(ql_dbg_disc, vha, 0x20cb,
2612 "RPA FDMI v2 issue IOCB failed (%d).\n", rval);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002613 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, "RPA") !=
Andrew Vasquezcca53352005-08-26 19:08:30 -07002614 QLA_SUCCESS) {
2615 rval = QLA_FUNCTION_FAILED;
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002616 if (ct_rsp->header.reason_code == CT_REASON_CANNOT_PERFORM &&
2617 ct_rsp->header.explanation_code ==
2618 CT_EXPL_ALREADY_REGISTERED) {
2619 ql_dbg(ql_dbg_disc, vha, 0x20ce,
2620 "RPA FDMI v2 already registered\n");
2621 rval = QLA_ALREADY_REGISTERED;
2622 } else {
2623 ql_dbg(ql_dbg_disc, vha, 0x2020,
2624 "RPA FDMI v2 failed, CT Reason code: 0x%x, CT Explanation 0x%x\n",
2625 ct_rsp->header.reason_code,
2626 ct_rsp->header.explanation_code);
2627 }
Andrew Vasquezcca53352005-08-26 19:08:30 -07002628 } else {
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002629 ql_dbg(ql_dbg_disc, vha, 0x20cc,
2630 "RPA FDMI V2 exiting normally.\n");
Andrew Vasquezcca53352005-08-26 19:08:30 -07002631 }
2632
2633 return rval;
2634}
2635
2636/**
2637 * qla2x00_fdmi_register() -
2638 * @ha: HA context
2639 *
2640 * Returns 0 on success.
2641 */
2642int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002643qla2x00_fdmi_register(scsi_qla_host_t *vha)
Andrew Vasquezcca53352005-08-26 19:08:30 -07002644{
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002645 int rval = QLA_FUNCTION_FAILED;
2646 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez80de7ef2009-07-31 15:09:33 -07002647
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002648 if (IS_QLA2100(ha) || IS_QLA2200(ha) ||
2649 IS_QLAFX00(ha))
Andrew Vasquez80de7ef2009-07-31 15:09:33 -07002650 return QLA_FUNCTION_FAILED;
Andrew Vasquezcca53352005-08-26 19:08:30 -07002651
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002652 rval = qla2x00_mgmt_svr_login(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002653 if (rval)
2654 return rval;
2655
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002656 rval = qla2x00_fdmiv2_rhba(vha);
2657 if (rval) {
2658 if (rval != QLA_ALREADY_REGISTERED)
2659 goto try_fdmi;
2660
2661 rval = qla2x00_fdmi_dhba(vha);
2662 if (rval)
2663 goto try_fdmi;
2664
2665 rval = qla2x00_fdmiv2_rhba(vha);
2666 if (rval)
2667 goto try_fdmi;
2668 }
2669 rval = qla2x00_fdmiv2_rpa(vha);
2670 if (rval)
2671 goto try_fdmi;
2672
2673 goto out;
2674
2675try_fdmi:
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002676 rval = qla2x00_fdmi_rhba(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002677 if (rval) {
2678 if (rval != QLA_ALREADY_REGISTERED)
2679 return rval;
2680
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002681 rval = qla2x00_fdmi_dhba(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002682 if (rval)
2683 return rval;
2684
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002685 rval = qla2x00_fdmi_rhba(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002686 if (rval)
2687 return rval;
2688 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002689 rval = qla2x00_fdmi_rpa(vha);
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002690out:
Andrew Vasquezcca53352005-08-26 19:08:30 -07002691 return rval;
2692}
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002693
2694/**
2695 * qla2x00_gfpn_id() - SNS Get Fabric Port Name (GFPN_ID) query.
2696 * @ha: HA context
2697 * @list: switch info entries to populate
2698 *
2699 * Returns 0 on success.
2700 */
2701int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002702qla2x00_gfpn_id(scsi_qla_host_t *vha, sw_info_t *list)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002703{
Chad Dupuis642ef982012-02-09 11:15:57 -08002704 int rval = QLA_SUCCESS;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002705 uint16_t i;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002706 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002707 ms_iocb_entry_t *ms_pkt;
2708 struct ct_sns_req *ct_req;
2709 struct ct_sns_rsp *ct_rsp;
Quinn Tran726b8542017-01-19 22:28:00 -08002710 struct ct_arg arg;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002711
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002712 if (!IS_IIDMA_CAPABLE(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002713 return QLA_FUNCTION_FAILED;
2714
Quinn Tran726b8542017-01-19 22:28:00 -08002715 arg.iocb = ha->ms_iocb;
2716 arg.req_dma = ha->ct_sns_dma;
2717 arg.rsp_dma = ha->ct_sns_dma;
2718 arg.req_size = GFPN_ID_REQ_SIZE;
2719 arg.rsp_size = GFPN_ID_RSP_SIZE;
2720 arg.nport_handle = NPH_SNS;
2721
Chad Dupuis642ef982012-02-09 11:15:57 -08002722 for (i = 0; i < ha->max_fibre_devices; i++) {
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002723 /* Issue GFPN_ID */
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002724 /* Prepare common MS IOCB */
Quinn Tran726b8542017-01-19 22:28:00 -08002725 ms_pkt = ha->isp_ops->prep_ms_iocb(vha, &arg);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002726
2727 /* Prepare CT request */
Bart Van Assche6ec6f902013-06-25 11:27:28 -04002728 ct_req = qla2x00_prep_ct_req(ha->ct_sns, GFPN_ID_CMD,
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002729 GFPN_ID_RSP_SIZE);
2730 ct_rsp = &ha->ct_sns->p.rsp;
2731
2732 /* Prepare CT arguments -- port_id */
2733 ct_req->req.port_id.port_id[0] = list[i].d_id.b.domain;
2734 ct_req->req.port_id.port_id[1] = list[i].d_id.b.area;
2735 ct_req->req.port_id.port_id[2] = list[i].d_id.b.al_pa;
2736
2737 /* Execute MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002738 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002739 sizeof(ms_iocb_entry_t));
2740 if (rval != QLA_SUCCESS) {
2741 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002742 ql_dbg(ql_dbg_disc, vha, 0x2023,
2743 "GFPN_ID issue IOCB failed (%d).\n", rval);
Arun Easidafdf892012-02-09 11:16:00 -08002744 break;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002745 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp,
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002746 "GFPN_ID") != QLA_SUCCESS) {
2747 rval = QLA_FUNCTION_FAILED;
Arun Easidafdf892012-02-09 11:16:00 -08002748 break;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002749 } else {
2750 /* Save fabric portname */
2751 memcpy(list[i].fabric_port_name,
2752 ct_rsp->rsp.gfpn_id.port_name, WWN_SIZE);
2753 }
2754
2755 /* Last device exit. */
2756 if (list[i].d_id.b.rsvd_1 != 0)
2757 break;
2758 }
2759
2760 return (rval);
2761}
2762
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002763
2764static inline struct ct_sns_req *
Bart Van Assche6ec6f902013-06-25 11:27:28 -04002765qla24xx_prep_ct_fm_req(struct ct_sns_pkt *p, uint16_t cmd,
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002766 uint16_t rsp_size)
2767{
Bart Van Assche6ec6f902013-06-25 11:27:28 -04002768 memset(p, 0, sizeof(struct ct_sns_pkt));
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002769
Bart Van Assche6ec6f902013-06-25 11:27:28 -04002770 p->p.req.header.revision = 0x01;
2771 p->p.req.header.gs_type = 0xFA;
2772 p->p.req.header.gs_subtype = 0x01;
2773 p->p.req.command = cpu_to_be16(cmd);
2774 p->p.req.max_rsp_size = cpu_to_be16((rsp_size - 16) / 4);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002775
Bart Van Assche6ec6f902013-06-25 11:27:28 -04002776 return &p->p.req;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002777}
2778
2779/**
2780 * qla2x00_gpsc() - FCS Get Port Speed Capabilities (GPSC) query.
2781 * @ha: HA context
2782 * @list: switch info entries to populate
2783 *
2784 * Returns 0 on success.
2785 */
2786int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002787qla2x00_gpsc(scsi_qla_host_t *vha, sw_info_t *list)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002788{
2789 int rval;
2790 uint16_t i;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002791 struct qla_hw_data *ha = vha->hw;
Quinn Tran726b8542017-01-19 22:28:00 -08002792 ms_iocb_entry_t *ms_pkt;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002793 struct ct_sns_req *ct_req;
2794 struct ct_sns_rsp *ct_rsp;
Quinn Tran726b8542017-01-19 22:28:00 -08002795 struct ct_arg arg;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002796
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002797 if (!IS_IIDMA_CAPABLE(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002798 return QLA_FUNCTION_FAILED;
Andrew Vasquez4346b142006-12-13 19:20:28 -08002799 if (!ha->flags.gpsc_supported)
2800 return QLA_FUNCTION_FAILED;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002801
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002802 rval = qla2x00_mgmt_svr_login(vha);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002803 if (rval)
2804 return rval;
2805
Quinn Tran726b8542017-01-19 22:28:00 -08002806 arg.iocb = ha->ms_iocb;
2807 arg.req_dma = ha->ct_sns_dma;
2808 arg.rsp_dma = ha->ct_sns_dma;
2809 arg.req_size = GPSC_REQ_SIZE;
2810 arg.rsp_size = GPSC_RSP_SIZE;
2811 arg.nport_handle = vha->mgmt_svr_loop_id;
2812
Chad Dupuis642ef982012-02-09 11:15:57 -08002813 for (i = 0; i < ha->max_fibre_devices; i++) {
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002814 /* Issue GFPN_ID */
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002815 /* Prepare common MS IOCB */
Quinn Tran726b8542017-01-19 22:28:00 -08002816 ms_pkt = qla24xx_prep_ms_iocb(vha, &arg);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002817
2818 /* Prepare CT request */
Bart Van Assche6ec6f902013-06-25 11:27:28 -04002819 ct_req = qla24xx_prep_ct_fm_req(ha->ct_sns, GPSC_CMD,
2820 GPSC_RSP_SIZE);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002821 ct_rsp = &ha->ct_sns->p.rsp;
2822
2823 /* Prepare CT arguments -- port_name */
2824 memcpy(ct_req->req.gpsc.port_name, list[i].fabric_port_name,
2825 WWN_SIZE);
2826
2827 /* Execute MS IOCB */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002828 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002829 sizeof(ms_iocb_entry_t));
2830 if (rval != QLA_SUCCESS) {
2831 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002832 ql_dbg(ql_dbg_disc, vha, 0x2059,
2833 "GPSC issue IOCB failed (%d).\n", rval);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002834 } else if ((rval = qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp,
Andrew Vasquez4346b142006-12-13 19:20:28 -08002835 "GPSC")) != QLA_SUCCESS) {
2836 /* FM command unsupported? */
2837 if (rval == QLA_INVALID_COMMAND &&
Andrew Vasquez3fe7cfb2008-04-03 13:13:23 -07002838 (ct_rsp->header.reason_code ==
2839 CT_REASON_INVALID_COMMAND_CODE ||
2840 ct_rsp->header.reason_code ==
2841 CT_REASON_COMMAND_UNSUPPORTED)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002842 ql_dbg(ql_dbg_disc, vha, 0x205a,
2843 "GPSC command unsupported, disabling "
2844 "query.\n");
Andrew Vasquez4346b142006-12-13 19:20:28 -08002845 ha->flags.gpsc_supported = 0;
2846 rval = QLA_FUNCTION_FAILED;
2847 break;
2848 }
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002849 rval = QLA_FUNCTION_FAILED;
2850 } else {
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002851 /* Save port-speed */
2852 switch (be16_to_cpu(ct_rsp->rsp.gpsc.speed)) {
2853 case BIT_15:
2854 list[i].fp_speed = PORT_SPEED_1GB;
2855 break;
2856 case BIT_14:
2857 list[i].fp_speed = PORT_SPEED_2GB;
2858 break;
2859 case BIT_13:
2860 list[i].fp_speed = PORT_SPEED_4GB;
2861 break;
Andrew Vasquez9f8fdde2009-06-03 09:55:22 -07002862 case BIT_12:
2863 list[i].fp_speed = PORT_SPEED_10GB;
2864 break;
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002865 case BIT_11:
2866 list[i].fp_speed = PORT_SPEED_8GB;
2867 break;
Joe Carnuccioc53dfac2012-11-21 02:40:39 -05002868 case BIT_10:
2869 list[i].fp_speed = PORT_SPEED_16GB;
2870 break;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002871 case BIT_8:
2872 list[i].fp_speed = PORT_SPEED_32GB;
2873 break;
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002874 }
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002875
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002876 ql_dbg(ql_dbg_disc, vha, 0x205b,
2877 "GPSC ext entry - fpn "
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -04002878 "%8phN speeds=%04x speed=%04x.\n",
2879 list[i].fabric_port_name,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002880 be16_to_cpu(ct_rsp->rsp.gpsc.speeds),
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002881 be16_to_cpu(ct_rsp->rsp.gpsc.speed));
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002882 }
2883
2884 /* Last device exit. */
2885 if (list[i].d_id.b.rsvd_1 != 0)
2886 break;
2887 }
2888
2889 return (rval);
2890}
Chad Dupuise8c72ba2010-07-23 15:28:25 +05002891
2892/**
2893 * qla2x00_gff_id() - SNS Get FC-4 Features (GFF_ID) query.
2894 *
2895 * @ha: HA context
2896 * @list: switch info entries to populate
2897 *
2898 */
2899void
2900qla2x00_gff_id(scsi_qla_host_t *vha, sw_info_t *list)
2901{
2902 int rval;
2903 uint16_t i;
2904
2905 ms_iocb_entry_t *ms_pkt;
2906 struct ct_sns_req *ct_req;
2907 struct ct_sns_rsp *ct_rsp;
2908 struct qla_hw_data *ha = vha->hw;
2909 uint8_t fcp_scsi_features = 0;
Quinn Tran726b8542017-01-19 22:28:00 -08002910 struct ct_arg arg;
Chad Dupuise8c72ba2010-07-23 15:28:25 +05002911
Chad Dupuis642ef982012-02-09 11:15:57 -08002912 for (i = 0; i < ha->max_fibre_devices; i++) {
Chad Dupuise8c72ba2010-07-23 15:28:25 +05002913 /* Set default FC4 Type as UNKNOWN so the default is to
2914 * Process this port */
2915 list[i].fc4_type = FC4_TYPE_UNKNOWN;
2916
2917 /* Do not attempt GFF_ID if we are not FWI_2 capable */
2918 if (!IS_FWI2_CAPABLE(ha))
2919 continue;
2920
Quinn Tran726b8542017-01-19 22:28:00 -08002921 arg.iocb = ha->ms_iocb;
2922 arg.req_dma = ha->ct_sns_dma;
2923 arg.rsp_dma = ha->ct_sns_dma;
2924 arg.req_size = GFF_ID_REQ_SIZE;
2925 arg.rsp_size = GFF_ID_RSP_SIZE;
2926 arg.nport_handle = NPH_SNS;
2927
Chad Dupuise8c72ba2010-07-23 15:28:25 +05002928 /* Prepare common MS IOCB */
Quinn Tran726b8542017-01-19 22:28:00 -08002929 ms_pkt = ha->isp_ops->prep_ms_iocb(vha, &arg);
Chad Dupuise8c72ba2010-07-23 15:28:25 +05002930
2931 /* Prepare CT request */
Bart Van Assche6ec6f902013-06-25 11:27:28 -04002932 ct_req = qla2x00_prep_ct_req(ha->ct_sns, GFF_ID_CMD,
Chad Dupuise8c72ba2010-07-23 15:28:25 +05002933 GFF_ID_RSP_SIZE);
2934 ct_rsp = &ha->ct_sns->p.rsp;
2935
2936 /* Prepare CT arguments -- port_id */
2937 ct_req->req.port_id.port_id[0] = list[i].d_id.b.domain;
2938 ct_req->req.port_id.port_id[1] = list[i].d_id.b.area;
2939 ct_req->req.port_id.port_id[2] = list[i].d_id.b.al_pa;
2940
2941 /* Execute MS IOCB */
2942 rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
2943 sizeof(ms_iocb_entry_t));
2944
2945 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002946 ql_dbg(ql_dbg_disc, vha, 0x205c,
2947 "GFF_ID issue IOCB failed (%d).\n", rval);
Chad Dupuise8c72ba2010-07-23 15:28:25 +05002948 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp,
Andrew Vasquez7a78ced2011-02-23 15:27:12 -08002949 "GFF_ID") != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002950 ql_dbg(ql_dbg_disc, vha, 0x205d,
2951 "GFF_ID IOCB status had a failure status code.\n");
Chad Dupuise8c72ba2010-07-23 15:28:25 +05002952 } else {
2953 fcp_scsi_features =
2954 ct_rsp->rsp.gff_id.fc4_features[GFF_FCP_SCSI_OFFSET];
2955 fcp_scsi_features &= 0x0f;
2956
2957 if (fcp_scsi_features)
2958 list[i].fc4_type = FC4_TYPE_FCP_SCSI;
2959 else
2960 list[i].fc4_type = FC4_TYPE_OTHER;
Duane Grigsbyd3bae932017-06-21 13:48:44 -07002961
2962 list[i].fc4f_nvme =
2963 ct_rsp->rsp.gff_id.fc4_features[GFF_NVME_OFFSET];
2964 list[i].fc4f_nvme &= 0xf;
Chad Dupuise8c72ba2010-07-23 15:28:25 +05002965 }
2966
2967 /* Last device exit. */
2968 if (list[i].d_id.b.rsvd_1 != 0)
2969 break;
2970 }
2971}
Quinn Tran726b8542017-01-19 22:28:00 -08002972
2973/* GID_PN completion processing. */
2974void qla24xx_handle_gidpn_event(scsi_qla_host_t *vha, struct event_arg *ea)
2975{
2976 fc_port_t *fcport = ea->fcport;
2977
Quinn Tran83548fe2017-06-02 09:12:01 -07002978 ql_dbg(ql_dbg_disc, vha, 0x201d,
Quinn Tranf352eeb2017-12-28 12:33:35 -08002979 "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d lid %d\n",
2980 __func__, fcport->port_name, fcport->disc_state,
2981 fcport->fw_login_state, ea->rc, fcport->login_gen, ea->sp->gen2,
2982 fcport->rscn_gen, ea->sp->gen1, fcport->loop_id);
Quinn Tran726b8542017-01-19 22:28:00 -08002983
Quinn Trana4239942017-12-28 12:33:26 -08002984 if (fcport->disc_state == DSC_DELETE_PEND)
2985 return;
2986
Quinn Tran726b8542017-01-19 22:28:00 -08002987 if (ea->sp->gen2 != fcport->login_gen) {
2988 /* PLOGI/PRLI/LOGO came in while cmd was out.*/
Quinn Tran83548fe2017-06-02 09:12:01 -07002989 ql_dbg(ql_dbg_disc, vha, 0x201e,
Quinn Tranf352eeb2017-12-28 12:33:35 -08002990 "%s %8phC generation changed rscn %d|%d n",
Quinn Tran726b8542017-01-19 22:28:00 -08002991 __func__, fcport->port_name, fcport->last_rscn_gen,
Quinn Tranf352eeb2017-12-28 12:33:35 -08002992 fcport->rscn_gen);
Quinn Tran726b8542017-01-19 22:28:00 -08002993 return;
2994 }
2995
2996 if (!ea->rc) {
2997 if (ea->sp->gen1 == fcport->rscn_gen) {
2998 fcport->scan_state = QLA_FCPORT_FOUND;
2999 fcport->flags |= FCF_FABRIC_DEVICE;
3000
3001 if (fcport->d_id.b24 == ea->id.b24) {
3002 /* cable plugged into the same place */
3003 switch (vha->host->active_mode) {
3004 case MODE_TARGET:
Quinn Trana4239942017-12-28 12:33:26 -08003005 if (fcport->fw_login_state ==
3006 DSC_LS_PRLI_COMP) {
3007 u16 data[2];
3008 /*
3009 * Late RSCN was delivered.
3010 * Remote port already login'ed.
3011 */
3012 ql_dbg(ql_dbg_disc, vha, 0x201f,
3013 "%s %d %8phC post adisc\n",
3014 __func__, __LINE__,
3015 fcport->port_name);
3016 data[0] = data[1] = 0;
3017 qla2x00_post_async_adisc_work(
3018 vha, fcport, data);
3019 }
Quinn Tran726b8542017-01-19 22:28:00 -08003020 break;
3021 case MODE_INITIATOR:
3022 case MODE_DUAL:
3023 default:
Quinn Trana07fc0a2017-08-23 15:05:21 -07003024 ql_dbg(ql_dbg_disc, vha, 0x201f,
3025 "%s %d %8phC post %s\n", __func__,
3026 __LINE__, fcport->port_name,
3027 (atomic_read(&fcport->state) ==
Quinn Tranf13515a2017-12-28 12:33:15 -08003028 FCS_ONLINE) ? "adisc" : "gnl");
Quinn Trana07fc0a2017-08-23 15:05:21 -07003029
Quinn Tran726b8542017-01-19 22:28:00 -08003030 if (atomic_read(&fcport->state) ==
Quinn Tranf13515a2017-12-28 12:33:15 -08003031 FCS_ONLINE) {
3032 u16 data[2];
3033
3034 data[0] = data[1] = 0;
3035 qla2x00_post_async_adisc_work(
3036 vha, fcport, data);
3037 } else {
Quinn Trana07fc0a2017-08-23 15:05:21 -07003038 qla24xx_post_gnl_work(vha,
3039 fcport);
Quinn Tranf13515a2017-12-28 12:33:15 -08003040 }
Quinn Tran726b8542017-01-19 22:28:00 -08003041 break;
3042 }
3043 } else { /* fcport->d_id.b24 != ea->id.b24 */
3044 fcport->d_id.b24 = ea->id.b24;
Quinn Trana4239942017-12-28 12:33:26 -08003045 fcport->id_changed = 1;
Quinn Trana084fd62017-12-04 14:45:00 -08003046 if (fcport->deleted != QLA_SESS_DELETED) {
Quinn Tran83548fe2017-06-02 09:12:01 -07003047 ql_dbg(ql_dbg_disc, vha, 0x2021,
Quinn Tran726b8542017-01-19 22:28:00 -08003048 "%s %d %8phC post del sess\n",
3049 __func__, __LINE__, fcport->port_name);
3050 qlt_schedule_sess_for_deletion_lock(fcport);
3051 }
3052 }
3053 } else { /* ea->sp->gen1 != fcport->rscn_gen */
Quinn Tran83548fe2017-06-02 09:12:01 -07003054 ql_dbg(ql_dbg_disc, vha, 0x2022,
Quinn Tran726b8542017-01-19 22:28:00 -08003055 "%s %d %8phC post gidpn\n",
3056 __func__, __LINE__, fcport->port_name);
3057 /* rscn came in while cmd was out */
3058 qla24xx_post_gidpn_work(vha, fcport);
3059 }
3060 } else { /* ea->rc */
3061 /* cable pulled */
3062 if (ea->sp->gen1 == fcport->rscn_gen) {
3063 if (ea->sp->gen2 == fcport->login_gen) {
Quinn Tran83548fe2017-06-02 09:12:01 -07003064 ql_dbg(ql_dbg_disc, vha, 0x2042,
Quinn Tran726b8542017-01-19 22:28:00 -08003065 "%s %d %8phC post del sess\n", __func__,
3066 __LINE__, fcport->port_name);
3067 qlt_schedule_sess_for_deletion_lock(fcport);
3068 } else {
Quinn Tran83548fe2017-06-02 09:12:01 -07003069 ql_dbg(ql_dbg_disc, vha, 0x2045,
Quinn Tran726b8542017-01-19 22:28:00 -08003070 "%s %d %8phC login\n", __func__, __LINE__,
3071 fcport->port_name);
3072 qla24xx_fcport_handle_login(vha, fcport);
3073 }
3074 } else {
Quinn Tran83548fe2017-06-02 09:12:01 -07003075 ql_dbg(ql_dbg_disc, vha, 0x2049,
Quinn Tran726b8542017-01-19 22:28:00 -08003076 "%s %d %8phC post gidpn\n", __func__, __LINE__,
3077 fcport->port_name);
3078 qla24xx_post_gidpn_work(vha, fcport);
3079 }
3080 }
3081} /* gidpn_event */
3082
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08003083static void qla2x00_async_gidpn_sp_done(void *s, int res)
Quinn Tran726b8542017-01-19 22:28:00 -08003084{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08003085 struct srb *sp = s;
3086 struct scsi_qla_host *vha = sp->vha;
Quinn Tran726b8542017-01-19 22:28:00 -08003087 fc_port_t *fcport = sp->fcport;
3088 u8 *id = fcport->ct_desc.ct_sns->p.rsp.rsp.gid_pn.port_id;
3089 struct event_arg ea;
3090
3091 fcport->flags &= ~FCF_ASYNC_SENT;
3092
3093 memset(&ea, 0, sizeof(ea));
3094 ea.fcport = fcport;
3095 ea.id.b.domain = id[0];
3096 ea.id.b.area = id[1];
3097 ea.id.b.al_pa = id[2];
3098 ea.sp = sp;
3099 ea.rc = res;
3100 ea.event = FCME_GIDPN_DONE;
3101
Quinn Tran25ad76b2017-12-04 14:45:01 -08003102 if (res == QLA_FUNCTION_TIMEOUT) {
3103 ql_dbg(ql_dbg_disc, sp->vha, 0xffff,
3104 "Async done-%s WWPN %8phC timed out.\n",
3105 sp->name, fcport->port_name);
3106 qla24xx_post_gidpn_work(sp->vha, fcport);
3107 sp->free(sp);
3108 return;
3109 } else if (res) {
3110 ql_dbg(ql_dbg_disc, sp->vha, 0xffff,
3111 "Async done-%s fail res %x, WWPN %8phC\n",
3112 sp->name, res, fcport->port_name);
3113 } else {
3114 ql_dbg(ql_dbg_disc, vha, 0x204f,
3115 "Async done-%s good WWPN %8phC ID %3phC\n",
3116 sp->name, fcport->port_name, id);
3117 }
Quinn Tran726b8542017-01-19 22:28:00 -08003118
3119 qla2x00_fcport_event_handler(vha, &ea);
3120
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08003121 sp->free(sp);
Quinn Tran726b8542017-01-19 22:28:00 -08003122}
3123
3124int qla24xx_async_gidpn(scsi_qla_host_t *vha, fc_port_t *fcport)
3125{
3126 int rval = QLA_FUNCTION_FAILED;
3127 struct ct_sns_req *ct_req;
3128 srb_t *sp;
3129
3130 if (!vha->flags.online)
3131 goto done;
3132
3133 fcport->flags |= FCF_ASYNC_SENT;
3134 fcport->disc_state = DSC_GID_PN;
3135 fcport->scan_state = QLA_FCPORT_SCAN;
3136 sp = qla2x00_get_sp(vha, fcport, GFP_ATOMIC);
3137 if (!sp)
3138 goto done;
3139
3140 sp->type = SRB_CT_PTHRU_CMD;
3141 sp->name = "gidpn";
3142 sp->gen1 = fcport->rscn_gen;
3143 sp->gen2 = fcport->login_gen;
3144
3145 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
3146
3147 /* CT_IU preamble */
3148 ct_req = qla2x00_prep_ct_req(fcport->ct_desc.ct_sns, GID_PN_CMD,
3149 GID_PN_RSP_SIZE);
3150
3151 /* GIDPN req */
3152 memcpy(ct_req->req.gid_pn.port_name, fcport->port_name,
3153 WWN_SIZE);
3154
3155 /* req & rsp use the same buffer */
3156 sp->u.iocb_cmd.u.ctarg.req = fcport->ct_desc.ct_sns;
3157 sp->u.iocb_cmd.u.ctarg.req_dma = fcport->ct_desc.ct_sns_dma;
3158 sp->u.iocb_cmd.u.ctarg.rsp = fcport->ct_desc.ct_sns;
3159 sp->u.iocb_cmd.u.ctarg.rsp_dma = fcport->ct_desc.ct_sns_dma;
3160 sp->u.iocb_cmd.u.ctarg.req_size = GID_PN_REQ_SIZE;
3161 sp->u.iocb_cmd.u.ctarg.rsp_size = GID_PN_RSP_SIZE;
3162 sp->u.iocb_cmd.u.ctarg.nport_handle = NPH_SNS;
3163
3164 sp->u.iocb_cmd.timeout = qla2x00_async_iocb_timeout;
3165 sp->done = qla2x00_async_gidpn_sp_done;
3166
3167 rval = qla2x00_start_sp(sp);
3168 if (rval != QLA_SUCCESS)
3169 goto done_free_sp;
3170
Quinn Tran83548fe2017-06-02 09:12:01 -07003171 ql_dbg(ql_dbg_disc, vha, 0x20a4,
3172 "Async-%s - %8phC hdl=%x loopid=%x portid %02x%02x%02x.\n",
3173 sp->name, fcport->port_name,
3174 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
3175 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Quinn Tran726b8542017-01-19 22:28:00 -08003176 return rval;
3177
3178done_free_sp:
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08003179 sp->free(sp);
Quinn Tran726b8542017-01-19 22:28:00 -08003180done:
3181 fcport->flags &= ~FCF_ASYNC_SENT;
3182 return rval;
3183}
3184
3185int qla24xx_post_gidpn_work(struct scsi_qla_host *vha, fc_port_t *fcport)
3186{
3187 struct qla_work_evt *e;
Quinn Tran41dc5292017-01-19 22:28:03 -08003188 int ls;
Quinn Tran726b8542017-01-19 22:28:00 -08003189
Quinn Tran41dc5292017-01-19 22:28:03 -08003190 ls = atomic_read(&vha->loop_state);
3191 if (((ls != LOOP_READY) && (ls != LOOP_UP)) ||
Quinn Tran726b8542017-01-19 22:28:00 -08003192 test_bit(UNLOADING, &vha->dpc_flags))
3193 return 0;
3194
3195 e = qla2x00_alloc_work(vha, QLA_EVT_GIDPN);
3196 if (!e)
3197 return QLA_FUNCTION_FAILED;
3198
3199 e->u.fcport.fcport = fcport;
3200 return qla2x00_post_work(vha, e);
3201}
3202
3203int qla24xx_post_gpsc_work(struct scsi_qla_host *vha, fc_port_t *fcport)
3204{
3205 struct qla_work_evt *e;
3206
3207 e = qla2x00_alloc_work(vha, QLA_EVT_GPSC);
3208 if (!e)
3209 return QLA_FUNCTION_FAILED;
3210
3211 e->u.fcport.fcport = fcport;
3212 return qla2x00_post_work(vha, e);
3213}
3214
Quinn Trana4239942017-12-28 12:33:26 -08003215void qla24xx_handle_gpsc_event(scsi_qla_host_t *vha, struct event_arg *ea)
3216{
3217 struct fc_port *fcport = ea->fcport;
3218
3219 ql_dbg(ql_dbg_disc, vha, 0x20d8,
Quinn Tranf352eeb2017-12-28 12:33:35 -08003220 "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d lid %d\n",
Quinn Trana4239942017-12-28 12:33:26 -08003221 __func__, fcport->port_name, fcport->disc_state,
Quinn Tranf352eeb2017-12-28 12:33:35 -08003222 fcport->fw_login_state, ea->rc, ea->sp->gen2, fcport->login_gen,
3223 ea->sp->gen2, fcport->rscn_gen|ea->sp->gen1, fcport->loop_id);
Quinn Trana4239942017-12-28 12:33:26 -08003224
3225 if (fcport->disc_state == DSC_DELETE_PEND)
3226 return;
3227
3228 if (ea->sp->gen2 != fcport->login_gen) {
3229 /* target side must have changed it. */
3230 ql_dbg(ql_dbg_disc, vha, 0x20d3,
Quinn Tranf352eeb2017-12-28 12:33:35 -08003231 "%s %8phC generation changed\n",
3232 __func__, fcport->port_name);
Quinn Trana4239942017-12-28 12:33:26 -08003233 return;
3234 } else if (ea->sp->gen1 != fcport->rscn_gen) {
3235 ql_dbg(ql_dbg_disc, vha, 0x20d4, "%s %d %8phC post gidpn\n",
3236 __func__, __LINE__, fcport->port_name);
3237 qla24xx_post_gidpn_work(vha, fcport);
3238 return;
3239 }
3240
3241 qla24xx_post_upd_fcport_work(vha, ea->fcport);
3242}
3243
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08003244static void qla24xx_async_gpsc_sp_done(void *s, int res)
Quinn Tran726b8542017-01-19 22:28:00 -08003245{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08003246 struct srb *sp = s;
3247 struct scsi_qla_host *vha = sp->vha;
Quinn Tran726b8542017-01-19 22:28:00 -08003248 struct qla_hw_data *ha = vha->hw;
Quinn Tran726b8542017-01-19 22:28:00 -08003249 fc_port_t *fcport = sp->fcport;
3250 struct ct_sns_rsp *ct_rsp;
3251 struct event_arg ea;
3252
3253 ct_rsp = &fcport->ct_desc.ct_sns->p.rsp;
3254
Quinn Tran83548fe2017-06-02 09:12:01 -07003255 ql_dbg(ql_dbg_disc, vha, 0x2053,
Quinn Tran726b8542017-01-19 22:28:00 -08003256 "Async done-%s res %x, WWPN %8phC \n",
3257 sp->name, res, fcport->port_name);
3258
3259 fcport->flags &= ~FCF_ASYNC_SENT;
3260
3261 if (res == (DID_ERROR << 16)) {
3262 /* entry status error */
3263 goto done;
3264 } else if (res) {
3265 if ((ct_rsp->header.reason_code ==
3266 CT_REASON_INVALID_COMMAND_CODE) ||
3267 (ct_rsp->header.reason_code ==
Quinn Tran83548fe2017-06-02 09:12:01 -07003268 CT_REASON_COMMAND_UNSUPPORTED)) {
3269 ql_dbg(ql_dbg_disc, vha, 0x2019,
3270 "GPSC command unsupported, disabling query.\n");
Quinn Tran726b8542017-01-19 22:28:00 -08003271 ha->flags.gpsc_supported = 0;
3272 res = QLA_SUCCESS;
3273 }
3274 } else {
3275 switch (be16_to_cpu(ct_rsp->rsp.gpsc.speed)) {
3276 case BIT_15:
3277 fcport->fp_speed = PORT_SPEED_1GB;
3278 break;
3279 case BIT_14:
3280 fcport->fp_speed = PORT_SPEED_2GB;
3281 break;
3282 case BIT_13:
3283 fcport->fp_speed = PORT_SPEED_4GB;
3284 break;
3285 case BIT_12:
3286 fcport->fp_speed = PORT_SPEED_10GB;
3287 break;
3288 case BIT_11:
3289 fcport->fp_speed = PORT_SPEED_8GB;
3290 break;
3291 case BIT_10:
3292 fcport->fp_speed = PORT_SPEED_16GB;
3293 break;
3294 case BIT_8:
3295 fcport->fp_speed = PORT_SPEED_32GB;
3296 break;
3297 }
3298
Quinn Tran83548fe2017-06-02 09:12:01 -07003299 ql_dbg(ql_dbg_disc, vha, 0x2054,
3300 "Async-%s OUT WWPN %8phC speeds=%04x speed=%04x.\n",
3301 sp->name, fcport->fabric_port_name,
3302 be16_to_cpu(ct_rsp->rsp.gpsc.speeds),
3303 be16_to_cpu(ct_rsp->rsp.gpsc.speed));
Quinn Tran726b8542017-01-19 22:28:00 -08003304 }
3305done:
3306 memset(&ea, 0, sizeof(ea));
3307 ea.event = FCME_GPSC_DONE;
3308 ea.rc = res;
3309 ea.fcport = fcport;
Quinn Trana4239942017-12-28 12:33:26 -08003310 ea.sp = sp;
Quinn Tran726b8542017-01-19 22:28:00 -08003311 qla2x00_fcport_event_handler(vha, &ea);
3312
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08003313 sp->free(sp);
Quinn Tran726b8542017-01-19 22:28:00 -08003314}
3315
3316int qla24xx_async_gpsc(scsi_qla_host_t *vha, fc_port_t *fcport)
3317{
3318 int rval = QLA_FUNCTION_FAILED;
3319 struct ct_sns_req *ct_req;
3320 srb_t *sp;
3321
3322 if (!vha->flags.online)
3323 goto done;
3324
3325 fcport->flags |= FCF_ASYNC_SENT;
3326 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
3327 if (!sp)
3328 goto done;
3329
3330 sp->type = SRB_CT_PTHRU_CMD;
3331 sp->name = "gpsc";
3332 sp->gen1 = fcport->rscn_gen;
3333 sp->gen2 = fcport->login_gen;
3334
3335 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
3336
3337 /* CT_IU preamble */
3338 ct_req = qla24xx_prep_ct_fm_req(fcport->ct_desc.ct_sns, GPSC_CMD,
3339 GPSC_RSP_SIZE);
3340
3341 /* GPSC req */
Quinn Tranb2e8ae32017-08-23 15:05:06 -07003342 memcpy(ct_req->req.gpsc.port_name, fcport->fabric_port_name,
Quinn Tran726b8542017-01-19 22:28:00 -08003343 WWN_SIZE);
3344
3345 sp->u.iocb_cmd.u.ctarg.req = fcport->ct_desc.ct_sns;
3346 sp->u.iocb_cmd.u.ctarg.req_dma = fcport->ct_desc.ct_sns_dma;
3347 sp->u.iocb_cmd.u.ctarg.rsp = fcport->ct_desc.ct_sns;
3348 sp->u.iocb_cmd.u.ctarg.rsp_dma = fcport->ct_desc.ct_sns_dma;
3349 sp->u.iocb_cmd.u.ctarg.req_size = GPSC_REQ_SIZE;
3350 sp->u.iocb_cmd.u.ctarg.rsp_size = GPSC_RSP_SIZE;
3351 sp->u.iocb_cmd.u.ctarg.nport_handle = vha->mgmt_svr_loop_id;
3352
3353 sp->u.iocb_cmd.timeout = qla2x00_async_iocb_timeout;
3354 sp->done = qla24xx_async_gpsc_sp_done;
3355
3356 rval = qla2x00_start_sp(sp);
3357 if (rval != QLA_SUCCESS)
3358 goto done_free_sp;
3359
Quinn Tran83548fe2017-06-02 09:12:01 -07003360 ql_dbg(ql_dbg_disc, vha, 0x205e,
3361 "Async-%s %8phC hdl=%x loopid=%x portid=%02x%02x%02x.\n",
3362 sp->name, fcport->port_name, sp->handle,
3363 fcport->loop_id, fcport->d_id.b.domain,
3364 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Quinn Tran726b8542017-01-19 22:28:00 -08003365 return rval;
3366
3367done_free_sp:
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08003368 sp->free(sp);
Quinn Tran726b8542017-01-19 22:28:00 -08003369done:
3370 fcport->flags &= ~FCF_ASYNC_SENT;
3371 return rval;
3372}
3373
3374int qla24xx_post_gpnid_work(struct scsi_qla_host *vha, port_id_t *id)
3375{
3376 struct qla_work_evt *e;
3377
3378 if (test_bit(UNLOADING, &vha->dpc_flags))
3379 return 0;
3380
3381 e = qla2x00_alloc_work(vha, QLA_EVT_GPNID);
3382 if (!e)
3383 return QLA_FUNCTION_FAILED;
3384
3385 e->u.gpnid.id = *id;
3386 return qla2x00_post_work(vha, e);
3387}
3388
Quinn Trane374f9f2017-12-28 12:33:31 -08003389void qla24xx_sp_unmap(scsi_qla_host_t *vha, srb_t *sp)
Quinn Tran726b8542017-01-19 22:28:00 -08003390{
3391 if (sp->u.iocb_cmd.u.ctarg.req) {
3392 dma_free_coherent(&vha->hw->pdev->dev,
3393 sizeof(struct ct_sns_pkt),
3394 sp->u.iocb_cmd.u.ctarg.req,
3395 sp->u.iocb_cmd.u.ctarg.req_dma);
3396 sp->u.iocb_cmd.u.ctarg.req = NULL;
3397 }
3398 if (sp->u.iocb_cmd.u.ctarg.rsp) {
3399 dma_free_coherent(&vha->hw->pdev->dev,
3400 sizeof(struct ct_sns_pkt),
3401 sp->u.iocb_cmd.u.ctarg.rsp,
3402 sp->u.iocb_cmd.u.ctarg.rsp_dma);
3403 sp->u.iocb_cmd.u.ctarg.rsp = NULL;
3404 }
3405
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08003406 sp->free(sp);
Quinn Tran726b8542017-01-19 22:28:00 -08003407}
3408
3409void qla24xx_handle_gpnid_event(scsi_qla_host_t *vha, struct event_arg *ea)
3410{
Quinn Tran5ef696a2017-12-04 14:45:05 -08003411 fc_port_t *fcport, *conflict, *t;
Quinn Tranf13515a2017-12-28 12:33:15 -08003412 u16 data[2];
Quinn Tran726b8542017-01-19 22:28:00 -08003413
Quinn Tran5ef696a2017-12-04 14:45:05 -08003414 ql_dbg(ql_dbg_disc, vha, 0xffff,
3415 "%s %d port_id: %06x\n",
3416 __func__, __LINE__, ea->id.b24);
Quinn Tran726b8542017-01-19 22:28:00 -08003417
Quinn Tran5ef696a2017-12-04 14:45:05 -08003418 if (ea->rc) {
3419 /* cable is disconnected */
3420 list_for_each_entry_safe(fcport, t, &vha->vp_fcports, list) {
3421 if (fcport->d_id.b24 == ea->id.b24) {
3422 ql_dbg(ql_dbg_disc, vha, 0xffff,
3423 "%s %d %8phC DS %d\n",
3424 __func__, __LINE__,
3425 fcport->port_name,
3426 fcport->disc_state);
3427 fcport->scan_state = QLA_FCPORT_SCAN;
3428 switch (fcport->disc_state) {
3429 case DSC_DELETED:
3430 case DSC_DELETE_PEND:
3431 break;
3432 default:
3433 ql_dbg(ql_dbg_disc, vha, 0xffff,
3434 "%s %d %8phC post del sess\n",
3435 __func__, __LINE__,
3436 fcport->port_name);
3437 qlt_schedule_sess_for_deletion_lock
3438 (fcport);
3439 break;
3440 }
3441 }
Quinn Tran66ee0fe2017-06-02 09:11:56 -07003442 }
Quinn Tran726b8542017-01-19 22:28:00 -08003443 } else {
Quinn Tran5ef696a2017-12-04 14:45:05 -08003444 /* cable is connected */
3445 fcport = qla2x00_find_fcport_by_wwpn(vha, ea->port_name, 1);
3446 if (fcport) {
3447 list_for_each_entry_safe(conflict, t, &vha->vp_fcports,
3448 list) {
3449 if ((conflict->d_id.b24 == ea->id.b24) &&
3450 (fcport != conflict)) {
3451 /* 2 fcports with conflict Nport ID or
3452 * an existing fcport is having nport ID
3453 * conflict with new fcport.
3454 */
Quinn Tran726b8542017-01-19 22:28:00 -08003455
Quinn Tran5ef696a2017-12-04 14:45:05 -08003456 ql_dbg(ql_dbg_disc, vha, 0xffff,
3457 "%s %d %8phC DS %d\n",
3458 __func__, __LINE__,
3459 conflict->port_name,
3460 conflict->disc_state);
3461 conflict->scan_state = QLA_FCPORT_SCAN;
3462 switch (conflict->disc_state) {
3463 case DSC_DELETED:
3464 case DSC_DELETE_PEND:
3465 break;
3466 default:
3467 ql_dbg(ql_dbg_disc, vha, 0xffff,
3468 "%s %d %8phC post del sess\n",
3469 __func__, __LINE__,
3470 conflict->port_name);
3471 qlt_schedule_sess_for_deletion_lock
3472 (conflict);
3473 break;
3474 }
3475 }
3476 }
3477
3478 fcport->rscn_gen++;
3479 fcport->scan_state = QLA_FCPORT_FOUND;
3480 fcport->flags |= FCF_FABRIC_DEVICE;
3481 switch (fcport->disc_state) {
3482 case DSC_LOGIN_COMPLETE:
3483 /* recheck session is still intact. */
3484 ql_dbg(ql_dbg_disc, vha, 0x210d,
3485 "%s %d %8phC revalidate session with ADISC\n",
3486 __func__, __LINE__, fcport->port_name);
Quinn Tranf13515a2017-12-28 12:33:15 -08003487 data[0] = data[1] = 0;
3488 qla2x00_post_async_adisc_work(vha, fcport,
3489 data);
Quinn Tran5ef696a2017-12-04 14:45:05 -08003490 break;
3491 case DSC_DELETED:
3492 ql_dbg(ql_dbg_disc, vha, 0x210d,
3493 "%s %d %8phC login\n", __func__, __LINE__,
3494 fcport->port_name);
3495 fcport->d_id = ea->id;
3496 qla24xx_fcport_handle_login(vha, fcport);
3497 break;
3498 case DSC_DELETE_PEND:
3499 fcport->d_id = ea->id;
3500 break;
3501 default:
3502 fcport->d_id = ea->id;
3503 break;
3504 }
3505 } else {
3506 list_for_each_entry_safe(conflict, t, &vha->vp_fcports,
3507 list) {
3508 if (conflict->d_id.b24 == ea->id.b24) {
3509 /* 2 fcports with conflict Nport ID or
3510 * an existing fcport is having nport ID
3511 * conflict with new fcport.
3512 */
3513 ql_dbg(ql_dbg_disc, vha, 0xffff,
3514 "%s %d %8phC DS %d\n",
3515 __func__, __LINE__,
3516 conflict->port_name,
3517 conflict->disc_state);
3518
3519 conflict->scan_state = QLA_FCPORT_SCAN;
3520 switch (conflict->disc_state) {
3521 case DSC_DELETED:
3522 case DSC_DELETE_PEND:
3523 break;
3524 default:
3525 ql_dbg(ql_dbg_disc, vha, 0xffff,
3526 "%s %d %8phC post del sess\n",
3527 __func__, __LINE__,
3528 conflict->port_name);
3529 qlt_schedule_sess_for_deletion_lock
3530 (conflict);
3531 break;
3532 }
3533 }
3534 }
3535
3536 /* create new fcport */
3537 ql_dbg(ql_dbg_disc, vha, 0x2065,
3538 "%s %d %8phC post new sess\n",
3539 __func__, __LINE__, ea->port_name);
3540 qla24xx_post_newsess_work(vha, &ea->id,
Quinn Trana4239942017-12-28 12:33:26 -08003541 ea->port_name, NULL, NULL, FC4_TYPE_UNKNOWN);
Quinn Tran5ef696a2017-12-04 14:45:05 -08003542 }
Quinn Tran726b8542017-01-19 22:28:00 -08003543 }
3544}
3545
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08003546static void qla2x00_async_gpnid_sp_done(void *s, int res)
Quinn Tran726b8542017-01-19 22:28:00 -08003547{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08003548 struct srb *sp = s;
3549 struct scsi_qla_host *vha = sp->vha;
Quinn Tran726b8542017-01-19 22:28:00 -08003550 struct ct_sns_req *ct_req =
3551 (struct ct_sns_req *)sp->u.iocb_cmd.u.ctarg.req;
3552 struct ct_sns_rsp *ct_rsp =
3553 (struct ct_sns_rsp *)sp->u.iocb_cmd.u.ctarg.rsp;
3554 struct event_arg ea;
3555 struct qla_work_evt *e;
Quinn Tran2d73ac62017-12-04 14:45:02 -08003556 unsigned long flags;
Quinn Tran726b8542017-01-19 22:28:00 -08003557
Quinn Trana084fd62017-12-04 14:45:00 -08003558 if (res)
3559 ql_dbg(ql_dbg_disc, vha, 0x2066,
Quinn Tran2d73ac62017-12-04 14:45:02 -08003560 "Async done-%s fail res %x rscn gen %d ID %3phC. %8phC\n",
3561 sp->name, res, sp->gen1, ct_req->req.port_id.port_id,
Quinn Trana084fd62017-12-04 14:45:00 -08003562 ct_rsp->rsp.gpn_id.port_name);
3563 else
3564 ql_dbg(ql_dbg_disc, vha, 0x2066,
Quinn Tran2d73ac62017-12-04 14:45:02 -08003565 "Async done-%s good rscn gen %d ID %3phC. %8phC\n",
3566 sp->name, sp->gen1, ct_req->req.port_id.port_id,
Quinn Trana084fd62017-12-04 14:45:00 -08003567 ct_rsp->rsp.gpn_id.port_name);
Quinn Tran726b8542017-01-19 22:28:00 -08003568
3569 memset(&ea, 0, sizeof(ea));
3570 memcpy(ea.port_name, ct_rsp->rsp.gpn_id.port_name, WWN_SIZE);
3571 ea.sp = sp;
3572 ea.id.b.domain = ct_req->req.port_id.port_id[0];
3573 ea.id.b.area = ct_req->req.port_id.port_id[1];
3574 ea.id.b.al_pa = ct_req->req.port_id.port_id[2];
3575 ea.rc = res;
3576 ea.event = FCME_GPNID_DONE;
3577
Quinn Tran2d73ac62017-12-04 14:45:02 -08003578 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
3579 list_del(&sp->elem);
3580 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
3581
Quinn Tran25ad76b2017-12-04 14:45:01 -08003582 if (res) {
Quinn Tran5ef696a2017-12-04 14:45:05 -08003583 if (res == QLA_FUNCTION_TIMEOUT) {
Quinn Tran25ad76b2017-12-04 14:45:01 -08003584 qla24xx_post_gpnid_work(sp->vha, &ea.id);
Quinn Tran5ef696a2017-12-04 14:45:05 -08003585 sp->free(sp);
3586 return;
3587 }
Quinn Tran2d73ac62017-12-04 14:45:02 -08003588 } else if (sp->gen1) {
Quinn Tran5ef696a2017-12-04 14:45:05 -08003589 /* There was another RSCN for this Nport ID */
Quinn Tran2d73ac62017-12-04 14:45:02 -08003590 qla24xx_post_gpnid_work(sp->vha, &ea.id);
3591 sp->free(sp);
3592 return;
Quinn Tran25ad76b2017-12-04 14:45:01 -08003593 }
3594
Quinn Tran726b8542017-01-19 22:28:00 -08003595 qla2x00_fcport_event_handler(vha, &ea);
3596
Quinn Trane374f9f2017-12-28 12:33:31 -08003597 e = qla2x00_alloc_work(vha, QLA_EVT_UNMAP);
Quinn Tran726b8542017-01-19 22:28:00 -08003598 if (!e) {
3599 /* please ignore kernel warning. otherwise, we have mem leak. */
3600 if (sp->u.iocb_cmd.u.ctarg.req) {
3601 dma_free_coherent(&vha->hw->pdev->dev,
3602 sizeof(struct ct_sns_pkt),
3603 sp->u.iocb_cmd.u.ctarg.req,
3604 sp->u.iocb_cmd.u.ctarg.req_dma);
3605 sp->u.iocb_cmd.u.ctarg.req = NULL;
3606 }
3607 if (sp->u.iocb_cmd.u.ctarg.rsp) {
3608 dma_free_coherent(&vha->hw->pdev->dev,
3609 sizeof(struct ct_sns_pkt),
3610 sp->u.iocb_cmd.u.ctarg.rsp,
3611 sp->u.iocb_cmd.u.ctarg.rsp_dma);
3612 sp->u.iocb_cmd.u.ctarg.rsp = NULL;
3613 }
3614
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08003615 sp->free(sp);
Quinn Tran726b8542017-01-19 22:28:00 -08003616 return;
3617 }
3618
3619 e->u.iosb.sp = sp;
3620 qla2x00_post_work(vha, e);
3621}
3622
3623/* Get WWPN with Nport ID. */
3624int qla24xx_async_gpnid(scsi_qla_host_t *vha, port_id_t *id)
3625{
3626 int rval = QLA_FUNCTION_FAILED;
3627 struct ct_sns_req *ct_req;
Quinn Tran2d73ac62017-12-04 14:45:02 -08003628 srb_t *sp, *tsp;
Quinn Tran726b8542017-01-19 22:28:00 -08003629 struct ct_sns_pkt *ct_sns;
Quinn Tran2d73ac62017-12-04 14:45:02 -08003630 unsigned long flags;
Quinn Tran726b8542017-01-19 22:28:00 -08003631
3632 if (!vha->flags.online)
3633 goto done;
3634
3635 sp = qla2x00_get_sp(vha, NULL, GFP_KERNEL);
3636 if (!sp)
3637 goto done;
3638
3639 sp->type = SRB_CT_PTHRU_CMD;
3640 sp->name = "gpnid";
Quinn Tran2d73ac62017-12-04 14:45:02 -08003641 sp->u.iocb_cmd.u.ctarg.id = *id;
3642 sp->gen1 = 0;
Quinn Tran726b8542017-01-19 22:28:00 -08003643 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
3644
Quinn Tran2d73ac62017-12-04 14:45:02 -08003645 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
3646 list_for_each_entry(tsp, &vha->gpnid_list, elem) {
3647 if (tsp->u.iocb_cmd.u.ctarg.id.b24 == id->b24) {
3648 tsp->gen1++;
3649 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
3650 sp->free(sp);
3651 goto done;
3652 }
3653 }
3654 list_add_tail(&sp->elem, &vha->gpnid_list);
3655 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
3656
Quinn Tran726b8542017-01-19 22:28:00 -08003657 sp->u.iocb_cmd.u.ctarg.req = dma_alloc_coherent(&vha->hw->pdev->dev,
3658 sizeof(struct ct_sns_pkt), &sp->u.iocb_cmd.u.ctarg.req_dma,
3659 GFP_KERNEL);
3660 if (!sp->u.iocb_cmd.u.ctarg.req) {
Quinn Tran83548fe2017-06-02 09:12:01 -07003661 ql_log(ql_log_warn, vha, 0xd041,
3662 "Failed to allocate ct_sns request.\n");
Quinn Tran726b8542017-01-19 22:28:00 -08003663 goto done_free_sp;
3664 }
3665
3666 sp->u.iocb_cmd.u.ctarg.rsp = dma_alloc_coherent(&vha->hw->pdev->dev,
3667 sizeof(struct ct_sns_pkt), &sp->u.iocb_cmd.u.ctarg.rsp_dma,
3668 GFP_KERNEL);
3669 if (!sp->u.iocb_cmd.u.ctarg.rsp) {
Quinn Tran83548fe2017-06-02 09:12:01 -07003670 ql_log(ql_log_warn, vha, 0xd042,
3671 "Failed to allocate ct_sns request.\n");
Quinn Tran726b8542017-01-19 22:28:00 -08003672 goto done_free_sp;
3673 }
3674
3675 ct_sns = (struct ct_sns_pkt *)sp->u.iocb_cmd.u.ctarg.rsp;
3676 memset(ct_sns, 0, sizeof(*ct_sns));
3677
3678 ct_sns = (struct ct_sns_pkt *)sp->u.iocb_cmd.u.ctarg.req;
3679 /* CT_IU preamble */
3680 ct_req = qla2x00_prep_ct_req(ct_sns, GPN_ID_CMD, GPN_ID_RSP_SIZE);
3681
3682 /* GPN_ID req */
3683 ct_req->req.port_id.port_id[0] = id->b.domain;
3684 ct_req->req.port_id.port_id[1] = id->b.area;
3685 ct_req->req.port_id.port_id[2] = id->b.al_pa;
3686
3687 sp->u.iocb_cmd.u.ctarg.req_size = GPN_ID_REQ_SIZE;
3688 sp->u.iocb_cmd.u.ctarg.rsp_size = GPN_ID_RSP_SIZE;
3689 sp->u.iocb_cmd.u.ctarg.nport_handle = NPH_SNS;
3690
3691 sp->u.iocb_cmd.timeout = qla2x00_async_iocb_timeout;
3692 sp->done = qla2x00_async_gpnid_sp_done;
3693
3694 rval = qla2x00_start_sp(sp);
3695 if (rval != QLA_SUCCESS)
3696 goto done_free_sp;
3697
Quinn Tran83548fe2017-06-02 09:12:01 -07003698 ql_dbg(ql_dbg_disc, vha, 0x2067,
3699 "Async-%s hdl=%x ID %3phC.\n", sp->name,
3700 sp->handle, ct_req->req.port_id.port_id);
Quinn Tran726b8542017-01-19 22:28:00 -08003701 return rval;
3702
3703done_free_sp:
3704 if (sp->u.iocb_cmd.u.ctarg.req) {
3705 dma_free_coherent(&vha->hw->pdev->dev,
3706 sizeof(struct ct_sns_pkt),
3707 sp->u.iocb_cmd.u.ctarg.req,
3708 sp->u.iocb_cmd.u.ctarg.req_dma);
3709 sp->u.iocb_cmd.u.ctarg.req = NULL;
3710 }
3711 if (sp->u.iocb_cmd.u.ctarg.rsp) {
3712 dma_free_coherent(&vha->hw->pdev->dev,
3713 sizeof(struct ct_sns_pkt),
3714 sp->u.iocb_cmd.u.ctarg.rsp,
3715 sp->u.iocb_cmd.u.ctarg.rsp_dma);
3716 sp->u.iocb_cmd.u.ctarg.rsp = NULL;
3717 }
3718
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08003719 sp->free(sp);
Quinn Tran726b8542017-01-19 22:28:00 -08003720done:
3721 return rval;
3722}
Duane Grigsbyd3bae932017-06-21 13:48:44 -07003723
3724void qla24xx_handle_gffid_event(scsi_qla_host_t *vha, struct event_arg *ea)
3725{
3726 fc_port_t *fcport = ea->fcport;
3727
3728 qla24xx_post_gnl_work(vha, fcport);
3729}
3730
3731void qla24xx_async_gffid_sp_done(void *s, int res)
3732{
3733 struct srb *sp = s;
3734 struct scsi_qla_host *vha = sp->vha;
3735 fc_port_t *fcport = sp->fcport;
3736 struct ct_sns_rsp *ct_rsp;
3737 struct event_arg ea;
3738
3739 ql_dbg(ql_dbg_disc, vha, 0x2133,
3740 "Async done-%s res %x ID %x. %8phC\n",
3741 sp->name, res, fcport->d_id.b24, fcport->port_name);
3742
3743 fcport->flags &= ~FCF_ASYNC_SENT;
3744 ct_rsp = &fcport->ct_desc.ct_sns->p.rsp;
3745 /*
3746 * FC-GS-7, 5.2.3.12 FC-4 Features - format
3747 * The format of the FC-4 Features object, as defined by the FC-4,
3748 * Shall be an array of 4-bit values, one for each type code value
3749 */
3750 if (!res) {
3751 if (ct_rsp->rsp.gff_id.fc4_features[GFF_FCP_SCSI_OFFSET] & 0xf) {
3752 /* w1 b00:03 */
3753 fcport->fc4_type =
3754 ct_rsp->rsp.gff_id.fc4_features[GFF_FCP_SCSI_OFFSET];
3755 fcport->fc4_type &= 0xf;
3756 }
3757
3758 if (ct_rsp->rsp.gff_id.fc4_features[GFF_NVME_OFFSET] & 0xf) {
3759 /* w5 [00:03]/28h */
3760 fcport->fc4f_nvme =
3761 ct_rsp->rsp.gff_id.fc4_features[GFF_NVME_OFFSET];
3762 fcport->fc4f_nvme &= 0xf;
3763 }
3764 }
3765
3766 memset(&ea, 0, sizeof(ea));
3767 ea.sp = sp;
3768 ea.fcport = sp->fcport;
3769 ea.rc = res;
3770 ea.event = FCME_GFFID_DONE;
3771
3772 qla2x00_fcport_event_handler(vha, &ea);
3773 sp->free(sp);
3774}
3775
3776/* Get FC4 Feature with Nport ID. */
3777int qla24xx_async_gffid(scsi_qla_host_t *vha, fc_port_t *fcport)
3778{
3779 int rval = QLA_FUNCTION_FAILED;
3780 struct ct_sns_req *ct_req;
3781 srb_t *sp;
3782
3783 if (!vha->flags.online)
3784 return rval;
3785
3786 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
3787 if (!sp)
3788 return rval;
3789
3790 fcport->flags |= FCF_ASYNC_SENT;
3791 sp->type = SRB_CT_PTHRU_CMD;
3792 sp->name = "gffid";
3793 sp->gen1 = fcport->rscn_gen;
3794 sp->gen2 = fcport->login_gen;
3795
3796 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
3797
3798 /* CT_IU preamble */
3799 ct_req = qla2x00_prep_ct_req(fcport->ct_desc.ct_sns, GFF_ID_CMD,
3800 GFF_ID_RSP_SIZE);
3801
3802 ct_req->req.gff_id.port_id[0] = fcport->d_id.b.domain;
3803 ct_req->req.gff_id.port_id[1] = fcport->d_id.b.area;
3804 ct_req->req.gff_id.port_id[2] = fcport->d_id.b.al_pa;
3805
3806 sp->u.iocb_cmd.u.ctarg.req = fcport->ct_desc.ct_sns;
3807 sp->u.iocb_cmd.u.ctarg.req_dma = fcport->ct_desc.ct_sns_dma;
3808 sp->u.iocb_cmd.u.ctarg.rsp = fcport->ct_desc.ct_sns;
3809 sp->u.iocb_cmd.u.ctarg.rsp_dma = fcport->ct_desc.ct_sns_dma;
3810 sp->u.iocb_cmd.u.ctarg.req_size = GFF_ID_REQ_SIZE;
3811 sp->u.iocb_cmd.u.ctarg.rsp_size = GFF_ID_RSP_SIZE;
3812 sp->u.iocb_cmd.u.ctarg.nport_handle = NPH_SNS;
3813
3814 sp->u.iocb_cmd.timeout = qla2x00_async_iocb_timeout;
3815 sp->done = qla24xx_async_gffid_sp_done;
3816
3817 rval = qla2x00_start_sp(sp);
3818 if (rval != QLA_SUCCESS)
3819 goto done_free_sp;
3820
3821 ql_dbg(ql_dbg_disc, vha, 0x2132,
3822 "Async-%s hdl=%x %8phC.\n", sp->name,
3823 sp->handle, fcport->port_name);
3824
3825 return rval;
3826done_free_sp:
3827 sp->free(sp);
3828 fcport->flags &= ~FCF_ASYNC_SENT;
3829 return rval;
3830}
Quinn Trana4239942017-12-28 12:33:26 -08003831
3832/* GPN_FT + GNN_FT*/
3833static int qla2x00_is_a_vp(scsi_qla_host_t *vha, u64 wwn)
3834{
3835 struct qla_hw_data *ha = vha->hw;
3836 scsi_qla_host_t *vp;
3837 unsigned long flags;
3838 u64 twwn;
3839 int rc = 0;
3840
3841 if (!ha->num_vhosts)
3842 return 0;
3843
3844 spin_lock_irqsave(&ha->vport_slock, flags);
3845 list_for_each_entry(vp, &ha->vp_list, list) {
3846 twwn = wwn_to_u64(vp->port_name);
3847 if (wwn == twwn) {
3848 rc = 1;
3849 break;
3850 }
3851 }
3852 spin_unlock_irqrestore(&ha->vport_slock, flags);
3853
3854 return rc;
3855}
3856
3857void qla24xx_async_gnnft_done(scsi_qla_host_t *vha, srb_t *sp)
3858{
3859 fc_port_t *fcport;
3860 u32 i, rc;
3861 bool found;
3862 u8 fc4type = sp->gen2;
3863 struct fab_scan_rp *rp;
Quinn Tranf352eeb2017-12-28 12:33:35 -08003864 unsigned long flags;
Quinn Trana4239942017-12-28 12:33:26 -08003865
3866 ql_dbg(ql_dbg_disc, vha, 0xffff,
3867 "%s enter\n", __func__);
3868
3869 if (sp->gen1 != vha->hw->base_qpair->chip_reset) {
3870 ql_dbg(ql_dbg_disc, vha, 0xffff,
3871 "%s scan stop due to chip reset %x/%x\n",
3872 sp->name, sp->gen1, vha->hw->base_qpair->chip_reset);
3873 goto out;
3874 }
3875
3876 rc = sp->rc;
3877 if (rc) {
3878 ql_dbg(ql_dbg_disc, vha, 0xffff,
3879 "GPNFT failed. FC4type %x. Rescanning.\n",
3880 fc4type);
Quinn Trancf055fb2017-12-28 12:33:33 -08003881 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Quinn Trana4239942017-12-28 12:33:26 -08003882 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
3883 goto out;
3884 }
3885
3886 list_for_each_entry(fcport, &vha->vp_fcports, list)
3887 fcport->scan_state = QLA_FCPORT_SCAN;
3888
3889 for (i = 0; i < vha->hw->max_fibre_devices; i++) {
3890 u64 wwn;
3891
3892 rp = &vha->scan.l[i];
3893 found = false;
3894
3895 wwn = wwn_to_u64(rp->port_name);
3896 if (wwn == 0)
3897 continue;
3898
3899 if (!memcmp(rp->port_name, vha->port_name, WWN_SIZE))
3900 continue;
3901
3902 /* Bypass reserved domain fields. */
3903 if ((rp->id.b.domain & 0xf0) == 0xf0)
3904 continue;
3905
3906 /* Bypass virtual ports of the same host. */
3907 if (qla2x00_is_a_vp(vha, wwn))
3908 continue;
3909
3910 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3911 if (memcmp(rp->port_name, fcport->port_name, WWN_SIZE))
3912 continue;
3913 fcport->scan_state = QLA_FCPORT_FOUND;
3914 fcport->d_id.b24 = rp->id.b24;
3915 found = true;
3916 /*
3917 * If device was not a fabric device before.
3918 */
3919 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
3920 qla2x00_clear_loop_id(fcport);
3921 fcport->flags |= FCF_FABRIC_DEVICE;
3922 }
3923 break;
3924 }
3925
3926 if (!found) {
3927 ql_dbg(ql_dbg_disc, vha, 0xffff,
3928 "%s %d %8phC post new sess\n",
3929 __func__, __LINE__, rp->port_name);
3930 qla24xx_post_newsess_work(vha, &rp->id, rp->port_name,
3931 rp->node_name, NULL, fc4type);
3932 }
3933 }
3934
3935 /*
3936 * Logout all previous fabric dev marked lost, except FCP2 devices.
3937 */
3938 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3939 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
3940 continue;
3941
Quinn Tranf352eeb2017-12-28 12:33:35 -08003942 if (fcport->scan_state != QLA_FCPORT_FOUND) {
Quinn Trana4239942017-12-28 12:33:26 -08003943 if ((qla_dual_mode_enabled(vha) ||
3944 qla_ini_mode_enabled(vha)) &&
3945 atomic_read(&fcport->state) == FCS_ONLINE) {
3946 qla2x00_mark_device_lost(vha, fcport,
3947 ql2xplogiabsentdevice, 0);
Quinn Tranf352eeb2017-12-28 12:33:35 -08003948
Quinn Trana4239942017-12-28 12:33:26 -08003949 if (fcport->loop_id != FC_NO_LOOP_ID &&
Quinn Tranf352eeb2017-12-28 12:33:35 -08003950 (fcport->flags & FCF_FCP2_DEVICE) == 0) {
Quinn Trana4239942017-12-28 12:33:26 -08003951 ql_dbg(ql_dbg_disc, vha, 0x20f0,
3952 "%s %d %8phC post del sess\n",
3953 __func__, __LINE__,
3954 fcport->port_name);
3955
3956 qlt_schedule_sess_for_deletion_lock
3957 (fcport);
3958 continue;
3959 }
3960 }
Quinn Tranf352eeb2017-12-28 12:33:35 -08003961 } else
Quinn Trana4239942017-12-28 12:33:26 -08003962 qla24xx_fcport_handle_login(vha, fcport);
3963 }
3964
3965out:
Quinn Trane374f9f2017-12-28 12:33:31 -08003966 qla24xx_sp_unmap(vha, sp);
Quinn Tranf352eeb2017-12-28 12:33:35 -08003967
3968 spin_lock_irqsave(&vha->work_lock, flags);
3969 vha->scan.scan_flags &= ~SF_SCANNING;
3970 spin_unlock_irqrestore(&vha->work_lock, flags);
Quinn Trana4239942017-12-28 12:33:26 -08003971}
3972
3973static void qla2x00_async_gpnft_gnnft_sp_done(void *s, int res)
3974{
3975 struct srb *sp = s;
3976 struct scsi_qla_host *vha = sp->vha;
3977 struct qla_work_evt *e;
3978 struct ct_sns_req *ct_req =
3979 (struct ct_sns_req *)sp->u.iocb_cmd.u.ctarg.req;
3980 struct ct_sns_gpnft_rsp *ct_rsp =
3981 (struct ct_sns_gpnft_rsp *)sp->u.iocb_cmd.u.ctarg.rsp;
3982 struct ct_sns_gpn_ft_data *d = &ct_rsp->entries[0];
3983 struct fab_scan_rp *rp;
3984 int i, j, k;
3985 u16 cmd = be16_to_cpu(ct_req->command);
3986
3987 /* gen2 field is holding the fc4type */
3988 ql_dbg(ql_dbg_disc, vha, 0xffff,
3989 "Async done-%s res %x FC4Type %x\n",
3990 sp->name, res, sp->gen2);
3991
Quinn Trancf055fb2017-12-28 12:33:33 -08003992 if (res) {
3993 unsigned long flags;
3994
3995 ql_dbg(ql_dbg_disc, sp->vha, 0xffff,
3996 "Async done-%s timed out.\n",
3997 sp->name);
3998 sp->free(sp);
Quinn Tranf352eeb2017-12-28 12:33:35 -08003999 spin_lock_irqsave(&vha->work_lock, flags);
4000 vha->scan.scan_flags &= ~SF_SCANNING;
4001 spin_unlock_irqrestore(&vha->work_lock, flags);
Quinn Trancf055fb2017-12-28 12:33:33 -08004002 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
4003 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4004 qla2xxx_wake_dpc(vha);
4005 return;
4006 }
4007
Quinn Trana4239942017-12-28 12:33:26 -08004008 if (!res) {
4009 port_id_t id;
4010 u64 wwn;
4011
4012 j = 0;
4013 for (i = 0; i < vha->hw->max_fibre_devices; i++) {
4014 d = &ct_rsp->entries[i];
4015
4016 id.b.rsvd_1 = 0;
4017 id.b.domain = d->port_id[0];
4018 id.b.area = d->port_id[1];
4019 id.b.al_pa = d->port_id[2];
4020 wwn = wwn_to_u64(d->port_name);
4021
4022 if (id.b24 == 0 || wwn == 0)
4023 continue;
4024
4025 if (cmd == GPN_FT_CMD) {
4026 rp = &vha->scan.l[j];
4027 rp->id = id;
4028 memcpy(rp->port_name, d->port_name, 8);
4029 j++;
4030 } else {/* GNN_FT_CMD */
4031 for (k = 0; k < vha->hw->max_fibre_devices;
4032 k++) {
4033 rp = &vha->scan.l[k];
4034 if (id.b24 == rp->id.b24) {
4035 memcpy(rp->node_name,
4036 d->port_name, 8);
4037 break;
4038 }
4039 }
4040 }
4041 }
4042 }
4043
4044 if (cmd == GPN_FT_CMD)
4045 e = qla2x00_alloc_work(vha, QLA_EVT_GPNFT_DONE);
4046 else
4047 e = qla2x00_alloc_work(vha, QLA_EVT_GNNFT_DONE);
4048 if (!e) {
4049 /* please ignore kernel warning. Otherwise, we have mem leak. */
4050 if (sp->u.iocb_cmd.u.ctarg.req) {
4051 dma_free_coherent(&vha->hw->pdev->dev,
4052 sizeof(struct ct_sns_pkt),
4053 sp->u.iocb_cmd.u.ctarg.req,
4054 sp->u.iocb_cmd.u.ctarg.req_dma);
4055 sp->u.iocb_cmd.u.ctarg.req = NULL;
4056 }
4057 if (sp->u.iocb_cmd.u.ctarg.rsp) {
4058 dma_free_coherent(&vha->hw->pdev->dev,
4059 sizeof(struct ct_sns_pkt),
4060 sp->u.iocb_cmd.u.ctarg.rsp,
4061 sp->u.iocb_cmd.u.ctarg.rsp_dma);
4062 sp->u.iocb_cmd.u.ctarg.rsp = NULL;
4063 }
4064
4065 ql_dbg(ql_dbg_disc, vha, 0xffff,
4066 "Async done-%s unable to alloc work element\n",
4067 sp->name);
4068 sp->free(sp);
Quinn Trancf055fb2017-12-28 12:33:33 -08004069 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Quinn Trana4239942017-12-28 12:33:26 -08004070 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4071 return;
4072 }
4073
4074 sp->rc = res;
4075 e->u.iosb.sp = sp;
4076
4077 qla2x00_post_work(vha, e);
4078}
4079
4080/*
4081 * Get WWNN list for fc4_type
4082 *
4083 * It is assumed the same SRB is re-used from GPNFT to avoid
4084 * mem free & re-alloc
4085 */
4086static int qla24xx_async_gnnft(scsi_qla_host_t *vha, struct srb *sp,
4087 u8 fc4_type)
4088{
4089 int rval = QLA_FUNCTION_FAILED;
4090 struct ct_sns_req *ct_req;
4091 struct ct_sns_pkt *ct_sns;
4092
Quinn Tranf352eeb2017-12-28 12:33:35 -08004093 if (!vha->flags.online) {
4094 vha->scan.scan_flags &= ~SF_SCANNING;
Quinn Trana4239942017-12-28 12:33:26 -08004095 goto done_free_sp;
Quinn Tranf352eeb2017-12-28 12:33:35 -08004096 }
Quinn Trana4239942017-12-28 12:33:26 -08004097
4098 if (!sp->u.iocb_cmd.u.ctarg.req || !sp->u.iocb_cmd.u.ctarg.rsp) {
4099 ql_log(ql_log_warn, vha, 0xffff,
4100 "%s: req %p rsp %p are not setup\n",
4101 __func__, sp->u.iocb_cmd.u.ctarg.req,
4102 sp->u.iocb_cmd.u.ctarg.rsp);
Quinn Tranf352eeb2017-12-28 12:33:35 -08004103 vha->scan.scan_flags &= ~SF_SCANNING;
Quinn Trana4239942017-12-28 12:33:26 -08004104 WARN_ON(1);
4105 goto done_free_sp;
4106 }
4107 sp->type = SRB_CT_PTHRU_CMD;
4108 sp->name = "gnnft";
4109 sp->gen1 = vha->hw->base_qpair->chip_reset;
4110 sp->gen2 = fc4_type;
4111 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
4112
4113 memset(sp->u.iocb_cmd.u.ctarg.rsp, 0, sp->u.iocb_cmd.u.ctarg.rsp_size);
4114 memset(sp->u.iocb_cmd.u.ctarg.req, 0, sp->u.iocb_cmd.u.ctarg.req_size);
4115
4116 ct_sns = (struct ct_sns_pkt *)sp->u.iocb_cmd.u.ctarg.req;
4117 /* CT_IU preamble */
4118 ct_req = qla2x00_prep_ct_req(ct_sns, GNN_FT_CMD,
4119 sp->u.iocb_cmd.u.ctarg.rsp_size);
4120
4121 /* GPN_FT req */
4122 ct_req->req.gpn_ft.port_type = fc4_type;
4123
4124 sp->u.iocb_cmd.u.ctarg.req_size = GNN_FT_REQ_SIZE;
4125 sp->u.iocb_cmd.u.ctarg.nport_handle = NPH_SNS;
4126
4127 sp->u.iocb_cmd.timeout = qla2x00_async_iocb_timeout;
4128 sp->done = qla2x00_async_gpnft_gnnft_sp_done;
4129
4130 rval = qla2x00_start_sp(sp);
4131 if (rval != QLA_SUCCESS)
4132 goto done_free_sp;
4133
4134 ql_dbg(ql_dbg_disc, vha, 0xffff,
4135 "Async-%s hdl=%x FC4Type %x.\n", sp->name,
4136 sp->handle, ct_req->req.gpn_ft.port_type);
4137 return rval;
4138
4139done_free_sp:
4140 if (sp->u.iocb_cmd.u.ctarg.req) {
4141 dma_free_coherent(&vha->hw->pdev->dev,
4142 sizeof(struct ct_sns_pkt),
4143 sp->u.iocb_cmd.u.ctarg.req,
4144 sp->u.iocb_cmd.u.ctarg.req_dma);
4145 sp->u.iocb_cmd.u.ctarg.req = NULL;
4146 }
4147 if (sp->u.iocb_cmd.u.ctarg.rsp) {
4148 dma_free_coherent(&vha->hw->pdev->dev,
4149 sizeof(struct ct_sns_pkt),
4150 sp->u.iocb_cmd.u.ctarg.rsp,
4151 sp->u.iocb_cmd.u.ctarg.rsp_dma);
4152 sp->u.iocb_cmd.u.ctarg.rsp = NULL;
4153 }
4154
4155 sp->free(sp);
4156
4157 return rval;
4158} /* GNNFT */
4159
4160void qla24xx_async_gpnft_done(scsi_qla_host_t *vha, srb_t *sp)
4161{
4162 ql_dbg(ql_dbg_disc, vha, 0xffff,
4163 "%s enter\n", __func__);
4164 del_timer(&sp->u.iocb_cmd.timer);
4165 qla24xx_async_gnnft(vha, sp, sp->gen2);
4166}
4167
4168/* Get WWPN list for certain fc4_type */
4169int qla24xx_async_gpnft(scsi_qla_host_t *vha, u8 fc4_type)
4170{
4171 int rval = QLA_FUNCTION_FAILED;
4172 struct ct_sns_req *ct_req;
4173 srb_t *sp;
4174 struct ct_sns_pkt *ct_sns;
4175 u32 rspsz;
Quinn Tranf352eeb2017-12-28 12:33:35 -08004176 unsigned long flags;
Quinn Trana4239942017-12-28 12:33:26 -08004177
4178 if (!vha->flags.online)
4179 return rval;
4180
Quinn Tranf352eeb2017-12-28 12:33:35 -08004181 spin_lock_irqsave(&vha->work_lock, flags);
4182 if (vha->scan.scan_flags & SF_SCANNING) {
4183 spin_unlock_irqrestore(&vha->work_lock, flags);
4184 ql_dbg(ql_dbg_disc, vha, 0xffff, "scan active\n");
Quinn Trana4239942017-12-28 12:33:26 -08004185 return rval;
Quinn Tranf352eeb2017-12-28 12:33:35 -08004186 }
4187 vha->scan.scan_flags |= SF_SCANNING;
4188 spin_unlock_irqrestore(&vha->work_lock, flags);
Quinn Trana4239942017-12-28 12:33:26 -08004189
Quinn Tranf352eeb2017-12-28 12:33:35 -08004190 sp = qla2x00_get_sp(vha, NULL, GFP_KERNEL);
4191 if (!sp) {
4192 vha->scan.scan_flags &= ~SF_SCANNING;
4193 return rval;
4194 }
Quinn Trana4239942017-12-28 12:33:26 -08004195
4196 sp->type = SRB_CT_PTHRU_CMD;
4197 sp->name = "gpnft";
4198 sp->gen1 = vha->hw->base_qpair->chip_reset;
4199 sp->gen2 = fc4_type;
4200 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
4201
4202 sp->u.iocb_cmd.u.ctarg.req = dma_zalloc_coherent(&vha->hw->pdev->dev,
4203 sizeof(struct ct_sns_pkt), &sp->u.iocb_cmd.u.ctarg.req_dma,
4204 GFP_KERNEL);
4205 if (!sp->u.iocb_cmd.u.ctarg.req) {
4206 ql_log(ql_log_warn, vha, 0xffff,
4207 "Failed to allocate ct_sns request.\n");
Quinn Tranf352eeb2017-12-28 12:33:35 -08004208 vha->scan.scan_flags &= ~SF_SCANNING;
Quinn Trana4239942017-12-28 12:33:26 -08004209 goto done_free_sp;
4210 }
4211
4212 rspsz = sizeof(struct ct_sns_gpnft_rsp) +
4213 ((vha->hw->max_fibre_devices - 1) *
4214 sizeof(struct ct_sns_gpn_ft_data));
4215
4216 sp->u.iocb_cmd.u.ctarg.rsp = dma_zalloc_coherent(&vha->hw->pdev->dev,
4217 rspsz, &sp->u.iocb_cmd.u.ctarg.rsp_dma, GFP_KERNEL);
4218 if (!sp->u.iocb_cmd.u.ctarg.rsp) {
4219 ql_log(ql_log_warn, vha, 0xffff,
4220 "Failed to allocate ct_sns request.\n");
Quinn Tranf352eeb2017-12-28 12:33:35 -08004221 vha->scan.scan_flags &= ~SF_SCANNING;
Quinn Trana4239942017-12-28 12:33:26 -08004222 goto done_free_sp;
4223 }
4224
4225 memset(vha->scan.l, 0, vha->scan.size);
4226
4227 ct_sns = (struct ct_sns_pkt *)sp->u.iocb_cmd.u.ctarg.req;
4228 /* CT_IU preamble */
4229 ct_req = qla2x00_prep_ct_req(ct_sns, GPN_FT_CMD, rspsz);
4230
4231 /* GPN_FT req */
4232 ct_req->req.gpn_ft.port_type = fc4_type;
4233
4234 sp->u.iocb_cmd.u.ctarg.req_size = GPN_FT_REQ_SIZE;
4235 sp->u.iocb_cmd.u.ctarg.rsp_size = rspsz;
4236 sp->u.iocb_cmd.u.ctarg.nport_handle = NPH_SNS;
4237
4238 sp->u.iocb_cmd.timeout = qla2x00_async_iocb_timeout;
4239 sp->done = qla2x00_async_gpnft_gnnft_sp_done;
4240
4241 rval = qla2x00_start_sp(sp);
Quinn Tranf352eeb2017-12-28 12:33:35 -08004242 if (rval != QLA_SUCCESS) {
4243 vha->scan.scan_flags &= ~SF_SCANNING;
Quinn Trana4239942017-12-28 12:33:26 -08004244 goto done_free_sp;
Quinn Tranf352eeb2017-12-28 12:33:35 -08004245 }
Quinn Trana4239942017-12-28 12:33:26 -08004246
4247 ql_dbg(ql_dbg_disc, vha, 0xffff,
4248 "Async-%s hdl=%x FC4Type %x.\n", sp->name,
4249 sp->handle, ct_req->req.gpn_ft.port_type);
4250 return rval;
4251
4252done_free_sp:
4253 if (sp->u.iocb_cmd.u.ctarg.req) {
4254 dma_free_coherent(&vha->hw->pdev->dev,
4255 sizeof(struct ct_sns_pkt),
4256 sp->u.iocb_cmd.u.ctarg.req,
4257 sp->u.iocb_cmd.u.ctarg.req_dma);
4258 sp->u.iocb_cmd.u.ctarg.req = NULL;
4259 }
4260 if (sp->u.iocb_cmd.u.ctarg.rsp) {
4261 dma_free_coherent(&vha->hw->pdev->dev,
4262 sizeof(struct ct_sns_pkt),
4263 sp->u.iocb_cmd.u.ctarg.rsp,
4264 sp->u.iocb_cmd.u.ctarg.rsp_dma);
4265 sp->u.iocb_cmd.u.ctarg.rsp = NULL;
4266 }
4267
4268 sp->free(sp);
4269
4270 return rval;
4271}
4272
Quinn Tranf352eeb2017-12-28 12:33:35 -08004273void qla_scan_work_fn(struct work_struct *work)
4274{
4275 struct fab_scan *s = container_of(to_delayed_work(work),
4276 struct fab_scan, scan_work);
4277 struct scsi_qla_host *vha = container_of(s, struct scsi_qla_host,
4278 scan);
4279 unsigned long flags;
4280
4281 ql_dbg(ql_dbg_disc, vha, 0xffff,
4282 "%s: schedule loop resync\n", __func__);
4283 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
4284 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4285 qla2xxx_wake_dpc(vha);
4286 spin_lock_irqsave(&vha->work_lock, flags);
4287 vha->scan.scan_flags &= ~SF_QUEUED;
4288 spin_unlock_irqrestore(&vha->work_lock, flags);
4289}
4290
Quinn Trana4239942017-12-28 12:33:26 -08004291/* GNN_ID */
4292void qla24xx_handle_gnnid_event(scsi_qla_host_t *vha, struct event_arg *ea)
4293{
4294 qla24xx_post_gnl_work(vha, ea->fcport);
4295}
4296
4297static void qla2x00_async_gnnid_sp_done(void *s, int res)
4298{
4299 struct srb *sp = s;
4300 struct scsi_qla_host *vha = sp->vha;
4301 fc_port_t *fcport = sp->fcport;
4302 u8 *node_name = fcport->ct_desc.ct_sns->p.rsp.rsp.gnn_id.node_name;
4303 struct event_arg ea;
4304 u64 wwnn;
4305
4306 fcport->flags &= ~FCF_ASYNC_SENT;
4307 wwnn = wwn_to_u64(node_name);
4308 if (wwnn)
4309 memcpy(fcport->node_name, node_name, WWN_SIZE);
4310
4311 memset(&ea, 0, sizeof(ea));
4312 ea.fcport = fcport;
4313 ea.sp = sp;
4314 ea.rc = res;
4315 ea.event = FCME_GNNID_DONE;
4316
4317 ql_dbg(ql_dbg_disc, vha, 0x204f,
4318 "Async done-%s res %x, WWPN %8phC %8phC\n",
4319 sp->name, res, fcport->port_name, fcport->node_name);
4320
4321 qla2x00_fcport_event_handler(vha, &ea);
4322
4323 sp->free(sp);
4324}
4325
4326int qla24xx_async_gnnid(scsi_qla_host_t *vha, fc_port_t *fcport)
4327{
4328 int rval = QLA_FUNCTION_FAILED;
4329 struct ct_sns_req *ct_req;
4330 srb_t *sp;
4331
4332 if (!vha->flags.online)
4333 goto done;
4334
4335 fcport->flags |= FCF_ASYNC_SENT;
4336 fcport->disc_state = DSC_GNN_ID;
4337 sp = qla2x00_get_sp(vha, fcport, GFP_ATOMIC);
4338 if (!sp)
4339 goto done;
4340
4341 sp->type = SRB_CT_PTHRU_CMD;
4342 sp->name = "gnnid";
4343 sp->gen1 = fcport->rscn_gen;
4344 sp->gen2 = fcport->login_gen;
4345
4346 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
4347
4348 /* CT_IU preamble */
4349 ct_req = qla2x00_prep_ct_req(fcport->ct_desc.ct_sns, GNN_ID_CMD,
4350 GNN_ID_RSP_SIZE);
4351
4352 /* GNN_ID req */
4353 ct_req->req.port_id.port_id[0] = fcport->d_id.b.domain;
4354 ct_req->req.port_id.port_id[1] = fcport->d_id.b.area;
4355 ct_req->req.port_id.port_id[2] = fcport->d_id.b.al_pa;
4356
4357
4358 /* req & rsp use the same buffer */
4359 sp->u.iocb_cmd.u.ctarg.req = fcport->ct_desc.ct_sns;
4360 sp->u.iocb_cmd.u.ctarg.req_dma = fcport->ct_desc.ct_sns_dma;
4361 sp->u.iocb_cmd.u.ctarg.rsp = fcport->ct_desc.ct_sns;
4362 sp->u.iocb_cmd.u.ctarg.rsp_dma = fcport->ct_desc.ct_sns_dma;
4363 sp->u.iocb_cmd.u.ctarg.req_size = GNN_ID_REQ_SIZE;
4364 sp->u.iocb_cmd.u.ctarg.rsp_size = GNN_ID_RSP_SIZE;
4365 sp->u.iocb_cmd.u.ctarg.nport_handle = NPH_SNS;
4366
4367 sp->u.iocb_cmd.timeout = qla2x00_async_iocb_timeout;
4368 sp->done = qla2x00_async_gnnid_sp_done;
4369
4370 rval = qla2x00_start_sp(sp);
4371 if (rval != QLA_SUCCESS)
4372 goto done_free_sp;
4373 ql_dbg(ql_dbg_disc, vha, 0xffff,
4374 "Async-%s - %8phC hdl=%x loopid=%x portid %06x.\n",
4375 sp->name, fcport->port_name,
4376 sp->handle, fcport->loop_id, fcport->d_id.b24);
4377 return rval;
4378
4379done_free_sp:
4380 sp->free(sp);
4381done:
4382 fcport->flags &= ~FCF_ASYNC_SENT;
4383 return rval;
4384}
4385
4386int qla24xx_post_gnnid_work(struct scsi_qla_host *vha, fc_port_t *fcport)
4387{
4388 struct qla_work_evt *e;
4389 int ls;
4390
4391 ls = atomic_read(&vha->loop_state);
4392 if (((ls != LOOP_READY) && (ls != LOOP_UP)) ||
4393 test_bit(UNLOADING, &vha->dpc_flags))
4394 return 0;
4395
4396 e = qla2x00_alloc_work(vha, QLA_EVT_GNNID);
4397 if (!e)
4398 return QLA_FUNCTION_FAILED;
4399
4400 e->u.fcport.fcport = fcport;
4401 return qla2x00_post_work(vha, e);
4402}
4403
4404/* GPFN_ID */
4405void qla24xx_handle_gfpnid_event(scsi_qla_host_t *vha, struct event_arg *ea)
4406{
4407 fc_port_t *fcport = ea->fcport;
4408
4409 ql_dbg(ql_dbg_disc, vha, 0xffff,
Quinn Tranf352eeb2017-12-28 12:33:35 -08004410 "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d fcpcnt %d\n",
4411 __func__, fcport->port_name, fcport->disc_state,
4412 fcport->fw_login_state, ea->rc, fcport->login_gen, ea->sp->gen2,
4413 fcport->rscn_gen, ea->sp->gen1, vha->fcport_count);
Quinn Trana4239942017-12-28 12:33:26 -08004414
4415 if (fcport->disc_state == DSC_DELETE_PEND)
4416 return;
4417
4418 if (ea->sp->gen2 != fcport->login_gen) {
4419 /* target side must have changed it. */
4420 ql_dbg(ql_dbg_disc, vha, 0x20d3,
Quinn Tranf352eeb2017-12-28 12:33:35 -08004421 "%s %8phC generation changed\n",
4422 __func__, fcport->port_name);
Quinn Trana4239942017-12-28 12:33:26 -08004423 return;
4424 } else if (ea->sp->gen1 != fcport->rscn_gen) {
4425 ql_dbg(ql_dbg_disc, vha, 0x20d4, "%s %d %8phC post gidpn\n",
4426 __func__, __LINE__, fcport->port_name);
4427 qla24xx_post_gidpn_work(vha, fcport);
4428 return;
4429 }
4430
4431 qla24xx_post_gpsc_work(vha, fcport);
4432}
4433
4434static void qla2x00_async_gfpnid_sp_done(void *s, int res)
4435{
4436 struct srb *sp = s;
4437 struct scsi_qla_host *vha = sp->vha;
4438 fc_port_t *fcport = sp->fcport;
4439 u8 *fpn = fcport->ct_desc.ct_sns->p.rsp.rsp.gfpn_id.port_name;
4440 struct event_arg ea;
4441 u64 wwn;
4442
4443 fcport->flags &= ~FCF_ASYNC_SENT;
4444 wwn = wwn_to_u64(fpn);
4445 if (wwn)
4446 memcpy(fcport->fabric_port_name, fpn, WWN_SIZE);
4447
4448 memset(&ea, 0, sizeof(ea));
4449 ea.fcport = fcport;
4450 ea.sp = sp;
4451 ea.rc = res;
4452 ea.event = FCME_GFPNID_DONE;
4453
4454 ql_dbg(ql_dbg_disc, vha, 0x204f,
4455 "Async done-%s res %x, WWPN %8phC %8phC\n",
4456 sp->name, res, fcport->port_name, fcport->fabric_port_name);
4457
4458 qla2x00_fcport_event_handler(vha, &ea);
4459
4460 sp->free(sp);
4461}
4462
4463int qla24xx_async_gfpnid(scsi_qla_host_t *vha, fc_port_t *fcport)
4464{
4465 int rval = QLA_FUNCTION_FAILED;
4466 struct ct_sns_req *ct_req;
4467 srb_t *sp;
4468
4469 if (!vha->flags.online)
4470 goto done;
4471
4472 fcport->flags |= FCF_ASYNC_SENT;
4473 fcport->disc_state = DSC_GFPN_ID;
4474 sp = qla2x00_get_sp(vha, fcport, GFP_ATOMIC);
4475 if (!sp)
4476 goto done;
4477
4478 sp->type = SRB_CT_PTHRU_CMD;
4479 sp->name = "gfpnid";
4480 sp->gen1 = fcport->rscn_gen;
4481 sp->gen2 = fcport->login_gen;
4482
4483 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
4484
4485 /* CT_IU preamble */
4486 ct_req = qla2x00_prep_ct_req(fcport->ct_desc.ct_sns, GFPN_ID_CMD,
4487 GFPN_ID_RSP_SIZE);
4488
4489 /* GFPN_ID req */
4490 ct_req->req.port_id.port_id[0] = fcport->d_id.b.domain;
4491 ct_req->req.port_id.port_id[1] = fcport->d_id.b.area;
4492 ct_req->req.port_id.port_id[2] = fcport->d_id.b.al_pa;
4493
4494
4495 /* req & rsp use the same buffer */
4496 sp->u.iocb_cmd.u.ctarg.req = fcport->ct_desc.ct_sns;
4497 sp->u.iocb_cmd.u.ctarg.req_dma = fcport->ct_desc.ct_sns_dma;
4498 sp->u.iocb_cmd.u.ctarg.rsp = fcport->ct_desc.ct_sns;
4499 sp->u.iocb_cmd.u.ctarg.rsp_dma = fcport->ct_desc.ct_sns_dma;
4500 sp->u.iocb_cmd.u.ctarg.req_size = GFPN_ID_REQ_SIZE;
4501 sp->u.iocb_cmd.u.ctarg.rsp_size = GFPN_ID_RSP_SIZE;
4502 sp->u.iocb_cmd.u.ctarg.nport_handle = NPH_SNS;
4503
4504 sp->u.iocb_cmd.timeout = qla2x00_async_iocb_timeout;
4505 sp->done = qla2x00_async_gfpnid_sp_done;
4506
4507 rval = qla2x00_start_sp(sp);
4508 if (rval != QLA_SUCCESS)
4509 goto done_free_sp;
4510
4511 ql_dbg(ql_dbg_disc, vha, 0xffff,
4512 "Async-%s - %8phC hdl=%x loopid=%x portid %06x.\n",
4513 sp->name, fcport->port_name,
4514 sp->handle, fcport->loop_id, fcport->d_id.b24);
4515 return rval;
4516
4517done_free_sp:
4518 sp->free(sp);
4519done:
4520 fcport->flags &= ~FCF_ASYNC_SENT;
4521 return rval;
4522}
4523
4524int qla24xx_post_gfpnid_work(struct scsi_qla_host *vha, fc_port_t *fcport)
4525{
4526 struct qla_work_evt *e;
4527 int ls;
4528
4529 ls = atomic_read(&vha->loop_state);
4530 if (((ls != LOOP_READY) && (ls != LOOP_UP)) ||
4531 test_bit(UNLOADING, &vha->dpc_flags))
4532 return 0;
4533
4534 e = qla2x00_alloc_work(vha, QLA_EVT_GFPNID);
4535 if (!e)
4536 return QLA_FUNCTION_FAILED;
4537
4538 e->u.fcport.fcport = fcport;
4539 return qla2x00_post_work(vha, e);
4540}