blob: 5bf9a59432f6a10a23360e4f0ea9950ee285956c [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);
Quinn Trand8630bb2017-12-28 12:33:43 -08003050 qlt_schedule_sess_for_deletion(fcport);
Quinn Tran726b8542017-01-19 22:28:00 -08003051 }
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);
Quinn Trand8630bb2017-12-28 12:33:43 -08003067 qlt_schedule_sess_for_deletion(fcport);
Quinn Tran726b8542017-01-19 22:28:00 -08003068 } 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
Quinn Tran6d6749272017-12-28 12:33:41 -08003091 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
Quinn Tran726b8542017-01-19 22:28:00 -08003092
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
Quinn Tran3dbec592017-12-28 12:33:40 -08003130 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT))
3131 return rval;
Quinn Tran726b8542017-01-19 22:28:00 -08003132
Quinn Tran726b8542017-01-19 22:28:00 -08003133 fcport->disc_state = DSC_GID_PN;
3134 fcport->scan_state = QLA_FCPORT_SCAN;
3135 sp = qla2x00_get_sp(vha, fcport, GFP_ATOMIC);
3136 if (!sp)
3137 goto done;
3138
Quinn Tran3dbec592017-12-28 12:33:40 -08003139 fcport->flags |= FCF_ASYNC_SENT;
Quinn Tran726b8542017-01-19 22:28:00 -08003140 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 -08003180 fcport->flags &= ~FCF_ASYNC_SENT;
Quinn Tran3dbec592017-12-28 12:33:40 -08003181done:
Quinn Tran726b8542017-01-19 22:28:00 -08003182 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;
Quinn Tran6d6749272017-12-28 12:33:41 -08003200 fcport->flags |= FCF_ASYNC_ACTIVE;
Quinn Tran726b8542017-01-19 22:28:00 -08003201 return qla2x00_post_work(vha, e);
3202}
3203
3204int qla24xx_post_gpsc_work(struct scsi_qla_host *vha, fc_port_t *fcport)
3205{
3206 struct qla_work_evt *e;
3207
3208 e = qla2x00_alloc_work(vha, QLA_EVT_GPSC);
3209 if (!e)
3210 return QLA_FUNCTION_FAILED;
3211
3212 e->u.fcport.fcport = fcport;
Quinn Tran6d6749272017-12-28 12:33:41 -08003213 fcport->flags |= FCF_ASYNC_ACTIVE;
Quinn Tran726b8542017-01-19 22:28:00 -08003214 return qla2x00_post_work(vha, e);
3215}
3216
Quinn Trana4239942017-12-28 12:33:26 -08003217void qla24xx_handle_gpsc_event(scsi_qla_host_t *vha, struct event_arg *ea)
3218{
3219 struct fc_port *fcport = ea->fcport;
3220
3221 ql_dbg(ql_dbg_disc, vha, 0x20d8,
Quinn Tranf352eeb2017-12-28 12:33:35 -08003222 "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d lid %d\n",
Quinn Trana4239942017-12-28 12:33:26 -08003223 __func__, fcport->port_name, fcport->disc_state,
Quinn Tranf352eeb2017-12-28 12:33:35 -08003224 fcport->fw_login_state, ea->rc, ea->sp->gen2, fcport->login_gen,
3225 ea->sp->gen2, fcport->rscn_gen|ea->sp->gen1, fcport->loop_id);
Quinn Trana4239942017-12-28 12:33:26 -08003226
3227 if (fcport->disc_state == DSC_DELETE_PEND)
3228 return;
3229
3230 if (ea->sp->gen2 != fcport->login_gen) {
3231 /* target side must have changed it. */
3232 ql_dbg(ql_dbg_disc, vha, 0x20d3,
Quinn Tranf352eeb2017-12-28 12:33:35 -08003233 "%s %8phC generation changed\n",
3234 __func__, fcport->port_name);
Quinn Trana4239942017-12-28 12:33:26 -08003235 return;
3236 } else if (ea->sp->gen1 != fcport->rscn_gen) {
3237 ql_dbg(ql_dbg_disc, vha, 0x20d4, "%s %d %8phC post gidpn\n",
3238 __func__, __LINE__, fcport->port_name);
3239 qla24xx_post_gidpn_work(vha, fcport);
3240 return;
3241 }
3242
3243 qla24xx_post_upd_fcport_work(vha, ea->fcport);
3244}
3245
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08003246static void qla24xx_async_gpsc_sp_done(void *s, int res)
Quinn Tran726b8542017-01-19 22:28:00 -08003247{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08003248 struct srb *sp = s;
3249 struct scsi_qla_host *vha = sp->vha;
Quinn Tran726b8542017-01-19 22:28:00 -08003250 struct qla_hw_data *ha = vha->hw;
Quinn Tran726b8542017-01-19 22:28:00 -08003251 fc_port_t *fcport = sp->fcport;
3252 struct ct_sns_rsp *ct_rsp;
3253 struct event_arg ea;
3254
3255 ct_rsp = &fcport->ct_desc.ct_sns->p.rsp;
3256
Quinn Tran83548fe2017-06-02 09:12:01 -07003257 ql_dbg(ql_dbg_disc, vha, 0x2053,
Quinn Tran726b8542017-01-19 22:28:00 -08003258 "Async done-%s res %x, WWPN %8phC \n",
3259 sp->name, res, fcport->port_name);
3260
Quinn Tran6d6749272017-12-28 12:33:41 -08003261 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
Quinn Tran726b8542017-01-19 22:28:00 -08003262
3263 if (res == (DID_ERROR << 16)) {
3264 /* entry status error */
3265 goto done;
3266 } else if (res) {
3267 if ((ct_rsp->header.reason_code ==
3268 CT_REASON_INVALID_COMMAND_CODE) ||
3269 (ct_rsp->header.reason_code ==
Quinn Tran83548fe2017-06-02 09:12:01 -07003270 CT_REASON_COMMAND_UNSUPPORTED)) {
3271 ql_dbg(ql_dbg_disc, vha, 0x2019,
3272 "GPSC command unsupported, disabling query.\n");
Quinn Tran726b8542017-01-19 22:28:00 -08003273 ha->flags.gpsc_supported = 0;
3274 res = QLA_SUCCESS;
3275 }
3276 } else {
3277 switch (be16_to_cpu(ct_rsp->rsp.gpsc.speed)) {
3278 case BIT_15:
3279 fcport->fp_speed = PORT_SPEED_1GB;
3280 break;
3281 case BIT_14:
3282 fcport->fp_speed = PORT_SPEED_2GB;
3283 break;
3284 case BIT_13:
3285 fcport->fp_speed = PORT_SPEED_4GB;
3286 break;
3287 case BIT_12:
3288 fcport->fp_speed = PORT_SPEED_10GB;
3289 break;
3290 case BIT_11:
3291 fcport->fp_speed = PORT_SPEED_8GB;
3292 break;
3293 case BIT_10:
3294 fcport->fp_speed = PORT_SPEED_16GB;
3295 break;
3296 case BIT_8:
3297 fcport->fp_speed = PORT_SPEED_32GB;
3298 break;
3299 }
3300
Quinn Tran83548fe2017-06-02 09:12:01 -07003301 ql_dbg(ql_dbg_disc, vha, 0x2054,
3302 "Async-%s OUT WWPN %8phC speeds=%04x speed=%04x.\n",
3303 sp->name, fcport->fabric_port_name,
3304 be16_to_cpu(ct_rsp->rsp.gpsc.speeds),
3305 be16_to_cpu(ct_rsp->rsp.gpsc.speed));
Quinn Tran726b8542017-01-19 22:28:00 -08003306 }
3307done:
3308 memset(&ea, 0, sizeof(ea));
3309 ea.event = FCME_GPSC_DONE;
3310 ea.rc = res;
3311 ea.fcport = fcport;
Quinn Trana4239942017-12-28 12:33:26 -08003312 ea.sp = sp;
Quinn Tran726b8542017-01-19 22:28:00 -08003313 qla2x00_fcport_event_handler(vha, &ea);
3314
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08003315 sp->free(sp);
Quinn Tran726b8542017-01-19 22:28:00 -08003316}
3317
3318int qla24xx_async_gpsc(scsi_qla_host_t *vha, fc_port_t *fcport)
3319{
3320 int rval = QLA_FUNCTION_FAILED;
3321 struct ct_sns_req *ct_req;
3322 srb_t *sp;
3323
Quinn Tran3dbec592017-12-28 12:33:40 -08003324 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT))
3325 return rval;
Quinn Tran726b8542017-01-19 22:28:00 -08003326
Quinn Tran726b8542017-01-19 22:28:00 -08003327 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
3328 if (!sp)
3329 goto done;
3330
Quinn Tran3dbec592017-12-28 12:33:40 -08003331 fcport->flags |= FCF_ASYNC_SENT;
Quinn Tran726b8542017-01-19 22:28:00 -08003332 sp->type = SRB_CT_PTHRU_CMD;
3333 sp->name = "gpsc";
3334 sp->gen1 = fcport->rscn_gen;
3335 sp->gen2 = fcport->login_gen;
3336
3337 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
3338
3339 /* CT_IU preamble */
3340 ct_req = qla24xx_prep_ct_fm_req(fcport->ct_desc.ct_sns, GPSC_CMD,
3341 GPSC_RSP_SIZE);
3342
3343 /* GPSC req */
Quinn Tranb2e8ae32017-08-23 15:05:06 -07003344 memcpy(ct_req->req.gpsc.port_name, fcport->fabric_port_name,
Quinn Tran726b8542017-01-19 22:28:00 -08003345 WWN_SIZE);
3346
3347 sp->u.iocb_cmd.u.ctarg.req = fcport->ct_desc.ct_sns;
3348 sp->u.iocb_cmd.u.ctarg.req_dma = fcport->ct_desc.ct_sns_dma;
3349 sp->u.iocb_cmd.u.ctarg.rsp = fcport->ct_desc.ct_sns;
3350 sp->u.iocb_cmd.u.ctarg.rsp_dma = fcport->ct_desc.ct_sns_dma;
3351 sp->u.iocb_cmd.u.ctarg.req_size = GPSC_REQ_SIZE;
3352 sp->u.iocb_cmd.u.ctarg.rsp_size = GPSC_RSP_SIZE;
3353 sp->u.iocb_cmd.u.ctarg.nport_handle = vha->mgmt_svr_loop_id;
3354
3355 sp->u.iocb_cmd.timeout = qla2x00_async_iocb_timeout;
3356 sp->done = qla24xx_async_gpsc_sp_done;
3357
3358 rval = qla2x00_start_sp(sp);
3359 if (rval != QLA_SUCCESS)
3360 goto done_free_sp;
3361
Quinn Tran83548fe2017-06-02 09:12:01 -07003362 ql_dbg(ql_dbg_disc, vha, 0x205e,
3363 "Async-%s %8phC hdl=%x loopid=%x portid=%02x%02x%02x.\n",
3364 sp->name, fcport->port_name, sp->handle,
3365 fcport->loop_id, fcport->d_id.b.domain,
3366 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Quinn Tran726b8542017-01-19 22:28:00 -08003367 return rval;
3368
3369done_free_sp:
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08003370 sp->free(sp);
Quinn Tran726b8542017-01-19 22:28:00 -08003371 fcport->flags &= ~FCF_ASYNC_SENT;
Quinn Tran3dbec592017-12-28 12:33:40 -08003372done:
Quinn Tran726b8542017-01-19 22:28:00 -08003373 return rval;
3374}
3375
3376int qla24xx_post_gpnid_work(struct scsi_qla_host *vha, port_id_t *id)
3377{
3378 struct qla_work_evt *e;
3379
3380 if (test_bit(UNLOADING, &vha->dpc_flags))
3381 return 0;
3382
3383 e = qla2x00_alloc_work(vha, QLA_EVT_GPNID);
3384 if (!e)
3385 return QLA_FUNCTION_FAILED;
3386
3387 e->u.gpnid.id = *id;
3388 return qla2x00_post_work(vha, e);
3389}
3390
Quinn Trane374f9f2017-12-28 12:33:31 -08003391void qla24xx_sp_unmap(scsi_qla_host_t *vha, srb_t *sp)
Quinn Tran726b8542017-01-19 22:28:00 -08003392{
3393 if (sp->u.iocb_cmd.u.ctarg.req) {
3394 dma_free_coherent(&vha->hw->pdev->dev,
3395 sizeof(struct ct_sns_pkt),
3396 sp->u.iocb_cmd.u.ctarg.req,
3397 sp->u.iocb_cmd.u.ctarg.req_dma);
3398 sp->u.iocb_cmd.u.ctarg.req = NULL;
3399 }
3400 if (sp->u.iocb_cmd.u.ctarg.rsp) {
3401 dma_free_coherent(&vha->hw->pdev->dev,
3402 sizeof(struct ct_sns_pkt),
3403 sp->u.iocb_cmd.u.ctarg.rsp,
3404 sp->u.iocb_cmd.u.ctarg.rsp_dma);
3405 sp->u.iocb_cmd.u.ctarg.rsp = NULL;
3406 }
3407
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08003408 sp->free(sp);
Quinn Tran726b8542017-01-19 22:28:00 -08003409}
3410
3411void qla24xx_handle_gpnid_event(scsi_qla_host_t *vha, struct event_arg *ea)
3412{
Quinn Tran5ef696a2017-12-04 14:45:05 -08003413 fc_port_t *fcport, *conflict, *t;
Quinn Tranf13515a2017-12-28 12:33:15 -08003414 u16 data[2];
Quinn Tran726b8542017-01-19 22:28:00 -08003415
Quinn Tran5ef696a2017-12-04 14:45:05 -08003416 ql_dbg(ql_dbg_disc, vha, 0xffff,
3417 "%s %d port_id: %06x\n",
3418 __func__, __LINE__, ea->id.b24);
Quinn Tran726b8542017-01-19 22:28:00 -08003419
Quinn Tran5ef696a2017-12-04 14:45:05 -08003420 if (ea->rc) {
3421 /* cable is disconnected */
3422 list_for_each_entry_safe(fcport, t, &vha->vp_fcports, list) {
3423 if (fcport->d_id.b24 == ea->id.b24) {
3424 ql_dbg(ql_dbg_disc, vha, 0xffff,
3425 "%s %d %8phC DS %d\n",
3426 __func__, __LINE__,
3427 fcport->port_name,
3428 fcport->disc_state);
3429 fcport->scan_state = QLA_FCPORT_SCAN;
3430 switch (fcport->disc_state) {
3431 case DSC_DELETED:
3432 case DSC_DELETE_PEND:
3433 break;
3434 default:
3435 ql_dbg(ql_dbg_disc, vha, 0xffff,
3436 "%s %d %8phC post del sess\n",
3437 __func__, __LINE__,
3438 fcport->port_name);
Quinn Trand8630bb2017-12-28 12:33:43 -08003439 qlt_schedule_sess_for_deletion(fcport);
Quinn Tran5ef696a2017-12-04 14:45:05 -08003440 break;
3441 }
3442 }
Quinn Tran66ee0fe2017-06-02 09:11:56 -07003443 }
Quinn Tran726b8542017-01-19 22:28:00 -08003444 } else {
Quinn Tran5ef696a2017-12-04 14:45:05 -08003445 /* cable is connected */
3446 fcport = qla2x00_find_fcport_by_wwpn(vha, ea->port_name, 1);
3447 if (fcport) {
3448 list_for_each_entry_safe(conflict, t, &vha->vp_fcports,
3449 list) {
3450 if ((conflict->d_id.b24 == ea->id.b24) &&
3451 (fcport != conflict)) {
3452 /* 2 fcports with conflict Nport ID or
3453 * an existing fcport is having nport ID
3454 * conflict with new fcport.
3455 */
Quinn Tran726b8542017-01-19 22:28:00 -08003456
Quinn Tran5ef696a2017-12-04 14:45:05 -08003457 ql_dbg(ql_dbg_disc, vha, 0xffff,
3458 "%s %d %8phC DS %d\n",
3459 __func__, __LINE__,
3460 conflict->port_name,
3461 conflict->disc_state);
3462 conflict->scan_state = QLA_FCPORT_SCAN;
3463 switch (conflict->disc_state) {
3464 case DSC_DELETED:
3465 case DSC_DELETE_PEND:
3466 break;
3467 default:
3468 ql_dbg(ql_dbg_disc, vha, 0xffff,
3469 "%s %d %8phC post del sess\n",
3470 __func__, __LINE__,
3471 conflict->port_name);
Quinn Trand8630bb2017-12-28 12:33:43 -08003472 qlt_schedule_sess_for_deletion
Quinn Tran5ef696a2017-12-04 14:45:05 -08003473 (conflict);
3474 break;
3475 }
3476 }
3477 }
3478
3479 fcport->rscn_gen++;
3480 fcport->scan_state = QLA_FCPORT_FOUND;
3481 fcport->flags |= FCF_FABRIC_DEVICE;
3482 switch (fcport->disc_state) {
3483 case DSC_LOGIN_COMPLETE:
3484 /* recheck session is still intact. */
3485 ql_dbg(ql_dbg_disc, vha, 0x210d,
3486 "%s %d %8phC revalidate session with ADISC\n",
3487 __func__, __LINE__, fcport->port_name);
Quinn Tranf13515a2017-12-28 12:33:15 -08003488 data[0] = data[1] = 0;
3489 qla2x00_post_async_adisc_work(vha, fcport,
3490 data);
Quinn Tran5ef696a2017-12-04 14:45:05 -08003491 break;
3492 case DSC_DELETED:
3493 ql_dbg(ql_dbg_disc, vha, 0x210d,
3494 "%s %d %8phC login\n", __func__, __LINE__,
3495 fcport->port_name);
3496 fcport->d_id = ea->id;
3497 qla24xx_fcport_handle_login(vha, fcport);
3498 break;
3499 case DSC_DELETE_PEND:
3500 fcport->d_id = ea->id;
3501 break;
3502 default:
3503 fcport->d_id = ea->id;
3504 break;
3505 }
3506 } else {
3507 list_for_each_entry_safe(conflict, t, &vha->vp_fcports,
3508 list) {
3509 if (conflict->d_id.b24 == ea->id.b24) {
3510 /* 2 fcports with conflict Nport ID or
3511 * an existing fcport is having nport ID
3512 * conflict with new fcport.
3513 */
3514 ql_dbg(ql_dbg_disc, vha, 0xffff,
3515 "%s %d %8phC DS %d\n",
3516 __func__, __LINE__,
3517 conflict->port_name,
3518 conflict->disc_state);
3519
3520 conflict->scan_state = QLA_FCPORT_SCAN;
3521 switch (conflict->disc_state) {
3522 case DSC_DELETED:
3523 case DSC_DELETE_PEND:
3524 break;
3525 default:
3526 ql_dbg(ql_dbg_disc, vha, 0xffff,
3527 "%s %d %8phC post del sess\n",
3528 __func__, __LINE__,
3529 conflict->port_name);
Quinn Trand8630bb2017-12-28 12:33:43 -08003530 qlt_schedule_sess_for_deletion
Quinn Tran5ef696a2017-12-04 14:45:05 -08003531 (conflict);
3532 break;
3533 }
3534 }
3535 }
3536
3537 /* create new fcport */
3538 ql_dbg(ql_dbg_disc, vha, 0x2065,
3539 "%s %d %8phC post new sess\n",
3540 __func__, __LINE__, ea->port_name);
3541 qla24xx_post_newsess_work(vha, &ea->id,
Quinn Trana4239942017-12-28 12:33:26 -08003542 ea->port_name, NULL, NULL, FC4_TYPE_UNKNOWN);
Quinn Tran5ef696a2017-12-04 14:45:05 -08003543 }
Quinn Tran726b8542017-01-19 22:28:00 -08003544 }
3545}
3546
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08003547static void qla2x00_async_gpnid_sp_done(void *s, int res)
Quinn Tran726b8542017-01-19 22:28:00 -08003548{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08003549 struct srb *sp = s;
3550 struct scsi_qla_host *vha = sp->vha;
Quinn Tran726b8542017-01-19 22:28:00 -08003551 struct ct_sns_req *ct_req =
3552 (struct ct_sns_req *)sp->u.iocb_cmd.u.ctarg.req;
3553 struct ct_sns_rsp *ct_rsp =
3554 (struct ct_sns_rsp *)sp->u.iocb_cmd.u.ctarg.rsp;
3555 struct event_arg ea;
3556 struct qla_work_evt *e;
Quinn Tran2d73ac62017-12-04 14:45:02 -08003557 unsigned long flags;
Quinn Tran726b8542017-01-19 22:28:00 -08003558
Quinn Trana084fd62017-12-04 14:45:00 -08003559 if (res)
3560 ql_dbg(ql_dbg_disc, vha, 0x2066,
Quinn Tran2d73ac62017-12-04 14:45:02 -08003561 "Async done-%s fail res %x rscn gen %d ID %3phC. %8phC\n",
3562 sp->name, res, sp->gen1, ct_req->req.port_id.port_id,
Quinn Trana084fd62017-12-04 14:45:00 -08003563 ct_rsp->rsp.gpn_id.port_name);
3564 else
3565 ql_dbg(ql_dbg_disc, vha, 0x2066,
Quinn Tran2d73ac62017-12-04 14:45:02 -08003566 "Async done-%s good rscn gen %d ID %3phC. %8phC\n",
3567 sp->name, sp->gen1, ct_req->req.port_id.port_id,
Quinn Trana084fd62017-12-04 14:45:00 -08003568 ct_rsp->rsp.gpn_id.port_name);
Quinn Tran726b8542017-01-19 22:28:00 -08003569
3570 memset(&ea, 0, sizeof(ea));
3571 memcpy(ea.port_name, ct_rsp->rsp.gpn_id.port_name, WWN_SIZE);
3572 ea.sp = sp;
3573 ea.id.b.domain = ct_req->req.port_id.port_id[0];
3574 ea.id.b.area = ct_req->req.port_id.port_id[1];
3575 ea.id.b.al_pa = ct_req->req.port_id.port_id[2];
3576 ea.rc = res;
3577 ea.event = FCME_GPNID_DONE;
3578
Quinn Tran2d73ac62017-12-04 14:45:02 -08003579 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
3580 list_del(&sp->elem);
3581 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
3582
Quinn Tran25ad76b2017-12-04 14:45:01 -08003583 if (res) {
Quinn Tran5ef696a2017-12-04 14:45:05 -08003584 if (res == QLA_FUNCTION_TIMEOUT) {
Quinn Tran25ad76b2017-12-04 14:45:01 -08003585 qla24xx_post_gpnid_work(sp->vha, &ea.id);
Quinn Tran5ef696a2017-12-04 14:45:05 -08003586 sp->free(sp);
3587 return;
3588 }
Quinn Tran2d73ac62017-12-04 14:45:02 -08003589 } else if (sp->gen1) {
Quinn Tran5ef696a2017-12-04 14:45:05 -08003590 /* There was another RSCN for this Nport ID */
Quinn Tran2d73ac62017-12-04 14:45:02 -08003591 qla24xx_post_gpnid_work(sp->vha, &ea.id);
3592 sp->free(sp);
3593 return;
Quinn Tran25ad76b2017-12-04 14:45:01 -08003594 }
3595
Quinn Tran726b8542017-01-19 22:28:00 -08003596 qla2x00_fcport_event_handler(vha, &ea);
3597
Quinn Trane374f9f2017-12-28 12:33:31 -08003598 e = qla2x00_alloc_work(vha, QLA_EVT_UNMAP);
Quinn Tran726b8542017-01-19 22:28:00 -08003599 if (!e) {
3600 /* please ignore kernel warning. otherwise, we have mem leak. */
3601 if (sp->u.iocb_cmd.u.ctarg.req) {
3602 dma_free_coherent(&vha->hw->pdev->dev,
3603 sizeof(struct ct_sns_pkt),
3604 sp->u.iocb_cmd.u.ctarg.req,
3605 sp->u.iocb_cmd.u.ctarg.req_dma);
3606 sp->u.iocb_cmd.u.ctarg.req = NULL;
3607 }
3608 if (sp->u.iocb_cmd.u.ctarg.rsp) {
3609 dma_free_coherent(&vha->hw->pdev->dev,
3610 sizeof(struct ct_sns_pkt),
3611 sp->u.iocb_cmd.u.ctarg.rsp,
3612 sp->u.iocb_cmd.u.ctarg.rsp_dma);
3613 sp->u.iocb_cmd.u.ctarg.rsp = NULL;
3614 }
3615
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08003616 sp->free(sp);
Quinn Tran726b8542017-01-19 22:28:00 -08003617 return;
3618 }
3619
3620 e->u.iosb.sp = sp;
3621 qla2x00_post_work(vha, e);
3622}
3623
3624/* Get WWPN with Nport ID. */
3625int qla24xx_async_gpnid(scsi_qla_host_t *vha, port_id_t *id)
3626{
3627 int rval = QLA_FUNCTION_FAILED;
3628 struct ct_sns_req *ct_req;
Quinn Tran2d73ac62017-12-04 14:45:02 -08003629 srb_t *sp, *tsp;
Quinn Tran726b8542017-01-19 22:28:00 -08003630 struct ct_sns_pkt *ct_sns;
Quinn Tran2d73ac62017-12-04 14:45:02 -08003631 unsigned long flags;
Quinn Tran726b8542017-01-19 22:28:00 -08003632
3633 if (!vha->flags.online)
3634 goto done;
3635
3636 sp = qla2x00_get_sp(vha, NULL, GFP_KERNEL);
3637 if (!sp)
3638 goto done;
3639
3640 sp->type = SRB_CT_PTHRU_CMD;
3641 sp->name = "gpnid";
Quinn Tran2d73ac62017-12-04 14:45:02 -08003642 sp->u.iocb_cmd.u.ctarg.id = *id;
3643 sp->gen1 = 0;
Quinn Tran726b8542017-01-19 22:28:00 -08003644 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
3645
Quinn Tran2d73ac62017-12-04 14:45:02 -08003646 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
3647 list_for_each_entry(tsp, &vha->gpnid_list, elem) {
3648 if (tsp->u.iocb_cmd.u.ctarg.id.b24 == id->b24) {
3649 tsp->gen1++;
3650 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
3651 sp->free(sp);
3652 goto done;
3653 }
3654 }
3655 list_add_tail(&sp->elem, &vha->gpnid_list);
3656 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
3657
Quinn Tran726b8542017-01-19 22:28:00 -08003658 sp->u.iocb_cmd.u.ctarg.req = dma_alloc_coherent(&vha->hw->pdev->dev,
3659 sizeof(struct ct_sns_pkt), &sp->u.iocb_cmd.u.ctarg.req_dma,
3660 GFP_KERNEL);
3661 if (!sp->u.iocb_cmd.u.ctarg.req) {
Quinn Tran83548fe2017-06-02 09:12:01 -07003662 ql_log(ql_log_warn, vha, 0xd041,
3663 "Failed to allocate ct_sns request.\n");
Quinn Tran726b8542017-01-19 22:28:00 -08003664 goto done_free_sp;
3665 }
3666
3667 sp->u.iocb_cmd.u.ctarg.rsp = dma_alloc_coherent(&vha->hw->pdev->dev,
3668 sizeof(struct ct_sns_pkt), &sp->u.iocb_cmd.u.ctarg.rsp_dma,
3669 GFP_KERNEL);
3670 if (!sp->u.iocb_cmd.u.ctarg.rsp) {
Quinn Tran83548fe2017-06-02 09:12:01 -07003671 ql_log(ql_log_warn, vha, 0xd042,
3672 "Failed to allocate ct_sns request.\n");
Quinn Tran726b8542017-01-19 22:28:00 -08003673 goto done_free_sp;
3674 }
3675
3676 ct_sns = (struct ct_sns_pkt *)sp->u.iocb_cmd.u.ctarg.rsp;
3677 memset(ct_sns, 0, sizeof(*ct_sns));
3678
3679 ct_sns = (struct ct_sns_pkt *)sp->u.iocb_cmd.u.ctarg.req;
3680 /* CT_IU preamble */
3681 ct_req = qla2x00_prep_ct_req(ct_sns, GPN_ID_CMD, GPN_ID_RSP_SIZE);
3682
3683 /* GPN_ID req */
3684 ct_req->req.port_id.port_id[0] = id->b.domain;
3685 ct_req->req.port_id.port_id[1] = id->b.area;
3686 ct_req->req.port_id.port_id[2] = id->b.al_pa;
3687
3688 sp->u.iocb_cmd.u.ctarg.req_size = GPN_ID_REQ_SIZE;
3689 sp->u.iocb_cmd.u.ctarg.rsp_size = GPN_ID_RSP_SIZE;
3690 sp->u.iocb_cmd.u.ctarg.nport_handle = NPH_SNS;
3691
3692 sp->u.iocb_cmd.timeout = qla2x00_async_iocb_timeout;
3693 sp->done = qla2x00_async_gpnid_sp_done;
3694
3695 rval = qla2x00_start_sp(sp);
3696 if (rval != QLA_SUCCESS)
3697 goto done_free_sp;
3698
Quinn Tran83548fe2017-06-02 09:12:01 -07003699 ql_dbg(ql_dbg_disc, vha, 0x2067,
3700 "Async-%s hdl=%x ID %3phC.\n", sp->name,
3701 sp->handle, ct_req->req.port_id.port_id);
Quinn Tran726b8542017-01-19 22:28:00 -08003702 return rval;
3703
3704done_free_sp:
3705 if (sp->u.iocb_cmd.u.ctarg.req) {
3706 dma_free_coherent(&vha->hw->pdev->dev,
3707 sizeof(struct ct_sns_pkt),
3708 sp->u.iocb_cmd.u.ctarg.req,
3709 sp->u.iocb_cmd.u.ctarg.req_dma);
3710 sp->u.iocb_cmd.u.ctarg.req = NULL;
3711 }
3712 if (sp->u.iocb_cmd.u.ctarg.rsp) {
3713 dma_free_coherent(&vha->hw->pdev->dev,
3714 sizeof(struct ct_sns_pkt),
3715 sp->u.iocb_cmd.u.ctarg.rsp,
3716 sp->u.iocb_cmd.u.ctarg.rsp_dma);
3717 sp->u.iocb_cmd.u.ctarg.rsp = NULL;
3718 }
3719
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08003720 sp->free(sp);
Quinn Tran726b8542017-01-19 22:28:00 -08003721done:
3722 return rval;
3723}
Duane Grigsbyd3bae932017-06-21 13:48:44 -07003724
3725void qla24xx_handle_gffid_event(scsi_qla_host_t *vha, struct event_arg *ea)
3726{
3727 fc_port_t *fcport = ea->fcport;
3728
3729 qla24xx_post_gnl_work(vha, fcport);
3730}
3731
3732void qla24xx_async_gffid_sp_done(void *s, int res)
3733{
3734 struct srb *sp = s;
3735 struct scsi_qla_host *vha = sp->vha;
3736 fc_port_t *fcport = sp->fcport;
3737 struct ct_sns_rsp *ct_rsp;
3738 struct event_arg ea;
3739
3740 ql_dbg(ql_dbg_disc, vha, 0x2133,
3741 "Async done-%s res %x ID %x. %8phC\n",
3742 sp->name, res, fcport->d_id.b24, fcport->port_name);
3743
3744 fcport->flags &= ~FCF_ASYNC_SENT;
3745 ct_rsp = &fcport->ct_desc.ct_sns->p.rsp;
3746 /*
3747 * FC-GS-7, 5.2.3.12 FC-4 Features - format
3748 * The format of the FC-4 Features object, as defined by the FC-4,
3749 * Shall be an array of 4-bit values, one for each type code value
3750 */
3751 if (!res) {
3752 if (ct_rsp->rsp.gff_id.fc4_features[GFF_FCP_SCSI_OFFSET] & 0xf) {
3753 /* w1 b00:03 */
3754 fcport->fc4_type =
3755 ct_rsp->rsp.gff_id.fc4_features[GFF_FCP_SCSI_OFFSET];
3756 fcport->fc4_type &= 0xf;
3757 }
3758
3759 if (ct_rsp->rsp.gff_id.fc4_features[GFF_NVME_OFFSET] & 0xf) {
3760 /* w5 [00:03]/28h */
3761 fcport->fc4f_nvme =
3762 ct_rsp->rsp.gff_id.fc4_features[GFF_NVME_OFFSET];
3763 fcport->fc4f_nvme &= 0xf;
3764 }
3765 }
3766
3767 memset(&ea, 0, sizeof(ea));
3768 ea.sp = sp;
3769 ea.fcport = sp->fcport;
3770 ea.rc = res;
3771 ea.event = FCME_GFFID_DONE;
3772
3773 qla2x00_fcport_event_handler(vha, &ea);
3774 sp->free(sp);
3775}
3776
3777/* Get FC4 Feature with Nport ID. */
3778int qla24xx_async_gffid(scsi_qla_host_t *vha, fc_port_t *fcport)
3779{
3780 int rval = QLA_FUNCTION_FAILED;
3781 struct ct_sns_req *ct_req;
3782 srb_t *sp;
3783
Quinn Tran3dbec592017-12-28 12:33:40 -08003784 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT))
Duane Grigsbyd3bae932017-06-21 13:48:44 -07003785 return rval;
3786
3787 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
3788 if (!sp)
3789 return rval;
3790
3791 fcport->flags |= FCF_ASYNC_SENT;
3792 sp->type = SRB_CT_PTHRU_CMD;
3793 sp->name = "gffid";
3794 sp->gen1 = fcport->rscn_gen;
3795 sp->gen2 = fcport->login_gen;
3796
3797 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
3798
3799 /* CT_IU preamble */
3800 ct_req = qla2x00_prep_ct_req(fcport->ct_desc.ct_sns, GFF_ID_CMD,
3801 GFF_ID_RSP_SIZE);
3802
3803 ct_req->req.gff_id.port_id[0] = fcport->d_id.b.domain;
3804 ct_req->req.gff_id.port_id[1] = fcport->d_id.b.area;
3805 ct_req->req.gff_id.port_id[2] = fcport->d_id.b.al_pa;
3806
3807 sp->u.iocb_cmd.u.ctarg.req = fcport->ct_desc.ct_sns;
3808 sp->u.iocb_cmd.u.ctarg.req_dma = fcport->ct_desc.ct_sns_dma;
3809 sp->u.iocb_cmd.u.ctarg.rsp = fcport->ct_desc.ct_sns;
3810 sp->u.iocb_cmd.u.ctarg.rsp_dma = fcport->ct_desc.ct_sns_dma;
3811 sp->u.iocb_cmd.u.ctarg.req_size = GFF_ID_REQ_SIZE;
3812 sp->u.iocb_cmd.u.ctarg.rsp_size = GFF_ID_RSP_SIZE;
3813 sp->u.iocb_cmd.u.ctarg.nport_handle = NPH_SNS;
3814
3815 sp->u.iocb_cmd.timeout = qla2x00_async_iocb_timeout;
3816 sp->done = qla24xx_async_gffid_sp_done;
3817
3818 rval = qla2x00_start_sp(sp);
3819 if (rval != QLA_SUCCESS)
3820 goto done_free_sp;
3821
3822 ql_dbg(ql_dbg_disc, vha, 0x2132,
3823 "Async-%s hdl=%x %8phC.\n", sp->name,
3824 sp->handle, fcport->port_name);
3825
3826 return rval;
3827done_free_sp:
3828 sp->free(sp);
3829 fcport->flags &= ~FCF_ASYNC_SENT;
3830 return rval;
3831}
Quinn Trana4239942017-12-28 12:33:26 -08003832
3833/* GPN_FT + GNN_FT*/
3834static int qla2x00_is_a_vp(scsi_qla_host_t *vha, u64 wwn)
3835{
3836 struct qla_hw_data *ha = vha->hw;
3837 scsi_qla_host_t *vp;
3838 unsigned long flags;
3839 u64 twwn;
3840 int rc = 0;
3841
3842 if (!ha->num_vhosts)
3843 return 0;
3844
3845 spin_lock_irqsave(&ha->vport_slock, flags);
3846 list_for_each_entry(vp, &ha->vp_list, list) {
3847 twwn = wwn_to_u64(vp->port_name);
3848 if (wwn == twwn) {
3849 rc = 1;
3850 break;
3851 }
3852 }
3853 spin_unlock_irqrestore(&ha->vport_slock, flags);
3854
3855 return rc;
3856}
3857
3858void qla24xx_async_gnnft_done(scsi_qla_host_t *vha, srb_t *sp)
3859{
3860 fc_port_t *fcport;
3861 u32 i, rc;
3862 bool found;
3863 u8 fc4type = sp->gen2;
3864 struct fab_scan_rp *rp;
Quinn Tranf352eeb2017-12-28 12:33:35 -08003865 unsigned long flags;
Quinn Trana4239942017-12-28 12:33:26 -08003866
3867 ql_dbg(ql_dbg_disc, vha, 0xffff,
3868 "%s enter\n", __func__);
3869
3870 if (sp->gen1 != vha->hw->base_qpair->chip_reset) {
3871 ql_dbg(ql_dbg_disc, vha, 0xffff,
3872 "%s scan stop due to chip reset %x/%x\n",
3873 sp->name, sp->gen1, vha->hw->base_qpair->chip_reset);
3874 goto out;
3875 }
3876
3877 rc = sp->rc;
3878 if (rc) {
Quinn Tran6944dcc2017-12-28 12:33:39 -08003879 vha->scan.scan_retry++;
3880 if (vha->scan.scan_retry < MAX_SCAN_RETRIES) {
3881 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
3882 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
3883 } else {
3884 ql_dbg(ql_dbg_disc, vha, 0xffff,
3885 "Fabric scan failed on all retries.\n");
3886 }
Quinn Trana4239942017-12-28 12:33:26 -08003887 goto out;
3888 }
Quinn Tran6944dcc2017-12-28 12:33:39 -08003889 vha->scan.scan_retry = 0;
Quinn Trana4239942017-12-28 12:33:26 -08003890
3891 list_for_each_entry(fcport, &vha->vp_fcports, list)
3892 fcport->scan_state = QLA_FCPORT_SCAN;
3893
3894 for (i = 0; i < vha->hw->max_fibre_devices; i++) {
3895 u64 wwn;
3896
3897 rp = &vha->scan.l[i];
3898 found = false;
3899
3900 wwn = wwn_to_u64(rp->port_name);
3901 if (wwn == 0)
3902 continue;
3903
3904 if (!memcmp(rp->port_name, vha->port_name, WWN_SIZE))
3905 continue;
3906
3907 /* Bypass reserved domain fields. */
3908 if ((rp->id.b.domain & 0xf0) == 0xf0)
3909 continue;
3910
3911 /* Bypass virtual ports of the same host. */
3912 if (qla2x00_is_a_vp(vha, wwn))
3913 continue;
3914
3915 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3916 if (memcmp(rp->port_name, fcport->port_name, WWN_SIZE))
3917 continue;
3918 fcport->scan_state = QLA_FCPORT_FOUND;
3919 fcport->d_id.b24 = rp->id.b24;
3920 found = true;
3921 /*
3922 * If device was not a fabric device before.
3923 */
3924 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
3925 qla2x00_clear_loop_id(fcport);
3926 fcport->flags |= FCF_FABRIC_DEVICE;
3927 }
3928 break;
3929 }
3930
3931 if (!found) {
3932 ql_dbg(ql_dbg_disc, vha, 0xffff,
3933 "%s %d %8phC post new sess\n",
3934 __func__, __LINE__, rp->port_name);
3935 qla24xx_post_newsess_work(vha, &rp->id, rp->port_name,
3936 rp->node_name, NULL, fc4type);
3937 }
3938 }
3939
3940 /*
3941 * Logout all previous fabric dev marked lost, except FCP2 devices.
3942 */
3943 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3944 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
3945 continue;
3946
Quinn Tranf352eeb2017-12-28 12:33:35 -08003947 if (fcport->scan_state != QLA_FCPORT_FOUND) {
Quinn Trana4239942017-12-28 12:33:26 -08003948 if ((qla_dual_mode_enabled(vha) ||
3949 qla_ini_mode_enabled(vha)) &&
3950 atomic_read(&fcport->state) == FCS_ONLINE) {
3951 qla2x00_mark_device_lost(vha, fcport,
3952 ql2xplogiabsentdevice, 0);
Quinn Tranf352eeb2017-12-28 12:33:35 -08003953
Quinn Trana4239942017-12-28 12:33:26 -08003954 if (fcport->loop_id != FC_NO_LOOP_ID &&
Quinn Tranf352eeb2017-12-28 12:33:35 -08003955 (fcport->flags & FCF_FCP2_DEVICE) == 0) {
Quinn Trana4239942017-12-28 12:33:26 -08003956 ql_dbg(ql_dbg_disc, vha, 0x20f0,
3957 "%s %d %8phC post del sess\n",
3958 __func__, __LINE__,
3959 fcport->port_name);
3960
Quinn Trand8630bb2017-12-28 12:33:43 -08003961 qlt_schedule_sess_for_deletion(fcport);
Quinn Trana4239942017-12-28 12:33:26 -08003962 continue;
3963 }
3964 }
Quinn Tranf352eeb2017-12-28 12:33:35 -08003965 } else
Quinn Trana4239942017-12-28 12:33:26 -08003966 qla24xx_fcport_handle_login(vha, fcport);
3967 }
3968
3969out:
Quinn Trane374f9f2017-12-28 12:33:31 -08003970 qla24xx_sp_unmap(vha, sp);
Quinn Tranf352eeb2017-12-28 12:33:35 -08003971 spin_lock_irqsave(&vha->work_lock, flags);
3972 vha->scan.scan_flags &= ~SF_SCANNING;
3973 spin_unlock_irqrestore(&vha->work_lock, flags);
Quinn Trana4239942017-12-28 12:33:26 -08003974}
3975
3976static void qla2x00_async_gpnft_gnnft_sp_done(void *s, int res)
3977{
3978 struct srb *sp = s;
3979 struct scsi_qla_host *vha = sp->vha;
3980 struct qla_work_evt *e;
3981 struct ct_sns_req *ct_req =
3982 (struct ct_sns_req *)sp->u.iocb_cmd.u.ctarg.req;
3983 struct ct_sns_gpnft_rsp *ct_rsp =
3984 (struct ct_sns_gpnft_rsp *)sp->u.iocb_cmd.u.ctarg.rsp;
Colin Ian King8b569182018-01-05 15:50:37 +00003985 struct ct_sns_gpn_ft_data *d;
Quinn Trana4239942017-12-28 12:33:26 -08003986 struct fab_scan_rp *rp;
3987 int i, j, k;
3988 u16 cmd = be16_to_cpu(ct_req->command);
3989
3990 /* gen2 field is holding the fc4type */
3991 ql_dbg(ql_dbg_disc, vha, 0xffff,
3992 "Async done-%s res %x FC4Type %x\n",
3993 sp->name, res, sp->gen2);
3994
Quinn Trancf055fb2017-12-28 12:33:33 -08003995 if (res) {
3996 unsigned long flags;
3997
Quinn Trancf055fb2017-12-28 12:33:33 -08003998 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;
Quinn Tran6944dcc2017-12-28 12:33:39 -08004001 vha->scan.scan_retry++;
Quinn Tranf352eeb2017-12-28 12:33:35 -08004002 spin_unlock_irqrestore(&vha->work_lock, flags);
Quinn Tran6944dcc2017-12-28 12:33:39 -08004003
4004 if (vha->scan.scan_retry < MAX_SCAN_RETRIES) {
4005 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
4006 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4007 qla2xxx_wake_dpc(vha);
4008 } else {
4009 ql_dbg(ql_dbg_disc, sp->vha, 0xffff,
4010 "Async done-%s rescan failed on all retries\n",
4011 sp->name);
4012 }
Quinn Trancf055fb2017-12-28 12:33:33 -08004013 return;
4014 }
4015
Quinn Trana4239942017-12-28 12:33:26 -08004016 if (!res) {
4017 port_id_t id;
4018 u64 wwn;
4019
4020 j = 0;
4021 for (i = 0; i < vha->hw->max_fibre_devices; i++) {
4022 d = &ct_rsp->entries[i];
4023
4024 id.b.rsvd_1 = 0;
4025 id.b.domain = d->port_id[0];
4026 id.b.area = d->port_id[1];
4027 id.b.al_pa = d->port_id[2];
4028 wwn = wwn_to_u64(d->port_name);
4029
4030 if (id.b24 == 0 || wwn == 0)
4031 continue;
4032
4033 if (cmd == GPN_FT_CMD) {
4034 rp = &vha->scan.l[j];
4035 rp->id = id;
4036 memcpy(rp->port_name, d->port_name, 8);
4037 j++;
4038 } else {/* GNN_FT_CMD */
4039 for (k = 0; k < vha->hw->max_fibre_devices;
4040 k++) {
4041 rp = &vha->scan.l[k];
4042 if (id.b24 == rp->id.b24) {
4043 memcpy(rp->node_name,
4044 d->port_name, 8);
4045 break;
4046 }
4047 }
4048 }
4049 }
4050 }
4051
4052 if (cmd == GPN_FT_CMD)
4053 e = qla2x00_alloc_work(vha, QLA_EVT_GPNFT_DONE);
4054 else
4055 e = qla2x00_alloc_work(vha, QLA_EVT_GNNFT_DONE);
4056 if (!e) {
4057 /* please ignore kernel warning. Otherwise, we have mem leak. */
4058 if (sp->u.iocb_cmd.u.ctarg.req) {
4059 dma_free_coherent(&vha->hw->pdev->dev,
4060 sizeof(struct ct_sns_pkt),
4061 sp->u.iocb_cmd.u.ctarg.req,
4062 sp->u.iocb_cmd.u.ctarg.req_dma);
4063 sp->u.iocb_cmd.u.ctarg.req = NULL;
4064 }
4065 if (sp->u.iocb_cmd.u.ctarg.rsp) {
4066 dma_free_coherent(&vha->hw->pdev->dev,
4067 sizeof(struct ct_sns_pkt),
4068 sp->u.iocb_cmd.u.ctarg.rsp,
4069 sp->u.iocb_cmd.u.ctarg.rsp_dma);
4070 sp->u.iocb_cmd.u.ctarg.rsp = NULL;
4071 }
4072
4073 ql_dbg(ql_dbg_disc, vha, 0xffff,
4074 "Async done-%s unable to alloc work element\n",
4075 sp->name);
4076 sp->free(sp);
Quinn Trancf055fb2017-12-28 12:33:33 -08004077 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Quinn Trana4239942017-12-28 12:33:26 -08004078 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4079 return;
4080 }
4081
4082 sp->rc = res;
4083 e->u.iosb.sp = sp;
4084
4085 qla2x00_post_work(vha, e);
4086}
4087
4088/*
4089 * Get WWNN list for fc4_type
4090 *
4091 * It is assumed the same SRB is re-used from GPNFT to avoid
4092 * mem free & re-alloc
4093 */
4094static int qla24xx_async_gnnft(scsi_qla_host_t *vha, struct srb *sp,
4095 u8 fc4_type)
4096{
4097 int rval = QLA_FUNCTION_FAILED;
4098 struct ct_sns_req *ct_req;
4099 struct ct_sns_pkt *ct_sns;
4100
Quinn Tranf352eeb2017-12-28 12:33:35 -08004101 if (!vha->flags.online) {
4102 vha->scan.scan_flags &= ~SF_SCANNING;
Quinn Trana4239942017-12-28 12:33:26 -08004103 goto done_free_sp;
Quinn Tranf352eeb2017-12-28 12:33:35 -08004104 }
Quinn Trana4239942017-12-28 12:33:26 -08004105
4106 if (!sp->u.iocb_cmd.u.ctarg.req || !sp->u.iocb_cmd.u.ctarg.rsp) {
4107 ql_log(ql_log_warn, vha, 0xffff,
4108 "%s: req %p rsp %p are not setup\n",
4109 __func__, sp->u.iocb_cmd.u.ctarg.req,
4110 sp->u.iocb_cmd.u.ctarg.rsp);
Quinn Tranf352eeb2017-12-28 12:33:35 -08004111 vha->scan.scan_flags &= ~SF_SCANNING;
Quinn Trana4239942017-12-28 12:33:26 -08004112 WARN_ON(1);
4113 goto done_free_sp;
4114 }
4115 sp->type = SRB_CT_PTHRU_CMD;
4116 sp->name = "gnnft";
4117 sp->gen1 = vha->hw->base_qpair->chip_reset;
4118 sp->gen2 = fc4_type;
4119 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
4120
4121 memset(sp->u.iocb_cmd.u.ctarg.rsp, 0, sp->u.iocb_cmd.u.ctarg.rsp_size);
4122 memset(sp->u.iocb_cmd.u.ctarg.req, 0, sp->u.iocb_cmd.u.ctarg.req_size);
4123
4124 ct_sns = (struct ct_sns_pkt *)sp->u.iocb_cmd.u.ctarg.req;
4125 /* CT_IU preamble */
4126 ct_req = qla2x00_prep_ct_req(ct_sns, GNN_FT_CMD,
4127 sp->u.iocb_cmd.u.ctarg.rsp_size);
4128
4129 /* GPN_FT req */
4130 ct_req->req.gpn_ft.port_type = fc4_type;
4131
4132 sp->u.iocb_cmd.u.ctarg.req_size = GNN_FT_REQ_SIZE;
4133 sp->u.iocb_cmd.u.ctarg.nport_handle = NPH_SNS;
4134
4135 sp->u.iocb_cmd.timeout = qla2x00_async_iocb_timeout;
4136 sp->done = qla2x00_async_gpnft_gnnft_sp_done;
4137
4138 rval = qla2x00_start_sp(sp);
4139 if (rval != QLA_SUCCESS)
4140 goto done_free_sp;
4141
4142 ql_dbg(ql_dbg_disc, vha, 0xffff,
4143 "Async-%s hdl=%x FC4Type %x.\n", sp->name,
4144 sp->handle, ct_req->req.gpn_ft.port_type);
4145 return rval;
4146
4147done_free_sp:
4148 if (sp->u.iocb_cmd.u.ctarg.req) {
4149 dma_free_coherent(&vha->hw->pdev->dev,
4150 sizeof(struct ct_sns_pkt),
4151 sp->u.iocb_cmd.u.ctarg.req,
4152 sp->u.iocb_cmd.u.ctarg.req_dma);
4153 sp->u.iocb_cmd.u.ctarg.req = NULL;
4154 }
4155 if (sp->u.iocb_cmd.u.ctarg.rsp) {
4156 dma_free_coherent(&vha->hw->pdev->dev,
4157 sizeof(struct ct_sns_pkt),
4158 sp->u.iocb_cmd.u.ctarg.rsp,
4159 sp->u.iocb_cmd.u.ctarg.rsp_dma);
4160 sp->u.iocb_cmd.u.ctarg.rsp = NULL;
4161 }
4162
4163 sp->free(sp);
4164
4165 return rval;
4166} /* GNNFT */
4167
4168void qla24xx_async_gpnft_done(scsi_qla_host_t *vha, srb_t *sp)
4169{
4170 ql_dbg(ql_dbg_disc, vha, 0xffff,
4171 "%s enter\n", __func__);
4172 del_timer(&sp->u.iocb_cmd.timer);
4173 qla24xx_async_gnnft(vha, sp, sp->gen2);
4174}
4175
4176/* Get WWPN list for certain fc4_type */
4177int qla24xx_async_gpnft(scsi_qla_host_t *vha, u8 fc4_type)
4178{
4179 int rval = QLA_FUNCTION_FAILED;
4180 struct ct_sns_req *ct_req;
4181 srb_t *sp;
4182 struct ct_sns_pkt *ct_sns;
4183 u32 rspsz;
Quinn Tranf352eeb2017-12-28 12:33:35 -08004184 unsigned long flags;
Quinn Trana4239942017-12-28 12:33:26 -08004185
4186 if (!vha->flags.online)
4187 return rval;
4188
Quinn Tranf352eeb2017-12-28 12:33:35 -08004189 spin_lock_irqsave(&vha->work_lock, flags);
4190 if (vha->scan.scan_flags & SF_SCANNING) {
4191 spin_unlock_irqrestore(&vha->work_lock, flags);
4192 ql_dbg(ql_dbg_disc, vha, 0xffff, "scan active\n");
Quinn Trana4239942017-12-28 12:33:26 -08004193 return rval;
Quinn Tranf352eeb2017-12-28 12:33:35 -08004194 }
4195 vha->scan.scan_flags |= SF_SCANNING;
4196 spin_unlock_irqrestore(&vha->work_lock, flags);
Quinn Trana4239942017-12-28 12:33:26 -08004197
Quinn Tranf352eeb2017-12-28 12:33:35 -08004198 sp = qla2x00_get_sp(vha, NULL, GFP_KERNEL);
4199 if (!sp) {
4200 vha->scan.scan_flags &= ~SF_SCANNING;
4201 return rval;
4202 }
Quinn Trana4239942017-12-28 12:33:26 -08004203
4204 sp->type = SRB_CT_PTHRU_CMD;
4205 sp->name = "gpnft";
4206 sp->gen1 = vha->hw->base_qpair->chip_reset;
4207 sp->gen2 = fc4_type;
4208 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
4209
4210 sp->u.iocb_cmd.u.ctarg.req = dma_zalloc_coherent(&vha->hw->pdev->dev,
4211 sizeof(struct ct_sns_pkt), &sp->u.iocb_cmd.u.ctarg.req_dma,
4212 GFP_KERNEL);
4213 if (!sp->u.iocb_cmd.u.ctarg.req) {
4214 ql_log(ql_log_warn, vha, 0xffff,
4215 "Failed to allocate ct_sns request.\n");
Quinn Tranf352eeb2017-12-28 12:33:35 -08004216 vha->scan.scan_flags &= ~SF_SCANNING;
Quinn Trana4239942017-12-28 12:33:26 -08004217 goto done_free_sp;
4218 }
4219
4220 rspsz = sizeof(struct ct_sns_gpnft_rsp) +
4221 ((vha->hw->max_fibre_devices - 1) *
4222 sizeof(struct ct_sns_gpn_ft_data));
4223
4224 sp->u.iocb_cmd.u.ctarg.rsp = dma_zalloc_coherent(&vha->hw->pdev->dev,
4225 rspsz, &sp->u.iocb_cmd.u.ctarg.rsp_dma, GFP_KERNEL);
4226 if (!sp->u.iocb_cmd.u.ctarg.rsp) {
4227 ql_log(ql_log_warn, vha, 0xffff,
4228 "Failed to allocate ct_sns request.\n");
Quinn Tranf352eeb2017-12-28 12:33:35 -08004229 vha->scan.scan_flags &= ~SF_SCANNING;
Quinn Trana4239942017-12-28 12:33:26 -08004230 goto done_free_sp;
4231 }
4232
4233 memset(vha->scan.l, 0, vha->scan.size);
4234
4235 ct_sns = (struct ct_sns_pkt *)sp->u.iocb_cmd.u.ctarg.req;
4236 /* CT_IU preamble */
4237 ct_req = qla2x00_prep_ct_req(ct_sns, GPN_FT_CMD, rspsz);
4238
4239 /* GPN_FT req */
4240 ct_req->req.gpn_ft.port_type = fc4_type;
4241
4242 sp->u.iocb_cmd.u.ctarg.req_size = GPN_FT_REQ_SIZE;
4243 sp->u.iocb_cmd.u.ctarg.rsp_size = rspsz;
4244 sp->u.iocb_cmd.u.ctarg.nport_handle = NPH_SNS;
4245
4246 sp->u.iocb_cmd.timeout = qla2x00_async_iocb_timeout;
4247 sp->done = qla2x00_async_gpnft_gnnft_sp_done;
4248
4249 rval = qla2x00_start_sp(sp);
Quinn Tranf352eeb2017-12-28 12:33:35 -08004250 if (rval != QLA_SUCCESS) {
4251 vha->scan.scan_flags &= ~SF_SCANNING;
Quinn Trana4239942017-12-28 12:33:26 -08004252 goto done_free_sp;
Quinn Tranf352eeb2017-12-28 12:33:35 -08004253 }
Quinn Trana4239942017-12-28 12:33:26 -08004254
4255 ql_dbg(ql_dbg_disc, vha, 0xffff,
4256 "Async-%s hdl=%x FC4Type %x.\n", sp->name,
4257 sp->handle, ct_req->req.gpn_ft.port_type);
4258 return rval;
4259
4260done_free_sp:
4261 if (sp->u.iocb_cmd.u.ctarg.req) {
4262 dma_free_coherent(&vha->hw->pdev->dev,
4263 sizeof(struct ct_sns_pkt),
4264 sp->u.iocb_cmd.u.ctarg.req,
4265 sp->u.iocb_cmd.u.ctarg.req_dma);
4266 sp->u.iocb_cmd.u.ctarg.req = NULL;
4267 }
4268 if (sp->u.iocb_cmd.u.ctarg.rsp) {
4269 dma_free_coherent(&vha->hw->pdev->dev,
4270 sizeof(struct ct_sns_pkt),
4271 sp->u.iocb_cmd.u.ctarg.rsp,
4272 sp->u.iocb_cmd.u.ctarg.rsp_dma);
4273 sp->u.iocb_cmd.u.ctarg.rsp = NULL;
4274 }
4275
4276 sp->free(sp);
4277
4278 return rval;
4279}
4280
Quinn Tranf352eeb2017-12-28 12:33:35 -08004281void qla_scan_work_fn(struct work_struct *work)
4282{
4283 struct fab_scan *s = container_of(to_delayed_work(work),
4284 struct fab_scan, scan_work);
4285 struct scsi_qla_host *vha = container_of(s, struct scsi_qla_host,
4286 scan);
4287 unsigned long flags;
4288
4289 ql_dbg(ql_dbg_disc, vha, 0xffff,
4290 "%s: schedule loop resync\n", __func__);
4291 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
4292 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4293 qla2xxx_wake_dpc(vha);
4294 spin_lock_irqsave(&vha->work_lock, flags);
4295 vha->scan.scan_flags &= ~SF_QUEUED;
4296 spin_unlock_irqrestore(&vha->work_lock, flags);
4297}
4298
Quinn Trana4239942017-12-28 12:33:26 -08004299/* GNN_ID */
4300void qla24xx_handle_gnnid_event(scsi_qla_host_t *vha, struct event_arg *ea)
4301{
4302 qla24xx_post_gnl_work(vha, ea->fcport);
4303}
4304
4305static void qla2x00_async_gnnid_sp_done(void *s, int res)
4306{
4307 struct srb *sp = s;
4308 struct scsi_qla_host *vha = sp->vha;
4309 fc_port_t *fcport = sp->fcport;
4310 u8 *node_name = fcport->ct_desc.ct_sns->p.rsp.rsp.gnn_id.node_name;
4311 struct event_arg ea;
4312 u64 wwnn;
4313
4314 fcport->flags &= ~FCF_ASYNC_SENT;
4315 wwnn = wwn_to_u64(node_name);
4316 if (wwnn)
4317 memcpy(fcport->node_name, node_name, WWN_SIZE);
4318
4319 memset(&ea, 0, sizeof(ea));
4320 ea.fcport = fcport;
4321 ea.sp = sp;
4322 ea.rc = res;
4323 ea.event = FCME_GNNID_DONE;
4324
4325 ql_dbg(ql_dbg_disc, vha, 0x204f,
4326 "Async done-%s res %x, WWPN %8phC %8phC\n",
4327 sp->name, res, fcport->port_name, fcport->node_name);
4328
4329 qla2x00_fcport_event_handler(vha, &ea);
4330
4331 sp->free(sp);
4332}
4333
4334int qla24xx_async_gnnid(scsi_qla_host_t *vha, fc_port_t *fcport)
4335{
4336 int rval = QLA_FUNCTION_FAILED;
4337 struct ct_sns_req *ct_req;
4338 srb_t *sp;
4339
Quinn Tran3dbec592017-12-28 12:33:40 -08004340 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT))
4341 return rval;
Quinn Trana4239942017-12-28 12:33:26 -08004342
Quinn Trana4239942017-12-28 12:33:26 -08004343 fcport->disc_state = DSC_GNN_ID;
4344 sp = qla2x00_get_sp(vha, fcport, GFP_ATOMIC);
4345 if (!sp)
4346 goto done;
4347
Quinn Tran3dbec592017-12-28 12:33:40 -08004348 fcport->flags |= FCF_ASYNC_SENT;
Quinn Trana4239942017-12-28 12:33:26 -08004349 sp->type = SRB_CT_PTHRU_CMD;
4350 sp->name = "gnnid";
4351 sp->gen1 = fcport->rscn_gen;
4352 sp->gen2 = fcport->login_gen;
4353
4354 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
4355
4356 /* CT_IU preamble */
4357 ct_req = qla2x00_prep_ct_req(fcport->ct_desc.ct_sns, GNN_ID_CMD,
4358 GNN_ID_RSP_SIZE);
4359
4360 /* GNN_ID req */
4361 ct_req->req.port_id.port_id[0] = fcport->d_id.b.domain;
4362 ct_req->req.port_id.port_id[1] = fcport->d_id.b.area;
4363 ct_req->req.port_id.port_id[2] = fcport->d_id.b.al_pa;
4364
4365
4366 /* req & rsp use the same buffer */
4367 sp->u.iocb_cmd.u.ctarg.req = fcport->ct_desc.ct_sns;
4368 sp->u.iocb_cmd.u.ctarg.req_dma = fcport->ct_desc.ct_sns_dma;
4369 sp->u.iocb_cmd.u.ctarg.rsp = fcport->ct_desc.ct_sns;
4370 sp->u.iocb_cmd.u.ctarg.rsp_dma = fcport->ct_desc.ct_sns_dma;
4371 sp->u.iocb_cmd.u.ctarg.req_size = GNN_ID_REQ_SIZE;
4372 sp->u.iocb_cmd.u.ctarg.rsp_size = GNN_ID_RSP_SIZE;
4373 sp->u.iocb_cmd.u.ctarg.nport_handle = NPH_SNS;
4374
4375 sp->u.iocb_cmd.timeout = qla2x00_async_iocb_timeout;
4376 sp->done = qla2x00_async_gnnid_sp_done;
4377
4378 rval = qla2x00_start_sp(sp);
4379 if (rval != QLA_SUCCESS)
4380 goto done_free_sp;
4381 ql_dbg(ql_dbg_disc, vha, 0xffff,
4382 "Async-%s - %8phC hdl=%x loopid=%x portid %06x.\n",
4383 sp->name, fcport->port_name,
4384 sp->handle, fcport->loop_id, fcport->d_id.b24);
4385 return rval;
4386
4387done_free_sp:
4388 sp->free(sp);
Quinn Trana4239942017-12-28 12:33:26 -08004389 fcport->flags &= ~FCF_ASYNC_SENT;
Quinn Tran3dbec592017-12-28 12:33:40 -08004390done:
Quinn Trana4239942017-12-28 12:33:26 -08004391 return rval;
4392}
4393
4394int qla24xx_post_gnnid_work(struct scsi_qla_host *vha, fc_port_t *fcport)
4395{
4396 struct qla_work_evt *e;
4397 int ls;
4398
4399 ls = atomic_read(&vha->loop_state);
4400 if (((ls != LOOP_READY) && (ls != LOOP_UP)) ||
4401 test_bit(UNLOADING, &vha->dpc_flags))
4402 return 0;
4403
4404 e = qla2x00_alloc_work(vha, QLA_EVT_GNNID);
4405 if (!e)
4406 return QLA_FUNCTION_FAILED;
4407
4408 e->u.fcport.fcport = fcport;
4409 return qla2x00_post_work(vha, e);
4410}
4411
4412/* GPFN_ID */
4413void qla24xx_handle_gfpnid_event(scsi_qla_host_t *vha, struct event_arg *ea)
4414{
4415 fc_port_t *fcport = ea->fcport;
4416
4417 ql_dbg(ql_dbg_disc, vha, 0xffff,
Quinn Tranf352eeb2017-12-28 12:33:35 -08004418 "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d fcpcnt %d\n",
4419 __func__, fcport->port_name, fcport->disc_state,
4420 fcport->fw_login_state, ea->rc, fcport->login_gen, ea->sp->gen2,
4421 fcport->rscn_gen, ea->sp->gen1, vha->fcport_count);
Quinn Trana4239942017-12-28 12:33:26 -08004422
4423 if (fcport->disc_state == DSC_DELETE_PEND)
4424 return;
4425
4426 if (ea->sp->gen2 != fcport->login_gen) {
4427 /* target side must have changed it. */
4428 ql_dbg(ql_dbg_disc, vha, 0x20d3,
Quinn Tranf352eeb2017-12-28 12:33:35 -08004429 "%s %8phC generation changed\n",
4430 __func__, fcport->port_name);
Quinn Trana4239942017-12-28 12:33:26 -08004431 return;
4432 } else if (ea->sp->gen1 != fcport->rscn_gen) {
4433 ql_dbg(ql_dbg_disc, vha, 0x20d4, "%s %d %8phC post gidpn\n",
4434 __func__, __LINE__, fcport->port_name);
4435 qla24xx_post_gidpn_work(vha, fcport);
4436 return;
4437 }
4438
4439 qla24xx_post_gpsc_work(vha, fcport);
4440}
4441
4442static void qla2x00_async_gfpnid_sp_done(void *s, int res)
4443{
4444 struct srb *sp = s;
4445 struct scsi_qla_host *vha = sp->vha;
4446 fc_port_t *fcport = sp->fcport;
4447 u8 *fpn = fcport->ct_desc.ct_sns->p.rsp.rsp.gfpn_id.port_name;
4448 struct event_arg ea;
4449 u64 wwn;
4450
4451 fcport->flags &= ~FCF_ASYNC_SENT;
4452 wwn = wwn_to_u64(fpn);
4453 if (wwn)
4454 memcpy(fcport->fabric_port_name, fpn, WWN_SIZE);
4455
4456 memset(&ea, 0, sizeof(ea));
4457 ea.fcport = fcport;
4458 ea.sp = sp;
4459 ea.rc = res;
4460 ea.event = FCME_GFPNID_DONE;
4461
4462 ql_dbg(ql_dbg_disc, vha, 0x204f,
4463 "Async done-%s res %x, WWPN %8phC %8phC\n",
4464 sp->name, res, fcport->port_name, fcport->fabric_port_name);
4465
4466 qla2x00_fcport_event_handler(vha, &ea);
4467
4468 sp->free(sp);
4469}
4470
4471int qla24xx_async_gfpnid(scsi_qla_host_t *vha, fc_port_t *fcport)
4472{
4473 int rval = QLA_FUNCTION_FAILED;
4474 struct ct_sns_req *ct_req;
4475 srb_t *sp;
4476
Quinn Tran3dbec592017-12-28 12:33:40 -08004477 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT))
4478 return rval;
Quinn Trana4239942017-12-28 12:33:26 -08004479
Quinn Trana4239942017-12-28 12:33:26 -08004480 fcport->disc_state = DSC_GFPN_ID;
4481 sp = qla2x00_get_sp(vha, fcport, GFP_ATOMIC);
4482 if (!sp)
4483 goto done;
4484
Quinn Tran3dbec592017-12-28 12:33:40 -08004485 fcport->flags |= FCF_ASYNC_SENT;
Quinn Trana4239942017-12-28 12:33:26 -08004486 sp->type = SRB_CT_PTHRU_CMD;
4487 sp->name = "gfpnid";
4488 sp->gen1 = fcport->rscn_gen;
4489 sp->gen2 = fcport->login_gen;
4490
4491 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
4492
4493 /* CT_IU preamble */
4494 ct_req = qla2x00_prep_ct_req(fcport->ct_desc.ct_sns, GFPN_ID_CMD,
4495 GFPN_ID_RSP_SIZE);
4496
4497 /* GFPN_ID req */
4498 ct_req->req.port_id.port_id[0] = fcport->d_id.b.domain;
4499 ct_req->req.port_id.port_id[1] = fcport->d_id.b.area;
4500 ct_req->req.port_id.port_id[2] = fcport->d_id.b.al_pa;
4501
4502
4503 /* req & rsp use the same buffer */
4504 sp->u.iocb_cmd.u.ctarg.req = fcport->ct_desc.ct_sns;
4505 sp->u.iocb_cmd.u.ctarg.req_dma = fcport->ct_desc.ct_sns_dma;
4506 sp->u.iocb_cmd.u.ctarg.rsp = fcport->ct_desc.ct_sns;
4507 sp->u.iocb_cmd.u.ctarg.rsp_dma = fcport->ct_desc.ct_sns_dma;
4508 sp->u.iocb_cmd.u.ctarg.req_size = GFPN_ID_REQ_SIZE;
4509 sp->u.iocb_cmd.u.ctarg.rsp_size = GFPN_ID_RSP_SIZE;
4510 sp->u.iocb_cmd.u.ctarg.nport_handle = NPH_SNS;
4511
4512 sp->u.iocb_cmd.timeout = qla2x00_async_iocb_timeout;
4513 sp->done = qla2x00_async_gfpnid_sp_done;
4514
4515 rval = qla2x00_start_sp(sp);
4516 if (rval != QLA_SUCCESS)
4517 goto done_free_sp;
4518
4519 ql_dbg(ql_dbg_disc, vha, 0xffff,
4520 "Async-%s - %8phC hdl=%x loopid=%x portid %06x.\n",
4521 sp->name, fcport->port_name,
4522 sp->handle, fcport->loop_id, fcport->d_id.b24);
4523 return rval;
4524
4525done_free_sp:
4526 sp->free(sp);
Quinn Trana4239942017-12-28 12:33:26 -08004527 fcport->flags &= ~FCF_ASYNC_SENT;
Quinn Tran3dbec592017-12-28 12:33:40 -08004528done:
Quinn Trana4239942017-12-28 12:33:26 -08004529 return rval;
4530}
4531
4532int qla24xx_post_gfpnid_work(struct scsi_qla_host *vha, fc_port_t *fcport)
4533{
4534 struct qla_work_evt *e;
4535 int ls;
4536
4537 ls = atomic_read(&vha->loop_state);
4538 if (((ls != LOOP_READY) && (ls != LOOP_UP)) ||
4539 test_bit(UNLOADING, &vha->dpc_flags))
4540 return 0;
4541
4542 e = qla2x00_alloc_work(vha, QLA_EVT_GFPNID);
4543 if (!e)
4544 return QLA_FUNCTION_FAILED;
4545
4546 e->u.fcport.fcport = fcport;
4547 return qla2x00_post_work(vha, e);
4548}