blob: 09f7a8cfed4d0580324f363d52368fecb0d2af83 [file] [log] [blame]
Giridhar Malavali6e980162010-03-19 17:03:58 -07001/*
2 * QLogic Fibre Channel HBA Driver
Armen Baloyanbd21eaf2014-04-11 16:54:24 -04003 * Copyright (c) 2003-2014 QLogic Corporation
Giridhar Malavali6e980162010-03-19 17:03:58 -07004 *
5 * See LICENSE.qla2xxx for copyright and licensing details.
6 */
7#include "qla_def.h"
8
9#include <linux/kthread.h>
10#include <linux/vmalloc.h>
11#include <linux/delay.h>
12
13/* BSG support for ELS/CT pass through */
Giridhar Malavali9ba56b92012-02-09 11:15:36 -080014void
15qla2x00_bsg_job_done(void *data, void *ptr, int res)
Giridhar Malavali6e980162010-03-19 17:03:58 -070016{
Giridhar Malavali9ba56b92012-02-09 11:15:36 -080017 srb_t *sp = (srb_t *)ptr;
18 struct scsi_qla_host *vha = (scsi_qla_host_t *)data;
19 struct fc_bsg_job *bsg_job = sp->u.bsg_job;
20
21 bsg_job->reply->result = res;
22 bsg_job->job_done(bsg_job);
23 sp->free(vha, sp);
24}
25
26void
27qla2x00_bsg_sp_free(void *data, void *ptr)
28{
29 srb_t *sp = (srb_t *)ptr;
Chad Dupuisb00ee7d2013-02-08 01:57:50 -050030 struct scsi_qla_host *vha = sp->fcport->vha;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -080031 struct fc_bsg_job *bsg_job = sp->u.bsg_job;
Giridhar Malavali6e980162010-03-19 17:03:58 -070032 struct qla_hw_data *ha = vha->hw;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -040033 struct qla_mt_iocb_rqst_fx00 *piocb_rqst;
Giridhar Malavali6e980162010-03-19 17:03:58 -070034
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -040035 if (sp->type == SRB_FXIOCB_BCMD) {
36 piocb_rqst = (struct qla_mt_iocb_rqst_fx00 *)
37 &bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
Giridhar Malavali6e980162010-03-19 17:03:58 -070038
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -040039 if (piocb_rqst->flags & SRB_FXDISC_REQ_DMA_VALID)
40 dma_unmap_sg(&ha->pdev->dev,
41 bsg_job->request_payload.sg_list,
42 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
43
44 if (piocb_rqst->flags & SRB_FXDISC_RESP_DMA_VALID)
45 dma_unmap_sg(&ha->pdev->dev,
46 bsg_job->reply_payload.sg_list,
47 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
48 } else {
49 dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
50 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
51
52 dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
53 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
54 }
Giridhar Malavali9ba56b92012-02-09 11:15:36 -080055
56 if (sp->type == SRB_CT_CMD ||
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -040057 sp->type == SRB_FXIOCB_BCMD ||
Giridhar Malavali9ba56b92012-02-09 11:15:36 -080058 sp->type == SRB_ELS_CMD_HST)
59 kfree(sp->fcport);
Chad Dupuisb00ee7d2013-02-08 01:57:50 -050060 qla2x00_rel_sp(vha, sp);
Giridhar Malavali6e980162010-03-19 17:03:58 -070061}
62
Sarang Radke09ff7012010-03-19 17:03:59 -070063int
Saurav Kashyap7c3df132011-07-14 12:00:13 -070064qla24xx_fcp_prio_cfg_valid(scsi_qla_host_t *vha,
65 struct qla_fcp_prio_cfg *pri_cfg, uint8_t flag)
Sarang Radke09ff7012010-03-19 17:03:59 -070066{
67 int i, ret, num_valid;
68 uint8_t *bcode;
69 struct qla_fcp_prio_entry *pri_entry;
Madhuranath Iyengar2f0f3f42010-07-23 15:28:24 +050070 uint32_t *bcode_val_ptr, bcode_val;
Sarang Radke09ff7012010-03-19 17:03:59 -070071
72 ret = 1;
73 num_valid = 0;
74 bcode = (uint8_t *)pri_cfg;
Madhuranath Iyengar2f0f3f42010-07-23 15:28:24 +050075 bcode_val_ptr = (uint32_t *)pri_cfg;
76 bcode_val = (uint32_t)(*bcode_val_ptr);
Sarang Radke09ff7012010-03-19 17:03:59 -070077
Madhuranath Iyengar2f0f3f42010-07-23 15:28:24 +050078 if (bcode_val == 0xFFFFFFFF) {
79 /* No FCP Priority config data in flash */
Saurav Kashyap7c3df132011-07-14 12:00:13 -070080 ql_dbg(ql_dbg_user, vha, 0x7051,
81 "No FCP Priority config data.\n");
Madhuranath Iyengar2f0f3f42010-07-23 15:28:24 +050082 return 0;
83 }
84
85 if (bcode[0] != 'H' || bcode[1] != 'Q' || bcode[2] != 'O' ||
86 bcode[3] != 'S') {
87 /* Invalid FCP priority data header*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -070088 ql_dbg(ql_dbg_user, vha, 0x7052,
89 "Invalid FCP Priority data header. bcode=0x%x.\n",
90 bcode_val);
Sarang Radke09ff7012010-03-19 17:03:59 -070091 return 0;
92 }
93 if (flag != 1)
94 return ret;
95
96 pri_entry = &pri_cfg->entry[0];
97 for (i = 0; i < pri_cfg->num_entries; i++) {
98 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
99 num_valid++;
100 pri_entry++;
101 }
102
Madhuranath Iyengar2f0f3f42010-07-23 15:28:24 +0500103 if (num_valid == 0) {
104 /* No valid FCP priority data entries */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700105 ql_dbg(ql_dbg_user, vha, 0x7053,
106 "No valid FCP Priority data entries.\n");
Sarang Radke09ff7012010-03-19 17:03:59 -0700107 ret = 0;
Madhuranath Iyengar2f0f3f42010-07-23 15:28:24 +0500108 } else {
109 /* FCP priority data is valid */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700110 ql_dbg(ql_dbg_user, vha, 0x7054,
111 "Valid FCP priority data. num entries = %d.\n",
112 num_valid);
Madhuranath Iyengar2f0f3f42010-07-23 15:28:24 +0500113 }
Sarang Radke09ff7012010-03-19 17:03:59 -0700114
115 return ret;
116}
117
118static int
119qla24xx_proc_fcp_prio_cfg_cmd(struct fc_bsg_job *bsg_job)
120{
121 struct Scsi_Host *host = bsg_job->shost;
122 scsi_qla_host_t *vha = shost_priv(host);
123 struct qla_hw_data *ha = vha->hw;
124 int ret = 0;
125 uint32_t len;
126 uint32_t oper;
127
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400128 if (!(IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha) || IS_P3P_TYPE(ha))) {
Madhuranath Iyengar2f0f3f42010-07-23 15:28:24 +0500129 ret = -EINVAL;
130 goto exit_fcp_prio_cfg;
131 }
132
Sarang Radke09ff7012010-03-19 17:03:59 -0700133 /* Get the sub command */
134 oper = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
135
136 /* Only set config is allowed if config memory is not allocated */
137 if (!ha->fcp_prio_cfg && (oper != QLFC_FCP_PRIO_SET_CONFIG)) {
138 ret = -EINVAL;
139 goto exit_fcp_prio_cfg;
140 }
141 switch (oper) {
142 case QLFC_FCP_PRIO_DISABLE:
143 if (ha->flags.fcp_prio_enabled) {
144 ha->flags.fcp_prio_enabled = 0;
145 ha->fcp_prio_cfg->attributes &=
146 ~FCP_PRIO_ATTR_ENABLE;
147 qla24xx_update_all_fcp_prio(vha);
148 bsg_job->reply->result = DID_OK;
149 } else {
150 ret = -EINVAL;
151 bsg_job->reply->result = (DID_ERROR << 16);
152 goto exit_fcp_prio_cfg;
153 }
154 break;
155
156 case QLFC_FCP_PRIO_ENABLE:
157 if (!ha->flags.fcp_prio_enabled) {
158 if (ha->fcp_prio_cfg) {
159 ha->flags.fcp_prio_enabled = 1;
160 ha->fcp_prio_cfg->attributes |=
161 FCP_PRIO_ATTR_ENABLE;
162 qla24xx_update_all_fcp_prio(vha);
163 bsg_job->reply->result = DID_OK;
164 } else {
165 ret = -EINVAL;
166 bsg_job->reply->result = (DID_ERROR << 16);
167 goto exit_fcp_prio_cfg;
168 }
169 }
170 break;
171
172 case QLFC_FCP_PRIO_GET_CONFIG:
173 len = bsg_job->reply_payload.payload_len;
174 if (!len || len > FCP_PRIO_CFG_SIZE) {
175 ret = -EINVAL;
176 bsg_job->reply->result = (DID_ERROR << 16);
177 goto exit_fcp_prio_cfg;
178 }
179
180 bsg_job->reply->result = DID_OK;
181 bsg_job->reply->reply_payload_rcv_len =
182 sg_copy_from_buffer(
183 bsg_job->reply_payload.sg_list,
184 bsg_job->reply_payload.sg_cnt, ha->fcp_prio_cfg,
185 len);
186
187 break;
188
189 case QLFC_FCP_PRIO_SET_CONFIG:
190 len = bsg_job->request_payload.payload_len;
191 if (!len || len > FCP_PRIO_CFG_SIZE) {
192 bsg_job->reply->result = (DID_ERROR << 16);
193 ret = -EINVAL;
194 goto exit_fcp_prio_cfg;
195 }
196
197 if (!ha->fcp_prio_cfg) {
198 ha->fcp_prio_cfg = vmalloc(FCP_PRIO_CFG_SIZE);
199 if (!ha->fcp_prio_cfg) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700200 ql_log(ql_log_warn, vha, 0x7050,
201 "Unable to allocate memory for fcp prio "
202 "config data (%x).\n", FCP_PRIO_CFG_SIZE);
Sarang Radke09ff7012010-03-19 17:03:59 -0700203 bsg_job->reply->result = (DID_ERROR << 16);
204 ret = -ENOMEM;
205 goto exit_fcp_prio_cfg;
206 }
207 }
208
209 memset(ha->fcp_prio_cfg, 0, FCP_PRIO_CFG_SIZE);
210 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
211 bsg_job->request_payload.sg_cnt, ha->fcp_prio_cfg,
212 FCP_PRIO_CFG_SIZE);
213
214 /* validate fcp priority data */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700215
216 if (!qla24xx_fcp_prio_cfg_valid(vha,
217 (struct qla_fcp_prio_cfg *) ha->fcp_prio_cfg, 1)) {
Sarang Radke09ff7012010-03-19 17:03:59 -0700218 bsg_job->reply->result = (DID_ERROR << 16);
219 ret = -EINVAL;
220 /* If buffer was invalidatic int
221 * fcp_prio_cfg is of no use
222 */
223 vfree(ha->fcp_prio_cfg);
224 ha->fcp_prio_cfg = NULL;
225 goto exit_fcp_prio_cfg;
226 }
227
228 ha->flags.fcp_prio_enabled = 0;
229 if (ha->fcp_prio_cfg->attributes & FCP_PRIO_ATTR_ENABLE)
230 ha->flags.fcp_prio_enabled = 1;
231 qla24xx_update_all_fcp_prio(vha);
232 bsg_job->reply->result = DID_OK;
233 break;
234 default:
235 ret = -EINVAL;
236 break;
237 }
238exit_fcp_prio_cfg:
Armen Baloyan63ea9232012-11-21 02:39:53 -0500239 if (!ret)
240 bsg_job->job_done(bsg_job);
Sarang Radke09ff7012010-03-19 17:03:59 -0700241 return ret;
242}
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800243
Giridhar Malavali6e980162010-03-19 17:03:58 -0700244static int
245qla2x00_process_els(struct fc_bsg_job *bsg_job)
246{
247 struct fc_rport *rport;
Harish Zunjarrao08f71e02010-07-23 15:28:33 +0500248 fc_port_t *fcport = NULL;
Giridhar Malavali6e980162010-03-19 17:03:58 -0700249 struct Scsi_Host *host;
250 scsi_qla_host_t *vha;
251 struct qla_hw_data *ha;
252 srb_t *sp;
253 const char *type;
254 int req_sg_cnt, rsp_sg_cnt;
Hannes Reinecke59e736b2019-10-18 16:04:58 +0200255 int rval = (DID_ERROR << 16);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700256 uint16_t nextlid = 0;
Giridhar Malavali6e980162010-03-19 17:03:58 -0700257
Harish Zunjarrao08f71e02010-07-23 15:28:33 +0500258 if (bsg_job->request->msgcode == FC_BSG_RPT_ELS) {
259 rport = bsg_job->rport;
260 fcport = *(fc_port_t **) rport->dd_data;
261 host = rport_to_shost(rport);
262 vha = shost_priv(host);
263 ha = vha->hw;
264 type = "FC_BSG_RPT_ELS";
265 } else {
266 host = bsg_job->shost;
267 vha = shost_priv(host);
268 ha = vha->hw;
269 type = "FC_BSG_HST_ELS_NOLOGIN";
270 }
271
Bart Van Assche8c0eb592013-06-25 11:27:31 -0400272 if (!vha->flags.online) {
273 ql_log(ql_log_warn, vha, 0x7005, "Host not online.\n");
274 rval = -EIO;
275 goto done;
276 }
277
Harish Zunjarrao08f71e02010-07-23 15:28:33 +0500278 /* pass through is supported only for ISP 4Gb or higher */
279 if (!IS_FWI2_CAPABLE(ha)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700280 ql_dbg(ql_dbg_user, vha, 0x7001,
281 "ELS passthru not supported for ISP23xx based adapters.\n");
Harish Zunjarrao08f71e02010-07-23 15:28:33 +0500282 rval = -EPERM;
283 goto done;
284 }
285
Giridhar Malavali6e980162010-03-19 17:03:58 -0700286 /* Multiple SG's are not supported for ELS requests */
287 if (bsg_job->request_payload.sg_cnt > 1 ||
288 bsg_job->reply_payload.sg_cnt > 1) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700289 ql_dbg(ql_dbg_user, vha, 0x7002,
290 "Multiple SG's are not suppored for ELS requests, "
291 "request_sg_cnt=%x reply_sg_cnt=%x.\n",
292 bsg_job->request_payload.sg_cnt,
293 bsg_job->reply_payload.sg_cnt);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700294 rval = -EPERM;
295 goto done;
296 }
297
298 /* ELS request for rport */
299 if (bsg_job->request->msgcode == FC_BSG_RPT_ELS) {
Giridhar Malavali6e980162010-03-19 17:03:58 -0700300 /* make sure the rport is logged in,
301 * if not perform fabric login
302 */
303 if (qla2x00_fabric_login(vha, fcport, &nextlid)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700304 ql_dbg(ql_dbg_user, vha, 0x7003,
305 "Failed to login port %06X for ELS passthru.\n",
306 fcport->d_id.b24);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700307 rval = -EIO;
308 goto done;
309 }
310 } else {
Giridhar Malavali6e980162010-03-19 17:03:58 -0700311 /* Allocate a dummy fcport structure, since functions
312 * preparing the IOCB and mailbox command retrieves port
313 * specific information from fcport structure. For Host based
314 * ELS commands there will be no fcport structure allocated
315 */
316 fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
317 if (!fcport) {
318 rval = -ENOMEM;
319 goto done;
320 }
321
322 /* Initialize all required fields of fcport */
323 fcport->vha = vha;
Giridhar Malavali6e980162010-03-19 17:03:58 -0700324 fcport->d_id.b.al_pa =
325 bsg_job->request->rqst_data.h_els.port_id[0];
326 fcport->d_id.b.area =
327 bsg_job->request->rqst_data.h_els.port_id[1];
328 fcport->d_id.b.domain =
329 bsg_job->request->rqst_data.h_els.port_id[2];
330 fcport->loop_id =
331 (fcport->d_id.b.al_pa == 0xFD) ?
332 NPH_FABRIC_CONTROLLER : NPH_F_PORT;
333 }
334
Giridhar Malavali6e980162010-03-19 17:03:58 -0700335 req_sg_cnt =
336 dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
337 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
338 if (!req_sg_cnt) {
Himanshu Madhani0f37bd02019-07-26 09:07:26 -0700339 dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
340 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700341 rval = -ENOMEM;
342 goto done_free_fcport;
343 }
Andrew Vasquez6c452a42010-03-19 17:04:02 -0700344
345 rsp_sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
346 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700347 if (!rsp_sg_cnt) {
Himanshu Madhani0f37bd02019-07-26 09:07:26 -0700348 dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
349 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700350 rval = -ENOMEM;
351 goto done_free_fcport;
352 }
353
354 if ((req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
Andrew Vasquez6c452a42010-03-19 17:04:02 -0700355 (rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700356 ql_log(ql_log_warn, vha, 0x7008,
357 "dma mapping resulted in different sg counts, "
358 "request_sg_cnt: %x dma_request_sg_cnt:%x reply_sg_cnt:%x "
359 "dma_reply_sg_cnt:%x.\n", bsg_job->request_payload.sg_cnt,
360 req_sg_cnt, bsg_job->reply_payload.sg_cnt, rsp_sg_cnt);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700361 rval = -EAGAIN;
362 goto done_unmap_sg;
363 }
364
365 /* Alloc SRB structure */
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800366 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700367 if (!sp) {
368 rval = -ENOMEM;
Andrew Vasquez6c452a42010-03-19 17:04:02 -0700369 goto done_unmap_sg;
Giridhar Malavali6e980162010-03-19 17:03:58 -0700370 }
371
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800372 sp->type =
Giridhar Malavali6e980162010-03-19 17:03:58 -0700373 (bsg_job->request->msgcode == FC_BSG_RPT_ELS ?
374 SRB_ELS_CMD_RPT : SRB_ELS_CMD_HST);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800375 sp->name =
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700376 (bsg_job->request->msgcode == FC_BSG_RPT_ELS ?
377 "bsg_els_rpt" : "bsg_els_hst");
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800378 sp->u.bsg_job = bsg_job;
379 sp->free = qla2x00_bsg_sp_free;
380 sp->done = qla2x00_bsg_job_done;
Giridhar Malavali6e980162010-03-19 17:03:58 -0700381
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700382 ql_dbg(ql_dbg_user, vha, 0x700a,
383 "bsg rqst type: %s els type: %x - loop-id=%x "
384 "portid=%-2x%02x%02x.\n", type,
385 bsg_job->request->rqst_data.h_els.command_code, fcport->loop_id,
386 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700387
388 rval = qla2x00_start_sp(sp);
389 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700390 ql_log(ql_log_warn, vha, 0x700e,
391 "qla2x00_start_sp failed = %d\n", rval);
Chad Dupuisb00ee7d2013-02-08 01:57:50 -0500392 qla2x00_rel_sp(vha, sp);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700393 rval = -EIO;
394 goto done_unmap_sg;
395 }
396 return rval;
397
398done_unmap_sg:
399 dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
400 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
401 dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
402 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
403 goto done_free_fcport;
404
405done_free_fcport:
Bart Van Assche8c0eb592013-06-25 11:27:31 -0400406 if (bsg_job->request->msgcode == FC_BSG_RPT_ELS)
Giridhar Malavali6e980162010-03-19 17:03:58 -0700407 kfree(fcport);
408done:
409 return rval;
410}
411
Bart Van Assche2374dd22015-07-09 07:23:02 -0700412static inline uint16_t
Andrew Vasquez57807902011-11-18 09:03:20 -0800413qla24xx_calc_ct_iocbs(uint16_t dsds)
414{
415 uint16_t iocbs;
416
417 iocbs = 1;
418 if (dsds > 2) {
419 iocbs += (dsds - 2) / 5;
420 if ((dsds - 2) % 5)
421 iocbs++;
422 }
423 return iocbs;
424}
425
Giridhar Malavali6e980162010-03-19 17:03:58 -0700426static int
427qla2x00_process_ct(struct fc_bsg_job *bsg_job)
428{
429 srb_t *sp;
430 struct Scsi_Host *host = bsg_job->shost;
431 scsi_qla_host_t *vha = shost_priv(host);
432 struct qla_hw_data *ha = vha->hw;
Hannes Reinecke59e736b2019-10-18 16:04:58 +0200433 int rval = (DID_ERROR << 16);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700434 int req_sg_cnt, rsp_sg_cnt;
435 uint16_t loop_id;
436 struct fc_port *fcport;
437 char *type = "FC_BSG_HST_CT";
Giridhar Malavali6e980162010-03-19 17:03:58 -0700438
Giridhar Malavali6e980162010-03-19 17:03:58 -0700439 req_sg_cnt =
440 dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
441 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
Andrew Vasquez6c452a42010-03-19 17:04:02 -0700442 if (!req_sg_cnt) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700443 ql_log(ql_log_warn, vha, 0x700f,
444 "dma_map_sg return %d for request\n", req_sg_cnt);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700445 rval = -ENOMEM;
446 goto done;
447 }
448
449 rsp_sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
450 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
451 if (!rsp_sg_cnt) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700452 ql_log(ql_log_warn, vha, 0x7010,
453 "dma_map_sg return %d for reply\n", rsp_sg_cnt);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700454 rval = -ENOMEM;
455 goto done;
456 }
457
458 if ((req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
Andrew Vasquez6c452a42010-03-19 17:04:02 -0700459 (rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700460 ql_log(ql_log_warn, vha, 0x7011,
461 "request_sg_cnt: %x dma_request_sg_cnt: %x reply_sg_cnt:%x "
462 "dma_reply_sg_cnt: %x\n", bsg_job->request_payload.sg_cnt,
463 req_sg_cnt, bsg_job->reply_payload.sg_cnt, rsp_sg_cnt);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700464 rval = -EAGAIN;
Andrew Vasquez6c452a42010-03-19 17:04:02 -0700465 goto done_unmap_sg;
Giridhar Malavali6e980162010-03-19 17:03:58 -0700466 }
467
468 if (!vha->flags.online) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700469 ql_log(ql_log_warn, vha, 0x7012,
470 "Host is not online.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -0700471 rval = -EIO;
472 goto done_unmap_sg;
473 }
474
475 loop_id =
476 (bsg_job->request->rqst_data.h_ct.preamble_word1 & 0xFF000000)
477 >> 24;
478 switch (loop_id) {
Andrew Vasquez6c452a42010-03-19 17:04:02 -0700479 case 0xFC:
480 loop_id = cpu_to_le16(NPH_SNS);
481 break;
482 case 0xFA:
483 loop_id = vha->mgmt_svr_loop_id;
484 break;
485 default:
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700486 ql_dbg(ql_dbg_user, vha, 0x7013,
487 "Unknown loop id: %x.\n", loop_id);
Andrew Vasquez6c452a42010-03-19 17:04:02 -0700488 rval = -EINVAL;
489 goto done_unmap_sg;
Giridhar Malavali6e980162010-03-19 17:03:58 -0700490 }
491
492 /* Allocate a dummy fcport structure, since functions preparing the
493 * IOCB and mailbox command retrieves port specific information
494 * from fcport structure. For Host based ELS commands there will be
495 * no fcport structure allocated
496 */
497 fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Andrew Vasquez6c452a42010-03-19 17:04:02 -0700498 if (!fcport) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700499 ql_log(ql_log_warn, vha, 0x7014,
500 "Failed to allocate fcport.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -0700501 rval = -ENOMEM;
Andrew Vasquez6c452a42010-03-19 17:04:02 -0700502 goto done_unmap_sg;
Giridhar Malavali6e980162010-03-19 17:03:58 -0700503 }
504
505 /* Initialize all required fields of fcport */
506 fcport->vha = vha;
Giridhar Malavali6e980162010-03-19 17:03:58 -0700507 fcport->d_id.b.al_pa = bsg_job->request->rqst_data.h_ct.port_id[0];
508 fcport->d_id.b.area = bsg_job->request->rqst_data.h_ct.port_id[1];
509 fcport->d_id.b.domain = bsg_job->request->rqst_data.h_ct.port_id[2];
510 fcport->loop_id = loop_id;
511
512 /* Alloc SRB structure */
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800513 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700514 if (!sp) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700515 ql_log(ql_log_warn, vha, 0x7015,
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800516 "qla2x00_get_sp failed.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -0700517 rval = -ENOMEM;
518 goto done_free_fcport;
519 }
520
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800521 sp->type = SRB_CT_CMD;
522 sp->name = "bsg_ct";
523 sp->iocbs = qla24xx_calc_ct_iocbs(req_sg_cnt + rsp_sg_cnt);
524 sp->u.bsg_job = bsg_job;
525 sp->free = qla2x00_bsg_sp_free;
526 sp->done = qla2x00_bsg_job_done;
Giridhar Malavali6e980162010-03-19 17:03:58 -0700527
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700528 ql_dbg(ql_dbg_user, vha, 0x7016,
529 "bsg rqst type: %s else type: %x - "
530 "loop-id=%x portid=%02x%02x%02x.\n", type,
531 (bsg_job->request->rqst_data.h_ct.preamble_word2 >> 16),
532 fcport->loop_id, fcport->d_id.b.domain, fcport->d_id.b.area,
533 fcport->d_id.b.al_pa);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700534
535 rval = qla2x00_start_sp(sp);
536 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700537 ql_log(ql_log_warn, vha, 0x7017,
538 "qla2x00_start_sp failed=%d.\n", rval);
Chad Dupuisb00ee7d2013-02-08 01:57:50 -0500539 qla2x00_rel_sp(vha, sp);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700540 rval = -EIO;
541 goto done_free_fcport;
542 }
543 return rval;
544
545done_free_fcport:
546 kfree(fcport);
547done_unmap_sg:
548 dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
549 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
550 dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
551 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
552done:
553 return rval;
554}
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700555
Chad Dupuis8fcd6b82012-08-22 14:21:06 -0400556/* Disable loopback mode */
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700557static inline int
Chad Dupuis8fcd6b82012-08-22 14:21:06 -0400558qla81xx_reset_loopback_mode(scsi_qla_host_t *vha, uint16_t *config,
Chad Dupuisf356bef2013-02-08 01:58:04 -0500559 int wait, int wait2)
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700560{
561 int ret = 0;
562 int rval = 0;
563 uint16_t new_config[4];
564 struct qla_hw_data *ha = vha->hw;
565
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400566 if (!IS_QLA81XX(ha) && !IS_QLA8031(ha) && !IS_QLA8044(ha))
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700567 goto done_reset_internal;
568
569 memset(new_config, 0 , sizeof(new_config));
570 if ((config[0] & INTERNAL_LOOPBACK_MASK) >> 1 ==
Chad Dupuis8fcd6b82012-08-22 14:21:06 -0400571 ENABLE_INTERNAL_LOOPBACK ||
572 (config[0] & INTERNAL_LOOPBACK_MASK) >> 1 ==
573 ENABLE_EXTERNAL_LOOPBACK) {
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700574 new_config[0] = config[0] & ~INTERNAL_LOOPBACK_MASK;
Chad Dupuis8fcd6b82012-08-22 14:21:06 -0400575 ql_dbg(ql_dbg_user, vha, 0x70bf, "new_config[0]=%02x\n",
576 (new_config[0] & INTERNAL_LOOPBACK_MASK));
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700577 memcpy(&new_config[1], &config[1], sizeof(uint16_t) * 3) ;
578
579 ha->notify_dcbx_comp = wait;
Chad Dupuisf356bef2013-02-08 01:58:04 -0500580 ha->notify_lb_portup_comp = wait2;
581
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700582 ret = qla81xx_set_port_config(vha, new_config);
583 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700584 ql_log(ql_log_warn, vha, 0x7025,
585 "Set port config failed.\n");
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700586 ha->notify_dcbx_comp = 0;
Chad Dupuisf356bef2013-02-08 01:58:04 -0500587 ha->notify_lb_portup_comp = 0;
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700588 rval = -EINVAL;
589 goto done_reset_internal;
590 }
591
592 /* Wait for DCBX complete event */
593 if (wait && !wait_for_completion_timeout(&ha->dcbx_comp,
Chad Dupuisf356bef2013-02-08 01:58:04 -0500594 (DCBX_COMP_TIMEOUT * HZ))) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700595 ql_dbg(ql_dbg_user, vha, 0x7026,
Chad Dupuisf356bef2013-02-08 01:58:04 -0500596 "DCBX completion not received.\n");
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700597 ha->notify_dcbx_comp = 0;
Chad Dupuisf356bef2013-02-08 01:58:04 -0500598 ha->notify_lb_portup_comp = 0;
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700599 rval = -EINVAL;
600 goto done_reset_internal;
601 } else
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700602 ql_dbg(ql_dbg_user, vha, 0x7027,
Chad Dupuisf356bef2013-02-08 01:58:04 -0500603 "DCBX completion received.\n");
604
605 if (wait2 &&
606 !wait_for_completion_timeout(&ha->lb_portup_comp,
607 (LB_PORTUP_COMP_TIMEOUT * HZ))) {
608 ql_dbg(ql_dbg_user, vha, 0x70c5,
609 "Port up completion not received.\n");
610 ha->notify_lb_portup_comp = 0;
611 rval = -EINVAL;
612 goto done_reset_internal;
613 } else
614 ql_dbg(ql_dbg_user, vha, 0x70c6,
615 "Port up completion received.\n");
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700616
617 ha->notify_dcbx_comp = 0;
Chad Dupuisf356bef2013-02-08 01:58:04 -0500618 ha->notify_lb_portup_comp = 0;
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700619 }
620done_reset_internal:
621 return rval;
622}
623
Chad Dupuis67b2a312013-02-08 01:57:51 -0500624/*
625 * Set the port configuration to enable the internal or external loopback
626 * depending on the loopback mode.
627 */
628static inline int
629qla81xx_set_loopback_mode(scsi_qla_host_t *vha, uint16_t *config,
630 uint16_t *new_config, uint16_t mode)
631{
632 int ret = 0;
633 int rval = 0;
Santosh Vernekar454073c2013-08-27 01:37:48 -0400634 unsigned long rem_tmo = 0, current_tmo = 0;
Chad Dupuis67b2a312013-02-08 01:57:51 -0500635 struct qla_hw_data *ha = vha->hw;
636
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400637 if (!IS_QLA81XX(ha) && !IS_QLA8031(ha) && !IS_QLA8044(ha))
Chad Dupuis67b2a312013-02-08 01:57:51 -0500638 goto done_set_internal;
639
640 if (mode == INTERNAL_LOOPBACK)
641 new_config[0] = config[0] | (ENABLE_INTERNAL_LOOPBACK << 1);
642 else if (mode == EXTERNAL_LOOPBACK)
643 new_config[0] = config[0] | (ENABLE_EXTERNAL_LOOPBACK << 1);
644 ql_dbg(ql_dbg_user, vha, 0x70be,
645 "new_config[0]=%02x\n", (new_config[0] & INTERNAL_LOOPBACK_MASK));
646
647 memcpy(&new_config[1], &config[1], sizeof(uint16_t) * 3);
648
649 ha->notify_dcbx_comp = 1;
650 ret = qla81xx_set_port_config(vha, new_config);
651 if (ret != QLA_SUCCESS) {
652 ql_log(ql_log_warn, vha, 0x7021,
653 "set port config failed.\n");
654 ha->notify_dcbx_comp = 0;
655 rval = -EINVAL;
656 goto done_set_internal;
657 }
658
659 /* Wait for DCBX complete event */
Santosh Vernekar454073c2013-08-27 01:37:48 -0400660 current_tmo = DCBX_COMP_TIMEOUT * HZ;
661 while (1) {
662 rem_tmo = wait_for_completion_timeout(&ha->dcbx_comp,
663 current_tmo);
664 if (!ha->idc_extend_tmo || rem_tmo) {
665 ha->idc_extend_tmo = 0;
666 break;
667 }
668 current_tmo = ha->idc_extend_tmo * HZ;
669 ha->idc_extend_tmo = 0;
670 }
671
672 if (!rem_tmo) {
Chad Dupuis67b2a312013-02-08 01:57:51 -0500673 ql_dbg(ql_dbg_user, vha, 0x7022,
Chad Dupuisf356bef2013-02-08 01:58:04 -0500674 "DCBX completion not received.\n");
675 ret = qla81xx_reset_loopback_mode(vha, new_config, 0, 0);
Chad Dupuis67b2a312013-02-08 01:57:51 -0500676 /*
677 * If the reset of the loopback mode doesn't work take a FCoE
678 * dump and reset the chip.
679 */
680 if (ret) {
681 ha->isp_ops->fw_dump(vha, 0);
682 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
683 }
684 rval = -EINVAL;
685 } else {
686 if (ha->flags.idc_compl_status) {
687 ql_dbg(ql_dbg_user, vha, 0x70c3,
688 "Bad status in IDC Completion AEN\n");
689 rval = -EINVAL;
690 ha->flags.idc_compl_status = 0;
691 } else
692 ql_dbg(ql_dbg_user, vha, 0x7023,
Chad Dupuisf356bef2013-02-08 01:58:04 -0500693 "DCBX completion received.\n");
Chad Dupuis67b2a312013-02-08 01:57:51 -0500694 }
695
696 ha->notify_dcbx_comp = 0;
Santosh Vernekar454073c2013-08-27 01:37:48 -0400697 ha->idc_extend_tmo = 0;
Chad Dupuis67b2a312013-02-08 01:57:51 -0500698
699done_set_internal:
700 return rval;
701}
702
Giridhar Malavali6e980162010-03-19 17:03:58 -0700703static int
704qla2x00_process_loopback(struct fc_bsg_job *bsg_job)
705{
706 struct Scsi_Host *host = bsg_job->shost;
707 scsi_qla_host_t *vha = shost_priv(host);
708 struct qla_hw_data *ha = vha->hw;
709 int rval;
710 uint8_t command_sent;
711 char *type;
712 struct msg_echo_lb elreq;
713 uint16_t response[MAILBOX_REGISTER_COUNT];
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700714 uint16_t config[4], new_config[4];
Andrew Vasquez6c452a42010-03-19 17:04:02 -0700715 uint8_t *fw_sts_ptr;
Giridhar Malavali6e980162010-03-19 17:03:58 -0700716 uint8_t *req_data = NULL;
717 dma_addr_t req_data_dma;
718 uint32_t req_data_len;
719 uint8_t *rsp_data = NULL;
720 dma_addr_t rsp_data_dma;
721 uint32_t rsp_data_len;
722
Giridhar Malavali6e980162010-03-19 17:03:58 -0700723 if (!vha->flags.online) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700724 ql_log(ql_log_warn, vha, 0x7019, "Host is not online.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -0700725 return -EIO;
726 }
727
Joe Carnuccio64dc4312017-05-24 18:06:22 -0700728 memset(&elreq, 0, sizeof(elreq));
729
Giridhar Malavali6e980162010-03-19 17:03:58 -0700730 elreq.req_sg_cnt = dma_map_sg(&ha->pdev->dev,
731 bsg_job->request_payload.sg_list, bsg_job->request_payload.sg_cnt,
732 DMA_TO_DEVICE);
733
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700734 if (!elreq.req_sg_cnt) {
735 ql_log(ql_log_warn, vha, 0x701a,
736 "dma_map_sg returned %d for request.\n", elreq.req_sg_cnt);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700737 return -ENOMEM;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700738 }
Giridhar Malavali6e980162010-03-19 17:03:58 -0700739
740 elreq.rsp_sg_cnt = dma_map_sg(&ha->pdev->dev,
741 bsg_job->reply_payload.sg_list, bsg_job->reply_payload.sg_cnt,
742 DMA_FROM_DEVICE);
743
744 if (!elreq.rsp_sg_cnt) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700745 ql_log(ql_log_warn, vha, 0x701b,
746 "dma_map_sg returned %d for reply.\n", elreq.rsp_sg_cnt);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700747 rval = -ENOMEM;
748 goto done_unmap_req_sg;
Andrew Vasquez6c452a42010-03-19 17:04:02 -0700749 }
Giridhar Malavali6e980162010-03-19 17:03:58 -0700750
751 if ((elreq.req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
752 (elreq.rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700753 ql_log(ql_log_warn, vha, 0x701c,
754 "dma mapping resulted in different sg counts, "
755 "request_sg_cnt: %x dma_request_sg_cnt: %x "
756 "reply_sg_cnt: %x dma_reply_sg_cnt: %x.\n",
757 bsg_job->request_payload.sg_cnt, elreq.req_sg_cnt,
758 bsg_job->reply_payload.sg_cnt, elreq.rsp_sg_cnt);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700759 rval = -EAGAIN;
760 goto done_unmap_sg;
761 }
762 req_data_len = rsp_data_len = bsg_job->request_payload.payload_len;
763 req_data = dma_alloc_coherent(&ha->pdev->dev, req_data_len,
764 &req_data_dma, GFP_KERNEL);
765 if (!req_data) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700766 ql_log(ql_log_warn, vha, 0x701d,
767 "dma alloc failed for req_data.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -0700768 rval = -ENOMEM;
769 goto done_unmap_sg;
770 }
771
772 rsp_data = dma_alloc_coherent(&ha->pdev->dev, rsp_data_len,
773 &rsp_data_dma, GFP_KERNEL);
774 if (!rsp_data) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700775 ql_log(ql_log_warn, vha, 0x7004,
776 "dma alloc failed for rsp_data.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -0700777 rval = -ENOMEM;
778 goto done_free_dma_req;
779 }
780
781 /* Copy the request buffer in req_data now */
782 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
783 bsg_job->request_payload.sg_cnt, req_data, req_data_len);
784
785 elreq.send_dma = req_data_dma;
786 elreq.rcv_dma = rsp_data_dma;
787 elreq.transfer_size = req_data_len;
788
789 elreq.options = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
Joe Carnuccio1b98b422013-03-28 08:21:26 -0400790 elreq.iteration_count =
791 bsg_job->request->rqst_data.h_vendor.vendor_cmd[2];
Giridhar Malavali6e980162010-03-19 17:03:58 -0700792
Chad Dupuis8fcd6b82012-08-22 14:21:06 -0400793 if (atomic_read(&vha->loop_state) == LOOP_READY &&
794 (ha->current_topology == ISP_CFG_F ||
Joe Carnuccio64dc4312017-05-24 18:06:22 -0700795 (le32_to_cpu(*(uint32_t *)req_data) == ELS_OPCODE_BYTE &&
796 req_data_len == MAX_ELS_FRAME_PAYLOAD)) &&
797 elreq.options == EXTERNAL_LOOPBACK) {
Giridhar Malavali6e980162010-03-19 17:03:58 -0700798 type = "FC_BSG_HST_VENDOR_ECHO_DIAG";
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700799 ql_dbg(ql_dbg_user, vha, 0x701e,
800 "BSG request type: %s.\n", type);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700801 command_sent = INT_DEF_LB_ECHO_CMD;
802 rval = qla2x00_echo_test(vha, &elreq, response);
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700803 } else {
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400804 if (IS_QLA81XX(ha) || IS_QLA8031(ha) || IS_QLA8044(ha)) {
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700805 memset(config, 0, sizeof(config));
806 memset(new_config, 0, sizeof(new_config));
Chad Dupuisf356bef2013-02-08 01:58:04 -0500807
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700808 if (qla81xx_get_port_config(vha, config)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700809 ql_log(ql_log_warn, vha, 0x701f,
810 "Get port config failed.\n");
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700811 rval = -EPERM;
Steve Hodgson9bceab42012-11-21 02:39:56 -0500812 goto done_free_dma_rsp;
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700813 }
814
Chad Dupuis1bcc46c2013-02-08 01:57:46 -0500815 if ((config[0] & INTERNAL_LOOPBACK_MASK) != 0) {
816 ql_dbg(ql_dbg_user, vha, 0x70c4,
817 "Loopback operation already in "
818 "progress.\n");
819 rval = -EAGAIN;
820 goto done_free_dma_rsp;
821 }
822
Chad Dupuis8fcd6b82012-08-22 14:21:06 -0400823 ql_dbg(ql_dbg_user, vha, 0x70c0,
824 "elreq.options=%04x\n", elreq.options);
825
826 if (elreq.options == EXTERNAL_LOOPBACK)
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400827 if (IS_QLA8031(ha) || IS_QLA8044(ha))
Chad Dupuis8fcd6b82012-08-22 14:21:06 -0400828 rval = qla81xx_set_loopback_mode(vha,
829 config, new_config, elreq.options);
830 else
831 rval = qla81xx_reset_loopback_mode(vha,
Chad Dupuisf356bef2013-02-08 01:58:04 -0500832 config, 1, 0);
Chad Dupuis8fcd6b82012-08-22 14:21:06 -0400833 else
834 rval = qla81xx_set_loopback_mode(vha, config,
835 new_config, elreq.options);
836
837 if (rval) {
Chad Dupuis8fcd6b82012-08-22 14:21:06 -0400838 rval = -EPERM;
Steve Hodgson9bceab42012-11-21 02:39:56 -0500839 goto done_free_dma_rsp;
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700840 }
841
842 type = "FC_BSG_HST_VENDOR_LOOPBACK";
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700843 ql_dbg(ql_dbg_user, vha, 0x7028,
844 "BSG request type: %s.\n", type);
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700845
846 command_sent = INT_DEF_LB_LOOPBACK_CMD;
847 rval = qla2x00_loopback_test(vha, &elreq, response);
848
Chad Dupuis992357c2013-02-08 01:57:52 -0500849 if (response[0] == MBS_COMMAND_ERROR &&
850 response[1] == MBS_LB_RESET) {
851 ql_log(ql_log_warn, vha, 0x7029,
852 "MBX command error, Aborting ISP.\n");
853 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
854 qla2xxx_wake_dpc(vha);
855 qla2x00_wait_for_chip_reset(vha);
856 /* Also reset the MPI */
857 if (IS_QLA81XX(ha)) {
858 if (qla81xx_restart_mpi_firmware(vha) !=
859 QLA_SUCCESS) {
860 ql_log(ql_log_warn, vha, 0x702a,
861 "MPI reset failed.\n");
862 }
863 }
864
865 rval = -EIO;
866 goto done_free_dma_rsp;
867 }
868
Joe Carnuccio4052bd52010-12-21 16:00:17 -0800869 if (new_config[0]) {
Chad Dupuis67b2a312013-02-08 01:57:51 -0500870 int ret;
871
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700872 /* Revert back to original port config
873 * Also clear internal loopback
874 */
Chad Dupuis67b2a312013-02-08 01:57:51 -0500875 ret = qla81xx_reset_loopback_mode(vha,
Chad Dupuisf356bef2013-02-08 01:58:04 -0500876 new_config, 0, 1);
Chad Dupuis67b2a312013-02-08 01:57:51 -0500877 if (ret) {
878 /*
879 * If the reset of the loopback mode
880 * doesn't work take FCoE dump and then
881 * reset the chip.
882 */
883 ha->isp_ops->fw_dump(vha, 0);
884 set_bit(ISP_ABORT_NEEDED,
885 &vha->dpc_flags);
886 }
887
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700888 }
889
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700890 } else {
891 type = "FC_BSG_HST_VENDOR_LOOPBACK";
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700892 ql_dbg(ql_dbg_user, vha, 0x702b,
893 "BSG request type: %s.\n", type);
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700894 command_sent = INT_DEF_LB_LOOPBACK_CMD;
895 rval = qla2x00_loopback_test(vha, &elreq, response);
896 }
Giridhar Malavali6e980162010-03-19 17:03:58 -0700897 }
898
899 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700900 ql_log(ql_log_warn, vha, 0x702c,
901 "Vendor request %s failed.\n", type);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700902
Giridhar Malavali6e980162010-03-19 17:03:58 -0700903 rval = 0;
Giridhar Malavali6e980162010-03-19 17:03:58 -0700904 bsg_job->reply->result = (DID_ERROR << 16);
Armen Baloyan63ea9232012-11-21 02:39:53 -0500905 bsg_job->reply->reply_payload_rcv_len = 0;
Giridhar Malavali6e980162010-03-19 17:03:58 -0700906 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700907 ql_dbg(ql_dbg_user, vha, 0x702d,
908 "Vendor request %s completed.\n", type);
Armen Baloyan63ea9232012-11-21 02:39:53 -0500909 bsg_job->reply->result = (DID_OK << 16);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700910 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
911 bsg_job->reply_payload.sg_cnt, rsp_data,
912 rsp_data_len);
913 }
Armen Baloyan63ea9232012-11-21 02:39:53 -0500914
915 bsg_job->reply_len = sizeof(struct fc_bsg_reply) +
916 sizeof(response) + sizeof(uint8_t);
917 fw_sts_ptr = ((uint8_t *)bsg_job->req->sense) +
918 sizeof(struct fc_bsg_reply);
919 memcpy(fw_sts_ptr, response, sizeof(response));
920 fw_sts_ptr += sizeof(response);
921 *fw_sts_ptr = command_sent;
Giridhar Malavali6e980162010-03-19 17:03:58 -0700922
Steve Hodgson9bceab42012-11-21 02:39:56 -0500923done_free_dma_rsp:
Giridhar Malavali6e980162010-03-19 17:03:58 -0700924 dma_free_coherent(&ha->pdev->dev, rsp_data_len,
925 rsp_data, rsp_data_dma);
926done_free_dma_req:
927 dma_free_coherent(&ha->pdev->dev, req_data_len,
928 req_data, req_data_dma);
929done_unmap_sg:
930 dma_unmap_sg(&ha->pdev->dev,
931 bsg_job->reply_payload.sg_list,
932 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
933done_unmap_req_sg:
934 dma_unmap_sg(&ha->pdev->dev,
935 bsg_job->request_payload.sg_list,
936 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
Armen Baloyan63ea9232012-11-21 02:39:53 -0500937 if (!rval)
938 bsg_job->job_done(bsg_job);
Andrew Vasquez6c452a42010-03-19 17:04:02 -0700939 return rval;
Giridhar Malavali6e980162010-03-19 17:03:58 -0700940}
941
942static int
943qla84xx_reset(struct fc_bsg_job *bsg_job)
944{
945 struct Scsi_Host *host = bsg_job->shost;
946 scsi_qla_host_t *vha = shost_priv(host);
947 struct qla_hw_data *ha = vha->hw;
948 int rval = 0;
949 uint32_t flag;
950
Giridhar Malavali6e980162010-03-19 17:03:58 -0700951 if (!IS_QLA84XX(ha)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700952 ql_dbg(ql_dbg_user, vha, 0x702f, "Not 84xx, exiting.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -0700953 return -EINVAL;
954 }
955
956 flag = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
957
958 rval = qla84xx_reset_chip(vha, flag == A84_ISSUE_RESET_DIAG_FW);
959
960 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700961 ql_log(ql_log_warn, vha, 0x7030,
962 "Vendor request 84xx reset failed.\n");
Armen Baloyan63ea9232012-11-21 02:39:53 -0500963 rval = (DID_ERROR << 16);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700964
965 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700966 ql_dbg(ql_dbg_user, vha, 0x7031,
967 "Vendor request 84xx reset completed.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -0700968 bsg_job->reply->result = DID_OK;
Armen Baloyan63ea9232012-11-21 02:39:53 -0500969 bsg_job->job_done(bsg_job);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700970 }
971
Giridhar Malavali6e980162010-03-19 17:03:58 -0700972 return rval;
973}
974
975static int
976qla84xx_updatefw(struct fc_bsg_job *bsg_job)
977{
978 struct Scsi_Host *host = bsg_job->shost;
979 scsi_qla_host_t *vha = shost_priv(host);
980 struct qla_hw_data *ha = vha->hw;
981 struct verify_chip_entry_84xx *mn = NULL;
982 dma_addr_t mn_dma, fw_dma;
983 void *fw_buf = NULL;
984 int rval = 0;
985 uint32_t sg_cnt;
986 uint32_t data_len;
987 uint16_t options;
988 uint32_t flag;
989 uint32_t fw_ver;
990
Giridhar Malavali6e980162010-03-19 17:03:58 -0700991 if (!IS_QLA84XX(ha)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700992 ql_dbg(ql_dbg_user, vha, 0x7032,
993 "Not 84xx, exiting.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -0700994 return -EINVAL;
995 }
996
997 sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
998 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700999 if (!sg_cnt) {
1000 ql_log(ql_log_warn, vha, 0x7033,
1001 "dma_map_sg returned %d for request.\n", sg_cnt);
Giridhar Malavali6e980162010-03-19 17:03:58 -07001002 return -ENOMEM;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001003 }
Giridhar Malavali6e980162010-03-19 17:03:58 -07001004
1005 if (sg_cnt != bsg_job->request_payload.sg_cnt) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001006 ql_log(ql_log_warn, vha, 0x7034,
1007 "DMA mapping resulted in different sg counts, "
1008 "request_sg_cnt: %x dma_request_sg_cnt: %x.\n",
1009 bsg_job->request_payload.sg_cnt, sg_cnt);
Giridhar Malavali6e980162010-03-19 17:03:58 -07001010 rval = -EAGAIN;
1011 goto done_unmap_sg;
1012 }
1013
1014 data_len = bsg_job->request_payload.payload_len;
1015 fw_buf = dma_alloc_coherent(&ha->pdev->dev, data_len,
1016 &fw_dma, GFP_KERNEL);
1017 if (!fw_buf) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001018 ql_log(ql_log_warn, vha, 0x7035,
1019 "DMA alloc failed for fw_buf.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -07001020 rval = -ENOMEM;
1021 goto done_unmap_sg;
1022 }
1023
1024 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1025 bsg_job->request_payload.sg_cnt, fw_buf, data_len);
1026
1027 mn = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma);
1028 if (!mn) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001029 ql_log(ql_log_warn, vha, 0x7036,
1030 "DMA alloc failed for fw buffer.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -07001031 rval = -ENOMEM;
1032 goto done_free_fw_buf;
1033 }
1034
1035 flag = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
1036 fw_ver = le32_to_cpu(*((uint32_t *)((uint32_t *)fw_buf + 2)));
1037
1038 memset(mn, 0, sizeof(struct access_chip_84xx));
1039 mn->entry_type = VERIFY_CHIP_IOCB_TYPE;
1040 mn->entry_count = 1;
1041
1042 options = VCO_FORCE_UPDATE | VCO_END_OF_DATA;
1043 if (flag == A84_ISSUE_UPDATE_DIAGFW_CMD)
1044 options |= VCO_DIAG_FW;
1045
1046 mn->options = cpu_to_le16(options);
1047 mn->fw_ver = cpu_to_le32(fw_ver);
1048 mn->fw_size = cpu_to_le32(data_len);
1049 mn->fw_seq_size = cpu_to_le32(data_len);
1050 mn->dseg_address[0] = cpu_to_le32(LSD(fw_dma));
1051 mn->dseg_address[1] = cpu_to_le32(MSD(fw_dma));
1052 mn->dseg_length = cpu_to_le32(data_len);
1053 mn->data_seg_cnt = cpu_to_le16(1);
1054
1055 rval = qla2x00_issue_iocb_timeout(vha, mn, mn_dma, 0, 120);
1056
1057 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001058 ql_log(ql_log_warn, vha, 0x7037,
1059 "Vendor request 84xx updatefw failed.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -07001060
Armen Baloyan63ea9232012-11-21 02:39:53 -05001061 rval = (DID_ERROR << 16);
Giridhar Malavali6e980162010-03-19 17:03:58 -07001062 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001063 ql_dbg(ql_dbg_user, vha, 0x7038,
1064 "Vendor request 84xx updatefw completed.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -07001065
1066 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1067 bsg_job->reply->result = DID_OK;
1068 }
1069
Giridhar Malavali6e980162010-03-19 17:03:58 -07001070 dma_pool_free(ha->s_dma_pool, mn, mn_dma);
1071
1072done_free_fw_buf:
1073 dma_free_coherent(&ha->pdev->dev, data_len, fw_buf, fw_dma);
1074
1075done_unmap_sg:
1076 dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
1077 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
1078
Armen Baloyan63ea9232012-11-21 02:39:53 -05001079 if (!rval)
1080 bsg_job->job_done(bsg_job);
Giridhar Malavali6e980162010-03-19 17:03:58 -07001081 return rval;
1082}
1083
1084static int
1085qla84xx_mgmt_cmd(struct fc_bsg_job *bsg_job)
1086{
1087 struct Scsi_Host *host = bsg_job->shost;
1088 scsi_qla_host_t *vha = shost_priv(host);
1089 struct qla_hw_data *ha = vha->hw;
1090 struct access_chip_84xx *mn = NULL;
1091 dma_addr_t mn_dma, mgmt_dma;
1092 void *mgmt_b = NULL;
1093 int rval = 0;
1094 struct qla_bsg_a84_mgmt *ql84_mgmt;
1095 uint32_t sg_cnt;
Harish Zunjarraod5459082010-03-19 17:04:00 -07001096 uint32_t data_len = 0;
Giridhar Malavali6e980162010-03-19 17:03:58 -07001097 uint32_t dma_direction = DMA_NONE;
1098
Giridhar Malavali6e980162010-03-19 17:03:58 -07001099 if (!IS_QLA84XX(ha)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001100 ql_log(ql_log_warn, vha, 0x703a,
1101 "Not 84xx, exiting.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -07001102 return -EINVAL;
1103 }
1104
Giridhar Malavali6e980162010-03-19 17:03:58 -07001105 mn = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma);
1106 if (!mn) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001107 ql_log(ql_log_warn, vha, 0x703c,
1108 "DMA alloc failed for fw buffer.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -07001109 return -ENOMEM;
1110 }
1111
1112 memset(mn, 0, sizeof(struct access_chip_84xx));
1113 mn->entry_type = ACCESS_CHIP_IOCB_TYPE;
1114 mn->entry_count = 1;
Bart Van Asschea44c72f2013-06-25 11:27:23 -04001115 ql84_mgmt = (void *)bsg_job->request + sizeof(struct fc_bsg_request);
Giridhar Malavali6e980162010-03-19 17:03:58 -07001116 switch (ql84_mgmt->mgmt.cmd) {
1117 case QLA84_MGMT_READ_MEM:
1118 case QLA84_MGMT_GET_INFO:
1119 sg_cnt = dma_map_sg(&ha->pdev->dev,
1120 bsg_job->reply_payload.sg_list,
1121 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
1122 if (!sg_cnt) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001123 ql_log(ql_log_warn, vha, 0x703d,
1124 "dma_map_sg returned %d for reply.\n", sg_cnt);
Giridhar Malavali6e980162010-03-19 17:03:58 -07001125 rval = -ENOMEM;
1126 goto exit_mgmt;
1127 }
1128
1129 dma_direction = DMA_FROM_DEVICE;
1130
1131 if (sg_cnt != bsg_job->reply_payload.sg_cnt) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001132 ql_log(ql_log_warn, vha, 0x703e,
1133 "DMA mapping resulted in different sg counts, "
1134 "reply_sg_cnt: %x dma_reply_sg_cnt: %x.\n",
1135 bsg_job->reply_payload.sg_cnt, sg_cnt);
Giridhar Malavali6e980162010-03-19 17:03:58 -07001136 rval = -EAGAIN;
1137 goto done_unmap_sg;
1138 }
1139
1140 data_len = bsg_job->reply_payload.payload_len;
1141
1142 mgmt_b = dma_alloc_coherent(&ha->pdev->dev, data_len,
1143 &mgmt_dma, GFP_KERNEL);
1144 if (!mgmt_b) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001145 ql_log(ql_log_warn, vha, 0x703f,
1146 "DMA alloc failed for mgmt_b.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -07001147 rval = -ENOMEM;
1148 goto done_unmap_sg;
1149 }
1150
1151 if (ql84_mgmt->mgmt.cmd == QLA84_MGMT_READ_MEM) {
1152 mn->options = cpu_to_le16(ACO_DUMP_MEMORY);
1153 mn->parameter1 =
1154 cpu_to_le32(
1155 ql84_mgmt->mgmt.mgmtp.u.mem.start_addr);
1156
1157 } else if (ql84_mgmt->mgmt.cmd == QLA84_MGMT_GET_INFO) {
1158 mn->options = cpu_to_le16(ACO_REQUEST_INFO);
1159 mn->parameter1 =
1160 cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.info.type);
1161
1162 mn->parameter2 =
1163 cpu_to_le32(
1164 ql84_mgmt->mgmt.mgmtp.u.info.context);
1165 }
1166 break;
1167
1168 case QLA84_MGMT_WRITE_MEM:
1169 sg_cnt = dma_map_sg(&ha->pdev->dev,
1170 bsg_job->request_payload.sg_list,
1171 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
1172
1173 if (!sg_cnt) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001174 ql_log(ql_log_warn, vha, 0x7040,
1175 "dma_map_sg returned %d.\n", sg_cnt);
Giridhar Malavali6e980162010-03-19 17:03:58 -07001176 rval = -ENOMEM;
1177 goto exit_mgmt;
1178 }
1179
1180 dma_direction = DMA_TO_DEVICE;
1181
1182 if (sg_cnt != bsg_job->request_payload.sg_cnt) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001183 ql_log(ql_log_warn, vha, 0x7041,
1184 "DMA mapping resulted in different sg counts, "
1185 "request_sg_cnt: %x dma_request_sg_cnt: %x.\n",
1186 bsg_job->request_payload.sg_cnt, sg_cnt);
Giridhar Malavali6e980162010-03-19 17:03:58 -07001187 rval = -EAGAIN;
1188 goto done_unmap_sg;
1189 }
1190
1191 data_len = bsg_job->request_payload.payload_len;
1192 mgmt_b = dma_alloc_coherent(&ha->pdev->dev, data_len,
1193 &mgmt_dma, GFP_KERNEL);
1194 if (!mgmt_b) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001195 ql_log(ql_log_warn, vha, 0x7042,
1196 "DMA alloc failed for mgmt_b.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -07001197 rval = -ENOMEM;
1198 goto done_unmap_sg;
1199 }
1200
1201 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1202 bsg_job->request_payload.sg_cnt, mgmt_b, data_len);
1203
1204 mn->options = cpu_to_le16(ACO_LOAD_MEMORY);
1205 mn->parameter1 =
1206 cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.mem.start_addr);
1207 break;
1208
1209 case QLA84_MGMT_CHNG_CONFIG:
1210 mn->options = cpu_to_le16(ACO_CHANGE_CONFIG_PARAM);
1211 mn->parameter1 =
1212 cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.config.id);
1213
1214 mn->parameter2 =
1215 cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.config.param0);
1216
1217 mn->parameter3 =
1218 cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.config.param1);
1219 break;
1220
1221 default:
1222 rval = -EIO;
1223 goto exit_mgmt;
1224 }
1225
1226 if (ql84_mgmt->mgmt.cmd != QLA84_MGMT_CHNG_CONFIG) {
1227 mn->total_byte_cnt = cpu_to_le32(ql84_mgmt->mgmt.len);
1228 mn->dseg_count = cpu_to_le16(1);
1229 mn->dseg_address[0] = cpu_to_le32(LSD(mgmt_dma));
1230 mn->dseg_address[1] = cpu_to_le32(MSD(mgmt_dma));
1231 mn->dseg_length = cpu_to_le32(ql84_mgmt->mgmt.len);
1232 }
1233
1234 rval = qla2x00_issue_iocb(vha, mn, mn_dma, 0);
1235
1236 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001237 ql_log(ql_log_warn, vha, 0x7043,
1238 "Vendor request 84xx mgmt failed.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -07001239
Armen Baloyan63ea9232012-11-21 02:39:53 -05001240 rval = (DID_ERROR << 16);
Giridhar Malavali6e980162010-03-19 17:03:58 -07001241
1242 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001243 ql_dbg(ql_dbg_user, vha, 0x7044,
1244 "Vendor request 84xx mgmt completed.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -07001245
1246 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1247 bsg_job->reply->result = DID_OK;
1248
1249 if ((ql84_mgmt->mgmt.cmd == QLA84_MGMT_READ_MEM) ||
1250 (ql84_mgmt->mgmt.cmd == QLA84_MGMT_GET_INFO)) {
1251 bsg_job->reply->reply_payload_rcv_len =
1252 bsg_job->reply_payload.payload_len;
1253
1254 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
Andrew Vasquez6c452a42010-03-19 17:04:02 -07001255 bsg_job->reply_payload.sg_cnt, mgmt_b,
1256 data_len);
Giridhar Malavali6e980162010-03-19 17:03:58 -07001257 }
1258 }
1259
Giridhar Malavali6e980162010-03-19 17:03:58 -07001260done_unmap_sg:
Harish Zunjarraod5459082010-03-19 17:04:00 -07001261 if (mgmt_b)
1262 dma_free_coherent(&ha->pdev->dev, data_len, mgmt_b, mgmt_dma);
1263
Giridhar Malavali6e980162010-03-19 17:03:58 -07001264 if (dma_direction == DMA_TO_DEVICE)
1265 dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
1266 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
1267 else if (dma_direction == DMA_FROM_DEVICE)
1268 dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
1269 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
1270
1271exit_mgmt:
1272 dma_pool_free(ha->s_dma_pool, mn, mn_dma);
1273
Armen Baloyan63ea9232012-11-21 02:39:53 -05001274 if (!rval)
1275 bsg_job->job_done(bsg_job);
Giridhar Malavali6e980162010-03-19 17:03:58 -07001276 return rval;
1277}
1278
1279static int
1280qla24xx_iidma(struct fc_bsg_job *bsg_job)
1281{
1282 struct Scsi_Host *host = bsg_job->shost;
1283 scsi_qla_host_t *vha = shost_priv(host);
Giridhar Malavali6e980162010-03-19 17:03:58 -07001284 int rval = 0;
1285 struct qla_port_param *port_param = NULL;
1286 fc_port_t *fcport = NULL;
Joe Carnuccioe8b8b8a2013-08-27 01:37:29 -04001287 int found = 0;
Giridhar Malavali6e980162010-03-19 17:03:58 -07001288 uint16_t mb[MAILBOX_REGISTER_COUNT];
1289 uint8_t *rsp_ptr = NULL;
1290
Giridhar Malavali6e980162010-03-19 17:03:58 -07001291 if (!IS_IIDMA_CAPABLE(vha->hw)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001292 ql_log(ql_log_info, vha, 0x7046, "iiDMA not supported.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -07001293 return -EINVAL;
1294 }
1295
Bart Van Assche090fc2e2013-06-25 11:27:22 -04001296 port_param = (void *)bsg_job->request + sizeof(struct fc_bsg_request);
Giridhar Malavali6e980162010-03-19 17:03:58 -07001297 if (port_param->fc_scsi_addr.dest_type != EXT_DEF_TYPE_WWPN) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001298 ql_log(ql_log_warn, vha, 0x7048,
1299 "Invalid destination type.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -07001300 return -EINVAL;
1301 }
1302
1303 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1304 if (fcport->port_type != FCT_TARGET)
1305 continue;
1306
1307 if (memcmp(port_param->fc_scsi_addr.dest_addr.wwpn,
1308 fcport->port_name, sizeof(fcport->port_name)))
1309 continue;
Joe Carnuccioe8b8b8a2013-08-27 01:37:29 -04001310
1311 found = 1;
Giridhar Malavali6e980162010-03-19 17:03:58 -07001312 break;
1313 }
1314
Joe Carnuccioe8b8b8a2013-08-27 01:37:29 -04001315 if (!found) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001316 ql_log(ql_log_warn, vha, 0x7049,
1317 "Failed to find port.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -07001318 return -EINVAL;
1319 }
1320
Giridhar Malavalic9afb9a2010-09-03 15:20:48 -07001321 if (atomic_read(&fcport->state) != FCS_ONLINE) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001322 ql_log(ql_log_warn, vha, 0x704a,
1323 "Port is not online.\n");
Madhuranath Iyengar17cf2c52010-07-23 15:28:22 +05001324 return -EINVAL;
1325 }
1326
Madhuranath Iyengar9a15eb42010-07-23 15:28:31 +05001327 if (fcport->flags & FCF_LOGIN_NEEDED) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001328 ql_log(ql_log_warn, vha, 0x704b,
1329 "Remote port not logged in flags = 0x%x.\n", fcport->flags);
Madhuranath Iyengar9a15eb42010-07-23 15:28:31 +05001330 return -EINVAL;
1331 }
1332
Giridhar Malavali6e980162010-03-19 17:03:58 -07001333 if (port_param->mode)
1334 rval = qla2x00_set_idma_speed(vha, fcport->loop_id,
1335 port_param->speed, mb);
1336 else
1337 rval = qla2x00_get_idma_speed(vha, fcport->loop_id,
1338 &port_param->speed, mb);
1339
1340 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001341 ql_log(ql_log_warn, vha, 0x704c,
Oleksandr Khoshaba7b833552013-08-27 01:37:27 -04001342 "iIDMA cmd failed for %8phN -- "
1343 "%04x %x %04x %04x.\n", fcport->port_name,
1344 rval, fcport->fp_speed, mb[0], mb[1]);
Armen Baloyan63ea9232012-11-21 02:39:53 -05001345 rval = (DID_ERROR << 16);
Giridhar Malavali6e980162010-03-19 17:03:58 -07001346 } else {
1347 if (!port_param->mode) {
1348 bsg_job->reply_len = sizeof(struct fc_bsg_reply) +
1349 sizeof(struct qla_port_param);
1350
1351 rsp_ptr = ((uint8_t *)bsg_job->reply) +
1352 sizeof(struct fc_bsg_reply);
1353
1354 memcpy(rsp_ptr, port_param,
1355 sizeof(struct qla_port_param));
1356 }
1357
1358 bsg_job->reply->result = DID_OK;
Armen Baloyan63ea9232012-11-21 02:39:53 -05001359 bsg_job->job_done(bsg_job);
Giridhar Malavali6e980162010-03-19 17:03:58 -07001360 }
1361
Giridhar Malavali6e980162010-03-19 17:03:58 -07001362 return rval;
1363}
1364
1365static int
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001366qla2x00_optrom_setup(struct fc_bsg_job *bsg_job, scsi_qla_host_t *vha,
Harish Zunjarraof19af162010-10-15 11:27:43 -07001367 uint8_t is_update)
1368{
1369 uint32_t start = 0;
1370 int valid = 0;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001371 struct qla_hw_data *ha = vha->hw;
Harish Zunjarraof19af162010-10-15 11:27:43 -07001372
Harish Zunjarraof19af162010-10-15 11:27:43 -07001373 if (unlikely(pci_channel_offline(ha->pdev)))
1374 return -EINVAL;
1375
1376 start = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001377 if (start > ha->optrom_size) {
1378 ql_log(ql_log_warn, vha, 0x7055,
1379 "start %d > optrom_size %d.\n", start, ha->optrom_size);
Harish Zunjarraof19af162010-10-15 11:27:43 -07001380 return -EINVAL;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001381 }
Harish Zunjarraof19af162010-10-15 11:27:43 -07001382
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001383 if (ha->optrom_state != QLA_SWAITING) {
1384 ql_log(ql_log_info, vha, 0x7056,
1385 "optrom_state %d.\n", ha->optrom_state);
Harish Zunjarraof19af162010-10-15 11:27:43 -07001386 return -EBUSY;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001387 }
Harish Zunjarraof19af162010-10-15 11:27:43 -07001388
1389 ha->optrom_region_start = start;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001390 ql_dbg(ql_dbg_user, vha, 0x7057, "is_update=%d.\n", is_update);
Harish Zunjarraof19af162010-10-15 11:27:43 -07001391 if (is_update) {
1392 if (ha->optrom_size == OPTROM_SIZE_2300 && start == 0)
1393 valid = 1;
1394 else if (start == (ha->flt_region_boot * 4) ||
1395 start == (ha->flt_region_fw * 4))
1396 valid = 1;
1397 else if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha) ||
Alex Vechersky9a6e6402014-09-25 05:16:58 -04001398 IS_CNA_CAPABLE(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha))
Harish Zunjarraof19af162010-10-15 11:27:43 -07001399 valid = 1;
1400 if (!valid) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001401 ql_log(ql_log_warn, vha, 0x7058,
1402 "Invalid start region 0x%x/0x%x.\n", start,
1403 bsg_job->request_payload.payload_len);
Harish Zunjarraof19af162010-10-15 11:27:43 -07001404 return -EINVAL;
1405 }
1406
1407 ha->optrom_region_size = start +
1408 bsg_job->request_payload.payload_len > ha->optrom_size ?
1409 ha->optrom_size - start :
1410 bsg_job->request_payload.payload_len;
1411 ha->optrom_state = QLA_SWRITING;
1412 } else {
1413 ha->optrom_region_size = start +
1414 bsg_job->reply_payload.payload_len > ha->optrom_size ?
1415 ha->optrom_size - start :
1416 bsg_job->reply_payload.payload_len;
1417 ha->optrom_state = QLA_SREADING;
1418 }
1419
1420 ha->optrom_buffer = vmalloc(ha->optrom_region_size);
1421 if (!ha->optrom_buffer) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001422 ql_log(ql_log_warn, vha, 0x7059,
Harish Zunjarraof19af162010-10-15 11:27:43 -07001423 "Read: Unable to allocate memory for optrom retrieval "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001424 "(%x)\n", ha->optrom_region_size);
Harish Zunjarraof19af162010-10-15 11:27:43 -07001425
1426 ha->optrom_state = QLA_SWAITING;
1427 return -ENOMEM;
1428 }
1429
1430 memset(ha->optrom_buffer, 0, ha->optrom_region_size);
1431 return 0;
1432}
1433
1434static int
1435qla2x00_read_optrom(struct fc_bsg_job *bsg_job)
1436{
1437 struct Scsi_Host *host = bsg_job->shost;
1438 scsi_qla_host_t *vha = shost_priv(host);
1439 struct qla_hw_data *ha = vha->hw;
1440 int rval = 0;
1441
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04001442 if (ha->flags.nic_core_reset_hdlr_active)
Giridhar Malavalia49393f2012-04-25 07:26:14 -07001443 return -EBUSY;
1444
Chad Dupuis7a8ab9c2014-02-26 04:14:56 -05001445 mutex_lock(&ha->optrom_mutex);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001446 rval = qla2x00_optrom_setup(bsg_job, vha, 0);
Chad Dupuis7a8ab9c2014-02-26 04:14:56 -05001447 if (rval) {
1448 mutex_unlock(&ha->optrom_mutex);
Harish Zunjarraof19af162010-10-15 11:27:43 -07001449 return rval;
Chad Dupuis7a8ab9c2014-02-26 04:14:56 -05001450 }
Harish Zunjarraof19af162010-10-15 11:27:43 -07001451
1452 ha->isp_ops->read_optrom(vha, ha->optrom_buffer,
1453 ha->optrom_region_start, ha->optrom_region_size);
1454
1455 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
1456 bsg_job->reply_payload.sg_cnt, ha->optrom_buffer,
1457 ha->optrom_region_size);
1458
1459 bsg_job->reply->reply_payload_rcv_len = ha->optrom_region_size;
1460 bsg_job->reply->result = DID_OK;
1461 vfree(ha->optrom_buffer);
1462 ha->optrom_buffer = NULL;
1463 ha->optrom_state = QLA_SWAITING;
Chad Dupuis7a8ab9c2014-02-26 04:14:56 -05001464 mutex_unlock(&ha->optrom_mutex);
Harish Zunjarraof19af162010-10-15 11:27:43 -07001465 bsg_job->job_done(bsg_job);
1466 return rval;
1467}
1468
1469static int
1470qla2x00_update_optrom(struct fc_bsg_job *bsg_job)
1471{
1472 struct Scsi_Host *host = bsg_job->shost;
1473 scsi_qla_host_t *vha = shost_priv(host);
1474 struct qla_hw_data *ha = vha->hw;
1475 int rval = 0;
1476
Chad Dupuis7a8ab9c2014-02-26 04:14:56 -05001477 mutex_lock(&ha->optrom_mutex);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001478 rval = qla2x00_optrom_setup(bsg_job, vha, 1);
Chad Dupuis7a8ab9c2014-02-26 04:14:56 -05001479 if (rval) {
1480 mutex_unlock(&ha->optrom_mutex);
Harish Zunjarraof19af162010-10-15 11:27:43 -07001481 return rval;
Chad Dupuis7a8ab9c2014-02-26 04:14:56 -05001482 }
Harish Zunjarraof19af162010-10-15 11:27:43 -07001483
Giridhar Malavalib6d0d9d2012-05-15 14:34:25 -04001484 /* Set the isp82xx_no_md_cap not to capture minidump */
1485 ha->flags.isp82xx_no_md_cap = 1;
1486
Harish Zunjarraof19af162010-10-15 11:27:43 -07001487 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1488 bsg_job->request_payload.sg_cnt, ha->optrom_buffer,
1489 ha->optrom_region_size);
1490
1491 ha->isp_ops->write_optrom(vha, ha->optrom_buffer,
1492 ha->optrom_region_start, ha->optrom_region_size);
1493
1494 bsg_job->reply->result = DID_OK;
1495 vfree(ha->optrom_buffer);
1496 ha->optrom_buffer = NULL;
1497 ha->optrom_state = QLA_SWAITING;
Chad Dupuis7a8ab9c2014-02-26 04:14:56 -05001498 mutex_unlock(&ha->optrom_mutex);
Harish Zunjarraof19af162010-10-15 11:27:43 -07001499 bsg_job->job_done(bsg_job);
1500 return rval;
1501}
1502
1503static int
Joe Carnuccio697a4bc2011-08-16 11:31:52 -07001504qla2x00_update_fru_versions(struct fc_bsg_job *bsg_job)
1505{
1506 struct Scsi_Host *host = bsg_job->shost;
1507 scsi_qla_host_t *vha = shost_priv(host);
1508 struct qla_hw_data *ha = vha->hw;
1509 int rval = 0;
1510 uint8_t bsg[DMA_POOL_SIZE];
1511 struct qla_image_version_list *list = (void *)bsg;
1512 struct qla_image_version *image;
1513 uint32_t count;
1514 dma_addr_t sfp_dma;
1515 void *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
1516 if (!sfp) {
1517 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
1518 EXT_STATUS_NO_MEMORY;
1519 goto done;
1520 }
1521
1522 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1523 bsg_job->request_payload.sg_cnt, list, sizeof(bsg));
1524
1525 image = list->version;
1526 count = list->count;
1527 while (count--) {
1528 memcpy(sfp, &image->field_info, sizeof(image->field_info));
1529 rval = qla2x00_write_sfp(vha, sfp_dma, sfp,
1530 image->field_address.device, image->field_address.offset,
1531 sizeof(image->field_info), image->field_address.option);
1532 if (rval) {
1533 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
1534 EXT_STATUS_MAILBOX;
1535 goto dealloc;
1536 }
1537 image++;
1538 }
1539
1540 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
1541
1542dealloc:
1543 dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
1544
1545done:
1546 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1547 bsg_job->reply->result = DID_OK << 16;
1548 bsg_job->job_done(bsg_job);
1549
1550 return 0;
1551}
1552
1553static int
1554qla2x00_read_fru_status(struct fc_bsg_job *bsg_job)
1555{
1556 struct Scsi_Host *host = bsg_job->shost;
1557 scsi_qla_host_t *vha = shost_priv(host);
1558 struct qla_hw_data *ha = vha->hw;
1559 int rval = 0;
1560 uint8_t bsg[DMA_POOL_SIZE];
1561 struct qla_status_reg *sr = (void *)bsg;
1562 dma_addr_t sfp_dma;
1563 uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
1564 if (!sfp) {
1565 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
1566 EXT_STATUS_NO_MEMORY;
1567 goto done;
1568 }
1569
1570 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1571 bsg_job->request_payload.sg_cnt, sr, sizeof(*sr));
1572
1573 rval = qla2x00_read_sfp(vha, sfp_dma, sfp,
1574 sr->field_address.device, sr->field_address.offset,
1575 sizeof(sr->status_reg), sr->field_address.option);
1576 sr->status_reg = *sfp;
1577
1578 if (rval) {
1579 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
1580 EXT_STATUS_MAILBOX;
1581 goto dealloc;
1582 }
1583
1584 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
1585 bsg_job->reply_payload.sg_cnt, sr, sizeof(*sr));
1586
1587 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
1588
1589dealloc:
1590 dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
1591
1592done:
1593 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1594 bsg_job->reply->reply_payload_rcv_len = sizeof(*sr);
1595 bsg_job->reply->result = DID_OK << 16;
1596 bsg_job->job_done(bsg_job);
1597
1598 return 0;
1599}
1600
1601static int
1602qla2x00_write_fru_status(struct fc_bsg_job *bsg_job)
1603{
1604 struct Scsi_Host *host = bsg_job->shost;
1605 scsi_qla_host_t *vha = shost_priv(host);
1606 struct qla_hw_data *ha = vha->hw;
1607 int rval = 0;
1608 uint8_t bsg[DMA_POOL_SIZE];
1609 struct qla_status_reg *sr = (void *)bsg;
1610 dma_addr_t sfp_dma;
1611 uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
1612 if (!sfp) {
1613 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
1614 EXT_STATUS_NO_MEMORY;
1615 goto done;
1616 }
1617
1618 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1619 bsg_job->request_payload.sg_cnt, sr, sizeof(*sr));
1620
1621 *sfp = sr->status_reg;
1622 rval = qla2x00_write_sfp(vha, sfp_dma, sfp,
1623 sr->field_address.device, sr->field_address.offset,
1624 sizeof(sr->status_reg), sr->field_address.option);
1625
1626 if (rval) {
1627 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
1628 EXT_STATUS_MAILBOX;
1629 goto dealloc;
1630 }
1631
1632 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
1633
1634dealloc:
1635 dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
1636
1637done:
1638 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1639 bsg_job->reply->result = DID_OK << 16;
1640 bsg_job->job_done(bsg_job);
1641
1642 return 0;
1643}
1644
1645static int
Joe Carnuccio9ebb5d92012-08-22 14:20:56 -04001646qla2x00_write_i2c(struct fc_bsg_job *bsg_job)
1647{
1648 struct Scsi_Host *host = bsg_job->shost;
1649 scsi_qla_host_t *vha = shost_priv(host);
1650 struct qla_hw_data *ha = vha->hw;
1651 int rval = 0;
1652 uint8_t bsg[DMA_POOL_SIZE];
1653 struct qla_i2c_access *i2c = (void *)bsg;
1654 dma_addr_t sfp_dma;
1655 uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
1656 if (!sfp) {
1657 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
1658 EXT_STATUS_NO_MEMORY;
1659 goto done;
1660 }
1661
1662 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1663 bsg_job->request_payload.sg_cnt, i2c, sizeof(*i2c));
1664
1665 memcpy(sfp, i2c->buffer, i2c->length);
1666 rval = qla2x00_write_sfp(vha, sfp_dma, sfp,
1667 i2c->device, i2c->offset, i2c->length, i2c->option);
1668
1669 if (rval) {
1670 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
1671 EXT_STATUS_MAILBOX;
1672 goto dealloc;
1673 }
1674
1675 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
1676
1677dealloc:
1678 dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
1679
1680done:
1681 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1682 bsg_job->reply->result = DID_OK << 16;
1683 bsg_job->job_done(bsg_job);
1684
1685 return 0;
1686}
1687
1688static int
1689qla2x00_read_i2c(struct fc_bsg_job *bsg_job)
1690{
1691 struct Scsi_Host *host = bsg_job->shost;
1692 scsi_qla_host_t *vha = shost_priv(host);
1693 struct qla_hw_data *ha = vha->hw;
1694 int rval = 0;
1695 uint8_t bsg[DMA_POOL_SIZE];
1696 struct qla_i2c_access *i2c = (void *)bsg;
1697 dma_addr_t sfp_dma;
1698 uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
1699 if (!sfp) {
1700 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
1701 EXT_STATUS_NO_MEMORY;
1702 goto done;
1703 }
1704
1705 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1706 bsg_job->request_payload.sg_cnt, i2c, sizeof(*i2c));
1707
1708 rval = qla2x00_read_sfp(vha, sfp_dma, sfp,
1709 i2c->device, i2c->offset, i2c->length, i2c->option);
1710
1711 if (rval) {
1712 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
1713 EXT_STATUS_MAILBOX;
1714 goto dealloc;
1715 }
1716
1717 memcpy(i2c->buffer, sfp, i2c->length);
1718 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
1719 bsg_job->reply_payload.sg_cnt, i2c, sizeof(*i2c));
1720
1721 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
1722
1723dealloc:
1724 dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
1725
1726done:
1727 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1728 bsg_job->reply->reply_payload_rcv_len = sizeof(*i2c);
1729 bsg_job->reply->result = DID_OK << 16;
1730 bsg_job->job_done(bsg_job);
1731
1732 return 0;
1733}
1734
1735static int
Saurav Kashyapa9b6f7222012-08-22 14:21:01 -04001736qla24xx_process_bidir_cmd(struct fc_bsg_job *bsg_job)
1737{
1738 struct Scsi_Host *host = bsg_job->shost;
1739 scsi_qla_host_t *vha = shost_priv(host);
1740 struct qla_hw_data *ha = vha->hw;
Saurav Kashyapa9b6f7222012-08-22 14:21:01 -04001741 uint32_t rval = EXT_STATUS_OK;
1742 uint16_t req_sg_cnt = 0;
1743 uint16_t rsp_sg_cnt = 0;
1744 uint16_t nextlid = 0;
1745 uint32_t tot_dsds;
1746 srb_t *sp = NULL;
Bart Van Asschec11c7a52019-08-08 20:01:48 -07001747 uint32_t req_data_len;
1748 uint32_t rsp_data_len;
Saurav Kashyapa9b6f7222012-08-22 14:21:01 -04001749
1750 /* Check the type of the adapter */
1751 if (!IS_BIDI_CAPABLE(ha)) {
1752 ql_log(ql_log_warn, vha, 0x70a0,
1753 "This adapter is not supported\n");
1754 rval = EXT_STATUS_NOT_SUPPORTED;
1755 goto done;
1756 }
1757
1758 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
1759 test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
1760 test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
1761 rval = EXT_STATUS_BUSY;
1762 goto done;
1763 }
1764
1765 /* Check if host is online */
1766 if (!vha->flags.online) {
1767 ql_log(ql_log_warn, vha, 0x70a1,
1768 "Host is not online\n");
1769 rval = EXT_STATUS_DEVICE_OFFLINE;
1770 goto done;
1771 }
1772
1773 /* Check if cable is plugged in or not */
1774 if (vha->device_flags & DFLG_NO_CABLE) {
1775 ql_log(ql_log_warn, vha, 0x70a2,
1776 "Cable is unplugged...\n");
1777 rval = EXT_STATUS_INVALID_CFG;
1778 goto done;
1779 }
1780
1781 /* Check if the switch is connected or not */
1782 if (ha->current_topology != ISP_CFG_F) {
1783 ql_log(ql_log_warn, vha, 0x70a3,
1784 "Host is not connected to the switch\n");
1785 rval = EXT_STATUS_INVALID_CFG;
1786 goto done;
1787 }
1788
1789 /* Check if operating mode is P2P */
1790 if (ha->operating_mode != P2P) {
1791 ql_log(ql_log_warn, vha, 0x70a4,
1792 "Host is operating mode is not P2p\n");
1793 rval = EXT_STATUS_INVALID_CFG;
1794 goto done;
1795 }
1796
Saurav Kashyapa9b6f7222012-08-22 14:21:01 -04001797 mutex_lock(&ha->selflogin_lock);
1798 if (vha->self_login_loop_id == 0) {
1799 /* Initialize all required fields of fcport */
1800 vha->bidir_fcport.vha = vha;
1801 vha->bidir_fcport.d_id.b.al_pa = vha->d_id.b.al_pa;
1802 vha->bidir_fcport.d_id.b.area = vha->d_id.b.area;
1803 vha->bidir_fcport.d_id.b.domain = vha->d_id.b.domain;
1804 vha->bidir_fcport.loop_id = vha->loop_id;
1805
1806 if (qla2x00_fabric_login(vha, &(vha->bidir_fcport), &nextlid)) {
1807 ql_log(ql_log_warn, vha, 0x70a7,
1808 "Failed to login port %06X for bidirectional IOCB\n",
1809 vha->bidir_fcport.d_id.b24);
1810 mutex_unlock(&ha->selflogin_lock);
1811 rval = EXT_STATUS_MAILBOX;
1812 goto done;
1813 }
1814 vha->self_login_loop_id = nextlid - 1;
1815
1816 }
1817 /* Assign the self login loop id to fcport */
1818 mutex_unlock(&ha->selflogin_lock);
1819
1820 vha->bidir_fcport.loop_id = vha->self_login_loop_id;
1821
1822 req_sg_cnt = dma_map_sg(&ha->pdev->dev,
1823 bsg_job->request_payload.sg_list,
1824 bsg_job->request_payload.sg_cnt,
1825 DMA_TO_DEVICE);
1826
1827 if (!req_sg_cnt) {
1828 rval = EXT_STATUS_NO_MEMORY;
1829 goto done;
1830 }
1831
1832 rsp_sg_cnt = dma_map_sg(&ha->pdev->dev,
1833 bsg_job->reply_payload.sg_list, bsg_job->reply_payload.sg_cnt,
1834 DMA_FROM_DEVICE);
1835
1836 if (!rsp_sg_cnt) {
1837 rval = EXT_STATUS_NO_MEMORY;
1838 goto done_unmap_req_sg;
1839 }
1840
1841 if ((req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
1842 (rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) {
1843 ql_dbg(ql_dbg_user, vha, 0x70a9,
1844 "Dma mapping resulted in different sg counts "
1845 "[request_sg_cnt: %x dma_request_sg_cnt: %x reply_sg_cnt: "
1846 "%x dma_reply_sg_cnt: %x]\n",
1847 bsg_job->request_payload.sg_cnt, req_sg_cnt,
1848 bsg_job->reply_payload.sg_cnt, rsp_sg_cnt);
1849 rval = EXT_STATUS_NO_MEMORY;
1850 goto done_unmap_sg;
1851 }
1852
Bart Van Asschec11c7a52019-08-08 20:01:48 -07001853 req_data_len = bsg_job->request_payload.payload_len;
1854 rsp_data_len = bsg_job->reply_payload.payload_len;
1855
Saurav Kashyapa9b6f7222012-08-22 14:21:01 -04001856 if (req_data_len != rsp_data_len) {
1857 rval = EXT_STATUS_BUSY;
1858 ql_log(ql_log_warn, vha, 0x70aa,
1859 "req_data_len != rsp_data_len\n");
1860 goto done_unmap_sg;
1861 }
1862
Saurav Kashyapa9b6f7222012-08-22 14:21:01 -04001863 /* Alloc SRB structure */
1864 sp = qla2x00_get_sp(vha, &(vha->bidir_fcport), GFP_KERNEL);
1865 if (!sp) {
1866 ql_dbg(ql_dbg_user, vha, 0x70ac,
1867 "Alloc SRB structure failed\n");
1868 rval = EXT_STATUS_NO_MEMORY;
1869 goto done_unmap_sg;
1870 }
1871
1872 /*Populate srb->ctx with bidir ctx*/
1873 sp->u.bsg_job = bsg_job;
1874 sp->free = qla2x00_bsg_sp_free;
1875 sp->type = SRB_BIDI_CMD;
1876 sp->done = qla2x00_bsg_job_done;
1877
1878 /* Add the read and write sg count */
1879 tot_dsds = rsp_sg_cnt + req_sg_cnt;
1880
1881 rval = qla2x00_start_bidir(sp, vha, tot_dsds);
1882 if (rval != EXT_STATUS_OK)
1883 goto done_free_srb;
1884 /* the bsg request will be completed in the interrupt handler */
1885 return rval;
1886
1887done_free_srb:
1888 mempool_free(sp, ha->srb_mempool);
1889done_unmap_sg:
1890 dma_unmap_sg(&ha->pdev->dev,
1891 bsg_job->reply_payload.sg_list,
1892 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
1893done_unmap_req_sg:
1894 dma_unmap_sg(&ha->pdev->dev,
1895 bsg_job->request_payload.sg_list,
1896 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
1897done:
1898
1899 /* Return an error vendor specific response
1900 * and complete the bsg request
1901 */
1902 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = rval;
1903 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1904 bsg_job->reply->reply_payload_rcv_len = 0;
1905 bsg_job->reply->result = (DID_OK) << 16;
1906 bsg_job->job_done(bsg_job);
Joe Perches9e03aa22013-09-03 13:45:58 -07001907 /* Always return success, vendor rsp carries correct status */
Saurav Kashyapa9b6f7222012-08-22 14:21:01 -04001908 return 0;
1909}
1910
1911static int
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001912qlafx00_mgmt_cmd(struct fc_bsg_job *bsg_job)
1913{
1914 struct Scsi_Host *host = bsg_job->shost;
1915 scsi_qla_host_t *vha = shost_priv(host);
1916 struct qla_hw_data *ha = vha->hw;
Hannes Reinecke59e736b2019-10-18 16:04:58 +02001917 int rval = (DID_ERROR << 16);
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001918 struct qla_mt_iocb_rqst_fx00 *piocb_rqst;
1919 srb_t *sp;
1920 int req_sg_cnt = 0, rsp_sg_cnt = 0;
1921 struct fc_port *fcport;
1922 char *type = "FC_BSG_HST_FX_MGMT";
1923
1924 /* Copy the IOCB specific information */
1925 piocb_rqst = (struct qla_mt_iocb_rqst_fx00 *)
1926 &bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
1927
1928 /* Dump the vendor information */
1929 ql_dump_buffer(ql_dbg_user + ql_dbg_verbose , vha, 0x70cf,
1930 (uint8_t *)piocb_rqst, sizeof(struct qla_mt_iocb_rqst_fx00));
1931
1932 if (!vha->flags.online) {
1933 ql_log(ql_log_warn, vha, 0x70d0,
1934 "Host is not online.\n");
1935 rval = -EIO;
1936 goto done;
1937 }
1938
1939 if (piocb_rqst->flags & SRB_FXDISC_REQ_DMA_VALID) {
1940 req_sg_cnt = dma_map_sg(&ha->pdev->dev,
1941 bsg_job->request_payload.sg_list,
1942 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
1943 if (!req_sg_cnt) {
1944 ql_log(ql_log_warn, vha, 0x70c7,
1945 "dma_map_sg return %d for request\n", req_sg_cnt);
1946 rval = -ENOMEM;
1947 goto done;
1948 }
1949 }
1950
1951 if (piocb_rqst->flags & SRB_FXDISC_RESP_DMA_VALID) {
1952 rsp_sg_cnt = dma_map_sg(&ha->pdev->dev,
1953 bsg_job->reply_payload.sg_list,
1954 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
1955 if (!rsp_sg_cnt) {
1956 ql_log(ql_log_warn, vha, 0x70c8,
1957 "dma_map_sg return %d for reply\n", rsp_sg_cnt);
1958 rval = -ENOMEM;
1959 goto done_unmap_req_sg;
1960 }
1961 }
1962
1963 ql_dbg(ql_dbg_user, vha, 0x70c9,
1964 "request_sg_cnt: %x dma_request_sg_cnt: %x reply_sg_cnt:%x "
1965 "dma_reply_sg_cnt: %x\n", bsg_job->request_payload.sg_cnt,
1966 req_sg_cnt, bsg_job->reply_payload.sg_cnt, rsp_sg_cnt);
1967
1968 /* Allocate a dummy fcport structure, since functions preparing the
1969 * IOCB and mailbox command retrieves port specific information
1970 * from fcport structure. For Host based ELS commands there will be
1971 * no fcport structure allocated
1972 */
1973 fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
1974 if (!fcport) {
1975 ql_log(ql_log_warn, vha, 0x70ca,
1976 "Failed to allocate fcport.\n");
1977 rval = -ENOMEM;
1978 goto done_unmap_rsp_sg;
1979 }
1980
1981 /* Alloc SRB structure */
1982 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1983 if (!sp) {
1984 ql_log(ql_log_warn, vha, 0x70cb,
1985 "qla2x00_get_sp failed.\n");
1986 rval = -ENOMEM;
1987 goto done_free_fcport;
1988 }
1989
1990 /* Initialize all required fields of fcport */
1991 fcport->vha = vha;
1992 fcport->loop_id = piocb_rqst->dataword;
1993
1994 sp->type = SRB_FXIOCB_BCMD;
1995 sp->name = "bsg_fx_mgmt";
1996 sp->iocbs = qla24xx_calc_ct_iocbs(req_sg_cnt + rsp_sg_cnt);
1997 sp->u.bsg_job = bsg_job;
1998 sp->free = qla2x00_bsg_sp_free;
1999 sp->done = qla2x00_bsg_job_done;
2000
2001 ql_dbg(ql_dbg_user, vha, 0x70cc,
2002 "bsg rqst type: %s fx_mgmt_type: %x id=%x\n",
2003 type, piocb_rqst->func_type, fcport->loop_id);
2004
2005 rval = qla2x00_start_sp(sp);
2006 if (rval != QLA_SUCCESS) {
2007 ql_log(ql_log_warn, vha, 0x70cd,
2008 "qla2x00_start_sp failed=%d.\n", rval);
2009 mempool_free(sp, ha->srb_mempool);
2010 rval = -EIO;
2011 goto done_free_fcport;
2012 }
2013 return rval;
2014
2015done_free_fcport:
2016 kfree(fcport);
2017
2018done_unmap_rsp_sg:
2019 if (piocb_rqst->flags & SRB_FXDISC_RESP_DMA_VALID)
2020 dma_unmap_sg(&ha->pdev->dev,
2021 bsg_job->reply_payload.sg_list,
2022 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
2023done_unmap_req_sg:
2024 if (piocb_rqst->flags & SRB_FXDISC_REQ_DMA_VALID)
2025 dma_unmap_sg(&ha->pdev->dev,
2026 bsg_job->request_payload.sg_list,
2027 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
2028
2029done:
2030 return rval;
2031}
2032
2033static int
Joe Carnucciodb64e932013-10-30 03:38:18 -04002034qla26xx_serdes_op(struct fc_bsg_job *bsg_job)
2035{
2036 struct Scsi_Host *host = bsg_job->shost;
2037 scsi_qla_host_t *vha = shost_priv(host);
2038 int rval = 0;
2039 struct qla_serdes_reg sr;
2040
2041 memset(&sr, 0, sizeof(sr));
2042
2043 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
2044 bsg_job->request_payload.sg_cnt, &sr, sizeof(sr));
2045
2046 switch (sr.cmd) {
2047 case INT_SC_SERDES_WRITE_REG:
2048 rval = qla2x00_write_serdes_word(vha, sr.addr, sr.val);
2049 bsg_job->reply->reply_payload_rcv_len = 0;
2050 break;
2051 case INT_SC_SERDES_READ_REG:
2052 rval = qla2x00_read_serdes_word(vha, sr.addr, &sr.val);
2053 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
2054 bsg_job->reply_payload.sg_cnt, &sr, sizeof(sr));
2055 bsg_job->reply->reply_payload_rcv_len = sizeof(sr);
2056 break;
2057 default:
Joe Carnuccioe8887c52014-04-11 16:54:17 -04002058 ql_dbg(ql_dbg_user, vha, 0x708c,
Joe Carnucciodb64e932013-10-30 03:38:18 -04002059 "Unknown serdes cmd %x.\n", sr.cmd);
Joe Carnuccioe8887c52014-04-11 16:54:17 -04002060 rval = -EINVAL;
2061 break;
2062 }
2063
2064 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
2065 rval ? EXT_STATUS_MAILBOX : 0;
2066
2067 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
2068 bsg_job->reply->result = DID_OK << 16;
2069 bsg_job->job_done(bsg_job);
2070 return 0;
2071}
2072
2073static int
2074qla8044_serdes_op(struct fc_bsg_job *bsg_job)
2075{
2076 struct Scsi_Host *host = bsg_job->shost;
2077 scsi_qla_host_t *vha = shost_priv(host);
2078 int rval = 0;
2079 struct qla_serdes_reg_ex sr;
2080
2081 memset(&sr, 0, sizeof(sr));
2082
2083 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
2084 bsg_job->request_payload.sg_cnt, &sr, sizeof(sr));
2085
2086 switch (sr.cmd) {
2087 case INT_SC_SERDES_WRITE_REG:
2088 rval = qla8044_write_serdes_word(vha, sr.addr, sr.val);
2089 bsg_job->reply->reply_payload_rcv_len = 0;
2090 break;
2091 case INT_SC_SERDES_READ_REG:
2092 rval = qla8044_read_serdes_word(vha, sr.addr, &sr.val);
2093 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
2094 bsg_job->reply_payload.sg_cnt, &sr, sizeof(sr));
2095 bsg_job->reply->reply_payload_rcv_len = sizeof(sr);
2096 break;
2097 default:
2098 ql_dbg(ql_dbg_user, vha, 0x70cf,
2099 "Unknown serdes cmd %x.\n", sr.cmd);
2100 rval = -EINVAL;
Joe Carnucciodb64e932013-10-30 03:38:18 -04002101 break;
2102 }
2103
2104 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
2105 rval ? EXT_STATUS_MAILBOX : 0;
2106
2107 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
2108 bsg_job->reply->result = DID_OK << 16;
2109 bsg_job->job_done(bsg_job);
2110 return 0;
2111}
2112
2113static int
Sawan Chandak4243c112016-01-27 12:03:31 -05002114qla27xx_get_flash_upd_cap(struct fc_bsg_job *bsg_job)
2115{
2116 struct Scsi_Host *host = bsg_job->shost;
2117 scsi_qla_host_t *vha = shost_priv(host);
2118 struct qla_hw_data *ha = vha->hw;
2119 struct qla_flash_update_caps cap;
2120
2121 if (!(IS_QLA27XX(ha)))
2122 return -EPERM;
2123
2124 memset(&cap, 0, sizeof(cap));
2125 cap.capabilities = (uint64_t)ha->fw_attributes_ext[1] << 48 |
2126 (uint64_t)ha->fw_attributes_ext[0] << 32 |
2127 (uint64_t)ha->fw_attributes_h << 16 |
2128 (uint64_t)ha->fw_attributes;
2129
2130 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
2131 bsg_job->reply_payload.sg_cnt, &cap, sizeof(cap));
2132 bsg_job->reply->reply_payload_rcv_len = sizeof(cap);
2133
2134 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
2135 EXT_STATUS_OK;
2136
2137 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
2138 bsg_job->reply->result = DID_OK << 16;
2139 bsg_job->job_done(bsg_job);
2140 return 0;
2141}
2142
2143static int
2144qla27xx_set_flash_upd_cap(struct fc_bsg_job *bsg_job)
2145{
2146 struct Scsi_Host *host = bsg_job->shost;
2147 scsi_qla_host_t *vha = shost_priv(host);
2148 struct qla_hw_data *ha = vha->hw;
2149 uint64_t online_fw_attr = 0;
2150 struct qla_flash_update_caps cap;
2151
2152 if (!(IS_QLA27XX(ha)))
2153 return -EPERM;
2154
2155 memset(&cap, 0, sizeof(cap));
2156 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
2157 bsg_job->request_payload.sg_cnt, &cap, sizeof(cap));
2158
2159 online_fw_attr = (uint64_t)ha->fw_attributes_ext[1] << 48 |
2160 (uint64_t)ha->fw_attributes_ext[0] << 32 |
2161 (uint64_t)ha->fw_attributes_h << 16 |
2162 (uint64_t)ha->fw_attributes;
2163
2164 if (online_fw_attr != cap.capabilities) {
2165 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
2166 EXT_STATUS_INVALID_PARAM;
2167 return -EINVAL;
2168 }
2169
2170 if (cap.outage_duration < MAX_LOOP_TIMEOUT) {
2171 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
2172 EXT_STATUS_INVALID_PARAM;
2173 return -EINVAL;
2174 }
2175
2176 bsg_job->reply->reply_payload_rcv_len = 0;
2177
2178 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
2179 EXT_STATUS_OK;
2180
2181 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
2182 bsg_job->reply->result = DID_OK << 16;
2183 bsg_job->job_done(bsg_job);
2184 return 0;
2185}
2186
2187static int
Sawan Chandak969a6192016-01-27 12:03:32 -05002188qla27xx_get_bbcr_data(struct fc_bsg_job *bsg_job)
2189{
2190 struct Scsi_Host *host = bsg_job->shost;
2191 scsi_qla_host_t *vha = shost_priv(host);
2192 struct qla_hw_data *ha = vha->hw;
2193 struct qla_bbcr_data bbcr;
2194 uint16_t loop_id, topo, sw_cap;
2195 uint8_t domain, area, al_pa, state;
2196 int rval;
2197
2198 if (!(IS_QLA27XX(ha)))
2199 return -EPERM;
2200
2201 memset(&bbcr, 0, sizeof(bbcr));
2202
2203 if (vha->flags.bbcr_enable)
2204 bbcr.status = QLA_BBCR_STATUS_ENABLED;
2205 else
2206 bbcr.status = QLA_BBCR_STATUS_DISABLED;
2207
2208 if (bbcr.status == QLA_BBCR_STATUS_ENABLED) {
2209 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
2210 &area, &domain, &topo, &sw_cap);
Harish Zunjarraoc73191b2016-01-27 12:03:35 -05002211 if (rval != QLA_SUCCESS) {
2212 bbcr.status = QLA_BBCR_STATUS_UNKNOWN;
2213 bbcr.state = QLA_BBCR_STATE_OFFLINE;
2214 bbcr.mbx1 = loop_id;
2215 goto done;
2216 }
Sawan Chandak969a6192016-01-27 12:03:32 -05002217
2218 state = (vha->bbcr >> 12) & 0x1;
2219
2220 if (state) {
2221 bbcr.state = QLA_BBCR_STATE_OFFLINE;
2222 bbcr.offline_reason_code = QLA_BBCR_REASON_LOGIN_REJECT;
2223 } else {
2224 bbcr.state = QLA_BBCR_STATE_ONLINE;
2225 bbcr.negotiated_bbscn = (vha->bbcr >> 8) & 0xf;
2226 }
2227
2228 bbcr.configured_bbscn = vha->bbcr & 0xf;
2229 }
2230
Harish Zunjarraoc73191b2016-01-27 12:03:35 -05002231done:
Sawan Chandak969a6192016-01-27 12:03:32 -05002232 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
2233 bsg_job->reply_payload.sg_cnt, &bbcr, sizeof(bbcr));
2234 bsg_job->reply->reply_payload_rcv_len = sizeof(bbcr);
2235
2236 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = EXT_STATUS_OK;
2237
2238 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
2239 bsg_job->reply->result = DID_OK << 16;
2240 bsg_job->job_done(bsg_job);
2241 return 0;
2242}
2243
2244static int
Harish Zunjarrao243de672016-01-27 12:03:33 -05002245qla2x00_get_priv_stats(struct fc_bsg_job *bsg_job)
2246{
2247 struct Scsi_Host *host = bsg_job->shost;
2248 scsi_qla_host_t *vha = shost_priv(host);
2249 struct qla_hw_data *ha = vha->hw;
2250 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
2251 struct link_statistics *stats = NULL;
2252 dma_addr_t stats_dma;
Sawan Chandak8437dda2016-07-06 11:14:27 -04002253 int rval;
2254 uint32_t *cmd = bsg_job->request->rqst_data.h_vendor.vendor_cmd;
2255 uint options = cmd[0] == QL_VND_GET_PRIV_STATS_EX ? cmd[1] : 0;
Harish Zunjarrao243de672016-01-27 12:03:33 -05002256
2257 if (test_bit(UNLOADING, &vha->dpc_flags))
Sawan Chandak8437dda2016-07-06 11:14:27 -04002258 return -ENODEV;
Harish Zunjarrao243de672016-01-27 12:03:33 -05002259
2260 if (unlikely(pci_channel_offline(ha->pdev)))
Sawan Chandak8437dda2016-07-06 11:14:27 -04002261 return -ENODEV;
Harish Zunjarrao243de672016-01-27 12:03:33 -05002262
2263 if (qla2x00_reset_active(vha))
Sawan Chandak8437dda2016-07-06 11:14:27 -04002264 return -EBUSY;
Harish Zunjarrao243de672016-01-27 12:03:33 -05002265
2266 if (!IS_FWI2_CAPABLE(ha))
Sawan Chandak8437dda2016-07-06 11:14:27 -04002267 return -EPERM;
Harish Zunjarrao243de672016-01-27 12:03:33 -05002268
2269 stats = dma_alloc_coherent(&ha->pdev->dev,
Sawan Chandak8437dda2016-07-06 11:14:27 -04002270 sizeof(*stats), &stats_dma, GFP_KERNEL);
Harish Zunjarrao243de672016-01-27 12:03:33 -05002271 if (!stats) {
2272 ql_log(ql_log_warn, vha, 0x70e2,
Sawan Chandak8437dda2016-07-06 11:14:27 -04002273 "Failed to allocate memory for stats.\n");
2274 return -ENOMEM;
Harish Zunjarrao243de672016-01-27 12:03:33 -05002275 }
2276
Sawan Chandak8437dda2016-07-06 11:14:27 -04002277 memset(stats, 0, sizeof(*stats));
Harish Zunjarrao243de672016-01-27 12:03:33 -05002278
Sawan Chandak8437dda2016-07-06 11:14:27 -04002279 rval = qla24xx_get_isp_stats(base_vha, stats, stats_dma, options);
Harish Zunjarrao243de672016-01-27 12:03:33 -05002280
Sawan Chandak8437dda2016-07-06 11:14:27 -04002281 if (rval == QLA_SUCCESS) {
2282 ql_dump_buffer(ql_dbg_user + ql_dbg_verbose, vha, 0x70e3,
2283 (uint8_t *)stats, sizeof(*stats));
2284 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
2285 bsg_job->reply_payload.sg_cnt, stats, sizeof(*stats));
2286 }
Harish Zunjarrao243de672016-01-27 12:03:33 -05002287
Sawan Chandak8437dda2016-07-06 11:14:27 -04002288 bsg_job->reply->reply_payload_rcv_len = sizeof(*stats);
2289 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
2290 rval ? EXT_STATUS_MAILBOX : EXT_STATUS_OK;
Harish Zunjarrao243de672016-01-27 12:03:33 -05002291
Sawan Chandak8437dda2016-07-06 11:14:27 -04002292 bsg_job->reply_len = sizeof(*bsg_job->reply);
Harish Zunjarrao243de672016-01-27 12:03:33 -05002293 bsg_job->reply->result = DID_OK << 16;
2294 bsg_job->job_done(bsg_job);
2295
Sawan Chandak8437dda2016-07-06 11:14:27 -04002296 dma_free_coherent(&ha->pdev->dev, sizeof(*stats),
Harish Zunjarrao243de672016-01-27 12:03:33 -05002297 stats, stats_dma);
Sawan Chandak8437dda2016-07-06 11:14:27 -04002298
2299 return 0;
Harish Zunjarrao243de672016-01-27 12:03:33 -05002300}
2301
2302static int
Joe Carnuccioec891462016-07-06 11:14:26 -04002303qla2x00_do_dport_diagnostics(struct fc_bsg_job *bsg_job)
2304{
2305 struct Scsi_Host *host = bsg_job->shost;
2306 scsi_qla_host_t *vha = shost_priv(host);
2307 int rval;
2308 struct qla_dport_diag *dd;
2309
2310 if (!IS_QLA83XX(vha->hw) && !IS_QLA27XX(vha->hw))
2311 return -EPERM;
2312
2313 dd = kmalloc(sizeof(*dd), GFP_KERNEL);
2314 if (!dd) {
2315 ql_log(ql_log_warn, vha, 0x70db,
2316 "Failed to allocate memory for dport.\n");
2317 return -ENOMEM;
2318 }
2319
2320 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
2321 bsg_job->request_payload.sg_cnt, dd, sizeof(*dd));
2322
2323 rval = qla26xx_dport_diagnostics(
2324 vha, dd->buf, sizeof(dd->buf), dd->options);
2325 if (rval == QLA_SUCCESS) {
2326 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
2327 bsg_job->reply_payload.sg_cnt, dd, sizeof(*dd));
2328 }
2329
2330 bsg_job->reply->reply_payload_rcv_len = sizeof(*dd);
2331 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
2332 rval ? EXT_STATUS_MAILBOX : EXT_STATUS_OK;
2333
2334 bsg_job->reply_len = sizeof(*bsg_job->reply);
2335 bsg_job->reply->result = DID_OK << 16;
2336 bsg_job->job_done(bsg_job);
2337
2338 kfree(dd);
2339
2340 return 0;
2341}
2342
2343static int
Giridhar Malavali6e980162010-03-19 17:03:58 -07002344qla2x00_process_vendor_specific(struct fc_bsg_job *bsg_job)
2345{
2346 switch (bsg_job->request->rqst_data.h_vendor.vendor_cmd[0]) {
2347 case QL_VND_LOOPBACK:
2348 return qla2x00_process_loopback(bsg_job);
2349
2350 case QL_VND_A84_RESET:
2351 return qla84xx_reset(bsg_job);
2352
2353 case QL_VND_A84_UPDATE_FW:
2354 return qla84xx_updatefw(bsg_job);
2355
2356 case QL_VND_A84_MGMT_CMD:
2357 return qla84xx_mgmt_cmd(bsg_job);
2358
2359 case QL_VND_IIDMA:
2360 return qla24xx_iidma(bsg_job);
2361
Sarang Radke09ff7012010-03-19 17:03:59 -07002362 case QL_VND_FCP_PRIO_CFG_CMD:
2363 return qla24xx_proc_fcp_prio_cfg_cmd(bsg_job);
2364
Harish Zunjarraof19af162010-10-15 11:27:43 -07002365 case QL_VND_READ_FLASH:
2366 return qla2x00_read_optrom(bsg_job);
2367
2368 case QL_VND_UPDATE_FLASH:
2369 return qla2x00_update_optrom(bsg_job);
2370
Joe Carnuccio697a4bc2011-08-16 11:31:52 -07002371 case QL_VND_SET_FRU_VERSION:
2372 return qla2x00_update_fru_versions(bsg_job);
2373
2374 case QL_VND_READ_FRU_STATUS:
2375 return qla2x00_read_fru_status(bsg_job);
2376
2377 case QL_VND_WRITE_FRU_STATUS:
2378 return qla2x00_write_fru_status(bsg_job);
2379
Joe Carnuccio9ebb5d92012-08-22 14:20:56 -04002380 case QL_VND_WRITE_I2C:
2381 return qla2x00_write_i2c(bsg_job);
2382
2383 case QL_VND_READ_I2C:
2384 return qla2x00_read_i2c(bsg_job);
2385
Saurav Kashyapa9b6f7222012-08-22 14:21:01 -04002386 case QL_VND_DIAG_IO_CMD:
2387 return qla24xx_process_bidir_cmd(bsg_job);
2388
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002389 case QL_VND_FX00_MGMT_CMD:
2390 return qlafx00_mgmt_cmd(bsg_job);
Joe Carnucciodb64e932013-10-30 03:38:18 -04002391
2392 case QL_VND_SERDES_OP:
2393 return qla26xx_serdes_op(bsg_job);
2394
Joe Carnuccioe8887c52014-04-11 16:54:17 -04002395 case QL_VND_SERDES_OP_EX:
2396 return qla8044_serdes_op(bsg_job);
2397
Sawan Chandak4243c112016-01-27 12:03:31 -05002398 case QL_VND_GET_FLASH_UPDATE_CAPS:
2399 return qla27xx_get_flash_upd_cap(bsg_job);
2400
2401 case QL_VND_SET_FLASH_UPDATE_CAPS:
2402 return qla27xx_set_flash_upd_cap(bsg_job);
2403
Sawan Chandak969a6192016-01-27 12:03:32 -05002404 case QL_VND_GET_BBCR_DATA:
2405 return qla27xx_get_bbcr_data(bsg_job);
2406
Harish Zunjarrao243de672016-01-27 12:03:33 -05002407 case QL_VND_GET_PRIV_STATS:
Sawan Chandak8437dda2016-07-06 11:14:27 -04002408 case QL_VND_GET_PRIV_STATS_EX:
Harish Zunjarrao243de672016-01-27 12:03:33 -05002409 return qla2x00_get_priv_stats(bsg_job);
2410
Joe Carnuccioec891462016-07-06 11:14:26 -04002411 case QL_VND_DPORT_DIAGNOSTICS:
2412 return qla2x00_do_dport_diagnostics(bsg_job);
2413
Giridhar Malavali6e980162010-03-19 17:03:58 -07002414 default:
Giridhar Malavali6e980162010-03-19 17:03:58 -07002415 return -ENOSYS;
2416 }
2417}
2418
2419int
2420qla24xx_bsg_request(struct fc_bsg_job *bsg_job)
2421{
2422 int ret = -EINVAL;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002423 struct fc_rport *rport;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002424 struct Scsi_Host *host;
2425 scsi_qla_host_t *vha;
2426
Andrew Vasquezb7bfbe12012-02-09 11:15:44 -08002427 /* In case no data transferred. */
2428 bsg_job->reply->reply_payload_rcv_len = 0;
2429
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002430 if (bsg_job->request->msgcode == FC_BSG_RPT_ELS) {
2431 rport = bsg_job->rport;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002432 host = rport_to_shost(rport);
2433 vha = shost_priv(host);
2434 } else {
2435 host = bsg_job->shost;
2436 vha = shost_priv(host);
2437 }
2438
Andrew Vasquezd051a5aa2012-02-09 11:14:05 -08002439 if (qla2x00_reset_active(vha)) {
2440 ql_dbg(ql_dbg_user, vha, 0x709f,
2441 "BSG: ISP abort active/needed -- cmd=%d.\n",
2442 bsg_job->request->msgcode);
Andrew Vasquezd051a5aa2012-02-09 11:14:05 -08002443 return -EBUSY;
2444 }
2445
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002446 ql_dbg(ql_dbg_user, vha, 0x7000,
Chad Dupuiscfb09192011-11-18 09:03:07 -08002447 "Entered %s msgcode=0x%x.\n", __func__, bsg_job->request->msgcode);
Giridhar Malavali6e980162010-03-19 17:03:58 -07002448
2449 switch (bsg_job->request->msgcode) {
2450 case FC_BSG_RPT_ELS:
2451 case FC_BSG_HST_ELS_NOLOGIN:
2452 ret = qla2x00_process_els(bsg_job);
2453 break;
2454 case FC_BSG_HST_CT:
2455 ret = qla2x00_process_ct(bsg_job);
2456 break;
2457 case FC_BSG_HST_VENDOR:
2458 ret = qla2x00_process_vendor_specific(bsg_job);
2459 break;
2460 case FC_BSG_HST_ADD_RPORT:
2461 case FC_BSG_HST_DEL_RPORT:
2462 case FC_BSG_RPT_CT:
2463 default:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002464 ql_log(ql_log_warn, vha, 0x705a, "Unsupported BSG request.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -07002465 break;
Andrew Vasquez6c452a42010-03-19 17:04:02 -07002466 }
Giridhar Malavali6e980162010-03-19 17:03:58 -07002467 return ret;
2468}
2469
2470int
2471qla24xx_bsg_timeout(struct fc_bsg_job *bsg_job)
2472{
2473 scsi_qla_host_t *vha = shost_priv(bsg_job->shost);
2474 struct qla_hw_data *ha = vha->hw;
2475 srb_t *sp;
2476 int cnt, que;
2477 unsigned long flags;
2478 struct req_que *req;
Giridhar Malavali6e980162010-03-19 17:03:58 -07002479
2480 /* find the bsg job from the active list of commands */
2481 spin_lock_irqsave(&ha->hardware_lock, flags);
2482 for (que = 0; que < ha->max_req_queues; que++) {
2483 req = ha->req_q_map[que];
2484 if (!req)
2485 continue;
2486
Chad Dupuis8d93f552013-01-30 03:34:37 -05002487 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) {
Giridhar Malavali6e980162010-03-19 17:03:58 -07002488 sp = req->outstanding_cmds[cnt];
Giridhar Malavali6e980162010-03-19 17:03:58 -07002489 if (sp) {
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002490 if (((sp->type == SRB_CT_CMD) ||
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002491 (sp->type == SRB_ELS_CMD_HST) ||
2492 (sp->type == SRB_FXIOCB_BCMD))
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002493 && (sp->u.bsg_job == bsg_job)) {
Giridhar Malavali8edf3ed2013-06-25 11:27:17 -04002494 req->outstanding_cmds[cnt] = NULL;
Giridhar Malavali900a36e2010-12-21 16:00:26 -08002495 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Giridhar Malavali6e980162010-03-19 17:03:58 -07002496 if (ha->isp_ops->abort_command(sp)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002497 ql_log(ql_log_warn, vha, 0x7089,
2498 "mbx abort_command "
2499 "failed.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -07002500 bsg_job->req->errors =
2501 bsg_job->reply->result = -EIO;
2502 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002503 ql_dbg(ql_dbg_user, vha, 0x708a,
2504 "mbx abort_command "
2505 "success.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -07002506 bsg_job->req->errors =
2507 bsg_job->reply->result = 0;
2508 }
Giridhar Malavali900a36e2010-12-21 16:00:26 -08002509 spin_lock_irqsave(&ha->hardware_lock, flags);
Giridhar Malavali6e980162010-03-19 17:03:58 -07002510 goto done;
2511 }
2512 }
2513 }
2514 }
2515 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002516 ql_log(ql_log_info, vha, 0x708b, "SRB not found to abort.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -07002517 bsg_job->req->errors = bsg_job->reply->result = -ENXIO;
2518 return 0;
2519
2520done:
2521 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Giridhar Malavali8edf3ed2013-06-25 11:27:17 -04002522 sp->free(vha, sp);
Giridhar Malavali6e980162010-03-19 17:03:58 -07002523 return 0;
2524}