blob: 747f440b1a93208ab9e5f5f6dc2683aa0cbd438a [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 Malavali6e980162010-03-19 17:03:58 -070033
Giridhar Malavali9ba56b92012-02-09 11:15:36 -080034 dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
35 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
Giridhar Malavali6e980162010-03-19 17:03:58 -070036
Giridhar Malavali9ba56b92012-02-09 11:15:36 -080037 dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
38 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
39
40 if (sp->type == SRB_CT_CMD ||
41 sp->type == SRB_ELS_CMD_HST)
42 kfree(sp->fcport);
Chad Dupuisb00ee7d2013-02-08 01:57:50 -050043 qla2x00_rel_sp(vha, sp);
Giridhar Malavali6e980162010-03-19 17:03:58 -070044}
45
Sarang Radke09ff7012010-03-19 17:03:59 -070046int
Saurav Kashyap7c3df132011-07-14 12:00:13 -070047qla24xx_fcp_prio_cfg_valid(scsi_qla_host_t *vha,
48 struct qla_fcp_prio_cfg *pri_cfg, uint8_t flag)
Sarang Radke09ff7012010-03-19 17:03:59 -070049{
50 int i, ret, num_valid;
51 uint8_t *bcode;
52 struct qla_fcp_prio_entry *pri_entry;
Madhuranath Iyengar2f0f3f42010-07-23 15:28:24 +050053 uint32_t *bcode_val_ptr, bcode_val;
Sarang Radke09ff7012010-03-19 17:03:59 -070054
55 ret = 1;
56 num_valid = 0;
57 bcode = (uint8_t *)pri_cfg;
Madhuranath Iyengar2f0f3f42010-07-23 15:28:24 +050058 bcode_val_ptr = (uint32_t *)pri_cfg;
59 bcode_val = (uint32_t)(*bcode_val_ptr);
Sarang Radke09ff7012010-03-19 17:03:59 -070060
Madhuranath Iyengar2f0f3f42010-07-23 15:28:24 +050061 if (bcode_val == 0xFFFFFFFF) {
62 /* No FCP Priority config data in flash */
Saurav Kashyap7c3df132011-07-14 12:00:13 -070063 ql_dbg(ql_dbg_user, vha, 0x7051,
64 "No FCP Priority config data.\n");
Madhuranath Iyengar2f0f3f42010-07-23 15:28:24 +050065 return 0;
66 }
67
68 if (bcode[0] != 'H' || bcode[1] != 'Q' || bcode[2] != 'O' ||
69 bcode[3] != 'S') {
70 /* Invalid FCP priority data header*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -070071 ql_dbg(ql_dbg_user, vha, 0x7052,
72 "Invalid FCP Priority data header. bcode=0x%x.\n",
73 bcode_val);
Sarang Radke09ff7012010-03-19 17:03:59 -070074 return 0;
75 }
76 if (flag != 1)
77 return ret;
78
79 pri_entry = &pri_cfg->entry[0];
80 for (i = 0; i < pri_cfg->num_entries; i++) {
81 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
82 num_valid++;
83 pri_entry++;
84 }
85
Madhuranath Iyengar2f0f3f42010-07-23 15:28:24 +050086 if (num_valid == 0) {
87 /* No valid FCP priority data entries */
Saurav Kashyap7c3df132011-07-14 12:00:13 -070088 ql_dbg(ql_dbg_user, vha, 0x7053,
89 "No valid FCP Priority data entries.\n");
Sarang Radke09ff7012010-03-19 17:03:59 -070090 ret = 0;
Madhuranath Iyengar2f0f3f42010-07-23 15:28:24 +050091 } else {
92 /* FCP priority data is valid */
Saurav Kashyap7c3df132011-07-14 12:00:13 -070093 ql_dbg(ql_dbg_user, vha, 0x7054,
94 "Valid FCP priority data. num entries = %d.\n",
95 num_valid);
Madhuranath Iyengar2f0f3f42010-07-23 15:28:24 +050096 }
Sarang Radke09ff7012010-03-19 17:03:59 -070097
98 return ret;
99}
100
101static int
102qla24xx_proc_fcp_prio_cfg_cmd(struct fc_bsg_job *bsg_job)
103{
104 struct Scsi_Host *host = bsg_job->shost;
105 scsi_qla_host_t *vha = shost_priv(host);
106 struct qla_hw_data *ha = vha->hw;
107 int ret = 0;
108 uint32_t len;
109 uint32_t oper;
110
Saurav Kashyapa00f6292011-11-18 09:03:19 -0800111 if (!(IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha) || IS_QLA82XX(ha))) {
Madhuranath Iyengar2f0f3f42010-07-23 15:28:24 +0500112 ret = -EINVAL;
113 goto exit_fcp_prio_cfg;
114 }
115
Sarang Radke09ff7012010-03-19 17:03:59 -0700116 /* Get the sub command */
117 oper = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
118
119 /* Only set config is allowed if config memory is not allocated */
120 if (!ha->fcp_prio_cfg && (oper != QLFC_FCP_PRIO_SET_CONFIG)) {
121 ret = -EINVAL;
122 goto exit_fcp_prio_cfg;
123 }
124 switch (oper) {
125 case QLFC_FCP_PRIO_DISABLE:
126 if (ha->flags.fcp_prio_enabled) {
127 ha->flags.fcp_prio_enabled = 0;
128 ha->fcp_prio_cfg->attributes &=
129 ~FCP_PRIO_ATTR_ENABLE;
130 qla24xx_update_all_fcp_prio(vha);
131 bsg_job->reply->result = DID_OK;
132 } else {
133 ret = -EINVAL;
134 bsg_job->reply->result = (DID_ERROR << 16);
135 goto exit_fcp_prio_cfg;
136 }
137 break;
138
139 case QLFC_FCP_PRIO_ENABLE:
140 if (!ha->flags.fcp_prio_enabled) {
141 if (ha->fcp_prio_cfg) {
142 ha->flags.fcp_prio_enabled = 1;
143 ha->fcp_prio_cfg->attributes |=
144 FCP_PRIO_ATTR_ENABLE;
145 qla24xx_update_all_fcp_prio(vha);
146 bsg_job->reply->result = DID_OK;
147 } else {
148 ret = -EINVAL;
149 bsg_job->reply->result = (DID_ERROR << 16);
150 goto exit_fcp_prio_cfg;
151 }
152 }
153 break;
154
155 case QLFC_FCP_PRIO_GET_CONFIG:
156 len = bsg_job->reply_payload.payload_len;
157 if (!len || len > FCP_PRIO_CFG_SIZE) {
158 ret = -EINVAL;
159 bsg_job->reply->result = (DID_ERROR << 16);
160 goto exit_fcp_prio_cfg;
161 }
162
163 bsg_job->reply->result = DID_OK;
164 bsg_job->reply->reply_payload_rcv_len =
165 sg_copy_from_buffer(
166 bsg_job->reply_payload.sg_list,
167 bsg_job->reply_payload.sg_cnt, ha->fcp_prio_cfg,
168 len);
169
170 break;
171
172 case QLFC_FCP_PRIO_SET_CONFIG:
173 len = bsg_job->request_payload.payload_len;
174 if (!len || len > FCP_PRIO_CFG_SIZE) {
175 bsg_job->reply->result = (DID_ERROR << 16);
176 ret = -EINVAL;
177 goto exit_fcp_prio_cfg;
178 }
179
180 if (!ha->fcp_prio_cfg) {
181 ha->fcp_prio_cfg = vmalloc(FCP_PRIO_CFG_SIZE);
182 if (!ha->fcp_prio_cfg) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700183 ql_log(ql_log_warn, vha, 0x7050,
184 "Unable to allocate memory for fcp prio "
185 "config data (%x).\n", FCP_PRIO_CFG_SIZE);
Sarang Radke09ff7012010-03-19 17:03:59 -0700186 bsg_job->reply->result = (DID_ERROR << 16);
187 ret = -ENOMEM;
188 goto exit_fcp_prio_cfg;
189 }
190 }
191
192 memset(ha->fcp_prio_cfg, 0, FCP_PRIO_CFG_SIZE);
193 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
194 bsg_job->request_payload.sg_cnt, ha->fcp_prio_cfg,
195 FCP_PRIO_CFG_SIZE);
196
197 /* validate fcp priority data */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700198
199 if (!qla24xx_fcp_prio_cfg_valid(vha,
200 (struct qla_fcp_prio_cfg *) ha->fcp_prio_cfg, 1)) {
Sarang Radke09ff7012010-03-19 17:03:59 -0700201 bsg_job->reply->result = (DID_ERROR << 16);
202 ret = -EINVAL;
203 /* If buffer was invalidatic int
204 * fcp_prio_cfg is of no use
205 */
206 vfree(ha->fcp_prio_cfg);
207 ha->fcp_prio_cfg = NULL;
208 goto exit_fcp_prio_cfg;
209 }
210
211 ha->flags.fcp_prio_enabled = 0;
212 if (ha->fcp_prio_cfg->attributes & FCP_PRIO_ATTR_ENABLE)
213 ha->flags.fcp_prio_enabled = 1;
214 qla24xx_update_all_fcp_prio(vha);
215 bsg_job->reply->result = DID_OK;
216 break;
217 default:
218 ret = -EINVAL;
219 break;
220 }
221exit_fcp_prio_cfg:
Armen Baloyan63ea9232012-11-21 02:39:53 -0500222 if (!ret)
223 bsg_job->job_done(bsg_job);
Sarang Radke09ff7012010-03-19 17:03:59 -0700224 return ret;
225}
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800226
Giridhar Malavali6e980162010-03-19 17:03:58 -0700227static int
228qla2x00_process_els(struct fc_bsg_job *bsg_job)
229{
230 struct fc_rport *rport;
Harish Zunjarrao08f71e02010-07-23 15:28:33 +0500231 fc_port_t *fcport = NULL;
Giridhar Malavali6e980162010-03-19 17:03:58 -0700232 struct Scsi_Host *host;
233 scsi_qla_host_t *vha;
234 struct qla_hw_data *ha;
235 srb_t *sp;
236 const char *type;
237 int req_sg_cnt, rsp_sg_cnt;
238 int rval = (DRIVER_ERROR << 16);
239 uint16_t nextlid = 0;
Giridhar Malavali6e980162010-03-19 17:03:58 -0700240
Harish Zunjarrao08f71e02010-07-23 15:28:33 +0500241 if (bsg_job->request->msgcode == FC_BSG_RPT_ELS) {
242 rport = bsg_job->rport;
243 fcport = *(fc_port_t **) rport->dd_data;
244 host = rport_to_shost(rport);
245 vha = shost_priv(host);
246 ha = vha->hw;
247 type = "FC_BSG_RPT_ELS";
248 } else {
249 host = bsg_job->shost;
250 vha = shost_priv(host);
251 ha = vha->hw;
252 type = "FC_BSG_HST_ELS_NOLOGIN";
253 }
254
255 /* pass through is supported only for ISP 4Gb or higher */
256 if (!IS_FWI2_CAPABLE(ha)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700257 ql_dbg(ql_dbg_user, vha, 0x7001,
258 "ELS passthru not supported for ISP23xx based adapters.\n");
Harish Zunjarrao08f71e02010-07-23 15:28:33 +0500259 rval = -EPERM;
260 goto done;
261 }
262
Giridhar Malavali6e980162010-03-19 17:03:58 -0700263 /* Multiple SG's are not supported for ELS requests */
264 if (bsg_job->request_payload.sg_cnt > 1 ||
265 bsg_job->reply_payload.sg_cnt > 1) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700266 ql_dbg(ql_dbg_user, vha, 0x7002,
267 "Multiple SG's are not suppored for ELS requests, "
268 "request_sg_cnt=%x reply_sg_cnt=%x.\n",
269 bsg_job->request_payload.sg_cnt,
270 bsg_job->reply_payload.sg_cnt);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700271 rval = -EPERM;
272 goto done;
273 }
274
275 /* ELS request for rport */
276 if (bsg_job->request->msgcode == FC_BSG_RPT_ELS) {
Giridhar Malavali6e980162010-03-19 17:03:58 -0700277 /* make sure the rport is logged in,
278 * if not perform fabric login
279 */
280 if (qla2x00_fabric_login(vha, fcport, &nextlid)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700281 ql_dbg(ql_dbg_user, vha, 0x7003,
282 "Failed to login port %06X for ELS passthru.\n",
283 fcport->d_id.b24);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700284 rval = -EIO;
285 goto done;
286 }
287 } else {
Giridhar Malavali6e980162010-03-19 17:03:58 -0700288 /* Allocate a dummy fcport structure, since functions
289 * preparing the IOCB and mailbox command retrieves port
290 * specific information from fcport structure. For Host based
291 * ELS commands there will be no fcport structure allocated
292 */
293 fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
294 if (!fcport) {
295 rval = -ENOMEM;
296 goto done;
297 }
298
299 /* Initialize all required fields of fcport */
300 fcport->vha = vha;
Giridhar Malavali6e980162010-03-19 17:03:58 -0700301 fcport->d_id.b.al_pa =
302 bsg_job->request->rqst_data.h_els.port_id[0];
303 fcport->d_id.b.area =
304 bsg_job->request->rqst_data.h_els.port_id[1];
305 fcport->d_id.b.domain =
306 bsg_job->request->rqst_data.h_els.port_id[2];
307 fcport->loop_id =
308 (fcport->d_id.b.al_pa == 0xFD) ?
309 NPH_FABRIC_CONTROLLER : NPH_F_PORT;
310 }
311
312 if (!vha->flags.online) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700313 ql_log(ql_log_warn, vha, 0x7005, "Host not online.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -0700314 rval = -EIO;
315 goto done;
316 }
317
318 req_sg_cnt =
319 dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
320 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
321 if (!req_sg_cnt) {
322 rval = -ENOMEM;
323 goto done_free_fcport;
324 }
Andrew Vasquez6c452a42010-03-19 17:04:02 -0700325
326 rsp_sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
327 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700328 if (!rsp_sg_cnt) {
329 rval = -ENOMEM;
330 goto done_free_fcport;
331 }
332
333 if ((req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
Andrew Vasquez6c452a42010-03-19 17:04:02 -0700334 (rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700335 ql_log(ql_log_warn, vha, 0x7008,
336 "dma mapping resulted in different sg counts, "
337 "request_sg_cnt: %x dma_request_sg_cnt:%x reply_sg_cnt:%x "
338 "dma_reply_sg_cnt:%x.\n", bsg_job->request_payload.sg_cnt,
339 req_sg_cnt, bsg_job->reply_payload.sg_cnt, rsp_sg_cnt);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700340 rval = -EAGAIN;
341 goto done_unmap_sg;
342 }
343
344 /* Alloc SRB structure */
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800345 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700346 if (!sp) {
347 rval = -ENOMEM;
Andrew Vasquez6c452a42010-03-19 17:04:02 -0700348 goto done_unmap_sg;
Giridhar Malavali6e980162010-03-19 17:03:58 -0700349 }
350
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800351 sp->type =
Giridhar Malavali6e980162010-03-19 17:03:58 -0700352 (bsg_job->request->msgcode == FC_BSG_RPT_ELS ?
353 SRB_ELS_CMD_RPT : SRB_ELS_CMD_HST);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800354 sp->name =
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700355 (bsg_job->request->msgcode == FC_BSG_RPT_ELS ?
356 "bsg_els_rpt" : "bsg_els_hst");
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800357 sp->u.bsg_job = bsg_job;
358 sp->free = qla2x00_bsg_sp_free;
359 sp->done = qla2x00_bsg_job_done;
Giridhar Malavali6e980162010-03-19 17:03:58 -0700360
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700361 ql_dbg(ql_dbg_user, vha, 0x700a,
362 "bsg rqst type: %s els type: %x - loop-id=%x "
363 "portid=%-2x%02x%02x.\n", type,
364 bsg_job->request->rqst_data.h_els.command_code, fcport->loop_id,
365 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700366
367 rval = qla2x00_start_sp(sp);
368 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700369 ql_log(ql_log_warn, vha, 0x700e,
370 "qla2x00_start_sp failed = %d\n", rval);
Chad Dupuisb00ee7d2013-02-08 01:57:50 -0500371 qla2x00_rel_sp(vha, sp);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700372 rval = -EIO;
373 goto done_unmap_sg;
374 }
375 return rval;
376
377done_unmap_sg:
378 dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
379 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
380 dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
381 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
382 goto done_free_fcport;
383
384done_free_fcport:
385 if (bsg_job->request->msgcode == FC_BSG_HST_ELS_NOLOGIN)
386 kfree(fcport);
387done:
388 return rval;
389}
390
Andrew Vasquez57807902011-11-18 09:03:20 -0800391inline uint16_t
392qla24xx_calc_ct_iocbs(uint16_t dsds)
393{
394 uint16_t iocbs;
395
396 iocbs = 1;
397 if (dsds > 2) {
398 iocbs += (dsds - 2) / 5;
399 if ((dsds - 2) % 5)
400 iocbs++;
401 }
402 return iocbs;
403}
404
Giridhar Malavali6e980162010-03-19 17:03:58 -0700405static int
406qla2x00_process_ct(struct fc_bsg_job *bsg_job)
407{
408 srb_t *sp;
409 struct Scsi_Host *host = bsg_job->shost;
410 scsi_qla_host_t *vha = shost_priv(host);
411 struct qla_hw_data *ha = vha->hw;
412 int rval = (DRIVER_ERROR << 16);
413 int req_sg_cnt, rsp_sg_cnt;
414 uint16_t loop_id;
415 struct fc_port *fcport;
416 char *type = "FC_BSG_HST_CT";
Giridhar Malavali6e980162010-03-19 17:03:58 -0700417
Giridhar Malavali6e980162010-03-19 17:03:58 -0700418 req_sg_cnt =
419 dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
420 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
Andrew Vasquez6c452a42010-03-19 17:04:02 -0700421 if (!req_sg_cnt) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700422 ql_log(ql_log_warn, vha, 0x700f,
423 "dma_map_sg return %d for request\n", req_sg_cnt);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700424 rval = -ENOMEM;
425 goto done;
426 }
427
428 rsp_sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
429 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
430 if (!rsp_sg_cnt) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700431 ql_log(ql_log_warn, vha, 0x7010,
432 "dma_map_sg return %d for reply\n", rsp_sg_cnt);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700433 rval = -ENOMEM;
434 goto done;
435 }
436
437 if ((req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
Andrew Vasquez6c452a42010-03-19 17:04:02 -0700438 (rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700439 ql_log(ql_log_warn, vha, 0x7011,
440 "request_sg_cnt: %x dma_request_sg_cnt: %x reply_sg_cnt:%x "
441 "dma_reply_sg_cnt: %x\n", bsg_job->request_payload.sg_cnt,
442 req_sg_cnt, bsg_job->reply_payload.sg_cnt, rsp_sg_cnt);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700443 rval = -EAGAIN;
Andrew Vasquez6c452a42010-03-19 17:04:02 -0700444 goto done_unmap_sg;
Giridhar Malavali6e980162010-03-19 17:03:58 -0700445 }
446
447 if (!vha->flags.online) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700448 ql_log(ql_log_warn, vha, 0x7012,
449 "Host is not online.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -0700450 rval = -EIO;
451 goto done_unmap_sg;
452 }
453
454 loop_id =
455 (bsg_job->request->rqst_data.h_ct.preamble_word1 & 0xFF000000)
456 >> 24;
457 switch (loop_id) {
Andrew Vasquez6c452a42010-03-19 17:04:02 -0700458 case 0xFC:
459 loop_id = cpu_to_le16(NPH_SNS);
460 break;
461 case 0xFA:
462 loop_id = vha->mgmt_svr_loop_id;
463 break;
464 default:
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700465 ql_dbg(ql_dbg_user, vha, 0x7013,
466 "Unknown loop id: %x.\n", loop_id);
Andrew Vasquez6c452a42010-03-19 17:04:02 -0700467 rval = -EINVAL;
468 goto done_unmap_sg;
Giridhar Malavali6e980162010-03-19 17:03:58 -0700469 }
470
471 /* Allocate a dummy fcport structure, since functions preparing the
472 * IOCB and mailbox command retrieves port specific information
473 * from fcport structure. For Host based ELS commands there will be
474 * no fcport structure allocated
475 */
476 fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Andrew Vasquez6c452a42010-03-19 17:04:02 -0700477 if (!fcport) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700478 ql_log(ql_log_warn, vha, 0x7014,
479 "Failed to allocate fcport.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -0700480 rval = -ENOMEM;
Andrew Vasquez6c452a42010-03-19 17:04:02 -0700481 goto done_unmap_sg;
Giridhar Malavali6e980162010-03-19 17:03:58 -0700482 }
483
484 /* Initialize all required fields of fcport */
485 fcport->vha = vha;
Giridhar Malavali6e980162010-03-19 17:03:58 -0700486 fcport->d_id.b.al_pa = bsg_job->request->rqst_data.h_ct.port_id[0];
487 fcport->d_id.b.area = bsg_job->request->rqst_data.h_ct.port_id[1];
488 fcport->d_id.b.domain = bsg_job->request->rqst_data.h_ct.port_id[2];
489 fcport->loop_id = loop_id;
490
491 /* Alloc SRB structure */
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800492 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700493 if (!sp) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700494 ql_log(ql_log_warn, vha, 0x7015,
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800495 "qla2x00_get_sp failed.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -0700496 rval = -ENOMEM;
497 goto done_free_fcport;
498 }
499
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800500 sp->type = SRB_CT_CMD;
501 sp->name = "bsg_ct";
502 sp->iocbs = qla24xx_calc_ct_iocbs(req_sg_cnt + rsp_sg_cnt);
503 sp->u.bsg_job = bsg_job;
504 sp->free = qla2x00_bsg_sp_free;
505 sp->done = qla2x00_bsg_job_done;
Giridhar Malavali6e980162010-03-19 17:03:58 -0700506
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700507 ql_dbg(ql_dbg_user, vha, 0x7016,
508 "bsg rqst type: %s else type: %x - "
509 "loop-id=%x portid=%02x%02x%02x.\n", type,
510 (bsg_job->request->rqst_data.h_ct.preamble_word2 >> 16),
511 fcport->loop_id, fcport->d_id.b.domain, fcport->d_id.b.area,
512 fcport->d_id.b.al_pa);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700513
514 rval = qla2x00_start_sp(sp);
515 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700516 ql_log(ql_log_warn, vha, 0x7017,
517 "qla2x00_start_sp failed=%d.\n", rval);
Chad Dupuisb00ee7d2013-02-08 01:57:50 -0500518 qla2x00_rel_sp(vha, sp);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700519 rval = -EIO;
520 goto done_free_fcport;
521 }
522 return rval;
523
524done_free_fcport:
525 kfree(fcport);
526done_unmap_sg:
527 dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
528 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
529 dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
530 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
531done:
532 return rval;
533}
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700534
Chad Dupuis8fcd6b82012-08-22 14:21:06 -0400535/* Disable loopback mode */
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700536static inline int
Chad Dupuis8fcd6b82012-08-22 14:21:06 -0400537qla81xx_reset_loopback_mode(scsi_qla_host_t *vha, uint16_t *config,
Chad Dupuis67b2a312013-02-08 01:57:51 -0500538 int wait)
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700539{
540 int ret = 0;
541 int rval = 0;
542 uint16_t new_config[4];
543 struct qla_hw_data *ha = vha->hw;
544
Nigel Kirklandf863f602012-05-15 14:34:19 -0400545 if (!IS_QLA81XX(ha) && !IS_QLA8031(ha))
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700546 goto done_reset_internal;
547
548 memset(new_config, 0 , sizeof(new_config));
549 if ((config[0] & INTERNAL_LOOPBACK_MASK) >> 1 ==
Chad Dupuis8fcd6b82012-08-22 14:21:06 -0400550 ENABLE_INTERNAL_LOOPBACK ||
551 (config[0] & INTERNAL_LOOPBACK_MASK) >> 1 ==
552 ENABLE_EXTERNAL_LOOPBACK) {
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700553 new_config[0] = config[0] & ~INTERNAL_LOOPBACK_MASK;
Chad Dupuis8fcd6b82012-08-22 14:21:06 -0400554 ql_dbg(ql_dbg_user, vha, 0x70bf, "new_config[0]=%02x\n",
555 (new_config[0] & INTERNAL_LOOPBACK_MASK));
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700556 memcpy(&new_config[1], &config[1], sizeof(uint16_t) * 3) ;
557
558 ha->notify_dcbx_comp = wait;
559 ret = qla81xx_set_port_config(vha, new_config);
560 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700561 ql_log(ql_log_warn, vha, 0x7025,
562 "Set port config failed.\n");
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700563 ha->notify_dcbx_comp = 0;
564 rval = -EINVAL;
565 goto done_reset_internal;
566 }
567
568 /* Wait for DCBX complete event */
569 if (wait && !wait_for_completion_timeout(&ha->dcbx_comp,
570 (20 * HZ))) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700571 ql_dbg(ql_dbg_user, vha, 0x7026,
572 "State change notification not received.\n");
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700573 ha->notify_dcbx_comp = 0;
574 rval = -EINVAL;
575 goto done_reset_internal;
576 } else
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700577 ql_dbg(ql_dbg_user, vha, 0x7027,
578 "State change received.\n");
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700579
580 ha->notify_dcbx_comp = 0;
581 }
582done_reset_internal:
583 return rval;
584}
585
Chad Dupuis67b2a312013-02-08 01:57:51 -0500586/*
587 * Set the port configuration to enable the internal or external loopback
588 * depending on the loopback mode.
589 */
590static inline int
591qla81xx_set_loopback_mode(scsi_qla_host_t *vha, uint16_t *config,
592 uint16_t *new_config, uint16_t mode)
593{
594 int ret = 0;
595 int rval = 0;
596 struct qla_hw_data *ha = vha->hw;
597
598 if (!IS_QLA81XX(ha) && !IS_QLA8031(ha))
599 goto done_set_internal;
600
601 if (mode == INTERNAL_LOOPBACK)
602 new_config[0] = config[0] | (ENABLE_INTERNAL_LOOPBACK << 1);
603 else if (mode == EXTERNAL_LOOPBACK)
604 new_config[0] = config[0] | (ENABLE_EXTERNAL_LOOPBACK << 1);
605 ql_dbg(ql_dbg_user, vha, 0x70be,
606 "new_config[0]=%02x\n", (new_config[0] & INTERNAL_LOOPBACK_MASK));
607
608 memcpy(&new_config[1], &config[1], sizeof(uint16_t) * 3);
609
610 ha->notify_dcbx_comp = 1;
611 ret = qla81xx_set_port_config(vha, new_config);
612 if (ret != QLA_SUCCESS) {
613 ql_log(ql_log_warn, vha, 0x7021,
614 "set port config failed.\n");
615 ha->notify_dcbx_comp = 0;
616 rval = -EINVAL;
617 goto done_set_internal;
618 }
619
620 /* Wait for DCBX complete event */
621 if (!wait_for_completion_timeout(&ha->dcbx_comp, (20 * HZ))) {
622 ql_dbg(ql_dbg_user, vha, 0x7022,
623 "State change notification not received.\n");
624 ret = qla81xx_reset_loopback_mode(vha, new_config, 0);
625 /*
626 * If the reset of the loopback mode doesn't work take a FCoE
627 * dump and reset the chip.
628 */
629 if (ret) {
630 ha->isp_ops->fw_dump(vha, 0);
631 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
632 }
633 rval = -EINVAL;
634 } else {
635 if (ha->flags.idc_compl_status) {
636 ql_dbg(ql_dbg_user, vha, 0x70c3,
637 "Bad status in IDC Completion AEN\n");
638 rval = -EINVAL;
639 ha->flags.idc_compl_status = 0;
640 } else
641 ql_dbg(ql_dbg_user, vha, 0x7023,
642 "State change received.\n");
643 }
644
645 ha->notify_dcbx_comp = 0;
646
647done_set_internal:
648 return rval;
649}
650
Giridhar Malavali6e980162010-03-19 17:03:58 -0700651static int
652qla2x00_process_loopback(struct fc_bsg_job *bsg_job)
653{
654 struct Scsi_Host *host = bsg_job->shost;
655 scsi_qla_host_t *vha = shost_priv(host);
656 struct qla_hw_data *ha = vha->hw;
657 int rval;
658 uint8_t command_sent;
659 char *type;
660 struct msg_echo_lb elreq;
661 uint16_t response[MAILBOX_REGISTER_COUNT];
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700662 uint16_t config[4], new_config[4];
Andrew Vasquez6c452a42010-03-19 17:04:02 -0700663 uint8_t *fw_sts_ptr;
Giridhar Malavali6e980162010-03-19 17:03:58 -0700664 uint8_t *req_data = NULL;
665 dma_addr_t req_data_dma;
666 uint32_t req_data_len;
667 uint8_t *rsp_data = NULL;
668 dma_addr_t rsp_data_dma;
669 uint32_t rsp_data_len;
670
Giridhar Malavali6e980162010-03-19 17:03:58 -0700671 if (!vha->flags.online) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700672 ql_log(ql_log_warn, vha, 0x7019, "Host is not online.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -0700673 return -EIO;
674 }
675
676 elreq.req_sg_cnt = dma_map_sg(&ha->pdev->dev,
677 bsg_job->request_payload.sg_list, bsg_job->request_payload.sg_cnt,
678 DMA_TO_DEVICE);
679
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700680 if (!elreq.req_sg_cnt) {
681 ql_log(ql_log_warn, vha, 0x701a,
682 "dma_map_sg returned %d for request.\n", elreq.req_sg_cnt);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700683 return -ENOMEM;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700684 }
Giridhar Malavali6e980162010-03-19 17:03:58 -0700685
686 elreq.rsp_sg_cnt = dma_map_sg(&ha->pdev->dev,
687 bsg_job->reply_payload.sg_list, bsg_job->reply_payload.sg_cnt,
688 DMA_FROM_DEVICE);
689
690 if (!elreq.rsp_sg_cnt) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700691 ql_log(ql_log_warn, vha, 0x701b,
692 "dma_map_sg returned %d for reply.\n", elreq.rsp_sg_cnt);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700693 rval = -ENOMEM;
694 goto done_unmap_req_sg;
Andrew Vasquez6c452a42010-03-19 17:04:02 -0700695 }
Giridhar Malavali6e980162010-03-19 17:03:58 -0700696
697 if ((elreq.req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
698 (elreq.rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700699 ql_log(ql_log_warn, vha, 0x701c,
700 "dma mapping resulted in different sg counts, "
701 "request_sg_cnt: %x dma_request_sg_cnt: %x "
702 "reply_sg_cnt: %x dma_reply_sg_cnt: %x.\n",
703 bsg_job->request_payload.sg_cnt, elreq.req_sg_cnt,
704 bsg_job->reply_payload.sg_cnt, elreq.rsp_sg_cnt);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700705 rval = -EAGAIN;
706 goto done_unmap_sg;
707 }
708 req_data_len = rsp_data_len = bsg_job->request_payload.payload_len;
709 req_data = dma_alloc_coherent(&ha->pdev->dev, req_data_len,
710 &req_data_dma, GFP_KERNEL);
711 if (!req_data) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700712 ql_log(ql_log_warn, vha, 0x701d,
713 "dma alloc failed for req_data.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -0700714 rval = -ENOMEM;
715 goto done_unmap_sg;
716 }
717
718 rsp_data = dma_alloc_coherent(&ha->pdev->dev, rsp_data_len,
719 &rsp_data_dma, GFP_KERNEL);
720 if (!rsp_data) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700721 ql_log(ql_log_warn, vha, 0x7004,
722 "dma alloc failed for rsp_data.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -0700723 rval = -ENOMEM;
724 goto done_free_dma_req;
725 }
726
727 /* Copy the request buffer in req_data now */
728 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
729 bsg_job->request_payload.sg_cnt, req_data, req_data_len);
730
731 elreq.send_dma = req_data_dma;
732 elreq.rcv_dma = rsp_data_dma;
733 elreq.transfer_size = req_data_len;
734
735 elreq.options = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
736
Chad Dupuis8fcd6b82012-08-22 14:21:06 -0400737 if (atomic_read(&vha->loop_state) == LOOP_READY &&
738 (ha->current_topology == ISP_CFG_F ||
Nigel Kirklandf863f602012-05-15 14:34:19 -0400739 ((IS_QLA81XX(ha) || IS_QLA8031(ha)) &&
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700740 le32_to_cpu(*(uint32_t *)req_data) == ELS_OPCODE_BYTE
741 && req_data_len == MAX_ELS_FRAME_PAYLOAD)) &&
742 elreq.options == EXTERNAL_LOOPBACK) {
Giridhar Malavali6e980162010-03-19 17:03:58 -0700743 type = "FC_BSG_HST_VENDOR_ECHO_DIAG";
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700744 ql_dbg(ql_dbg_user, vha, 0x701e,
745 "BSG request type: %s.\n", type);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700746 command_sent = INT_DEF_LB_ECHO_CMD;
747 rval = qla2x00_echo_test(vha, &elreq, response);
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700748 } else {
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800749 if (IS_QLA81XX(ha) || IS_QLA8031(ha)) {
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700750 memset(config, 0, sizeof(config));
751 memset(new_config, 0, sizeof(new_config));
752 if (qla81xx_get_port_config(vha, config)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700753 ql_log(ql_log_warn, vha, 0x701f,
754 "Get port config failed.\n");
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700755 rval = -EPERM;
Steve Hodgson9bceab42012-11-21 02:39:56 -0500756 goto done_free_dma_rsp;
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700757 }
758
Chad Dupuis1bcc46c2013-02-08 01:57:46 -0500759 if ((config[0] & INTERNAL_LOOPBACK_MASK) != 0) {
760 ql_dbg(ql_dbg_user, vha, 0x70c4,
761 "Loopback operation already in "
762 "progress.\n");
763 rval = -EAGAIN;
764 goto done_free_dma_rsp;
765 }
766
Chad Dupuis8fcd6b82012-08-22 14:21:06 -0400767 ql_dbg(ql_dbg_user, vha, 0x70c0,
768 "elreq.options=%04x\n", elreq.options);
769
770 if (elreq.options == EXTERNAL_LOOPBACK)
771 if (IS_QLA8031(ha))
772 rval = qla81xx_set_loopback_mode(vha,
773 config, new_config, elreq.options);
774 else
775 rval = qla81xx_reset_loopback_mode(vha,
776 config, 1);
777 else
778 rval = qla81xx_set_loopback_mode(vha, config,
779 new_config, elreq.options);
780
781 if (rval) {
Chad Dupuis8fcd6b82012-08-22 14:21:06 -0400782 rval = -EPERM;
Steve Hodgson9bceab42012-11-21 02:39:56 -0500783 goto done_free_dma_rsp;
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700784 }
785
786 type = "FC_BSG_HST_VENDOR_LOOPBACK";
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700787 ql_dbg(ql_dbg_user, vha, 0x7028,
788 "BSG request type: %s.\n", type);
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700789
790 command_sent = INT_DEF_LB_LOOPBACK_CMD;
791 rval = qla2x00_loopback_test(vha, &elreq, response);
792
Chad Dupuis992357c2013-02-08 01:57:52 -0500793 if (response[0] == MBS_COMMAND_ERROR &&
794 response[1] == MBS_LB_RESET) {
795 ql_log(ql_log_warn, vha, 0x7029,
796 "MBX command error, Aborting ISP.\n");
797 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
798 qla2xxx_wake_dpc(vha);
799 qla2x00_wait_for_chip_reset(vha);
800 /* Also reset the MPI */
801 if (IS_QLA81XX(ha)) {
802 if (qla81xx_restart_mpi_firmware(vha) !=
803 QLA_SUCCESS) {
804 ql_log(ql_log_warn, vha, 0x702a,
805 "MPI reset failed.\n");
806 }
807 }
808
809 rval = -EIO;
810 goto done_free_dma_rsp;
811 }
812
Joe Carnuccio4052bd52010-12-21 16:00:17 -0800813 if (new_config[0]) {
Chad Dupuis67b2a312013-02-08 01:57:51 -0500814 int ret;
815
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700816 /* Revert back to original port config
817 * Also clear internal loopback
818 */
Chad Dupuis67b2a312013-02-08 01:57:51 -0500819 ret = qla81xx_reset_loopback_mode(vha,
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700820 new_config, 0);
Chad Dupuis67b2a312013-02-08 01:57:51 -0500821 if (ret) {
822 /*
823 * If the reset of the loopback mode
824 * doesn't work take FCoE dump and then
825 * reset the chip.
826 */
827 ha->isp_ops->fw_dump(vha, 0);
828 set_bit(ISP_ABORT_NEEDED,
829 &vha->dpc_flags);
830 }
831
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700832 }
833
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700834 } else {
835 type = "FC_BSG_HST_VENDOR_LOOPBACK";
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700836 ql_dbg(ql_dbg_user, vha, 0x702b,
837 "BSG request type: %s.\n", type);
Sarang Radke23f2ebd2010-05-28 15:08:21 -0700838 command_sent = INT_DEF_LB_LOOPBACK_CMD;
839 rval = qla2x00_loopback_test(vha, &elreq, response);
840 }
Giridhar Malavali6e980162010-03-19 17:03:58 -0700841 }
842
843 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700844 ql_log(ql_log_warn, vha, 0x702c,
845 "Vendor request %s failed.\n", type);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700846
Giridhar Malavali6e980162010-03-19 17:03:58 -0700847 rval = 0;
Giridhar Malavali6e980162010-03-19 17:03:58 -0700848 bsg_job->reply->result = (DID_ERROR << 16);
Armen Baloyan63ea9232012-11-21 02:39:53 -0500849 bsg_job->reply->reply_payload_rcv_len = 0;
Giridhar Malavali6e980162010-03-19 17:03:58 -0700850 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700851 ql_dbg(ql_dbg_user, vha, 0x702d,
852 "Vendor request %s completed.\n", type);
Armen Baloyan63ea9232012-11-21 02:39:53 -0500853 bsg_job->reply->result = (DID_OK << 16);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700854 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
855 bsg_job->reply_payload.sg_cnt, rsp_data,
856 rsp_data_len);
857 }
Armen Baloyan63ea9232012-11-21 02:39:53 -0500858
859 bsg_job->reply_len = sizeof(struct fc_bsg_reply) +
860 sizeof(response) + sizeof(uint8_t);
861 fw_sts_ptr = ((uint8_t *)bsg_job->req->sense) +
862 sizeof(struct fc_bsg_reply);
863 memcpy(fw_sts_ptr, response, sizeof(response));
864 fw_sts_ptr += sizeof(response);
865 *fw_sts_ptr = command_sent;
Giridhar Malavali6e980162010-03-19 17:03:58 -0700866
Steve Hodgson9bceab42012-11-21 02:39:56 -0500867done_free_dma_rsp:
Giridhar Malavali6e980162010-03-19 17:03:58 -0700868 dma_free_coherent(&ha->pdev->dev, rsp_data_len,
869 rsp_data, rsp_data_dma);
870done_free_dma_req:
871 dma_free_coherent(&ha->pdev->dev, req_data_len,
872 req_data, req_data_dma);
873done_unmap_sg:
874 dma_unmap_sg(&ha->pdev->dev,
875 bsg_job->reply_payload.sg_list,
876 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
877done_unmap_req_sg:
878 dma_unmap_sg(&ha->pdev->dev,
879 bsg_job->request_payload.sg_list,
880 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
Armen Baloyan63ea9232012-11-21 02:39:53 -0500881 if (!rval)
882 bsg_job->job_done(bsg_job);
Andrew Vasquez6c452a42010-03-19 17:04:02 -0700883 return rval;
Giridhar Malavali6e980162010-03-19 17:03:58 -0700884}
885
886static int
887qla84xx_reset(struct fc_bsg_job *bsg_job)
888{
889 struct Scsi_Host *host = bsg_job->shost;
890 scsi_qla_host_t *vha = shost_priv(host);
891 struct qla_hw_data *ha = vha->hw;
892 int rval = 0;
893 uint32_t flag;
894
Giridhar Malavali6e980162010-03-19 17:03:58 -0700895 if (!IS_QLA84XX(ha)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700896 ql_dbg(ql_dbg_user, vha, 0x702f, "Not 84xx, exiting.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -0700897 return -EINVAL;
898 }
899
900 flag = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
901
902 rval = qla84xx_reset_chip(vha, flag == A84_ISSUE_RESET_DIAG_FW);
903
904 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700905 ql_log(ql_log_warn, vha, 0x7030,
906 "Vendor request 84xx reset failed.\n");
Armen Baloyan63ea9232012-11-21 02:39:53 -0500907 rval = (DID_ERROR << 16);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700908
909 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700910 ql_dbg(ql_dbg_user, vha, 0x7031,
911 "Vendor request 84xx reset completed.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -0700912 bsg_job->reply->result = DID_OK;
Armen Baloyan63ea9232012-11-21 02:39:53 -0500913 bsg_job->job_done(bsg_job);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700914 }
915
Giridhar Malavali6e980162010-03-19 17:03:58 -0700916 return rval;
917}
918
919static int
920qla84xx_updatefw(struct fc_bsg_job *bsg_job)
921{
922 struct Scsi_Host *host = bsg_job->shost;
923 scsi_qla_host_t *vha = shost_priv(host);
924 struct qla_hw_data *ha = vha->hw;
925 struct verify_chip_entry_84xx *mn = NULL;
926 dma_addr_t mn_dma, fw_dma;
927 void *fw_buf = NULL;
928 int rval = 0;
929 uint32_t sg_cnt;
930 uint32_t data_len;
931 uint16_t options;
932 uint32_t flag;
933 uint32_t fw_ver;
934
Giridhar Malavali6e980162010-03-19 17:03:58 -0700935 if (!IS_QLA84XX(ha)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700936 ql_dbg(ql_dbg_user, vha, 0x7032,
937 "Not 84xx, exiting.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -0700938 return -EINVAL;
939 }
940
941 sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
942 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700943 if (!sg_cnt) {
944 ql_log(ql_log_warn, vha, 0x7033,
945 "dma_map_sg returned %d for request.\n", sg_cnt);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700946 return -ENOMEM;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700947 }
Giridhar Malavali6e980162010-03-19 17:03:58 -0700948
949 if (sg_cnt != bsg_job->request_payload.sg_cnt) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700950 ql_log(ql_log_warn, vha, 0x7034,
951 "DMA mapping resulted in different sg counts, "
952 "request_sg_cnt: %x dma_request_sg_cnt: %x.\n",
953 bsg_job->request_payload.sg_cnt, sg_cnt);
Giridhar Malavali6e980162010-03-19 17:03:58 -0700954 rval = -EAGAIN;
955 goto done_unmap_sg;
956 }
957
958 data_len = bsg_job->request_payload.payload_len;
959 fw_buf = dma_alloc_coherent(&ha->pdev->dev, data_len,
960 &fw_dma, GFP_KERNEL);
961 if (!fw_buf) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700962 ql_log(ql_log_warn, vha, 0x7035,
963 "DMA alloc failed for fw_buf.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -0700964 rval = -ENOMEM;
965 goto done_unmap_sg;
966 }
967
968 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
969 bsg_job->request_payload.sg_cnt, fw_buf, data_len);
970
971 mn = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma);
972 if (!mn) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700973 ql_log(ql_log_warn, vha, 0x7036,
974 "DMA alloc failed for fw buffer.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -0700975 rval = -ENOMEM;
976 goto done_free_fw_buf;
977 }
978
979 flag = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
980 fw_ver = le32_to_cpu(*((uint32_t *)((uint32_t *)fw_buf + 2)));
981
982 memset(mn, 0, sizeof(struct access_chip_84xx));
983 mn->entry_type = VERIFY_CHIP_IOCB_TYPE;
984 mn->entry_count = 1;
985
986 options = VCO_FORCE_UPDATE | VCO_END_OF_DATA;
987 if (flag == A84_ISSUE_UPDATE_DIAGFW_CMD)
988 options |= VCO_DIAG_FW;
989
990 mn->options = cpu_to_le16(options);
991 mn->fw_ver = cpu_to_le32(fw_ver);
992 mn->fw_size = cpu_to_le32(data_len);
993 mn->fw_seq_size = cpu_to_le32(data_len);
994 mn->dseg_address[0] = cpu_to_le32(LSD(fw_dma));
995 mn->dseg_address[1] = cpu_to_le32(MSD(fw_dma));
996 mn->dseg_length = cpu_to_le32(data_len);
997 mn->data_seg_cnt = cpu_to_le16(1);
998
999 rval = qla2x00_issue_iocb_timeout(vha, mn, mn_dma, 0, 120);
1000
1001 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001002 ql_log(ql_log_warn, vha, 0x7037,
1003 "Vendor request 84xx updatefw failed.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -07001004
Armen Baloyan63ea9232012-11-21 02:39:53 -05001005 rval = (DID_ERROR << 16);
Giridhar Malavali6e980162010-03-19 17:03:58 -07001006 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001007 ql_dbg(ql_dbg_user, vha, 0x7038,
1008 "Vendor request 84xx updatefw completed.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -07001009
1010 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1011 bsg_job->reply->result = DID_OK;
1012 }
1013
Giridhar Malavali6e980162010-03-19 17:03:58 -07001014 dma_pool_free(ha->s_dma_pool, mn, mn_dma);
1015
1016done_free_fw_buf:
1017 dma_free_coherent(&ha->pdev->dev, data_len, fw_buf, fw_dma);
1018
1019done_unmap_sg:
1020 dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
1021 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
1022
Armen Baloyan63ea9232012-11-21 02:39:53 -05001023 if (!rval)
1024 bsg_job->job_done(bsg_job);
Giridhar Malavali6e980162010-03-19 17:03:58 -07001025 return rval;
1026}
1027
1028static int
1029qla84xx_mgmt_cmd(struct fc_bsg_job *bsg_job)
1030{
1031 struct Scsi_Host *host = bsg_job->shost;
1032 scsi_qla_host_t *vha = shost_priv(host);
1033 struct qla_hw_data *ha = vha->hw;
1034 struct access_chip_84xx *mn = NULL;
1035 dma_addr_t mn_dma, mgmt_dma;
1036 void *mgmt_b = NULL;
1037 int rval = 0;
1038 struct qla_bsg_a84_mgmt *ql84_mgmt;
1039 uint32_t sg_cnt;
Harish Zunjarraod54590832010-03-19 17:04:00 -07001040 uint32_t data_len = 0;
Giridhar Malavali6e980162010-03-19 17:03:58 -07001041 uint32_t dma_direction = DMA_NONE;
1042
Giridhar Malavali6e980162010-03-19 17:03:58 -07001043 if (!IS_QLA84XX(ha)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001044 ql_log(ql_log_warn, vha, 0x703a,
1045 "Not 84xx, exiting.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -07001046 return -EINVAL;
1047 }
1048
1049 ql84_mgmt = (struct qla_bsg_a84_mgmt *)((char *)bsg_job->request +
1050 sizeof(struct fc_bsg_request));
1051 if (!ql84_mgmt) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001052 ql_log(ql_log_warn, vha, 0x703b,
1053 "MGMT header not provided, exiting.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -07001054 return -EINVAL;
1055 }
1056
1057 mn = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma);
1058 if (!mn) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001059 ql_log(ql_log_warn, vha, 0x703c,
1060 "DMA alloc failed for fw buffer.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -07001061 return -ENOMEM;
1062 }
1063
1064 memset(mn, 0, sizeof(struct access_chip_84xx));
1065 mn->entry_type = ACCESS_CHIP_IOCB_TYPE;
1066 mn->entry_count = 1;
1067
1068 switch (ql84_mgmt->mgmt.cmd) {
1069 case QLA84_MGMT_READ_MEM:
1070 case QLA84_MGMT_GET_INFO:
1071 sg_cnt = dma_map_sg(&ha->pdev->dev,
1072 bsg_job->reply_payload.sg_list,
1073 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
1074 if (!sg_cnt) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001075 ql_log(ql_log_warn, vha, 0x703d,
1076 "dma_map_sg returned %d for reply.\n", sg_cnt);
Giridhar Malavali6e980162010-03-19 17:03:58 -07001077 rval = -ENOMEM;
1078 goto exit_mgmt;
1079 }
1080
1081 dma_direction = DMA_FROM_DEVICE;
1082
1083 if (sg_cnt != bsg_job->reply_payload.sg_cnt) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001084 ql_log(ql_log_warn, vha, 0x703e,
1085 "DMA mapping resulted in different sg counts, "
1086 "reply_sg_cnt: %x dma_reply_sg_cnt: %x.\n",
1087 bsg_job->reply_payload.sg_cnt, sg_cnt);
Giridhar Malavali6e980162010-03-19 17:03:58 -07001088 rval = -EAGAIN;
1089 goto done_unmap_sg;
1090 }
1091
1092 data_len = bsg_job->reply_payload.payload_len;
1093
1094 mgmt_b = dma_alloc_coherent(&ha->pdev->dev, data_len,
1095 &mgmt_dma, GFP_KERNEL);
1096 if (!mgmt_b) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001097 ql_log(ql_log_warn, vha, 0x703f,
1098 "DMA alloc failed for mgmt_b.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -07001099 rval = -ENOMEM;
1100 goto done_unmap_sg;
1101 }
1102
1103 if (ql84_mgmt->mgmt.cmd == QLA84_MGMT_READ_MEM) {
1104 mn->options = cpu_to_le16(ACO_DUMP_MEMORY);
1105 mn->parameter1 =
1106 cpu_to_le32(
1107 ql84_mgmt->mgmt.mgmtp.u.mem.start_addr);
1108
1109 } else if (ql84_mgmt->mgmt.cmd == QLA84_MGMT_GET_INFO) {
1110 mn->options = cpu_to_le16(ACO_REQUEST_INFO);
1111 mn->parameter1 =
1112 cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.info.type);
1113
1114 mn->parameter2 =
1115 cpu_to_le32(
1116 ql84_mgmt->mgmt.mgmtp.u.info.context);
1117 }
1118 break;
1119
1120 case QLA84_MGMT_WRITE_MEM:
1121 sg_cnt = dma_map_sg(&ha->pdev->dev,
1122 bsg_job->request_payload.sg_list,
1123 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
1124
1125 if (!sg_cnt) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001126 ql_log(ql_log_warn, vha, 0x7040,
1127 "dma_map_sg returned %d.\n", sg_cnt);
Giridhar Malavali6e980162010-03-19 17:03:58 -07001128 rval = -ENOMEM;
1129 goto exit_mgmt;
1130 }
1131
1132 dma_direction = DMA_TO_DEVICE;
1133
1134 if (sg_cnt != bsg_job->request_payload.sg_cnt) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001135 ql_log(ql_log_warn, vha, 0x7041,
1136 "DMA mapping resulted in different sg counts, "
1137 "request_sg_cnt: %x dma_request_sg_cnt: %x.\n",
1138 bsg_job->request_payload.sg_cnt, sg_cnt);
Giridhar Malavali6e980162010-03-19 17:03:58 -07001139 rval = -EAGAIN;
1140 goto done_unmap_sg;
1141 }
1142
1143 data_len = bsg_job->request_payload.payload_len;
1144 mgmt_b = dma_alloc_coherent(&ha->pdev->dev, data_len,
1145 &mgmt_dma, GFP_KERNEL);
1146 if (!mgmt_b) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001147 ql_log(ql_log_warn, vha, 0x7042,
1148 "DMA alloc failed for mgmt_b.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -07001149 rval = -ENOMEM;
1150 goto done_unmap_sg;
1151 }
1152
1153 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1154 bsg_job->request_payload.sg_cnt, mgmt_b, data_len);
1155
1156 mn->options = cpu_to_le16(ACO_LOAD_MEMORY);
1157 mn->parameter1 =
1158 cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.mem.start_addr);
1159 break;
1160
1161 case QLA84_MGMT_CHNG_CONFIG:
1162 mn->options = cpu_to_le16(ACO_CHANGE_CONFIG_PARAM);
1163 mn->parameter1 =
1164 cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.config.id);
1165
1166 mn->parameter2 =
1167 cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.config.param0);
1168
1169 mn->parameter3 =
1170 cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.config.param1);
1171 break;
1172
1173 default:
1174 rval = -EIO;
1175 goto exit_mgmt;
1176 }
1177
1178 if (ql84_mgmt->mgmt.cmd != QLA84_MGMT_CHNG_CONFIG) {
1179 mn->total_byte_cnt = cpu_to_le32(ql84_mgmt->mgmt.len);
1180 mn->dseg_count = cpu_to_le16(1);
1181 mn->dseg_address[0] = cpu_to_le32(LSD(mgmt_dma));
1182 mn->dseg_address[1] = cpu_to_le32(MSD(mgmt_dma));
1183 mn->dseg_length = cpu_to_le32(ql84_mgmt->mgmt.len);
1184 }
1185
1186 rval = qla2x00_issue_iocb(vha, mn, mn_dma, 0);
1187
1188 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001189 ql_log(ql_log_warn, vha, 0x7043,
1190 "Vendor request 84xx mgmt failed.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -07001191
Armen Baloyan63ea9232012-11-21 02:39:53 -05001192 rval = (DID_ERROR << 16);
Giridhar Malavali6e980162010-03-19 17:03:58 -07001193
1194 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001195 ql_dbg(ql_dbg_user, vha, 0x7044,
1196 "Vendor request 84xx mgmt completed.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -07001197
1198 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1199 bsg_job->reply->result = DID_OK;
1200
1201 if ((ql84_mgmt->mgmt.cmd == QLA84_MGMT_READ_MEM) ||
1202 (ql84_mgmt->mgmt.cmd == QLA84_MGMT_GET_INFO)) {
1203 bsg_job->reply->reply_payload_rcv_len =
1204 bsg_job->reply_payload.payload_len;
1205
1206 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
Andrew Vasquez6c452a42010-03-19 17:04:02 -07001207 bsg_job->reply_payload.sg_cnt, mgmt_b,
1208 data_len);
Giridhar Malavali6e980162010-03-19 17:03:58 -07001209 }
1210 }
1211
Giridhar Malavali6e980162010-03-19 17:03:58 -07001212done_unmap_sg:
Harish Zunjarraod54590832010-03-19 17:04:00 -07001213 if (mgmt_b)
1214 dma_free_coherent(&ha->pdev->dev, data_len, mgmt_b, mgmt_dma);
1215
Giridhar Malavali6e980162010-03-19 17:03:58 -07001216 if (dma_direction == DMA_TO_DEVICE)
1217 dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
1218 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
1219 else if (dma_direction == DMA_FROM_DEVICE)
1220 dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
1221 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
1222
1223exit_mgmt:
1224 dma_pool_free(ha->s_dma_pool, mn, mn_dma);
1225
Armen Baloyan63ea9232012-11-21 02:39:53 -05001226 if (!rval)
1227 bsg_job->job_done(bsg_job);
Giridhar Malavali6e980162010-03-19 17:03:58 -07001228 return rval;
1229}
1230
1231static int
1232qla24xx_iidma(struct fc_bsg_job *bsg_job)
1233{
1234 struct Scsi_Host *host = bsg_job->shost;
1235 scsi_qla_host_t *vha = shost_priv(host);
Giridhar Malavali6e980162010-03-19 17:03:58 -07001236 int rval = 0;
1237 struct qla_port_param *port_param = NULL;
1238 fc_port_t *fcport = NULL;
1239 uint16_t mb[MAILBOX_REGISTER_COUNT];
1240 uint8_t *rsp_ptr = NULL;
1241
Giridhar Malavali6e980162010-03-19 17:03:58 -07001242 if (!IS_IIDMA_CAPABLE(vha->hw)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001243 ql_log(ql_log_info, vha, 0x7046, "iiDMA not supported.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -07001244 return -EINVAL;
1245 }
1246
1247 port_param = (struct qla_port_param *)((char *)bsg_job->request +
1248 sizeof(struct fc_bsg_request));
1249 if (!port_param) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001250 ql_log(ql_log_warn, vha, 0x7047,
1251 "port_param header not provided.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -07001252 return -EINVAL;
1253 }
1254
1255 if (port_param->fc_scsi_addr.dest_type != EXT_DEF_TYPE_WWPN) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001256 ql_log(ql_log_warn, vha, 0x7048,
1257 "Invalid destination type.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -07001258 return -EINVAL;
1259 }
1260
1261 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1262 if (fcport->port_type != FCT_TARGET)
1263 continue;
1264
1265 if (memcmp(port_param->fc_scsi_addr.dest_addr.wwpn,
1266 fcport->port_name, sizeof(fcport->port_name)))
1267 continue;
1268 break;
1269 }
1270
1271 if (!fcport) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001272 ql_log(ql_log_warn, vha, 0x7049,
1273 "Failed to find port.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -07001274 return -EINVAL;
1275 }
1276
Giridhar Malavalic9afb9a2010-09-03 15:20:48 -07001277 if (atomic_read(&fcport->state) != FCS_ONLINE) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001278 ql_log(ql_log_warn, vha, 0x704a,
1279 "Port is not online.\n");
Madhuranath Iyengar17cf2c52010-07-23 15:28:22 +05001280 return -EINVAL;
1281 }
1282
Madhuranath Iyengar9a15eb42010-07-23 15:28:31 +05001283 if (fcport->flags & FCF_LOGIN_NEEDED) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001284 ql_log(ql_log_warn, vha, 0x704b,
1285 "Remote port not logged in flags = 0x%x.\n", fcport->flags);
Madhuranath Iyengar9a15eb42010-07-23 15:28:31 +05001286 return -EINVAL;
1287 }
1288
Giridhar Malavali6e980162010-03-19 17:03:58 -07001289 if (port_param->mode)
1290 rval = qla2x00_set_idma_speed(vha, fcport->loop_id,
1291 port_param->speed, mb);
1292 else
1293 rval = qla2x00_get_idma_speed(vha, fcport->loop_id,
1294 &port_param->speed, mb);
1295
1296 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001297 ql_log(ql_log_warn, vha, 0x704c,
1298 "iIDMA cmd failed for %02x%02x%02x%02x%02x%02x%02x%02x -- "
1299 "%04x %x %04x %04x.\n", fcport->port_name[0],
1300 fcport->port_name[1], fcport->port_name[2],
1301 fcport->port_name[3], fcport->port_name[4],
1302 fcport->port_name[5], fcport->port_name[6],
1303 fcport->port_name[7], rval, fcport->fp_speed, mb[0], mb[1]);
Armen Baloyan63ea9232012-11-21 02:39:53 -05001304 rval = (DID_ERROR << 16);
Giridhar Malavali6e980162010-03-19 17:03:58 -07001305 } else {
1306 if (!port_param->mode) {
1307 bsg_job->reply_len = sizeof(struct fc_bsg_reply) +
1308 sizeof(struct qla_port_param);
1309
1310 rsp_ptr = ((uint8_t *)bsg_job->reply) +
1311 sizeof(struct fc_bsg_reply);
1312
1313 memcpy(rsp_ptr, port_param,
1314 sizeof(struct qla_port_param));
1315 }
1316
1317 bsg_job->reply->result = DID_OK;
Armen Baloyan63ea9232012-11-21 02:39:53 -05001318 bsg_job->job_done(bsg_job);
Giridhar Malavali6e980162010-03-19 17:03:58 -07001319 }
1320
Giridhar Malavali6e980162010-03-19 17:03:58 -07001321 return rval;
1322}
1323
1324static int
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001325qla2x00_optrom_setup(struct fc_bsg_job *bsg_job, scsi_qla_host_t *vha,
Harish Zunjarraof19af162010-10-15 11:27:43 -07001326 uint8_t is_update)
1327{
1328 uint32_t start = 0;
1329 int valid = 0;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001330 struct qla_hw_data *ha = vha->hw;
Harish Zunjarraof19af162010-10-15 11:27:43 -07001331
Harish Zunjarraof19af162010-10-15 11:27:43 -07001332 if (unlikely(pci_channel_offline(ha->pdev)))
1333 return -EINVAL;
1334
1335 start = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001336 if (start > ha->optrom_size) {
1337 ql_log(ql_log_warn, vha, 0x7055,
1338 "start %d > optrom_size %d.\n", start, ha->optrom_size);
Harish Zunjarraof19af162010-10-15 11:27:43 -07001339 return -EINVAL;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001340 }
Harish Zunjarraof19af162010-10-15 11:27:43 -07001341
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001342 if (ha->optrom_state != QLA_SWAITING) {
1343 ql_log(ql_log_info, vha, 0x7056,
1344 "optrom_state %d.\n", ha->optrom_state);
Harish Zunjarraof19af162010-10-15 11:27:43 -07001345 return -EBUSY;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001346 }
Harish Zunjarraof19af162010-10-15 11:27:43 -07001347
1348 ha->optrom_region_start = start;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001349 ql_dbg(ql_dbg_user, vha, 0x7057, "is_update=%d.\n", is_update);
Harish Zunjarraof19af162010-10-15 11:27:43 -07001350 if (is_update) {
1351 if (ha->optrom_size == OPTROM_SIZE_2300 && start == 0)
1352 valid = 1;
1353 else if (start == (ha->flt_region_boot * 4) ||
1354 start == (ha->flt_region_fw * 4))
1355 valid = 1;
1356 else if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha) ||
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001357 IS_CNA_CAPABLE(ha) || IS_QLA2031(ha))
Harish Zunjarraof19af162010-10-15 11:27:43 -07001358 valid = 1;
1359 if (!valid) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001360 ql_log(ql_log_warn, vha, 0x7058,
1361 "Invalid start region 0x%x/0x%x.\n", start,
1362 bsg_job->request_payload.payload_len);
Harish Zunjarraof19af162010-10-15 11:27:43 -07001363 return -EINVAL;
1364 }
1365
1366 ha->optrom_region_size = start +
1367 bsg_job->request_payload.payload_len > ha->optrom_size ?
1368 ha->optrom_size - start :
1369 bsg_job->request_payload.payload_len;
1370 ha->optrom_state = QLA_SWRITING;
1371 } else {
1372 ha->optrom_region_size = start +
1373 bsg_job->reply_payload.payload_len > ha->optrom_size ?
1374 ha->optrom_size - start :
1375 bsg_job->reply_payload.payload_len;
1376 ha->optrom_state = QLA_SREADING;
1377 }
1378
1379 ha->optrom_buffer = vmalloc(ha->optrom_region_size);
1380 if (!ha->optrom_buffer) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001381 ql_log(ql_log_warn, vha, 0x7059,
Harish Zunjarraof19af162010-10-15 11:27:43 -07001382 "Read: Unable to allocate memory for optrom retrieval "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001383 "(%x)\n", ha->optrom_region_size);
Harish Zunjarraof19af162010-10-15 11:27:43 -07001384
1385 ha->optrom_state = QLA_SWAITING;
1386 return -ENOMEM;
1387 }
1388
1389 memset(ha->optrom_buffer, 0, ha->optrom_region_size);
1390 return 0;
1391}
1392
1393static int
1394qla2x00_read_optrom(struct fc_bsg_job *bsg_job)
1395{
1396 struct Scsi_Host *host = bsg_job->shost;
1397 scsi_qla_host_t *vha = shost_priv(host);
1398 struct qla_hw_data *ha = vha->hw;
1399 int rval = 0;
1400
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04001401 if (ha->flags.nic_core_reset_hdlr_active)
Giridhar Malavalia49393f2012-04-25 07:26:14 -07001402 return -EBUSY;
1403
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001404 rval = qla2x00_optrom_setup(bsg_job, vha, 0);
Harish Zunjarraof19af162010-10-15 11:27:43 -07001405 if (rval)
1406 return rval;
1407
1408 ha->isp_ops->read_optrom(vha, ha->optrom_buffer,
1409 ha->optrom_region_start, ha->optrom_region_size);
1410
1411 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
1412 bsg_job->reply_payload.sg_cnt, ha->optrom_buffer,
1413 ha->optrom_region_size);
1414
1415 bsg_job->reply->reply_payload_rcv_len = ha->optrom_region_size;
1416 bsg_job->reply->result = DID_OK;
1417 vfree(ha->optrom_buffer);
1418 ha->optrom_buffer = NULL;
1419 ha->optrom_state = QLA_SWAITING;
1420 bsg_job->job_done(bsg_job);
1421 return rval;
1422}
1423
1424static int
1425qla2x00_update_optrom(struct fc_bsg_job *bsg_job)
1426{
1427 struct Scsi_Host *host = bsg_job->shost;
1428 scsi_qla_host_t *vha = shost_priv(host);
1429 struct qla_hw_data *ha = vha->hw;
1430 int rval = 0;
1431
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001432 rval = qla2x00_optrom_setup(bsg_job, vha, 1);
Harish Zunjarraof19af162010-10-15 11:27:43 -07001433 if (rval)
1434 return rval;
1435
Giridhar Malavalib6d0d9d2012-05-15 14:34:25 -04001436 /* Set the isp82xx_no_md_cap not to capture minidump */
1437 ha->flags.isp82xx_no_md_cap = 1;
1438
Harish Zunjarraof19af162010-10-15 11:27:43 -07001439 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1440 bsg_job->request_payload.sg_cnt, ha->optrom_buffer,
1441 ha->optrom_region_size);
1442
1443 ha->isp_ops->write_optrom(vha, ha->optrom_buffer,
1444 ha->optrom_region_start, ha->optrom_region_size);
1445
1446 bsg_job->reply->result = DID_OK;
1447 vfree(ha->optrom_buffer);
1448 ha->optrom_buffer = NULL;
1449 ha->optrom_state = QLA_SWAITING;
1450 bsg_job->job_done(bsg_job);
1451 return rval;
1452}
1453
1454static int
Joe Carnuccio697a4bc2011-08-16 11:31:52 -07001455qla2x00_update_fru_versions(struct fc_bsg_job *bsg_job)
1456{
1457 struct Scsi_Host *host = bsg_job->shost;
1458 scsi_qla_host_t *vha = shost_priv(host);
1459 struct qla_hw_data *ha = vha->hw;
1460 int rval = 0;
1461 uint8_t bsg[DMA_POOL_SIZE];
1462 struct qla_image_version_list *list = (void *)bsg;
1463 struct qla_image_version *image;
1464 uint32_t count;
1465 dma_addr_t sfp_dma;
1466 void *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
1467 if (!sfp) {
1468 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
1469 EXT_STATUS_NO_MEMORY;
1470 goto done;
1471 }
1472
1473 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1474 bsg_job->request_payload.sg_cnt, list, sizeof(bsg));
1475
1476 image = list->version;
1477 count = list->count;
1478 while (count--) {
1479 memcpy(sfp, &image->field_info, sizeof(image->field_info));
1480 rval = qla2x00_write_sfp(vha, sfp_dma, sfp,
1481 image->field_address.device, image->field_address.offset,
1482 sizeof(image->field_info), image->field_address.option);
1483 if (rval) {
1484 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
1485 EXT_STATUS_MAILBOX;
1486 goto dealloc;
1487 }
1488 image++;
1489 }
1490
1491 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
1492
1493dealloc:
1494 dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
1495
1496done:
1497 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1498 bsg_job->reply->result = DID_OK << 16;
1499 bsg_job->job_done(bsg_job);
1500
1501 return 0;
1502}
1503
1504static int
1505qla2x00_read_fru_status(struct fc_bsg_job *bsg_job)
1506{
1507 struct Scsi_Host *host = bsg_job->shost;
1508 scsi_qla_host_t *vha = shost_priv(host);
1509 struct qla_hw_data *ha = vha->hw;
1510 int rval = 0;
1511 uint8_t bsg[DMA_POOL_SIZE];
1512 struct qla_status_reg *sr = (void *)bsg;
1513 dma_addr_t sfp_dma;
1514 uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
1515 if (!sfp) {
1516 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
1517 EXT_STATUS_NO_MEMORY;
1518 goto done;
1519 }
1520
1521 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1522 bsg_job->request_payload.sg_cnt, sr, sizeof(*sr));
1523
1524 rval = qla2x00_read_sfp(vha, sfp_dma, sfp,
1525 sr->field_address.device, sr->field_address.offset,
1526 sizeof(sr->status_reg), sr->field_address.option);
1527 sr->status_reg = *sfp;
1528
1529 if (rval) {
1530 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
1531 EXT_STATUS_MAILBOX;
1532 goto dealloc;
1533 }
1534
1535 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
1536 bsg_job->reply_payload.sg_cnt, sr, sizeof(*sr));
1537
1538 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
1539
1540dealloc:
1541 dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
1542
1543done:
1544 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1545 bsg_job->reply->reply_payload_rcv_len = sizeof(*sr);
1546 bsg_job->reply->result = DID_OK << 16;
1547 bsg_job->job_done(bsg_job);
1548
1549 return 0;
1550}
1551
1552static int
1553qla2x00_write_fru_status(struct fc_bsg_job *bsg_job)
1554{
1555 struct Scsi_Host *host = bsg_job->shost;
1556 scsi_qla_host_t *vha = shost_priv(host);
1557 struct qla_hw_data *ha = vha->hw;
1558 int rval = 0;
1559 uint8_t bsg[DMA_POOL_SIZE];
1560 struct qla_status_reg *sr = (void *)bsg;
1561 dma_addr_t sfp_dma;
1562 uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
1563 if (!sfp) {
1564 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
1565 EXT_STATUS_NO_MEMORY;
1566 goto done;
1567 }
1568
1569 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1570 bsg_job->request_payload.sg_cnt, sr, sizeof(*sr));
1571
1572 *sfp = sr->status_reg;
1573 rval = qla2x00_write_sfp(vha, sfp_dma, sfp,
1574 sr->field_address.device, sr->field_address.offset,
1575 sizeof(sr->status_reg), sr->field_address.option);
1576
1577 if (rval) {
1578 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
1579 EXT_STATUS_MAILBOX;
1580 goto dealloc;
1581 }
1582
1583 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
1584
1585dealloc:
1586 dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
1587
1588done:
1589 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1590 bsg_job->reply->result = DID_OK << 16;
1591 bsg_job->job_done(bsg_job);
1592
1593 return 0;
1594}
1595
1596static int
Joe Carnuccio9ebb5d92012-08-22 14:20:56 -04001597qla2x00_write_i2c(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_i2c_access *i2c = (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, i2c, sizeof(*i2c));
1615
1616 memcpy(sfp, i2c->buffer, i2c->length);
1617 rval = qla2x00_write_sfp(vha, sfp_dma, sfp,
1618 i2c->device, i2c->offset, i2c->length, i2c->option);
1619
1620 if (rval) {
1621 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
1622 EXT_STATUS_MAILBOX;
1623 goto dealloc;
1624 }
1625
1626 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
1627
1628dealloc:
1629 dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
1630
1631done:
1632 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1633 bsg_job->reply->result = DID_OK << 16;
1634 bsg_job->job_done(bsg_job);
1635
1636 return 0;
1637}
1638
1639static int
1640qla2x00_read_i2c(struct fc_bsg_job *bsg_job)
1641{
1642 struct Scsi_Host *host = bsg_job->shost;
1643 scsi_qla_host_t *vha = shost_priv(host);
1644 struct qla_hw_data *ha = vha->hw;
1645 int rval = 0;
1646 uint8_t bsg[DMA_POOL_SIZE];
1647 struct qla_i2c_access *i2c = (void *)bsg;
1648 dma_addr_t sfp_dma;
1649 uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
1650 if (!sfp) {
1651 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
1652 EXT_STATUS_NO_MEMORY;
1653 goto done;
1654 }
1655
1656 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
1657 bsg_job->request_payload.sg_cnt, i2c, sizeof(*i2c));
1658
1659 rval = qla2x00_read_sfp(vha, sfp_dma, sfp,
1660 i2c->device, i2c->offset, i2c->length, i2c->option);
1661
1662 if (rval) {
1663 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
1664 EXT_STATUS_MAILBOX;
1665 goto dealloc;
1666 }
1667
1668 memcpy(i2c->buffer, sfp, i2c->length);
1669 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
1670 bsg_job->reply_payload.sg_cnt, i2c, sizeof(*i2c));
1671
1672 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
1673
1674dealloc:
1675 dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
1676
1677done:
1678 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1679 bsg_job->reply->reply_payload_rcv_len = sizeof(*i2c);
1680 bsg_job->reply->result = DID_OK << 16;
1681 bsg_job->job_done(bsg_job);
1682
1683 return 0;
1684}
1685
1686static int
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04001687qla24xx_process_bidir_cmd(struct fc_bsg_job *bsg_job)
1688{
1689 struct Scsi_Host *host = bsg_job->shost;
1690 scsi_qla_host_t *vha = shost_priv(host);
1691 struct qla_hw_data *ha = vha->hw;
1692 uint16_t thread_id;
1693 uint32_t rval = EXT_STATUS_OK;
1694 uint16_t req_sg_cnt = 0;
1695 uint16_t rsp_sg_cnt = 0;
1696 uint16_t nextlid = 0;
1697 uint32_t tot_dsds;
1698 srb_t *sp = NULL;
1699 uint32_t req_data_len = 0;
1700 uint32_t rsp_data_len = 0;
1701
1702 /* Check the type of the adapter */
1703 if (!IS_BIDI_CAPABLE(ha)) {
1704 ql_log(ql_log_warn, vha, 0x70a0,
1705 "This adapter is not supported\n");
1706 rval = EXT_STATUS_NOT_SUPPORTED;
1707 goto done;
1708 }
1709
1710 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
1711 test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
1712 test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
1713 rval = EXT_STATUS_BUSY;
1714 goto done;
1715 }
1716
1717 /* Check if host is online */
1718 if (!vha->flags.online) {
1719 ql_log(ql_log_warn, vha, 0x70a1,
1720 "Host is not online\n");
1721 rval = EXT_STATUS_DEVICE_OFFLINE;
1722 goto done;
1723 }
1724
1725 /* Check if cable is plugged in or not */
1726 if (vha->device_flags & DFLG_NO_CABLE) {
1727 ql_log(ql_log_warn, vha, 0x70a2,
1728 "Cable is unplugged...\n");
1729 rval = EXT_STATUS_INVALID_CFG;
1730 goto done;
1731 }
1732
1733 /* Check if the switch is connected or not */
1734 if (ha->current_topology != ISP_CFG_F) {
1735 ql_log(ql_log_warn, vha, 0x70a3,
1736 "Host is not connected to the switch\n");
1737 rval = EXT_STATUS_INVALID_CFG;
1738 goto done;
1739 }
1740
1741 /* Check if operating mode is P2P */
1742 if (ha->operating_mode != P2P) {
1743 ql_log(ql_log_warn, vha, 0x70a4,
1744 "Host is operating mode is not P2p\n");
1745 rval = EXT_STATUS_INVALID_CFG;
1746 goto done;
1747 }
1748
1749 thread_id = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
1750
1751 mutex_lock(&ha->selflogin_lock);
1752 if (vha->self_login_loop_id == 0) {
1753 /* Initialize all required fields of fcport */
1754 vha->bidir_fcport.vha = vha;
1755 vha->bidir_fcport.d_id.b.al_pa = vha->d_id.b.al_pa;
1756 vha->bidir_fcport.d_id.b.area = vha->d_id.b.area;
1757 vha->bidir_fcport.d_id.b.domain = vha->d_id.b.domain;
1758 vha->bidir_fcport.loop_id = vha->loop_id;
1759
1760 if (qla2x00_fabric_login(vha, &(vha->bidir_fcport), &nextlid)) {
1761 ql_log(ql_log_warn, vha, 0x70a7,
1762 "Failed to login port %06X for bidirectional IOCB\n",
1763 vha->bidir_fcport.d_id.b24);
1764 mutex_unlock(&ha->selflogin_lock);
1765 rval = EXT_STATUS_MAILBOX;
1766 goto done;
1767 }
1768 vha->self_login_loop_id = nextlid - 1;
1769
1770 }
1771 /* Assign the self login loop id to fcport */
1772 mutex_unlock(&ha->selflogin_lock);
1773
1774 vha->bidir_fcport.loop_id = vha->self_login_loop_id;
1775
1776 req_sg_cnt = dma_map_sg(&ha->pdev->dev,
1777 bsg_job->request_payload.sg_list,
1778 bsg_job->request_payload.sg_cnt,
1779 DMA_TO_DEVICE);
1780
1781 if (!req_sg_cnt) {
1782 rval = EXT_STATUS_NO_MEMORY;
1783 goto done;
1784 }
1785
1786 rsp_sg_cnt = dma_map_sg(&ha->pdev->dev,
1787 bsg_job->reply_payload.sg_list, bsg_job->reply_payload.sg_cnt,
1788 DMA_FROM_DEVICE);
1789
1790 if (!rsp_sg_cnt) {
1791 rval = EXT_STATUS_NO_MEMORY;
1792 goto done_unmap_req_sg;
1793 }
1794
1795 if ((req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
1796 (rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) {
1797 ql_dbg(ql_dbg_user, vha, 0x70a9,
1798 "Dma mapping resulted in different sg counts "
1799 "[request_sg_cnt: %x dma_request_sg_cnt: %x reply_sg_cnt: "
1800 "%x dma_reply_sg_cnt: %x]\n",
1801 bsg_job->request_payload.sg_cnt, req_sg_cnt,
1802 bsg_job->reply_payload.sg_cnt, rsp_sg_cnt);
1803 rval = EXT_STATUS_NO_MEMORY;
1804 goto done_unmap_sg;
1805 }
1806
1807 if (req_data_len != rsp_data_len) {
1808 rval = EXT_STATUS_BUSY;
1809 ql_log(ql_log_warn, vha, 0x70aa,
1810 "req_data_len != rsp_data_len\n");
1811 goto done_unmap_sg;
1812 }
1813
1814 req_data_len = bsg_job->request_payload.payload_len;
1815 rsp_data_len = bsg_job->reply_payload.payload_len;
1816
1817
1818 /* Alloc SRB structure */
1819 sp = qla2x00_get_sp(vha, &(vha->bidir_fcport), GFP_KERNEL);
1820 if (!sp) {
1821 ql_dbg(ql_dbg_user, vha, 0x70ac,
1822 "Alloc SRB structure failed\n");
1823 rval = EXT_STATUS_NO_MEMORY;
1824 goto done_unmap_sg;
1825 }
1826
1827 /*Populate srb->ctx with bidir ctx*/
1828 sp->u.bsg_job = bsg_job;
1829 sp->free = qla2x00_bsg_sp_free;
1830 sp->type = SRB_BIDI_CMD;
1831 sp->done = qla2x00_bsg_job_done;
1832
1833 /* Add the read and write sg count */
1834 tot_dsds = rsp_sg_cnt + req_sg_cnt;
1835
1836 rval = qla2x00_start_bidir(sp, vha, tot_dsds);
1837 if (rval != EXT_STATUS_OK)
1838 goto done_free_srb;
1839 /* the bsg request will be completed in the interrupt handler */
1840 return rval;
1841
1842done_free_srb:
1843 mempool_free(sp, ha->srb_mempool);
1844done_unmap_sg:
1845 dma_unmap_sg(&ha->pdev->dev,
1846 bsg_job->reply_payload.sg_list,
1847 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
1848done_unmap_req_sg:
1849 dma_unmap_sg(&ha->pdev->dev,
1850 bsg_job->request_payload.sg_list,
1851 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
1852done:
1853
1854 /* Return an error vendor specific response
1855 * and complete the bsg request
1856 */
1857 bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = rval;
1858 bsg_job->reply_len = sizeof(struct fc_bsg_reply);
1859 bsg_job->reply->reply_payload_rcv_len = 0;
1860 bsg_job->reply->result = (DID_OK) << 16;
1861 bsg_job->job_done(bsg_job);
1862 /* Always retrun success, vendor rsp carries correct status */
1863 return 0;
1864}
1865
1866static int
Giridhar Malavali6e980162010-03-19 17:03:58 -07001867qla2x00_process_vendor_specific(struct fc_bsg_job *bsg_job)
1868{
1869 switch (bsg_job->request->rqst_data.h_vendor.vendor_cmd[0]) {
1870 case QL_VND_LOOPBACK:
1871 return qla2x00_process_loopback(bsg_job);
1872
1873 case QL_VND_A84_RESET:
1874 return qla84xx_reset(bsg_job);
1875
1876 case QL_VND_A84_UPDATE_FW:
1877 return qla84xx_updatefw(bsg_job);
1878
1879 case QL_VND_A84_MGMT_CMD:
1880 return qla84xx_mgmt_cmd(bsg_job);
1881
1882 case QL_VND_IIDMA:
1883 return qla24xx_iidma(bsg_job);
1884
Sarang Radke09ff7012010-03-19 17:03:59 -07001885 case QL_VND_FCP_PRIO_CFG_CMD:
1886 return qla24xx_proc_fcp_prio_cfg_cmd(bsg_job);
1887
Harish Zunjarraof19af162010-10-15 11:27:43 -07001888 case QL_VND_READ_FLASH:
1889 return qla2x00_read_optrom(bsg_job);
1890
1891 case QL_VND_UPDATE_FLASH:
1892 return qla2x00_update_optrom(bsg_job);
1893
Joe Carnuccio697a4bc2011-08-16 11:31:52 -07001894 case QL_VND_SET_FRU_VERSION:
1895 return qla2x00_update_fru_versions(bsg_job);
1896
1897 case QL_VND_READ_FRU_STATUS:
1898 return qla2x00_read_fru_status(bsg_job);
1899
1900 case QL_VND_WRITE_FRU_STATUS:
1901 return qla2x00_write_fru_status(bsg_job);
1902
Joe Carnuccio9ebb5d92012-08-22 14:20:56 -04001903 case QL_VND_WRITE_I2C:
1904 return qla2x00_write_i2c(bsg_job);
1905
1906 case QL_VND_READ_I2C:
1907 return qla2x00_read_i2c(bsg_job);
1908
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04001909 case QL_VND_DIAG_IO_CMD:
1910 return qla24xx_process_bidir_cmd(bsg_job);
1911
Giridhar Malavali6e980162010-03-19 17:03:58 -07001912 default:
Giridhar Malavali6e980162010-03-19 17:03:58 -07001913 return -ENOSYS;
1914 }
1915}
1916
1917int
1918qla24xx_bsg_request(struct fc_bsg_job *bsg_job)
1919{
1920 int ret = -EINVAL;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001921 struct fc_rport *rport;
1922 fc_port_t *fcport = NULL;
1923 struct Scsi_Host *host;
1924 scsi_qla_host_t *vha;
1925
Andrew Vasquezb7bfbe12012-02-09 11:15:44 -08001926 /* In case no data transferred. */
1927 bsg_job->reply->reply_payload_rcv_len = 0;
1928
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001929 if (bsg_job->request->msgcode == FC_BSG_RPT_ELS) {
1930 rport = bsg_job->rport;
1931 fcport = *(fc_port_t **) rport->dd_data;
1932 host = rport_to_shost(rport);
1933 vha = shost_priv(host);
1934 } else {
1935 host = bsg_job->shost;
1936 vha = shost_priv(host);
1937 }
1938
Andrew Vasquezd051a5aa2012-02-09 11:14:05 -08001939 if (qla2x00_reset_active(vha)) {
1940 ql_dbg(ql_dbg_user, vha, 0x709f,
1941 "BSG: ISP abort active/needed -- cmd=%d.\n",
1942 bsg_job->request->msgcode);
Andrew Vasquezd051a5aa2012-02-09 11:14:05 -08001943 return -EBUSY;
1944 }
1945
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001946 ql_dbg(ql_dbg_user, vha, 0x7000,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001947 "Entered %s msgcode=0x%x.\n", __func__, bsg_job->request->msgcode);
Giridhar Malavali6e980162010-03-19 17:03:58 -07001948
1949 switch (bsg_job->request->msgcode) {
1950 case FC_BSG_RPT_ELS:
1951 case FC_BSG_HST_ELS_NOLOGIN:
1952 ret = qla2x00_process_els(bsg_job);
1953 break;
1954 case FC_BSG_HST_CT:
1955 ret = qla2x00_process_ct(bsg_job);
1956 break;
1957 case FC_BSG_HST_VENDOR:
1958 ret = qla2x00_process_vendor_specific(bsg_job);
1959 break;
1960 case FC_BSG_HST_ADD_RPORT:
1961 case FC_BSG_HST_DEL_RPORT:
1962 case FC_BSG_RPT_CT:
1963 default:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001964 ql_log(ql_log_warn, vha, 0x705a, "Unsupported BSG request.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -07001965 break;
Andrew Vasquez6c452a42010-03-19 17:04:02 -07001966 }
Giridhar Malavali6e980162010-03-19 17:03:58 -07001967 return ret;
1968}
1969
1970int
1971qla24xx_bsg_timeout(struct fc_bsg_job *bsg_job)
1972{
1973 scsi_qla_host_t *vha = shost_priv(bsg_job->shost);
1974 struct qla_hw_data *ha = vha->hw;
1975 srb_t *sp;
1976 int cnt, que;
1977 unsigned long flags;
1978 struct req_que *req;
Giridhar Malavali6e980162010-03-19 17:03:58 -07001979
1980 /* find the bsg job from the active list of commands */
1981 spin_lock_irqsave(&ha->hardware_lock, flags);
1982 for (que = 0; que < ha->max_req_queues; que++) {
1983 req = ha->req_q_map[que];
1984 if (!req)
1985 continue;
1986
Chad Dupuis8d93f552013-01-30 03:34:37 -05001987 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) {
Giridhar Malavali6e980162010-03-19 17:03:58 -07001988 sp = req->outstanding_cmds[cnt];
Giridhar Malavali6e980162010-03-19 17:03:58 -07001989 if (sp) {
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001990 if (((sp->type == SRB_CT_CMD) ||
1991 (sp->type == SRB_ELS_CMD_HST))
1992 && (sp->u.bsg_job == bsg_job)) {
Giridhar Malavali900a36e2010-12-21 16:00:26 -08001993 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Giridhar Malavali6e980162010-03-19 17:03:58 -07001994 if (ha->isp_ops->abort_command(sp)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001995 ql_log(ql_log_warn, vha, 0x7089,
1996 "mbx abort_command "
1997 "failed.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -07001998 bsg_job->req->errors =
1999 bsg_job->reply->result = -EIO;
2000 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002001 ql_dbg(ql_dbg_user, vha, 0x708a,
2002 "mbx abort_command "
2003 "success.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -07002004 bsg_job->req->errors =
2005 bsg_job->reply->result = 0;
2006 }
Giridhar Malavali900a36e2010-12-21 16:00:26 -08002007 spin_lock_irqsave(&ha->hardware_lock, flags);
Giridhar Malavali6e980162010-03-19 17:03:58 -07002008 goto done;
2009 }
2010 }
2011 }
2012 }
2013 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002014 ql_log(ql_log_info, vha, 0x708b, "SRB not found to abort.\n");
Giridhar Malavali6e980162010-03-19 17:03:58 -07002015 bsg_job->req->errors = bsg_job->reply->result = -ENXIO;
2016 return 0;
2017
2018done:
2019 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2020 if (bsg_job->request->msgcode == FC_BSG_HST_CT)
2021 kfree(sp->fcport);
Chad Dupuisb00ee7d2013-02-08 01:57:50 -05002022 qla2x00_rel_sp(vha, sp);
Giridhar Malavali6e980162010-03-19 17:03:58 -07002023 return 0;
2024}