blob: 467c694e6f2ed788cd99d8646a5910b39b27f0c7 [file] [log] [blame]
Giridhar Malavali6e980162010-03-19 17:03:58 -07001/*
2 * QLogic Fibre Channel HBA Driver
Chad Dupuis46152ce2012-08-22 14:21:08 -04003 * Copyright (c) 2003-2012 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;
255 int rval = (DRIVER_ERROR << 16);
256 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) {
339 rval = -ENOMEM;
340 goto done_free_fcport;
341 }
Andrew Vasquez6c452a42010-03-19 17:04:02 -0700342
343 rsp_sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
344 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700345 if (!rsp_sg_cnt) {
346 rval = -ENOMEM;
347 goto done_free_fcport;
348 }
349
350 if ((req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
Andrew Vasquez6c452a42010-03-19 17:04:02 -0700351 (rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700352 ql_log(ql_log_warn, vha, 0x7008,
353 "dma mapping resulted in different sg counts, "
354 "request_sg_cnt: %x dma_request_sg_cnt:%x reply_sg_cnt:%x "
355 "dma_reply_sg_cnt:%x.\n", bsg_job->request_payload.sg_cnt,
356 req_sg_cnt, bsg_job->reply_payload.sg_cnt, rsp_sg_cnt);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700357 rval = -EAGAIN;
358 goto done_unmap_sg;
359 }
360
361 /* Alloc SRB structure */
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800362 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700363 if (!sp) {
364 rval = -ENOMEM;
Andrew Vasquez6c452a42010-03-19 17:04:02 -0700365 goto done_unmap_sg;
Giridhar Malavali6e980162010-03-19 17:03:58 -0700366 }
367
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800368 sp->type =
Giridhar Malavali6e980162010-03-19 17:03:58 -0700369 (bsg_job->request->msgcode == FC_BSG_RPT_ELS ?
370 SRB_ELS_CMD_RPT : SRB_ELS_CMD_HST);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800371 sp->name =
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700372 (bsg_job->request->msgcode == FC_BSG_RPT_ELS ?
373 "bsg_els_rpt" : "bsg_els_hst");
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800374 sp->u.bsg_job = bsg_job;
375 sp->free = qla2x00_bsg_sp_free;
376 sp->done = qla2x00_bsg_job_done;
Giridhar Malavali6e980162010-03-19 17:03:58 -0700377
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700378 ql_dbg(ql_dbg_user, vha, 0x700a,
379 "bsg rqst type: %s els type: %x - loop-id=%x "
380 "portid=%-2x%02x%02x.\n", type,
381 bsg_job->request->rqst_data.h_els.command_code, fcport->loop_id,
382 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700383
384 rval = qla2x00_start_sp(sp);
385 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700386 ql_log(ql_log_warn, vha, 0x700e,
387 "qla2x00_start_sp failed = %d\n", rval);
Chad Dupuisb00ee7d2013-02-08 01:57:50 -0500388 qla2x00_rel_sp(vha, sp);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700389 rval = -EIO;
390 goto done_unmap_sg;
391 }
392 return rval;
393
394done_unmap_sg:
395 dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
396 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
397 dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
398 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
399 goto done_free_fcport;
400
401done_free_fcport:
Bart Van Assche8c0eb592013-06-25 11:27:31 -0400402 if (bsg_job->request->msgcode == FC_BSG_RPT_ELS)
Giridhar Malavali6e980162010-03-19 17:03:58 -0700403 kfree(fcport);
404done:
405 return rval;
406}
407
Andrew Vasquez57807902011-11-18 09:03:20 -0800408inline uint16_t
409qla24xx_calc_ct_iocbs(uint16_t dsds)
410{
411 uint16_t iocbs;
412
413 iocbs = 1;
414 if (dsds > 2) {
415 iocbs += (dsds - 2) / 5;
416 if ((dsds - 2) % 5)
417 iocbs++;
418 }
419 return iocbs;
420}
421
Giridhar Malavali6e980162010-03-19 17:03:58 -0700422static int
423qla2x00_process_ct(struct fc_bsg_job *bsg_job)
424{
425 srb_t *sp;
426 struct Scsi_Host *host = bsg_job->shost;
427 scsi_qla_host_t *vha = shost_priv(host);
428 struct qla_hw_data *ha = vha->hw;
429 int rval = (DRIVER_ERROR << 16);
430 int req_sg_cnt, rsp_sg_cnt;
431 uint16_t loop_id;
432 struct fc_port *fcport;
433 char *type = "FC_BSG_HST_CT";
Giridhar Malavali6e980162010-03-19 17:03:58 -0700434
Giridhar Malavali6e980162010-03-19 17:03:58 -0700435 req_sg_cnt =
436 dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
437 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
Andrew Vasquez6c452a42010-03-19 17:04:02 -0700438 if (!req_sg_cnt) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700439 ql_log(ql_log_warn, vha, 0x700f,
440 "dma_map_sg return %d for request\n", req_sg_cnt);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700441 rval = -ENOMEM;
442 goto done;
443 }
444
445 rsp_sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
446 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
447 if (!rsp_sg_cnt) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700448 ql_log(ql_log_warn, vha, 0x7010,
449 "dma_map_sg return %d for reply\n", rsp_sg_cnt);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700450 rval = -ENOMEM;
451 goto done;
452 }
453
454 if ((req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
Andrew Vasquez6c452a42010-03-19 17:04:02 -0700455 (rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700456 ql_log(ql_log_warn, vha, 0x7011,
457 "request_sg_cnt: %x dma_request_sg_cnt: %x reply_sg_cnt:%x "
458 "dma_reply_sg_cnt: %x\n", bsg_job->request_payload.sg_cnt,
459 req_sg_cnt, bsg_job->reply_payload.sg_cnt, rsp_sg_cnt);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700460 rval = -EAGAIN;
Andrew Vasquez6c452a42010-03-19 17:04:02 -0700461 goto done_unmap_sg;
Giridhar Malavali6e980162010-03-19 17:03:58 -0700462 }
463
464 if (!vha->flags.online) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700465 ql_log(ql_log_warn, vha, 0x7012,
466 "Host is not online.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -0700467 rval = -EIO;
468 goto done_unmap_sg;
469 }
470
471 loop_id =
472 (bsg_job->request->rqst_data.h_ct.preamble_word1 & 0xFF000000)
473 >> 24;
474 switch (loop_id) {
Andrew Vasquez6c452a42010-03-19 17:04:02 -0700475 case 0xFC:
476 loop_id = cpu_to_le16(NPH_SNS);
477 break;
478 case 0xFA:
479 loop_id = vha->mgmt_svr_loop_id;
480 break;
481 default:
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700482 ql_dbg(ql_dbg_user, vha, 0x7013,
483 "Unknown loop id: %x.\n", loop_id);
Andrew Vasquez6c452a42010-03-19 17:04:02 -0700484 rval = -EINVAL;
485 goto done_unmap_sg;
Giridhar Malavali6e980162010-03-19 17:03:58 -0700486 }
487
488 /* Allocate a dummy fcport structure, since functions preparing the
489 * IOCB and mailbox command retrieves port specific information
490 * from fcport structure. For Host based ELS commands there will be
491 * no fcport structure allocated
492 */
493 fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Andrew Vasquez6c452a42010-03-19 17:04:02 -0700494 if (!fcport) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700495 ql_log(ql_log_warn, vha, 0x7014,
496 "Failed to allocate fcport.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -0700497 rval = -ENOMEM;
Andrew Vasquez6c452a42010-03-19 17:04:02 -0700498 goto done_unmap_sg;
Giridhar Malavali6e980162010-03-19 17:03:58 -0700499 }
500
501 /* Initialize all required fields of fcport */
502 fcport->vha = vha;
Giridhar Malavali6e980162010-03-19 17:03:58 -0700503 fcport->d_id.b.al_pa = bsg_job->request->rqst_data.h_ct.port_id[0];
504 fcport->d_id.b.area = bsg_job->request->rqst_data.h_ct.port_id[1];
505 fcport->d_id.b.domain = bsg_job->request->rqst_data.h_ct.port_id[2];
506 fcport->loop_id = loop_id;
507
508 /* Alloc SRB structure */
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800509 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700510 if (!sp) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700511 ql_log(ql_log_warn, vha, 0x7015,
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800512 "qla2x00_get_sp failed.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -0700513 rval = -ENOMEM;
514 goto done_free_fcport;
515 }
516
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800517 sp->type = SRB_CT_CMD;
518 sp->name = "bsg_ct";
519 sp->iocbs = qla24xx_calc_ct_iocbs(req_sg_cnt + rsp_sg_cnt);
520 sp->u.bsg_job = bsg_job;
521 sp->free = qla2x00_bsg_sp_free;
522 sp->done = qla2x00_bsg_job_done;
Giridhar Malavali6e980162010-03-19 17:03:58 -0700523
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700524 ql_dbg(ql_dbg_user, vha, 0x7016,
525 "bsg rqst type: %s else type: %x - "
526 "loop-id=%x portid=%02x%02x%02x.\n", type,
527 (bsg_job->request->rqst_data.h_ct.preamble_word2 >> 16),
528 fcport->loop_id, fcport->d_id.b.domain, fcport->d_id.b.area,
529 fcport->d_id.b.al_pa);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700530
531 rval = qla2x00_start_sp(sp);
532 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700533 ql_log(ql_log_warn, vha, 0x7017,
534 "qla2x00_start_sp failed=%d.\n", rval);
Chad Dupuisb00ee7d2013-02-08 01:57:50 -0500535 qla2x00_rel_sp(vha, sp);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700536 rval = -EIO;
537 goto done_free_fcport;
538 }
539 return rval;
540
541done_free_fcport:
542 kfree(fcport);
543done_unmap_sg:
544 dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
545 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
546 dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
547 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
548done:
549 return rval;
550}
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700551
Chad Dupuis8fcd6b82012-08-22 14:21:06 -0400552/* Disable loopback mode */
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700553static inline int
Chad Dupuis8fcd6b82012-08-22 14:21:06 -0400554qla81xx_reset_loopback_mode(scsi_qla_host_t *vha, uint16_t *config,
Chad Dupuisf356bef2013-02-08 01:58:04 -0500555 int wait, int wait2)
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700556{
557 int ret = 0;
558 int rval = 0;
559 uint16_t new_config[4];
560 struct qla_hw_data *ha = vha->hw;
561
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400562 if (!IS_QLA81XX(ha) && !IS_QLA8031(ha) && !IS_QLA8044(ha))
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700563 goto done_reset_internal;
564
565 memset(new_config, 0 , sizeof(new_config));
566 if ((config[0] & INTERNAL_LOOPBACK_MASK) >> 1 ==
Chad Dupuis8fcd6b82012-08-22 14:21:06 -0400567 ENABLE_INTERNAL_LOOPBACK ||
568 (config[0] & INTERNAL_LOOPBACK_MASK) >> 1 ==
569 ENABLE_EXTERNAL_LOOPBACK) {
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700570 new_config[0] = config[0] & ~INTERNAL_LOOPBACK_MASK;
Chad Dupuis8fcd6b82012-08-22 14:21:06 -0400571 ql_dbg(ql_dbg_user, vha, 0x70bf, "new_config[0]=%02x\n",
572 (new_config[0] & INTERNAL_LOOPBACK_MASK));
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700573 memcpy(&new_config[1], &config[1], sizeof(uint16_t) * 3) ;
574
575 ha->notify_dcbx_comp = wait;
Chad Dupuisf356bef2013-02-08 01:58:04 -0500576 ha->notify_lb_portup_comp = wait2;
577
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700578 ret = qla81xx_set_port_config(vha, new_config);
579 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700580 ql_log(ql_log_warn, vha, 0x7025,
581 "Set port config failed.\n");
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700582 ha->notify_dcbx_comp = 0;
Chad Dupuisf356bef2013-02-08 01:58:04 -0500583 ha->notify_lb_portup_comp = 0;
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700584 rval = -EINVAL;
585 goto done_reset_internal;
586 }
587
588 /* Wait for DCBX complete event */
589 if (wait && !wait_for_completion_timeout(&ha->dcbx_comp,
Chad Dupuisf356bef2013-02-08 01:58:04 -0500590 (DCBX_COMP_TIMEOUT * HZ))) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700591 ql_dbg(ql_dbg_user, vha, 0x7026,
Chad Dupuisf356bef2013-02-08 01:58:04 -0500592 "DCBX completion not received.\n");
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700593 ha->notify_dcbx_comp = 0;
Chad Dupuisf356bef2013-02-08 01:58:04 -0500594 ha->notify_lb_portup_comp = 0;
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700595 rval = -EINVAL;
596 goto done_reset_internal;
597 } else
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700598 ql_dbg(ql_dbg_user, vha, 0x7027,
Chad Dupuisf356bef2013-02-08 01:58:04 -0500599 "DCBX completion received.\n");
600
601 if (wait2 &&
602 !wait_for_completion_timeout(&ha->lb_portup_comp,
603 (LB_PORTUP_COMP_TIMEOUT * HZ))) {
604 ql_dbg(ql_dbg_user, vha, 0x70c5,
605 "Port up completion not received.\n");
606 ha->notify_lb_portup_comp = 0;
607 rval = -EINVAL;
608 goto done_reset_internal;
609 } else
610 ql_dbg(ql_dbg_user, vha, 0x70c6,
611 "Port up completion received.\n");
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700612
613 ha->notify_dcbx_comp = 0;
Chad Dupuisf356bef2013-02-08 01:58:04 -0500614 ha->notify_lb_portup_comp = 0;
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700615 }
616done_reset_internal:
617 return rval;
618}
619
Chad Dupuis67b2a312013-02-08 01:57:51 -0500620/*
621 * Set the port configuration to enable the internal or external loopback
622 * depending on the loopback mode.
623 */
624static inline int
625qla81xx_set_loopback_mode(scsi_qla_host_t *vha, uint16_t *config,
626 uint16_t *new_config, uint16_t mode)
627{
628 int ret = 0;
629 int rval = 0;
Santosh Vernekar454073c2013-08-27 01:37:48 -0400630 unsigned long rem_tmo = 0, current_tmo = 0;
Chad Dupuis67b2a312013-02-08 01:57:51 -0500631 struct qla_hw_data *ha = vha->hw;
632
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400633 if (!IS_QLA81XX(ha) && !IS_QLA8031(ha) && !IS_QLA8044(ha))
Chad Dupuis67b2a312013-02-08 01:57:51 -0500634 goto done_set_internal;
635
636 if (mode == INTERNAL_LOOPBACK)
637 new_config[0] = config[0] | (ENABLE_INTERNAL_LOOPBACK << 1);
638 else if (mode == EXTERNAL_LOOPBACK)
639 new_config[0] = config[0] | (ENABLE_EXTERNAL_LOOPBACK << 1);
640 ql_dbg(ql_dbg_user, vha, 0x70be,
641 "new_config[0]=%02x\n", (new_config[0] & INTERNAL_LOOPBACK_MASK));
642
643 memcpy(&new_config[1], &config[1], sizeof(uint16_t) * 3);
644
645 ha->notify_dcbx_comp = 1;
646 ret = qla81xx_set_port_config(vha, new_config);
647 if (ret != QLA_SUCCESS) {
648 ql_log(ql_log_warn, vha, 0x7021,
649 "set port config failed.\n");
650 ha->notify_dcbx_comp = 0;
651 rval = -EINVAL;
652 goto done_set_internal;
653 }
654
655 /* Wait for DCBX complete event */
Santosh Vernekar454073c2013-08-27 01:37:48 -0400656 current_tmo = DCBX_COMP_TIMEOUT * HZ;
657 while (1) {
658 rem_tmo = wait_for_completion_timeout(&ha->dcbx_comp,
659 current_tmo);
660 if (!ha->idc_extend_tmo || rem_tmo) {
661 ha->idc_extend_tmo = 0;
662 break;
663 }
664 current_tmo = ha->idc_extend_tmo * HZ;
665 ha->idc_extend_tmo = 0;
666 }
667
668 if (!rem_tmo) {
Chad Dupuis67b2a312013-02-08 01:57:51 -0500669 ql_dbg(ql_dbg_user, vha, 0x7022,
Chad Dupuisf356bef2013-02-08 01:58:04 -0500670 "DCBX completion not received.\n");
671 ret = qla81xx_reset_loopback_mode(vha, new_config, 0, 0);
Chad Dupuis67b2a312013-02-08 01:57:51 -0500672 /*
673 * If the reset of the loopback mode doesn't work take a FCoE
674 * dump and reset the chip.
675 */
676 if (ret) {
677 ha->isp_ops->fw_dump(vha, 0);
678 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
679 }
680 rval = -EINVAL;
681 } else {
682 if (ha->flags.idc_compl_status) {
683 ql_dbg(ql_dbg_user, vha, 0x70c3,
684 "Bad status in IDC Completion AEN\n");
685 rval = -EINVAL;
686 ha->flags.idc_compl_status = 0;
687 } else
688 ql_dbg(ql_dbg_user, vha, 0x7023,
Chad Dupuisf356bef2013-02-08 01:58:04 -0500689 "DCBX completion received.\n");
Chad Dupuis67b2a312013-02-08 01:57:51 -0500690 }
691
692 ha->notify_dcbx_comp = 0;
Santosh Vernekar454073c2013-08-27 01:37:48 -0400693 ha->idc_extend_tmo = 0;
Chad Dupuis67b2a312013-02-08 01:57:51 -0500694
695done_set_internal:
696 return rval;
697}
698
Giridhar Malavali6e980162010-03-19 17:03:58 -0700699static int
700qla2x00_process_loopback(struct fc_bsg_job *bsg_job)
701{
702 struct Scsi_Host *host = bsg_job->shost;
703 scsi_qla_host_t *vha = shost_priv(host);
704 struct qla_hw_data *ha = vha->hw;
705 int rval;
706 uint8_t command_sent;
707 char *type;
708 struct msg_echo_lb elreq;
709 uint16_t response[MAILBOX_REGISTER_COUNT];
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700710 uint16_t config[4], new_config[4];
Andrew Vasquez6c452a42010-03-19 17:04:02 -0700711 uint8_t *fw_sts_ptr;
Giridhar Malavali6e980162010-03-19 17:03:58 -0700712 uint8_t *req_data = NULL;
713 dma_addr_t req_data_dma;
714 uint32_t req_data_len;
715 uint8_t *rsp_data = NULL;
716 dma_addr_t rsp_data_dma;
717 uint32_t rsp_data_len;
718
Giridhar Malavali6e980162010-03-19 17:03:58 -0700719 if (!vha->flags.online) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700720 ql_log(ql_log_warn, vha, 0x7019, "Host is not online.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -0700721 return -EIO;
722 }
723
724 elreq.req_sg_cnt = dma_map_sg(&ha->pdev->dev,
725 bsg_job->request_payload.sg_list, bsg_job->request_payload.sg_cnt,
726 DMA_TO_DEVICE);
727
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700728 if (!elreq.req_sg_cnt) {
729 ql_log(ql_log_warn, vha, 0x701a,
730 "dma_map_sg returned %d for request.\n", elreq.req_sg_cnt);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700731 return -ENOMEM;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700732 }
Giridhar Malavali6e980162010-03-19 17:03:58 -0700733
734 elreq.rsp_sg_cnt = dma_map_sg(&ha->pdev->dev,
735 bsg_job->reply_payload.sg_list, bsg_job->reply_payload.sg_cnt,
736 DMA_FROM_DEVICE);
737
738 if (!elreq.rsp_sg_cnt) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700739 ql_log(ql_log_warn, vha, 0x701b,
740 "dma_map_sg returned %d for reply.\n", elreq.rsp_sg_cnt);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700741 rval = -ENOMEM;
742 goto done_unmap_req_sg;
Andrew Vasquez6c452a42010-03-19 17:04:02 -0700743 }
Giridhar Malavali6e980162010-03-19 17:03:58 -0700744
745 if ((elreq.req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
746 (elreq.rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700747 ql_log(ql_log_warn, vha, 0x701c,
748 "dma mapping resulted in different sg counts, "
749 "request_sg_cnt: %x dma_request_sg_cnt: %x "
750 "reply_sg_cnt: %x dma_reply_sg_cnt: %x.\n",
751 bsg_job->request_payload.sg_cnt, elreq.req_sg_cnt,
752 bsg_job->reply_payload.sg_cnt, elreq.rsp_sg_cnt);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700753 rval = -EAGAIN;
754 goto done_unmap_sg;
755 }
756 req_data_len = rsp_data_len = bsg_job->request_payload.payload_len;
757 req_data = dma_alloc_coherent(&ha->pdev->dev, req_data_len,
758 &req_data_dma, GFP_KERNEL);
759 if (!req_data) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700760 ql_log(ql_log_warn, vha, 0x701d,
761 "dma alloc failed for req_data.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -0700762 rval = -ENOMEM;
763 goto done_unmap_sg;
764 }
765
766 rsp_data = dma_alloc_coherent(&ha->pdev->dev, rsp_data_len,
767 &rsp_data_dma, GFP_KERNEL);
768 if (!rsp_data) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700769 ql_log(ql_log_warn, vha, 0x7004,
770 "dma alloc failed for rsp_data.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -0700771 rval = -ENOMEM;
772 goto done_free_dma_req;
773 }
774
775 /* Copy the request buffer in req_data now */
776 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
777 bsg_job->request_payload.sg_cnt, req_data, req_data_len);
778
779 elreq.send_dma = req_data_dma;
780 elreq.rcv_dma = rsp_data_dma;
781 elreq.transfer_size = req_data_len;
782
783 elreq.options = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
Joe Carnuccio1b98b422013-03-28 08:21:26 -0400784 elreq.iteration_count =
785 bsg_job->request->rqst_data.h_vendor.vendor_cmd[2];
Giridhar Malavali6e980162010-03-19 17:03:58 -0700786
Chad Dupuis8fcd6b82012-08-22 14:21:06 -0400787 if (atomic_read(&vha->loop_state) == LOOP_READY &&
788 (ha->current_topology == ISP_CFG_F ||
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400789 ((IS_QLA81XX(ha) || IS_QLA8031(ha) || IS_QLA8044(ha)) &&
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700790 le32_to_cpu(*(uint32_t *)req_data) == ELS_OPCODE_BYTE
791 && req_data_len == MAX_ELS_FRAME_PAYLOAD)) &&
792 elreq.options == EXTERNAL_LOOPBACK) {
Giridhar Malavali6e980162010-03-19 17:03:58 -0700793 type = "FC_BSG_HST_VENDOR_ECHO_DIAG";
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700794 ql_dbg(ql_dbg_user, vha, 0x701e,
795 "BSG request type: %s.\n", type);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700796 command_sent = INT_DEF_LB_ECHO_CMD;
797 rval = qla2x00_echo_test(vha, &elreq, response);
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700798 } else {
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400799 if (IS_QLA81XX(ha) || IS_QLA8031(ha) || IS_QLA8044(ha)) {
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700800 memset(config, 0, sizeof(config));
801 memset(new_config, 0, sizeof(new_config));
Chad Dupuisf356bef2013-02-08 01:58:04 -0500802
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700803 if (qla81xx_get_port_config(vha, config)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700804 ql_log(ql_log_warn, vha, 0x701f,
805 "Get port config failed.\n");
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700806 rval = -EPERM;
Steve Hodgson9bceab42012-11-21 02:39:56 -0500807 goto done_free_dma_rsp;
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700808 }
809
Chad Dupuis1bcc46c2013-02-08 01:57:46 -0500810 if ((config[0] & INTERNAL_LOOPBACK_MASK) != 0) {
811 ql_dbg(ql_dbg_user, vha, 0x70c4,
812 "Loopback operation already in "
813 "progress.\n");
814 rval = -EAGAIN;
815 goto done_free_dma_rsp;
816 }
817
Chad Dupuis8fcd6b82012-08-22 14:21:06 -0400818 ql_dbg(ql_dbg_user, vha, 0x70c0,
819 "elreq.options=%04x\n", elreq.options);
820
821 if (elreq.options == EXTERNAL_LOOPBACK)
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400822 if (IS_QLA8031(ha) || IS_QLA8044(ha))
Chad Dupuis8fcd6b82012-08-22 14:21:06 -0400823 rval = qla81xx_set_loopback_mode(vha,
824 config, new_config, elreq.options);
825 else
826 rval = qla81xx_reset_loopback_mode(vha,
Chad Dupuisf356bef2013-02-08 01:58:04 -0500827 config, 1, 0);
Chad Dupuis8fcd6b82012-08-22 14:21:06 -0400828 else
829 rval = qla81xx_set_loopback_mode(vha, config,
830 new_config, elreq.options);
831
832 if (rval) {
Chad Dupuis8fcd6b82012-08-22 14:21:06 -0400833 rval = -EPERM;
Steve Hodgson9bceab42012-11-21 02:39:56 -0500834 goto done_free_dma_rsp;
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700835 }
836
837 type = "FC_BSG_HST_VENDOR_LOOPBACK";
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700838 ql_dbg(ql_dbg_user, vha, 0x7028,
839 "BSG request type: %s.\n", type);
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700840
841 command_sent = INT_DEF_LB_LOOPBACK_CMD;
842 rval = qla2x00_loopback_test(vha, &elreq, response);
843
Chad Dupuis992357c2013-02-08 01:57:52 -0500844 if (response[0] == MBS_COMMAND_ERROR &&
845 response[1] == MBS_LB_RESET) {
846 ql_log(ql_log_warn, vha, 0x7029,
847 "MBX command error, Aborting ISP.\n");
848 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
849 qla2xxx_wake_dpc(vha);
850 qla2x00_wait_for_chip_reset(vha);
851 /* Also reset the MPI */
852 if (IS_QLA81XX(ha)) {
853 if (qla81xx_restart_mpi_firmware(vha) !=
854 QLA_SUCCESS) {
855 ql_log(ql_log_warn, vha, 0x702a,
856 "MPI reset failed.\n");
857 }
858 }
859
860 rval = -EIO;
861 goto done_free_dma_rsp;
862 }
863
Joe Carnuccio4052bd52010-12-21 16:00:17 -0800864 if (new_config[0]) {
Chad Dupuis67b2a312013-02-08 01:57:51 -0500865 int ret;
866
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700867 /* Revert back to original port config
868 * Also clear internal loopback
869 */
Chad Dupuis67b2a312013-02-08 01:57:51 -0500870 ret = qla81xx_reset_loopback_mode(vha,
Chad Dupuisf356bef2013-02-08 01:58:04 -0500871 new_config, 0, 1);
Chad Dupuis67b2a312013-02-08 01:57:51 -0500872 if (ret) {
873 /*
874 * If the reset of the loopback mode
875 * doesn't work take FCoE dump and then
876 * reset the chip.
877 */
878 ha->isp_ops->fw_dump(vha, 0);
879 set_bit(ISP_ABORT_NEEDED,
880 &vha->dpc_flags);
881 }
882
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700883 }
884
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700885 } else {
886 type = "FC_BSG_HST_VENDOR_LOOPBACK";
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700887 ql_dbg(ql_dbg_user, vha, 0x702b,
888 "BSG request type: %s.\n", type);
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700889 command_sent = INT_DEF_LB_LOOPBACK_CMD;
890 rval = qla2x00_loopback_test(vha, &elreq, response);
891 }
Giridhar Malavali6e980162010-03-19 17:03:58 -0700892 }
893
894 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700895 ql_log(ql_log_warn, vha, 0x702c,
896 "Vendor request %s failed.\n", type);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700897
Giridhar Malavali6e980162010-03-19 17:03:58 -0700898 rval = 0;
Giridhar Malavali6e980162010-03-19 17:03:58 -0700899 bsg_job->reply->result = (DID_ERROR << 16);
Armen Baloyan63ea9232012-11-21 02:39:53 -0500900 bsg_job->reply->reply_payload_rcv_len = 0;
Giridhar Malavali6e980162010-03-19 17:03:58 -0700901 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700902 ql_dbg(ql_dbg_user, vha, 0x702d,
903 "Vendor request %s completed.\n", type);
Armen Baloyan63ea9232012-11-21 02:39:53 -0500904 bsg_job->reply->result = (DID_OK << 16);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700905 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
906 bsg_job->reply_payload.sg_cnt, rsp_data,
907 rsp_data_len);
908 }
Armen Baloyan63ea9232012-11-21 02:39:53 -0500909
910 bsg_job->reply_len = sizeof(struct fc_bsg_reply) +
911 sizeof(response) + sizeof(uint8_t);
912 fw_sts_ptr = ((uint8_t *)bsg_job->req->sense) +
913 sizeof(struct fc_bsg_reply);
914 memcpy(fw_sts_ptr, response, sizeof(response));
915 fw_sts_ptr += sizeof(response);
916 *fw_sts_ptr = command_sent;
Giridhar Malavali6e980162010-03-19 17:03:58 -0700917
Steve Hodgson9bceab42012-11-21 02:39:56 -0500918done_free_dma_rsp:
Giridhar Malavali6e980162010-03-19 17:03:58 -0700919 dma_free_coherent(&ha->pdev->dev, rsp_data_len,
920 rsp_data, rsp_data_dma);
921done_free_dma_req:
922 dma_free_coherent(&ha->pdev->dev, req_data_len,
923 req_data, req_data_dma);
924done_unmap_sg:
925 dma_unmap_sg(&ha->pdev->dev,
926 bsg_job->reply_payload.sg_list,
927 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
928done_unmap_req_sg:
929 dma_unmap_sg(&ha->pdev->dev,
930 bsg_job->request_payload.sg_list,
931 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
Armen Baloyan63ea9232012-11-21 02:39:53 -0500932 if (!rval)
933 bsg_job->job_done(bsg_job);
Andrew Vasquez6c452a42010-03-19 17:04:02 -0700934 return rval;
Giridhar Malavali6e980162010-03-19 17:03:58 -0700935}
936
937static int
938qla84xx_reset(struct fc_bsg_job *bsg_job)
939{
940 struct Scsi_Host *host = bsg_job->shost;
941 scsi_qla_host_t *vha = shost_priv(host);
942 struct qla_hw_data *ha = vha->hw;
943 int rval = 0;
944 uint32_t flag;
945
Giridhar Malavali6e980162010-03-19 17:03:58 -0700946 if (!IS_QLA84XX(ha)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700947 ql_dbg(ql_dbg_user, vha, 0x702f, "Not 84xx, exiting.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -0700948 return -EINVAL;
949 }
950
951 flag = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
952
953 rval = qla84xx_reset_chip(vha, flag == A84_ISSUE_RESET_DIAG_FW);
954
955 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700956 ql_log(ql_log_warn, vha, 0x7030,
957 "Vendor request 84xx reset failed.\n");
Armen Baloyan63ea9232012-11-21 02:39:53 -0500958 rval = (DID_ERROR << 16);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700959
960 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700961 ql_dbg(ql_dbg_user, vha, 0x7031,
962 "Vendor request 84xx reset completed.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -0700963 bsg_job->reply->result = DID_OK;
Armen Baloyan63ea9232012-11-21 02:39:53 -0500964 bsg_job->job_done(bsg_job);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700965 }
966
Giridhar Malavali6e980162010-03-19 17:03:58 -0700967 return rval;
968}
969
970static int
971qla84xx_updatefw(struct fc_bsg_job *bsg_job)
972{
973 struct Scsi_Host *host = bsg_job->shost;
974 scsi_qla_host_t *vha = shost_priv(host);
975 struct qla_hw_data *ha = vha->hw;
976 struct verify_chip_entry_84xx *mn = NULL;
977 dma_addr_t mn_dma, fw_dma;
978 void *fw_buf = NULL;
979 int rval = 0;
980 uint32_t sg_cnt;
981 uint32_t data_len;
982 uint16_t options;
983 uint32_t flag;
984 uint32_t fw_ver;
985
Giridhar Malavali6e980162010-03-19 17:03:58 -0700986 if (!IS_QLA84XX(ha)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700987 ql_dbg(ql_dbg_user, vha, 0x7032,
988 "Not 84xx, exiting.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -0700989 return -EINVAL;
990 }
991
992 sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
993 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700994 if (!sg_cnt) {
995 ql_log(ql_log_warn, vha, 0x7033,
996 "dma_map_sg returned %d for request.\n", sg_cnt);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700997 return -ENOMEM;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700998 }
Giridhar Malavali6e980162010-03-19 17:03:58 -0700999
1000 if (sg_cnt != bsg_job->request_payload.sg_cnt) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001001 ql_log(ql_log_warn, vha, 0x7034,
1002 "DMA mapping resulted in different sg counts, "
1003 "request_sg_cnt: %x dma_request_sg_cnt: %x.\n",
1004 bsg_job->request_payload.sg_cnt, sg_cnt);
Giridhar Malavali6e980162010-03-19 17:03:58 -07001005 rval = -EAGAIN;
1006 goto done_unmap_sg;
1007 }
1008
1009 data_len = bsg_job->request_payload.payload_len;
1010 fw_buf = dma_alloc_coherent(&ha->pdev->dev, data_len,
1011 &fw_dma, GFP_KERNEL);
1012 if (!fw_buf) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001013 ql_log(ql_log_warn, vha, 0x7035,
1014 "DMA alloc failed for fw_buf.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -07001015 rval = -ENOMEM;
1016 goto done_unmap_sg;
1017 }
1018
1019 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1020 bsg_job->request_payload.sg_cnt, fw_buf, data_len);
1021
1022 mn = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma);
1023 if (!mn) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001024 ql_log(ql_log_warn, vha, 0x7036,
1025 "DMA alloc failed for fw buffer.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -07001026 rval = -ENOMEM;
1027 goto done_free_fw_buf;
1028 }
1029
1030 flag = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
1031 fw_ver = le32_to_cpu(*((uint32_t *)((uint32_t *)fw_buf + 2)));
1032
1033 memset(mn, 0, sizeof(struct access_chip_84xx));
1034 mn->entry_type = VERIFY_CHIP_IOCB_TYPE;
1035 mn->entry_count = 1;
1036
1037 options = VCO_FORCE_UPDATE | VCO_END_OF_DATA;
1038 if (flag == A84_ISSUE_UPDATE_DIAGFW_CMD)
1039 options |= VCO_DIAG_FW;
1040
1041 mn->options = cpu_to_le16(options);
1042 mn->fw_ver = cpu_to_le32(fw_ver);
1043 mn->fw_size = cpu_to_le32(data_len);
1044 mn->fw_seq_size = cpu_to_le32(data_len);
1045 mn->dseg_address[0] = cpu_to_le32(LSD(fw_dma));
1046 mn->dseg_address[1] = cpu_to_le32(MSD(fw_dma));
1047 mn->dseg_length = cpu_to_le32(data_len);
1048 mn->data_seg_cnt = cpu_to_le16(1);
1049
1050 rval = qla2x00_issue_iocb_timeout(vha, mn, mn_dma, 0, 120);
1051
1052 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001053 ql_log(ql_log_warn, vha, 0x7037,
1054 "Vendor request 84xx updatefw failed.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -07001055
Armen Baloyan63ea9232012-11-21 02:39:53 -05001056 rval = (DID_ERROR << 16);
Giridhar Malavali6e980162010-03-19 17:03:58 -07001057 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001058 ql_dbg(ql_dbg_user, vha, 0x7038,
1059 "Vendor request 84xx updatefw completed.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -07001060
1061 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1062 bsg_job->reply->result = DID_OK;
1063 }
1064
Giridhar Malavali6e980162010-03-19 17:03:58 -07001065 dma_pool_free(ha->s_dma_pool, mn, mn_dma);
1066
1067done_free_fw_buf:
1068 dma_free_coherent(&ha->pdev->dev, data_len, fw_buf, fw_dma);
1069
1070done_unmap_sg:
1071 dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
1072 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
1073
Armen Baloyan63ea9232012-11-21 02:39:53 -05001074 if (!rval)
1075 bsg_job->job_done(bsg_job);
Giridhar Malavali6e980162010-03-19 17:03:58 -07001076 return rval;
1077}
1078
1079static int
1080qla84xx_mgmt_cmd(struct fc_bsg_job *bsg_job)
1081{
1082 struct Scsi_Host *host = bsg_job->shost;
1083 scsi_qla_host_t *vha = shost_priv(host);
1084 struct qla_hw_data *ha = vha->hw;
1085 struct access_chip_84xx *mn = NULL;
1086 dma_addr_t mn_dma, mgmt_dma;
1087 void *mgmt_b = NULL;
1088 int rval = 0;
1089 struct qla_bsg_a84_mgmt *ql84_mgmt;
1090 uint32_t sg_cnt;
Harish Zunjarraod5459082010-03-19 17:04:00 -07001091 uint32_t data_len = 0;
Giridhar Malavali6e980162010-03-19 17:03:58 -07001092 uint32_t dma_direction = DMA_NONE;
1093
Giridhar Malavali6e980162010-03-19 17:03:58 -07001094 if (!IS_QLA84XX(ha)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001095 ql_log(ql_log_warn, vha, 0x703a,
1096 "Not 84xx, exiting.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -07001097 return -EINVAL;
1098 }
1099
Giridhar Malavali6e980162010-03-19 17:03:58 -07001100 mn = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma);
1101 if (!mn) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001102 ql_log(ql_log_warn, vha, 0x703c,
1103 "DMA alloc failed for fw buffer.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -07001104 return -ENOMEM;
1105 }
1106
1107 memset(mn, 0, sizeof(struct access_chip_84xx));
1108 mn->entry_type = ACCESS_CHIP_IOCB_TYPE;
1109 mn->entry_count = 1;
Bart Van Asschea44c72f2013-06-25 11:27:23 -04001110 ql84_mgmt = (void *)bsg_job->request + sizeof(struct fc_bsg_request);
Giridhar Malavali6e980162010-03-19 17:03:58 -07001111 switch (ql84_mgmt->mgmt.cmd) {
1112 case QLA84_MGMT_READ_MEM:
1113 case QLA84_MGMT_GET_INFO:
1114 sg_cnt = dma_map_sg(&ha->pdev->dev,
1115 bsg_job->reply_payload.sg_list,
1116 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
1117 if (!sg_cnt) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001118 ql_log(ql_log_warn, vha, 0x703d,
1119 "dma_map_sg returned %d for reply.\n", sg_cnt);
Giridhar Malavali6e980162010-03-19 17:03:58 -07001120 rval = -ENOMEM;
1121 goto exit_mgmt;
1122 }
1123
1124 dma_direction = DMA_FROM_DEVICE;
1125
1126 if (sg_cnt != bsg_job->reply_payload.sg_cnt) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001127 ql_log(ql_log_warn, vha, 0x703e,
1128 "DMA mapping resulted in different sg counts, "
1129 "reply_sg_cnt: %x dma_reply_sg_cnt: %x.\n",
1130 bsg_job->reply_payload.sg_cnt, sg_cnt);
Giridhar Malavali6e980162010-03-19 17:03:58 -07001131 rval = -EAGAIN;
1132 goto done_unmap_sg;
1133 }
1134
1135 data_len = bsg_job->reply_payload.payload_len;
1136
1137 mgmt_b = dma_alloc_coherent(&ha->pdev->dev, data_len,
1138 &mgmt_dma, GFP_KERNEL);
1139 if (!mgmt_b) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001140 ql_log(ql_log_warn, vha, 0x703f,
1141 "DMA alloc failed for mgmt_b.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -07001142 rval = -ENOMEM;
1143 goto done_unmap_sg;
1144 }
1145
1146 if (ql84_mgmt->mgmt.cmd == QLA84_MGMT_READ_MEM) {
1147 mn->options = cpu_to_le16(ACO_DUMP_MEMORY);
1148 mn->parameter1 =
1149 cpu_to_le32(
1150 ql84_mgmt->mgmt.mgmtp.u.mem.start_addr);
1151
1152 } else if (ql84_mgmt->mgmt.cmd == QLA84_MGMT_GET_INFO) {
1153 mn->options = cpu_to_le16(ACO_REQUEST_INFO);
1154 mn->parameter1 =
1155 cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.info.type);
1156
1157 mn->parameter2 =
1158 cpu_to_le32(
1159 ql84_mgmt->mgmt.mgmtp.u.info.context);
1160 }
1161 break;
1162
1163 case QLA84_MGMT_WRITE_MEM:
1164 sg_cnt = dma_map_sg(&ha->pdev->dev,
1165 bsg_job->request_payload.sg_list,
1166 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
1167
1168 if (!sg_cnt) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001169 ql_log(ql_log_warn, vha, 0x7040,
1170 "dma_map_sg returned %d.\n", sg_cnt);
Giridhar Malavali6e980162010-03-19 17:03:58 -07001171 rval = -ENOMEM;
1172 goto exit_mgmt;
1173 }
1174
1175 dma_direction = DMA_TO_DEVICE;
1176
1177 if (sg_cnt != bsg_job->request_payload.sg_cnt) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001178 ql_log(ql_log_warn, vha, 0x7041,
1179 "DMA mapping resulted in different sg counts, "
1180 "request_sg_cnt: %x dma_request_sg_cnt: %x.\n",
1181 bsg_job->request_payload.sg_cnt, sg_cnt);
Giridhar Malavali6e980162010-03-19 17:03:58 -07001182 rval = -EAGAIN;
1183 goto done_unmap_sg;
1184 }
1185
1186 data_len = bsg_job->request_payload.payload_len;
1187 mgmt_b = dma_alloc_coherent(&ha->pdev->dev, data_len,
1188 &mgmt_dma, GFP_KERNEL);
1189 if (!mgmt_b) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001190 ql_log(ql_log_warn, vha, 0x7042,
1191 "DMA alloc failed for mgmt_b.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -07001192 rval = -ENOMEM;
1193 goto done_unmap_sg;
1194 }
1195
1196 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1197 bsg_job->request_payload.sg_cnt, mgmt_b, data_len);
1198
1199 mn->options = cpu_to_le16(ACO_LOAD_MEMORY);
1200 mn->parameter1 =
1201 cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.mem.start_addr);
1202 break;
1203
1204 case QLA84_MGMT_CHNG_CONFIG:
1205 mn->options = cpu_to_le16(ACO_CHANGE_CONFIG_PARAM);
1206 mn->parameter1 =
1207 cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.config.id);
1208
1209 mn->parameter2 =
1210 cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.config.param0);
1211
1212 mn->parameter3 =
1213 cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.config.param1);
1214 break;
1215
1216 default:
1217 rval = -EIO;
1218 goto exit_mgmt;
1219 }
1220
1221 if (ql84_mgmt->mgmt.cmd != QLA84_MGMT_CHNG_CONFIG) {
1222 mn->total_byte_cnt = cpu_to_le32(ql84_mgmt->mgmt.len);
1223 mn->dseg_count = cpu_to_le16(1);
1224 mn->dseg_address[0] = cpu_to_le32(LSD(mgmt_dma));
1225 mn->dseg_address[1] = cpu_to_le32(MSD(mgmt_dma));
1226 mn->dseg_length = cpu_to_le32(ql84_mgmt->mgmt.len);
1227 }
1228
1229 rval = qla2x00_issue_iocb(vha, mn, mn_dma, 0);
1230
1231 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001232 ql_log(ql_log_warn, vha, 0x7043,
1233 "Vendor request 84xx mgmt failed.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -07001234
Armen Baloyan63ea9232012-11-21 02:39:53 -05001235 rval = (DID_ERROR << 16);
Giridhar Malavali6e980162010-03-19 17:03:58 -07001236
1237 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001238 ql_dbg(ql_dbg_user, vha, 0x7044,
1239 "Vendor request 84xx mgmt completed.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -07001240
1241 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1242 bsg_job->reply->result = DID_OK;
1243
1244 if ((ql84_mgmt->mgmt.cmd == QLA84_MGMT_READ_MEM) ||
1245 (ql84_mgmt->mgmt.cmd == QLA84_MGMT_GET_INFO)) {
1246 bsg_job->reply->reply_payload_rcv_len =
1247 bsg_job->reply_payload.payload_len;
1248
1249 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
Andrew Vasquez6c452a42010-03-19 17:04:02 -07001250 bsg_job->reply_payload.sg_cnt, mgmt_b,
1251 data_len);
Giridhar Malavali6e980162010-03-19 17:03:58 -07001252 }
1253 }
1254
Giridhar Malavali6e980162010-03-19 17:03:58 -07001255done_unmap_sg:
Harish Zunjarraod5459082010-03-19 17:04:00 -07001256 if (mgmt_b)
1257 dma_free_coherent(&ha->pdev->dev, data_len, mgmt_b, mgmt_dma);
1258
Giridhar Malavali6e980162010-03-19 17:03:58 -07001259 if (dma_direction == DMA_TO_DEVICE)
1260 dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
1261 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
1262 else if (dma_direction == DMA_FROM_DEVICE)
1263 dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
1264 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
1265
1266exit_mgmt:
1267 dma_pool_free(ha->s_dma_pool, mn, mn_dma);
1268
Armen Baloyan63ea9232012-11-21 02:39:53 -05001269 if (!rval)
1270 bsg_job->job_done(bsg_job);
Giridhar Malavali6e980162010-03-19 17:03:58 -07001271 return rval;
1272}
1273
1274static int
1275qla24xx_iidma(struct fc_bsg_job *bsg_job)
1276{
1277 struct Scsi_Host *host = bsg_job->shost;
1278 scsi_qla_host_t *vha = shost_priv(host);
Giridhar Malavali6e980162010-03-19 17:03:58 -07001279 int rval = 0;
1280 struct qla_port_param *port_param = NULL;
1281 fc_port_t *fcport = NULL;
Joe Carnuccioe8b8b8a2013-08-27 01:37:29 -04001282 int found = 0;
Giridhar Malavali6e980162010-03-19 17:03:58 -07001283 uint16_t mb[MAILBOX_REGISTER_COUNT];
1284 uint8_t *rsp_ptr = NULL;
1285
Giridhar Malavali6e980162010-03-19 17:03:58 -07001286 if (!IS_IIDMA_CAPABLE(vha->hw)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001287 ql_log(ql_log_info, vha, 0x7046, "iiDMA not supported.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -07001288 return -EINVAL;
1289 }
1290
Bart Van Assche090fc2e2013-06-25 11:27:22 -04001291 port_param = (void *)bsg_job->request + sizeof(struct fc_bsg_request);
Giridhar Malavali6e980162010-03-19 17:03:58 -07001292 if (port_param->fc_scsi_addr.dest_type != EXT_DEF_TYPE_WWPN) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001293 ql_log(ql_log_warn, vha, 0x7048,
1294 "Invalid destination type.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -07001295 return -EINVAL;
1296 }
1297
1298 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1299 if (fcport->port_type != FCT_TARGET)
1300 continue;
1301
1302 if (memcmp(port_param->fc_scsi_addr.dest_addr.wwpn,
1303 fcport->port_name, sizeof(fcport->port_name)))
1304 continue;
Joe Carnuccioe8b8b8a2013-08-27 01:37:29 -04001305
1306 found = 1;
Giridhar Malavali6e980162010-03-19 17:03:58 -07001307 break;
1308 }
1309
Joe Carnuccioe8b8b8a2013-08-27 01:37:29 -04001310 if (!found) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001311 ql_log(ql_log_warn, vha, 0x7049,
1312 "Failed to find port.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -07001313 return -EINVAL;
1314 }
1315
Giridhar Malavalic9afb9a2010-09-03 15:20:48 -07001316 if (atomic_read(&fcport->state) != FCS_ONLINE) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001317 ql_log(ql_log_warn, vha, 0x704a,
1318 "Port is not online.\n");
Madhuranath Iyengar17cf2c52010-07-23 15:28:22 +05001319 return -EINVAL;
1320 }
1321
Madhuranath Iyengar9a15eb42010-07-23 15:28:31 +05001322 if (fcport->flags & FCF_LOGIN_NEEDED) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001323 ql_log(ql_log_warn, vha, 0x704b,
1324 "Remote port not logged in flags = 0x%x.\n", fcport->flags);
Madhuranath Iyengar9a15eb42010-07-23 15:28:31 +05001325 return -EINVAL;
1326 }
1327
Giridhar Malavali6e980162010-03-19 17:03:58 -07001328 if (port_param->mode)
1329 rval = qla2x00_set_idma_speed(vha, fcport->loop_id,
1330 port_param->speed, mb);
1331 else
1332 rval = qla2x00_get_idma_speed(vha, fcport->loop_id,
1333 &port_param->speed, mb);
1334
1335 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001336 ql_log(ql_log_warn, vha, 0x704c,
Oleksandr Khoshaba7b833552013-08-27 01:37:27 -04001337 "iIDMA cmd failed for %8phN -- "
1338 "%04x %x %04x %04x.\n", fcport->port_name,
1339 rval, fcport->fp_speed, mb[0], mb[1]);
Armen Baloyan63ea9232012-11-21 02:39:53 -05001340 rval = (DID_ERROR << 16);
Giridhar Malavali6e980162010-03-19 17:03:58 -07001341 } else {
1342 if (!port_param->mode) {
1343 bsg_job->reply_len = sizeof(struct fc_bsg_reply) +
1344 sizeof(struct qla_port_param);
1345
1346 rsp_ptr = ((uint8_t *)bsg_job->reply) +
1347 sizeof(struct fc_bsg_reply);
1348
1349 memcpy(rsp_ptr, port_param,
1350 sizeof(struct qla_port_param));
1351 }
1352
1353 bsg_job->reply->result = DID_OK;
Armen Baloyan63ea9232012-11-21 02:39:53 -05001354 bsg_job->job_done(bsg_job);
Giridhar Malavali6e980162010-03-19 17:03:58 -07001355 }
1356
Giridhar Malavali6e980162010-03-19 17:03:58 -07001357 return rval;
1358}
1359
1360static int
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001361qla2x00_optrom_setup(struct fc_bsg_job *bsg_job, scsi_qla_host_t *vha,
Harish Zunjarraof19af162010-10-15 11:27:43 -07001362 uint8_t is_update)
1363{
1364 uint32_t start = 0;
1365 int valid = 0;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001366 struct qla_hw_data *ha = vha->hw;
Harish Zunjarraof19af162010-10-15 11:27:43 -07001367
Harish Zunjarraof19af162010-10-15 11:27:43 -07001368 if (unlikely(pci_channel_offline(ha->pdev)))
1369 return -EINVAL;
1370
1371 start = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001372 if (start > ha->optrom_size) {
1373 ql_log(ql_log_warn, vha, 0x7055,
1374 "start %d > optrom_size %d.\n", start, ha->optrom_size);
Harish Zunjarraof19af162010-10-15 11:27:43 -07001375 return -EINVAL;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001376 }
Harish Zunjarraof19af162010-10-15 11:27:43 -07001377
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001378 if (ha->optrom_state != QLA_SWAITING) {
1379 ql_log(ql_log_info, vha, 0x7056,
1380 "optrom_state %d.\n", ha->optrom_state);
Harish Zunjarraof19af162010-10-15 11:27:43 -07001381 return -EBUSY;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001382 }
Harish Zunjarraof19af162010-10-15 11:27:43 -07001383
1384 ha->optrom_region_start = start;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001385 ql_dbg(ql_dbg_user, vha, 0x7057, "is_update=%d.\n", is_update);
Harish Zunjarraof19af162010-10-15 11:27:43 -07001386 if (is_update) {
1387 if (ha->optrom_size == OPTROM_SIZE_2300 && start == 0)
1388 valid = 1;
1389 else if (start == (ha->flt_region_boot * 4) ||
1390 start == (ha->flt_region_fw * 4))
1391 valid = 1;
1392 else if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha) ||
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001393 IS_CNA_CAPABLE(ha) || IS_QLA2031(ha))
Harish Zunjarraof19af162010-10-15 11:27:43 -07001394 valid = 1;
1395 if (!valid) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001396 ql_log(ql_log_warn, vha, 0x7058,
1397 "Invalid start region 0x%x/0x%x.\n", start,
1398 bsg_job->request_payload.payload_len);
Harish Zunjarraof19af162010-10-15 11:27:43 -07001399 return -EINVAL;
1400 }
1401
1402 ha->optrom_region_size = start +
1403 bsg_job->request_payload.payload_len > ha->optrom_size ?
1404 ha->optrom_size - start :
1405 bsg_job->request_payload.payload_len;
1406 ha->optrom_state = QLA_SWRITING;
1407 } else {
1408 ha->optrom_region_size = start +
1409 bsg_job->reply_payload.payload_len > ha->optrom_size ?
1410 ha->optrom_size - start :
1411 bsg_job->reply_payload.payload_len;
1412 ha->optrom_state = QLA_SREADING;
1413 }
1414
1415 ha->optrom_buffer = vmalloc(ha->optrom_region_size);
1416 if (!ha->optrom_buffer) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001417 ql_log(ql_log_warn, vha, 0x7059,
Harish Zunjarraof19af162010-10-15 11:27:43 -07001418 "Read: Unable to allocate memory for optrom retrieval "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001419 "(%x)\n", ha->optrom_region_size);
Harish Zunjarraof19af162010-10-15 11:27:43 -07001420
1421 ha->optrom_state = QLA_SWAITING;
1422 return -ENOMEM;
1423 }
1424
1425 memset(ha->optrom_buffer, 0, ha->optrom_region_size);
1426 return 0;
1427}
1428
1429static int
1430qla2x00_read_optrom(struct fc_bsg_job *bsg_job)
1431{
1432 struct Scsi_Host *host = bsg_job->shost;
1433 scsi_qla_host_t *vha = shost_priv(host);
1434 struct qla_hw_data *ha = vha->hw;
1435 int rval = 0;
1436
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04001437 if (ha->flags.nic_core_reset_hdlr_active)
Giridhar Malavalia49393f2012-04-25 07:26:14 -07001438 return -EBUSY;
1439
Chad Dupuis7a8ab9c2014-02-26 04:14:56 -05001440 mutex_lock(&ha->optrom_mutex);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001441 rval = qla2x00_optrom_setup(bsg_job, vha, 0);
Chad Dupuis7a8ab9c2014-02-26 04:14:56 -05001442 if (rval) {
1443 mutex_unlock(&ha->optrom_mutex);
Harish Zunjarraof19af162010-10-15 11:27:43 -07001444 return rval;
Chad Dupuis7a8ab9c2014-02-26 04:14:56 -05001445 }
Harish Zunjarraof19af162010-10-15 11:27:43 -07001446
1447 ha->isp_ops->read_optrom(vha, ha->optrom_buffer,
1448 ha->optrom_region_start, ha->optrom_region_size);
1449
1450 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
1451 bsg_job->reply_payload.sg_cnt, ha->optrom_buffer,
1452 ha->optrom_region_size);
1453
1454 bsg_job->reply->reply_payload_rcv_len = ha->optrom_region_size;
1455 bsg_job->reply->result = DID_OK;
1456 vfree(ha->optrom_buffer);
1457 ha->optrom_buffer = NULL;
1458 ha->optrom_state = QLA_SWAITING;
Chad Dupuis7a8ab9c2014-02-26 04:14:56 -05001459 mutex_unlock(&ha->optrom_mutex);
Harish Zunjarraof19af162010-10-15 11:27:43 -07001460 bsg_job->job_done(bsg_job);
1461 return rval;
1462}
1463
1464static int
1465qla2x00_update_optrom(struct fc_bsg_job *bsg_job)
1466{
1467 struct Scsi_Host *host = bsg_job->shost;
1468 scsi_qla_host_t *vha = shost_priv(host);
1469 struct qla_hw_data *ha = vha->hw;
1470 int rval = 0;
1471
Chad Dupuis7a8ab9c2014-02-26 04:14:56 -05001472 mutex_lock(&ha->optrom_mutex);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001473 rval = qla2x00_optrom_setup(bsg_job, vha, 1);
Chad Dupuis7a8ab9c2014-02-26 04:14:56 -05001474 if (rval) {
1475 mutex_unlock(&ha->optrom_mutex);
Harish Zunjarraof19af162010-10-15 11:27:43 -07001476 return rval;
Chad Dupuis7a8ab9c2014-02-26 04:14:56 -05001477 }
Harish Zunjarraof19af162010-10-15 11:27:43 -07001478
Giridhar Malavalib6d0d9d2012-05-15 14:34:25 -04001479 /* Set the isp82xx_no_md_cap not to capture minidump */
1480 ha->flags.isp82xx_no_md_cap = 1;
1481
Harish Zunjarraof19af162010-10-15 11:27:43 -07001482 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1483 bsg_job->request_payload.sg_cnt, ha->optrom_buffer,
1484 ha->optrom_region_size);
1485
1486 ha->isp_ops->write_optrom(vha, ha->optrom_buffer,
1487 ha->optrom_region_start, ha->optrom_region_size);
1488
1489 bsg_job->reply->result = DID_OK;
1490 vfree(ha->optrom_buffer);
1491 ha->optrom_buffer = NULL;
1492 ha->optrom_state = QLA_SWAITING;
Chad Dupuis7a8ab9c2014-02-26 04:14:56 -05001493 mutex_unlock(&ha->optrom_mutex);
Harish Zunjarraof19af162010-10-15 11:27:43 -07001494 bsg_job->job_done(bsg_job);
1495 return rval;
1496}
1497
1498static int
Joe Carnuccio697a4bc2011-08-16 11:31:52 -07001499qla2x00_update_fru_versions(struct fc_bsg_job *bsg_job)
1500{
1501 struct Scsi_Host *host = bsg_job->shost;
1502 scsi_qla_host_t *vha = shost_priv(host);
1503 struct qla_hw_data *ha = vha->hw;
1504 int rval = 0;
1505 uint8_t bsg[DMA_POOL_SIZE];
1506 struct qla_image_version_list *list = (void *)bsg;
1507 struct qla_image_version *image;
1508 uint32_t count;
1509 dma_addr_t sfp_dma;
1510 void *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
1511 if (!sfp) {
1512 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
1513 EXT_STATUS_NO_MEMORY;
1514 goto done;
1515 }
1516
1517 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1518 bsg_job->request_payload.sg_cnt, list, sizeof(bsg));
1519
1520 image = list->version;
1521 count = list->count;
1522 while (count--) {
1523 memcpy(sfp, &image->field_info, sizeof(image->field_info));
1524 rval = qla2x00_write_sfp(vha, sfp_dma, sfp,
1525 image->field_address.device, image->field_address.offset,
1526 sizeof(image->field_info), image->field_address.option);
1527 if (rval) {
1528 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
1529 EXT_STATUS_MAILBOX;
1530 goto dealloc;
1531 }
1532 image++;
1533 }
1534
1535 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
1536
1537dealloc:
1538 dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
1539
1540done:
1541 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1542 bsg_job->reply->result = DID_OK << 16;
1543 bsg_job->job_done(bsg_job);
1544
1545 return 0;
1546}
1547
1548static int
1549qla2x00_read_fru_status(struct fc_bsg_job *bsg_job)
1550{
1551 struct Scsi_Host *host = bsg_job->shost;
1552 scsi_qla_host_t *vha = shost_priv(host);
1553 struct qla_hw_data *ha = vha->hw;
1554 int rval = 0;
1555 uint8_t bsg[DMA_POOL_SIZE];
1556 struct qla_status_reg *sr = (void *)bsg;
1557 dma_addr_t sfp_dma;
1558 uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
1559 if (!sfp) {
1560 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
1561 EXT_STATUS_NO_MEMORY;
1562 goto done;
1563 }
1564
1565 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1566 bsg_job->request_payload.sg_cnt, sr, sizeof(*sr));
1567
1568 rval = qla2x00_read_sfp(vha, sfp_dma, sfp,
1569 sr->field_address.device, sr->field_address.offset,
1570 sizeof(sr->status_reg), sr->field_address.option);
1571 sr->status_reg = *sfp;
1572
1573 if (rval) {
1574 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
1575 EXT_STATUS_MAILBOX;
1576 goto dealloc;
1577 }
1578
1579 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
1580 bsg_job->reply_payload.sg_cnt, sr, sizeof(*sr));
1581
1582 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
1583
1584dealloc:
1585 dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
1586
1587done:
1588 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1589 bsg_job->reply->reply_payload_rcv_len = sizeof(*sr);
1590 bsg_job->reply->result = DID_OK << 16;
1591 bsg_job->job_done(bsg_job);
1592
1593 return 0;
1594}
1595
1596static int
1597qla2x00_write_fru_status(struct fc_bsg_job *bsg_job)
1598{
1599 struct Scsi_Host *host = bsg_job->shost;
1600 scsi_qla_host_t *vha = shost_priv(host);
1601 struct qla_hw_data *ha = vha->hw;
1602 int rval = 0;
1603 uint8_t bsg[DMA_POOL_SIZE];
1604 struct qla_status_reg *sr = (void *)bsg;
1605 dma_addr_t sfp_dma;
1606 uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
1607 if (!sfp) {
1608 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
1609 EXT_STATUS_NO_MEMORY;
1610 goto done;
1611 }
1612
1613 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1614 bsg_job->request_payload.sg_cnt, sr, sizeof(*sr));
1615
1616 *sfp = sr->status_reg;
1617 rval = qla2x00_write_sfp(vha, sfp_dma, sfp,
1618 sr->field_address.device, sr->field_address.offset,
1619 sizeof(sr->status_reg), sr->field_address.option);
1620
1621 if (rval) {
1622 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
1623 EXT_STATUS_MAILBOX;
1624 goto dealloc;
1625 }
1626
1627 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
1628
1629dealloc:
1630 dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
1631
1632done:
1633 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1634 bsg_job->reply->result = DID_OK << 16;
1635 bsg_job->job_done(bsg_job);
1636
1637 return 0;
1638}
1639
1640static int
Joe Carnuccio9ebb5d92012-08-22 14:20:56 -04001641qla2x00_write_i2c(struct fc_bsg_job *bsg_job)
1642{
1643 struct Scsi_Host *host = bsg_job->shost;
1644 scsi_qla_host_t *vha = shost_priv(host);
1645 struct qla_hw_data *ha = vha->hw;
1646 int rval = 0;
1647 uint8_t bsg[DMA_POOL_SIZE];
1648 struct qla_i2c_access *i2c = (void *)bsg;
1649 dma_addr_t sfp_dma;
1650 uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
1651 if (!sfp) {
1652 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
1653 EXT_STATUS_NO_MEMORY;
1654 goto done;
1655 }
1656
1657 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1658 bsg_job->request_payload.sg_cnt, i2c, sizeof(*i2c));
1659
1660 memcpy(sfp, i2c->buffer, i2c->length);
1661 rval = qla2x00_write_sfp(vha, sfp_dma, sfp,
1662 i2c->device, i2c->offset, i2c->length, i2c->option);
1663
1664 if (rval) {
1665 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
1666 EXT_STATUS_MAILBOX;
1667 goto dealloc;
1668 }
1669
1670 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
1671
1672dealloc:
1673 dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
1674
1675done:
1676 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1677 bsg_job->reply->result = DID_OK << 16;
1678 bsg_job->job_done(bsg_job);
1679
1680 return 0;
1681}
1682
1683static int
1684qla2x00_read_i2c(struct fc_bsg_job *bsg_job)
1685{
1686 struct Scsi_Host *host = bsg_job->shost;
1687 scsi_qla_host_t *vha = shost_priv(host);
1688 struct qla_hw_data *ha = vha->hw;
1689 int rval = 0;
1690 uint8_t bsg[DMA_POOL_SIZE];
1691 struct qla_i2c_access *i2c = (void *)bsg;
1692 dma_addr_t sfp_dma;
1693 uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
1694 if (!sfp) {
1695 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
1696 EXT_STATUS_NO_MEMORY;
1697 goto done;
1698 }
1699
1700 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1701 bsg_job->request_payload.sg_cnt, i2c, sizeof(*i2c));
1702
1703 rval = qla2x00_read_sfp(vha, sfp_dma, sfp,
1704 i2c->device, i2c->offset, i2c->length, i2c->option);
1705
1706 if (rval) {
1707 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
1708 EXT_STATUS_MAILBOX;
1709 goto dealloc;
1710 }
1711
1712 memcpy(i2c->buffer, sfp, i2c->length);
1713 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
1714 bsg_job->reply_payload.sg_cnt, i2c, sizeof(*i2c));
1715
1716 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
1717
1718dealloc:
1719 dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
1720
1721done:
1722 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1723 bsg_job->reply->reply_payload_rcv_len = sizeof(*i2c);
1724 bsg_job->reply->result = DID_OK << 16;
1725 bsg_job->job_done(bsg_job);
1726
1727 return 0;
1728}
1729
1730static int
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04001731qla24xx_process_bidir_cmd(struct fc_bsg_job *bsg_job)
1732{
1733 struct Scsi_Host *host = bsg_job->shost;
1734 scsi_qla_host_t *vha = shost_priv(host);
1735 struct qla_hw_data *ha = vha->hw;
1736 uint16_t thread_id;
1737 uint32_t rval = EXT_STATUS_OK;
1738 uint16_t req_sg_cnt = 0;
1739 uint16_t rsp_sg_cnt = 0;
1740 uint16_t nextlid = 0;
1741 uint32_t tot_dsds;
1742 srb_t *sp = NULL;
1743 uint32_t req_data_len = 0;
1744 uint32_t rsp_data_len = 0;
1745
1746 /* Check the type of the adapter */
1747 if (!IS_BIDI_CAPABLE(ha)) {
1748 ql_log(ql_log_warn, vha, 0x70a0,
1749 "This adapter is not supported\n");
1750 rval = EXT_STATUS_NOT_SUPPORTED;
1751 goto done;
1752 }
1753
1754 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
1755 test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
1756 test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
1757 rval = EXT_STATUS_BUSY;
1758 goto done;
1759 }
1760
1761 /* Check if host is online */
1762 if (!vha->flags.online) {
1763 ql_log(ql_log_warn, vha, 0x70a1,
1764 "Host is not online\n");
1765 rval = EXT_STATUS_DEVICE_OFFLINE;
1766 goto done;
1767 }
1768
1769 /* Check if cable is plugged in or not */
1770 if (vha->device_flags & DFLG_NO_CABLE) {
1771 ql_log(ql_log_warn, vha, 0x70a2,
1772 "Cable is unplugged...\n");
1773 rval = EXT_STATUS_INVALID_CFG;
1774 goto done;
1775 }
1776
1777 /* Check if the switch is connected or not */
1778 if (ha->current_topology != ISP_CFG_F) {
1779 ql_log(ql_log_warn, vha, 0x70a3,
1780 "Host is not connected to the switch\n");
1781 rval = EXT_STATUS_INVALID_CFG;
1782 goto done;
1783 }
1784
1785 /* Check if operating mode is P2P */
1786 if (ha->operating_mode != P2P) {
1787 ql_log(ql_log_warn, vha, 0x70a4,
1788 "Host is operating mode is not P2p\n");
1789 rval = EXT_STATUS_INVALID_CFG;
1790 goto done;
1791 }
1792
1793 thread_id = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
1794
1795 mutex_lock(&ha->selflogin_lock);
1796 if (vha->self_login_loop_id == 0) {
1797 /* Initialize all required fields of fcport */
1798 vha->bidir_fcport.vha = vha;
1799 vha->bidir_fcport.d_id.b.al_pa = vha->d_id.b.al_pa;
1800 vha->bidir_fcport.d_id.b.area = vha->d_id.b.area;
1801 vha->bidir_fcport.d_id.b.domain = vha->d_id.b.domain;
1802 vha->bidir_fcport.loop_id = vha->loop_id;
1803
1804 if (qla2x00_fabric_login(vha, &(vha->bidir_fcport), &nextlid)) {
1805 ql_log(ql_log_warn, vha, 0x70a7,
1806 "Failed to login port %06X for bidirectional IOCB\n",
1807 vha->bidir_fcport.d_id.b24);
1808 mutex_unlock(&ha->selflogin_lock);
1809 rval = EXT_STATUS_MAILBOX;
1810 goto done;
1811 }
1812 vha->self_login_loop_id = nextlid - 1;
1813
1814 }
1815 /* Assign the self login loop id to fcport */
1816 mutex_unlock(&ha->selflogin_lock);
1817
1818 vha->bidir_fcport.loop_id = vha->self_login_loop_id;
1819
1820 req_sg_cnt = dma_map_sg(&ha->pdev->dev,
1821 bsg_job->request_payload.sg_list,
1822 bsg_job->request_payload.sg_cnt,
1823 DMA_TO_DEVICE);
1824
1825 if (!req_sg_cnt) {
1826 rval = EXT_STATUS_NO_MEMORY;
1827 goto done;
1828 }
1829
1830 rsp_sg_cnt = dma_map_sg(&ha->pdev->dev,
1831 bsg_job->reply_payload.sg_list, bsg_job->reply_payload.sg_cnt,
1832 DMA_FROM_DEVICE);
1833
1834 if (!rsp_sg_cnt) {
1835 rval = EXT_STATUS_NO_MEMORY;
1836 goto done_unmap_req_sg;
1837 }
1838
1839 if ((req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
1840 (rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) {
1841 ql_dbg(ql_dbg_user, vha, 0x70a9,
1842 "Dma mapping resulted in different sg counts "
1843 "[request_sg_cnt: %x dma_request_sg_cnt: %x reply_sg_cnt: "
1844 "%x dma_reply_sg_cnt: %x]\n",
1845 bsg_job->request_payload.sg_cnt, req_sg_cnt,
1846 bsg_job->reply_payload.sg_cnt, rsp_sg_cnt);
1847 rval = EXT_STATUS_NO_MEMORY;
1848 goto done_unmap_sg;
1849 }
1850
1851 if (req_data_len != rsp_data_len) {
1852 rval = EXT_STATUS_BUSY;
1853 ql_log(ql_log_warn, vha, 0x70aa,
1854 "req_data_len != rsp_data_len\n");
1855 goto done_unmap_sg;
1856 }
1857
1858 req_data_len = bsg_job->request_payload.payload_len;
1859 rsp_data_len = bsg_job->reply_payload.payload_len;
1860
1861
1862 /* Alloc SRB structure */
1863 sp = qla2x00_get_sp(vha, &(vha->bidir_fcport), GFP_KERNEL);
1864 if (!sp) {
1865 ql_dbg(ql_dbg_user, vha, 0x70ac,
1866 "Alloc SRB structure failed\n");
1867 rval = EXT_STATUS_NO_MEMORY;
1868 goto done_unmap_sg;
1869 }
1870
1871 /*Populate srb->ctx with bidir ctx*/
1872 sp->u.bsg_job = bsg_job;
1873 sp->free = qla2x00_bsg_sp_free;
1874 sp->type = SRB_BIDI_CMD;
1875 sp->done = qla2x00_bsg_job_done;
1876
1877 /* Add the read and write sg count */
1878 tot_dsds = rsp_sg_cnt + req_sg_cnt;
1879
1880 rval = qla2x00_start_bidir(sp, vha, tot_dsds);
1881 if (rval != EXT_STATUS_OK)
1882 goto done_free_srb;
1883 /* the bsg request will be completed in the interrupt handler */
1884 return rval;
1885
1886done_free_srb:
1887 mempool_free(sp, ha->srb_mempool);
1888done_unmap_sg:
1889 dma_unmap_sg(&ha->pdev->dev,
1890 bsg_job->reply_payload.sg_list,
1891 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
1892done_unmap_req_sg:
1893 dma_unmap_sg(&ha->pdev->dev,
1894 bsg_job->request_payload.sg_list,
1895 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
1896done:
1897
1898 /* Return an error vendor specific response
1899 * and complete the bsg request
1900 */
1901 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = rval;
1902 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1903 bsg_job->reply->reply_payload_rcv_len = 0;
1904 bsg_job->reply->result = (DID_OK) << 16;
1905 bsg_job->job_done(bsg_job);
Joe Perches9e03aa22013-09-03 13:45:58 -07001906 /* Always return success, vendor rsp carries correct status */
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04001907 return 0;
1908}
1909
1910static int
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001911qlafx00_mgmt_cmd(struct fc_bsg_job *bsg_job)
1912{
1913 struct Scsi_Host *host = bsg_job->shost;
1914 scsi_qla_host_t *vha = shost_priv(host);
1915 struct qla_hw_data *ha = vha->hw;
1916 int rval = (DRIVER_ERROR << 16);
1917 struct qla_mt_iocb_rqst_fx00 *piocb_rqst;
1918 srb_t *sp;
1919 int req_sg_cnt = 0, rsp_sg_cnt = 0;
1920 struct fc_port *fcport;
1921 char *type = "FC_BSG_HST_FX_MGMT";
1922
1923 /* Copy the IOCB specific information */
1924 piocb_rqst = (struct qla_mt_iocb_rqst_fx00 *)
1925 &bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
1926
1927 /* Dump the vendor information */
1928 ql_dump_buffer(ql_dbg_user + ql_dbg_verbose , vha, 0x70cf,
1929 (uint8_t *)piocb_rqst, sizeof(struct qla_mt_iocb_rqst_fx00));
1930
1931 if (!vha->flags.online) {
1932 ql_log(ql_log_warn, vha, 0x70d0,
1933 "Host is not online.\n");
1934 rval = -EIO;
1935 goto done;
1936 }
1937
1938 if (piocb_rqst->flags & SRB_FXDISC_REQ_DMA_VALID) {
1939 req_sg_cnt = dma_map_sg(&ha->pdev->dev,
1940 bsg_job->request_payload.sg_list,
1941 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
1942 if (!req_sg_cnt) {
1943 ql_log(ql_log_warn, vha, 0x70c7,
1944 "dma_map_sg return %d for request\n", req_sg_cnt);
1945 rval = -ENOMEM;
1946 goto done;
1947 }
1948 }
1949
1950 if (piocb_rqst->flags & SRB_FXDISC_RESP_DMA_VALID) {
1951 rsp_sg_cnt = dma_map_sg(&ha->pdev->dev,
1952 bsg_job->reply_payload.sg_list,
1953 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
1954 if (!rsp_sg_cnt) {
1955 ql_log(ql_log_warn, vha, 0x70c8,
1956 "dma_map_sg return %d for reply\n", rsp_sg_cnt);
1957 rval = -ENOMEM;
1958 goto done_unmap_req_sg;
1959 }
1960 }
1961
1962 ql_dbg(ql_dbg_user, vha, 0x70c9,
1963 "request_sg_cnt: %x dma_request_sg_cnt: %x reply_sg_cnt:%x "
1964 "dma_reply_sg_cnt: %x\n", bsg_job->request_payload.sg_cnt,
1965 req_sg_cnt, bsg_job->reply_payload.sg_cnt, rsp_sg_cnt);
1966
1967 /* Allocate a dummy fcport structure, since functions preparing the
1968 * IOCB and mailbox command retrieves port specific information
1969 * from fcport structure. For Host based ELS commands there will be
1970 * no fcport structure allocated
1971 */
1972 fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
1973 if (!fcport) {
1974 ql_log(ql_log_warn, vha, 0x70ca,
1975 "Failed to allocate fcport.\n");
1976 rval = -ENOMEM;
1977 goto done_unmap_rsp_sg;
1978 }
1979
1980 /* Alloc SRB structure */
1981 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1982 if (!sp) {
1983 ql_log(ql_log_warn, vha, 0x70cb,
1984 "qla2x00_get_sp failed.\n");
1985 rval = -ENOMEM;
1986 goto done_free_fcport;
1987 }
1988
1989 /* Initialize all required fields of fcport */
1990 fcport->vha = vha;
1991 fcport->loop_id = piocb_rqst->dataword;
1992
1993 sp->type = SRB_FXIOCB_BCMD;
1994 sp->name = "bsg_fx_mgmt";
1995 sp->iocbs = qla24xx_calc_ct_iocbs(req_sg_cnt + rsp_sg_cnt);
1996 sp->u.bsg_job = bsg_job;
1997 sp->free = qla2x00_bsg_sp_free;
1998 sp->done = qla2x00_bsg_job_done;
1999
2000 ql_dbg(ql_dbg_user, vha, 0x70cc,
2001 "bsg rqst type: %s fx_mgmt_type: %x id=%x\n",
2002 type, piocb_rqst->func_type, fcport->loop_id);
2003
2004 rval = qla2x00_start_sp(sp);
2005 if (rval != QLA_SUCCESS) {
2006 ql_log(ql_log_warn, vha, 0x70cd,
2007 "qla2x00_start_sp failed=%d.\n", rval);
2008 mempool_free(sp, ha->srb_mempool);
2009 rval = -EIO;
2010 goto done_free_fcport;
2011 }
2012 return rval;
2013
2014done_free_fcport:
2015 kfree(fcport);
2016
2017done_unmap_rsp_sg:
2018 if (piocb_rqst->flags & SRB_FXDISC_RESP_DMA_VALID)
2019 dma_unmap_sg(&ha->pdev->dev,
2020 bsg_job->reply_payload.sg_list,
2021 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
2022done_unmap_req_sg:
2023 if (piocb_rqst->flags & SRB_FXDISC_REQ_DMA_VALID)
2024 dma_unmap_sg(&ha->pdev->dev,
2025 bsg_job->request_payload.sg_list,
2026 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
2027
2028done:
2029 return rval;
2030}
2031
2032static int
Joe Carnucciodb64e932013-10-30 03:38:18 -04002033qla26xx_serdes_op(struct fc_bsg_job *bsg_job)
2034{
2035 struct Scsi_Host *host = bsg_job->shost;
2036 scsi_qla_host_t *vha = shost_priv(host);
2037 int rval = 0;
2038 struct qla_serdes_reg sr;
2039
2040 memset(&sr, 0, sizeof(sr));
2041
2042 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
2043 bsg_job->request_payload.sg_cnt, &sr, sizeof(sr));
2044
2045 switch (sr.cmd) {
2046 case INT_SC_SERDES_WRITE_REG:
2047 rval = qla2x00_write_serdes_word(vha, sr.addr, sr.val);
2048 bsg_job->reply->reply_payload_rcv_len = 0;
2049 break;
2050 case INT_SC_SERDES_READ_REG:
2051 rval = qla2x00_read_serdes_word(vha, sr.addr, &sr.val);
2052 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
2053 bsg_job->reply_payload.sg_cnt, &sr, sizeof(sr));
2054 bsg_job->reply->reply_payload_rcv_len = sizeof(sr);
2055 break;
2056 default:
Joe Carnuccioe8887c52014-04-11 16:54:17 -04002057 ql_dbg(ql_dbg_user, vha, 0x708c,
Joe Carnucciodb64e932013-10-30 03:38:18 -04002058 "Unknown serdes cmd %x.\n", sr.cmd);
Joe Carnuccioe8887c52014-04-11 16:54:17 -04002059 rval = -EINVAL;
2060 break;
2061 }
2062
2063 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
2064 rval ? EXT_STATUS_MAILBOX : 0;
2065
2066 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
2067 bsg_job->reply->result = DID_OK << 16;
2068 bsg_job->job_done(bsg_job);
2069 return 0;
2070}
2071
2072static int
2073qla8044_serdes_op(struct fc_bsg_job *bsg_job)
2074{
2075 struct Scsi_Host *host = bsg_job->shost;
2076 scsi_qla_host_t *vha = shost_priv(host);
2077 int rval = 0;
2078 struct qla_serdes_reg_ex sr;
2079
2080 memset(&sr, 0, sizeof(sr));
2081
2082 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
2083 bsg_job->request_payload.sg_cnt, &sr, sizeof(sr));
2084
2085 switch (sr.cmd) {
2086 case INT_SC_SERDES_WRITE_REG:
2087 rval = qla8044_write_serdes_word(vha, sr.addr, sr.val);
2088 bsg_job->reply->reply_payload_rcv_len = 0;
2089 break;
2090 case INT_SC_SERDES_READ_REG:
2091 rval = qla8044_read_serdes_word(vha, sr.addr, &sr.val);
2092 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
2093 bsg_job->reply_payload.sg_cnt, &sr, sizeof(sr));
2094 bsg_job->reply->reply_payload_rcv_len = sizeof(sr);
2095 break;
2096 default:
2097 ql_dbg(ql_dbg_user, vha, 0x70cf,
2098 "Unknown serdes cmd %x.\n", sr.cmd);
2099 rval = -EINVAL;
Joe Carnucciodb64e932013-10-30 03:38:18 -04002100 break;
2101 }
2102
2103 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
2104 rval ? EXT_STATUS_MAILBOX : 0;
2105
2106 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
2107 bsg_job->reply->result = DID_OK << 16;
2108 bsg_job->job_done(bsg_job);
2109 return 0;
2110}
2111
2112static int
Giridhar Malavali6e980162010-03-19 17:03:58 -07002113qla2x00_process_vendor_specific(struct fc_bsg_job *bsg_job)
2114{
2115 switch (bsg_job->request->rqst_data.h_vendor.vendor_cmd[0]) {
2116 case QL_VND_LOOPBACK:
2117 return qla2x00_process_loopback(bsg_job);
2118
2119 case QL_VND_A84_RESET:
2120 return qla84xx_reset(bsg_job);
2121
2122 case QL_VND_A84_UPDATE_FW:
2123 return qla84xx_updatefw(bsg_job);
2124
2125 case QL_VND_A84_MGMT_CMD:
2126 return qla84xx_mgmt_cmd(bsg_job);
2127
2128 case QL_VND_IIDMA:
2129 return qla24xx_iidma(bsg_job);
2130
Sarang Radke09ff7012010-03-19 17:03:59 -07002131 case QL_VND_FCP_PRIO_CFG_CMD:
2132 return qla24xx_proc_fcp_prio_cfg_cmd(bsg_job);
2133
Harish Zunjarraof19af162010-10-15 11:27:43 -07002134 case QL_VND_READ_FLASH:
2135 return qla2x00_read_optrom(bsg_job);
2136
2137 case QL_VND_UPDATE_FLASH:
2138 return qla2x00_update_optrom(bsg_job);
2139
Joe Carnuccio697a4bc2011-08-16 11:31:52 -07002140 case QL_VND_SET_FRU_VERSION:
2141 return qla2x00_update_fru_versions(bsg_job);
2142
2143 case QL_VND_READ_FRU_STATUS:
2144 return qla2x00_read_fru_status(bsg_job);
2145
2146 case QL_VND_WRITE_FRU_STATUS:
2147 return qla2x00_write_fru_status(bsg_job);
2148
Joe Carnuccio9ebb5d92012-08-22 14:20:56 -04002149 case QL_VND_WRITE_I2C:
2150 return qla2x00_write_i2c(bsg_job);
2151
2152 case QL_VND_READ_I2C:
2153 return qla2x00_read_i2c(bsg_job);
2154
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04002155 case QL_VND_DIAG_IO_CMD:
2156 return qla24xx_process_bidir_cmd(bsg_job);
2157
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002158 case QL_VND_FX00_MGMT_CMD:
2159 return qlafx00_mgmt_cmd(bsg_job);
Joe Carnucciodb64e932013-10-30 03:38:18 -04002160
2161 case QL_VND_SERDES_OP:
2162 return qla26xx_serdes_op(bsg_job);
2163
Joe Carnuccioe8887c52014-04-11 16:54:17 -04002164 case QL_VND_SERDES_OP_EX:
2165 return qla8044_serdes_op(bsg_job);
2166
Giridhar Malavali6e980162010-03-19 17:03:58 -07002167 default:
Giridhar Malavali6e980162010-03-19 17:03:58 -07002168 return -ENOSYS;
2169 }
2170}
2171
2172int
2173qla24xx_bsg_request(struct fc_bsg_job *bsg_job)
2174{
2175 int ret = -EINVAL;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002176 struct fc_rport *rport;
2177 fc_port_t *fcport = NULL;
2178 struct Scsi_Host *host;
2179 scsi_qla_host_t *vha;
2180
Andrew Vasquezb7bfbe12012-02-09 11:15:44 -08002181 /* In case no data transferred. */
2182 bsg_job->reply->reply_payload_rcv_len = 0;
2183
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002184 if (bsg_job->request->msgcode == FC_BSG_RPT_ELS) {
2185 rport = bsg_job->rport;
2186 fcport = *(fc_port_t **) rport->dd_data;
2187 host = rport_to_shost(rport);
2188 vha = shost_priv(host);
2189 } else {
2190 host = bsg_job->shost;
2191 vha = shost_priv(host);
2192 }
2193
Andrew Vasquezd051a5aa2012-02-09 11:14:05 -08002194 if (qla2x00_reset_active(vha)) {
2195 ql_dbg(ql_dbg_user, vha, 0x709f,
2196 "BSG: ISP abort active/needed -- cmd=%d.\n",
2197 bsg_job->request->msgcode);
Andrew Vasquezd051a5aa2012-02-09 11:14:05 -08002198 return -EBUSY;
2199 }
2200
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002201 ql_dbg(ql_dbg_user, vha, 0x7000,
Chad Dupuiscfb09192011-11-18 09:03:07 -08002202 "Entered %s msgcode=0x%x.\n", __func__, bsg_job->request->msgcode);
Giridhar Malavali6e980162010-03-19 17:03:58 -07002203
2204 switch (bsg_job->request->msgcode) {
2205 case FC_BSG_RPT_ELS:
2206 case FC_BSG_HST_ELS_NOLOGIN:
2207 ret = qla2x00_process_els(bsg_job);
2208 break;
2209 case FC_BSG_HST_CT:
2210 ret = qla2x00_process_ct(bsg_job);
2211 break;
2212 case FC_BSG_HST_VENDOR:
2213 ret = qla2x00_process_vendor_specific(bsg_job);
2214 break;
2215 case FC_BSG_HST_ADD_RPORT:
2216 case FC_BSG_HST_DEL_RPORT:
2217 case FC_BSG_RPT_CT:
2218 default:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002219 ql_log(ql_log_warn, vha, 0x705a, "Unsupported BSG request.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -07002220 break;
Andrew Vasquez6c452a42010-03-19 17:04:02 -07002221 }
Giridhar Malavali6e980162010-03-19 17:03:58 -07002222 return ret;
2223}
2224
2225int
2226qla24xx_bsg_timeout(struct fc_bsg_job *bsg_job)
2227{
2228 scsi_qla_host_t *vha = shost_priv(bsg_job->shost);
2229 struct qla_hw_data *ha = vha->hw;
2230 srb_t *sp;
2231 int cnt, que;
2232 unsigned long flags;
2233 struct req_que *req;
Giridhar Malavali6e980162010-03-19 17:03:58 -07002234
2235 /* find the bsg job from the active list of commands */
2236 spin_lock_irqsave(&ha->hardware_lock, flags);
2237 for (que = 0; que < ha->max_req_queues; que++) {
2238 req = ha->req_q_map[que];
2239 if (!req)
2240 continue;
2241
Chad Dupuis8d93f552013-01-30 03:34:37 -05002242 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) {
Giridhar Malavali6e980162010-03-19 17:03:58 -07002243 sp = req->outstanding_cmds[cnt];
Giridhar Malavali6e980162010-03-19 17:03:58 -07002244 if (sp) {
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002245 if (((sp->type == SRB_CT_CMD) ||
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002246 (sp->type == SRB_ELS_CMD_HST) ||
2247 (sp->type == SRB_FXIOCB_BCMD))
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08002248 && (sp->u.bsg_job == bsg_job)) {
Giridhar Malavali8edf3ed2013-06-25 11:27:17 -04002249 req->outstanding_cmds[cnt] = NULL;
Giridhar Malavali900a36e2010-12-21 16:00:26 -08002250 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Giridhar Malavali6e980162010-03-19 17:03:58 -07002251 if (ha->isp_ops->abort_command(sp)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002252 ql_log(ql_log_warn, vha, 0x7089,
2253 "mbx abort_command "
2254 "failed.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -07002255 bsg_job->req->errors =
2256 bsg_job->reply->result = -EIO;
2257 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002258 ql_dbg(ql_dbg_user, vha, 0x708a,
2259 "mbx abort_command "
2260 "success.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -07002261 bsg_job->req->errors =
2262 bsg_job->reply->result = 0;
2263 }
Giridhar Malavali900a36e2010-12-21 16:00:26 -08002264 spin_lock_irqsave(&ha->hardware_lock, flags);
Giridhar Malavali6e980162010-03-19 17:03:58 -07002265 goto done;
2266 }
2267 }
2268 }
2269 }
2270 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002271 ql_log(ql_log_info, vha, 0x708b, "SRB not found to abort.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -07002272 bsg_job->req->errors = bsg_job->reply->result = -ENXIO;
2273 return 0;
2274
2275done:
2276 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Giridhar Malavali8edf3ed2013-06-25 11:27:17 -04002277 sp->free(vha, sp);
Giridhar Malavali6e980162010-03-19 17:03:58 -07002278 return 0;
2279}