Commit | Line | Data |
---|---|---|
dea3101e | 1 | /******************************************************************* |
2 | * This file is part of the Emulex Linux Device Driver for * | |
c44ce173 | 3 | * Fibre Channel Host Bus Adapters. * |
d8e93df1 | 4 | * Copyright (C) 2004-2009 Emulex. All rights reserved. * |
c44ce173 | 5 | * EMULEX and SLI are trademarks of Emulex. * |
dea3101e | 6 | * www.emulex.com * |
c44ce173 | 7 | * Portions Copyright (C) 2004-2005 Christoph Hellwig * |
dea3101e | 8 | * * |
9 | * This program is free software; you can redistribute it and/or * | |
c44ce173 JSEC |
10 | * modify it under the terms of version 2 of the GNU General * |
11 | * Public License as published by the Free Software Foundation. * | |
12 | * This program is distributed in the hope that it will be useful. * | |
13 | * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * | |
14 | * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * | |
15 | * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE * | |
16 | * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD * | |
17 | * TO BE LEGALLY INVALID. See the GNU General Public License for * | |
18 | * more details, a copy of which can be found in the file COPYING * | |
19 | * included with this package. * | |
dea3101e | 20 | *******************************************************************/ |
dea3101e | 21 | #include <linux/pci.h> |
22 | #include <linux/interrupt.h> | |
a90f5684 | 23 | #include <linux/delay.h> |
e2a0a9d6 | 24 | #include <asm/unaligned.h> |
dea3101e | 25 | |
26 | #include <scsi/scsi.h> | |
27 | #include <scsi/scsi_device.h> | |
e2a0a9d6 | 28 | #include <scsi/scsi_eh.h> |
dea3101e | 29 | #include <scsi/scsi_host.h> |
30 | #include <scsi/scsi_tcq.h> | |
31 | #include <scsi/scsi_transport_fc.h> | |
32 | ||
33 | #include "lpfc_version.h" | |
da0436e9 | 34 | #include "lpfc_hw4.h" |
dea3101e | 35 | #include "lpfc_hw.h" |
36 | #include "lpfc_sli.h" | |
da0436e9 | 37 | #include "lpfc_sli4.h" |
ea2151b4 | 38 | #include "lpfc_nl.h" |
dea3101e | 39 | #include "lpfc_disc.h" |
40 | #include "lpfc_scsi.h" | |
41 | #include "lpfc.h" | |
42 | #include "lpfc_logmsg.h" | |
43 | #include "lpfc_crtn.h" | |
92d7f7b0 | 44 | #include "lpfc_vport.h" |
dea3101e | 45 | |
46 | #define LPFC_RESET_WAIT 2 | |
47 | #define LPFC_ABORT_WAIT 2 | |
48 | ||
e2a0a9d6 JS |
49 | int _dump_buf_done; |
50 | ||
51 | static char *dif_op_str[] = { | |
52 | "SCSI_PROT_NORMAL", | |
53 | "SCSI_PROT_READ_INSERT", | |
54 | "SCSI_PROT_WRITE_STRIP", | |
55 | "SCSI_PROT_READ_STRIP", | |
56 | "SCSI_PROT_WRITE_INSERT", | |
57 | "SCSI_PROT_READ_PASS", | |
58 | "SCSI_PROT_WRITE_PASS", | |
59 | "SCSI_PROT_READ_CONVERT", | |
60 | "SCSI_PROT_WRITE_CONVERT" | |
61 | }; | |
da0436e9 JS |
62 | static void |
63 | lpfc_release_scsi_buf_s4(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb); | |
e2a0a9d6 JS |
64 | |
65 | static void | |
66 | lpfc_debug_save_data(struct scsi_cmnd *cmnd) | |
67 | { | |
68 | void *src, *dst; | |
69 | struct scatterlist *sgde = scsi_sglist(cmnd); | |
70 | ||
71 | if (!_dump_buf_data) { | |
72 | printk(KERN_ERR "BLKGRD ERROR %s _dump_buf_data is NULL\n", | |
73 | __func__); | |
74 | return; | |
75 | } | |
76 | ||
77 | ||
78 | if (!sgde) { | |
79 | printk(KERN_ERR "BLKGRD ERROR: data scatterlist is null\n"); | |
80 | return; | |
81 | } | |
82 | ||
83 | dst = (void *) _dump_buf_data; | |
84 | while (sgde) { | |
85 | src = sg_virt(sgde); | |
86 | memcpy(dst, src, sgde->length); | |
87 | dst += sgde->length; | |
88 | sgde = sg_next(sgde); | |
89 | } | |
90 | } | |
91 | ||
92 | static void | |
93 | lpfc_debug_save_dif(struct scsi_cmnd *cmnd) | |
94 | { | |
95 | void *src, *dst; | |
96 | struct scatterlist *sgde = scsi_prot_sglist(cmnd); | |
97 | ||
98 | if (!_dump_buf_dif) { | |
99 | printk(KERN_ERR "BLKGRD ERROR %s _dump_buf_data is NULL\n", | |
100 | __func__); | |
101 | return; | |
102 | } | |
103 | ||
104 | if (!sgde) { | |
105 | printk(KERN_ERR "BLKGRD ERROR: prot scatterlist is null\n"); | |
106 | return; | |
107 | } | |
108 | ||
109 | dst = _dump_buf_dif; | |
110 | while (sgde) { | |
111 | src = sg_virt(sgde); | |
112 | memcpy(dst, src, sgde->length); | |
113 | dst += sgde->length; | |
114 | sgde = sg_next(sgde); | |
115 | } | |
116 | } | |
117 | ||
f1126688 JS |
118 | /** |
119 | * lpfc_sli4_set_rsp_sgl_last - Set the last bit in the response sge. | |
120 | * @phba: Pointer to HBA object. | |
121 | * @lpfc_cmd: lpfc scsi command object pointer. | |
122 | * | |
123 | * This function is called from the lpfc_prep_task_mgmt_cmd function to | |
124 | * set the last bit in the response sge entry. | |
125 | **/ | |
126 | static void | |
127 | lpfc_sli4_set_rsp_sgl_last(struct lpfc_hba *phba, | |
128 | struct lpfc_scsi_buf *lpfc_cmd) | |
129 | { | |
130 | struct sli4_sge *sgl = (struct sli4_sge *)lpfc_cmd->fcp_bpl; | |
131 | if (sgl) { | |
132 | sgl += 1; | |
133 | sgl->word2 = le32_to_cpu(sgl->word2); | |
134 | bf_set(lpfc_sli4_sge_last, sgl, 1); | |
135 | sgl->word2 = cpu_to_le32(sgl->word2); | |
136 | } | |
137 | } | |
138 | ||
ea2151b4 | 139 | /** |
3621a710 | 140 | * lpfc_update_stats - Update statistical data for the command completion |
ea2151b4 JS |
141 | * @phba: Pointer to HBA object. |
142 | * @lpfc_cmd: lpfc scsi command object pointer. | |
143 | * | |
144 | * This function is called when there is a command completion and this | |
145 | * function updates the statistical data for the command completion. | |
146 | **/ | |
147 | static void | |
148 | lpfc_update_stats(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd) | |
149 | { | |
150 | struct lpfc_rport_data *rdata = lpfc_cmd->rdata; | |
151 | struct lpfc_nodelist *pnode = rdata->pnode; | |
152 | struct scsi_cmnd *cmd = lpfc_cmd->pCmd; | |
153 | unsigned long flags; | |
154 | struct Scsi_Host *shost = cmd->device->host; | |
155 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
156 | unsigned long latency; | |
157 | int i; | |
158 | ||
159 | if (cmd->result) | |
160 | return; | |
161 | ||
9f1e1b50 JS |
162 | latency = jiffies_to_msecs((long)jiffies - (long)lpfc_cmd->start_time); |
163 | ||
ea2151b4 JS |
164 | spin_lock_irqsave(shost->host_lock, flags); |
165 | if (!vport->stat_data_enabled || | |
166 | vport->stat_data_blocked || | |
167 | !pnode->lat_data || | |
168 | (phba->bucket_type == LPFC_NO_BUCKET)) { | |
169 | spin_unlock_irqrestore(shost->host_lock, flags); | |
170 | return; | |
171 | } | |
ea2151b4 JS |
172 | |
173 | if (phba->bucket_type == LPFC_LINEAR_BUCKET) { | |
174 | i = (latency + phba->bucket_step - 1 - phba->bucket_base)/ | |
175 | phba->bucket_step; | |
9f1e1b50 JS |
176 | /* check array subscript bounds */ |
177 | if (i < 0) | |
178 | i = 0; | |
179 | else if (i >= LPFC_MAX_BUCKET_COUNT) | |
180 | i = LPFC_MAX_BUCKET_COUNT - 1; | |
ea2151b4 JS |
181 | } else { |
182 | for (i = 0; i < LPFC_MAX_BUCKET_COUNT-1; i++) | |
183 | if (latency <= (phba->bucket_base + | |
184 | ((1<<i)*phba->bucket_step))) | |
185 | break; | |
186 | } | |
187 | ||
188 | pnode->lat_data[i].cmd_count++; | |
189 | spin_unlock_irqrestore(shost->host_lock, flags); | |
190 | } | |
191 | ||
ea2151b4 | 192 | /** |
3621a710 | 193 | * lpfc_send_sdev_queuedepth_change_event - Posts a queuedepth change event |
ea2151b4 JS |
194 | * @phba: Pointer to HBA context object. |
195 | * @vport: Pointer to vport object. | |
196 | * @ndlp: Pointer to FC node associated with the target. | |
197 | * @lun: Lun number of the scsi device. | |
198 | * @old_val: Old value of the queue depth. | |
199 | * @new_val: New value of the queue depth. | |
200 | * | |
201 | * This function sends an event to the mgmt application indicating | |
202 | * there is a change in the scsi device queue depth. | |
203 | **/ | |
204 | static void | |
205 | lpfc_send_sdev_queuedepth_change_event(struct lpfc_hba *phba, | |
206 | struct lpfc_vport *vport, | |
207 | struct lpfc_nodelist *ndlp, | |
208 | uint32_t lun, | |
209 | uint32_t old_val, | |
210 | uint32_t new_val) | |
211 | { | |
212 | struct lpfc_fast_path_event *fast_path_evt; | |
213 | unsigned long flags; | |
214 | ||
215 | fast_path_evt = lpfc_alloc_fast_evt(phba); | |
216 | if (!fast_path_evt) | |
217 | return; | |
218 | ||
219 | fast_path_evt->un.queue_depth_evt.scsi_event.event_type = | |
220 | FC_REG_SCSI_EVENT; | |
221 | fast_path_evt->un.queue_depth_evt.scsi_event.subcategory = | |
222 | LPFC_EVENT_VARQUEDEPTH; | |
223 | ||
224 | /* Report all luns with change in queue depth */ | |
225 | fast_path_evt->un.queue_depth_evt.scsi_event.lun = lun; | |
226 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { | |
227 | memcpy(&fast_path_evt->un.queue_depth_evt.scsi_event.wwpn, | |
228 | &ndlp->nlp_portname, sizeof(struct lpfc_name)); | |
229 | memcpy(&fast_path_evt->un.queue_depth_evt.scsi_event.wwnn, | |
230 | &ndlp->nlp_nodename, sizeof(struct lpfc_name)); | |
231 | } | |
232 | ||
233 | fast_path_evt->un.queue_depth_evt.oldval = old_val; | |
234 | fast_path_evt->un.queue_depth_evt.newval = new_val; | |
235 | fast_path_evt->vport = vport; | |
236 | ||
237 | fast_path_evt->work_evt.evt = LPFC_EVT_FASTPATH_MGMT_EVT; | |
238 | spin_lock_irqsave(&phba->hbalock, flags); | |
239 | list_add_tail(&fast_path_evt->work_evt.evt_listp, &phba->work_list); | |
240 | spin_unlock_irqrestore(&phba->hbalock, flags); | |
241 | lpfc_worker_wake_up(phba); | |
242 | ||
243 | return; | |
244 | } | |
245 | ||
9bad7671 | 246 | /** |
3621a710 | 247 | * lpfc_rampdown_queue_depth - Post RAMP_DOWN_QUEUE event to worker thread |
9bad7671 JS |
248 | * @phba: The Hba for which this call is being executed. |
249 | * | |
250 | * This routine is called when there is resource error in driver or firmware. | |
251 | * This routine posts WORKER_RAMP_DOWN_QUEUE event for @phba. This routine | |
252 | * posts at most 1 event each second. This routine wakes up worker thread of | |
253 | * @phba to process WORKER_RAM_DOWN_EVENT event. | |
254 | * | |
255 | * This routine should be called with no lock held. | |
256 | **/ | |
92d7f7b0 | 257 | void |
eaf15d5b | 258 | lpfc_rampdown_queue_depth(struct lpfc_hba *phba) |
92d7f7b0 JS |
259 | { |
260 | unsigned long flags; | |
5e9d9b82 | 261 | uint32_t evt_posted; |
92d7f7b0 JS |
262 | |
263 | spin_lock_irqsave(&phba->hbalock, flags); | |
264 | atomic_inc(&phba->num_rsrc_err); | |
265 | phba->last_rsrc_error_time = jiffies; | |
266 | ||
267 | if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) { | |
268 | spin_unlock_irqrestore(&phba->hbalock, flags); | |
269 | return; | |
270 | } | |
271 | ||
272 | phba->last_ramp_down_time = jiffies; | |
273 | ||
274 | spin_unlock_irqrestore(&phba->hbalock, flags); | |
275 | ||
276 | spin_lock_irqsave(&phba->pport->work_port_lock, flags); | |
5e9d9b82 JS |
277 | evt_posted = phba->pport->work_port_events & WORKER_RAMP_DOWN_QUEUE; |
278 | if (!evt_posted) | |
92d7f7b0 | 279 | phba->pport->work_port_events |= WORKER_RAMP_DOWN_QUEUE; |
92d7f7b0 JS |
280 | spin_unlock_irqrestore(&phba->pport->work_port_lock, flags); |
281 | ||
5e9d9b82 JS |
282 | if (!evt_posted) |
283 | lpfc_worker_wake_up(phba); | |
92d7f7b0 JS |
284 | return; |
285 | } | |
286 | ||
9bad7671 | 287 | /** |
3621a710 | 288 | * lpfc_rampup_queue_depth - Post RAMP_UP_QUEUE event for worker thread |
9bad7671 JS |
289 | * @phba: The Hba for which this call is being executed. |
290 | * | |
291 | * This routine post WORKER_RAMP_UP_QUEUE event for @phba vport. This routine | |
292 | * post at most 1 event every 5 minute after last_ramp_up_time or | |
293 | * last_rsrc_error_time. This routine wakes up worker thread of @phba | |
294 | * to process WORKER_RAM_DOWN_EVENT event. | |
295 | * | |
296 | * This routine should be called with no lock held. | |
297 | **/ | |
92d7f7b0 | 298 | static inline void |
3de2a653 | 299 | lpfc_rampup_queue_depth(struct lpfc_vport *vport, |
a257bf90 | 300 | uint32_t queue_depth) |
92d7f7b0 JS |
301 | { |
302 | unsigned long flags; | |
3de2a653 | 303 | struct lpfc_hba *phba = vport->phba; |
5e9d9b82 | 304 | uint32_t evt_posted; |
92d7f7b0 JS |
305 | atomic_inc(&phba->num_cmd_success); |
306 | ||
a257bf90 | 307 | if (vport->cfg_lun_queue_depth <= queue_depth) |
92d7f7b0 | 308 | return; |
92d7f7b0 JS |
309 | spin_lock_irqsave(&phba->hbalock, flags); |
310 | if (((phba->last_ramp_up_time + QUEUE_RAMP_UP_INTERVAL) > jiffies) || | |
311 | ((phba->last_rsrc_error_time + QUEUE_RAMP_UP_INTERVAL ) > jiffies)) { | |
312 | spin_unlock_irqrestore(&phba->hbalock, flags); | |
313 | return; | |
314 | } | |
92d7f7b0 JS |
315 | phba->last_ramp_up_time = jiffies; |
316 | spin_unlock_irqrestore(&phba->hbalock, flags); | |
317 | ||
318 | spin_lock_irqsave(&phba->pport->work_port_lock, flags); | |
5e9d9b82 JS |
319 | evt_posted = phba->pport->work_port_events & WORKER_RAMP_UP_QUEUE; |
320 | if (!evt_posted) | |
92d7f7b0 | 321 | phba->pport->work_port_events |= WORKER_RAMP_UP_QUEUE; |
92d7f7b0 JS |
322 | spin_unlock_irqrestore(&phba->pport->work_port_lock, flags); |
323 | ||
5e9d9b82 JS |
324 | if (!evt_posted) |
325 | lpfc_worker_wake_up(phba); | |
326 | return; | |
92d7f7b0 JS |
327 | } |
328 | ||
9bad7671 | 329 | /** |
3621a710 | 330 | * lpfc_ramp_down_queue_handler - WORKER_RAMP_DOWN_QUEUE event handler |
9bad7671 JS |
331 | * @phba: The Hba for which this call is being executed. |
332 | * | |
333 | * This routine is called to process WORKER_RAMP_DOWN_QUEUE event for worker | |
334 | * thread.This routine reduces queue depth for all scsi device on each vport | |
335 | * associated with @phba. | |
336 | **/ | |
92d7f7b0 JS |
337 | void |
338 | lpfc_ramp_down_queue_handler(struct lpfc_hba *phba) | |
339 | { | |
549e55cd JS |
340 | struct lpfc_vport **vports; |
341 | struct Scsi_Host *shost; | |
92d7f7b0 | 342 | struct scsi_device *sdev; |
ea2151b4 | 343 | unsigned long new_queue_depth, old_queue_depth; |
92d7f7b0 | 344 | unsigned long num_rsrc_err, num_cmd_success; |
549e55cd | 345 | int i; |
ea2151b4 | 346 | struct lpfc_rport_data *rdata; |
92d7f7b0 JS |
347 | |
348 | num_rsrc_err = atomic_read(&phba->num_rsrc_err); | |
349 | num_cmd_success = atomic_read(&phba->num_cmd_success); | |
350 | ||
549e55cd JS |
351 | vports = lpfc_create_vport_work_array(phba); |
352 | if (vports != NULL) | |
21e9a0a5 | 353 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
549e55cd JS |
354 | shost = lpfc_shost_from_vport(vports[i]); |
355 | shost_for_each_device(sdev, shost) { | |
92d7f7b0 | 356 | new_queue_depth = |
549e55cd JS |
357 | sdev->queue_depth * num_rsrc_err / |
358 | (num_rsrc_err + num_cmd_success); | |
359 | if (!new_queue_depth) | |
360 | new_queue_depth = sdev->queue_depth - 1; | |
361 | else | |
362 | new_queue_depth = sdev->queue_depth - | |
363 | new_queue_depth; | |
ea2151b4 | 364 | old_queue_depth = sdev->queue_depth; |
549e55cd JS |
365 | if (sdev->ordered_tags) |
366 | scsi_adjust_queue_depth(sdev, | |
367 | MSG_ORDERED_TAG, | |
368 | new_queue_depth); | |
369 | else | |
370 | scsi_adjust_queue_depth(sdev, | |
371 | MSG_SIMPLE_TAG, | |
372 | new_queue_depth); | |
ea2151b4 JS |
373 | rdata = sdev->hostdata; |
374 | if (rdata) | |
375 | lpfc_send_sdev_queuedepth_change_event( | |
376 | phba, vports[i], | |
377 | rdata->pnode, | |
378 | sdev->lun, old_queue_depth, | |
379 | new_queue_depth); | |
549e55cd | 380 | } |
92d7f7b0 | 381 | } |
09372820 | 382 | lpfc_destroy_vport_work_array(phba, vports); |
92d7f7b0 JS |
383 | atomic_set(&phba->num_rsrc_err, 0); |
384 | atomic_set(&phba->num_cmd_success, 0); | |
385 | } | |
386 | ||
9bad7671 | 387 | /** |
3621a710 | 388 | * lpfc_ramp_up_queue_handler - WORKER_RAMP_UP_QUEUE event handler |
9bad7671 JS |
389 | * @phba: The Hba for which this call is being executed. |
390 | * | |
391 | * This routine is called to process WORKER_RAMP_UP_QUEUE event for worker | |
392 | * thread.This routine increases queue depth for all scsi device on each vport | |
393 | * associated with @phba by 1. This routine also sets @phba num_rsrc_err and | |
394 | * num_cmd_success to zero. | |
395 | **/ | |
92d7f7b0 JS |
396 | void |
397 | lpfc_ramp_up_queue_handler(struct lpfc_hba *phba) | |
398 | { | |
549e55cd JS |
399 | struct lpfc_vport **vports; |
400 | struct Scsi_Host *shost; | |
92d7f7b0 | 401 | struct scsi_device *sdev; |
549e55cd | 402 | int i; |
ea2151b4 | 403 | struct lpfc_rport_data *rdata; |
549e55cd JS |
404 | |
405 | vports = lpfc_create_vport_work_array(phba); | |
406 | if (vports != NULL) | |
21e9a0a5 | 407 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
549e55cd JS |
408 | shost = lpfc_shost_from_vport(vports[i]); |
409 | shost_for_each_device(sdev, shost) { | |
97eab634 JS |
410 | if (vports[i]->cfg_lun_queue_depth <= |
411 | sdev->queue_depth) | |
412 | continue; | |
549e55cd JS |
413 | if (sdev->ordered_tags) |
414 | scsi_adjust_queue_depth(sdev, | |
415 | MSG_ORDERED_TAG, | |
416 | sdev->queue_depth+1); | |
417 | else | |
418 | scsi_adjust_queue_depth(sdev, | |
419 | MSG_SIMPLE_TAG, | |
420 | sdev->queue_depth+1); | |
ea2151b4 JS |
421 | rdata = sdev->hostdata; |
422 | if (rdata) | |
423 | lpfc_send_sdev_queuedepth_change_event( | |
424 | phba, vports[i], | |
425 | rdata->pnode, | |
426 | sdev->lun, | |
427 | sdev->queue_depth - 1, | |
428 | sdev->queue_depth); | |
549e55cd | 429 | } |
92d7f7b0 | 430 | } |
09372820 | 431 | lpfc_destroy_vport_work_array(phba, vports); |
92d7f7b0 JS |
432 | atomic_set(&phba->num_rsrc_err, 0); |
433 | atomic_set(&phba->num_cmd_success, 0); | |
434 | } | |
435 | ||
a8e497d5 | 436 | /** |
3621a710 | 437 | * lpfc_scsi_dev_block - set all scsi hosts to block state |
a8e497d5 JS |
438 | * @phba: Pointer to HBA context object. |
439 | * | |
440 | * This function walks vport list and set each SCSI host to block state | |
441 | * by invoking fc_remote_port_delete() routine. This function is invoked | |
442 | * with EEH when device's PCI slot has been permanently disabled. | |
443 | **/ | |
444 | void | |
445 | lpfc_scsi_dev_block(struct lpfc_hba *phba) | |
446 | { | |
447 | struct lpfc_vport **vports; | |
448 | struct Scsi_Host *shost; | |
449 | struct scsi_device *sdev; | |
450 | struct fc_rport *rport; | |
451 | int i; | |
452 | ||
453 | vports = lpfc_create_vport_work_array(phba); | |
454 | if (vports != NULL) | |
21e9a0a5 | 455 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
a8e497d5 JS |
456 | shost = lpfc_shost_from_vport(vports[i]); |
457 | shost_for_each_device(sdev, shost) { | |
458 | rport = starget_to_rport(scsi_target(sdev)); | |
459 | fc_remote_port_delete(rport); | |
460 | } | |
461 | } | |
462 | lpfc_destroy_vport_work_array(phba, vports); | |
463 | } | |
464 | ||
9bad7671 | 465 | /** |
3772a991 | 466 | * lpfc_new_scsi_buf_s3 - Scsi buffer allocator for HBA with SLI3 IF spec |
9bad7671 | 467 | * @vport: The virtual port for which this call being executed. |
3772a991 | 468 | * @num_to_allocate: The requested number of buffers to allocate. |
9bad7671 | 469 | * |
3772a991 JS |
470 | * This routine allocates a scsi buffer for device with SLI-3 interface spec, |
471 | * the scsi buffer contains all the necessary information needed to initiate | |
472 | * a SCSI I/O. The non-DMAable buffer region contains information to build | |
473 | * the IOCB. The DMAable region contains memory for the FCP CMND, FCP RSP, | |
474 | * and the initial BPL. In addition to allocating memory, the FCP CMND and | |
475 | * FCP RSP BDEs are setup in the BPL and the BPL BDE is setup in the IOCB. | |
9bad7671 JS |
476 | * |
477 | * Return codes: | |
3772a991 JS |
478 | * int - number of scsi buffers that were allocated. |
479 | * 0 = failure, less than num_to_alloc is a partial failure. | |
9bad7671 | 480 | **/ |
3772a991 JS |
481 | static int |
482 | lpfc_new_scsi_buf_s3(struct lpfc_vport *vport, int num_to_alloc) | |
dea3101e | 483 | { |
2e0fef85 | 484 | struct lpfc_hba *phba = vport->phba; |
dea3101e | 485 | struct lpfc_scsi_buf *psb; |
486 | struct ulp_bde64 *bpl; | |
487 | IOCB_t *iocb; | |
34b02dcd JS |
488 | dma_addr_t pdma_phys_fcp_cmd; |
489 | dma_addr_t pdma_phys_fcp_rsp; | |
490 | dma_addr_t pdma_phys_bpl; | |
604a3e30 | 491 | uint16_t iotag; |
3772a991 | 492 | int bcnt; |
dea3101e | 493 | |
3772a991 JS |
494 | for (bcnt = 0; bcnt < num_to_alloc; bcnt++) { |
495 | psb = kzalloc(sizeof(struct lpfc_scsi_buf), GFP_KERNEL); | |
496 | if (!psb) | |
497 | break; | |
dea3101e | 498 | |
3772a991 JS |
499 | /* |
500 | * Get memory from the pci pool to map the virt space to pci | |
501 | * bus space for an I/O. The DMA buffer includes space for the | |
502 | * struct fcp_cmnd, struct fcp_rsp and the number of bde's | |
503 | * necessary to support the sg_tablesize. | |
504 | */ | |
505 | psb->data = pci_pool_alloc(phba->lpfc_scsi_dma_buf_pool, | |
506 | GFP_KERNEL, &psb->dma_handle); | |
507 | if (!psb->data) { | |
508 | kfree(psb); | |
509 | break; | |
510 | } | |
511 | ||
512 | /* Initialize virtual ptrs to dma_buf region. */ | |
513 | memset(psb->data, 0, phba->cfg_sg_dma_buf_size); | |
514 | ||
515 | /* Allocate iotag for psb->cur_iocbq. */ | |
516 | iotag = lpfc_sli_next_iotag(phba, &psb->cur_iocbq); | |
517 | if (iotag == 0) { | |
518 | pci_pool_free(phba->lpfc_scsi_dma_buf_pool, | |
519 | psb->data, psb->dma_handle); | |
520 | kfree(psb); | |
521 | break; | |
522 | } | |
523 | psb->cur_iocbq.iocb_flag |= LPFC_IO_FCP; | |
524 | ||
525 | psb->fcp_cmnd = psb->data; | |
526 | psb->fcp_rsp = psb->data + sizeof(struct fcp_cmnd); | |
527 | psb->fcp_bpl = psb->data + sizeof(struct fcp_cmnd) + | |
34b02dcd | 528 | sizeof(struct fcp_rsp); |
dea3101e | 529 | |
3772a991 JS |
530 | /* Initialize local short-hand pointers. */ |
531 | bpl = psb->fcp_bpl; | |
532 | pdma_phys_fcp_cmd = psb->dma_handle; | |
533 | pdma_phys_fcp_rsp = psb->dma_handle + sizeof(struct fcp_cmnd); | |
534 | pdma_phys_bpl = psb->dma_handle + sizeof(struct fcp_cmnd) + | |
535 | sizeof(struct fcp_rsp); | |
536 | ||
537 | /* | |
538 | * The first two bdes are the FCP_CMD and FCP_RSP. The balance | |
539 | * are sg list bdes. Initialize the first two and leave the | |
540 | * rest for queuecommand. | |
541 | */ | |
542 | bpl[0].addrHigh = le32_to_cpu(putPaddrHigh(pdma_phys_fcp_cmd)); | |
543 | bpl[0].addrLow = le32_to_cpu(putPaddrLow(pdma_phys_fcp_cmd)); | |
544 | bpl[0].tus.f.bdeSize = sizeof(struct fcp_cmnd); | |
545 | bpl[0].tus.f.bdeFlags = BUFF_TYPE_BDE_64; | |
546 | bpl[0].tus.w = le32_to_cpu(bpl[0].tus.w); | |
547 | ||
548 | /* Setup the physical region for the FCP RSP */ | |
549 | bpl[1].addrHigh = le32_to_cpu(putPaddrHigh(pdma_phys_fcp_rsp)); | |
550 | bpl[1].addrLow = le32_to_cpu(putPaddrLow(pdma_phys_fcp_rsp)); | |
551 | bpl[1].tus.f.bdeSize = sizeof(struct fcp_rsp); | |
552 | bpl[1].tus.f.bdeFlags = BUFF_TYPE_BDE_64; | |
553 | bpl[1].tus.w = le32_to_cpu(bpl[1].tus.w); | |
554 | ||
555 | /* | |
556 | * Since the IOCB for the FCP I/O is built into this | |
557 | * lpfc_scsi_buf, initialize it with all known data now. | |
558 | */ | |
559 | iocb = &psb->cur_iocbq.iocb; | |
560 | iocb->un.fcpi64.bdl.ulpIoTag32 = 0; | |
561 | if ((phba->sli_rev == 3) && | |
562 | !(phba->sli3_options & LPFC_SLI3_BG_ENABLED)) { | |
563 | /* fill in immediate fcp command BDE */ | |
564 | iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BDE_IMMED; | |
565 | iocb->un.fcpi64.bdl.bdeSize = sizeof(struct fcp_cmnd); | |
566 | iocb->un.fcpi64.bdl.addrLow = offsetof(IOCB_t, | |
567 | unsli3.fcp_ext.icd); | |
568 | iocb->un.fcpi64.bdl.addrHigh = 0; | |
569 | iocb->ulpBdeCount = 0; | |
570 | iocb->ulpLe = 0; | |
571 | /* fill in responce BDE */ | |
572 | iocb->unsli3.fcp_ext.rbde.tus.f.bdeFlags = | |
573 | BUFF_TYPE_BDE_64; | |
574 | iocb->unsli3.fcp_ext.rbde.tus.f.bdeSize = | |
575 | sizeof(struct fcp_rsp); | |
576 | iocb->unsli3.fcp_ext.rbde.addrLow = | |
577 | putPaddrLow(pdma_phys_fcp_rsp); | |
578 | iocb->unsli3.fcp_ext.rbde.addrHigh = | |
579 | putPaddrHigh(pdma_phys_fcp_rsp); | |
580 | } else { | |
581 | iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BLP_64; | |
582 | iocb->un.fcpi64.bdl.bdeSize = | |
583 | (2 * sizeof(struct ulp_bde64)); | |
584 | iocb->un.fcpi64.bdl.addrLow = | |
585 | putPaddrLow(pdma_phys_bpl); | |
586 | iocb->un.fcpi64.bdl.addrHigh = | |
587 | putPaddrHigh(pdma_phys_bpl); | |
588 | iocb->ulpBdeCount = 1; | |
589 | iocb->ulpLe = 1; | |
590 | } | |
591 | iocb->ulpClass = CLASS3; | |
592 | psb->status = IOSTAT_SUCCESS; | |
da0436e9 JS |
593 | /* Put it back into the SCSI buffer list */ |
594 | lpfc_release_scsi_buf_s4(phba, psb); | |
dea3101e | 595 | |
34b02dcd | 596 | } |
dea3101e | 597 | |
3772a991 | 598 | return bcnt; |
dea3101e | 599 | } |
600 | ||
da0436e9 JS |
601 | /** |
602 | * lpfc_sli4_fcp_xri_aborted - Fast-path process of fcp xri abort | |
603 | * @phba: pointer to lpfc hba data structure. | |
604 | * @axri: pointer to the fcp xri abort wcqe structure. | |
605 | * | |
606 | * This routine is invoked by the worker thread to process a SLI4 fast-path | |
607 | * FCP aborted xri. | |
608 | **/ | |
609 | void | |
610 | lpfc_sli4_fcp_xri_aborted(struct lpfc_hba *phba, | |
611 | struct sli4_wcqe_xri_aborted *axri) | |
612 | { | |
613 | uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri); | |
614 | struct lpfc_scsi_buf *psb, *next_psb; | |
615 | unsigned long iflag = 0; | |
616 | ||
617 | spin_lock_irqsave(&phba->sli4_hba.abts_scsi_buf_list_lock, iflag); | |
618 | list_for_each_entry_safe(psb, next_psb, | |
619 | &phba->sli4_hba.lpfc_abts_scsi_buf_list, list) { | |
620 | if (psb->cur_iocbq.sli4_xritag == xri) { | |
621 | list_del(&psb->list); | |
622 | psb->status = IOSTAT_SUCCESS; | |
623 | spin_unlock_irqrestore( | |
624 | &phba->sli4_hba.abts_scsi_buf_list_lock, | |
625 | iflag); | |
626 | lpfc_release_scsi_buf_s4(phba, psb); | |
627 | return; | |
628 | } | |
629 | } | |
630 | spin_unlock_irqrestore(&phba->sli4_hba.abts_scsi_buf_list_lock, | |
631 | iflag); | |
632 | } | |
633 | ||
634 | /** | |
635 | * lpfc_sli4_repost_scsi_sgl_list - Repsot the Scsi buffers sgl pages as block | |
636 | * @phba: pointer to lpfc hba data structure. | |
637 | * | |
638 | * This routine walks the list of scsi buffers that have been allocated and | |
639 | * repost them to the HBA by using SGL block post. This is needed after a | |
640 | * pci_function_reset/warm_start or start. The lpfc_hba_down_post_s4 routine | |
641 | * is responsible for moving all scsi buffers on the lpfc_abts_scsi_sgl_list | |
642 | * to the lpfc_scsi_buf_list. If the repost fails, reject all scsi buffers. | |
643 | * | |
644 | * Returns: 0 = success, non-zero failure. | |
645 | **/ | |
646 | int | |
647 | lpfc_sli4_repost_scsi_sgl_list(struct lpfc_hba *phba) | |
648 | { | |
649 | struct lpfc_scsi_buf *psb; | |
650 | int index, status, bcnt = 0, rcnt = 0, rc = 0; | |
651 | LIST_HEAD(sblist); | |
652 | ||
653 | for (index = 0; index < phba->sli4_hba.scsi_xri_cnt; index++) { | |
654 | psb = phba->sli4_hba.lpfc_scsi_psb_array[index]; | |
655 | if (psb) { | |
656 | /* Remove from SCSI buffer list */ | |
657 | list_del(&psb->list); | |
658 | /* Add it to a local SCSI buffer list */ | |
659 | list_add_tail(&psb->list, &sblist); | |
660 | if (++rcnt == LPFC_NEMBED_MBOX_SGL_CNT) { | |
661 | bcnt = rcnt; | |
662 | rcnt = 0; | |
663 | } | |
664 | } else | |
665 | /* A hole present in the XRI array, need to skip */ | |
666 | bcnt = rcnt; | |
667 | ||
668 | if (index == phba->sli4_hba.scsi_xri_cnt - 1) | |
669 | /* End of XRI array for SCSI buffer, complete */ | |
670 | bcnt = rcnt; | |
671 | ||
672 | /* Continue until collect up to a nembed page worth of sgls */ | |
673 | if (bcnt == 0) | |
674 | continue; | |
675 | /* Now, post the SCSI buffer list sgls as a block */ | |
676 | status = lpfc_sli4_post_scsi_sgl_block(phba, &sblist, bcnt); | |
677 | /* Reset SCSI buffer count for next round of posting */ | |
678 | bcnt = 0; | |
679 | while (!list_empty(&sblist)) { | |
680 | list_remove_head(&sblist, psb, struct lpfc_scsi_buf, | |
681 | list); | |
682 | if (status) { | |
683 | /* Put this back on the abort scsi list */ | |
684 | psb->status = IOSTAT_LOCAL_REJECT; | |
685 | psb->result = IOERR_ABORT_REQUESTED; | |
686 | rc++; | |
687 | } else | |
688 | psb->status = IOSTAT_SUCCESS; | |
689 | /* Put it back into the SCSI buffer list */ | |
690 | lpfc_release_scsi_buf_s4(phba, psb); | |
691 | } | |
692 | } | |
693 | return rc; | |
694 | } | |
695 | ||
696 | /** | |
697 | * lpfc_new_scsi_buf_s4 - Scsi buffer allocator for HBA with SLI4 IF spec | |
698 | * @vport: The virtual port for which this call being executed. | |
699 | * @num_to_allocate: The requested number of buffers to allocate. | |
700 | * | |
701 | * This routine allocates a scsi buffer for device with SLI-4 interface spec, | |
702 | * the scsi buffer contains all the necessary information needed to initiate | |
703 | * a SCSI I/O. | |
704 | * | |
705 | * Return codes: | |
706 | * int - number of scsi buffers that were allocated. | |
707 | * 0 = failure, less than num_to_alloc is a partial failure. | |
708 | **/ | |
709 | static int | |
710 | lpfc_new_scsi_buf_s4(struct lpfc_vport *vport, int num_to_alloc) | |
711 | { | |
712 | struct lpfc_hba *phba = vport->phba; | |
713 | struct lpfc_scsi_buf *psb; | |
714 | struct sli4_sge *sgl; | |
715 | IOCB_t *iocb; | |
716 | dma_addr_t pdma_phys_fcp_cmd; | |
717 | dma_addr_t pdma_phys_fcp_rsp; | |
718 | dma_addr_t pdma_phys_bpl, pdma_phys_bpl1; | |
719 | uint16_t iotag, last_xritag = NO_XRI; | |
720 | int status = 0, index; | |
721 | int bcnt; | |
722 | int non_sequential_xri = 0; | |
723 | int rc = 0; | |
724 | LIST_HEAD(sblist); | |
725 | ||
726 | for (bcnt = 0; bcnt < num_to_alloc; bcnt++) { | |
727 | psb = kzalloc(sizeof(struct lpfc_scsi_buf), GFP_KERNEL); | |
728 | if (!psb) | |
729 | break; | |
730 | ||
731 | /* | |
732 | * Get memory from the pci pool to map the virt space to pci bus | |
733 | * space for an I/O. The DMA buffer includes space for the | |
734 | * struct fcp_cmnd, struct fcp_rsp and the number of bde's | |
735 | * necessary to support the sg_tablesize. | |
736 | */ | |
737 | psb->data = pci_pool_alloc(phba->lpfc_scsi_dma_buf_pool, | |
738 | GFP_KERNEL, &psb->dma_handle); | |
739 | if (!psb->data) { | |
740 | kfree(psb); | |
741 | break; | |
742 | } | |
743 | ||
744 | /* Initialize virtual ptrs to dma_buf region. */ | |
745 | memset(psb->data, 0, phba->cfg_sg_dma_buf_size); | |
746 | ||
747 | /* Allocate iotag for psb->cur_iocbq. */ | |
748 | iotag = lpfc_sli_next_iotag(phba, &psb->cur_iocbq); | |
749 | if (iotag == 0) { | |
750 | kfree(psb); | |
751 | break; | |
752 | } | |
753 | ||
754 | psb->cur_iocbq.sli4_xritag = lpfc_sli4_next_xritag(phba); | |
755 | if (psb->cur_iocbq.sli4_xritag == NO_XRI) { | |
756 | pci_pool_free(phba->lpfc_scsi_dma_buf_pool, | |
757 | psb->data, psb->dma_handle); | |
758 | kfree(psb); | |
759 | break; | |
760 | } | |
761 | if (last_xritag != NO_XRI | |
762 | && psb->cur_iocbq.sli4_xritag != (last_xritag+1)) { | |
763 | non_sequential_xri = 1; | |
764 | } else | |
765 | list_add_tail(&psb->list, &sblist); | |
766 | last_xritag = psb->cur_iocbq.sli4_xritag; | |
767 | ||
768 | index = phba->sli4_hba.scsi_xri_cnt++; | |
769 | psb->cur_iocbq.iocb_flag |= LPFC_IO_FCP; | |
770 | ||
771 | psb->fcp_bpl = psb->data; | |
772 | psb->fcp_cmnd = (psb->data + phba->cfg_sg_dma_buf_size) | |
773 | - (sizeof(struct fcp_cmnd) + sizeof(struct fcp_rsp)); | |
774 | psb->fcp_rsp = (struct fcp_rsp *)((uint8_t *)psb->fcp_cmnd + | |
775 | sizeof(struct fcp_cmnd)); | |
776 | ||
777 | /* Initialize local short-hand pointers. */ | |
778 | sgl = (struct sli4_sge *)psb->fcp_bpl; | |
779 | pdma_phys_bpl = psb->dma_handle; | |
780 | pdma_phys_fcp_cmd = | |
781 | (psb->dma_handle + phba->cfg_sg_dma_buf_size) | |
782 | - (sizeof(struct fcp_cmnd) + sizeof(struct fcp_rsp)); | |
783 | pdma_phys_fcp_rsp = pdma_phys_fcp_cmd + sizeof(struct fcp_cmnd); | |
784 | ||
785 | /* | |
786 | * The first two bdes are the FCP_CMD and FCP_RSP. The balance | |
787 | * are sg list bdes. Initialize the first two and leave the | |
788 | * rest for queuecommand. | |
789 | */ | |
790 | sgl->addr_hi = cpu_to_le32(putPaddrHigh(pdma_phys_fcp_cmd)); | |
791 | sgl->addr_lo = cpu_to_le32(putPaddrLow(pdma_phys_fcp_cmd)); | |
792 | bf_set(lpfc_sli4_sge_len, sgl, sizeof(struct fcp_cmnd)); | |
793 | bf_set(lpfc_sli4_sge_last, sgl, 0); | |
794 | sgl->word2 = cpu_to_le32(sgl->word2); | |
795 | sgl->word3 = cpu_to_le32(sgl->word3); | |
796 | sgl++; | |
797 | ||
798 | /* Setup the physical region for the FCP RSP */ | |
799 | sgl->addr_hi = cpu_to_le32(putPaddrHigh(pdma_phys_fcp_rsp)); | |
800 | sgl->addr_lo = cpu_to_le32(putPaddrLow(pdma_phys_fcp_rsp)); | |
801 | bf_set(lpfc_sli4_sge_len, sgl, sizeof(struct fcp_rsp)); | |
802 | bf_set(lpfc_sli4_sge_last, sgl, 1); | |
803 | sgl->word2 = cpu_to_le32(sgl->word2); | |
804 | sgl->word3 = cpu_to_le32(sgl->word3); | |
805 | ||
806 | /* | |
807 | * Since the IOCB for the FCP I/O is built into this | |
808 | * lpfc_scsi_buf, initialize it with all known data now. | |
809 | */ | |
810 | iocb = &psb->cur_iocbq.iocb; | |
811 | iocb->un.fcpi64.bdl.ulpIoTag32 = 0; | |
812 | iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BDE_64; | |
813 | /* setting the BLP size to 2 * sizeof BDE may not be correct. | |
814 | * We are setting the bpl to point to out sgl. An sgl's | |
815 | * entries are 16 bytes, a bpl entries are 12 bytes. | |
816 | */ | |
817 | iocb->un.fcpi64.bdl.bdeSize = sizeof(struct fcp_cmnd); | |
818 | iocb->un.fcpi64.bdl.addrLow = putPaddrLow(pdma_phys_fcp_cmd); | |
819 | iocb->un.fcpi64.bdl.addrHigh = putPaddrHigh(pdma_phys_fcp_cmd); | |
820 | iocb->ulpBdeCount = 1; | |
821 | iocb->ulpLe = 1; | |
822 | iocb->ulpClass = CLASS3; | |
823 | if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE) | |
824 | pdma_phys_bpl1 = pdma_phys_bpl + SGL_PAGE_SIZE; | |
825 | else | |
826 | pdma_phys_bpl1 = 0; | |
827 | psb->dma_phys_bpl = pdma_phys_bpl; | |
828 | phba->sli4_hba.lpfc_scsi_psb_array[index] = psb; | |
829 | if (non_sequential_xri) { | |
830 | status = lpfc_sli4_post_sgl(phba, pdma_phys_bpl, | |
831 | pdma_phys_bpl1, | |
832 | psb->cur_iocbq.sli4_xritag); | |
833 | if (status) { | |
834 | /* Put this back on the abort scsi list */ | |
835 | psb->status = IOSTAT_LOCAL_REJECT; | |
836 | psb->result = IOERR_ABORT_REQUESTED; | |
837 | rc++; | |
838 | } else | |
839 | psb->status = IOSTAT_SUCCESS; | |
840 | /* Put it back into the SCSI buffer list */ | |
841 | lpfc_release_scsi_buf_s4(phba, psb); | |
842 | break; | |
843 | } | |
844 | } | |
845 | if (bcnt) { | |
846 | status = lpfc_sli4_post_scsi_sgl_block(phba, &sblist, bcnt); | |
847 | /* Reset SCSI buffer count for next round of posting */ | |
848 | while (!list_empty(&sblist)) { | |
849 | list_remove_head(&sblist, psb, struct lpfc_scsi_buf, | |
850 | list); | |
851 | if (status) { | |
852 | /* Put this back on the abort scsi list */ | |
853 | psb->status = IOSTAT_LOCAL_REJECT; | |
854 | psb->result = IOERR_ABORT_REQUESTED; | |
855 | rc++; | |
856 | } else | |
857 | psb->status = IOSTAT_SUCCESS; | |
858 | /* Put it back into the SCSI buffer list */ | |
859 | lpfc_release_scsi_buf_s4(phba, psb); | |
860 | } | |
861 | } | |
862 | ||
863 | return bcnt + non_sequential_xri - rc; | |
864 | } | |
865 | ||
9bad7671 | 866 | /** |
3772a991 JS |
867 | * lpfc_new_scsi_buf - Wrapper funciton for scsi buffer allocator |
868 | * @vport: The virtual port for which this call being executed. | |
869 | * @num_to_allocate: The requested number of buffers to allocate. | |
870 | * | |
871 | * This routine wraps the actual SCSI buffer allocator function pointer from | |
872 | * the lpfc_hba struct. | |
873 | * | |
874 | * Return codes: | |
875 | * int - number of scsi buffers that were allocated. | |
876 | * 0 = failure, less than num_to_alloc is a partial failure. | |
877 | **/ | |
878 | static inline int | |
879 | lpfc_new_scsi_buf(struct lpfc_vport *vport, int num_to_alloc) | |
880 | { | |
881 | return vport->phba->lpfc_new_scsi_buf(vport, num_to_alloc); | |
882 | } | |
883 | ||
884 | /** | |
885 | * lpfc_get_scsi_buf - Get a scsi buffer from lpfc_scsi_buf_list of the HBA | |
886 | * @phba: The HBA for which this call is being executed. | |
9bad7671 JS |
887 | * |
888 | * This routine removes a scsi buffer from head of @phba lpfc_scsi_buf_list list | |
889 | * and returns to caller. | |
890 | * | |
891 | * Return codes: | |
892 | * NULL - Error | |
893 | * Pointer to lpfc_scsi_buf - Success | |
894 | **/ | |
455c53ec | 895 | static struct lpfc_scsi_buf* |
875fbdfe | 896 | lpfc_get_scsi_buf(struct lpfc_hba * phba) |
dea3101e | 897 | { |
0bd4ca25 JSEC |
898 | struct lpfc_scsi_buf * lpfc_cmd = NULL; |
899 | struct list_head *scsi_buf_list = &phba->lpfc_scsi_buf_list; | |
875fbdfe | 900 | unsigned long iflag = 0; |
0bd4ca25 | 901 | |
875fbdfe | 902 | spin_lock_irqsave(&phba->scsi_buf_list_lock, iflag); |
0bd4ca25 | 903 | list_remove_head(scsi_buf_list, lpfc_cmd, struct lpfc_scsi_buf, list); |
1dcb58e5 JS |
904 | if (lpfc_cmd) { |
905 | lpfc_cmd->seg_cnt = 0; | |
906 | lpfc_cmd->nonsg_phys = 0; | |
e2a0a9d6 | 907 | lpfc_cmd->prot_seg_cnt = 0; |
1dcb58e5 | 908 | } |
875fbdfe | 909 | spin_unlock_irqrestore(&phba->scsi_buf_list_lock, iflag); |
0bd4ca25 JSEC |
910 | return lpfc_cmd; |
911 | } | |
dea3101e | 912 | |
9bad7671 | 913 | /** |
3772a991 | 914 | * lpfc_release_scsi_buf - Return a scsi buffer back to hba scsi buf list |
9bad7671 JS |
915 | * @phba: The Hba for which this call is being executed. |
916 | * @psb: The scsi buffer which is being released. | |
917 | * | |
918 | * This routine releases @psb scsi buffer by adding it to tail of @phba | |
919 | * lpfc_scsi_buf_list list. | |
920 | **/ | |
0bd4ca25 | 921 | static void |
3772a991 | 922 | lpfc_release_scsi_buf_s3(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb) |
0bd4ca25 | 923 | { |
875fbdfe | 924 | unsigned long iflag = 0; |
dea3101e | 925 | |
875fbdfe | 926 | spin_lock_irqsave(&phba->scsi_buf_list_lock, iflag); |
0bd4ca25 | 927 | psb->pCmd = NULL; |
dea3101e | 928 | list_add_tail(&psb->list, &phba->lpfc_scsi_buf_list); |
875fbdfe | 929 | spin_unlock_irqrestore(&phba->scsi_buf_list_lock, iflag); |
dea3101e | 930 | } |
931 | ||
da0436e9 JS |
932 | /** |
933 | * lpfc_release_scsi_buf_s4: Return a scsi buffer back to hba scsi buf list. | |
934 | * @phba: The Hba for which this call is being executed. | |
935 | * @psb: The scsi buffer which is being released. | |
936 | * | |
937 | * This routine releases @psb scsi buffer by adding it to tail of @phba | |
938 | * lpfc_scsi_buf_list list. For SLI4 XRI's are tied to the scsi buffer | |
939 | * and cannot be reused for at least RA_TOV amount of time if it was | |
940 | * aborted. | |
941 | **/ | |
942 | static void | |
943 | lpfc_release_scsi_buf_s4(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb) | |
944 | { | |
945 | unsigned long iflag = 0; | |
946 | ||
947 | if (psb->status == IOSTAT_LOCAL_REJECT | |
948 | && psb->result == IOERR_ABORT_REQUESTED) { | |
949 | spin_lock_irqsave(&phba->sli4_hba.abts_scsi_buf_list_lock, | |
950 | iflag); | |
951 | psb->pCmd = NULL; | |
952 | list_add_tail(&psb->list, | |
953 | &phba->sli4_hba.lpfc_abts_scsi_buf_list); | |
954 | spin_unlock_irqrestore(&phba->sli4_hba.abts_scsi_buf_list_lock, | |
955 | iflag); | |
956 | } else { | |
957 | ||
958 | spin_lock_irqsave(&phba->scsi_buf_list_lock, iflag); | |
959 | psb->pCmd = NULL; | |
960 | list_add_tail(&psb->list, &phba->lpfc_scsi_buf_list); | |
961 | spin_unlock_irqrestore(&phba->scsi_buf_list_lock, iflag); | |
962 | } | |
963 | } | |
964 | ||
9bad7671 | 965 | /** |
3772a991 JS |
966 | * lpfc_release_scsi_buf: Return a scsi buffer back to hba scsi buf list. |
967 | * @phba: The Hba for which this call is being executed. | |
968 | * @psb: The scsi buffer which is being released. | |
969 | * | |
970 | * This routine releases @psb scsi buffer by adding it to tail of @phba | |
971 | * lpfc_scsi_buf_list list. | |
972 | **/ | |
973 | static void | |
974 | lpfc_release_scsi_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb) | |
975 | { | |
976 | ||
977 | phba->lpfc_release_scsi_buf(phba, psb); | |
978 | } | |
979 | ||
980 | /** | |
981 | * lpfc_scsi_prep_dma_buf_s3 - DMA mapping for scsi buffer to SLI3 IF spec | |
9bad7671 JS |
982 | * @phba: The Hba for which this call is being executed. |
983 | * @lpfc_cmd: The scsi buffer which is going to be mapped. | |
984 | * | |
985 | * This routine does the pci dma mapping for scatter-gather list of scsi cmnd | |
3772a991 JS |
986 | * field of @lpfc_cmd for device with SLI-3 interface spec. This routine scans |
987 | * through sg elements and format the bdea. This routine also initializes all | |
988 | * IOCB fields which are dependent on scsi command request buffer. | |
9bad7671 JS |
989 | * |
990 | * Return codes: | |
991 | * 1 - Error | |
992 | * 0 - Success | |
993 | **/ | |
dea3101e | 994 | static int |
3772a991 | 995 | lpfc_scsi_prep_dma_buf_s3(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd) |
dea3101e | 996 | { |
997 | struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; | |
998 | struct scatterlist *sgel = NULL; | |
999 | struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; | |
1000 | struct ulp_bde64 *bpl = lpfc_cmd->fcp_bpl; | |
1001 | IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb; | |
34b02dcd | 1002 | struct ulp_bde64 *data_bde = iocb_cmd->unsli3.fcp_ext.dbde; |
dea3101e | 1003 | dma_addr_t physaddr; |
34b02dcd | 1004 | uint32_t num_bde = 0; |
a0b4f78f | 1005 | int nseg, datadir = scsi_cmnd->sc_data_direction; |
dea3101e | 1006 | |
1007 | /* | |
1008 | * There are three possibilities here - use scatter-gather segment, use | |
1009 | * the single mapping, or neither. Start the lpfc command prep by | |
1010 | * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first | |
1011 | * data bde entry. | |
1012 | */ | |
1013 | bpl += 2; | |
c59fd9eb | 1014 | if (scsi_sg_count(scsi_cmnd)) { |
dea3101e | 1015 | /* |
1016 | * The driver stores the segment count returned from pci_map_sg | |
1017 | * because this a count of dma-mappings used to map the use_sg | |
1018 | * pages. They are not guaranteed to be the same for those | |
1019 | * architectures that implement an IOMMU. | |
1020 | */ | |
dea3101e | 1021 | |
c59fd9eb FT |
1022 | nseg = dma_map_sg(&phba->pcidev->dev, scsi_sglist(scsi_cmnd), |
1023 | scsi_sg_count(scsi_cmnd), datadir); | |
1024 | if (unlikely(!nseg)) | |
1025 | return 1; | |
1026 | ||
a0b4f78f | 1027 | lpfc_cmd->seg_cnt = nseg; |
dea3101e | 1028 | if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) { |
1029 | printk(KERN_ERR "%s: Too many sg segments from " | |
e2a0a9d6 | 1030 | "dma_map_sg. Config %d, seg_cnt %d\n", |
cadbd4a5 | 1031 | __func__, phba->cfg_sg_seg_cnt, |
dea3101e | 1032 | lpfc_cmd->seg_cnt); |
a0b4f78f | 1033 | scsi_dma_unmap(scsi_cmnd); |
dea3101e | 1034 | return 1; |
1035 | } | |
1036 | ||
1037 | /* | |
1038 | * The driver established a maximum scatter-gather segment count | |
1039 | * during probe that limits the number of sg elements in any | |
1040 | * single scsi command. Just run through the seg_cnt and format | |
1041 | * the bde's. | |
34b02dcd JS |
1042 | * When using SLI-3 the driver will try to fit all the BDEs into |
1043 | * the IOCB. If it can't then the BDEs get added to a BPL as it | |
1044 | * does for SLI-2 mode. | |
dea3101e | 1045 | */ |
34b02dcd | 1046 | scsi_for_each_sg(scsi_cmnd, sgel, nseg, num_bde) { |
dea3101e | 1047 | physaddr = sg_dma_address(sgel); |
34b02dcd | 1048 | if (phba->sli_rev == 3 && |
e2a0a9d6 | 1049 | !(phba->sli3_options & LPFC_SLI3_BG_ENABLED) && |
34b02dcd JS |
1050 | nseg <= LPFC_EXT_DATA_BDE_COUNT) { |
1051 | data_bde->tus.f.bdeFlags = BUFF_TYPE_BDE_64; | |
1052 | data_bde->tus.f.bdeSize = sg_dma_len(sgel); | |
1053 | data_bde->addrLow = putPaddrLow(physaddr); | |
1054 | data_bde->addrHigh = putPaddrHigh(physaddr); | |
1055 | data_bde++; | |
1056 | } else { | |
1057 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; | |
1058 | bpl->tus.f.bdeSize = sg_dma_len(sgel); | |
1059 | bpl->tus.w = le32_to_cpu(bpl->tus.w); | |
1060 | bpl->addrLow = | |
1061 | le32_to_cpu(putPaddrLow(physaddr)); | |
1062 | bpl->addrHigh = | |
1063 | le32_to_cpu(putPaddrHigh(physaddr)); | |
1064 | bpl++; | |
1065 | } | |
dea3101e | 1066 | } |
c59fd9eb | 1067 | } |
dea3101e | 1068 | |
1069 | /* | |
1070 | * Finish initializing those IOCB fields that are dependent on the | |
34b02dcd JS |
1071 | * scsi_cmnd request_buffer. Note that for SLI-2 the bdeSize is |
1072 | * explicitly reinitialized and for SLI-3 the extended bde count is | |
1073 | * explicitly reinitialized since all iocb memory resources are reused. | |
dea3101e | 1074 | */ |
e2a0a9d6 JS |
1075 | if (phba->sli_rev == 3 && |
1076 | !(phba->sli3_options & LPFC_SLI3_BG_ENABLED)) { | |
34b02dcd JS |
1077 | if (num_bde > LPFC_EXT_DATA_BDE_COUNT) { |
1078 | /* | |
1079 | * The extended IOCB format can only fit 3 BDE or a BPL. | |
1080 | * This I/O has more than 3 BDE so the 1st data bde will | |
1081 | * be a BPL that is filled in here. | |
1082 | */ | |
1083 | physaddr = lpfc_cmd->dma_handle; | |
1084 | data_bde->tus.f.bdeFlags = BUFF_TYPE_BLP_64; | |
1085 | data_bde->tus.f.bdeSize = (num_bde * | |
1086 | sizeof(struct ulp_bde64)); | |
1087 | physaddr += (sizeof(struct fcp_cmnd) + | |
1088 | sizeof(struct fcp_rsp) + | |
1089 | (2 * sizeof(struct ulp_bde64))); | |
1090 | data_bde->addrHigh = putPaddrHigh(physaddr); | |
1091 | data_bde->addrLow = putPaddrLow(physaddr); | |
1092 | /* ebde count includes the responce bde and data bpl */ | |
1093 | iocb_cmd->unsli3.fcp_ext.ebde_count = 2; | |
1094 | } else { | |
1095 | /* ebde count includes the responce bde and data bdes */ | |
1096 | iocb_cmd->unsli3.fcp_ext.ebde_count = (num_bde + 1); | |
1097 | } | |
1098 | } else { | |
1099 | iocb_cmd->un.fcpi64.bdl.bdeSize = | |
1100 | ((num_bde + 2) * sizeof(struct ulp_bde64)); | |
1101 | } | |
09372820 | 1102 | fcp_cmnd->fcpDl = cpu_to_be32(scsi_bufflen(scsi_cmnd)); |
e2a0a9d6 JS |
1103 | |
1104 | /* | |
1105 | * Due to difference in data length between DIF/non-DIF paths, | |
1106 | * we need to set word 4 of IOCB here | |
1107 | */ | |
a257bf90 | 1108 | iocb_cmd->un.fcpi.fcpi_parm = scsi_bufflen(scsi_cmnd); |
e2a0a9d6 JS |
1109 | return 0; |
1110 | } | |
1111 | ||
1112 | /* | |
1113 | * Given a scsi cmnd, determine the BlockGuard profile to be used | |
1114 | * with the cmd | |
1115 | */ | |
1116 | static int | |
1117 | lpfc_sc_to_sli_prof(struct scsi_cmnd *sc) | |
1118 | { | |
1119 | uint8_t guard_type = scsi_host_get_guard(sc->device->host); | |
1120 | uint8_t ret_prof = LPFC_PROF_INVALID; | |
1121 | ||
1122 | if (guard_type == SHOST_DIX_GUARD_IP) { | |
1123 | switch (scsi_get_prot_op(sc)) { | |
1124 | case SCSI_PROT_READ_INSERT: | |
1125 | case SCSI_PROT_WRITE_STRIP: | |
1126 | ret_prof = LPFC_PROF_AST2; | |
1127 | break; | |
1128 | ||
1129 | case SCSI_PROT_READ_STRIP: | |
1130 | case SCSI_PROT_WRITE_INSERT: | |
1131 | ret_prof = LPFC_PROF_A1; | |
1132 | break; | |
1133 | ||
1134 | case SCSI_PROT_READ_CONVERT: | |
1135 | case SCSI_PROT_WRITE_CONVERT: | |
1136 | ret_prof = LPFC_PROF_AST1; | |
1137 | break; | |
1138 | ||
1139 | case SCSI_PROT_READ_PASS: | |
1140 | case SCSI_PROT_WRITE_PASS: | |
1141 | case SCSI_PROT_NORMAL: | |
1142 | default: | |
1143 | printk(KERN_ERR "Bad op/guard:%d/%d combination\n", | |
1144 | scsi_get_prot_op(sc), guard_type); | |
1145 | break; | |
1146 | ||
1147 | } | |
1148 | } else if (guard_type == SHOST_DIX_GUARD_CRC) { | |
1149 | switch (scsi_get_prot_op(sc)) { | |
1150 | case SCSI_PROT_READ_STRIP: | |
1151 | case SCSI_PROT_WRITE_INSERT: | |
1152 | ret_prof = LPFC_PROF_A1; | |
1153 | break; | |
1154 | ||
1155 | case SCSI_PROT_READ_PASS: | |
1156 | case SCSI_PROT_WRITE_PASS: | |
1157 | ret_prof = LPFC_PROF_C1; | |
1158 | break; | |
1159 | ||
1160 | case SCSI_PROT_READ_CONVERT: | |
1161 | case SCSI_PROT_WRITE_CONVERT: | |
1162 | case SCSI_PROT_READ_INSERT: | |
1163 | case SCSI_PROT_WRITE_STRIP: | |
1164 | case SCSI_PROT_NORMAL: | |
1165 | default: | |
1166 | printk(KERN_ERR "Bad op/guard:%d/%d combination\n", | |
1167 | scsi_get_prot_op(sc), guard_type); | |
1168 | break; | |
1169 | } | |
1170 | } else { | |
1171 | /* unsupported format */ | |
1172 | BUG(); | |
1173 | } | |
1174 | ||
1175 | return ret_prof; | |
1176 | } | |
1177 | ||
1178 | struct scsi_dif_tuple { | |
1179 | __be16 guard_tag; /* Checksum */ | |
1180 | __be16 app_tag; /* Opaque storage */ | |
1181 | __be32 ref_tag; /* Target LBA or indirect LBA */ | |
1182 | }; | |
1183 | ||
1184 | static inline unsigned | |
1185 | lpfc_cmd_blksize(struct scsi_cmnd *sc) | |
1186 | { | |
1187 | return sc->device->sector_size; | |
1188 | } | |
1189 | ||
1190 | /** | |
1191 | * lpfc_get_cmd_dif_parms - Extract DIF parameters from SCSI command | |
1192 | * @sc: in: SCSI command | |
3621a710 JS |
1193 | * @apptagmask: out: app tag mask |
1194 | * @apptagval: out: app tag value | |
1195 | * @reftag: out: ref tag (reference tag) | |
e2a0a9d6 JS |
1196 | * |
1197 | * Description: | |
1198 | * Extract DIF paramters from the command if possible. Otherwise, | |
1199 | * use default paratmers. | |
1200 | * | |
1201 | **/ | |
1202 | static inline void | |
1203 | lpfc_get_cmd_dif_parms(struct scsi_cmnd *sc, uint16_t *apptagmask, | |
1204 | uint16_t *apptagval, uint32_t *reftag) | |
1205 | { | |
1206 | struct scsi_dif_tuple *spt; | |
1207 | unsigned char op = scsi_get_prot_op(sc); | |
1208 | unsigned int protcnt = scsi_prot_sg_count(sc); | |
1209 | static int cnt; | |
1210 | ||
1211 | if (protcnt && (op == SCSI_PROT_WRITE_STRIP || | |
1212 | op == SCSI_PROT_WRITE_PASS || | |
1213 | op == SCSI_PROT_WRITE_CONVERT)) { | |
1214 | ||
1215 | cnt++; | |
1216 | spt = page_address(sg_page(scsi_prot_sglist(sc))) + | |
1217 | scsi_prot_sglist(sc)[0].offset; | |
1218 | *apptagmask = 0; | |
1219 | *apptagval = 0; | |
1220 | *reftag = cpu_to_be32(spt->ref_tag); | |
1221 | ||
1222 | } else { | |
1223 | /* SBC defines ref tag to be lower 32bits of LBA */ | |
1224 | *reftag = (uint32_t) (0xffffffff & scsi_get_lba(sc)); | |
1225 | *apptagmask = 0; | |
1226 | *apptagval = 0; | |
1227 | } | |
1228 | } | |
1229 | ||
1230 | /* | |
1231 | * This function sets up buffer list for protection groups of | |
1232 | * type LPFC_PG_TYPE_NO_DIF | |
1233 | * | |
1234 | * This is usually used when the HBA is instructed to generate | |
1235 | * DIFs and insert them into data stream (or strip DIF from | |
1236 | * incoming data stream) | |
1237 | * | |
1238 | * The buffer list consists of just one protection group described | |
1239 | * below: | |
1240 | * +-------------------------+ | |
1241 | * start of prot group --> | PDE_1 | | |
1242 | * +-------------------------+ | |
1243 | * | Data BDE | | |
1244 | * +-------------------------+ | |
1245 | * |more Data BDE's ... (opt)| | |
1246 | * +-------------------------+ | |
1247 | * | |
1248 | * @sc: pointer to scsi command we're working on | |
1249 | * @bpl: pointer to buffer list for protection groups | |
1250 | * @datacnt: number of segments of data that have been dma mapped | |
1251 | * | |
1252 | * Note: Data s/g buffers have been dma mapped | |
1253 | */ | |
1254 | static int | |
1255 | lpfc_bg_setup_bpl(struct lpfc_hba *phba, struct scsi_cmnd *sc, | |
1256 | struct ulp_bde64 *bpl, int datasegcnt) | |
1257 | { | |
1258 | struct scatterlist *sgde = NULL; /* s/g data entry */ | |
1259 | struct lpfc_pde *pde1 = NULL; | |
1260 | dma_addr_t physaddr; | |
1261 | int i = 0, num_bde = 0; | |
1262 | int datadir = sc->sc_data_direction; | |
1263 | int prof = LPFC_PROF_INVALID; | |
1264 | unsigned blksize; | |
1265 | uint32_t reftag; | |
1266 | uint16_t apptagmask, apptagval; | |
1267 | ||
1268 | pde1 = (struct lpfc_pde *) bpl; | |
1269 | prof = lpfc_sc_to_sli_prof(sc); | |
1270 | ||
1271 | if (prof == LPFC_PROF_INVALID) | |
1272 | goto out; | |
1273 | ||
1274 | /* extract some info from the scsi command for PDE1*/ | |
1275 | blksize = lpfc_cmd_blksize(sc); | |
1276 | lpfc_get_cmd_dif_parms(sc, &apptagmask, &apptagval, &reftag); | |
1277 | ||
1278 | /* setup PDE1 with what we have */ | |
1279 | lpfc_pde_set_bg_parms(pde1, LPFC_PDE1_DESCRIPTOR, prof, blksize, | |
1280 | BG_EC_STOP_ERR); | |
1281 | lpfc_pde_set_dif_parms(pde1, apptagmask, apptagval, reftag); | |
1282 | ||
1283 | num_bde++; | |
1284 | bpl++; | |
1285 | ||
1286 | /* assumption: caller has already run dma_map_sg on command data */ | |
1287 | scsi_for_each_sg(sc, sgde, datasegcnt, i) { | |
1288 | physaddr = sg_dma_address(sgde); | |
1289 | bpl->addrLow = le32_to_cpu(putPaddrLow(physaddr)); | |
1290 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(physaddr)); | |
1291 | bpl->tus.f.bdeSize = sg_dma_len(sgde); | |
1292 | if (datadir == DMA_TO_DEVICE) | |
1293 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; | |
1294 | else | |
1295 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I; | |
1296 | bpl->tus.w = le32_to_cpu(bpl->tus.w); | |
1297 | bpl++; | |
1298 | num_bde++; | |
1299 | } | |
1300 | ||
1301 | out: | |
1302 | return num_bde; | |
1303 | } | |
1304 | ||
1305 | /* | |
1306 | * This function sets up buffer list for protection groups of | |
1307 | * type LPFC_PG_TYPE_DIF_BUF | |
1308 | * | |
1309 | * This is usually used when DIFs are in their own buffers, | |
1310 | * separate from the data. The HBA can then by instructed | |
1311 | * to place the DIFs in the outgoing stream. For read operations, | |
1312 | * The HBA could extract the DIFs and place it in DIF buffers. | |
1313 | * | |
1314 | * The buffer list for this type consists of one or more of the | |
1315 | * protection groups described below: | |
1316 | * +-------------------------+ | |
1317 | * start of first prot group --> | PDE_1 | | |
1318 | * +-------------------------+ | |
1319 | * | PDE_3 (Prot BDE) | | |
1320 | * +-------------------------+ | |
1321 | * | Data BDE | | |
1322 | * +-------------------------+ | |
1323 | * |more Data BDE's ... (opt)| | |
1324 | * +-------------------------+ | |
1325 | * start of new prot group --> | PDE_1 | | |
1326 | * +-------------------------+ | |
1327 | * | ... | | |
1328 | * +-------------------------+ | |
1329 | * | |
1330 | * @sc: pointer to scsi command we're working on | |
1331 | * @bpl: pointer to buffer list for protection groups | |
1332 | * @datacnt: number of segments of data that have been dma mapped | |
1333 | * @protcnt: number of segment of protection data that have been dma mapped | |
1334 | * | |
1335 | * Note: It is assumed that both data and protection s/g buffers have been | |
1336 | * mapped for DMA | |
1337 | */ | |
1338 | static int | |
1339 | lpfc_bg_setup_bpl_prot(struct lpfc_hba *phba, struct scsi_cmnd *sc, | |
1340 | struct ulp_bde64 *bpl, int datacnt, int protcnt) | |
1341 | { | |
1342 | struct scatterlist *sgde = NULL; /* s/g data entry */ | |
1343 | struct scatterlist *sgpe = NULL; /* s/g prot entry */ | |
1344 | struct lpfc_pde *pde1 = NULL; | |
1345 | struct ulp_bde64 *prot_bde = NULL; | |
1346 | dma_addr_t dataphysaddr, protphysaddr; | |
1347 | unsigned short curr_data = 0, curr_prot = 0; | |
1348 | unsigned int split_offset, protgroup_len; | |
1349 | unsigned int protgrp_blks, protgrp_bytes; | |
1350 | unsigned int remainder, subtotal; | |
1351 | int prof = LPFC_PROF_INVALID; | |
1352 | int datadir = sc->sc_data_direction; | |
1353 | unsigned char pgdone = 0, alldone = 0; | |
1354 | unsigned blksize; | |
1355 | uint32_t reftag; | |
1356 | uint16_t apptagmask, apptagval; | |
1357 | int num_bde = 0; | |
1358 | ||
1359 | sgpe = scsi_prot_sglist(sc); | |
1360 | sgde = scsi_sglist(sc); | |
1361 | ||
1362 | if (!sgpe || !sgde) { | |
1363 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, | |
1364 | "9020 Invalid s/g entry: data=0x%p prot=0x%p\n", | |
1365 | sgpe, sgde); | |
1366 | return 0; | |
1367 | } | |
1368 | ||
1369 | prof = lpfc_sc_to_sli_prof(sc); | |
1370 | if (prof == LPFC_PROF_INVALID) | |
1371 | goto out; | |
1372 | ||
1373 | /* extract some info from the scsi command for PDE1*/ | |
1374 | blksize = lpfc_cmd_blksize(sc); | |
1375 | lpfc_get_cmd_dif_parms(sc, &apptagmask, &apptagval, &reftag); | |
1376 | ||
1377 | split_offset = 0; | |
1378 | do { | |
1379 | /* setup the first PDE_1 */ | |
1380 | pde1 = (struct lpfc_pde *) bpl; | |
1381 | ||
1382 | lpfc_pde_set_bg_parms(pde1, LPFC_PDE1_DESCRIPTOR, prof, blksize, | |
1383 | BG_EC_STOP_ERR); | |
1384 | lpfc_pde_set_dif_parms(pde1, apptagmask, apptagval, reftag); | |
1385 | ||
1386 | num_bde++; | |
1387 | bpl++; | |
1388 | ||
1389 | /* setup the first BDE that points to protection buffer */ | |
1390 | prot_bde = (struct ulp_bde64 *) bpl; | |
1391 | protphysaddr = sg_dma_address(sgpe); | |
1392 | prot_bde->addrLow = le32_to_cpu(putPaddrLow(protphysaddr)); | |
1393 | prot_bde->addrHigh = le32_to_cpu(putPaddrHigh(protphysaddr)); | |
1394 | protgroup_len = sg_dma_len(sgpe); | |
1395 | ||
1396 | ||
1397 | /* must be integer multiple of the DIF block length */ | |
1398 | BUG_ON(protgroup_len % 8); | |
1399 | ||
1400 | protgrp_blks = protgroup_len / 8; | |
1401 | protgrp_bytes = protgrp_blks * blksize; | |
1402 | ||
1403 | prot_bde->tus.f.bdeSize = protgroup_len; | |
1404 | if (datadir == DMA_TO_DEVICE) | |
1405 | prot_bde->tus.f.bdeFlags = BUFF_TYPE_BDE_64; | |
1406 | else | |
1407 | prot_bde->tus.f.bdeFlags = BUFF_TYPE_BDE_64I; | |
1408 | prot_bde->tus.w = le32_to_cpu(bpl->tus.w); | |
1409 | ||
1410 | curr_prot++; | |
1411 | num_bde++; | |
1412 | ||
1413 | /* setup BDE's for data blocks associated with DIF data */ | |
1414 | pgdone = 0; | |
1415 | subtotal = 0; /* total bytes processed for current prot grp */ | |
1416 | while (!pgdone) { | |
1417 | if (!sgde) { | |
1418 | printk(KERN_ERR "%s Invalid data segment\n", | |
1419 | __func__); | |
1420 | return 0; | |
1421 | } | |
1422 | bpl++; | |
1423 | dataphysaddr = sg_dma_address(sgde) + split_offset; | |
1424 | bpl->addrLow = le32_to_cpu(putPaddrLow(dataphysaddr)); | |
1425 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(dataphysaddr)); | |
1426 | ||
1427 | remainder = sg_dma_len(sgde) - split_offset; | |
1428 | ||
1429 | if ((subtotal + remainder) <= protgrp_bytes) { | |
1430 | /* we can use this whole buffer */ | |
1431 | bpl->tus.f.bdeSize = remainder; | |
1432 | split_offset = 0; | |
1433 | ||
1434 | if ((subtotal + remainder) == protgrp_bytes) | |
1435 | pgdone = 1; | |
1436 | } else { | |
1437 | /* must split this buffer with next prot grp */ | |
1438 | bpl->tus.f.bdeSize = protgrp_bytes - subtotal; | |
1439 | split_offset += bpl->tus.f.bdeSize; | |
1440 | } | |
1441 | ||
1442 | subtotal += bpl->tus.f.bdeSize; | |
1443 | ||
1444 | if (datadir == DMA_TO_DEVICE) | |
1445 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; | |
1446 | else | |
1447 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I; | |
1448 | bpl->tus.w = le32_to_cpu(bpl->tus.w); | |
1449 | ||
1450 | num_bde++; | |
1451 | curr_data++; | |
1452 | ||
1453 | if (split_offset) | |
1454 | break; | |
1455 | ||
1456 | /* Move to the next s/g segment if possible */ | |
1457 | sgde = sg_next(sgde); | |
1458 | } | |
1459 | ||
1460 | /* are we done ? */ | |
1461 | if (curr_prot == protcnt) { | |
1462 | alldone = 1; | |
1463 | } else if (curr_prot < protcnt) { | |
1464 | /* advance to next prot buffer */ | |
1465 | sgpe = sg_next(sgpe); | |
1466 | bpl++; | |
1467 | ||
1468 | /* update the reference tag */ | |
1469 | reftag += protgrp_blks; | |
1470 | } else { | |
1471 | /* if we're here, we have a bug */ | |
1472 | printk(KERN_ERR "BLKGRD: bug in %s\n", __func__); | |
1473 | } | |
1474 | ||
1475 | } while (!alldone); | |
1476 | ||
1477 | out: | |
1478 | ||
1479 | ||
1480 | return num_bde; | |
1481 | } | |
1482 | /* | |
1483 | * Given a SCSI command that supports DIF, determine composition of protection | |
1484 | * groups involved in setting up buffer lists | |
1485 | * | |
1486 | * Returns: | |
1487 | * for DIF (for both read and write) | |
1488 | * */ | |
1489 | static int | |
1490 | lpfc_prot_group_type(struct lpfc_hba *phba, struct scsi_cmnd *sc) | |
1491 | { | |
1492 | int ret = LPFC_PG_TYPE_INVALID; | |
1493 | unsigned char op = scsi_get_prot_op(sc); | |
1494 | ||
1495 | switch (op) { | |
1496 | case SCSI_PROT_READ_STRIP: | |
1497 | case SCSI_PROT_WRITE_INSERT: | |
1498 | ret = LPFC_PG_TYPE_NO_DIF; | |
1499 | break; | |
1500 | case SCSI_PROT_READ_INSERT: | |
1501 | case SCSI_PROT_WRITE_STRIP: | |
1502 | case SCSI_PROT_READ_PASS: | |
1503 | case SCSI_PROT_WRITE_PASS: | |
1504 | case SCSI_PROT_WRITE_CONVERT: | |
1505 | case SCSI_PROT_READ_CONVERT: | |
1506 | ret = LPFC_PG_TYPE_DIF_BUF; | |
1507 | break; | |
1508 | default: | |
1509 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, | |
1510 | "9021 Unsupported protection op:%d\n", op); | |
1511 | break; | |
1512 | } | |
1513 | ||
1514 | return ret; | |
1515 | } | |
1516 | ||
1517 | /* | |
1518 | * This is the protection/DIF aware version of | |
1519 | * lpfc_scsi_prep_dma_buf(). It may be a good idea to combine the | |
1520 | * two functions eventually, but for now, it's here | |
1521 | */ | |
1522 | static int | |
1523 | lpfc_bg_scsi_prep_dma_buf(struct lpfc_hba *phba, | |
1524 | struct lpfc_scsi_buf *lpfc_cmd) | |
1525 | { | |
1526 | struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; | |
1527 | struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; | |
1528 | struct ulp_bde64 *bpl = lpfc_cmd->fcp_bpl; | |
1529 | IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb; | |
1530 | uint32_t num_bde = 0; | |
1531 | int datasegcnt, protsegcnt, datadir = scsi_cmnd->sc_data_direction; | |
1532 | int prot_group_type = 0; | |
1533 | int diflen, fcpdl; | |
1534 | unsigned blksize; | |
1535 | ||
1536 | /* | |
1537 | * Start the lpfc command prep by bumping the bpl beyond fcp_cmnd | |
1538 | * fcp_rsp regions to the first data bde entry | |
1539 | */ | |
1540 | bpl += 2; | |
1541 | if (scsi_sg_count(scsi_cmnd)) { | |
1542 | /* | |
1543 | * The driver stores the segment count returned from pci_map_sg | |
1544 | * because this a count of dma-mappings used to map the use_sg | |
1545 | * pages. They are not guaranteed to be the same for those | |
1546 | * architectures that implement an IOMMU. | |
1547 | */ | |
1548 | datasegcnt = dma_map_sg(&phba->pcidev->dev, | |
1549 | scsi_sglist(scsi_cmnd), | |
1550 | scsi_sg_count(scsi_cmnd), datadir); | |
1551 | if (unlikely(!datasegcnt)) | |
1552 | return 1; | |
1553 | ||
1554 | lpfc_cmd->seg_cnt = datasegcnt; | |
1555 | if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) { | |
1556 | printk(KERN_ERR "%s: Too many sg segments from " | |
1557 | "dma_map_sg. Config %d, seg_cnt %d\n", | |
1558 | __func__, phba->cfg_sg_seg_cnt, | |
1559 | lpfc_cmd->seg_cnt); | |
1560 | scsi_dma_unmap(scsi_cmnd); | |
1561 | return 1; | |
1562 | } | |
1563 | ||
1564 | prot_group_type = lpfc_prot_group_type(phba, scsi_cmnd); | |
1565 | ||
1566 | switch (prot_group_type) { | |
1567 | case LPFC_PG_TYPE_NO_DIF: | |
1568 | num_bde = lpfc_bg_setup_bpl(phba, scsi_cmnd, bpl, | |
1569 | datasegcnt); | |
1570 | /* we shoud have 2 or more entries in buffer list */ | |
1571 | if (num_bde < 2) | |
1572 | goto err; | |
1573 | break; | |
1574 | case LPFC_PG_TYPE_DIF_BUF:{ | |
1575 | /* | |
1576 | * This type indicates that protection buffers are | |
1577 | * passed to the driver, so that needs to be prepared | |
1578 | * for DMA | |
1579 | */ | |
1580 | protsegcnt = dma_map_sg(&phba->pcidev->dev, | |
1581 | scsi_prot_sglist(scsi_cmnd), | |
1582 | scsi_prot_sg_count(scsi_cmnd), datadir); | |
1583 | if (unlikely(!protsegcnt)) { | |
1584 | scsi_dma_unmap(scsi_cmnd); | |
1585 | return 1; | |
1586 | } | |
1587 | ||
1588 | lpfc_cmd->prot_seg_cnt = protsegcnt; | |
1589 | if (lpfc_cmd->prot_seg_cnt | |
1590 | > phba->cfg_prot_sg_seg_cnt) { | |
1591 | printk(KERN_ERR "%s: Too many prot sg segments " | |
1592 | "from dma_map_sg. Config %d," | |
1593 | "prot_seg_cnt %d\n", __func__, | |
1594 | phba->cfg_prot_sg_seg_cnt, | |
1595 | lpfc_cmd->prot_seg_cnt); | |
1596 | dma_unmap_sg(&phba->pcidev->dev, | |
1597 | scsi_prot_sglist(scsi_cmnd), | |
1598 | scsi_prot_sg_count(scsi_cmnd), | |
1599 | datadir); | |
1600 | scsi_dma_unmap(scsi_cmnd); | |
1601 | return 1; | |
1602 | } | |
1603 | ||
1604 | num_bde = lpfc_bg_setup_bpl_prot(phba, scsi_cmnd, bpl, | |
1605 | datasegcnt, protsegcnt); | |
1606 | /* we shoud have 3 or more entries in buffer list */ | |
1607 | if (num_bde < 3) | |
1608 | goto err; | |
1609 | break; | |
1610 | } | |
1611 | case LPFC_PG_TYPE_INVALID: | |
1612 | default: | |
1613 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, | |
1614 | "9022 Unexpected protection group %i\n", | |
1615 | prot_group_type); | |
1616 | return 1; | |
1617 | } | |
1618 | } | |
1619 | ||
1620 | /* | |
1621 | * Finish initializing those IOCB fields that are dependent on the | |
1622 | * scsi_cmnd request_buffer. Note that the bdeSize is explicitly | |
1623 | * reinitialized since all iocb memory resources are used many times | |
1624 | * for transmit, receive, and continuation bpl's. | |
1625 | */ | |
1626 | iocb_cmd->un.fcpi64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64)); | |
1627 | iocb_cmd->un.fcpi64.bdl.bdeSize += (num_bde * sizeof(struct ulp_bde64)); | |
1628 | iocb_cmd->ulpBdeCount = 1; | |
1629 | iocb_cmd->ulpLe = 1; | |
1630 | ||
1631 | fcpdl = scsi_bufflen(scsi_cmnd); | |
1632 | ||
1633 | if (scsi_get_prot_type(scsi_cmnd) == SCSI_PROT_DIF_TYPE1) { | |
1634 | /* | |
1635 | * We are in DIF Type 1 mode | |
1636 | * Every data block has a 8 byte DIF (trailer) | |
1637 | * attached to it. Must ajust FCP data length | |
1638 | */ | |
1639 | blksize = lpfc_cmd_blksize(scsi_cmnd); | |
1640 | diflen = (fcpdl / blksize) * 8; | |
1641 | fcpdl += diflen; | |
1642 | } | |
1643 | fcp_cmnd->fcpDl = be32_to_cpu(fcpdl); | |
1644 | ||
1645 | /* | |
1646 | * Due to difference in data length between DIF/non-DIF paths, | |
1647 | * we need to set word 4 of IOCB here | |
1648 | */ | |
1649 | iocb_cmd->un.fcpi.fcpi_parm = fcpdl; | |
1650 | ||
dea3101e | 1651 | return 0; |
e2a0a9d6 JS |
1652 | err: |
1653 | lpfc_printf_log(phba, KERN_ERR, LOG_FCP, | |
1654 | "9023 Could not setup all needed BDE's" | |
1655 | "prot_group_type=%d, num_bde=%d\n", | |
1656 | prot_group_type, num_bde); | |
1657 | return 1; | |
1658 | } | |
1659 | ||
1660 | /* | |
1661 | * This function checks for BlockGuard errors detected by | |
1662 | * the HBA. In case of errors, the ASC/ASCQ fields in the | |
1663 | * sense buffer will be set accordingly, paired with | |
1664 | * ILLEGAL_REQUEST to signal to the kernel that the HBA | |
1665 | * detected corruption. | |
1666 | * | |
1667 | * Returns: | |
1668 | * 0 - No error found | |
1669 | * 1 - BlockGuard error found | |
1670 | * -1 - Internal error (bad profile, ...etc) | |
1671 | */ | |
1672 | static int | |
1673 | lpfc_parse_bg_err(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd, | |
1674 | struct lpfc_iocbq *pIocbOut) | |
1675 | { | |
1676 | struct scsi_cmnd *cmd = lpfc_cmd->pCmd; | |
1677 | struct sli3_bg_fields *bgf = &pIocbOut->iocb.unsli3.sli3_bg; | |
1678 | int ret = 0; | |
1679 | uint32_t bghm = bgf->bghm; | |
1680 | uint32_t bgstat = bgf->bgstat; | |
1681 | uint64_t failing_sector = 0; | |
1682 | ||
83096ebf | 1683 | printk(KERN_ERR "BG ERROR in cmd 0x%x lba 0x%llx blk cnt 0x%x " |
e2a0a9d6 | 1684 | "bgstat=0x%x bghm=0x%x\n", |
87b5c328 | 1685 | cmd->cmnd[0], (unsigned long long)scsi_get_lba(cmd), |
83096ebf | 1686 | blk_rq_sectors(cmd->request), bgstat, bghm); |
e2a0a9d6 JS |
1687 | |
1688 | spin_lock(&_dump_buf_lock); | |
1689 | if (!_dump_buf_done) { | |
1690 | printk(KERN_ERR "Saving Data for %u blocks to debugfs\n", | |
1691 | (cmd->cmnd[7] << 8 | cmd->cmnd[8])); | |
1692 | lpfc_debug_save_data(cmd); | |
1693 | ||
1694 | /* If we have a prot sgl, save the DIF buffer */ | |
1695 | if (lpfc_prot_group_type(phba, cmd) == | |
1696 | LPFC_PG_TYPE_DIF_BUF) { | |
1697 | printk(KERN_ERR "Saving DIF for %u blocks to debugfs\n", | |
1698 | (cmd->cmnd[7] << 8 | cmd->cmnd[8])); | |
1699 | lpfc_debug_save_dif(cmd); | |
1700 | } | |
1701 | ||
1702 | _dump_buf_done = 1; | |
1703 | } | |
1704 | spin_unlock(&_dump_buf_lock); | |
1705 | ||
1706 | if (lpfc_bgs_get_invalid_prof(bgstat)) { | |
1707 | cmd->result = ScsiResult(DID_ERROR, 0); | |
1708 | printk(KERN_ERR "Invalid BlockGuard profile. bgstat:0x%x\n", | |
1709 | bgstat); | |
1710 | ret = (-1); | |
1711 | goto out; | |
1712 | } | |
1713 | ||
1714 | if (lpfc_bgs_get_uninit_dif_block(bgstat)) { | |
1715 | cmd->result = ScsiResult(DID_ERROR, 0); | |
1716 | printk(KERN_ERR "Invalid BlockGuard DIF Block. bgstat:0x%x\n", | |
1717 | bgstat); | |
1718 | ret = (-1); | |
1719 | goto out; | |
1720 | } | |
1721 | ||
1722 | if (lpfc_bgs_get_guard_err(bgstat)) { | |
1723 | ret = 1; | |
1724 | ||
1725 | scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, | |
1726 | 0x10, 0x1); | |
1c9fbafc | 1727 | cmd->result = DRIVER_SENSE << 24 |
e2a0a9d6 JS |
1728 | | ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION); |
1729 | phba->bg_guard_err_cnt++; | |
1730 | printk(KERN_ERR "BLKGRD: guard_tag error\n"); | |
1731 | } | |
1732 | ||
1733 | if (lpfc_bgs_get_reftag_err(bgstat)) { | |
1734 | ret = 1; | |
1735 | ||
1736 | scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, | |
1737 | 0x10, 0x3); | |
1c9fbafc | 1738 | cmd->result = DRIVER_SENSE << 24 |
e2a0a9d6 JS |
1739 | | ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION); |
1740 | ||
1741 | phba->bg_reftag_err_cnt++; | |
1742 | printk(KERN_ERR "BLKGRD: ref_tag error\n"); | |
1743 | } | |
1744 | ||
1745 | if (lpfc_bgs_get_apptag_err(bgstat)) { | |
1746 | ret = 1; | |
1747 | ||
1748 | scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, | |
1749 | 0x10, 0x2); | |
1c9fbafc | 1750 | cmd->result = DRIVER_SENSE << 24 |
e2a0a9d6 JS |
1751 | | ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION); |
1752 | ||
1753 | phba->bg_apptag_err_cnt++; | |
1754 | printk(KERN_ERR "BLKGRD: app_tag error\n"); | |
1755 | } | |
1756 | ||
1757 | if (lpfc_bgs_get_hi_water_mark_present(bgstat)) { | |
1758 | /* | |
1759 | * setup sense data descriptor 0 per SPC-4 as an information | |
1760 | * field, and put the failing LBA in it | |
1761 | */ | |
1762 | cmd->sense_buffer[8] = 0; /* Information */ | |
1763 | cmd->sense_buffer[9] = 0xa; /* Add. length */ | |
2344b5b6 | 1764 | bghm /= cmd->device->sector_size; |
e2a0a9d6 JS |
1765 | |
1766 | failing_sector = scsi_get_lba(cmd); | |
1767 | failing_sector += bghm; | |
1768 | ||
1769 | put_unaligned_be64(failing_sector, &cmd->sense_buffer[10]); | |
1770 | } | |
1771 | ||
1772 | if (!ret) { | |
1773 | /* No error was reported - problem in FW? */ | |
1774 | cmd->result = ScsiResult(DID_ERROR, 0); | |
1775 | printk(KERN_ERR "BLKGRD: no errors reported!\n"); | |
1776 | } | |
1777 | ||
1778 | out: | |
1779 | return ret; | |
dea3101e | 1780 | } |
1781 | ||
da0436e9 JS |
1782 | /** |
1783 | * lpfc_scsi_prep_dma_buf_s4 - DMA mapping for scsi buffer to SLI4 IF spec | |
1784 | * @phba: The Hba for which this call is being executed. | |
1785 | * @lpfc_cmd: The scsi buffer which is going to be mapped. | |
1786 | * | |
1787 | * This routine does the pci dma mapping for scatter-gather list of scsi cmnd | |
1788 | * field of @lpfc_cmd for device with SLI-4 interface spec. | |
1789 | * | |
1790 | * Return codes: | |
1791 | * 1 - Error | |
1792 | * 0 - Success | |
1793 | **/ | |
1794 | static int | |
1795 | lpfc_scsi_prep_dma_buf_s4(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd) | |
1796 | { | |
1797 | struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; | |
1798 | struct scatterlist *sgel = NULL; | |
1799 | struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; | |
1800 | struct sli4_sge *sgl = (struct sli4_sge *)lpfc_cmd->fcp_bpl; | |
1801 | IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb; | |
1802 | dma_addr_t physaddr; | |
1803 | uint32_t num_bde = 0; | |
1804 | uint32_t dma_len; | |
1805 | uint32_t dma_offset = 0; | |
1806 | int nseg; | |
1807 | ||
1808 | /* | |
1809 | * There are three possibilities here - use scatter-gather segment, use | |
1810 | * the single mapping, or neither. Start the lpfc command prep by | |
1811 | * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first | |
1812 | * data bde entry. | |
1813 | */ | |
1814 | if (scsi_sg_count(scsi_cmnd)) { | |
1815 | /* | |
1816 | * The driver stores the segment count returned from pci_map_sg | |
1817 | * because this a count of dma-mappings used to map the use_sg | |
1818 | * pages. They are not guaranteed to be the same for those | |
1819 | * architectures that implement an IOMMU. | |
1820 | */ | |
1821 | ||
1822 | nseg = scsi_dma_map(scsi_cmnd); | |
1823 | if (unlikely(!nseg)) | |
1824 | return 1; | |
1825 | sgl += 1; | |
1826 | /* clear the last flag in the fcp_rsp map entry */ | |
1827 | sgl->word2 = le32_to_cpu(sgl->word2); | |
1828 | bf_set(lpfc_sli4_sge_last, sgl, 0); | |
1829 | sgl->word2 = cpu_to_le32(sgl->word2); | |
1830 | sgl += 1; | |
1831 | ||
1832 | lpfc_cmd->seg_cnt = nseg; | |
1833 | if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) { | |
1834 | printk(KERN_ERR "%s: Too many sg segments from " | |
1835 | "dma_map_sg. Config %d, seg_cnt %d\n", | |
1836 | __func__, phba->cfg_sg_seg_cnt, | |
1837 | lpfc_cmd->seg_cnt); | |
1838 | scsi_dma_unmap(scsi_cmnd); | |
1839 | return 1; | |
1840 | } | |
1841 | ||
1842 | /* | |
1843 | * The driver established a maximum scatter-gather segment count | |
1844 | * during probe that limits the number of sg elements in any | |
1845 | * single scsi command. Just run through the seg_cnt and format | |
1846 | * the sge's. | |
1847 | * When using SLI-3 the driver will try to fit all the BDEs into | |
1848 | * the IOCB. If it can't then the BDEs get added to a BPL as it | |
1849 | * does for SLI-2 mode. | |
1850 | */ | |
1851 | scsi_for_each_sg(scsi_cmnd, sgel, nseg, num_bde) { | |
1852 | physaddr = sg_dma_address(sgel); | |
1853 | dma_len = sg_dma_len(sgel); | |
1854 | bf_set(lpfc_sli4_sge_len, sgl, sg_dma_len(sgel)); | |
1855 | sgl->addr_lo = cpu_to_le32(putPaddrLow(physaddr)); | |
1856 | sgl->addr_hi = cpu_to_le32(putPaddrHigh(physaddr)); | |
1857 | if ((num_bde + 1) == nseg) | |
1858 | bf_set(lpfc_sli4_sge_last, sgl, 1); | |
1859 | else | |
1860 | bf_set(lpfc_sli4_sge_last, sgl, 0); | |
1861 | bf_set(lpfc_sli4_sge_offset, sgl, dma_offset); | |
1862 | sgl->word2 = cpu_to_le32(sgl->word2); | |
1863 | sgl->word3 = cpu_to_le32(sgl->word3); | |
1864 | dma_offset += dma_len; | |
1865 | sgl++; | |
1866 | } | |
1867 | } else { | |
1868 | sgl += 1; | |
1869 | /* clear the last flag in the fcp_rsp map entry */ | |
1870 | sgl->word2 = le32_to_cpu(sgl->word2); | |
1871 | bf_set(lpfc_sli4_sge_last, sgl, 1); | |
1872 | sgl->word2 = cpu_to_le32(sgl->word2); | |
1873 | } | |
1874 | ||
1875 | /* | |
1876 | * Finish initializing those IOCB fields that are dependent on the | |
1877 | * scsi_cmnd request_buffer. Note that for SLI-2 the bdeSize is | |
1878 | * explicitly reinitialized. | |
1879 | * all iocb memory resources are reused. | |
1880 | */ | |
1881 | fcp_cmnd->fcpDl = cpu_to_be32(scsi_bufflen(scsi_cmnd)); | |
1882 | ||
1883 | /* | |
1884 | * Due to difference in data length between DIF/non-DIF paths, | |
1885 | * we need to set word 4 of IOCB here | |
1886 | */ | |
1887 | iocb_cmd->un.fcpi.fcpi_parm = scsi_bufflen(scsi_cmnd); | |
1888 | return 0; | |
1889 | } | |
1890 | ||
3772a991 JS |
1891 | /** |
1892 | * lpfc_scsi_prep_dma_buf - Wrapper function for DMA mapping of scsi buffer | |
1893 | * @phba: The Hba for which this call is being executed. | |
1894 | * @lpfc_cmd: The scsi buffer which is going to be mapped. | |
1895 | * | |
1896 | * This routine wraps the actual DMA mapping function pointer from the | |
1897 | * lpfc_hba struct. | |
1898 | * | |
1899 | * Return codes: | |
1900 | * 1 - Error | |
1901 | * 0 - Success | |
1902 | **/ | |
1903 | static inline int | |
1904 | lpfc_scsi_prep_dma_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd) | |
1905 | { | |
1906 | return phba->lpfc_scsi_prep_dma_buf(phba, lpfc_cmd); | |
1907 | } | |
1908 | ||
ea2151b4 | 1909 | /** |
3621a710 | 1910 | * lpfc_send_scsi_error_event - Posts an event when there is SCSI error |
ea2151b4 JS |
1911 | * @phba: Pointer to hba context object. |
1912 | * @vport: Pointer to vport object. | |
1913 | * @lpfc_cmd: Pointer to lpfc scsi command which reported the error. | |
1914 | * @rsp_iocb: Pointer to response iocb object which reported error. | |
1915 | * | |
1916 | * This function posts an event when there is a SCSI command reporting | |
1917 | * error from the scsi device. | |
1918 | **/ | |
1919 | static void | |
1920 | lpfc_send_scsi_error_event(struct lpfc_hba *phba, struct lpfc_vport *vport, | |
1921 | struct lpfc_scsi_buf *lpfc_cmd, struct lpfc_iocbq *rsp_iocb) { | |
1922 | struct scsi_cmnd *cmnd = lpfc_cmd->pCmd; | |
1923 | struct fcp_rsp *fcprsp = lpfc_cmd->fcp_rsp; | |
1924 | uint32_t resp_info = fcprsp->rspStatus2; | |
1925 | uint32_t scsi_status = fcprsp->rspStatus3; | |
1926 | uint32_t fcpi_parm = rsp_iocb->iocb.un.fcpi.fcpi_parm; | |
1927 | struct lpfc_fast_path_event *fast_path_evt = NULL; | |
1928 | struct lpfc_nodelist *pnode = lpfc_cmd->rdata->pnode; | |
1929 | unsigned long flags; | |
1930 | ||
1931 | /* If there is queuefull or busy condition send a scsi event */ | |
1932 | if ((cmnd->result == SAM_STAT_TASK_SET_FULL) || | |
1933 | (cmnd->result == SAM_STAT_BUSY)) { | |
1934 | fast_path_evt = lpfc_alloc_fast_evt(phba); | |
1935 | if (!fast_path_evt) | |
1936 | return; | |
1937 | fast_path_evt->un.scsi_evt.event_type = | |
1938 | FC_REG_SCSI_EVENT; | |
1939 | fast_path_evt->un.scsi_evt.subcategory = | |
1940 | (cmnd->result == SAM_STAT_TASK_SET_FULL) ? | |
1941 | LPFC_EVENT_QFULL : LPFC_EVENT_DEVBSY; | |
1942 | fast_path_evt->un.scsi_evt.lun = cmnd->device->lun; | |
1943 | memcpy(&fast_path_evt->un.scsi_evt.wwpn, | |
1944 | &pnode->nlp_portname, sizeof(struct lpfc_name)); | |
1945 | memcpy(&fast_path_evt->un.scsi_evt.wwnn, | |
1946 | &pnode->nlp_nodename, sizeof(struct lpfc_name)); | |
1947 | } else if ((resp_info & SNS_LEN_VALID) && fcprsp->rspSnsLen && | |
1948 | ((cmnd->cmnd[0] == READ_10) || (cmnd->cmnd[0] == WRITE_10))) { | |
1949 | fast_path_evt = lpfc_alloc_fast_evt(phba); | |
1950 | if (!fast_path_evt) | |
1951 | return; | |
1952 | fast_path_evt->un.check_cond_evt.scsi_event.event_type = | |
1953 | FC_REG_SCSI_EVENT; | |
1954 | fast_path_evt->un.check_cond_evt.scsi_event.subcategory = | |
1955 | LPFC_EVENT_CHECK_COND; | |
1956 | fast_path_evt->un.check_cond_evt.scsi_event.lun = | |
1957 | cmnd->device->lun; | |
1958 | memcpy(&fast_path_evt->un.check_cond_evt.scsi_event.wwpn, | |
1959 | &pnode->nlp_portname, sizeof(struct lpfc_name)); | |
1960 | memcpy(&fast_path_evt->un.check_cond_evt.scsi_event.wwnn, | |
1961 | &pnode->nlp_nodename, sizeof(struct lpfc_name)); | |
1962 | fast_path_evt->un.check_cond_evt.sense_key = | |
1963 | cmnd->sense_buffer[2] & 0xf; | |
1964 | fast_path_evt->un.check_cond_evt.asc = cmnd->sense_buffer[12]; | |
1965 | fast_path_evt->un.check_cond_evt.ascq = cmnd->sense_buffer[13]; | |
1966 | } else if ((cmnd->sc_data_direction == DMA_FROM_DEVICE) && | |
1967 | fcpi_parm && | |
1968 | ((be32_to_cpu(fcprsp->rspResId) != fcpi_parm) || | |
1969 | ((scsi_status == SAM_STAT_GOOD) && | |
1970 | !(resp_info & (RESID_UNDER | RESID_OVER))))) { | |
1971 | /* | |
1972 | * If status is good or resid does not match with fcp_param and | |
1973 | * there is valid fcpi_parm, then there is a read_check error | |
1974 | */ | |
1975 | fast_path_evt = lpfc_alloc_fast_evt(phba); | |
1976 | if (!fast_path_evt) | |
1977 | return; | |
1978 | fast_path_evt->un.read_check_error.header.event_type = | |
1979 | FC_REG_FABRIC_EVENT; | |
1980 | fast_path_evt->un.read_check_error.header.subcategory = | |
1981 | LPFC_EVENT_FCPRDCHKERR; | |
1982 | memcpy(&fast_path_evt->un.read_check_error.header.wwpn, | |
1983 | &pnode->nlp_portname, sizeof(struct lpfc_name)); | |
1984 | memcpy(&fast_path_evt->un.read_check_error.header.wwnn, | |
1985 | &pnode->nlp_nodename, sizeof(struct lpfc_name)); | |
1986 | fast_path_evt->un.read_check_error.lun = cmnd->device->lun; | |
1987 | fast_path_evt->un.read_check_error.opcode = cmnd->cmnd[0]; | |
1988 | fast_path_evt->un.read_check_error.fcpiparam = | |
1989 | fcpi_parm; | |
1990 | } else | |
1991 | return; | |
1992 | ||
1993 | fast_path_evt->vport = vport; | |
1994 | spin_lock_irqsave(&phba->hbalock, flags); | |
1995 | list_add_tail(&fast_path_evt->work_evt.evt_listp, &phba->work_list); | |
1996 | spin_unlock_irqrestore(&phba->hbalock, flags); | |
1997 | lpfc_worker_wake_up(phba); | |
1998 | return; | |
1999 | } | |
9bad7671 JS |
2000 | |
2001 | /** | |
f1126688 | 2002 | * lpfc_scsi_unprep_dma_buf - Un-map DMA mapping of SG-list for dev |
3772a991 | 2003 | * @phba: The HBA for which this call is being executed. |
9bad7671 JS |
2004 | * @psb: The scsi buffer which is going to be un-mapped. |
2005 | * | |
2006 | * This routine does DMA un-mapping of scatter gather list of scsi command | |
3772a991 | 2007 | * field of @lpfc_cmd for device with SLI-3 interface spec. |
9bad7671 | 2008 | **/ |
bcf4dbfa | 2009 | static void |
f1126688 | 2010 | lpfc_scsi_unprep_dma_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb) |
bcf4dbfa JS |
2011 | { |
2012 | /* | |
2013 | * There are only two special cases to consider. (1) the scsi command | |
2014 | * requested scatter-gather usage or (2) the scsi command allocated | |
2015 | * a request buffer, but did not request use_sg. There is a third | |
2016 | * case, but it does not require resource deallocation. | |
2017 | */ | |
a0b4f78f FT |
2018 | if (psb->seg_cnt > 0) |
2019 | scsi_dma_unmap(psb->pCmd); | |
e2a0a9d6 JS |
2020 | if (psb->prot_seg_cnt > 0) |
2021 | dma_unmap_sg(&phba->pcidev->dev, scsi_prot_sglist(psb->pCmd), | |
2022 | scsi_prot_sg_count(psb->pCmd), | |
2023 | psb->pCmd->sc_data_direction); | |
bcf4dbfa JS |
2024 | } |
2025 | ||
9bad7671 | 2026 | /** |
3621a710 | 2027 | * lpfc_handler_fcp_err - FCP response handler |
9bad7671 JS |
2028 | * @vport: The virtual port for which this call is being executed. |
2029 | * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure. | |
2030 | * @rsp_iocb: The response IOCB which contains FCP error. | |
2031 | * | |
2032 | * This routine is called to process response IOCB with status field | |
2033 | * IOSTAT_FCP_RSP_ERROR. This routine sets result field of scsi command | |
2034 | * based upon SCSI and FCP error. | |
2035 | **/ | |
dea3101e | 2036 | static void |
2e0fef85 JS |
2037 | lpfc_handle_fcp_err(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd, |
2038 | struct lpfc_iocbq *rsp_iocb) | |
dea3101e | 2039 | { |
2040 | struct scsi_cmnd *cmnd = lpfc_cmd->pCmd; | |
2041 | struct fcp_cmnd *fcpcmd = lpfc_cmd->fcp_cmnd; | |
2042 | struct fcp_rsp *fcprsp = lpfc_cmd->fcp_rsp; | |
7054a606 | 2043 | uint32_t fcpi_parm = rsp_iocb->iocb.un.fcpi.fcpi_parm; |
dea3101e | 2044 | uint32_t resp_info = fcprsp->rspStatus2; |
2045 | uint32_t scsi_status = fcprsp->rspStatus3; | |
c7743956 | 2046 | uint32_t *lp; |
dea3101e | 2047 | uint32_t host_status = DID_OK; |
2048 | uint32_t rsplen = 0; | |
c7743956 | 2049 | uint32_t logit = LOG_FCP | LOG_FCP_ERROR; |
dea3101e | 2050 | |
ea2151b4 | 2051 | |
dea3101e | 2052 | /* |
2053 | * If this is a task management command, there is no | |
2054 | * scsi packet associated with this lpfc_cmd. The driver | |
2055 | * consumes it. | |
2056 | */ | |
2057 | if (fcpcmd->fcpCntl2) { | |
2058 | scsi_status = 0; | |
2059 | goto out; | |
2060 | } | |
2061 | ||
c7743956 JS |
2062 | if ((resp_info & SNS_LEN_VALID) && fcprsp->rspSnsLen) { |
2063 | uint32_t snslen = be32_to_cpu(fcprsp->rspSnsLen); | |
2064 | if (snslen > SCSI_SENSE_BUFFERSIZE) | |
2065 | snslen = SCSI_SENSE_BUFFERSIZE; | |
2066 | ||
2067 | if (resp_info & RSP_LEN_VALID) | |
2068 | rsplen = be32_to_cpu(fcprsp->rspRspLen); | |
2069 | memcpy(cmnd->sense_buffer, &fcprsp->rspInfo0 + rsplen, snslen); | |
2070 | } | |
2071 | lp = (uint32_t *)cmnd->sense_buffer; | |
2072 | ||
2073 | if (!scsi_status && (resp_info & RESID_UNDER)) | |
2074 | logit = LOG_FCP; | |
2075 | ||
e8b62011 | 2076 | lpfc_printf_vlog(vport, KERN_WARNING, logit, |
e2a0a9d6 | 2077 | "9024 FCP command x%x failed: x%x SNS x%x x%x " |
e8b62011 JS |
2078 | "Data: x%x x%x x%x x%x x%x\n", |
2079 | cmnd->cmnd[0], scsi_status, | |
2080 | be32_to_cpu(*lp), be32_to_cpu(*(lp + 3)), resp_info, | |
2081 | be32_to_cpu(fcprsp->rspResId), | |
2082 | be32_to_cpu(fcprsp->rspSnsLen), | |
2083 | be32_to_cpu(fcprsp->rspRspLen), | |
2084 | fcprsp->rspInfo3); | |
dea3101e | 2085 | |
2086 | if (resp_info & RSP_LEN_VALID) { | |
2087 | rsplen = be32_to_cpu(fcprsp->rspRspLen); | |
2088 | if ((rsplen != 0 && rsplen != 4 && rsplen != 8) || | |
2089 | (fcprsp->rspInfo3 != RSP_NO_FAILURE)) { | |
2090 | host_status = DID_ERROR; | |
2091 | goto out; | |
2092 | } | |
2093 | } | |
2094 | ||
a0b4f78f | 2095 | scsi_set_resid(cmnd, 0); |
dea3101e | 2096 | if (resp_info & RESID_UNDER) { |
a0b4f78f | 2097 | scsi_set_resid(cmnd, be32_to_cpu(fcprsp->rspResId)); |
dea3101e | 2098 | |
e8b62011 | 2099 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
e2a0a9d6 | 2100 | "9025 FCP Read Underrun, expected %d, " |
e8b62011 JS |
2101 | "residual %d Data: x%x x%x x%x\n", |
2102 | be32_to_cpu(fcpcmd->fcpDl), | |
2103 | scsi_get_resid(cmnd), fcpi_parm, cmnd->cmnd[0], | |
2104 | cmnd->underflow); | |
dea3101e | 2105 | |
7054a606 JS |
2106 | /* |
2107 | * If there is an under run check if under run reported by | |
2108 | * storage array is same as the under run reported by HBA. | |
2109 | * If this is not same, there is a dropped frame. | |
2110 | */ | |
2111 | if ((cmnd->sc_data_direction == DMA_FROM_DEVICE) && | |
2112 | fcpi_parm && | |
a0b4f78f | 2113 | (scsi_get_resid(cmnd) != fcpi_parm)) { |
e8b62011 JS |
2114 | lpfc_printf_vlog(vport, KERN_WARNING, |
2115 | LOG_FCP | LOG_FCP_ERROR, | |
e2a0a9d6 | 2116 | "9026 FCP Read Check Error " |
e8b62011 JS |
2117 | "and Underrun Data: x%x x%x x%x x%x\n", |
2118 | be32_to_cpu(fcpcmd->fcpDl), | |
2119 | scsi_get_resid(cmnd), fcpi_parm, | |
2120 | cmnd->cmnd[0]); | |
a0b4f78f | 2121 | scsi_set_resid(cmnd, scsi_bufflen(cmnd)); |
7054a606 JS |
2122 | host_status = DID_ERROR; |
2123 | } | |
dea3101e | 2124 | /* |
2125 | * The cmnd->underflow is the minimum number of bytes that must | |
2126 | * be transfered for this command. Provided a sense condition | |
2127 | * is not present, make sure the actual amount transferred is at | |
2128 | * least the underflow value or fail. | |
2129 | */ | |
2130 | if (!(resp_info & SNS_LEN_VALID) && | |
2131 | (scsi_status == SAM_STAT_GOOD) && | |
a0b4f78f FT |
2132 | (scsi_bufflen(cmnd) - scsi_get_resid(cmnd) |
2133 | < cmnd->underflow)) { | |
e8b62011 | 2134 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
e2a0a9d6 | 2135 | "9027 FCP command x%x residual " |
e8b62011 JS |
2136 | "underrun converted to error " |
2137 | "Data: x%x x%x x%x\n", | |
66dbfbe6 | 2138 | cmnd->cmnd[0], scsi_bufflen(cmnd), |
e8b62011 | 2139 | scsi_get_resid(cmnd), cmnd->underflow); |
dea3101e | 2140 | host_status = DID_ERROR; |
2141 | } | |
2142 | } else if (resp_info & RESID_OVER) { | |
e8b62011 | 2143 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
e2a0a9d6 | 2144 | "9028 FCP command x%x residual overrun error. " |
e8b62011 JS |
2145 | "Data: x%x x%x \n", cmnd->cmnd[0], |
2146 | scsi_bufflen(cmnd), scsi_get_resid(cmnd)); | |
dea3101e | 2147 | host_status = DID_ERROR; |
2148 | ||
2149 | /* | |
2150 | * Check SLI validation that all the transfer was actually done | |
2151 | * (fcpi_parm should be zero). Apply check only to reads. | |
2152 | */ | |
2153 | } else if ((scsi_status == SAM_STAT_GOOD) && fcpi_parm && | |
2154 | (cmnd->sc_data_direction == DMA_FROM_DEVICE)) { | |
e8b62011 | 2155 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP | LOG_FCP_ERROR, |
e2a0a9d6 | 2156 | "9029 FCP Read Check Error Data: " |
e8b62011 JS |
2157 | "x%x x%x x%x x%x\n", |
2158 | be32_to_cpu(fcpcmd->fcpDl), | |
2159 | be32_to_cpu(fcprsp->rspResId), | |
2160 | fcpi_parm, cmnd->cmnd[0]); | |
dea3101e | 2161 | host_status = DID_ERROR; |
a0b4f78f | 2162 | scsi_set_resid(cmnd, scsi_bufflen(cmnd)); |
dea3101e | 2163 | } |
2164 | ||
2165 | out: | |
2166 | cmnd->result = ScsiResult(host_status, scsi_status); | |
ea2151b4 | 2167 | lpfc_send_scsi_error_event(vport->phba, vport, lpfc_cmd, rsp_iocb); |
dea3101e | 2168 | } |
2169 | ||
9bad7671 | 2170 | /** |
3621a710 | 2171 | * lpfc_scsi_cmd_iocb_cmpl - Scsi cmnd IOCB completion routine |
9bad7671 JS |
2172 | * @phba: The Hba for which this call is being executed. |
2173 | * @pIocbIn: The command IOCBQ for the scsi cmnd. | |
3772a991 | 2174 | * @pIocbOut: The response IOCBQ for the scsi cmnd. |
9bad7671 JS |
2175 | * |
2176 | * This routine assigns scsi command result by looking into response IOCB | |
2177 | * status field appropriately. This routine handles QUEUE FULL condition as | |
2178 | * well by ramping down device queue depth. | |
2179 | **/ | |
dea3101e | 2180 | static void |
2181 | lpfc_scsi_cmd_iocb_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pIocbIn, | |
2182 | struct lpfc_iocbq *pIocbOut) | |
2183 | { | |
2184 | struct lpfc_scsi_buf *lpfc_cmd = | |
2185 | (struct lpfc_scsi_buf *) pIocbIn->context1; | |
2e0fef85 | 2186 | struct lpfc_vport *vport = pIocbIn->vport; |
dea3101e | 2187 | struct lpfc_rport_data *rdata = lpfc_cmd->rdata; |
2188 | struct lpfc_nodelist *pnode = rdata->pnode; | |
2189 | struct scsi_cmnd *cmd = lpfc_cmd->pCmd; | |
445cf4f4 | 2190 | int result; |
a257bf90 | 2191 | struct scsi_device *tmp_sdev; |
445cf4f4 | 2192 | int depth = 0; |
fa61a54e | 2193 | unsigned long flags; |
ea2151b4 | 2194 | struct lpfc_fast_path_event *fast_path_evt; |
a257bf90 JS |
2195 | struct Scsi_Host *shost = cmd->device->host; |
2196 | uint32_t queue_depth, scsi_id; | |
dea3101e | 2197 | |
2198 | lpfc_cmd->result = pIocbOut->iocb.un.ulpWord[4]; | |
2199 | lpfc_cmd->status = pIocbOut->iocb.ulpStatus; | |
109f6ed0 JS |
2200 | if (pnode && NLP_CHK_NODE_ACT(pnode)) |
2201 | atomic_dec(&pnode->cmd_pending); | |
dea3101e | 2202 | |
2203 | if (lpfc_cmd->status) { | |
2204 | if (lpfc_cmd->status == IOSTAT_LOCAL_REJECT && | |
2205 | (lpfc_cmd->result & IOERR_DRVR_MASK)) | |
2206 | lpfc_cmd->status = IOSTAT_DRIVER_REJECT; | |
2207 | else if (lpfc_cmd->status >= IOSTAT_CNT) | |
2208 | lpfc_cmd->status = IOSTAT_DEFAULT; | |
2209 | ||
e8b62011 | 2210 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
e2a0a9d6 | 2211 | "9030 FCP cmd x%x failed <%d/%d> " |
e8b62011 JS |
2212 | "status: x%x result: x%x Data: x%x x%x\n", |
2213 | cmd->cmnd[0], | |
2214 | cmd->device ? cmd->device->id : 0xffff, | |
2215 | cmd->device ? cmd->device->lun : 0xffff, | |
2216 | lpfc_cmd->status, lpfc_cmd->result, | |
2217 | pIocbOut->iocb.ulpContext, | |
2218 | lpfc_cmd->cur_iocbq.iocb.ulpIoTag); | |
dea3101e | 2219 | |
2220 | switch (lpfc_cmd->status) { | |
2221 | case IOSTAT_FCP_RSP_ERROR: | |
2222 | /* Call FCP RSP handler to determine result */ | |
2e0fef85 | 2223 | lpfc_handle_fcp_err(vport, lpfc_cmd, pIocbOut); |
dea3101e | 2224 | break; |
2225 | case IOSTAT_NPORT_BSY: | |
2226 | case IOSTAT_FABRIC_BSY: | |
0f1f53a7 | 2227 | cmd->result = ScsiResult(DID_TRANSPORT_DISRUPTED, 0); |
ea2151b4 JS |
2228 | fast_path_evt = lpfc_alloc_fast_evt(phba); |
2229 | if (!fast_path_evt) | |
2230 | break; | |
2231 | fast_path_evt->un.fabric_evt.event_type = | |
2232 | FC_REG_FABRIC_EVENT; | |
2233 | fast_path_evt->un.fabric_evt.subcategory = | |
2234 | (lpfc_cmd->status == IOSTAT_NPORT_BSY) ? | |
2235 | LPFC_EVENT_PORT_BUSY : LPFC_EVENT_FABRIC_BUSY; | |
2236 | if (pnode && NLP_CHK_NODE_ACT(pnode)) { | |
2237 | memcpy(&fast_path_evt->un.fabric_evt.wwpn, | |
2238 | &pnode->nlp_portname, | |
2239 | sizeof(struct lpfc_name)); | |
2240 | memcpy(&fast_path_evt->un.fabric_evt.wwnn, | |
2241 | &pnode->nlp_nodename, | |
2242 | sizeof(struct lpfc_name)); | |
2243 | } | |
2244 | fast_path_evt->vport = vport; | |
2245 | fast_path_evt->work_evt.evt = | |
2246 | LPFC_EVT_FASTPATH_MGMT_EVT; | |
2247 | spin_lock_irqsave(&phba->hbalock, flags); | |
2248 | list_add_tail(&fast_path_evt->work_evt.evt_listp, | |
2249 | &phba->work_list); | |
2250 | spin_unlock_irqrestore(&phba->hbalock, flags); | |
2251 | lpfc_worker_wake_up(phba); | |
dea3101e | 2252 | break; |
92d7f7b0 | 2253 | case IOSTAT_LOCAL_REJECT: |
d7c255b2 | 2254 | if (lpfc_cmd->result == IOERR_INVALID_RPI || |
92d7f7b0 | 2255 | lpfc_cmd->result == IOERR_NO_RESOURCES || |
d7c255b2 | 2256 | lpfc_cmd->result == IOERR_ABORT_REQUESTED) { |
92d7f7b0 | 2257 | cmd->result = ScsiResult(DID_REQUEUE, 0); |
58da1ffb | 2258 | break; |
e2a0a9d6 JS |
2259 | } |
2260 | ||
2261 | if ((lpfc_cmd->result == IOERR_RX_DMA_FAILED || | |
2262 | lpfc_cmd->result == IOERR_TX_DMA_FAILED) && | |
2263 | pIocbOut->iocb.unsli3.sli3_bg.bgstat) { | |
2264 | if (scsi_get_prot_op(cmd) != SCSI_PROT_NORMAL) { | |
2265 | /* | |
2266 | * This is a response for a BG enabled | |
2267 | * cmd. Parse BG error | |
2268 | */ | |
2269 | lpfc_parse_bg_err(phba, lpfc_cmd, | |
2270 | pIocbOut); | |
2271 | break; | |
2272 | } else { | |
2273 | lpfc_printf_vlog(vport, KERN_WARNING, | |
2274 | LOG_BG, | |
2275 | "9031 non-zero BGSTAT " | |
2276 | "on unprotected cmd"); | |
2277 | } | |
2278 | } | |
2279 | ||
2280 | /* else: fall through */ | |
dea3101e | 2281 | default: |
2282 | cmd->result = ScsiResult(DID_ERROR, 0); | |
2283 | break; | |
2284 | } | |
2285 | ||
58da1ffb | 2286 | if (!pnode || !NLP_CHK_NODE_ACT(pnode) |
19a7b4ae | 2287 | || (pnode->nlp_state != NLP_STE_MAPPED_NODE)) |
0f1f53a7 JS |
2288 | cmd->result = ScsiResult(DID_TRANSPORT_DISRUPTED, |
2289 | SAM_STAT_BUSY); | |
dea3101e | 2290 | } else { |
2291 | cmd->result = ScsiResult(DID_OK, 0); | |
2292 | } | |
2293 | ||
2294 | if (cmd->result || lpfc_cmd->fcp_rsp->rspSnsLen) { | |
2295 | uint32_t *lp = (uint32_t *)cmd->sense_buffer; | |
2296 | ||
e8b62011 JS |
2297 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
2298 | "0710 Iodone <%d/%d> cmd %p, error " | |
2299 | "x%x SNS x%x x%x Data: x%x x%x\n", | |
2300 | cmd->device->id, cmd->device->lun, cmd, | |
2301 | cmd->result, *lp, *(lp + 3), cmd->retries, | |
2302 | scsi_get_resid(cmd)); | |
dea3101e | 2303 | } |
2304 | ||
ea2151b4 | 2305 | lpfc_update_stats(phba, lpfc_cmd); |
445cf4f4 | 2306 | result = cmd->result; |
977b5a0a JS |
2307 | if (vport->cfg_max_scsicmpl_time && |
2308 | time_after(jiffies, lpfc_cmd->start_time + | |
2309 | msecs_to_jiffies(vport->cfg_max_scsicmpl_time))) { | |
a257bf90 | 2310 | spin_lock_irqsave(shost->host_lock, flags); |
109f6ed0 JS |
2311 | if (pnode && NLP_CHK_NODE_ACT(pnode)) { |
2312 | if (pnode->cmd_qdepth > | |
2313 | atomic_read(&pnode->cmd_pending) && | |
2314 | (atomic_read(&pnode->cmd_pending) > | |
2315 | LPFC_MIN_TGT_QDEPTH) && | |
2316 | ((cmd->cmnd[0] == READ_10) || | |
2317 | (cmd->cmnd[0] == WRITE_10))) | |
2318 | pnode->cmd_qdepth = | |
2319 | atomic_read(&pnode->cmd_pending); | |
2320 | ||
2321 | pnode->last_change_time = jiffies; | |
2322 | } | |
a257bf90 | 2323 | spin_unlock_irqrestore(shost->host_lock, flags); |
109f6ed0 JS |
2324 | } else if (pnode && NLP_CHK_NODE_ACT(pnode)) { |
2325 | if ((pnode->cmd_qdepth < LPFC_MAX_TGT_QDEPTH) && | |
977b5a0a | 2326 | time_after(jiffies, pnode->last_change_time + |
109f6ed0 | 2327 | msecs_to_jiffies(LPFC_TGTQ_INTERVAL))) { |
a257bf90 | 2328 | spin_lock_irqsave(shost->host_lock, flags); |
109f6ed0 JS |
2329 | pnode->cmd_qdepth += pnode->cmd_qdepth * |
2330 | LPFC_TGTQ_RAMPUP_PCENT / 100; | |
2331 | if (pnode->cmd_qdepth > LPFC_MAX_TGT_QDEPTH) | |
2332 | pnode->cmd_qdepth = LPFC_MAX_TGT_QDEPTH; | |
2333 | pnode->last_change_time = jiffies; | |
a257bf90 | 2334 | spin_unlock_irqrestore(shost->host_lock, flags); |
109f6ed0 | 2335 | } |
977b5a0a JS |
2336 | } |
2337 | ||
1dcb58e5 | 2338 | lpfc_scsi_unprep_dma_buf(phba, lpfc_cmd); |
a257bf90 JS |
2339 | |
2340 | /* The sdev is not guaranteed to be valid post scsi_done upcall. */ | |
2341 | queue_depth = cmd->device->queue_depth; | |
2342 | scsi_id = cmd->device->id; | |
0bd4ca25 JSEC |
2343 | cmd->scsi_done(cmd); |
2344 | ||
b808608b | 2345 | if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) { |
fa61a54e JS |
2346 | /* |
2347 | * If there is a thread waiting for command completion | |
2348 | * wake up the thread. | |
2349 | */ | |
a257bf90 | 2350 | spin_lock_irqsave(shost->host_lock, flags); |
495a714c | 2351 | lpfc_cmd->pCmd = NULL; |
fa61a54e JS |
2352 | if (lpfc_cmd->waitq) |
2353 | wake_up(lpfc_cmd->waitq); | |
a257bf90 | 2354 | spin_unlock_irqrestore(shost->host_lock, flags); |
b808608b JW |
2355 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
2356 | return; | |
2357 | } | |
2358 | ||
92d7f7b0 JS |
2359 | |
2360 | if (!result) | |
a257bf90 | 2361 | lpfc_rampup_queue_depth(vport, queue_depth); |
92d7f7b0 | 2362 | |
58da1ffb | 2363 | if (!result && pnode && NLP_CHK_NODE_ACT(pnode) && |
445cf4f4 JSEC |
2364 | ((jiffies - pnode->last_ramp_up_time) > |
2365 | LPFC_Q_RAMP_UP_INTERVAL * HZ) && | |
2366 | ((jiffies - pnode->last_q_full_time) > | |
2367 | LPFC_Q_RAMP_UP_INTERVAL * HZ) && | |
a257bf90 JS |
2368 | (vport->cfg_lun_queue_depth > queue_depth)) { |
2369 | shost_for_each_device(tmp_sdev, shost) { | |
3de2a653 | 2370 | if (vport->cfg_lun_queue_depth > tmp_sdev->queue_depth){ |
a257bf90 | 2371 | if (tmp_sdev->id != scsi_id) |
445cf4f4 JSEC |
2372 | continue; |
2373 | if (tmp_sdev->ordered_tags) | |
2374 | scsi_adjust_queue_depth(tmp_sdev, | |
2375 | MSG_ORDERED_TAG, | |
2376 | tmp_sdev->queue_depth+1); | |
2377 | else | |
2378 | scsi_adjust_queue_depth(tmp_sdev, | |
2379 | MSG_SIMPLE_TAG, | |
2380 | tmp_sdev->queue_depth+1); | |
2381 | ||
2382 | pnode->last_ramp_up_time = jiffies; | |
2383 | } | |
2384 | } | |
ea2151b4 JS |
2385 | lpfc_send_sdev_queuedepth_change_event(phba, vport, pnode, |
2386 | 0xFFFFFFFF, | |
a257bf90 | 2387 | queue_depth , queue_depth + 1); |
445cf4f4 JSEC |
2388 | } |
2389 | ||
2390 | /* | |
2391 | * Check for queue full. If the lun is reporting queue full, then | |
2392 | * back off the lun queue depth to prevent target overloads. | |
2393 | */ | |
58da1ffb JS |
2394 | if (result == SAM_STAT_TASK_SET_FULL && pnode && |
2395 | NLP_CHK_NODE_ACT(pnode)) { | |
445cf4f4 JSEC |
2396 | pnode->last_q_full_time = jiffies; |
2397 | ||
a257bf90 JS |
2398 | shost_for_each_device(tmp_sdev, shost) { |
2399 | if (tmp_sdev->id != scsi_id) | |
445cf4f4 JSEC |
2400 | continue; |
2401 | depth = scsi_track_queue_full(tmp_sdev, | |
2402 | tmp_sdev->queue_depth - 1); | |
2403 | } | |
2404 | /* | |
2e0fef85 | 2405 | * The queue depth cannot be lowered any more. |
445cf4f4 JSEC |
2406 | * Modify the returned error code to store |
2407 | * the final depth value set by | |
2408 | * scsi_track_queue_full. | |
2409 | */ | |
2410 | if (depth == -1) | |
a257bf90 | 2411 | depth = shost->cmd_per_lun; |
445cf4f4 JSEC |
2412 | |
2413 | if (depth) { | |
e8b62011 JS |
2414 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
2415 | "0711 detected queue full - lun queue " | |
2416 | "depth adjusted to %d.\n", depth); | |
ea2151b4 JS |
2417 | lpfc_send_sdev_queuedepth_change_event(phba, vport, |
2418 | pnode, 0xFFFFFFFF, | |
2419 | depth+1, depth); | |
445cf4f4 JSEC |
2420 | } |
2421 | } | |
2422 | ||
fa61a54e JS |
2423 | /* |
2424 | * If there is a thread waiting for command completion | |
2425 | * wake up the thread. | |
2426 | */ | |
a257bf90 | 2427 | spin_lock_irqsave(shost->host_lock, flags); |
495a714c | 2428 | lpfc_cmd->pCmd = NULL; |
fa61a54e JS |
2429 | if (lpfc_cmd->waitq) |
2430 | wake_up(lpfc_cmd->waitq); | |
a257bf90 | 2431 | spin_unlock_irqrestore(shost->host_lock, flags); |
fa61a54e | 2432 | |
0bd4ca25 | 2433 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
dea3101e | 2434 | } |
2435 | ||
34b02dcd | 2436 | /** |
3621a710 | 2437 | * lpfc_fcpcmd_to_iocb - copy the fcp_cmd data into the IOCB |
34b02dcd JS |
2438 | * @data: A pointer to the immediate command data portion of the IOCB. |
2439 | * @fcp_cmnd: The FCP Command that is provided by the SCSI layer. | |
2440 | * | |
2441 | * The routine copies the entire FCP command from @fcp_cmnd to @data while | |
2442 | * byte swapping the data to big endian format for transmission on the wire. | |
2443 | **/ | |
2444 | static void | |
2445 | lpfc_fcpcmd_to_iocb(uint8_t *data, struct fcp_cmnd *fcp_cmnd) | |
2446 | { | |
2447 | int i, j; | |
2448 | for (i = 0, j = 0; i < sizeof(struct fcp_cmnd); | |
2449 | i += sizeof(uint32_t), j++) { | |
2450 | ((uint32_t *)data)[j] = cpu_to_be32(((uint32_t *)fcp_cmnd)[j]); | |
2451 | } | |
2452 | } | |
2453 | ||
9bad7671 | 2454 | /** |
f1126688 | 2455 | * lpfc_scsi_prep_cmnd - Wrapper func for convert scsi cmnd to FCP info unit |
9bad7671 JS |
2456 | * @vport: The virtual port for which this call is being executed. |
2457 | * @lpfc_cmd: The scsi command which needs to send. | |
2458 | * @pnode: Pointer to lpfc_nodelist. | |
2459 | * | |
2460 | * This routine initializes fcp_cmnd and iocb data structure from scsi command | |
3772a991 | 2461 | * to transfer for device with SLI3 interface spec. |
9bad7671 | 2462 | **/ |
dea3101e | 2463 | static void |
f1126688 | 2464 | lpfc_scsi_prep_cmnd(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd, |
2e0fef85 | 2465 | struct lpfc_nodelist *pnode) |
dea3101e | 2466 | { |
2e0fef85 | 2467 | struct lpfc_hba *phba = vport->phba; |
dea3101e | 2468 | struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; |
2469 | struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; | |
2470 | IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb; | |
2471 | struct lpfc_iocbq *piocbq = &(lpfc_cmd->cur_iocbq); | |
2472 | int datadir = scsi_cmnd->sc_data_direction; | |
7e2b19fb | 2473 | char tag[2]; |
dea3101e | 2474 | |
58da1ffb JS |
2475 | if (!pnode || !NLP_CHK_NODE_ACT(pnode)) |
2476 | return; | |
2477 | ||
dea3101e | 2478 | lpfc_cmd->fcp_rsp->rspSnsLen = 0; |
69859dc4 JSEC |
2479 | /* clear task management bits */ |
2480 | lpfc_cmd->fcp_cmnd->fcpCntl2 = 0; | |
dea3101e | 2481 | |
91886523 JSEC |
2482 | int_to_scsilun(lpfc_cmd->pCmd->device->lun, |
2483 | &lpfc_cmd->fcp_cmnd->fcp_lun); | |
dea3101e | 2484 | |
2485 | memcpy(&fcp_cmnd->fcpCdb[0], scsi_cmnd->cmnd, 16); | |
2486 | ||
7e2b19fb JS |
2487 | if (scsi_populate_tag_msg(scsi_cmnd, tag)) { |
2488 | switch (tag[0]) { | |
dea3101e | 2489 | case HEAD_OF_QUEUE_TAG: |
2490 | fcp_cmnd->fcpCntl1 = HEAD_OF_Q; | |
2491 | break; | |
2492 | case ORDERED_QUEUE_TAG: | |
2493 | fcp_cmnd->fcpCntl1 = ORDERED_Q; | |
2494 | break; | |
2495 | default: | |
2496 | fcp_cmnd->fcpCntl1 = SIMPLE_Q; | |
2497 | break; | |
2498 | } | |
2499 | } else | |
2500 | fcp_cmnd->fcpCntl1 = 0; | |
2501 | ||
2502 | /* | |
2503 | * There are three possibilities here - use scatter-gather segment, use | |
2504 | * the single mapping, or neither. Start the lpfc command prep by | |
2505 | * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first | |
2506 | * data bde entry. | |
2507 | */ | |
a0b4f78f | 2508 | if (scsi_sg_count(scsi_cmnd)) { |
dea3101e | 2509 | if (datadir == DMA_TO_DEVICE) { |
2510 | iocb_cmd->ulpCommand = CMD_FCP_IWRITE64_CR; | |
3772a991 JS |
2511 | if (phba->sli_rev < LPFC_SLI_REV4) { |
2512 | iocb_cmd->un.fcpi.fcpi_parm = 0; | |
2513 | iocb_cmd->ulpPU = 0; | |
2514 | } else | |
2515 | iocb_cmd->ulpPU = PARM_READ_CHECK; | |
dea3101e | 2516 | fcp_cmnd->fcpCntl3 = WRITE_DATA; |
2517 | phba->fc4OutputRequests++; | |
2518 | } else { | |
2519 | iocb_cmd->ulpCommand = CMD_FCP_IREAD64_CR; | |
2520 | iocb_cmd->ulpPU = PARM_READ_CHECK; | |
dea3101e | 2521 | fcp_cmnd->fcpCntl3 = READ_DATA; |
2522 | phba->fc4InputRequests++; | |
2523 | } | |
2524 | } else { | |
2525 | iocb_cmd->ulpCommand = CMD_FCP_ICMND64_CR; | |
2526 | iocb_cmd->un.fcpi.fcpi_parm = 0; | |
2527 | iocb_cmd->ulpPU = 0; | |
2528 | fcp_cmnd->fcpCntl3 = 0; | |
2529 | phba->fc4ControlRequests++; | |
2530 | } | |
e2a0a9d6 JS |
2531 | if (phba->sli_rev == 3 && |
2532 | !(phba->sli3_options & LPFC_SLI3_BG_ENABLED)) | |
34b02dcd | 2533 | lpfc_fcpcmd_to_iocb(iocb_cmd->unsli3.fcp_ext.icd, fcp_cmnd); |
dea3101e | 2534 | /* |
2535 | * Finish initializing those IOCB fields that are independent | |
2536 | * of the scsi_cmnd request_buffer | |
2537 | */ | |
2538 | piocbq->iocb.ulpContext = pnode->nlp_rpi; | |
2539 | if (pnode->nlp_fcp_info & NLP_FCP_2_DEVICE) | |
2540 | piocbq->iocb.ulpFCP2Rcvy = 1; | |
09372820 JS |
2541 | else |
2542 | piocbq->iocb.ulpFCP2Rcvy = 0; | |
dea3101e | 2543 | |
2544 | piocbq->iocb.ulpClass = (pnode->nlp_fcp_info & 0x0f); | |
2545 | piocbq->context1 = lpfc_cmd; | |
2546 | piocbq->iocb_cmpl = lpfc_scsi_cmd_iocb_cmpl; | |
2547 | piocbq->iocb.ulpTimeout = lpfc_cmd->timeout; | |
2e0fef85 | 2548 | piocbq->vport = vport; |
dea3101e | 2549 | } |
2550 | ||
da0436e9 | 2551 | /** |
f1126688 | 2552 | * lpfc_scsi_prep_task_mgmt_cmnd - Convert SLI3 scsi TM cmd to FCP info unit |
9bad7671 JS |
2553 | * @vport: The virtual port for which this call is being executed. |
2554 | * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure. | |
2555 | * @lun: Logical unit number. | |
2556 | * @task_mgmt_cmd: SCSI task management command. | |
2557 | * | |
3772a991 JS |
2558 | * This routine creates FCP information unit corresponding to @task_mgmt_cmd |
2559 | * for device with SLI-3 interface spec. | |
9bad7671 JS |
2560 | * |
2561 | * Return codes: | |
2562 | * 0 - Error | |
2563 | * 1 - Success | |
2564 | **/ | |
dea3101e | 2565 | static int |
f1126688 | 2566 | lpfc_scsi_prep_task_mgmt_cmd(struct lpfc_vport *vport, |
dea3101e | 2567 | struct lpfc_scsi_buf *lpfc_cmd, |
420b630d | 2568 | unsigned int lun, |
dea3101e | 2569 | uint8_t task_mgmt_cmd) |
2570 | { | |
dea3101e | 2571 | struct lpfc_iocbq *piocbq; |
2572 | IOCB_t *piocb; | |
2573 | struct fcp_cmnd *fcp_cmnd; | |
0b18ac42 | 2574 | struct lpfc_rport_data *rdata = lpfc_cmd->rdata; |
dea3101e | 2575 | struct lpfc_nodelist *ndlp = rdata->pnode; |
2576 | ||
58da1ffb JS |
2577 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || |
2578 | ndlp->nlp_state != NLP_STE_MAPPED_NODE) | |
dea3101e | 2579 | return 0; |
dea3101e | 2580 | |
dea3101e | 2581 | piocbq = &(lpfc_cmd->cur_iocbq); |
2e0fef85 JS |
2582 | piocbq->vport = vport; |
2583 | ||
dea3101e | 2584 | piocb = &piocbq->iocb; |
2585 | ||
2586 | fcp_cmnd = lpfc_cmd->fcp_cmnd; | |
34b02dcd JS |
2587 | /* Clear out any old data in the FCP command area */ |
2588 | memset(fcp_cmnd, 0, sizeof(struct fcp_cmnd)); | |
2589 | int_to_scsilun(lun, &fcp_cmnd->fcp_lun); | |
dea3101e | 2590 | fcp_cmnd->fcpCntl2 = task_mgmt_cmd; |
e2a0a9d6 JS |
2591 | if (vport->phba->sli_rev == 3 && |
2592 | !(vport->phba->sli3_options & LPFC_SLI3_BG_ENABLED)) | |
34b02dcd | 2593 | lpfc_fcpcmd_to_iocb(piocb->unsli3.fcp_ext.icd, fcp_cmnd); |
dea3101e | 2594 | piocb->ulpCommand = CMD_FCP_ICMND64_CR; |
dea3101e | 2595 | piocb->ulpContext = ndlp->nlp_rpi; |
2596 | if (ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) { | |
2597 | piocb->ulpFCP2Rcvy = 1; | |
2598 | } | |
2599 | piocb->ulpClass = (ndlp->nlp_fcp_info & 0x0f); | |
2600 | ||
2601 | /* ulpTimeout is only one byte */ | |
2602 | if (lpfc_cmd->timeout > 0xff) { | |
2603 | /* | |
2604 | * Do not timeout the command at the firmware level. | |
2605 | * The driver will provide the timeout mechanism. | |
2606 | */ | |
2607 | piocb->ulpTimeout = 0; | |
f1126688 | 2608 | } else |
dea3101e | 2609 | piocb->ulpTimeout = lpfc_cmd->timeout; |
da0436e9 | 2610 | |
f1126688 JS |
2611 | if (vport->phba->sli_rev == LPFC_SLI_REV4) |
2612 | lpfc_sli4_set_rsp_sgl_last(vport->phba, lpfc_cmd); | |
3772a991 | 2613 | |
f1126688 | 2614 | return 1; |
3772a991 JS |
2615 | } |
2616 | ||
2617 | /** | |
2618 | * lpfc_scsi_api_table_setup - Set up scsi api fucntion jump table | |
2619 | * @phba: The hba struct for which this call is being executed. | |
2620 | * @dev_grp: The HBA PCI-Device group number. | |
2621 | * | |
2622 | * This routine sets up the SCSI interface API function jump table in @phba | |
2623 | * struct. | |
2624 | * Returns: 0 - success, -ENODEV - failure. | |
2625 | **/ | |
2626 | int | |
2627 | lpfc_scsi_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) | |
2628 | { | |
2629 | ||
f1126688 JS |
2630 | phba->lpfc_scsi_unprep_dma_buf = lpfc_scsi_unprep_dma_buf; |
2631 | phba->lpfc_scsi_prep_cmnd = lpfc_scsi_prep_cmnd; | |
2632 | phba->lpfc_get_scsi_buf = lpfc_get_scsi_buf; | |
2633 | ||
3772a991 JS |
2634 | switch (dev_grp) { |
2635 | case LPFC_PCI_DEV_LP: | |
2636 | phba->lpfc_new_scsi_buf = lpfc_new_scsi_buf_s3; | |
2637 | phba->lpfc_scsi_prep_dma_buf = lpfc_scsi_prep_dma_buf_s3; | |
3772a991 JS |
2638 | phba->lpfc_release_scsi_buf = lpfc_release_scsi_buf_s3; |
2639 | break; | |
da0436e9 JS |
2640 | case LPFC_PCI_DEV_OC: |
2641 | phba->lpfc_new_scsi_buf = lpfc_new_scsi_buf_s4; | |
2642 | phba->lpfc_scsi_prep_dma_buf = lpfc_scsi_prep_dma_buf_s4; | |
da0436e9 JS |
2643 | phba->lpfc_release_scsi_buf = lpfc_release_scsi_buf_s4; |
2644 | break; | |
3772a991 JS |
2645 | default: |
2646 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
2647 | "1418 Invalid HBA PCI-device group: 0x%x\n", | |
2648 | dev_grp); | |
2649 | return -ENODEV; | |
2650 | break; | |
2651 | } | |
2652 | phba->lpfc_get_scsi_buf = lpfc_get_scsi_buf; | |
2653 | phba->lpfc_rampdown_queue_depth = lpfc_rampdown_queue_depth; | |
2654 | return 0; | |
2655 | } | |
2656 | ||
9bad7671 | 2657 | /** |
3621a710 | 2658 | * lpfc_taskmgmt_def_cmpl - IOCB completion routine for task management command |
9bad7671 JS |
2659 | * @phba: The Hba for which this call is being executed. |
2660 | * @cmdiocbq: Pointer to lpfc_iocbq data structure. | |
2661 | * @rspiocbq: Pointer to lpfc_iocbq data structure. | |
2662 | * | |
2663 | * This routine is IOCB completion routine for device reset and target reset | |
2664 | * routine. This routine release scsi buffer associated with lpfc_cmd. | |
2665 | **/ | |
7054a606 JS |
2666 | static void |
2667 | lpfc_tskmgmt_def_cmpl(struct lpfc_hba *phba, | |
2668 | struct lpfc_iocbq *cmdiocbq, | |
2669 | struct lpfc_iocbq *rspiocbq) | |
2670 | { | |
2671 | struct lpfc_scsi_buf *lpfc_cmd = | |
2672 | (struct lpfc_scsi_buf *) cmdiocbq->context1; | |
2673 | if (lpfc_cmd) | |
2674 | lpfc_release_scsi_buf(phba, lpfc_cmd); | |
2675 | return; | |
2676 | } | |
2677 | ||
9bad7671 | 2678 | /** |
3621a710 | 2679 | * lpfc_scsi_tgt_reset - Target reset handler |
9bad7671 JS |
2680 | * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure |
2681 | * @vport: The virtual port for which this call is being executed. | |
2682 | * @tgt_id: Target ID. | |
2683 | * @lun: Lun number. | |
2684 | * @rdata: Pointer to lpfc_rport_data. | |
2685 | * | |
2686 | * This routine issues a TARGET RESET iocb to reset a target with @tgt_id ID. | |
2687 | * | |
2688 | * Return Code: | |
2689 | * 0x2003 - Error | |
2690 | * 0x2002 - Success. | |
2691 | **/ | |
dea3101e | 2692 | static int |
2e0fef85 | 2693 | lpfc_scsi_tgt_reset(struct lpfc_scsi_buf *lpfc_cmd, struct lpfc_vport *vport, |
420b630d JS |
2694 | unsigned tgt_id, unsigned int lun, |
2695 | struct lpfc_rport_data *rdata) | |
dea3101e | 2696 | { |
2e0fef85 | 2697 | struct lpfc_hba *phba = vport->phba; |
dea3101e | 2698 | struct lpfc_iocbq *iocbq; |
0bd4ca25 | 2699 | struct lpfc_iocbq *iocbqrsp; |
dea3101e | 2700 | int ret; |
915caaaf | 2701 | int status; |
dea3101e | 2702 | |
58da1ffb | 2703 | if (!rdata->pnode || !NLP_CHK_NODE_ACT(rdata->pnode)) |
f5603511 JS |
2704 | return FAILED; |
2705 | ||
0b18ac42 | 2706 | lpfc_cmd->rdata = rdata; |
915caaaf | 2707 | status = lpfc_scsi_prep_task_mgmt_cmd(vport, lpfc_cmd, lun, |
420b630d | 2708 | FCP_TARGET_RESET); |
915caaaf | 2709 | if (!status) |
dea3101e | 2710 | return FAILED; |
2711 | ||
dea3101e | 2712 | iocbq = &lpfc_cmd->cur_iocbq; |
0bd4ca25 JSEC |
2713 | iocbqrsp = lpfc_sli_get_iocbq(phba); |
2714 | ||
dea3101e | 2715 | if (!iocbqrsp) |
2716 | return FAILED; | |
dea3101e | 2717 | |
0b18ac42 | 2718 | /* Issue Target Reset to TGT <num> */ |
e8b62011 JS |
2719 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
2720 | "0702 Issue Target Reset to TGT %d Data: x%x x%x\n", | |
2721 | tgt_id, rdata->pnode->nlp_rpi, rdata->pnode->nlp_flag); | |
3772a991 JS |
2722 | status = lpfc_sli_issue_iocb_wait(phba, LPFC_FCP_RING, |
2723 | iocbq, iocbqrsp, lpfc_cmd->timeout); | |
915caaaf JS |
2724 | if (status != IOCB_SUCCESS) { |
2725 | if (status == IOCB_TIMEDOUT) { | |
7054a606 | 2726 | iocbq->iocb_cmpl = lpfc_tskmgmt_def_cmpl; |
915caaaf JS |
2727 | ret = TIMEOUT_ERROR; |
2728 | } else | |
2729 | ret = FAILED; | |
dea3101e | 2730 | lpfc_cmd->status = IOSTAT_DRIVER_REJECT; |
dea3101e | 2731 | } else { |
2732 | ret = SUCCESS; | |
2733 | lpfc_cmd->result = iocbqrsp->iocb.un.ulpWord[4]; | |
2734 | lpfc_cmd->status = iocbqrsp->iocb.ulpStatus; | |
2735 | if (lpfc_cmd->status == IOSTAT_LOCAL_REJECT && | |
2736 | (lpfc_cmd->result & IOERR_DRVR_MASK)) | |
2737 | lpfc_cmd->status = IOSTAT_DRIVER_REJECT; | |
2738 | } | |
2739 | ||
604a3e30 | 2740 | lpfc_sli_release_iocbq(phba, iocbqrsp); |
dea3101e | 2741 | return ret; |
2742 | } | |
2743 | ||
9bad7671 | 2744 | /** |
3621a710 | 2745 | * lpfc_info - Info entry point of scsi_host_template data structure |
9bad7671 JS |
2746 | * @host: The scsi host for which this call is being executed. |
2747 | * | |
2748 | * This routine provides module information about hba. | |
2749 | * | |
2750 | * Reutrn code: | |
2751 | * Pointer to char - Success. | |
2752 | **/ | |
dea3101e | 2753 | const char * |
2754 | lpfc_info(struct Scsi_Host *host) | |
2755 | { | |
2e0fef85 JS |
2756 | struct lpfc_vport *vport = (struct lpfc_vport *) host->hostdata; |
2757 | struct lpfc_hba *phba = vport->phba; | |
dea3101e | 2758 | int len; |
2759 | static char lpfcinfobuf[384]; | |
2760 | ||
2761 | memset(lpfcinfobuf,0,384); | |
2762 | if (phba && phba->pcidev){ | |
2763 | strncpy(lpfcinfobuf, phba->ModelDesc, 256); | |
2764 | len = strlen(lpfcinfobuf); | |
2765 | snprintf(lpfcinfobuf + len, | |
2766 | 384-len, | |
2767 | " on PCI bus %02x device %02x irq %d", | |
2768 | phba->pcidev->bus->number, | |
2769 | phba->pcidev->devfn, | |
2770 | phba->pcidev->irq); | |
2771 | len = strlen(lpfcinfobuf); | |
2772 | if (phba->Port[0]) { | |
2773 | snprintf(lpfcinfobuf + len, | |
2774 | 384-len, | |
2775 | " port %s", | |
2776 | phba->Port); | |
2777 | } | |
2778 | } | |
2779 | return lpfcinfobuf; | |
2780 | } | |
2781 | ||
9bad7671 | 2782 | /** |
3621a710 | 2783 | * lpfc_poll_rearm_time - Routine to modify fcp_poll timer of hba |
9bad7671 JS |
2784 | * @phba: The Hba for which this call is being executed. |
2785 | * | |
2786 | * This routine modifies fcp_poll_timer field of @phba by cfg_poll_tmo. | |
2787 | * The default value of cfg_poll_tmo is 10 milliseconds. | |
2788 | **/ | |
875fbdfe JSEC |
2789 | static __inline__ void lpfc_poll_rearm_timer(struct lpfc_hba * phba) |
2790 | { | |
2791 | unsigned long poll_tmo_expires = | |
2792 | (jiffies + msecs_to_jiffies(phba->cfg_poll_tmo)); | |
2793 | ||
2794 | if (phba->sli.ring[LPFC_FCP_RING].txcmplq_cnt) | |
2795 | mod_timer(&phba->fcp_poll_timer, | |
2796 | poll_tmo_expires); | |
2797 | } | |
2798 | ||
9bad7671 | 2799 | /** |
3621a710 | 2800 | * lpfc_poll_start_timer - Routine to start fcp_poll_timer of HBA |
9bad7671 JS |
2801 | * @phba: The Hba for which this call is being executed. |
2802 | * | |
2803 | * This routine starts the fcp_poll_timer of @phba. | |
2804 | **/ | |
875fbdfe JSEC |
2805 | void lpfc_poll_start_timer(struct lpfc_hba * phba) |
2806 | { | |
2807 | lpfc_poll_rearm_timer(phba); | |
2808 | } | |
2809 | ||
9bad7671 | 2810 | /** |
3621a710 | 2811 | * lpfc_poll_timeout - Restart polling timer |
9bad7671 JS |
2812 | * @ptr: Map to lpfc_hba data structure pointer. |
2813 | * | |
2814 | * This routine restarts fcp_poll timer, when FCP ring polling is enable | |
2815 | * and FCP Ring interrupt is disable. | |
2816 | **/ | |
2817 | ||
875fbdfe JSEC |
2818 | void lpfc_poll_timeout(unsigned long ptr) |
2819 | { | |
2e0fef85 | 2820 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; |
875fbdfe JSEC |
2821 | |
2822 | if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) { | |
2823 | lpfc_sli_poll_fcp_ring (phba); | |
2824 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) | |
2825 | lpfc_poll_rearm_timer(phba); | |
2826 | } | |
875fbdfe JSEC |
2827 | } |
2828 | ||
9bad7671 | 2829 | /** |
3621a710 | 2830 | * lpfc_queuecommand - scsi_host_template queuecommand entry point |
9bad7671 JS |
2831 | * @cmnd: Pointer to scsi_cmnd data structure. |
2832 | * @done: Pointer to done routine. | |
2833 | * | |
2834 | * Driver registers this routine to scsi midlayer to submit a @cmd to process. | |
2835 | * This routine prepares an IOCB from scsi command and provides to firmware. | |
2836 | * The @done callback is invoked after driver finished processing the command. | |
2837 | * | |
2838 | * Return value : | |
2839 | * 0 - Success | |
2840 | * SCSI_MLQUEUE_HOST_BUSY - Block all devices served by this host temporarily. | |
2841 | **/ | |
dea3101e | 2842 | static int |
2843 | lpfc_queuecommand(struct scsi_cmnd *cmnd, void (*done) (struct scsi_cmnd *)) | |
2844 | { | |
2e0fef85 JS |
2845 | struct Scsi_Host *shost = cmnd->device->host; |
2846 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
2847 | struct lpfc_hba *phba = vport->phba; | |
dea3101e | 2848 | struct lpfc_rport_data *rdata = cmnd->device->hostdata; |
2849 | struct lpfc_nodelist *ndlp = rdata->pnode; | |
0bd4ca25 | 2850 | struct lpfc_scsi_buf *lpfc_cmd; |
19a7b4ae | 2851 | struct fc_rport *rport = starget_to_rport(scsi_target(cmnd->device)); |
19a7b4ae | 2852 | int err; |
dea3101e | 2853 | |
19a7b4ae JSEC |
2854 | err = fc_remote_port_chkready(rport); |
2855 | if (err) { | |
2856 | cmnd->result = err; | |
dea3101e | 2857 | goto out_fail_command; |
2858 | } | |
2859 | ||
e2a0a9d6 JS |
2860 | if (!(phba->sli3_options & LPFC_SLI3_BG_ENABLED) && |
2861 | scsi_get_prot_op(cmnd) != SCSI_PROT_NORMAL) { | |
2862 | ||
2863 | printk(KERN_ERR "BLKGRD ERROR: rcvd protected cmd:%02x op:%02x " | |
2864 | "str=%s without registering for BlockGuard - " | |
2865 | "Rejecting command\n", | |
2866 | cmnd->cmnd[0], scsi_get_prot_op(cmnd), | |
2867 | dif_op_str[scsi_get_prot_op(cmnd)]); | |
2868 | goto out_fail_command; | |
2869 | } | |
2870 | ||
dea3101e | 2871 | /* |
19a7b4ae JSEC |
2872 | * Catch race where our node has transitioned, but the |
2873 | * transport is still transitioning. | |
dea3101e | 2874 | */ |
b522d7d4 JS |
2875 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
2876 | cmnd->result = ScsiResult(DID_TRANSPORT_DISRUPTED, 0); | |
2877 | goto out_fail_command; | |
2878 | } | |
109f6ed0 JS |
2879 | if (vport->cfg_max_scsicmpl_time && |
2880 | (atomic_read(&ndlp->cmd_pending) >= ndlp->cmd_qdepth)) | |
977b5a0a | 2881 | goto out_host_busy; |
a93ce024 | 2882 | |
ed957684 | 2883 | lpfc_cmd = lpfc_get_scsi_buf(phba); |
dea3101e | 2884 | if (lpfc_cmd == NULL) { |
eaf15d5b | 2885 | lpfc_rampdown_queue_depth(phba); |
92d7f7b0 | 2886 | |
e8b62011 JS |
2887 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
2888 | "0707 driver's buffer pool is empty, " | |
2889 | "IO busied\n"); | |
dea3101e | 2890 | goto out_host_busy; |
2891 | } | |
2892 | ||
2893 | /* | |
2894 | * Store the midlayer's command structure for the completion phase | |
2895 | * and complete the command initialization. | |
2896 | */ | |
2897 | lpfc_cmd->pCmd = cmnd; | |
2898 | lpfc_cmd->rdata = rdata; | |
2899 | lpfc_cmd->timeout = 0; | |
977b5a0a | 2900 | lpfc_cmd->start_time = jiffies; |
dea3101e | 2901 | cmnd->host_scribble = (unsigned char *)lpfc_cmd; |
2902 | cmnd->scsi_done = done; | |
2903 | ||
e2a0a9d6 JS |
2904 | if (scsi_get_prot_op(cmnd) != SCSI_PROT_NORMAL) { |
2905 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG, | |
2906 | "9033 BLKGRD: rcvd protected cmd:%02x op:%02x " | |
2907 | "str=%s\n", | |
2908 | cmnd->cmnd[0], scsi_get_prot_op(cmnd), | |
2909 | dif_op_str[scsi_get_prot_op(cmnd)]); | |
2910 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG, | |
2911 | "9034 BLKGRD: CDB: %02x %02x %02x %02x %02x " | |
2912 | "%02x %02x %02x %02x %02x \n", | |
2913 | cmnd->cmnd[0], cmnd->cmnd[1], cmnd->cmnd[2], | |
2914 | cmnd->cmnd[3], cmnd->cmnd[4], cmnd->cmnd[5], | |
2915 | cmnd->cmnd[6], cmnd->cmnd[7], cmnd->cmnd[8], | |
2916 | cmnd->cmnd[9]); | |
2917 | if (cmnd->cmnd[0] == READ_10) | |
2918 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG, | |
2919 | "9035 BLKGRD: READ @ sector %llu, " | |
83096ebf TH |
2920 | "count %u\n", |
2921 | (unsigned long long)scsi_get_lba(cmnd), | |
2922 | blk_rq_sectors(cmnd->request)); | |
e2a0a9d6 JS |
2923 | else if (cmnd->cmnd[0] == WRITE_10) |
2924 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG, | |
2925 | "9036 BLKGRD: WRITE @ sector %llu, " | |
83096ebf | 2926 | "count %u cmd=%p\n", |
87b5c328 | 2927 | (unsigned long long)scsi_get_lba(cmnd), |
83096ebf | 2928 | blk_rq_sectors(cmnd->request), |
e2a0a9d6 JS |
2929 | cmnd); |
2930 | ||
2931 | err = lpfc_bg_scsi_prep_dma_buf(phba, lpfc_cmd); | |
2932 | } else { | |
2933 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG, | |
2934 | "9038 BLKGRD: rcvd unprotected cmd:%02x op:%02x" | |
2935 | " str=%s\n", | |
2936 | cmnd->cmnd[0], scsi_get_prot_op(cmnd), | |
2937 | dif_op_str[scsi_get_prot_op(cmnd)]); | |
2938 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG, | |
2939 | "9039 BLKGRD: CDB: %02x %02x %02x %02x %02x " | |
2940 | "%02x %02x %02x %02x %02x \n", | |
2941 | cmnd->cmnd[0], cmnd->cmnd[1], cmnd->cmnd[2], | |
2942 | cmnd->cmnd[3], cmnd->cmnd[4], cmnd->cmnd[5], | |
2943 | cmnd->cmnd[6], cmnd->cmnd[7], cmnd->cmnd[8], | |
2944 | cmnd->cmnd[9]); | |
2945 | if (cmnd->cmnd[0] == READ_10) | |
2946 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG, | |
2947 | "9040 dbg: READ @ sector %llu, " | |
83096ebf | 2948 | "count %u\n", |
87b5c328 | 2949 | (unsigned long long)scsi_get_lba(cmnd), |
83096ebf | 2950 | blk_rq_sectors(cmnd->request)); |
e2a0a9d6 JS |
2951 | else if (cmnd->cmnd[0] == WRITE_10) |
2952 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG, | |
2953 | "9041 dbg: WRITE @ sector %llu, " | |
83096ebf | 2954 | "count %u cmd=%p\n", |
87b5c328 | 2955 | (unsigned long long)scsi_get_lba(cmnd), |
83096ebf | 2956 | blk_rq_sectors(cmnd->request), cmnd); |
e2a0a9d6 JS |
2957 | else |
2958 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG, | |
2959 | "9042 dbg: parser not implemented\n"); | |
2960 | err = lpfc_scsi_prep_dma_buf(phba, lpfc_cmd); | |
2961 | } | |
2962 | ||
dea3101e | 2963 | if (err) |
2964 | goto out_host_busy_free_buf; | |
2965 | ||
2e0fef85 | 2966 | lpfc_scsi_prep_cmnd(vport, lpfc_cmd, ndlp); |
dea3101e | 2967 | |
977b5a0a | 2968 | atomic_inc(&ndlp->cmd_pending); |
3772a991 | 2969 | err = lpfc_sli_issue_iocb(phba, LPFC_FCP_RING, |
92d7f7b0 | 2970 | &lpfc_cmd->cur_iocbq, SLI_IOCB_RET_IOCB); |
eaf15d5b JS |
2971 | if (err) { |
2972 | atomic_dec(&ndlp->cmd_pending); | |
dea3101e | 2973 | goto out_host_busy_free_buf; |
eaf15d5b | 2974 | } |
875fbdfe JSEC |
2975 | if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) { |
2976 | lpfc_sli_poll_fcp_ring(phba); | |
2977 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) | |
2978 | lpfc_poll_rearm_timer(phba); | |
2979 | } | |
2980 | ||
dea3101e | 2981 | return 0; |
2982 | ||
2983 | out_host_busy_free_buf: | |
bcf4dbfa | 2984 | lpfc_scsi_unprep_dma_buf(phba, lpfc_cmd); |
0bd4ca25 | 2985 | lpfc_release_scsi_buf(phba, lpfc_cmd); |
dea3101e | 2986 | out_host_busy: |
2987 | return SCSI_MLQUEUE_HOST_BUSY; | |
2988 | ||
2989 | out_fail_command: | |
2990 | done(cmnd); | |
2991 | return 0; | |
2992 | } | |
2993 | ||
9bad7671 | 2994 | /** |
3621a710 | 2995 | * lpfc_block_error_handler - Routine to block error handler |
9bad7671 JS |
2996 | * @cmnd: Pointer to scsi_cmnd data structure. |
2997 | * | |
2998 | * This routine blocks execution till fc_rport state is not FC_PORSTAT_BLCOEKD. | |
2999 | **/ | |
a90f5684 JS |
3000 | static void |
3001 | lpfc_block_error_handler(struct scsi_cmnd *cmnd) | |
3002 | { | |
3003 | struct Scsi_Host *shost = cmnd->device->host; | |
3004 | struct fc_rport *rport = starget_to_rport(scsi_target(cmnd->device)); | |
3005 | ||
3006 | spin_lock_irq(shost->host_lock); | |
3007 | while (rport->port_state == FC_PORTSTATE_BLOCKED) { | |
3008 | spin_unlock_irq(shost->host_lock); | |
3009 | msleep(1000); | |
3010 | spin_lock_irq(shost->host_lock); | |
3011 | } | |
3012 | spin_unlock_irq(shost->host_lock); | |
3013 | return; | |
3014 | } | |
63c59c3b | 3015 | |
9bad7671 | 3016 | /** |
3621a710 | 3017 | * lpfc_abort_handler - scsi_host_template eh_abort_handler entry point |
9bad7671 JS |
3018 | * @cmnd: Pointer to scsi_cmnd data structure. |
3019 | * | |
3020 | * This routine aborts @cmnd pending in base driver. | |
3021 | * | |
3022 | * Return code : | |
3023 | * 0x2003 - Error | |
3024 | * 0x2002 - Success | |
3025 | **/ | |
dea3101e | 3026 | static int |
63c59c3b | 3027 | lpfc_abort_handler(struct scsi_cmnd *cmnd) |
dea3101e | 3028 | { |
2e0fef85 JS |
3029 | struct Scsi_Host *shost = cmnd->device->host; |
3030 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
3031 | struct lpfc_hba *phba = vport->phba; | |
0bd4ca25 JSEC |
3032 | struct lpfc_iocbq *iocb; |
3033 | struct lpfc_iocbq *abtsiocb; | |
dea3101e | 3034 | struct lpfc_scsi_buf *lpfc_cmd; |
dea3101e | 3035 | IOCB_t *cmd, *icmd; |
0bd4ca25 | 3036 | int ret = SUCCESS; |
fa61a54e | 3037 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(waitq); |
dea3101e | 3038 | |
a90f5684 | 3039 | lpfc_block_error_handler(cmnd); |
0bd4ca25 JSEC |
3040 | lpfc_cmd = (struct lpfc_scsi_buf *)cmnd->host_scribble; |
3041 | BUG_ON(!lpfc_cmd); | |
dea3101e | 3042 | |
0bd4ca25 JSEC |
3043 | /* |
3044 | * If pCmd field of the corresponding lpfc_scsi_buf structure | |
3045 | * points to a different SCSI command, then the driver has | |
3046 | * already completed this command, but the midlayer did not | |
3047 | * see the completion before the eh fired. Just return | |
3048 | * SUCCESS. | |
3049 | */ | |
3050 | iocb = &lpfc_cmd->cur_iocbq; | |
3051 | if (lpfc_cmd->pCmd != cmnd) | |
3052 | goto out; | |
dea3101e | 3053 | |
0bd4ca25 | 3054 | BUG_ON(iocb->context1 != lpfc_cmd); |
dea3101e | 3055 | |
0bd4ca25 JSEC |
3056 | abtsiocb = lpfc_sli_get_iocbq(phba); |
3057 | if (abtsiocb == NULL) { | |
3058 | ret = FAILED; | |
dea3101e | 3059 | goto out; |
3060 | } | |
3061 | ||
dea3101e | 3062 | /* |
0bd4ca25 JSEC |
3063 | * The scsi command can not be in txq and it is in flight because the |
3064 | * pCmd is still pointig at the SCSI command we have to abort. There | |
3065 | * is no need to search the txcmplq. Just send an abort to the FW. | |
dea3101e | 3066 | */ |
dea3101e | 3067 | |
0bd4ca25 JSEC |
3068 | cmd = &iocb->iocb; |
3069 | icmd = &abtsiocb->iocb; | |
3070 | icmd->un.acxri.abortType = ABORT_TYPE_ABTS; | |
3071 | icmd->un.acxri.abortContextTag = cmd->ulpContext; | |
3772a991 JS |
3072 | if (phba->sli_rev == LPFC_SLI_REV4) |
3073 | icmd->un.acxri.abortIoTag = iocb->sli4_xritag; | |
3074 | else | |
3075 | icmd->un.acxri.abortIoTag = cmd->ulpIoTag; | |
dea3101e | 3076 | |
0bd4ca25 JSEC |
3077 | icmd->ulpLe = 1; |
3078 | icmd->ulpClass = cmd->ulpClass; | |
2e0fef85 | 3079 | if (lpfc_is_link_up(phba)) |
0bd4ca25 JSEC |
3080 | icmd->ulpCommand = CMD_ABORT_XRI_CN; |
3081 | else | |
3082 | icmd->ulpCommand = CMD_CLOSE_XRI_CN; | |
dea3101e | 3083 | |
0bd4ca25 | 3084 | abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; |
2e0fef85 | 3085 | abtsiocb->vport = vport; |
3772a991 JS |
3086 | if (lpfc_sli_issue_iocb(phba, LPFC_FCP_RING, abtsiocb, 0) == |
3087 | IOCB_ERROR) { | |
0bd4ca25 JSEC |
3088 | lpfc_sli_release_iocbq(phba, abtsiocb); |
3089 | ret = FAILED; | |
3090 | goto out; | |
3091 | } | |
dea3101e | 3092 | |
875fbdfe JSEC |
3093 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) |
3094 | lpfc_sli_poll_fcp_ring (phba); | |
3095 | ||
fa61a54e | 3096 | lpfc_cmd->waitq = &waitq; |
0bd4ca25 | 3097 | /* Wait for abort to complete */ |
fa61a54e JS |
3098 | wait_event_timeout(waitq, |
3099 | (lpfc_cmd->pCmd != cmnd), | |
3100 | (2*vport->cfg_devloss_tmo*HZ)); | |
875fbdfe | 3101 | |
fa61a54e JS |
3102 | spin_lock_irq(shost->host_lock); |
3103 | lpfc_cmd->waitq = NULL; | |
3104 | spin_unlock_irq(shost->host_lock); | |
dea3101e | 3105 | |
0bd4ca25 JSEC |
3106 | if (lpfc_cmd->pCmd == cmnd) { |
3107 | ret = FAILED; | |
e8b62011 JS |
3108 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
3109 | "0748 abort handler timed out waiting " | |
3110 | "for abort to complete: ret %#x, ID %d, " | |
3111 | "LUN %d, snum %#lx\n", | |
3112 | ret, cmnd->device->id, cmnd->device->lun, | |
3113 | cmnd->serial_number); | |
dea3101e | 3114 | } |
3115 | ||
3116 | out: | |
e8b62011 JS |
3117 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
3118 | "0749 SCSI Layer I/O Abort Request Status x%x ID %d " | |
3119 | "LUN %d snum %#lx\n", ret, cmnd->device->id, | |
3120 | cmnd->device->lun, cmnd->serial_number); | |
63c59c3b | 3121 | return ret; |
8fa728a2 JG |
3122 | } |
3123 | ||
9bad7671 | 3124 | /** |
3621a710 | 3125 | * lpfc_device_reset_handler - scsi_host_template eh_device_reset entry point |
9bad7671 JS |
3126 | * @cmnd: Pointer to scsi_cmnd data structure. |
3127 | * | |
3128 | * This routine does a device reset by sending a TARGET_RESET task management | |
3129 | * command. | |
3130 | * | |
3131 | * Return code : | |
3132 | * 0x2003 - Error | |
3621a710 | 3133 | * 0x2002 - Success |
9bad7671 | 3134 | **/ |
dea3101e | 3135 | static int |
7054a606 | 3136 | lpfc_device_reset_handler(struct scsi_cmnd *cmnd) |
dea3101e | 3137 | { |
2e0fef85 JS |
3138 | struct Scsi_Host *shost = cmnd->device->host; |
3139 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
3140 | struct lpfc_hba *phba = vport->phba; | |
0bd4ca25 JSEC |
3141 | struct lpfc_scsi_buf *lpfc_cmd; |
3142 | struct lpfc_iocbq *iocbq, *iocbqrsp; | |
dea3101e | 3143 | struct lpfc_rport_data *rdata = cmnd->device->hostdata; |
3144 | struct lpfc_nodelist *pnode = rdata->pnode; | |
915caaaf JS |
3145 | unsigned long later; |
3146 | int ret = SUCCESS; | |
3147 | int status; | |
3148 | int cnt; | |
ea2151b4 | 3149 | struct lpfc_scsi_event_header scsi_event; |
dea3101e | 3150 | |
a90f5684 | 3151 | lpfc_block_error_handler(cmnd); |
dea3101e | 3152 | /* |
3153 | * If target is not in a MAPPED state, delay the reset until | |
c01f3208 | 3154 | * target is rediscovered or devloss timeout expires. |
dea3101e | 3155 | */ |
915caaaf JS |
3156 | later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies; |
3157 | while (time_after(later, jiffies)) { | |
58da1ffb | 3158 | if (!pnode || !NLP_CHK_NODE_ACT(pnode)) |
915caaaf | 3159 | return FAILED; |
f5603511 | 3160 | if (pnode->nlp_state == NLP_STE_MAPPED_NODE) |
dea3101e | 3161 | break; |
915caaaf JS |
3162 | schedule_timeout_uninterruptible(msecs_to_jiffies(500)); |
3163 | rdata = cmnd->device->hostdata; | |
3164 | if (!rdata) | |
3165 | break; | |
3166 | pnode = rdata->pnode; | |
3167 | } | |
ea2151b4 JS |
3168 | |
3169 | scsi_event.event_type = FC_REG_SCSI_EVENT; | |
3170 | scsi_event.subcategory = LPFC_EVENT_TGTRESET; | |
3171 | scsi_event.lun = 0; | |
3172 | memcpy(scsi_event.wwpn, &pnode->nlp_portname, sizeof(struct lpfc_name)); | |
3173 | memcpy(scsi_event.wwnn, &pnode->nlp_nodename, sizeof(struct lpfc_name)); | |
3174 | ||
3175 | fc_host_post_vendor_event(shost, | |
3176 | fc_get_event_number(), | |
3177 | sizeof(scsi_event), | |
3178 | (char *)&scsi_event, | |
ddcc50f0 | 3179 | LPFC_NL_VENDOR_ID); |
ea2151b4 | 3180 | |
915caaaf JS |
3181 | if (!rdata || pnode->nlp_state != NLP_STE_MAPPED_NODE) { |
3182 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, | |
3183 | "0721 LUN Reset rport " | |
3184 | "failure: msec x%x rdata x%p\n", | |
3185 | jiffies_to_msecs(jiffies - later), rdata); | |
3186 | return FAILED; | |
dea3101e | 3187 | } |
2e0fef85 | 3188 | lpfc_cmd = lpfc_get_scsi_buf(phba); |
dea3101e | 3189 | if (lpfc_cmd == NULL) |
915caaaf | 3190 | return FAILED; |
dea3101e | 3191 | lpfc_cmd->timeout = 60; |
0b18ac42 | 3192 | lpfc_cmd->rdata = rdata; |
dea3101e | 3193 | |
915caaaf JS |
3194 | status = lpfc_scsi_prep_task_mgmt_cmd(vport, lpfc_cmd, |
3195 | cmnd->device->lun, | |
3196 | FCP_TARGET_RESET); | |
3197 | if (!status) { | |
3198 | lpfc_release_scsi_buf(phba, lpfc_cmd); | |
3199 | return FAILED; | |
3200 | } | |
dea3101e | 3201 | iocbq = &lpfc_cmd->cur_iocbq; |
3202 | ||
3203 | /* get a buffer for this IOCB command response */ | |
0bd4ca25 | 3204 | iocbqrsp = lpfc_sli_get_iocbq(phba); |
915caaaf JS |
3205 | if (iocbqrsp == NULL) { |
3206 | lpfc_release_scsi_buf(phba, lpfc_cmd); | |
3207 | return FAILED; | |
3208 | } | |
e8b62011 JS |
3209 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
3210 | "0703 Issue target reset to TGT %d LUN %d " | |
3211 | "rpi x%x nlp_flag x%x\n", cmnd->device->id, | |
3212 | cmnd->device->lun, pnode->nlp_rpi, pnode->nlp_flag); | |
3772a991 | 3213 | status = lpfc_sli_issue_iocb_wait(phba, LPFC_FCP_RING, |
915caaaf JS |
3214 | iocbq, iocbqrsp, lpfc_cmd->timeout); |
3215 | if (status == IOCB_TIMEDOUT) { | |
7054a606 | 3216 | iocbq->iocb_cmpl = lpfc_tskmgmt_def_cmpl; |
915caaaf JS |
3217 | ret = TIMEOUT_ERROR; |
3218 | } else { | |
3219 | if (status != IOCB_SUCCESS) | |
3220 | ret = FAILED; | |
3221 | lpfc_release_scsi_buf(phba, lpfc_cmd); | |
3222 | } | |
3223 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, | |
3224 | "0713 SCSI layer issued device reset (%d, %d) " | |
3225 | "return x%x status x%x result x%x\n", | |
3226 | cmnd->device->id, cmnd->device->lun, ret, | |
3227 | iocbqrsp->iocb.ulpStatus, | |
3228 | iocbqrsp->iocb.un.ulpWord[4]); | |
6175c02a | 3229 | lpfc_sli_release_iocbq(phba, iocbqrsp); |
51ef4c26 | 3230 | cnt = lpfc_sli_sum_iocb(vport, cmnd->device->id, cmnd->device->lun, |
915caaaf | 3231 | LPFC_CTX_TGT); |
6175c02a | 3232 | if (cnt) |
51ef4c26 | 3233 | lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring], |
6175c02a | 3234 | cmnd->device->id, cmnd->device->lun, |
915caaaf JS |
3235 | LPFC_CTX_TGT); |
3236 | later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies; | |
3237 | while (time_after(later, jiffies) && cnt) { | |
3238 | schedule_timeout_uninterruptible(msecs_to_jiffies(20)); | |
51ef4c26 | 3239 | cnt = lpfc_sli_sum_iocb(vport, cmnd->device->id, |
915caaaf | 3240 | cmnd->device->lun, LPFC_CTX_TGT); |
dea3101e | 3241 | } |
dea3101e | 3242 | if (cnt) { |
e8b62011 JS |
3243 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
3244 | "0719 device reset I/O flush failure: " | |
3245 | "cnt x%x\n", cnt); | |
0bd4ca25 | 3246 | ret = FAILED; |
dea3101e | 3247 | } |
dea3101e | 3248 | return ret; |
3249 | } | |
3250 | ||
9bad7671 | 3251 | /** |
3621a710 | 3252 | * lpfc_bus_reset_handler - scsi_host_template eh_bus_reset_handler entry point |
9bad7671 JS |
3253 | * @cmnd: Pointer to scsi_cmnd data structure. |
3254 | * | |
3255 | * This routine does target reset to all target on @cmnd->device->host. | |
3256 | * | |
3257 | * Return Code: | |
3258 | * 0x2003 - Error | |
3259 | * 0x2002 - Success | |
3260 | **/ | |
94d0e7b8 | 3261 | static int |
7054a606 | 3262 | lpfc_bus_reset_handler(struct scsi_cmnd *cmnd) |
dea3101e | 3263 | { |
2e0fef85 JS |
3264 | struct Scsi_Host *shost = cmnd->device->host; |
3265 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
3266 | struct lpfc_hba *phba = vport->phba; | |
dea3101e | 3267 | struct lpfc_nodelist *ndlp = NULL; |
3268 | int match; | |
d7c255b2 | 3269 | int ret = SUCCESS, status = SUCCESS, i; |
915caaaf | 3270 | int cnt; |
0bd4ca25 | 3271 | struct lpfc_scsi_buf * lpfc_cmd; |
915caaaf | 3272 | unsigned long later; |
ea2151b4 JS |
3273 | struct lpfc_scsi_event_header scsi_event; |
3274 | ||
3275 | scsi_event.event_type = FC_REG_SCSI_EVENT; | |
3276 | scsi_event.subcategory = LPFC_EVENT_BUSRESET; | |
3277 | scsi_event.lun = 0; | |
3278 | memcpy(scsi_event.wwpn, &vport->fc_portname, sizeof(struct lpfc_name)); | |
3279 | memcpy(scsi_event.wwnn, &vport->fc_nodename, sizeof(struct lpfc_name)); | |
3280 | ||
3281 | fc_host_post_vendor_event(shost, | |
3282 | fc_get_event_number(), | |
3283 | sizeof(scsi_event), | |
3284 | (char *)&scsi_event, | |
ddcc50f0 | 3285 | LPFC_NL_VENDOR_ID); |
dea3101e | 3286 | |
a90f5684 | 3287 | lpfc_block_error_handler(cmnd); |
dea3101e | 3288 | /* |
3289 | * Since the driver manages a single bus device, reset all | |
3290 | * targets known to the driver. Should any target reset | |
3291 | * fail, this routine returns failure to the midlayer. | |
3292 | */ | |
e17da18e | 3293 | for (i = 0; i < LPFC_MAX_TARGET; i++) { |
685f0bf7 | 3294 | /* Search for mapped node by target ID */ |
dea3101e | 3295 | match = 0; |
2e0fef85 JS |
3296 | spin_lock_irq(shost->host_lock); |
3297 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { | |
e47c9093 JS |
3298 | if (!NLP_CHK_NODE_ACT(ndlp)) |
3299 | continue; | |
685f0bf7 | 3300 | if (ndlp->nlp_state == NLP_STE_MAPPED_NODE && |
915caaaf | 3301 | ndlp->nlp_sid == i && |
685f0bf7 | 3302 | ndlp->rport) { |
dea3101e | 3303 | match = 1; |
3304 | break; | |
3305 | } | |
3306 | } | |
2e0fef85 | 3307 | spin_unlock_irq(shost->host_lock); |
dea3101e | 3308 | if (!match) |
3309 | continue; | |
915caaaf JS |
3310 | lpfc_cmd = lpfc_get_scsi_buf(phba); |
3311 | if (lpfc_cmd) { | |
3312 | lpfc_cmd->timeout = 60; | |
3313 | status = lpfc_scsi_tgt_reset(lpfc_cmd, vport, i, | |
3314 | cmnd->device->lun, | |
3315 | ndlp->rport->dd_data); | |
3316 | if (status != TIMEOUT_ERROR) | |
3317 | lpfc_release_scsi_buf(phba, lpfc_cmd); | |
3318 | } | |
3319 | if (!lpfc_cmd || status != SUCCESS) { | |
e8b62011 JS |
3320 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
3321 | "0700 Bus Reset on target %d failed\n", | |
3322 | i); | |
915caaaf | 3323 | ret = FAILED; |
dea3101e | 3324 | } |
3325 | } | |
6175c02a JSEC |
3326 | /* |
3327 | * All outstanding txcmplq I/Os should have been aborted by | |
3328 | * the targets. Unfortunately, some targets do not abide by | |
3329 | * this forcing the driver to double check. | |
3330 | */ | |
51ef4c26 | 3331 | cnt = lpfc_sli_sum_iocb(vport, 0, 0, LPFC_CTX_HOST); |
6175c02a | 3332 | if (cnt) |
51ef4c26 JS |
3333 | lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring], |
3334 | 0, 0, LPFC_CTX_HOST); | |
915caaaf JS |
3335 | later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies; |
3336 | while (time_after(later, jiffies) && cnt) { | |
3337 | schedule_timeout_uninterruptible(msecs_to_jiffies(20)); | |
51ef4c26 | 3338 | cnt = lpfc_sli_sum_iocb(vport, 0, 0, LPFC_CTX_HOST); |
dea3101e | 3339 | } |
dea3101e | 3340 | if (cnt) { |
e8b62011 JS |
3341 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
3342 | "0715 Bus Reset I/O flush failure: " | |
3343 | "cnt x%x left x%x\n", cnt, i); | |
0bd4ca25 | 3344 | ret = FAILED; |
6175c02a | 3345 | } |
e8b62011 JS |
3346 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, |
3347 | "0714 SCSI layer issued Bus Reset Data: x%x\n", ret); | |
dea3101e | 3348 | return ret; |
3349 | } | |
3350 | ||
9bad7671 | 3351 | /** |
3621a710 | 3352 | * lpfc_slave_alloc - scsi_host_template slave_alloc entry point |
9bad7671 JS |
3353 | * @sdev: Pointer to scsi_device. |
3354 | * | |
3355 | * This routine populates the cmds_per_lun count + 2 scsi_bufs into this host's | |
3356 | * globally available list of scsi buffers. This routine also makes sure scsi | |
3357 | * buffer is not allocated more than HBA limit conveyed to midlayer. This list | |
3358 | * of scsi buffer exists for the lifetime of the driver. | |
3359 | * | |
3360 | * Return codes: | |
3361 | * non-0 - Error | |
3362 | * 0 - Success | |
3363 | **/ | |
dea3101e | 3364 | static int |
3365 | lpfc_slave_alloc(struct scsi_device *sdev) | |
3366 | { | |
2e0fef85 JS |
3367 | struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata; |
3368 | struct lpfc_hba *phba = vport->phba; | |
19a7b4ae | 3369 | struct fc_rport *rport = starget_to_rport(scsi_target(sdev)); |
3772a991 | 3370 | uint32_t total = 0; |
dea3101e | 3371 | uint32_t num_to_alloc = 0; |
3772a991 | 3372 | int num_allocated = 0; |
dea3101e | 3373 | |
19a7b4ae | 3374 | if (!rport || fc_remote_port_chkready(rport)) |
dea3101e | 3375 | return -ENXIO; |
3376 | ||
19a7b4ae | 3377 | sdev->hostdata = rport->dd_data; |
dea3101e | 3378 | |
3379 | /* | |
3380 | * Populate the cmds_per_lun count scsi_bufs into this host's globally | |
3381 | * available list of scsi buffers. Don't allocate more than the | |
a784efbf JSEC |
3382 | * HBA limit conveyed to the midlayer via the host structure. The |
3383 | * formula accounts for the lun_queue_depth + error handlers + 1 | |
3384 | * extra. This list of scsi bufs exists for the lifetime of the driver. | |
dea3101e | 3385 | */ |
3386 | total = phba->total_scsi_bufs; | |
3de2a653 | 3387 | num_to_alloc = vport->cfg_lun_queue_depth + 2; |
92d7f7b0 JS |
3388 | |
3389 | /* Allow some exchanges to be available always to complete discovery */ | |
3390 | if (total >= phba->cfg_hba_queue_depth - LPFC_DISC_IOCB_BUFF_COUNT ) { | |
e8b62011 JS |
3391 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
3392 | "0704 At limitation of %d preallocated " | |
3393 | "command buffers\n", total); | |
dea3101e | 3394 | return 0; |
92d7f7b0 JS |
3395 | /* Allow some exchanges to be available always to complete discovery */ |
3396 | } else if (total + num_to_alloc > | |
3397 | phba->cfg_hba_queue_depth - LPFC_DISC_IOCB_BUFF_COUNT ) { | |
e8b62011 JS |
3398 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
3399 | "0705 Allocation request of %d " | |
3400 | "command buffers will exceed max of %d. " | |
3401 | "Reducing allocation request to %d.\n", | |
3402 | num_to_alloc, phba->cfg_hba_queue_depth, | |
3403 | (phba->cfg_hba_queue_depth - total)); | |
dea3101e | 3404 | num_to_alloc = phba->cfg_hba_queue_depth - total; |
3405 | } | |
3772a991 JS |
3406 | num_allocated = lpfc_new_scsi_buf(vport, num_to_alloc); |
3407 | if (num_to_alloc != num_allocated) { | |
3408 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, | |
3409 | "0708 Allocation request of %d " | |
3410 | "command buffers did not succeed. " | |
3411 | "Allocated %d buffers.\n", | |
3412 | num_to_alloc, num_allocated); | |
dea3101e | 3413 | } |
3414 | return 0; | |
3415 | } | |
3416 | ||
9bad7671 | 3417 | /** |
3621a710 | 3418 | * lpfc_slave_configure - scsi_host_template slave_configure entry point |
9bad7671 JS |
3419 | * @sdev: Pointer to scsi_device. |
3420 | * | |
3421 | * This routine configures following items | |
3422 | * - Tag command queuing support for @sdev if supported. | |
3423 | * - Dev loss time out value of fc_rport. | |
3424 | * - Enable SLI polling for fcp ring if ENABLE_FCP_RING_POLLING flag is set. | |
3425 | * | |
3426 | * Return codes: | |
3427 | * 0 - Success | |
3428 | **/ | |
dea3101e | 3429 | static int |
3430 | lpfc_slave_configure(struct scsi_device *sdev) | |
3431 | { | |
2e0fef85 JS |
3432 | struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata; |
3433 | struct lpfc_hba *phba = vport->phba; | |
3434 | struct fc_rport *rport = starget_to_rport(sdev->sdev_target); | |
dea3101e | 3435 | |
3436 | if (sdev->tagged_supported) | |
3de2a653 | 3437 | scsi_activate_tcq(sdev, vport->cfg_lun_queue_depth); |
dea3101e | 3438 | else |
3de2a653 | 3439 | scsi_deactivate_tcq(sdev, vport->cfg_lun_queue_depth); |
dea3101e | 3440 | |
3441 | /* | |
3442 | * Initialize the fc transport attributes for the target | |
3443 | * containing this scsi device. Also note that the driver's | |
3444 | * target pointer is stored in the starget_data for the | |
3445 | * driver's sysfs entry point functions. | |
3446 | */ | |
3de2a653 | 3447 | rport->dev_loss_tmo = vport->cfg_devloss_tmo; |
dea3101e | 3448 | |
875fbdfe JSEC |
3449 | if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) { |
3450 | lpfc_sli_poll_fcp_ring(phba); | |
3451 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) | |
3452 | lpfc_poll_rearm_timer(phba); | |
3453 | } | |
3454 | ||
dea3101e | 3455 | return 0; |
3456 | } | |
3457 | ||
9bad7671 | 3458 | /** |
3621a710 | 3459 | * lpfc_slave_destroy - slave_destroy entry point of SHT data structure |
9bad7671 JS |
3460 | * @sdev: Pointer to scsi_device. |
3461 | * | |
3462 | * This routine sets @sdev hostatdata filed to null. | |
3463 | **/ | |
dea3101e | 3464 | static void |
3465 | lpfc_slave_destroy(struct scsi_device *sdev) | |
3466 | { | |
3467 | sdev->hostdata = NULL; | |
3468 | return; | |
3469 | } | |
3470 | ||
92d7f7b0 | 3471 | |
dea3101e | 3472 | struct scsi_host_template lpfc_template = { |
3473 | .module = THIS_MODULE, | |
3474 | .name = LPFC_DRIVER_NAME, | |
3475 | .info = lpfc_info, | |
3476 | .queuecommand = lpfc_queuecommand, | |
3477 | .eh_abort_handler = lpfc_abort_handler, | |
7054a606 JS |
3478 | .eh_device_reset_handler= lpfc_device_reset_handler, |
3479 | .eh_bus_reset_handler = lpfc_bus_reset_handler, | |
dea3101e | 3480 | .slave_alloc = lpfc_slave_alloc, |
3481 | .slave_configure = lpfc_slave_configure, | |
3482 | .slave_destroy = lpfc_slave_destroy, | |
47a8617c | 3483 | .scan_finished = lpfc_scan_finished, |
dea3101e | 3484 | .this_id = -1, |
83108bd3 | 3485 | .sg_tablesize = LPFC_DEFAULT_SG_SEG_CNT, |
dea3101e | 3486 | .cmd_per_lun = LPFC_CMD_PER_LUN, |
3487 | .use_clustering = ENABLE_CLUSTERING, | |
2e0fef85 | 3488 | .shost_attrs = lpfc_hba_attrs, |
564b2960 | 3489 | .max_sectors = 0xFFFF, |
dea3101e | 3490 | }; |
3de2a653 JS |
3491 | |
3492 | struct scsi_host_template lpfc_vport_template = { | |
3493 | .module = THIS_MODULE, | |
3494 | .name = LPFC_DRIVER_NAME, | |
3495 | .info = lpfc_info, | |
3496 | .queuecommand = lpfc_queuecommand, | |
3497 | .eh_abort_handler = lpfc_abort_handler, | |
3498 | .eh_device_reset_handler= lpfc_device_reset_handler, | |
3499 | .eh_bus_reset_handler = lpfc_bus_reset_handler, | |
3500 | .slave_alloc = lpfc_slave_alloc, | |
3501 | .slave_configure = lpfc_slave_configure, | |
3502 | .slave_destroy = lpfc_slave_destroy, | |
3503 | .scan_finished = lpfc_scan_finished, | |
3504 | .this_id = -1, | |
83108bd3 | 3505 | .sg_tablesize = LPFC_DEFAULT_SG_SEG_CNT, |
3de2a653 JS |
3506 | .cmd_per_lun = LPFC_CMD_PER_LUN, |
3507 | .use_clustering = ENABLE_CLUSTERING, | |
3508 | .shost_attrs = lpfc_vport_attrs, | |
3509 | .max_sectors = 0xFFFF, | |
3510 | }; |