]>
Commit | Line | Data |
---|---|---|
6e98016c GM |
1 | /* |
2 | * QLogic Fibre Channel HBA Driver | |
07e264b7 | 3 | * Copyright (c) 2003-2011 QLogic Corporation |
6e98016c GM |
4 | * |
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 */ | |
9ba56b95 GM |
14 | void |
15 | qla2x00_bsg_job_done(void *data, void *ptr, int res) | |
6e98016c | 16 | { |
9ba56b95 GM |
17 | 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 | ||
26 | void | |
27 | qla2x00_bsg_sp_free(void *data, void *ptr) | |
28 | { | |
29 | srb_t *sp = (srb_t *)ptr; | |
30 | struct scsi_qla_host *vha = (scsi_qla_host_t *)data; | |
31 | struct fc_bsg_job *bsg_job = sp->u.bsg_job; | |
6e98016c | 32 | struct qla_hw_data *ha = vha->hw; |
6e98016c | 33 | |
9ba56b95 GM |
34 | dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list, |
35 | bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE); | |
6e98016c | 36 | |
9ba56b95 GM |
37 | 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); | |
43 | mempool_free(sp, vha->hw->srb_mempool); | |
6e98016c GM |
44 | } |
45 | ||
09ff701a | 46 | int |
7c3df132 SK |
47 | qla24xx_fcp_prio_cfg_valid(scsi_qla_host_t *vha, |
48 | struct qla_fcp_prio_cfg *pri_cfg, uint8_t flag) | |
09ff701a SR |
49 | { |
50 | int i, ret, num_valid; | |
51 | uint8_t *bcode; | |
52 | struct qla_fcp_prio_entry *pri_entry; | |
2f0f3f4f | 53 | uint32_t *bcode_val_ptr, bcode_val; |
09ff701a SR |
54 | |
55 | ret = 1; | |
56 | num_valid = 0; | |
57 | bcode = (uint8_t *)pri_cfg; | |
2f0f3f4f MI |
58 | bcode_val_ptr = (uint32_t *)pri_cfg; |
59 | bcode_val = (uint32_t)(*bcode_val_ptr); | |
09ff701a | 60 | |
2f0f3f4f MI |
61 | if (bcode_val == 0xFFFFFFFF) { |
62 | /* No FCP Priority config data in flash */ | |
7c3df132 SK |
63 | ql_dbg(ql_dbg_user, vha, 0x7051, |
64 | "No FCP Priority config data.\n"); | |
2f0f3f4f MI |
65 | 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*/ | |
7c3df132 SK |
71 | ql_dbg(ql_dbg_user, vha, 0x7052, |
72 | "Invalid FCP Priority data header. bcode=0x%x.\n", | |
73 | bcode_val); | |
09ff701a SR |
74 | 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 | ||
2f0f3f4f MI |
86 | if (num_valid == 0) { |
87 | /* No valid FCP priority data entries */ | |
7c3df132 SK |
88 | ql_dbg(ql_dbg_user, vha, 0x7053, |
89 | "No valid FCP Priority data entries.\n"); | |
09ff701a | 90 | ret = 0; |
2f0f3f4f MI |
91 | } else { |
92 | /* FCP priority data is valid */ | |
7c3df132 SK |
93 | ql_dbg(ql_dbg_user, vha, 0x7054, |
94 | "Valid FCP priority data. num entries = %d.\n", | |
95 | num_valid); | |
2f0f3f4f | 96 | } |
09ff701a SR |
97 | |
98 | return ret; | |
99 | } | |
100 | ||
101 | static int | |
102 | qla24xx_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 | ||
a00f6296 | 111 | if (!(IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha) || IS_QLA82XX(ha))) { |
2f0f3f4f MI |
112 | ret = -EINVAL; |
113 | goto exit_fcp_prio_cfg; | |
114 | } | |
115 | ||
09ff701a SR |
116 | /* 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) { | |
7c3df132 SK |
183 | ql_log(ql_log_warn, vha, 0x7050, |
184 | "Unable to allocate memory for fcp prio " | |
185 | "config data (%x).\n", FCP_PRIO_CFG_SIZE); | |
09ff701a SR |
186 | 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 */ | |
7c3df132 SK |
198 | |
199 | if (!qla24xx_fcp_prio_cfg_valid(vha, | |
200 | (struct qla_fcp_prio_cfg *) ha->fcp_prio_cfg, 1)) { | |
09ff701a SR |
201 | 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 | } | |
221 | exit_fcp_prio_cfg: | |
222 | bsg_job->job_done(bsg_job); | |
223 | return ret; | |
224 | } | |
9ba56b95 | 225 | |
6e98016c GM |
226 | static int |
227 | qla2x00_process_els(struct fc_bsg_job *bsg_job) | |
228 | { | |
229 | struct fc_rport *rport; | |
08f71e09 | 230 | fc_port_t *fcport = NULL; |
6e98016c GM |
231 | struct Scsi_Host *host; |
232 | scsi_qla_host_t *vha; | |
233 | struct qla_hw_data *ha; | |
234 | srb_t *sp; | |
235 | const char *type; | |
236 | int req_sg_cnt, rsp_sg_cnt; | |
237 | int rval = (DRIVER_ERROR << 16); | |
238 | uint16_t nextlid = 0; | |
6e98016c | 239 | |
08f71e09 HZ |
240 | if (bsg_job->request->msgcode == FC_BSG_RPT_ELS) { |
241 | rport = bsg_job->rport; | |
242 | fcport = *(fc_port_t **) rport->dd_data; | |
243 | host = rport_to_shost(rport); | |
244 | vha = shost_priv(host); | |
245 | ha = vha->hw; | |
246 | type = "FC_BSG_RPT_ELS"; | |
247 | } else { | |
248 | host = bsg_job->shost; | |
249 | vha = shost_priv(host); | |
250 | ha = vha->hw; | |
251 | type = "FC_BSG_HST_ELS_NOLOGIN"; | |
252 | } | |
253 | ||
254 | /* pass through is supported only for ISP 4Gb or higher */ | |
255 | if (!IS_FWI2_CAPABLE(ha)) { | |
7c3df132 SK |
256 | ql_dbg(ql_dbg_user, vha, 0x7001, |
257 | "ELS passthru not supported for ISP23xx based adapters.\n"); | |
08f71e09 HZ |
258 | rval = -EPERM; |
259 | goto done; | |
260 | } | |
261 | ||
6e98016c GM |
262 | /* Multiple SG's are not supported for ELS requests */ |
263 | if (bsg_job->request_payload.sg_cnt > 1 || | |
264 | bsg_job->reply_payload.sg_cnt > 1) { | |
7c3df132 SK |
265 | ql_dbg(ql_dbg_user, vha, 0x7002, |
266 | "Multiple SG's are not suppored for ELS requests, " | |
267 | "request_sg_cnt=%x reply_sg_cnt=%x.\n", | |
268 | bsg_job->request_payload.sg_cnt, | |
269 | bsg_job->reply_payload.sg_cnt); | |
6e98016c GM |
270 | rval = -EPERM; |
271 | goto done; | |
272 | } | |
273 | ||
274 | /* ELS request for rport */ | |
275 | if (bsg_job->request->msgcode == FC_BSG_RPT_ELS) { | |
6e98016c GM |
276 | /* make sure the rport is logged in, |
277 | * if not perform fabric login | |
278 | */ | |
279 | if (qla2x00_fabric_login(vha, fcport, &nextlid)) { | |
7c3df132 SK |
280 | ql_dbg(ql_dbg_user, vha, 0x7003, |
281 | "Failed to login port %06X for ELS passthru.\n", | |
282 | fcport->d_id.b24); | |
6e98016c GM |
283 | rval = -EIO; |
284 | goto done; | |
285 | } | |
286 | } else { | |
6e98016c GM |
287 | /* Allocate a dummy fcport structure, since functions |
288 | * preparing the IOCB and mailbox command retrieves port | |
289 | * specific information from fcport structure. For Host based | |
290 | * ELS commands there will be no fcport structure allocated | |
291 | */ | |
292 | fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); | |
293 | if (!fcport) { | |
294 | rval = -ENOMEM; | |
295 | goto done; | |
296 | } | |
297 | ||
298 | /* Initialize all required fields of fcport */ | |
299 | fcport->vha = vha; | |
6e98016c GM |
300 | fcport->d_id.b.al_pa = |
301 | bsg_job->request->rqst_data.h_els.port_id[0]; | |
302 | fcport->d_id.b.area = | |
303 | bsg_job->request->rqst_data.h_els.port_id[1]; | |
304 | fcport->d_id.b.domain = | |
305 | bsg_job->request->rqst_data.h_els.port_id[2]; | |
306 | fcport->loop_id = | |
307 | (fcport->d_id.b.al_pa == 0xFD) ? | |
308 | NPH_FABRIC_CONTROLLER : NPH_F_PORT; | |
309 | } | |
310 | ||
311 | if (!vha->flags.online) { | |
7c3df132 | 312 | ql_log(ql_log_warn, vha, 0x7005, "Host not online.\n"); |
6e98016c GM |
313 | rval = -EIO; |
314 | goto done; | |
315 | } | |
316 | ||
317 | req_sg_cnt = | |
318 | dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list, | |
319 | bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE); | |
320 | if (!req_sg_cnt) { | |
321 | rval = -ENOMEM; | |
322 | goto done_free_fcport; | |
323 | } | |
6c452a45 AV |
324 | |
325 | rsp_sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list, | |
326 | bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE); | |
6e98016c GM |
327 | if (!rsp_sg_cnt) { |
328 | rval = -ENOMEM; | |
329 | goto done_free_fcport; | |
330 | } | |
331 | ||
332 | if ((req_sg_cnt != bsg_job->request_payload.sg_cnt) || | |
6c452a45 | 333 | (rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) { |
7c3df132 SK |
334 | ql_log(ql_log_warn, vha, 0x7008, |
335 | "dma mapping resulted in different sg counts, " | |
336 | "request_sg_cnt: %x dma_request_sg_cnt:%x reply_sg_cnt:%x " | |
337 | "dma_reply_sg_cnt:%x.\n", bsg_job->request_payload.sg_cnt, | |
338 | req_sg_cnt, bsg_job->reply_payload.sg_cnt, rsp_sg_cnt); | |
6e98016c GM |
339 | rval = -EAGAIN; |
340 | goto done_unmap_sg; | |
341 | } | |
342 | ||
343 | /* Alloc SRB structure */ | |
9ba56b95 | 344 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
6e98016c GM |
345 | if (!sp) { |
346 | rval = -ENOMEM; | |
6c452a45 | 347 | goto done_unmap_sg; |
6e98016c GM |
348 | } |
349 | ||
9ba56b95 | 350 | sp->type = |
6e98016c GM |
351 | (bsg_job->request->msgcode == FC_BSG_RPT_ELS ? |
352 | SRB_ELS_CMD_RPT : SRB_ELS_CMD_HST); | |
9ba56b95 | 353 | sp->name = |
3822263e MI |
354 | (bsg_job->request->msgcode == FC_BSG_RPT_ELS ? |
355 | "bsg_els_rpt" : "bsg_els_hst"); | |
9ba56b95 GM |
356 | sp->u.bsg_job = bsg_job; |
357 | sp->free = qla2x00_bsg_sp_free; | |
358 | sp->done = qla2x00_bsg_job_done; | |
6e98016c | 359 | |
7c3df132 SK |
360 | ql_dbg(ql_dbg_user, vha, 0x700a, |
361 | "bsg rqst type: %s els type: %x - loop-id=%x " | |
362 | "portid=%-2x%02x%02x.\n", type, | |
363 | bsg_job->request->rqst_data.h_els.command_code, fcport->loop_id, | |
364 | fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa); | |
6e98016c GM |
365 | |
366 | rval = qla2x00_start_sp(sp); | |
367 | if (rval != QLA_SUCCESS) { | |
7c3df132 SK |
368 | ql_log(ql_log_warn, vha, 0x700e, |
369 | "qla2x00_start_sp failed = %d\n", rval); | |
6e98016c GM |
370 | mempool_free(sp, ha->srb_mempool); |
371 | rval = -EIO; | |
372 | goto done_unmap_sg; | |
373 | } | |
374 | return rval; | |
375 | ||
376 | done_unmap_sg: | |
377 | dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list, | |
378 | bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE); | |
379 | dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list, | |
380 | bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE); | |
381 | goto done_free_fcport; | |
382 | ||
383 | done_free_fcport: | |
384 | if (bsg_job->request->msgcode == FC_BSG_HST_ELS_NOLOGIN) | |
385 | kfree(fcport); | |
386 | done: | |
387 | return rval; | |
388 | } | |
389 | ||
5780790e AV |
390 | inline uint16_t |
391 | qla24xx_calc_ct_iocbs(uint16_t dsds) | |
392 | { | |
393 | uint16_t iocbs; | |
394 | ||
395 | iocbs = 1; | |
396 | if (dsds > 2) { | |
397 | iocbs += (dsds - 2) / 5; | |
398 | if ((dsds - 2) % 5) | |
399 | iocbs++; | |
400 | } | |
401 | return iocbs; | |
402 | } | |
403 | ||
6e98016c GM |
404 | static int |
405 | qla2x00_process_ct(struct fc_bsg_job *bsg_job) | |
406 | { | |
407 | srb_t *sp; | |
408 | struct Scsi_Host *host = bsg_job->shost; | |
409 | scsi_qla_host_t *vha = shost_priv(host); | |
410 | struct qla_hw_data *ha = vha->hw; | |
411 | int rval = (DRIVER_ERROR << 16); | |
412 | int req_sg_cnt, rsp_sg_cnt; | |
413 | uint16_t loop_id; | |
414 | struct fc_port *fcport; | |
415 | char *type = "FC_BSG_HST_CT"; | |
6e98016c | 416 | |
6e98016c GM |
417 | req_sg_cnt = |
418 | dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list, | |
419 | bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE); | |
6c452a45 | 420 | if (!req_sg_cnt) { |
7c3df132 SK |
421 | ql_log(ql_log_warn, vha, 0x700f, |
422 | "dma_map_sg return %d for request\n", req_sg_cnt); | |
6e98016c GM |
423 | rval = -ENOMEM; |
424 | goto done; | |
425 | } | |
426 | ||
427 | rsp_sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list, | |
428 | bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE); | |
429 | if (!rsp_sg_cnt) { | |
7c3df132 SK |
430 | ql_log(ql_log_warn, vha, 0x7010, |
431 | "dma_map_sg return %d for reply\n", rsp_sg_cnt); | |
6e98016c GM |
432 | rval = -ENOMEM; |
433 | goto done; | |
434 | } | |
435 | ||
436 | if ((req_sg_cnt != bsg_job->request_payload.sg_cnt) || | |
6c452a45 | 437 | (rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) { |
7c3df132 SK |
438 | ql_log(ql_log_warn, vha, 0x7011, |
439 | "request_sg_cnt: %x dma_request_sg_cnt: %x reply_sg_cnt:%x " | |
440 | "dma_reply_sg_cnt: %x\n", bsg_job->request_payload.sg_cnt, | |
441 | req_sg_cnt, bsg_job->reply_payload.sg_cnt, rsp_sg_cnt); | |
6e98016c | 442 | rval = -EAGAIN; |
6c452a45 | 443 | goto done_unmap_sg; |
6e98016c GM |
444 | } |
445 | ||
446 | if (!vha->flags.online) { | |
7c3df132 SK |
447 | ql_log(ql_log_warn, vha, 0x7012, |
448 | "Host is not online.\n"); | |
6e98016c GM |
449 | rval = -EIO; |
450 | goto done_unmap_sg; | |
451 | } | |
452 | ||
453 | loop_id = | |
454 | (bsg_job->request->rqst_data.h_ct.preamble_word1 & 0xFF000000) | |
455 | >> 24; | |
456 | switch (loop_id) { | |
6c452a45 AV |
457 | case 0xFC: |
458 | loop_id = cpu_to_le16(NPH_SNS); | |
459 | break; | |
460 | case 0xFA: | |
461 | loop_id = vha->mgmt_svr_loop_id; | |
462 | break; | |
463 | default: | |
7c3df132 SK |
464 | ql_dbg(ql_dbg_user, vha, 0x7013, |
465 | "Unknown loop id: %x.\n", loop_id); | |
6c452a45 AV |
466 | rval = -EINVAL; |
467 | goto done_unmap_sg; | |
6e98016c GM |
468 | } |
469 | ||
470 | /* Allocate a dummy fcport structure, since functions preparing the | |
471 | * IOCB and mailbox command retrieves port specific information | |
472 | * from fcport structure. For Host based ELS commands there will be | |
473 | * no fcport structure allocated | |
474 | */ | |
475 | fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); | |
6c452a45 | 476 | if (!fcport) { |
7c3df132 SK |
477 | ql_log(ql_log_warn, vha, 0x7014, |
478 | "Failed to allocate fcport.\n"); | |
6e98016c | 479 | rval = -ENOMEM; |
6c452a45 | 480 | goto done_unmap_sg; |
6e98016c GM |
481 | } |
482 | ||
483 | /* Initialize all required fields of fcport */ | |
484 | fcport->vha = vha; | |
6e98016c GM |
485 | fcport->d_id.b.al_pa = bsg_job->request->rqst_data.h_ct.port_id[0]; |
486 | fcport->d_id.b.area = bsg_job->request->rqst_data.h_ct.port_id[1]; | |
487 | fcport->d_id.b.domain = bsg_job->request->rqst_data.h_ct.port_id[2]; | |
488 | fcport->loop_id = loop_id; | |
489 | ||
490 | /* Alloc SRB structure */ | |
9ba56b95 | 491 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
6e98016c | 492 | if (!sp) { |
7c3df132 | 493 | ql_log(ql_log_warn, vha, 0x7015, |
9ba56b95 | 494 | "qla2x00_get_sp failed.\n"); |
6e98016c GM |
495 | rval = -ENOMEM; |
496 | goto done_free_fcport; | |
497 | } | |
498 | ||
9ba56b95 GM |
499 | sp->type = SRB_CT_CMD; |
500 | sp->name = "bsg_ct"; | |
501 | sp->iocbs = qla24xx_calc_ct_iocbs(req_sg_cnt + rsp_sg_cnt); | |
502 | sp->u.bsg_job = bsg_job; | |
503 | sp->free = qla2x00_bsg_sp_free; | |
504 | sp->done = qla2x00_bsg_job_done; | |
6e98016c | 505 | |
7c3df132 SK |
506 | ql_dbg(ql_dbg_user, vha, 0x7016, |
507 | "bsg rqst type: %s else type: %x - " | |
508 | "loop-id=%x portid=%02x%02x%02x.\n", type, | |
509 | (bsg_job->request->rqst_data.h_ct.preamble_word2 >> 16), | |
510 | fcport->loop_id, fcport->d_id.b.domain, fcport->d_id.b.area, | |
511 | fcport->d_id.b.al_pa); | |
6e98016c GM |
512 | |
513 | rval = qla2x00_start_sp(sp); | |
514 | if (rval != QLA_SUCCESS) { | |
7c3df132 SK |
515 | ql_log(ql_log_warn, vha, 0x7017, |
516 | "qla2x00_start_sp failed=%d.\n", rval); | |
6e98016c GM |
517 | mempool_free(sp, ha->srb_mempool); |
518 | rval = -EIO; | |
519 | goto done_free_fcport; | |
520 | } | |
521 | return rval; | |
522 | ||
523 | done_free_fcport: | |
524 | kfree(fcport); | |
525 | done_unmap_sg: | |
526 | dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list, | |
527 | bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE); | |
528 | dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list, | |
529 | bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE); | |
530 | done: | |
531 | return rval; | |
532 | } | |
8fcd6b8b CD |
533 | /* |
534 | * Set the port configuration to enable the internal or external loopback | |
535 | * depending on the loopback mode. | |
23f2ebd1 SR |
536 | */ |
537 | static inline int | |
8fcd6b8b CD |
538 | qla81xx_set_loopback_mode(scsi_qla_host_t *vha, uint16_t *config, |
539 | uint16_t *new_config, uint16_t mode) | |
23f2ebd1 SR |
540 | { |
541 | int ret = 0; | |
542 | int rval = 0; | |
543 | struct qla_hw_data *ha = vha->hw; | |
544 | ||
f863f603 | 545 | if (!IS_QLA81XX(ha) && !IS_QLA8031(ha)) |
23f2ebd1 SR |
546 | goto done_set_internal; |
547 | ||
8fcd6b8b CD |
548 | if (mode == INTERNAL_LOOPBACK) |
549 | new_config[0] = config[0] | (ENABLE_INTERNAL_LOOPBACK << 1); | |
550 | else if (mode == EXTERNAL_LOOPBACK) | |
551 | new_config[0] = config[0] | (ENABLE_EXTERNAL_LOOPBACK << 1); | |
552 | ql_dbg(ql_dbg_user, vha, 0x70be, | |
553 | "new_config[0]=%02x\n", (new_config[0] & INTERNAL_LOOPBACK_MASK)); | |
554 | ||
555 | memcpy(&new_config[1], &config[1], sizeof(uint16_t) * 3); | |
23f2ebd1 SR |
556 | |
557 | ha->notify_dcbx_comp = 1; | |
558 | ret = qla81xx_set_port_config(vha, new_config); | |
559 | if (ret != QLA_SUCCESS) { | |
7c3df132 SK |
560 | ql_log(ql_log_warn, vha, 0x7021, |
561 | "set port config failed.\n"); | |
23f2ebd1 SR |
562 | ha->notify_dcbx_comp = 0; |
563 | rval = -EINVAL; | |
564 | goto done_set_internal; | |
565 | } | |
566 | ||
567 | /* Wait for DCBX complete event */ | |
568 | if (!wait_for_completion_timeout(&ha->dcbx_comp, (20 * HZ))) { | |
7c3df132 SK |
569 | ql_dbg(ql_dbg_user, vha, 0x7022, |
570 | "State change notification not received.\n"); | |
23f2ebd1 | 571 | } else |
7c3df132 SK |
572 | ql_dbg(ql_dbg_user, vha, 0x7023, |
573 | "State change received.\n"); | |
23f2ebd1 SR |
574 | |
575 | ha->notify_dcbx_comp = 0; | |
576 | ||
577 | done_set_internal: | |
578 | return rval; | |
579 | } | |
580 | ||
8fcd6b8b | 581 | /* Disable loopback mode */ |
23f2ebd1 | 582 | static inline int |
8fcd6b8b | 583 | qla81xx_reset_loopback_mode(scsi_qla_host_t *vha, uint16_t *config, |
23f2ebd1 SR |
584 | int wait) |
585 | { | |
586 | int ret = 0; | |
587 | int rval = 0; | |
588 | uint16_t new_config[4]; | |
589 | struct qla_hw_data *ha = vha->hw; | |
590 | ||
f863f603 | 591 | if (!IS_QLA81XX(ha) && !IS_QLA8031(ha)) |
23f2ebd1 SR |
592 | goto done_reset_internal; |
593 | ||
594 | memset(new_config, 0 , sizeof(new_config)); | |
595 | if ((config[0] & INTERNAL_LOOPBACK_MASK) >> 1 == | |
8fcd6b8b CD |
596 | ENABLE_INTERNAL_LOOPBACK || |
597 | (config[0] & INTERNAL_LOOPBACK_MASK) >> 1 == | |
598 | ENABLE_EXTERNAL_LOOPBACK) { | |
23f2ebd1 | 599 | new_config[0] = config[0] & ~INTERNAL_LOOPBACK_MASK; |
8fcd6b8b CD |
600 | ql_dbg(ql_dbg_user, vha, 0x70bf, "new_config[0]=%02x\n", |
601 | (new_config[0] & INTERNAL_LOOPBACK_MASK)); | |
23f2ebd1 SR |
602 | memcpy(&new_config[1], &config[1], sizeof(uint16_t) * 3) ; |
603 | ||
604 | ha->notify_dcbx_comp = wait; | |
605 | ret = qla81xx_set_port_config(vha, new_config); | |
606 | if (ret != QLA_SUCCESS) { | |
7c3df132 SK |
607 | ql_log(ql_log_warn, vha, 0x7025, |
608 | "Set port config failed.\n"); | |
23f2ebd1 SR |
609 | ha->notify_dcbx_comp = 0; |
610 | rval = -EINVAL; | |
611 | goto done_reset_internal; | |
612 | } | |
613 | ||
614 | /* Wait for DCBX complete event */ | |
615 | if (wait && !wait_for_completion_timeout(&ha->dcbx_comp, | |
616 | (20 * HZ))) { | |
7c3df132 SK |
617 | ql_dbg(ql_dbg_user, vha, 0x7026, |
618 | "State change notification not received.\n"); | |
23f2ebd1 SR |
619 | ha->notify_dcbx_comp = 0; |
620 | rval = -EINVAL; | |
621 | goto done_reset_internal; | |
622 | } else | |
7c3df132 SK |
623 | ql_dbg(ql_dbg_user, vha, 0x7027, |
624 | "State change received.\n"); | |
23f2ebd1 SR |
625 | |
626 | ha->notify_dcbx_comp = 0; | |
627 | } | |
628 | done_reset_internal: | |
629 | return rval; | |
630 | } | |
631 | ||
6e98016c GM |
632 | static int |
633 | qla2x00_process_loopback(struct fc_bsg_job *bsg_job) | |
634 | { | |
635 | struct Scsi_Host *host = bsg_job->shost; | |
636 | scsi_qla_host_t *vha = shost_priv(host); | |
637 | struct qla_hw_data *ha = vha->hw; | |
638 | int rval; | |
639 | uint8_t command_sent; | |
640 | char *type; | |
641 | struct msg_echo_lb elreq; | |
642 | uint16_t response[MAILBOX_REGISTER_COUNT]; | |
23f2ebd1 | 643 | uint16_t config[4], new_config[4]; |
6c452a45 | 644 | uint8_t *fw_sts_ptr; |
6e98016c GM |
645 | uint8_t *req_data = NULL; |
646 | dma_addr_t req_data_dma; | |
647 | uint32_t req_data_len; | |
648 | uint8_t *rsp_data = NULL; | |
649 | dma_addr_t rsp_data_dma; | |
650 | uint32_t rsp_data_len; | |
651 | ||
6e98016c | 652 | if (!vha->flags.online) { |
7c3df132 | 653 | ql_log(ql_log_warn, vha, 0x7019, "Host is not online.\n"); |
6e98016c GM |
654 | return -EIO; |
655 | } | |
656 | ||
657 | elreq.req_sg_cnt = dma_map_sg(&ha->pdev->dev, | |
658 | bsg_job->request_payload.sg_list, bsg_job->request_payload.sg_cnt, | |
659 | DMA_TO_DEVICE); | |
660 | ||
7c3df132 SK |
661 | if (!elreq.req_sg_cnt) { |
662 | ql_log(ql_log_warn, vha, 0x701a, | |
663 | "dma_map_sg returned %d for request.\n", elreq.req_sg_cnt); | |
6e98016c | 664 | return -ENOMEM; |
7c3df132 | 665 | } |
6e98016c GM |
666 | |
667 | elreq.rsp_sg_cnt = dma_map_sg(&ha->pdev->dev, | |
668 | bsg_job->reply_payload.sg_list, bsg_job->reply_payload.sg_cnt, | |
669 | DMA_FROM_DEVICE); | |
670 | ||
671 | if (!elreq.rsp_sg_cnt) { | |
7c3df132 SK |
672 | ql_log(ql_log_warn, vha, 0x701b, |
673 | "dma_map_sg returned %d for reply.\n", elreq.rsp_sg_cnt); | |
6e98016c GM |
674 | rval = -ENOMEM; |
675 | goto done_unmap_req_sg; | |
6c452a45 | 676 | } |
6e98016c GM |
677 | |
678 | if ((elreq.req_sg_cnt != bsg_job->request_payload.sg_cnt) || | |
679 | (elreq.rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) { | |
7c3df132 SK |
680 | ql_log(ql_log_warn, vha, 0x701c, |
681 | "dma mapping resulted in different sg counts, " | |
682 | "request_sg_cnt: %x dma_request_sg_cnt: %x " | |
683 | "reply_sg_cnt: %x dma_reply_sg_cnt: %x.\n", | |
684 | bsg_job->request_payload.sg_cnt, elreq.req_sg_cnt, | |
685 | bsg_job->reply_payload.sg_cnt, elreq.rsp_sg_cnt); | |
6e98016c GM |
686 | rval = -EAGAIN; |
687 | goto done_unmap_sg; | |
688 | } | |
689 | req_data_len = rsp_data_len = bsg_job->request_payload.payload_len; | |
690 | req_data = dma_alloc_coherent(&ha->pdev->dev, req_data_len, | |
691 | &req_data_dma, GFP_KERNEL); | |
692 | if (!req_data) { | |
7c3df132 SK |
693 | ql_log(ql_log_warn, vha, 0x701d, |
694 | "dma alloc failed for req_data.\n"); | |
6e98016c GM |
695 | rval = -ENOMEM; |
696 | goto done_unmap_sg; | |
697 | } | |
698 | ||
699 | rsp_data = dma_alloc_coherent(&ha->pdev->dev, rsp_data_len, | |
700 | &rsp_data_dma, GFP_KERNEL); | |
701 | if (!rsp_data) { | |
7c3df132 SK |
702 | ql_log(ql_log_warn, vha, 0x7004, |
703 | "dma alloc failed for rsp_data.\n"); | |
6e98016c GM |
704 | rval = -ENOMEM; |
705 | goto done_free_dma_req; | |
706 | } | |
707 | ||
708 | /* Copy the request buffer in req_data now */ | |
709 | sg_copy_to_buffer(bsg_job->request_payload.sg_list, | |
710 | bsg_job->request_payload.sg_cnt, req_data, req_data_len); | |
711 | ||
712 | elreq.send_dma = req_data_dma; | |
713 | elreq.rcv_dma = rsp_data_dma; | |
714 | elreq.transfer_size = req_data_len; | |
715 | ||
716 | elreq.options = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1]; | |
717 | ||
8fcd6b8b CD |
718 | if (atomic_read(&vha->loop_state) == LOOP_READY && |
719 | (ha->current_topology == ISP_CFG_F || | |
f863f603 | 720 | ((IS_QLA81XX(ha) || IS_QLA8031(ha)) && |
23f2ebd1 SR |
721 | le32_to_cpu(*(uint32_t *)req_data) == ELS_OPCODE_BYTE |
722 | && req_data_len == MAX_ELS_FRAME_PAYLOAD)) && | |
723 | elreq.options == EXTERNAL_LOOPBACK) { | |
724 | type = "FC_BSG_HST_VENDOR_ECHO_DIAG"; | |
7c3df132 SK |
725 | ql_dbg(ql_dbg_user, vha, 0x701e, |
726 | "BSG request type: %s.\n", type); | |
23f2ebd1 SR |
727 | command_sent = INT_DEF_LB_ECHO_CMD; |
728 | rval = qla2x00_echo_test(vha, &elreq, response); | |
729 | } else { | |
6246b8a1 | 730 | if (IS_QLA81XX(ha) || IS_QLA8031(ha)) { |
23f2ebd1 SR |
731 | memset(config, 0, sizeof(config)); |
732 | memset(new_config, 0, sizeof(new_config)); | |
733 | if (qla81xx_get_port_config(vha, config)) { | |
7c3df132 SK |
734 | ql_log(ql_log_warn, vha, 0x701f, |
735 | "Get port config failed.\n"); | |
23f2ebd1 SR |
736 | bsg_job->reply->result = (DID_ERROR << 16); |
737 | rval = -EPERM; | |
738 | goto done_free_dma_req; | |
739 | } | |
740 | ||
8fcd6b8b CD |
741 | ql_dbg(ql_dbg_user, vha, 0x70c0, |
742 | "elreq.options=%04x\n", elreq.options); | |
743 | ||
744 | if (elreq.options == EXTERNAL_LOOPBACK) | |
745 | if (IS_QLA8031(ha)) | |
746 | rval = qla81xx_set_loopback_mode(vha, | |
747 | config, new_config, elreq.options); | |
748 | else | |
749 | rval = qla81xx_reset_loopback_mode(vha, | |
750 | config, 1); | |
751 | else | |
752 | rval = qla81xx_set_loopback_mode(vha, config, | |
753 | new_config, elreq.options); | |
754 | ||
755 | if (rval) { | |
756 | bsg_job->reply->result = (DID_ERROR << 16); | |
757 | rval = -EPERM; | |
758 | goto done_free_dma_req; | |
23f2ebd1 SR |
759 | } |
760 | ||
761 | type = "FC_BSG_HST_VENDOR_LOOPBACK"; | |
7c3df132 SK |
762 | ql_dbg(ql_dbg_user, vha, 0x7028, |
763 | "BSG request type: %s.\n", type); | |
23f2ebd1 SR |
764 | |
765 | command_sent = INT_DEF_LB_LOOPBACK_CMD; | |
766 | rval = qla2x00_loopback_test(vha, &elreq, response); | |
767 | ||
4052bd57 | 768 | if (new_config[0]) { |
23f2ebd1 SR |
769 | /* Revert back to original port config |
770 | * Also clear internal loopback | |
771 | */ | |
8fcd6b8b | 772 | qla81xx_reset_loopback_mode(vha, |
23f2ebd1 SR |
773 | new_config, 0); |
774 | } | |
775 | ||
6e98016c | 776 | if (response[0] == MBS_COMMAND_ERROR && |
23f2ebd1 | 777 | response[1] == MBS_LB_RESET) { |
7c3df132 SK |
778 | ql_log(ql_log_warn, vha, 0x7029, |
779 | "MBX command error, Aborting ISP.\n"); | |
6e98016c GM |
780 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
781 | qla2xxx_wake_dpc(vha); | |
23f2ebd1 SR |
782 | qla2x00_wait_for_chip_reset(vha); |
783 | /* Also reset the MPI */ | |
784 | if (qla81xx_restart_mpi_firmware(vha) != | |
785 | QLA_SUCCESS) { | |
7c3df132 SK |
786 | ql_log(ql_log_warn, vha, 0x702a, |
787 | "MPI reset failed.\n"); | |
23f2ebd1 SR |
788 | } |
789 | ||
23f2ebd1 SR |
790 | bsg_job->reply->result = (DID_ERROR << 16); |
791 | rval = -EIO; | |
792 | goto done_free_dma_req; | |
6e98016c | 793 | } |
23f2ebd1 SR |
794 | } else { |
795 | type = "FC_BSG_HST_VENDOR_LOOPBACK"; | |
7c3df132 SK |
796 | ql_dbg(ql_dbg_user, vha, 0x702b, |
797 | "BSG request type: %s.\n", type); | |
23f2ebd1 SR |
798 | command_sent = INT_DEF_LB_LOOPBACK_CMD; |
799 | rval = qla2x00_loopback_test(vha, &elreq, response); | |
6e98016c | 800 | } |
6e98016c GM |
801 | } |
802 | ||
803 | if (rval) { | |
7c3df132 SK |
804 | ql_log(ql_log_warn, vha, 0x702c, |
805 | "Vendor request %s failed.\n", type); | |
6e98016c GM |
806 | |
807 | fw_sts_ptr = ((uint8_t *)bsg_job->req->sense) + | |
6c452a45 | 808 | sizeof(struct fc_bsg_reply); |
6e98016c GM |
809 | |
810 | memcpy(fw_sts_ptr, response, sizeof(response)); | |
811 | fw_sts_ptr += sizeof(response); | |
6c452a45 | 812 | *fw_sts_ptr = command_sent; |
6e98016c | 813 | rval = 0; |
6e98016c GM |
814 | bsg_job->reply->result = (DID_ERROR << 16); |
815 | } else { | |
7c3df132 SK |
816 | ql_dbg(ql_dbg_user, vha, 0x702d, |
817 | "Vendor request %s completed.\n", type); | |
6e98016c GM |
818 | |
819 | bsg_job->reply_len = sizeof(struct fc_bsg_reply) + | |
820 | sizeof(response) + sizeof(uint8_t); | |
821 | bsg_job->reply->reply_payload_rcv_len = | |
822 | bsg_job->reply_payload.payload_len; | |
823 | fw_sts_ptr = ((uint8_t *)bsg_job->req->sense) + | |
824 | sizeof(struct fc_bsg_reply); | |
825 | memcpy(fw_sts_ptr, response, sizeof(response)); | |
826 | fw_sts_ptr += sizeof(response); | |
827 | *fw_sts_ptr = command_sent; | |
828 | bsg_job->reply->result = DID_OK; | |
829 | sg_copy_from_buffer(bsg_job->reply_payload.sg_list, | |
830 | bsg_job->reply_payload.sg_cnt, rsp_data, | |
831 | rsp_data_len); | |
832 | } | |
833 | bsg_job->job_done(bsg_job); | |
834 | ||
835 | dma_free_coherent(&ha->pdev->dev, rsp_data_len, | |
836 | rsp_data, rsp_data_dma); | |
837 | done_free_dma_req: | |
838 | dma_free_coherent(&ha->pdev->dev, req_data_len, | |
839 | req_data, req_data_dma); | |
840 | done_unmap_sg: | |
841 | dma_unmap_sg(&ha->pdev->dev, | |
842 | bsg_job->reply_payload.sg_list, | |
843 | bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE); | |
844 | done_unmap_req_sg: | |
845 | dma_unmap_sg(&ha->pdev->dev, | |
846 | bsg_job->request_payload.sg_list, | |
847 | bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE); | |
6c452a45 | 848 | return rval; |
6e98016c GM |
849 | } |
850 | ||
851 | static int | |
852 | qla84xx_reset(struct fc_bsg_job *bsg_job) | |
853 | { | |
854 | struct Scsi_Host *host = bsg_job->shost; | |
855 | scsi_qla_host_t *vha = shost_priv(host); | |
856 | struct qla_hw_data *ha = vha->hw; | |
857 | int rval = 0; | |
858 | uint32_t flag; | |
859 | ||
6e98016c | 860 | if (!IS_QLA84XX(ha)) { |
7c3df132 | 861 | ql_dbg(ql_dbg_user, vha, 0x702f, "Not 84xx, exiting.\n"); |
6e98016c GM |
862 | return -EINVAL; |
863 | } | |
864 | ||
865 | flag = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1]; | |
866 | ||
867 | rval = qla84xx_reset_chip(vha, flag == A84_ISSUE_RESET_DIAG_FW); | |
868 | ||
869 | if (rval) { | |
7c3df132 SK |
870 | ql_log(ql_log_warn, vha, 0x7030, |
871 | "Vendor request 84xx reset failed.\n"); | |
b7bfbe12 | 872 | rval = 0; |
6e98016c GM |
873 | bsg_job->reply->result = (DID_ERROR << 16); |
874 | ||
875 | } else { | |
7c3df132 SK |
876 | ql_dbg(ql_dbg_user, vha, 0x7031, |
877 | "Vendor request 84xx reset completed.\n"); | |
6e98016c GM |
878 | bsg_job->reply->result = DID_OK; |
879 | } | |
880 | ||
881 | bsg_job->job_done(bsg_job); | |
882 | return rval; | |
883 | } | |
884 | ||
885 | static int | |
886 | qla84xx_updatefw(struct fc_bsg_job *bsg_job) | |
887 | { | |
888 | struct Scsi_Host *host = bsg_job->shost; | |
889 | scsi_qla_host_t *vha = shost_priv(host); | |
890 | struct qla_hw_data *ha = vha->hw; | |
891 | struct verify_chip_entry_84xx *mn = NULL; | |
892 | dma_addr_t mn_dma, fw_dma; | |
893 | void *fw_buf = NULL; | |
894 | int rval = 0; | |
895 | uint32_t sg_cnt; | |
896 | uint32_t data_len; | |
897 | uint16_t options; | |
898 | uint32_t flag; | |
899 | uint32_t fw_ver; | |
900 | ||
6e98016c | 901 | if (!IS_QLA84XX(ha)) { |
7c3df132 SK |
902 | ql_dbg(ql_dbg_user, vha, 0x7032, |
903 | "Not 84xx, exiting.\n"); | |
6e98016c GM |
904 | return -EINVAL; |
905 | } | |
906 | ||
907 | sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list, | |
908 | bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE); | |
7c3df132 SK |
909 | if (!sg_cnt) { |
910 | ql_log(ql_log_warn, vha, 0x7033, | |
911 | "dma_map_sg returned %d for request.\n", sg_cnt); | |
6e98016c | 912 | return -ENOMEM; |
7c3df132 | 913 | } |
6e98016c GM |
914 | |
915 | if (sg_cnt != bsg_job->request_payload.sg_cnt) { | |
7c3df132 SK |
916 | ql_log(ql_log_warn, vha, 0x7034, |
917 | "DMA mapping resulted in different sg counts, " | |
918 | "request_sg_cnt: %x dma_request_sg_cnt: %x.\n", | |
919 | bsg_job->request_payload.sg_cnt, sg_cnt); | |
6e98016c GM |
920 | rval = -EAGAIN; |
921 | goto done_unmap_sg; | |
922 | } | |
923 | ||
924 | data_len = bsg_job->request_payload.payload_len; | |
925 | fw_buf = dma_alloc_coherent(&ha->pdev->dev, data_len, | |
926 | &fw_dma, GFP_KERNEL); | |
927 | if (!fw_buf) { | |
7c3df132 SK |
928 | ql_log(ql_log_warn, vha, 0x7035, |
929 | "DMA alloc failed for fw_buf.\n"); | |
6e98016c GM |
930 | rval = -ENOMEM; |
931 | goto done_unmap_sg; | |
932 | } | |
933 | ||
934 | sg_copy_to_buffer(bsg_job->request_payload.sg_list, | |
935 | bsg_job->request_payload.sg_cnt, fw_buf, data_len); | |
936 | ||
937 | mn = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma); | |
938 | if (!mn) { | |
7c3df132 SK |
939 | ql_log(ql_log_warn, vha, 0x7036, |
940 | "DMA alloc failed for fw buffer.\n"); | |
6e98016c GM |
941 | rval = -ENOMEM; |
942 | goto done_free_fw_buf; | |
943 | } | |
944 | ||
945 | flag = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1]; | |
946 | fw_ver = le32_to_cpu(*((uint32_t *)((uint32_t *)fw_buf + 2))); | |
947 | ||
948 | memset(mn, 0, sizeof(struct access_chip_84xx)); | |
949 | mn->entry_type = VERIFY_CHIP_IOCB_TYPE; | |
950 | mn->entry_count = 1; | |
951 | ||
952 | options = VCO_FORCE_UPDATE | VCO_END_OF_DATA; | |
953 | if (flag == A84_ISSUE_UPDATE_DIAGFW_CMD) | |
954 | options |= VCO_DIAG_FW; | |
955 | ||
956 | mn->options = cpu_to_le16(options); | |
957 | mn->fw_ver = cpu_to_le32(fw_ver); | |
958 | mn->fw_size = cpu_to_le32(data_len); | |
959 | mn->fw_seq_size = cpu_to_le32(data_len); | |
960 | mn->dseg_address[0] = cpu_to_le32(LSD(fw_dma)); | |
961 | mn->dseg_address[1] = cpu_to_le32(MSD(fw_dma)); | |
962 | mn->dseg_length = cpu_to_le32(data_len); | |
963 | mn->data_seg_cnt = cpu_to_le16(1); | |
964 | ||
965 | rval = qla2x00_issue_iocb_timeout(vha, mn, mn_dma, 0, 120); | |
966 | ||
967 | if (rval) { | |
7c3df132 SK |
968 | ql_log(ql_log_warn, vha, 0x7037, |
969 | "Vendor request 84xx updatefw failed.\n"); | |
6e98016c | 970 | |
b7bfbe12 | 971 | rval = 0; |
6e98016c | 972 | bsg_job->reply->result = (DID_ERROR << 16); |
6e98016c | 973 | } else { |
7c3df132 SK |
974 | ql_dbg(ql_dbg_user, vha, 0x7038, |
975 | "Vendor request 84xx updatefw completed.\n"); | |
6e98016c GM |
976 | |
977 | bsg_job->reply_len = sizeof(struct fc_bsg_reply); | |
978 | bsg_job->reply->result = DID_OK; | |
979 | } | |
980 | ||
981 | bsg_job->job_done(bsg_job); | |
982 | dma_pool_free(ha->s_dma_pool, mn, mn_dma); | |
983 | ||
984 | done_free_fw_buf: | |
985 | dma_free_coherent(&ha->pdev->dev, data_len, fw_buf, fw_dma); | |
986 | ||
987 | done_unmap_sg: | |
988 | dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list, | |
989 | bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE); | |
990 | ||
991 | return rval; | |
992 | } | |
993 | ||
994 | static int | |
995 | qla84xx_mgmt_cmd(struct fc_bsg_job *bsg_job) | |
996 | { | |
997 | struct Scsi_Host *host = bsg_job->shost; | |
998 | scsi_qla_host_t *vha = shost_priv(host); | |
999 | struct qla_hw_data *ha = vha->hw; | |
1000 | struct access_chip_84xx *mn = NULL; | |
1001 | dma_addr_t mn_dma, mgmt_dma; | |
1002 | void *mgmt_b = NULL; | |
1003 | int rval = 0; | |
1004 | struct qla_bsg_a84_mgmt *ql84_mgmt; | |
1005 | uint32_t sg_cnt; | |
d5459083 | 1006 | uint32_t data_len = 0; |
6e98016c GM |
1007 | uint32_t dma_direction = DMA_NONE; |
1008 | ||
6e98016c | 1009 | if (!IS_QLA84XX(ha)) { |
7c3df132 SK |
1010 | ql_log(ql_log_warn, vha, 0x703a, |
1011 | "Not 84xx, exiting.\n"); | |
6e98016c GM |
1012 | return -EINVAL; |
1013 | } | |
1014 | ||
1015 | ql84_mgmt = (struct qla_bsg_a84_mgmt *)((char *)bsg_job->request + | |
1016 | sizeof(struct fc_bsg_request)); | |
1017 | if (!ql84_mgmt) { | |
7c3df132 SK |
1018 | ql_log(ql_log_warn, vha, 0x703b, |
1019 | "MGMT header not provided, exiting.\n"); | |
6e98016c GM |
1020 | return -EINVAL; |
1021 | } | |
1022 | ||
1023 | mn = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma); | |
1024 | if (!mn) { | |
7c3df132 SK |
1025 | ql_log(ql_log_warn, vha, 0x703c, |
1026 | "DMA alloc failed for fw buffer.\n"); | |
6e98016c GM |
1027 | return -ENOMEM; |
1028 | } | |
1029 | ||
1030 | memset(mn, 0, sizeof(struct access_chip_84xx)); | |
1031 | mn->entry_type = ACCESS_CHIP_IOCB_TYPE; | |
1032 | mn->entry_count = 1; | |
1033 | ||
1034 | switch (ql84_mgmt->mgmt.cmd) { | |
1035 | case QLA84_MGMT_READ_MEM: | |
1036 | case QLA84_MGMT_GET_INFO: | |
1037 | sg_cnt = dma_map_sg(&ha->pdev->dev, | |
1038 | bsg_job->reply_payload.sg_list, | |
1039 | bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE); | |
1040 | if (!sg_cnt) { | |
7c3df132 SK |
1041 | ql_log(ql_log_warn, vha, 0x703d, |
1042 | "dma_map_sg returned %d for reply.\n", sg_cnt); | |
6e98016c GM |
1043 | rval = -ENOMEM; |
1044 | goto exit_mgmt; | |
1045 | } | |
1046 | ||
1047 | dma_direction = DMA_FROM_DEVICE; | |
1048 | ||
1049 | if (sg_cnt != bsg_job->reply_payload.sg_cnt) { | |
7c3df132 SK |
1050 | ql_log(ql_log_warn, vha, 0x703e, |
1051 | "DMA mapping resulted in different sg counts, " | |
1052 | "reply_sg_cnt: %x dma_reply_sg_cnt: %x.\n", | |
1053 | bsg_job->reply_payload.sg_cnt, sg_cnt); | |
6e98016c GM |
1054 | rval = -EAGAIN; |
1055 | goto done_unmap_sg; | |
1056 | } | |
1057 | ||
1058 | data_len = bsg_job->reply_payload.payload_len; | |
1059 | ||
1060 | mgmt_b = dma_alloc_coherent(&ha->pdev->dev, data_len, | |
1061 | &mgmt_dma, GFP_KERNEL); | |
1062 | if (!mgmt_b) { | |
7c3df132 SK |
1063 | ql_log(ql_log_warn, vha, 0x703f, |
1064 | "DMA alloc failed for mgmt_b.\n"); | |
6e98016c GM |
1065 | rval = -ENOMEM; |
1066 | goto done_unmap_sg; | |
1067 | } | |
1068 | ||
1069 | if (ql84_mgmt->mgmt.cmd == QLA84_MGMT_READ_MEM) { | |
1070 | mn->options = cpu_to_le16(ACO_DUMP_MEMORY); | |
1071 | mn->parameter1 = | |
1072 | cpu_to_le32( | |
1073 | ql84_mgmt->mgmt.mgmtp.u.mem.start_addr); | |
1074 | ||
1075 | } else if (ql84_mgmt->mgmt.cmd == QLA84_MGMT_GET_INFO) { | |
1076 | mn->options = cpu_to_le16(ACO_REQUEST_INFO); | |
1077 | mn->parameter1 = | |
1078 | cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.info.type); | |
1079 | ||
1080 | mn->parameter2 = | |
1081 | cpu_to_le32( | |
1082 | ql84_mgmt->mgmt.mgmtp.u.info.context); | |
1083 | } | |
1084 | break; | |
1085 | ||
1086 | case QLA84_MGMT_WRITE_MEM: | |
1087 | sg_cnt = dma_map_sg(&ha->pdev->dev, | |
1088 | bsg_job->request_payload.sg_list, | |
1089 | bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE); | |
1090 | ||
1091 | if (!sg_cnt) { | |
7c3df132 SK |
1092 | ql_log(ql_log_warn, vha, 0x7040, |
1093 | "dma_map_sg returned %d.\n", sg_cnt); | |
6e98016c GM |
1094 | rval = -ENOMEM; |
1095 | goto exit_mgmt; | |
1096 | } | |
1097 | ||
1098 | dma_direction = DMA_TO_DEVICE; | |
1099 | ||
1100 | if (sg_cnt != bsg_job->request_payload.sg_cnt) { | |
7c3df132 SK |
1101 | ql_log(ql_log_warn, vha, 0x7041, |
1102 | "DMA mapping resulted in different sg counts, " | |
1103 | "request_sg_cnt: %x dma_request_sg_cnt: %x.\n", | |
1104 | bsg_job->request_payload.sg_cnt, sg_cnt); | |
6e98016c GM |
1105 | rval = -EAGAIN; |
1106 | goto done_unmap_sg; | |
1107 | } | |
1108 | ||
1109 | data_len = bsg_job->request_payload.payload_len; | |
1110 | mgmt_b = dma_alloc_coherent(&ha->pdev->dev, data_len, | |
1111 | &mgmt_dma, GFP_KERNEL); | |
1112 | if (!mgmt_b) { | |
7c3df132 SK |
1113 | ql_log(ql_log_warn, vha, 0x7042, |
1114 | "DMA alloc failed for mgmt_b.\n"); | |
6e98016c GM |
1115 | rval = -ENOMEM; |
1116 | goto done_unmap_sg; | |
1117 | } | |
1118 | ||
1119 | sg_copy_to_buffer(bsg_job->request_payload.sg_list, | |
1120 | bsg_job->request_payload.sg_cnt, mgmt_b, data_len); | |
1121 | ||
1122 | mn->options = cpu_to_le16(ACO_LOAD_MEMORY); | |
1123 | mn->parameter1 = | |
1124 | cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.mem.start_addr); | |
1125 | break; | |
1126 | ||
1127 | case QLA84_MGMT_CHNG_CONFIG: | |
1128 | mn->options = cpu_to_le16(ACO_CHANGE_CONFIG_PARAM); | |
1129 | mn->parameter1 = | |
1130 | cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.config.id); | |
1131 | ||
1132 | mn->parameter2 = | |
1133 | cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.config.param0); | |
1134 | ||
1135 | mn->parameter3 = | |
1136 | cpu_to_le32(ql84_mgmt->mgmt.mgmtp.u.config.param1); | |
1137 | break; | |
1138 | ||
1139 | default: | |
1140 | rval = -EIO; | |
1141 | goto exit_mgmt; | |
1142 | } | |
1143 | ||
1144 | if (ql84_mgmt->mgmt.cmd != QLA84_MGMT_CHNG_CONFIG) { | |
1145 | mn->total_byte_cnt = cpu_to_le32(ql84_mgmt->mgmt.len); | |
1146 | mn->dseg_count = cpu_to_le16(1); | |
1147 | mn->dseg_address[0] = cpu_to_le32(LSD(mgmt_dma)); | |
1148 | mn->dseg_address[1] = cpu_to_le32(MSD(mgmt_dma)); | |
1149 | mn->dseg_length = cpu_to_le32(ql84_mgmt->mgmt.len); | |
1150 | } | |
1151 | ||
1152 | rval = qla2x00_issue_iocb(vha, mn, mn_dma, 0); | |
1153 | ||
1154 | if (rval) { | |
7c3df132 SK |
1155 | ql_log(ql_log_warn, vha, 0x7043, |
1156 | "Vendor request 84xx mgmt failed.\n"); | |
6e98016c | 1157 | |
b7bfbe12 | 1158 | rval = 0; |
6e98016c GM |
1159 | bsg_job->reply->result = (DID_ERROR << 16); |
1160 | ||
1161 | } else { | |
7c3df132 SK |
1162 | ql_dbg(ql_dbg_user, vha, 0x7044, |
1163 | "Vendor request 84xx mgmt completed.\n"); | |
6e98016c GM |
1164 | |
1165 | bsg_job->reply_len = sizeof(struct fc_bsg_reply); | |
1166 | bsg_job->reply->result = DID_OK; | |
1167 | ||
1168 | if ((ql84_mgmt->mgmt.cmd == QLA84_MGMT_READ_MEM) || | |
1169 | (ql84_mgmt->mgmt.cmd == QLA84_MGMT_GET_INFO)) { | |
1170 | bsg_job->reply->reply_payload_rcv_len = | |
1171 | bsg_job->reply_payload.payload_len; | |
1172 | ||
1173 | sg_copy_from_buffer(bsg_job->reply_payload.sg_list, | |
6c452a45 AV |
1174 | bsg_job->reply_payload.sg_cnt, mgmt_b, |
1175 | data_len); | |
6e98016c GM |
1176 | } |
1177 | } | |
1178 | ||
1179 | bsg_job->job_done(bsg_job); | |
6e98016c GM |
1180 | |
1181 | done_unmap_sg: | |
d5459083 HZ |
1182 | if (mgmt_b) |
1183 | dma_free_coherent(&ha->pdev->dev, data_len, mgmt_b, mgmt_dma); | |
1184 | ||
6e98016c GM |
1185 | if (dma_direction == DMA_TO_DEVICE) |
1186 | dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list, | |
1187 | bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE); | |
1188 | else if (dma_direction == DMA_FROM_DEVICE) | |
1189 | dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list, | |
1190 | bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE); | |
1191 | ||
1192 | exit_mgmt: | |
1193 | dma_pool_free(ha->s_dma_pool, mn, mn_dma); | |
1194 | ||
1195 | return rval; | |
1196 | } | |
1197 | ||
1198 | static int | |
1199 | qla24xx_iidma(struct fc_bsg_job *bsg_job) | |
1200 | { | |
1201 | struct Scsi_Host *host = bsg_job->shost; | |
1202 | scsi_qla_host_t *vha = shost_priv(host); | |
6e98016c GM |
1203 | int rval = 0; |
1204 | struct qla_port_param *port_param = NULL; | |
1205 | fc_port_t *fcport = NULL; | |
1206 | uint16_t mb[MAILBOX_REGISTER_COUNT]; | |
1207 | uint8_t *rsp_ptr = NULL; | |
1208 | ||
6e98016c | 1209 | if (!IS_IIDMA_CAPABLE(vha->hw)) { |
7c3df132 | 1210 | ql_log(ql_log_info, vha, 0x7046, "iiDMA not supported.\n"); |
6e98016c GM |
1211 | return -EINVAL; |
1212 | } | |
1213 | ||
1214 | port_param = (struct qla_port_param *)((char *)bsg_job->request + | |
1215 | sizeof(struct fc_bsg_request)); | |
1216 | if (!port_param) { | |
7c3df132 SK |
1217 | ql_log(ql_log_warn, vha, 0x7047, |
1218 | "port_param header not provided.\n"); | |
6e98016c GM |
1219 | return -EINVAL; |
1220 | } | |
1221 | ||
1222 | if (port_param->fc_scsi_addr.dest_type != EXT_DEF_TYPE_WWPN) { | |
7c3df132 SK |
1223 | ql_log(ql_log_warn, vha, 0x7048, |
1224 | "Invalid destination type.\n"); | |
6e98016c GM |
1225 | return -EINVAL; |
1226 | } | |
1227 | ||
1228 | list_for_each_entry(fcport, &vha->vp_fcports, list) { | |
1229 | if (fcport->port_type != FCT_TARGET) | |
1230 | continue; | |
1231 | ||
1232 | if (memcmp(port_param->fc_scsi_addr.dest_addr.wwpn, | |
1233 | fcport->port_name, sizeof(fcport->port_name))) | |
1234 | continue; | |
1235 | break; | |
1236 | } | |
1237 | ||
1238 | if (!fcport) { | |
7c3df132 SK |
1239 | ql_log(ql_log_warn, vha, 0x7049, |
1240 | "Failed to find port.\n"); | |
6e98016c GM |
1241 | return -EINVAL; |
1242 | } | |
1243 | ||
c9afb9a2 | 1244 | if (atomic_read(&fcport->state) != FCS_ONLINE) { |
7c3df132 SK |
1245 | ql_log(ql_log_warn, vha, 0x704a, |
1246 | "Port is not online.\n"); | |
17cf2c5d MI |
1247 | return -EINVAL; |
1248 | } | |
1249 | ||
9a15eb4b | 1250 | if (fcport->flags & FCF_LOGIN_NEEDED) { |
7c3df132 SK |
1251 | ql_log(ql_log_warn, vha, 0x704b, |
1252 | "Remote port not logged in flags = 0x%x.\n", fcport->flags); | |
9a15eb4b MI |
1253 | return -EINVAL; |
1254 | } | |
1255 | ||
6e98016c GM |
1256 | if (port_param->mode) |
1257 | rval = qla2x00_set_idma_speed(vha, fcport->loop_id, | |
1258 | port_param->speed, mb); | |
1259 | else | |
1260 | rval = qla2x00_get_idma_speed(vha, fcport->loop_id, | |
1261 | &port_param->speed, mb); | |
1262 | ||
1263 | if (rval) { | |
7c3df132 SK |
1264 | ql_log(ql_log_warn, vha, 0x704c, |
1265 | "iIDMA cmd failed for %02x%02x%02x%02x%02x%02x%02x%02x -- " | |
1266 | "%04x %x %04x %04x.\n", fcport->port_name[0], | |
1267 | fcport->port_name[1], fcport->port_name[2], | |
1268 | fcport->port_name[3], fcport->port_name[4], | |
1269 | fcport->port_name[5], fcport->port_name[6], | |
1270 | fcport->port_name[7], rval, fcport->fp_speed, mb[0], mb[1]); | |
6e98016c GM |
1271 | rval = 0; |
1272 | bsg_job->reply->result = (DID_ERROR << 16); | |
1273 | ||
1274 | } else { | |
1275 | if (!port_param->mode) { | |
1276 | bsg_job->reply_len = sizeof(struct fc_bsg_reply) + | |
1277 | sizeof(struct qla_port_param); | |
1278 | ||
1279 | rsp_ptr = ((uint8_t *)bsg_job->reply) + | |
1280 | sizeof(struct fc_bsg_reply); | |
1281 | ||
1282 | memcpy(rsp_ptr, port_param, | |
1283 | sizeof(struct qla_port_param)); | |
1284 | } | |
1285 | ||
1286 | bsg_job->reply->result = DID_OK; | |
1287 | } | |
1288 | ||
1289 | bsg_job->job_done(bsg_job); | |
1290 | return rval; | |
1291 | } | |
1292 | ||
f19af163 | 1293 | static int |
7c3df132 | 1294 | qla2x00_optrom_setup(struct fc_bsg_job *bsg_job, scsi_qla_host_t *vha, |
f19af163 HZ |
1295 | uint8_t is_update) |
1296 | { | |
1297 | uint32_t start = 0; | |
1298 | int valid = 0; | |
7c3df132 | 1299 | struct qla_hw_data *ha = vha->hw; |
f19af163 | 1300 | |
f19af163 HZ |
1301 | if (unlikely(pci_channel_offline(ha->pdev))) |
1302 | return -EINVAL; | |
1303 | ||
1304 | start = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1]; | |
7c3df132 SK |
1305 | if (start > ha->optrom_size) { |
1306 | ql_log(ql_log_warn, vha, 0x7055, | |
1307 | "start %d > optrom_size %d.\n", start, ha->optrom_size); | |
f19af163 | 1308 | return -EINVAL; |
7c3df132 | 1309 | } |
f19af163 | 1310 | |
7c3df132 SK |
1311 | if (ha->optrom_state != QLA_SWAITING) { |
1312 | ql_log(ql_log_info, vha, 0x7056, | |
1313 | "optrom_state %d.\n", ha->optrom_state); | |
f19af163 | 1314 | return -EBUSY; |
7c3df132 | 1315 | } |
f19af163 HZ |
1316 | |
1317 | ha->optrom_region_start = start; | |
7c3df132 | 1318 | ql_dbg(ql_dbg_user, vha, 0x7057, "is_update=%d.\n", is_update); |
f19af163 HZ |
1319 | if (is_update) { |
1320 | if (ha->optrom_size == OPTROM_SIZE_2300 && start == 0) | |
1321 | valid = 1; | |
1322 | else if (start == (ha->flt_region_boot * 4) || | |
1323 | start == (ha->flt_region_fw * 4)) | |
1324 | valid = 1; | |
1325 | else if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha) || | |
6246b8a1 | 1326 | IS_CNA_CAPABLE(ha) || IS_QLA2031(ha)) |
f19af163 HZ |
1327 | valid = 1; |
1328 | if (!valid) { | |
7c3df132 SK |
1329 | ql_log(ql_log_warn, vha, 0x7058, |
1330 | "Invalid start region 0x%x/0x%x.\n", start, | |
1331 | bsg_job->request_payload.payload_len); | |
f19af163 HZ |
1332 | return -EINVAL; |
1333 | } | |
1334 | ||
1335 | ha->optrom_region_size = start + | |
1336 | bsg_job->request_payload.payload_len > ha->optrom_size ? | |
1337 | ha->optrom_size - start : | |
1338 | bsg_job->request_payload.payload_len; | |
1339 | ha->optrom_state = QLA_SWRITING; | |
1340 | } else { | |
1341 | ha->optrom_region_size = start + | |
1342 | bsg_job->reply_payload.payload_len > ha->optrom_size ? | |
1343 | ha->optrom_size - start : | |
1344 | bsg_job->reply_payload.payload_len; | |
1345 | ha->optrom_state = QLA_SREADING; | |
1346 | } | |
1347 | ||
1348 | ha->optrom_buffer = vmalloc(ha->optrom_region_size); | |
1349 | if (!ha->optrom_buffer) { | |
7c3df132 | 1350 | ql_log(ql_log_warn, vha, 0x7059, |
f19af163 | 1351 | "Read: Unable to allocate memory for optrom retrieval " |
7c3df132 | 1352 | "(%x)\n", ha->optrom_region_size); |
f19af163 HZ |
1353 | |
1354 | ha->optrom_state = QLA_SWAITING; | |
1355 | return -ENOMEM; | |
1356 | } | |
1357 | ||
1358 | memset(ha->optrom_buffer, 0, ha->optrom_region_size); | |
1359 | return 0; | |
1360 | } | |
1361 | ||
1362 | static int | |
1363 | qla2x00_read_optrom(struct fc_bsg_job *bsg_job) | |
1364 | { | |
1365 | struct Scsi_Host *host = bsg_job->shost; | |
1366 | scsi_qla_host_t *vha = shost_priv(host); | |
1367 | struct qla_hw_data *ha = vha->hw; | |
1368 | int rval = 0; | |
1369 | ||
7d613ac6 | 1370 | if (ha->flags.nic_core_reset_hdlr_active) |
a49393f2 GM |
1371 | return -EBUSY; |
1372 | ||
7c3df132 | 1373 | rval = qla2x00_optrom_setup(bsg_job, vha, 0); |
f19af163 HZ |
1374 | if (rval) |
1375 | return rval; | |
1376 | ||
1377 | ha->isp_ops->read_optrom(vha, ha->optrom_buffer, | |
1378 | ha->optrom_region_start, ha->optrom_region_size); | |
1379 | ||
1380 | sg_copy_from_buffer(bsg_job->reply_payload.sg_list, | |
1381 | bsg_job->reply_payload.sg_cnt, ha->optrom_buffer, | |
1382 | ha->optrom_region_size); | |
1383 | ||
1384 | bsg_job->reply->reply_payload_rcv_len = ha->optrom_region_size; | |
1385 | bsg_job->reply->result = DID_OK; | |
1386 | vfree(ha->optrom_buffer); | |
1387 | ha->optrom_buffer = NULL; | |
1388 | ha->optrom_state = QLA_SWAITING; | |
1389 | bsg_job->job_done(bsg_job); | |
1390 | return rval; | |
1391 | } | |
1392 | ||
1393 | static int | |
1394 | qla2x00_update_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 | ||
7c3df132 | 1401 | rval = qla2x00_optrom_setup(bsg_job, vha, 1); |
f19af163 HZ |
1402 | if (rval) |
1403 | return rval; | |
1404 | ||
b6d0d9d5 GM |
1405 | /* Set the isp82xx_no_md_cap not to capture minidump */ |
1406 | ha->flags.isp82xx_no_md_cap = 1; | |
1407 | ||
f19af163 HZ |
1408 | sg_copy_to_buffer(bsg_job->request_payload.sg_list, |
1409 | bsg_job->request_payload.sg_cnt, ha->optrom_buffer, | |
1410 | ha->optrom_region_size); | |
1411 | ||
1412 | ha->isp_ops->write_optrom(vha, ha->optrom_buffer, | |
1413 | ha->optrom_region_start, ha->optrom_region_size); | |
1414 | ||
1415 | bsg_job->reply->result = DID_OK; | |
1416 | vfree(ha->optrom_buffer); | |
1417 | ha->optrom_buffer = NULL; | |
1418 | ha->optrom_state = QLA_SWAITING; | |
1419 | bsg_job->job_done(bsg_job); | |
1420 | return rval; | |
1421 | } | |
1422 | ||
697a4bc6 JC |
1423 | static int |
1424 | qla2x00_update_fru_versions(struct fc_bsg_job *bsg_job) | |
1425 | { | |
1426 | struct Scsi_Host *host = bsg_job->shost; | |
1427 | scsi_qla_host_t *vha = shost_priv(host); | |
1428 | struct qla_hw_data *ha = vha->hw; | |
1429 | int rval = 0; | |
1430 | uint8_t bsg[DMA_POOL_SIZE]; | |
1431 | struct qla_image_version_list *list = (void *)bsg; | |
1432 | struct qla_image_version *image; | |
1433 | uint32_t count; | |
1434 | dma_addr_t sfp_dma; | |
1435 | void *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma); | |
1436 | if (!sfp) { | |
1437 | bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = | |
1438 | EXT_STATUS_NO_MEMORY; | |
1439 | goto done; | |
1440 | } | |
1441 | ||
1442 | sg_copy_to_buffer(bsg_job->request_payload.sg_list, | |
1443 | bsg_job->request_payload.sg_cnt, list, sizeof(bsg)); | |
1444 | ||
1445 | image = list->version; | |
1446 | count = list->count; | |
1447 | while (count--) { | |
1448 | memcpy(sfp, &image->field_info, sizeof(image->field_info)); | |
1449 | rval = qla2x00_write_sfp(vha, sfp_dma, sfp, | |
1450 | image->field_address.device, image->field_address.offset, | |
1451 | sizeof(image->field_info), image->field_address.option); | |
1452 | if (rval) { | |
1453 | bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = | |
1454 | EXT_STATUS_MAILBOX; | |
1455 | goto dealloc; | |
1456 | } | |
1457 | image++; | |
1458 | } | |
1459 | ||
1460 | bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = 0; | |
1461 | ||
1462 | dealloc: | |
1463 | dma_pool_free(ha->s_dma_pool, sfp, sfp_dma); | |
1464 | ||
1465 | done: | |
1466 | bsg_job->reply_len = sizeof(struct fc_bsg_reply); | |
1467 | bsg_job->reply->result = DID_OK << 16; | |
1468 | bsg_job->job_done(bsg_job); | |
1469 | ||
1470 | return 0; | |
1471 | } | |
1472 | ||
1473 | static int | |
1474 | qla2x00_read_fru_status(struct fc_bsg_job *bsg_job) | |
1475 | { | |
1476 | struct Scsi_Host *host = bsg_job->shost; | |
1477 | scsi_qla_host_t *vha = shost_priv(host); | |
1478 | struct qla_hw_data *ha = vha->hw; | |
1479 | int rval = 0; | |
1480 | uint8_t bsg[DMA_POOL_SIZE]; | |
1481 | struct qla_status_reg *sr = (void *)bsg; | |
1482 | dma_addr_t sfp_dma; | |
1483 | uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma); | |
1484 | if (!sfp) { | |
1485 | bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = | |
1486 | EXT_STATUS_NO_MEMORY; | |
1487 | goto done; | |
1488 | } | |
1489 | ||
1490 | sg_copy_to_buffer(bsg_job->request_payload.sg_list, | |
1491 | bsg_job->request_payload.sg_cnt, sr, sizeof(*sr)); | |
1492 | ||
1493 | rval = qla2x00_read_sfp(vha, sfp_dma, sfp, | |
1494 | sr->field_address.device, sr->field_address.offset, | |
1495 | sizeof(sr->status_reg), sr->field_address.option); | |
1496 | sr->status_reg = *sfp; | |
1497 | ||
1498 | if (rval) { | |
1499 | bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = | |
1500 | EXT_STATUS_MAILBOX; | |
1501 | goto dealloc; | |
1502 | } | |
1503 | ||
1504 | sg_copy_from_buffer(bsg_job->reply_payload.sg_list, | |
1505 | bsg_job->reply_payload.sg_cnt, sr, sizeof(*sr)); | |
1506 | ||
1507 | bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = 0; | |
1508 | ||
1509 | dealloc: | |
1510 | dma_pool_free(ha->s_dma_pool, sfp, sfp_dma); | |
1511 | ||
1512 | done: | |
1513 | bsg_job->reply_len = sizeof(struct fc_bsg_reply); | |
1514 | bsg_job->reply->reply_payload_rcv_len = sizeof(*sr); | |
1515 | bsg_job->reply->result = DID_OK << 16; | |
1516 | bsg_job->job_done(bsg_job); | |
1517 | ||
1518 | return 0; | |
1519 | } | |
1520 | ||
1521 | static int | |
1522 | qla2x00_write_fru_status(struct fc_bsg_job *bsg_job) | |
1523 | { | |
1524 | struct Scsi_Host *host = bsg_job->shost; | |
1525 | scsi_qla_host_t *vha = shost_priv(host); | |
1526 | struct qla_hw_data *ha = vha->hw; | |
1527 | int rval = 0; | |
1528 | uint8_t bsg[DMA_POOL_SIZE]; | |
1529 | struct qla_status_reg *sr = (void *)bsg; | |
1530 | dma_addr_t sfp_dma; | |
1531 | uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma); | |
1532 | if (!sfp) { | |
1533 | bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = | |
1534 | EXT_STATUS_NO_MEMORY; | |
1535 | goto done; | |
1536 | } | |
1537 | ||
1538 | sg_copy_to_buffer(bsg_job->request_payload.sg_list, | |
1539 | bsg_job->request_payload.sg_cnt, sr, sizeof(*sr)); | |
1540 | ||
1541 | *sfp = sr->status_reg; | |
1542 | rval = qla2x00_write_sfp(vha, sfp_dma, sfp, | |
1543 | sr->field_address.device, sr->field_address.offset, | |
1544 | sizeof(sr->status_reg), sr->field_address.option); | |
1545 | ||
1546 | if (rval) { | |
1547 | bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = | |
1548 | EXT_STATUS_MAILBOX; | |
1549 | goto dealloc; | |
1550 | } | |
1551 | ||
1552 | bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = 0; | |
1553 | ||
1554 | dealloc: | |
1555 | dma_pool_free(ha->s_dma_pool, sfp, sfp_dma); | |
1556 | ||
1557 | done: | |
1558 | bsg_job->reply_len = sizeof(struct fc_bsg_reply); | |
1559 | bsg_job->reply->result = DID_OK << 16; | |
1560 | bsg_job->job_done(bsg_job); | |
1561 | ||
1562 | return 0; | |
1563 | } | |
1564 | ||
9ebb5d9c JC |
1565 | static int |
1566 | qla2x00_write_i2c(struct fc_bsg_job *bsg_job) | |
1567 | { | |
1568 | struct Scsi_Host *host = bsg_job->shost; | |
1569 | scsi_qla_host_t *vha = shost_priv(host); | |
1570 | struct qla_hw_data *ha = vha->hw; | |
1571 | int rval = 0; | |
1572 | uint8_t bsg[DMA_POOL_SIZE]; | |
1573 | struct qla_i2c_access *i2c = (void *)bsg; | |
1574 | dma_addr_t sfp_dma; | |
1575 | uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma); | |
1576 | if (!sfp) { | |
1577 | bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = | |
1578 | EXT_STATUS_NO_MEMORY; | |
1579 | goto done; | |
1580 | } | |
1581 | ||
1582 | sg_copy_to_buffer(bsg_job->request_payload.sg_list, | |
1583 | bsg_job->request_payload.sg_cnt, i2c, sizeof(*i2c)); | |
1584 | ||
1585 | memcpy(sfp, i2c->buffer, i2c->length); | |
1586 | rval = qla2x00_write_sfp(vha, sfp_dma, sfp, | |
1587 | i2c->device, i2c->offset, i2c->length, i2c->option); | |
1588 | ||
1589 | if (rval) { | |
1590 | bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = | |
1591 | EXT_STATUS_MAILBOX; | |
1592 | goto dealloc; | |
1593 | } | |
1594 | ||
1595 | bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = 0; | |
1596 | ||
1597 | dealloc: | |
1598 | dma_pool_free(ha->s_dma_pool, sfp, sfp_dma); | |
1599 | ||
1600 | done: | |
1601 | bsg_job->reply_len = sizeof(struct fc_bsg_reply); | |
1602 | bsg_job->reply->result = DID_OK << 16; | |
1603 | bsg_job->job_done(bsg_job); | |
1604 | ||
1605 | return 0; | |
1606 | } | |
1607 | ||
1608 | static int | |
1609 | qla2x00_read_i2c(struct fc_bsg_job *bsg_job) | |
1610 | { | |
1611 | struct Scsi_Host *host = bsg_job->shost; | |
1612 | scsi_qla_host_t *vha = shost_priv(host); | |
1613 | struct qla_hw_data *ha = vha->hw; | |
1614 | int rval = 0; | |
1615 | uint8_t bsg[DMA_POOL_SIZE]; | |
1616 | struct qla_i2c_access *i2c = (void *)bsg; | |
1617 | dma_addr_t sfp_dma; | |
1618 | uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma); | |
1619 | if (!sfp) { | |
1620 | bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = | |
1621 | EXT_STATUS_NO_MEMORY; | |
1622 | goto done; | |
1623 | } | |
1624 | ||
1625 | sg_copy_to_buffer(bsg_job->request_payload.sg_list, | |
1626 | bsg_job->request_payload.sg_cnt, i2c, sizeof(*i2c)); | |
1627 | ||
1628 | rval = qla2x00_read_sfp(vha, sfp_dma, sfp, | |
1629 | i2c->device, i2c->offset, i2c->length, i2c->option); | |
1630 | ||
1631 | if (rval) { | |
1632 | bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = | |
1633 | EXT_STATUS_MAILBOX; | |
1634 | goto dealloc; | |
1635 | } | |
1636 | ||
1637 | memcpy(i2c->buffer, sfp, i2c->length); | |
1638 | sg_copy_from_buffer(bsg_job->reply_payload.sg_list, | |
1639 | bsg_job->reply_payload.sg_cnt, i2c, sizeof(*i2c)); | |
1640 | ||
1641 | bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = 0; | |
1642 | ||
1643 | dealloc: | |
1644 | dma_pool_free(ha->s_dma_pool, sfp, sfp_dma); | |
1645 | ||
1646 | done: | |
1647 | bsg_job->reply_len = sizeof(struct fc_bsg_reply); | |
1648 | bsg_job->reply->reply_payload_rcv_len = sizeof(*i2c); | |
1649 | bsg_job->reply->result = DID_OK << 16; | |
1650 | bsg_job->job_done(bsg_job); | |
1651 | ||
1652 | return 0; | |
1653 | } | |
1654 | ||
a9b6f722 SK |
1655 | static int |
1656 | qla24xx_process_bidir_cmd(struct fc_bsg_job *bsg_job) | |
1657 | { | |
1658 | struct Scsi_Host *host = bsg_job->shost; | |
1659 | scsi_qla_host_t *vha = shost_priv(host); | |
1660 | struct qla_hw_data *ha = vha->hw; | |
1661 | uint16_t thread_id; | |
1662 | uint32_t rval = EXT_STATUS_OK; | |
1663 | uint16_t req_sg_cnt = 0; | |
1664 | uint16_t rsp_sg_cnt = 0; | |
1665 | uint16_t nextlid = 0; | |
1666 | uint32_t tot_dsds; | |
1667 | srb_t *sp = NULL; | |
1668 | uint32_t req_data_len = 0; | |
1669 | uint32_t rsp_data_len = 0; | |
1670 | ||
1671 | /* Check the type of the adapter */ | |
1672 | if (!IS_BIDI_CAPABLE(ha)) { | |
1673 | ql_log(ql_log_warn, vha, 0x70a0, | |
1674 | "This adapter is not supported\n"); | |
1675 | rval = EXT_STATUS_NOT_SUPPORTED; | |
1676 | goto done; | |
1677 | } | |
1678 | ||
1679 | if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) || | |
1680 | test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) || | |
1681 | test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) { | |
1682 | rval = EXT_STATUS_BUSY; | |
1683 | goto done; | |
1684 | } | |
1685 | ||
1686 | /* Check if host is online */ | |
1687 | if (!vha->flags.online) { | |
1688 | ql_log(ql_log_warn, vha, 0x70a1, | |
1689 | "Host is not online\n"); | |
1690 | rval = EXT_STATUS_DEVICE_OFFLINE; | |
1691 | goto done; | |
1692 | } | |
1693 | ||
1694 | /* Check if cable is plugged in or not */ | |
1695 | if (vha->device_flags & DFLG_NO_CABLE) { | |
1696 | ql_log(ql_log_warn, vha, 0x70a2, | |
1697 | "Cable is unplugged...\n"); | |
1698 | rval = EXT_STATUS_INVALID_CFG; | |
1699 | goto done; | |
1700 | } | |
1701 | ||
1702 | /* Check if the switch is connected or not */ | |
1703 | if (ha->current_topology != ISP_CFG_F) { | |
1704 | ql_log(ql_log_warn, vha, 0x70a3, | |
1705 | "Host is not connected to the switch\n"); | |
1706 | rval = EXT_STATUS_INVALID_CFG; | |
1707 | goto done; | |
1708 | } | |
1709 | ||
1710 | /* Check if operating mode is P2P */ | |
1711 | if (ha->operating_mode != P2P) { | |
1712 | ql_log(ql_log_warn, vha, 0x70a4, | |
1713 | "Host is operating mode is not P2p\n"); | |
1714 | rval = EXT_STATUS_INVALID_CFG; | |
1715 | goto done; | |
1716 | } | |
1717 | ||
1718 | thread_id = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1]; | |
1719 | ||
1720 | mutex_lock(&ha->selflogin_lock); | |
1721 | if (vha->self_login_loop_id == 0) { | |
1722 | /* Initialize all required fields of fcport */ | |
1723 | vha->bidir_fcport.vha = vha; | |
1724 | vha->bidir_fcport.d_id.b.al_pa = vha->d_id.b.al_pa; | |
1725 | vha->bidir_fcport.d_id.b.area = vha->d_id.b.area; | |
1726 | vha->bidir_fcport.d_id.b.domain = vha->d_id.b.domain; | |
1727 | vha->bidir_fcport.loop_id = vha->loop_id; | |
1728 | ||
1729 | if (qla2x00_fabric_login(vha, &(vha->bidir_fcport), &nextlid)) { | |
1730 | ql_log(ql_log_warn, vha, 0x70a7, | |
1731 | "Failed to login port %06X for bidirectional IOCB\n", | |
1732 | vha->bidir_fcport.d_id.b24); | |
1733 | mutex_unlock(&ha->selflogin_lock); | |
1734 | rval = EXT_STATUS_MAILBOX; | |
1735 | goto done; | |
1736 | } | |
1737 | vha->self_login_loop_id = nextlid - 1; | |
1738 | ||
1739 | } | |
1740 | /* Assign the self login loop id to fcport */ | |
1741 | mutex_unlock(&ha->selflogin_lock); | |
1742 | ||
1743 | vha->bidir_fcport.loop_id = vha->self_login_loop_id; | |
1744 | ||
1745 | req_sg_cnt = dma_map_sg(&ha->pdev->dev, | |
1746 | bsg_job->request_payload.sg_list, | |
1747 | bsg_job->request_payload.sg_cnt, | |
1748 | DMA_TO_DEVICE); | |
1749 | ||
1750 | if (!req_sg_cnt) { | |
1751 | rval = EXT_STATUS_NO_MEMORY; | |
1752 | goto done; | |
1753 | } | |
1754 | ||
1755 | rsp_sg_cnt = dma_map_sg(&ha->pdev->dev, | |
1756 | bsg_job->reply_payload.sg_list, bsg_job->reply_payload.sg_cnt, | |
1757 | DMA_FROM_DEVICE); | |
1758 | ||
1759 | if (!rsp_sg_cnt) { | |
1760 | rval = EXT_STATUS_NO_MEMORY; | |
1761 | goto done_unmap_req_sg; | |
1762 | } | |
1763 | ||
1764 | if ((req_sg_cnt != bsg_job->request_payload.sg_cnt) || | |
1765 | (rsp_sg_cnt != bsg_job->reply_payload.sg_cnt)) { | |
1766 | ql_dbg(ql_dbg_user, vha, 0x70a9, | |
1767 | "Dma mapping resulted in different sg counts " | |
1768 | "[request_sg_cnt: %x dma_request_sg_cnt: %x reply_sg_cnt: " | |
1769 | "%x dma_reply_sg_cnt: %x]\n", | |
1770 | bsg_job->request_payload.sg_cnt, req_sg_cnt, | |
1771 | bsg_job->reply_payload.sg_cnt, rsp_sg_cnt); | |
1772 | rval = EXT_STATUS_NO_MEMORY; | |
1773 | goto done_unmap_sg; | |
1774 | } | |
1775 | ||
1776 | if (req_data_len != rsp_data_len) { | |
1777 | rval = EXT_STATUS_BUSY; | |
1778 | ql_log(ql_log_warn, vha, 0x70aa, | |
1779 | "req_data_len != rsp_data_len\n"); | |
1780 | goto done_unmap_sg; | |
1781 | } | |
1782 | ||
1783 | req_data_len = bsg_job->request_payload.payload_len; | |
1784 | rsp_data_len = bsg_job->reply_payload.payload_len; | |
1785 | ||
1786 | ||
1787 | /* Alloc SRB structure */ | |
1788 | sp = qla2x00_get_sp(vha, &(vha->bidir_fcport), GFP_KERNEL); | |
1789 | if (!sp) { | |
1790 | ql_dbg(ql_dbg_user, vha, 0x70ac, | |
1791 | "Alloc SRB structure failed\n"); | |
1792 | rval = EXT_STATUS_NO_MEMORY; | |
1793 | goto done_unmap_sg; | |
1794 | } | |
1795 | ||
1796 | /*Populate srb->ctx with bidir ctx*/ | |
1797 | sp->u.bsg_job = bsg_job; | |
1798 | sp->free = qla2x00_bsg_sp_free; | |
1799 | sp->type = SRB_BIDI_CMD; | |
1800 | sp->done = qla2x00_bsg_job_done; | |
1801 | ||
1802 | /* Add the read and write sg count */ | |
1803 | tot_dsds = rsp_sg_cnt + req_sg_cnt; | |
1804 | ||
1805 | rval = qla2x00_start_bidir(sp, vha, tot_dsds); | |
1806 | if (rval != EXT_STATUS_OK) | |
1807 | goto done_free_srb; | |
1808 | /* the bsg request will be completed in the interrupt handler */ | |
1809 | return rval; | |
1810 | ||
1811 | done_free_srb: | |
1812 | mempool_free(sp, ha->srb_mempool); | |
1813 | done_unmap_sg: | |
1814 | dma_unmap_sg(&ha->pdev->dev, | |
1815 | bsg_job->reply_payload.sg_list, | |
1816 | bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE); | |
1817 | done_unmap_req_sg: | |
1818 | dma_unmap_sg(&ha->pdev->dev, | |
1819 | bsg_job->request_payload.sg_list, | |
1820 | bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE); | |
1821 | done: | |
1822 | ||
1823 | /* Return an error vendor specific response | |
1824 | * and complete the bsg request | |
1825 | */ | |
1826 | bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = rval; | |
1827 | bsg_job->reply_len = sizeof(struct fc_bsg_reply); | |
1828 | bsg_job->reply->reply_payload_rcv_len = 0; | |
1829 | bsg_job->reply->result = (DID_OK) << 16; | |
1830 | bsg_job->job_done(bsg_job); | |
1831 | /* Always retrun success, vendor rsp carries correct status */ | |
1832 | return 0; | |
1833 | } | |
1834 | ||
6e98016c GM |
1835 | static int |
1836 | qla2x00_process_vendor_specific(struct fc_bsg_job *bsg_job) | |
1837 | { | |
1838 | switch (bsg_job->request->rqst_data.h_vendor.vendor_cmd[0]) { | |
1839 | case QL_VND_LOOPBACK: | |
1840 | return qla2x00_process_loopback(bsg_job); | |
1841 | ||
1842 | case QL_VND_A84_RESET: | |
1843 | return qla84xx_reset(bsg_job); | |
1844 | ||
1845 | case QL_VND_A84_UPDATE_FW: | |
1846 | return qla84xx_updatefw(bsg_job); | |
1847 | ||
1848 | case QL_VND_A84_MGMT_CMD: | |
1849 | return qla84xx_mgmt_cmd(bsg_job); | |
1850 | ||
1851 | case QL_VND_IIDMA: | |
1852 | return qla24xx_iidma(bsg_job); | |
1853 | ||
09ff701a SR |
1854 | case QL_VND_FCP_PRIO_CFG_CMD: |
1855 | return qla24xx_proc_fcp_prio_cfg_cmd(bsg_job); | |
1856 | ||
f19af163 HZ |
1857 | case QL_VND_READ_FLASH: |
1858 | return qla2x00_read_optrom(bsg_job); | |
1859 | ||
1860 | case QL_VND_UPDATE_FLASH: | |
1861 | return qla2x00_update_optrom(bsg_job); | |
1862 | ||
697a4bc6 JC |
1863 | case QL_VND_SET_FRU_VERSION: |
1864 | return qla2x00_update_fru_versions(bsg_job); | |
1865 | ||
1866 | case QL_VND_READ_FRU_STATUS: | |
1867 | return qla2x00_read_fru_status(bsg_job); | |
1868 | ||
1869 | case QL_VND_WRITE_FRU_STATUS: | |
1870 | return qla2x00_write_fru_status(bsg_job); | |
1871 | ||
9ebb5d9c JC |
1872 | case QL_VND_WRITE_I2C: |
1873 | return qla2x00_write_i2c(bsg_job); | |
1874 | ||
1875 | case QL_VND_READ_I2C: | |
1876 | return qla2x00_read_i2c(bsg_job); | |
1877 | ||
a9b6f722 SK |
1878 | case QL_VND_DIAG_IO_CMD: |
1879 | return qla24xx_process_bidir_cmd(bsg_job); | |
1880 | ||
6e98016c GM |
1881 | default: |
1882 | bsg_job->reply->result = (DID_ERROR << 16); | |
1883 | bsg_job->job_done(bsg_job); | |
1884 | return -ENOSYS; | |
1885 | } | |
1886 | } | |
1887 | ||
1888 | int | |
1889 | qla24xx_bsg_request(struct fc_bsg_job *bsg_job) | |
1890 | { | |
1891 | int ret = -EINVAL; | |
7c3df132 SK |
1892 | struct fc_rport *rport; |
1893 | fc_port_t *fcport = NULL; | |
1894 | struct Scsi_Host *host; | |
1895 | scsi_qla_host_t *vha; | |
1896 | ||
b7bfbe12 AV |
1897 | /* In case no data transferred. */ |
1898 | bsg_job->reply->reply_payload_rcv_len = 0; | |
1899 | ||
7c3df132 SK |
1900 | if (bsg_job->request->msgcode == FC_BSG_RPT_ELS) { |
1901 | rport = bsg_job->rport; | |
1902 | fcport = *(fc_port_t **) rport->dd_data; | |
1903 | host = rport_to_shost(rport); | |
1904 | vha = shost_priv(host); | |
1905 | } else { | |
1906 | host = bsg_job->shost; | |
1907 | vha = shost_priv(host); | |
1908 | } | |
1909 | ||
d051a5aa AV |
1910 | if (qla2x00_reset_active(vha)) { |
1911 | ql_dbg(ql_dbg_user, vha, 0x709f, | |
1912 | "BSG: ISP abort active/needed -- cmd=%d.\n", | |
1913 | bsg_job->request->msgcode); | |
1914 | bsg_job->reply->result = (DID_ERROR << 16); | |
1915 | bsg_job->job_done(bsg_job); | |
1916 | return -EBUSY; | |
1917 | } | |
1918 | ||
7c3df132 | 1919 | ql_dbg(ql_dbg_user, vha, 0x7000, |
cfb0919c | 1920 | "Entered %s msgcode=0x%x.\n", __func__, bsg_job->request->msgcode); |
6e98016c GM |
1921 | |
1922 | switch (bsg_job->request->msgcode) { | |
1923 | case FC_BSG_RPT_ELS: | |
1924 | case FC_BSG_HST_ELS_NOLOGIN: | |
1925 | ret = qla2x00_process_els(bsg_job); | |
1926 | break; | |
1927 | case FC_BSG_HST_CT: | |
1928 | ret = qla2x00_process_ct(bsg_job); | |
1929 | break; | |
1930 | case FC_BSG_HST_VENDOR: | |
1931 | ret = qla2x00_process_vendor_specific(bsg_job); | |
1932 | break; | |
1933 | case FC_BSG_HST_ADD_RPORT: | |
1934 | case FC_BSG_HST_DEL_RPORT: | |
1935 | case FC_BSG_RPT_CT: | |
1936 | default: | |
7c3df132 | 1937 | ql_log(ql_log_warn, vha, 0x705a, "Unsupported BSG request.\n"); |
b7bfbe12 | 1938 | bsg_job->reply->result = ret; |
6e98016c | 1939 | break; |
6c452a45 | 1940 | } |
6e98016c GM |
1941 | return ret; |
1942 | } | |
1943 | ||
1944 | int | |
1945 | qla24xx_bsg_timeout(struct fc_bsg_job *bsg_job) | |
1946 | { | |
1947 | scsi_qla_host_t *vha = shost_priv(bsg_job->shost); | |
1948 | struct qla_hw_data *ha = vha->hw; | |
1949 | srb_t *sp; | |
1950 | int cnt, que; | |
1951 | unsigned long flags; | |
1952 | struct req_que *req; | |
6e98016c GM |
1953 | |
1954 | /* find the bsg job from the active list of commands */ | |
1955 | spin_lock_irqsave(&ha->hardware_lock, flags); | |
1956 | for (que = 0; que < ha->max_req_queues; que++) { | |
1957 | req = ha->req_q_map[que]; | |
1958 | if (!req) | |
1959 | continue; | |
1960 | ||
6c452a45 | 1961 | for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) { |
6e98016c | 1962 | sp = req->outstanding_cmds[cnt]; |
6e98016c | 1963 | if (sp) { |
9ba56b95 GM |
1964 | if (((sp->type == SRB_CT_CMD) || |
1965 | (sp->type == SRB_ELS_CMD_HST)) | |
1966 | && (sp->u.bsg_job == bsg_job)) { | |
900a36e3 | 1967 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
6e98016c | 1968 | if (ha->isp_ops->abort_command(sp)) { |
7c3df132 SK |
1969 | ql_log(ql_log_warn, vha, 0x7089, |
1970 | "mbx abort_command " | |
1971 | "failed.\n"); | |
6e98016c GM |
1972 | bsg_job->req->errors = |
1973 | bsg_job->reply->result = -EIO; | |
1974 | } else { | |
7c3df132 SK |
1975 | ql_dbg(ql_dbg_user, vha, 0x708a, |
1976 | "mbx abort_command " | |
1977 | "success.\n"); | |
6e98016c GM |
1978 | bsg_job->req->errors = |
1979 | bsg_job->reply->result = 0; | |
1980 | } | |
900a36e3 | 1981 | spin_lock_irqsave(&ha->hardware_lock, flags); |
6e98016c GM |
1982 | goto done; |
1983 | } | |
1984 | } | |
1985 | } | |
1986 | } | |
1987 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
7c3df132 | 1988 | ql_log(ql_log_info, vha, 0x708b, "SRB not found to abort.\n"); |
6e98016c GM |
1989 | bsg_job->req->errors = bsg_job->reply->result = -ENXIO; |
1990 | return 0; | |
1991 | ||
1992 | done: | |
1993 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
1994 | if (bsg_job->request->msgcode == FC_BSG_HST_CT) | |
1995 | kfree(sp->fcport); | |
6e98016c GM |
1996 | mempool_free(sp, ha->srb_mempool); |
1997 | return 0; | |
1998 | } |