Commit | Line | Data |
---|---|---|
dea3101e | 1 | /******************************************************************* |
2 | * This file is part of the Emulex Linux Device Driver for * | |
c44ce173 | 3 | * Fibre Channel Host Bus Adapters. * |
bdcd2b92 | 4 | * Copyright (C) 2004-2012 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 | *******************************************************************/ |
21 | ||
dea3101e | 22 | #include <linux/blkdev.h> |
23 | #include <linux/pci.h> | |
24 | #include <linux/interrupt.h> | |
25 | #include <linux/delay.h> | |
5a0e3ad6 | 26 | #include <linux/slab.h> |
dea3101e | 27 | |
91886523 | 28 | #include <scsi/scsi.h> |
dea3101e | 29 | #include <scsi/scsi_cmnd.h> |
30 | #include <scsi/scsi_device.h> | |
31 | #include <scsi/scsi_host.h> | |
f888ba3c | 32 | #include <scsi/scsi_transport_fc.h> |
da0436e9 | 33 | #include <scsi/fc/fc_fs.h> |
0d878419 | 34 | #include <linux/aer.h> |
dea3101e | 35 | |
da0436e9 | 36 | #include "lpfc_hw4.h" |
dea3101e | 37 | #include "lpfc_hw.h" |
38 | #include "lpfc_sli.h" | |
da0436e9 | 39 | #include "lpfc_sli4.h" |
ea2151b4 | 40 | #include "lpfc_nl.h" |
dea3101e | 41 | #include "lpfc_disc.h" |
42 | #include "lpfc_scsi.h" | |
43 | #include "lpfc.h" | |
44 | #include "lpfc_crtn.h" | |
45 | #include "lpfc_logmsg.h" | |
46 | #include "lpfc_compat.h" | |
858c9f6c | 47 | #include "lpfc_debugfs.h" |
04c68496 | 48 | #include "lpfc_vport.h" |
dea3101e | 49 | |
50 | /* There are only four IOCB completion types. */ | |
51 | typedef enum _lpfc_iocb_type { | |
52 | LPFC_UNKNOWN_IOCB, | |
53 | LPFC_UNSOL_IOCB, | |
54 | LPFC_SOL_IOCB, | |
55 | LPFC_ABORT_IOCB | |
56 | } lpfc_iocb_type; | |
57 | ||
4f774513 JS |
58 | |
59 | /* Provide function prototypes local to this module. */ | |
60 | static int lpfc_sli_issue_mbox_s4(struct lpfc_hba *, LPFC_MBOXQ_t *, | |
61 | uint32_t); | |
62 | static int lpfc_sli4_read_rev(struct lpfc_hba *, LPFC_MBOXQ_t *, | |
45ed1190 JS |
63 | uint8_t *, uint32_t *); |
64 | static struct lpfc_iocbq *lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *, | |
65 | struct lpfc_iocbq *); | |
6669f9bb JS |
66 | static void lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *, |
67 | struct hbq_dmabuf *); | |
0558056c JS |
68 | static int lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *, struct lpfc_queue *, |
69 | struct lpfc_cqe *); | |
8a9d2e80 JS |
70 | static int lpfc_sli4_post_els_sgl_list(struct lpfc_hba *, struct list_head *, |
71 | int); | |
ba20c853 JS |
72 | static void lpfc_sli4_hba_handle_eqe(struct lpfc_hba *, struct lpfc_eqe *, |
73 | uint32_t); | |
0558056c | 74 | |
4f774513 JS |
75 | static IOCB_t * |
76 | lpfc_get_iocb_from_iocbq(struct lpfc_iocbq *iocbq) | |
77 | { | |
78 | return &iocbq->iocb; | |
79 | } | |
80 | ||
81 | /** | |
82 | * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue | |
83 | * @q: The Work Queue to operate on. | |
84 | * @wqe: The work Queue Entry to put on the Work queue. | |
85 | * | |
86 | * This routine will copy the contents of @wqe to the next available entry on | |
87 | * the @q. This function will then ring the Work Queue Doorbell to signal the | |
88 | * HBA to start processing the Work Queue Entry. This function returns 0 if | |
89 | * successful. If no entries are available on @q then this function will return | |
90 | * -ENOMEM. | |
91 | * The caller is expected to hold the hbalock when calling this routine. | |
92 | **/ | |
93 | static uint32_t | |
94 | lpfc_sli4_wq_put(struct lpfc_queue *q, union lpfc_wqe *wqe) | |
95 | { | |
2e90f4b5 | 96 | union lpfc_wqe *temp_wqe; |
4f774513 JS |
97 | struct lpfc_register doorbell; |
98 | uint32_t host_index; | |
027140ea | 99 | uint32_t idx; |
4f774513 | 100 | |
2e90f4b5 JS |
101 | /* sanity check on queue memory */ |
102 | if (unlikely(!q)) | |
103 | return -ENOMEM; | |
104 | temp_wqe = q->qe[q->host_index].wqe; | |
105 | ||
4f774513 | 106 | /* If the host has not yet processed the next entry then we are done */ |
027140ea JS |
107 | idx = ((q->host_index + 1) % q->entry_count); |
108 | if (idx == q->hba_index) { | |
b84daac9 | 109 | q->WQ_overflow++; |
4f774513 | 110 | return -ENOMEM; |
b84daac9 JS |
111 | } |
112 | q->WQ_posted++; | |
4f774513 | 113 | /* set consumption flag every once in a while */ |
ff78d8f9 | 114 | if (!((q->host_index + 1) % q->entry_repost)) |
f0d9bccc | 115 | bf_set(wqe_wqec, &wqe->generic.wqe_com, 1); |
fedd3b7b JS |
116 | if (q->phba->sli3_options & LPFC_SLI4_PHWQ_ENABLED) |
117 | bf_set(wqe_wqid, &wqe->generic.wqe_com, q->queue_id); | |
4f774513 JS |
118 | lpfc_sli_pcimem_bcopy(wqe, temp_wqe, q->entry_size); |
119 | ||
120 | /* Update the host index before invoking device */ | |
121 | host_index = q->host_index; | |
027140ea JS |
122 | |
123 | q->host_index = idx; | |
4f774513 JS |
124 | |
125 | /* Ring Doorbell */ | |
126 | doorbell.word0 = 0; | |
127 | bf_set(lpfc_wq_doorbell_num_posted, &doorbell, 1); | |
128 | bf_set(lpfc_wq_doorbell_index, &doorbell, host_index); | |
129 | bf_set(lpfc_wq_doorbell_id, &doorbell, q->queue_id); | |
130 | writel(doorbell.word0, q->phba->sli4_hba.WQDBregaddr); | |
4f774513 JS |
131 | |
132 | return 0; | |
133 | } | |
134 | ||
135 | /** | |
136 | * lpfc_sli4_wq_release - Updates internal hba index for WQ | |
137 | * @q: The Work Queue to operate on. | |
138 | * @index: The index to advance the hba index to. | |
139 | * | |
140 | * This routine will update the HBA index of a queue to reflect consumption of | |
141 | * Work Queue Entries by the HBA. When the HBA indicates that it has consumed | |
142 | * an entry the host calls this function to update the queue's internal | |
143 | * pointers. This routine returns the number of entries that were consumed by | |
144 | * the HBA. | |
145 | **/ | |
146 | static uint32_t | |
147 | lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index) | |
148 | { | |
149 | uint32_t released = 0; | |
150 | ||
2e90f4b5 JS |
151 | /* sanity check on queue memory */ |
152 | if (unlikely(!q)) | |
153 | return 0; | |
154 | ||
4f774513 JS |
155 | if (q->hba_index == index) |
156 | return 0; | |
157 | do { | |
158 | q->hba_index = ((q->hba_index + 1) % q->entry_count); | |
159 | released++; | |
160 | } while (q->hba_index != index); | |
161 | return released; | |
162 | } | |
163 | ||
164 | /** | |
165 | * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue | |
166 | * @q: The Mailbox Queue to operate on. | |
167 | * @wqe: The Mailbox Queue Entry to put on the Work queue. | |
168 | * | |
169 | * This routine will copy the contents of @mqe to the next available entry on | |
170 | * the @q. This function will then ring the Work Queue Doorbell to signal the | |
171 | * HBA to start processing the Work Queue Entry. This function returns 0 if | |
172 | * successful. If no entries are available on @q then this function will return | |
173 | * -ENOMEM. | |
174 | * The caller is expected to hold the hbalock when calling this routine. | |
175 | **/ | |
176 | static uint32_t | |
177 | lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe) | |
178 | { | |
2e90f4b5 | 179 | struct lpfc_mqe *temp_mqe; |
4f774513 JS |
180 | struct lpfc_register doorbell; |
181 | uint32_t host_index; | |
182 | ||
2e90f4b5 JS |
183 | /* sanity check on queue memory */ |
184 | if (unlikely(!q)) | |
185 | return -ENOMEM; | |
186 | temp_mqe = q->qe[q->host_index].mqe; | |
187 | ||
4f774513 JS |
188 | /* If the host has not yet processed the next entry then we are done */ |
189 | if (((q->host_index + 1) % q->entry_count) == q->hba_index) | |
190 | return -ENOMEM; | |
191 | lpfc_sli_pcimem_bcopy(mqe, temp_mqe, q->entry_size); | |
192 | /* Save off the mailbox pointer for completion */ | |
193 | q->phba->mbox = (MAILBOX_t *)temp_mqe; | |
194 | ||
195 | /* Update the host index before invoking device */ | |
196 | host_index = q->host_index; | |
197 | q->host_index = ((q->host_index + 1) % q->entry_count); | |
198 | ||
199 | /* Ring Doorbell */ | |
200 | doorbell.word0 = 0; | |
201 | bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1); | |
202 | bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id); | |
203 | writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr); | |
4f774513 JS |
204 | return 0; |
205 | } | |
206 | ||
207 | /** | |
208 | * lpfc_sli4_mq_release - Updates internal hba index for MQ | |
209 | * @q: The Mailbox Queue to operate on. | |
210 | * | |
211 | * This routine will update the HBA index of a queue to reflect consumption of | |
212 | * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed | |
213 | * an entry the host calls this function to update the queue's internal | |
214 | * pointers. This routine returns the number of entries that were consumed by | |
215 | * the HBA. | |
216 | **/ | |
217 | static uint32_t | |
218 | lpfc_sli4_mq_release(struct lpfc_queue *q) | |
219 | { | |
2e90f4b5 JS |
220 | /* sanity check on queue memory */ |
221 | if (unlikely(!q)) | |
222 | return 0; | |
223 | ||
4f774513 JS |
224 | /* Clear the mailbox pointer for completion */ |
225 | q->phba->mbox = NULL; | |
226 | q->hba_index = ((q->hba_index + 1) % q->entry_count); | |
227 | return 1; | |
228 | } | |
229 | ||
230 | /** | |
231 | * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ | |
232 | * @q: The Event Queue to get the first valid EQE from | |
233 | * | |
234 | * This routine will get the first valid Event Queue Entry from @q, update | |
235 | * the queue's internal hba index, and return the EQE. If no valid EQEs are in | |
236 | * the Queue (no more work to do), or the Queue is full of EQEs that have been | |
237 | * processed, but not popped back to the HBA then this routine will return NULL. | |
238 | **/ | |
239 | static struct lpfc_eqe * | |
240 | lpfc_sli4_eq_get(struct lpfc_queue *q) | |
241 | { | |
2e90f4b5 | 242 | struct lpfc_eqe *eqe; |
027140ea | 243 | uint32_t idx; |
2e90f4b5 JS |
244 | |
245 | /* sanity check on queue memory */ | |
246 | if (unlikely(!q)) | |
247 | return NULL; | |
248 | eqe = q->qe[q->hba_index].eqe; | |
4f774513 JS |
249 | |
250 | /* If the next EQE is not valid then we are done */ | |
cb5172ea | 251 | if (!bf_get_le32(lpfc_eqe_valid, eqe)) |
4f774513 JS |
252 | return NULL; |
253 | /* If the host has not yet processed the next entry then we are done */ | |
027140ea JS |
254 | idx = ((q->hba_index + 1) % q->entry_count); |
255 | if (idx == q->host_index) | |
4f774513 JS |
256 | return NULL; |
257 | ||
027140ea | 258 | q->hba_index = idx; |
4f774513 JS |
259 | return eqe; |
260 | } | |
261 | ||
ba20c853 JS |
262 | /** |
263 | * lpfc_sli4_eq_clr_intr - Turn off interrupts from this EQ | |
264 | * @q: The Event Queue to disable interrupts | |
265 | * | |
266 | **/ | |
267 | static inline void | |
268 | lpfc_sli4_eq_clr_intr(struct lpfc_queue *q) | |
269 | { | |
270 | struct lpfc_register doorbell; | |
271 | ||
272 | doorbell.word0 = 0; | |
273 | bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1); | |
274 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT); | |
275 | bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell, | |
276 | (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT)); | |
277 | bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id); | |
278 | writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr); | |
279 | } | |
280 | ||
4f774513 JS |
281 | /** |
282 | * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ | |
283 | * @q: The Event Queue that the host has completed processing for. | |
284 | * @arm: Indicates whether the host wants to arms this CQ. | |
285 | * | |
286 | * This routine will mark all Event Queue Entries on @q, from the last | |
287 | * known completed entry to the last entry that was processed, as completed | |
288 | * by clearing the valid bit for each completion queue entry. Then it will | |
289 | * notify the HBA, by ringing the doorbell, that the EQEs have been processed. | |
290 | * The internal host index in the @q will be updated by this routine to indicate | |
291 | * that the host has finished processing the entries. The @arm parameter | |
292 | * indicates that the queue should be rearmed when ringing the doorbell. | |
293 | * | |
294 | * This function will return the number of EQEs that were popped. | |
295 | **/ | |
296 | uint32_t | |
297 | lpfc_sli4_eq_release(struct lpfc_queue *q, bool arm) | |
298 | { | |
299 | uint32_t released = 0; | |
300 | struct lpfc_eqe *temp_eqe; | |
301 | struct lpfc_register doorbell; | |
302 | ||
2e90f4b5 JS |
303 | /* sanity check on queue memory */ |
304 | if (unlikely(!q)) | |
305 | return 0; | |
306 | ||
4f774513 JS |
307 | /* while there are valid entries */ |
308 | while (q->hba_index != q->host_index) { | |
309 | temp_eqe = q->qe[q->host_index].eqe; | |
cb5172ea | 310 | bf_set_le32(lpfc_eqe_valid, temp_eqe, 0); |
4f774513 JS |
311 | released++; |
312 | q->host_index = ((q->host_index + 1) % q->entry_count); | |
313 | } | |
314 | if (unlikely(released == 0 && !arm)) | |
315 | return 0; | |
316 | ||
317 | /* ring doorbell for number popped */ | |
318 | doorbell.word0 = 0; | |
319 | if (arm) { | |
320 | bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1); | |
321 | bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1); | |
322 | } | |
323 | bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released); | |
324 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT); | |
6b5151fd JS |
325 | bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell, |
326 | (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT)); | |
327 | bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id); | |
4f774513 | 328 | writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr); |
a747c9ce JS |
329 | /* PCI read to flush PCI pipeline on re-arming for INTx mode */ |
330 | if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM)) | |
331 | readl(q->phba->sli4_hba.EQCQDBregaddr); | |
4f774513 JS |
332 | return released; |
333 | } | |
334 | ||
335 | /** | |
336 | * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ | |
337 | * @q: The Completion Queue to get the first valid CQE from | |
338 | * | |
339 | * This routine will get the first valid Completion Queue Entry from @q, update | |
340 | * the queue's internal hba index, and return the CQE. If no valid CQEs are in | |
341 | * the Queue (no more work to do), or the Queue is full of CQEs that have been | |
342 | * processed, but not popped back to the HBA then this routine will return NULL. | |
343 | **/ | |
344 | static struct lpfc_cqe * | |
345 | lpfc_sli4_cq_get(struct lpfc_queue *q) | |
346 | { | |
347 | struct lpfc_cqe *cqe; | |
027140ea | 348 | uint32_t idx; |
4f774513 | 349 | |
2e90f4b5 JS |
350 | /* sanity check on queue memory */ |
351 | if (unlikely(!q)) | |
352 | return NULL; | |
353 | ||
4f774513 | 354 | /* If the next CQE is not valid then we are done */ |
cb5172ea | 355 | if (!bf_get_le32(lpfc_cqe_valid, q->qe[q->hba_index].cqe)) |
4f774513 JS |
356 | return NULL; |
357 | /* If the host has not yet processed the next entry then we are done */ | |
027140ea JS |
358 | idx = ((q->hba_index + 1) % q->entry_count); |
359 | if (idx == q->host_index) | |
4f774513 JS |
360 | return NULL; |
361 | ||
362 | cqe = q->qe[q->hba_index].cqe; | |
027140ea | 363 | q->hba_index = idx; |
4f774513 JS |
364 | return cqe; |
365 | } | |
366 | ||
367 | /** | |
368 | * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ | |
369 | * @q: The Completion Queue that the host has completed processing for. | |
370 | * @arm: Indicates whether the host wants to arms this CQ. | |
371 | * | |
372 | * This routine will mark all Completion queue entries on @q, from the last | |
373 | * known completed entry to the last entry that was processed, as completed | |
374 | * by clearing the valid bit for each completion queue entry. Then it will | |
375 | * notify the HBA, by ringing the doorbell, that the CQEs have been processed. | |
376 | * The internal host index in the @q will be updated by this routine to indicate | |
377 | * that the host has finished processing the entries. The @arm parameter | |
378 | * indicates that the queue should be rearmed when ringing the doorbell. | |
379 | * | |
380 | * This function will return the number of CQEs that were released. | |
381 | **/ | |
382 | uint32_t | |
383 | lpfc_sli4_cq_release(struct lpfc_queue *q, bool arm) | |
384 | { | |
385 | uint32_t released = 0; | |
386 | struct lpfc_cqe *temp_qe; | |
387 | struct lpfc_register doorbell; | |
388 | ||
2e90f4b5 JS |
389 | /* sanity check on queue memory */ |
390 | if (unlikely(!q)) | |
391 | return 0; | |
4f774513 JS |
392 | /* while there are valid entries */ |
393 | while (q->hba_index != q->host_index) { | |
394 | temp_qe = q->qe[q->host_index].cqe; | |
cb5172ea | 395 | bf_set_le32(lpfc_cqe_valid, temp_qe, 0); |
4f774513 JS |
396 | released++; |
397 | q->host_index = ((q->host_index + 1) % q->entry_count); | |
398 | } | |
399 | if (unlikely(released == 0 && !arm)) | |
400 | return 0; | |
401 | ||
402 | /* ring doorbell for number popped */ | |
403 | doorbell.word0 = 0; | |
404 | if (arm) | |
405 | bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1); | |
406 | bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released); | |
407 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION); | |
6b5151fd JS |
408 | bf_set(lpfc_eqcq_doorbell_cqid_hi, &doorbell, |
409 | (q->queue_id >> LPFC_CQID_HI_FIELD_SHIFT)); | |
410 | bf_set(lpfc_eqcq_doorbell_cqid_lo, &doorbell, q->queue_id); | |
4f774513 JS |
411 | writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr); |
412 | return released; | |
413 | } | |
414 | ||
415 | /** | |
416 | * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue | |
417 | * @q: The Header Receive Queue to operate on. | |
418 | * @wqe: The Receive Queue Entry to put on the Receive queue. | |
419 | * | |
420 | * This routine will copy the contents of @wqe to the next available entry on | |
421 | * the @q. This function will then ring the Receive Queue Doorbell to signal the | |
422 | * HBA to start processing the Receive Queue Entry. This function returns the | |
423 | * index that the rqe was copied to if successful. If no entries are available | |
424 | * on @q then this function will return -ENOMEM. | |
425 | * The caller is expected to hold the hbalock when calling this routine. | |
426 | **/ | |
427 | static int | |
428 | lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq, | |
429 | struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe) | |
430 | { | |
2e90f4b5 JS |
431 | struct lpfc_rqe *temp_hrqe; |
432 | struct lpfc_rqe *temp_drqe; | |
4f774513 JS |
433 | struct lpfc_register doorbell; |
434 | int put_index = hq->host_index; | |
435 | ||
2e90f4b5 JS |
436 | /* sanity check on queue memory */ |
437 | if (unlikely(!hq) || unlikely(!dq)) | |
438 | return -ENOMEM; | |
439 | temp_hrqe = hq->qe[hq->host_index].rqe; | |
440 | temp_drqe = dq->qe[dq->host_index].rqe; | |
441 | ||
4f774513 JS |
442 | if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ) |
443 | return -EINVAL; | |
444 | if (hq->host_index != dq->host_index) | |
445 | return -EINVAL; | |
446 | /* If the host has not yet processed the next entry then we are done */ | |
447 | if (((hq->host_index + 1) % hq->entry_count) == hq->hba_index) | |
448 | return -EBUSY; | |
449 | lpfc_sli_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size); | |
450 | lpfc_sli_pcimem_bcopy(drqe, temp_drqe, dq->entry_size); | |
451 | ||
452 | /* Update the host index to point to the next slot */ | |
453 | hq->host_index = ((hq->host_index + 1) % hq->entry_count); | |
454 | dq->host_index = ((dq->host_index + 1) % dq->entry_count); | |
455 | ||
456 | /* Ring The Header Receive Queue Doorbell */ | |
73d91e50 | 457 | if (!(hq->host_index % hq->entry_repost)) { |
4f774513 JS |
458 | doorbell.word0 = 0; |
459 | bf_set(lpfc_rq_doorbell_num_posted, &doorbell, | |
73d91e50 | 460 | hq->entry_repost); |
4f774513 JS |
461 | bf_set(lpfc_rq_doorbell_id, &doorbell, hq->queue_id); |
462 | writel(doorbell.word0, hq->phba->sli4_hba.RQDBregaddr); | |
463 | } | |
464 | return put_index; | |
465 | } | |
466 | ||
467 | /** | |
468 | * lpfc_sli4_rq_release - Updates internal hba index for RQ | |
469 | * @q: The Header Receive Queue to operate on. | |
470 | * | |
471 | * This routine will update the HBA index of a queue to reflect consumption of | |
472 | * one Receive Queue Entry by the HBA. When the HBA indicates that it has | |
473 | * consumed an entry the host calls this function to update the queue's | |
474 | * internal pointers. This routine returns the number of entries that were | |
475 | * consumed by the HBA. | |
476 | **/ | |
477 | static uint32_t | |
478 | lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq) | |
479 | { | |
2e90f4b5 JS |
480 | /* sanity check on queue memory */ |
481 | if (unlikely(!hq) || unlikely(!dq)) | |
482 | return 0; | |
483 | ||
4f774513 JS |
484 | if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ)) |
485 | return 0; | |
486 | hq->hba_index = ((hq->hba_index + 1) % hq->entry_count); | |
487 | dq->hba_index = ((dq->hba_index + 1) % dq->entry_count); | |
488 | return 1; | |
489 | } | |
490 | ||
e59058c4 | 491 | /** |
3621a710 | 492 | * lpfc_cmd_iocb - Get next command iocb entry in the ring |
e59058c4 JS |
493 | * @phba: Pointer to HBA context object. |
494 | * @pring: Pointer to driver SLI ring object. | |
495 | * | |
496 | * This function returns pointer to next command iocb entry | |
497 | * in the command ring. The caller must hold hbalock to prevent | |
498 | * other threads consume the next command iocb. | |
499 | * SLI-2/SLI-3 provide different sized iocbs. | |
500 | **/ | |
ed957684 JS |
501 | static inline IOCB_t * |
502 | lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) | |
503 | { | |
7e56aa25 JS |
504 | return (IOCB_t *) (((char *) pring->sli.sli3.cmdringaddr) + |
505 | pring->sli.sli3.cmdidx * phba->iocb_cmd_size); | |
ed957684 JS |
506 | } |
507 | ||
e59058c4 | 508 | /** |
3621a710 | 509 | * lpfc_resp_iocb - Get next response iocb entry in the ring |
e59058c4 JS |
510 | * @phba: Pointer to HBA context object. |
511 | * @pring: Pointer to driver SLI ring object. | |
512 | * | |
513 | * This function returns pointer to next response iocb entry | |
514 | * in the response ring. The caller must hold hbalock to make sure | |
515 | * that no other thread consume the next response iocb. | |
516 | * SLI-2/SLI-3 provide different sized iocbs. | |
517 | **/ | |
ed957684 JS |
518 | static inline IOCB_t * |
519 | lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) | |
520 | { | |
7e56aa25 JS |
521 | return (IOCB_t *) (((char *) pring->sli.sli3.rspringaddr) + |
522 | pring->sli.sli3.rspidx * phba->iocb_rsp_size); | |
ed957684 JS |
523 | } |
524 | ||
e59058c4 | 525 | /** |
3621a710 | 526 | * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool |
e59058c4 JS |
527 | * @phba: Pointer to HBA context object. |
528 | * | |
529 | * This function is called with hbalock held. This function | |
530 | * allocates a new driver iocb object from the iocb pool. If the | |
531 | * allocation is successful, it returns pointer to the newly | |
532 | * allocated iocb object else it returns NULL. | |
533 | **/ | |
4f2e66c6 | 534 | struct lpfc_iocbq * |
2e0fef85 | 535 | __lpfc_sli_get_iocbq(struct lpfc_hba *phba) |
0bd4ca25 JSEC |
536 | { |
537 | struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list; | |
538 | struct lpfc_iocbq * iocbq = NULL; | |
539 | ||
540 | list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list); | |
2a9bf3d0 JS |
541 | if (iocbq) |
542 | phba->iocb_cnt++; | |
543 | if (phba->iocb_cnt > phba->iocb_max) | |
544 | phba->iocb_max = phba->iocb_cnt; | |
0bd4ca25 JSEC |
545 | return iocbq; |
546 | } | |
547 | ||
da0436e9 JS |
548 | /** |
549 | * __lpfc_clear_active_sglq - Remove the active sglq for this XRI. | |
550 | * @phba: Pointer to HBA context object. | |
551 | * @xritag: XRI value. | |
552 | * | |
553 | * This function clears the sglq pointer from the array of acive | |
554 | * sglq's. The xritag that is passed in is used to index into the | |
555 | * array. Before the xritag can be used it needs to be adjusted | |
556 | * by subtracting the xribase. | |
557 | * | |
558 | * Returns sglq ponter = success, NULL = Failure. | |
559 | **/ | |
560 | static struct lpfc_sglq * | |
561 | __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag) | |
562 | { | |
da0436e9 | 563 | struct lpfc_sglq *sglq; |
6d368e53 JS |
564 | |
565 | sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag]; | |
566 | phba->sli4_hba.lpfc_sglq_active_list[xritag] = NULL; | |
da0436e9 JS |
567 | return sglq; |
568 | } | |
569 | ||
570 | /** | |
571 | * __lpfc_get_active_sglq - Get the active sglq for this XRI. | |
572 | * @phba: Pointer to HBA context object. | |
573 | * @xritag: XRI value. | |
574 | * | |
575 | * This function returns the sglq pointer from the array of acive | |
576 | * sglq's. The xritag that is passed in is used to index into the | |
577 | * array. Before the xritag can be used it needs to be adjusted | |
578 | * by subtracting the xribase. | |
579 | * | |
580 | * Returns sglq ponter = success, NULL = Failure. | |
581 | **/ | |
0f65ff68 | 582 | struct lpfc_sglq * |
da0436e9 JS |
583 | __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag) |
584 | { | |
da0436e9 | 585 | struct lpfc_sglq *sglq; |
6d368e53 JS |
586 | |
587 | sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag]; | |
da0436e9 JS |
588 | return sglq; |
589 | } | |
590 | ||
19ca7609 | 591 | /** |
1151e3ec | 592 | * lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap. |
19ca7609 JS |
593 | * @phba: Pointer to HBA context object. |
594 | * @xritag: xri used in this exchange. | |
595 | * @rrq: The RRQ to be cleared. | |
596 | * | |
19ca7609 | 597 | **/ |
1151e3ec JS |
598 | void |
599 | lpfc_clr_rrq_active(struct lpfc_hba *phba, | |
600 | uint16_t xritag, | |
601 | struct lpfc_node_rrq *rrq) | |
19ca7609 | 602 | { |
1151e3ec | 603 | struct lpfc_nodelist *ndlp = NULL; |
19ca7609 | 604 | |
1151e3ec JS |
605 | if ((rrq->vport) && NLP_CHK_NODE_ACT(rrq->ndlp)) |
606 | ndlp = lpfc_findnode_did(rrq->vport, rrq->nlp_DID); | |
19ca7609 JS |
607 | |
608 | /* The target DID could have been swapped (cable swap) | |
609 | * we should use the ndlp from the findnode if it is | |
610 | * available. | |
611 | */ | |
1151e3ec | 612 | if ((!ndlp) && rrq->ndlp) |
19ca7609 JS |
613 | ndlp = rrq->ndlp; |
614 | ||
1151e3ec JS |
615 | if (!ndlp) |
616 | goto out; | |
617 | ||
6d368e53 | 618 | if (test_and_clear_bit(xritag, ndlp->active_rrqs.xri_bitmap)) { |
19ca7609 JS |
619 | rrq->send_rrq = 0; |
620 | rrq->xritag = 0; | |
621 | rrq->rrq_stop_time = 0; | |
622 | } | |
1151e3ec | 623 | out: |
19ca7609 JS |
624 | mempool_free(rrq, phba->rrq_pool); |
625 | } | |
626 | ||
627 | /** | |
628 | * lpfc_handle_rrq_active - Checks if RRQ has waithed RATOV. | |
629 | * @phba: Pointer to HBA context object. | |
630 | * | |
631 | * This function is called with hbalock held. This function | |
632 | * Checks if stop_time (ratov from setting rrq active) has | |
633 | * been reached, if it has and the send_rrq flag is set then | |
634 | * it will call lpfc_send_rrq. If the send_rrq flag is not set | |
635 | * then it will just call the routine to clear the rrq and | |
636 | * free the rrq resource. | |
637 | * The timer is set to the next rrq that is going to expire before | |
638 | * leaving the routine. | |
639 | * | |
640 | **/ | |
641 | void | |
642 | lpfc_handle_rrq_active(struct lpfc_hba *phba) | |
643 | { | |
644 | struct lpfc_node_rrq *rrq; | |
645 | struct lpfc_node_rrq *nextrrq; | |
646 | unsigned long next_time; | |
647 | unsigned long iflags; | |
1151e3ec | 648 | LIST_HEAD(send_rrq); |
19ca7609 JS |
649 | |
650 | spin_lock_irqsave(&phba->hbalock, iflags); | |
651 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; | |
652 | next_time = jiffies + HZ * (phba->fc_ratov + 1); | |
653 | list_for_each_entry_safe(rrq, nextrrq, | |
1151e3ec JS |
654 | &phba->active_rrq_list, list) { |
655 | if (time_after(jiffies, rrq->rrq_stop_time)) | |
656 | list_move(&rrq->list, &send_rrq); | |
657 | else if (time_before(rrq->rrq_stop_time, next_time)) | |
19ca7609 JS |
658 | next_time = rrq->rrq_stop_time; |
659 | } | |
660 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
661 | if (!list_empty(&phba->active_rrq_list)) | |
662 | mod_timer(&phba->rrq_tmr, next_time); | |
1151e3ec JS |
663 | list_for_each_entry_safe(rrq, nextrrq, &send_rrq, list) { |
664 | list_del(&rrq->list); | |
665 | if (!rrq->send_rrq) | |
666 | /* this call will free the rrq */ | |
667 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); | |
668 | else if (lpfc_send_rrq(phba, rrq)) { | |
669 | /* if we send the rrq then the completion handler | |
670 | * will clear the bit in the xribitmap. | |
671 | */ | |
672 | lpfc_clr_rrq_active(phba, rrq->xritag, | |
673 | rrq); | |
674 | } | |
675 | } | |
19ca7609 JS |
676 | } |
677 | ||
678 | /** | |
679 | * lpfc_get_active_rrq - Get the active RRQ for this exchange. | |
680 | * @vport: Pointer to vport context object. | |
681 | * @xri: The xri used in the exchange. | |
682 | * @did: The targets DID for this exchange. | |
683 | * | |
684 | * returns NULL = rrq not found in the phba->active_rrq_list. | |
685 | * rrq = rrq for this xri and target. | |
686 | **/ | |
687 | struct lpfc_node_rrq * | |
688 | lpfc_get_active_rrq(struct lpfc_vport *vport, uint16_t xri, uint32_t did) | |
689 | { | |
690 | struct lpfc_hba *phba = vport->phba; | |
691 | struct lpfc_node_rrq *rrq; | |
692 | struct lpfc_node_rrq *nextrrq; | |
693 | unsigned long iflags; | |
694 | ||
695 | if (phba->sli_rev != LPFC_SLI_REV4) | |
696 | return NULL; | |
697 | spin_lock_irqsave(&phba->hbalock, iflags); | |
698 | list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) { | |
699 | if (rrq->vport == vport && rrq->xritag == xri && | |
700 | rrq->nlp_DID == did){ | |
701 | list_del(&rrq->list); | |
702 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
703 | return rrq; | |
704 | } | |
705 | } | |
706 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
707 | return NULL; | |
708 | } | |
709 | ||
710 | /** | |
711 | * lpfc_cleanup_vports_rrqs - Remove and clear the active RRQ for this vport. | |
712 | * @vport: Pointer to vport context object. | |
1151e3ec JS |
713 | * @ndlp: Pointer to the lpfc_node_list structure. |
714 | * If ndlp is NULL Remove all active RRQs for this vport from the | |
715 | * phba->active_rrq_list and clear the rrq. | |
716 | * If ndlp is not NULL then only remove rrqs for this vport & this ndlp. | |
19ca7609 JS |
717 | **/ |
718 | void | |
1151e3ec | 719 | lpfc_cleanup_vports_rrqs(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
19ca7609 JS |
720 | |
721 | { | |
722 | struct lpfc_hba *phba = vport->phba; | |
723 | struct lpfc_node_rrq *rrq; | |
724 | struct lpfc_node_rrq *nextrrq; | |
725 | unsigned long iflags; | |
1151e3ec | 726 | LIST_HEAD(rrq_list); |
19ca7609 JS |
727 | |
728 | if (phba->sli_rev != LPFC_SLI_REV4) | |
729 | return; | |
1151e3ec JS |
730 | if (!ndlp) { |
731 | lpfc_sli4_vport_delete_els_xri_aborted(vport); | |
732 | lpfc_sli4_vport_delete_fcp_xri_aborted(vport); | |
19ca7609 | 733 | } |
1151e3ec JS |
734 | spin_lock_irqsave(&phba->hbalock, iflags); |
735 | list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) | |
736 | if ((rrq->vport == vport) && (!ndlp || rrq->ndlp == ndlp)) | |
737 | list_move(&rrq->list, &rrq_list); | |
19ca7609 | 738 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
1151e3ec JS |
739 | |
740 | list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) { | |
741 | list_del(&rrq->list); | |
742 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); | |
743 | } | |
19ca7609 JS |
744 | } |
745 | ||
746 | /** | |
747 | * lpfc_cleanup_wt_rrqs - Remove all rrq's from the active list. | |
748 | * @phba: Pointer to HBA context object. | |
749 | * | |
750 | * Remove all rrqs from the phba->active_rrq_list and free them by | |
751 | * calling __lpfc_clr_active_rrq | |
752 | * | |
753 | **/ | |
754 | void | |
755 | lpfc_cleanup_wt_rrqs(struct lpfc_hba *phba) | |
756 | { | |
757 | struct lpfc_node_rrq *rrq; | |
758 | struct lpfc_node_rrq *nextrrq; | |
759 | unsigned long next_time; | |
760 | unsigned long iflags; | |
1151e3ec | 761 | LIST_HEAD(rrq_list); |
19ca7609 JS |
762 | |
763 | if (phba->sli_rev != LPFC_SLI_REV4) | |
764 | return; | |
765 | spin_lock_irqsave(&phba->hbalock, iflags); | |
766 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; | |
767 | next_time = jiffies + HZ * (phba->fc_ratov * 2); | |
1151e3ec JS |
768 | list_splice_init(&phba->active_rrq_list, &rrq_list); |
769 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
770 | ||
771 | list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) { | |
19ca7609 | 772 | list_del(&rrq->list); |
1151e3ec | 773 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); |
19ca7609 | 774 | } |
19ca7609 JS |
775 | if (!list_empty(&phba->active_rrq_list)) |
776 | mod_timer(&phba->rrq_tmr, next_time); | |
777 | } | |
778 | ||
779 | ||
780 | /** | |
1151e3ec | 781 | * lpfc_test_rrq_active - Test RRQ bit in xri_bitmap. |
19ca7609 JS |
782 | * @phba: Pointer to HBA context object. |
783 | * @ndlp: Targets nodelist pointer for this exchange. | |
784 | * @xritag the xri in the bitmap to test. | |
785 | * | |
786 | * This function is called with hbalock held. This function | |
787 | * returns 0 = rrq not active for this xri | |
788 | * 1 = rrq is valid for this xri. | |
789 | **/ | |
1151e3ec JS |
790 | int |
791 | lpfc_test_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, | |
19ca7609 JS |
792 | uint16_t xritag) |
793 | { | |
19ca7609 JS |
794 | if (!ndlp) |
795 | return 0; | |
6d368e53 | 796 | if (test_bit(xritag, ndlp->active_rrqs.xri_bitmap)) |
19ca7609 JS |
797 | return 1; |
798 | else | |
799 | return 0; | |
800 | } | |
801 | ||
802 | /** | |
803 | * lpfc_set_rrq_active - set RRQ active bit in xri_bitmap. | |
804 | * @phba: Pointer to HBA context object. | |
805 | * @ndlp: nodelist pointer for this target. | |
806 | * @xritag: xri used in this exchange. | |
807 | * @rxid: Remote Exchange ID. | |
808 | * @send_rrq: Flag used to determine if we should send rrq els cmd. | |
809 | * | |
810 | * This function takes the hbalock. | |
811 | * The active bit is always set in the active rrq xri_bitmap even | |
812 | * if there is no slot avaiable for the other rrq information. | |
813 | * | |
814 | * returns 0 rrq actived for this xri | |
815 | * < 0 No memory or invalid ndlp. | |
816 | **/ | |
817 | int | |
818 | lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, | |
b42c07c8 | 819 | uint16_t xritag, uint16_t rxid, uint16_t send_rrq) |
19ca7609 | 820 | { |
19ca7609 | 821 | unsigned long iflags; |
b42c07c8 JS |
822 | struct lpfc_node_rrq *rrq; |
823 | int empty; | |
824 | ||
825 | if (!ndlp) | |
826 | return -EINVAL; | |
827 | ||
828 | if (!phba->cfg_enable_rrq) | |
829 | return -EINVAL; | |
19ca7609 JS |
830 | |
831 | spin_lock_irqsave(&phba->hbalock, iflags); | |
b42c07c8 JS |
832 | if (phba->pport->load_flag & FC_UNLOADING) { |
833 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; | |
834 | goto out; | |
835 | } | |
836 | ||
837 | /* | |
838 | * set the active bit even if there is no mem available. | |
839 | */ | |
840 | if (NLP_CHK_FREE_REQ(ndlp)) | |
841 | goto out; | |
842 | ||
843 | if (ndlp->vport && (ndlp->vport->load_flag & FC_UNLOADING)) | |
844 | goto out; | |
845 | ||
846 | if (test_and_set_bit(xritag, ndlp->active_rrqs.xri_bitmap)) | |
847 | goto out; | |
848 | ||
19ca7609 | 849 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
b42c07c8 JS |
850 | rrq = mempool_alloc(phba->rrq_pool, GFP_KERNEL); |
851 | if (!rrq) { | |
852 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
853 | "3155 Unable to allocate RRQ xri:0x%x rxid:0x%x" | |
854 | " DID:0x%x Send:%d\n", | |
855 | xritag, rxid, ndlp->nlp_DID, send_rrq); | |
856 | return -EINVAL; | |
857 | } | |
858 | rrq->send_rrq = send_rrq; | |
859 | rrq->xritag = xritag; | |
860 | rrq->rrq_stop_time = jiffies + HZ * (phba->fc_ratov + 1); | |
861 | rrq->ndlp = ndlp; | |
862 | rrq->nlp_DID = ndlp->nlp_DID; | |
863 | rrq->vport = ndlp->vport; | |
864 | rrq->rxid = rxid; | |
865 | rrq->send_rrq = send_rrq; | |
866 | spin_lock_irqsave(&phba->hbalock, iflags); | |
867 | empty = list_empty(&phba->active_rrq_list); | |
868 | list_add_tail(&rrq->list, &phba->active_rrq_list); | |
869 | phba->hba_flag |= HBA_RRQ_ACTIVE; | |
870 | if (empty) | |
871 | lpfc_worker_wake_up(phba); | |
872 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
873 | return 0; | |
874 | out: | |
875 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
876 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
877 | "2921 Can't set rrq active xri:0x%x rxid:0x%x" | |
878 | " DID:0x%x Send:%d\n", | |
879 | xritag, rxid, ndlp->nlp_DID, send_rrq); | |
880 | return -EINVAL; | |
19ca7609 JS |
881 | } |
882 | ||
da0436e9 JS |
883 | /** |
884 | * __lpfc_sli_get_sglq - Allocates an iocb object from sgl pool | |
885 | * @phba: Pointer to HBA context object. | |
19ca7609 | 886 | * @piocb: Pointer to the iocbq. |
da0436e9 JS |
887 | * |
888 | * This function is called with hbalock held. This function | |
6d368e53 | 889 | * gets a new driver sglq object from the sglq list. If the |
da0436e9 JS |
890 | * list is not empty then it is successful, it returns pointer to the newly |
891 | * allocated sglq object else it returns NULL. | |
892 | **/ | |
893 | static struct lpfc_sglq * | |
19ca7609 | 894 | __lpfc_sli_get_sglq(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq) |
da0436e9 JS |
895 | { |
896 | struct list_head *lpfc_sgl_list = &phba->sli4_hba.lpfc_sgl_list; | |
897 | struct lpfc_sglq *sglq = NULL; | |
19ca7609 | 898 | struct lpfc_sglq *start_sglq = NULL; |
19ca7609 JS |
899 | struct lpfc_scsi_buf *lpfc_cmd; |
900 | struct lpfc_nodelist *ndlp; | |
901 | int found = 0; | |
902 | ||
903 | if (piocbq->iocb_flag & LPFC_IO_FCP) { | |
904 | lpfc_cmd = (struct lpfc_scsi_buf *) piocbq->context1; | |
905 | ndlp = lpfc_cmd->rdata->pnode; | |
be858b65 JS |
906 | } else if ((piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) && |
907 | !(piocbq->iocb_flag & LPFC_IO_LIBDFC)) | |
19ca7609 | 908 | ndlp = piocbq->context_un.ndlp; |
93d1379e JS |
909 | else if ((piocbq->iocb.ulpCommand == CMD_ELS_REQUEST64_CR) && |
910 | (piocbq->iocb_flag & LPFC_IO_LIBDFC)) | |
911 | ndlp = piocbq->context_un.ndlp; | |
19ca7609 JS |
912 | else |
913 | ndlp = piocbq->context1; | |
914 | ||
da0436e9 | 915 | list_remove_head(lpfc_sgl_list, sglq, struct lpfc_sglq, list); |
19ca7609 JS |
916 | start_sglq = sglq; |
917 | while (!found) { | |
918 | if (!sglq) | |
919 | return NULL; | |
ee0f4fe1 | 920 | if (lpfc_test_rrq_active(phba, ndlp, sglq->sli4_lxritag)) { |
19ca7609 JS |
921 | /* This xri has an rrq outstanding for this DID. |
922 | * put it back in the list and get another xri. | |
923 | */ | |
924 | list_add_tail(&sglq->list, lpfc_sgl_list); | |
925 | sglq = NULL; | |
926 | list_remove_head(lpfc_sgl_list, sglq, | |
927 | struct lpfc_sglq, list); | |
928 | if (sglq == start_sglq) { | |
929 | sglq = NULL; | |
930 | break; | |
931 | } else | |
932 | continue; | |
933 | } | |
934 | sglq->ndlp = ndlp; | |
935 | found = 1; | |
6d368e53 | 936 | phba->sli4_hba.lpfc_sglq_active_list[sglq->sli4_lxritag] = sglq; |
19ca7609 JS |
937 | sglq->state = SGL_ALLOCATED; |
938 | } | |
da0436e9 JS |
939 | return sglq; |
940 | } | |
941 | ||
e59058c4 | 942 | /** |
3621a710 | 943 | * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool |
e59058c4 JS |
944 | * @phba: Pointer to HBA context object. |
945 | * | |
946 | * This function is called with no lock held. This function | |
947 | * allocates a new driver iocb object from the iocb pool. If the | |
948 | * allocation is successful, it returns pointer to the newly | |
949 | * allocated iocb object else it returns NULL. | |
950 | **/ | |
2e0fef85 JS |
951 | struct lpfc_iocbq * |
952 | lpfc_sli_get_iocbq(struct lpfc_hba *phba) | |
953 | { | |
954 | struct lpfc_iocbq * iocbq = NULL; | |
955 | unsigned long iflags; | |
956 | ||
957 | spin_lock_irqsave(&phba->hbalock, iflags); | |
958 | iocbq = __lpfc_sli_get_iocbq(phba); | |
959 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
960 | return iocbq; | |
961 | } | |
962 | ||
4f774513 JS |
963 | /** |
964 | * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool | |
965 | * @phba: Pointer to HBA context object. | |
966 | * @iocbq: Pointer to driver iocb object. | |
967 | * | |
968 | * This function is called with hbalock held to release driver | |
969 | * iocb object to the iocb pool. The iotag in the iocb object | |
970 | * does not change for each use of the iocb object. This function | |
971 | * clears all other fields of the iocb object when it is freed. | |
972 | * The sqlq structure that holds the xritag and phys and virtual | |
973 | * mappings for the scatter gather list is retrieved from the | |
974 | * active array of sglq. The get of the sglq pointer also clears | |
975 | * the entry in the array. If the status of the IO indiactes that | |
976 | * this IO was aborted then the sglq entry it put on the | |
977 | * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the | |
978 | * IO has good status or fails for any other reason then the sglq | |
979 | * entry is added to the free list (lpfc_sgl_list). | |
980 | **/ | |
981 | static void | |
982 | __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) | |
983 | { | |
984 | struct lpfc_sglq *sglq; | |
985 | size_t start_clean = offsetof(struct lpfc_iocbq, iocb); | |
2a9bf3d0 JS |
986 | unsigned long iflag = 0; |
987 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; | |
4f774513 JS |
988 | |
989 | if (iocbq->sli4_xritag == NO_XRI) | |
990 | sglq = NULL; | |
991 | else | |
6d368e53 JS |
992 | sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_lxritag); |
993 | ||
4f774513 | 994 | if (sglq) { |
0f65ff68 JS |
995 | if ((iocbq->iocb_flag & LPFC_EXCHANGE_BUSY) && |
996 | (sglq->state != SGL_XRI_ABORTED)) { | |
4f774513 JS |
997 | spin_lock_irqsave(&phba->sli4_hba.abts_sgl_list_lock, |
998 | iflag); | |
999 | list_add(&sglq->list, | |
1000 | &phba->sli4_hba.lpfc_abts_els_sgl_list); | |
1001 | spin_unlock_irqrestore( | |
1002 | &phba->sli4_hba.abts_sgl_list_lock, iflag); | |
0f65ff68 JS |
1003 | } else { |
1004 | sglq->state = SGL_FREED; | |
19ca7609 | 1005 | sglq->ndlp = NULL; |
fedd3b7b JS |
1006 | list_add_tail(&sglq->list, |
1007 | &phba->sli4_hba.lpfc_sgl_list); | |
2a9bf3d0 JS |
1008 | |
1009 | /* Check if TXQ queue needs to be serviced */ | |
589a52d6 | 1010 | if (pring->txq_cnt) |
2a9bf3d0 | 1011 | lpfc_worker_wake_up(phba); |
0f65ff68 | 1012 | } |
4f774513 JS |
1013 | } |
1014 | ||
1015 | ||
1016 | /* | |
1017 | * Clean all volatile data fields, preserve iotag and node struct. | |
1018 | */ | |
1019 | memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean); | |
6d368e53 | 1020 | iocbq->sli4_lxritag = NO_XRI; |
4f774513 JS |
1021 | iocbq->sli4_xritag = NO_XRI; |
1022 | list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); | |
1023 | } | |
1024 | ||
2a9bf3d0 | 1025 | |
e59058c4 | 1026 | /** |
3772a991 | 1027 | * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool |
e59058c4 JS |
1028 | * @phba: Pointer to HBA context object. |
1029 | * @iocbq: Pointer to driver iocb object. | |
1030 | * | |
1031 | * This function is called with hbalock held to release driver | |
1032 | * iocb object to the iocb pool. The iotag in the iocb object | |
1033 | * does not change for each use of the iocb object. This function | |
1034 | * clears all other fields of the iocb object when it is freed. | |
1035 | **/ | |
a6ababd2 | 1036 | static void |
3772a991 | 1037 | __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
604a3e30 | 1038 | { |
2e0fef85 | 1039 | size_t start_clean = offsetof(struct lpfc_iocbq, iocb); |
604a3e30 JB |
1040 | |
1041 | /* | |
1042 | * Clean all volatile data fields, preserve iotag and node struct. | |
1043 | */ | |
1044 | memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean); | |
3772a991 | 1045 | iocbq->sli4_xritag = NO_XRI; |
604a3e30 JB |
1046 | list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); |
1047 | } | |
1048 | ||
3772a991 JS |
1049 | /** |
1050 | * __lpfc_sli_release_iocbq - Release iocb to the iocb pool | |
1051 | * @phba: Pointer to HBA context object. | |
1052 | * @iocbq: Pointer to driver iocb object. | |
1053 | * | |
1054 | * This function is called with hbalock held to release driver | |
1055 | * iocb object to the iocb pool. The iotag in the iocb object | |
1056 | * does not change for each use of the iocb object. This function | |
1057 | * clears all other fields of the iocb object when it is freed. | |
1058 | **/ | |
1059 | static void | |
1060 | __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) | |
1061 | { | |
1062 | phba->__lpfc_sli_release_iocbq(phba, iocbq); | |
2a9bf3d0 | 1063 | phba->iocb_cnt--; |
3772a991 JS |
1064 | } |
1065 | ||
e59058c4 | 1066 | /** |
3621a710 | 1067 | * lpfc_sli_release_iocbq - Release iocb to the iocb pool |
e59058c4 JS |
1068 | * @phba: Pointer to HBA context object. |
1069 | * @iocbq: Pointer to driver iocb object. | |
1070 | * | |
1071 | * This function is called with no lock held to release the iocb to | |
1072 | * iocb pool. | |
1073 | **/ | |
2e0fef85 JS |
1074 | void |
1075 | lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) | |
1076 | { | |
1077 | unsigned long iflags; | |
1078 | ||
1079 | /* | |
1080 | * Clean all volatile data fields, preserve iotag and node struct. | |
1081 | */ | |
1082 | spin_lock_irqsave(&phba->hbalock, iflags); | |
1083 | __lpfc_sli_release_iocbq(phba, iocbq); | |
1084 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
1085 | } | |
1086 | ||
a257bf90 JS |
1087 | /** |
1088 | * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list. | |
1089 | * @phba: Pointer to HBA context object. | |
1090 | * @iocblist: List of IOCBs. | |
1091 | * @ulpstatus: ULP status in IOCB command field. | |
1092 | * @ulpWord4: ULP word-4 in IOCB command field. | |
1093 | * | |
1094 | * This function is called with a list of IOCBs to cancel. It cancels the IOCB | |
1095 | * on the list by invoking the complete callback function associated with the | |
1096 | * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond | |
1097 | * fields. | |
1098 | **/ | |
1099 | void | |
1100 | lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist, | |
1101 | uint32_t ulpstatus, uint32_t ulpWord4) | |
1102 | { | |
1103 | struct lpfc_iocbq *piocb; | |
1104 | ||
1105 | while (!list_empty(iocblist)) { | |
1106 | list_remove_head(iocblist, piocb, struct lpfc_iocbq, list); | |
1107 | ||
1108 | if (!piocb->iocb_cmpl) | |
1109 | lpfc_sli_release_iocbq(phba, piocb); | |
1110 | else { | |
1111 | piocb->iocb.ulpStatus = ulpstatus; | |
1112 | piocb->iocb.un.ulpWord[4] = ulpWord4; | |
1113 | (piocb->iocb_cmpl) (phba, piocb, piocb); | |
1114 | } | |
1115 | } | |
1116 | return; | |
1117 | } | |
1118 | ||
e59058c4 | 1119 | /** |
3621a710 JS |
1120 | * lpfc_sli_iocb_cmd_type - Get the iocb type |
1121 | * @iocb_cmnd: iocb command code. | |
e59058c4 JS |
1122 | * |
1123 | * This function is called by ring event handler function to get the iocb type. | |
1124 | * This function translates the iocb command to an iocb command type used to | |
1125 | * decide the final disposition of each completed IOCB. | |
1126 | * The function returns | |
1127 | * LPFC_UNKNOWN_IOCB if it is an unsupported iocb | |
1128 | * LPFC_SOL_IOCB if it is a solicited iocb completion | |
1129 | * LPFC_ABORT_IOCB if it is an abort iocb | |
1130 | * LPFC_UNSOL_IOCB if it is an unsolicited iocb | |
1131 | * | |
1132 | * The caller is not required to hold any lock. | |
1133 | **/ | |
dea3101e | 1134 | static lpfc_iocb_type |
1135 | lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd) | |
1136 | { | |
1137 | lpfc_iocb_type type = LPFC_UNKNOWN_IOCB; | |
1138 | ||
1139 | if (iocb_cmnd > CMD_MAX_IOCB_CMD) | |
1140 | return 0; | |
1141 | ||
1142 | switch (iocb_cmnd) { | |
1143 | case CMD_XMIT_SEQUENCE_CR: | |
1144 | case CMD_XMIT_SEQUENCE_CX: | |
1145 | case CMD_XMIT_BCAST_CN: | |
1146 | case CMD_XMIT_BCAST_CX: | |
1147 | case CMD_ELS_REQUEST_CR: | |
1148 | case CMD_ELS_REQUEST_CX: | |
1149 | case CMD_CREATE_XRI_CR: | |
1150 | case CMD_CREATE_XRI_CX: | |
1151 | case CMD_GET_RPI_CN: | |
1152 | case CMD_XMIT_ELS_RSP_CX: | |
1153 | case CMD_GET_RPI_CR: | |
1154 | case CMD_FCP_IWRITE_CR: | |
1155 | case CMD_FCP_IWRITE_CX: | |
1156 | case CMD_FCP_IREAD_CR: | |
1157 | case CMD_FCP_IREAD_CX: | |
1158 | case CMD_FCP_ICMND_CR: | |
1159 | case CMD_FCP_ICMND_CX: | |
f5603511 JS |
1160 | case CMD_FCP_TSEND_CX: |
1161 | case CMD_FCP_TRSP_CX: | |
1162 | case CMD_FCP_TRECEIVE_CX: | |
1163 | case CMD_FCP_AUTO_TRSP_CX: | |
dea3101e | 1164 | case CMD_ADAPTER_MSG: |
1165 | case CMD_ADAPTER_DUMP: | |
1166 | case CMD_XMIT_SEQUENCE64_CR: | |
1167 | case CMD_XMIT_SEQUENCE64_CX: | |
1168 | case CMD_XMIT_BCAST64_CN: | |
1169 | case CMD_XMIT_BCAST64_CX: | |
1170 | case CMD_ELS_REQUEST64_CR: | |
1171 | case CMD_ELS_REQUEST64_CX: | |
1172 | case CMD_FCP_IWRITE64_CR: | |
1173 | case CMD_FCP_IWRITE64_CX: | |
1174 | case CMD_FCP_IREAD64_CR: | |
1175 | case CMD_FCP_IREAD64_CX: | |
1176 | case CMD_FCP_ICMND64_CR: | |
1177 | case CMD_FCP_ICMND64_CX: | |
f5603511 JS |
1178 | case CMD_FCP_TSEND64_CX: |
1179 | case CMD_FCP_TRSP64_CX: | |
1180 | case CMD_FCP_TRECEIVE64_CX: | |
dea3101e | 1181 | case CMD_GEN_REQUEST64_CR: |
1182 | case CMD_GEN_REQUEST64_CX: | |
1183 | case CMD_XMIT_ELS_RSP64_CX: | |
da0436e9 JS |
1184 | case DSSCMD_IWRITE64_CR: |
1185 | case DSSCMD_IWRITE64_CX: | |
1186 | case DSSCMD_IREAD64_CR: | |
1187 | case DSSCMD_IREAD64_CX: | |
dea3101e | 1188 | type = LPFC_SOL_IOCB; |
1189 | break; | |
1190 | case CMD_ABORT_XRI_CN: | |
1191 | case CMD_ABORT_XRI_CX: | |
1192 | case CMD_CLOSE_XRI_CN: | |
1193 | case CMD_CLOSE_XRI_CX: | |
1194 | case CMD_XRI_ABORTED_CX: | |
1195 | case CMD_ABORT_MXRI64_CN: | |
6669f9bb | 1196 | case CMD_XMIT_BLS_RSP64_CX: |
dea3101e | 1197 | type = LPFC_ABORT_IOCB; |
1198 | break; | |
1199 | case CMD_RCV_SEQUENCE_CX: | |
1200 | case CMD_RCV_ELS_REQ_CX: | |
1201 | case CMD_RCV_SEQUENCE64_CX: | |
1202 | case CMD_RCV_ELS_REQ64_CX: | |
57127f15 | 1203 | case CMD_ASYNC_STATUS: |
ed957684 JS |
1204 | case CMD_IOCB_RCV_SEQ64_CX: |
1205 | case CMD_IOCB_RCV_ELS64_CX: | |
1206 | case CMD_IOCB_RCV_CONT64_CX: | |
3163f725 | 1207 | case CMD_IOCB_RET_XRI64_CX: |
dea3101e | 1208 | type = LPFC_UNSOL_IOCB; |
1209 | break; | |
3163f725 JS |
1210 | case CMD_IOCB_XMIT_MSEQ64_CR: |
1211 | case CMD_IOCB_XMIT_MSEQ64_CX: | |
1212 | case CMD_IOCB_RCV_SEQ_LIST64_CX: | |
1213 | case CMD_IOCB_RCV_ELS_LIST64_CX: | |
1214 | case CMD_IOCB_CLOSE_EXTENDED_CN: | |
1215 | case CMD_IOCB_ABORT_EXTENDED_CN: | |
1216 | case CMD_IOCB_RET_HBQE64_CN: | |
1217 | case CMD_IOCB_FCP_IBIDIR64_CR: | |
1218 | case CMD_IOCB_FCP_IBIDIR64_CX: | |
1219 | case CMD_IOCB_FCP_ITASKMGT64_CX: | |
1220 | case CMD_IOCB_LOGENTRY_CN: | |
1221 | case CMD_IOCB_LOGENTRY_ASYNC_CN: | |
1222 | printk("%s - Unhandled SLI-3 Command x%x\n", | |
cadbd4a5 | 1223 | __func__, iocb_cmnd); |
3163f725 JS |
1224 | type = LPFC_UNKNOWN_IOCB; |
1225 | break; | |
dea3101e | 1226 | default: |
1227 | type = LPFC_UNKNOWN_IOCB; | |
1228 | break; | |
1229 | } | |
1230 | ||
1231 | return type; | |
1232 | } | |
1233 | ||
e59058c4 | 1234 | /** |
3621a710 | 1235 | * lpfc_sli_ring_map - Issue config_ring mbox for all rings |
e59058c4 JS |
1236 | * @phba: Pointer to HBA context object. |
1237 | * | |
1238 | * This function is called from SLI initialization code | |
1239 | * to configure every ring of the HBA's SLI interface. The | |
1240 | * caller is not required to hold any lock. This function issues | |
1241 | * a config_ring mailbox command for each ring. | |
1242 | * This function returns zero if successful else returns a negative | |
1243 | * error code. | |
1244 | **/ | |
dea3101e | 1245 | static int |
ed957684 | 1246 | lpfc_sli_ring_map(struct lpfc_hba *phba) |
dea3101e | 1247 | { |
1248 | struct lpfc_sli *psli = &phba->sli; | |
ed957684 JS |
1249 | LPFC_MBOXQ_t *pmb; |
1250 | MAILBOX_t *pmbox; | |
1251 | int i, rc, ret = 0; | |
dea3101e | 1252 | |
ed957684 JS |
1253 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
1254 | if (!pmb) | |
1255 | return -ENOMEM; | |
04c68496 | 1256 | pmbox = &pmb->u.mb; |
ed957684 | 1257 | phba->link_state = LPFC_INIT_MBX_CMDS; |
dea3101e | 1258 | for (i = 0; i < psli->num_rings; i++) { |
dea3101e | 1259 | lpfc_config_ring(phba, i, pmb); |
1260 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); | |
1261 | if (rc != MBX_SUCCESS) { | |
92d7f7b0 | 1262 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 1263 | "0446 Adapter failed to init (%d), " |
dea3101e | 1264 | "mbxCmd x%x CFG_RING, mbxStatus x%x, " |
1265 | "ring %d\n", | |
e8b62011 JS |
1266 | rc, pmbox->mbxCommand, |
1267 | pmbox->mbxStatus, i); | |
2e0fef85 | 1268 | phba->link_state = LPFC_HBA_ERROR; |
ed957684 JS |
1269 | ret = -ENXIO; |
1270 | break; | |
dea3101e | 1271 | } |
1272 | } | |
ed957684 JS |
1273 | mempool_free(pmb, phba->mbox_mem_pool); |
1274 | return ret; | |
dea3101e | 1275 | } |
1276 | ||
e59058c4 | 1277 | /** |
3621a710 | 1278 | * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq |
e59058c4 JS |
1279 | * @phba: Pointer to HBA context object. |
1280 | * @pring: Pointer to driver SLI ring object. | |
1281 | * @piocb: Pointer to the driver iocb object. | |
1282 | * | |
1283 | * This function is called with hbalock held. The function adds the | |
1284 | * new iocb to txcmplq of the given ring. This function always returns | |
1285 | * 0. If this function is called for ELS ring, this function checks if | |
1286 | * there is a vport associated with the ELS command. This function also | |
1287 | * starts els_tmofunc timer if this is an ELS command. | |
1288 | **/ | |
dea3101e | 1289 | static int |
2e0fef85 JS |
1290 | lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
1291 | struct lpfc_iocbq *piocb) | |
dea3101e | 1292 | { |
dea3101e | 1293 | list_add_tail(&piocb->list, &pring->txcmplq); |
4f2e66c6 | 1294 | piocb->iocb_flag |= LPFC_IO_ON_TXCMPLQ; |
dea3101e | 1295 | pring->txcmplq_cnt++; |
2a9bf3d0 JS |
1296 | if (pring->txcmplq_cnt > pring->txcmplq_max) |
1297 | pring->txcmplq_max = pring->txcmplq_cnt; | |
1298 | ||
92d7f7b0 JS |
1299 | if ((unlikely(pring->ringno == LPFC_ELS_RING)) && |
1300 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && | |
1301 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { | |
1302 | if (!piocb->vport) | |
1303 | BUG(); | |
1304 | else | |
1305 | mod_timer(&piocb->vport->els_tmofunc, | |
1306 | jiffies + HZ * (phba->fc_ratov << 1)); | |
1307 | } | |
1308 | ||
dea3101e | 1309 | |
2e0fef85 | 1310 | return 0; |
dea3101e | 1311 | } |
1312 | ||
e59058c4 | 1313 | /** |
3621a710 | 1314 | * lpfc_sli_ringtx_get - Get first element of the txq |
e59058c4 JS |
1315 | * @phba: Pointer to HBA context object. |
1316 | * @pring: Pointer to driver SLI ring object. | |
1317 | * | |
1318 | * This function is called with hbalock held to get next | |
1319 | * iocb in txq of the given ring. If there is any iocb in | |
1320 | * the txq, the function returns first iocb in the list after | |
1321 | * removing the iocb from the list, else it returns NULL. | |
1322 | **/ | |
2a9bf3d0 | 1323 | struct lpfc_iocbq * |
2e0fef85 | 1324 | lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
dea3101e | 1325 | { |
dea3101e | 1326 | struct lpfc_iocbq *cmd_iocb; |
1327 | ||
858c9f6c JS |
1328 | list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list); |
1329 | if (cmd_iocb != NULL) | |
dea3101e | 1330 | pring->txq_cnt--; |
2e0fef85 | 1331 | return cmd_iocb; |
dea3101e | 1332 | } |
1333 | ||
e59058c4 | 1334 | /** |
3621a710 | 1335 | * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring |
e59058c4 JS |
1336 | * @phba: Pointer to HBA context object. |
1337 | * @pring: Pointer to driver SLI ring object. | |
1338 | * | |
1339 | * This function is called with hbalock held and the caller must post the | |
1340 | * iocb without releasing the lock. If the caller releases the lock, | |
1341 | * iocb slot returned by the function is not guaranteed to be available. | |
1342 | * The function returns pointer to the next available iocb slot if there | |
1343 | * is available slot in the ring, else it returns NULL. | |
1344 | * If the get index of the ring is ahead of the put index, the function | |
1345 | * will post an error attention event to the worker thread to take the | |
1346 | * HBA to offline state. | |
1347 | **/ | |
dea3101e | 1348 | static IOCB_t * |
1349 | lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring) | |
1350 | { | |
34b02dcd | 1351 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
7e56aa25 JS |
1352 | uint32_t max_cmd_idx = pring->sli.sli3.numCiocb; |
1353 | if ((pring->sli.sli3.next_cmdidx == pring->sli.sli3.cmdidx) && | |
1354 | (++pring->sli.sli3.next_cmdidx >= max_cmd_idx)) | |
1355 | pring->sli.sli3.next_cmdidx = 0; | |
dea3101e | 1356 | |
7e56aa25 JS |
1357 | if (unlikely(pring->sli.sli3.local_getidx == |
1358 | pring->sli.sli3.next_cmdidx)) { | |
dea3101e | 1359 | |
7e56aa25 | 1360 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
dea3101e | 1361 | |
7e56aa25 | 1362 | if (unlikely(pring->sli.sli3.local_getidx >= max_cmd_idx)) { |
dea3101e | 1363 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
e8b62011 | 1364 | "0315 Ring %d issue: portCmdGet %d " |
025dfdaf | 1365 | "is bigger than cmd ring %d\n", |
e8b62011 | 1366 | pring->ringno, |
7e56aa25 JS |
1367 | pring->sli.sli3.local_getidx, |
1368 | max_cmd_idx); | |
dea3101e | 1369 | |
2e0fef85 | 1370 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e | 1371 | /* |
1372 | * All error attention handlers are posted to | |
1373 | * worker thread | |
1374 | */ | |
1375 | phba->work_ha |= HA_ERATT; | |
1376 | phba->work_hs = HS_FFER3; | |
92d7f7b0 | 1377 | |
5e9d9b82 | 1378 | lpfc_worker_wake_up(phba); |
dea3101e | 1379 | |
1380 | return NULL; | |
1381 | } | |
1382 | ||
7e56aa25 | 1383 | if (pring->sli.sli3.local_getidx == pring->sli.sli3.next_cmdidx) |
dea3101e | 1384 | return NULL; |
1385 | } | |
1386 | ||
ed957684 | 1387 | return lpfc_cmd_iocb(phba, pring); |
dea3101e | 1388 | } |
1389 | ||
e59058c4 | 1390 | /** |
3621a710 | 1391 | * lpfc_sli_next_iotag - Get an iotag for the iocb |
e59058c4 JS |
1392 | * @phba: Pointer to HBA context object. |
1393 | * @iocbq: Pointer to driver iocb object. | |
1394 | * | |
1395 | * This function gets an iotag for the iocb. If there is no unused iotag and | |
1396 | * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup | |
1397 | * array and assigns a new iotag. | |
1398 | * The function returns the allocated iotag if successful, else returns zero. | |
1399 | * Zero is not a valid iotag. | |
1400 | * The caller is not required to hold any lock. | |
1401 | **/ | |
604a3e30 | 1402 | uint16_t |
2e0fef85 | 1403 | lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
dea3101e | 1404 | { |
2e0fef85 JS |
1405 | struct lpfc_iocbq **new_arr; |
1406 | struct lpfc_iocbq **old_arr; | |
604a3e30 JB |
1407 | size_t new_len; |
1408 | struct lpfc_sli *psli = &phba->sli; | |
1409 | uint16_t iotag; | |
dea3101e | 1410 | |
2e0fef85 | 1411 | spin_lock_irq(&phba->hbalock); |
604a3e30 JB |
1412 | iotag = psli->last_iotag; |
1413 | if(++iotag < psli->iocbq_lookup_len) { | |
1414 | psli->last_iotag = iotag; | |
1415 | psli->iocbq_lookup[iotag] = iocbq; | |
2e0fef85 | 1416 | spin_unlock_irq(&phba->hbalock); |
604a3e30 JB |
1417 | iocbq->iotag = iotag; |
1418 | return iotag; | |
2e0fef85 | 1419 | } else if (psli->iocbq_lookup_len < (0xffff |
604a3e30 JB |
1420 | - LPFC_IOCBQ_LOOKUP_INCREMENT)) { |
1421 | new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT; | |
2e0fef85 JS |
1422 | spin_unlock_irq(&phba->hbalock); |
1423 | new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *), | |
604a3e30 JB |
1424 | GFP_KERNEL); |
1425 | if (new_arr) { | |
2e0fef85 | 1426 | spin_lock_irq(&phba->hbalock); |
604a3e30 JB |
1427 | old_arr = psli->iocbq_lookup; |
1428 | if (new_len <= psli->iocbq_lookup_len) { | |
1429 | /* highly unprobable case */ | |
1430 | kfree(new_arr); | |
1431 | iotag = psli->last_iotag; | |
1432 | if(++iotag < psli->iocbq_lookup_len) { | |
1433 | psli->last_iotag = iotag; | |
1434 | psli->iocbq_lookup[iotag] = iocbq; | |
2e0fef85 | 1435 | spin_unlock_irq(&phba->hbalock); |
604a3e30 JB |
1436 | iocbq->iotag = iotag; |
1437 | return iotag; | |
1438 | } | |
2e0fef85 | 1439 | spin_unlock_irq(&phba->hbalock); |
604a3e30 JB |
1440 | return 0; |
1441 | } | |
1442 | if (psli->iocbq_lookup) | |
1443 | memcpy(new_arr, old_arr, | |
1444 | ((psli->last_iotag + 1) * | |
311464ec | 1445 | sizeof (struct lpfc_iocbq *))); |
604a3e30 JB |
1446 | psli->iocbq_lookup = new_arr; |
1447 | psli->iocbq_lookup_len = new_len; | |
1448 | psli->last_iotag = iotag; | |
1449 | psli->iocbq_lookup[iotag] = iocbq; | |
2e0fef85 | 1450 | spin_unlock_irq(&phba->hbalock); |
604a3e30 JB |
1451 | iocbq->iotag = iotag; |
1452 | kfree(old_arr); | |
1453 | return iotag; | |
1454 | } | |
8f6d98d2 | 1455 | } else |
2e0fef85 | 1456 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 1457 | |
bc73905a | 1458 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
e8b62011 JS |
1459 | "0318 Failed to allocate IOTAG.last IOTAG is %d\n", |
1460 | psli->last_iotag); | |
dea3101e | 1461 | |
604a3e30 | 1462 | return 0; |
dea3101e | 1463 | } |
1464 | ||
e59058c4 | 1465 | /** |
3621a710 | 1466 | * lpfc_sli_submit_iocb - Submit an iocb to the firmware |
e59058c4 JS |
1467 | * @phba: Pointer to HBA context object. |
1468 | * @pring: Pointer to driver SLI ring object. | |
1469 | * @iocb: Pointer to iocb slot in the ring. | |
1470 | * @nextiocb: Pointer to driver iocb object which need to be | |
1471 | * posted to firmware. | |
1472 | * | |
1473 | * This function is called with hbalock held to post a new iocb to | |
1474 | * the firmware. This function copies the new iocb to ring iocb slot and | |
1475 | * updates the ring pointers. It adds the new iocb to txcmplq if there is | |
1476 | * a completion call back for this iocb else the function will free the | |
1477 | * iocb object. | |
1478 | **/ | |
dea3101e | 1479 | static void |
1480 | lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
1481 | IOCB_t *iocb, struct lpfc_iocbq *nextiocb) | |
1482 | { | |
1483 | /* | |
604a3e30 | 1484 | * Set up an iotag |
dea3101e | 1485 | */ |
604a3e30 | 1486 | nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0; |
dea3101e | 1487 | |
e2a0a9d6 | 1488 | |
a58cbd52 JS |
1489 | if (pring->ringno == LPFC_ELS_RING) { |
1490 | lpfc_debugfs_slow_ring_trc(phba, | |
1491 | "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x", | |
1492 | *(((uint32_t *) &nextiocb->iocb) + 4), | |
1493 | *(((uint32_t *) &nextiocb->iocb) + 6), | |
1494 | *(((uint32_t *) &nextiocb->iocb) + 7)); | |
1495 | } | |
1496 | ||
dea3101e | 1497 | /* |
1498 | * Issue iocb command to adapter | |
1499 | */ | |
92d7f7b0 | 1500 | lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size); |
dea3101e | 1501 | wmb(); |
1502 | pring->stats.iocb_cmd++; | |
1503 | ||
1504 | /* | |
1505 | * If there is no completion routine to call, we can release the | |
1506 | * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF, | |
1507 | * that have no rsp ring completion, iocb_cmpl MUST be NULL. | |
1508 | */ | |
1509 | if (nextiocb->iocb_cmpl) | |
1510 | lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb); | |
604a3e30 | 1511 | else |
2e0fef85 | 1512 | __lpfc_sli_release_iocbq(phba, nextiocb); |
dea3101e | 1513 | |
1514 | /* | |
1515 | * Let the HBA know what IOCB slot will be the next one the | |
1516 | * driver will put a command into. | |
1517 | */ | |
7e56aa25 JS |
1518 | pring->sli.sli3.cmdidx = pring->sli.sli3.next_cmdidx; |
1519 | writel(pring->sli.sli3.cmdidx, &phba->host_gp[pring->ringno].cmdPutInx); | |
dea3101e | 1520 | } |
1521 | ||
e59058c4 | 1522 | /** |
3621a710 | 1523 | * lpfc_sli_update_full_ring - Update the chip attention register |
e59058c4 JS |
1524 | * @phba: Pointer to HBA context object. |
1525 | * @pring: Pointer to driver SLI ring object. | |
1526 | * | |
1527 | * The caller is not required to hold any lock for calling this function. | |
1528 | * This function updates the chip attention bits for the ring to inform firmware | |
1529 | * that there are pending work to be done for this ring and requests an | |
1530 | * interrupt when there is space available in the ring. This function is | |
1531 | * called when the driver is unable to post more iocbs to the ring due | |
1532 | * to unavailability of space in the ring. | |
1533 | **/ | |
dea3101e | 1534 | static void |
2e0fef85 | 1535 | lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
dea3101e | 1536 | { |
1537 | int ringno = pring->ringno; | |
1538 | ||
1539 | pring->flag |= LPFC_CALL_RING_AVAILABLE; | |
1540 | ||
1541 | wmb(); | |
1542 | ||
1543 | /* | |
1544 | * Set ring 'ringno' to SET R0CE_REQ in Chip Att register. | |
1545 | * The HBA will tell us when an IOCB entry is available. | |
1546 | */ | |
1547 | writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr); | |
1548 | readl(phba->CAregaddr); /* flush */ | |
1549 | ||
1550 | pring->stats.iocb_cmd_full++; | |
1551 | } | |
1552 | ||
e59058c4 | 1553 | /** |
3621a710 | 1554 | * lpfc_sli_update_ring - Update chip attention register |
e59058c4 JS |
1555 | * @phba: Pointer to HBA context object. |
1556 | * @pring: Pointer to driver SLI ring object. | |
1557 | * | |
1558 | * This function updates the chip attention register bit for the | |
1559 | * given ring to inform HBA that there is more work to be done | |
1560 | * in this ring. The caller is not required to hold any lock. | |
1561 | **/ | |
dea3101e | 1562 | static void |
2e0fef85 | 1563 | lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
dea3101e | 1564 | { |
1565 | int ringno = pring->ringno; | |
1566 | ||
1567 | /* | |
1568 | * Tell the HBA that there is work to do in this ring. | |
1569 | */ | |
34b02dcd JS |
1570 | if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) { |
1571 | wmb(); | |
1572 | writel(CA_R0ATT << (ringno * 4), phba->CAregaddr); | |
1573 | readl(phba->CAregaddr); /* flush */ | |
1574 | } | |
dea3101e | 1575 | } |
1576 | ||
e59058c4 | 1577 | /** |
3621a710 | 1578 | * lpfc_sli_resume_iocb - Process iocbs in the txq |
e59058c4 JS |
1579 | * @phba: Pointer to HBA context object. |
1580 | * @pring: Pointer to driver SLI ring object. | |
1581 | * | |
1582 | * This function is called with hbalock held to post pending iocbs | |
1583 | * in the txq to the firmware. This function is called when driver | |
1584 | * detects space available in the ring. | |
1585 | **/ | |
dea3101e | 1586 | static void |
2e0fef85 | 1587 | lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
dea3101e | 1588 | { |
1589 | IOCB_t *iocb; | |
1590 | struct lpfc_iocbq *nextiocb; | |
1591 | ||
1592 | /* | |
1593 | * Check to see if: | |
1594 | * (a) there is anything on the txq to send | |
1595 | * (b) link is up | |
1596 | * (c) link attention events can be processed (fcp ring only) | |
1597 | * (d) IOCB processing is not blocked by the outstanding mbox command. | |
1598 | */ | |
1599 | if (pring->txq_cnt && | |
2e0fef85 | 1600 | lpfc_is_link_up(phba) && |
dea3101e | 1601 | (pring->ringno != phba->sli.fcp_ring || |
0b727fea | 1602 | phba->sli.sli_flag & LPFC_PROCESS_LA)) { |
dea3101e | 1603 | |
1604 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && | |
1605 | (nextiocb = lpfc_sli_ringtx_get(phba, pring))) | |
1606 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); | |
1607 | ||
1608 | if (iocb) | |
1609 | lpfc_sli_update_ring(phba, pring); | |
1610 | else | |
1611 | lpfc_sli_update_full_ring(phba, pring); | |
1612 | } | |
1613 | ||
1614 | return; | |
1615 | } | |
1616 | ||
e59058c4 | 1617 | /** |
3621a710 | 1618 | * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ |
e59058c4 JS |
1619 | * @phba: Pointer to HBA context object. |
1620 | * @hbqno: HBQ number. | |
1621 | * | |
1622 | * This function is called with hbalock held to get the next | |
1623 | * available slot for the given HBQ. If there is free slot | |
1624 | * available for the HBQ it will return pointer to the next available | |
1625 | * HBQ entry else it will return NULL. | |
1626 | **/ | |
a6ababd2 | 1627 | static struct lpfc_hbq_entry * |
ed957684 JS |
1628 | lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno) |
1629 | { | |
1630 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; | |
1631 | ||
1632 | if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx && | |
1633 | ++hbqp->next_hbqPutIdx >= hbqp->entry_count) | |
1634 | hbqp->next_hbqPutIdx = 0; | |
1635 | ||
1636 | if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) { | |
92d7f7b0 | 1637 | uint32_t raw_index = phba->hbq_get[hbqno]; |
ed957684 JS |
1638 | uint32_t getidx = le32_to_cpu(raw_index); |
1639 | ||
1640 | hbqp->local_hbqGetIdx = getidx; | |
1641 | ||
1642 | if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) { | |
1643 | lpfc_printf_log(phba, KERN_ERR, | |
92d7f7b0 | 1644 | LOG_SLI | LOG_VPORT, |
e8b62011 | 1645 | "1802 HBQ %d: local_hbqGetIdx " |
ed957684 | 1646 | "%u is > than hbqp->entry_count %u\n", |
e8b62011 | 1647 | hbqno, hbqp->local_hbqGetIdx, |
ed957684 JS |
1648 | hbqp->entry_count); |
1649 | ||
1650 | phba->link_state = LPFC_HBA_ERROR; | |
1651 | return NULL; | |
1652 | } | |
1653 | ||
1654 | if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx) | |
1655 | return NULL; | |
1656 | } | |
1657 | ||
51ef4c26 JS |
1658 | return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt + |
1659 | hbqp->hbqPutIdx; | |
ed957684 JS |
1660 | } |
1661 | ||
e59058c4 | 1662 | /** |
3621a710 | 1663 | * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers |
e59058c4 JS |
1664 | * @phba: Pointer to HBA context object. |
1665 | * | |
1666 | * This function is called with no lock held to free all the | |
1667 | * hbq buffers while uninitializing the SLI interface. It also | |
1668 | * frees the HBQ buffers returned by the firmware but not yet | |
1669 | * processed by the upper layers. | |
1670 | **/ | |
ed957684 JS |
1671 | void |
1672 | lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba) | |
1673 | { | |
92d7f7b0 JS |
1674 | struct lpfc_dmabuf *dmabuf, *next_dmabuf; |
1675 | struct hbq_dmabuf *hbq_buf; | |
3163f725 | 1676 | unsigned long flags; |
51ef4c26 | 1677 | int i, hbq_count; |
3163f725 | 1678 | uint32_t hbqno; |
ed957684 | 1679 | |
51ef4c26 | 1680 | hbq_count = lpfc_sli_hbq_count(); |
ed957684 | 1681 | /* Return all memory used by all HBQs */ |
3163f725 | 1682 | spin_lock_irqsave(&phba->hbalock, flags); |
51ef4c26 JS |
1683 | for (i = 0; i < hbq_count; ++i) { |
1684 | list_for_each_entry_safe(dmabuf, next_dmabuf, | |
1685 | &phba->hbqs[i].hbq_buffer_list, list) { | |
1686 | hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf); | |
1687 | list_del(&hbq_buf->dbuf.list); | |
1688 | (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf); | |
1689 | } | |
a8adb832 | 1690 | phba->hbqs[i].buffer_count = 0; |
ed957684 | 1691 | } |
3163f725 | 1692 | /* Return all HBQ buffer that are in-fly */ |
3772a991 JS |
1693 | list_for_each_entry_safe(dmabuf, next_dmabuf, &phba->rb_pend_list, |
1694 | list) { | |
3163f725 JS |
1695 | hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf); |
1696 | list_del(&hbq_buf->dbuf.list); | |
1697 | if (hbq_buf->tag == -1) { | |
1698 | (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer) | |
1699 | (phba, hbq_buf); | |
1700 | } else { | |
1701 | hbqno = hbq_buf->tag >> 16; | |
1702 | if (hbqno >= LPFC_MAX_HBQS) | |
1703 | (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer) | |
1704 | (phba, hbq_buf); | |
1705 | else | |
1706 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, | |
1707 | hbq_buf); | |
1708 | } | |
1709 | } | |
1710 | ||
1711 | /* Mark the HBQs not in use */ | |
1712 | phba->hbq_in_use = 0; | |
1713 | spin_unlock_irqrestore(&phba->hbalock, flags); | |
ed957684 JS |
1714 | } |
1715 | ||
e59058c4 | 1716 | /** |
3621a710 | 1717 | * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware |
e59058c4 JS |
1718 | * @phba: Pointer to HBA context object. |
1719 | * @hbqno: HBQ number. | |
1720 | * @hbq_buf: Pointer to HBQ buffer. | |
1721 | * | |
1722 | * This function is called with the hbalock held to post a | |
1723 | * hbq buffer to the firmware. If the function finds an empty | |
1724 | * slot in the HBQ, it will post the buffer. The function will return | |
1725 | * pointer to the hbq entry if it successfully post the buffer | |
1726 | * else it will return NULL. | |
1727 | **/ | |
3772a991 | 1728 | static int |
ed957684 | 1729 | lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno, |
92d7f7b0 | 1730 | struct hbq_dmabuf *hbq_buf) |
3772a991 JS |
1731 | { |
1732 | return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf); | |
1733 | } | |
1734 | ||
1735 | /** | |
1736 | * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware | |
1737 | * @phba: Pointer to HBA context object. | |
1738 | * @hbqno: HBQ number. | |
1739 | * @hbq_buf: Pointer to HBQ buffer. | |
1740 | * | |
1741 | * This function is called with the hbalock held to post a hbq buffer to the | |
1742 | * firmware. If the function finds an empty slot in the HBQ, it will post the | |
1743 | * buffer and place it on the hbq_buffer_list. The function will return zero if | |
1744 | * it successfully post the buffer else it will return an error. | |
1745 | **/ | |
1746 | static int | |
1747 | lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno, | |
1748 | struct hbq_dmabuf *hbq_buf) | |
ed957684 JS |
1749 | { |
1750 | struct lpfc_hbq_entry *hbqe; | |
92d7f7b0 | 1751 | dma_addr_t physaddr = hbq_buf->dbuf.phys; |
ed957684 JS |
1752 | |
1753 | /* Get next HBQ entry slot to use */ | |
1754 | hbqe = lpfc_sli_next_hbq_slot(phba, hbqno); | |
1755 | if (hbqe) { | |
1756 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; | |
1757 | ||
92d7f7b0 JS |
1758 | hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr)); |
1759 | hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr)); | |
51ef4c26 | 1760 | hbqe->bde.tus.f.bdeSize = hbq_buf->size; |
ed957684 | 1761 | hbqe->bde.tus.f.bdeFlags = 0; |
92d7f7b0 JS |
1762 | hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w); |
1763 | hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag); | |
1764 | /* Sync SLIM */ | |
ed957684 JS |
1765 | hbqp->hbqPutIdx = hbqp->next_hbqPutIdx; |
1766 | writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno); | |
92d7f7b0 | 1767 | /* flush */ |
ed957684 | 1768 | readl(phba->hbq_put + hbqno); |
51ef4c26 | 1769 | list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list); |
3772a991 JS |
1770 | return 0; |
1771 | } else | |
1772 | return -ENOMEM; | |
ed957684 JS |
1773 | } |
1774 | ||
4f774513 JS |
1775 | /** |
1776 | * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware | |
1777 | * @phba: Pointer to HBA context object. | |
1778 | * @hbqno: HBQ number. | |
1779 | * @hbq_buf: Pointer to HBQ buffer. | |
1780 | * | |
1781 | * This function is called with the hbalock held to post an RQE to the SLI4 | |
1782 | * firmware. If able to post the RQE to the RQ it will queue the hbq entry to | |
1783 | * the hbq_buffer_list and return zero, otherwise it will return an error. | |
1784 | **/ | |
1785 | static int | |
1786 | lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno, | |
1787 | struct hbq_dmabuf *hbq_buf) | |
1788 | { | |
1789 | int rc; | |
1790 | struct lpfc_rqe hrqe; | |
1791 | struct lpfc_rqe drqe; | |
1792 | ||
1793 | hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys); | |
1794 | hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys); | |
1795 | drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys); | |
1796 | drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys); | |
1797 | rc = lpfc_sli4_rq_put(phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq, | |
1798 | &hrqe, &drqe); | |
1799 | if (rc < 0) | |
1800 | return rc; | |
1801 | hbq_buf->tag = rc; | |
1802 | list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list); | |
1803 | return 0; | |
1804 | } | |
1805 | ||
e59058c4 | 1806 | /* HBQ for ELS and CT traffic. */ |
92d7f7b0 JS |
1807 | static struct lpfc_hbq_init lpfc_els_hbq = { |
1808 | .rn = 1, | |
def9c7a9 | 1809 | .entry_count = 256, |
92d7f7b0 JS |
1810 | .mask_count = 0, |
1811 | .profile = 0, | |
51ef4c26 | 1812 | .ring_mask = (1 << LPFC_ELS_RING), |
92d7f7b0 | 1813 | .buffer_count = 0, |
a257bf90 JS |
1814 | .init_count = 40, |
1815 | .add_count = 40, | |
92d7f7b0 | 1816 | }; |
ed957684 | 1817 | |
e59058c4 | 1818 | /* HBQ for the extra ring if needed */ |
51ef4c26 JS |
1819 | static struct lpfc_hbq_init lpfc_extra_hbq = { |
1820 | .rn = 1, | |
1821 | .entry_count = 200, | |
1822 | .mask_count = 0, | |
1823 | .profile = 0, | |
1824 | .ring_mask = (1 << LPFC_EXTRA_RING), | |
1825 | .buffer_count = 0, | |
1826 | .init_count = 0, | |
1827 | .add_count = 5, | |
1828 | }; | |
1829 | ||
e59058c4 | 1830 | /* Array of HBQs */ |
78b2d852 | 1831 | struct lpfc_hbq_init *lpfc_hbq_defs[] = { |
92d7f7b0 | 1832 | &lpfc_els_hbq, |
51ef4c26 | 1833 | &lpfc_extra_hbq, |
92d7f7b0 | 1834 | }; |
ed957684 | 1835 | |
e59058c4 | 1836 | /** |
3621a710 | 1837 | * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ |
e59058c4 JS |
1838 | * @phba: Pointer to HBA context object. |
1839 | * @hbqno: HBQ number. | |
1840 | * @count: Number of HBQ buffers to be posted. | |
1841 | * | |
d7c255b2 JS |
1842 | * This function is called with no lock held to post more hbq buffers to the |
1843 | * given HBQ. The function returns the number of HBQ buffers successfully | |
1844 | * posted. | |
e59058c4 | 1845 | **/ |
311464ec | 1846 | static int |
92d7f7b0 | 1847 | lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count) |
ed957684 | 1848 | { |
d7c255b2 | 1849 | uint32_t i, posted = 0; |
3163f725 | 1850 | unsigned long flags; |
92d7f7b0 | 1851 | struct hbq_dmabuf *hbq_buffer; |
d7c255b2 | 1852 | LIST_HEAD(hbq_buf_list); |
eafe1df9 | 1853 | if (!phba->hbqs[hbqno].hbq_alloc_buffer) |
51ef4c26 | 1854 | return 0; |
51ef4c26 | 1855 | |
d7c255b2 JS |
1856 | if ((phba->hbqs[hbqno].buffer_count + count) > |
1857 | lpfc_hbq_defs[hbqno]->entry_count) | |
1858 | count = lpfc_hbq_defs[hbqno]->entry_count - | |
1859 | phba->hbqs[hbqno].buffer_count; | |
1860 | if (!count) | |
1861 | return 0; | |
1862 | /* Allocate HBQ entries */ | |
1863 | for (i = 0; i < count; i++) { | |
1864 | hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba); | |
1865 | if (!hbq_buffer) | |
1866 | break; | |
1867 | list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list); | |
1868 | } | |
3163f725 JS |
1869 | /* Check whether HBQ is still in use */ |
1870 | spin_lock_irqsave(&phba->hbalock, flags); | |
eafe1df9 | 1871 | if (!phba->hbq_in_use) |
d7c255b2 JS |
1872 | goto err; |
1873 | while (!list_empty(&hbq_buf_list)) { | |
1874 | list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf, | |
1875 | dbuf.list); | |
1876 | hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count | | |
1877 | (hbqno << 16)); | |
3772a991 | 1878 | if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) { |
a8adb832 | 1879 | phba->hbqs[hbqno].buffer_count++; |
d7c255b2 JS |
1880 | posted++; |
1881 | } else | |
51ef4c26 | 1882 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
ed957684 | 1883 | } |
3163f725 | 1884 | spin_unlock_irqrestore(&phba->hbalock, flags); |
d7c255b2 JS |
1885 | return posted; |
1886 | err: | |
eafe1df9 | 1887 | spin_unlock_irqrestore(&phba->hbalock, flags); |
d7c255b2 JS |
1888 | while (!list_empty(&hbq_buf_list)) { |
1889 | list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf, | |
1890 | dbuf.list); | |
1891 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); | |
1892 | } | |
1893 | return 0; | |
ed957684 JS |
1894 | } |
1895 | ||
e59058c4 | 1896 | /** |
3621a710 | 1897 | * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware |
e59058c4 JS |
1898 | * @phba: Pointer to HBA context object. |
1899 | * @qno: HBQ number. | |
1900 | * | |
1901 | * This function posts more buffers to the HBQ. This function | |
d7c255b2 JS |
1902 | * is called with no lock held. The function returns the number of HBQ entries |
1903 | * successfully allocated. | |
e59058c4 | 1904 | **/ |
92d7f7b0 JS |
1905 | int |
1906 | lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno) | |
ed957684 | 1907 | { |
def9c7a9 JS |
1908 | if (phba->sli_rev == LPFC_SLI_REV4) |
1909 | return 0; | |
1910 | else | |
1911 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, | |
1912 | lpfc_hbq_defs[qno]->add_count); | |
92d7f7b0 | 1913 | } |
ed957684 | 1914 | |
e59058c4 | 1915 | /** |
3621a710 | 1916 | * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ |
e59058c4 JS |
1917 | * @phba: Pointer to HBA context object. |
1918 | * @qno: HBQ queue number. | |
1919 | * | |
1920 | * This function is called from SLI initialization code path with | |
1921 | * no lock held to post initial HBQ buffers to firmware. The | |
d7c255b2 | 1922 | * function returns the number of HBQ entries successfully allocated. |
e59058c4 | 1923 | **/ |
a6ababd2 | 1924 | static int |
92d7f7b0 JS |
1925 | lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno) |
1926 | { | |
def9c7a9 JS |
1927 | if (phba->sli_rev == LPFC_SLI_REV4) |
1928 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, | |
73d91e50 | 1929 | lpfc_hbq_defs[qno]->entry_count); |
def9c7a9 JS |
1930 | else |
1931 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, | |
1932 | lpfc_hbq_defs[qno]->init_count); | |
ed957684 JS |
1933 | } |
1934 | ||
3772a991 JS |
1935 | /** |
1936 | * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list | |
1937 | * @phba: Pointer to HBA context object. | |
1938 | * @hbqno: HBQ number. | |
1939 | * | |
1940 | * This function removes the first hbq buffer on an hbq list and returns a | |
1941 | * pointer to that buffer. If it finds no buffers on the list it returns NULL. | |
1942 | **/ | |
1943 | static struct hbq_dmabuf * | |
1944 | lpfc_sli_hbqbuf_get(struct list_head *rb_list) | |
1945 | { | |
1946 | struct lpfc_dmabuf *d_buf; | |
1947 | ||
1948 | list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list); | |
1949 | if (!d_buf) | |
1950 | return NULL; | |
1951 | return container_of(d_buf, struct hbq_dmabuf, dbuf); | |
1952 | } | |
1953 | ||
e59058c4 | 1954 | /** |
3621a710 | 1955 | * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag |
e59058c4 JS |
1956 | * @phba: Pointer to HBA context object. |
1957 | * @tag: Tag of the hbq buffer. | |
1958 | * | |
1959 | * This function is called with hbalock held. This function searches | |
1960 | * for the hbq buffer associated with the given tag in the hbq buffer | |
1961 | * list. If it finds the hbq buffer, it returns the hbq_buffer other wise | |
1962 | * it returns NULL. | |
1963 | **/ | |
a6ababd2 | 1964 | static struct hbq_dmabuf * |
92d7f7b0 | 1965 | lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag) |
ed957684 | 1966 | { |
92d7f7b0 JS |
1967 | struct lpfc_dmabuf *d_buf; |
1968 | struct hbq_dmabuf *hbq_buf; | |
51ef4c26 JS |
1969 | uint32_t hbqno; |
1970 | ||
1971 | hbqno = tag >> 16; | |
a0a74e45 | 1972 | if (hbqno >= LPFC_MAX_HBQS) |
51ef4c26 | 1973 | return NULL; |
ed957684 | 1974 | |
3772a991 | 1975 | spin_lock_irq(&phba->hbalock); |
51ef4c26 | 1976 | list_for_each_entry(d_buf, &phba->hbqs[hbqno].hbq_buffer_list, list) { |
92d7f7b0 | 1977 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
51ef4c26 | 1978 | if (hbq_buf->tag == tag) { |
3772a991 | 1979 | spin_unlock_irq(&phba->hbalock); |
92d7f7b0 | 1980 | return hbq_buf; |
ed957684 JS |
1981 | } |
1982 | } | |
3772a991 | 1983 | spin_unlock_irq(&phba->hbalock); |
92d7f7b0 | 1984 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT, |
e8b62011 | 1985 | "1803 Bad hbq tag. Data: x%x x%x\n", |
a8adb832 | 1986 | tag, phba->hbqs[tag >> 16].buffer_count); |
92d7f7b0 | 1987 | return NULL; |
ed957684 JS |
1988 | } |
1989 | ||
e59058c4 | 1990 | /** |
3621a710 | 1991 | * lpfc_sli_free_hbq - Give back the hbq buffer to firmware |
e59058c4 JS |
1992 | * @phba: Pointer to HBA context object. |
1993 | * @hbq_buffer: Pointer to HBQ buffer. | |
1994 | * | |
1995 | * This function is called with hbalock. This function gives back | |
1996 | * the hbq buffer to firmware. If the HBQ does not have space to | |
1997 | * post the buffer, it will free the buffer. | |
1998 | **/ | |
ed957684 | 1999 | void |
51ef4c26 | 2000 | lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer) |
ed957684 JS |
2001 | { |
2002 | uint32_t hbqno; | |
2003 | ||
51ef4c26 JS |
2004 | if (hbq_buffer) { |
2005 | hbqno = hbq_buffer->tag >> 16; | |
3772a991 | 2006 | if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) |
51ef4c26 | 2007 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
ed957684 JS |
2008 | } |
2009 | } | |
2010 | ||
e59058c4 | 2011 | /** |
3621a710 | 2012 | * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox |
e59058c4 JS |
2013 | * @mbxCommand: mailbox command code. |
2014 | * | |
2015 | * This function is called by the mailbox event handler function to verify | |
2016 | * that the completed mailbox command is a legitimate mailbox command. If the | |
2017 | * completed mailbox is not known to the function, it will return MBX_SHUTDOWN | |
2018 | * and the mailbox event handler will take the HBA offline. | |
2019 | **/ | |
dea3101e | 2020 | static int |
2021 | lpfc_sli_chk_mbx_command(uint8_t mbxCommand) | |
2022 | { | |
2023 | uint8_t ret; | |
2024 | ||
2025 | switch (mbxCommand) { | |
2026 | case MBX_LOAD_SM: | |
2027 | case MBX_READ_NV: | |
2028 | case MBX_WRITE_NV: | |
a8adb832 | 2029 | case MBX_WRITE_VPARMS: |
dea3101e | 2030 | case MBX_RUN_BIU_DIAG: |
2031 | case MBX_INIT_LINK: | |
2032 | case MBX_DOWN_LINK: | |
2033 | case MBX_CONFIG_LINK: | |
2034 | case MBX_CONFIG_RING: | |
2035 | case MBX_RESET_RING: | |
2036 | case MBX_READ_CONFIG: | |
2037 | case MBX_READ_RCONFIG: | |
2038 | case MBX_READ_SPARM: | |
2039 | case MBX_READ_STATUS: | |
2040 | case MBX_READ_RPI: | |
2041 | case MBX_READ_XRI: | |
2042 | case MBX_READ_REV: | |
2043 | case MBX_READ_LNK_STAT: | |
2044 | case MBX_REG_LOGIN: | |
2045 | case MBX_UNREG_LOGIN: | |
dea3101e | 2046 | case MBX_CLEAR_LA: |
2047 | case MBX_DUMP_MEMORY: | |
2048 | case MBX_DUMP_CONTEXT: | |
2049 | case MBX_RUN_DIAGS: | |
2050 | case MBX_RESTART: | |
2051 | case MBX_UPDATE_CFG: | |
2052 | case MBX_DOWN_LOAD: | |
2053 | case MBX_DEL_LD_ENTRY: | |
2054 | case MBX_RUN_PROGRAM: | |
2055 | case MBX_SET_MASK: | |
09372820 | 2056 | case MBX_SET_VARIABLE: |
dea3101e | 2057 | case MBX_UNREG_D_ID: |
41415862 | 2058 | case MBX_KILL_BOARD: |
dea3101e | 2059 | case MBX_CONFIG_FARP: |
41415862 | 2060 | case MBX_BEACON: |
dea3101e | 2061 | case MBX_LOAD_AREA: |
2062 | case MBX_RUN_BIU_DIAG64: | |
2063 | case MBX_CONFIG_PORT: | |
2064 | case MBX_READ_SPARM64: | |
2065 | case MBX_READ_RPI64: | |
2066 | case MBX_REG_LOGIN64: | |
76a95d75 | 2067 | case MBX_READ_TOPOLOGY: |
09372820 | 2068 | case MBX_WRITE_WWN: |
dea3101e | 2069 | case MBX_SET_DEBUG: |
2070 | case MBX_LOAD_EXP_ROM: | |
57127f15 | 2071 | case MBX_ASYNCEVT_ENABLE: |
92d7f7b0 JS |
2072 | case MBX_REG_VPI: |
2073 | case MBX_UNREG_VPI: | |
858c9f6c | 2074 | case MBX_HEARTBEAT: |
84774a4d JS |
2075 | case MBX_PORT_CAPABILITIES: |
2076 | case MBX_PORT_IOV_CONTROL: | |
04c68496 JS |
2077 | case MBX_SLI4_CONFIG: |
2078 | case MBX_SLI4_REQ_FTRS: | |
2079 | case MBX_REG_FCFI: | |
2080 | case MBX_UNREG_FCFI: | |
2081 | case MBX_REG_VFI: | |
2082 | case MBX_UNREG_VFI: | |
2083 | case MBX_INIT_VPI: | |
2084 | case MBX_INIT_VFI: | |
2085 | case MBX_RESUME_RPI: | |
c7495937 JS |
2086 | case MBX_READ_EVENT_LOG_STATUS: |
2087 | case MBX_READ_EVENT_LOG: | |
dcf2a4e0 JS |
2088 | case MBX_SECURITY_MGMT: |
2089 | case MBX_AUTH_PORT: | |
940eb687 | 2090 | case MBX_ACCESS_VDATA: |
dea3101e | 2091 | ret = mbxCommand; |
2092 | break; | |
2093 | default: | |
2094 | ret = MBX_SHUTDOWN; | |
2095 | break; | |
2096 | } | |
2e0fef85 | 2097 | return ret; |
dea3101e | 2098 | } |
e59058c4 JS |
2099 | |
2100 | /** | |
3621a710 | 2101 | * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler |
e59058c4 JS |
2102 | * @phba: Pointer to HBA context object. |
2103 | * @pmboxq: Pointer to mailbox command. | |
2104 | * | |
2105 | * This is completion handler function for mailbox commands issued from | |
2106 | * lpfc_sli_issue_mbox_wait function. This function is called by the | |
2107 | * mailbox event handler function with no lock held. This function | |
2108 | * will wake up thread waiting on the wait queue pointed by context1 | |
2109 | * of the mailbox. | |
2110 | **/ | |
04c68496 | 2111 | void |
2e0fef85 | 2112 | lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) |
dea3101e | 2113 | { |
2114 | wait_queue_head_t *pdone_q; | |
858c9f6c | 2115 | unsigned long drvr_flag; |
dea3101e | 2116 | |
2117 | /* | |
2118 | * If pdone_q is empty, the driver thread gave up waiting and | |
2119 | * continued running. | |
2120 | */ | |
7054a606 | 2121 | pmboxq->mbox_flag |= LPFC_MBX_WAKE; |
858c9f6c | 2122 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
dea3101e | 2123 | pdone_q = (wait_queue_head_t *) pmboxq->context1; |
2124 | if (pdone_q) | |
2125 | wake_up_interruptible(pdone_q); | |
858c9f6c | 2126 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
dea3101e | 2127 | return; |
2128 | } | |
2129 | ||
e59058c4 JS |
2130 | |
2131 | /** | |
3621a710 | 2132 | * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler |
e59058c4 JS |
2133 | * @phba: Pointer to HBA context object. |
2134 | * @pmb: Pointer to mailbox object. | |
2135 | * | |
2136 | * This function is the default mailbox completion handler. It | |
2137 | * frees the memory resources associated with the completed mailbox | |
2138 | * command. If the completed command is a REG_LOGIN mailbox command, | |
2139 | * this function will issue a UREG_LOGIN to re-claim the RPI. | |
2140 | **/ | |
dea3101e | 2141 | void |
2e0fef85 | 2142 | lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
dea3101e | 2143 | { |
d439d286 | 2144 | struct lpfc_vport *vport = pmb->vport; |
dea3101e | 2145 | struct lpfc_dmabuf *mp; |
d439d286 | 2146 | struct lpfc_nodelist *ndlp; |
5af5eee7 | 2147 | struct Scsi_Host *shost; |
04c68496 | 2148 | uint16_t rpi, vpi; |
7054a606 JS |
2149 | int rc; |
2150 | ||
dea3101e | 2151 | mp = (struct lpfc_dmabuf *) (pmb->context1); |
7054a606 | 2152 | |
dea3101e | 2153 | if (mp) { |
2154 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
2155 | kfree(mp); | |
2156 | } | |
7054a606 JS |
2157 | |
2158 | /* | |
2159 | * If a REG_LOGIN succeeded after node is destroyed or node | |
2160 | * is in re-discovery driver need to cleanup the RPI. | |
2161 | */ | |
2e0fef85 | 2162 | if (!(phba->pport->load_flag & FC_UNLOADING) && |
04c68496 JS |
2163 | pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 && |
2164 | !pmb->u.mb.mbxStatus) { | |
2165 | rpi = pmb->u.mb.un.varWords[0]; | |
6d368e53 | 2166 | vpi = pmb->u.mb.un.varRegLogin.vpi; |
04c68496 | 2167 | lpfc_unreg_login(phba, vpi, rpi, pmb); |
92d7f7b0 | 2168 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
7054a606 JS |
2169 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
2170 | if (rc != MBX_NOT_FINISHED) | |
2171 | return; | |
2172 | } | |
2173 | ||
695a814e JS |
2174 | if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) && |
2175 | !(phba->pport->load_flag & FC_UNLOADING) && | |
2176 | !pmb->u.mb.mbxStatus) { | |
5af5eee7 JS |
2177 | shost = lpfc_shost_from_vport(vport); |
2178 | spin_lock_irq(shost->host_lock); | |
2179 | vport->vpi_state |= LPFC_VPI_REGISTERED; | |
2180 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; | |
2181 | spin_unlock_irq(shost->host_lock); | |
695a814e JS |
2182 | } |
2183 | ||
d439d286 JS |
2184 | if (pmb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
2185 | ndlp = (struct lpfc_nodelist *)pmb->context2; | |
2186 | lpfc_nlp_put(ndlp); | |
2187 | pmb->context2 = NULL; | |
2188 | } | |
2189 | ||
dcf2a4e0 JS |
2190 | /* Check security permission status on INIT_LINK mailbox command */ |
2191 | if ((pmb->u.mb.mbxCommand == MBX_INIT_LINK) && | |
2192 | (pmb->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION)) | |
2193 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
2194 | "2860 SLI authentication is required " | |
2195 | "for INIT_LINK but has not done yet\n"); | |
2196 | ||
04c68496 JS |
2197 | if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG) |
2198 | lpfc_sli4_mbox_cmd_free(phba, pmb); | |
2199 | else | |
2200 | mempool_free(pmb, phba->mbox_mem_pool); | |
dea3101e | 2201 | } |
2202 | ||
e59058c4 | 2203 | /** |
3621a710 | 2204 | * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware |
e59058c4 JS |
2205 | * @phba: Pointer to HBA context object. |
2206 | * | |
2207 | * This function is called with no lock held. This function processes all | |
2208 | * the completed mailbox commands and gives it to upper layers. The interrupt | |
2209 | * service routine processes mailbox completion interrupt and adds completed | |
2210 | * mailbox commands to the mboxq_cmpl queue and signals the worker thread. | |
2211 | * Worker thread call lpfc_sli_handle_mb_event, which will return the | |
2212 | * completed mailbox commands in mboxq_cmpl queue to the upper layers. This | |
2213 | * function returns the mailbox commands to the upper layer by calling the | |
2214 | * completion handler function of each mailbox. | |
2215 | **/ | |
dea3101e | 2216 | int |
2e0fef85 | 2217 | lpfc_sli_handle_mb_event(struct lpfc_hba *phba) |
dea3101e | 2218 | { |
92d7f7b0 | 2219 | MAILBOX_t *pmbox; |
dea3101e | 2220 | LPFC_MBOXQ_t *pmb; |
92d7f7b0 JS |
2221 | int rc; |
2222 | LIST_HEAD(cmplq); | |
dea3101e | 2223 | |
2224 | phba->sli.slistat.mbox_event++; | |
2225 | ||
92d7f7b0 JS |
2226 | /* Get all completed mailboxe buffers into the cmplq */ |
2227 | spin_lock_irq(&phba->hbalock); | |
2228 | list_splice_init(&phba->sli.mboxq_cmpl, &cmplq); | |
2229 | spin_unlock_irq(&phba->hbalock); | |
dea3101e | 2230 | |
92d7f7b0 JS |
2231 | /* Get a Mailbox buffer to setup mailbox commands for callback */ |
2232 | do { | |
2233 | list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list); | |
2234 | if (pmb == NULL) | |
2235 | break; | |
2e0fef85 | 2236 | |
04c68496 | 2237 | pmbox = &pmb->u.mb; |
dea3101e | 2238 | |
858c9f6c JS |
2239 | if (pmbox->mbxCommand != MBX_HEARTBEAT) { |
2240 | if (pmb->vport) { | |
2241 | lpfc_debugfs_disc_trc(pmb->vport, | |
2242 | LPFC_DISC_TRC_MBOX_VPORT, | |
2243 | "MBOX cmpl vport: cmd:x%x mb:x%x x%x", | |
2244 | (uint32_t)pmbox->mbxCommand, | |
2245 | pmbox->un.varWords[0], | |
2246 | pmbox->un.varWords[1]); | |
2247 | } | |
2248 | else { | |
2249 | lpfc_debugfs_disc_trc(phba->pport, | |
2250 | LPFC_DISC_TRC_MBOX, | |
2251 | "MBOX cmpl: cmd:x%x mb:x%x x%x", | |
2252 | (uint32_t)pmbox->mbxCommand, | |
2253 | pmbox->un.varWords[0], | |
2254 | pmbox->un.varWords[1]); | |
2255 | } | |
2256 | } | |
2257 | ||
dea3101e | 2258 | /* |
2259 | * It is a fatal error if unknown mbox command completion. | |
2260 | */ | |
2261 | if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) == | |
2262 | MBX_SHUTDOWN) { | |
af901ca1 | 2263 | /* Unknown mailbox command compl */ |
92d7f7b0 | 2264 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
e8b62011 | 2265 | "(%d):0323 Unknown Mailbox command " |
a183a15f | 2266 | "x%x (x%x/x%x) Cmpl\n", |
92d7f7b0 | 2267 | pmb->vport ? pmb->vport->vpi : 0, |
04c68496 | 2268 | pmbox->mbxCommand, |
a183a15f JS |
2269 | lpfc_sli_config_mbox_subsys_get(phba, |
2270 | pmb), | |
2271 | lpfc_sli_config_mbox_opcode_get(phba, | |
2272 | pmb)); | |
2e0fef85 | 2273 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e | 2274 | phba->work_hs = HS_FFER3; |
2275 | lpfc_handle_eratt(phba); | |
92d7f7b0 | 2276 | continue; |
dea3101e | 2277 | } |
2278 | ||
dea3101e | 2279 | if (pmbox->mbxStatus) { |
2280 | phba->sli.slistat.mbox_stat_err++; | |
2281 | if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) { | |
2282 | /* Mbox cmd cmpl error - RETRYing */ | |
92d7f7b0 | 2283 | lpfc_printf_log(phba, KERN_INFO, |
a183a15f JS |
2284 | LOG_MBOX | LOG_SLI, |
2285 | "(%d):0305 Mbox cmd cmpl " | |
2286 | "error - RETRYing Data: x%x " | |
2287 | "(x%x/x%x) x%x x%x x%x\n", | |
2288 | pmb->vport ? pmb->vport->vpi : 0, | |
2289 | pmbox->mbxCommand, | |
2290 | lpfc_sli_config_mbox_subsys_get(phba, | |
2291 | pmb), | |
2292 | lpfc_sli_config_mbox_opcode_get(phba, | |
2293 | pmb), | |
2294 | pmbox->mbxStatus, | |
2295 | pmbox->un.varWords[0], | |
2296 | pmb->vport->port_state); | |
dea3101e | 2297 | pmbox->mbxStatus = 0; |
2298 | pmbox->mbxOwner = OWN_HOST; | |
dea3101e | 2299 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
04c68496 | 2300 | if (rc != MBX_NOT_FINISHED) |
92d7f7b0 | 2301 | continue; |
dea3101e | 2302 | } |
2303 | } | |
2304 | ||
2305 | /* Mailbox cmd <cmd> Cmpl <cmpl> */ | |
92d7f7b0 | 2306 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
a183a15f | 2307 | "(%d):0307 Mailbox cmd x%x (x%x/x%x) Cmpl x%p " |
dea3101e | 2308 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n", |
92d7f7b0 | 2309 | pmb->vport ? pmb->vport->vpi : 0, |
dea3101e | 2310 | pmbox->mbxCommand, |
a183a15f JS |
2311 | lpfc_sli_config_mbox_subsys_get(phba, pmb), |
2312 | lpfc_sli_config_mbox_opcode_get(phba, pmb), | |
dea3101e | 2313 | pmb->mbox_cmpl, |
2314 | *((uint32_t *) pmbox), | |
2315 | pmbox->un.varWords[0], | |
2316 | pmbox->un.varWords[1], | |
2317 | pmbox->un.varWords[2], | |
2318 | pmbox->un.varWords[3], | |
2319 | pmbox->un.varWords[4], | |
2320 | pmbox->un.varWords[5], | |
2321 | pmbox->un.varWords[6], | |
2322 | pmbox->un.varWords[7]); | |
2323 | ||
92d7f7b0 | 2324 | if (pmb->mbox_cmpl) |
dea3101e | 2325 | pmb->mbox_cmpl(phba,pmb); |
92d7f7b0 JS |
2326 | } while (1); |
2327 | return 0; | |
2328 | } | |
dea3101e | 2329 | |
e59058c4 | 2330 | /** |
3621a710 | 2331 | * lpfc_sli_get_buff - Get the buffer associated with the buffer tag |
e59058c4 JS |
2332 | * @phba: Pointer to HBA context object. |
2333 | * @pring: Pointer to driver SLI ring object. | |
2334 | * @tag: buffer tag. | |
2335 | * | |
2336 | * This function is called with no lock held. When QUE_BUFTAG_BIT bit | |
2337 | * is set in the tag the buffer is posted for a particular exchange, | |
2338 | * the function will return the buffer without replacing the buffer. | |
2339 | * If the buffer is for unsolicited ELS or CT traffic, this function | |
2340 | * returns the buffer and also posts another buffer to the firmware. | |
2341 | **/ | |
76bb24ef JS |
2342 | static struct lpfc_dmabuf * |
2343 | lpfc_sli_get_buff(struct lpfc_hba *phba, | |
9f1e1b50 JS |
2344 | struct lpfc_sli_ring *pring, |
2345 | uint32_t tag) | |
76bb24ef | 2346 | { |
9f1e1b50 JS |
2347 | struct hbq_dmabuf *hbq_entry; |
2348 | ||
76bb24ef JS |
2349 | if (tag & QUE_BUFTAG_BIT) |
2350 | return lpfc_sli_ring_taggedbuf_get(phba, pring, tag); | |
9f1e1b50 JS |
2351 | hbq_entry = lpfc_sli_hbqbuf_find(phba, tag); |
2352 | if (!hbq_entry) | |
2353 | return NULL; | |
2354 | return &hbq_entry->dbuf; | |
76bb24ef | 2355 | } |
57127f15 | 2356 | |
3772a991 JS |
2357 | /** |
2358 | * lpfc_complete_unsol_iocb - Complete an unsolicited sequence | |
2359 | * @phba: Pointer to HBA context object. | |
2360 | * @pring: Pointer to driver SLI ring object. | |
2361 | * @saveq: Pointer to the iocbq struct representing the sequence starting frame. | |
2362 | * @fch_r_ctl: the r_ctl for the first frame of the sequence. | |
2363 | * @fch_type: the type for the first frame of the sequence. | |
2364 | * | |
2365 | * This function is called with no lock held. This function uses the r_ctl and | |
2366 | * type of the received sequence to find the correct callback function to call | |
2367 | * to process the sequence. | |
2368 | **/ | |
2369 | static int | |
2370 | lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
2371 | struct lpfc_iocbq *saveq, uint32_t fch_r_ctl, | |
2372 | uint32_t fch_type) | |
2373 | { | |
2374 | int i; | |
2375 | ||
2376 | /* unSolicited Responses */ | |
2377 | if (pring->prt[0].profile) { | |
2378 | if (pring->prt[0].lpfc_sli_rcv_unsol_event) | |
2379 | (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring, | |
2380 | saveq); | |
2381 | return 1; | |
2382 | } | |
2383 | /* We must search, based on rctl / type | |
2384 | for the right routine */ | |
2385 | for (i = 0; i < pring->num_mask; i++) { | |
2386 | if ((pring->prt[i].rctl == fch_r_ctl) && | |
2387 | (pring->prt[i].type == fch_type)) { | |
2388 | if (pring->prt[i].lpfc_sli_rcv_unsol_event) | |
2389 | (pring->prt[i].lpfc_sli_rcv_unsol_event) | |
2390 | (phba, pring, saveq); | |
2391 | return 1; | |
2392 | } | |
2393 | } | |
2394 | return 0; | |
2395 | } | |
e59058c4 JS |
2396 | |
2397 | /** | |
3621a710 | 2398 | * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler |
e59058c4 JS |
2399 | * @phba: Pointer to HBA context object. |
2400 | * @pring: Pointer to driver SLI ring object. | |
2401 | * @saveq: Pointer to the unsolicited iocb. | |
2402 | * | |
2403 | * This function is called with no lock held by the ring event handler | |
2404 | * when there is an unsolicited iocb posted to the response ring by the | |
2405 | * firmware. This function gets the buffer associated with the iocbs | |
2406 | * and calls the event handler for the ring. This function handles both | |
2407 | * qring buffers and hbq buffers. | |
2408 | * When the function returns 1 the caller can free the iocb object otherwise | |
2409 | * upper layer functions will free the iocb objects. | |
2410 | **/ | |
dea3101e | 2411 | static int |
2412 | lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
2413 | struct lpfc_iocbq *saveq) | |
2414 | { | |
2415 | IOCB_t * irsp; | |
2416 | WORD5 * w5p; | |
2417 | uint32_t Rctl, Type; | |
3772a991 | 2418 | uint32_t match; |
76bb24ef | 2419 | struct lpfc_iocbq *iocbq; |
3163f725 | 2420 | struct lpfc_dmabuf *dmzbuf; |
dea3101e | 2421 | |
2422 | match = 0; | |
2423 | irsp = &(saveq->iocb); | |
57127f15 JS |
2424 | |
2425 | if (irsp->ulpCommand == CMD_ASYNC_STATUS) { | |
2426 | if (pring->lpfc_sli_rcv_async_status) | |
2427 | pring->lpfc_sli_rcv_async_status(phba, pring, saveq); | |
2428 | else | |
2429 | lpfc_printf_log(phba, | |
2430 | KERN_WARNING, | |
2431 | LOG_SLI, | |
2432 | "0316 Ring %d handler: unexpected " | |
2433 | "ASYNC_STATUS iocb received evt_code " | |
2434 | "0x%x\n", | |
2435 | pring->ringno, | |
2436 | irsp->un.asyncstat.evt_code); | |
2437 | return 1; | |
2438 | } | |
2439 | ||
3163f725 JS |
2440 | if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) && |
2441 | (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) { | |
2442 | if (irsp->ulpBdeCount > 0) { | |
2443 | dmzbuf = lpfc_sli_get_buff(phba, pring, | |
2444 | irsp->un.ulpWord[3]); | |
2445 | lpfc_in_buf_free(phba, dmzbuf); | |
2446 | } | |
2447 | ||
2448 | if (irsp->ulpBdeCount > 1) { | |
2449 | dmzbuf = lpfc_sli_get_buff(phba, pring, | |
2450 | irsp->unsli3.sli3Words[3]); | |
2451 | lpfc_in_buf_free(phba, dmzbuf); | |
2452 | } | |
2453 | ||
2454 | if (irsp->ulpBdeCount > 2) { | |
2455 | dmzbuf = lpfc_sli_get_buff(phba, pring, | |
2456 | irsp->unsli3.sli3Words[7]); | |
2457 | lpfc_in_buf_free(phba, dmzbuf); | |
2458 | } | |
2459 | ||
2460 | return 1; | |
2461 | } | |
2462 | ||
92d7f7b0 | 2463 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
76bb24ef JS |
2464 | if (irsp->ulpBdeCount != 0) { |
2465 | saveq->context2 = lpfc_sli_get_buff(phba, pring, | |
2466 | irsp->un.ulpWord[3]); | |
2467 | if (!saveq->context2) | |
2468 | lpfc_printf_log(phba, | |
2469 | KERN_ERR, | |
2470 | LOG_SLI, | |
2471 | "0341 Ring %d Cannot find buffer for " | |
2472 | "an unsolicited iocb. tag 0x%x\n", | |
2473 | pring->ringno, | |
2474 | irsp->un.ulpWord[3]); | |
76bb24ef JS |
2475 | } |
2476 | if (irsp->ulpBdeCount == 2) { | |
2477 | saveq->context3 = lpfc_sli_get_buff(phba, pring, | |
2478 | irsp->unsli3.sli3Words[7]); | |
2479 | if (!saveq->context3) | |
2480 | lpfc_printf_log(phba, | |
2481 | KERN_ERR, | |
2482 | LOG_SLI, | |
2483 | "0342 Ring %d Cannot find buffer for an" | |
2484 | " unsolicited iocb. tag 0x%x\n", | |
2485 | pring->ringno, | |
2486 | irsp->unsli3.sli3Words[7]); | |
2487 | } | |
2488 | list_for_each_entry(iocbq, &saveq->list, list) { | |
76bb24ef | 2489 | irsp = &(iocbq->iocb); |
76bb24ef JS |
2490 | if (irsp->ulpBdeCount != 0) { |
2491 | iocbq->context2 = lpfc_sli_get_buff(phba, pring, | |
2492 | irsp->un.ulpWord[3]); | |
9c2face6 | 2493 | if (!iocbq->context2) |
76bb24ef JS |
2494 | lpfc_printf_log(phba, |
2495 | KERN_ERR, | |
2496 | LOG_SLI, | |
2497 | "0343 Ring %d Cannot find " | |
2498 | "buffer for an unsolicited iocb" | |
2499 | ". tag 0x%x\n", pring->ringno, | |
92d7f7b0 | 2500 | irsp->un.ulpWord[3]); |
76bb24ef JS |
2501 | } |
2502 | if (irsp->ulpBdeCount == 2) { | |
2503 | iocbq->context3 = lpfc_sli_get_buff(phba, pring, | |
51ef4c26 | 2504 | irsp->unsli3.sli3Words[7]); |
9c2face6 | 2505 | if (!iocbq->context3) |
76bb24ef JS |
2506 | lpfc_printf_log(phba, |
2507 | KERN_ERR, | |
2508 | LOG_SLI, | |
2509 | "0344 Ring %d Cannot find " | |
2510 | "buffer for an unsolicited " | |
2511 | "iocb. tag 0x%x\n", | |
2512 | pring->ringno, | |
2513 | irsp->unsli3.sli3Words[7]); | |
2514 | } | |
2515 | } | |
92d7f7b0 | 2516 | } |
9c2face6 JS |
2517 | if (irsp->ulpBdeCount != 0 && |
2518 | (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX || | |
2519 | irsp->ulpStatus == IOSTAT_INTERMED_RSP)) { | |
2520 | int found = 0; | |
2521 | ||
2522 | /* search continue save q for same XRI */ | |
2523 | list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) { | |
7851fe2c JS |
2524 | if (iocbq->iocb.unsli3.rcvsli3.ox_id == |
2525 | saveq->iocb.unsli3.rcvsli3.ox_id) { | |
9c2face6 JS |
2526 | list_add_tail(&saveq->list, &iocbq->list); |
2527 | found = 1; | |
2528 | break; | |
2529 | } | |
2530 | } | |
2531 | if (!found) | |
2532 | list_add_tail(&saveq->clist, | |
2533 | &pring->iocb_continue_saveq); | |
2534 | if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) { | |
2535 | list_del_init(&iocbq->clist); | |
2536 | saveq = iocbq; | |
2537 | irsp = &(saveq->iocb); | |
2538 | } else | |
2539 | return 0; | |
2540 | } | |
2541 | if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) || | |
2542 | (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) || | |
2543 | (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) { | |
6a9c52cf JS |
2544 | Rctl = FC_RCTL_ELS_REQ; |
2545 | Type = FC_TYPE_ELS; | |
9c2face6 JS |
2546 | } else { |
2547 | w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]); | |
2548 | Rctl = w5p->hcsw.Rctl; | |
2549 | Type = w5p->hcsw.Type; | |
2550 | ||
2551 | /* Firmware Workaround */ | |
2552 | if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) && | |
2553 | (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX || | |
2554 | irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { | |
6a9c52cf JS |
2555 | Rctl = FC_RCTL_ELS_REQ; |
2556 | Type = FC_TYPE_ELS; | |
9c2face6 JS |
2557 | w5p->hcsw.Rctl = Rctl; |
2558 | w5p->hcsw.Type = Type; | |
2559 | } | |
2560 | } | |
92d7f7b0 | 2561 | |
3772a991 | 2562 | if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type)) |
92d7f7b0 | 2563 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
e8b62011 | 2564 | "0313 Ring %d handler: unexpected Rctl x%x " |
92d7f7b0 | 2565 | "Type x%x received\n", |
e8b62011 | 2566 | pring->ringno, Rctl, Type); |
3772a991 | 2567 | |
92d7f7b0 | 2568 | return 1; |
dea3101e | 2569 | } |
2570 | ||
e59058c4 | 2571 | /** |
3621a710 | 2572 | * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb |
e59058c4 JS |
2573 | * @phba: Pointer to HBA context object. |
2574 | * @pring: Pointer to driver SLI ring object. | |
2575 | * @prspiocb: Pointer to response iocb object. | |
2576 | * | |
2577 | * This function looks up the iocb_lookup table to get the command iocb | |
2578 | * corresponding to the given response iocb using the iotag of the | |
2579 | * response iocb. This function is called with the hbalock held. | |
2580 | * This function returns the command iocb object if it finds the command | |
2581 | * iocb else returns NULL. | |
2582 | **/ | |
dea3101e | 2583 | static struct lpfc_iocbq * |
2e0fef85 JS |
2584 | lpfc_sli_iocbq_lookup(struct lpfc_hba *phba, |
2585 | struct lpfc_sli_ring *pring, | |
2586 | struct lpfc_iocbq *prspiocb) | |
dea3101e | 2587 | { |
dea3101e | 2588 | struct lpfc_iocbq *cmd_iocb = NULL; |
2589 | uint16_t iotag; | |
2590 | ||
604a3e30 JB |
2591 | iotag = prspiocb->iocb.ulpIoTag; |
2592 | ||
2593 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { | |
2594 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; | |
92d7f7b0 | 2595 | list_del_init(&cmd_iocb->list); |
4f2e66c6 | 2596 | if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) { |
2a9bf3d0 | 2597 | pring->txcmplq_cnt--; |
4f2e66c6 | 2598 | cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
2a9bf3d0 | 2599 | } |
604a3e30 | 2600 | return cmd_iocb; |
dea3101e | 2601 | } |
2602 | ||
dea3101e | 2603 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
e8b62011 | 2604 | "0317 iotag x%x is out off " |
604a3e30 | 2605 | "range: max iotag x%x wd0 x%x\n", |
e8b62011 | 2606 | iotag, phba->sli.last_iotag, |
604a3e30 | 2607 | *(((uint32_t *) &prspiocb->iocb) + 7)); |
dea3101e | 2608 | return NULL; |
2609 | } | |
2610 | ||
3772a991 JS |
2611 | /** |
2612 | * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag | |
2613 | * @phba: Pointer to HBA context object. | |
2614 | * @pring: Pointer to driver SLI ring object. | |
2615 | * @iotag: IOCB tag. | |
2616 | * | |
2617 | * This function looks up the iocb_lookup table to get the command iocb | |
2618 | * corresponding to the given iotag. This function is called with the | |
2619 | * hbalock held. | |
2620 | * This function returns the command iocb object if it finds the command | |
2621 | * iocb else returns NULL. | |
2622 | **/ | |
2623 | static struct lpfc_iocbq * | |
2624 | lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba, | |
2625 | struct lpfc_sli_ring *pring, uint16_t iotag) | |
2626 | { | |
2627 | struct lpfc_iocbq *cmd_iocb; | |
2628 | ||
2629 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { | |
2630 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; | |
4f2e66c6 JS |
2631 | if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) { |
2632 | /* remove from txcmpl queue list */ | |
2633 | list_del_init(&cmd_iocb->list); | |
2634 | cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; | |
2a9bf3d0 | 2635 | pring->txcmplq_cnt--; |
4f2e66c6 | 2636 | return cmd_iocb; |
2a9bf3d0 | 2637 | } |
3772a991 | 2638 | } |
3772a991 JS |
2639 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
2640 | "0372 iotag x%x is out off range: max iotag (x%x)\n", | |
2641 | iotag, phba->sli.last_iotag); | |
2642 | return NULL; | |
2643 | } | |
2644 | ||
e59058c4 | 2645 | /** |
3621a710 | 2646 | * lpfc_sli_process_sol_iocb - process solicited iocb completion |
e59058c4 JS |
2647 | * @phba: Pointer to HBA context object. |
2648 | * @pring: Pointer to driver SLI ring object. | |
2649 | * @saveq: Pointer to the response iocb to be processed. | |
2650 | * | |
2651 | * This function is called by the ring event handler for non-fcp | |
2652 | * rings when there is a new response iocb in the response ring. | |
2653 | * The caller is not required to hold any locks. This function | |
2654 | * gets the command iocb associated with the response iocb and | |
2655 | * calls the completion handler for the command iocb. If there | |
2656 | * is no completion handler, the function will free the resources | |
2657 | * associated with command iocb. If the response iocb is for | |
2658 | * an already aborted command iocb, the status of the completion | |
2659 | * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED. | |
2660 | * This function always returns 1. | |
2661 | **/ | |
dea3101e | 2662 | static int |
2e0fef85 | 2663 | lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
dea3101e | 2664 | struct lpfc_iocbq *saveq) |
2665 | { | |
2e0fef85 | 2666 | struct lpfc_iocbq *cmdiocbp; |
dea3101e | 2667 | int rc = 1; |
2668 | unsigned long iflag; | |
2669 | ||
2670 | /* Based on the iotag field, get the cmd IOCB from the txcmplq */ | |
2e0fef85 | 2671 | spin_lock_irqsave(&phba->hbalock, iflag); |
604a3e30 | 2672 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq); |
2e0fef85 JS |
2673 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
2674 | ||
dea3101e | 2675 | if (cmdiocbp) { |
2676 | if (cmdiocbp->iocb_cmpl) { | |
ea2151b4 JS |
2677 | /* |
2678 | * If an ELS command failed send an event to mgmt | |
2679 | * application. | |
2680 | */ | |
2681 | if (saveq->iocb.ulpStatus && | |
2682 | (pring->ringno == LPFC_ELS_RING) && | |
2683 | (cmdiocbp->iocb.ulpCommand == | |
2684 | CMD_ELS_REQUEST64_CR)) | |
2685 | lpfc_send_els_failure_event(phba, | |
2686 | cmdiocbp, saveq); | |
2687 | ||
dea3101e | 2688 | /* |
2689 | * Post all ELS completions to the worker thread. | |
2690 | * All other are passed to the completion callback. | |
2691 | */ | |
2692 | if (pring->ringno == LPFC_ELS_RING) { | |
341af102 JS |
2693 | if ((phba->sli_rev < LPFC_SLI_REV4) && |
2694 | (cmdiocbp->iocb_flag & | |
2695 | LPFC_DRIVER_ABORTED)) { | |
2696 | spin_lock_irqsave(&phba->hbalock, | |
2697 | iflag); | |
07951076 JS |
2698 | cmdiocbp->iocb_flag &= |
2699 | ~LPFC_DRIVER_ABORTED; | |
341af102 JS |
2700 | spin_unlock_irqrestore(&phba->hbalock, |
2701 | iflag); | |
07951076 JS |
2702 | saveq->iocb.ulpStatus = |
2703 | IOSTAT_LOCAL_REJECT; | |
2704 | saveq->iocb.un.ulpWord[4] = | |
2705 | IOERR_SLI_ABORTED; | |
0ff10d46 JS |
2706 | |
2707 | /* Firmware could still be in progress | |
2708 | * of DMAing payload, so don't free data | |
2709 | * buffer till after a hbeat. | |
2710 | */ | |
341af102 JS |
2711 | spin_lock_irqsave(&phba->hbalock, |
2712 | iflag); | |
0ff10d46 | 2713 | saveq->iocb_flag |= LPFC_DELAY_MEM_FREE; |
341af102 JS |
2714 | spin_unlock_irqrestore(&phba->hbalock, |
2715 | iflag); | |
2716 | } | |
0f65ff68 JS |
2717 | if (phba->sli_rev == LPFC_SLI_REV4) { |
2718 | if (saveq->iocb_flag & | |
2719 | LPFC_EXCHANGE_BUSY) { | |
2720 | /* Set cmdiocb flag for the | |
2721 | * exchange busy so sgl (xri) | |
2722 | * will not be released until | |
2723 | * the abort xri is received | |
2724 | * from hba. | |
2725 | */ | |
2726 | spin_lock_irqsave( | |
2727 | &phba->hbalock, iflag); | |
2728 | cmdiocbp->iocb_flag |= | |
2729 | LPFC_EXCHANGE_BUSY; | |
2730 | spin_unlock_irqrestore( | |
2731 | &phba->hbalock, iflag); | |
2732 | } | |
2733 | if (cmdiocbp->iocb_flag & | |
2734 | LPFC_DRIVER_ABORTED) { | |
2735 | /* | |
2736 | * Clear LPFC_DRIVER_ABORTED | |
2737 | * bit in case it was driver | |
2738 | * initiated abort. | |
2739 | */ | |
2740 | spin_lock_irqsave( | |
2741 | &phba->hbalock, iflag); | |
2742 | cmdiocbp->iocb_flag &= | |
2743 | ~LPFC_DRIVER_ABORTED; | |
2744 | spin_unlock_irqrestore( | |
2745 | &phba->hbalock, iflag); | |
2746 | cmdiocbp->iocb.ulpStatus = | |
2747 | IOSTAT_LOCAL_REJECT; | |
2748 | cmdiocbp->iocb.un.ulpWord[4] = | |
2749 | IOERR_ABORT_REQUESTED; | |
2750 | /* | |
2751 | * For SLI4, irsiocb contains | |
2752 | * NO_XRI in sli_xritag, it | |
2753 | * shall not affect releasing | |
2754 | * sgl (xri) process. | |
2755 | */ | |
2756 | saveq->iocb.ulpStatus = | |
2757 | IOSTAT_LOCAL_REJECT; | |
2758 | saveq->iocb.un.ulpWord[4] = | |
2759 | IOERR_SLI_ABORTED; | |
2760 | spin_lock_irqsave( | |
2761 | &phba->hbalock, iflag); | |
2762 | saveq->iocb_flag |= | |
2763 | LPFC_DELAY_MEM_FREE; | |
2764 | spin_unlock_irqrestore( | |
2765 | &phba->hbalock, iflag); | |
2766 | } | |
07951076 | 2767 | } |
dea3101e | 2768 | } |
2e0fef85 | 2769 | (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq); |
604a3e30 JB |
2770 | } else |
2771 | lpfc_sli_release_iocbq(phba, cmdiocbp); | |
dea3101e | 2772 | } else { |
2773 | /* | |
2774 | * Unknown initiating command based on the response iotag. | |
2775 | * This could be the case on the ELS ring because of | |
2776 | * lpfc_els_abort(). | |
2777 | */ | |
2778 | if (pring->ringno != LPFC_ELS_RING) { | |
2779 | /* | |
2780 | * Ring <ringno> handler: unexpected completion IoTag | |
2781 | * <IoTag> | |
2782 | */ | |
a257bf90 | 2783 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
e8b62011 JS |
2784 | "0322 Ring %d handler: " |
2785 | "unexpected completion IoTag x%x " | |
2786 | "Data: x%x x%x x%x x%x\n", | |
2787 | pring->ringno, | |
2788 | saveq->iocb.ulpIoTag, | |
2789 | saveq->iocb.ulpStatus, | |
2790 | saveq->iocb.un.ulpWord[4], | |
2791 | saveq->iocb.ulpCommand, | |
2792 | saveq->iocb.ulpContext); | |
dea3101e | 2793 | } |
2794 | } | |
68876920 | 2795 | |
dea3101e | 2796 | return rc; |
2797 | } | |
2798 | ||
e59058c4 | 2799 | /** |
3621a710 | 2800 | * lpfc_sli_rsp_pointers_error - Response ring pointer error handler |
e59058c4 JS |
2801 | * @phba: Pointer to HBA context object. |
2802 | * @pring: Pointer to driver SLI ring object. | |
2803 | * | |
2804 | * This function is called from the iocb ring event handlers when | |
2805 | * put pointer is ahead of the get pointer for a ring. This function signal | |
2806 | * an error attention condition to the worker thread and the worker | |
2807 | * thread will transition the HBA to offline state. | |
2808 | **/ | |
2e0fef85 JS |
2809 | static void |
2810 | lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) | |
875fbdfe | 2811 | { |
34b02dcd | 2812 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
875fbdfe | 2813 | /* |
025dfdaf | 2814 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger than |
875fbdfe JSEC |
2815 | * rsp ring <portRspMax> |
2816 | */ | |
2817 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
e8b62011 | 2818 | "0312 Ring %d handler: portRspPut %d " |
025dfdaf | 2819 | "is bigger than rsp ring %d\n", |
e8b62011 | 2820 | pring->ringno, le32_to_cpu(pgp->rspPutInx), |
7e56aa25 | 2821 | pring->sli.sli3.numRiocb); |
875fbdfe | 2822 | |
2e0fef85 | 2823 | phba->link_state = LPFC_HBA_ERROR; |
875fbdfe JSEC |
2824 | |
2825 | /* | |
2826 | * All error attention handlers are posted to | |
2827 | * worker thread | |
2828 | */ | |
2829 | phba->work_ha |= HA_ERATT; | |
2830 | phba->work_hs = HS_FFER3; | |
92d7f7b0 | 2831 | |
5e9d9b82 | 2832 | lpfc_worker_wake_up(phba); |
875fbdfe JSEC |
2833 | |
2834 | return; | |
2835 | } | |
2836 | ||
9399627f | 2837 | /** |
3621a710 | 2838 | * lpfc_poll_eratt - Error attention polling timer timeout handler |
9399627f JS |
2839 | * @ptr: Pointer to address of HBA context object. |
2840 | * | |
2841 | * This function is invoked by the Error Attention polling timer when the | |
2842 | * timer times out. It will check the SLI Error Attention register for | |
2843 | * possible attention events. If so, it will post an Error Attention event | |
2844 | * and wake up worker thread to process it. Otherwise, it will set up the | |
2845 | * Error Attention polling timer for the next poll. | |
2846 | **/ | |
2847 | void lpfc_poll_eratt(unsigned long ptr) | |
2848 | { | |
2849 | struct lpfc_hba *phba; | |
aa6fbb75 JS |
2850 | uint32_t eratt = 0, rem; |
2851 | uint64_t sli_intr, cnt; | |
9399627f JS |
2852 | |
2853 | phba = (struct lpfc_hba *)ptr; | |
2854 | ||
aa6fbb75 JS |
2855 | /* Here we will also keep track of interrupts per sec of the hba */ |
2856 | sli_intr = phba->sli.slistat.sli_intr; | |
2857 | ||
2858 | if (phba->sli.slistat.sli_prev_intr > sli_intr) | |
2859 | cnt = (((uint64_t)(-1) - phba->sli.slistat.sli_prev_intr) + | |
2860 | sli_intr); | |
2861 | else | |
2862 | cnt = (sli_intr - phba->sli.slistat.sli_prev_intr); | |
2863 | ||
2864 | /* 64-bit integer division not supporte on 32-bit x86 - use do_div */ | |
2865 | rem = do_div(cnt, LPFC_ERATT_POLL_INTERVAL); | |
2866 | phba->sli.slistat.sli_ips = cnt; | |
2867 | ||
2868 | phba->sli.slistat.sli_prev_intr = sli_intr; | |
2869 | ||
9399627f JS |
2870 | /* Check chip HA register for error event */ |
2871 | eratt = lpfc_sli_check_eratt(phba); | |
2872 | ||
2873 | if (eratt) | |
2874 | /* Tell the worker thread there is work to do */ | |
2875 | lpfc_worker_wake_up(phba); | |
2876 | else | |
2877 | /* Restart the timer for next eratt poll */ | |
2878 | mod_timer(&phba->eratt_poll, jiffies + | |
2879 | HZ * LPFC_ERATT_POLL_INTERVAL); | |
2880 | return; | |
2881 | } | |
2882 | ||
875fbdfe | 2883 | |
e59058c4 | 2884 | /** |
3621a710 | 2885 | * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring |
e59058c4 JS |
2886 | * @phba: Pointer to HBA context object. |
2887 | * @pring: Pointer to driver SLI ring object. | |
2888 | * @mask: Host attention register mask for this ring. | |
2889 | * | |
2890 | * This function is called from the interrupt context when there is a ring | |
2891 | * event for the fcp ring. The caller does not hold any lock. | |
2892 | * The function processes each response iocb in the response ring until it | |
25985edc | 2893 | * finds an iocb with LE bit set and chains all the iocbs up to the iocb with |
e59058c4 JS |
2894 | * LE bit set. The function will call the completion handler of the command iocb |
2895 | * if the response iocb indicates a completion for a command iocb or it is | |
2896 | * an abort completion. The function will call lpfc_sli_process_unsol_iocb | |
2897 | * function if this is an unsolicited iocb. | |
dea3101e | 2898 | * This routine presumes LPFC_FCP_RING handling and doesn't bother |
45ed1190 JS |
2899 | * to check it explicitly. |
2900 | */ | |
2901 | int | |
2e0fef85 JS |
2902 | lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba, |
2903 | struct lpfc_sli_ring *pring, uint32_t mask) | |
dea3101e | 2904 | { |
34b02dcd | 2905 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
dea3101e | 2906 | IOCB_t *irsp = NULL; |
87f6eaff | 2907 | IOCB_t *entry = NULL; |
dea3101e | 2908 | struct lpfc_iocbq *cmdiocbq = NULL; |
2909 | struct lpfc_iocbq rspiocbq; | |
dea3101e | 2910 | uint32_t status; |
2911 | uint32_t portRspPut, portRspMax; | |
2912 | int rc = 1; | |
2913 | lpfc_iocb_type type; | |
2914 | unsigned long iflag; | |
2915 | uint32_t rsp_cmpl = 0; | |
dea3101e | 2916 | |
2e0fef85 | 2917 | spin_lock_irqsave(&phba->hbalock, iflag); |
dea3101e | 2918 | pring->stats.iocb_event++; |
2919 | ||
dea3101e | 2920 | /* |
2921 | * The next available response entry should never exceed the maximum | |
2922 | * entries. If it does, treat it as an adapter hardware error. | |
2923 | */ | |
7e56aa25 | 2924 | portRspMax = pring->sli.sli3.numRiocb; |
dea3101e | 2925 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
2926 | if (unlikely(portRspPut >= portRspMax)) { | |
875fbdfe | 2927 | lpfc_sli_rsp_pointers_error(phba, pring); |
2e0fef85 | 2928 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
dea3101e | 2929 | return 1; |
2930 | } | |
45ed1190 JS |
2931 | if (phba->fcp_ring_in_use) { |
2932 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
2933 | return 1; | |
2934 | } else | |
2935 | phba->fcp_ring_in_use = 1; | |
dea3101e | 2936 | |
2937 | rmb(); | |
7e56aa25 | 2938 | while (pring->sli.sli3.rspidx != portRspPut) { |
87f6eaff JSEC |
2939 | /* |
2940 | * Fetch an entry off the ring and copy it into a local data | |
2941 | * structure. The copy involves a byte-swap since the | |
2942 | * network byte order and pci byte orders are different. | |
2943 | */ | |
ed957684 | 2944 | entry = lpfc_resp_iocb(phba, pring); |
858c9f6c | 2945 | phba->last_completion_time = jiffies; |
875fbdfe | 2946 | |
7e56aa25 JS |
2947 | if (++pring->sli.sli3.rspidx >= portRspMax) |
2948 | pring->sli.sli3.rspidx = 0; | |
875fbdfe | 2949 | |
87f6eaff JSEC |
2950 | lpfc_sli_pcimem_bcopy((uint32_t *) entry, |
2951 | (uint32_t *) &rspiocbq.iocb, | |
ed957684 | 2952 | phba->iocb_rsp_size); |
a4bc3379 | 2953 | INIT_LIST_HEAD(&(rspiocbq.list)); |
87f6eaff JSEC |
2954 | irsp = &rspiocbq.iocb; |
2955 | ||
dea3101e | 2956 | type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK); |
2957 | pring->stats.iocb_rsp++; | |
2958 | rsp_cmpl++; | |
2959 | ||
2960 | if (unlikely(irsp->ulpStatus)) { | |
92d7f7b0 JS |
2961 | /* |
2962 | * If resource errors reported from HBA, reduce | |
2963 | * queuedepths of the SCSI device. | |
2964 | */ | |
2965 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && | |
2966 | (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) { | |
2967 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
3772a991 | 2968 | phba->lpfc_rampdown_queue_depth(phba); |
92d7f7b0 JS |
2969 | spin_lock_irqsave(&phba->hbalock, iflag); |
2970 | } | |
2971 | ||
dea3101e | 2972 | /* Rsp ring <ringno> error: IOCB */ |
2973 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
e8b62011 | 2974 | "0336 Rsp Ring %d error: IOCB Data: " |
92d7f7b0 | 2975 | "x%x x%x x%x x%x x%x x%x x%x x%x\n", |
e8b62011 | 2976 | pring->ringno, |
92d7f7b0 JS |
2977 | irsp->un.ulpWord[0], |
2978 | irsp->un.ulpWord[1], | |
2979 | irsp->un.ulpWord[2], | |
2980 | irsp->un.ulpWord[3], | |
2981 | irsp->un.ulpWord[4], | |
2982 | irsp->un.ulpWord[5], | |
d7c255b2 JS |
2983 | *(uint32_t *)&irsp->un1, |
2984 | *((uint32_t *)&irsp->un1 + 1)); | |
dea3101e | 2985 | } |
2986 | ||
2987 | switch (type) { | |
2988 | case LPFC_ABORT_IOCB: | |
2989 | case LPFC_SOL_IOCB: | |
2990 | /* | |
2991 | * Idle exchange closed via ABTS from port. No iocb | |
2992 | * resources need to be recovered. | |
2993 | */ | |
2994 | if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) { | |
dca9479b | 2995 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
e8b62011 | 2996 | "0333 IOCB cmd 0x%x" |
dca9479b | 2997 | " processed. Skipping" |
92d7f7b0 | 2998 | " completion\n", |
dca9479b | 2999 | irsp->ulpCommand); |
dea3101e | 3000 | break; |
3001 | } | |
3002 | ||
604a3e30 JB |
3003 | cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring, |
3004 | &rspiocbq); | |
0f65ff68 JS |
3005 | if (unlikely(!cmdiocbq)) |
3006 | break; | |
3007 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) | |
3008 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; | |
3009 | if (cmdiocbq->iocb_cmpl) { | |
3010 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
3011 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, | |
3012 | &rspiocbq); | |
3013 | spin_lock_irqsave(&phba->hbalock, iflag); | |
3014 | } | |
dea3101e | 3015 | break; |
a4bc3379 | 3016 | case LPFC_UNSOL_IOCB: |
2e0fef85 | 3017 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
a4bc3379 | 3018 | lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq); |
2e0fef85 | 3019 | spin_lock_irqsave(&phba->hbalock, iflag); |
a4bc3379 | 3020 | break; |
dea3101e | 3021 | default: |
3022 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { | |
3023 | char adaptermsg[LPFC_MAX_ADPTMSG]; | |
3024 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); | |
3025 | memcpy(&adaptermsg[0], (uint8_t *) irsp, | |
3026 | MAX_MSG_DATA); | |
898eb71c JP |
3027 | dev_warn(&((phba->pcidev)->dev), |
3028 | "lpfc%d: %s\n", | |
dea3101e | 3029 | phba->brd_no, adaptermsg); |
3030 | } else { | |
3031 | /* Unknown IOCB command */ | |
3032 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
e8b62011 | 3033 | "0334 Unknown IOCB command " |
92d7f7b0 | 3034 | "Data: x%x, x%x x%x x%x x%x\n", |
e8b62011 | 3035 | type, irsp->ulpCommand, |
92d7f7b0 JS |
3036 | irsp->ulpStatus, |
3037 | irsp->ulpIoTag, | |
3038 | irsp->ulpContext); | |
dea3101e | 3039 | } |
3040 | break; | |
3041 | } | |
3042 | ||
3043 | /* | |
3044 | * The response IOCB has been processed. Update the ring | |
3045 | * pointer in SLIM. If the port response put pointer has not | |
3046 | * been updated, sync the pgp->rspPutInx and fetch the new port | |
3047 | * response put pointer. | |
3048 | */ | |
7e56aa25 JS |
3049 | writel(pring->sli.sli3.rspidx, |
3050 | &phba->host_gp[pring->ringno].rspGetInx); | |
dea3101e | 3051 | |
7e56aa25 | 3052 | if (pring->sli.sli3.rspidx == portRspPut) |
dea3101e | 3053 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
3054 | } | |
3055 | ||
3056 | if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) { | |
3057 | pring->stats.iocb_rsp_full++; | |
3058 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); | |
3059 | writel(status, phba->CAregaddr); | |
3060 | readl(phba->CAregaddr); | |
3061 | } | |
3062 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { | |
3063 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; | |
3064 | pring->stats.iocb_cmd_empty++; | |
3065 | ||
3066 | /* Force update of the local copy of cmdGetInx */ | |
7e56aa25 | 3067 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
dea3101e | 3068 | lpfc_sli_resume_iocb(phba, pring); |
3069 | ||
3070 | if ((pring->lpfc_sli_cmd_available)) | |
3071 | (pring->lpfc_sli_cmd_available) (phba, pring); | |
3072 | ||
3073 | } | |
3074 | ||
45ed1190 | 3075 | phba->fcp_ring_in_use = 0; |
2e0fef85 | 3076 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
dea3101e | 3077 | return rc; |
3078 | } | |
3079 | ||
e59058c4 | 3080 | /** |
3772a991 JS |
3081 | * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb |
3082 | * @phba: Pointer to HBA context object. | |
3083 | * @pring: Pointer to driver SLI ring object. | |
3084 | * @rspiocbp: Pointer to driver response IOCB object. | |
3085 | * | |
3086 | * This function is called from the worker thread when there is a slow-path | |
3087 | * response IOCB to process. This function chains all the response iocbs until | |
3088 | * seeing the iocb with the LE bit set. The function will call | |
3089 | * lpfc_sli_process_sol_iocb function if the response iocb indicates a | |
3090 | * completion of a command iocb. The function will call the | |
3091 | * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb. | |
3092 | * The function frees the resources or calls the completion handler if this | |
3093 | * iocb is an abort completion. The function returns NULL when the response | |
3094 | * iocb has the LE bit set and all the chained iocbs are processed, otherwise | |
3095 | * this function shall chain the iocb on to the iocb_continueq and return the | |
3096 | * response iocb passed in. | |
3097 | **/ | |
3098 | static struct lpfc_iocbq * | |
3099 | lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
3100 | struct lpfc_iocbq *rspiocbp) | |
3101 | { | |
3102 | struct lpfc_iocbq *saveq; | |
3103 | struct lpfc_iocbq *cmdiocbp; | |
3104 | struct lpfc_iocbq *next_iocb; | |
3105 | IOCB_t *irsp = NULL; | |
3106 | uint32_t free_saveq; | |
3107 | uint8_t iocb_cmd_type; | |
3108 | lpfc_iocb_type type; | |
3109 | unsigned long iflag; | |
3110 | int rc; | |
3111 | ||
3112 | spin_lock_irqsave(&phba->hbalock, iflag); | |
3113 | /* First add the response iocb to the countinueq list */ | |
3114 | list_add_tail(&rspiocbp->list, &(pring->iocb_continueq)); | |
3115 | pring->iocb_continueq_cnt++; | |
3116 | ||
70f23fd6 | 3117 | /* Now, determine whether the list is completed for processing */ |
3772a991 JS |
3118 | irsp = &rspiocbp->iocb; |
3119 | if (irsp->ulpLe) { | |
3120 | /* | |
3121 | * By default, the driver expects to free all resources | |
3122 | * associated with this iocb completion. | |
3123 | */ | |
3124 | free_saveq = 1; | |
3125 | saveq = list_get_first(&pring->iocb_continueq, | |
3126 | struct lpfc_iocbq, list); | |
3127 | irsp = &(saveq->iocb); | |
3128 | list_del_init(&pring->iocb_continueq); | |
3129 | pring->iocb_continueq_cnt = 0; | |
3130 | ||
3131 | pring->stats.iocb_rsp++; | |
3132 | ||
3133 | /* | |
3134 | * If resource errors reported from HBA, reduce | |
3135 | * queuedepths of the SCSI device. | |
3136 | */ | |
3137 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && | |
3138 | (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) { | |
3139 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
3140 | phba->lpfc_rampdown_queue_depth(phba); | |
3141 | spin_lock_irqsave(&phba->hbalock, iflag); | |
3142 | } | |
3143 | ||
3144 | if (irsp->ulpStatus) { | |
3145 | /* Rsp ring <ringno> error: IOCB */ | |
3146 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
3147 | "0328 Rsp Ring %d error: " | |
3148 | "IOCB Data: " | |
3149 | "x%x x%x x%x x%x " | |
3150 | "x%x x%x x%x x%x " | |
3151 | "x%x x%x x%x x%x " | |
3152 | "x%x x%x x%x x%x\n", | |
3153 | pring->ringno, | |
3154 | irsp->un.ulpWord[0], | |
3155 | irsp->un.ulpWord[1], | |
3156 | irsp->un.ulpWord[2], | |
3157 | irsp->un.ulpWord[3], | |
3158 | irsp->un.ulpWord[4], | |
3159 | irsp->un.ulpWord[5], | |
3160 | *(((uint32_t *) irsp) + 6), | |
3161 | *(((uint32_t *) irsp) + 7), | |
3162 | *(((uint32_t *) irsp) + 8), | |
3163 | *(((uint32_t *) irsp) + 9), | |
3164 | *(((uint32_t *) irsp) + 10), | |
3165 | *(((uint32_t *) irsp) + 11), | |
3166 | *(((uint32_t *) irsp) + 12), | |
3167 | *(((uint32_t *) irsp) + 13), | |
3168 | *(((uint32_t *) irsp) + 14), | |
3169 | *(((uint32_t *) irsp) + 15)); | |
3170 | } | |
3171 | ||
3172 | /* | |
3173 | * Fetch the IOCB command type and call the correct completion | |
3174 | * routine. Solicited and Unsolicited IOCBs on the ELS ring | |
3175 | * get freed back to the lpfc_iocb_list by the discovery | |
3176 | * kernel thread. | |
3177 | */ | |
3178 | iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK; | |
3179 | type = lpfc_sli_iocb_cmd_type(iocb_cmd_type); | |
3180 | switch (type) { | |
3181 | case LPFC_SOL_IOCB: | |
3182 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
3183 | rc = lpfc_sli_process_sol_iocb(phba, pring, saveq); | |
3184 | spin_lock_irqsave(&phba->hbalock, iflag); | |
3185 | break; | |
3186 | ||
3187 | case LPFC_UNSOL_IOCB: | |
3188 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
3189 | rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq); | |
3190 | spin_lock_irqsave(&phba->hbalock, iflag); | |
3191 | if (!rc) | |
3192 | free_saveq = 0; | |
3193 | break; | |
3194 | ||
3195 | case LPFC_ABORT_IOCB: | |
3196 | cmdiocbp = NULL; | |
3197 | if (irsp->ulpCommand != CMD_XRI_ABORTED_CX) | |
3198 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, | |
3199 | saveq); | |
3200 | if (cmdiocbp) { | |
3201 | /* Call the specified completion routine */ | |
3202 | if (cmdiocbp->iocb_cmpl) { | |
3203 | spin_unlock_irqrestore(&phba->hbalock, | |
3204 | iflag); | |
3205 | (cmdiocbp->iocb_cmpl)(phba, cmdiocbp, | |
3206 | saveq); | |
3207 | spin_lock_irqsave(&phba->hbalock, | |
3208 | iflag); | |
3209 | } else | |
3210 | __lpfc_sli_release_iocbq(phba, | |
3211 | cmdiocbp); | |
3212 | } | |
3213 | break; | |
3214 | ||
3215 | case LPFC_UNKNOWN_IOCB: | |
3216 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { | |
3217 | char adaptermsg[LPFC_MAX_ADPTMSG]; | |
3218 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); | |
3219 | memcpy(&adaptermsg[0], (uint8_t *)irsp, | |
3220 | MAX_MSG_DATA); | |
3221 | dev_warn(&((phba->pcidev)->dev), | |
3222 | "lpfc%d: %s\n", | |
3223 | phba->brd_no, adaptermsg); | |
3224 | } else { | |
3225 | /* Unknown IOCB command */ | |
3226 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3227 | "0335 Unknown IOCB " | |
3228 | "command Data: x%x " | |
3229 | "x%x x%x x%x\n", | |
3230 | irsp->ulpCommand, | |
3231 | irsp->ulpStatus, | |
3232 | irsp->ulpIoTag, | |
3233 | irsp->ulpContext); | |
3234 | } | |
3235 | break; | |
3236 | } | |
3237 | ||
3238 | if (free_saveq) { | |
3239 | list_for_each_entry_safe(rspiocbp, next_iocb, | |
3240 | &saveq->list, list) { | |
3241 | list_del(&rspiocbp->list); | |
3242 | __lpfc_sli_release_iocbq(phba, rspiocbp); | |
3243 | } | |
3244 | __lpfc_sli_release_iocbq(phba, saveq); | |
3245 | } | |
3246 | rspiocbp = NULL; | |
3247 | } | |
3248 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
3249 | return rspiocbp; | |
3250 | } | |
3251 | ||
3252 | /** | |
3253 | * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs | |
e59058c4 JS |
3254 | * @phba: Pointer to HBA context object. |
3255 | * @pring: Pointer to driver SLI ring object. | |
3256 | * @mask: Host attention register mask for this ring. | |
3257 | * | |
3772a991 JS |
3258 | * This routine wraps the actual slow_ring event process routine from the |
3259 | * API jump table function pointer from the lpfc_hba struct. | |
e59058c4 | 3260 | **/ |
3772a991 | 3261 | void |
2e0fef85 JS |
3262 | lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba, |
3263 | struct lpfc_sli_ring *pring, uint32_t mask) | |
3772a991 JS |
3264 | { |
3265 | phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask); | |
3266 | } | |
3267 | ||
3268 | /** | |
3269 | * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings | |
3270 | * @phba: Pointer to HBA context object. | |
3271 | * @pring: Pointer to driver SLI ring object. | |
3272 | * @mask: Host attention register mask for this ring. | |
3273 | * | |
3274 | * This function is called from the worker thread when there is a ring event | |
3275 | * for non-fcp rings. The caller does not hold any lock. The function will | |
3276 | * remove each response iocb in the response ring and calls the handle | |
3277 | * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it. | |
3278 | **/ | |
3279 | static void | |
3280 | lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba, | |
3281 | struct lpfc_sli_ring *pring, uint32_t mask) | |
dea3101e | 3282 | { |
34b02dcd | 3283 | struct lpfc_pgp *pgp; |
dea3101e | 3284 | IOCB_t *entry; |
3285 | IOCB_t *irsp = NULL; | |
3286 | struct lpfc_iocbq *rspiocbp = NULL; | |
dea3101e | 3287 | uint32_t portRspPut, portRspMax; |
dea3101e | 3288 | unsigned long iflag; |
3772a991 | 3289 | uint32_t status; |
dea3101e | 3290 | |
34b02dcd | 3291 | pgp = &phba->port_gp[pring->ringno]; |
2e0fef85 | 3292 | spin_lock_irqsave(&phba->hbalock, iflag); |
dea3101e | 3293 | pring->stats.iocb_event++; |
3294 | ||
dea3101e | 3295 | /* |
3296 | * The next available response entry should never exceed the maximum | |
3297 | * entries. If it does, treat it as an adapter hardware error. | |
3298 | */ | |
7e56aa25 | 3299 | portRspMax = pring->sli.sli3.numRiocb; |
dea3101e | 3300 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
3301 | if (portRspPut >= portRspMax) { | |
3302 | /* | |
025dfdaf | 3303 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger than |
dea3101e | 3304 | * rsp ring <portRspMax> |
3305 | */ | |
ed957684 | 3306 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
e8b62011 | 3307 | "0303 Ring %d handler: portRspPut %d " |
025dfdaf | 3308 | "is bigger than rsp ring %d\n", |
e8b62011 | 3309 | pring->ringno, portRspPut, portRspMax); |
dea3101e | 3310 | |
2e0fef85 JS |
3311 | phba->link_state = LPFC_HBA_ERROR; |
3312 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
dea3101e | 3313 | |
3314 | phba->work_hs = HS_FFER3; | |
3315 | lpfc_handle_eratt(phba); | |
3316 | ||
3772a991 | 3317 | return; |
dea3101e | 3318 | } |
3319 | ||
3320 | rmb(); | |
7e56aa25 | 3321 | while (pring->sli.sli3.rspidx != portRspPut) { |
dea3101e | 3322 | /* |
3323 | * Build a completion list and call the appropriate handler. | |
3324 | * The process is to get the next available response iocb, get | |
3325 | * a free iocb from the list, copy the response data into the | |
3326 | * free iocb, insert to the continuation list, and update the | |
3327 | * next response index to slim. This process makes response | |
3328 | * iocb's in the ring available to DMA as fast as possible but | |
3329 | * pays a penalty for a copy operation. Since the iocb is | |
3330 | * only 32 bytes, this penalty is considered small relative to | |
3331 | * the PCI reads for register values and a slim write. When | |
3332 | * the ulpLe field is set, the entire Command has been | |
3333 | * received. | |
3334 | */ | |
ed957684 JS |
3335 | entry = lpfc_resp_iocb(phba, pring); |
3336 | ||
858c9f6c | 3337 | phba->last_completion_time = jiffies; |
2e0fef85 | 3338 | rspiocbp = __lpfc_sli_get_iocbq(phba); |
dea3101e | 3339 | if (rspiocbp == NULL) { |
3340 | printk(KERN_ERR "%s: out of buffers! Failing " | |
cadbd4a5 | 3341 | "completion.\n", __func__); |
dea3101e | 3342 | break; |
3343 | } | |
3344 | ||
ed957684 JS |
3345 | lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb, |
3346 | phba->iocb_rsp_size); | |
dea3101e | 3347 | irsp = &rspiocbp->iocb; |
3348 | ||
7e56aa25 JS |
3349 | if (++pring->sli.sli3.rspidx >= portRspMax) |
3350 | pring->sli.sli3.rspidx = 0; | |
dea3101e | 3351 | |
a58cbd52 JS |
3352 | if (pring->ringno == LPFC_ELS_RING) { |
3353 | lpfc_debugfs_slow_ring_trc(phba, | |
3354 | "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x", | |
3355 | *(((uint32_t *) irsp) + 4), | |
3356 | *(((uint32_t *) irsp) + 6), | |
3357 | *(((uint32_t *) irsp) + 7)); | |
3358 | } | |
3359 | ||
7e56aa25 JS |
3360 | writel(pring->sli.sli3.rspidx, |
3361 | &phba->host_gp[pring->ringno].rspGetInx); | |
dea3101e | 3362 | |
3772a991 JS |
3363 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
3364 | /* Handle the response IOCB */ | |
3365 | rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp); | |
3366 | spin_lock_irqsave(&phba->hbalock, iflag); | |
dea3101e | 3367 | |
3368 | /* | |
3369 | * If the port response put pointer has not been updated, sync | |
3370 | * the pgp->rspPutInx in the MAILBOX_tand fetch the new port | |
3371 | * response put pointer. | |
3372 | */ | |
7e56aa25 | 3373 | if (pring->sli.sli3.rspidx == portRspPut) { |
dea3101e | 3374 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
3375 | } | |
7e56aa25 | 3376 | } /* while (pring->sli.sli3.rspidx != portRspPut) */ |
dea3101e | 3377 | |
92d7f7b0 | 3378 | if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) { |
dea3101e | 3379 | /* At least one response entry has been freed */ |
3380 | pring->stats.iocb_rsp_full++; | |
3381 | /* SET RxRE_RSP in Chip Att register */ | |
3382 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); | |
3383 | writel(status, phba->CAregaddr); | |
3384 | readl(phba->CAregaddr); /* flush */ | |
3385 | } | |
3386 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { | |
3387 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; | |
3388 | pring->stats.iocb_cmd_empty++; | |
3389 | ||
3390 | /* Force update of the local copy of cmdGetInx */ | |
7e56aa25 | 3391 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
dea3101e | 3392 | lpfc_sli_resume_iocb(phba, pring); |
3393 | ||
3394 | if ((pring->lpfc_sli_cmd_available)) | |
3395 | (pring->lpfc_sli_cmd_available) (phba, pring); | |
3396 | ||
3397 | } | |
3398 | ||
2e0fef85 | 3399 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
3772a991 | 3400 | return; |
dea3101e | 3401 | } |
3402 | ||
4f774513 JS |
3403 | /** |
3404 | * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events | |
3405 | * @phba: Pointer to HBA context object. | |
3406 | * @pring: Pointer to driver SLI ring object. | |
3407 | * @mask: Host attention register mask for this ring. | |
3408 | * | |
3409 | * This function is called from the worker thread when there is a pending | |
3410 | * ELS response iocb on the driver internal slow-path response iocb worker | |
3411 | * queue. The caller does not hold any lock. The function will remove each | |
3412 | * response iocb from the response worker queue and calls the handle | |
3413 | * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it. | |
3414 | **/ | |
3415 | static void | |
3416 | lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba, | |
3417 | struct lpfc_sli_ring *pring, uint32_t mask) | |
3418 | { | |
3419 | struct lpfc_iocbq *irspiocbq; | |
4d9ab994 JS |
3420 | struct hbq_dmabuf *dmabuf; |
3421 | struct lpfc_cq_event *cq_event; | |
4f774513 JS |
3422 | unsigned long iflag; |
3423 | ||
45ed1190 JS |
3424 | spin_lock_irqsave(&phba->hbalock, iflag); |
3425 | phba->hba_flag &= ~HBA_SP_QUEUE_EVT; | |
3426 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
3427 | while (!list_empty(&phba->sli4_hba.sp_queue_event)) { | |
4f774513 JS |
3428 | /* Get the response iocb from the head of work queue */ |
3429 | spin_lock_irqsave(&phba->hbalock, iflag); | |
45ed1190 | 3430 | list_remove_head(&phba->sli4_hba.sp_queue_event, |
4d9ab994 | 3431 | cq_event, struct lpfc_cq_event, list); |
4f774513 | 3432 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
4d9ab994 JS |
3433 | |
3434 | switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) { | |
3435 | case CQE_CODE_COMPL_WQE: | |
3436 | irspiocbq = container_of(cq_event, struct lpfc_iocbq, | |
3437 | cq_event); | |
45ed1190 JS |
3438 | /* Translate ELS WCQE to response IOCBQ */ |
3439 | irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba, | |
3440 | irspiocbq); | |
3441 | if (irspiocbq) | |
3442 | lpfc_sli_sp_handle_rspiocb(phba, pring, | |
3443 | irspiocbq); | |
4d9ab994 JS |
3444 | break; |
3445 | case CQE_CODE_RECEIVE: | |
7851fe2c | 3446 | case CQE_CODE_RECEIVE_V1: |
4d9ab994 JS |
3447 | dmabuf = container_of(cq_event, struct hbq_dmabuf, |
3448 | cq_event); | |
3449 | lpfc_sli4_handle_received_buffer(phba, dmabuf); | |
3450 | break; | |
3451 | default: | |
3452 | break; | |
3453 | } | |
4f774513 JS |
3454 | } |
3455 | } | |
3456 | ||
e59058c4 | 3457 | /** |
3621a710 | 3458 | * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring |
e59058c4 JS |
3459 | * @phba: Pointer to HBA context object. |
3460 | * @pring: Pointer to driver SLI ring object. | |
3461 | * | |
3462 | * This function aborts all iocbs in the given ring and frees all the iocb | |
3463 | * objects in txq. This function issues an abort iocb for all the iocb commands | |
3464 | * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before | |
3465 | * the return of this function. The caller is not required to hold any locks. | |
3466 | **/ | |
2e0fef85 | 3467 | void |
dea3101e | 3468 | lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
3469 | { | |
2534ba75 | 3470 | LIST_HEAD(completions); |
dea3101e | 3471 | struct lpfc_iocbq *iocb, *next_iocb; |
dea3101e | 3472 | |
92d7f7b0 JS |
3473 | if (pring->ringno == LPFC_ELS_RING) { |
3474 | lpfc_fabric_abort_hba(phba); | |
3475 | } | |
3476 | ||
dea3101e | 3477 | /* Error everything on txq and txcmplq |
3478 | * First do the txq. | |
3479 | */ | |
2e0fef85 | 3480 | spin_lock_irq(&phba->hbalock); |
2534ba75 | 3481 | list_splice_init(&pring->txq, &completions); |
dea3101e | 3482 | pring->txq_cnt = 0; |
dea3101e | 3483 | |
3484 | /* Next issue ABTS for everything on the txcmplq */ | |
2534ba75 JS |
3485 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) |
3486 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); | |
dea3101e | 3487 | |
2e0fef85 | 3488 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 3489 | |
a257bf90 JS |
3490 | /* Cancel all the IOCBs from the completions list */ |
3491 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, | |
3492 | IOERR_SLI_ABORTED); | |
dea3101e | 3493 | } |
3494 | ||
a8e497d5 | 3495 | /** |
3621a710 | 3496 | * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring |
a8e497d5 JS |
3497 | * @phba: Pointer to HBA context object. |
3498 | * | |
3499 | * This function flushes all iocbs in the fcp ring and frees all the iocb | |
3500 | * objects in txq and txcmplq. This function will not issue abort iocbs | |
3501 | * for all the iocb commands in txcmplq, they will just be returned with | |
3502 | * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI | |
3503 | * slot has been permanently disabled. | |
3504 | **/ | |
3505 | void | |
3506 | lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba) | |
3507 | { | |
3508 | LIST_HEAD(txq); | |
3509 | LIST_HEAD(txcmplq); | |
a8e497d5 JS |
3510 | struct lpfc_sli *psli = &phba->sli; |
3511 | struct lpfc_sli_ring *pring; | |
3512 | ||
3513 | /* Currently, only one fcp ring */ | |
3514 | pring = &psli->ring[psli->fcp_ring]; | |
3515 | ||
3516 | spin_lock_irq(&phba->hbalock); | |
3517 | /* Retrieve everything on txq */ | |
3518 | list_splice_init(&pring->txq, &txq); | |
3519 | pring->txq_cnt = 0; | |
3520 | ||
3521 | /* Retrieve everything on the txcmplq */ | |
3522 | list_splice_init(&pring->txcmplq, &txcmplq); | |
3523 | pring->txcmplq_cnt = 0; | |
4f2e66c6 JS |
3524 | |
3525 | /* Indicate the I/O queues are flushed */ | |
3526 | phba->hba_flag |= HBA_FCP_IOQ_FLUSH; | |
a8e497d5 JS |
3527 | spin_unlock_irq(&phba->hbalock); |
3528 | ||
3529 | /* Flush the txq */ | |
a257bf90 JS |
3530 | lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT, |
3531 | IOERR_SLI_DOWN); | |
a8e497d5 JS |
3532 | |
3533 | /* Flush the txcmpq */ | |
a257bf90 JS |
3534 | lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT, |
3535 | IOERR_SLI_DOWN); | |
a8e497d5 JS |
3536 | } |
3537 | ||
e59058c4 | 3538 | /** |
3772a991 | 3539 | * lpfc_sli_brdready_s3 - Check for sli3 host ready status |
e59058c4 JS |
3540 | * @phba: Pointer to HBA context object. |
3541 | * @mask: Bit mask to be checked. | |
3542 | * | |
3543 | * This function reads the host status register and compares | |
3544 | * with the provided bit mask to check if HBA completed | |
3545 | * the restart. This function will wait in a loop for the | |
3546 | * HBA to complete restart. If the HBA does not restart within | |
3547 | * 15 iterations, the function will reset the HBA again. The | |
3548 | * function returns 1 when HBA fail to restart otherwise returns | |
3549 | * zero. | |
3550 | **/ | |
3772a991 JS |
3551 | static int |
3552 | lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask) | |
dea3101e | 3553 | { |
41415862 JW |
3554 | uint32_t status; |
3555 | int i = 0; | |
3556 | int retval = 0; | |
dea3101e | 3557 | |
41415862 | 3558 | /* Read the HBA Host Status Register */ |
9940b97b JS |
3559 | if (lpfc_readl(phba->HSregaddr, &status)) |
3560 | return 1; | |
dea3101e | 3561 | |
41415862 JW |
3562 | /* |
3563 | * Check status register every 100ms for 5 retries, then every | |
3564 | * 500ms for 5, then every 2.5 sec for 5, then reset board and | |
3565 | * every 2.5 sec for 4. | |
3566 | * Break our of the loop if errors occurred during init. | |
3567 | */ | |
3568 | while (((status & mask) != mask) && | |
3569 | !(status & HS_FFERM) && | |
3570 | i++ < 20) { | |
dea3101e | 3571 | |
41415862 JW |
3572 | if (i <= 5) |
3573 | msleep(10); | |
3574 | else if (i <= 10) | |
3575 | msleep(500); | |
3576 | else | |
3577 | msleep(2500); | |
dea3101e | 3578 | |
41415862 | 3579 | if (i == 15) { |
2e0fef85 | 3580 | /* Do post */ |
92d7f7b0 | 3581 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
41415862 JW |
3582 | lpfc_sli_brdrestart(phba); |
3583 | } | |
3584 | /* Read the HBA Host Status Register */ | |
9940b97b JS |
3585 | if (lpfc_readl(phba->HSregaddr, &status)) { |
3586 | retval = 1; | |
3587 | break; | |
3588 | } | |
41415862 | 3589 | } |
dea3101e | 3590 | |
41415862 JW |
3591 | /* Check to see if any errors occurred during init */ |
3592 | if ((status & HS_FFERM) || (i >= 20)) { | |
e40a02c1 JS |
3593 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
3594 | "2751 Adapter failed to restart, " | |
3595 | "status reg x%x, FW Data: A8 x%x AC x%x\n", | |
3596 | status, | |
3597 | readl(phba->MBslimaddr + 0xa8), | |
3598 | readl(phba->MBslimaddr + 0xac)); | |
2e0fef85 | 3599 | phba->link_state = LPFC_HBA_ERROR; |
41415862 | 3600 | retval = 1; |
dea3101e | 3601 | } |
dea3101e | 3602 | |
41415862 JW |
3603 | return retval; |
3604 | } | |
dea3101e | 3605 | |
da0436e9 JS |
3606 | /** |
3607 | * lpfc_sli_brdready_s4 - Check for sli4 host ready status | |
3608 | * @phba: Pointer to HBA context object. | |
3609 | * @mask: Bit mask to be checked. | |
3610 | * | |
3611 | * This function checks the host status register to check if HBA is | |
3612 | * ready. This function will wait in a loop for the HBA to be ready | |
3613 | * If the HBA is not ready , the function will will reset the HBA PCI | |
3614 | * function again. The function returns 1 when HBA fail to be ready | |
3615 | * otherwise returns zero. | |
3616 | **/ | |
3617 | static int | |
3618 | lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask) | |
3619 | { | |
3620 | uint32_t status; | |
3621 | int retval = 0; | |
3622 | ||
3623 | /* Read the HBA Host Status Register */ | |
3624 | status = lpfc_sli4_post_status_check(phba); | |
3625 | ||
3626 | if (status) { | |
3627 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; | |
3628 | lpfc_sli_brdrestart(phba); | |
3629 | status = lpfc_sli4_post_status_check(phba); | |
3630 | } | |
3631 | ||
3632 | /* Check to see if any errors occurred during init */ | |
3633 | if (status) { | |
3634 | phba->link_state = LPFC_HBA_ERROR; | |
3635 | retval = 1; | |
3636 | } else | |
3637 | phba->sli4_hba.intr_enable = 0; | |
3638 | ||
3639 | return retval; | |
3640 | } | |
3641 | ||
3642 | /** | |
3643 | * lpfc_sli_brdready - Wrapper func for checking the hba readyness | |
3644 | * @phba: Pointer to HBA context object. | |
3645 | * @mask: Bit mask to be checked. | |
3646 | * | |
3647 | * This routine wraps the actual SLI3 or SLI4 hba readyness check routine | |
3648 | * from the API jump table function pointer from the lpfc_hba struct. | |
3649 | **/ | |
3650 | int | |
3651 | lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask) | |
3652 | { | |
3653 | return phba->lpfc_sli_brdready(phba, mask); | |
3654 | } | |
3655 | ||
9290831f JS |
3656 | #define BARRIER_TEST_PATTERN (0xdeadbeef) |
3657 | ||
e59058c4 | 3658 | /** |
3621a710 | 3659 | * lpfc_reset_barrier - Make HBA ready for HBA reset |
e59058c4 JS |
3660 | * @phba: Pointer to HBA context object. |
3661 | * | |
1b51197d JS |
3662 | * This function is called before resetting an HBA. This function is called |
3663 | * with hbalock held and requests HBA to quiesce DMAs before a reset. | |
e59058c4 | 3664 | **/ |
2e0fef85 | 3665 | void lpfc_reset_barrier(struct lpfc_hba *phba) |
9290831f | 3666 | { |
65a29c16 JS |
3667 | uint32_t __iomem *resp_buf; |
3668 | uint32_t __iomem *mbox_buf; | |
9290831f | 3669 | volatile uint32_t mbox; |
9940b97b | 3670 | uint32_t hc_copy, ha_copy, resp_data; |
9290831f JS |
3671 | int i; |
3672 | uint8_t hdrtype; | |
3673 | ||
3674 | pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype); | |
3675 | if (hdrtype != 0x80 || | |
3676 | (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID && | |
3677 | FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID)) | |
3678 | return; | |
3679 | ||
3680 | /* | |
3681 | * Tell the other part of the chip to suspend temporarily all | |
3682 | * its DMA activity. | |
3683 | */ | |
65a29c16 | 3684 | resp_buf = phba->MBslimaddr; |
9290831f JS |
3685 | |
3686 | /* Disable the error attention */ | |
9940b97b JS |
3687 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) |
3688 | return; | |
9290831f JS |
3689 | writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr); |
3690 | readl(phba->HCregaddr); /* flush */ | |
2e0fef85 | 3691 | phba->link_flag |= LS_IGNORE_ERATT; |
9290831f | 3692 | |
9940b97b JS |
3693 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
3694 | return; | |
3695 | if (ha_copy & HA_ERATT) { | |
9290831f JS |
3696 | /* Clear Chip error bit */ |
3697 | writel(HA_ERATT, phba->HAregaddr); | |
2e0fef85 | 3698 | phba->pport->stopped = 1; |
9290831f JS |
3699 | } |
3700 | ||
3701 | mbox = 0; | |
3702 | ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD; | |
3703 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP; | |
3704 | ||
3705 | writel(BARRIER_TEST_PATTERN, (resp_buf + 1)); | |
65a29c16 | 3706 | mbox_buf = phba->MBslimaddr; |
9290831f JS |
3707 | writel(mbox, mbox_buf); |
3708 | ||
9940b97b JS |
3709 | for (i = 0; i < 50; i++) { |
3710 | if (lpfc_readl((resp_buf + 1), &resp_data)) | |
3711 | return; | |
3712 | if (resp_data != ~(BARRIER_TEST_PATTERN)) | |
3713 | mdelay(1); | |
3714 | else | |
3715 | break; | |
3716 | } | |
3717 | resp_data = 0; | |
3718 | if (lpfc_readl((resp_buf + 1), &resp_data)) | |
3719 | return; | |
3720 | if (resp_data != ~(BARRIER_TEST_PATTERN)) { | |
f4b4c68f | 3721 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE || |
2e0fef85 | 3722 | phba->pport->stopped) |
9290831f JS |
3723 | goto restore_hc; |
3724 | else | |
3725 | goto clear_errat; | |
3726 | } | |
3727 | ||
3728 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST; | |
9940b97b JS |
3729 | resp_data = 0; |
3730 | for (i = 0; i < 500; i++) { | |
3731 | if (lpfc_readl(resp_buf, &resp_data)) | |
3732 | return; | |
3733 | if (resp_data != mbox) | |
3734 | mdelay(1); | |
3735 | else | |
3736 | break; | |
3737 | } | |
9290831f JS |
3738 | |
3739 | clear_errat: | |
3740 | ||
9940b97b JS |
3741 | while (++i < 500) { |
3742 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) | |
3743 | return; | |
3744 | if (!(ha_copy & HA_ERATT)) | |
3745 | mdelay(1); | |
3746 | else | |
3747 | break; | |
3748 | } | |
9290831f JS |
3749 | |
3750 | if (readl(phba->HAregaddr) & HA_ERATT) { | |
3751 | writel(HA_ERATT, phba->HAregaddr); | |
2e0fef85 | 3752 | phba->pport->stopped = 1; |
9290831f JS |
3753 | } |
3754 | ||
3755 | restore_hc: | |
2e0fef85 | 3756 | phba->link_flag &= ~LS_IGNORE_ERATT; |
9290831f JS |
3757 | writel(hc_copy, phba->HCregaddr); |
3758 | readl(phba->HCregaddr); /* flush */ | |
3759 | } | |
3760 | ||
e59058c4 | 3761 | /** |
3621a710 | 3762 | * lpfc_sli_brdkill - Issue a kill_board mailbox command |
e59058c4 JS |
3763 | * @phba: Pointer to HBA context object. |
3764 | * | |
3765 | * This function issues a kill_board mailbox command and waits for | |
3766 | * the error attention interrupt. This function is called for stopping | |
3767 | * the firmware processing. The caller is not required to hold any | |
3768 | * locks. This function calls lpfc_hba_down_post function to free | |
3769 | * any pending commands after the kill. The function will return 1 when it | |
3770 | * fails to kill the board else will return 0. | |
3771 | **/ | |
41415862 | 3772 | int |
2e0fef85 | 3773 | lpfc_sli_brdkill(struct lpfc_hba *phba) |
41415862 JW |
3774 | { |
3775 | struct lpfc_sli *psli; | |
3776 | LPFC_MBOXQ_t *pmb; | |
3777 | uint32_t status; | |
3778 | uint32_t ha_copy; | |
3779 | int retval; | |
3780 | int i = 0; | |
dea3101e | 3781 | |
41415862 | 3782 | psli = &phba->sli; |
dea3101e | 3783 | |
41415862 | 3784 | /* Kill HBA */ |
ed957684 | 3785 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
e8b62011 JS |
3786 | "0329 Kill HBA Data: x%x x%x\n", |
3787 | phba->pport->port_state, psli->sli_flag); | |
41415862 | 3788 | |
98c9ea5c JS |
3789 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
3790 | if (!pmb) | |
41415862 | 3791 | return 1; |
41415862 JW |
3792 | |
3793 | /* Disable the error attention */ | |
2e0fef85 | 3794 | spin_lock_irq(&phba->hbalock); |
9940b97b JS |
3795 | if (lpfc_readl(phba->HCregaddr, &status)) { |
3796 | spin_unlock_irq(&phba->hbalock); | |
3797 | mempool_free(pmb, phba->mbox_mem_pool); | |
3798 | return 1; | |
3799 | } | |
41415862 JW |
3800 | status &= ~HC_ERINT_ENA; |
3801 | writel(status, phba->HCregaddr); | |
3802 | readl(phba->HCregaddr); /* flush */ | |
2e0fef85 JS |
3803 | phba->link_flag |= LS_IGNORE_ERATT; |
3804 | spin_unlock_irq(&phba->hbalock); | |
41415862 JW |
3805 | |
3806 | lpfc_kill_board(phba, pmb); | |
3807 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
3808 | retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); | |
3809 | ||
3810 | if (retval != MBX_SUCCESS) { | |
3811 | if (retval != MBX_BUSY) | |
3812 | mempool_free(pmb, phba->mbox_mem_pool); | |
e40a02c1 JS |
3813 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
3814 | "2752 KILL_BOARD command failed retval %d\n", | |
3815 | retval); | |
2e0fef85 JS |
3816 | spin_lock_irq(&phba->hbalock); |
3817 | phba->link_flag &= ~LS_IGNORE_ERATT; | |
3818 | spin_unlock_irq(&phba->hbalock); | |
41415862 JW |
3819 | return 1; |
3820 | } | |
3821 | ||
f4b4c68f JS |
3822 | spin_lock_irq(&phba->hbalock); |
3823 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; | |
3824 | spin_unlock_irq(&phba->hbalock); | |
9290831f | 3825 | |
41415862 JW |
3826 | mempool_free(pmb, phba->mbox_mem_pool); |
3827 | ||
3828 | /* There is no completion for a KILL_BOARD mbox cmd. Check for an error | |
3829 | * attention every 100ms for 3 seconds. If we don't get ERATT after | |
3830 | * 3 seconds we still set HBA_ERROR state because the status of the | |
3831 | * board is now undefined. | |
3832 | */ | |
9940b97b JS |
3833 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
3834 | return 1; | |
41415862 JW |
3835 | while ((i++ < 30) && !(ha_copy & HA_ERATT)) { |
3836 | mdelay(100); | |
9940b97b JS |
3837 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
3838 | return 1; | |
41415862 JW |
3839 | } |
3840 | ||
3841 | del_timer_sync(&psli->mbox_tmo); | |
9290831f JS |
3842 | if (ha_copy & HA_ERATT) { |
3843 | writel(HA_ERATT, phba->HAregaddr); | |
2e0fef85 | 3844 | phba->pport->stopped = 1; |
9290831f | 3845 | } |
2e0fef85 | 3846 | spin_lock_irq(&phba->hbalock); |
41415862 | 3847 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
04c68496 | 3848 | psli->mbox_active = NULL; |
2e0fef85 JS |
3849 | phba->link_flag &= ~LS_IGNORE_ERATT; |
3850 | spin_unlock_irq(&phba->hbalock); | |
41415862 | 3851 | |
41415862 | 3852 | lpfc_hba_down_post(phba); |
2e0fef85 | 3853 | phba->link_state = LPFC_HBA_ERROR; |
41415862 | 3854 | |
2e0fef85 | 3855 | return ha_copy & HA_ERATT ? 0 : 1; |
dea3101e | 3856 | } |
3857 | ||
e59058c4 | 3858 | /** |
3772a991 | 3859 | * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA |
e59058c4 JS |
3860 | * @phba: Pointer to HBA context object. |
3861 | * | |
3862 | * This function resets the HBA by writing HC_INITFF to the control | |
3863 | * register. After the HBA resets, this function resets all the iocb ring | |
3864 | * indices. This function disables PCI layer parity checking during | |
3865 | * the reset. | |
3866 | * This function returns 0 always. | |
3867 | * The caller is not required to hold any locks. | |
3868 | **/ | |
41415862 | 3869 | int |
2e0fef85 | 3870 | lpfc_sli_brdreset(struct lpfc_hba *phba) |
dea3101e | 3871 | { |
41415862 | 3872 | struct lpfc_sli *psli; |
dea3101e | 3873 | struct lpfc_sli_ring *pring; |
41415862 | 3874 | uint16_t cfg_value; |
dea3101e | 3875 | int i; |
dea3101e | 3876 | |
41415862 | 3877 | psli = &phba->sli; |
dea3101e | 3878 | |
41415862 JW |
3879 | /* Reset HBA */ |
3880 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
e8b62011 | 3881 | "0325 Reset HBA Data: x%x x%x\n", |
2e0fef85 | 3882 | phba->pport->port_state, psli->sli_flag); |
dea3101e | 3883 | |
3884 | /* perform board reset */ | |
3885 | phba->fc_eventTag = 0; | |
4d9ab994 | 3886 | phba->link_events = 0; |
2e0fef85 JS |
3887 | phba->pport->fc_myDID = 0; |
3888 | phba->pport->fc_prevDID = 0; | |
dea3101e | 3889 | |
41415862 JW |
3890 | /* Turn off parity checking and serr during the physical reset */ |
3891 | pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value); | |
3892 | pci_write_config_word(phba->pcidev, PCI_COMMAND, | |
3893 | (cfg_value & | |
3894 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); | |
3895 | ||
3772a991 JS |
3896 | psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA); |
3897 | ||
41415862 JW |
3898 | /* Now toggle INITFF bit in the Host Control Register */ |
3899 | writel(HC_INITFF, phba->HCregaddr); | |
3900 | mdelay(1); | |
3901 | readl(phba->HCregaddr); /* flush */ | |
3902 | writel(0, phba->HCregaddr); | |
3903 | readl(phba->HCregaddr); /* flush */ | |
3904 | ||
3905 | /* Restore PCI cmd register */ | |
3906 | pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); | |
dea3101e | 3907 | |
3908 | /* Initialize relevant SLI info */ | |
41415862 JW |
3909 | for (i = 0; i < psli->num_rings; i++) { |
3910 | pring = &psli->ring[i]; | |
dea3101e | 3911 | pring->flag = 0; |
7e56aa25 JS |
3912 | pring->sli.sli3.rspidx = 0; |
3913 | pring->sli.sli3.next_cmdidx = 0; | |
3914 | pring->sli.sli3.local_getidx = 0; | |
3915 | pring->sli.sli3.cmdidx = 0; | |
dea3101e | 3916 | pring->missbufcnt = 0; |
3917 | } | |
dea3101e | 3918 | |
2e0fef85 | 3919 | phba->link_state = LPFC_WARM_START; |
41415862 JW |
3920 | return 0; |
3921 | } | |
3922 | ||
e59058c4 | 3923 | /** |
da0436e9 JS |
3924 | * lpfc_sli4_brdreset - Reset a sli-4 HBA |
3925 | * @phba: Pointer to HBA context object. | |
3926 | * | |
3927 | * This function resets a SLI4 HBA. This function disables PCI layer parity | |
3928 | * checking during resets the device. The caller is not required to hold | |
3929 | * any locks. | |
3930 | * | |
3931 | * This function returns 0 always. | |
3932 | **/ | |
3933 | int | |
3934 | lpfc_sli4_brdreset(struct lpfc_hba *phba) | |
3935 | { | |
3936 | struct lpfc_sli *psli = &phba->sli; | |
3937 | uint16_t cfg_value; | |
27b01b82 | 3938 | int rc; |
da0436e9 JS |
3939 | |
3940 | /* Reset HBA */ | |
3941 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
3942 | "0295 Reset HBA Data: x%x x%x\n", | |
3943 | phba->pport->port_state, psli->sli_flag); | |
3944 | ||
3945 | /* perform board reset */ | |
3946 | phba->fc_eventTag = 0; | |
4d9ab994 | 3947 | phba->link_events = 0; |
da0436e9 JS |
3948 | phba->pport->fc_myDID = 0; |
3949 | phba->pport->fc_prevDID = 0; | |
3950 | ||
da0436e9 JS |
3951 | spin_lock_irq(&phba->hbalock); |
3952 | psli->sli_flag &= ~(LPFC_PROCESS_LA); | |
3953 | phba->fcf.fcf_flag = 0; | |
da0436e9 JS |
3954 | spin_unlock_irq(&phba->hbalock); |
3955 | ||
3956 | /* Now physically reset the device */ | |
3957 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
3958 | "0389 Performing PCI function reset!\n"); | |
be858b65 JS |
3959 | |
3960 | /* Turn off parity checking and serr during the physical reset */ | |
3961 | pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value); | |
3962 | pci_write_config_word(phba->pcidev, PCI_COMMAND, (cfg_value & | |
3963 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); | |
3964 | ||
da0436e9 | 3965 | /* Perform FCoE PCI function reset */ |
2e90f4b5 | 3966 | lpfc_sli4_queue_destroy(phba); |
27b01b82 | 3967 | rc = lpfc_pci_function_reset(phba); |
da0436e9 | 3968 | |
be858b65 JS |
3969 | /* Restore PCI cmd register */ |
3970 | pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); | |
3971 | ||
27b01b82 | 3972 | return rc; |
da0436e9 JS |
3973 | } |
3974 | ||
3975 | /** | |
3976 | * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba | |
e59058c4 JS |
3977 | * @phba: Pointer to HBA context object. |
3978 | * | |
3979 | * This function is called in the SLI initialization code path to | |
3980 | * restart the HBA. The caller is not required to hold any lock. | |
3981 | * This function writes MBX_RESTART mailbox command to the SLIM and | |
3982 | * resets the HBA. At the end of the function, it calls lpfc_hba_down_post | |
3983 | * function to free any pending commands. The function enables | |
3984 | * POST only during the first initialization. The function returns zero. | |
3985 | * The function does not guarantee completion of MBX_RESTART mailbox | |
3986 | * command before the return of this function. | |
3987 | **/ | |
da0436e9 JS |
3988 | static int |
3989 | lpfc_sli_brdrestart_s3(struct lpfc_hba *phba) | |
41415862 JW |
3990 | { |
3991 | MAILBOX_t *mb; | |
3992 | struct lpfc_sli *psli; | |
41415862 JW |
3993 | volatile uint32_t word0; |
3994 | void __iomem *to_slim; | |
0d878419 | 3995 | uint32_t hba_aer_enabled; |
41415862 | 3996 | |
2e0fef85 | 3997 | spin_lock_irq(&phba->hbalock); |
41415862 | 3998 | |
0d878419 JS |
3999 | /* Take PCIe device Advanced Error Reporting (AER) state */ |
4000 | hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED; | |
4001 | ||
41415862 JW |
4002 | psli = &phba->sli; |
4003 | ||
4004 | /* Restart HBA */ | |
4005 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
e8b62011 | 4006 | "0337 Restart HBA Data: x%x x%x\n", |
2e0fef85 | 4007 | phba->pport->port_state, psli->sli_flag); |
41415862 JW |
4008 | |
4009 | word0 = 0; | |
4010 | mb = (MAILBOX_t *) &word0; | |
4011 | mb->mbxCommand = MBX_RESTART; | |
4012 | mb->mbxHc = 1; | |
4013 | ||
9290831f JS |
4014 | lpfc_reset_barrier(phba); |
4015 | ||
41415862 JW |
4016 | to_slim = phba->MBslimaddr; |
4017 | writel(*(uint32_t *) mb, to_slim); | |
4018 | readl(to_slim); /* flush */ | |
4019 | ||
4020 | /* Only skip post after fc_ffinit is completed */ | |
eaf15d5b | 4021 | if (phba->pport->port_state) |
41415862 | 4022 | word0 = 1; /* This is really setting up word1 */ |
eaf15d5b | 4023 | else |
41415862 | 4024 | word0 = 0; /* This is really setting up word1 */ |
65a29c16 | 4025 | to_slim = phba->MBslimaddr + sizeof (uint32_t); |
41415862 JW |
4026 | writel(*(uint32_t *) mb, to_slim); |
4027 | readl(to_slim); /* flush */ | |
dea3101e | 4028 | |
41415862 | 4029 | lpfc_sli_brdreset(phba); |
2e0fef85 JS |
4030 | phba->pport->stopped = 0; |
4031 | phba->link_state = LPFC_INIT_START; | |
da0436e9 | 4032 | phba->hba_flag = 0; |
2e0fef85 | 4033 | spin_unlock_irq(&phba->hbalock); |
41415862 | 4034 | |
64ba8818 JS |
4035 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); |
4036 | psli->stats_start = get_seconds(); | |
4037 | ||
eaf15d5b JS |
4038 | /* Give the INITFF and Post time to settle. */ |
4039 | mdelay(100); | |
41415862 | 4040 | |
0d878419 JS |
4041 | /* Reset HBA AER if it was enabled, note hba_flag was reset above */ |
4042 | if (hba_aer_enabled) | |
4043 | pci_disable_pcie_error_reporting(phba->pcidev); | |
4044 | ||
41415862 | 4045 | lpfc_hba_down_post(phba); |
dea3101e | 4046 | |
4047 | return 0; | |
4048 | } | |
4049 | ||
da0436e9 JS |
4050 | /** |
4051 | * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba | |
4052 | * @phba: Pointer to HBA context object. | |
4053 | * | |
4054 | * This function is called in the SLI initialization code path to restart | |
4055 | * a SLI4 HBA. The caller is not required to hold any lock. | |
4056 | * At the end of the function, it calls lpfc_hba_down_post function to | |
4057 | * free any pending commands. | |
4058 | **/ | |
4059 | static int | |
4060 | lpfc_sli_brdrestart_s4(struct lpfc_hba *phba) | |
4061 | { | |
4062 | struct lpfc_sli *psli = &phba->sli; | |
75baf696 | 4063 | uint32_t hba_aer_enabled; |
27b01b82 | 4064 | int rc; |
da0436e9 JS |
4065 | |
4066 | /* Restart HBA */ | |
4067 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
4068 | "0296 Restart HBA Data: x%x x%x\n", | |
4069 | phba->pport->port_state, psli->sli_flag); | |
4070 | ||
75baf696 JS |
4071 | /* Take PCIe device Advanced Error Reporting (AER) state */ |
4072 | hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED; | |
4073 | ||
27b01b82 | 4074 | rc = lpfc_sli4_brdreset(phba); |
da0436e9 JS |
4075 | |
4076 | spin_lock_irq(&phba->hbalock); | |
4077 | phba->pport->stopped = 0; | |
4078 | phba->link_state = LPFC_INIT_START; | |
4079 | phba->hba_flag = 0; | |
4080 | spin_unlock_irq(&phba->hbalock); | |
4081 | ||
4082 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); | |
4083 | psli->stats_start = get_seconds(); | |
4084 | ||
75baf696 JS |
4085 | /* Reset HBA AER if it was enabled, note hba_flag was reset above */ |
4086 | if (hba_aer_enabled) | |
4087 | pci_disable_pcie_error_reporting(phba->pcidev); | |
4088 | ||
da0436e9 JS |
4089 | lpfc_hba_down_post(phba); |
4090 | ||
27b01b82 | 4091 | return rc; |
da0436e9 JS |
4092 | } |
4093 | ||
4094 | /** | |
4095 | * lpfc_sli_brdrestart - Wrapper func for restarting hba | |
4096 | * @phba: Pointer to HBA context object. | |
4097 | * | |
4098 | * This routine wraps the actual SLI3 or SLI4 hba restart routine from the | |
4099 | * API jump table function pointer from the lpfc_hba struct. | |
4100 | **/ | |
4101 | int | |
4102 | lpfc_sli_brdrestart(struct lpfc_hba *phba) | |
4103 | { | |
4104 | return phba->lpfc_sli_brdrestart(phba); | |
4105 | } | |
4106 | ||
e59058c4 | 4107 | /** |
3621a710 | 4108 | * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart |
e59058c4 JS |
4109 | * @phba: Pointer to HBA context object. |
4110 | * | |
4111 | * This function is called after a HBA restart to wait for successful | |
4112 | * restart of the HBA. Successful restart of the HBA is indicated by | |
4113 | * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15 | |
4114 | * iteration, the function will restart the HBA again. The function returns | |
4115 | * zero if HBA successfully restarted else returns negative error code. | |
4116 | **/ | |
dea3101e | 4117 | static int |
4118 | lpfc_sli_chipset_init(struct lpfc_hba *phba) | |
4119 | { | |
4120 | uint32_t status, i = 0; | |
4121 | ||
4122 | /* Read the HBA Host Status Register */ | |
9940b97b JS |
4123 | if (lpfc_readl(phba->HSregaddr, &status)) |
4124 | return -EIO; | |
dea3101e | 4125 | |
4126 | /* Check status register to see what current state is */ | |
4127 | i = 0; | |
4128 | while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) { | |
4129 | ||
dcf2a4e0 JS |
4130 | /* Check every 10ms for 10 retries, then every 100ms for 90 |
4131 | * retries, then every 1 sec for 50 retires for a total of | |
4132 | * ~60 seconds before reset the board again and check every | |
4133 | * 1 sec for 50 retries. The up to 60 seconds before the | |
4134 | * board ready is required by the Falcon FIPS zeroization | |
4135 | * complete, and any reset the board in between shall cause | |
4136 | * restart of zeroization, further delay the board ready. | |
dea3101e | 4137 | */ |
dcf2a4e0 | 4138 | if (i++ >= 200) { |
dea3101e | 4139 | /* Adapter failed to init, timeout, status reg |
4140 | <status> */ | |
ed957684 | 4141 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 4142 | "0436 Adapter failed to init, " |
09372820 JS |
4143 | "timeout, status reg x%x, " |
4144 | "FW Data: A8 x%x AC x%x\n", status, | |
4145 | readl(phba->MBslimaddr + 0xa8), | |
4146 | readl(phba->MBslimaddr + 0xac)); | |
2e0fef85 | 4147 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e | 4148 | return -ETIMEDOUT; |
4149 | } | |
4150 | ||
4151 | /* Check to see if any errors occurred during init */ | |
4152 | if (status & HS_FFERM) { | |
4153 | /* ERROR: During chipset initialization */ | |
4154 | /* Adapter failed to init, chipset, status reg | |
4155 | <status> */ | |
ed957684 | 4156 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 4157 | "0437 Adapter failed to init, " |
09372820 JS |
4158 | "chipset, status reg x%x, " |
4159 | "FW Data: A8 x%x AC x%x\n", status, | |
4160 | readl(phba->MBslimaddr + 0xa8), | |
4161 | readl(phba->MBslimaddr + 0xac)); | |
2e0fef85 | 4162 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e | 4163 | return -EIO; |
4164 | } | |
4165 | ||
dcf2a4e0 | 4166 | if (i <= 10) |
dea3101e | 4167 | msleep(10); |
dcf2a4e0 JS |
4168 | else if (i <= 100) |
4169 | msleep(100); | |
4170 | else | |
4171 | msleep(1000); | |
dea3101e | 4172 | |
dcf2a4e0 JS |
4173 | if (i == 150) { |
4174 | /* Do post */ | |
92d7f7b0 | 4175 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
41415862 | 4176 | lpfc_sli_brdrestart(phba); |
dea3101e | 4177 | } |
4178 | /* Read the HBA Host Status Register */ | |
9940b97b JS |
4179 | if (lpfc_readl(phba->HSregaddr, &status)) |
4180 | return -EIO; | |
dea3101e | 4181 | } |
4182 | ||
4183 | /* Check to see if any errors occurred during init */ | |
4184 | if (status & HS_FFERM) { | |
4185 | /* ERROR: During chipset initialization */ | |
4186 | /* Adapter failed to init, chipset, status reg <status> */ | |
ed957684 | 4187 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 4188 | "0438 Adapter failed to init, chipset, " |
09372820 JS |
4189 | "status reg x%x, " |
4190 | "FW Data: A8 x%x AC x%x\n", status, | |
4191 | readl(phba->MBslimaddr + 0xa8), | |
4192 | readl(phba->MBslimaddr + 0xac)); | |
2e0fef85 | 4193 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e | 4194 | return -EIO; |
4195 | } | |
4196 | ||
4197 | /* Clear all interrupt enable conditions */ | |
4198 | writel(0, phba->HCregaddr); | |
4199 | readl(phba->HCregaddr); /* flush */ | |
4200 | ||
4201 | /* setup host attn register */ | |
4202 | writel(0xffffffff, phba->HAregaddr); | |
4203 | readl(phba->HAregaddr); /* flush */ | |
4204 | return 0; | |
4205 | } | |
4206 | ||
e59058c4 | 4207 | /** |
3621a710 | 4208 | * lpfc_sli_hbq_count - Get the number of HBQs to be configured |
e59058c4 JS |
4209 | * |
4210 | * This function calculates and returns the number of HBQs required to be | |
4211 | * configured. | |
4212 | **/ | |
78b2d852 | 4213 | int |
ed957684 JS |
4214 | lpfc_sli_hbq_count(void) |
4215 | { | |
92d7f7b0 | 4216 | return ARRAY_SIZE(lpfc_hbq_defs); |
ed957684 JS |
4217 | } |
4218 | ||
e59058c4 | 4219 | /** |
3621a710 | 4220 | * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries |
e59058c4 JS |
4221 | * |
4222 | * This function adds the number of hbq entries in every HBQ to get | |
4223 | * the total number of hbq entries required for the HBA and returns | |
4224 | * the total count. | |
4225 | **/ | |
ed957684 JS |
4226 | static int |
4227 | lpfc_sli_hbq_entry_count(void) | |
4228 | { | |
4229 | int hbq_count = lpfc_sli_hbq_count(); | |
4230 | int count = 0; | |
4231 | int i; | |
4232 | ||
4233 | for (i = 0; i < hbq_count; ++i) | |
92d7f7b0 | 4234 | count += lpfc_hbq_defs[i]->entry_count; |
ed957684 JS |
4235 | return count; |
4236 | } | |
4237 | ||
e59058c4 | 4238 | /** |
3621a710 | 4239 | * lpfc_sli_hbq_size - Calculate memory required for all hbq entries |
e59058c4 JS |
4240 | * |
4241 | * This function calculates amount of memory required for all hbq entries | |
4242 | * to be configured and returns the total memory required. | |
4243 | **/ | |
dea3101e | 4244 | int |
ed957684 JS |
4245 | lpfc_sli_hbq_size(void) |
4246 | { | |
4247 | return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry); | |
4248 | } | |
4249 | ||
e59058c4 | 4250 | /** |
3621a710 | 4251 | * lpfc_sli_hbq_setup - configure and initialize HBQs |
e59058c4 JS |
4252 | * @phba: Pointer to HBA context object. |
4253 | * | |
4254 | * This function is called during the SLI initialization to configure | |
4255 | * all the HBQs and post buffers to the HBQ. The caller is not | |
4256 | * required to hold any locks. This function will return zero if successful | |
4257 | * else it will return negative error code. | |
4258 | **/ | |
ed957684 JS |
4259 | static int |
4260 | lpfc_sli_hbq_setup(struct lpfc_hba *phba) | |
4261 | { | |
4262 | int hbq_count = lpfc_sli_hbq_count(); | |
4263 | LPFC_MBOXQ_t *pmb; | |
4264 | MAILBOX_t *pmbox; | |
4265 | uint32_t hbqno; | |
4266 | uint32_t hbq_entry_index; | |
ed957684 | 4267 | |
92d7f7b0 JS |
4268 | /* Get a Mailbox buffer to setup mailbox |
4269 | * commands for HBA initialization | |
4270 | */ | |
ed957684 JS |
4271 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
4272 | ||
4273 | if (!pmb) | |
4274 | return -ENOMEM; | |
4275 | ||
04c68496 | 4276 | pmbox = &pmb->u.mb; |
ed957684 JS |
4277 | |
4278 | /* Initialize the struct lpfc_sli_hbq structure for each hbq */ | |
4279 | phba->link_state = LPFC_INIT_MBX_CMDS; | |
3163f725 | 4280 | phba->hbq_in_use = 1; |
ed957684 JS |
4281 | |
4282 | hbq_entry_index = 0; | |
4283 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) { | |
4284 | phba->hbqs[hbqno].next_hbqPutIdx = 0; | |
4285 | phba->hbqs[hbqno].hbqPutIdx = 0; | |
4286 | phba->hbqs[hbqno].local_hbqGetIdx = 0; | |
4287 | phba->hbqs[hbqno].entry_count = | |
92d7f7b0 | 4288 | lpfc_hbq_defs[hbqno]->entry_count; |
51ef4c26 JS |
4289 | lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno], |
4290 | hbq_entry_index, pmb); | |
ed957684 JS |
4291 | hbq_entry_index += phba->hbqs[hbqno].entry_count; |
4292 | ||
4293 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { | |
4294 | /* Adapter failed to init, mbxCmd <cmd> CFG_RING, | |
4295 | mbxStatus <status>, ring <num> */ | |
4296 | ||
4297 | lpfc_printf_log(phba, KERN_ERR, | |
92d7f7b0 | 4298 | LOG_SLI | LOG_VPORT, |
e8b62011 | 4299 | "1805 Adapter failed to init. " |
ed957684 | 4300 | "Data: x%x x%x x%x\n", |
e8b62011 | 4301 | pmbox->mbxCommand, |
ed957684 JS |
4302 | pmbox->mbxStatus, hbqno); |
4303 | ||
4304 | phba->link_state = LPFC_HBA_ERROR; | |
4305 | mempool_free(pmb, phba->mbox_mem_pool); | |
6e7288d9 | 4306 | return -ENXIO; |
ed957684 JS |
4307 | } |
4308 | } | |
4309 | phba->hbq_count = hbq_count; | |
4310 | ||
ed957684 JS |
4311 | mempool_free(pmb, phba->mbox_mem_pool); |
4312 | ||
92d7f7b0 | 4313 | /* Initially populate or replenish the HBQs */ |
d7c255b2 JS |
4314 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) |
4315 | lpfc_sli_hbqbuf_init_hbqs(phba, hbqno); | |
ed957684 JS |
4316 | return 0; |
4317 | } | |
4318 | ||
4f774513 JS |
4319 | /** |
4320 | * lpfc_sli4_rb_setup - Initialize and post RBs to HBA | |
4321 | * @phba: Pointer to HBA context object. | |
4322 | * | |
4323 | * This function is called during the SLI initialization to configure | |
4324 | * all the HBQs and post buffers to the HBQ. The caller is not | |
4325 | * required to hold any locks. This function will return zero if successful | |
4326 | * else it will return negative error code. | |
4327 | **/ | |
4328 | static int | |
4329 | lpfc_sli4_rb_setup(struct lpfc_hba *phba) | |
4330 | { | |
4331 | phba->hbq_in_use = 1; | |
4332 | phba->hbqs[0].entry_count = lpfc_hbq_defs[0]->entry_count; | |
4333 | phba->hbq_count = 1; | |
4334 | /* Initially populate or replenish the HBQs */ | |
4335 | lpfc_sli_hbqbuf_init_hbqs(phba, 0); | |
4336 | return 0; | |
4337 | } | |
4338 | ||
e59058c4 | 4339 | /** |
3621a710 | 4340 | * lpfc_sli_config_port - Issue config port mailbox command |
e59058c4 JS |
4341 | * @phba: Pointer to HBA context object. |
4342 | * @sli_mode: sli mode - 2/3 | |
4343 | * | |
4344 | * This function is called by the sli intialization code path | |
4345 | * to issue config_port mailbox command. This function restarts the | |
4346 | * HBA firmware and issues a config_port mailbox command to configure | |
4347 | * the SLI interface in the sli mode specified by sli_mode | |
4348 | * variable. The caller is not required to hold any locks. | |
4349 | * The function returns 0 if successful, else returns negative error | |
4350 | * code. | |
4351 | **/ | |
9399627f JS |
4352 | int |
4353 | lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode) | |
dea3101e | 4354 | { |
4355 | LPFC_MBOXQ_t *pmb; | |
4356 | uint32_t resetcount = 0, rc = 0, done = 0; | |
4357 | ||
4358 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
4359 | if (!pmb) { | |
2e0fef85 | 4360 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e | 4361 | return -ENOMEM; |
4362 | } | |
4363 | ||
ed957684 | 4364 | phba->sli_rev = sli_mode; |
dea3101e | 4365 | while (resetcount < 2 && !done) { |
2e0fef85 | 4366 | spin_lock_irq(&phba->hbalock); |
1c067a42 | 4367 | phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
2e0fef85 | 4368 | spin_unlock_irq(&phba->hbalock); |
92d7f7b0 | 4369 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
41415862 | 4370 | lpfc_sli_brdrestart(phba); |
dea3101e | 4371 | rc = lpfc_sli_chipset_init(phba); |
4372 | if (rc) | |
4373 | break; | |
4374 | ||
2e0fef85 | 4375 | spin_lock_irq(&phba->hbalock); |
1c067a42 | 4376 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
2e0fef85 | 4377 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 4378 | resetcount++; |
4379 | ||
ed957684 JS |
4380 | /* Call pre CONFIG_PORT mailbox command initialization. A |
4381 | * value of 0 means the call was successful. Any other | |
4382 | * nonzero value is a failure, but if ERESTART is returned, | |
4383 | * the driver may reset the HBA and try again. | |
4384 | */ | |
dea3101e | 4385 | rc = lpfc_config_port_prep(phba); |
4386 | if (rc == -ERESTART) { | |
ed957684 | 4387 | phba->link_state = LPFC_LINK_UNKNOWN; |
dea3101e | 4388 | continue; |
34b02dcd | 4389 | } else if (rc) |
dea3101e | 4390 | break; |
6d368e53 | 4391 | |
2e0fef85 | 4392 | phba->link_state = LPFC_INIT_MBX_CMDS; |
dea3101e | 4393 | lpfc_config_port(phba, pmb); |
4394 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); | |
34b02dcd JS |
4395 | phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED | |
4396 | LPFC_SLI3_HBQ_ENABLED | | |
4397 | LPFC_SLI3_CRP_ENABLED | | |
bc73905a JS |
4398 | LPFC_SLI3_BG_ENABLED | |
4399 | LPFC_SLI3_DSS_ENABLED); | |
ed957684 | 4400 | if (rc != MBX_SUCCESS) { |
dea3101e | 4401 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 4402 | "0442 Adapter failed to init, mbxCmd x%x " |
92d7f7b0 | 4403 | "CONFIG_PORT, mbxStatus x%x Data: x%x\n", |
04c68496 | 4404 | pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0); |
2e0fef85 | 4405 | spin_lock_irq(&phba->hbalock); |
04c68496 | 4406 | phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE; |
2e0fef85 JS |
4407 | spin_unlock_irq(&phba->hbalock); |
4408 | rc = -ENXIO; | |
04c68496 JS |
4409 | } else { |
4410 | /* Allow asynchronous mailbox command to go through */ | |
4411 | spin_lock_irq(&phba->hbalock); | |
4412 | phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; | |
4413 | spin_unlock_irq(&phba->hbalock); | |
ed957684 | 4414 | done = 1; |
cb69f7de JS |
4415 | |
4416 | if ((pmb->u.mb.un.varCfgPort.casabt == 1) && | |
4417 | (pmb->u.mb.un.varCfgPort.gasabt == 0)) | |
4418 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
4419 | "3110 Port did not grant ASABT\n"); | |
04c68496 | 4420 | } |
dea3101e | 4421 | } |
ed957684 JS |
4422 | if (!done) { |
4423 | rc = -EINVAL; | |
4424 | goto do_prep_failed; | |
4425 | } | |
04c68496 JS |
4426 | if (pmb->u.mb.un.varCfgPort.sli_mode == 3) { |
4427 | if (!pmb->u.mb.un.varCfgPort.cMA) { | |
34b02dcd JS |
4428 | rc = -ENXIO; |
4429 | goto do_prep_failed; | |
4430 | } | |
04c68496 | 4431 | if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) { |
34b02dcd | 4432 | phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED; |
04c68496 JS |
4433 | phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi; |
4434 | phba->max_vports = (phba->max_vpi > phba->max_vports) ? | |
4435 | phba->max_vpi : phba->max_vports; | |
4436 | ||
34b02dcd JS |
4437 | } else |
4438 | phba->max_vpi = 0; | |
bc73905a JS |
4439 | phba->fips_level = 0; |
4440 | phba->fips_spec_rev = 0; | |
4441 | if (pmb->u.mb.un.varCfgPort.gdss) { | |
04c68496 | 4442 | phba->sli3_options |= LPFC_SLI3_DSS_ENABLED; |
bc73905a JS |
4443 | phba->fips_level = pmb->u.mb.un.varCfgPort.fips_level; |
4444 | phba->fips_spec_rev = pmb->u.mb.un.varCfgPort.fips_rev; | |
4445 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
4446 | "2850 Security Crypto Active. FIPS x%d " | |
4447 | "(Spec Rev: x%d)", | |
4448 | phba->fips_level, phba->fips_spec_rev); | |
4449 | } | |
4450 | if (pmb->u.mb.un.varCfgPort.sec_err) { | |
4451 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4452 | "2856 Config Port Security Crypto " | |
4453 | "Error: x%x ", | |
4454 | pmb->u.mb.un.varCfgPort.sec_err); | |
4455 | } | |
04c68496 | 4456 | if (pmb->u.mb.un.varCfgPort.gerbm) |
34b02dcd | 4457 | phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED; |
04c68496 | 4458 | if (pmb->u.mb.un.varCfgPort.gcrp) |
34b02dcd | 4459 | phba->sli3_options |= LPFC_SLI3_CRP_ENABLED; |
6e7288d9 JS |
4460 | |
4461 | phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get; | |
4462 | phba->port_gp = phba->mbox->us.s3_pgp.port; | |
e2a0a9d6 JS |
4463 | |
4464 | if (phba->cfg_enable_bg) { | |
04c68496 | 4465 | if (pmb->u.mb.un.varCfgPort.gbg) |
e2a0a9d6 JS |
4466 | phba->sli3_options |= LPFC_SLI3_BG_ENABLED; |
4467 | else | |
4468 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4469 | "0443 Adapter did not grant " | |
4470 | "BlockGuard\n"); | |
4471 | } | |
34b02dcd | 4472 | } else { |
8f34f4ce | 4473 | phba->hbq_get = NULL; |
34b02dcd | 4474 | phba->port_gp = phba->mbox->us.s2.port; |
d7c255b2 | 4475 | phba->max_vpi = 0; |
ed957684 | 4476 | } |
92d7f7b0 | 4477 | do_prep_failed: |
ed957684 JS |
4478 | mempool_free(pmb, phba->mbox_mem_pool); |
4479 | return rc; | |
4480 | } | |
4481 | ||
e59058c4 JS |
4482 | |
4483 | /** | |
3621a710 | 4484 | * lpfc_sli_hba_setup - SLI intialization function |
e59058c4 JS |
4485 | * @phba: Pointer to HBA context object. |
4486 | * | |
4487 | * This function is the main SLI intialization function. This function | |
4488 | * is called by the HBA intialization code, HBA reset code and HBA | |
4489 | * error attention handler code. Caller is not required to hold any | |
4490 | * locks. This function issues config_port mailbox command to configure | |
4491 | * the SLI, setup iocb rings and HBQ rings. In the end the function | |
4492 | * calls the config_port_post function to issue init_link mailbox | |
4493 | * command and to start the discovery. The function will return zero | |
4494 | * if successful, else it will return negative error code. | |
4495 | **/ | |
ed957684 JS |
4496 | int |
4497 | lpfc_sli_hba_setup(struct lpfc_hba *phba) | |
4498 | { | |
4499 | uint32_t rc; | |
6d368e53 JS |
4500 | int mode = 3, i; |
4501 | int longs; | |
ed957684 JS |
4502 | |
4503 | switch (lpfc_sli_mode) { | |
4504 | case 2: | |
78b2d852 | 4505 | if (phba->cfg_enable_npiv) { |
92d7f7b0 | 4506 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
e8b62011 | 4507 | "1824 NPIV enabled: Override lpfc_sli_mode " |
92d7f7b0 | 4508 | "parameter (%d) to auto (0).\n", |
e8b62011 | 4509 | lpfc_sli_mode); |
92d7f7b0 JS |
4510 | break; |
4511 | } | |
ed957684 JS |
4512 | mode = 2; |
4513 | break; | |
4514 | case 0: | |
4515 | case 3: | |
4516 | break; | |
4517 | default: | |
92d7f7b0 | 4518 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
e8b62011 JS |
4519 | "1819 Unrecognized lpfc_sli_mode " |
4520 | "parameter: %d.\n", lpfc_sli_mode); | |
ed957684 JS |
4521 | |
4522 | break; | |
4523 | } | |
4524 | ||
9399627f JS |
4525 | rc = lpfc_sli_config_port(phba, mode); |
4526 | ||
ed957684 | 4527 | if (rc && lpfc_sli_mode == 3) |
92d7f7b0 | 4528 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
e8b62011 JS |
4529 | "1820 Unable to select SLI-3. " |
4530 | "Not supported by adapter.\n"); | |
ed957684 | 4531 | if (rc && mode != 2) |
9399627f | 4532 | rc = lpfc_sli_config_port(phba, 2); |
ed957684 | 4533 | if (rc) |
dea3101e | 4534 | goto lpfc_sli_hba_setup_error; |
4535 | ||
0d878419 JS |
4536 | /* Enable PCIe device Advanced Error Reporting (AER) if configured */ |
4537 | if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) { | |
4538 | rc = pci_enable_pcie_error_reporting(phba->pcidev); | |
4539 | if (!rc) { | |
4540 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
4541 | "2709 This device supports " | |
4542 | "Advanced Error Reporting (AER)\n"); | |
4543 | spin_lock_irq(&phba->hbalock); | |
4544 | phba->hba_flag |= HBA_AER_ENABLED; | |
4545 | spin_unlock_irq(&phba->hbalock); | |
4546 | } else { | |
4547 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
4548 | "2708 This device does not support " | |
4549 | "Advanced Error Reporting (AER)\n"); | |
4550 | phba->cfg_aer_support = 0; | |
4551 | } | |
4552 | } | |
4553 | ||
ed957684 JS |
4554 | if (phba->sli_rev == 3) { |
4555 | phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE; | |
4556 | phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE; | |
ed957684 JS |
4557 | } else { |
4558 | phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE; | |
4559 | phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE; | |
92d7f7b0 | 4560 | phba->sli3_options = 0; |
ed957684 JS |
4561 | } |
4562 | ||
4563 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
e8b62011 JS |
4564 | "0444 Firmware in SLI %x mode. Max_vpi %d\n", |
4565 | phba->sli_rev, phba->max_vpi); | |
ed957684 | 4566 | rc = lpfc_sli_ring_map(phba); |
dea3101e | 4567 | |
4568 | if (rc) | |
4569 | goto lpfc_sli_hba_setup_error; | |
4570 | ||
6d368e53 JS |
4571 | /* Initialize VPIs. */ |
4572 | if (phba->sli_rev == LPFC_SLI_REV3) { | |
4573 | /* | |
4574 | * The VPI bitmask and physical ID array are allocated | |
4575 | * and initialized once only - at driver load. A port | |
4576 | * reset doesn't need to reinitialize this memory. | |
4577 | */ | |
4578 | if ((phba->vpi_bmask == NULL) && (phba->vpi_ids == NULL)) { | |
4579 | longs = (phba->max_vpi + BITS_PER_LONG) / BITS_PER_LONG; | |
4580 | phba->vpi_bmask = kzalloc(longs * sizeof(unsigned long), | |
4581 | GFP_KERNEL); | |
4582 | if (!phba->vpi_bmask) { | |
4583 | rc = -ENOMEM; | |
4584 | goto lpfc_sli_hba_setup_error; | |
4585 | } | |
4586 | ||
4587 | phba->vpi_ids = kzalloc( | |
4588 | (phba->max_vpi+1) * sizeof(uint16_t), | |
4589 | GFP_KERNEL); | |
4590 | if (!phba->vpi_ids) { | |
4591 | kfree(phba->vpi_bmask); | |
4592 | rc = -ENOMEM; | |
4593 | goto lpfc_sli_hba_setup_error; | |
4594 | } | |
4595 | for (i = 0; i < phba->max_vpi; i++) | |
4596 | phba->vpi_ids[i] = i; | |
4597 | } | |
4598 | } | |
4599 | ||
9399627f | 4600 | /* Init HBQs */ |
ed957684 JS |
4601 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
4602 | rc = lpfc_sli_hbq_setup(phba); | |
4603 | if (rc) | |
4604 | goto lpfc_sli_hba_setup_error; | |
4605 | } | |
04c68496 | 4606 | spin_lock_irq(&phba->hbalock); |
dea3101e | 4607 | phba->sli.sli_flag |= LPFC_PROCESS_LA; |
04c68496 | 4608 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 4609 | |
4610 | rc = lpfc_config_port_post(phba); | |
4611 | if (rc) | |
4612 | goto lpfc_sli_hba_setup_error; | |
4613 | ||
ed957684 JS |
4614 | return rc; |
4615 | ||
92d7f7b0 | 4616 | lpfc_sli_hba_setup_error: |
2e0fef85 | 4617 | phba->link_state = LPFC_HBA_ERROR; |
e40a02c1 | 4618 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 4619 | "0445 Firmware initialization failed\n"); |
dea3101e | 4620 | return rc; |
4621 | } | |
4622 | ||
e59058c4 | 4623 | /** |
da0436e9 JS |
4624 | * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region |
4625 | * @phba: Pointer to HBA context object. | |
4626 | * @mboxq: mailbox pointer. | |
4627 | * This function issue a dump mailbox command to read config region | |
4628 | * 23 and parse the records in the region and populate driver | |
4629 | * data structure. | |
e59058c4 | 4630 | **/ |
da0436e9 | 4631 | static int |
ff78d8f9 | 4632 | lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba) |
dea3101e | 4633 | { |
ff78d8f9 | 4634 | LPFC_MBOXQ_t *mboxq; |
da0436e9 JS |
4635 | struct lpfc_dmabuf *mp; |
4636 | struct lpfc_mqe *mqe; | |
4637 | uint32_t data_length; | |
4638 | int rc; | |
dea3101e | 4639 | |
da0436e9 JS |
4640 | /* Program the default value of vlan_id and fc_map */ |
4641 | phba->valid_vlan = 0; | |
4642 | phba->fc_map[0] = LPFC_FCOE_FCF_MAP0; | |
4643 | phba->fc_map[1] = LPFC_FCOE_FCF_MAP1; | |
4644 | phba->fc_map[2] = LPFC_FCOE_FCF_MAP2; | |
2e0fef85 | 4645 | |
ff78d8f9 JS |
4646 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
4647 | if (!mboxq) | |
da0436e9 JS |
4648 | return -ENOMEM; |
4649 | ||
ff78d8f9 JS |
4650 | mqe = &mboxq->u.mqe; |
4651 | if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) { | |
4652 | rc = -ENOMEM; | |
4653 | goto out_free_mboxq; | |
4654 | } | |
4655 | ||
da0436e9 JS |
4656 | mp = (struct lpfc_dmabuf *) mboxq->context1; |
4657 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
4658 | ||
4659 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, | |
4660 | "(%d):2571 Mailbox cmd x%x Status x%x " | |
4661 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x " | |
4662 | "x%x x%x x%x x%x x%x x%x x%x x%x x%x " | |
4663 | "CQ: x%x x%x x%x x%x\n", | |
4664 | mboxq->vport ? mboxq->vport->vpi : 0, | |
4665 | bf_get(lpfc_mqe_command, mqe), | |
4666 | bf_get(lpfc_mqe_status, mqe), | |
4667 | mqe->un.mb_words[0], mqe->un.mb_words[1], | |
4668 | mqe->un.mb_words[2], mqe->un.mb_words[3], | |
4669 | mqe->un.mb_words[4], mqe->un.mb_words[5], | |
4670 | mqe->un.mb_words[6], mqe->un.mb_words[7], | |
4671 | mqe->un.mb_words[8], mqe->un.mb_words[9], | |
4672 | mqe->un.mb_words[10], mqe->un.mb_words[11], | |
4673 | mqe->un.mb_words[12], mqe->un.mb_words[13], | |
4674 | mqe->un.mb_words[14], mqe->un.mb_words[15], | |
4675 | mqe->un.mb_words[16], mqe->un.mb_words[50], | |
4676 | mboxq->mcqe.word0, | |
4677 | mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1, | |
4678 | mboxq->mcqe.trailer); | |
4679 | ||
4680 | if (rc) { | |
4681 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
4682 | kfree(mp); | |
ff78d8f9 JS |
4683 | rc = -EIO; |
4684 | goto out_free_mboxq; | |
da0436e9 JS |
4685 | } |
4686 | data_length = mqe->un.mb_words[5]; | |
a0c87cbd | 4687 | if (data_length > DMP_RGN23_SIZE) { |
d11e31dd JS |
4688 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
4689 | kfree(mp); | |
ff78d8f9 JS |
4690 | rc = -EIO; |
4691 | goto out_free_mboxq; | |
d11e31dd | 4692 | } |
dea3101e | 4693 | |
da0436e9 JS |
4694 | lpfc_parse_fcoe_conf(phba, mp->virt, data_length); |
4695 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
4696 | kfree(mp); | |
ff78d8f9 JS |
4697 | rc = 0; |
4698 | ||
4699 | out_free_mboxq: | |
4700 | mempool_free(mboxq, phba->mbox_mem_pool); | |
4701 | return rc; | |
da0436e9 | 4702 | } |
e59058c4 JS |
4703 | |
4704 | /** | |
da0436e9 JS |
4705 | * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data |
4706 | * @phba: pointer to lpfc hba data structure. | |
4707 | * @mboxq: pointer to the LPFC_MBOXQ_t structure. | |
4708 | * @vpd: pointer to the memory to hold resulting port vpd data. | |
4709 | * @vpd_size: On input, the number of bytes allocated to @vpd. | |
4710 | * On output, the number of data bytes in @vpd. | |
e59058c4 | 4711 | * |
da0436e9 JS |
4712 | * This routine executes a READ_REV SLI4 mailbox command. In |
4713 | * addition, this routine gets the port vpd data. | |
4714 | * | |
4715 | * Return codes | |
af901ca1 | 4716 | * 0 - successful |
d439d286 | 4717 | * -ENOMEM - could not allocated memory. |
e59058c4 | 4718 | **/ |
da0436e9 JS |
4719 | static int |
4720 | lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, | |
4721 | uint8_t *vpd, uint32_t *vpd_size) | |
dea3101e | 4722 | { |
da0436e9 JS |
4723 | int rc = 0; |
4724 | uint32_t dma_size; | |
4725 | struct lpfc_dmabuf *dmabuf; | |
4726 | struct lpfc_mqe *mqe; | |
dea3101e | 4727 | |
da0436e9 JS |
4728 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
4729 | if (!dmabuf) | |
4730 | return -ENOMEM; | |
4731 | ||
4732 | /* | |
4733 | * Get a DMA buffer for the vpd data resulting from the READ_REV | |
4734 | * mailbox command. | |
a257bf90 | 4735 | */ |
da0436e9 JS |
4736 | dma_size = *vpd_size; |
4737 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, | |
4738 | dma_size, | |
4739 | &dmabuf->phys, | |
4740 | GFP_KERNEL); | |
4741 | if (!dmabuf->virt) { | |
4742 | kfree(dmabuf); | |
4743 | return -ENOMEM; | |
a257bf90 | 4744 | } |
da0436e9 | 4745 | memset(dmabuf->virt, 0, dma_size); |
a257bf90 | 4746 | |
da0436e9 JS |
4747 | /* |
4748 | * The SLI4 implementation of READ_REV conflicts at word1, | |
4749 | * bits 31:16 and SLI4 adds vpd functionality not present | |
4750 | * in SLI3. This code corrects the conflicts. | |
1dcb58e5 | 4751 | */ |
da0436e9 JS |
4752 | lpfc_read_rev(phba, mboxq); |
4753 | mqe = &mboxq->u.mqe; | |
4754 | mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys); | |
4755 | mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys); | |
4756 | mqe->un.read_rev.word1 &= 0x0000FFFF; | |
4757 | bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1); | |
4758 | bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size); | |
4759 | ||
4760 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
4761 | if (rc) { | |
4762 | dma_free_coherent(&phba->pcidev->dev, dma_size, | |
4763 | dmabuf->virt, dmabuf->phys); | |
def9c7a9 | 4764 | kfree(dmabuf); |
da0436e9 JS |
4765 | return -EIO; |
4766 | } | |
1dcb58e5 | 4767 | |
da0436e9 JS |
4768 | /* |
4769 | * The available vpd length cannot be bigger than the | |
4770 | * DMA buffer passed to the port. Catch the less than | |
4771 | * case and update the caller's size. | |
4772 | */ | |
4773 | if (mqe->un.read_rev.avail_vpd_len < *vpd_size) | |
4774 | *vpd_size = mqe->un.read_rev.avail_vpd_len; | |
3772a991 | 4775 | |
d7c47992 JS |
4776 | memcpy(vpd, dmabuf->virt, *vpd_size); |
4777 | ||
da0436e9 JS |
4778 | dma_free_coherent(&phba->pcidev->dev, dma_size, |
4779 | dmabuf->virt, dmabuf->phys); | |
4780 | kfree(dmabuf); | |
4781 | return 0; | |
dea3101e | 4782 | } |
4783 | ||
cd1c8301 JS |
4784 | /** |
4785 | * lpfc_sli4_retrieve_pport_name - Retrieve SLI4 device physical port name | |
4786 | * @phba: pointer to lpfc hba data structure. | |
4787 | * | |
4788 | * This routine retrieves SLI4 device physical port name this PCI function | |
4789 | * is attached to. | |
4790 | * | |
4791 | * Return codes | |
4792 | * 0 - sucessful | |
4793 | * otherwise - failed to retrieve physical port name | |
4794 | **/ | |
4795 | static int | |
4796 | lpfc_sli4_retrieve_pport_name(struct lpfc_hba *phba) | |
4797 | { | |
4798 | LPFC_MBOXQ_t *mboxq; | |
cd1c8301 JS |
4799 | struct lpfc_mbx_get_cntl_attributes *mbx_cntl_attr; |
4800 | struct lpfc_controller_attribute *cntl_attr; | |
4801 | struct lpfc_mbx_get_port_name *get_port_name; | |
4802 | void *virtaddr = NULL; | |
4803 | uint32_t alloclen, reqlen; | |
4804 | uint32_t shdr_status, shdr_add_status; | |
4805 | union lpfc_sli4_cfg_shdr *shdr; | |
4806 | char cport_name = 0; | |
4807 | int rc; | |
4808 | ||
4809 | /* We assume nothing at this point */ | |
4810 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL; | |
4811 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_NON; | |
4812 | ||
4813 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
4814 | if (!mboxq) | |
4815 | return -ENOMEM; | |
cd1c8301 | 4816 | /* obtain link type and link number via READ_CONFIG */ |
ff78d8f9 JS |
4817 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL; |
4818 | lpfc_sli4_read_config(phba); | |
4819 | if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) | |
4820 | goto retrieve_ppname; | |
cd1c8301 JS |
4821 | |
4822 | /* obtain link type and link number via COMMON_GET_CNTL_ATTRIBUTES */ | |
4823 | reqlen = sizeof(struct lpfc_mbx_get_cntl_attributes); | |
4824 | alloclen = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, | |
4825 | LPFC_MBOX_OPCODE_GET_CNTL_ATTRIBUTES, reqlen, | |
4826 | LPFC_SLI4_MBX_NEMBED); | |
4827 | if (alloclen < reqlen) { | |
4828 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
4829 | "3084 Allocated DMA memory size (%d) is " | |
4830 | "less than the requested DMA memory size " | |
4831 | "(%d)\n", alloclen, reqlen); | |
4832 | rc = -ENOMEM; | |
4833 | goto out_free_mboxq; | |
4834 | } | |
4835 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
4836 | virtaddr = mboxq->sge_array->addr[0]; | |
4837 | mbx_cntl_attr = (struct lpfc_mbx_get_cntl_attributes *)virtaddr; | |
4838 | shdr = &mbx_cntl_attr->cfg_shdr; | |
4839 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
4840 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
4841 | if (shdr_status || shdr_add_status || rc) { | |
4842 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
4843 | "3085 Mailbox x%x (x%x/x%x) failed, " | |
4844 | "rc:x%x, status:x%x, add_status:x%x\n", | |
4845 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), | |
4846 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), | |
4847 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), | |
4848 | rc, shdr_status, shdr_add_status); | |
4849 | rc = -ENXIO; | |
4850 | goto out_free_mboxq; | |
4851 | } | |
4852 | cntl_attr = &mbx_cntl_attr->cntl_attr; | |
4853 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL; | |
4854 | phba->sli4_hba.lnk_info.lnk_tp = | |
4855 | bf_get(lpfc_cntl_attr_lnk_type, cntl_attr); | |
4856 | phba->sli4_hba.lnk_info.lnk_no = | |
4857 | bf_get(lpfc_cntl_attr_lnk_numb, cntl_attr); | |
4858 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
4859 | "3086 lnk_type:%d, lnk_numb:%d\n", | |
4860 | phba->sli4_hba.lnk_info.lnk_tp, | |
4861 | phba->sli4_hba.lnk_info.lnk_no); | |
4862 | ||
4863 | retrieve_ppname: | |
4864 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, | |
4865 | LPFC_MBOX_OPCODE_GET_PORT_NAME, | |
4866 | sizeof(struct lpfc_mbx_get_port_name) - | |
4867 | sizeof(struct lpfc_sli4_cfg_mhdr), | |
4868 | LPFC_SLI4_MBX_EMBED); | |
4869 | get_port_name = &mboxq->u.mqe.un.get_port_name; | |
4870 | shdr = (union lpfc_sli4_cfg_shdr *)&get_port_name->header.cfg_shdr; | |
4871 | bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_OPCODE_VERSION_1); | |
4872 | bf_set(lpfc_mbx_get_port_name_lnk_type, &get_port_name->u.request, | |
4873 | phba->sli4_hba.lnk_info.lnk_tp); | |
4874 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
4875 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
4876 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
4877 | if (shdr_status || shdr_add_status || rc) { | |
4878 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
4879 | "3087 Mailbox x%x (x%x/x%x) failed: " | |
4880 | "rc:x%x, status:x%x, add_status:x%x\n", | |
4881 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), | |
4882 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), | |
4883 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), | |
4884 | rc, shdr_status, shdr_add_status); | |
4885 | rc = -ENXIO; | |
4886 | goto out_free_mboxq; | |
4887 | } | |
4888 | switch (phba->sli4_hba.lnk_info.lnk_no) { | |
4889 | case LPFC_LINK_NUMBER_0: | |
4890 | cport_name = bf_get(lpfc_mbx_get_port_name_name0, | |
4891 | &get_port_name->u.response); | |
4892 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; | |
4893 | break; | |
4894 | case LPFC_LINK_NUMBER_1: | |
4895 | cport_name = bf_get(lpfc_mbx_get_port_name_name1, | |
4896 | &get_port_name->u.response); | |
4897 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; | |
4898 | break; | |
4899 | case LPFC_LINK_NUMBER_2: | |
4900 | cport_name = bf_get(lpfc_mbx_get_port_name_name2, | |
4901 | &get_port_name->u.response); | |
4902 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; | |
4903 | break; | |
4904 | case LPFC_LINK_NUMBER_3: | |
4905 | cport_name = bf_get(lpfc_mbx_get_port_name_name3, | |
4906 | &get_port_name->u.response); | |
4907 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; | |
4908 | break; | |
4909 | default: | |
4910 | break; | |
4911 | } | |
4912 | ||
4913 | if (phba->sli4_hba.pport_name_sta == LPFC_SLI4_PPNAME_GET) { | |
4914 | phba->Port[0] = cport_name; | |
4915 | phba->Port[1] = '\0'; | |
4916 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
4917 | "3091 SLI get port name: %s\n", phba->Port); | |
4918 | } | |
4919 | ||
4920 | out_free_mboxq: | |
4921 | if (rc != MBX_TIMEOUT) { | |
4922 | if (bf_get(lpfc_mqe_command, &mboxq->u.mqe) == MBX_SLI4_CONFIG) | |
4923 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
4924 | else | |
4925 | mempool_free(mboxq, phba->mbox_mem_pool); | |
4926 | } | |
4927 | return rc; | |
4928 | } | |
4929 | ||
e59058c4 | 4930 | /** |
da0436e9 JS |
4931 | * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues |
4932 | * @phba: pointer to lpfc hba data structure. | |
e59058c4 | 4933 | * |
da0436e9 JS |
4934 | * This routine is called to explicitly arm the SLI4 device's completion and |
4935 | * event queues | |
4936 | **/ | |
4937 | static void | |
4938 | lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba) | |
4939 | { | |
4940 | uint8_t fcp_eqidx; | |
4941 | ||
4942 | lpfc_sli4_cq_release(phba->sli4_hba.mbx_cq, LPFC_QUEUE_REARM); | |
4943 | lpfc_sli4_cq_release(phba->sli4_hba.els_cq, LPFC_QUEUE_REARM); | |
0558056c | 4944 | fcp_eqidx = 0; |
2e90f4b5 | 4945 | if (phba->sli4_hba.fcp_cq) { |
67d12733 | 4946 | do { |
2e90f4b5 JS |
4947 | lpfc_sli4_cq_release(phba->sli4_hba.fcp_cq[fcp_eqidx], |
4948 | LPFC_QUEUE_REARM); | |
67d12733 | 4949 | } while (++fcp_eqidx < phba->cfg_fcp_io_channel); |
2e90f4b5 | 4950 | } |
67d12733 JS |
4951 | if (phba->sli4_hba.hba_eq) { |
4952 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_io_channel; | |
2e90f4b5 | 4953 | fcp_eqidx++) |
67d12733 | 4954 | lpfc_sli4_eq_release(phba->sli4_hba.hba_eq[fcp_eqidx], |
2e90f4b5 JS |
4955 | LPFC_QUEUE_REARM); |
4956 | } | |
da0436e9 JS |
4957 | } |
4958 | ||
6d368e53 JS |
4959 | /** |
4960 | * lpfc_sli4_get_avail_extnt_rsrc - Get available resource extent count. | |
4961 | * @phba: Pointer to HBA context object. | |
4962 | * @type: The resource extent type. | |
b76f2dc9 JS |
4963 | * @extnt_count: buffer to hold port available extent count. |
4964 | * @extnt_size: buffer to hold element count per extent. | |
6d368e53 | 4965 | * |
b76f2dc9 JS |
4966 | * This function calls the port and retrievs the number of available |
4967 | * extents and their size for a particular extent type. | |
4968 | * | |
4969 | * Returns: 0 if successful. Nonzero otherwise. | |
6d368e53 | 4970 | **/ |
b76f2dc9 | 4971 | int |
6d368e53 JS |
4972 | lpfc_sli4_get_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type, |
4973 | uint16_t *extnt_count, uint16_t *extnt_size) | |
4974 | { | |
4975 | int rc = 0; | |
4976 | uint32_t length; | |
4977 | uint32_t mbox_tmo; | |
4978 | struct lpfc_mbx_get_rsrc_extent_info *rsrc_info; | |
4979 | LPFC_MBOXQ_t *mbox; | |
4980 | ||
4981 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
4982 | if (!mbox) | |
4983 | return -ENOMEM; | |
4984 | ||
4985 | /* Find out how many extents are available for this resource type */ | |
4986 | length = (sizeof(struct lpfc_mbx_get_rsrc_extent_info) - | |
4987 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
4988 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
4989 | LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO, | |
4990 | length, LPFC_SLI4_MBX_EMBED); | |
4991 | ||
4992 | /* Send an extents count of 0 - the GET doesn't use it. */ | |
4993 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type, | |
4994 | LPFC_SLI4_MBX_EMBED); | |
4995 | if (unlikely(rc)) { | |
4996 | rc = -EIO; | |
4997 | goto err_exit; | |
4998 | } | |
4999 | ||
5000 | if (!phba->sli4_hba.intr_enable) | |
5001 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
5002 | else { | |
a183a15f | 5003 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
6d368e53 JS |
5004 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
5005 | } | |
5006 | if (unlikely(rc)) { | |
5007 | rc = -EIO; | |
5008 | goto err_exit; | |
5009 | } | |
5010 | ||
5011 | rsrc_info = &mbox->u.mqe.un.rsrc_extent_info; | |
5012 | if (bf_get(lpfc_mbox_hdr_status, | |
5013 | &rsrc_info->header.cfg_shdr.response)) { | |
5014 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, | |
5015 | "2930 Failed to get resource extents " | |
5016 | "Status 0x%x Add'l Status 0x%x\n", | |
5017 | bf_get(lpfc_mbox_hdr_status, | |
5018 | &rsrc_info->header.cfg_shdr.response), | |
5019 | bf_get(lpfc_mbox_hdr_add_status, | |
5020 | &rsrc_info->header.cfg_shdr.response)); | |
5021 | rc = -EIO; | |
5022 | goto err_exit; | |
5023 | } | |
5024 | ||
5025 | *extnt_count = bf_get(lpfc_mbx_get_rsrc_extent_info_cnt, | |
5026 | &rsrc_info->u.rsp); | |
5027 | *extnt_size = bf_get(lpfc_mbx_get_rsrc_extent_info_size, | |
5028 | &rsrc_info->u.rsp); | |
8a9d2e80 JS |
5029 | |
5030 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
5031 | "3162 Retrieved extents type-%d from port: count:%d, " | |
5032 | "size:%d\n", type, *extnt_count, *extnt_size); | |
5033 | ||
5034 | err_exit: | |
6d368e53 JS |
5035 | mempool_free(mbox, phba->mbox_mem_pool); |
5036 | return rc; | |
5037 | } | |
5038 | ||
5039 | /** | |
5040 | * lpfc_sli4_chk_avail_extnt_rsrc - Check for available SLI4 resource extents. | |
5041 | * @phba: Pointer to HBA context object. | |
5042 | * @type: The extent type to check. | |
5043 | * | |
5044 | * This function reads the current available extents from the port and checks | |
5045 | * if the extent count or extent size has changed since the last access. | |
5046 | * Callers use this routine post port reset to understand if there is a | |
5047 | * extent reprovisioning requirement. | |
5048 | * | |
5049 | * Returns: | |
5050 | * -Error: error indicates problem. | |
5051 | * 1: Extent count or size has changed. | |
5052 | * 0: No changes. | |
5053 | **/ | |
5054 | static int | |
5055 | lpfc_sli4_chk_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type) | |
5056 | { | |
5057 | uint16_t curr_ext_cnt, rsrc_ext_cnt; | |
5058 | uint16_t size_diff, rsrc_ext_size; | |
5059 | int rc = 0; | |
5060 | struct lpfc_rsrc_blks *rsrc_entry; | |
5061 | struct list_head *rsrc_blk_list = NULL; | |
5062 | ||
5063 | size_diff = 0; | |
5064 | curr_ext_cnt = 0; | |
5065 | rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type, | |
5066 | &rsrc_ext_cnt, | |
5067 | &rsrc_ext_size); | |
5068 | if (unlikely(rc)) | |
5069 | return -EIO; | |
5070 | ||
5071 | switch (type) { | |
5072 | case LPFC_RSC_TYPE_FCOE_RPI: | |
5073 | rsrc_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list; | |
5074 | break; | |
5075 | case LPFC_RSC_TYPE_FCOE_VPI: | |
5076 | rsrc_blk_list = &phba->lpfc_vpi_blk_list; | |
5077 | break; | |
5078 | case LPFC_RSC_TYPE_FCOE_XRI: | |
5079 | rsrc_blk_list = &phba->sli4_hba.lpfc_xri_blk_list; | |
5080 | break; | |
5081 | case LPFC_RSC_TYPE_FCOE_VFI: | |
5082 | rsrc_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list; | |
5083 | break; | |
5084 | default: | |
5085 | break; | |
5086 | } | |
5087 | ||
5088 | list_for_each_entry(rsrc_entry, rsrc_blk_list, list) { | |
5089 | curr_ext_cnt++; | |
5090 | if (rsrc_entry->rsrc_size != rsrc_ext_size) | |
5091 | size_diff++; | |
5092 | } | |
5093 | ||
5094 | if (curr_ext_cnt != rsrc_ext_cnt || size_diff != 0) | |
5095 | rc = 1; | |
5096 | ||
5097 | return rc; | |
5098 | } | |
5099 | ||
5100 | /** | |
5101 | * lpfc_sli4_cfg_post_extnts - | |
5102 | * @phba: Pointer to HBA context object. | |
5103 | * @extnt_cnt - number of available extents. | |
5104 | * @type - the extent type (rpi, xri, vfi, vpi). | |
5105 | * @emb - buffer to hold either MBX_EMBED or MBX_NEMBED operation. | |
5106 | * @mbox - pointer to the caller's allocated mailbox structure. | |
5107 | * | |
5108 | * This function executes the extents allocation request. It also | |
5109 | * takes care of the amount of memory needed to allocate or get the | |
5110 | * allocated extents. It is the caller's responsibility to evaluate | |
5111 | * the response. | |
5112 | * | |
5113 | * Returns: | |
5114 | * -Error: Error value describes the condition found. | |
5115 | * 0: if successful | |
5116 | **/ | |
5117 | static int | |
8a9d2e80 | 5118 | lpfc_sli4_cfg_post_extnts(struct lpfc_hba *phba, uint16_t extnt_cnt, |
6d368e53 JS |
5119 | uint16_t type, bool *emb, LPFC_MBOXQ_t *mbox) |
5120 | { | |
5121 | int rc = 0; | |
5122 | uint32_t req_len; | |
5123 | uint32_t emb_len; | |
5124 | uint32_t alloc_len, mbox_tmo; | |
5125 | ||
5126 | /* Calculate the total requested length of the dma memory */ | |
8a9d2e80 | 5127 | req_len = extnt_cnt * sizeof(uint16_t); |
6d368e53 JS |
5128 | |
5129 | /* | |
5130 | * Calculate the size of an embedded mailbox. The uint32_t | |
5131 | * accounts for extents-specific word. | |
5132 | */ | |
5133 | emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) - | |
5134 | sizeof(uint32_t); | |
5135 | ||
5136 | /* | |
5137 | * Presume the allocation and response will fit into an embedded | |
5138 | * mailbox. If not true, reconfigure to a non-embedded mailbox. | |
5139 | */ | |
5140 | *emb = LPFC_SLI4_MBX_EMBED; | |
5141 | if (req_len > emb_len) { | |
8a9d2e80 | 5142 | req_len = extnt_cnt * sizeof(uint16_t) + |
6d368e53 JS |
5143 | sizeof(union lpfc_sli4_cfg_shdr) + |
5144 | sizeof(uint32_t); | |
5145 | *emb = LPFC_SLI4_MBX_NEMBED; | |
5146 | } | |
5147 | ||
5148 | alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
5149 | LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT, | |
5150 | req_len, *emb); | |
5151 | if (alloc_len < req_len) { | |
5152 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
b76f2dc9 | 5153 | "2982 Allocated DMA memory size (x%x) is " |
6d368e53 JS |
5154 | "less than the requested DMA memory " |
5155 | "size (x%x)\n", alloc_len, req_len); | |
5156 | return -ENOMEM; | |
5157 | } | |
8a9d2e80 | 5158 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, extnt_cnt, type, *emb); |
6d368e53 JS |
5159 | if (unlikely(rc)) |
5160 | return -EIO; | |
5161 | ||
5162 | if (!phba->sli4_hba.intr_enable) | |
5163 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
5164 | else { | |
a183a15f | 5165 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
6d368e53 JS |
5166 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
5167 | } | |
5168 | ||
5169 | if (unlikely(rc)) | |
5170 | rc = -EIO; | |
5171 | return rc; | |
5172 | } | |
5173 | ||
5174 | /** | |
5175 | * lpfc_sli4_alloc_extent - Allocate an SLI4 resource extent. | |
5176 | * @phba: Pointer to HBA context object. | |
5177 | * @type: The resource extent type to allocate. | |
5178 | * | |
5179 | * This function allocates the number of elements for the specified | |
5180 | * resource type. | |
5181 | **/ | |
5182 | static int | |
5183 | lpfc_sli4_alloc_extent(struct lpfc_hba *phba, uint16_t type) | |
5184 | { | |
5185 | bool emb = false; | |
5186 | uint16_t rsrc_id_cnt, rsrc_cnt, rsrc_size; | |
5187 | uint16_t rsrc_id, rsrc_start, j, k; | |
5188 | uint16_t *ids; | |
5189 | int i, rc; | |
5190 | unsigned long longs; | |
5191 | unsigned long *bmask; | |
5192 | struct lpfc_rsrc_blks *rsrc_blks; | |
5193 | LPFC_MBOXQ_t *mbox; | |
5194 | uint32_t length; | |
5195 | struct lpfc_id_range *id_array = NULL; | |
5196 | void *virtaddr = NULL; | |
5197 | struct lpfc_mbx_nembed_rsrc_extent *n_rsrc; | |
5198 | struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext; | |
5199 | struct list_head *ext_blk_list; | |
5200 | ||
5201 | rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type, | |
5202 | &rsrc_cnt, | |
5203 | &rsrc_size); | |
5204 | if (unlikely(rc)) | |
5205 | return -EIO; | |
5206 | ||
5207 | if ((rsrc_cnt == 0) || (rsrc_size == 0)) { | |
5208 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, | |
5209 | "3009 No available Resource Extents " | |
5210 | "for resource type 0x%x: Count: 0x%x, " | |
5211 | "Size 0x%x\n", type, rsrc_cnt, | |
5212 | rsrc_size); | |
5213 | return -ENOMEM; | |
5214 | } | |
5215 | ||
8a9d2e80 JS |
5216 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_INIT | LOG_SLI, |
5217 | "2903 Post resource extents type-0x%x: " | |
5218 | "count:%d, size %d\n", type, rsrc_cnt, rsrc_size); | |
6d368e53 JS |
5219 | |
5220 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
5221 | if (!mbox) | |
5222 | return -ENOMEM; | |
5223 | ||
8a9d2e80 | 5224 | rc = lpfc_sli4_cfg_post_extnts(phba, rsrc_cnt, type, &emb, mbox); |
6d368e53 JS |
5225 | if (unlikely(rc)) { |
5226 | rc = -EIO; | |
5227 | goto err_exit; | |
5228 | } | |
5229 | ||
5230 | /* | |
5231 | * Figure out where the response is located. Then get local pointers | |
5232 | * to the response data. The port does not guarantee to respond to | |
5233 | * all extents counts request so update the local variable with the | |
5234 | * allocated count from the port. | |
5235 | */ | |
5236 | if (emb == LPFC_SLI4_MBX_EMBED) { | |
5237 | rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents; | |
5238 | id_array = &rsrc_ext->u.rsp.id[0]; | |
5239 | rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp); | |
5240 | } else { | |
5241 | virtaddr = mbox->sge_array->addr[0]; | |
5242 | n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr; | |
5243 | rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc); | |
5244 | id_array = &n_rsrc->id; | |
5245 | } | |
5246 | ||
5247 | longs = ((rsrc_cnt * rsrc_size) + BITS_PER_LONG - 1) / BITS_PER_LONG; | |
5248 | rsrc_id_cnt = rsrc_cnt * rsrc_size; | |
5249 | ||
5250 | /* | |
5251 | * Based on the resource size and count, correct the base and max | |
5252 | * resource values. | |
5253 | */ | |
5254 | length = sizeof(struct lpfc_rsrc_blks); | |
5255 | switch (type) { | |
5256 | case LPFC_RSC_TYPE_FCOE_RPI: | |
5257 | phba->sli4_hba.rpi_bmask = kzalloc(longs * | |
5258 | sizeof(unsigned long), | |
5259 | GFP_KERNEL); | |
5260 | if (unlikely(!phba->sli4_hba.rpi_bmask)) { | |
5261 | rc = -ENOMEM; | |
5262 | goto err_exit; | |
5263 | } | |
5264 | phba->sli4_hba.rpi_ids = kzalloc(rsrc_id_cnt * | |
5265 | sizeof(uint16_t), | |
5266 | GFP_KERNEL); | |
5267 | if (unlikely(!phba->sli4_hba.rpi_ids)) { | |
5268 | kfree(phba->sli4_hba.rpi_bmask); | |
5269 | rc = -ENOMEM; | |
5270 | goto err_exit; | |
5271 | } | |
5272 | ||
5273 | /* | |
5274 | * The next_rpi was initialized with the maximum available | |
5275 | * count but the port may allocate a smaller number. Catch | |
5276 | * that case and update the next_rpi. | |
5277 | */ | |
5278 | phba->sli4_hba.next_rpi = rsrc_id_cnt; | |
5279 | ||
5280 | /* Initialize local ptrs for common extent processing later. */ | |
5281 | bmask = phba->sli4_hba.rpi_bmask; | |
5282 | ids = phba->sli4_hba.rpi_ids; | |
5283 | ext_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list; | |
5284 | break; | |
5285 | case LPFC_RSC_TYPE_FCOE_VPI: | |
5286 | phba->vpi_bmask = kzalloc(longs * | |
5287 | sizeof(unsigned long), | |
5288 | GFP_KERNEL); | |
5289 | if (unlikely(!phba->vpi_bmask)) { | |
5290 | rc = -ENOMEM; | |
5291 | goto err_exit; | |
5292 | } | |
5293 | phba->vpi_ids = kzalloc(rsrc_id_cnt * | |
5294 | sizeof(uint16_t), | |
5295 | GFP_KERNEL); | |
5296 | if (unlikely(!phba->vpi_ids)) { | |
5297 | kfree(phba->vpi_bmask); | |
5298 | rc = -ENOMEM; | |
5299 | goto err_exit; | |
5300 | } | |
5301 | ||
5302 | /* Initialize local ptrs for common extent processing later. */ | |
5303 | bmask = phba->vpi_bmask; | |
5304 | ids = phba->vpi_ids; | |
5305 | ext_blk_list = &phba->lpfc_vpi_blk_list; | |
5306 | break; | |
5307 | case LPFC_RSC_TYPE_FCOE_XRI: | |
5308 | phba->sli4_hba.xri_bmask = kzalloc(longs * | |
5309 | sizeof(unsigned long), | |
5310 | GFP_KERNEL); | |
5311 | if (unlikely(!phba->sli4_hba.xri_bmask)) { | |
5312 | rc = -ENOMEM; | |
5313 | goto err_exit; | |
5314 | } | |
8a9d2e80 | 5315 | phba->sli4_hba.max_cfg_param.xri_used = 0; |
6d368e53 JS |
5316 | phba->sli4_hba.xri_ids = kzalloc(rsrc_id_cnt * |
5317 | sizeof(uint16_t), | |
5318 | GFP_KERNEL); | |
5319 | if (unlikely(!phba->sli4_hba.xri_ids)) { | |
5320 | kfree(phba->sli4_hba.xri_bmask); | |
5321 | rc = -ENOMEM; | |
5322 | goto err_exit; | |
5323 | } | |
5324 | ||
5325 | /* Initialize local ptrs for common extent processing later. */ | |
5326 | bmask = phba->sli4_hba.xri_bmask; | |
5327 | ids = phba->sli4_hba.xri_ids; | |
5328 | ext_blk_list = &phba->sli4_hba.lpfc_xri_blk_list; | |
5329 | break; | |
5330 | case LPFC_RSC_TYPE_FCOE_VFI: | |
5331 | phba->sli4_hba.vfi_bmask = kzalloc(longs * | |
5332 | sizeof(unsigned long), | |
5333 | GFP_KERNEL); | |
5334 | if (unlikely(!phba->sli4_hba.vfi_bmask)) { | |
5335 | rc = -ENOMEM; | |
5336 | goto err_exit; | |
5337 | } | |
5338 | phba->sli4_hba.vfi_ids = kzalloc(rsrc_id_cnt * | |
5339 | sizeof(uint16_t), | |
5340 | GFP_KERNEL); | |
5341 | if (unlikely(!phba->sli4_hba.vfi_ids)) { | |
5342 | kfree(phba->sli4_hba.vfi_bmask); | |
5343 | rc = -ENOMEM; | |
5344 | goto err_exit; | |
5345 | } | |
5346 | ||
5347 | /* Initialize local ptrs for common extent processing later. */ | |
5348 | bmask = phba->sli4_hba.vfi_bmask; | |
5349 | ids = phba->sli4_hba.vfi_ids; | |
5350 | ext_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list; | |
5351 | break; | |
5352 | default: | |
5353 | /* Unsupported Opcode. Fail call. */ | |
5354 | id_array = NULL; | |
5355 | bmask = NULL; | |
5356 | ids = NULL; | |
5357 | ext_blk_list = NULL; | |
5358 | goto err_exit; | |
5359 | } | |
5360 | ||
5361 | /* | |
5362 | * Complete initializing the extent configuration with the | |
5363 | * allocated ids assigned to this function. The bitmask serves | |
5364 | * as an index into the array and manages the available ids. The | |
5365 | * array just stores the ids communicated to the port via the wqes. | |
5366 | */ | |
5367 | for (i = 0, j = 0, k = 0; i < rsrc_cnt; i++) { | |
5368 | if ((i % 2) == 0) | |
5369 | rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_0, | |
5370 | &id_array[k]); | |
5371 | else | |
5372 | rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_1, | |
5373 | &id_array[k]); | |
5374 | ||
5375 | rsrc_blks = kzalloc(length, GFP_KERNEL); | |
5376 | if (unlikely(!rsrc_blks)) { | |
5377 | rc = -ENOMEM; | |
5378 | kfree(bmask); | |
5379 | kfree(ids); | |
5380 | goto err_exit; | |
5381 | } | |
5382 | rsrc_blks->rsrc_start = rsrc_id; | |
5383 | rsrc_blks->rsrc_size = rsrc_size; | |
5384 | list_add_tail(&rsrc_blks->list, ext_blk_list); | |
5385 | rsrc_start = rsrc_id; | |
5386 | if ((type == LPFC_RSC_TYPE_FCOE_XRI) && (j == 0)) | |
5387 | phba->sli4_hba.scsi_xri_start = rsrc_start + | |
5388 | lpfc_sli4_get_els_iocb_cnt(phba); | |
5389 | ||
5390 | while (rsrc_id < (rsrc_start + rsrc_size)) { | |
5391 | ids[j] = rsrc_id; | |
5392 | rsrc_id++; | |
5393 | j++; | |
5394 | } | |
5395 | /* Entire word processed. Get next word.*/ | |
5396 | if ((i % 2) == 1) | |
5397 | k++; | |
5398 | } | |
5399 | err_exit: | |
5400 | lpfc_sli4_mbox_cmd_free(phba, mbox); | |
5401 | return rc; | |
5402 | } | |
5403 | ||
5404 | /** | |
5405 | * lpfc_sli4_dealloc_extent - Deallocate an SLI4 resource extent. | |
5406 | * @phba: Pointer to HBA context object. | |
5407 | * @type: the extent's type. | |
5408 | * | |
5409 | * This function deallocates all extents of a particular resource type. | |
5410 | * SLI4 does not allow for deallocating a particular extent range. It | |
5411 | * is the caller's responsibility to release all kernel memory resources. | |
5412 | **/ | |
5413 | static int | |
5414 | lpfc_sli4_dealloc_extent(struct lpfc_hba *phba, uint16_t type) | |
5415 | { | |
5416 | int rc; | |
5417 | uint32_t length, mbox_tmo = 0; | |
5418 | LPFC_MBOXQ_t *mbox; | |
5419 | struct lpfc_mbx_dealloc_rsrc_extents *dealloc_rsrc; | |
5420 | struct lpfc_rsrc_blks *rsrc_blk, *rsrc_blk_next; | |
5421 | ||
5422 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
5423 | if (!mbox) | |
5424 | return -ENOMEM; | |
5425 | ||
5426 | /* | |
5427 | * This function sends an embedded mailbox because it only sends the | |
5428 | * the resource type. All extents of this type are released by the | |
5429 | * port. | |
5430 | */ | |
5431 | length = (sizeof(struct lpfc_mbx_dealloc_rsrc_extents) - | |
5432 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
5433 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
5434 | LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT, | |
5435 | length, LPFC_SLI4_MBX_EMBED); | |
5436 | ||
5437 | /* Send an extents count of 0 - the dealloc doesn't use it. */ | |
5438 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type, | |
5439 | LPFC_SLI4_MBX_EMBED); | |
5440 | if (unlikely(rc)) { | |
5441 | rc = -EIO; | |
5442 | goto out_free_mbox; | |
5443 | } | |
5444 | if (!phba->sli4_hba.intr_enable) | |
5445 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
5446 | else { | |
a183a15f | 5447 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
6d368e53 JS |
5448 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
5449 | } | |
5450 | if (unlikely(rc)) { | |
5451 | rc = -EIO; | |
5452 | goto out_free_mbox; | |
5453 | } | |
5454 | ||
5455 | dealloc_rsrc = &mbox->u.mqe.un.dealloc_rsrc_extents; | |
5456 | if (bf_get(lpfc_mbox_hdr_status, | |
5457 | &dealloc_rsrc->header.cfg_shdr.response)) { | |
5458 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, | |
5459 | "2919 Failed to release resource extents " | |
5460 | "for type %d - Status 0x%x Add'l Status 0x%x. " | |
5461 | "Resource memory not released.\n", | |
5462 | type, | |
5463 | bf_get(lpfc_mbox_hdr_status, | |
5464 | &dealloc_rsrc->header.cfg_shdr.response), | |
5465 | bf_get(lpfc_mbox_hdr_add_status, | |
5466 | &dealloc_rsrc->header.cfg_shdr.response)); | |
5467 | rc = -EIO; | |
5468 | goto out_free_mbox; | |
5469 | } | |
5470 | ||
5471 | /* Release kernel memory resources for the specific type. */ | |
5472 | switch (type) { | |
5473 | case LPFC_RSC_TYPE_FCOE_VPI: | |
5474 | kfree(phba->vpi_bmask); | |
5475 | kfree(phba->vpi_ids); | |
5476 | bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); | |
5477 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, | |
5478 | &phba->lpfc_vpi_blk_list, list) { | |
5479 | list_del_init(&rsrc_blk->list); | |
5480 | kfree(rsrc_blk); | |
5481 | } | |
5482 | break; | |
5483 | case LPFC_RSC_TYPE_FCOE_XRI: | |
5484 | kfree(phba->sli4_hba.xri_bmask); | |
5485 | kfree(phba->sli4_hba.xri_ids); | |
6d368e53 JS |
5486 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
5487 | &phba->sli4_hba.lpfc_xri_blk_list, list) { | |
5488 | list_del_init(&rsrc_blk->list); | |
5489 | kfree(rsrc_blk); | |
5490 | } | |
5491 | break; | |
5492 | case LPFC_RSC_TYPE_FCOE_VFI: | |
5493 | kfree(phba->sli4_hba.vfi_bmask); | |
5494 | kfree(phba->sli4_hba.vfi_ids); | |
5495 | bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); | |
5496 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, | |
5497 | &phba->sli4_hba.lpfc_vfi_blk_list, list) { | |
5498 | list_del_init(&rsrc_blk->list); | |
5499 | kfree(rsrc_blk); | |
5500 | } | |
5501 | break; | |
5502 | case LPFC_RSC_TYPE_FCOE_RPI: | |
5503 | /* RPI bitmask and physical id array are cleaned up earlier. */ | |
5504 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, | |
5505 | &phba->sli4_hba.lpfc_rpi_blk_list, list) { | |
5506 | list_del_init(&rsrc_blk->list); | |
5507 | kfree(rsrc_blk); | |
5508 | } | |
5509 | break; | |
5510 | default: | |
5511 | break; | |
5512 | } | |
5513 | ||
5514 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); | |
5515 | ||
5516 | out_free_mbox: | |
5517 | mempool_free(mbox, phba->mbox_mem_pool); | |
5518 | return rc; | |
5519 | } | |
5520 | ||
5521 | /** | |
5522 | * lpfc_sli4_alloc_resource_identifiers - Allocate all SLI4 resource extents. | |
5523 | * @phba: Pointer to HBA context object. | |
5524 | * | |
5525 | * This function allocates all SLI4 resource identifiers. | |
5526 | **/ | |
5527 | int | |
5528 | lpfc_sli4_alloc_resource_identifiers(struct lpfc_hba *phba) | |
5529 | { | |
5530 | int i, rc, error = 0; | |
5531 | uint16_t count, base; | |
5532 | unsigned long longs; | |
5533 | ||
ff78d8f9 JS |
5534 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
5535 | phba->sli4_hba.next_rpi = phba->sli4_hba.max_cfg_param.max_rpi; | |
6d368e53 JS |
5536 | if (phba->sli4_hba.extents_in_use) { |
5537 | /* | |
5538 | * The port supports resource extents. The XRI, VPI, VFI, RPI | |
5539 | * resource extent count must be read and allocated before | |
5540 | * provisioning the resource id arrays. | |
5541 | */ | |
5542 | if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) == | |
5543 | LPFC_IDX_RSRC_RDY) { | |
5544 | /* | |
5545 | * Extent-based resources are set - the driver could | |
5546 | * be in a port reset. Figure out if any corrective | |
5547 | * actions need to be taken. | |
5548 | */ | |
5549 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, | |
5550 | LPFC_RSC_TYPE_FCOE_VFI); | |
5551 | if (rc != 0) | |
5552 | error++; | |
5553 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, | |
5554 | LPFC_RSC_TYPE_FCOE_VPI); | |
5555 | if (rc != 0) | |
5556 | error++; | |
5557 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, | |
5558 | LPFC_RSC_TYPE_FCOE_XRI); | |
5559 | if (rc != 0) | |
5560 | error++; | |
5561 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, | |
5562 | LPFC_RSC_TYPE_FCOE_RPI); | |
5563 | if (rc != 0) | |
5564 | error++; | |
5565 | ||
5566 | /* | |
5567 | * It's possible that the number of resources | |
5568 | * provided to this port instance changed between | |
5569 | * resets. Detect this condition and reallocate | |
5570 | * resources. Otherwise, there is no action. | |
5571 | */ | |
5572 | if (error) { | |
5573 | lpfc_printf_log(phba, KERN_INFO, | |
5574 | LOG_MBOX | LOG_INIT, | |
5575 | "2931 Detected extent resource " | |
5576 | "change. Reallocating all " | |
5577 | "extents.\n"); | |
5578 | rc = lpfc_sli4_dealloc_extent(phba, | |
5579 | LPFC_RSC_TYPE_FCOE_VFI); | |
5580 | rc = lpfc_sli4_dealloc_extent(phba, | |
5581 | LPFC_RSC_TYPE_FCOE_VPI); | |
5582 | rc = lpfc_sli4_dealloc_extent(phba, | |
5583 | LPFC_RSC_TYPE_FCOE_XRI); | |
5584 | rc = lpfc_sli4_dealloc_extent(phba, | |
5585 | LPFC_RSC_TYPE_FCOE_RPI); | |
5586 | } else | |
5587 | return 0; | |
5588 | } | |
5589 | ||
5590 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI); | |
5591 | if (unlikely(rc)) | |
5592 | goto err_exit; | |
5593 | ||
5594 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI); | |
5595 | if (unlikely(rc)) | |
5596 | goto err_exit; | |
5597 | ||
5598 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI); | |
5599 | if (unlikely(rc)) | |
5600 | goto err_exit; | |
5601 | ||
5602 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI); | |
5603 | if (unlikely(rc)) | |
5604 | goto err_exit; | |
5605 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, | |
5606 | LPFC_IDX_RSRC_RDY); | |
5607 | return rc; | |
5608 | } else { | |
5609 | /* | |
5610 | * The port does not support resource extents. The XRI, VPI, | |
5611 | * VFI, RPI resource ids were determined from READ_CONFIG. | |
5612 | * Just allocate the bitmasks and provision the resource id | |
5613 | * arrays. If a port reset is active, the resources don't | |
5614 | * need any action - just exit. | |
5615 | */ | |
5616 | if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) == | |
ff78d8f9 JS |
5617 | LPFC_IDX_RSRC_RDY) { |
5618 | lpfc_sli4_dealloc_resource_identifiers(phba); | |
5619 | lpfc_sli4_remove_rpis(phba); | |
5620 | } | |
6d368e53 JS |
5621 | /* RPIs. */ |
5622 | count = phba->sli4_hba.max_cfg_param.max_rpi; | |
5623 | base = phba->sli4_hba.max_cfg_param.rpi_base; | |
5624 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; | |
5625 | phba->sli4_hba.rpi_bmask = kzalloc(longs * | |
5626 | sizeof(unsigned long), | |
5627 | GFP_KERNEL); | |
5628 | if (unlikely(!phba->sli4_hba.rpi_bmask)) { | |
5629 | rc = -ENOMEM; | |
5630 | goto err_exit; | |
5631 | } | |
5632 | phba->sli4_hba.rpi_ids = kzalloc(count * | |
5633 | sizeof(uint16_t), | |
5634 | GFP_KERNEL); | |
5635 | if (unlikely(!phba->sli4_hba.rpi_ids)) { | |
5636 | rc = -ENOMEM; | |
5637 | goto free_rpi_bmask; | |
5638 | } | |
5639 | ||
5640 | for (i = 0; i < count; i++) | |
5641 | phba->sli4_hba.rpi_ids[i] = base + i; | |
5642 | ||
5643 | /* VPIs. */ | |
5644 | count = phba->sli4_hba.max_cfg_param.max_vpi; | |
5645 | base = phba->sli4_hba.max_cfg_param.vpi_base; | |
5646 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; | |
5647 | phba->vpi_bmask = kzalloc(longs * | |
5648 | sizeof(unsigned long), | |
5649 | GFP_KERNEL); | |
5650 | if (unlikely(!phba->vpi_bmask)) { | |
5651 | rc = -ENOMEM; | |
5652 | goto free_rpi_ids; | |
5653 | } | |
5654 | phba->vpi_ids = kzalloc(count * | |
5655 | sizeof(uint16_t), | |
5656 | GFP_KERNEL); | |
5657 | if (unlikely(!phba->vpi_ids)) { | |
5658 | rc = -ENOMEM; | |
5659 | goto free_vpi_bmask; | |
5660 | } | |
5661 | ||
5662 | for (i = 0; i < count; i++) | |
5663 | phba->vpi_ids[i] = base + i; | |
5664 | ||
5665 | /* XRIs. */ | |
5666 | count = phba->sli4_hba.max_cfg_param.max_xri; | |
5667 | base = phba->sli4_hba.max_cfg_param.xri_base; | |
5668 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; | |
5669 | phba->sli4_hba.xri_bmask = kzalloc(longs * | |
5670 | sizeof(unsigned long), | |
5671 | GFP_KERNEL); | |
5672 | if (unlikely(!phba->sli4_hba.xri_bmask)) { | |
5673 | rc = -ENOMEM; | |
5674 | goto free_vpi_ids; | |
5675 | } | |
41899be7 | 5676 | phba->sli4_hba.max_cfg_param.xri_used = 0; |
6d368e53 JS |
5677 | phba->sli4_hba.xri_ids = kzalloc(count * |
5678 | sizeof(uint16_t), | |
5679 | GFP_KERNEL); | |
5680 | if (unlikely(!phba->sli4_hba.xri_ids)) { | |
5681 | rc = -ENOMEM; | |
5682 | goto free_xri_bmask; | |
5683 | } | |
5684 | ||
5685 | for (i = 0; i < count; i++) | |
5686 | phba->sli4_hba.xri_ids[i] = base + i; | |
5687 | ||
5688 | /* VFIs. */ | |
5689 | count = phba->sli4_hba.max_cfg_param.max_vfi; | |
5690 | base = phba->sli4_hba.max_cfg_param.vfi_base; | |
5691 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; | |
5692 | phba->sli4_hba.vfi_bmask = kzalloc(longs * | |
5693 | sizeof(unsigned long), | |
5694 | GFP_KERNEL); | |
5695 | if (unlikely(!phba->sli4_hba.vfi_bmask)) { | |
5696 | rc = -ENOMEM; | |
5697 | goto free_xri_ids; | |
5698 | } | |
5699 | phba->sli4_hba.vfi_ids = kzalloc(count * | |
5700 | sizeof(uint16_t), | |
5701 | GFP_KERNEL); | |
5702 | if (unlikely(!phba->sli4_hba.vfi_ids)) { | |
5703 | rc = -ENOMEM; | |
5704 | goto free_vfi_bmask; | |
5705 | } | |
5706 | ||
5707 | for (i = 0; i < count; i++) | |
5708 | phba->sli4_hba.vfi_ids[i] = base + i; | |
5709 | ||
5710 | /* | |
5711 | * Mark all resources ready. An HBA reset doesn't need | |
5712 | * to reset the initialization. | |
5713 | */ | |
5714 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, | |
5715 | LPFC_IDX_RSRC_RDY); | |
5716 | return 0; | |
5717 | } | |
5718 | ||
5719 | free_vfi_bmask: | |
5720 | kfree(phba->sli4_hba.vfi_bmask); | |
5721 | free_xri_ids: | |
5722 | kfree(phba->sli4_hba.xri_ids); | |
5723 | free_xri_bmask: | |
5724 | kfree(phba->sli4_hba.xri_bmask); | |
5725 | free_vpi_ids: | |
5726 | kfree(phba->vpi_ids); | |
5727 | free_vpi_bmask: | |
5728 | kfree(phba->vpi_bmask); | |
5729 | free_rpi_ids: | |
5730 | kfree(phba->sli4_hba.rpi_ids); | |
5731 | free_rpi_bmask: | |
5732 | kfree(phba->sli4_hba.rpi_bmask); | |
5733 | err_exit: | |
5734 | return rc; | |
5735 | } | |
5736 | ||
5737 | /** | |
5738 | * lpfc_sli4_dealloc_resource_identifiers - Deallocate all SLI4 resource extents. | |
5739 | * @phba: Pointer to HBA context object. | |
5740 | * | |
5741 | * This function allocates the number of elements for the specified | |
5742 | * resource type. | |
5743 | **/ | |
5744 | int | |
5745 | lpfc_sli4_dealloc_resource_identifiers(struct lpfc_hba *phba) | |
5746 | { | |
5747 | if (phba->sli4_hba.extents_in_use) { | |
5748 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI); | |
5749 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI); | |
5750 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI); | |
5751 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI); | |
5752 | } else { | |
5753 | kfree(phba->vpi_bmask); | |
5754 | kfree(phba->vpi_ids); | |
5755 | bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); | |
5756 | kfree(phba->sli4_hba.xri_bmask); | |
5757 | kfree(phba->sli4_hba.xri_ids); | |
6d368e53 JS |
5758 | kfree(phba->sli4_hba.vfi_bmask); |
5759 | kfree(phba->sli4_hba.vfi_ids); | |
5760 | bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); | |
5761 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); | |
5762 | } | |
5763 | ||
5764 | return 0; | |
5765 | } | |
5766 | ||
b76f2dc9 JS |
5767 | /** |
5768 | * lpfc_sli4_get_allocated_extnts - Get the port's allocated extents. | |
5769 | * @phba: Pointer to HBA context object. | |
5770 | * @type: The resource extent type. | |
5771 | * @extnt_count: buffer to hold port extent count response | |
5772 | * @extnt_size: buffer to hold port extent size response. | |
5773 | * | |
5774 | * This function calls the port to read the host allocated extents | |
5775 | * for a particular type. | |
5776 | **/ | |
5777 | int | |
5778 | lpfc_sli4_get_allocated_extnts(struct lpfc_hba *phba, uint16_t type, | |
5779 | uint16_t *extnt_cnt, uint16_t *extnt_size) | |
5780 | { | |
5781 | bool emb; | |
5782 | int rc = 0; | |
5783 | uint16_t curr_blks = 0; | |
5784 | uint32_t req_len, emb_len; | |
5785 | uint32_t alloc_len, mbox_tmo; | |
5786 | struct list_head *blk_list_head; | |
5787 | struct lpfc_rsrc_blks *rsrc_blk; | |
5788 | LPFC_MBOXQ_t *mbox; | |
5789 | void *virtaddr = NULL; | |
5790 | struct lpfc_mbx_nembed_rsrc_extent *n_rsrc; | |
5791 | struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext; | |
5792 | union lpfc_sli4_cfg_shdr *shdr; | |
5793 | ||
5794 | switch (type) { | |
5795 | case LPFC_RSC_TYPE_FCOE_VPI: | |
5796 | blk_list_head = &phba->lpfc_vpi_blk_list; | |
5797 | break; | |
5798 | case LPFC_RSC_TYPE_FCOE_XRI: | |
5799 | blk_list_head = &phba->sli4_hba.lpfc_xri_blk_list; | |
5800 | break; | |
5801 | case LPFC_RSC_TYPE_FCOE_VFI: | |
5802 | blk_list_head = &phba->sli4_hba.lpfc_vfi_blk_list; | |
5803 | break; | |
5804 | case LPFC_RSC_TYPE_FCOE_RPI: | |
5805 | blk_list_head = &phba->sli4_hba.lpfc_rpi_blk_list; | |
5806 | break; | |
5807 | default: | |
5808 | return -EIO; | |
5809 | } | |
5810 | ||
5811 | /* Count the number of extents currently allocatd for this type. */ | |
5812 | list_for_each_entry(rsrc_blk, blk_list_head, list) { | |
5813 | if (curr_blks == 0) { | |
5814 | /* | |
5815 | * The GET_ALLOCATED mailbox does not return the size, | |
5816 | * just the count. The size should be just the size | |
5817 | * stored in the current allocated block and all sizes | |
5818 | * for an extent type are the same so set the return | |
5819 | * value now. | |
5820 | */ | |
5821 | *extnt_size = rsrc_blk->rsrc_size; | |
5822 | } | |
5823 | curr_blks++; | |
5824 | } | |
5825 | ||
5826 | /* Calculate the total requested length of the dma memory. */ | |
5827 | req_len = curr_blks * sizeof(uint16_t); | |
5828 | ||
5829 | /* | |
5830 | * Calculate the size of an embedded mailbox. The uint32_t | |
5831 | * accounts for extents-specific word. | |
5832 | */ | |
5833 | emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) - | |
5834 | sizeof(uint32_t); | |
5835 | ||
5836 | /* | |
5837 | * Presume the allocation and response will fit into an embedded | |
5838 | * mailbox. If not true, reconfigure to a non-embedded mailbox. | |
5839 | */ | |
5840 | emb = LPFC_SLI4_MBX_EMBED; | |
5841 | req_len = emb_len; | |
5842 | if (req_len > emb_len) { | |
5843 | req_len = curr_blks * sizeof(uint16_t) + | |
5844 | sizeof(union lpfc_sli4_cfg_shdr) + | |
5845 | sizeof(uint32_t); | |
5846 | emb = LPFC_SLI4_MBX_NEMBED; | |
5847 | } | |
5848 | ||
5849 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
5850 | if (!mbox) | |
5851 | return -ENOMEM; | |
5852 | memset(mbox, 0, sizeof(LPFC_MBOXQ_t)); | |
5853 | ||
5854 | alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
5855 | LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT, | |
5856 | req_len, emb); | |
5857 | if (alloc_len < req_len) { | |
5858 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
5859 | "2983 Allocated DMA memory size (x%x) is " | |
5860 | "less than the requested DMA memory " | |
5861 | "size (x%x)\n", alloc_len, req_len); | |
5862 | rc = -ENOMEM; | |
5863 | goto err_exit; | |
5864 | } | |
5865 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, curr_blks, type, emb); | |
5866 | if (unlikely(rc)) { | |
5867 | rc = -EIO; | |
5868 | goto err_exit; | |
5869 | } | |
5870 | ||
5871 | if (!phba->sli4_hba.intr_enable) | |
5872 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
5873 | else { | |
a183a15f | 5874 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
b76f2dc9 JS |
5875 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
5876 | } | |
5877 | ||
5878 | if (unlikely(rc)) { | |
5879 | rc = -EIO; | |
5880 | goto err_exit; | |
5881 | } | |
5882 | ||
5883 | /* | |
5884 | * Figure out where the response is located. Then get local pointers | |
5885 | * to the response data. The port does not guarantee to respond to | |
5886 | * all extents counts request so update the local variable with the | |
5887 | * allocated count from the port. | |
5888 | */ | |
5889 | if (emb == LPFC_SLI4_MBX_EMBED) { | |
5890 | rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents; | |
5891 | shdr = &rsrc_ext->header.cfg_shdr; | |
5892 | *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp); | |
5893 | } else { | |
5894 | virtaddr = mbox->sge_array->addr[0]; | |
5895 | n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr; | |
5896 | shdr = &n_rsrc->cfg_shdr; | |
5897 | *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc); | |
5898 | } | |
5899 | ||
5900 | if (bf_get(lpfc_mbox_hdr_status, &shdr->response)) { | |
5901 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, | |
5902 | "2984 Failed to read allocated resources " | |
5903 | "for type %d - Status 0x%x Add'l Status 0x%x.\n", | |
5904 | type, | |
5905 | bf_get(lpfc_mbox_hdr_status, &shdr->response), | |
5906 | bf_get(lpfc_mbox_hdr_add_status, &shdr->response)); | |
5907 | rc = -EIO; | |
5908 | goto err_exit; | |
5909 | } | |
5910 | err_exit: | |
5911 | lpfc_sli4_mbox_cmd_free(phba, mbox); | |
5912 | return rc; | |
5913 | } | |
5914 | ||
8a9d2e80 JS |
5915 | /** |
5916 | * lpfc_sli4_repost_els_sgl_list - Repsot the els buffers sgl pages as block | |
5917 | * @phba: pointer to lpfc hba data structure. | |
5918 | * | |
5919 | * This routine walks the list of els buffers that have been allocated and | |
5920 | * repost them to the port by using SGL block post. This is needed after a | |
5921 | * pci_function_reset/warm_start or start. It attempts to construct blocks | |
5922 | * of els buffer sgls which contains contiguous xris and uses the non-embedded | |
5923 | * SGL block post mailbox commands to post them to the port. For single els | |
5924 | * buffer sgl with non-contiguous xri, if any, it shall use embedded SGL post | |
5925 | * mailbox command for posting. | |
5926 | * | |
5927 | * Returns: 0 = success, non-zero failure. | |
5928 | **/ | |
5929 | static int | |
5930 | lpfc_sli4_repost_els_sgl_list(struct lpfc_hba *phba) | |
5931 | { | |
5932 | struct lpfc_sglq *sglq_entry = NULL; | |
5933 | struct lpfc_sglq *sglq_entry_next = NULL; | |
5934 | struct lpfc_sglq *sglq_entry_first = NULL; | |
5935 | int status, post_cnt = 0, num_posted = 0, block_cnt = 0; | |
5936 | int last_xritag = NO_XRI; | |
5937 | LIST_HEAD(prep_sgl_list); | |
5938 | LIST_HEAD(blck_sgl_list); | |
5939 | LIST_HEAD(allc_sgl_list); | |
5940 | LIST_HEAD(post_sgl_list); | |
5941 | LIST_HEAD(free_sgl_list); | |
5942 | ||
5943 | spin_lock(&phba->hbalock); | |
5944 | list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &allc_sgl_list); | |
5945 | spin_unlock(&phba->hbalock); | |
5946 | ||
5947 | list_for_each_entry_safe(sglq_entry, sglq_entry_next, | |
5948 | &allc_sgl_list, list) { | |
5949 | list_del_init(&sglq_entry->list); | |
5950 | block_cnt++; | |
5951 | if ((last_xritag != NO_XRI) && | |
5952 | (sglq_entry->sli4_xritag != last_xritag + 1)) { | |
5953 | /* a hole in xri block, form a sgl posting block */ | |
5954 | list_splice_init(&prep_sgl_list, &blck_sgl_list); | |
5955 | post_cnt = block_cnt - 1; | |
5956 | /* prepare list for next posting block */ | |
5957 | list_add_tail(&sglq_entry->list, &prep_sgl_list); | |
5958 | block_cnt = 1; | |
5959 | } else { | |
5960 | /* prepare list for next posting block */ | |
5961 | list_add_tail(&sglq_entry->list, &prep_sgl_list); | |
5962 | /* enough sgls for non-embed sgl mbox command */ | |
5963 | if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) { | |
5964 | list_splice_init(&prep_sgl_list, | |
5965 | &blck_sgl_list); | |
5966 | post_cnt = block_cnt; | |
5967 | block_cnt = 0; | |
5968 | } | |
5969 | } | |
5970 | num_posted++; | |
5971 | ||
5972 | /* keep track of last sgl's xritag */ | |
5973 | last_xritag = sglq_entry->sli4_xritag; | |
5974 | ||
5975 | /* end of repost sgl list condition for els buffers */ | |
5976 | if (num_posted == phba->sli4_hba.els_xri_cnt) { | |
5977 | if (post_cnt == 0) { | |
5978 | list_splice_init(&prep_sgl_list, | |
5979 | &blck_sgl_list); | |
5980 | post_cnt = block_cnt; | |
5981 | } else if (block_cnt == 1) { | |
5982 | status = lpfc_sli4_post_sgl(phba, | |
5983 | sglq_entry->phys, 0, | |
5984 | sglq_entry->sli4_xritag); | |
5985 | if (!status) { | |
5986 | /* successful, put sgl to posted list */ | |
5987 | list_add_tail(&sglq_entry->list, | |
5988 | &post_sgl_list); | |
5989 | } else { | |
5990 | /* Failure, put sgl to free list */ | |
5991 | lpfc_printf_log(phba, KERN_WARNING, | |
5992 | LOG_SLI, | |
5993 | "3159 Failed to post els " | |
5994 | "sgl, xritag:x%x\n", | |
5995 | sglq_entry->sli4_xritag); | |
5996 | list_add_tail(&sglq_entry->list, | |
5997 | &free_sgl_list); | |
5998 | spin_lock_irq(&phba->hbalock); | |
5999 | phba->sli4_hba.els_xri_cnt--; | |
6000 | spin_unlock_irq(&phba->hbalock); | |
6001 | } | |
6002 | } | |
6003 | } | |
6004 | ||
6005 | /* continue until a nembed page worth of sgls */ | |
6006 | if (post_cnt == 0) | |
6007 | continue; | |
6008 | ||
6009 | /* post the els buffer list sgls as a block */ | |
6010 | status = lpfc_sli4_post_els_sgl_list(phba, &blck_sgl_list, | |
6011 | post_cnt); | |
6012 | ||
6013 | if (!status) { | |
6014 | /* success, put sgl list to posted sgl list */ | |
6015 | list_splice_init(&blck_sgl_list, &post_sgl_list); | |
6016 | } else { | |
6017 | /* Failure, put sgl list to free sgl list */ | |
6018 | sglq_entry_first = list_first_entry(&blck_sgl_list, | |
6019 | struct lpfc_sglq, | |
6020 | list); | |
6021 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
6022 | "3160 Failed to post els sgl-list, " | |
6023 | "xritag:x%x-x%x\n", | |
6024 | sglq_entry_first->sli4_xritag, | |
6025 | (sglq_entry_first->sli4_xritag + | |
6026 | post_cnt - 1)); | |
6027 | list_splice_init(&blck_sgl_list, &free_sgl_list); | |
6028 | spin_lock_irq(&phba->hbalock); | |
6029 | phba->sli4_hba.els_xri_cnt -= post_cnt; | |
6030 | spin_unlock_irq(&phba->hbalock); | |
6031 | } | |
6032 | ||
6033 | /* don't reset xirtag due to hole in xri block */ | |
6034 | if (block_cnt == 0) | |
6035 | last_xritag = NO_XRI; | |
6036 | ||
6037 | /* reset els sgl post count for next round of posting */ | |
6038 | post_cnt = 0; | |
6039 | } | |
6040 | ||
6041 | /* free the els sgls failed to post */ | |
6042 | lpfc_free_sgl_list(phba, &free_sgl_list); | |
6043 | ||
6044 | /* push els sgls posted to the availble list */ | |
6045 | if (!list_empty(&post_sgl_list)) { | |
6046 | spin_lock(&phba->hbalock); | |
6047 | list_splice_init(&post_sgl_list, | |
6048 | &phba->sli4_hba.lpfc_sgl_list); | |
6049 | spin_unlock(&phba->hbalock); | |
6050 | } else { | |
6051 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
6052 | "3161 Failure to post els sgl to port.\n"); | |
6053 | return -EIO; | |
6054 | } | |
6055 | return 0; | |
6056 | } | |
6057 | ||
da0436e9 JS |
6058 | /** |
6059 | * lpfc_sli4_hba_setup - SLI4 device intialization PCI function | |
6060 | * @phba: Pointer to HBA context object. | |
6061 | * | |
6062 | * This function is the main SLI4 device intialization PCI function. This | |
6063 | * function is called by the HBA intialization code, HBA reset code and | |
6064 | * HBA error attention handler code. Caller is not required to hold any | |
6065 | * locks. | |
6066 | **/ | |
6067 | int | |
6068 | lpfc_sli4_hba_setup(struct lpfc_hba *phba) | |
6069 | { | |
6070 | int rc; | |
6071 | LPFC_MBOXQ_t *mboxq; | |
6072 | struct lpfc_mqe *mqe; | |
6073 | uint8_t *vpd; | |
6074 | uint32_t vpd_size; | |
6075 | uint32_t ftr_rsp = 0; | |
6076 | struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport); | |
6077 | struct lpfc_vport *vport = phba->pport; | |
6078 | struct lpfc_dmabuf *mp; | |
6079 | ||
6080 | /* Perform a PCI function reset to start from clean */ | |
6081 | rc = lpfc_pci_function_reset(phba); | |
6082 | if (unlikely(rc)) | |
6083 | return -ENODEV; | |
6084 | ||
6085 | /* Check the HBA Host Status Register for readyness */ | |
6086 | rc = lpfc_sli4_post_status_check(phba); | |
6087 | if (unlikely(rc)) | |
6088 | return -ENODEV; | |
6089 | else { | |
6090 | spin_lock_irq(&phba->hbalock); | |
6091 | phba->sli.sli_flag |= LPFC_SLI_ACTIVE; | |
6092 | spin_unlock_irq(&phba->hbalock); | |
6093 | } | |
6094 | ||
6095 | /* | |
6096 | * Allocate a single mailbox container for initializing the | |
6097 | * port. | |
6098 | */ | |
6099 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
6100 | if (!mboxq) | |
6101 | return -ENOMEM; | |
6102 | ||
da0436e9 | 6103 | /* Issue READ_REV to collect vpd and FW information. */ |
49198b37 | 6104 | vpd_size = SLI4_PAGE_SIZE; |
da0436e9 JS |
6105 | vpd = kzalloc(vpd_size, GFP_KERNEL); |
6106 | if (!vpd) { | |
6107 | rc = -ENOMEM; | |
6108 | goto out_free_mbox; | |
6109 | } | |
6110 | ||
6111 | rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size); | |
76a95d75 JS |
6112 | if (unlikely(rc)) { |
6113 | kfree(vpd); | |
6114 | goto out_free_mbox; | |
6115 | } | |
da0436e9 | 6116 | mqe = &mboxq->u.mqe; |
f1126688 JS |
6117 | phba->sli_rev = bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev); |
6118 | if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev)) | |
76a95d75 JS |
6119 | phba->hba_flag |= HBA_FCOE_MODE; |
6120 | else | |
6121 | phba->hba_flag &= ~HBA_FCOE_MODE; | |
45ed1190 JS |
6122 | |
6123 | if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) == | |
6124 | LPFC_DCBX_CEE_MODE) | |
6125 | phba->hba_flag |= HBA_FIP_SUPPORT; | |
6126 | else | |
6127 | phba->hba_flag &= ~HBA_FIP_SUPPORT; | |
6128 | ||
4f2e66c6 JS |
6129 | phba->hba_flag &= ~HBA_FCP_IOQ_FLUSH; |
6130 | ||
c31098ce | 6131 | if (phba->sli_rev != LPFC_SLI_REV4) { |
da0436e9 JS |
6132 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
6133 | "0376 READ_REV Error. SLI Level %d " | |
6134 | "FCoE enabled %d\n", | |
76a95d75 | 6135 | phba->sli_rev, phba->hba_flag & HBA_FCOE_MODE); |
da0436e9 | 6136 | rc = -EIO; |
76a95d75 JS |
6137 | kfree(vpd); |
6138 | goto out_free_mbox; | |
da0436e9 | 6139 | } |
cd1c8301 | 6140 | |
ff78d8f9 JS |
6141 | /* |
6142 | * Continue initialization with default values even if driver failed | |
6143 | * to read FCoE param config regions, only read parameters if the | |
6144 | * board is FCoE | |
6145 | */ | |
6146 | if (phba->hba_flag & HBA_FCOE_MODE && | |
6147 | lpfc_sli4_read_fcoe_params(phba)) | |
6148 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_INIT, | |
6149 | "2570 Failed to read FCoE parameters\n"); | |
6150 | ||
cd1c8301 JS |
6151 | /* |
6152 | * Retrieve sli4 device physical port name, failure of doing it | |
6153 | * is considered as non-fatal. | |
6154 | */ | |
6155 | rc = lpfc_sli4_retrieve_pport_name(phba); | |
6156 | if (!rc) | |
6157 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, | |
6158 | "3080 Successful retrieving SLI4 device " | |
6159 | "physical port name: %s.\n", phba->Port); | |
6160 | ||
da0436e9 JS |
6161 | /* |
6162 | * Evaluate the read rev and vpd data. Populate the driver | |
6163 | * state with the results. If this routine fails, the failure | |
6164 | * is not fatal as the driver will use generic values. | |
6165 | */ | |
6166 | rc = lpfc_parse_vpd(phba, vpd, vpd_size); | |
6167 | if (unlikely(!rc)) { | |
6168 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
6169 | "0377 Error %d parsing vpd. " | |
6170 | "Using defaults.\n", rc); | |
6171 | rc = 0; | |
6172 | } | |
76a95d75 | 6173 | kfree(vpd); |
da0436e9 | 6174 | |
f1126688 JS |
6175 | /* Save information as VPD data */ |
6176 | phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev; | |
6177 | phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev; | |
6178 | phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev; | |
6179 | phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high, | |
6180 | &mqe->un.read_rev); | |
6181 | phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low, | |
6182 | &mqe->un.read_rev); | |
6183 | phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high, | |
6184 | &mqe->un.read_rev); | |
6185 | phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low, | |
6186 | &mqe->un.read_rev); | |
6187 | phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev; | |
6188 | memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16); | |
6189 | phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev; | |
6190 | memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16); | |
6191 | phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev; | |
6192 | memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16); | |
6193 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, | |
6194 | "(%d):0380 READ_REV Status x%x " | |
6195 | "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n", | |
6196 | mboxq->vport ? mboxq->vport->vpi : 0, | |
6197 | bf_get(lpfc_mqe_status, mqe), | |
6198 | phba->vpd.rev.opFwName, | |
6199 | phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow, | |
6200 | phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow); | |
da0436e9 JS |
6201 | |
6202 | /* | |
6203 | * Discover the port's supported feature set and match it against the | |
6204 | * hosts requests. | |
6205 | */ | |
6206 | lpfc_request_features(phba, mboxq); | |
6207 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
6208 | if (unlikely(rc)) { | |
6209 | rc = -EIO; | |
76a95d75 | 6210 | goto out_free_mbox; |
da0436e9 JS |
6211 | } |
6212 | ||
6213 | /* | |
6214 | * The port must support FCP initiator mode as this is the | |
6215 | * only mode running in the host. | |
6216 | */ | |
6217 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) { | |
6218 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, | |
6219 | "0378 No support for fcpi mode.\n"); | |
6220 | ftr_rsp++; | |
6221 | } | |
fedd3b7b JS |
6222 | if (bf_get(lpfc_mbx_rq_ftr_rsp_perfh, &mqe->un.req_ftrs)) |
6223 | phba->sli3_options |= LPFC_SLI4_PERFH_ENABLED; | |
6224 | else | |
6225 | phba->sli3_options &= ~LPFC_SLI4_PERFH_ENABLED; | |
da0436e9 JS |
6226 | /* |
6227 | * If the port cannot support the host's requested features | |
6228 | * then turn off the global config parameters to disable the | |
6229 | * feature in the driver. This is not a fatal error. | |
6230 | */ | |
bf08611b JS |
6231 | phba->sli3_options &= ~LPFC_SLI3_BG_ENABLED; |
6232 | if (phba->cfg_enable_bg) { | |
6233 | if (bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)) | |
6234 | phba->sli3_options |= LPFC_SLI3_BG_ENABLED; | |
6235 | else | |
6236 | ftr_rsp++; | |
6237 | } | |
da0436e9 JS |
6238 | |
6239 | if (phba->max_vpi && phba->cfg_enable_npiv && | |
6240 | !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs))) | |
6241 | ftr_rsp++; | |
6242 | ||
6243 | if (ftr_rsp) { | |
6244 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, | |
6245 | "0379 Feature Mismatch Data: x%08x %08x " | |
6246 | "x%x x%x x%x\n", mqe->un.req_ftrs.word2, | |
6247 | mqe->un.req_ftrs.word3, phba->cfg_enable_bg, | |
6248 | phba->cfg_enable_npiv, phba->max_vpi); | |
6249 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))) | |
6250 | phba->cfg_enable_bg = 0; | |
6251 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs))) | |
6252 | phba->cfg_enable_npiv = 0; | |
6253 | } | |
6254 | ||
6255 | /* These SLI3 features are assumed in SLI4 */ | |
6256 | spin_lock_irq(&phba->hbalock); | |
6257 | phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED); | |
6258 | spin_unlock_irq(&phba->hbalock); | |
6259 | ||
6d368e53 JS |
6260 | /* |
6261 | * Allocate all resources (xri,rpi,vpi,vfi) now. Subsequent | |
6262 | * calls depends on these resources to complete port setup. | |
6263 | */ | |
6264 | rc = lpfc_sli4_alloc_resource_identifiers(phba); | |
6265 | if (rc) { | |
6266 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
6267 | "2920 Failed to alloc Resource IDs " | |
6268 | "rc = x%x\n", rc); | |
6269 | goto out_free_mbox; | |
6270 | } | |
6271 | ||
da0436e9 | 6272 | /* Read the port's service parameters. */ |
9f1177a3 JS |
6273 | rc = lpfc_read_sparam(phba, mboxq, vport->vpi); |
6274 | if (rc) { | |
6275 | phba->link_state = LPFC_HBA_ERROR; | |
6276 | rc = -ENOMEM; | |
76a95d75 | 6277 | goto out_free_mbox; |
9f1177a3 JS |
6278 | } |
6279 | ||
da0436e9 JS |
6280 | mboxq->vport = vport; |
6281 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
6282 | mp = (struct lpfc_dmabuf *) mboxq->context1; | |
6283 | if (rc == MBX_SUCCESS) { | |
6284 | memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm)); | |
6285 | rc = 0; | |
6286 | } | |
6287 | ||
6288 | /* | |
6289 | * This memory was allocated by the lpfc_read_sparam routine. Release | |
6290 | * it to the mbuf pool. | |
6291 | */ | |
6292 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
6293 | kfree(mp); | |
6294 | mboxq->context1 = NULL; | |
6295 | if (unlikely(rc)) { | |
6296 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
6297 | "0382 READ_SPARAM command failed " | |
6298 | "status %d, mbxStatus x%x\n", | |
6299 | rc, bf_get(lpfc_mqe_status, mqe)); | |
6300 | phba->link_state = LPFC_HBA_ERROR; | |
6301 | rc = -EIO; | |
76a95d75 | 6302 | goto out_free_mbox; |
da0436e9 JS |
6303 | } |
6304 | ||
0558056c | 6305 | lpfc_update_vport_wwn(vport); |
da0436e9 JS |
6306 | |
6307 | /* Update the fc_host data structures with new wwn. */ | |
6308 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); | |
6309 | fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn); | |
6310 | ||
8a9d2e80 JS |
6311 | /* update host els and scsi xri-sgl sizes and mappings */ |
6312 | rc = lpfc_sli4_xri_sgl_update(phba); | |
6313 | if (unlikely(rc)) { | |
6314 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
6315 | "1400 Failed to update xri-sgl size and " | |
6316 | "mapping: %d\n", rc); | |
6317 | goto out_free_mbox; | |
da0436e9 JS |
6318 | } |
6319 | ||
8a9d2e80 JS |
6320 | /* register the els sgl pool to the port */ |
6321 | rc = lpfc_sli4_repost_els_sgl_list(phba); | |
6322 | if (unlikely(rc)) { | |
6323 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
6324 | "0582 Error %d during els sgl post " | |
6325 | "operation\n", rc); | |
6326 | rc = -ENODEV; | |
6327 | goto out_free_mbox; | |
6328 | } | |
6329 | ||
6330 | /* register the allocated scsi sgl pool to the port */ | |
da0436e9 JS |
6331 | rc = lpfc_sli4_repost_scsi_sgl_list(phba); |
6332 | if (unlikely(rc)) { | |
6d368e53 | 6333 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
6a9c52cf JS |
6334 | "0383 Error %d during scsi sgl post " |
6335 | "operation\n", rc); | |
da0436e9 JS |
6336 | /* Some Scsi buffers were moved to the abort scsi list */ |
6337 | /* A pci function reset will repost them */ | |
6338 | rc = -ENODEV; | |
76a95d75 | 6339 | goto out_free_mbox; |
da0436e9 JS |
6340 | } |
6341 | ||
6342 | /* Post the rpi header region to the device. */ | |
6343 | rc = lpfc_sli4_post_all_rpi_hdrs(phba); | |
6344 | if (unlikely(rc)) { | |
6345 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
6346 | "0393 Error %d during rpi post operation\n", | |
6347 | rc); | |
6348 | rc = -ENODEV; | |
76a95d75 | 6349 | goto out_free_mbox; |
da0436e9 | 6350 | } |
97f2ecf1 | 6351 | lpfc_sli4_node_prep(phba); |
da0436e9 | 6352 | |
5350d872 JS |
6353 | /* Create all the SLI4 queues */ |
6354 | rc = lpfc_sli4_queue_create(phba); | |
6355 | if (rc) { | |
6356 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6357 | "3089 Failed to allocate queues\n"); | |
6358 | rc = -ENODEV; | |
6359 | goto out_stop_timers; | |
6360 | } | |
da0436e9 JS |
6361 | /* Set up all the queues to the device */ |
6362 | rc = lpfc_sli4_queue_setup(phba); | |
6363 | if (unlikely(rc)) { | |
6364 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
6365 | "0381 Error %d during queue setup.\n ", rc); | |
5350d872 | 6366 | goto out_destroy_queue; |
da0436e9 JS |
6367 | } |
6368 | ||
6369 | /* Arm the CQs and then EQs on device */ | |
6370 | lpfc_sli4_arm_cqeq_intr(phba); | |
6371 | ||
6372 | /* Indicate device interrupt mode */ | |
6373 | phba->sli4_hba.intr_enable = 1; | |
6374 | ||
6375 | /* Allow asynchronous mailbox command to go through */ | |
6376 | spin_lock_irq(&phba->hbalock); | |
6377 | phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; | |
6378 | spin_unlock_irq(&phba->hbalock); | |
6379 | ||
6380 | /* Post receive buffers to the device */ | |
6381 | lpfc_sli4_rb_setup(phba); | |
6382 | ||
fc2b989b JS |
6383 | /* Reset HBA FCF states after HBA reset */ |
6384 | phba->fcf.fcf_flag = 0; | |
6385 | phba->fcf.current_rec.flag = 0; | |
6386 | ||
da0436e9 | 6387 | /* Start the ELS watchdog timer */ |
8fa38513 JS |
6388 | mod_timer(&vport->els_tmofunc, |
6389 | jiffies + HZ * (phba->fc_ratov * 2)); | |
da0436e9 JS |
6390 | |
6391 | /* Start heart beat timer */ | |
6392 | mod_timer(&phba->hb_tmofunc, | |
6393 | jiffies + HZ * LPFC_HB_MBOX_INTERVAL); | |
6394 | phba->hb_outstanding = 0; | |
6395 | phba->last_completion_time = jiffies; | |
6396 | ||
6397 | /* Start error attention (ERATT) polling timer */ | |
6398 | mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL); | |
6399 | ||
75baf696 JS |
6400 | /* Enable PCIe device Advanced Error Reporting (AER) if configured */ |
6401 | if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) { | |
6402 | rc = pci_enable_pcie_error_reporting(phba->pcidev); | |
6403 | if (!rc) { | |
6404 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
6405 | "2829 This device supports " | |
6406 | "Advanced Error Reporting (AER)\n"); | |
6407 | spin_lock_irq(&phba->hbalock); | |
6408 | phba->hba_flag |= HBA_AER_ENABLED; | |
6409 | spin_unlock_irq(&phba->hbalock); | |
6410 | } else { | |
6411 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
6412 | "2830 This device does not support " | |
6413 | "Advanced Error Reporting (AER)\n"); | |
6414 | phba->cfg_aer_support = 0; | |
6415 | } | |
0a96e975 | 6416 | rc = 0; |
75baf696 JS |
6417 | } |
6418 | ||
76a95d75 JS |
6419 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { |
6420 | /* | |
6421 | * The FC Port needs to register FCFI (index 0) | |
6422 | */ | |
6423 | lpfc_reg_fcfi(phba, mboxq); | |
6424 | mboxq->vport = phba->pport; | |
6425 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
9589b062 | 6426 | if (rc != MBX_SUCCESS) |
76a95d75 | 6427 | goto out_unset_queue; |
9589b062 JS |
6428 | rc = 0; |
6429 | phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, | |
6430 | &mboxq->u.mqe.un.reg_fcfi); | |
026abb87 JS |
6431 | |
6432 | /* Check if the port is configured to be disabled */ | |
6433 | lpfc_sli_read_link_ste(phba); | |
76a95d75 | 6434 | } |
026abb87 | 6435 | |
da0436e9 JS |
6436 | /* |
6437 | * The port is ready, set the host's link state to LINK_DOWN | |
6438 | * in preparation for link interrupts. | |
6439 | */ | |
da0436e9 JS |
6440 | spin_lock_irq(&phba->hbalock); |
6441 | phba->link_state = LPFC_LINK_DOWN; | |
6442 | spin_unlock_irq(&phba->hbalock); | |
026abb87 JS |
6443 | if (!(phba->hba_flag & HBA_FCOE_MODE) && |
6444 | (phba->hba_flag & LINK_DISABLED)) { | |
6445 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI, | |
6446 | "3103 Adapter Link is disabled.\n"); | |
6447 | lpfc_down_link(phba, mboxq); | |
6448 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
6449 | if (rc != MBX_SUCCESS) { | |
6450 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI, | |
6451 | "3104 Adapter failed to issue " | |
6452 | "DOWN_LINK mbox cmd, rc:x%x\n", rc); | |
6453 | goto out_unset_queue; | |
6454 | } | |
6455 | } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) { | |
1b51197d JS |
6456 | /* don't perform init_link on SLI4 FC port loopback test */ |
6457 | if (!(phba->link_flag & LS_LOOPBACK_MODE)) { | |
6458 | rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT); | |
6459 | if (rc) | |
6460 | goto out_unset_queue; | |
6461 | } | |
5350d872 JS |
6462 | } |
6463 | mempool_free(mboxq, phba->mbox_mem_pool); | |
6464 | return rc; | |
76a95d75 | 6465 | out_unset_queue: |
da0436e9 | 6466 | /* Unset all the queues set up in this routine when error out */ |
5350d872 JS |
6467 | lpfc_sli4_queue_unset(phba); |
6468 | out_destroy_queue: | |
6469 | lpfc_sli4_queue_destroy(phba); | |
da0436e9 | 6470 | out_stop_timers: |
5350d872 | 6471 | lpfc_stop_hba_timers(phba); |
da0436e9 JS |
6472 | out_free_mbox: |
6473 | mempool_free(mboxq, phba->mbox_mem_pool); | |
6474 | return rc; | |
6475 | } | |
6476 | ||
6477 | /** | |
6478 | * lpfc_mbox_timeout - Timeout call back function for mbox timer | |
6479 | * @ptr: context object - pointer to hba structure. | |
6480 | * | |
6481 | * This is the callback function for mailbox timer. The mailbox | |
6482 | * timer is armed when a new mailbox command is issued and the timer | |
6483 | * is deleted when the mailbox complete. The function is called by | |
6484 | * the kernel timer code when a mailbox does not complete within | |
6485 | * expected time. This function wakes up the worker thread to | |
6486 | * process the mailbox timeout and returns. All the processing is | |
6487 | * done by the worker thread function lpfc_mbox_timeout_handler. | |
6488 | **/ | |
6489 | void | |
6490 | lpfc_mbox_timeout(unsigned long ptr) | |
6491 | { | |
6492 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; | |
6493 | unsigned long iflag; | |
6494 | uint32_t tmo_posted; | |
6495 | ||
6496 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); | |
6497 | tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO; | |
6498 | if (!tmo_posted) | |
6499 | phba->pport->work_port_events |= WORKER_MBOX_TMO; | |
6500 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); | |
6501 | ||
6502 | if (!tmo_posted) | |
6503 | lpfc_worker_wake_up(phba); | |
6504 | return; | |
6505 | } | |
6506 | ||
6507 | ||
6508 | /** | |
6509 | * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout | |
6510 | * @phba: Pointer to HBA context object. | |
6511 | * | |
6512 | * This function is called from worker thread when a mailbox command times out. | |
6513 | * The caller is not required to hold any locks. This function will reset the | |
6514 | * HBA and recover all the pending commands. | |
6515 | **/ | |
6516 | void | |
6517 | lpfc_mbox_timeout_handler(struct lpfc_hba *phba) | |
6518 | { | |
6519 | LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active; | |
04c68496 | 6520 | MAILBOX_t *mb = &pmbox->u.mb; |
da0436e9 JS |
6521 | struct lpfc_sli *psli = &phba->sli; |
6522 | struct lpfc_sli_ring *pring; | |
6523 | ||
6524 | /* Check the pmbox pointer first. There is a race condition | |
6525 | * between the mbox timeout handler getting executed in the | |
6526 | * worklist and the mailbox actually completing. When this | |
6527 | * race condition occurs, the mbox_active will be NULL. | |
6528 | */ | |
6529 | spin_lock_irq(&phba->hbalock); | |
6530 | if (pmbox == NULL) { | |
6531 | lpfc_printf_log(phba, KERN_WARNING, | |
6532 | LOG_MBOX | LOG_SLI, | |
6533 | "0353 Active Mailbox cleared - mailbox timeout " | |
6534 | "exiting\n"); | |
6535 | spin_unlock_irq(&phba->hbalock); | |
6536 | return; | |
6537 | } | |
6538 | ||
6539 | /* Mbox cmd <mbxCommand> timeout */ | |
6540 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
6541 | "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n", | |
6542 | mb->mbxCommand, | |
6543 | phba->pport->port_state, | |
6544 | phba->sli.sli_flag, | |
6545 | phba->sli.mbox_active); | |
6546 | spin_unlock_irq(&phba->hbalock); | |
6547 | ||
6548 | /* Setting state unknown so lpfc_sli_abort_iocb_ring | |
6549 | * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing | |
25985edc | 6550 | * it to fail all outstanding SCSI IO. |
da0436e9 JS |
6551 | */ |
6552 | spin_lock_irq(&phba->pport->work_port_lock); | |
6553 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; | |
6554 | spin_unlock_irq(&phba->pport->work_port_lock); | |
6555 | spin_lock_irq(&phba->hbalock); | |
6556 | phba->link_state = LPFC_LINK_UNKNOWN; | |
f4b4c68f | 6557 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
da0436e9 JS |
6558 | spin_unlock_irq(&phba->hbalock); |
6559 | ||
6560 | pring = &psli->ring[psli->fcp_ring]; | |
6561 | lpfc_sli_abort_iocb_ring(phba, pring); | |
6562 | ||
6563 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
6564 | "0345 Resetting board due to mailbox timeout\n"); | |
6565 | ||
6566 | /* Reset the HBA device */ | |
6567 | lpfc_reset_hba(phba); | |
6568 | } | |
6569 | ||
6570 | /** | |
6571 | * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware | |
6572 | * @phba: Pointer to HBA context object. | |
6573 | * @pmbox: Pointer to mailbox object. | |
6574 | * @flag: Flag indicating how the mailbox need to be processed. | |
6575 | * | |
6576 | * This function is called by discovery code and HBA management code | |
6577 | * to submit a mailbox command to firmware with SLI-3 interface spec. This | |
6578 | * function gets the hbalock to protect the data structures. | |
6579 | * The mailbox command can be submitted in polling mode, in which case | |
6580 | * this function will wait in a polling loop for the completion of the | |
6581 | * mailbox. | |
6582 | * If the mailbox is submitted in no_wait mode (not polling) the | |
6583 | * function will submit the command and returns immediately without waiting | |
6584 | * for the mailbox completion. The no_wait is supported only when HBA | |
6585 | * is in SLI2/SLI3 mode - interrupts are enabled. | |
6586 | * The SLI interface allows only one mailbox pending at a time. If the | |
6587 | * mailbox is issued in polling mode and there is already a mailbox | |
6588 | * pending, then the function will return an error. If the mailbox is issued | |
6589 | * in NO_WAIT mode and there is a mailbox pending already, the function | |
6590 | * will return MBX_BUSY after queuing the mailbox into mailbox queue. | |
6591 | * The sli layer owns the mailbox object until the completion of mailbox | |
6592 | * command if this function return MBX_BUSY or MBX_SUCCESS. For all other | |
6593 | * return codes the caller owns the mailbox command after the return of | |
6594 | * the function. | |
e59058c4 | 6595 | **/ |
3772a991 JS |
6596 | static int |
6597 | lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, | |
6598 | uint32_t flag) | |
dea3101e | 6599 | { |
dea3101e | 6600 | MAILBOX_t *mb; |
2e0fef85 | 6601 | struct lpfc_sli *psli = &phba->sli; |
dea3101e | 6602 | uint32_t status, evtctr; |
9940b97b | 6603 | uint32_t ha_copy, hc_copy; |
dea3101e | 6604 | int i; |
09372820 | 6605 | unsigned long timeout; |
dea3101e | 6606 | unsigned long drvr_flag = 0; |
34b02dcd | 6607 | uint32_t word0, ldata; |
dea3101e | 6608 | void __iomem *to_slim; |
58da1ffb JS |
6609 | int processing_queue = 0; |
6610 | ||
6611 | spin_lock_irqsave(&phba->hbalock, drvr_flag); | |
6612 | if (!pmbox) { | |
8568a4d2 | 6613 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
58da1ffb | 6614 | /* processing mbox queue from intr_handler */ |
3772a991 JS |
6615 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
6616 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | |
6617 | return MBX_SUCCESS; | |
6618 | } | |
58da1ffb | 6619 | processing_queue = 1; |
58da1ffb JS |
6620 | pmbox = lpfc_mbox_get(phba); |
6621 | if (!pmbox) { | |
6622 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | |
6623 | return MBX_SUCCESS; | |
6624 | } | |
6625 | } | |
dea3101e | 6626 | |
ed957684 | 6627 | if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl && |
92d7f7b0 | 6628 | pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) { |
ed957684 | 6629 | if(!pmbox->vport) { |
58da1ffb | 6630 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
ed957684 | 6631 | lpfc_printf_log(phba, KERN_ERR, |
92d7f7b0 | 6632 | LOG_MBOX | LOG_VPORT, |
e8b62011 | 6633 | "1806 Mbox x%x failed. No vport\n", |
3772a991 | 6634 | pmbox->u.mb.mbxCommand); |
ed957684 | 6635 | dump_stack(); |
58da1ffb | 6636 | goto out_not_finished; |
ed957684 JS |
6637 | } |
6638 | } | |
6639 | ||
8d63f375 | 6640 | /* If the PCI channel is in offline state, do not post mbox. */ |
58da1ffb JS |
6641 | if (unlikely(pci_channel_offline(phba->pcidev))) { |
6642 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | |
6643 | goto out_not_finished; | |
6644 | } | |
8d63f375 | 6645 | |
a257bf90 JS |
6646 | /* If HBA has a deferred error attention, fail the iocb. */ |
6647 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { | |
6648 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | |
6649 | goto out_not_finished; | |
6650 | } | |
6651 | ||
dea3101e | 6652 | psli = &phba->sli; |
92d7f7b0 | 6653 | |
3772a991 | 6654 | mb = &pmbox->u.mb; |
dea3101e | 6655 | status = MBX_SUCCESS; |
6656 | ||
2e0fef85 JS |
6657 | if (phba->link_state == LPFC_HBA_ERROR) { |
6658 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | |
41415862 JW |
6659 | |
6660 | /* Mbox command <mbxCommand> cannot issue */ | |
3772a991 JS |
6661 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
6662 | "(%d):0311 Mailbox command x%x cannot " | |
6663 | "issue Data: x%x x%x\n", | |
6664 | pmbox->vport ? pmbox->vport->vpi : 0, | |
6665 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); | |
58da1ffb | 6666 | goto out_not_finished; |
41415862 JW |
6667 | } |
6668 | ||
9940b97b JS |
6669 | if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT) { |
6670 | if (lpfc_readl(phba->HCregaddr, &hc_copy) || | |
6671 | !(hc_copy & HC_MBINT_ENA)) { | |
6672 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | |
6673 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
3772a991 JS |
6674 | "(%d):2528 Mailbox command x%x cannot " |
6675 | "issue Data: x%x x%x\n", | |
6676 | pmbox->vport ? pmbox->vport->vpi : 0, | |
6677 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); | |
9940b97b JS |
6678 | goto out_not_finished; |
6679 | } | |
9290831f JS |
6680 | } |
6681 | ||
dea3101e | 6682 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
6683 | /* Polling for a mbox command when another one is already active | |
6684 | * is not allowed in SLI. Also, the driver must have established | |
6685 | * SLI2 mode to queue and process multiple mbox commands. | |
6686 | */ | |
6687 | ||
6688 | if (flag & MBX_POLL) { | |
2e0fef85 | 6689 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
dea3101e | 6690 | |
6691 | /* Mbox command <mbxCommand> cannot issue */ | |
3772a991 JS |
6692 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
6693 | "(%d):2529 Mailbox command x%x " | |
6694 | "cannot issue Data: x%x x%x\n", | |
6695 | pmbox->vport ? pmbox->vport->vpi : 0, | |
6696 | pmbox->u.mb.mbxCommand, | |
6697 | psli->sli_flag, flag); | |
58da1ffb | 6698 | goto out_not_finished; |
dea3101e | 6699 | } |
6700 | ||
3772a991 | 6701 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) { |
2e0fef85 | 6702 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
dea3101e | 6703 | /* Mbox command <mbxCommand> cannot issue */ |
3772a991 JS |
6704 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
6705 | "(%d):2530 Mailbox command x%x " | |
6706 | "cannot issue Data: x%x x%x\n", | |
6707 | pmbox->vport ? pmbox->vport->vpi : 0, | |
6708 | pmbox->u.mb.mbxCommand, | |
6709 | psli->sli_flag, flag); | |
58da1ffb | 6710 | goto out_not_finished; |
dea3101e | 6711 | } |
6712 | ||
dea3101e | 6713 | /* Another mailbox command is still being processed, queue this |
6714 | * command to be processed later. | |
6715 | */ | |
6716 | lpfc_mbox_put(phba, pmbox); | |
6717 | ||
6718 | /* Mbox cmd issue - BUSY */ | |
ed957684 | 6719 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
e8b62011 | 6720 | "(%d):0308 Mbox cmd issue - BUSY Data: " |
92d7f7b0 | 6721 | "x%x x%x x%x x%x\n", |
92d7f7b0 JS |
6722 | pmbox->vport ? pmbox->vport->vpi : 0xffffff, |
6723 | mb->mbxCommand, phba->pport->port_state, | |
6724 | psli->sli_flag, flag); | |
dea3101e | 6725 | |
6726 | psli->slistat.mbox_busy++; | |
2e0fef85 | 6727 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
dea3101e | 6728 | |
858c9f6c JS |
6729 | if (pmbox->vport) { |
6730 | lpfc_debugfs_disc_trc(pmbox->vport, | |
6731 | LPFC_DISC_TRC_MBOX_VPORT, | |
6732 | "MBOX Bsy vport: cmd:x%x mb:x%x x%x", | |
6733 | (uint32_t)mb->mbxCommand, | |
6734 | mb->un.varWords[0], mb->un.varWords[1]); | |
6735 | } | |
6736 | else { | |
6737 | lpfc_debugfs_disc_trc(phba->pport, | |
6738 | LPFC_DISC_TRC_MBOX, | |
6739 | "MBOX Bsy: cmd:x%x mb:x%x x%x", | |
6740 | (uint32_t)mb->mbxCommand, | |
6741 | mb->un.varWords[0], mb->un.varWords[1]); | |
6742 | } | |
6743 | ||
2e0fef85 | 6744 | return MBX_BUSY; |
dea3101e | 6745 | } |
6746 | ||
dea3101e | 6747 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
6748 | ||
6749 | /* If we are not polling, we MUST be in SLI2 mode */ | |
6750 | if (flag != MBX_POLL) { | |
3772a991 | 6751 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE) && |
41415862 | 6752 | (mb->mbxCommand != MBX_KILL_BOARD)) { |
dea3101e | 6753 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
2e0fef85 | 6754 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
dea3101e | 6755 | /* Mbox command <mbxCommand> cannot issue */ |
3772a991 JS |
6756 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
6757 | "(%d):2531 Mailbox command x%x " | |
6758 | "cannot issue Data: x%x x%x\n", | |
6759 | pmbox->vport ? pmbox->vport->vpi : 0, | |
6760 | pmbox->u.mb.mbxCommand, | |
6761 | psli->sli_flag, flag); | |
58da1ffb | 6762 | goto out_not_finished; |
dea3101e | 6763 | } |
6764 | /* timeout active mbox command */ | |
a309a6b6 | 6765 | mod_timer(&psli->mbox_tmo, (jiffies + |
a183a15f | 6766 | (HZ * lpfc_mbox_tmo_val(phba, pmbox)))); |
dea3101e | 6767 | } |
6768 | ||
6769 | /* Mailbox cmd <cmd> issue */ | |
ed957684 | 6770 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
e8b62011 | 6771 | "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x " |
92d7f7b0 | 6772 | "x%x\n", |
e8b62011 | 6773 | pmbox->vport ? pmbox->vport->vpi : 0, |
92d7f7b0 JS |
6774 | mb->mbxCommand, phba->pport->port_state, |
6775 | psli->sli_flag, flag); | |
dea3101e | 6776 | |
858c9f6c JS |
6777 | if (mb->mbxCommand != MBX_HEARTBEAT) { |
6778 | if (pmbox->vport) { | |
6779 | lpfc_debugfs_disc_trc(pmbox->vport, | |
6780 | LPFC_DISC_TRC_MBOX_VPORT, | |
6781 | "MBOX Send vport: cmd:x%x mb:x%x x%x", | |
6782 | (uint32_t)mb->mbxCommand, | |
6783 | mb->un.varWords[0], mb->un.varWords[1]); | |
6784 | } | |
6785 | else { | |
6786 | lpfc_debugfs_disc_trc(phba->pport, | |
6787 | LPFC_DISC_TRC_MBOX, | |
6788 | "MBOX Send: cmd:x%x mb:x%x x%x", | |
6789 | (uint32_t)mb->mbxCommand, | |
6790 | mb->un.varWords[0], mb->un.varWords[1]); | |
6791 | } | |
6792 | } | |
6793 | ||
dea3101e | 6794 | psli->slistat.mbox_cmd++; |
6795 | evtctr = psli->slistat.mbox_event; | |
6796 | ||
6797 | /* next set own bit for the adapter and copy over command word */ | |
6798 | mb->mbxOwner = OWN_CHIP; | |
6799 | ||
3772a991 | 6800 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
7a470277 JS |
6801 | /* Populate mbox extension offset word. */ |
6802 | if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) { | |
6803 | *(((uint32_t *)mb) + pmbox->mbox_offset_word) | |
6804 | = (uint8_t *)phba->mbox_ext | |
6805 | - (uint8_t *)phba->mbox; | |
6806 | } | |
6807 | ||
6808 | /* Copy the mailbox extension data */ | |
6809 | if (pmbox->in_ext_byte_len && pmbox->context2) { | |
6810 | lpfc_sli_pcimem_bcopy(pmbox->context2, | |
6811 | (uint8_t *)phba->mbox_ext, | |
6812 | pmbox->in_ext_byte_len); | |
6813 | } | |
6814 | /* Copy command data to host SLIM area */ | |
34b02dcd | 6815 | lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE); |
dea3101e | 6816 | } else { |
7a470277 JS |
6817 | /* Populate mbox extension offset word. */ |
6818 | if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) | |
6819 | *(((uint32_t *)mb) + pmbox->mbox_offset_word) | |
6820 | = MAILBOX_HBA_EXT_OFFSET; | |
6821 | ||
6822 | /* Copy the mailbox extension data */ | |
6823 | if (pmbox->in_ext_byte_len && pmbox->context2) { | |
6824 | lpfc_memcpy_to_slim(phba->MBslimaddr + | |
6825 | MAILBOX_HBA_EXT_OFFSET, | |
6826 | pmbox->context2, pmbox->in_ext_byte_len); | |
6827 | ||
6828 | } | |
9290831f | 6829 | if (mb->mbxCommand == MBX_CONFIG_PORT) { |
dea3101e | 6830 | /* copy command data into host mbox for cmpl */ |
34b02dcd | 6831 | lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE); |
dea3101e | 6832 | } |
6833 | ||
6834 | /* First copy mbox command data to HBA SLIM, skip past first | |
6835 | word */ | |
6836 | to_slim = phba->MBslimaddr + sizeof (uint32_t); | |
6837 | lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0], | |
6838 | MAILBOX_CMD_SIZE - sizeof (uint32_t)); | |
6839 | ||
6840 | /* Next copy over first word, with mbxOwner set */ | |
34b02dcd | 6841 | ldata = *((uint32_t *)mb); |
dea3101e | 6842 | to_slim = phba->MBslimaddr; |
6843 | writel(ldata, to_slim); | |
6844 | readl(to_slim); /* flush */ | |
6845 | ||
6846 | if (mb->mbxCommand == MBX_CONFIG_PORT) { | |
6847 | /* switch over to host mailbox */ | |
3772a991 | 6848 | psli->sli_flag |= LPFC_SLI_ACTIVE; |
dea3101e | 6849 | } |
6850 | } | |
6851 | ||
6852 | wmb(); | |
dea3101e | 6853 | |
6854 | switch (flag) { | |
6855 | case MBX_NOWAIT: | |
09372820 | 6856 | /* Set up reference to mailbox command */ |
dea3101e | 6857 | psli->mbox_active = pmbox; |
09372820 JS |
6858 | /* Interrupt board to do it */ |
6859 | writel(CA_MBATT, phba->CAregaddr); | |
6860 | readl(phba->CAregaddr); /* flush */ | |
6861 | /* Don't wait for it to finish, just return */ | |
dea3101e | 6862 | break; |
6863 | ||
6864 | case MBX_POLL: | |
09372820 | 6865 | /* Set up null reference to mailbox command */ |
dea3101e | 6866 | psli->mbox_active = NULL; |
09372820 JS |
6867 | /* Interrupt board to do it */ |
6868 | writel(CA_MBATT, phba->CAregaddr); | |
6869 | readl(phba->CAregaddr); /* flush */ | |
6870 | ||
3772a991 | 6871 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
dea3101e | 6872 | /* First read mbox status word */ |
34b02dcd | 6873 | word0 = *((uint32_t *)phba->mbox); |
dea3101e | 6874 | word0 = le32_to_cpu(word0); |
6875 | } else { | |
6876 | /* First read mbox status word */ | |
9940b97b JS |
6877 | if (lpfc_readl(phba->MBslimaddr, &word0)) { |
6878 | spin_unlock_irqrestore(&phba->hbalock, | |
6879 | drvr_flag); | |
6880 | goto out_not_finished; | |
6881 | } | |
dea3101e | 6882 | } |
6883 | ||
6884 | /* Read the HBA Host Attention Register */ | |
9940b97b JS |
6885 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) { |
6886 | spin_unlock_irqrestore(&phba->hbalock, | |
6887 | drvr_flag); | |
6888 | goto out_not_finished; | |
6889 | } | |
a183a15f JS |
6890 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) * |
6891 | 1000) + jiffies; | |
09372820 | 6892 | i = 0; |
dea3101e | 6893 | /* Wait for command to complete */ |
41415862 JW |
6894 | while (((word0 & OWN_CHIP) == OWN_CHIP) || |
6895 | (!(ha_copy & HA_MBATT) && | |
2e0fef85 | 6896 | (phba->link_state > LPFC_WARM_START))) { |
09372820 | 6897 | if (time_after(jiffies, timeout)) { |
dea3101e | 6898 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
2e0fef85 | 6899 | spin_unlock_irqrestore(&phba->hbalock, |
dea3101e | 6900 | drvr_flag); |
58da1ffb | 6901 | goto out_not_finished; |
dea3101e | 6902 | } |
6903 | ||
6904 | /* Check if we took a mbox interrupt while we were | |
6905 | polling */ | |
6906 | if (((word0 & OWN_CHIP) != OWN_CHIP) | |
6907 | && (evtctr != psli->slistat.mbox_event)) | |
6908 | break; | |
6909 | ||
09372820 JS |
6910 | if (i++ > 10) { |
6911 | spin_unlock_irqrestore(&phba->hbalock, | |
6912 | drvr_flag); | |
6913 | msleep(1); | |
6914 | spin_lock_irqsave(&phba->hbalock, drvr_flag); | |
6915 | } | |
dea3101e | 6916 | |
3772a991 | 6917 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
dea3101e | 6918 | /* First copy command data */ |
34b02dcd | 6919 | word0 = *((uint32_t *)phba->mbox); |
dea3101e | 6920 | word0 = le32_to_cpu(word0); |
6921 | if (mb->mbxCommand == MBX_CONFIG_PORT) { | |
6922 | MAILBOX_t *slimmb; | |
34b02dcd | 6923 | uint32_t slimword0; |
dea3101e | 6924 | /* Check real SLIM for any errors */ |
6925 | slimword0 = readl(phba->MBslimaddr); | |
6926 | slimmb = (MAILBOX_t *) & slimword0; | |
6927 | if (((slimword0 & OWN_CHIP) != OWN_CHIP) | |
6928 | && slimmb->mbxStatus) { | |
6929 | psli->sli_flag &= | |
3772a991 | 6930 | ~LPFC_SLI_ACTIVE; |
dea3101e | 6931 | word0 = slimword0; |
6932 | } | |
6933 | } | |
6934 | } else { | |
6935 | /* First copy command data */ | |
6936 | word0 = readl(phba->MBslimaddr); | |
6937 | } | |
6938 | /* Read the HBA Host Attention Register */ | |
9940b97b JS |
6939 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) { |
6940 | spin_unlock_irqrestore(&phba->hbalock, | |
6941 | drvr_flag); | |
6942 | goto out_not_finished; | |
6943 | } | |
dea3101e | 6944 | } |
6945 | ||
3772a991 | 6946 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
dea3101e | 6947 | /* copy results back to user */ |
34b02dcd | 6948 | lpfc_sli_pcimem_bcopy(phba->mbox, mb, MAILBOX_CMD_SIZE); |
7a470277 JS |
6949 | /* Copy the mailbox extension data */ |
6950 | if (pmbox->out_ext_byte_len && pmbox->context2) { | |
6951 | lpfc_sli_pcimem_bcopy(phba->mbox_ext, | |
6952 | pmbox->context2, | |
6953 | pmbox->out_ext_byte_len); | |
6954 | } | |
dea3101e | 6955 | } else { |
6956 | /* First copy command data */ | |
6957 | lpfc_memcpy_from_slim(mb, phba->MBslimaddr, | |
6958 | MAILBOX_CMD_SIZE); | |
7a470277 JS |
6959 | /* Copy the mailbox extension data */ |
6960 | if (pmbox->out_ext_byte_len && pmbox->context2) { | |
6961 | lpfc_memcpy_from_slim(pmbox->context2, | |
6962 | phba->MBslimaddr + | |
6963 | MAILBOX_HBA_EXT_OFFSET, | |
6964 | pmbox->out_ext_byte_len); | |
dea3101e | 6965 | } |
6966 | } | |
6967 | ||
6968 | writel(HA_MBATT, phba->HAregaddr); | |
6969 | readl(phba->HAregaddr); /* flush */ | |
6970 | ||
6971 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
6972 | status = mb->mbxStatus; | |
6973 | } | |
6974 | ||
2e0fef85 JS |
6975 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
6976 | return status; | |
58da1ffb JS |
6977 | |
6978 | out_not_finished: | |
6979 | if (processing_queue) { | |
da0436e9 | 6980 | pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED; |
58da1ffb JS |
6981 | lpfc_mbox_cmpl_put(phba, pmbox); |
6982 | } | |
6983 | return MBX_NOT_FINISHED; | |
dea3101e | 6984 | } |
6985 | ||
f1126688 JS |
6986 | /** |
6987 | * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command | |
6988 | * @phba: Pointer to HBA context object. | |
6989 | * | |
6990 | * The function blocks the posting of SLI4 asynchronous mailbox commands from | |
6991 | * the driver internal pending mailbox queue. It will then try to wait out the | |
6992 | * possible outstanding mailbox command before return. | |
6993 | * | |
6994 | * Returns: | |
6995 | * 0 - the outstanding mailbox command completed; otherwise, the wait for | |
6996 | * the outstanding mailbox command timed out. | |
6997 | **/ | |
6998 | static int | |
6999 | lpfc_sli4_async_mbox_block(struct lpfc_hba *phba) | |
7000 | { | |
7001 | struct lpfc_sli *psli = &phba->sli; | |
f1126688 | 7002 | int rc = 0; |
a183a15f | 7003 | unsigned long timeout = 0; |
f1126688 JS |
7004 | |
7005 | /* Mark the asynchronous mailbox command posting as blocked */ | |
7006 | spin_lock_irq(&phba->hbalock); | |
7007 | psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; | |
f1126688 JS |
7008 | /* Determine how long we might wait for the active mailbox |
7009 | * command to be gracefully completed by firmware. | |
7010 | */ | |
a183a15f JS |
7011 | if (phba->sli.mbox_active) |
7012 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, | |
7013 | phba->sli.mbox_active) * | |
7014 | 1000) + jiffies; | |
7015 | spin_unlock_irq(&phba->hbalock); | |
7016 | ||
f1126688 JS |
7017 | /* Wait for the outstnading mailbox command to complete */ |
7018 | while (phba->sli.mbox_active) { | |
7019 | /* Check active mailbox complete status every 2ms */ | |
7020 | msleep(2); | |
7021 | if (time_after(jiffies, timeout)) { | |
7022 | /* Timeout, marked the outstanding cmd not complete */ | |
7023 | rc = 1; | |
7024 | break; | |
7025 | } | |
7026 | } | |
7027 | ||
7028 | /* Can not cleanly block async mailbox command, fails it */ | |
7029 | if (rc) { | |
7030 | spin_lock_irq(&phba->hbalock); | |
7031 | psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; | |
7032 | spin_unlock_irq(&phba->hbalock); | |
7033 | } | |
7034 | return rc; | |
7035 | } | |
7036 | ||
7037 | /** | |
7038 | * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command | |
7039 | * @phba: Pointer to HBA context object. | |
7040 | * | |
7041 | * The function unblocks and resume posting of SLI4 asynchronous mailbox | |
7042 | * commands from the driver internal pending mailbox queue. It makes sure | |
7043 | * that there is no outstanding mailbox command before resuming posting | |
7044 | * asynchronous mailbox commands. If, for any reason, there is outstanding | |
7045 | * mailbox command, it will try to wait it out before resuming asynchronous | |
7046 | * mailbox command posting. | |
7047 | **/ | |
7048 | static void | |
7049 | lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba) | |
7050 | { | |
7051 | struct lpfc_sli *psli = &phba->sli; | |
7052 | ||
7053 | spin_lock_irq(&phba->hbalock); | |
7054 | if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { | |
7055 | /* Asynchronous mailbox posting is not blocked, do nothing */ | |
7056 | spin_unlock_irq(&phba->hbalock); | |
7057 | return; | |
7058 | } | |
7059 | ||
7060 | /* Outstanding synchronous mailbox command is guaranteed to be done, | |
7061 | * successful or timeout, after timing-out the outstanding mailbox | |
7062 | * command shall always be removed, so just unblock posting async | |
7063 | * mailbox command and resume | |
7064 | */ | |
7065 | psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; | |
7066 | spin_unlock_irq(&phba->hbalock); | |
7067 | ||
7068 | /* wake up worker thread to post asynchronlous mailbox command */ | |
7069 | lpfc_worker_wake_up(phba); | |
7070 | } | |
7071 | ||
da0436e9 JS |
7072 | /** |
7073 | * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox | |
7074 | * @phba: Pointer to HBA context object. | |
7075 | * @mboxq: Pointer to mailbox object. | |
7076 | * | |
7077 | * The function posts a mailbox to the port. The mailbox is expected | |
7078 | * to be comletely filled in and ready for the port to operate on it. | |
7079 | * This routine executes a synchronous completion operation on the | |
7080 | * mailbox by polling for its completion. | |
7081 | * | |
7082 | * The caller must not be holding any locks when calling this routine. | |
7083 | * | |
7084 | * Returns: | |
7085 | * MBX_SUCCESS - mailbox posted successfully | |
7086 | * Any of the MBX error values. | |
7087 | **/ | |
7088 | static int | |
7089 | lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) | |
7090 | { | |
7091 | int rc = MBX_SUCCESS; | |
7092 | unsigned long iflag; | |
7093 | uint32_t db_ready; | |
7094 | uint32_t mcqe_status; | |
7095 | uint32_t mbx_cmnd; | |
7096 | unsigned long timeout; | |
7097 | struct lpfc_sli *psli = &phba->sli; | |
7098 | struct lpfc_mqe *mb = &mboxq->u.mqe; | |
7099 | struct lpfc_bmbx_create *mbox_rgn; | |
7100 | struct dma_address *dma_address; | |
7101 | struct lpfc_register bmbx_reg; | |
7102 | ||
7103 | /* | |
7104 | * Only one mailbox can be active to the bootstrap mailbox region | |
7105 | * at a time and there is no queueing provided. | |
7106 | */ | |
7107 | spin_lock_irqsave(&phba->hbalock, iflag); | |
7108 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { | |
7109 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
7110 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
a183a15f | 7111 | "(%d):2532 Mailbox command x%x (x%x/x%x) " |
da0436e9 JS |
7112 | "cannot issue Data: x%x x%x\n", |
7113 | mboxq->vport ? mboxq->vport->vpi : 0, | |
7114 | mboxq->u.mb.mbxCommand, | |
a183a15f JS |
7115 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
7116 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), | |
da0436e9 JS |
7117 | psli->sli_flag, MBX_POLL); |
7118 | return MBXERR_ERROR; | |
7119 | } | |
7120 | /* The server grabs the token and owns it until release */ | |
7121 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; | |
7122 | phba->sli.mbox_active = mboxq; | |
7123 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
7124 | ||
7125 | /* | |
7126 | * Initialize the bootstrap memory region to avoid stale data areas | |
7127 | * in the mailbox post. Then copy the caller's mailbox contents to | |
7128 | * the bmbx mailbox region. | |
7129 | */ | |
7130 | mbx_cmnd = bf_get(lpfc_mqe_command, mb); | |
7131 | memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create)); | |
7132 | lpfc_sli_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt, | |
7133 | sizeof(struct lpfc_mqe)); | |
7134 | ||
7135 | /* Post the high mailbox dma address to the port and wait for ready. */ | |
7136 | dma_address = &phba->sli4_hba.bmbx.dma_address; | |
7137 | writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr); | |
7138 | ||
a183a15f | 7139 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mboxq) |
da0436e9 JS |
7140 | * 1000) + jiffies; |
7141 | do { | |
7142 | bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr); | |
7143 | db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg); | |
7144 | if (!db_ready) | |
7145 | msleep(2); | |
7146 | ||
7147 | if (time_after(jiffies, timeout)) { | |
7148 | rc = MBXERR_ERROR; | |
7149 | goto exit; | |
7150 | } | |
7151 | } while (!db_ready); | |
7152 | ||
7153 | /* Post the low mailbox dma address to the port. */ | |
7154 | writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr); | |
a183a15f | 7155 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mboxq) |
da0436e9 JS |
7156 | * 1000) + jiffies; |
7157 | do { | |
7158 | bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr); | |
7159 | db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg); | |
7160 | if (!db_ready) | |
7161 | msleep(2); | |
7162 | ||
7163 | if (time_after(jiffies, timeout)) { | |
7164 | rc = MBXERR_ERROR; | |
7165 | goto exit; | |
7166 | } | |
7167 | } while (!db_ready); | |
7168 | ||
7169 | /* | |
7170 | * Read the CQ to ensure the mailbox has completed. | |
7171 | * If so, update the mailbox status so that the upper layers | |
7172 | * can complete the request normally. | |
7173 | */ | |
7174 | lpfc_sli_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb, | |
7175 | sizeof(struct lpfc_mqe)); | |
7176 | mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt; | |
7177 | lpfc_sli_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe, | |
7178 | sizeof(struct lpfc_mcqe)); | |
7179 | mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe); | |
0558056c JS |
7180 | /* |
7181 | * When the CQE status indicates a failure and the mailbox status | |
7182 | * indicates success then copy the CQE status into the mailbox status | |
7183 | * (and prefix it with x4000). | |
7184 | */ | |
da0436e9 | 7185 | if (mcqe_status != MB_CQE_STATUS_SUCCESS) { |
0558056c JS |
7186 | if (bf_get(lpfc_mqe_status, mb) == MBX_SUCCESS) |
7187 | bf_set(lpfc_mqe_status, mb, | |
7188 | (LPFC_MBX_ERROR_RANGE | mcqe_status)); | |
da0436e9 | 7189 | rc = MBXERR_ERROR; |
d7c47992 JS |
7190 | } else |
7191 | lpfc_sli4_swap_str(phba, mboxq); | |
da0436e9 JS |
7192 | |
7193 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, | |
a183a15f | 7194 | "(%d):0356 Mailbox cmd x%x (x%x/x%x) Status x%x " |
da0436e9 JS |
7195 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x" |
7196 | " x%x x%x CQ: x%x x%x x%x x%x\n", | |
a183a15f JS |
7197 | mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd, |
7198 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), | |
7199 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), | |
da0436e9 JS |
7200 | bf_get(lpfc_mqe_status, mb), |
7201 | mb->un.mb_words[0], mb->un.mb_words[1], | |
7202 | mb->un.mb_words[2], mb->un.mb_words[3], | |
7203 | mb->un.mb_words[4], mb->un.mb_words[5], | |
7204 | mb->un.mb_words[6], mb->un.mb_words[7], | |
7205 | mb->un.mb_words[8], mb->un.mb_words[9], | |
7206 | mb->un.mb_words[10], mb->un.mb_words[11], | |
7207 | mb->un.mb_words[12], mboxq->mcqe.word0, | |
7208 | mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1, | |
7209 | mboxq->mcqe.trailer); | |
7210 | exit: | |
7211 | /* We are holding the token, no needed for lock when release */ | |
7212 | spin_lock_irqsave(&phba->hbalock, iflag); | |
7213 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
7214 | phba->sli.mbox_active = NULL; | |
7215 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
7216 | return rc; | |
7217 | } | |
7218 | ||
7219 | /** | |
7220 | * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware | |
7221 | * @phba: Pointer to HBA context object. | |
7222 | * @pmbox: Pointer to mailbox object. | |
7223 | * @flag: Flag indicating how the mailbox need to be processed. | |
7224 | * | |
7225 | * This function is called by discovery code and HBA management code to submit | |
7226 | * a mailbox command to firmware with SLI-4 interface spec. | |
7227 | * | |
7228 | * Return codes the caller owns the mailbox command after the return of the | |
7229 | * function. | |
7230 | **/ | |
7231 | static int | |
7232 | lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, | |
7233 | uint32_t flag) | |
7234 | { | |
7235 | struct lpfc_sli *psli = &phba->sli; | |
7236 | unsigned long iflags; | |
7237 | int rc; | |
7238 | ||
b76f2dc9 JS |
7239 | /* dump from issue mailbox command if setup */ |
7240 | lpfc_idiag_mbxacc_dump_issue_mbox(phba, &mboxq->u.mb); | |
7241 | ||
8fa38513 JS |
7242 | rc = lpfc_mbox_dev_check(phba); |
7243 | if (unlikely(rc)) { | |
7244 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
a183a15f | 7245 | "(%d):2544 Mailbox command x%x (x%x/x%x) " |
8fa38513 JS |
7246 | "cannot issue Data: x%x x%x\n", |
7247 | mboxq->vport ? mboxq->vport->vpi : 0, | |
7248 | mboxq->u.mb.mbxCommand, | |
a183a15f JS |
7249 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
7250 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), | |
8fa38513 JS |
7251 | psli->sli_flag, flag); |
7252 | goto out_not_finished; | |
7253 | } | |
7254 | ||
da0436e9 JS |
7255 | /* Detect polling mode and jump to a handler */ |
7256 | if (!phba->sli4_hba.intr_enable) { | |
7257 | if (flag == MBX_POLL) | |
7258 | rc = lpfc_sli4_post_sync_mbox(phba, mboxq); | |
7259 | else | |
7260 | rc = -EIO; | |
7261 | if (rc != MBX_SUCCESS) | |
0558056c | 7262 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
da0436e9 | 7263 | "(%d):2541 Mailbox command x%x " |
cc459f19 JS |
7264 | "(x%x/x%x) failure: " |
7265 | "mqe_sta: x%x mcqe_sta: x%x/x%x " | |
7266 | "Data: x%x x%x\n,", | |
da0436e9 JS |
7267 | mboxq->vport ? mboxq->vport->vpi : 0, |
7268 | mboxq->u.mb.mbxCommand, | |
a183a15f JS |
7269 | lpfc_sli_config_mbox_subsys_get(phba, |
7270 | mboxq), | |
7271 | lpfc_sli_config_mbox_opcode_get(phba, | |
7272 | mboxq), | |
cc459f19 JS |
7273 | bf_get(lpfc_mqe_status, &mboxq->u.mqe), |
7274 | bf_get(lpfc_mcqe_status, &mboxq->mcqe), | |
7275 | bf_get(lpfc_mcqe_ext_status, | |
7276 | &mboxq->mcqe), | |
da0436e9 JS |
7277 | psli->sli_flag, flag); |
7278 | return rc; | |
7279 | } else if (flag == MBX_POLL) { | |
f1126688 JS |
7280 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
7281 | "(%d):2542 Try to issue mailbox command " | |
a183a15f | 7282 | "x%x (x%x/x%x) synchronously ahead of async" |
f1126688 | 7283 | "mailbox command queue: x%x x%x\n", |
da0436e9 JS |
7284 | mboxq->vport ? mboxq->vport->vpi : 0, |
7285 | mboxq->u.mb.mbxCommand, | |
a183a15f JS |
7286 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
7287 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), | |
da0436e9 | 7288 | psli->sli_flag, flag); |
f1126688 JS |
7289 | /* Try to block the asynchronous mailbox posting */ |
7290 | rc = lpfc_sli4_async_mbox_block(phba); | |
7291 | if (!rc) { | |
7292 | /* Successfully blocked, now issue sync mbox cmd */ | |
7293 | rc = lpfc_sli4_post_sync_mbox(phba, mboxq); | |
7294 | if (rc != MBX_SUCCESS) | |
cc459f19 | 7295 | lpfc_printf_log(phba, KERN_WARNING, |
a183a15f | 7296 | LOG_MBOX | LOG_SLI, |
cc459f19 JS |
7297 | "(%d):2597 Sync Mailbox command " |
7298 | "x%x (x%x/x%x) failure: " | |
7299 | "mqe_sta: x%x mcqe_sta: x%x/x%x " | |
7300 | "Data: x%x x%x\n,", | |
7301 | mboxq->vport ? mboxq->vport->vpi : 0, | |
a183a15f JS |
7302 | mboxq->u.mb.mbxCommand, |
7303 | lpfc_sli_config_mbox_subsys_get(phba, | |
7304 | mboxq), | |
7305 | lpfc_sli_config_mbox_opcode_get(phba, | |
7306 | mboxq), | |
cc459f19 JS |
7307 | bf_get(lpfc_mqe_status, &mboxq->u.mqe), |
7308 | bf_get(lpfc_mcqe_status, &mboxq->mcqe), | |
7309 | bf_get(lpfc_mcqe_ext_status, | |
7310 | &mboxq->mcqe), | |
a183a15f | 7311 | psli->sli_flag, flag); |
f1126688 JS |
7312 | /* Unblock the async mailbox posting afterward */ |
7313 | lpfc_sli4_async_mbox_unblock(phba); | |
7314 | } | |
7315 | return rc; | |
da0436e9 JS |
7316 | } |
7317 | ||
7318 | /* Now, interrupt mode asynchrous mailbox command */ | |
7319 | rc = lpfc_mbox_cmd_check(phba, mboxq); | |
7320 | if (rc) { | |
7321 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
a183a15f | 7322 | "(%d):2543 Mailbox command x%x (x%x/x%x) " |
da0436e9 JS |
7323 | "cannot issue Data: x%x x%x\n", |
7324 | mboxq->vport ? mboxq->vport->vpi : 0, | |
7325 | mboxq->u.mb.mbxCommand, | |
a183a15f JS |
7326 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
7327 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), | |
da0436e9 JS |
7328 | psli->sli_flag, flag); |
7329 | goto out_not_finished; | |
7330 | } | |
da0436e9 JS |
7331 | |
7332 | /* Put the mailbox command to the driver internal FIFO */ | |
7333 | psli->slistat.mbox_busy++; | |
7334 | spin_lock_irqsave(&phba->hbalock, iflags); | |
7335 | lpfc_mbox_put(phba, mboxq); | |
7336 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
7337 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, | |
7338 | "(%d):0354 Mbox cmd issue - Enqueue Data: " | |
a183a15f | 7339 | "x%x (x%x/x%x) x%x x%x x%x\n", |
da0436e9 JS |
7340 | mboxq->vport ? mboxq->vport->vpi : 0xffffff, |
7341 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), | |
a183a15f JS |
7342 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
7343 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), | |
da0436e9 JS |
7344 | phba->pport->port_state, |
7345 | psli->sli_flag, MBX_NOWAIT); | |
7346 | /* Wake up worker thread to transport mailbox command from head */ | |
7347 | lpfc_worker_wake_up(phba); | |
7348 | ||
7349 | return MBX_BUSY; | |
7350 | ||
7351 | out_not_finished: | |
7352 | return MBX_NOT_FINISHED; | |
7353 | } | |
7354 | ||
7355 | /** | |
7356 | * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device | |
7357 | * @phba: Pointer to HBA context object. | |
7358 | * | |
7359 | * This function is called by worker thread to send a mailbox command to | |
7360 | * SLI4 HBA firmware. | |
7361 | * | |
7362 | **/ | |
7363 | int | |
7364 | lpfc_sli4_post_async_mbox(struct lpfc_hba *phba) | |
7365 | { | |
7366 | struct lpfc_sli *psli = &phba->sli; | |
7367 | LPFC_MBOXQ_t *mboxq; | |
7368 | int rc = MBX_SUCCESS; | |
7369 | unsigned long iflags; | |
7370 | struct lpfc_mqe *mqe; | |
7371 | uint32_t mbx_cmnd; | |
7372 | ||
7373 | /* Check interrupt mode before post async mailbox command */ | |
7374 | if (unlikely(!phba->sli4_hba.intr_enable)) | |
7375 | return MBX_NOT_FINISHED; | |
7376 | ||
7377 | /* Check for mailbox command service token */ | |
7378 | spin_lock_irqsave(&phba->hbalock, iflags); | |
7379 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { | |
7380 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
7381 | return MBX_NOT_FINISHED; | |
7382 | } | |
7383 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { | |
7384 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
7385 | return MBX_NOT_FINISHED; | |
7386 | } | |
7387 | if (unlikely(phba->sli.mbox_active)) { | |
7388 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
7389 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
7390 | "0384 There is pending active mailbox cmd\n"); | |
7391 | return MBX_NOT_FINISHED; | |
7392 | } | |
7393 | /* Take the mailbox command service token */ | |
7394 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; | |
7395 | ||
7396 | /* Get the next mailbox command from head of queue */ | |
7397 | mboxq = lpfc_mbox_get(phba); | |
7398 | ||
7399 | /* If no more mailbox command waiting for post, we're done */ | |
7400 | if (!mboxq) { | |
7401 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
7402 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
7403 | return MBX_SUCCESS; | |
7404 | } | |
7405 | phba->sli.mbox_active = mboxq; | |
7406 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
7407 | ||
7408 | /* Check device readiness for posting mailbox command */ | |
7409 | rc = lpfc_mbox_dev_check(phba); | |
7410 | if (unlikely(rc)) | |
7411 | /* Driver clean routine will clean up pending mailbox */ | |
7412 | goto out_not_finished; | |
7413 | ||
7414 | /* Prepare the mbox command to be posted */ | |
7415 | mqe = &mboxq->u.mqe; | |
7416 | mbx_cmnd = bf_get(lpfc_mqe_command, mqe); | |
7417 | ||
7418 | /* Start timer for the mbox_tmo and log some mailbox post messages */ | |
7419 | mod_timer(&psli->mbox_tmo, (jiffies + | |
a183a15f | 7420 | (HZ * lpfc_mbox_tmo_val(phba, mboxq)))); |
da0436e9 JS |
7421 | |
7422 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, | |
a183a15f | 7423 | "(%d):0355 Mailbox cmd x%x (x%x/x%x) issue Data: " |
da0436e9 JS |
7424 | "x%x x%x\n", |
7425 | mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd, | |
a183a15f JS |
7426 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
7427 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), | |
da0436e9 JS |
7428 | phba->pport->port_state, psli->sli_flag); |
7429 | ||
7430 | if (mbx_cmnd != MBX_HEARTBEAT) { | |
7431 | if (mboxq->vport) { | |
7432 | lpfc_debugfs_disc_trc(mboxq->vport, | |
7433 | LPFC_DISC_TRC_MBOX_VPORT, | |
7434 | "MBOX Send vport: cmd:x%x mb:x%x x%x", | |
7435 | mbx_cmnd, mqe->un.mb_words[0], | |
7436 | mqe->un.mb_words[1]); | |
7437 | } else { | |
7438 | lpfc_debugfs_disc_trc(phba->pport, | |
7439 | LPFC_DISC_TRC_MBOX, | |
7440 | "MBOX Send: cmd:x%x mb:x%x x%x", | |
7441 | mbx_cmnd, mqe->un.mb_words[0], | |
7442 | mqe->un.mb_words[1]); | |
7443 | } | |
7444 | } | |
7445 | psli->slistat.mbox_cmd++; | |
7446 | ||
7447 | /* Post the mailbox command to the port */ | |
7448 | rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe); | |
7449 | if (rc != MBX_SUCCESS) { | |
7450 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
a183a15f | 7451 | "(%d):2533 Mailbox command x%x (x%x/x%x) " |
da0436e9 JS |
7452 | "cannot issue Data: x%x x%x\n", |
7453 | mboxq->vport ? mboxq->vport->vpi : 0, | |
7454 | mboxq->u.mb.mbxCommand, | |
a183a15f JS |
7455 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
7456 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), | |
da0436e9 JS |
7457 | psli->sli_flag, MBX_NOWAIT); |
7458 | goto out_not_finished; | |
7459 | } | |
7460 | ||
7461 | return rc; | |
7462 | ||
7463 | out_not_finished: | |
7464 | spin_lock_irqsave(&phba->hbalock, iflags); | |
d7069f09 JS |
7465 | if (phba->sli.mbox_active) { |
7466 | mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED; | |
7467 | __lpfc_mbox_cmpl_put(phba, mboxq); | |
7468 | /* Release the token */ | |
7469 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
7470 | phba->sli.mbox_active = NULL; | |
7471 | } | |
da0436e9 JS |
7472 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
7473 | ||
7474 | return MBX_NOT_FINISHED; | |
7475 | } | |
7476 | ||
7477 | /** | |
7478 | * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command | |
7479 | * @phba: Pointer to HBA context object. | |
7480 | * @pmbox: Pointer to mailbox object. | |
7481 | * @flag: Flag indicating how the mailbox need to be processed. | |
7482 | * | |
7483 | * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from | |
7484 | * the API jump table function pointer from the lpfc_hba struct. | |
7485 | * | |
7486 | * Return codes the caller owns the mailbox command after the return of the | |
7487 | * function. | |
7488 | **/ | |
7489 | int | |
7490 | lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag) | |
7491 | { | |
7492 | return phba->lpfc_sli_issue_mbox(phba, pmbox, flag); | |
7493 | } | |
7494 | ||
7495 | /** | |
25985edc | 7496 | * lpfc_mbox_api_table_setup - Set up mbox api function jump table |
da0436e9 JS |
7497 | * @phba: The hba struct for which this call is being executed. |
7498 | * @dev_grp: The HBA PCI-Device group number. | |
7499 | * | |
7500 | * This routine sets up the mbox interface API function jump table in @phba | |
7501 | * struct. | |
7502 | * Returns: 0 - success, -ENODEV - failure. | |
7503 | **/ | |
7504 | int | |
7505 | lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) | |
7506 | { | |
7507 | ||
7508 | switch (dev_grp) { | |
7509 | case LPFC_PCI_DEV_LP: | |
7510 | phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3; | |
7511 | phba->lpfc_sli_handle_slow_ring_event = | |
7512 | lpfc_sli_handle_slow_ring_event_s3; | |
7513 | phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3; | |
7514 | phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3; | |
7515 | phba->lpfc_sli_brdready = lpfc_sli_brdready_s3; | |
7516 | break; | |
7517 | case LPFC_PCI_DEV_OC: | |
7518 | phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4; | |
7519 | phba->lpfc_sli_handle_slow_ring_event = | |
7520 | lpfc_sli_handle_slow_ring_event_s4; | |
7521 | phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4; | |
7522 | phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4; | |
7523 | phba->lpfc_sli_brdready = lpfc_sli_brdready_s4; | |
7524 | break; | |
7525 | default: | |
7526 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7527 | "1420 Invalid HBA PCI-device group: 0x%x\n", | |
7528 | dev_grp); | |
7529 | return -ENODEV; | |
7530 | break; | |
7531 | } | |
7532 | return 0; | |
7533 | } | |
7534 | ||
e59058c4 | 7535 | /** |
3621a710 | 7536 | * __lpfc_sli_ringtx_put - Add an iocb to the txq |
e59058c4 JS |
7537 | * @phba: Pointer to HBA context object. |
7538 | * @pring: Pointer to driver SLI ring object. | |
7539 | * @piocb: Pointer to address of newly added command iocb. | |
7540 | * | |
7541 | * This function is called with hbalock held to add a command | |
7542 | * iocb to the txq when SLI layer cannot submit the command iocb | |
7543 | * to the ring. | |
7544 | **/ | |
2a9bf3d0 | 7545 | void |
92d7f7b0 | 7546 | __lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
2e0fef85 | 7547 | struct lpfc_iocbq *piocb) |
dea3101e | 7548 | { |
7549 | /* Insert the caller's iocb in the txq tail for later processing. */ | |
7550 | list_add_tail(&piocb->list, &pring->txq); | |
7551 | pring->txq_cnt++; | |
dea3101e | 7552 | } |
7553 | ||
e59058c4 | 7554 | /** |
3621a710 | 7555 | * lpfc_sli_next_iocb - Get the next iocb in the txq |
e59058c4 JS |
7556 | * @phba: Pointer to HBA context object. |
7557 | * @pring: Pointer to driver SLI ring object. | |
7558 | * @piocb: Pointer to address of newly added command iocb. | |
7559 | * | |
7560 | * This function is called with hbalock held before a new | |
7561 | * iocb is submitted to the firmware. This function checks | |
7562 | * txq to flush the iocbs in txq to Firmware before | |
7563 | * submitting new iocbs to the Firmware. | |
7564 | * If there are iocbs in the txq which need to be submitted | |
7565 | * to firmware, lpfc_sli_next_iocb returns the first element | |
7566 | * of the txq after dequeuing it from txq. | |
7567 | * If there is no iocb in the txq then the function will return | |
7568 | * *piocb and *piocb is set to NULL. Caller needs to check | |
7569 | * *piocb to find if there are more commands in the txq. | |
7570 | **/ | |
dea3101e | 7571 | static struct lpfc_iocbq * |
7572 | lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
2e0fef85 | 7573 | struct lpfc_iocbq **piocb) |
dea3101e | 7574 | { |
7575 | struct lpfc_iocbq * nextiocb; | |
7576 | ||
7577 | nextiocb = lpfc_sli_ringtx_get(phba, pring); | |
7578 | if (!nextiocb) { | |
7579 | nextiocb = *piocb; | |
7580 | *piocb = NULL; | |
7581 | } | |
7582 | ||
7583 | return nextiocb; | |
7584 | } | |
7585 | ||
e59058c4 | 7586 | /** |
3772a991 | 7587 | * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb |
e59058c4 | 7588 | * @phba: Pointer to HBA context object. |
3772a991 | 7589 | * @ring_number: SLI ring number to issue iocb on. |
e59058c4 JS |
7590 | * @piocb: Pointer to command iocb. |
7591 | * @flag: Flag indicating if this command can be put into txq. | |
7592 | * | |
3772a991 JS |
7593 | * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue |
7594 | * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is | |
7595 | * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT | |
7596 | * flag is turned on, the function returns IOCB_ERROR. When the link is down, | |
7597 | * this function allows only iocbs for posting buffers. This function finds | |
7598 | * next available slot in the command ring and posts the command to the | |
7599 | * available slot and writes the port attention register to request HBA start | |
7600 | * processing new iocb. If there is no slot available in the ring and | |
7601 | * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise | |
7602 | * the function returns IOCB_BUSY. | |
e59058c4 | 7603 | * |
3772a991 JS |
7604 | * This function is called with hbalock held. The function will return success |
7605 | * after it successfully submit the iocb to firmware or after adding to the | |
7606 | * txq. | |
e59058c4 | 7607 | **/ |
98c9ea5c | 7608 | static int |
3772a991 | 7609 | __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number, |
dea3101e | 7610 | struct lpfc_iocbq *piocb, uint32_t flag) |
7611 | { | |
7612 | struct lpfc_iocbq *nextiocb; | |
7613 | IOCB_t *iocb; | |
3772a991 | 7614 | struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number]; |
dea3101e | 7615 | |
92d7f7b0 JS |
7616 | if (piocb->iocb_cmpl && (!piocb->vport) && |
7617 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && | |
7618 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { | |
7619 | lpfc_printf_log(phba, KERN_ERR, | |
7620 | LOG_SLI | LOG_VPORT, | |
e8b62011 | 7621 | "1807 IOCB x%x failed. No vport\n", |
92d7f7b0 JS |
7622 | piocb->iocb.ulpCommand); |
7623 | dump_stack(); | |
7624 | return IOCB_ERROR; | |
7625 | } | |
7626 | ||
7627 | ||
8d63f375 LV |
7628 | /* If the PCI channel is in offline state, do not post iocbs. */ |
7629 | if (unlikely(pci_channel_offline(phba->pcidev))) | |
7630 | return IOCB_ERROR; | |
7631 | ||
a257bf90 JS |
7632 | /* If HBA has a deferred error attention, fail the iocb. */ |
7633 | if (unlikely(phba->hba_flag & DEFER_ERATT)) | |
7634 | return IOCB_ERROR; | |
7635 | ||
dea3101e | 7636 | /* |
7637 | * We should never get an IOCB if we are in a < LINK_DOWN state | |
7638 | */ | |
2e0fef85 | 7639 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
dea3101e | 7640 | return IOCB_ERROR; |
7641 | ||
7642 | /* | |
7643 | * Check to see if we are blocking IOCB processing because of a | |
0b727fea | 7644 | * outstanding event. |
dea3101e | 7645 | */ |
0b727fea | 7646 | if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT)) |
dea3101e | 7647 | goto iocb_busy; |
7648 | ||
2e0fef85 | 7649 | if (unlikely(phba->link_state == LPFC_LINK_DOWN)) { |
dea3101e | 7650 | /* |
2680eeaa | 7651 | * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF |
dea3101e | 7652 | * can be issued if the link is not up. |
7653 | */ | |
7654 | switch (piocb->iocb.ulpCommand) { | |
84774a4d JS |
7655 | case CMD_GEN_REQUEST64_CR: |
7656 | case CMD_GEN_REQUEST64_CX: | |
7657 | if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) || | |
7658 | (piocb->iocb.un.genreq64.w5.hcsw.Rctl != | |
6a9c52cf | 7659 | FC_RCTL_DD_UNSOL_CMD) || |
84774a4d JS |
7660 | (piocb->iocb.un.genreq64.w5.hcsw.Type != |
7661 | MENLO_TRANSPORT_TYPE)) | |
7662 | ||
7663 | goto iocb_busy; | |
7664 | break; | |
dea3101e | 7665 | case CMD_QUE_RING_BUF_CN: |
7666 | case CMD_QUE_RING_BUF64_CN: | |
dea3101e | 7667 | /* |
7668 | * For IOCBs, like QUE_RING_BUF, that have no rsp ring | |
7669 | * completion, iocb_cmpl MUST be 0. | |
7670 | */ | |
7671 | if (piocb->iocb_cmpl) | |
7672 | piocb->iocb_cmpl = NULL; | |
7673 | /*FALLTHROUGH*/ | |
7674 | case CMD_CREATE_XRI_CR: | |
2680eeaa JS |
7675 | case CMD_CLOSE_XRI_CN: |
7676 | case CMD_CLOSE_XRI_CX: | |
dea3101e | 7677 | break; |
7678 | default: | |
7679 | goto iocb_busy; | |
7680 | } | |
7681 | ||
7682 | /* | |
7683 | * For FCP commands, we must be in a state where we can process link | |
7684 | * attention events. | |
7685 | */ | |
7686 | } else if (unlikely(pring->ringno == phba->sli.fcp_ring && | |
92d7f7b0 | 7687 | !(phba->sli.sli_flag & LPFC_PROCESS_LA))) { |
dea3101e | 7688 | goto iocb_busy; |
92d7f7b0 | 7689 | } |
dea3101e | 7690 | |
dea3101e | 7691 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && |
7692 | (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb))) | |
7693 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); | |
7694 | ||
7695 | if (iocb) | |
7696 | lpfc_sli_update_ring(phba, pring); | |
7697 | else | |
7698 | lpfc_sli_update_full_ring(phba, pring); | |
7699 | ||
7700 | if (!piocb) | |
7701 | return IOCB_SUCCESS; | |
7702 | ||
7703 | goto out_busy; | |
7704 | ||
7705 | iocb_busy: | |
7706 | pring->stats.iocb_cmd_delay++; | |
7707 | ||
7708 | out_busy: | |
7709 | ||
7710 | if (!(flag & SLI_IOCB_RET_IOCB)) { | |
92d7f7b0 | 7711 | __lpfc_sli_ringtx_put(phba, pring, piocb); |
dea3101e | 7712 | return IOCB_SUCCESS; |
7713 | } | |
7714 | ||
7715 | return IOCB_BUSY; | |
7716 | } | |
7717 | ||
3772a991 | 7718 | /** |
4f774513 JS |
7719 | * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl. |
7720 | * @phba: Pointer to HBA context object. | |
7721 | * @piocb: Pointer to command iocb. | |
7722 | * @sglq: Pointer to the scatter gather queue object. | |
7723 | * | |
7724 | * This routine converts the bpl or bde that is in the IOCB | |
7725 | * to a sgl list for the sli4 hardware. The physical address | |
7726 | * of the bpl/bde is converted back to a virtual address. | |
7727 | * If the IOCB contains a BPL then the list of BDE's is | |
7728 | * converted to sli4_sge's. If the IOCB contains a single | |
7729 | * BDE then it is converted to a single sli_sge. | |
7730 | * The IOCB is still in cpu endianess so the contents of | |
7731 | * the bpl can be used without byte swapping. | |
7732 | * | |
7733 | * Returns valid XRI = Success, NO_XRI = Failure. | |
7734 | **/ | |
7735 | static uint16_t | |
7736 | lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq, | |
7737 | struct lpfc_sglq *sglq) | |
3772a991 | 7738 | { |
4f774513 JS |
7739 | uint16_t xritag = NO_XRI; |
7740 | struct ulp_bde64 *bpl = NULL; | |
7741 | struct ulp_bde64 bde; | |
7742 | struct sli4_sge *sgl = NULL; | |
1b51197d | 7743 | struct lpfc_dmabuf *dmabuf; |
4f774513 JS |
7744 | IOCB_t *icmd; |
7745 | int numBdes = 0; | |
7746 | int i = 0; | |
63e801ce JS |
7747 | uint32_t offset = 0; /* accumulated offset in the sg request list */ |
7748 | int inbound = 0; /* number of sg reply entries inbound from firmware */ | |
3772a991 | 7749 | |
4f774513 JS |
7750 | if (!piocbq || !sglq) |
7751 | return xritag; | |
7752 | ||
7753 | sgl = (struct sli4_sge *)sglq->sgl; | |
7754 | icmd = &piocbq->iocb; | |
6b5151fd JS |
7755 | if (icmd->ulpCommand == CMD_XMIT_BLS_RSP64_CX) |
7756 | return sglq->sli4_xritag; | |
4f774513 JS |
7757 | if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) { |
7758 | numBdes = icmd->un.genreq64.bdl.bdeSize / | |
7759 | sizeof(struct ulp_bde64); | |
7760 | /* The addrHigh and addrLow fields within the IOCB | |
7761 | * have not been byteswapped yet so there is no | |
7762 | * need to swap them back. | |
7763 | */ | |
1b51197d JS |
7764 | if (piocbq->context3) |
7765 | dmabuf = (struct lpfc_dmabuf *)piocbq->context3; | |
7766 | else | |
7767 | return xritag; | |
4f774513 | 7768 | |
1b51197d | 7769 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
4f774513 JS |
7770 | if (!bpl) |
7771 | return xritag; | |
7772 | ||
7773 | for (i = 0; i < numBdes; i++) { | |
7774 | /* Should already be byte swapped. */ | |
28baac74 JS |
7775 | sgl->addr_hi = bpl->addrHigh; |
7776 | sgl->addr_lo = bpl->addrLow; | |
7777 | ||
0558056c | 7778 | sgl->word2 = le32_to_cpu(sgl->word2); |
4f774513 JS |
7779 | if ((i+1) == numBdes) |
7780 | bf_set(lpfc_sli4_sge_last, sgl, 1); | |
7781 | else | |
7782 | bf_set(lpfc_sli4_sge_last, sgl, 0); | |
28baac74 JS |
7783 | /* swap the size field back to the cpu so we |
7784 | * can assign it to the sgl. | |
7785 | */ | |
7786 | bde.tus.w = le32_to_cpu(bpl->tus.w); | |
7787 | sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize); | |
63e801ce JS |
7788 | /* The offsets in the sgl need to be accumulated |
7789 | * separately for the request and reply lists. | |
7790 | * The request is always first, the reply follows. | |
7791 | */ | |
7792 | if (piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) { | |
7793 | /* add up the reply sg entries */ | |
7794 | if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I) | |
7795 | inbound++; | |
7796 | /* first inbound? reset the offset */ | |
7797 | if (inbound == 1) | |
7798 | offset = 0; | |
7799 | bf_set(lpfc_sli4_sge_offset, sgl, offset); | |
f9bb2da1 JS |
7800 | bf_set(lpfc_sli4_sge_type, sgl, |
7801 | LPFC_SGE_TYPE_DATA); | |
63e801ce JS |
7802 | offset += bde.tus.f.bdeSize; |
7803 | } | |
546fc854 | 7804 | sgl->word2 = cpu_to_le32(sgl->word2); |
4f774513 JS |
7805 | bpl++; |
7806 | sgl++; | |
7807 | } | |
7808 | } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) { | |
7809 | /* The addrHigh and addrLow fields of the BDE have not | |
7810 | * been byteswapped yet so they need to be swapped | |
7811 | * before putting them in the sgl. | |
7812 | */ | |
7813 | sgl->addr_hi = | |
7814 | cpu_to_le32(icmd->un.genreq64.bdl.addrHigh); | |
7815 | sgl->addr_lo = | |
7816 | cpu_to_le32(icmd->un.genreq64.bdl.addrLow); | |
0558056c | 7817 | sgl->word2 = le32_to_cpu(sgl->word2); |
4f774513 JS |
7818 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
7819 | sgl->word2 = cpu_to_le32(sgl->word2); | |
28baac74 JS |
7820 | sgl->sge_len = |
7821 | cpu_to_le32(icmd->un.genreq64.bdl.bdeSize); | |
4f774513 JS |
7822 | } |
7823 | return sglq->sli4_xritag; | |
3772a991 | 7824 | } |
92d7f7b0 | 7825 | |
e59058c4 | 7826 | /** |
4f774513 | 7827 | * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution |
e59058c4 | 7828 | * @phba: Pointer to HBA context object. |
e59058c4 | 7829 | * |
a93ff37a | 7830 | * This routine performs a roundrobin SCSI command to SLI4 FCP WQ index |
8fa38513 JS |
7831 | * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock |
7832 | * held. | |
4f774513 JS |
7833 | * |
7834 | * Return: index into SLI4 fast-path FCP queue index. | |
e59058c4 | 7835 | **/ |
2a76a283 | 7836 | static inline uint32_t |
8fa38513 | 7837 | lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba *phba) |
92d7f7b0 | 7838 | { |
2a76a283 | 7839 | int i; |
92d7f7b0 | 7840 | |
49aa143d JS |
7841 | if (phba->cfg_fcp_io_sched == LPFC_FCP_SCHED_BY_CPU) |
7842 | i = smp_processor_id(); | |
7843 | else | |
7844 | i = atomic_add_return(1, &phba->fcp_qidx); | |
7845 | ||
67d12733 | 7846 | i = (i % phba->cfg_fcp_io_channel); |
2a76a283 | 7847 | return i; |
92d7f7b0 JS |
7848 | } |
7849 | ||
e59058c4 | 7850 | /** |
4f774513 | 7851 | * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry. |
e59058c4 | 7852 | * @phba: Pointer to HBA context object. |
4f774513 JS |
7853 | * @piocb: Pointer to command iocb. |
7854 | * @wqe: Pointer to the work queue entry. | |
e59058c4 | 7855 | * |
4f774513 JS |
7856 | * This routine converts the iocb command to its Work Queue Entry |
7857 | * equivalent. The wqe pointer should not have any fields set when | |
7858 | * this routine is called because it will memcpy over them. | |
7859 | * This routine does not set the CQ_ID or the WQEC bits in the | |
7860 | * wqe. | |
e59058c4 | 7861 | * |
4f774513 | 7862 | * Returns: 0 = Success, IOCB_ERROR = Failure. |
e59058c4 | 7863 | **/ |
cf5bf97e | 7864 | static int |
4f774513 JS |
7865 | lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq, |
7866 | union lpfc_wqe *wqe) | |
cf5bf97e | 7867 | { |
5ffc266e | 7868 | uint32_t xmit_len = 0, total_len = 0; |
4f774513 JS |
7869 | uint8_t ct = 0; |
7870 | uint32_t fip; | |
7871 | uint32_t abort_tag; | |
7872 | uint8_t command_type = ELS_COMMAND_NON_FIP; | |
7873 | uint8_t cmnd; | |
7874 | uint16_t xritag; | |
dcf2a4e0 JS |
7875 | uint16_t abrt_iotag; |
7876 | struct lpfc_iocbq *abrtiocbq; | |
4f774513 | 7877 | struct ulp_bde64 *bpl = NULL; |
f0d9bccc | 7878 | uint32_t els_id = LPFC_ELS_ID_DEFAULT; |
5ffc266e JS |
7879 | int numBdes, i; |
7880 | struct ulp_bde64 bde; | |
c31098ce | 7881 | struct lpfc_nodelist *ndlp; |
ff78d8f9 | 7882 | uint32_t *pcmd; |
1b51197d | 7883 | uint32_t if_type; |
4f774513 | 7884 | |
45ed1190 | 7885 | fip = phba->hba_flag & HBA_FIP_SUPPORT; |
4f774513 | 7886 | /* The fcp commands will set command type */ |
0c287589 | 7887 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
4f774513 | 7888 | command_type = FCP_COMMAND; |
c868595d | 7889 | else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)) |
0c287589 JS |
7890 | command_type = ELS_COMMAND_FIP; |
7891 | else | |
7892 | command_type = ELS_COMMAND_NON_FIP; | |
7893 | ||
4f774513 JS |
7894 | /* Some of the fields are in the right position already */ |
7895 | memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe)); | |
7896 | abort_tag = (uint32_t) iocbq->iotag; | |
7897 | xritag = iocbq->sli4_xritag; | |
f0d9bccc | 7898 | wqe->generic.wqe_com.word7 = 0; /* The ct field has moved so reset */ |
4f774513 JS |
7899 | /* words0-2 bpl convert bde */ |
7900 | if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) { | |
5ffc266e JS |
7901 | numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize / |
7902 | sizeof(struct ulp_bde64); | |
4f774513 JS |
7903 | bpl = (struct ulp_bde64 *) |
7904 | ((struct lpfc_dmabuf *)iocbq->context3)->virt; | |
7905 | if (!bpl) | |
7906 | return IOCB_ERROR; | |
cf5bf97e | 7907 | |
4f774513 JS |
7908 | /* Should already be byte swapped. */ |
7909 | wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh); | |
7910 | wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow); | |
7911 | /* swap the size field back to the cpu so we | |
7912 | * can assign it to the sgl. | |
7913 | */ | |
7914 | wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w); | |
5ffc266e JS |
7915 | xmit_len = wqe->generic.bde.tus.f.bdeSize; |
7916 | total_len = 0; | |
7917 | for (i = 0; i < numBdes; i++) { | |
7918 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); | |
7919 | total_len += bde.tus.f.bdeSize; | |
7920 | } | |
4f774513 | 7921 | } else |
5ffc266e | 7922 | xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize; |
cf5bf97e | 7923 | |
4f774513 JS |
7924 | iocbq->iocb.ulpIoTag = iocbq->iotag; |
7925 | cmnd = iocbq->iocb.ulpCommand; | |
a4bc3379 | 7926 | |
4f774513 JS |
7927 | switch (iocbq->iocb.ulpCommand) { |
7928 | case CMD_ELS_REQUEST64_CR: | |
93d1379e JS |
7929 | if (iocbq->iocb_flag & LPFC_IO_LIBDFC) |
7930 | ndlp = iocbq->context_un.ndlp; | |
7931 | else | |
7932 | ndlp = (struct lpfc_nodelist *)iocbq->context1; | |
4f774513 JS |
7933 | if (!iocbq->iocb.ulpLe) { |
7934 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
7935 | "2007 Only Limited Edition cmd Format" | |
7936 | " supported 0x%x\n", | |
7937 | iocbq->iocb.ulpCommand); | |
7938 | return IOCB_ERROR; | |
7939 | } | |
ff78d8f9 | 7940 | |
5ffc266e | 7941 | wqe->els_req.payload_len = xmit_len; |
4f774513 JS |
7942 | /* Els_reguest64 has a TMO */ |
7943 | bf_set(wqe_tmo, &wqe->els_req.wqe_com, | |
7944 | iocbq->iocb.ulpTimeout); | |
7945 | /* Need a VF for word 4 set the vf bit*/ | |
7946 | bf_set(els_req64_vf, &wqe->els_req, 0); | |
7947 | /* And a VFID for word 12 */ | |
7948 | bf_set(els_req64_vfid, &wqe->els_req, 0); | |
4f774513 | 7949 | ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l); |
f0d9bccc JS |
7950 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
7951 | iocbq->iocb.ulpContext); | |
7952 | bf_set(wqe_ct, &wqe->els_req.wqe_com, ct); | |
7953 | bf_set(wqe_pu, &wqe->els_req.wqe_com, 0); | |
4f774513 | 7954 | /* CCP CCPE PV PRI in word10 were set in the memcpy */ |
ff78d8f9 | 7955 | if (command_type == ELS_COMMAND_FIP) |
c868595d JS |
7956 | els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK) |
7957 | >> LPFC_FIP_ELS_ID_SHIFT); | |
ff78d8f9 JS |
7958 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
7959 | iocbq->context2)->virt); | |
1b51197d JS |
7960 | if_type = bf_get(lpfc_sli_intf_if_type, |
7961 | &phba->sli4_hba.sli_intf); | |
7962 | if (if_type == LPFC_SLI_INTF_IF_TYPE_2) { | |
ff78d8f9 | 7963 | if (pcmd && (*pcmd == ELS_CMD_FLOGI || |
cb69f7de | 7964 | *pcmd == ELS_CMD_SCR || |
6b5151fd | 7965 | *pcmd == ELS_CMD_FDISC || |
bdcd2b92 | 7966 | *pcmd == ELS_CMD_LOGO || |
ff78d8f9 JS |
7967 | *pcmd == ELS_CMD_PLOGI)) { |
7968 | bf_set(els_req64_sp, &wqe->els_req, 1); | |
7969 | bf_set(els_req64_sid, &wqe->els_req, | |
7970 | iocbq->vport->fc_myDID); | |
939723a4 JS |
7971 | if ((*pcmd == ELS_CMD_FLOGI) && |
7972 | !(phba->fc_topology == | |
7973 | LPFC_TOPOLOGY_LOOP)) | |
7974 | bf_set(els_req64_sid, &wqe->els_req, 0); | |
ff78d8f9 JS |
7975 | bf_set(wqe_ct, &wqe->els_req.wqe_com, 1); |
7976 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, | |
a7dd9c0f | 7977 | phba->vpi_ids[iocbq->vport->vpi]); |
3ef6d24c | 7978 | } else if (pcmd && iocbq->context1) { |
ff78d8f9 JS |
7979 | bf_set(wqe_ct, &wqe->els_req.wqe_com, 0); |
7980 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, | |
7981 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); | |
7982 | } | |
c868595d | 7983 | } |
6d368e53 JS |
7984 | bf_set(wqe_temp_rpi, &wqe->els_req.wqe_com, |
7985 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); | |
f0d9bccc JS |
7986 | bf_set(wqe_els_id, &wqe->els_req.wqe_com, els_id); |
7987 | bf_set(wqe_dbde, &wqe->els_req.wqe_com, 1); | |
7988 | bf_set(wqe_iod, &wqe->els_req.wqe_com, LPFC_WQE_IOD_READ); | |
7989 | bf_set(wqe_qosd, &wqe->els_req.wqe_com, 1); | |
7990 | bf_set(wqe_lenloc, &wqe->els_req.wqe_com, LPFC_WQE_LENLOC_NONE); | |
7991 | bf_set(wqe_ebde_cnt, &wqe->els_req.wqe_com, 0); | |
7851fe2c | 7992 | break; |
5ffc266e | 7993 | case CMD_XMIT_SEQUENCE64_CX: |
f0d9bccc JS |
7994 | bf_set(wqe_ctxt_tag, &wqe->xmit_sequence.wqe_com, |
7995 | iocbq->iocb.un.ulpWord[3]); | |
7996 | bf_set(wqe_rcvoxid, &wqe->xmit_sequence.wqe_com, | |
7851fe2c | 7997 | iocbq->iocb.unsli3.rcvsli3.ox_id); |
5ffc266e JS |
7998 | /* The entire sequence is transmitted for this IOCB */ |
7999 | xmit_len = total_len; | |
8000 | cmnd = CMD_XMIT_SEQUENCE64_CR; | |
1b51197d JS |
8001 | if (phba->link_flag & LS_LOOPBACK_MODE) |
8002 | bf_set(wqe_xo, &wqe->xmit_sequence.wge_ctl, 1); | |
4f774513 | 8003 | case CMD_XMIT_SEQUENCE64_CR: |
f0d9bccc JS |
8004 | /* word3 iocb=io_tag32 wqe=reserved */ |
8005 | wqe->xmit_sequence.rsvd3 = 0; | |
4f774513 JS |
8006 | /* word4 relative_offset memcpy */ |
8007 | /* word5 r_ctl/df_ctl memcpy */ | |
f0d9bccc JS |
8008 | bf_set(wqe_pu, &wqe->xmit_sequence.wqe_com, 0); |
8009 | bf_set(wqe_dbde, &wqe->xmit_sequence.wqe_com, 1); | |
8010 | bf_set(wqe_iod, &wqe->xmit_sequence.wqe_com, | |
8011 | LPFC_WQE_IOD_WRITE); | |
8012 | bf_set(wqe_lenloc, &wqe->xmit_sequence.wqe_com, | |
8013 | LPFC_WQE_LENLOC_WORD12); | |
8014 | bf_set(wqe_ebde_cnt, &wqe->xmit_sequence.wqe_com, 0); | |
5ffc266e JS |
8015 | wqe->xmit_sequence.xmit_len = xmit_len; |
8016 | command_type = OTHER_COMMAND; | |
7851fe2c | 8017 | break; |
4f774513 | 8018 | case CMD_XMIT_BCAST64_CN: |
f0d9bccc JS |
8019 | /* word3 iocb=iotag32 wqe=seq_payload_len */ |
8020 | wqe->xmit_bcast64.seq_payload_len = xmit_len; | |
4f774513 JS |
8021 | /* word4 iocb=rsvd wqe=rsvd */ |
8022 | /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */ | |
8023 | /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */ | |
f0d9bccc | 8024 | bf_set(wqe_ct, &wqe->xmit_bcast64.wqe_com, |
4f774513 | 8025 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
f0d9bccc JS |
8026 | bf_set(wqe_dbde, &wqe->xmit_bcast64.wqe_com, 1); |
8027 | bf_set(wqe_iod, &wqe->xmit_bcast64.wqe_com, LPFC_WQE_IOD_WRITE); | |
8028 | bf_set(wqe_lenloc, &wqe->xmit_bcast64.wqe_com, | |
8029 | LPFC_WQE_LENLOC_WORD3); | |
8030 | bf_set(wqe_ebde_cnt, &wqe->xmit_bcast64.wqe_com, 0); | |
7851fe2c | 8031 | break; |
4f774513 JS |
8032 | case CMD_FCP_IWRITE64_CR: |
8033 | command_type = FCP_COMMAND_DATA_OUT; | |
f0d9bccc JS |
8034 | /* word3 iocb=iotag wqe=payload_offset_len */ |
8035 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ | |
8036 | wqe->fcp_iwrite.payload_offset_len = | |
8037 | xmit_len + sizeof(struct fcp_rsp); | |
8038 | /* word4 iocb=parameter wqe=total_xfer_length memcpy */ | |
8039 | /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */ | |
8040 | bf_set(wqe_erp, &wqe->fcp_iwrite.wqe_com, | |
8041 | iocbq->iocb.ulpFCP2Rcvy); | |
8042 | bf_set(wqe_lnk, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpXS); | |
8043 | /* Always open the exchange */ | |
8044 | bf_set(wqe_xc, &wqe->fcp_iwrite.wqe_com, 0); | |
f0d9bccc JS |
8045 | bf_set(wqe_iod, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_IOD_WRITE); |
8046 | bf_set(wqe_lenloc, &wqe->fcp_iwrite.wqe_com, | |
8047 | LPFC_WQE_LENLOC_WORD4); | |
8048 | bf_set(wqe_ebde_cnt, &wqe->fcp_iwrite.wqe_com, 0); | |
8049 | bf_set(wqe_pu, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpPU); | |
acd6859b JS |
8050 | if (iocbq->iocb_flag & LPFC_IO_DIF) { |
8051 | iocbq->iocb_flag &= ~LPFC_IO_DIF; | |
8052 | bf_set(wqe_dif, &wqe->generic.wqe_com, 1); | |
8053 | } | |
8054 | bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 1); | |
7851fe2c | 8055 | break; |
4f774513 | 8056 | case CMD_FCP_IREAD64_CR: |
f0d9bccc JS |
8057 | /* word3 iocb=iotag wqe=payload_offset_len */ |
8058 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ | |
8059 | wqe->fcp_iread.payload_offset_len = | |
5ffc266e | 8060 | xmit_len + sizeof(struct fcp_rsp); |
f0d9bccc JS |
8061 | /* word4 iocb=parameter wqe=total_xfer_length memcpy */ |
8062 | /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */ | |
8063 | bf_set(wqe_erp, &wqe->fcp_iread.wqe_com, | |
8064 | iocbq->iocb.ulpFCP2Rcvy); | |
8065 | bf_set(wqe_lnk, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpXS); | |
f1126688 JS |
8066 | /* Always open the exchange */ |
8067 | bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0); | |
f0d9bccc JS |
8068 | bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, LPFC_WQE_IOD_READ); |
8069 | bf_set(wqe_lenloc, &wqe->fcp_iread.wqe_com, | |
8070 | LPFC_WQE_LENLOC_WORD4); | |
8071 | bf_set(wqe_ebde_cnt, &wqe->fcp_iread.wqe_com, 0); | |
8072 | bf_set(wqe_pu, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpPU); | |
acd6859b JS |
8073 | if (iocbq->iocb_flag & LPFC_IO_DIF) { |
8074 | iocbq->iocb_flag &= ~LPFC_IO_DIF; | |
8075 | bf_set(wqe_dif, &wqe->generic.wqe_com, 1); | |
8076 | } | |
8077 | bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 1); | |
7851fe2c | 8078 | break; |
4f774513 | 8079 | case CMD_FCP_ICMND64_CR: |
f0d9bccc JS |
8080 | /* word3 iocb=IO_TAG wqe=reserved */ |
8081 | wqe->fcp_icmd.rsrvd3 = 0; | |
8082 | bf_set(wqe_pu, &wqe->fcp_icmd.wqe_com, 0); | |
4f774513 | 8083 | /* Always open the exchange */ |
f0d9bccc JS |
8084 | bf_set(wqe_xc, &wqe->fcp_icmd.wqe_com, 0); |
8085 | bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 1); | |
8086 | bf_set(wqe_iod, &wqe->fcp_icmd.wqe_com, LPFC_WQE_IOD_WRITE); | |
8087 | bf_set(wqe_qosd, &wqe->fcp_icmd.wqe_com, 1); | |
8088 | bf_set(wqe_lenloc, &wqe->fcp_icmd.wqe_com, | |
8089 | LPFC_WQE_LENLOC_NONE); | |
8090 | bf_set(wqe_ebde_cnt, &wqe->fcp_icmd.wqe_com, 0); | |
7851fe2c | 8091 | break; |
4f774513 | 8092 | case CMD_GEN_REQUEST64_CR: |
63e801ce JS |
8093 | /* For this command calculate the xmit length of the |
8094 | * request bde. | |
8095 | */ | |
8096 | xmit_len = 0; | |
8097 | numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize / | |
8098 | sizeof(struct ulp_bde64); | |
8099 | for (i = 0; i < numBdes; i++) { | |
63e801ce | 8100 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
546fc854 JS |
8101 | if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64) |
8102 | break; | |
63e801ce JS |
8103 | xmit_len += bde.tus.f.bdeSize; |
8104 | } | |
f0d9bccc JS |
8105 | /* word3 iocb=IO_TAG wqe=request_payload_len */ |
8106 | wqe->gen_req.request_payload_len = xmit_len; | |
8107 | /* word4 iocb=parameter wqe=relative_offset memcpy */ | |
8108 | /* word5 [rctl, type, df_ctl, la] copied in memcpy */ | |
4f774513 JS |
8109 | /* word6 context tag copied in memcpy */ |
8110 | if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) { | |
8111 | ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l); | |
8112 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
8113 | "2015 Invalid CT %x command 0x%x\n", | |
8114 | ct, iocbq->iocb.ulpCommand); | |
8115 | return IOCB_ERROR; | |
8116 | } | |
f0d9bccc JS |
8117 | bf_set(wqe_ct, &wqe->gen_req.wqe_com, 0); |
8118 | bf_set(wqe_tmo, &wqe->gen_req.wqe_com, iocbq->iocb.ulpTimeout); | |
8119 | bf_set(wqe_pu, &wqe->gen_req.wqe_com, iocbq->iocb.ulpPU); | |
8120 | bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1); | |
8121 | bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ); | |
8122 | bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1); | |
8123 | bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE); | |
8124 | bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0); | |
4f774513 | 8125 | command_type = OTHER_COMMAND; |
7851fe2c | 8126 | break; |
4f774513 | 8127 | case CMD_XMIT_ELS_RSP64_CX: |
c31098ce | 8128 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
4f774513 | 8129 | /* words0-2 BDE memcpy */ |
f0d9bccc JS |
8130 | /* word3 iocb=iotag32 wqe=response_payload_len */ |
8131 | wqe->xmit_els_rsp.response_payload_len = xmit_len; | |
939723a4 JS |
8132 | /* word4 */ |
8133 | wqe->xmit_els_rsp.word4 = 0; | |
4f774513 JS |
8134 | /* word5 iocb=rsvd wge=did */ |
8135 | bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest, | |
939723a4 JS |
8136 | iocbq->iocb.un.xseq64.xmit_els_remoteID); |
8137 | ||
8138 | if_type = bf_get(lpfc_sli_intf_if_type, | |
8139 | &phba->sli4_hba.sli_intf); | |
8140 | if (if_type == LPFC_SLI_INTF_IF_TYPE_2) { | |
8141 | if (iocbq->vport->fc_flag & FC_PT2PT) { | |
8142 | bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1); | |
8143 | bf_set(els_rsp64_sid, &wqe->xmit_els_rsp, | |
8144 | iocbq->vport->fc_myDID); | |
8145 | if (iocbq->vport->fc_myDID == Fabric_DID) { | |
8146 | bf_set(wqe_els_did, | |
8147 | &wqe->xmit_els_rsp.wqe_dest, 0); | |
8148 | } | |
8149 | } | |
8150 | } | |
f0d9bccc JS |
8151 | bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, |
8152 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); | |
8153 | bf_set(wqe_pu, &wqe->xmit_els_rsp.wqe_com, iocbq->iocb.ulpPU); | |
8154 | bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com, | |
7851fe2c | 8155 | iocbq->iocb.unsli3.rcvsli3.ox_id); |
4f774513 | 8156 | if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l) |
f0d9bccc | 8157 | bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, |
6d368e53 | 8158 | phba->vpi_ids[iocbq->vport->vpi]); |
f0d9bccc JS |
8159 | bf_set(wqe_dbde, &wqe->xmit_els_rsp.wqe_com, 1); |
8160 | bf_set(wqe_iod, &wqe->xmit_els_rsp.wqe_com, LPFC_WQE_IOD_WRITE); | |
8161 | bf_set(wqe_qosd, &wqe->xmit_els_rsp.wqe_com, 1); | |
8162 | bf_set(wqe_lenloc, &wqe->xmit_els_rsp.wqe_com, | |
8163 | LPFC_WQE_LENLOC_WORD3); | |
8164 | bf_set(wqe_ebde_cnt, &wqe->xmit_els_rsp.wqe_com, 0); | |
6d368e53 JS |
8165 | bf_set(wqe_rsp_temp_rpi, &wqe->xmit_els_rsp, |
8166 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); | |
ff78d8f9 JS |
8167 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
8168 | iocbq->context2)->virt); | |
8169 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { | |
939723a4 JS |
8170 | bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1); |
8171 | bf_set(els_rsp64_sid, &wqe->xmit_els_rsp, | |
ff78d8f9 | 8172 | iocbq->vport->fc_myDID); |
939723a4 JS |
8173 | bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, 1); |
8174 | bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, | |
ff78d8f9 JS |
8175 | phba->vpi_ids[phba->pport->vpi]); |
8176 | } | |
4f774513 | 8177 | command_type = OTHER_COMMAND; |
7851fe2c | 8178 | break; |
4f774513 JS |
8179 | case CMD_CLOSE_XRI_CN: |
8180 | case CMD_ABORT_XRI_CN: | |
8181 | case CMD_ABORT_XRI_CX: | |
8182 | /* words 0-2 memcpy should be 0 rserved */ | |
8183 | /* port will send abts */ | |
dcf2a4e0 JS |
8184 | abrt_iotag = iocbq->iocb.un.acxri.abortContextTag; |
8185 | if (abrt_iotag != 0 && abrt_iotag <= phba->sli.last_iotag) { | |
8186 | abrtiocbq = phba->sli.iocbq_lookup[abrt_iotag]; | |
8187 | fip = abrtiocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK; | |
8188 | } else | |
8189 | fip = 0; | |
8190 | ||
8191 | if ((iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN) || fip) | |
4f774513 | 8192 | /* |
dcf2a4e0 JS |
8193 | * The link is down, or the command was ELS_FIP |
8194 | * so the fw does not need to send abts | |
4f774513 JS |
8195 | * on the wire. |
8196 | */ | |
8197 | bf_set(abort_cmd_ia, &wqe->abort_cmd, 1); | |
8198 | else | |
8199 | bf_set(abort_cmd_ia, &wqe->abort_cmd, 0); | |
8200 | bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG); | |
f0d9bccc JS |
8201 | /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */ |
8202 | wqe->abort_cmd.rsrvd5 = 0; | |
8203 | bf_set(wqe_ct, &wqe->abort_cmd.wqe_com, | |
4f774513 JS |
8204 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
8205 | abort_tag = iocbq->iocb.un.acxri.abortIoTag; | |
4f774513 JS |
8206 | /* |
8207 | * The abort handler will send us CMD_ABORT_XRI_CN or | |
8208 | * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX | |
8209 | */ | |
f0d9bccc JS |
8210 | bf_set(wqe_cmnd, &wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX); |
8211 | bf_set(wqe_qosd, &wqe->abort_cmd.wqe_com, 1); | |
8212 | bf_set(wqe_lenloc, &wqe->abort_cmd.wqe_com, | |
8213 | LPFC_WQE_LENLOC_NONE); | |
4f774513 JS |
8214 | cmnd = CMD_ABORT_XRI_CX; |
8215 | command_type = OTHER_COMMAND; | |
8216 | xritag = 0; | |
7851fe2c | 8217 | break; |
6669f9bb | 8218 | case CMD_XMIT_BLS_RSP64_CX: |
6b5151fd | 8219 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
546fc854 | 8220 | /* As BLS ABTS RSP WQE is very different from other WQEs, |
6669f9bb JS |
8221 | * we re-construct this WQE here based on information in |
8222 | * iocbq from scratch. | |
8223 | */ | |
8224 | memset(wqe, 0, sizeof(union lpfc_wqe)); | |
5ffc266e | 8225 | /* OX_ID is invariable to who sent ABTS to CT exchange */ |
6669f9bb | 8226 | bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp, |
546fc854 JS |
8227 | bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_rsp)); |
8228 | if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_rsp) == | |
5ffc266e JS |
8229 | LPFC_ABTS_UNSOL_INT) { |
8230 | /* ABTS sent by initiator to CT exchange, the | |
8231 | * RX_ID field will be filled with the newly | |
8232 | * allocated responder XRI. | |
8233 | */ | |
8234 | bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp, | |
8235 | iocbq->sli4_xritag); | |
8236 | } else { | |
8237 | /* ABTS sent by responder to CT exchange, the | |
8238 | * RX_ID field will be filled with the responder | |
8239 | * RX_ID from ABTS. | |
8240 | */ | |
8241 | bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp, | |
546fc854 | 8242 | bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_rsp)); |
5ffc266e | 8243 | } |
6669f9bb JS |
8244 | bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff); |
8245 | bf_set(wqe_xmit_bls_pt, &wqe->xmit_bls_rsp.wqe_dest, 0x1); | |
6b5151fd JS |
8246 | |
8247 | /* Use CT=VPI */ | |
8248 | bf_set(wqe_els_did, &wqe->xmit_bls_rsp.wqe_dest, | |
8249 | ndlp->nlp_DID); | |
8250 | bf_set(xmit_bls_rsp64_temprpi, &wqe->xmit_bls_rsp, | |
8251 | iocbq->iocb.ulpContext); | |
8252 | bf_set(wqe_ct, &wqe->xmit_bls_rsp.wqe_com, 1); | |
6669f9bb | 8253 | bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com, |
6b5151fd | 8254 | phba->vpi_ids[phba->pport->vpi]); |
f0d9bccc JS |
8255 | bf_set(wqe_qosd, &wqe->xmit_bls_rsp.wqe_com, 1); |
8256 | bf_set(wqe_lenloc, &wqe->xmit_bls_rsp.wqe_com, | |
8257 | LPFC_WQE_LENLOC_NONE); | |
6669f9bb JS |
8258 | /* Overwrite the pre-set comnd type with OTHER_COMMAND */ |
8259 | command_type = OTHER_COMMAND; | |
546fc854 JS |
8260 | if (iocbq->iocb.un.xseq64.w5.hcsw.Rctl == FC_RCTL_BA_RJT) { |
8261 | bf_set(xmit_bls_rsp64_rjt_vspec, &wqe->xmit_bls_rsp, | |
8262 | bf_get(lpfc_vndr_code, &iocbq->iocb.un.bls_rsp)); | |
8263 | bf_set(xmit_bls_rsp64_rjt_expc, &wqe->xmit_bls_rsp, | |
8264 | bf_get(lpfc_rsn_expln, &iocbq->iocb.un.bls_rsp)); | |
8265 | bf_set(xmit_bls_rsp64_rjt_rsnc, &wqe->xmit_bls_rsp, | |
8266 | bf_get(lpfc_rsn_code, &iocbq->iocb.un.bls_rsp)); | |
8267 | } | |
8268 | ||
7851fe2c | 8269 | break; |
4f774513 JS |
8270 | case CMD_XRI_ABORTED_CX: |
8271 | case CMD_CREATE_XRI_CR: /* Do we expect to use this? */ | |
4f774513 JS |
8272 | case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */ |
8273 | case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */ | |
8274 | case CMD_FCP_TRSP64_CX: /* Target mode rcv */ | |
8275 | case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */ | |
8276 | default: | |
8277 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
8278 | "2014 Invalid command 0x%x\n", | |
8279 | iocbq->iocb.ulpCommand); | |
8280 | return IOCB_ERROR; | |
7851fe2c | 8281 | break; |
4f774513 | 8282 | } |
6d368e53 | 8283 | |
f0d9bccc JS |
8284 | bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag); |
8285 | bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag); | |
8286 | wqe->generic.wqe_com.abort_tag = abort_tag; | |
8287 | bf_set(wqe_cmd_type, &wqe->generic.wqe_com, command_type); | |
8288 | bf_set(wqe_cmnd, &wqe->generic.wqe_com, cmnd); | |
8289 | bf_set(wqe_class, &wqe->generic.wqe_com, iocbq->iocb.ulpClass); | |
8290 | bf_set(wqe_cqid, &wqe->generic.wqe_com, LPFC_WQE_CQ_ID_DEFAULT); | |
4f774513 JS |
8291 | return 0; |
8292 | } | |
8293 | ||
8294 | /** | |
8295 | * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb | |
8296 | * @phba: Pointer to HBA context object. | |
8297 | * @ring_number: SLI ring number to issue iocb on. | |
8298 | * @piocb: Pointer to command iocb. | |
8299 | * @flag: Flag indicating if this command can be put into txq. | |
8300 | * | |
8301 | * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue | |
8302 | * an iocb command to an HBA with SLI-4 interface spec. | |
8303 | * | |
8304 | * This function is called with hbalock held. The function will return success | |
8305 | * after it successfully submit the iocb to firmware or after adding to the | |
8306 | * txq. | |
8307 | **/ | |
8308 | static int | |
8309 | __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number, | |
8310 | struct lpfc_iocbq *piocb, uint32_t flag) | |
8311 | { | |
8312 | struct lpfc_sglq *sglq; | |
4f774513 JS |
8313 | union lpfc_wqe wqe; |
8314 | struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number]; | |
4f774513 JS |
8315 | |
8316 | if (piocb->sli4_xritag == NO_XRI) { | |
8317 | if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || | |
6b5151fd | 8318 | piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN) |
4f774513 JS |
8319 | sglq = NULL; |
8320 | else { | |
2a9bf3d0 JS |
8321 | if (pring->txq_cnt) { |
8322 | if (!(flag & SLI_IOCB_RET_IOCB)) { | |
8323 | __lpfc_sli_ringtx_put(phba, | |
8324 | pring, piocb); | |
8325 | return IOCB_SUCCESS; | |
8326 | } else { | |
8327 | return IOCB_BUSY; | |
8328 | } | |
8329 | } else { | |
6d368e53 | 8330 | sglq = __lpfc_sli_get_sglq(phba, piocb); |
2a9bf3d0 JS |
8331 | if (!sglq) { |
8332 | if (!(flag & SLI_IOCB_RET_IOCB)) { | |
8333 | __lpfc_sli_ringtx_put(phba, | |
8334 | pring, | |
8335 | piocb); | |
8336 | return IOCB_SUCCESS; | |
8337 | } else | |
8338 | return IOCB_BUSY; | |
8339 | } | |
8340 | } | |
4f774513 JS |
8341 | } |
8342 | } else if (piocb->iocb_flag & LPFC_IO_FCP) { | |
6d368e53 JS |
8343 | /* These IO's already have an XRI and a mapped sgl. */ |
8344 | sglq = NULL; | |
4f774513 | 8345 | } else { |
6d368e53 JS |
8346 | /* |
8347 | * This is a continuation of a commandi,(CX) so this | |
4f774513 JS |
8348 | * sglq is on the active list |
8349 | */ | |
8350 | sglq = __lpfc_get_active_sglq(phba, piocb->sli4_xritag); | |
8351 | if (!sglq) | |
8352 | return IOCB_ERROR; | |
8353 | } | |
8354 | ||
8355 | if (sglq) { | |
6d368e53 | 8356 | piocb->sli4_lxritag = sglq->sli4_lxritag; |
2a9bf3d0 | 8357 | piocb->sli4_xritag = sglq->sli4_xritag; |
2a9bf3d0 | 8358 | if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocb, sglq)) |
4f774513 JS |
8359 | return IOCB_ERROR; |
8360 | } | |
8361 | ||
8362 | if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe)) | |
8363 | return IOCB_ERROR; | |
8364 | ||
341af102 JS |
8365 | if ((piocb->iocb_flag & LPFC_IO_FCP) || |
8366 | (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) { | |
5ffc266e JS |
8367 | if (lpfc_sli4_wq_put(phba->sli4_hba.fcp_wq[piocb->fcp_wqidx], |
8368 | &wqe)) | |
4f774513 JS |
8369 | return IOCB_ERROR; |
8370 | } else { | |
8371 | if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe)) | |
8372 | return IOCB_ERROR; | |
8373 | } | |
8374 | lpfc_sli_ringtxcmpl_put(phba, pring, piocb); | |
8375 | ||
8376 | return 0; | |
8377 | } | |
8378 | ||
8379 | /** | |
8380 | * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb | |
8381 | * | |
8382 | * This routine wraps the actual lockless version for issusing IOCB function | |
8383 | * pointer from the lpfc_hba struct. | |
8384 | * | |
8385 | * Return codes: | |
8386 | * IOCB_ERROR - Error | |
8387 | * IOCB_SUCCESS - Success | |
8388 | * IOCB_BUSY - Busy | |
8389 | **/ | |
2a9bf3d0 | 8390 | int |
4f774513 JS |
8391 | __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, |
8392 | struct lpfc_iocbq *piocb, uint32_t flag) | |
8393 | { | |
8394 | return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); | |
8395 | } | |
8396 | ||
8397 | /** | |
25985edc | 8398 | * lpfc_sli_api_table_setup - Set up sli api function jump table |
4f774513 JS |
8399 | * @phba: The hba struct for which this call is being executed. |
8400 | * @dev_grp: The HBA PCI-Device group number. | |
8401 | * | |
8402 | * This routine sets up the SLI interface API function jump table in @phba | |
8403 | * struct. | |
8404 | * Returns: 0 - success, -ENODEV - failure. | |
8405 | **/ | |
8406 | int | |
8407 | lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) | |
8408 | { | |
8409 | ||
8410 | switch (dev_grp) { | |
8411 | case LPFC_PCI_DEV_LP: | |
8412 | phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3; | |
8413 | phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3; | |
8414 | break; | |
8415 | case LPFC_PCI_DEV_OC: | |
8416 | phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4; | |
8417 | phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4; | |
8418 | break; | |
8419 | default: | |
8420 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8421 | "1419 Invalid HBA PCI-device group: 0x%x\n", | |
8422 | dev_grp); | |
8423 | return -ENODEV; | |
8424 | break; | |
8425 | } | |
8426 | phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq; | |
8427 | return 0; | |
8428 | } | |
8429 | ||
8430 | /** | |
8431 | * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb | |
8432 | * @phba: Pointer to HBA context object. | |
8433 | * @pring: Pointer to driver SLI ring object. | |
8434 | * @piocb: Pointer to command iocb. | |
8435 | * @flag: Flag indicating if this command can be put into txq. | |
8436 | * | |
8437 | * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb | |
8438 | * function. This function gets the hbalock and calls | |
8439 | * __lpfc_sli_issue_iocb function and will return the error returned | |
8440 | * by __lpfc_sli_issue_iocb function. This wrapper is used by | |
8441 | * functions which do not hold hbalock. | |
8442 | **/ | |
8443 | int | |
8444 | lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, | |
8445 | struct lpfc_iocbq *piocb, uint32_t flag) | |
8446 | { | |
ba20c853 | 8447 | struct lpfc_fcp_eq_hdl *fcp_eq_hdl; |
2a76a283 | 8448 | struct lpfc_sli_ring *pring; |
ba20c853 JS |
8449 | struct lpfc_queue *fpeq; |
8450 | struct lpfc_eqe *eqe; | |
4f774513 | 8451 | unsigned long iflags; |
2a76a283 | 8452 | int rc, idx; |
4f774513 | 8453 | |
7e56aa25 | 8454 | if (phba->sli_rev == LPFC_SLI_REV4) { |
2a76a283 JS |
8455 | if (piocb->iocb_flag & LPFC_IO_FCP) { |
8456 | if (unlikely(!phba->sli4_hba.fcp_wq)) | |
8457 | return IOCB_ERROR; | |
8458 | idx = lpfc_sli4_scmd_to_wqidx_distr(phba); | |
8459 | piocb->fcp_wqidx = idx; | |
8460 | ring_number = MAX_SLI3_CONFIGURED_RINGS + idx; | |
ba20c853 JS |
8461 | |
8462 | pring = &phba->sli.ring[ring_number]; | |
8463 | spin_lock_irqsave(&pring->ring_lock, iflags); | |
8464 | rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, | |
8465 | flag); | |
8466 | spin_unlock_irqrestore(&pring->ring_lock, iflags); | |
8467 | ||
8468 | if (lpfc_fcp_look_ahead) { | |
8469 | fcp_eq_hdl = &phba->sli4_hba.fcp_eq_hdl[idx]; | |
8470 | ||
8471 | if (atomic_dec_and_test(&fcp_eq_hdl-> | |
8472 | fcp_eq_in_use)) { | |
8473 | ||
8474 | /* Get associated EQ with this index */ | |
8475 | fpeq = phba->sli4_hba.hba_eq[idx]; | |
8476 | ||
8477 | /* Turn off interrupts from this EQ */ | |
8478 | lpfc_sli4_eq_clr_intr(fpeq); | |
8479 | ||
8480 | /* | |
8481 | * Process all the events on FCP EQ | |
8482 | */ | |
8483 | while ((eqe = lpfc_sli4_eq_get(fpeq))) { | |
8484 | lpfc_sli4_hba_handle_eqe(phba, | |
8485 | eqe, idx); | |
8486 | fpeq->EQ_processed++; | |
8487 | } | |
8488 | ||
8489 | /* Always clear and re-arm the EQ */ | |
8490 | lpfc_sli4_eq_release(fpeq, | |
8491 | LPFC_QUEUE_REARM); | |
8492 | } | |
8493 | atomic_inc(&fcp_eq_hdl->fcp_eq_in_use); | |
8494 | } | |
8495 | } else { | |
8496 | pring = &phba->sli.ring[ring_number]; | |
8497 | spin_lock_irqsave(&pring->ring_lock, iflags); | |
8498 | rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, | |
8499 | flag); | |
8500 | spin_unlock_irqrestore(&pring->ring_lock, iflags); | |
8501 | ||
2a76a283 | 8502 | } |
7e56aa25 JS |
8503 | } else { |
8504 | /* For now, SLI2/3 will still use hbalock */ | |
8505 | spin_lock_irqsave(&phba->hbalock, iflags); | |
8506 | rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); | |
8507 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
8508 | } | |
4f774513 JS |
8509 | return rc; |
8510 | } | |
8511 | ||
8512 | /** | |
8513 | * lpfc_extra_ring_setup - Extra ring setup function | |
8514 | * @phba: Pointer to HBA context object. | |
8515 | * | |
8516 | * This function is called while driver attaches with the | |
8517 | * HBA to setup the extra ring. The extra ring is used | |
8518 | * only when driver needs to support target mode functionality | |
8519 | * or IP over FC functionalities. | |
8520 | * | |
8521 | * This function is called with no lock held. | |
8522 | **/ | |
8523 | static int | |
8524 | lpfc_extra_ring_setup( struct lpfc_hba *phba) | |
8525 | { | |
8526 | struct lpfc_sli *psli; | |
8527 | struct lpfc_sli_ring *pring; | |
8528 | ||
8529 | psli = &phba->sli; | |
8530 | ||
8531 | /* Adjust cmd/rsp ring iocb entries more evenly */ | |
8532 | ||
8533 | /* Take some away from the FCP ring */ | |
8534 | pring = &psli->ring[psli->fcp_ring]; | |
7e56aa25 JS |
8535 | pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
8536 | pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES; | |
8537 | pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES; | |
8538 | pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES; | |
cf5bf97e | 8539 | |
a4bc3379 JS |
8540 | /* and give them to the extra ring */ |
8541 | pring = &psli->ring[psli->extra_ring]; | |
8542 | ||
7e56aa25 JS |
8543 | pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
8544 | pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES; | |
8545 | pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES; | |
8546 | pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES; | |
cf5bf97e JW |
8547 | |
8548 | /* Setup default profile for this ring */ | |
8549 | pring->iotag_max = 4096; | |
8550 | pring->num_mask = 1; | |
8551 | pring->prt[0].profile = 0; /* Mask 0 */ | |
a4bc3379 JS |
8552 | pring->prt[0].rctl = phba->cfg_multi_ring_rctl; |
8553 | pring->prt[0].type = phba->cfg_multi_ring_type; | |
cf5bf97e JW |
8554 | pring->prt[0].lpfc_sli_rcv_unsol_event = NULL; |
8555 | return 0; | |
8556 | } | |
8557 | ||
cb69f7de JS |
8558 | /* lpfc_sli_abts_err_handler - handle a failed ABTS request from an SLI3 port. |
8559 | * @phba: Pointer to HBA context object. | |
8560 | * @iocbq: Pointer to iocb object. | |
8561 | * | |
8562 | * The async_event handler calls this routine when it receives | |
8563 | * an ASYNC_STATUS_CN event from the port. The port generates | |
8564 | * this event when an Abort Sequence request to an rport fails | |
8565 | * twice in succession. The abort could be originated by the | |
8566 | * driver or by the port. The ABTS could have been for an ELS | |
8567 | * or FCP IO. The port only generates this event when an ABTS | |
8568 | * fails to complete after one retry. | |
8569 | */ | |
8570 | static void | |
8571 | lpfc_sli_abts_err_handler(struct lpfc_hba *phba, | |
8572 | struct lpfc_iocbq *iocbq) | |
8573 | { | |
8574 | struct lpfc_nodelist *ndlp = NULL; | |
8575 | uint16_t rpi = 0, vpi = 0; | |
8576 | struct lpfc_vport *vport = NULL; | |
8577 | ||
8578 | /* The rpi in the ulpContext is vport-sensitive. */ | |
8579 | vpi = iocbq->iocb.un.asyncstat.sub_ctxt_tag; | |
8580 | rpi = iocbq->iocb.ulpContext; | |
8581 | ||
8582 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
8583 | "3092 Port generated ABTS async event " | |
8584 | "on vpi %d rpi %d status 0x%x\n", | |
8585 | vpi, rpi, iocbq->iocb.ulpStatus); | |
8586 | ||
8587 | vport = lpfc_find_vport_by_vpid(phba, vpi); | |
8588 | if (!vport) | |
8589 | goto err_exit; | |
8590 | ndlp = lpfc_findnode_rpi(vport, rpi); | |
8591 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) | |
8592 | goto err_exit; | |
8593 | ||
8594 | if (iocbq->iocb.ulpStatus == IOSTAT_LOCAL_REJECT) | |
8595 | lpfc_sli_abts_recover_port(vport, ndlp); | |
8596 | return; | |
8597 | ||
8598 | err_exit: | |
8599 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
8600 | "3095 Event Context not found, no " | |
8601 | "action on vpi %d rpi %d status 0x%x, reason 0x%x\n", | |
8602 | iocbq->iocb.ulpContext, iocbq->iocb.ulpStatus, | |
8603 | vpi, rpi); | |
8604 | } | |
8605 | ||
8606 | /* lpfc_sli4_abts_err_handler - handle a failed ABTS request from an SLI4 port. | |
8607 | * @phba: pointer to HBA context object. | |
8608 | * @ndlp: nodelist pointer for the impacted rport. | |
8609 | * @axri: pointer to the wcqe containing the failed exchange. | |
8610 | * | |
8611 | * The driver calls this routine when it receives an ABORT_XRI_FCP CQE from the | |
8612 | * port. The port generates this event when an abort exchange request to an | |
8613 | * rport fails twice in succession with no reply. The abort could be originated | |
8614 | * by the driver or by the port. The ABTS could have been for an ELS or FCP IO. | |
8615 | */ | |
8616 | void | |
8617 | lpfc_sli4_abts_err_handler(struct lpfc_hba *phba, | |
8618 | struct lpfc_nodelist *ndlp, | |
8619 | struct sli4_wcqe_xri_aborted *axri) | |
8620 | { | |
8621 | struct lpfc_vport *vport; | |
5c1db2ac | 8622 | uint32_t ext_status = 0; |
cb69f7de | 8623 | |
6b5151fd | 8624 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
cb69f7de JS |
8625 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
8626 | "3115 Node Context not found, driver " | |
8627 | "ignoring abts err event\n"); | |
6b5151fd JS |
8628 | return; |
8629 | } | |
8630 | ||
cb69f7de JS |
8631 | vport = ndlp->vport; |
8632 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
8633 | "3116 Port generated FCP XRI ABORT event on " | |
5c1db2ac | 8634 | "vpi %d rpi %d xri x%x status 0x%x parameter x%x\n", |
cb69f7de JS |
8635 | ndlp->vport->vpi, ndlp->nlp_rpi, |
8636 | bf_get(lpfc_wcqe_xa_xri, axri), | |
5c1db2ac JS |
8637 | bf_get(lpfc_wcqe_xa_status, axri), |
8638 | axri->parameter); | |
cb69f7de | 8639 | |
5c1db2ac JS |
8640 | /* |
8641 | * Catch the ABTS protocol failure case. Older OCe FW releases returned | |
8642 | * LOCAL_REJECT and 0 for a failed ABTS exchange and later OCe and | |
8643 | * LPe FW releases returned LOCAL_REJECT and SEQUENCE_TIMEOUT. | |
8644 | */ | |
8645 | ext_status = axri->parameter & WCQE_PARAM_MASK; | |
8646 | if ((bf_get(lpfc_wcqe_xa_status, axri) == IOSTAT_LOCAL_REJECT) && | |
8647 | ((ext_status == IOERR_SEQUENCE_TIMEOUT) || (ext_status == 0))) | |
cb69f7de JS |
8648 | lpfc_sli_abts_recover_port(vport, ndlp); |
8649 | } | |
8650 | ||
e59058c4 | 8651 | /** |
3621a710 | 8652 | * lpfc_sli_async_event_handler - ASYNC iocb handler function |
e59058c4 JS |
8653 | * @phba: Pointer to HBA context object. |
8654 | * @pring: Pointer to driver SLI ring object. | |
8655 | * @iocbq: Pointer to iocb object. | |
8656 | * | |
8657 | * This function is called by the slow ring event handler | |
8658 | * function when there is an ASYNC event iocb in the ring. | |
8659 | * This function is called with no lock held. | |
8660 | * Currently this function handles only temperature related | |
8661 | * ASYNC events. The function decodes the temperature sensor | |
8662 | * event message and posts events for the management applications. | |
8663 | **/ | |
98c9ea5c | 8664 | static void |
57127f15 JS |
8665 | lpfc_sli_async_event_handler(struct lpfc_hba * phba, |
8666 | struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq) | |
8667 | { | |
8668 | IOCB_t *icmd; | |
8669 | uint16_t evt_code; | |
57127f15 JS |
8670 | struct temp_event temp_event_data; |
8671 | struct Scsi_Host *shost; | |
a257bf90 | 8672 | uint32_t *iocb_w; |
57127f15 JS |
8673 | |
8674 | icmd = &iocbq->iocb; | |
8675 | evt_code = icmd->un.asyncstat.evt_code; | |
57127f15 | 8676 | |
cb69f7de JS |
8677 | switch (evt_code) { |
8678 | case ASYNC_TEMP_WARN: | |
8679 | case ASYNC_TEMP_SAFE: | |
8680 | temp_event_data.data = (uint32_t) icmd->ulpContext; | |
8681 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; | |
8682 | if (evt_code == ASYNC_TEMP_WARN) { | |
8683 | temp_event_data.event_code = LPFC_THRESHOLD_TEMP; | |
8684 | lpfc_printf_log(phba, KERN_ERR, LOG_TEMP, | |
8685 | "0347 Adapter is very hot, please take " | |
8686 | "corrective action. temperature : %d Celsius\n", | |
8687 | (uint32_t) icmd->ulpContext); | |
8688 | } else { | |
8689 | temp_event_data.event_code = LPFC_NORMAL_TEMP; | |
8690 | lpfc_printf_log(phba, KERN_ERR, LOG_TEMP, | |
8691 | "0340 Adapter temperature is OK now. " | |
8692 | "temperature : %d Celsius\n", | |
8693 | (uint32_t) icmd->ulpContext); | |
8694 | } | |
8695 | ||
8696 | /* Send temperature change event to applications */ | |
8697 | shost = lpfc_shost_from_vport(phba->pport); | |
8698 | fc_host_post_vendor_event(shost, fc_get_event_number(), | |
8699 | sizeof(temp_event_data), (char *) &temp_event_data, | |
8700 | LPFC_NL_VENDOR_ID); | |
8701 | break; | |
8702 | case ASYNC_STATUS_CN: | |
8703 | lpfc_sli_abts_err_handler(phba, iocbq); | |
8704 | break; | |
8705 | default: | |
a257bf90 | 8706 | iocb_w = (uint32_t *) icmd; |
cb69f7de | 8707 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
76bb24ef | 8708 | "0346 Ring %d handler: unexpected ASYNC_STATUS" |
e4e74273 | 8709 | " evt_code 0x%x\n" |
a257bf90 JS |
8710 | "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n" |
8711 | "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n" | |
8712 | "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n" | |
8713 | "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n", | |
cb69f7de | 8714 | pring->ringno, icmd->un.asyncstat.evt_code, |
a257bf90 JS |
8715 | iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3], |
8716 | iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7], | |
8717 | iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11], | |
8718 | iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]); | |
8719 | ||
cb69f7de | 8720 | break; |
57127f15 | 8721 | } |
57127f15 JS |
8722 | } |
8723 | ||
8724 | ||
e59058c4 | 8725 | /** |
3621a710 | 8726 | * lpfc_sli_setup - SLI ring setup function |
e59058c4 JS |
8727 | * @phba: Pointer to HBA context object. |
8728 | * | |
8729 | * lpfc_sli_setup sets up rings of the SLI interface with | |
8730 | * number of iocbs per ring and iotags. This function is | |
8731 | * called while driver attach to the HBA and before the | |
8732 | * interrupts are enabled. So there is no need for locking. | |
8733 | * | |
8734 | * This function always returns 0. | |
8735 | **/ | |
dea3101e | 8736 | int |
8737 | lpfc_sli_setup(struct lpfc_hba *phba) | |
8738 | { | |
ed957684 | 8739 | int i, totiocbsize = 0; |
dea3101e | 8740 | struct lpfc_sli *psli = &phba->sli; |
8741 | struct lpfc_sli_ring *pring; | |
8742 | ||
2a76a283 JS |
8743 | psli->num_rings = MAX_SLI3_CONFIGURED_RINGS; |
8744 | if (phba->sli_rev == LPFC_SLI_REV4) | |
67d12733 | 8745 | psli->num_rings += phba->cfg_fcp_io_channel; |
dea3101e | 8746 | psli->sli_flag = 0; |
8747 | psli->fcp_ring = LPFC_FCP_RING; | |
8748 | psli->next_ring = LPFC_FCP_NEXT_RING; | |
a4bc3379 | 8749 | psli->extra_ring = LPFC_EXTRA_RING; |
dea3101e | 8750 | |
604a3e30 JB |
8751 | psli->iocbq_lookup = NULL; |
8752 | psli->iocbq_lookup_len = 0; | |
8753 | psli->last_iotag = 0; | |
8754 | ||
dea3101e | 8755 | for (i = 0; i < psli->num_rings; i++) { |
8756 | pring = &psli->ring[i]; | |
8757 | switch (i) { | |
8758 | case LPFC_FCP_RING: /* ring 0 - FCP */ | |
8759 | /* numCiocb and numRiocb are used in config_port */ | |
7e56aa25 JS |
8760 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R0_ENTRIES; |
8761 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R0_ENTRIES; | |
8762 | pring->sli.sli3.numCiocb += | |
8763 | SLI2_IOCB_CMD_R1XTRA_ENTRIES; | |
8764 | pring->sli.sli3.numRiocb += | |
8765 | SLI2_IOCB_RSP_R1XTRA_ENTRIES; | |
8766 | pring->sli.sli3.numCiocb += | |
8767 | SLI2_IOCB_CMD_R3XTRA_ENTRIES; | |
8768 | pring->sli.sli3.numRiocb += | |
8769 | SLI2_IOCB_RSP_R3XTRA_ENTRIES; | |
8770 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? | |
92d7f7b0 JS |
8771 | SLI3_IOCB_CMD_SIZE : |
8772 | SLI2_IOCB_CMD_SIZE; | |
7e56aa25 | 8773 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
92d7f7b0 JS |
8774 | SLI3_IOCB_RSP_SIZE : |
8775 | SLI2_IOCB_RSP_SIZE; | |
dea3101e | 8776 | pring->iotag_ctr = 0; |
8777 | pring->iotag_max = | |
92d7f7b0 | 8778 | (phba->cfg_hba_queue_depth * 2); |
dea3101e | 8779 | pring->fast_iotag = pring->iotag_max; |
8780 | pring->num_mask = 0; | |
8781 | break; | |
a4bc3379 | 8782 | case LPFC_EXTRA_RING: /* ring 1 - EXTRA */ |
dea3101e | 8783 | /* numCiocb and numRiocb are used in config_port */ |
7e56aa25 JS |
8784 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R1_ENTRIES; |
8785 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R1_ENTRIES; | |
8786 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? | |
92d7f7b0 JS |
8787 | SLI3_IOCB_CMD_SIZE : |
8788 | SLI2_IOCB_CMD_SIZE; | |
7e56aa25 | 8789 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
92d7f7b0 JS |
8790 | SLI3_IOCB_RSP_SIZE : |
8791 | SLI2_IOCB_RSP_SIZE; | |
2e0fef85 | 8792 | pring->iotag_max = phba->cfg_hba_queue_depth; |
dea3101e | 8793 | pring->num_mask = 0; |
8794 | break; | |
8795 | case LPFC_ELS_RING: /* ring 2 - ELS / CT */ | |
8796 | /* numCiocb and numRiocb are used in config_port */ | |
7e56aa25 JS |
8797 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R2_ENTRIES; |
8798 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R2_ENTRIES; | |
8799 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? | |
92d7f7b0 JS |
8800 | SLI3_IOCB_CMD_SIZE : |
8801 | SLI2_IOCB_CMD_SIZE; | |
7e56aa25 | 8802 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
92d7f7b0 JS |
8803 | SLI3_IOCB_RSP_SIZE : |
8804 | SLI2_IOCB_RSP_SIZE; | |
dea3101e | 8805 | pring->fast_iotag = 0; |
8806 | pring->iotag_ctr = 0; | |
8807 | pring->iotag_max = 4096; | |
57127f15 JS |
8808 | pring->lpfc_sli_rcv_async_status = |
8809 | lpfc_sli_async_event_handler; | |
6669f9bb | 8810 | pring->num_mask = LPFC_MAX_RING_MASK; |
dea3101e | 8811 | pring->prt[0].profile = 0; /* Mask 0 */ |
6a9c52cf JS |
8812 | pring->prt[0].rctl = FC_RCTL_ELS_REQ; |
8813 | pring->prt[0].type = FC_TYPE_ELS; | |
dea3101e | 8814 | pring->prt[0].lpfc_sli_rcv_unsol_event = |
92d7f7b0 | 8815 | lpfc_els_unsol_event; |
dea3101e | 8816 | pring->prt[1].profile = 0; /* Mask 1 */ |
6a9c52cf JS |
8817 | pring->prt[1].rctl = FC_RCTL_ELS_REP; |
8818 | pring->prt[1].type = FC_TYPE_ELS; | |
dea3101e | 8819 | pring->prt[1].lpfc_sli_rcv_unsol_event = |
92d7f7b0 | 8820 | lpfc_els_unsol_event; |
dea3101e | 8821 | pring->prt[2].profile = 0; /* Mask 2 */ |
8822 | /* NameServer Inquiry */ | |
6a9c52cf | 8823 | pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL; |
dea3101e | 8824 | /* NameServer */ |
6a9c52cf | 8825 | pring->prt[2].type = FC_TYPE_CT; |
dea3101e | 8826 | pring->prt[2].lpfc_sli_rcv_unsol_event = |
92d7f7b0 | 8827 | lpfc_ct_unsol_event; |
dea3101e | 8828 | pring->prt[3].profile = 0; /* Mask 3 */ |
8829 | /* NameServer response */ | |
6a9c52cf | 8830 | pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL; |
dea3101e | 8831 | /* NameServer */ |
6a9c52cf | 8832 | pring->prt[3].type = FC_TYPE_CT; |
dea3101e | 8833 | pring->prt[3].lpfc_sli_rcv_unsol_event = |
92d7f7b0 | 8834 | lpfc_ct_unsol_event; |
6669f9bb JS |
8835 | /* abort unsolicited sequence */ |
8836 | pring->prt[4].profile = 0; /* Mask 4 */ | |
8837 | pring->prt[4].rctl = FC_RCTL_BA_ABTS; | |
8838 | pring->prt[4].type = FC_TYPE_BLS; | |
8839 | pring->prt[4].lpfc_sli_rcv_unsol_event = | |
8840 | lpfc_sli4_ct_abort_unsol_event; | |
dea3101e | 8841 | break; |
8842 | } | |
7e56aa25 JS |
8843 | totiocbsize += (pring->sli.sli3.numCiocb * |
8844 | pring->sli.sli3.sizeCiocb) + | |
8845 | (pring->sli.sli3.numRiocb * pring->sli.sli3.sizeRiocb); | |
dea3101e | 8846 | } |
ed957684 | 8847 | if (totiocbsize > MAX_SLIM_IOCB_SIZE) { |
dea3101e | 8848 | /* Too many cmd / rsp ring entries in SLI2 SLIM */ |
e8b62011 JS |
8849 | printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in " |
8850 | "SLI2 SLIM Data: x%x x%lx\n", | |
8851 | phba->brd_no, totiocbsize, | |
8852 | (unsigned long) MAX_SLIM_IOCB_SIZE); | |
dea3101e | 8853 | } |
cf5bf97e JW |
8854 | if (phba->cfg_multi_ring_support == 2) |
8855 | lpfc_extra_ring_setup(phba); | |
dea3101e | 8856 | |
8857 | return 0; | |
8858 | } | |
8859 | ||
e59058c4 | 8860 | /** |
3621a710 | 8861 | * lpfc_sli_queue_setup - Queue initialization function |
e59058c4 JS |
8862 | * @phba: Pointer to HBA context object. |
8863 | * | |
8864 | * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each | |
8865 | * ring. This function also initializes ring indices of each ring. | |
8866 | * This function is called during the initialization of the SLI | |
8867 | * interface of an HBA. | |
8868 | * This function is called with no lock held and always returns | |
8869 | * 1. | |
8870 | **/ | |
dea3101e | 8871 | int |
2e0fef85 | 8872 | lpfc_sli_queue_setup(struct lpfc_hba *phba) |
dea3101e | 8873 | { |
8874 | struct lpfc_sli *psli; | |
8875 | struct lpfc_sli_ring *pring; | |
604a3e30 | 8876 | int i; |
dea3101e | 8877 | |
8878 | psli = &phba->sli; | |
2e0fef85 | 8879 | spin_lock_irq(&phba->hbalock); |
dea3101e | 8880 | INIT_LIST_HEAD(&psli->mboxq); |
92d7f7b0 | 8881 | INIT_LIST_HEAD(&psli->mboxq_cmpl); |
dea3101e | 8882 | /* Initialize list headers for txq and txcmplq as double linked lists */ |
8883 | for (i = 0; i < psli->num_rings; i++) { | |
8884 | pring = &psli->ring[i]; | |
8885 | pring->ringno = i; | |
7e56aa25 JS |
8886 | pring->sli.sli3.next_cmdidx = 0; |
8887 | pring->sli.sli3.local_getidx = 0; | |
8888 | pring->sli.sli3.cmdidx = 0; | |
dea3101e | 8889 | INIT_LIST_HEAD(&pring->txq); |
8890 | INIT_LIST_HEAD(&pring->txcmplq); | |
8891 | INIT_LIST_HEAD(&pring->iocb_continueq); | |
9c2face6 | 8892 | INIT_LIST_HEAD(&pring->iocb_continue_saveq); |
dea3101e | 8893 | INIT_LIST_HEAD(&pring->postbufq); |
7e56aa25 | 8894 | spin_lock_init(&pring->ring_lock); |
dea3101e | 8895 | } |
2e0fef85 JS |
8896 | spin_unlock_irq(&phba->hbalock); |
8897 | return 1; | |
dea3101e | 8898 | } |
8899 | ||
04c68496 JS |
8900 | /** |
8901 | * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system | |
8902 | * @phba: Pointer to HBA context object. | |
8903 | * | |
8904 | * This routine flushes the mailbox command subsystem. It will unconditionally | |
8905 | * flush all the mailbox commands in the three possible stages in the mailbox | |
8906 | * command sub-system: pending mailbox command queue; the outstanding mailbox | |
8907 | * command; and completed mailbox command queue. It is caller's responsibility | |
8908 | * to make sure that the driver is in the proper state to flush the mailbox | |
8909 | * command sub-system. Namely, the posting of mailbox commands into the | |
8910 | * pending mailbox command queue from the various clients must be stopped; | |
8911 | * either the HBA is in a state that it will never works on the outstanding | |
8912 | * mailbox command (such as in EEH or ERATT conditions) or the outstanding | |
8913 | * mailbox command has been completed. | |
8914 | **/ | |
8915 | static void | |
8916 | lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba) | |
8917 | { | |
8918 | LIST_HEAD(completions); | |
8919 | struct lpfc_sli *psli = &phba->sli; | |
8920 | LPFC_MBOXQ_t *pmb; | |
8921 | unsigned long iflag; | |
8922 | ||
8923 | /* Flush all the mailbox commands in the mbox system */ | |
8924 | spin_lock_irqsave(&phba->hbalock, iflag); | |
8925 | /* The pending mailbox command queue */ | |
8926 | list_splice_init(&phba->sli.mboxq, &completions); | |
8927 | /* The outstanding active mailbox command */ | |
8928 | if (psli->mbox_active) { | |
8929 | list_add_tail(&psli->mbox_active->list, &completions); | |
8930 | psli->mbox_active = NULL; | |
8931 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
8932 | } | |
8933 | /* The completed mailbox command queue */ | |
8934 | list_splice_init(&phba->sli.mboxq_cmpl, &completions); | |
8935 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
8936 | ||
8937 | /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */ | |
8938 | while (!list_empty(&completions)) { | |
8939 | list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list); | |
8940 | pmb->u.mb.mbxStatus = MBX_NOT_FINISHED; | |
8941 | if (pmb->mbox_cmpl) | |
8942 | pmb->mbox_cmpl(phba, pmb); | |
8943 | } | |
8944 | } | |
8945 | ||
e59058c4 | 8946 | /** |
3621a710 | 8947 | * lpfc_sli_host_down - Vport cleanup function |
e59058c4 JS |
8948 | * @vport: Pointer to virtual port object. |
8949 | * | |
8950 | * lpfc_sli_host_down is called to clean up the resources | |
8951 | * associated with a vport before destroying virtual | |
8952 | * port data structures. | |
8953 | * This function does following operations: | |
8954 | * - Free discovery resources associated with this virtual | |
8955 | * port. | |
8956 | * - Free iocbs associated with this virtual port in | |
8957 | * the txq. | |
8958 | * - Send abort for all iocb commands associated with this | |
8959 | * vport in txcmplq. | |
8960 | * | |
8961 | * This function is called with no lock held and always returns 1. | |
8962 | **/ | |
92d7f7b0 JS |
8963 | int |
8964 | lpfc_sli_host_down(struct lpfc_vport *vport) | |
8965 | { | |
858c9f6c | 8966 | LIST_HEAD(completions); |
92d7f7b0 JS |
8967 | struct lpfc_hba *phba = vport->phba; |
8968 | struct lpfc_sli *psli = &phba->sli; | |
8969 | struct lpfc_sli_ring *pring; | |
8970 | struct lpfc_iocbq *iocb, *next_iocb; | |
92d7f7b0 JS |
8971 | int i; |
8972 | unsigned long flags = 0; | |
8973 | uint16_t prev_pring_flag; | |
8974 | ||
8975 | lpfc_cleanup_discovery_resources(vport); | |
8976 | ||
8977 | spin_lock_irqsave(&phba->hbalock, flags); | |
92d7f7b0 JS |
8978 | for (i = 0; i < psli->num_rings; i++) { |
8979 | pring = &psli->ring[i]; | |
8980 | prev_pring_flag = pring->flag; | |
5e9d9b82 JS |
8981 | /* Only slow rings */ |
8982 | if (pring->ringno == LPFC_ELS_RING) { | |
858c9f6c | 8983 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
5e9d9b82 JS |
8984 | /* Set the lpfc data pending flag */ |
8985 | set_bit(LPFC_DATA_READY, &phba->data_flags); | |
8986 | } | |
92d7f7b0 JS |
8987 | /* |
8988 | * Error everything on the txq since these iocbs have not been | |
8989 | * given to the FW yet. | |
8990 | */ | |
92d7f7b0 JS |
8991 | list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) { |
8992 | if (iocb->vport != vport) | |
8993 | continue; | |
858c9f6c | 8994 | list_move_tail(&iocb->list, &completions); |
92d7f7b0 | 8995 | pring->txq_cnt--; |
92d7f7b0 JS |
8996 | } |
8997 | ||
8998 | /* Next issue ABTS for everything on the txcmplq */ | |
8999 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, | |
9000 | list) { | |
9001 | if (iocb->vport != vport) | |
9002 | continue; | |
9003 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); | |
9004 | } | |
9005 | ||
9006 | pring->flag = prev_pring_flag; | |
9007 | } | |
9008 | ||
9009 | spin_unlock_irqrestore(&phba->hbalock, flags); | |
9010 | ||
a257bf90 JS |
9011 | /* Cancel all the IOCBs from the completions list */ |
9012 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, | |
9013 | IOERR_SLI_DOWN); | |
92d7f7b0 JS |
9014 | return 1; |
9015 | } | |
9016 | ||
e59058c4 | 9017 | /** |
3621a710 | 9018 | * lpfc_sli_hba_down - Resource cleanup function for the HBA |
e59058c4 JS |
9019 | * @phba: Pointer to HBA context object. |
9020 | * | |
9021 | * This function cleans up all iocb, buffers, mailbox commands | |
9022 | * while shutting down the HBA. This function is called with no | |
9023 | * lock held and always returns 1. | |
9024 | * This function does the following to cleanup driver resources: | |
9025 | * - Free discovery resources for each virtual port | |
9026 | * - Cleanup any pending fabric iocbs | |
9027 | * - Iterate through the iocb txq and free each entry | |
9028 | * in the list. | |
9029 | * - Free up any buffer posted to the HBA | |
9030 | * - Free mailbox commands in the mailbox queue. | |
9031 | **/ | |
dea3101e | 9032 | int |
2e0fef85 | 9033 | lpfc_sli_hba_down(struct lpfc_hba *phba) |
dea3101e | 9034 | { |
2534ba75 | 9035 | LIST_HEAD(completions); |
2e0fef85 | 9036 | struct lpfc_sli *psli = &phba->sli; |
dea3101e | 9037 | struct lpfc_sli_ring *pring; |
0ff10d46 | 9038 | struct lpfc_dmabuf *buf_ptr; |
dea3101e | 9039 | unsigned long flags = 0; |
04c68496 JS |
9040 | int i; |
9041 | ||
9042 | /* Shutdown the mailbox command sub-system */ | |
618a5230 | 9043 | lpfc_sli_mbox_sys_shutdown(phba, LPFC_MBX_WAIT); |
dea3101e | 9044 | |
dea3101e | 9045 | lpfc_hba_down_prep(phba); |
9046 | ||
92d7f7b0 JS |
9047 | lpfc_fabric_abort_hba(phba); |
9048 | ||
2e0fef85 | 9049 | spin_lock_irqsave(&phba->hbalock, flags); |
dea3101e | 9050 | for (i = 0; i < psli->num_rings; i++) { |
9051 | pring = &psli->ring[i]; | |
5e9d9b82 JS |
9052 | /* Only slow rings */ |
9053 | if (pring->ringno == LPFC_ELS_RING) { | |
858c9f6c | 9054 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
5e9d9b82 JS |
9055 | /* Set the lpfc data pending flag */ |
9056 | set_bit(LPFC_DATA_READY, &phba->data_flags); | |
9057 | } | |
dea3101e | 9058 | |
9059 | /* | |
9060 | * Error everything on the txq since these iocbs have not been | |
9061 | * given to the FW yet. | |
9062 | */ | |
2534ba75 | 9063 | list_splice_init(&pring->txq, &completions); |
dea3101e | 9064 | pring->txq_cnt = 0; |
9065 | ||
2534ba75 | 9066 | } |
2e0fef85 | 9067 | spin_unlock_irqrestore(&phba->hbalock, flags); |
dea3101e | 9068 | |
a257bf90 JS |
9069 | /* Cancel all the IOCBs from the completions list */ |
9070 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, | |
9071 | IOERR_SLI_DOWN); | |
dea3101e | 9072 | |
0ff10d46 JS |
9073 | spin_lock_irqsave(&phba->hbalock, flags); |
9074 | list_splice_init(&phba->elsbuf, &completions); | |
9075 | phba->elsbuf_cnt = 0; | |
9076 | phba->elsbuf_prev_cnt = 0; | |
9077 | spin_unlock_irqrestore(&phba->hbalock, flags); | |
9078 | ||
9079 | while (!list_empty(&completions)) { | |
9080 | list_remove_head(&completions, buf_ptr, | |
9081 | struct lpfc_dmabuf, list); | |
9082 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); | |
9083 | kfree(buf_ptr); | |
9084 | } | |
9085 | ||
dea3101e | 9086 | /* Return any active mbox cmds */ |
9087 | del_timer_sync(&psli->mbox_tmo); | |
2e0fef85 | 9088 | |
da0436e9 | 9089 | spin_lock_irqsave(&phba->pport->work_port_lock, flags); |
2e0fef85 | 9090 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
da0436e9 | 9091 | spin_unlock_irqrestore(&phba->pport->work_port_lock, flags); |
2e0fef85 | 9092 | |
da0436e9 JS |
9093 | return 1; |
9094 | } | |
9095 | ||
e59058c4 | 9096 | /** |
3621a710 | 9097 | * lpfc_sli_pcimem_bcopy - SLI memory copy function |
e59058c4 JS |
9098 | * @srcp: Source memory pointer. |
9099 | * @destp: Destination memory pointer. | |
9100 | * @cnt: Number of words required to be copied. | |
9101 | * | |
9102 | * This function is used for copying data between driver memory | |
9103 | * and the SLI memory. This function also changes the endianness | |
9104 | * of each word if native endianness is different from SLI | |
9105 | * endianness. This function can be called with or without | |
9106 | * lock. | |
9107 | **/ | |
dea3101e | 9108 | void |
9109 | lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt) | |
9110 | { | |
9111 | uint32_t *src = srcp; | |
9112 | uint32_t *dest = destp; | |
9113 | uint32_t ldata; | |
9114 | int i; | |
9115 | ||
9116 | for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) { | |
9117 | ldata = *src; | |
9118 | ldata = le32_to_cpu(ldata); | |
9119 | *dest = ldata; | |
9120 | src++; | |
9121 | dest++; | |
9122 | } | |
9123 | } | |
9124 | ||
e59058c4 | 9125 | |
a0c87cbd JS |
9126 | /** |
9127 | * lpfc_sli_bemem_bcopy - SLI memory copy function | |
9128 | * @srcp: Source memory pointer. | |
9129 | * @destp: Destination memory pointer. | |
9130 | * @cnt: Number of words required to be copied. | |
9131 | * | |
9132 | * This function is used for copying data between a data structure | |
9133 | * with big endian representation to local endianness. | |
9134 | * This function can be called with or without lock. | |
9135 | **/ | |
9136 | void | |
9137 | lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt) | |
9138 | { | |
9139 | uint32_t *src = srcp; | |
9140 | uint32_t *dest = destp; | |
9141 | uint32_t ldata; | |
9142 | int i; | |
9143 | ||
9144 | for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) { | |
9145 | ldata = *src; | |
9146 | ldata = be32_to_cpu(ldata); | |
9147 | *dest = ldata; | |
9148 | src++; | |
9149 | dest++; | |
9150 | } | |
9151 | } | |
9152 | ||
e59058c4 | 9153 | /** |
3621a710 | 9154 | * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq |
e59058c4 JS |
9155 | * @phba: Pointer to HBA context object. |
9156 | * @pring: Pointer to driver SLI ring object. | |
9157 | * @mp: Pointer to driver buffer object. | |
9158 | * | |
9159 | * This function is called with no lock held. | |
9160 | * It always return zero after adding the buffer to the postbufq | |
9161 | * buffer list. | |
9162 | **/ | |
dea3101e | 9163 | int |
2e0fef85 JS |
9164 | lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
9165 | struct lpfc_dmabuf *mp) | |
dea3101e | 9166 | { |
9167 | /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up | |
9168 | later */ | |
2e0fef85 | 9169 | spin_lock_irq(&phba->hbalock); |
dea3101e | 9170 | list_add_tail(&mp->list, &pring->postbufq); |
dea3101e | 9171 | pring->postbufq_cnt++; |
2e0fef85 | 9172 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 9173 | return 0; |
9174 | } | |
9175 | ||
e59058c4 | 9176 | /** |
3621a710 | 9177 | * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer |
e59058c4 JS |
9178 | * @phba: Pointer to HBA context object. |
9179 | * | |
9180 | * When HBQ is enabled, buffers are searched based on tags. This function | |
9181 | * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The | |
9182 | * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag | |
9183 | * does not conflict with tags of buffer posted for unsolicited events. | |
9184 | * The function returns the allocated tag. The function is called with | |
9185 | * no locks held. | |
9186 | **/ | |
76bb24ef JS |
9187 | uint32_t |
9188 | lpfc_sli_get_buffer_tag(struct lpfc_hba *phba) | |
9189 | { | |
9190 | spin_lock_irq(&phba->hbalock); | |
9191 | phba->buffer_tag_count++; | |
9192 | /* | |
9193 | * Always set the QUE_BUFTAG_BIT to distiguish between | |
9194 | * a tag assigned by HBQ. | |
9195 | */ | |
9196 | phba->buffer_tag_count |= QUE_BUFTAG_BIT; | |
9197 | spin_unlock_irq(&phba->hbalock); | |
9198 | return phba->buffer_tag_count; | |
9199 | } | |
9200 | ||
e59058c4 | 9201 | /** |
3621a710 | 9202 | * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag |
e59058c4 JS |
9203 | * @phba: Pointer to HBA context object. |
9204 | * @pring: Pointer to driver SLI ring object. | |
9205 | * @tag: Buffer tag. | |
9206 | * | |
9207 | * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq | |
9208 | * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX | |
9209 | * iocb is posted to the response ring with the tag of the buffer. | |
9210 | * This function searches the pring->postbufq list using the tag | |
9211 | * to find buffer associated with CMD_IOCB_RET_XRI64_CX | |
9212 | * iocb. If the buffer is found then lpfc_dmabuf object of the | |
9213 | * buffer is returned to the caller else NULL is returned. | |
9214 | * This function is called with no lock held. | |
9215 | **/ | |
76bb24ef JS |
9216 | struct lpfc_dmabuf * |
9217 | lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
9218 | uint32_t tag) | |
9219 | { | |
9220 | struct lpfc_dmabuf *mp, *next_mp; | |
9221 | struct list_head *slp = &pring->postbufq; | |
9222 | ||
25985edc | 9223 | /* Search postbufq, from the beginning, looking for a match on tag */ |
76bb24ef JS |
9224 | spin_lock_irq(&phba->hbalock); |
9225 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { | |
9226 | if (mp->buffer_tag == tag) { | |
9227 | list_del_init(&mp->list); | |
9228 | pring->postbufq_cnt--; | |
9229 | spin_unlock_irq(&phba->hbalock); | |
9230 | return mp; | |
9231 | } | |
9232 | } | |
9233 | ||
9234 | spin_unlock_irq(&phba->hbalock); | |
9235 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
d7c255b2 | 9236 | "0402 Cannot find virtual addr for buffer tag on " |
76bb24ef JS |
9237 | "ring %d Data x%lx x%p x%p x%x\n", |
9238 | pring->ringno, (unsigned long) tag, | |
9239 | slp->next, slp->prev, pring->postbufq_cnt); | |
9240 | ||
9241 | return NULL; | |
9242 | } | |
dea3101e | 9243 | |
e59058c4 | 9244 | /** |
3621a710 | 9245 | * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events |
e59058c4 JS |
9246 | * @phba: Pointer to HBA context object. |
9247 | * @pring: Pointer to driver SLI ring object. | |
9248 | * @phys: DMA address of the buffer. | |
9249 | * | |
9250 | * This function searches the buffer list using the dma_address | |
9251 | * of unsolicited event to find the driver's lpfc_dmabuf object | |
9252 | * corresponding to the dma_address. The function returns the | |
9253 | * lpfc_dmabuf object if a buffer is found else it returns NULL. | |
9254 | * This function is called by the ct and els unsolicited event | |
9255 | * handlers to get the buffer associated with the unsolicited | |
9256 | * event. | |
9257 | * | |
9258 | * This function is called with no lock held. | |
9259 | **/ | |
dea3101e | 9260 | struct lpfc_dmabuf * |
9261 | lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
9262 | dma_addr_t phys) | |
9263 | { | |
9264 | struct lpfc_dmabuf *mp, *next_mp; | |
9265 | struct list_head *slp = &pring->postbufq; | |
9266 | ||
25985edc | 9267 | /* Search postbufq, from the beginning, looking for a match on phys */ |
2e0fef85 | 9268 | spin_lock_irq(&phba->hbalock); |
dea3101e | 9269 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
9270 | if (mp->phys == phys) { | |
9271 | list_del_init(&mp->list); | |
9272 | pring->postbufq_cnt--; | |
2e0fef85 | 9273 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 9274 | return mp; |
9275 | } | |
9276 | } | |
9277 | ||
2e0fef85 | 9278 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 9279 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 9280 | "0410 Cannot find virtual addr for mapped buf on " |
dea3101e | 9281 | "ring %d Data x%llx x%p x%p x%x\n", |
e8b62011 | 9282 | pring->ringno, (unsigned long long)phys, |
dea3101e | 9283 | slp->next, slp->prev, pring->postbufq_cnt); |
9284 | return NULL; | |
9285 | } | |
9286 | ||
e59058c4 | 9287 | /** |
3621a710 | 9288 | * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs |
e59058c4 JS |
9289 | * @phba: Pointer to HBA context object. |
9290 | * @cmdiocb: Pointer to driver command iocb object. | |
9291 | * @rspiocb: Pointer to driver response iocb object. | |
9292 | * | |
9293 | * This function is the completion handler for the abort iocbs for | |
9294 | * ELS commands. This function is called from the ELS ring event | |
9295 | * handler with no lock held. This function frees memory resources | |
9296 | * associated with the abort iocb. | |
9297 | **/ | |
dea3101e | 9298 | static void |
2e0fef85 JS |
9299 | lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
9300 | struct lpfc_iocbq *rspiocb) | |
dea3101e | 9301 | { |
2e0fef85 | 9302 | IOCB_t *irsp = &rspiocb->iocb; |
2680eeaa | 9303 | uint16_t abort_iotag, abort_context; |
ff78d8f9 | 9304 | struct lpfc_iocbq *abort_iocb = NULL; |
2680eeaa JS |
9305 | |
9306 | if (irsp->ulpStatus) { | |
ff78d8f9 JS |
9307 | |
9308 | /* | |
9309 | * Assume that the port already completed and returned, or | |
9310 | * will return the iocb. Just Log the message. | |
9311 | */ | |
2680eeaa JS |
9312 | abort_context = cmdiocb->iocb.un.acxri.abortContextTag; |
9313 | abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag; | |
9314 | ||
2e0fef85 | 9315 | spin_lock_irq(&phba->hbalock); |
45ed1190 JS |
9316 | if (phba->sli_rev < LPFC_SLI_REV4) { |
9317 | if (abort_iotag != 0 && | |
9318 | abort_iotag <= phba->sli.last_iotag) | |
9319 | abort_iocb = | |
9320 | phba->sli.iocbq_lookup[abort_iotag]; | |
9321 | } else | |
9322 | /* For sli4 the abort_tag is the XRI, | |
9323 | * so the abort routine puts the iotag of the iocb | |
9324 | * being aborted in the context field of the abort | |
9325 | * IOCB. | |
9326 | */ | |
9327 | abort_iocb = phba->sli.iocbq_lookup[abort_context]; | |
2680eeaa | 9328 | |
2a9bf3d0 JS |
9329 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_SLI, |
9330 | "0327 Cannot abort els iocb %p " | |
9331 | "with tag %x context %x, abort status %x, " | |
9332 | "abort code %x\n", | |
9333 | abort_iocb, abort_iotag, abort_context, | |
9334 | irsp->ulpStatus, irsp->un.ulpWord[4]); | |
341af102 | 9335 | |
ff78d8f9 | 9336 | spin_unlock_irq(&phba->hbalock); |
2680eeaa | 9337 | } |
604a3e30 | 9338 | lpfc_sli_release_iocbq(phba, cmdiocb); |
dea3101e | 9339 | return; |
9340 | } | |
9341 | ||
e59058c4 | 9342 | /** |
3621a710 | 9343 | * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command |
e59058c4 JS |
9344 | * @phba: Pointer to HBA context object. |
9345 | * @cmdiocb: Pointer to driver command iocb object. | |
9346 | * @rspiocb: Pointer to driver response iocb object. | |
9347 | * | |
9348 | * The function is called from SLI ring event handler with no | |
9349 | * lock held. This function is the completion handler for ELS commands | |
9350 | * which are aborted. The function frees memory resources used for | |
9351 | * the aborted ELS commands. | |
9352 | **/ | |
92d7f7b0 JS |
9353 | static void |
9354 | lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, | |
9355 | struct lpfc_iocbq *rspiocb) | |
9356 | { | |
9357 | IOCB_t *irsp = &rspiocb->iocb; | |
9358 | ||
9359 | /* ELS cmd tag <ulpIoTag> completes */ | |
9360 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, | |
d7c255b2 | 9361 | "0139 Ignoring ELS cmd tag x%x completion Data: " |
92d7f7b0 | 9362 | "x%x x%x x%x\n", |
e8b62011 | 9363 | irsp->ulpIoTag, irsp->ulpStatus, |
92d7f7b0 | 9364 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
858c9f6c JS |
9365 | if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) |
9366 | lpfc_ct_free_iocb(phba, cmdiocb); | |
9367 | else | |
9368 | lpfc_els_free_iocb(phba, cmdiocb); | |
92d7f7b0 JS |
9369 | return; |
9370 | } | |
9371 | ||
e59058c4 | 9372 | /** |
5af5eee7 | 9373 | * lpfc_sli_abort_iotag_issue - Issue abort for a command iocb |
e59058c4 JS |
9374 | * @phba: Pointer to HBA context object. |
9375 | * @pring: Pointer to driver SLI ring object. | |
9376 | * @cmdiocb: Pointer to driver command iocb object. | |
9377 | * | |
5af5eee7 JS |
9378 | * This function issues an abort iocb for the provided command iocb down to |
9379 | * the port. Other than the case the outstanding command iocb is an abort | |
9380 | * request, this function issues abort out unconditionally. This function is | |
9381 | * called with hbalock held. The function returns 0 when it fails due to | |
9382 | * memory allocation failure or when the command iocb is an abort request. | |
e59058c4 | 9383 | **/ |
5af5eee7 JS |
9384 | static int |
9385 | lpfc_sli_abort_iotag_issue(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
2e0fef85 | 9386 | struct lpfc_iocbq *cmdiocb) |
dea3101e | 9387 | { |
2e0fef85 | 9388 | struct lpfc_vport *vport = cmdiocb->vport; |
0bd4ca25 | 9389 | struct lpfc_iocbq *abtsiocbp; |
dea3101e | 9390 | IOCB_t *icmd = NULL; |
9391 | IOCB_t *iabt = NULL; | |
5af5eee7 | 9392 | int retval; |
7e56aa25 | 9393 | unsigned long iflags; |
07951076 | 9394 | |
92d7f7b0 JS |
9395 | /* |
9396 | * There are certain command types we don't want to abort. And we | |
9397 | * don't want to abort commands that are already in the process of | |
9398 | * being aborted. | |
07951076 JS |
9399 | */ |
9400 | icmd = &cmdiocb->iocb; | |
2e0fef85 | 9401 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || |
92d7f7b0 JS |
9402 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || |
9403 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) | |
07951076 JS |
9404 | return 0; |
9405 | ||
dea3101e | 9406 | /* issue ABTS for this IOCB based on iotag */ |
92d7f7b0 | 9407 | abtsiocbp = __lpfc_sli_get_iocbq(phba); |
dea3101e | 9408 | if (abtsiocbp == NULL) |
9409 | return 0; | |
dea3101e | 9410 | |
07951076 | 9411 | /* This signals the response to set the correct status |
341af102 | 9412 | * before calling the completion handler |
07951076 JS |
9413 | */ |
9414 | cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED; | |
9415 | ||
dea3101e | 9416 | iabt = &abtsiocbp->iocb; |
07951076 JS |
9417 | iabt->un.acxri.abortType = ABORT_TYPE_ABTS; |
9418 | iabt->un.acxri.abortContextTag = icmd->ulpContext; | |
45ed1190 | 9419 | if (phba->sli_rev == LPFC_SLI_REV4) { |
da0436e9 | 9420 | iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag; |
45ed1190 JS |
9421 | iabt->un.acxri.abortContextTag = cmdiocb->iotag; |
9422 | } | |
da0436e9 JS |
9423 | else |
9424 | iabt->un.acxri.abortIoTag = icmd->ulpIoTag; | |
07951076 JS |
9425 | iabt->ulpLe = 1; |
9426 | iabt->ulpClass = icmd->ulpClass; | |
dea3101e | 9427 | |
5ffc266e JS |
9428 | /* ABTS WQE must go to the same WQ as the WQE to be aborted */ |
9429 | abtsiocbp->fcp_wqidx = cmdiocb->fcp_wqidx; | |
341af102 JS |
9430 | if (cmdiocb->iocb_flag & LPFC_IO_FCP) |
9431 | abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX; | |
5ffc266e | 9432 | |
2e0fef85 | 9433 | if (phba->link_state >= LPFC_LINK_UP) |
07951076 JS |
9434 | iabt->ulpCommand = CMD_ABORT_XRI_CN; |
9435 | else | |
9436 | iabt->ulpCommand = CMD_CLOSE_XRI_CN; | |
dea3101e | 9437 | |
07951076 | 9438 | abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl; |
5b8bd0c9 | 9439 | |
e8b62011 JS |
9440 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
9441 | "0339 Abort xri x%x, original iotag x%x, " | |
9442 | "abort cmd iotag x%x\n", | |
2a9bf3d0 | 9443 | iabt->un.acxri.abortIoTag, |
e8b62011 | 9444 | iabt->un.acxri.abortContextTag, |
2a9bf3d0 | 9445 | abtsiocbp->iotag); |
7e56aa25 JS |
9446 | |
9447 | if (phba->sli_rev == LPFC_SLI_REV4) { | |
9448 | /* Note: both hbalock and ring_lock need to be set here */ | |
9449 | spin_lock_irqsave(&pring->ring_lock, iflags); | |
9450 | retval = __lpfc_sli_issue_iocb(phba, pring->ringno, | |
9451 | abtsiocbp, 0); | |
9452 | spin_unlock_irqrestore(&pring->ring_lock, iflags); | |
9453 | } else { | |
9454 | retval = __lpfc_sli_issue_iocb(phba, pring->ringno, | |
9455 | abtsiocbp, 0); | |
9456 | } | |
dea3101e | 9457 | |
d7c255b2 JS |
9458 | if (retval) |
9459 | __lpfc_sli_release_iocbq(phba, abtsiocbp); | |
5af5eee7 JS |
9460 | |
9461 | /* | |
9462 | * Caller to this routine should check for IOCB_ERROR | |
9463 | * and handle it properly. This routine no longer removes | |
9464 | * iocb off txcmplq and call compl in case of IOCB_ERROR. | |
9465 | */ | |
9466 | return retval; | |
9467 | } | |
9468 | ||
9469 | /** | |
9470 | * lpfc_sli_issue_abort_iotag - Abort function for a command iocb | |
9471 | * @phba: Pointer to HBA context object. | |
9472 | * @pring: Pointer to driver SLI ring object. | |
9473 | * @cmdiocb: Pointer to driver command iocb object. | |
9474 | * | |
9475 | * This function issues an abort iocb for the provided command iocb. In case | |
9476 | * of unloading, the abort iocb will not be issued to commands on the ELS | |
9477 | * ring. Instead, the callback function shall be changed to those commands | |
9478 | * so that nothing happens when them finishes. This function is called with | |
9479 | * hbalock held. The function returns 0 when the command iocb is an abort | |
9480 | * request. | |
9481 | **/ | |
9482 | int | |
9483 | lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
9484 | struct lpfc_iocbq *cmdiocb) | |
9485 | { | |
9486 | struct lpfc_vport *vport = cmdiocb->vport; | |
9487 | int retval = IOCB_ERROR; | |
9488 | IOCB_t *icmd = NULL; | |
9489 | ||
9490 | /* | |
9491 | * There are certain command types we don't want to abort. And we | |
9492 | * don't want to abort commands that are already in the process of | |
9493 | * being aborted. | |
9494 | */ | |
9495 | icmd = &cmdiocb->iocb; | |
9496 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || | |
9497 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || | |
9498 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) | |
9499 | return 0; | |
9500 | ||
9501 | /* | |
9502 | * If we're unloading, don't abort iocb on the ELS ring, but change | |
9503 | * the callback so that nothing happens when it finishes. | |
9504 | */ | |
9505 | if ((vport->load_flag & FC_UNLOADING) && | |
9506 | (pring->ringno == LPFC_ELS_RING)) { | |
9507 | if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) | |
9508 | cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl; | |
9509 | else | |
9510 | cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl; | |
9511 | goto abort_iotag_exit; | |
9512 | } | |
9513 | ||
9514 | /* Now, we try to issue the abort to the cmdiocb out */ | |
9515 | retval = lpfc_sli_abort_iotag_issue(phba, pring, cmdiocb); | |
9516 | ||
07951076 | 9517 | abort_iotag_exit: |
2e0fef85 JS |
9518 | /* |
9519 | * Caller to this routine should check for IOCB_ERROR | |
9520 | * and handle it properly. This routine no longer removes | |
9521 | * iocb off txcmplq and call compl in case of IOCB_ERROR. | |
07951076 | 9522 | */ |
2e0fef85 | 9523 | return retval; |
dea3101e | 9524 | } |
9525 | ||
5af5eee7 JS |
9526 | /** |
9527 | * lpfc_sli_iocb_ring_abort - Unconditionally abort all iocbs on an iocb ring | |
9528 | * @phba: Pointer to HBA context object. | |
9529 | * @pring: Pointer to driver SLI ring object. | |
9530 | * | |
9531 | * This function aborts all iocbs in the given ring and frees all the iocb | |
9532 | * objects in txq. This function issues abort iocbs unconditionally for all | |
9533 | * the iocb commands in txcmplq. The iocbs in the txcmplq is not guaranteed | |
9534 | * to complete before the return of this function. The caller is not required | |
9535 | * to hold any locks. | |
9536 | **/ | |
9537 | static void | |
9538 | lpfc_sli_iocb_ring_abort(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) | |
9539 | { | |
9540 | LIST_HEAD(completions); | |
9541 | struct lpfc_iocbq *iocb, *next_iocb; | |
9542 | ||
9543 | if (pring->ringno == LPFC_ELS_RING) | |
9544 | lpfc_fabric_abort_hba(phba); | |
9545 | ||
9546 | spin_lock_irq(&phba->hbalock); | |
9547 | ||
9548 | /* Take off all the iocbs on txq for cancelling */ | |
9549 | list_splice_init(&pring->txq, &completions); | |
9550 | pring->txq_cnt = 0; | |
9551 | ||
9552 | /* Next issue ABTS for everything on the txcmplq */ | |
9553 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) | |
9554 | lpfc_sli_abort_iotag_issue(phba, pring, iocb); | |
9555 | ||
9556 | spin_unlock_irq(&phba->hbalock); | |
9557 | ||
9558 | /* Cancel all the IOCBs from the completions list */ | |
9559 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, | |
9560 | IOERR_SLI_ABORTED); | |
9561 | } | |
9562 | ||
9563 | /** | |
9564 | * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba. | |
9565 | * @phba: pointer to lpfc HBA data structure. | |
9566 | * | |
9567 | * This routine will abort all pending and outstanding iocbs to an HBA. | |
9568 | **/ | |
9569 | void | |
9570 | lpfc_sli_hba_iocb_abort(struct lpfc_hba *phba) | |
9571 | { | |
9572 | struct lpfc_sli *psli = &phba->sli; | |
9573 | struct lpfc_sli_ring *pring; | |
9574 | int i; | |
9575 | ||
9576 | for (i = 0; i < psli->num_rings; i++) { | |
9577 | pring = &psli->ring[i]; | |
9578 | lpfc_sli_iocb_ring_abort(phba, pring); | |
9579 | } | |
9580 | } | |
9581 | ||
e59058c4 | 9582 | /** |
3621a710 | 9583 | * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN |
e59058c4 JS |
9584 | * @iocbq: Pointer to driver iocb object. |
9585 | * @vport: Pointer to driver virtual port object. | |
9586 | * @tgt_id: SCSI ID of the target. | |
9587 | * @lun_id: LUN ID of the scsi device. | |
9588 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST | |
9589 | * | |
3621a710 | 9590 | * This function acts as an iocb filter for functions which abort or count |
e59058c4 JS |
9591 | * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return |
9592 | * 0 if the filtering criteria is met for the given iocb and will return | |
9593 | * 1 if the filtering criteria is not met. | |
9594 | * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the | |
9595 | * given iocb is for the SCSI device specified by vport, tgt_id and | |
9596 | * lun_id parameter. | |
9597 | * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the | |
9598 | * given iocb is for the SCSI target specified by vport and tgt_id | |
9599 | * parameters. | |
9600 | * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the | |
9601 | * given iocb is for the SCSI host associated with the given vport. | |
9602 | * This function is called with no locks held. | |
9603 | **/ | |
dea3101e | 9604 | static int |
51ef4c26 JS |
9605 | lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport, |
9606 | uint16_t tgt_id, uint64_t lun_id, | |
0bd4ca25 | 9607 | lpfc_ctx_cmd ctx_cmd) |
dea3101e | 9608 | { |
0bd4ca25 | 9609 | struct lpfc_scsi_buf *lpfc_cmd; |
dea3101e | 9610 | int rc = 1; |
9611 | ||
0bd4ca25 JSEC |
9612 | if (!(iocbq->iocb_flag & LPFC_IO_FCP)) |
9613 | return rc; | |
9614 | ||
51ef4c26 JS |
9615 | if (iocbq->vport != vport) |
9616 | return rc; | |
9617 | ||
0bd4ca25 | 9618 | lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq); |
0bd4ca25 | 9619 | |
495a714c | 9620 | if (lpfc_cmd->pCmd == NULL) |
dea3101e | 9621 | return rc; |
9622 | ||
9623 | switch (ctx_cmd) { | |
9624 | case LPFC_CTX_LUN: | |
495a714c JS |
9625 | if ((lpfc_cmd->rdata->pnode) && |
9626 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) && | |
9627 | (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id)) | |
dea3101e | 9628 | rc = 0; |
9629 | break; | |
9630 | case LPFC_CTX_TGT: | |
495a714c JS |
9631 | if ((lpfc_cmd->rdata->pnode) && |
9632 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id)) | |
dea3101e | 9633 | rc = 0; |
9634 | break; | |
dea3101e | 9635 | case LPFC_CTX_HOST: |
9636 | rc = 0; | |
9637 | break; | |
9638 | default: | |
9639 | printk(KERN_ERR "%s: Unknown context cmd type, value %d\n", | |
cadbd4a5 | 9640 | __func__, ctx_cmd); |
dea3101e | 9641 | break; |
9642 | } | |
9643 | ||
9644 | return rc; | |
9645 | } | |
9646 | ||
e59058c4 | 9647 | /** |
3621a710 | 9648 | * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending |
e59058c4 JS |
9649 | * @vport: Pointer to virtual port. |
9650 | * @tgt_id: SCSI ID of the target. | |
9651 | * @lun_id: LUN ID of the scsi device. | |
9652 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. | |
9653 | * | |
9654 | * This function returns number of FCP commands pending for the vport. | |
9655 | * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP | |
9656 | * commands pending on the vport associated with SCSI device specified | |
9657 | * by tgt_id and lun_id parameters. | |
9658 | * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP | |
9659 | * commands pending on the vport associated with SCSI target specified | |
9660 | * by tgt_id parameter. | |
9661 | * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP | |
9662 | * commands pending on the vport. | |
9663 | * This function returns the number of iocbs which satisfy the filter. | |
9664 | * This function is called without any lock held. | |
9665 | **/ | |
dea3101e | 9666 | int |
51ef4c26 JS |
9667 | lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id, |
9668 | lpfc_ctx_cmd ctx_cmd) | |
dea3101e | 9669 | { |
51ef4c26 | 9670 | struct lpfc_hba *phba = vport->phba; |
0bd4ca25 JSEC |
9671 | struct lpfc_iocbq *iocbq; |
9672 | int sum, i; | |
dea3101e | 9673 | |
0bd4ca25 JSEC |
9674 | for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) { |
9675 | iocbq = phba->sli.iocbq_lookup[i]; | |
dea3101e | 9676 | |
51ef4c26 JS |
9677 | if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id, |
9678 | ctx_cmd) == 0) | |
0bd4ca25 | 9679 | sum++; |
dea3101e | 9680 | } |
0bd4ca25 | 9681 | |
dea3101e | 9682 | return sum; |
9683 | } | |
9684 | ||
e59058c4 | 9685 | /** |
3621a710 | 9686 | * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs |
e59058c4 JS |
9687 | * @phba: Pointer to HBA context object |
9688 | * @cmdiocb: Pointer to command iocb object. | |
9689 | * @rspiocb: Pointer to response iocb object. | |
9690 | * | |
9691 | * This function is called when an aborted FCP iocb completes. This | |
9692 | * function is called by the ring event handler with no lock held. | |
9693 | * This function frees the iocb. | |
9694 | **/ | |
5eb95af0 | 9695 | void |
2e0fef85 JS |
9696 | lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
9697 | struct lpfc_iocbq *rspiocb) | |
5eb95af0 | 9698 | { |
cb69f7de JS |
9699 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
9700 | "3096 ABORT_XRI_CN completing on xri x%x " | |
9701 | "original iotag x%x, abort cmd iotag x%x " | |
9702 | "status 0x%x, reason 0x%x\n", | |
9703 | cmdiocb->iocb.un.acxri.abortContextTag, | |
9704 | cmdiocb->iocb.un.acxri.abortIoTag, | |
9705 | cmdiocb->iotag, rspiocb->iocb.ulpStatus, | |
9706 | rspiocb->iocb.un.ulpWord[4]); | |
604a3e30 | 9707 | lpfc_sli_release_iocbq(phba, cmdiocb); |
5eb95af0 JSEC |
9708 | return; |
9709 | } | |
9710 | ||
e59058c4 | 9711 | /** |
3621a710 | 9712 | * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN |
e59058c4 JS |
9713 | * @vport: Pointer to virtual port. |
9714 | * @pring: Pointer to driver SLI ring object. | |
9715 | * @tgt_id: SCSI ID of the target. | |
9716 | * @lun_id: LUN ID of the scsi device. | |
9717 | * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. | |
9718 | * | |
9719 | * This function sends an abort command for every SCSI command | |
9720 | * associated with the given virtual port pending on the ring | |
9721 | * filtered by lpfc_sli_validate_fcp_iocb function. | |
9722 | * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the | |
9723 | * FCP iocbs associated with lun specified by tgt_id and lun_id | |
9724 | * parameters | |
9725 | * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the | |
9726 | * FCP iocbs associated with SCSI target specified by tgt_id parameter. | |
9727 | * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all | |
9728 | * FCP iocbs associated with virtual port. | |
9729 | * This function returns number of iocbs it failed to abort. | |
9730 | * This function is called with no locks held. | |
9731 | **/ | |
dea3101e | 9732 | int |
51ef4c26 JS |
9733 | lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring, |
9734 | uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd) | |
dea3101e | 9735 | { |
51ef4c26 | 9736 | struct lpfc_hba *phba = vport->phba; |
0bd4ca25 JSEC |
9737 | struct lpfc_iocbq *iocbq; |
9738 | struct lpfc_iocbq *abtsiocb; | |
dea3101e | 9739 | IOCB_t *cmd = NULL; |
dea3101e | 9740 | int errcnt = 0, ret_val = 0; |
0bd4ca25 | 9741 | int i; |
dea3101e | 9742 | |
0bd4ca25 JSEC |
9743 | for (i = 1; i <= phba->sli.last_iotag; i++) { |
9744 | iocbq = phba->sli.iocbq_lookup[i]; | |
dea3101e | 9745 | |
51ef4c26 | 9746 | if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id, |
2e0fef85 | 9747 | abort_cmd) != 0) |
dea3101e | 9748 | continue; |
9749 | ||
9750 | /* issue ABTS for this IOCB based on iotag */ | |
0bd4ca25 | 9751 | abtsiocb = lpfc_sli_get_iocbq(phba); |
dea3101e | 9752 | if (abtsiocb == NULL) { |
9753 | errcnt++; | |
9754 | continue; | |
9755 | } | |
dea3101e | 9756 | |
0bd4ca25 | 9757 | cmd = &iocbq->iocb; |
dea3101e | 9758 | abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS; |
9759 | abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext; | |
da0436e9 JS |
9760 | if (phba->sli_rev == LPFC_SLI_REV4) |
9761 | abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag; | |
9762 | else | |
9763 | abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag; | |
dea3101e | 9764 | abtsiocb->iocb.ulpLe = 1; |
9765 | abtsiocb->iocb.ulpClass = cmd->ulpClass; | |
2e0fef85 | 9766 | abtsiocb->vport = phba->pport; |
dea3101e | 9767 | |
5ffc266e JS |
9768 | /* ABTS WQE must go to the same WQ as the WQE to be aborted */ |
9769 | abtsiocb->fcp_wqidx = iocbq->fcp_wqidx; | |
341af102 JS |
9770 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
9771 | abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX; | |
5ffc266e | 9772 | |
2e0fef85 | 9773 | if (lpfc_is_link_up(phba)) |
dea3101e | 9774 | abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN; |
9775 | else | |
9776 | abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN; | |
9777 | ||
5eb95af0 JSEC |
9778 | /* Setup callback routine and issue the command. */ |
9779 | abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; | |
da0436e9 JS |
9780 | ret_val = lpfc_sli_issue_iocb(phba, pring->ringno, |
9781 | abtsiocb, 0); | |
dea3101e | 9782 | if (ret_val == IOCB_ERROR) { |
604a3e30 | 9783 | lpfc_sli_release_iocbq(phba, abtsiocb); |
dea3101e | 9784 | errcnt++; |
9785 | continue; | |
9786 | } | |
9787 | } | |
9788 | ||
9789 | return errcnt; | |
9790 | } | |
9791 | ||
e59058c4 | 9792 | /** |
3621a710 | 9793 | * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler |
e59058c4 JS |
9794 | * @phba: Pointer to HBA context object. |
9795 | * @cmdiocbq: Pointer to command iocb. | |
9796 | * @rspiocbq: Pointer to response iocb. | |
9797 | * | |
9798 | * This function is the completion handler for iocbs issued using | |
9799 | * lpfc_sli_issue_iocb_wait function. This function is called by the | |
9800 | * ring event handler function without any lock held. This function | |
9801 | * can be called from both worker thread context and interrupt | |
9802 | * context. This function also can be called from other thread which | |
9803 | * cleans up the SLI layer objects. | |
9804 | * This function copy the contents of the response iocb to the | |
9805 | * response iocb memory object provided by the caller of | |
9806 | * lpfc_sli_issue_iocb_wait and then wakes up the thread which | |
9807 | * sleeps for the iocb completion. | |
9808 | **/ | |
68876920 JSEC |
9809 | static void |
9810 | lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba, | |
9811 | struct lpfc_iocbq *cmdiocbq, | |
9812 | struct lpfc_iocbq *rspiocbq) | |
dea3101e | 9813 | { |
68876920 JSEC |
9814 | wait_queue_head_t *pdone_q; |
9815 | unsigned long iflags; | |
0f65ff68 | 9816 | struct lpfc_scsi_buf *lpfc_cmd; |
dea3101e | 9817 | |
2e0fef85 | 9818 | spin_lock_irqsave(&phba->hbalock, iflags); |
68876920 JSEC |
9819 | cmdiocbq->iocb_flag |= LPFC_IO_WAKE; |
9820 | if (cmdiocbq->context2 && rspiocbq) | |
9821 | memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb, | |
9822 | &rspiocbq->iocb, sizeof(IOCB_t)); | |
9823 | ||
0f65ff68 JS |
9824 | /* Set the exchange busy flag for task management commands */ |
9825 | if ((cmdiocbq->iocb_flag & LPFC_IO_FCP) && | |
9826 | !(cmdiocbq->iocb_flag & LPFC_IO_LIBDFC)) { | |
9827 | lpfc_cmd = container_of(cmdiocbq, struct lpfc_scsi_buf, | |
9828 | cur_iocbq); | |
9829 | lpfc_cmd->exch_busy = rspiocbq->iocb_flag & LPFC_EXCHANGE_BUSY; | |
9830 | } | |
9831 | ||
68876920 | 9832 | pdone_q = cmdiocbq->context_un.wait_queue; |
68876920 JSEC |
9833 | if (pdone_q) |
9834 | wake_up(pdone_q); | |
858c9f6c | 9835 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
dea3101e | 9836 | return; |
9837 | } | |
9838 | ||
d11e31dd JS |
9839 | /** |
9840 | * lpfc_chk_iocb_flg - Test IOCB flag with lock held. | |
9841 | * @phba: Pointer to HBA context object.. | |
9842 | * @piocbq: Pointer to command iocb. | |
9843 | * @flag: Flag to test. | |
9844 | * | |
9845 | * This routine grabs the hbalock and then test the iocb_flag to | |
9846 | * see if the passed in flag is set. | |
9847 | * Returns: | |
9848 | * 1 if flag is set. | |
9849 | * 0 if flag is not set. | |
9850 | **/ | |
9851 | static int | |
9852 | lpfc_chk_iocb_flg(struct lpfc_hba *phba, | |
9853 | struct lpfc_iocbq *piocbq, uint32_t flag) | |
9854 | { | |
9855 | unsigned long iflags; | |
9856 | int ret; | |
9857 | ||
9858 | spin_lock_irqsave(&phba->hbalock, iflags); | |
9859 | ret = piocbq->iocb_flag & flag; | |
9860 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
9861 | return ret; | |
9862 | ||
9863 | } | |
9864 | ||
e59058c4 | 9865 | /** |
3621a710 | 9866 | * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands |
e59058c4 JS |
9867 | * @phba: Pointer to HBA context object.. |
9868 | * @pring: Pointer to sli ring. | |
9869 | * @piocb: Pointer to command iocb. | |
9870 | * @prspiocbq: Pointer to response iocb. | |
9871 | * @timeout: Timeout in number of seconds. | |
9872 | * | |
9873 | * This function issues the iocb to firmware and waits for the | |
9874 | * iocb to complete. If the iocb command is not | |
9875 | * completed within timeout seconds, it returns IOCB_TIMEDOUT. | |
9876 | * Caller should not free the iocb resources if this function | |
9877 | * returns IOCB_TIMEDOUT. | |
9878 | * The function waits for the iocb completion using an | |
9879 | * non-interruptible wait. | |
9880 | * This function will sleep while waiting for iocb completion. | |
9881 | * So, this function should not be called from any context which | |
9882 | * does not allow sleeping. Due to the same reason, this function | |
9883 | * cannot be called with interrupt disabled. | |
9884 | * This function assumes that the iocb completions occur while | |
9885 | * this function sleep. So, this function cannot be called from | |
9886 | * the thread which process iocb completion for this ring. | |
9887 | * This function clears the iocb_flag of the iocb object before | |
9888 | * issuing the iocb and the iocb completion handler sets this | |
9889 | * flag and wakes this thread when the iocb completes. | |
9890 | * The contents of the response iocb will be copied to prspiocbq | |
9891 | * by the completion handler when the command completes. | |
9892 | * This function returns IOCB_SUCCESS when success. | |
9893 | * This function is called with no lock held. | |
9894 | **/ | |
dea3101e | 9895 | int |
2e0fef85 | 9896 | lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba, |
da0436e9 | 9897 | uint32_t ring_number, |
2e0fef85 JS |
9898 | struct lpfc_iocbq *piocb, |
9899 | struct lpfc_iocbq *prspiocbq, | |
68876920 | 9900 | uint32_t timeout) |
dea3101e | 9901 | { |
7259f0d0 | 9902 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
68876920 JSEC |
9903 | long timeleft, timeout_req = 0; |
9904 | int retval = IOCB_SUCCESS; | |
875fbdfe | 9905 | uint32_t creg_val; |
2a9bf3d0 | 9906 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
dea3101e | 9907 | /* |
68876920 JSEC |
9908 | * If the caller has provided a response iocbq buffer, then context2 |
9909 | * is NULL or its an error. | |
dea3101e | 9910 | */ |
68876920 JSEC |
9911 | if (prspiocbq) { |
9912 | if (piocb->context2) | |
9913 | return IOCB_ERROR; | |
9914 | piocb->context2 = prspiocbq; | |
dea3101e | 9915 | } |
9916 | ||
68876920 JSEC |
9917 | piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait; |
9918 | piocb->context_un.wait_queue = &done_q; | |
9919 | piocb->iocb_flag &= ~LPFC_IO_WAKE; | |
dea3101e | 9920 | |
875fbdfe | 9921 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
9940b97b JS |
9922 | if (lpfc_readl(phba->HCregaddr, &creg_val)) |
9923 | return IOCB_ERROR; | |
875fbdfe JSEC |
9924 | creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING); |
9925 | writel(creg_val, phba->HCregaddr); | |
9926 | readl(phba->HCregaddr); /* flush */ | |
9927 | } | |
9928 | ||
2a9bf3d0 JS |
9929 | retval = lpfc_sli_issue_iocb(phba, ring_number, piocb, |
9930 | SLI_IOCB_RET_IOCB); | |
68876920 JSEC |
9931 | if (retval == IOCB_SUCCESS) { |
9932 | timeout_req = timeout * HZ; | |
68876920 | 9933 | timeleft = wait_event_timeout(done_q, |
d11e31dd | 9934 | lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE), |
68876920 | 9935 | timeout_req); |
dea3101e | 9936 | |
7054a606 JS |
9937 | if (piocb->iocb_flag & LPFC_IO_WAKE) { |
9938 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
e8b62011 | 9939 | "0331 IOCB wake signaled\n"); |
7054a606 | 9940 | } else if (timeleft == 0) { |
68876920 | 9941 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
e8b62011 JS |
9942 | "0338 IOCB wait timeout error - no " |
9943 | "wake response Data x%x\n", timeout); | |
68876920 | 9944 | retval = IOCB_TIMEDOUT; |
7054a606 | 9945 | } else { |
68876920 | 9946 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
e8b62011 JS |
9947 | "0330 IOCB wake NOT set, " |
9948 | "Data x%x x%lx\n", | |
68876920 JSEC |
9949 | timeout, (timeleft / jiffies)); |
9950 | retval = IOCB_TIMEDOUT; | |
dea3101e | 9951 | } |
2a9bf3d0 JS |
9952 | } else if (retval == IOCB_BUSY) { |
9953 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
9954 | "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n", | |
9955 | phba->iocb_cnt, pring->txq_cnt, pring->txcmplq_cnt); | |
9956 | return retval; | |
68876920 JSEC |
9957 | } else { |
9958 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
d7c255b2 | 9959 | "0332 IOCB wait issue failed, Data x%x\n", |
e8b62011 | 9960 | retval); |
68876920 | 9961 | retval = IOCB_ERROR; |
dea3101e | 9962 | } |
9963 | ||
875fbdfe | 9964 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
9940b97b JS |
9965 | if (lpfc_readl(phba->HCregaddr, &creg_val)) |
9966 | return IOCB_ERROR; | |
875fbdfe JSEC |
9967 | creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING); |
9968 | writel(creg_val, phba->HCregaddr); | |
9969 | readl(phba->HCregaddr); /* flush */ | |
9970 | } | |
9971 | ||
68876920 JSEC |
9972 | if (prspiocbq) |
9973 | piocb->context2 = NULL; | |
9974 | ||
9975 | piocb->context_un.wait_queue = NULL; | |
9976 | piocb->iocb_cmpl = NULL; | |
dea3101e | 9977 | return retval; |
9978 | } | |
68876920 | 9979 | |
e59058c4 | 9980 | /** |
3621a710 | 9981 | * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox |
e59058c4 JS |
9982 | * @phba: Pointer to HBA context object. |
9983 | * @pmboxq: Pointer to driver mailbox object. | |
9984 | * @timeout: Timeout in number of seconds. | |
9985 | * | |
9986 | * This function issues the mailbox to firmware and waits for the | |
9987 | * mailbox command to complete. If the mailbox command is not | |
9988 | * completed within timeout seconds, it returns MBX_TIMEOUT. | |
9989 | * The function waits for the mailbox completion using an | |
9990 | * interruptible wait. If the thread is woken up due to a | |
9991 | * signal, MBX_TIMEOUT error is returned to the caller. Caller | |
9992 | * should not free the mailbox resources, if this function returns | |
9993 | * MBX_TIMEOUT. | |
9994 | * This function will sleep while waiting for mailbox completion. | |
9995 | * So, this function should not be called from any context which | |
9996 | * does not allow sleeping. Due to the same reason, this function | |
9997 | * cannot be called with interrupt disabled. | |
9998 | * This function assumes that the mailbox completion occurs while | |
9999 | * this function sleep. So, this function cannot be called from | |
10000 | * the worker thread which processes mailbox completion. | |
10001 | * This function is called in the context of HBA management | |
10002 | * applications. | |
10003 | * This function returns MBX_SUCCESS when successful. | |
10004 | * This function is called with no lock held. | |
10005 | **/ | |
dea3101e | 10006 | int |
2e0fef85 | 10007 | lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq, |
dea3101e | 10008 | uint32_t timeout) |
10009 | { | |
7259f0d0 | 10010 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
dea3101e | 10011 | int retval; |
858c9f6c | 10012 | unsigned long flag; |
dea3101e | 10013 | |
10014 | /* The caller must leave context1 empty. */ | |
98c9ea5c | 10015 | if (pmboxq->context1) |
2e0fef85 | 10016 | return MBX_NOT_FINISHED; |
dea3101e | 10017 | |
495a714c | 10018 | pmboxq->mbox_flag &= ~LPFC_MBX_WAKE; |
dea3101e | 10019 | /* setup wake call as IOCB callback */ |
10020 | pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait; | |
10021 | /* setup context field to pass wait_queue pointer to wake function */ | |
10022 | pmboxq->context1 = &done_q; | |
10023 | ||
dea3101e | 10024 | /* now issue the command */ |
10025 | retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT); | |
dea3101e | 10026 | if (retval == MBX_BUSY || retval == MBX_SUCCESS) { |
7054a606 JS |
10027 | wait_event_interruptible_timeout(done_q, |
10028 | pmboxq->mbox_flag & LPFC_MBX_WAKE, | |
10029 | timeout * HZ); | |
10030 | ||
858c9f6c | 10031 | spin_lock_irqsave(&phba->hbalock, flag); |
dea3101e | 10032 | pmboxq->context1 = NULL; |
7054a606 JS |
10033 | /* |
10034 | * if LPFC_MBX_WAKE flag is set the mailbox is completed | |
10035 | * else do not free the resources. | |
10036 | */ | |
d7c47992 | 10037 | if (pmboxq->mbox_flag & LPFC_MBX_WAKE) { |
dea3101e | 10038 | retval = MBX_SUCCESS; |
d7c47992 JS |
10039 | lpfc_sli4_swap_str(phba, pmboxq); |
10040 | } else { | |
7054a606 | 10041 | retval = MBX_TIMEOUT; |
858c9f6c JS |
10042 | pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
10043 | } | |
10044 | spin_unlock_irqrestore(&phba->hbalock, flag); | |
dea3101e | 10045 | } |
10046 | ||
dea3101e | 10047 | return retval; |
10048 | } | |
10049 | ||
e59058c4 | 10050 | /** |
3772a991 | 10051 | * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system |
e59058c4 JS |
10052 | * @phba: Pointer to HBA context. |
10053 | * | |
3772a991 JS |
10054 | * This function is called to shutdown the driver's mailbox sub-system. |
10055 | * It first marks the mailbox sub-system is in a block state to prevent | |
10056 | * the asynchronous mailbox command from issued off the pending mailbox | |
10057 | * command queue. If the mailbox command sub-system shutdown is due to | |
10058 | * HBA error conditions such as EEH or ERATT, this routine shall invoke | |
10059 | * the mailbox sub-system flush routine to forcefully bring down the | |
10060 | * mailbox sub-system. Otherwise, if it is due to normal condition (such | |
10061 | * as with offline or HBA function reset), this routine will wait for the | |
10062 | * outstanding mailbox command to complete before invoking the mailbox | |
10063 | * sub-system flush routine to gracefully bring down mailbox sub-system. | |
e59058c4 | 10064 | **/ |
3772a991 | 10065 | void |
618a5230 | 10066 | lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba, int mbx_action) |
b4c02652 | 10067 | { |
3772a991 | 10068 | struct lpfc_sli *psli = &phba->sli; |
3772a991 | 10069 | unsigned long timeout; |
b4c02652 | 10070 | |
618a5230 JS |
10071 | if (mbx_action == LPFC_MBX_NO_WAIT) { |
10072 | /* delay 100ms for port state */ | |
10073 | msleep(100); | |
10074 | lpfc_sli_mbox_sys_flush(phba); | |
10075 | return; | |
10076 | } | |
a183a15f | 10077 | timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies; |
d7069f09 | 10078 | |
3772a991 JS |
10079 | spin_lock_irq(&phba->hbalock); |
10080 | psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; | |
b4c02652 | 10081 | |
3772a991 | 10082 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
3772a991 JS |
10083 | /* Determine how long we might wait for the active mailbox |
10084 | * command to be gracefully completed by firmware. | |
10085 | */ | |
a183a15f JS |
10086 | if (phba->sli.mbox_active) |
10087 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, | |
10088 | phba->sli.mbox_active) * | |
10089 | 1000) + jiffies; | |
10090 | spin_unlock_irq(&phba->hbalock); | |
10091 | ||
3772a991 JS |
10092 | while (phba->sli.mbox_active) { |
10093 | /* Check active mailbox complete status every 2ms */ | |
10094 | msleep(2); | |
10095 | if (time_after(jiffies, timeout)) | |
10096 | /* Timeout, let the mailbox flush routine to | |
10097 | * forcefully release active mailbox command | |
10098 | */ | |
10099 | break; | |
10100 | } | |
d7069f09 JS |
10101 | } else |
10102 | spin_unlock_irq(&phba->hbalock); | |
10103 | ||
3772a991 JS |
10104 | lpfc_sli_mbox_sys_flush(phba); |
10105 | } | |
ed957684 | 10106 | |
3772a991 JS |
10107 | /** |
10108 | * lpfc_sli_eratt_read - read sli-3 error attention events | |
10109 | * @phba: Pointer to HBA context. | |
10110 | * | |
10111 | * This function is called to read the SLI3 device error attention registers | |
10112 | * for possible error attention events. The caller must hold the hostlock | |
10113 | * with spin_lock_irq(). | |
10114 | * | |
25985edc | 10115 | * This function returns 1 when there is Error Attention in the Host Attention |
3772a991 JS |
10116 | * Register and returns 0 otherwise. |
10117 | **/ | |
10118 | static int | |
10119 | lpfc_sli_eratt_read(struct lpfc_hba *phba) | |
10120 | { | |
10121 | uint32_t ha_copy; | |
b4c02652 | 10122 | |
3772a991 | 10123 | /* Read chip Host Attention (HA) register */ |
9940b97b JS |
10124 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
10125 | goto unplug_err; | |
10126 | ||
3772a991 JS |
10127 | if (ha_copy & HA_ERATT) { |
10128 | /* Read host status register to retrieve error event */ | |
9940b97b JS |
10129 | if (lpfc_sli_read_hs(phba)) |
10130 | goto unplug_err; | |
b4c02652 | 10131 | |
3772a991 JS |
10132 | /* Check if there is a deferred error condition is active */ |
10133 | if ((HS_FFER1 & phba->work_hs) && | |
10134 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | | |
dcf2a4e0 | 10135 | HS_FFER6 | HS_FFER7 | HS_FFER8) & phba->work_hs)) { |
3772a991 | 10136 | phba->hba_flag |= DEFER_ERATT; |
3772a991 JS |
10137 | /* Clear all interrupt enable conditions */ |
10138 | writel(0, phba->HCregaddr); | |
10139 | readl(phba->HCregaddr); | |
10140 | } | |
10141 | ||
10142 | /* Set the driver HA work bitmap */ | |
3772a991 JS |
10143 | phba->work_ha |= HA_ERATT; |
10144 | /* Indicate polling handles this ERATT */ | |
10145 | phba->hba_flag |= HBA_ERATT_HANDLED; | |
3772a991 JS |
10146 | return 1; |
10147 | } | |
10148 | return 0; | |
9940b97b JS |
10149 | |
10150 | unplug_err: | |
10151 | /* Set the driver HS work bitmap */ | |
10152 | phba->work_hs |= UNPLUG_ERR; | |
10153 | /* Set the driver HA work bitmap */ | |
10154 | phba->work_ha |= HA_ERATT; | |
10155 | /* Indicate polling handles this ERATT */ | |
10156 | phba->hba_flag |= HBA_ERATT_HANDLED; | |
10157 | return 1; | |
b4c02652 JS |
10158 | } |
10159 | ||
da0436e9 JS |
10160 | /** |
10161 | * lpfc_sli4_eratt_read - read sli-4 error attention events | |
10162 | * @phba: Pointer to HBA context. | |
10163 | * | |
10164 | * This function is called to read the SLI4 device error attention registers | |
10165 | * for possible error attention events. The caller must hold the hostlock | |
10166 | * with spin_lock_irq(). | |
10167 | * | |
25985edc | 10168 | * This function returns 1 when there is Error Attention in the Host Attention |
da0436e9 JS |
10169 | * Register and returns 0 otherwise. |
10170 | **/ | |
10171 | static int | |
10172 | lpfc_sli4_eratt_read(struct lpfc_hba *phba) | |
10173 | { | |
10174 | uint32_t uerr_sta_hi, uerr_sta_lo; | |
2fcee4bf JS |
10175 | uint32_t if_type, portsmphr; |
10176 | struct lpfc_register portstat_reg; | |
da0436e9 | 10177 | |
2fcee4bf JS |
10178 | /* |
10179 | * For now, use the SLI4 device internal unrecoverable error | |
da0436e9 JS |
10180 | * registers for error attention. This can be changed later. |
10181 | */ | |
2fcee4bf JS |
10182 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
10183 | switch (if_type) { | |
10184 | case LPFC_SLI_INTF_IF_TYPE_0: | |
9940b97b JS |
10185 | if (lpfc_readl(phba->sli4_hba.u.if_type0.UERRLOregaddr, |
10186 | &uerr_sta_lo) || | |
10187 | lpfc_readl(phba->sli4_hba.u.if_type0.UERRHIregaddr, | |
10188 | &uerr_sta_hi)) { | |
10189 | phba->work_hs |= UNPLUG_ERR; | |
10190 | phba->work_ha |= HA_ERATT; | |
10191 | phba->hba_flag |= HBA_ERATT_HANDLED; | |
10192 | return 1; | |
10193 | } | |
2fcee4bf JS |
10194 | if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) || |
10195 | (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) { | |
10196 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
10197 | "1423 HBA Unrecoverable error: " | |
10198 | "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, " | |
10199 | "ue_mask_lo_reg=0x%x, " | |
10200 | "ue_mask_hi_reg=0x%x\n", | |
10201 | uerr_sta_lo, uerr_sta_hi, | |
10202 | phba->sli4_hba.ue_mask_lo, | |
10203 | phba->sli4_hba.ue_mask_hi); | |
10204 | phba->work_status[0] = uerr_sta_lo; | |
10205 | phba->work_status[1] = uerr_sta_hi; | |
10206 | phba->work_ha |= HA_ERATT; | |
10207 | phba->hba_flag |= HBA_ERATT_HANDLED; | |
10208 | return 1; | |
10209 | } | |
10210 | break; | |
10211 | case LPFC_SLI_INTF_IF_TYPE_2: | |
9940b97b JS |
10212 | if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr, |
10213 | &portstat_reg.word0) || | |
10214 | lpfc_readl(phba->sli4_hba.PSMPHRregaddr, | |
10215 | &portsmphr)){ | |
10216 | phba->work_hs |= UNPLUG_ERR; | |
10217 | phba->work_ha |= HA_ERATT; | |
10218 | phba->hba_flag |= HBA_ERATT_HANDLED; | |
10219 | return 1; | |
10220 | } | |
2fcee4bf JS |
10221 | if (bf_get(lpfc_sliport_status_err, &portstat_reg)) { |
10222 | phba->work_status[0] = | |
10223 | readl(phba->sli4_hba.u.if_type2.ERR1regaddr); | |
10224 | phba->work_status[1] = | |
10225 | readl(phba->sli4_hba.u.if_type2.ERR2regaddr); | |
10226 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
2e90f4b5 | 10227 | "2885 Port Status Event: " |
2fcee4bf JS |
10228 | "port status reg 0x%x, " |
10229 | "port smphr reg 0x%x, " | |
10230 | "error 1=0x%x, error 2=0x%x\n", | |
10231 | portstat_reg.word0, | |
10232 | portsmphr, | |
10233 | phba->work_status[0], | |
10234 | phba->work_status[1]); | |
10235 | phba->work_ha |= HA_ERATT; | |
10236 | phba->hba_flag |= HBA_ERATT_HANDLED; | |
10237 | return 1; | |
10238 | } | |
10239 | break; | |
10240 | case LPFC_SLI_INTF_IF_TYPE_1: | |
10241 | default: | |
a747c9ce | 10242 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
2fcee4bf JS |
10243 | "2886 HBA Error Attention on unsupported " |
10244 | "if type %d.", if_type); | |
a747c9ce | 10245 | return 1; |
da0436e9 | 10246 | } |
2fcee4bf | 10247 | |
da0436e9 JS |
10248 | return 0; |
10249 | } | |
10250 | ||
e59058c4 | 10251 | /** |
3621a710 | 10252 | * lpfc_sli_check_eratt - check error attention events |
9399627f JS |
10253 | * @phba: Pointer to HBA context. |
10254 | * | |
3772a991 | 10255 | * This function is called from timer soft interrupt context to check HBA's |
9399627f JS |
10256 | * error attention register bit for error attention events. |
10257 | * | |
25985edc | 10258 | * This function returns 1 when there is Error Attention in the Host Attention |
9399627f JS |
10259 | * Register and returns 0 otherwise. |
10260 | **/ | |
10261 | int | |
10262 | lpfc_sli_check_eratt(struct lpfc_hba *phba) | |
10263 | { | |
10264 | uint32_t ha_copy; | |
10265 | ||
10266 | /* If somebody is waiting to handle an eratt, don't process it | |
10267 | * here. The brdkill function will do this. | |
10268 | */ | |
10269 | if (phba->link_flag & LS_IGNORE_ERATT) | |
10270 | return 0; | |
10271 | ||
10272 | /* Check if interrupt handler handles this ERATT */ | |
10273 | spin_lock_irq(&phba->hbalock); | |
10274 | if (phba->hba_flag & HBA_ERATT_HANDLED) { | |
10275 | /* Interrupt handler has handled ERATT */ | |
10276 | spin_unlock_irq(&phba->hbalock); | |
10277 | return 0; | |
10278 | } | |
10279 | ||
a257bf90 JS |
10280 | /* |
10281 | * If there is deferred error attention, do not check for error | |
10282 | * attention | |
10283 | */ | |
10284 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { | |
10285 | spin_unlock_irq(&phba->hbalock); | |
10286 | return 0; | |
10287 | } | |
10288 | ||
3772a991 JS |
10289 | /* If PCI channel is offline, don't process it */ |
10290 | if (unlikely(pci_channel_offline(phba->pcidev))) { | |
9399627f | 10291 | spin_unlock_irq(&phba->hbalock); |
3772a991 JS |
10292 | return 0; |
10293 | } | |
10294 | ||
10295 | switch (phba->sli_rev) { | |
10296 | case LPFC_SLI_REV2: | |
10297 | case LPFC_SLI_REV3: | |
10298 | /* Read chip Host Attention (HA) register */ | |
10299 | ha_copy = lpfc_sli_eratt_read(phba); | |
10300 | break; | |
da0436e9 | 10301 | case LPFC_SLI_REV4: |
2fcee4bf | 10302 | /* Read device Uncoverable Error (UERR) registers */ |
da0436e9 JS |
10303 | ha_copy = lpfc_sli4_eratt_read(phba); |
10304 | break; | |
3772a991 JS |
10305 | default: |
10306 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
10307 | "0299 Invalid SLI revision (%d)\n", | |
10308 | phba->sli_rev); | |
10309 | ha_copy = 0; | |
10310 | break; | |
9399627f JS |
10311 | } |
10312 | spin_unlock_irq(&phba->hbalock); | |
3772a991 JS |
10313 | |
10314 | return ha_copy; | |
10315 | } | |
10316 | ||
10317 | /** | |
10318 | * lpfc_intr_state_check - Check device state for interrupt handling | |
10319 | * @phba: Pointer to HBA context. | |
10320 | * | |
10321 | * This inline routine checks whether a device or its PCI slot is in a state | |
10322 | * that the interrupt should be handled. | |
10323 | * | |
10324 | * This function returns 0 if the device or the PCI slot is in a state that | |
10325 | * interrupt should be handled, otherwise -EIO. | |
10326 | */ | |
10327 | static inline int | |
10328 | lpfc_intr_state_check(struct lpfc_hba *phba) | |
10329 | { | |
10330 | /* If the pci channel is offline, ignore all the interrupts */ | |
10331 | if (unlikely(pci_channel_offline(phba->pcidev))) | |
10332 | return -EIO; | |
10333 | ||
10334 | /* Update device level interrupt statistics */ | |
10335 | phba->sli.slistat.sli_intr++; | |
10336 | ||
10337 | /* Ignore all interrupts during initialization. */ | |
10338 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) | |
10339 | return -EIO; | |
10340 | ||
9399627f JS |
10341 | return 0; |
10342 | } | |
10343 | ||
10344 | /** | |
3772a991 | 10345 | * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device |
e59058c4 JS |
10346 | * @irq: Interrupt number. |
10347 | * @dev_id: The device context pointer. | |
10348 | * | |
9399627f | 10349 | * This function is directly called from the PCI layer as an interrupt |
3772a991 JS |
10350 | * service routine when device with SLI-3 interface spec is enabled with |
10351 | * MSI-X multi-message interrupt mode and there are slow-path events in | |
10352 | * the HBA. However, when the device is enabled with either MSI or Pin-IRQ | |
10353 | * interrupt mode, this function is called as part of the device-level | |
10354 | * interrupt handler. When the PCI slot is in error recovery or the HBA | |
10355 | * is undergoing initialization, the interrupt handler will not process | |
10356 | * the interrupt. The link attention and ELS ring attention events are | |
10357 | * handled by the worker thread. The interrupt handler signals the worker | |
10358 | * thread and returns for these events. This function is called without | |
10359 | * any lock held. It gets the hbalock to access and update SLI data | |
9399627f JS |
10360 | * structures. |
10361 | * | |
10362 | * This function returns IRQ_HANDLED when interrupt is handled else it | |
10363 | * returns IRQ_NONE. | |
e59058c4 | 10364 | **/ |
dea3101e | 10365 | irqreturn_t |
3772a991 | 10366 | lpfc_sli_sp_intr_handler(int irq, void *dev_id) |
dea3101e | 10367 | { |
2e0fef85 | 10368 | struct lpfc_hba *phba; |
a747c9ce | 10369 | uint32_t ha_copy, hc_copy; |
dea3101e | 10370 | uint32_t work_ha_copy; |
10371 | unsigned long status; | |
5b75da2f | 10372 | unsigned long iflag; |
dea3101e | 10373 | uint32_t control; |
10374 | ||
92d7f7b0 | 10375 | MAILBOX_t *mbox, *pmbox; |
858c9f6c JS |
10376 | struct lpfc_vport *vport; |
10377 | struct lpfc_nodelist *ndlp; | |
10378 | struct lpfc_dmabuf *mp; | |
92d7f7b0 JS |
10379 | LPFC_MBOXQ_t *pmb; |
10380 | int rc; | |
10381 | ||
dea3101e | 10382 | /* |
10383 | * Get the driver's phba structure from the dev_id and | |
10384 | * assume the HBA is not interrupting. | |
10385 | */ | |
9399627f | 10386 | phba = (struct lpfc_hba *)dev_id; |
dea3101e | 10387 | |
10388 | if (unlikely(!phba)) | |
10389 | return IRQ_NONE; | |
10390 | ||
dea3101e | 10391 | /* |
9399627f JS |
10392 | * Stuff needs to be attented to when this function is invoked as an |
10393 | * individual interrupt handler in MSI-X multi-message interrupt mode | |
dea3101e | 10394 | */ |
9399627f | 10395 | if (phba->intr_type == MSIX) { |
3772a991 JS |
10396 | /* Check device state for handling interrupt */ |
10397 | if (lpfc_intr_state_check(phba)) | |
9399627f JS |
10398 | return IRQ_NONE; |
10399 | /* Need to read HA REG for slow-path events */ | |
5b75da2f | 10400 | spin_lock_irqsave(&phba->hbalock, iflag); |
9940b97b JS |
10401 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
10402 | goto unplug_error; | |
9399627f JS |
10403 | /* If somebody is waiting to handle an eratt don't process it |
10404 | * here. The brdkill function will do this. | |
10405 | */ | |
10406 | if (phba->link_flag & LS_IGNORE_ERATT) | |
10407 | ha_copy &= ~HA_ERATT; | |
10408 | /* Check the need for handling ERATT in interrupt handler */ | |
10409 | if (ha_copy & HA_ERATT) { | |
10410 | if (phba->hba_flag & HBA_ERATT_HANDLED) | |
10411 | /* ERATT polling has handled ERATT */ | |
10412 | ha_copy &= ~HA_ERATT; | |
10413 | else | |
10414 | /* Indicate interrupt handler handles ERATT */ | |
10415 | phba->hba_flag |= HBA_ERATT_HANDLED; | |
10416 | } | |
a257bf90 JS |
10417 | |
10418 | /* | |
10419 | * If there is deferred error attention, do not check for any | |
10420 | * interrupt. | |
10421 | */ | |
10422 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { | |
3772a991 | 10423 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
a257bf90 JS |
10424 | return IRQ_NONE; |
10425 | } | |
10426 | ||
9399627f | 10427 | /* Clear up only attention source related to slow-path */ |
9940b97b JS |
10428 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) |
10429 | goto unplug_error; | |
10430 | ||
a747c9ce JS |
10431 | writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA | |
10432 | HC_LAINT_ENA | HC_ERINT_ENA), | |
10433 | phba->HCregaddr); | |
9399627f JS |
10434 | writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)), |
10435 | phba->HAregaddr); | |
a747c9ce | 10436 | writel(hc_copy, phba->HCregaddr); |
9399627f | 10437 | readl(phba->HAregaddr); /* flush */ |
5b75da2f | 10438 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
9399627f JS |
10439 | } else |
10440 | ha_copy = phba->ha_copy; | |
dea3101e | 10441 | |
dea3101e | 10442 | work_ha_copy = ha_copy & phba->work_ha_mask; |
10443 | ||
9399627f | 10444 | if (work_ha_copy) { |
dea3101e | 10445 | if (work_ha_copy & HA_LATT) { |
10446 | if (phba->sli.sli_flag & LPFC_PROCESS_LA) { | |
10447 | /* | |
10448 | * Turn off Link Attention interrupts | |
10449 | * until CLEAR_LA done | |
10450 | */ | |
5b75da2f | 10451 | spin_lock_irqsave(&phba->hbalock, iflag); |
dea3101e | 10452 | phba->sli.sli_flag &= ~LPFC_PROCESS_LA; |
9940b97b JS |
10453 | if (lpfc_readl(phba->HCregaddr, &control)) |
10454 | goto unplug_error; | |
dea3101e | 10455 | control &= ~HC_LAINT_ENA; |
10456 | writel(control, phba->HCregaddr); | |
10457 | readl(phba->HCregaddr); /* flush */ | |
5b75da2f | 10458 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
dea3101e | 10459 | } |
10460 | else | |
10461 | work_ha_copy &= ~HA_LATT; | |
10462 | } | |
10463 | ||
9399627f | 10464 | if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) { |
858c9f6c JS |
10465 | /* |
10466 | * Turn off Slow Rings interrupts, LPFC_ELS_RING is | |
10467 | * the only slow ring. | |
10468 | */ | |
10469 | status = (work_ha_copy & | |
10470 | (HA_RXMASK << (4*LPFC_ELS_RING))); | |
10471 | status >>= (4*LPFC_ELS_RING); | |
10472 | if (status & HA_RXMASK) { | |
5b75da2f | 10473 | spin_lock_irqsave(&phba->hbalock, iflag); |
9940b97b JS |
10474 | if (lpfc_readl(phba->HCregaddr, &control)) |
10475 | goto unplug_error; | |
a58cbd52 JS |
10476 | |
10477 | lpfc_debugfs_slow_ring_trc(phba, | |
10478 | "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x", | |
10479 | control, status, | |
10480 | (uint32_t)phba->sli.slistat.sli_intr); | |
10481 | ||
858c9f6c | 10482 | if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) { |
a58cbd52 JS |
10483 | lpfc_debugfs_slow_ring_trc(phba, |
10484 | "ISR Disable ring:" | |
10485 | "pwork:x%x hawork:x%x wait:x%x", | |
10486 | phba->work_ha, work_ha_copy, | |
10487 | (uint32_t)((unsigned long) | |
5e9d9b82 | 10488 | &phba->work_waitq)); |
a58cbd52 | 10489 | |
858c9f6c JS |
10490 | control &= |
10491 | ~(HC_R0INT_ENA << LPFC_ELS_RING); | |
dea3101e | 10492 | writel(control, phba->HCregaddr); |
10493 | readl(phba->HCregaddr); /* flush */ | |
dea3101e | 10494 | } |
a58cbd52 JS |
10495 | else { |
10496 | lpfc_debugfs_slow_ring_trc(phba, | |
10497 | "ISR slow ring: pwork:" | |
10498 | "x%x hawork:x%x wait:x%x", | |
10499 | phba->work_ha, work_ha_copy, | |
10500 | (uint32_t)((unsigned long) | |
5e9d9b82 | 10501 | &phba->work_waitq)); |
a58cbd52 | 10502 | } |
5b75da2f | 10503 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
dea3101e | 10504 | } |
10505 | } | |
5b75da2f | 10506 | spin_lock_irqsave(&phba->hbalock, iflag); |
a257bf90 | 10507 | if (work_ha_copy & HA_ERATT) { |
9940b97b JS |
10508 | if (lpfc_sli_read_hs(phba)) |
10509 | goto unplug_error; | |
a257bf90 JS |
10510 | /* |
10511 | * Check if there is a deferred error condition | |
10512 | * is active | |
10513 | */ | |
10514 | if ((HS_FFER1 & phba->work_hs) && | |
10515 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | | |
dcf2a4e0 JS |
10516 | HS_FFER6 | HS_FFER7 | HS_FFER8) & |
10517 | phba->work_hs)) { | |
a257bf90 JS |
10518 | phba->hba_flag |= DEFER_ERATT; |
10519 | /* Clear all interrupt enable conditions */ | |
10520 | writel(0, phba->HCregaddr); | |
10521 | readl(phba->HCregaddr); | |
10522 | } | |
10523 | } | |
10524 | ||
9399627f | 10525 | if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) { |
92d7f7b0 | 10526 | pmb = phba->sli.mbox_active; |
04c68496 | 10527 | pmbox = &pmb->u.mb; |
34b02dcd | 10528 | mbox = phba->mbox; |
858c9f6c | 10529 | vport = pmb->vport; |
92d7f7b0 JS |
10530 | |
10531 | /* First check out the status word */ | |
10532 | lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t)); | |
10533 | if (pmbox->mbxOwner != OWN_HOST) { | |
5b75da2f | 10534 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
92d7f7b0 JS |
10535 | /* |
10536 | * Stray Mailbox Interrupt, mbxCommand <cmd> | |
10537 | * mbxStatus <status> | |
10538 | */ | |
09372820 | 10539 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
92d7f7b0 | 10540 | LOG_SLI, |
e8b62011 | 10541 | "(%d):0304 Stray Mailbox " |
92d7f7b0 JS |
10542 | "Interrupt mbxCommand x%x " |
10543 | "mbxStatus x%x\n", | |
e8b62011 | 10544 | (vport ? vport->vpi : 0), |
92d7f7b0 JS |
10545 | pmbox->mbxCommand, |
10546 | pmbox->mbxStatus); | |
09372820 JS |
10547 | /* clear mailbox attention bit */ |
10548 | work_ha_copy &= ~HA_MBATT; | |
10549 | } else { | |
97eab634 | 10550 | phba->sli.mbox_active = NULL; |
5b75da2f | 10551 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
09372820 JS |
10552 | phba->last_completion_time = jiffies; |
10553 | del_timer(&phba->sli.mbox_tmo); | |
09372820 JS |
10554 | if (pmb->mbox_cmpl) { |
10555 | lpfc_sli_pcimem_bcopy(mbox, pmbox, | |
10556 | MAILBOX_CMD_SIZE); | |
7a470277 JS |
10557 | if (pmb->out_ext_byte_len && |
10558 | pmb->context2) | |
10559 | lpfc_sli_pcimem_bcopy( | |
10560 | phba->mbox_ext, | |
10561 | pmb->context2, | |
10562 | pmb->out_ext_byte_len); | |
09372820 JS |
10563 | } |
10564 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { | |
10565 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; | |
10566 | ||
10567 | lpfc_debugfs_disc_trc(vport, | |
10568 | LPFC_DISC_TRC_MBOX_VPORT, | |
10569 | "MBOX dflt rpi: : " | |
10570 | "status:x%x rpi:x%x", | |
10571 | (uint32_t)pmbox->mbxStatus, | |
10572 | pmbox->un.varWords[0], 0); | |
10573 | ||
10574 | if (!pmbox->mbxStatus) { | |
10575 | mp = (struct lpfc_dmabuf *) | |
10576 | (pmb->context1); | |
10577 | ndlp = (struct lpfc_nodelist *) | |
10578 | pmb->context2; | |
10579 | ||
10580 | /* Reg_LOGIN of dflt RPI was | |
10581 | * successful. new lets get | |
10582 | * rid of the RPI using the | |
10583 | * same mbox buffer. | |
10584 | */ | |
10585 | lpfc_unreg_login(phba, | |
10586 | vport->vpi, | |
10587 | pmbox->un.varWords[0], | |
10588 | pmb); | |
10589 | pmb->mbox_cmpl = | |
10590 | lpfc_mbx_cmpl_dflt_rpi; | |
10591 | pmb->context1 = mp; | |
10592 | pmb->context2 = ndlp; | |
10593 | pmb->vport = vport; | |
58da1ffb JS |
10594 | rc = lpfc_sli_issue_mbox(phba, |
10595 | pmb, | |
10596 | MBX_NOWAIT); | |
10597 | if (rc != MBX_BUSY) | |
10598 | lpfc_printf_log(phba, | |
10599 | KERN_ERR, | |
10600 | LOG_MBOX | LOG_SLI, | |
d7c255b2 | 10601 | "0350 rc should have" |
6a9c52cf | 10602 | "been MBX_BUSY\n"); |
3772a991 JS |
10603 | if (rc != MBX_NOT_FINISHED) |
10604 | goto send_current_mbox; | |
09372820 | 10605 | } |
858c9f6c | 10606 | } |
5b75da2f JS |
10607 | spin_lock_irqsave( |
10608 | &phba->pport->work_port_lock, | |
10609 | iflag); | |
09372820 JS |
10610 | phba->pport->work_port_events &= |
10611 | ~WORKER_MBOX_TMO; | |
5b75da2f JS |
10612 | spin_unlock_irqrestore( |
10613 | &phba->pport->work_port_lock, | |
10614 | iflag); | |
09372820 | 10615 | lpfc_mbox_cmpl_put(phba, pmb); |
858c9f6c | 10616 | } |
97eab634 | 10617 | } else |
5b75da2f | 10618 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
9399627f | 10619 | |
92d7f7b0 JS |
10620 | if ((work_ha_copy & HA_MBATT) && |
10621 | (phba->sli.mbox_active == NULL)) { | |
858c9f6c | 10622 | send_current_mbox: |
92d7f7b0 | 10623 | /* Process next mailbox command if there is one */ |
58da1ffb JS |
10624 | do { |
10625 | rc = lpfc_sli_issue_mbox(phba, NULL, | |
10626 | MBX_NOWAIT); | |
10627 | } while (rc == MBX_NOT_FINISHED); | |
10628 | if (rc != MBX_SUCCESS) | |
10629 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | | |
10630 | LOG_SLI, "0349 rc should be " | |
6a9c52cf | 10631 | "MBX_SUCCESS\n"); |
92d7f7b0 JS |
10632 | } |
10633 | ||
5b75da2f | 10634 | spin_lock_irqsave(&phba->hbalock, iflag); |
dea3101e | 10635 | phba->work_ha |= work_ha_copy; |
5b75da2f | 10636 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
5e9d9b82 | 10637 | lpfc_worker_wake_up(phba); |
dea3101e | 10638 | } |
9399627f | 10639 | return IRQ_HANDLED; |
9940b97b JS |
10640 | unplug_error: |
10641 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
10642 | return IRQ_HANDLED; | |
dea3101e | 10643 | |
3772a991 | 10644 | } /* lpfc_sli_sp_intr_handler */ |
9399627f JS |
10645 | |
10646 | /** | |
3772a991 | 10647 | * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device. |
9399627f JS |
10648 | * @irq: Interrupt number. |
10649 | * @dev_id: The device context pointer. | |
10650 | * | |
10651 | * This function is directly called from the PCI layer as an interrupt | |
3772a991 JS |
10652 | * service routine when device with SLI-3 interface spec is enabled with |
10653 | * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB | |
10654 | * ring event in the HBA. However, when the device is enabled with either | |
10655 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the | |
10656 | * device-level interrupt handler. When the PCI slot is in error recovery | |
10657 | * or the HBA is undergoing initialization, the interrupt handler will not | |
10658 | * process the interrupt. The SCSI FCP fast-path ring event are handled in | |
10659 | * the intrrupt context. This function is called without any lock held. | |
10660 | * It gets the hbalock to access and update SLI data structures. | |
9399627f JS |
10661 | * |
10662 | * This function returns IRQ_HANDLED when interrupt is handled else it | |
10663 | * returns IRQ_NONE. | |
10664 | **/ | |
10665 | irqreturn_t | |
3772a991 | 10666 | lpfc_sli_fp_intr_handler(int irq, void *dev_id) |
9399627f JS |
10667 | { |
10668 | struct lpfc_hba *phba; | |
10669 | uint32_t ha_copy; | |
10670 | unsigned long status; | |
5b75da2f | 10671 | unsigned long iflag; |
9399627f JS |
10672 | |
10673 | /* Get the driver's phba structure from the dev_id and | |
10674 | * assume the HBA is not interrupting. | |
10675 | */ | |
10676 | phba = (struct lpfc_hba *) dev_id; | |
10677 | ||
10678 | if (unlikely(!phba)) | |
10679 | return IRQ_NONE; | |
10680 | ||
10681 | /* | |
10682 | * Stuff needs to be attented to when this function is invoked as an | |
10683 | * individual interrupt handler in MSI-X multi-message interrupt mode | |
10684 | */ | |
10685 | if (phba->intr_type == MSIX) { | |
3772a991 JS |
10686 | /* Check device state for handling interrupt */ |
10687 | if (lpfc_intr_state_check(phba)) | |
9399627f JS |
10688 | return IRQ_NONE; |
10689 | /* Need to read HA REG for FCP ring and other ring events */ | |
9940b97b JS |
10690 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
10691 | return IRQ_HANDLED; | |
9399627f | 10692 | /* Clear up only attention source related to fast-path */ |
5b75da2f | 10693 | spin_lock_irqsave(&phba->hbalock, iflag); |
a257bf90 JS |
10694 | /* |
10695 | * If there is deferred error attention, do not check for | |
10696 | * any interrupt. | |
10697 | */ | |
10698 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { | |
3772a991 | 10699 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
a257bf90 JS |
10700 | return IRQ_NONE; |
10701 | } | |
9399627f JS |
10702 | writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)), |
10703 | phba->HAregaddr); | |
10704 | readl(phba->HAregaddr); /* flush */ | |
5b75da2f | 10705 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
9399627f JS |
10706 | } else |
10707 | ha_copy = phba->ha_copy; | |
dea3101e | 10708 | |
10709 | /* | |
9399627f | 10710 | * Process all events on FCP ring. Take the optimized path for FCP IO. |
dea3101e | 10711 | */ |
9399627f JS |
10712 | ha_copy &= ~(phba->work_ha_mask); |
10713 | ||
10714 | status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); | |
dea3101e | 10715 | status >>= (4*LPFC_FCP_RING); |
858c9f6c | 10716 | if (status & HA_RXMASK) |
dea3101e | 10717 | lpfc_sli_handle_fast_ring_event(phba, |
10718 | &phba->sli.ring[LPFC_FCP_RING], | |
10719 | status); | |
a4bc3379 JS |
10720 | |
10721 | if (phba->cfg_multi_ring_support == 2) { | |
10722 | /* | |
9399627f JS |
10723 | * Process all events on extra ring. Take the optimized path |
10724 | * for extra ring IO. | |
a4bc3379 | 10725 | */ |
9399627f | 10726 | status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); |
a4bc3379 | 10727 | status >>= (4*LPFC_EXTRA_RING); |
858c9f6c | 10728 | if (status & HA_RXMASK) { |
a4bc3379 JS |
10729 | lpfc_sli_handle_fast_ring_event(phba, |
10730 | &phba->sli.ring[LPFC_EXTRA_RING], | |
10731 | status); | |
10732 | } | |
10733 | } | |
dea3101e | 10734 | return IRQ_HANDLED; |
3772a991 | 10735 | } /* lpfc_sli_fp_intr_handler */ |
9399627f JS |
10736 | |
10737 | /** | |
3772a991 | 10738 | * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device |
9399627f JS |
10739 | * @irq: Interrupt number. |
10740 | * @dev_id: The device context pointer. | |
10741 | * | |
3772a991 JS |
10742 | * This function is the HBA device-level interrupt handler to device with |
10743 | * SLI-3 interface spec, called from the PCI layer when either MSI or | |
10744 | * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which | |
10745 | * requires driver attention. This function invokes the slow-path interrupt | |
10746 | * attention handling function and fast-path interrupt attention handling | |
10747 | * function in turn to process the relevant HBA attention events. This | |
10748 | * function is called without any lock held. It gets the hbalock to access | |
10749 | * and update SLI data structures. | |
9399627f JS |
10750 | * |
10751 | * This function returns IRQ_HANDLED when interrupt is handled, else it | |
10752 | * returns IRQ_NONE. | |
10753 | **/ | |
10754 | irqreturn_t | |
3772a991 | 10755 | lpfc_sli_intr_handler(int irq, void *dev_id) |
9399627f JS |
10756 | { |
10757 | struct lpfc_hba *phba; | |
10758 | irqreturn_t sp_irq_rc, fp_irq_rc; | |
10759 | unsigned long status1, status2; | |
a747c9ce | 10760 | uint32_t hc_copy; |
9399627f JS |
10761 | |
10762 | /* | |
10763 | * Get the driver's phba structure from the dev_id and | |
10764 | * assume the HBA is not interrupting. | |
10765 | */ | |
10766 | phba = (struct lpfc_hba *) dev_id; | |
10767 | ||
10768 | if (unlikely(!phba)) | |
10769 | return IRQ_NONE; | |
10770 | ||
3772a991 JS |
10771 | /* Check device state for handling interrupt */ |
10772 | if (lpfc_intr_state_check(phba)) | |
9399627f JS |
10773 | return IRQ_NONE; |
10774 | ||
10775 | spin_lock(&phba->hbalock); | |
9940b97b JS |
10776 | if (lpfc_readl(phba->HAregaddr, &phba->ha_copy)) { |
10777 | spin_unlock(&phba->hbalock); | |
10778 | return IRQ_HANDLED; | |
10779 | } | |
10780 | ||
9399627f JS |
10781 | if (unlikely(!phba->ha_copy)) { |
10782 | spin_unlock(&phba->hbalock); | |
10783 | return IRQ_NONE; | |
10784 | } else if (phba->ha_copy & HA_ERATT) { | |
10785 | if (phba->hba_flag & HBA_ERATT_HANDLED) | |
10786 | /* ERATT polling has handled ERATT */ | |
10787 | phba->ha_copy &= ~HA_ERATT; | |
10788 | else | |
10789 | /* Indicate interrupt handler handles ERATT */ | |
10790 | phba->hba_flag |= HBA_ERATT_HANDLED; | |
10791 | } | |
10792 | ||
a257bf90 JS |
10793 | /* |
10794 | * If there is deferred error attention, do not check for any interrupt. | |
10795 | */ | |
10796 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { | |
ec21b3b0 | 10797 | spin_unlock(&phba->hbalock); |
a257bf90 JS |
10798 | return IRQ_NONE; |
10799 | } | |
10800 | ||
9399627f | 10801 | /* Clear attention sources except link and error attentions */ |
9940b97b JS |
10802 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) { |
10803 | spin_unlock(&phba->hbalock); | |
10804 | return IRQ_HANDLED; | |
10805 | } | |
a747c9ce JS |
10806 | writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA |
10807 | | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA), | |
10808 | phba->HCregaddr); | |
9399627f | 10809 | writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr); |
a747c9ce | 10810 | writel(hc_copy, phba->HCregaddr); |
9399627f JS |
10811 | readl(phba->HAregaddr); /* flush */ |
10812 | spin_unlock(&phba->hbalock); | |
10813 | ||
10814 | /* | |
10815 | * Invokes slow-path host attention interrupt handling as appropriate. | |
10816 | */ | |
10817 | ||
10818 | /* status of events with mailbox and link attention */ | |
10819 | status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT); | |
10820 | ||
10821 | /* status of events with ELS ring */ | |
10822 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING))); | |
10823 | status2 >>= (4*LPFC_ELS_RING); | |
10824 | ||
10825 | if (status1 || (status2 & HA_RXMASK)) | |
3772a991 | 10826 | sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id); |
9399627f JS |
10827 | else |
10828 | sp_irq_rc = IRQ_NONE; | |
10829 | ||
10830 | /* | |
10831 | * Invoke fast-path host attention interrupt handling as appropriate. | |
10832 | */ | |
10833 | ||
10834 | /* status of events with FCP ring */ | |
10835 | status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); | |
10836 | status1 >>= (4*LPFC_FCP_RING); | |
10837 | ||
10838 | /* status of events with extra ring */ | |
10839 | if (phba->cfg_multi_ring_support == 2) { | |
10840 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); | |
10841 | status2 >>= (4*LPFC_EXTRA_RING); | |
10842 | } else | |
10843 | status2 = 0; | |
10844 | ||
10845 | if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK)) | |
3772a991 | 10846 | fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id); |
9399627f JS |
10847 | else |
10848 | fp_irq_rc = IRQ_NONE; | |
dea3101e | 10849 | |
9399627f JS |
10850 | /* Return device-level interrupt handling status */ |
10851 | return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc; | |
3772a991 | 10852 | } /* lpfc_sli_intr_handler */ |
4f774513 JS |
10853 | |
10854 | /** | |
10855 | * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event | |
10856 | * @phba: pointer to lpfc hba data structure. | |
10857 | * | |
10858 | * This routine is invoked by the worker thread to process all the pending | |
10859 | * SLI4 FCP abort XRI events. | |
10860 | **/ | |
10861 | void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *phba) | |
10862 | { | |
10863 | struct lpfc_cq_event *cq_event; | |
10864 | ||
10865 | /* First, declare the fcp xri abort event has been handled */ | |
10866 | spin_lock_irq(&phba->hbalock); | |
10867 | phba->hba_flag &= ~FCP_XRI_ABORT_EVENT; | |
10868 | spin_unlock_irq(&phba->hbalock); | |
10869 | /* Now, handle all the fcp xri abort events */ | |
10870 | while (!list_empty(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue)) { | |
10871 | /* Get the first event from the head of the event queue */ | |
10872 | spin_lock_irq(&phba->hbalock); | |
10873 | list_remove_head(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue, | |
10874 | cq_event, struct lpfc_cq_event, list); | |
10875 | spin_unlock_irq(&phba->hbalock); | |
10876 | /* Notify aborted XRI for FCP work queue */ | |
10877 | lpfc_sli4_fcp_xri_aborted(phba, &cq_event->cqe.wcqe_axri); | |
10878 | /* Free the event processed back to the free pool */ | |
10879 | lpfc_sli4_cq_event_release(phba, cq_event); | |
10880 | } | |
10881 | } | |
10882 | ||
10883 | /** | |
10884 | * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event | |
10885 | * @phba: pointer to lpfc hba data structure. | |
10886 | * | |
10887 | * This routine is invoked by the worker thread to process all the pending | |
10888 | * SLI4 els abort xri events. | |
10889 | **/ | |
10890 | void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba) | |
10891 | { | |
10892 | struct lpfc_cq_event *cq_event; | |
10893 | ||
10894 | /* First, declare the els xri abort event has been handled */ | |
10895 | spin_lock_irq(&phba->hbalock); | |
10896 | phba->hba_flag &= ~ELS_XRI_ABORT_EVENT; | |
10897 | spin_unlock_irq(&phba->hbalock); | |
10898 | /* Now, handle all the els xri abort events */ | |
10899 | while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) { | |
10900 | /* Get the first event from the head of the event queue */ | |
10901 | spin_lock_irq(&phba->hbalock); | |
10902 | list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue, | |
10903 | cq_event, struct lpfc_cq_event, list); | |
10904 | spin_unlock_irq(&phba->hbalock); | |
10905 | /* Notify aborted XRI for ELS work queue */ | |
10906 | lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri); | |
10907 | /* Free the event processed back to the free pool */ | |
10908 | lpfc_sli4_cq_event_release(phba, cq_event); | |
10909 | } | |
10910 | } | |
10911 | ||
341af102 JS |
10912 | /** |
10913 | * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn | |
10914 | * @phba: pointer to lpfc hba data structure | |
10915 | * @pIocbIn: pointer to the rspiocbq | |
10916 | * @pIocbOut: pointer to the cmdiocbq | |
10917 | * @wcqe: pointer to the complete wcqe | |
10918 | * | |
10919 | * This routine transfers the fields of a command iocbq to a response iocbq | |
10920 | * by copying all the IOCB fields from command iocbq and transferring the | |
10921 | * completion status information from the complete wcqe. | |
10922 | **/ | |
4f774513 | 10923 | static void |
341af102 JS |
10924 | lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba, |
10925 | struct lpfc_iocbq *pIocbIn, | |
4f774513 JS |
10926 | struct lpfc_iocbq *pIocbOut, |
10927 | struct lpfc_wcqe_complete *wcqe) | |
10928 | { | |
341af102 | 10929 | unsigned long iflags; |
acd6859b | 10930 | uint32_t status; |
4f774513 JS |
10931 | size_t offset = offsetof(struct lpfc_iocbq, iocb); |
10932 | ||
10933 | memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset, | |
10934 | sizeof(struct lpfc_iocbq) - offset); | |
4f774513 | 10935 | /* Map WCQE parameters into irspiocb parameters */ |
acd6859b JS |
10936 | status = bf_get(lpfc_wcqe_c_status, wcqe); |
10937 | pIocbIn->iocb.ulpStatus = (status & LPFC_IOCB_STATUS_MASK); | |
4f774513 JS |
10938 | if (pIocbOut->iocb_flag & LPFC_IO_FCP) |
10939 | if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR) | |
10940 | pIocbIn->iocb.un.fcpi.fcpi_parm = | |
10941 | pIocbOut->iocb.un.fcpi.fcpi_parm - | |
10942 | wcqe->total_data_placed; | |
10943 | else | |
10944 | pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter; | |
695a814e | 10945 | else { |
4f774513 | 10946 | pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter; |
695a814e JS |
10947 | pIocbIn->iocb.un.genreq64.bdl.bdeSize = wcqe->total_data_placed; |
10948 | } | |
341af102 | 10949 | |
acd6859b JS |
10950 | /* Convert BG errors for completion status */ |
10951 | if (status == CQE_STATUS_DI_ERROR) { | |
10952 | pIocbIn->iocb.ulpStatus = IOSTAT_LOCAL_REJECT; | |
10953 | ||
10954 | if (bf_get(lpfc_wcqe_c_bg_edir, wcqe)) | |
10955 | pIocbIn->iocb.un.ulpWord[4] = IOERR_RX_DMA_FAILED; | |
10956 | else | |
10957 | pIocbIn->iocb.un.ulpWord[4] = IOERR_TX_DMA_FAILED; | |
10958 | ||
10959 | pIocbIn->iocb.unsli3.sli3_bg.bgstat = 0; | |
10960 | if (bf_get(lpfc_wcqe_c_bg_ge, wcqe)) /* Guard Check failed */ | |
10961 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= | |
10962 | BGS_GUARD_ERR_MASK; | |
10963 | if (bf_get(lpfc_wcqe_c_bg_ae, wcqe)) /* App Tag Check failed */ | |
10964 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= | |
10965 | BGS_APPTAG_ERR_MASK; | |
10966 | if (bf_get(lpfc_wcqe_c_bg_re, wcqe)) /* Ref Tag Check failed */ | |
10967 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= | |
10968 | BGS_REFTAG_ERR_MASK; | |
10969 | ||
10970 | /* Check to see if there was any good data before the error */ | |
10971 | if (bf_get(lpfc_wcqe_c_bg_tdpv, wcqe)) { | |
10972 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= | |
10973 | BGS_HI_WATER_MARK_PRESENT_MASK; | |
10974 | pIocbIn->iocb.unsli3.sli3_bg.bghm = | |
10975 | wcqe->total_data_placed; | |
10976 | } | |
10977 | ||
10978 | /* | |
10979 | * Set ALL the error bits to indicate we don't know what | |
10980 | * type of error it is. | |
10981 | */ | |
10982 | if (!pIocbIn->iocb.unsli3.sli3_bg.bgstat) | |
10983 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= | |
10984 | (BGS_REFTAG_ERR_MASK | BGS_APPTAG_ERR_MASK | | |
10985 | BGS_GUARD_ERR_MASK); | |
10986 | } | |
10987 | ||
341af102 JS |
10988 | /* Pick up HBA exchange busy condition */ |
10989 | if (bf_get(lpfc_wcqe_c_xb, wcqe)) { | |
10990 | spin_lock_irqsave(&phba->hbalock, iflags); | |
10991 | pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY; | |
10992 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
10993 | } | |
4f774513 JS |
10994 | } |
10995 | ||
45ed1190 JS |
10996 | /** |
10997 | * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe | |
10998 | * @phba: Pointer to HBA context object. | |
10999 | * @wcqe: Pointer to work-queue completion queue entry. | |
11000 | * | |
11001 | * This routine handles an ELS work-queue completion event and construct | |
11002 | * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common | |
11003 | * discovery engine to handle. | |
11004 | * | |
11005 | * Return: Pointer to the receive IOCBQ, NULL otherwise. | |
11006 | **/ | |
11007 | static struct lpfc_iocbq * | |
11008 | lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba, | |
11009 | struct lpfc_iocbq *irspiocbq) | |
11010 | { | |
11011 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; | |
11012 | struct lpfc_iocbq *cmdiocbq; | |
11013 | struct lpfc_wcqe_complete *wcqe; | |
11014 | unsigned long iflags; | |
11015 | ||
11016 | wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl; | |
7e56aa25 | 11017 | spin_lock_irqsave(&pring->ring_lock, iflags); |
45ed1190 JS |
11018 | pring->stats.iocb_event++; |
11019 | /* Look up the ELS command IOCB and create pseudo response IOCB */ | |
11020 | cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring, | |
11021 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); | |
7e56aa25 | 11022 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
45ed1190 JS |
11023 | |
11024 | if (unlikely(!cmdiocbq)) { | |
11025 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
11026 | "0386 ELS complete with no corresponding " | |
11027 | "cmdiocb: iotag (%d)\n", | |
11028 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); | |
11029 | lpfc_sli_release_iocbq(phba, irspiocbq); | |
11030 | return NULL; | |
11031 | } | |
11032 | ||
11033 | /* Fake the irspiocbq and copy necessary response information */ | |
341af102 | 11034 | lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe); |
45ed1190 JS |
11035 | |
11036 | return irspiocbq; | |
11037 | } | |
11038 | ||
04c68496 JS |
11039 | /** |
11040 | * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event | |
11041 | * @phba: Pointer to HBA context object. | |
11042 | * @cqe: Pointer to mailbox completion queue entry. | |
11043 | * | |
11044 | * This routine process a mailbox completion queue entry with asynchrous | |
11045 | * event. | |
11046 | * | |
11047 | * Return: true if work posted to worker thread, otherwise false. | |
11048 | **/ | |
11049 | static bool | |
11050 | lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe) | |
11051 | { | |
11052 | struct lpfc_cq_event *cq_event; | |
11053 | unsigned long iflags; | |
11054 | ||
11055 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
11056 | "0392 Async Event: word0:x%x, word1:x%x, " | |
11057 | "word2:x%x, word3:x%x\n", mcqe->word0, | |
11058 | mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer); | |
11059 | ||
11060 | /* Allocate a new internal CQ_EVENT entry */ | |
11061 | cq_event = lpfc_sli4_cq_event_alloc(phba); | |
11062 | if (!cq_event) { | |
11063 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
11064 | "0394 Failed to allocate CQ_EVENT entry\n"); | |
11065 | return false; | |
11066 | } | |
11067 | ||
11068 | /* Move the CQE into an asynchronous event entry */ | |
11069 | memcpy(&cq_event->cqe, mcqe, sizeof(struct lpfc_mcqe)); | |
11070 | spin_lock_irqsave(&phba->hbalock, iflags); | |
11071 | list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue); | |
11072 | /* Set the async event flag */ | |
11073 | phba->hba_flag |= ASYNC_EVENT; | |
11074 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
11075 | ||
11076 | return true; | |
11077 | } | |
11078 | ||
11079 | /** | |
11080 | * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event | |
11081 | * @phba: Pointer to HBA context object. | |
11082 | * @cqe: Pointer to mailbox completion queue entry. | |
11083 | * | |
11084 | * This routine process a mailbox completion queue entry with mailbox | |
11085 | * completion event. | |
11086 | * | |
11087 | * Return: true if work posted to worker thread, otherwise false. | |
11088 | **/ | |
11089 | static bool | |
11090 | lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe) | |
11091 | { | |
11092 | uint32_t mcqe_status; | |
11093 | MAILBOX_t *mbox, *pmbox; | |
11094 | struct lpfc_mqe *mqe; | |
11095 | struct lpfc_vport *vport; | |
11096 | struct lpfc_nodelist *ndlp; | |
11097 | struct lpfc_dmabuf *mp; | |
11098 | unsigned long iflags; | |
11099 | LPFC_MBOXQ_t *pmb; | |
11100 | bool workposted = false; | |
11101 | int rc; | |
11102 | ||
11103 | /* If not a mailbox complete MCQE, out by checking mailbox consume */ | |
11104 | if (!bf_get(lpfc_trailer_completed, mcqe)) | |
11105 | goto out_no_mqe_complete; | |
11106 | ||
11107 | /* Get the reference to the active mbox command */ | |
11108 | spin_lock_irqsave(&phba->hbalock, iflags); | |
11109 | pmb = phba->sli.mbox_active; | |
11110 | if (unlikely(!pmb)) { | |
11111 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, | |
11112 | "1832 No pending MBOX command to handle\n"); | |
11113 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
11114 | goto out_no_mqe_complete; | |
11115 | } | |
11116 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
11117 | mqe = &pmb->u.mqe; | |
11118 | pmbox = (MAILBOX_t *)&pmb->u.mqe; | |
11119 | mbox = phba->mbox; | |
11120 | vport = pmb->vport; | |
11121 | ||
11122 | /* Reset heartbeat timer */ | |
11123 | phba->last_completion_time = jiffies; | |
11124 | del_timer(&phba->sli.mbox_tmo); | |
11125 | ||
11126 | /* Move mbox data to caller's mailbox region, do endian swapping */ | |
11127 | if (pmb->mbox_cmpl && mbox) | |
11128 | lpfc_sli_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe)); | |
04c68496 | 11129 | |
73d91e50 JS |
11130 | /* |
11131 | * For mcqe errors, conditionally move a modified error code to | |
11132 | * the mbox so that the error will not be missed. | |
11133 | */ | |
11134 | mcqe_status = bf_get(lpfc_mcqe_status, mcqe); | |
11135 | if (mcqe_status != MB_CQE_STATUS_SUCCESS) { | |
11136 | if (bf_get(lpfc_mqe_status, mqe) == MBX_SUCCESS) | |
11137 | bf_set(lpfc_mqe_status, mqe, | |
11138 | (LPFC_MBX_ERROR_RANGE | mcqe_status)); | |
11139 | } | |
04c68496 JS |
11140 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { |
11141 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; | |
11142 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT, | |
11143 | "MBOX dflt rpi: status:x%x rpi:x%x", | |
11144 | mcqe_status, | |
11145 | pmbox->un.varWords[0], 0); | |
11146 | if (mcqe_status == MB_CQE_STATUS_SUCCESS) { | |
11147 | mp = (struct lpfc_dmabuf *)(pmb->context1); | |
11148 | ndlp = (struct lpfc_nodelist *)pmb->context2; | |
11149 | /* Reg_LOGIN of dflt RPI was successful. Now lets get | |
11150 | * RID of the PPI using the same mbox buffer. | |
11151 | */ | |
11152 | lpfc_unreg_login(phba, vport->vpi, | |
11153 | pmbox->un.varWords[0], pmb); | |
11154 | pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; | |
11155 | pmb->context1 = mp; | |
11156 | pmb->context2 = ndlp; | |
11157 | pmb->vport = vport; | |
11158 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); | |
11159 | if (rc != MBX_BUSY) | |
11160 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | | |
11161 | LOG_SLI, "0385 rc should " | |
11162 | "have been MBX_BUSY\n"); | |
11163 | if (rc != MBX_NOT_FINISHED) | |
11164 | goto send_current_mbox; | |
11165 | } | |
11166 | } | |
11167 | spin_lock_irqsave(&phba->pport->work_port_lock, iflags); | |
11168 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; | |
11169 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); | |
11170 | ||
11171 | /* There is mailbox completion work to do */ | |
11172 | spin_lock_irqsave(&phba->hbalock, iflags); | |
11173 | __lpfc_mbox_cmpl_put(phba, pmb); | |
11174 | phba->work_ha |= HA_MBATT; | |
11175 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
11176 | workposted = true; | |
11177 | ||
11178 | send_current_mbox: | |
11179 | spin_lock_irqsave(&phba->hbalock, iflags); | |
11180 | /* Release the mailbox command posting token */ | |
11181 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
11182 | /* Setting active mailbox pointer need to be in sync to flag clear */ | |
11183 | phba->sli.mbox_active = NULL; | |
11184 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
11185 | /* Wake up worker thread to post the next pending mailbox command */ | |
11186 | lpfc_worker_wake_up(phba); | |
11187 | out_no_mqe_complete: | |
11188 | if (bf_get(lpfc_trailer_consumed, mcqe)) | |
11189 | lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq); | |
11190 | return workposted; | |
11191 | } | |
11192 | ||
11193 | /** | |
11194 | * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry | |
11195 | * @phba: Pointer to HBA context object. | |
11196 | * @cqe: Pointer to mailbox completion queue entry. | |
11197 | * | |
11198 | * This routine process a mailbox completion queue entry, it invokes the | |
11199 | * proper mailbox complete handling or asynchrous event handling routine | |
11200 | * according to the MCQE's async bit. | |
11201 | * | |
11202 | * Return: true if work posted to worker thread, otherwise false. | |
11203 | **/ | |
11204 | static bool | |
11205 | lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe) | |
11206 | { | |
11207 | struct lpfc_mcqe mcqe; | |
11208 | bool workposted; | |
11209 | ||
11210 | /* Copy the mailbox MCQE and convert endian order as needed */ | |
11211 | lpfc_sli_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe)); | |
11212 | ||
11213 | /* Invoke the proper event handling routine */ | |
11214 | if (!bf_get(lpfc_trailer_async, &mcqe)) | |
11215 | workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe); | |
11216 | else | |
11217 | workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe); | |
11218 | return workposted; | |
11219 | } | |
11220 | ||
4f774513 JS |
11221 | /** |
11222 | * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event | |
11223 | * @phba: Pointer to HBA context object. | |
2a76a283 | 11224 | * @cq: Pointer to associated CQ |
4f774513 JS |
11225 | * @wcqe: Pointer to work-queue completion queue entry. |
11226 | * | |
11227 | * This routine handles an ELS work-queue completion event. | |
11228 | * | |
11229 | * Return: true if work posted to worker thread, otherwise false. | |
11230 | **/ | |
11231 | static bool | |
2a76a283 | 11232 | lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
4f774513 JS |
11233 | struct lpfc_wcqe_complete *wcqe) |
11234 | { | |
4f774513 JS |
11235 | struct lpfc_iocbq *irspiocbq; |
11236 | unsigned long iflags; | |
2a76a283 | 11237 | struct lpfc_sli_ring *pring = cq->pring; |
4f774513 | 11238 | |
45ed1190 | 11239 | /* Get an irspiocbq for later ELS response processing use */ |
4f774513 JS |
11240 | irspiocbq = lpfc_sli_get_iocbq(phba); |
11241 | if (!irspiocbq) { | |
11242 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
2a9bf3d0 JS |
11243 | "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d " |
11244 | "fcp_txcmplq_cnt=%d, els_txcmplq_cnt=%d\n", | |
11245 | pring->txq_cnt, phba->iocb_cnt, | |
11246 | phba->sli.ring[LPFC_FCP_RING].txcmplq_cnt, | |
11247 | phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt); | |
45ed1190 | 11248 | return false; |
4f774513 | 11249 | } |
4f774513 | 11250 | |
45ed1190 JS |
11251 | /* Save off the slow-path queue event for work thread to process */ |
11252 | memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe)); | |
4f774513 | 11253 | spin_lock_irqsave(&phba->hbalock, iflags); |
4d9ab994 | 11254 | list_add_tail(&irspiocbq->cq_event.list, |
45ed1190 JS |
11255 | &phba->sli4_hba.sp_queue_event); |
11256 | phba->hba_flag |= HBA_SP_QUEUE_EVT; | |
4f774513 | 11257 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
4f774513 | 11258 | |
45ed1190 | 11259 | return true; |
4f774513 JS |
11260 | } |
11261 | ||
11262 | /** | |
11263 | * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event | |
11264 | * @phba: Pointer to HBA context object. | |
11265 | * @wcqe: Pointer to work-queue completion queue entry. | |
11266 | * | |
11267 | * This routine handles slow-path WQ entry comsumed event by invoking the | |
11268 | * proper WQ release routine to the slow-path WQ. | |
11269 | **/ | |
11270 | static void | |
11271 | lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba, | |
11272 | struct lpfc_wcqe_release *wcqe) | |
11273 | { | |
2e90f4b5 JS |
11274 | /* sanity check on queue memory */ |
11275 | if (unlikely(!phba->sli4_hba.els_wq)) | |
11276 | return; | |
4f774513 JS |
11277 | /* Check for the slow-path ELS work queue */ |
11278 | if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id) | |
11279 | lpfc_sli4_wq_release(phba->sli4_hba.els_wq, | |
11280 | bf_get(lpfc_wcqe_r_wqe_index, wcqe)); | |
11281 | else | |
11282 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
11283 | "2579 Slow-path wqe consume event carries " | |
11284 | "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n", | |
11285 | bf_get(lpfc_wcqe_r_wqe_index, wcqe), | |
11286 | phba->sli4_hba.els_wq->queue_id); | |
11287 | } | |
11288 | ||
11289 | /** | |
11290 | * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event | |
11291 | * @phba: Pointer to HBA context object. | |
11292 | * @cq: Pointer to a WQ completion queue. | |
11293 | * @wcqe: Pointer to work-queue completion queue entry. | |
11294 | * | |
11295 | * This routine handles an XRI abort event. | |
11296 | * | |
11297 | * Return: true if work posted to worker thread, otherwise false. | |
11298 | **/ | |
11299 | static bool | |
11300 | lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba, | |
11301 | struct lpfc_queue *cq, | |
11302 | struct sli4_wcqe_xri_aborted *wcqe) | |
11303 | { | |
11304 | bool workposted = false; | |
11305 | struct lpfc_cq_event *cq_event; | |
11306 | unsigned long iflags; | |
11307 | ||
11308 | /* Allocate a new internal CQ_EVENT entry */ | |
11309 | cq_event = lpfc_sli4_cq_event_alloc(phba); | |
11310 | if (!cq_event) { | |
11311 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
11312 | "0602 Failed to allocate CQ_EVENT entry\n"); | |
11313 | return false; | |
11314 | } | |
11315 | ||
11316 | /* Move the CQE into the proper xri abort event list */ | |
11317 | memcpy(&cq_event->cqe, wcqe, sizeof(struct sli4_wcqe_xri_aborted)); | |
11318 | switch (cq->subtype) { | |
11319 | case LPFC_FCP: | |
11320 | spin_lock_irqsave(&phba->hbalock, iflags); | |
11321 | list_add_tail(&cq_event->list, | |
11322 | &phba->sli4_hba.sp_fcp_xri_aborted_work_queue); | |
11323 | /* Set the fcp xri abort event flag */ | |
11324 | phba->hba_flag |= FCP_XRI_ABORT_EVENT; | |
11325 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
11326 | workposted = true; | |
11327 | break; | |
11328 | case LPFC_ELS: | |
11329 | spin_lock_irqsave(&phba->hbalock, iflags); | |
11330 | list_add_tail(&cq_event->list, | |
11331 | &phba->sli4_hba.sp_els_xri_aborted_work_queue); | |
11332 | /* Set the els xri abort event flag */ | |
11333 | phba->hba_flag |= ELS_XRI_ABORT_EVENT; | |
11334 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
11335 | workposted = true; | |
11336 | break; | |
11337 | default: | |
11338 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
11339 | "0603 Invalid work queue CQE subtype (x%x)\n", | |
11340 | cq->subtype); | |
11341 | workposted = false; | |
11342 | break; | |
11343 | } | |
11344 | return workposted; | |
11345 | } | |
11346 | ||
4f774513 JS |
11347 | /** |
11348 | * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry | |
11349 | * @phba: Pointer to HBA context object. | |
11350 | * @rcqe: Pointer to receive-queue completion queue entry. | |
11351 | * | |
11352 | * This routine process a receive-queue completion queue entry. | |
11353 | * | |
11354 | * Return: true if work posted to worker thread, otherwise false. | |
11355 | **/ | |
11356 | static bool | |
4d9ab994 | 11357 | lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe) |
4f774513 | 11358 | { |
4f774513 JS |
11359 | bool workposted = false; |
11360 | struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq; | |
11361 | struct lpfc_queue *drq = phba->sli4_hba.dat_rq; | |
11362 | struct hbq_dmabuf *dma_buf; | |
7851fe2c | 11363 | uint32_t status, rq_id; |
4f774513 JS |
11364 | unsigned long iflags; |
11365 | ||
2e90f4b5 JS |
11366 | /* sanity check on queue memory */ |
11367 | if (unlikely(!hrq) || unlikely(!drq)) | |
11368 | return workposted; | |
11369 | ||
7851fe2c JS |
11370 | if (bf_get(lpfc_cqe_code, rcqe) == CQE_CODE_RECEIVE_V1) |
11371 | rq_id = bf_get(lpfc_rcqe_rq_id_v1, rcqe); | |
11372 | else | |
11373 | rq_id = bf_get(lpfc_rcqe_rq_id, rcqe); | |
11374 | if (rq_id != hrq->queue_id) | |
4f774513 JS |
11375 | goto out; |
11376 | ||
4d9ab994 | 11377 | status = bf_get(lpfc_rcqe_status, rcqe); |
4f774513 JS |
11378 | switch (status) { |
11379 | case FC_STATUS_RQ_BUF_LEN_EXCEEDED: | |
11380 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
11381 | "2537 Receive Frame Truncated!!\n"); | |
b84daac9 | 11382 | hrq->RQ_buf_trunc++; |
4f774513 | 11383 | case FC_STATUS_RQ_SUCCESS: |
5ffc266e | 11384 | lpfc_sli4_rq_release(hrq, drq); |
4f774513 JS |
11385 | spin_lock_irqsave(&phba->hbalock, iflags); |
11386 | dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list); | |
11387 | if (!dma_buf) { | |
b84daac9 | 11388 | hrq->RQ_no_buf_found++; |
4f774513 JS |
11389 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
11390 | goto out; | |
11391 | } | |
b84daac9 | 11392 | hrq->RQ_rcv_buf++; |
4d9ab994 | 11393 | memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe)); |
4f774513 | 11394 | /* save off the frame for the word thread to process */ |
4d9ab994 | 11395 | list_add_tail(&dma_buf->cq_event.list, |
45ed1190 | 11396 | &phba->sli4_hba.sp_queue_event); |
4f774513 | 11397 | /* Frame received */ |
45ed1190 | 11398 | phba->hba_flag |= HBA_SP_QUEUE_EVT; |
4f774513 JS |
11399 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
11400 | workposted = true; | |
11401 | break; | |
11402 | case FC_STATUS_INSUFF_BUF_NEED_BUF: | |
11403 | case FC_STATUS_INSUFF_BUF_FRM_DISC: | |
b84daac9 | 11404 | hrq->RQ_no_posted_buf++; |
4f774513 JS |
11405 | /* Post more buffers if possible */ |
11406 | spin_lock_irqsave(&phba->hbalock, iflags); | |
11407 | phba->hba_flag |= HBA_POST_RECEIVE_BUFFER; | |
11408 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
11409 | workposted = true; | |
11410 | break; | |
11411 | } | |
11412 | out: | |
11413 | return workposted; | |
4f774513 JS |
11414 | } |
11415 | ||
4d9ab994 JS |
11416 | /** |
11417 | * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry | |
11418 | * @phba: Pointer to HBA context object. | |
11419 | * @cq: Pointer to the completion queue. | |
11420 | * @wcqe: Pointer to a completion queue entry. | |
11421 | * | |
25985edc | 11422 | * This routine process a slow-path work-queue or receive queue completion queue |
4d9ab994 JS |
11423 | * entry. |
11424 | * | |
11425 | * Return: true if work posted to worker thread, otherwise false. | |
11426 | **/ | |
11427 | static bool | |
11428 | lpfc_sli4_sp_handle_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq, | |
11429 | struct lpfc_cqe *cqe) | |
11430 | { | |
45ed1190 | 11431 | struct lpfc_cqe cqevt; |
4d9ab994 JS |
11432 | bool workposted = false; |
11433 | ||
11434 | /* Copy the work queue CQE and convert endian order if needed */ | |
45ed1190 | 11435 | lpfc_sli_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe)); |
4d9ab994 JS |
11436 | |
11437 | /* Check and process for different type of WCQE and dispatch */ | |
45ed1190 | 11438 | switch (bf_get(lpfc_cqe_code, &cqevt)) { |
4d9ab994 | 11439 | case CQE_CODE_COMPL_WQE: |
45ed1190 | 11440 | /* Process the WQ/RQ complete event */ |
bc73905a | 11441 | phba->last_completion_time = jiffies; |
2a76a283 | 11442 | workposted = lpfc_sli4_sp_handle_els_wcqe(phba, cq, |
45ed1190 | 11443 | (struct lpfc_wcqe_complete *)&cqevt); |
4d9ab994 JS |
11444 | break; |
11445 | case CQE_CODE_RELEASE_WQE: | |
11446 | /* Process the WQ release event */ | |
11447 | lpfc_sli4_sp_handle_rel_wcqe(phba, | |
45ed1190 | 11448 | (struct lpfc_wcqe_release *)&cqevt); |
4d9ab994 JS |
11449 | break; |
11450 | case CQE_CODE_XRI_ABORTED: | |
11451 | /* Process the WQ XRI abort event */ | |
bc73905a | 11452 | phba->last_completion_time = jiffies; |
4d9ab994 | 11453 | workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq, |
45ed1190 | 11454 | (struct sli4_wcqe_xri_aborted *)&cqevt); |
4d9ab994 JS |
11455 | break; |
11456 | case CQE_CODE_RECEIVE: | |
7851fe2c | 11457 | case CQE_CODE_RECEIVE_V1: |
4d9ab994 | 11458 | /* Process the RQ event */ |
bc73905a | 11459 | phba->last_completion_time = jiffies; |
4d9ab994 | 11460 | workposted = lpfc_sli4_sp_handle_rcqe(phba, |
45ed1190 | 11461 | (struct lpfc_rcqe *)&cqevt); |
4d9ab994 JS |
11462 | break; |
11463 | default: | |
11464 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
11465 | "0388 Not a valid WCQE code: x%x\n", | |
45ed1190 | 11466 | bf_get(lpfc_cqe_code, &cqevt)); |
4d9ab994 JS |
11467 | break; |
11468 | } | |
11469 | return workposted; | |
11470 | } | |
11471 | ||
4f774513 JS |
11472 | /** |
11473 | * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry | |
11474 | * @phba: Pointer to HBA context object. | |
11475 | * @eqe: Pointer to fast-path event queue entry. | |
11476 | * | |
11477 | * This routine process a event queue entry from the slow-path event queue. | |
11478 | * It will check the MajorCode and MinorCode to determine this is for a | |
11479 | * completion event on a completion queue, if not, an error shall be logged | |
11480 | * and just return. Otherwise, it will get to the corresponding completion | |
11481 | * queue and process all the entries on that completion queue, rearm the | |
11482 | * completion queue, and then return. | |
11483 | * | |
11484 | **/ | |
11485 | static void | |
67d12733 JS |
11486 | lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe, |
11487 | struct lpfc_queue *speq) | |
4f774513 | 11488 | { |
67d12733 | 11489 | struct lpfc_queue *cq = NULL, *childq; |
4f774513 JS |
11490 | struct lpfc_cqe *cqe; |
11491 | bool workposted = false; | |
11492 | int ecount = 0; | |
11493 | uint16_t cqid; | |
11494 | ||
4f774513 | 11495 | /* Get the reference to the corresponding CQ */ |
cb5172ea | 11496 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
4f774513 | 11497 | |
4f774513 JS |
11498 | list_for_each_entry(childq, &speq->child_list, list) { |
11499 | if (childq->queue_id == cqid) { | |
11500 | cq = childq; | |
11501 | break; | |
11502 | } | |
11503 | } | |
11504 | if (unlikely(!cq)) { | |
75baf696 JS |
11505 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) |
11506 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
11507 | "0365 Slow-path CQ identifier " | |
11508 | "(%d) does not exist\n", cqid); | |
4f774513 JS |
11509 | return; |
11510 | } | |
11511 | ||
11512 | /* Process all the entries to the CQ */ | |
11513 | switch (cq->type) { | |
11514 | case LPFC_MCQ: | |
11515 | while ((cqe = lpfc_sli4_cq_get(cq))) { | |
11516 | workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe); | |
73d91e50 | 11517 | if (!(++ecount % cq->entry_repost)) |
4f774513 | 11518 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM); |
b84daac9 | 11519 | cq->CQ_mbox++; |
4f774513 JS |
11520 | } |
11521 | break; | |
11522 | case LPFC_WCQ: | |
11523 | while ((cqe = lpfc_sli4_cq_get(cq))) { | |
0558056c JS |
11524 | if (cq->subtype == LPFC_FCP) |
11525 | workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, | |
11526 | cqe); | |
11527 | else | |
11528 | workposted |= lpfc_sli4_sp_handle_cqe(phba, cq, | |
11529 | cqe); | |
73d91e50 | 11530 | if (!(++ecount % cq->entry_repost)) |
4f774513 JS |
11531 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM); |
11532 | } | |
b84daac9 JS |
11533 | |
11534 | /* Track the max number of CQEs processed in 1 EQ */ | |
11535 | if (ecount > cq->CQ_max_cqe) | |
11536 | cq->CQ_max_cqe = ecount; | |
4f774513 JS |
11537 | break; |
11538 | default: | |
11539 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
11540 | "0370 Invalid completion queue type (%d)\n", | |
11541 | cq->type); | |
11542 | return; | |
11543 | } | |
11544 | ||
11545 | /* Catch the no cq entry condition, log an error */ | |
11546 | if (unlikely(ecount == 0)) | |
11547 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
11548 | "0371 No entry from the CQ: identifier " | |
11549 | "(x%x), type (%d)\n", cq->queue_id, cq->type); | |
11550 | ||
11551 | /* In any case, flash and re-arm the RCQ */ | |
11552 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM); | |
11553 | ||
11554 | /* wake up worker thread if there are works to be done */ | |
11555 | if (workposted) | |
11556 | lpfc_worker_wake_up(phba); | |
11557 | } | |
11558 | ||
11559 | /** | |
11560 | * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry | |
2a76a283 JS |
11561 | * @phba: Pointer to HBA context object. |
11562 | * @cq: Pointer to associated CQ | |
11563 | * @wcqe: Pointer to work-queue completion queue entry. | |
4f774513 JS |
11564 | * |
11565 | * This routine process a fast-path work queue completion entry from fast-path | |
11566 | * event queue for FCP command response completion. | |
11567 | **/ | |
11568 | static void | |
2a76a283 | 11569 | lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
4f774513 JS |
11570 | struct lpfc_wcqe_complete *wcqe) |
11571 | { | |
2a76a283 | 11572 | struct lpfc_sli_ring *pring = cq->pring; |
4f774513 JS |
11573 | struct lpfc_iocbq *cmdiocbq; |
11574 | struct lpfc_iocbq irspiocbq; | |
11575 | unsigned long iflags; | |
11576 | ||
4f774513 JS |
11577 | /* Check for response status */ |
11578 | if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) { | |
11579 | /* If resource errors reported from HBA, reduce queue | |
11580 | * depth of the SCSI device. | |
11581 | */ | |
11582 | if ((bf_get(lpfc_wcqe_c_status, wcqe) == | |
11583 | IOSTAT_LOCAL_REJECT) && | |
11584 | (wcqe->parameter == IOERR_NO_RESOURCES)) { | |
11585 | phba->lpfc_rampdown_queue_depth(phba); | |
11586 | } | |
11587 | /* Log the error status */ | |
11588 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
11589 | "0373 FCP complete error: status=x%x, " | |
11590 | "hw_status=x%x, total_data_specified=%d, " | |
11591 | "parameter=x%x, word3=x%x\n", | |
11592 | bf_get(lpfc_wcqe_c_status, wcqe), | |
11593 | bf_get(lpfc_wcqe_c_hw_status, wcqe), | |
11594 | wcqe->total_data_placed, wcqe->parameter, | |
11595 | wcqe->word3); | |
11596 | } | |
11597 | ||
11598 | /* Look up the FCP command IOCB and create pseudo response IOCB */ | |
7e56aa25 JS |
11599 | spin_lock_irqsave(&pring->ring_lock, iflags); |
11600 | pring->stats.iocb_event++; | |
4f774513 JS |
11601 | cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring, |
11602 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); | |
7e56aa25 | 11603 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
4f774513 JS |
11604 | if (unlikely(!cmdiocbq)) { |
11605 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
11606 | "0374 FCP complete with no corresponding " | |
11607 | "cmdiocb: iotag (%d)\n", | |
11608 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); | |
11609 | return; | |
11610 | } | |
11611 | if (unlikely(!cmdiocbq->iocb_cmpl)) { | |
11612 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
11613 | "0375 FCP cmdiocb not callback function " | |
11614 | "iotag: (%d)\n", | |
11615 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); | |
11616 | return; | |
11617 | } | |
11618 | ||
11619 | /* Fake the irspiocb and copy necessary response information */ | |
341af102 | 11620 | lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe); |
4f774513 | 11621 | |
0f65ff68 JS |
11622 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) { |
11623 | spin_lock_irqsave(&phba->hbalock, iflags); | |
11624 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; | |
11625 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
11626 | } | |
11627 | ||
4f774513 JS |
11628 | /* Pass the cmd_iocb and the rsp state to the upper layer */ |
11629 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq); | |
11630 | } | |
11631 | ||
11632 | /** | |
11633 | * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event | |
11634 | * @phba: Pointer to HBA context object. | |
11635 | * @cq: Pointer to completion queue. | |
11636 | * @wcqe: Pointer to work-queue completion queue entry. | |
11637 | * | |
11638 | * This routine handles an fast-path WQ entry comsumed event by invoking the | |
11639 | * proper WQ release routine to the slow-path WQ. | |
11640 | **/ | |
11641 | static void | |
11642 | lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, | |
11643 | struct lpfc_wcqe_release *wcqe) | |
11644 | { | |
11645 | struct lpfc_queue *childwq; | |
11646 | bool wqid_matched = false; | |
11647 | uint16_t fcp_wqid; | |
11648 | ||
11649 | /* Check for fast-path FCP work queue release */ | |
11650 | fcp_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe); | |
11651 | list_for_each_entry(childwq, &cq->child_list, list) { | |
11652 | if (childwq->queue_id == fcp_wqid) { | |
11653 | lpfc_sli4_wq_release(childwq, | |
11654 | bf_get(lpfc_wcqe_r_wqe_index, wcqe)); | |
11655 | wqid_matched = true; | |
11656 | break; | |
11657 | } | |
11658 | } | |
11659 | /* Report warning log message if no match found */ | |
11660 | if (wqid_matched != true) | |
11661 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
11662 | "2580 Fast-path wqe consume event carries " | |
11663 | "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid); | |
11664 | } | |
11665 | ||
11666 | /** | |
11667 | * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry | |
11668 | * @cq: Pointer to the completion queue. | |
11669 | * @eqe: Pointer to fast-path completion queue entry. | |
11670 | * | |
11671 | * This routine process a fast-path work queue completion entry from fast-path | |
11672 | * event queue for FCP command response completion. | |
11673 | **/ | |
11674 | static int | |
11675 | lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, | |
11676 | struct lpfc_cqe *cqe) | |
11677 | { | |
11678 | struct lpfc_wcqe_release wcqe; | |
11679 | bool workposted = false; | |
11680 | ||
11681 | /* Copy the work queue CQE and convert endian order if needed */ | |
11682 | lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe)); | |
11683 | ||
11684 | /* Check and process for different type of WCQE and dispatch */ | |
11685 | switch (bf_get(lpfc_wcqe_c_code, &wcqe)) { | |
11686 | case CQE_CODE_COMPL_WQE: | |
b84daac9 | 11687 | cq->CQ_wq++; |
4f774513 | 11688 | /* Process the WQ complete event */ |
98fc5dd9 | 11689 | phba->last_completion_time = jiffies; |
2a76a283 | 11690 | lpfc_sli4_fp_handle_fcp_wcqe(phba, cq, |
4f774513 JS |
11691 | (struct lpfc_wcqe_complete *)&wcqe); |
11692 | break; | |
11693 | case CQE_CODE_RELEASE_WQE: | |
b84daac9 | 11694 | cq->CQ_release_wqe++; |
4f774513 JS |
11695 | /* Process the WQ release event */ |
11696 | lpfc_sli4_fp_handle_rel_wcqe(phba, cq, | |
11697 | (struct lpfc_wcqe_release *)&wcqe); | |
11698 | break; | |
11699 | case CQE_CODE_XRI_ABORTED: | |
b84daac9 | 11700 | cq->CQ_xri_aborted++; |
4f774513 | 11701 | /* Process the WQ XRI abort event */ |
bc73905a | 11702 | phba->last_completion_time = jiffies; |
4f774513 JS |
11703 | workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq, |
11704 | (struct sli4_wcqe_xri_aborted *)&wcqe); | |
11705 | break; | |
11706 | default: | |
11707 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
11708 | "0144 Not a valid WCQE code: x%x\n", | |
11709 | bf_get(lpfc_wcqe_c_code, &wcqe)); | |
11710 | break; | |
11711 | } | |
11712 | return workposted; | |
11713 | } | |
11714 | ||
11715 | /** | |
67d12733 | 11716 | * lpfc_sli4_hba_handle_eqe - Process a fast-path event queue entry |
4f774513 JS |
11717 | * @phba: Pointer to HBA context object. |
11718 | * @eqe: Pointer to fast-path event queue entry. | |
11719 | * | |
11720 | * This routine process a event queue entry from the fast-path event queue. | |
11721 | * It will check the MajorCode and MinorCode to determine this is for a | |
11722 | * completion event on a completion queue, if not, an error shall be logged | |
11723 | * and just return. Otherwise, it will get to the corresponding completion | |
11724 | * queue and process all the entries on the completion queue, rearm the | |
11725 | * completion queue, and then return. | |
11726 | **/ | |
11727 | static void | |
67d12733 JS |
11728 | lpfc_sli4_hba_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe, |
11729 | uint32_t qidx) | |
4f774513 JS |
11730 | { |
11731 | struct lpfc_queue *cq; | |
11732 | struct lpfc_cqe *cqe; | |
11733 | bool workposted = false; | |
11734 | uint16_t cqid; | |
11735 | int ecount = 0; | |
11736 | ||
cb5172ea | 11737 | if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) { |
4f774513 | 11738 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
67d12733 | 11739 | "0366 Not a valid completion " |
4f774513 | 11740 | "event: majorcode=x%x, minorcode=x%x\n", |
cb5172ea JS |
11741 | bf_get_le32(lpfc_eqe_major_code, eqe), |
11742 | bf_get_le32(lpfc_eqe_minor_code, eqe)); | |
4f774513 JS |
11743 | return; |
11744 | } | |
11745 | ||
67d12733 JS |
11746 | /* Get the reference to the corresponding CQ */ |
11747 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); | |
11748 | ||
11749 | /* Check if this is a Slow path event */ | |
11750 | if (unlikely(cqid != phba->sli4_hba.fcp_cq_map[qidx])) { | |
11751 | lpfc_sli4_sp_handle_eqe(phba, eqe, | |
11752 | phba->sli4_hba.hba_eq[qidx]); | |
11753 | return; | |
11754 | } | |
11755 | ||
2e90f4b5 JS |
11756 | if (unlikely(!phba->sli4_hba.fcp_cq)) { |
11757 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
11758 | "3146 Fast-path completion queues " | |
11759 | "does not exist\n"); | |
11760 | return; | |
11761 | } | |
67d12733 | 11762 | cq = phba->sli4_hba.fcp_cq[qidx]; |
4f774513 | 11763 | if (unlikely(!cq)) { |
75baf696 JS |
11764 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) |
11765 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
11766 | "0367 Fast-path completion queue " | |
67d12733 | 11767 | "(%d) does not exist\n", qidx); |
4f774513 JS |
11768 | return; |
11769 | } | |
11770 | ||
4f774513 JS |
11771 | if (unlikely(cqid != cq->queue_id)) { |
11772 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
11773 | "0368 Miss-matched fast-path completion " | |
11774 | "queue identifier: eqcqid=%d, fcpcqid=%d\n", | |
11775 | cqid, cq->queue_id); | |
11776 | return; | |
11777 | } | |
11778 | ||
11779 | /* Process all the entries to the CQ */ | |
11780 | while ((cqe = lpfc_sli4_cq_get(cq))) { | |
11781 | workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe); | |
73d91e50 | 11782 | if (!(++ecount % cq->entry_repost)) |
4f774513 JS |
11783 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM); |
11784 | } | |
11785 | ||
b84daac9 JS |
11786 | /* Track the max number of CQEs processed in 1 EQ */ |
11787 | if (ecount > cq->CQ_max_cqe) | |
11788 | cq->CQ_max_cqe = ecount; | |
11789 | ||
4f774513 JS |
11790 | /* Catch the no cq entry condition */ |
11791 | if (unlikely(ecount == 0)) | |
11792 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
11793 | "0369 No entry from fast-path completion " | |
11794 | "queue fcpcqid=%d\n", cq->queue_id); | |
11795 | ||
11796 | /* In any case, flash and re-arm the CQ */ | |
11797 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM); | |
11798 | ||
11799 | /* wake up worker thread if there are works to be done */ | |
11800 | if (workposted) | |
11801 | lpfc_worker_wake_up(phba); | |
11802 | } | |
11803 | ||
11804 | static void | |
11805 | lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq) | |
11806 | { | |
11807 | struct lpfc_eqe *eqe; | |
11808 | ||
11809 | /* walk all the EQ entries and drop on the floor */ | |
11810 | while ((eqe = lpfc_sli4_eq_get(eq))) | |
11811 | ; | |
11812 | ||
11813 | /* Clear and re-arm the EQ */ | |
11814 | lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM); | |
11815 | } | |
11816 | ||
11817 | /** | |
67d12733 | 11818 | * lpfc_sli4_hba_intr_handler - HBA interrupt handler to SLI-4 device |
4f774513 JS |
11819 | * @irq: Interrupt number. |
11820 | * @dev_id: The device context pointer. | |
11821 | * | |
11822 | * This function is directly called from the PCI layer as an interrupt | |
11823 | * service routine when device with SLI-4 interface spec is enabled with | |
11824 | * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB | |
11825 | * ring event in the HBA. However, when the device is enabled with either | |
11826 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the | |
11827 | * device-level interrupt handler. When the PCI slot is in error recovery | |
11828 | * or the HBA is undergoing initialization, the interrupt handler will not | |
11829 | * process the interrupt. The SCSI FCP fast-path ring event are handled in | |
11830 | * the intrrupt context. This function is called without any lock held. | |
11831 | * It gets the hbalock to access and update SLI data structures. Note that, | |
11832 | * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is | |
11833 | * equal to that of FCP CQ index. | |
11834 | * | |
67d12733 JS |
11835 | * The link attention and ELS ring attention events are handled |
11836 | * by the worker thread. The interrupt handler signals the worker thread | |
11837 | * and returns for these events. This function is called without any lock | |
11838 | * held. It gets the hbalock to access and update SLI data structures. | |
11839 | * | |
4f774513 JS |
11840 | * This function returns IRQ_HANDLED when interrupt is handled else it |
11841 | * returns IRQ_NONE. | |
11842 | **/ | |
11843 | irqreturn_t | |
67d12733 | 11844 | lpfc_sli4_hba_intr_handler(int irq, void *dev_id) |
4f774513 JS |
11845 | { |
11846 | struct lpfc_hba *phba; | |
11847 | struct lpfc_fcp_eq_hdl *fcp_eq_hdl; | |
11848 | struct lpfc_queue *fpeq; | |
11849 | struct lpfc_eqe *eqe; | |
11850 | unsigned long iflag; | |
11851 | int ecount = 0; | |
11852 | uint32_t fcp_eqidx; | |
11853 | ||
11854 | /* Get the driver's phba structure from the dev_id */ | |
11855 | fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id; | |
11856 | phba = fcp_eq_hdl->phba; | |
11857 | fcp_eqidx = fcp_eq_hdl->idx; | |
11858 | ||
11859 | if (unlikely(!phba)) | |
11860 | return IRQ_NONE; | |
67d12733 | 11861 | if (unlikely(!phba->sli4_hba.hba_eq)) |
5350d872 | 11862 | return IRQ_NONE; |
4f774513 JS |
11863 | |
11864 | /* Get to the EQ struct associated with this vector */ | |
67d12733 | 11865 | fpeq = phba->sli4_hba.hba_eq[fcp_eqidx]; |
2e90f4b5 JS |
11866 | if (unlikely(!fpeq)) |
11867 | return IRQ_NONE; | |
4f774513 | 11868 | |
ba20c853 JS |
11869 | if (lpfc_fcp_look_ahead) { |
11870 | if (atomic_dec_and_test(&fcp_eq_hdl->fcp_eq_in_use)) | |
11871 | lpfc_sli4_eq_clr_intr(fpeq); | |
11872 | else { | |
11873 | atomic_inc(&fcp_eq_hdl->fcp_eq_in_use); | |
11874 | return IRQ_NONE; | |
11875 | } | |
11876 | } | |
11877 | ||
4f774513 JS |
11878 | /* Check device state for handling interrupt */ |
11879 | if (unlikely(lpfc_intr_state_check(phba))) { | |
b84daac9 | 11880 | fpeq->EQ_badstate++; |
4f774513 JS |
11881 | /* Check again for link_state with lock held */ |
11882 | spin_lock_irqsave(&phba->hbalock, iflag); | |
11883 | if (phba->link_state < LPFC_LINK_DOWN) | |
11884 | /* Flush, clear interrupt, and rearm the EQ */ | |
11885 | lpfc_sli4_eq_flush(phba, fpeq); | |
11886 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
ba20c853 JS |
11887 | if (lpfc_fcp_look_ahead) |
11888 | atomic_inc(&fcp_eq_hdl->fcp_eq_in_use); | |
4f774513 JS |
11889 | return IRQ_NONE; |
11890 | } | |
11891 | ||
11892 | /* | |
11893 | * Process all the event on FCP fast-path EQ | |
11894 | */ | |
11895 | while ((eqe = lpfc_sli4_eq_get(fpeq))) { | |
67d12733 | 11896 | lpfc_sli4_hba_handle_eqe(phba, eqe, fcp_eqidx); |
73d91e50 | 11897 | if (!(++ecount % fpeq->entry_repost)) |
4f774513 | 11898 | lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_NOARM); |
b84daac9 | 11899 | fpeq->EQ_processed++; |
4f774513 JS |
11900 | } |
11901 | ||
b84daac9 JS |
11902 | /* Track the max number of EQEs processed in 1 intr */ |
11903 | if (ecount > fpeq->EQ_max_eqe) | |
11904 | fpeq->EQ_max_eqe = ecount; | |
11905 | ||
4f774513 JS |
11906 | /* Always clear and re-arm the fast-path EQ */ |
11907 | lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM); | |
11908 | ||
11909 | if (unlikely(ecount == 0)) { | |
b84daac9 | 11910 | fpeq->EQ_no_entry++; |
ba20c853 JS |
11911 | |
11912 | if (lpfc_fcp_look_ahead) { | |
11913 | atomic_inc(&fcp_eq_hdl->fcp_eq_in_use); | |
11914 | return IRQ_NONE; | |
11915 | } | |
11916 | ||
4f774513 JS |
11917 | if (phba->intr_type == MSIX) |
11918 | /* MSI-X treated interrupt served as no EQ share INT */ | |
11919 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
11920 | "0358 MSI-X interrupt with no EQE\n"); | |
11921 | else | |
11922 | /* Non MSI-X treated on interrupt as EQ share INT */ | |
11923 | return IRQ_NONE; | |
11924 | } | |
11925 | ||
ba20c853 JS |
11926 | if (lpfc_fcp_look_ahead) |
11927 | atomic_inc(&fcp_eq_hdl->fcp_eq_in_use); | |
4f774513 JS |
11928 | return IRQ_HANDLED; |
11929 | } /* lpfc_sli4_fp_intr_handler */ | |
11930 | ||
11931 | /** | |
11932 | * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device | |
11933 | * @irq: Interrupt number. | |
11934 | * @dev_id: The device context pointer. | |
11935 | * | |
11936 | * This function is the device-level interrupt handler to device with SLI-4 | |
11937 | * interface spec, called from the PCI layer when either MSI or Pin-IRQ | |
11938 | * interrupt mode is enabled and there is an event in the HBA which requires | |
11939 | * driver attention. This function invokes the slow-path interrupt attention | |
11940 | * handling function and fast-path interrupt attention handling function in | |
11941 | * turn to process the relevant HBA attention events. This function is called | |
11942 | * without any lock held. It gets the hbalock to access and update SLI data | |
11943 | * structures. | |
11944 | * | |
11945 | * This function returns IRQ_HANDLED when interrupt is handled, else it | |
11946 | * returns IRQ_NONE. | |
11947 | **/ | |
11948 | irqreturn_t | |
11949 | lpfc_sli4_intr_handler(int irq, void *dev_id) | |
11950 | { | |
11951 | struct lpfc_hba *phba; | |
67d12733 JS |
11952 | irqreturn_t hba_irq_rc; |
11953 | bool hba_handled = false; | |
4f774513 JS |
11954 | uint32_t fcp_eqidx; |
11955 | ||
11956 | /* Get the driver's phba structure from the dev_id */ | |
11957 | phba = (struct lpfc_hba *)dev_id; | |
11958 | ||
11959 | if (unlikely(!phba)) | |
11960 | return IRQ_NONE; | |
11961 | ||
4f774513 JS |
11962 | /* |
11963 | * Invoke fast-path host attention interrupt handling as appropriate. | |
11964 | */ | |
67d12733 JS |
11965 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_io_channel; fcp_eqidx++) { |
11966 | hba_irq_rc = lpfc_sli4_hba_intr_handler(irq, | |
4f774513 | 11967 | &phba->sli4_hba.fcp_eq_hdl[fcp_eqidx]); |
67d12733 JS |
11968 | if (hba_irq_rc == IRQ_HANDLED) |
11969 | hba_handled |= true; | |
4f774513 JS |
11970 | } |
11971 | ||
67d12733 | 11972 | return (hba_handled == true) ? IRQ_HANDLED : IRQ_NONE; |
4f774513 JS |
11973 | } /* lpfc_sli4_intr_handler */ |
11974 | ||
11975 | /** | |
11976 | * lpfc_sli4_queue_free - free a queue structure and associated memory | |
11977 | * @queue: The queue structure to free. | |
11978 | * | |
b595076a | 11979 | * This function frees a queue structure and the DMAable memory used for |
4f774513 JS |
11980 | * the host resident queue. This function must be called after destroying the |
11981 | * queue on the HBA. | |
11982 | **/ | |
11983 | void | |
11984 | lpfc_sli4_queue_free(struct lpfc_queue *queue) | |
11985 | { | |
11986 | struct lpfc_dmabuf *dmabuf; | |
11987 | ||
11988 | if (!queue) | |
11989 | return; | |
11990 | ||
11991 | while (!list_empty(&queue->page_list)) { | |
11992 | list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf, | |
11993 | list); | |
49198b37 | 11994 | dma_free_coherent(&queue->phba->pcidev->dev, SLI4_PAGE_SIZE, |
4f774513 JS |
11995 | dmabuf->virt, dmabuf->phys); |
11996 | kfree(dmabuf); | |
11997 | } | |
11998 | kfree(queue); | |
11999 | return; | |
12000 | } | |
12001 | ||
12002 | /** | |
12003 | * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure | |
12004 | * @phba: The HBA that this queue is being created on. | |
12005 | * @entry_size: The size of each queue entry for this queue. | |
12006 | * @entry count: The number of entries that this queue will handle. | |
12007 | * | |
12008 | * This function allocates a queue structure and the DMAable memory used for | |
12009 | * the host resident queue. This function must be called before creating the | |
12010 | * queue on the HBA. | |
12011 | **/ | |
12012 | struct lpfc_queue * | |
12013 | lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t entry_size, | |
12014 | uint32_t entry_count) | |
12015 | { | |
12016 | struct lpfc_queue *queue; | |
12017 | struct lpfc_dmabuf *dmabuf; | |
12018 | int x, total_qe_count; | |
12019 | void *dma_pointer; | |
cb5172ea | 12020 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
4f774513 | 12021 | |
cb5172ea JS |
12022 | if (!phba->sli4_hba.pc_sli4_params.supported) |
12023 | hw_page_size = SLI4_PAGE_SIZE; | |
12024 | ||
4f774513 JS |
12025 | queue = kzalloc(sizeof(struct lpfc_queue) + |
12026 | (sizeof(union sli4_qe) * entry_count), GFP_KERNEL); | |
12027 | if (!queue) | |
12028 | return NULL; | |
cb5172ea JS |
12029 | queue->page_count = (ALIGN(entry_size * entry_count, |
12030 | hw_page_size))/hw_page_size; | |
4f774513 JS |
12031 | INIT_LIST_HEAD(&queue->list); |
12032 | INIT_LIST_HEAD(&queue->page_list); | |
12033 | INIT_LIST_HEAD(&queue->child_list); | |
12034 | for (x = 0, total_qe_count = 0; x < queue->page_count; x++) { | |
12035 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | |
12036 | if (!dmabuf) | |
12037 | goto out_fail; | |
12038 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, | |
cb5172ea | 12039 | hw_page_size, &dmabuf->phys, |
4f774513 JS |
12040 | GFP_KERNEL); |
12041 | if (!dmabuf->virt) { | |
12042 | kfree(dmabuf); | |
12043 | goto out_fail; | |
12044 | } | |
cb5172ea | 12045 | memset(dmabuf->virt, 0, hw_page_size); |
4f774513 JS |
12046 | dmabuf->buffer_tag = x; |
12047 | list_add_tail(&dmabuf->list, &queue->page_list); | |
12048 | /* initialize queue's entry array */ | |
12049 | dma_pointer = dmabuf->virt; | |
12050 | for (; total_qe_count < entry_count && | |
cb5172ea | 12051 | dma_pointer < (hw_page_size + dmabuf->virt); |
4f774513 JS |
12052 | total_qe_count++, dma_pointer += entry_size) { |
12053 | queue->qe[total_qe_count].address = dma_pointer; | |
12054 | } | |
12055 | } | |
12056 | queue->entry_size = entry_size; | |
12057 | queue->entry_count = entry_count; | |
73d91e50 JS |
12058 | |
12059 | /* | |
12060 | * entry_repost is calculated based on the number of entries in the | |
12061 | * queue. This works out except for RQs. If buffers are NOT initially | |
12062 | * posted for every RQE, entry_repost should be adjusted accordingly. | |
12063 | */ | |
12064 | queue->entry_repost = (entry_count >> 3); | |
12065 | if (queue->entry_repost < LPFC_QUEUE_MIN_REPOST) | |
12066 | queue->entry_repost = LPFC_QUEUE_MIN_REPOST; | |
4f774513 JS |
12067 | queue->phba = phba; |
12068 | ||
12069 | return queue; | |
12070 | out_fail: | |
12071 | lpfc_sli4_queue_free(queue); | |
12072 | return NULL; | |
12073 | } | |
12074 | ||
173edbb2 JS |
12075 | /** |
12076 | * lpfc_modify_fcp_eq_delay - Modify Delay Multiplier on FCP EQs | |
12077 | * @phba: HBA structure that indicates port to create a queue on. | |
12078 | * @startq: The starting FCP EQ to modify | |
12079 | * | |
12080 | * This function sends an MODIFY_EQ_DELAY mailbox command to the HBA. | |
12081 | * | |
12082 | * The @phba struct is used to send mailbox command to HBA. The @startq | |
12083 | * is used to get the starting FCP EQ to change. | |
12084 | * This function is asynchronous and will wait for the mailbox | |
12085 | * command to finish before continuing. | |
12086 | * | |
12087 | * On success this function will return a zero. If unable to allocate enough | |
12088 | * memory this function will return -ENOMEM. If the queue create mailbox command | |
12089 | * fails this function will return -ENXIO. | |
12090 | **/ | |
12091 | uint32_t | |
12092 | lpfc_modify_fcp_eq_delay(struct lpfc_hba *phba, uint16_t startq) | |
12093 | { | |
12094 | struct lpfc_mbx_modify_eq_delay *eq_delay; | |
12095 | LPFC_MBOXQ_t *mbox; | |
12096 | struct lpfc_queue *eq; | |
12097 | int cnt, rc, length, status = 0; | |
12098 | uint32_t shdr_status, shdr_add_status; | |
12099 | int fcp_eqidx; | |
12100 | union lpfc_sli4_cfg_shdr *shdr; | |
12101 | uint16_t dmult; | |
12102 | ||
67d12733 | 12103 | if (startq >= phba->cfg_fcp_io_channel) |
173edbb2 JS |
12104 | return 0; |
12105 | ||
12106 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
12107 | if (!mbox) | |
12108 | return -ENOMEM; | |
12109 | length = (sizeof(struct lpfc_mbx_modify_eq_delay) - | |
12110 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
12111 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
12112 | LPFC_MBOX_OPCODE_MODIFY_EQ_DELAY, | |
12113 | length, LPFC_SLI4_MBX_EMBED); | |
12114 | eq_delay = &mbox->u.mqe.un.eq_delay; | |
12115 | ||
12116 | /* Calculate delay multiper from maximum interrupt per second */ | |
bf8dae83 JS |
12117 | dmult = phba->cfg_fcp_imax / phba->cfg_fcp_io_channel; |
12118 | dmult = LPFC_DMULT_CONST/dmult - 1; | |
173edbb2 JS |
12119 | |
12120 | cnt = 0; | |
67d12733 | 12121 | for (fcp_eqidx = startq; fcp_eqidx < phba->cfg_fcp_io_channel; |
173edbb2 | 12122 | fcp_eqidx++) { |
67d12733 | 12123 | eq = phba->sli4_hba.hba_eq[fcp_eqidx]; |
173edbb2 JS |
12124 | if (!eq) |
12125 | continue; | |
12126 | eq_delay->u.request.eq[cnt].eq_id = eq->queue_id; | |
12127 | eq_delay->u.request.eq[cnt].phase = 0; | |
12128 | eq_delay->u.request.eq[cnt].delay_multi = dmult; | |
12129 | cnt++; | |
12130 | if (cnt >= LPFC_MAX_EQ_DELAY) | |
12131 | break; | |
12132 | } | |
12133 | eq_delay->u.request.num_eq = cnt; | |
12134 | ||
12135 | mbox->vport = phba->pport; | |
12136 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
12137 | mbox->context1 = NULL; | |
12138 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
12139 | shdr = (union lpfc_sli4_cfg_shdr *) &eq_delay->header.cfg_shdr; | |
12140 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
12141 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
12142 | if (shdr_status || shdr_add_status || rc) { | |
12143 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
12144 | "2512 MODIFY_EQ_DELAY mailbox failed with " | |
12145 | "status x%x add_status x%x, mbx status x%x\n", | |
12146 | shdr_status, shdr_add_status, rc); | |
12147 | status = -ENXIO; | |
12148 | } | |
12149 | mempool_free(mbox, phba->mbox_mem_pool); | |
12150 | return status; | |
12151 | } | |
12152 | ||
4f774513 JS |
12153 | /** |
12154 | * lpfc_eq_create - Create an Event Queue on the HBA | |
12155 | * @phba: HBA structure that indicates port to create a queue on. | |
12156 | * @eq: The queue structure to use to create the event queue. | |
12157 | * @imax: The maximum interrupt per second limit. | |
12158 | * | |
12159 | * This function creates an event queue, as detailed in @eq, on a port, | |
12160 | * described by @phba by sending an EQ_CREATE mailbox command to the HBA. | |
12161 | * | |
12162 | * The @phba struct is used to send mailbox command to HBA. The @eq struct | |
12163 | * is used to get the entry count and entry size that are necessary to | |
12164 | * determine the number of pages to allocate and use for this queue. This | |
12165 | * function will send the EQ_CREATE mailbox command to the HBA to setup the | |
12166 | * event queue. This function is asynchronous and will wait for the mailbox | |
12167 | * command to finish before continuing. | |
12168 | * | |
12169 | * On success this function will return a zero. If unable to allocate enough | |
d439d286 JS |
12170 | * memory this function will return -ENOMEM. If the queue create mailbox command |
12171 | * fails this function will return -ENXIO. | |
4f774513 JS |
12172 | **/ |
12173 | uint32_t | |
12174 | lpfc_eq_create(struct lpfc_hba *phba, struct lpfc_queue *eq, uint16_t imax) | |
12175 | { | |
12176 | struct lpfc_mbx_eq_create *eq_create; | |
12177 | LPFC_MBOXQ_t *mbox; | |
12178 | int rc, length, status = 0; | |
12179 | struct lpfc_dmabuf *dmabuf; | |
12180 | uint32_t shdr_status, shdr_add_status; | |
12181 | union lpfc_sli4_cfg_shdr *shdr; | |
12182 | uint16_t dmult; | |
49198b37 JS |
12183 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
12184 | ||
2e90f4b5 JS |
12185 | /* sanity check on queue memory */ |
12186 | if (!eq) | |
12187 | return -ENODEV; | |
49198b37 JS |
12188 | if (!phba->sli4_hba.pc_sli4_params.supported) |
12189 | hw_page_size = SLI4_PAGE_SIZE; | |
4f774513 JS |
12190 | |
12191 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
12192 | if (!mbox) | |
12193 | return -ENOMEM; | |
12194 | length = (sizeof(struct lpfc_mbx_eq_create) - | |
12195 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
12196 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
12197 | LPFC_MBOX_OPCODE_EQ_CREATE, | |
12198 | length, LPFC_SLI4_MBX_EMBED); | |
12199 | eq_create = &mbox->u.mqe.un.eq_create; | |
12200 | bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request, | |
12201 | eq->page_count); | |
12202 | bf_set(lpfc_eq_context_size, &eq_create->u.request.context, | |
12203 | LPFC_EQE_SIZE); | |
12204 | bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1); | |
12205 | /* Calculate delay multiper from maximum interrupt per second */ | |
12206 | dmult = LPFC_DMULT_CONST/imax - 1; | |
12207 | bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context, | |
12208 | dmult); | |
12209 | switch (eq->entry_count) { | |
12210 | default: | |
12211 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
12212 | "0360 Unsupported EQ count. (%d)\n", | |
12213 | eq->entry_count); | |
12214 | if (eq->entry_count < 256) | |
12215 | return -EINVAL; | |
12216 | /* otherwise default to smallest count (drop through) */ | |
12217 | case 256: | |
12218 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, | |
12219 | LPFC_EQ_CNT_256); | |
12220 | break; | |
12221 | case 512: | |
12222 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, | |
12223 | LPFC_EQ_CNT_512); | |
12224 | break; | |
12225 | case 1024: | |
12226 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, | |
12227 | LPFC_EQ_CNT_1024); | |
12228 | break; | |
12229 | case 2048: | |
12230 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, | |
12231 | LPFC_EQ_CNT_2048); | |
12232 | break; | |
12233 | case 4096: | |
12234 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, | |
12235 | LPFC_EQ_CNT_4096); | |
12236 | break; | |
12237 | } | |
12238 | list_for_each_entry(dmabuf, &eq->page_list, list) { | |
49198b37 | 12239 | memset(dmabuf->virt, 0, hw_page_size); |
4f774513 JS |
12240 | eq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
12241 | putPaddrLow(dmabuf->phys); | |
12242 | eq_create->u.request.page[dmabuf->buffer_tag].addr_hi = | |
12243 | putPaddrHigh(dmabuf->phys); | |
12244 | } | |
12245 | mbox->vport = phba->pport; | |
12246 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
12247 | mbox->context1 = NULL; | |
12248 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
12249 | shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr; | |
12250 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
12251 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
12252 | if (shdr_status || shdr_add_status || rc) { | |
12253 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
12254 | "2500 EQ_CREATE mailbox failed with " | |
12255 | "status x%x add_status x%x, mbx status x%x\n", | |
12256 | shdr_status, shdr_add_status, rc); | |
12257 | status = -ENXIO; | |
12258 | } | |
12259 | eq->type = LPFC_EQ; | |
12260 | eq->subtype = LPFC_NONE; | |
12261 | eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response); | |
12262 | if (eq->queue_id == 0xFFFF) | |
12263 | status = -ENXIO; | |
12264 | eq->host_index = 0; | |
12265 | eq->hba_index = 0; | |
12266 | ||
8fa38513 | 12267 | mempool_free(mbox, phba->mbox_mem_pool); |
4f774513 JS |
12268 | return status; |
12269 | } | |
12270 | ||
12271 | /** | |
12272 | * lpfc_cq_create - Create a Completion Queue on the HBA | |
12273 | * @phba: HBA structure that indicates port to create a queue on. | |
12274 | * @cq: The queue structure to use to create the completion queue. | |
12275 | * @eq: The event queue to bind this completion queue to. | |
12276 | * | |
12277 | * This function creates a completion queue, as detailed in @wq, on a port, | |
12278 | * described by @phba by sending a CQ_CREATE mailbox command to the HBA. | |
12279 | * | |
12280 | * The @phba struct is used to send mailbox command to HBA. The @cq struct | |
12281 | * is used to get the entry count and entry size that are necessary to | |
12282 | * determine the number of pages to allocate and use for this queue. The @eq | |
12283 | * is used to indicate which event queue to bind this completion queue to. This | |
12284 | * function will send the CQ_CREATE mailbox command to the HBA to setup the | |
12285 | * completion queue. This function is asynchronous and will wait for the mailbox | |
12286 | * command to finish before continuing. | |
12287 | * | |
12288 | * On success this function will return a zero. If unable to allocate enough | |
d439d286 JS |
12289 | * memory this function will return -ENOMEM. If the queue create mailbox command |
12290 | * fails this function will return -ENXIO. | |
4f774513 JS |
12291 | **/ |
12292 | uint32_t | |
12293 | lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq, | |
12294 | struct lpfc_queue *eq, uint32_t type, uint32_t subtype) | |
12295 | { | |
12296 | struct lpfc_mbx_cq_create *cq_create; | |
12297 | struct lpfc_dmabuf *dmabuf; | |
12298 | LPFC_MBOXQ_t *mbox; | |
12299 | int rc, length, status = 0; | |
12300 | uint32_t shdr_status, shdr_add_status; | |
12301 | union lpfc_sli4_cfg_shdr *shdr; | |
49198b37 JS |
12302 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
12303 | ||
2e90f4b5 JS |
12304 | /* sanity check on queue memory */ |
12305 | if (!cq || !eq) | |
12306 | return -ENODEV; | |
49198b37 JS |
12307 | if (!phba->sli4_hba.pc_sli4_params.supported) |
12308 | hw_page_size = SLI4_PAGE_SIZE; | |
12309 | ||
4f774513 JS |
12310 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
12311 | if (!mbox) | |
12312 | return -ENOMEM; | |
12313 | length = (sizeof(struct lpfc_mbx_cq_create) - | |
12314 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
12315 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
12316 | LPFC_MBOX_OPCODE_CQ_CREATE, | |
12317 | length, LPFC_SLI4_MBX_EMBED); | |
12318 | cq_create = &mbox->u.mqe.un.cq_create; | |
5a6f133e | 12319 | shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr; |
4f774513 JS |
12320 | bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request, |
12321 | cq->page_count); | |
12322 | bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1); | |
12323 | bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1); | |
5a6f133e JS |
12324 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
12325 | phba->sli4_hba.pc_sli4_params.cqv); | |
12326 | if (phba->sli4_hba.pc_sli4_params.cqv == LPFC_Q_CREATE_VERSION_2) { | |
c31098ce JS |
12327 | /* FW only supports 1. Should be PAGE_SIZE/SLI4_PAGE_SIZE */ |
12328 | bf_set(lpfc_mbx_cq_create_page_size, &cq_create->u.request, 1); | |
5a6f133e JS |
12329 | bf_set(lpfc_cq_eq_id_2, &cq_create->u.request.context, |
12330 | eq->queue_id); | |
12331 | } else { | |
12332 | bf_set(lpfc_cq_eq_id, &cq_create->u.request.context, | |
12333 | eq->queue_id); | |
12334 | } | |
4f774513 JS |
12335 | switch (cq->entry_count) { |
12336 | default: | |
12337 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
12338 | "0361 Unsupported CQ count. (%d)\n", | |
12339 | cq->entry_count); | |
4f4c1863 JS |
12340 | if (cq->entry_count < 256) { |
12341 | status = -EINVAL; | |
12342 | goto out; | |
12343 | } | |
4f774513 JS |
12344 | /* otherwise default to smallest count (drop through) */ |
12345 | case 256: | |
12346 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, | |
12347 | LPFC_CQ_CNT_256); | |
12348 | break; | |
12349 | case 512: | |
12350 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, | |
12351 | LPFC_CQ_CNT_512); | |
12352 | break; | |
12353 | case 1024: | |
12354 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, | |
12355 | LPFC_CQ_CNT_1024); | |
12356 | break; | |
12357 | } | |
12358 | list_for_each_entry(dmabuf, &cq->page_list, list) { | |
49198b37 | 12359 | memset(dmabuf->virt, 0, hw_page_size); |
4f774513 JS |
12360 | cq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
12361 | putPaddrLow(dmabuf->phys); | |
12362 | cq_create->u.request.page[dmabuf->buffer_tag].addr_hi = | |
12363 | putPaddrHigh(dmabuf->phys); | |
12364 | } | |
12365 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
12366 | ||
12367 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
4f774513 JS |
12368 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
12369 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
12370 | if (shdr_status || shdr_add_status || rc) { | |
12371 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
12372 | "2501 CQ_CREATE mailbox failed with " | |
12373 | "status x%x add_status x%x, mbx status x%x\n", | |
12374 | shdr_status, shdr_add_status, rc); | |
12375 | status = -ENXIO; | |
12376 | goto out; | |
12377 | } | |
12378 | cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response); | |
12379 | if (cq->queue_id == 0xFFFF) { | |
12380 | status = -ENXIO; | |
12381 | goto out; | |
12382 | } | |
12383 | /* link the cq onto the parent eq child list */ | |
12384 | list_add_tail(&cq->list, &eq->child_list); | |
12385 | /* Set up completion queue's type and subtype */ | |
12386 | cq->type = type; | |
12387 | cq->subtype = subtype; | |
12388 | cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response); | |
2a622bfb | 12389 | cq->assoc_qid = eq->queue_id; |
4f774513 JS |
12390 | cq->host_index = 0; |
12391 | cq->hba_index = 0; | |
4f774513 | 12392 | |
8fa38513 JS |
12393 | out: |
12394 | mempool_free(mbox, phba->mbox_mem_pool); | |
4f774513 JS |
12395 | return status; |
12396 | } | |
12397 | ||
b19a061a JS |
12398 | /** |
12399 | * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration | |
12400 | * @phba: HBA structure that indicates port to create a queue on. | |
12401 | * @mq: The queue structure to use to create the mailbox queue. | |
12402 | * @mbox: An allocated pointer to type LPFC_MBOXQ_t | |
12403 | * @cq: The completion queue to associate with this cq. | |
12404 | * | |
12405 | * This function provides failback (fb) functionality when the | |
12406 | * mq_create_ext fails on older FW generations. It's purpose is identical | |
12407 | * to mq_create_ext otherwise. | |
12408 | * | |
12409 | * This routine cannot fail as all attributes were previously accessed and | |
12410 | * initialized in mq_create_ext. | |
12411 | **/ | |
12412 | static void | |
12413 | lpfc_mq_create_fb_init(struct lpfc_hba *phba, struct lpfc_queue *mq, | |
12414 | LPFC_MBOXQ_t *mbox, struct lpfc_queue *cq) | |
12415 | { | |
12416 | struct lpfc_mbx_mq_create *mq_create; | |
12417 | struct lpfc_dmabuf *dmabuf; | |
12418 | int length; | |
12419 | ||
12420 | length = (sizeof(struct lpfc_mbx_mq_create) - | |
12421 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
12422 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
12423 | LPFC_MBOX_OPCODE_MQ_CREATE, | |
12424 | length, LPFC_SLI4_MBX_EMBED); | |
12425 | mq_create = &mbox->u.mqe.un.mq_create; | |
12426 | bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request, | |
12427 | mq->page_count); | |
12428 | bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context, | |
12429 | cq->queue_id); | |
12430 | bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1); | |
12431 | switch (mq->entry_count) { | |
12432 | case 16: | |
5a6f133e JS |
12433 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
12434 | LPFC_MQ_RING_SIZE_16); | |
b19a061a JS |
12435 | break; |
12436 | case 32: | |
5a6f133e JS |
12437 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
12438 | LPFC_MQ_RING_SIZE_32); | |
b19a061a JS |
12439 | break; |
12440 | case 64: | |
5a6f133e JS |
12441 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
12442 | LPFC_MQ_RING_SIZE_64); | |
b19a061a JS |
12443 | break; |
12444 | case 128: | |
5a6f133e JS |
12445 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
12446 | LPFC_MQ_RING_SIZE_128); | |
b19a061a JS |
12447 | break; |
12448 | } | |
12449 | list_for_each_entry(dmabuf, &mq->page_list, list) { | |
12450 | mq_create->u.request.page[dmabuf->buffer_tag].addr_lo = | |
12451 | putPaddrLow(dmabuf->phys); | |
12452 | mq_create->u.request.page[dmabuf->buffer_tag].addr_hi = | |
12453 | putPaddrHigh(dmabuf->phys); | |
12454 | } | |
12455 | } | |
12456 | ||
04c68496 JS |
12457 | /** |
12458 | * lpfc_mq_create - Create a mailbox Queue on the HBA | |
12459 | * @phba: HBA structure that indicates port to create a queue on. | |
12460 | * @mq: The queue structure to use to create the mailbox queue. | |
b19a061a JS |
12461 | * @cq: The completion queue to associate with this cq. |
12462 | * @subtype: The queue's subtype. | |
04c68496 JS |
12463 | * |
12464 | * This function creates a mailbox queue, as detailed in @mq, on a port, | |
12465 | * described by @phba by sending a MQ_CREATE mailbox command to the HBA. | |
12466 | * | |
12467 | * The @phba struct is used to send mailbox command to HBA. The @cq struct | |
12468 | * is used to get the entry count and entry size that are necessary to | |
12469 | * determine the number of pages to allocate and use for this queue. This | |
12470 | * function will send the MQ_CREATE mailbox command to the HBA to setup the | |
12471 | * mailbox queue. This function is asynchronous and will wait for the mailbox | |
12472 | * command to finish before continuing. | |
12473 | * | |
12474 | * On success this function will return a zero. If unable to allocate enough | |
d439d286 JS |
12475 | * memory this function will return -ENOMEM. If the queue create mailbox command |
12476 | * fails this function will return -ENXIO. | |
04c68496 | 12477 | **/ |
b19a061a | 12478 | int32_t |
04c68496 JS |
12479 | lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq, |
12480 | struct lpfc_queue *cq, uint32_t subtype) | |
12481 | { | |
12482 | struct lpfc_mbx_mq_create *mq_create; | |
b19a061a | 12483 | struct lpfc_mbx_mq_create_ext *mq_create_ext; |
04c68496 JS |
12484 | struct lpfc_dmabuf *dmabuf; |
12485 | LPFC_MBOXQ_t *mbox; | |
12486 | int rc, length, status = 0; | |
12487 | uint32_t shdr_status, shdr_add_status; | |
12488 | union lpfc_sli4_cfg_shdr *shdr; | |
49198b37 | 12489 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
04c68496 | 12490 | |
2e90f4b5 JS |
12491 | /* sanity check on queue memory */ |
12492 | if (!mq || !cq) | |
12493 | return -ENODEV; | |
49198b37 JS |
12494 | if (!phba->sli4_hba.pc_sli4_params.supported) |
12495 | hw_page_size = SLI4_PAGE_SIZE; | |
b19a061a | 12496 | |
04c68496 JS |
12497 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
12498 | if (!mbox) | |
12499 | return -ENOMEM; | |
b19a061a | 12500 | length = (sizeof(struct lpfc_mbx_mq_create_ext) - |
04c68496 JS |
12501 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
12502 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
b19a061a | 12503 | LPFC_MBOX_OPCODE_MQ_CREATE_EXT, |
04c68496 | 12504 | length, LPFC_SLI4_MBX_EMBED); |
b19a061a JS |
12505 | |
12506 | mq_create_ext = &mbox->u.mqe.un.mq_create_ext; | |
5a6f133e | 12507 | shdr = (union lpfc_sli4_cfg_shdr *) &mq_create_ext->header.cfg_shdr; |
70f3c073 JS |
12508 | bf_set(lpfc_mbx_mq_create_ext_num_pages, |
12509 | &mq_create_ext->u.request, mq->page_count); | |
12510 | bf_set(lpfc_mbx_mq_create_ext_async_evt_link, | |
12511 | &mq_create_ext->u.request, 1); | |
12512 | bf_set(lpfc_mbx_mq_create_ext_async_evt_fip, | |
b19a061a JS |
12513 | &mq_create_ext->u.request, 1); |
12514 | bf_set(lpfc_mbx_mq_create_ext_async_evt_group5, | |
12515 | &mq_create_ext->u.request, 1); | |
70f3c073 JS |
12516 | bf_set(lpfc_mbx_mq_create_ext_async_evt_fc, |
12517 | &mq_create_ext->u.request, 1); | |
12518 | bf_set(lpfc_mbx_mq_create_ext_async_evt_sli, | |
12519 | &mq_create_ext->u.request, 1); | |
b19a061a | 12520 | bf_set(lpfc_mq_context_valid, &mq_create_ext->u.request.context, 1); |
5a6f133e JS |
12521 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
12522 | phba->sli4_hba.pc_sli4_params.mqv); | |
12523 | if (phba->sli4_hba.pc_sli4_params.mqv == LPFC_Q_CREATE_VERSION_1) | |
12524 | bf_set(lpfc_mbx_mq_create_ext_cq_id, &mq_create_ext->u.request, | |
12525 | cq->queue_id); | |
12526 | else | |
12527 | bf_set(lpfc_mq_context_cq_id, &mq_create_ext->u.request.context, | |
12528 | cq->queue_id); | |
04c68496 JS |
12529 | switch (mq->entry_count) { |
12530 | default: | |
12531 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
12532 | "0362 Unsupported MQ count. (%d)\n", | |
12533 | mq->entry_count); | |
4f4c1863 JS |
12534 | if (mq->entry_count < 16) { |
12535 | status = -EINVAL; | |
12536 | goto out; | |
12537 | } | |
04c68496 JS |
12538 | /* otherwise default to smallest count (drop through) */ |
12539 | case 16: | |
5a6f133e JS |
12540 | bf_set(lpfc_mq_context_ring_size, |
12541 | &mq_create_ext->u.request.context, | |
12542 | LPFC_MQ_RING_SIZE_16); | |
04c68496 JS |
12543 | break; |
12544 | case 32: | |
5a6f133e JS |
12545 | bf_set(lpfc_mq_context_ring_size, |
12546 | &mq_create_ext->u.request.context, | |
12547 | LPFC_MQ_RING_SIZE_32); | |
04c68496 JS |
12548 | break; |
12549 | case 64: | |
5a6f133e JS |
12550 | bf_set(lpfc_mq_context_ring_size, |
12551 | &mq_create_ext->u.request.context, | |
12552 | LPFC_MQ_RING_SIZE_64); | |
04c68496 JS |
12553 | break; |
12554 | case 128: | |
5a6f133e JS |
12555 | bf_set(lpfc_mq_context_ring_size, |
12556 | &mq_create_ext->u.request.context, | |
12557 | LPFC_MQ_RING_SIZE_128); | |
04c68496 JS |
12558 | break; |
12559 | } | |
12560 | list_for_each_entry(dmabuf, &mq->page_list, list) { | |
49198b37 | 12561 | memset(dmabuf->virt, 0, hw_page_size); |
b19a061a | 12562 | mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_lo = |
04c68496 | 12563 | putPaddrLow(dmabuf->phys); |
b19a061a | 12564 | mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_hi = |
04c68496 JS |
12565 | putPaddrHigh(dmabuf->phys); |
12566 | } | |
12567 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
b19a061a JS |
12568 | mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, |
12569 | &mq_create_ext->u.response); | |
12570 | if (rc != MBX_SUCCESS) { | |
12571 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
12572 | "2795 MQ_CREATE_EXT failed with " | |
12573 | "status x%x. Failback to MQ_CREATE.\n", | |
12574 | rc); | |
12575 | lpfc_mq_create_fb_init(phba, mq, mbox, cq); | |
12576 | mq_create = &mbox->u.mqe.un.mq_create; | |
12577 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
12578 | shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr; | |
12579 | mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, | |
12580 | &mq_create->u.response); | |
12581 | } | |
12582 | ||
04c68496 | 12583 | /* The IOCTL status is embedded in the mailbox subheader. */ |
04c68496 JS |
12584 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
12585 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
12586 | if (shdr_status || shdr_add_status || rc) { | |
12587 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
12588 | "2502 MQ_CREATE mailbox failed with " | |
12589 | "status x%x add_status x%x, mbx status x%x\n", | |
12590 | shdr_status, shdr_add_status, rc); | |
12591 | status = -ENXIO; | |
12592 | goto out; | |
12593 | } | |
04c68496 JS |
12594 | if (mq->queue_id == 0xFFFF) { |
12595 | status = -ENXIO; | |
12596 | goto out; | |
12597 | } | |
12598 | mq->type = LPFC_MQ; | |
2a622bfb | 12599 | mq->assoc_qid = cq->queue_id; |
04c68496 JS |
12600 | mq->subtype = subtype; |
12601 | mq->host_index = 0; | |
12602 | mq->hba_index = 0; | |
12603 | ||
12604 | /* link the mq onto the parent cq child list */ | |
12605 | list_add_tail(&mq->list, &cq->child_list); | |
12606 | out: | |
8fa38513 | 12607 | mempool_free(mbox, phba->mbox_mem_pool); |
04c68496 JS |
12608 | return status; |
12609 | } | |
12610 | ||
4f774513 JS |
12611 | /** |
12612 | * lpfc_wq_create - Create a Work Queue on the HBA | |
12613 | * @phba: HBA structure that indicates port to create a queue on. | |
12614 | * @wq: The queue structure to use to create the work queue. | |
12615 | * @cq: The completion queue to bind this work queue to. | |
12616 | * @subtype: The subtype of the work queue indicating its functionality. | |
12617 | * | |
12618 | * This function creates a work queue, as detailed in @wq, on a port, described | |
12619 | * by @phba by sending a WQ_CREATE mailbox command to the HBA. | |
12620 | * | |
12621 | * The @phba struct is used to send mailbox command to HBA. The @wq struct | |
12622 | * is used to get the entry count and entry size that are necessary to | |
12623 | * determine the number of pages to allocate and use for this queue. The @cq | |
12624 | * is used to indicate which completion queue to bind this work queue to. This | |
12625 | * function will send the WQ_CREATE mailbox command to the HBA to setup the | |
12626 | * work queue. This function is asynchronous and will wait for the mailbox | |
12627 | * command to finish before continuing. | |
12628 | * | |
12629 | * On success this function will return a zero. If unable to allocate enough | |
d439d286 JS |
12630 | * memory this function will return -ENOMEM. If the queue create mailbox command |
12631 | * fails this function will return -ENXIO. | |
4f774513 JS |
12632 | **/ |
12633 | uint32_t | |
12634 | lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq, | |
12635 | struct lpfc_queue *cq, uint32_t subtype) | |
12636 | { | |
12637 | struct lpfc_mbx_wq_create *wq_create; | |
12638 | struct lpfc_dmabuf *dmabuf; | |
12639 | LPFC_MBOXQ_t *mbox; | |
12640 | int rc, length, status = 0; | |
12641 | uint32_t shdr_status, shdr_add_status; | |
12642 | union lpfc_sli4_cfg_shdr *shdr; | |
49198b37 | 12643 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
5a6f133e | 12644 | struct dma_address *page; |
49198b37 | 12645 | |
2e90f4b5 JS |
12646 | /* sanity check on queue memory */ |
12647 | if (!wq || !cq) | |
12648 | return -ENODEV; | |
49198b37 JS |
12649 | if (!phba->sli4_hba.pc_sli4_params.supported) |
12650 | hw_page_size = SLI4_PAGE_SIZE; | |
4f774513 JS |
12651 | |
12652 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
12653 | if (!mbox) | |
12654 | return -ENOMEM; | |
12655 | length = (sizeof(struct lpfc_mbx_wq_create) - | |
12656 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
12657 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
12658 | LPFC_MBOX_OPCODE_FCOE_WQ_CREATE, | |
12659 | length, LPFC_SLI4_MBX_EMBED); | |
12660 | wq_create = &mbox->u.mqe.un.wq_create; | |
5a6f133e | 12661 | shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr; |
4f774513 JS |
12662 | bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request, |
12663 | wq->page_count); | |
12664 | bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request, | |
12665 | cq->queue_id); | |
5a6f133e JS |
12666 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
12667 | phba->sli4_hba.pc_sli4_params.wqv); | |
12668 | if (phba->sli4_hba.pc_sli4_params.wqv == LPFC_Q_CREATE_VERSION_1) { | |
12669 | bf_set(lpfc_mbx_wq_create_wqe_count, &wq_create->u.request_1, | |
12670 | wq->entry_count); | |
12671 | switch (wq->entry_size) { | |
12672 | default: | |
12673 | case 64: | |
12674 | bf_set(lpfc_mbx_wq_create_wqe_size, | |
12675 | &wq_create->u.request_1, | |
12676 | LPFC_WQ_WQE_SIZE_64); | |
12677 | break; | |
12678 | case 128: | |
12679 | bf_set(lpfc_mbx_wq_create_wqe_size, | |
12680 | &wq_create->u.request_1, | |
12681 | LPFC_WQ_WQE_SIZE_128); | |
12682 | break; | |
12683 | } | |
12684 | bf_set(lpfc_mbx_wq_create_page_size, &wq_create->u.request_1, | |
12685 | (PAGE_SIZE/SLI4_PAGE_SIZE)); | |
12686 | page = wq_create->u.request_1.page; | |
12687 | } else { | |
12688 | page = wq_create->u.request.page; | |
12689 | } | |
4f774513 | 12690 | list_for_each_entry(dmabuf, &wq->page_list, list) { |
49198b37 | 12691 | memset(dmabuf->virt, 0, hw_page_size); |
5a6f133e JS |
12692 | page[dmabuf->buffer_tag].addr_lo = putPaddrLow(dmabuf->phys); |
12693 | page[dmabuf->buffer_tag].addr_hi = putPaddrHigh(dmabuf->phys); | |
4f774513 JS |
12694 | } |
12695 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
12696 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
4f774513 JS |
12697 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
12698 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
12699 | if (shdr_status || shdr_add_status || rc) { | |
12700 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
12701 | "2503 WQ_CREATE mailbox failed with " | |
12702 | "status x%x add_status x%x, mbx status x%x\n", | |
12703 | shdr_status, shdr_add_status, rc); | |
12704 | status = -ENXIO; | |
12705 | goto out; | |
12706 | } | |
12707 | wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, &wq_create->u.response); | |
12708 | if (wq->queue_id == 0xFFFF) { | |
12709 | status = -ENXIO; | |
12710 | goto out; | |
12711 | } | |
12712 | wq->type = LPFC_WQ; | |
2a622bfb | 12713 | wq->assoc_qid = cq->queue_id; |
4f774513 JS |
12714 | wq->subtype = subtype; |
12715 | wq->host_index = 0; | |
12716 | wq->hba_index = 0; | |
ff78d8f9 | 12717 | wq->entry_repost = LPFC_RELEASE_NOTIFICATION_INTERVAL; |
4f774513 JS |
12718 | |
12719 | /* link the wq onto the parent cq child list */ | |
12720 | list_add_tail(&wq->list, &cq->child_list); | |
12721 | out: | |
8fa38513 | 12722 | mempool_free(mbox, phba->mbox_mem_pool); |
4f774513 JS |
12723 | return status; |
12724 | } | |
12725 | ||
73d91e50 JS |
12726 | /** |
12727 | * lpfc_rq_adjust_repost - Adjust entry_repost for an RQ | |
12728 | * @phba: HBA structure that indicates port to create a queue on. | |
12729 | * @rq: The queue structure to use for the receive queue. | |
12730 | * @qno: The associated HBQ number | |
12731 | * | |
12732 | * | |
12733 | * For SLI4 we need to adjust the RQ repost value based on | |
12734 | * the number of buffers that are initially posted to the RQ. | |
12735 | */ | |
12736 | void | |
12737 | lpfc_rq_adjust_repost(struct lpfc_hba *phba, struct lpfc_queue *rq, int qno) | |
12738 | { | |
12739 | uint32_t cnt; | |
12740 | ||
2e90f4b5 JS |
12741 | /* sanity check on queue memory */ |
12742 | if (!rq) | |
12743 | return; | |
73d91e50 JS |
12744 | cnt = lpfc_hbq_defs[qno]->entry_count; |
12745 | ||
12746 | /* Recalc repost for RQs based on buffers initially posted */ | |
12747 | cnt = (cnt >> 3); | |
12748 | if (cnt < LPFC_QUEUE_MIN_REPOST) | |
12749 | cnt = LPFC_QUEUE_MIN_REPOST; | |
12750 | ||
12751 | rq->entry_repost = cnt; | |
12752 | } | |
12753 | ||
4f774513 JS |
12754 | /** |
12755 | * lpfc_rq_create - Create a Receive Queue on the HBA | |
12756 | * @phba: HBA structure that indicates port to create a queue on. | |
12757 | * @hrq: The queue structure to use to create the header receive queue. | |
12758 | * @drq: The queue structure to use to create the data receive queue. | |
12759 | * @cq: The completion queue to bind this work queue to. | |
12760 | * | |
12761 | * This function creates a receive buffer queue pair , as detailed in @hrq and | |
12762 | * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command | |
12763 | * to the HBA. | |
12764 | * | |
12765 | * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq | |
12766 | * struct is used to get the entry count that is necessary to determine the | |
12767 | * number of pages to use for this queue. The @cq is used to indicate which | |
12768 | * completion queue to bind received buffers that are posted to these queues to. | |
12769 | * This function will send the RQ_CREATE mailbox command to the HBA to setup the | |
12770 | * receive queue pair. This function is asynchronous and will wait for the | |
12771 | * mailbox command to finish before continuing. | |
12772 | * | |
12773 | * On success this function will return a zero. If unable to allocate enough | |
d439d286 JS |
12774 | * memory this function will return -ENOMEM. If the queue create mailbox command |
12775 | * fails this function will return -ENXIO. | |
4f774513 JS |
12776 | **/ |
12777 | uint32_t | |
12778 | lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq, | |
12779 | struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype) | |
12780 | { | |
12781 | struct lpfc_mbx_rq_create *rq_create; | |
12782 | struct lpfc_dmabuf *dmabuf; | |
12783 | LPFC_MBOXQ_t *mbox; | |
12784 | int rc, length, status = 0; | |
12785 | uint32_t shdr_status, shdr_add_status; | |
12786 | union lpfc_sli4_cfg_shdr *shdr; | |
49198b37 JS |
12787 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
12788 | ||
2e90f4b5 JS |
12789 | /* sanity check on queue memory */ |
12790 | if (!hrq || !drq || !cq) | |
12791 | return -ENODEV; | |
49198b37 JS |
12792 | if (!phba->sli4_hba.pc_sli4_params.supported) |
12793 | hw_page_size = SLI4_PAGE_SIZE; | |
4f774513 JS |
12794 | |
12795 | if (hrq->entry_count != drq->entry_count) | |
12796 | return -EINVAL; | |
12797 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
12798 | if (!mbox) | |
12799 | return -ENOMEM; | |
12800 | length = (sizeof(struct lpfc_mbx_rq_create) - | |
12801 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
12802 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
12803 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, | |
12804 | length, LPFC_SLI4_MBX_EMBED); | |
12805 | rq_create = &mbox->u.mqe.un.rq_create; | |
5a6f133e JS |
12806 | shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr; |
12807 | bf_set(lpfc_mbox_hdr_version, &shdr->request, | |
12808 | phba->sli4_hba.pc_sli4_params.rqv); | |
12809 | if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) { | |
12810 | bf_set(lpfc_rq_context_rqe_count_1, | |
12811 | &rq_create->u.request.context, | |
12812 | hrq->entry_count); | |
12813 | rq_create->u.request.context.buffer_size = LPFC_HDR_BUF_SIZE; | |
c31098ce JS |
12814 | bf_set(lpfc_rq_context_rqe_size, |
12815 | &rq_create->u.request.context, | |
12816 | LPFC_RQE_SIZE_8); | |
12817 | bf_set(lpfc_rq_context_page_size, | |
12818 | &rq_create->u.request.context, | |
12819 | (PAGE_SIZE/SLI4_PAGE_SIZE)); | |
5a6f133e JS |
12820 | } else { |
12821 | switch (hrq->entry_count) { | |
12822 | default: | |
12823 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
12824 | "2535 Unsupported RQ count. (%d)\n", | |
12825 | hrq->entry_count); | |
4f4c1863 JS |
12826 | if (hrq->entry_count < 512) { |
12827 | status = -EINVAL; | |
12828 | goto out; | |
12829 | } | |
5a6f133e JS |
12830 | /* otherwise default to smallest count (drop through) */ |
12831 | case 512: | |
12832 | bf_set(lpfc_rq_context_rqe_count, | |
12833 | &rq_create->u.request.context, | |
12834 | LPFC_RQ_RING_SIZE_512); | |
12835 | break; | |
12836 | case 1024: | |
12837 | bf_set(lpfc_rq_context_rqe_count, | |
12838 | &rq_create->u.request.context, | |
12839 | LPFC_RQ_RING_SIZE_1024); | |
12840 | break; | |
12841 | case 2048: | |
12842 | bf_set(lpfc_rq_context_rqe_count, | |
12843 | &rq_create->u.request.context, | |
12844 | LPFC_RQ_RING_SIZE_2048); | |
12845 | break; | |
12846 | case 4096: | |
12847 | bf_set(lpfc_rq_context_rqe_count, | |
12848 | &rq_create->u.request.context, | |
12849 | LPFC_RQ_RING_SIZE_4096); | |
12850 | break; | |
12851 | } | |
12852 | bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context, | |
12853 | LPFC_HDR_BUF_SIZE); | |
4f774513 JS |
12854 | } |
12855 | bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context, | |
12856 | cq->queue_id); | |
12857 | bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request, | |
12858 | hrq->page_count); | |
4f774513 | 12859 | list_for_each_entry(dmabuf, &hrq->page_list, list) { |
49198b37 | 12860 | memset(dmabuf->virt, 0, hw_page_size); |
4f774513 JS |
12861 | rq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
12862 | putPaddrLow(dmabuf->phys); | |
12863 | rq_create->u.request.page[dmabuf->buffer_tag].addr_hi = | |
12864 | putPaddrHigh(dmabuf->phys); | |
12865 | } | |
12866 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
12867 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
4f774513 JS |
12868 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
12869 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
12870 | if (shdr_status || shdr_add_status || rc) { | |
12871 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
12872 | "2504 RQ_CREATE mailbox failed with " | |
12873 | "status x%x add_status x%x, mbx status x%x\n", | |
12874 | shdr_status, shdr_add_status, rc); | |
12875 | status = -ENXIO; | |
12876 | goto out; | |
12877 | } | |
12878 | hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); | |
12879 | if (hrq->queue_id == 0xFFFF) { | |
12880 | status = -ENXIO; | |
12881 | goto out; | |
12882 | } | |
12883 | hrq->type = LPFC_HRQ; | |
2a622bfb | 12884 | hrq->assoc_qid = cq->queue_id; |
4f774513 JS |
12885 | hrq->subtype = subtype; |
12886 | hrq->host_index = 0; | |
12887 | hrq->hba_index = 0; | |
12888 | ||
12889 | /* now create the data queue */ | |
12890 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
12891 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, | |
12892 | length, LPFC_SLI4_MBX_EMBED); | |
5a6f133e JS |
12893 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
12894 | phba->sli4_hba.pc_sli4_params.rqv); | |
12895 | if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) { | |
12896 | bf_set(lpfc_rq_context_rqe_count_1, | |
c31098ce | 12897 | &rq_create->u.request.context, hrq->entry_count); |
5a6f133e | 12898 | rq_create->u.request.context.buffer_size = LPFC_DATA_BUF_SIZE; |
c31098ce JS |
12899 | bf_set(lpfc_rq_context_rqe_size, &rq_create->u.request.context, |
12900 | LPFC_RQE_SIZE_8); | |
12901 | bf_set(lpfc_rq_context_page_size, &rq_create->u.request.context, | |
12902 | (PAGE_SIZE/SLI4_PAGE_SIZE)); | |
5a6f133e JS |
12903 | } else { |
12904 | switch (drq->entry_count) { | |
12905 | default: | |
12906 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
12907 | "2536 Unsupported RQ count. (%d)\n", | |
12908 | drq->entry_count); | |
4f4c1863 JS |
12909 | if (drq->entry_count < 512) { |
12910 | status = -EINVAL; | |
12911 | goto out; | |
12912 | } | |
5a6f133e JS |
12913 | /* otherwise default to smallest count (drop through) */ |
12914 | case 512: | |
12915 | bf_set(lpfc_rq_context_rqe_count, | |
12916 | &rq_create->u.request.context, | |
12917 | LPFC_RQ_RING_SIZE_512); | |
12918 | break; | |
12919 | case 1024: | |
12920 | bf_set(lpfc_rq_context_rqe_count, | |
12921 | &rq_create->u.request.context, | |
12922 | LPFC_RQ_RING_SIZE_1024); | |
12923 | break; | |
12924 | case 2048: | |
12925 | bf_set(lpfc_rq_context_rqe_count, | |
12926 | &rq_create->u.request.context, | |
12927 | LPFC_RQ_RING_SIZE_2048); | |
12928 | break; | |
12929 | case 4096: | |
12930 | bf_set(lpfc_rq_context_rqe_count, | |
12931 | &rq_create->u.request.context, | |
12932 | LPFC_RQ_RING_SIZE_4096); | |
12933 | break; | |
12934 | } | |
12935 | bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context, | |
12936 | LPFC_DATA_BUF_SIZE); | |
4f774513 JS |
12937 | } |
12938 | bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context, | |
12939 | cq->queue_id); | |
12940 | bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request, | |
12941 | drq->page_count); | |
4f774513 JS |
12942 | list_for_each_entry(dmabuf, &drq->page_list, list) { |
12943 | rq_create->u.request.page[dmabuf->buffer_tag].addr_lo = | |
12944 | putPaddrLow(dmabuf->phys); | |
12945 | rq_create->u.request.page[dmabuf->buffer_tag].addr_hi = | |
12946 | putPaddrHigh(dmabuf->phys); | |
12947 | } | |
12948 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
12949 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
12950 | shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr; | |
12951 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
12952 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
12953 | if (shdr_status || shdr_add_status || rc) { | |
12954 | status = -ENXIO; | |
12955 | goto out; | |
12956 | } | |
12957 | drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); | |
12958 | if (drq->queue_id == 0xFFFF) { | |
12959 | status = -ENXIO; | |
12960 | goto out; | |
12961 | } | |
12962 | drq->type = LPFC_DRQ; | |
2a622bfb | 12963 | drq->assoc_qid = cq->queue_id; |
4f774513 JS |
12964 | drq->subtype = subtype; |
12965 | drq->host_index = 0; | |
12966 | drq->hba_index = 0; | |
12967 | ||
12968 | /* link the header and data RQs onto the parent cq child list */ | |
12969 | list_add_tail(&hrq->list, &cq->child_list); | |
12970 | list_add_tail(&drq->list, &cq->child_list); | |
12971 | ||
12972 | out: | |
8fa38513 | 12973 | mempool_free(mbox, phba->mbox_mem_pool); |
4f774513 JS |
12974 | return status; |
12975 | } | |
12976 | ||
12977 | /** | |
12978 | * lpfc_eq_destroy - Destroy an event Queue on the HBA | |
12979 | * @eq: The queue structure associated with the queue to destroy. | |
12980 | * | |
12981 | * This function destroys a queue, as detailed in @eq by sending an mailbox | |
12982 | * command, specific to the type of queue, to the HBA. | |
12983 | * | |
12984 | * The @eq struct is used to get the queue ID of the queue to destroy. | |
12985 | * | |
12986 | * On success this function will return a zero. If the queue destroy mailbox | |
d439d286 | 12987 | * command fails this function will return -ENXIO. |
4f774513 JS |
12988 | **/ |
12989 | uint32_t | |
12990 | lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq) | |
12991 | { | |
12992 | LPFC_MBOXQ_t *mbox; | |
12993 | int rc, length, status = 0; | |
12994 | uint32_t shdr_status, shdr_add_status; | |
12995 | union lpfc_sli4_cfg_shdr *shdr; | |
12996 | ||
2e90f4b5 | 12997 | /* sanity check on queue memory */ |
4f774513 JS |
12998 | if (!eq) |
12999 | return -ENODEV; | |
13000 | mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL); | |
13001 | if (!mbox) | |
13002 | return -ENOMEM; | |
13003 | length = (sizeof(struct lpfc_mbx_eq_destroy) - | |
13004 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
13005 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
13006 | LPFC_MBOX_OPCODE_EQ_DESTROY, | |
13007 | length, LPFC_SLI4_MBX_EMBED); | |
13008 | bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request, | |
13009 | eq->queue_id); | |
13010 | mbox->vport = eq->phba->pport; | |
13011 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
13012 | ||
13013 | rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL); | |
13014 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
13015 | shdr = (union lpfc_sli4_cfg_shdr *) | |
13016 | &mbox->u.mqe.un.eq_destroy.header.cfg_shdr; | |
13017 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
13018 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
13019 | if (shdr_status || shdr_add_status || rc) { | |
13020 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
13021 | "2505 EQ_DESTROY mailbox failed with " | |
13022 | "status x%x add_status x%x, mbx status x%x\n", | |
13023 | shdr_status, shdr_add_status, rc); | |
13024 | status = -ENXIO; | |
13025 | } | |
13026 | ||
13027 | /* Remove eq from any list */ | |
13028 | list_del_init(&eq->list); | |
8fa38513 | 13029 | mempool_free(mbox, eq->phba->mbox_mem_pool); |
4f774513 JS |
13030 | return status; |
13031 | } | |
13032 | ||
13033 | /** | |
13034 | * lpfc_cq_destroy - Destroy a Completion Queue on the HBA | |
13035 | * @cq: The queue structure associated with the queue to destroy. | |
13036 | * | |
13037 | * This function destroys a queue, as detailed in @cq by sending an mailbox | |
13038 | * command, specific to the type of queue, to the HBA. | |
13039 | * | |
13040 | * The @cq struct is used to get the queue ID of the queue to destroy. | |
13041 | * | |
13042 | * On success this function will return a zero. If the queue destroy mailbox | |
d439d286 | 13043 | * command fails this function will return -ENXIO. |
4f774513 JS |
13044 | **/ |
13045 | uint32_t | |
13046 | lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq) | |
13047 | { | |
13048 | LPFC_MBOXQ_t *mbox; | |
13049 | int rc, length, status = 0; | |
13050 | uint32_t shdr_status, shdr_add_status; | |
13051 | union lpfc_sli4_cfg_shdr *shdr; | |
13052 | ||
2e90f4b5 | 13053 | /* sanity check on queue memory */ |
4f774513 JS |
13054 | if (!cq) |
13055 | return -ENODEV; | |
13056 | mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL); | |
13057 | if (!mbox) | |
13058 | return -ENOMEM; | |
13059 | length = (sizeof(struct lpfc_mbx_cq_destroy) - | |
13060 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
13061 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
13062 | LPFC_MBOX_OPCODE_CQ_DESTROY, | |
13063 | length, LPFC_SLI4_MBX_EMBED); | |
13064 | bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request, | |
13065 | cq->queue_id); | |
13066 | mbox->vport = cq->phba->pport; | |
13067 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
13068 | rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL); | |
13069 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
13070 | shdr = (union lpfc_sli4_cfg_shdr *) | |
13071 | &mbox->u.mqe.un.wq_create.header.cfg_shdr; | |
13072 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
13073 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
13074 | if (shdr_status || shdr_add_status || rc) { | |
13075 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
13076 | "2506 CQ_DESTROY mailbox failed with " | |
13077 | "status x%x add_status x%x, mbx status x%x\n", | |
13078 | shdr_status, shdr_add_status, rc); | |
13079 | status = -ENXIO; | |
13080 | } | |
13081 | /* Remove cq from any list */ | |
13082 | list_del_init(&cq->list); | |
8fa38513 | 13083 | mempool_free(mbox, cq->phba->mbox_mem_pool); |
4f774513 JS |
13084 | return status; |
13085 | } | |
13086 | ||
04c68496 JS |
13087 | /** |
13088 | * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA | |
13089 | * @qm: The queue structure associated with the queue to destroy. | |
13090 | * | |
13091 | * This function destroys a queue, as detailed in @mq by sending an mailbox | |
13092 | * command, specific to the type of queue, to the HBA. | |
13093 | * | |
13094 | * The @mq struct is used to get the queue ID of the queue to destroy. | |
13095 | * | |
13096 | * On success this function will return a zero. If the queue destroy mailbox | |
d439d286 | 13097 | * command fails this function will return -ENXIO. |
04c68496 JS |
13098 | **/ |
13099 | uint32_t | |
13100 | lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq) | |
13101 | { | |
13102 | LPFC_MBOXQ_t *mbox; | |
13103 | int rc, length, status = 0; | |
13104 | uint32_t shdr_status, shdr_add_status; | |
13105 | union lpfc_sli4_cfg_shdr *shdr; | |
13106 | ||
2e90f4b5 | 13107 | /* sanity check on queue memory */ |
04c68496 JS |
13108 | if (!mq) |
13109 | return -ENODEV; | |
13110 | mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL); | |
13111 | if (!mbox) | |
13112 | return -ENOMEM; | |
13113 | length = (sizeof(struct lpfc_mbx_mq_destroy) - | |
13114 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
13115 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
13116 | LPFC_MBOX_OPCODE_MQ_DESTROY, | |
13117 | length, LPFC_SLI4_MBX_EMBED); | |
13118 | bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request, | |
13119 | mq->queue_id); | |
13120 | mbox->vport = mq->phba->pport; | |
13121 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
13122 | rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL); | |
13123 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
13124 | shdr = (union lpfc_sli4_cfg_shdr *) | |
13125 | &mbox->u.mqe.un.mq_destroy.header.cfg_shdr; | |
13126 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
13127 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
13128 | if (shdr_status || shdr_add_status || rc) { | |
13129 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
13130 | "2507 MQ_DESTROY mailbox failed with " | |
13131 | "status x%x add_status x%x, mbx status x%x\n", | |
13132 | shdr_status, shdr_add_status, rc); | |
13133 | status = -ENXIO; | |
13134 | } | |
13135 | /* Remove mq from any list */ | |
13136 | list_del_init(&mq->list); | |
8fa38513 | 13137 | mempool_free(mbox, mq->phba->mbox_mem_pool); |
04c68496 JS |
13138 | return status; |
13139 | } | |
13140 | ||
4f774513 JS |
13141 | /** |
13142 | * lpfc_wq_destroy - Destroy a Work Queue on the HBA | |
13143 | * @wq: The queue structure associated with the queue to destroy. | |
13144 | * | |
13145 | * This function destroys a queue, as detailed in @wq by sending an mailbox | |
13146 | * command, specific to the type of queue, to the HBA. | |
13147 | * | |
13148 | * The @wq struct is used to get the queue ID of the queue to destroy. | |
13149 | * | |
13150 | * On success this function will return a zero. If the queue destroy mailbox | |
d439d286 | 13151 | * command fails this function will return -ENXIO. |
4f774513 JS |
13152 | **/ |
13153 | uint32_t | |
13154 | lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq) | |
13155 | { | |
13156 | LPFC_MBOXQ_t *mbox; | |
13157 | int rc, length, status = 0; | |
13158 | uint32_t shdr_status, shdr_add_status; | |
13159 | union lpfc_sli4_cfg_shdr *shdr; | |
13160 | ||
2e90f4b5 | 13161 | /* sanity check on queue memory */ |
4f774513 JS |
13162 | if (!wq) |
13163 | return -ENODEV; | |
13164 | mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL); | |
13165 | if (!mbox) | |
13166 | return -ENOMEM; | |
13167 | length = (sizeof(struct lpfc_mbx_wq_destroy) - | |
13168 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
13169 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
13170 | LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY, | |
13171 | length, LPFC_SLI4_MBX_EMBED); | |
13172 | bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request, | |
13173 | wq->queue_id); | |
13174 | mbox->vport = wq->phba->pport; | |
13175 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
13176 | rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL); | |
13177 | shdr = (union lpfc_sli4_cfg_shdr *) | |
13178 | &mbox->u.mqe.un.wq_destroy.header.cfg_shdr; | |
13179 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
13180 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
13181 | if (shdr_status || shdr_add_status || rc) { | |
13182 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
13183 | "2508 WQ_DESTROY mailbox failed with " | |
13184 | "status x%x add_status x%x, mbx status x%x\n", | |
13185 | shdr_status, shdr_add_status, rc); | |
13186 | status = -ENXIO; | |
13187 | } | |
13188 | /* Remove wq from any list */ | |
13189 | list_del_init(&wq->list); | |
8fa38513 | 13190 | mempool_free(mbox, wq->phba->mbox_mem_pool); |
4f774513 JS |
13191 | return status; |
13192 | } | |
13193 | ||
13194 | /** | |
13195 | * lpfc_rq_destroy - Destroy a Receive Queue on the HBA | |
13196 | * @rq: The queue structure associated with the queue to destroy. | |
13197 | * | |
13198 | * This function destroys a queue, as detailed in @rq by sending an mailbox | |
13199 | * command, specific to the type of queue, to the HBA. | |
13200 | * | |
13201 | * The @rq struct is used to get the queue ID of the queue to destroy. | |
13202 | * | |
13203 | * On success this function will return a zero. If the queue destroy mailbox | |
d439d286 | 13204 | * command fails this function will return -ENXIO. |
4f774513 JS |
13205 | **/ |
13206 | uint32_t | |
13207 | lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq, | |
13208 | struct lpfc_queue *drq) | |
13209 | { | |
13210 | LPFC_MBOXQ_t *mbox; | |
13211 | int rc, length, status = 0; | |
13212 | uint32_t shdr_status, shdr_add_status; | |
13213 | union lpfc_sli4_cfg_shdr *shdr; | |
13214 | ||
2e90f4b5 | 13215 | /* sanity check on queue memory */ |
4f774513 JS |
13216 | if (!hrq || !drq) |
13217 | return -ENODEV; | |
13218 | mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL); | |
13219 | if (!mbox) | |
13220 | return -ENOMEM; | |
13221 | length = (sizeof(struct lpfc_mbx_rq_destroy) - | |
fedd3b7b | 13222 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
4f774513 JS |
13223 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
13224 | LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY, | |
13225 | length, LPFC_SLI4_MBX_EMBED); | |
13226 | bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request, | |
13227 | hrq->queue_id); | |
13228 | mbox->vport = hrq->phba->pport; | |
13229 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
13230 | rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL); | |
13231 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
13232 | shdr = (union lpfc_sli4_cfg_shdr *) | |
13233 | &mbox->u.mqe.un.rq_destroy.header.cfg_shdr; | |
13234 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
13235 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
13236 | if (shdr_status || shdr_add_status || rc) { | |
13237 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
13238 | "2509 RQ_DESTROY mailbox failed with " | |
13239 | "status x%x add_status x%x, mbx status x%x\n", | |
13240 | shdr_status, shdr_add_status, rc); | |
13241 | if (rc != MBX_TIMEOUT) | |
13242 | mempool_free(mbox, hrq->phba->mbox_mem_pool); | |
13243 | return -ENXIO; | |
13244 | } | |
13245 | bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request, | |
13246 | drq->queue_id); | |
13247 | rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL); | |
13248 | shdr = (union lpfc_sli4_cfg_shdr *) | |
13249 | &mbox->u.mqe.un.rq_destroy.header.cfg_shdr; | |
13250 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
13251 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
13252 | if (shdr_status || shdr_add_status || rc) { | |
13253 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
13254 | "2510 RQ_DESTROY mailbox failed with " | |
13255 | "status x%x add_status x%x, mbx status x%x\n", | |
13256 | shdr_status, shdr_add_status, rc); | |
13257 | status = -ENXIO; | |
13258 | } | |
13259 | list_del_init(&hrq->list); | |
13260 | list_del_init(&drq->list); | |
8fa38513 | 13261 | mempool_free(mbox, hrq->phba->mbox_mem_pool); |
4f774513 JS |
13262 | return status; |
13263 | } | |
13264 | ||
13265 | /** | |
13266 | * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA | |
13267 | * @phba: The virtual port for which this call being executed. | |
13268 | * @pdma_phys_addr0: Physical address of the 1st SGL page. | |
13269 | * @pdma_phys_addr1: Physical address of the 2nd SGL page. | |
13270 | * @xritag: the xritag that ties this io to the SGL pages. | |
13271 | * | |
13272 | * This routine will post the sgl pages for the IO that has the xritag | |
13273 | * that is in the iocbq structure. The xritag is assigned during iocbq | |
13274 | * creation and persists for as long as the driver is loaded. | |
13275 | * if the caller has fewer than 256 scatter gather segments to map then | |
13276 | * pdma_phys_addr1 should be 0. | |
13277 | * If the caller needs to map more than 256 scatter gather segment then | |
13278 | * pdma_phys_addr1 should be a valid physical address. | |
13279 | * physical address for SGLs must be 64 byte aligned. | |
13280 | * If you are going to map 2 SGL's then the first one must have 256 entries | |
13281 | * the second sgl can have between 1 and 256 entries. | |
13282 | * | |
13283 | * Return codes: | |
13284 | * 0 - Success | |
13285 | * -ENXIO, -ENOMEM - Failure | |
13286 | **/ | |
13287 | int | |
13288 | lpfc_sli4_post_sgl(struct lpfc_hba *phba, | |
13289 | dma_addr_t pdma_phys_addr0, | |
13290 | dma_addr_t pdma_phys_addr1, | |
13291 | uint16_t xritag) | |
13292 | { | |
13293 | struct lpfc_mbx_post_sgl_pages *post_sgl_pages; | |
13294 | LPFC_MBOXQ_t *mbox; | |
13295 | int rc; | |
13296 | uint32_t shdr_status, shdr_add_status; | |
6d368e53 | 13297 | uint32_t mbox_tmo; |
4f774513 JS |
13298 | union lpfc_sli4_cfg_shdr *shdr; |
13299 | ||
13300 | if (xritag == NO_XRI) { | |
13301 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
13302 | "0364 Invalid param:\n"); | |
13303 | return -EINVAL; | |
13304 | } | |
13305 | ||
13306 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
13307 | if (!mbox) | |
13308 | return -ENOMEM; | |
13309 | ||
13310 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
13311 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, | |
13312 | sizeof(struct lpfc_mbx_post_sgl_pages) - | |
fedd3b7b | 13313 | sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED); |
4f774513 JS |
13314 | |
13315 | post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *) | |
13316 | &mbox->u.mqe.un.post_sgl_pages; | |
13317 | bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag); | |
13318 | bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1); | |
13319 | ||
13320 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo = | |
13321 | cpu_to_le32(putPaddrLow(pdma_phys_addr0)); | |
13322 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi = | |
13323 | cpu_to_le32(putPaddrHigh(pdma_phys_addr0)); | |
13324 | ||
13325 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo = | |
13326 | cpu_to_le32(putPaddrLow(pdma_phys_addr1)); | |
13327 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi = | |
13328 | cpu_to_le32(putPaddrHigh(pdma_phys_addr1)); | |
13329 | if (!phba->sli4_hba.intr_enable) | |
13330 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
6d368e53 | 13331 | else { |
a183a15f | 13332 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
6d368e53 JS |
13333 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
13334 | } | |
4f774513 JS |
13335 | /* The IOCTL status is embedded in the mailbox subheader. */ |
13336 | shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr; | |
13337 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
13338 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
13339 | if (rc != MBX_TIMEOUT) | |
13340 | mempool_free(mbox, phba->mbox_mem_pool); | |
13341 | if (shdr_status || shdr_add_status || rc) { | |
13342 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
13343 | "2511 POST_SGL mailbox failed with " | |
13344 | "status x%x add_status x%x, mbx status x%x\n", | |
13345 | shdr_status, shdr_add_status, rc); | |
13346 | rc = -ENXIO; | |
13347 | } | |
13348 | return 0; | |
13349 | } | |
4f774513 | 13350 | |
6d368e53 | 13351 | /** |
88a2cfbb | 13352 | * lpfc_sli4_alloc_xri - Get an available rpi in the device's range |
6d368e53 JS |
13353 | * @phba: pointer to lpfc hba data structure. |
13354 | * | |
13355 | * This routine is invoked to post rpi header templates to the | |
88a2cfbb JS |
13356 | * HBA consistent with the SLI-4 interface spec. This routine |
13357 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to | |
13358 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. | |
6d368e53 | 13359 | * |
88a2cfbb JS |
13360 | * Returns |
13361 | * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful | |
13362 | * LPFC_RPI_ALLOC_ERROR if no rpis are available. | |
13363 | **/ | |
6d368e53 JS |
13364 | uint16_t |
13365 | lpfc_sli4_alloc_xri(struct lpfc_hba *phba) | |
13366 | { | |
13367 | unsigned long xri; | |
13368 | ||
13369 | /* | |
13370 | * Fetch the next logical xri. Because this index is logical, | |
13371 | * the driver starts at 0 each time. | |
13372 | */ | |
13373 | spin_lock_irq(&phba->hbalock); | |
13374 | xri = find_next_zero_bit(phba->sli4_hba.xri_bmask, | |
13375 | phba->sli4_hba.max_cfg_param.max_xri, 0); | |
13376 | if (xri >= phba->sli4_hba.max_cfg_param.max_xri) { | |
13377 | spin_unlock_irq(&phba->hbalock); | |
13378 | return NO_XRI; | |
13379 | } else { | |
13380 | set_bit(xri, phba->sli4_hba.xri_bmask); | |
13381 | phba->sli4_hba.max_cfg_param.xri_used++; | |
6d368e53 | 13382 | } |
6d368e53 JS |
13383 | spin_unlock_irq(&phba->hbalock); |
13384 | return xri; | |
13385 | } | |
13386 | ||
13387 | /** | |
13388 | * lpfc_sli4_free_xri - Release an xri for reuse. | |
13389 | * @phba: pointer to lpfc hba data structure. | |
13390 | * | |
13391 | * This routine is invoked to release an xri to the pool of | |
13392 | * available rpis maintained by the driver. | |
13393 | **/ | |
13394 | void | |
13395 | __lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri) | |
13396 | { | |
13397 | if (test_and_clear_bit(xri, phba->sli4_hba.xri_bmask)) { | |
6d368e53 JS |
13398 | phba->sli4_hba.max_cfg_param.xri_used--; |
13399 | } | |
13400 | } | |
13401 | ||
13402 | /** | |
13403 | * lpfc_sli4_free_xri - Release an xri for reuse. | |
13404 | * @phba: pointer to lpfc hba data structure. | |
13405 | * | |
13406 | * This routine is invoked to release an xri to the pool of | |
13407 | * available rpis maintained by the driver. | |
13408 | **/ | |
13409 | void | |
13410 | lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri) | |
13411 | { | |
13412 | spin_lock_irq(&phba->hbalock); | |
13413 | __lpfc_sli4_free_xri(phba, xri); | |
13414 | spin_unlock_irq(&phba->hbalock); | |
13415 | } | |
13416 | ||
4f774513 JS |
13417 | /** |
13418 | * lpfc_sli4_next_xritag - Get an xritag for the io | |
13419 | * @phba: Pointer to HBA context object. | |
13420 | * | |
13421 | * This function gets an xritag for the iocb. If there is no unused xritag | |
13422 | * it will return 0xffff. | |
13423 | * The function returns the allocated xritag if successful, else returns zero. | |
13424 | * Zero is not a valid xritag. | |
13425 | * The caller is not required to hold any lock. | |
13426 | **/ | |
13427 | uint16_t | |
13428 | lpfc_sli4_next_xritag(struct lpfc_hba *phba) | |
13429 | { | |
6d368e53 | 13430 | uint16_t xri_index; |
4f774513 | 13431 | |
6d368e53 | 13432 | xri_index = lpfc_sli4_alloc_xri(phba); |
81378052 JS |
13433 | if (xri_index == NO_XRI) |
13434 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
13435 | "2004 Failed to allocate XRI.last XRITAG is %d" | |
13436 | " Max XRI is %d, Used XRI is %d\n", | |
13437 | xri_index, | |
13438 | phba->sli4_hba.max_cfg_param.max_xri, | |
13439 | phba->sli4_hba.max_cfg_param.xri_used); | |
13440 | return xri_index; | |
4f774513 JS |
13441 | } |
13442 | ||
13443 | /** | |
6d368e53 | 13444 | * lpfc_sli4_post_els_sgl_list - post a block of ELS sgls to the port. |
4f774513 | 13445 | * @phba: pointer to lpfc hba data structure. |
8a9d2e80 JS |
13446 | * @post_sgl_list: pointer to els sgl entry list. |
13447 | * @count: number of els sgl entries on the list. | |
4f774513 JS |
13448 | * |
13449 | * This routine is invoked to post a block of driver's sgl pages to the | |
13450 | * HBA using non-embedded mailbox command. No Lock is held. This routine | |
13451 | * is only called when the driver is loading and after all IO has been | |
13452 | * stopped. | |
13453 | **/ | |
8a9d2e80 JS |
13454 | static int |
13455 | lpfc_sli4_post_els_sgl_list(struct lpfc_hba *phba, | |
13456 | struct list_head *post_sgl_list, | |
13457 | int post_cnt) | |
4f774513 | 13458 | { |
8a9d2e80 | 13459 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
4f774513 JS |
13460 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; |
13461 | struct sgl_page_pairs *sgl_pg_pairs; | |
13462 | void *viraddr; | |
13463 | LPFC_MBOXQ_t *mbox; | |
13464 | uint32_t reqlen, alloclen, pg_pairs; | |
13465 | uint32_t mbox_tmo; | |
8a9d2e80 JS |
13466 | uint16_t xritag_start = 0; |
13467 | int rc = 0; | |
4f774513 JS |
13468 | uint32_t shdr_status, shdr_add_status; |
13469 | union lpfc_sli4_cfg_shdr *shdr; | |
13470 | ||
8a9d2e80 | 13471 | reqlen = phba->sli4_hba.els_xri_cnt * sizeof(struct sgl_page_pairs) + |
4f774513 | 13472 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); |
49198b37 | 13473 | if (reqlen > SLI4_PAGE_SIZE) { |
4f774513 JS |
13474 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
13475 | "2559 Block sgl registration required DMA " | |
13476 | "size (%d) great than a page\n", reqlen); | |
13477 | return -ENOMEM; | |
13478 | } | |
13479 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
6d368e53 | 13480 | if (!mbox) |
4f774513 | 13481 | return -ENOMEM; |
4f774513 JS |
13482 | |
13483 | /* Allocate DMA memory and set up the non-embedded mailbox command */ | |
13484 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
13485 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen, | |
13486 | LPFC_SLI4_MBX_NEMBED); | |
13487 | ||
13488 | if (alloclen < reqlen) { | |
13489 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
13490 | "0285 Allocated DMA memory size (%d) is " | |
13491 | "less than the requested DMA memory " | |
13492 | "size (%d)\n", alloclen, reqlen); | |
13493 | lpfc_sli4_mbox_cmd_free(phba, mbox); | |
13494 | return -ENOMEM; | |
13495 | } | |
4f774513 | 13496 | /* Set up the SGL pages in the non-embedded DMA pages */ |
6d368e53 | 13497 | viraddr = mbox->sge_array->addr[0]; |
4f774513 JS |
13498 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; |
13499 | sgl_pg_pairs = &sgl->sgl_pg_pairs; | |
13500 | ||
8a9d2e80 JS |
13501 | pg_pairs = 0; |
13502 | list_for_each_entry_safe(sglq_entry, sglq_next, post_sgl_list, list) { | |
4f774513 JS |
13503 | /* Set up the sge entry */ |
13504 | sgl_pg_pairs->sgl_pg0_addr_lo = | |
13505 | cpu_to_le32(putPaddrLow(sglq_entry->phys)); | |
13506 | sgl_pg_pairs->sgl_pg0_addr_hi = | |
13507 | cpu_to_le32(putPaddrHigh(sglq_entry->phys)); | |
13508 | sgl_pg_pairs->sgl_pg1_addr_lo = | |
13509 | cpu_to_le32(putPaddrLow(0)); | |
13510 | sgl_pg_pairs->sgl_pg1_addr_hi = | |
13511 | cpu_to_le32(putPaddrHigh(0)); | |
6d368e53 | 13512 | |
4f774513 JS |
13513 | /* Keep the first xritag on the list */ |
13514 | if (pg_pairs == 0) | |
13515 | xritag_start = sglq_entry->sli4_xritag; | |
13516 | sgl_pg_pairs++; | |
8a9d2e80 | 13517 | pg_pairs++; |
4f774513 | 13518 | } |
6d368e53 JS |
13519 | |
13520 | /* Complete initialization and perform endian conversion. */ | |
4f774513 | 13521 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); |
8a9d2e80 | 13522 | bf_set(lpfc_post_sgl_pages_xricnt, sgl, phba->sli4_hba.els_xri_cnt); |
4f774513 | 13523 | sgl->word0 = cpu_to_le32(sgl->word0); |
4f774513 JS |
13524 | if (!phba->sli4_hba.intr_enable) |
13525 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
13526 | else { | |
a183a15f | 13527 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
4f774513 JS |
13528 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
13529 | } | |
13530 | shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr; | |
13531 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
13532 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
13533 | if (rc != MBX_TIMEOUT) | |
13534 | lpfc_sli4_mbox_cmd_free(phba, mbox); | |
13535 | if (shdr_status || shdr_add_status || rc) { | |
13536 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
13537 | "2513 POST_SGL_BLOCK mailbox command failed " | |
13538 | "status x%x add_status x%x mbx status x%x\n", | |
13539 | shdr_status, shdr_add_status, rc); | |
13540 | rc = -ENXIO; | |
13541 | } | |
13542 | return rc; | |
13543 | } | |
13544 | ||
13545 | /** | |
13546 | * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware | |
13547 | * @phba: pointer to lpfc hba data structure. | |
13548 | * @sblist: pointer to scsi buffer list. | |
13549 | * @count: number of scsi buffers on the list. | |
13550 | * | |
13551 | * This routine is invoked to post a block of @count scsi sgl pages from a | |
13552 | * SCSI buffer list @sblist to the HBA using non-embedded mailbox command. | |
13553 | * No Lock is held. | |
13554 | * | |
13555 | **/ | |
13556 | int | |
8a9d2e80 JS |
13557 | lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba, |
13558 | struct list_head *sblist, | |
13559 | int count) | |
4f774513 JS |
13560 | { |
13561 | struct lpfc_scsi_buf *psb; | |
13562 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; | |
13563 | struct sgl_page_pairs *sgl_pg_pairs; | |
13564 | void *viraddr; | |
13565 | LPFC_MBOXQ_t *mbox; | |
13566 | uint32_t reqlen, alloclen, pg_pairs; | |
13567 | uint32_t mbox_tmo; | |
13568 | uint16_t xritag_start = 0; | |
13569 | int rc = 0; | |
13570 | uint32_t shdr_status, shdr_add_status; | |
13571 | dma_addr_t pdma_phys_bpl1; | |
13572 | union lpfc_sli4_cfg_shdr *shdr; | |
13573 | ||
13574 | /* Calculate the requested length of the dma memory */ | |
8a9d2e80 | 13575 | reqlen = count * sizeof(struct sgl_page_pairs) + |
4f774513 | 13576 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); |
49198b37 | 13577 | if (reqlen > SLI4_PAGE_SIZE) { |
4f774513 JS |
13578 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
13579 | "0217 Block sgl registration required DMA " | |
13580 | "size (%d) great than a page\n", reqlen); | |
13581 | return -ENOMEM; | |
13582 | } | |
13583 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
13584 | if (!mbox) { | |
13585 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
13586 | "0283 Failed to allocate mbox cmd memory\n"); | |
13587 | return -ENOMEM; | |
13588 | } | |
13589 | ||
13590 | /* Allocate DMA memory and set up the non-embedded mailbox command */ | |
13591 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
13592 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen, | |
13593 | LPFC_SLI4_MBX_NEMBED); | |
13594 | ||
13595 | if (alloclen < reqlen) { | |
13596 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
13597 | "2561 Allocated DMA memory size (%d) is " | |
13598 | "less than the requested DMA memory " | |
13599 | "size (%d)\n", alloclen, reqlen); | |
13600 | lpfc_sli4_mbox_cmd_free(phba, mbox); | |
13601 | return -ENOMEM; | |
13602 | } | |
6d368e53 | 13603 | |
4f774513 | 13604 | /* Get the first SGE entry from the non-embedded DMA memory */ |
4f774513 JS |
13605 | viraddr = mbox->sge_array->addr[0]; |
13606 | ||
13607 | /* Set up the SGL pages in the non-embedded DMA pages */ | |
13608 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; | |
13609 | sgl_pg_pairs = &sgl->sgl_pg_pairs; | |
13610 | ||
13611 | pg_pairs = 0; | |
13612 | list_for_each_entry(psb, sblist, list) { | |
13613 | /* Set up the sge entry */ | |
13614 | sgl_pg_pairs->sgl_pg0_addr_lo = | |
13615 | cpu_to_le32(putPaddrLow(psb->dma_phys_bpl)); | |
13616 | sgl_pg_pairs->sgl_pg0_addr_hi = | |
13617 | cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl)); | |
13618 | if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE) | |
13619 | pdma_phys_bpl1 = psb->dma_phys_bpl + SGL_PAGE_SIZE; | |
13620 | else | |
13621 | pdma_phys_bpl1 = 0; | |
13622 | sgl_pg_pairs->sgl_pg1_addr_lo = | |
13623 | cpu_to_le32(putPaddrLow(pdma_phys_bpl1)); | |
13624 | sgl_pg_pairs->sgl_pg1_addr_hi = | |
13625 | cpu_to_le32(putPaddrHigh(pdma_phys_bpl1)); | |
13626 | /* Keep the first xritag on the list */ | |
13627 | if (pg_pairs == 0) | |
13628 | xritag_start = psb->cur_iocbq.sli4_xritag; | |
13629 | sgl_pg_pairs++; | |
13630 | pg_pairs++; | |
13631 | } | |
13632 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); | |
13633 | bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs); | |
13634 | /* Perform endian conversion if necessary */ | |
13635 | sgl->word0 = cpu_to_le32(sgl->word0); | |
13636 | ||
13637 | if (!phba->sli4_hba.intr_enable) | |
13638 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
13639 | else { | |
a183a15f | 13640 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
4f774513 JS |
13641 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
13642 | } | |
13643 | shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr; | |
13644 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
13645 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
13646 | if (rc != MBX_TIMEOUT) | |
13647 | lpfc_sli4_mbox_cmd_free(phba, mbox); | |
13648 | if (shdr_status || shdr_add_status || rc) { | |
13649 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
13650 | "2564 POST_SGL_BLOCK mailbox command failed " | |
13651 | "status x%x add_status x%x mbx status x%x\n", | |
13652 | shdr_status, shdr_add_status, rc); | |
13653 | rc = -ENXIO; | |
13654 | } | |
13655 | return rc; | |
13656 | } | |
13657 | ||
13658 | /** | |
13659 | * lpfc_fc_frame_check - Check that this frame is a valid frame to handle | |
13660 | * @phba: pointer to lpfc_hba struct that the frame was received on | |
13661 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) | |
13662 | * | |
13663 | * This function checks the fields in the @fc_hdr to see if the FC frame is a | |
13664 | * valid type of frame that the LPFC driver will handle. This function will | |
13665 | * return a zero if the frame is a valid frame or a non zero value when the | |
13666 | * frame does not pass the check. | |
13667 | **/ | |
13668 | static int | |
13669 | lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr) | |
13670 | { | |
474ffb74 TH |
13671 | /* make rctl_names static to save stack space */ |
13672 | static char *rctl_names[] = FC_RCTL_NAMES_INIT; | |
4f774513 JS |
13673 | char *type_names[] = FC_TYPE_NAMES_INIT; |
13674 | struct fc_vft_header *fc_vft_hdr; | |
546fc854 | 13675 | uint32_t *header = (uint32_t *) fc_hdr; |
4f774513 JS |
13676 | |
13677 | switch (fc_hdr->fh_r_ctl) { | |
13678 | case FC_RCTL_DD_UNCAT: /* uncategorized information */ | |
13679 | case FC_RCTL_DD_SOL_DATA: /* solicited data */ | |
13680 | case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */ | |
13681 | case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */ | |
13682 | case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */ | |
13683 | case FC_RCTL_DD_DATA_DESC: /* data descriptor */ | |
13684 | case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */ | |
13685 | case FC_RCTL_DD_CMD_STATUS: /* command status */ | |
13686 | case FC_RCTL_ELS_REQ: /* extended link services request */ | |
13687 | case FC_RCTL_ELS_REP: /* extended link services reply */ | |
13688 | case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */ | |
13689 | case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */ | |
13690 | case FC_RCTL_BA_NOP: /* basic link service NOP */ | |
13691 | case FC_RCTL_BA_ABTS: /* basic link service abort */ | |
13692 | case FC_RCTL_BA_RMC: /* remove connection */ | |
13693 | case FC_RCTL_BA_ACC: /* basic accept */ | |
13694 | case FC_RCTL_BA_RJT: /* basic reject */ | |
13695 | case FC_RCTL_BA_PRMT: | |
13696 | case FC_RCTL_ACK_1: /* acknowledge_1 */ | |
13697 | case FC_RCTL_ACK_0: /* acknowledge_0 */ | |
13698 | case FC_RCTL_P_RJT: /* port reject */ | |
13699 | case FC_RCTL_F_RJT: /* fabric reject */ | |
13700 | case FC_RCTL_P_BSY: /* port busy */ | |
13701 | case FC_RCTL_F_BSY: /* fabric busy to data frame */ | |
13702 | case FC_RCTL_F_BSYL: /* fabric busy to link control frame */ | |
13703 | case FC_RCTL_LCR: /* link credit reset */ | |
13704 | case FC_RCTL_END: /* end */ | |
13705 | break; | |
13706 | case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */ | |
13707 | fc_vft_hdr = (struct fc_vft_header *)fc_hdr; | |
13708 | fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1]; | |
13709 | return lpfc_fc_frame_check(phba, fc_hdr); | |
13710 | default: | |
13711 | goto drop; | |
13712 | } | |
13713 | switch (fc_hdr->fh_type) { | |
13714 | case FC_TYPE_BLS: | |
13715 | case FC_TYPE_ELS: | |
13716 | case FC_TYPE_FCP: | |
13717 | case FC_TYPE_CT: | |
13718 | break; | |
13719 | case FC_TYPE_IP: | |
13720 | case FC_TYPE_ILS: | |
13721 | default: | |
13722 | goto drop; | |
13723 | } | |
546fc854 | 13724 | |
4f774513 | 13725 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
546fc854 JS |
13726 | "2538 Received frame rctl:%s type:%s " |
13727 | "Frame Data:%08x %08x %08x %08x %08x %08x\n", | |
4f774513 | 13728 | rctl_names[fc_hdr->fh_r_ctl], |
546fc854 JS |
13729 | type_names[fc_hdr->fh_type], |
13730 | be32_to_cpu(header[0]), be32_to_cpu(header[1]), | |
13731 | be32_to_cpu(header[2]), be32_to_cpu(header[3]), | |
13732 | be32_to_cpu(header[4]), be32_to_cpu(header[5])); | |
4f774513 JS |
13733 | return 0; |
13734 | drop: | |
13735 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS, | |
13736 | "2539 Dropped frame rctl:%s type:%s\n", | |
13737 | rctl_names[fc_hdr->fh_r_ctl], | |
13738 | type_names[fc_hdr->fh_type]); | |
13739 | return 1; | |
13740 | } | |
13741 | ||
13742 | /** | |
13743 | * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame | |
13744 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) | |
13745 | * | |
13746 | * This function processes the FC header to retrieve the VFI from the VF | |
13747 | * header, if one exists. This function will return the VFI if one exists | |
13748 | * or 0 if no VSAN Header exists. | |
13749 | **/ | |
13750 | static uint32_t | |
13751 | lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr) | |
13752 | { | |
13753 | struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr; | |
13754 | ||
13755 | if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH) | |
13756 | return 0; | |
13757 | return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr); | |
13758 | } | |
13759 | ||
13760 | /** | |
13761 | * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to | |
13762 | * @phba: Pointer to the HBA structure to search for the vport on | |
13763 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) | |
13764 | * @fcfi: The FC Fabric ID that the frame came from | |
13765 | * | |
13766 | * This function searches the @phba for a vport that matches the content of the | |
13767 | * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the | |
13768 | * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function | |
13769 | * returns the matching vport pointer or NULL if unable to match frame to a | |
13770 | * vport. | |
13771 | **/ | |
13772 | static struct lpfc_vport * | |
13773 | lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr, | |
13774 | uint16_t fcfi) | |
13775 | { | |
13776 | struct lpfc_vport **vports; | |
13777 | struct lpfc_vport *vport = NULL; | |
13778 | int i; | |
13779 | uint32_t did = (fc_hdr->fh_d_id[0] << 16 | | |
13780 | fc_hdr->fh_d_id[1] << 8 | | |
13781 | fc_hdr->fh_d_id[2]); | |
939723a4 | 13782 | |
bf08611b JS |
13783 | if (did == Fabric_DID) |
13784 | return phba->pport; | |
939723a4 JS |
13785 | if ((phba->pport->fc_flag & FC_PT2PT) && |
13786 | !(phba->link_state == LPFC_HBA_READY)) | |
13787 | return phba->pport; | |
13788 | ||
4f774513 JS |
13789 | vports = lpfc_create_vport_work_array(phba); |
13790 | if (vports != NULL) | |
13791 | for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) { | |
13792 | if (phba->fcf.fcfi == fcfi && | |
13793 | vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) && | |
13794 | vports[i]->fc_myDID == did) { | |
13795 | vport = vports[i]; | |
13796 | break; | |
13797 | } | |
13798 | } | |
13799 | lpfc_destroy_vport_work_array(phba, vports); | |
13800 | return vport; | |
13801 | } | |
13802 | ||
45ed1190 JS |
13803 | /** |
13804 | * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp | |
13805 | * @vport: The vport to work on. | |
13806 | * | |
13807 | * This function updates the receive sequence time stamp for this vport. The | |
13808 | * receive sequence time stamp indicates the time that the last frame of the | |
13809 | * the sequence that has been idle for the longest amount of time was received. | |
13810 | * the driver uses this time stamp to indicate if any received sequences have | |
13811 | * timed out. | |
13812 | **/ | |
13813 | void | |
13814 | lpfc_update_rcv_time_stamp(struct lpfc_vport *vport) | |
13815 | { | |
13816 | struct lpfc_dmabuf *h_buf; | |
13817 | struct hbq_dmabuf *dmabuf = NULL; | |
13818 | ||
13819 | /* get the oldest sequence on the rcv list */ | |
13820 | h_buf = list_get_first(&vport->rcv_buffer_list, | |
13821 | struct lpfc_dmabuf, list); | |
13822 | if (!h_buf) | |
13823 | return; | |
13824 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); | |
13825 | vport->rcv_buffer_time_stamp = dmabuf->time_stamp; | |
13826 | } | |
13827 | ||
13828 | /** | |
13829 | * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences. | |
13830 | * @vport: The vport that the received sequences were sent to. | |
13831 | * | |
13832 | * This function cleans up all outstanding received sequences. This is called | |
13833 | * by the driver when a link event or user action invalidates all the received | |
13834 | * sequences. | |
13835 | **/ | |
13836 | void | |
13837 | lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport) | |
13838 | { | |
13839 | struct lpfc_dmabuf *h_buf, *hnext; | |
13840 | struct lpfc_dmabuf *d_buf, *dnext; | |
13841 | struct hbq_dmabuf *dmabuf = NULL; | |
13842 | ||
13843 | /* start with the oldest sequence on the rcv list */ | |
13844 | list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) { | |
13845 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); | |
13846 | list_del_init(&dmabuf->hbuf.list); | |
13847 | list_for_each_entry_safe(d_buf, dnext, | |
13848 | &dmabuf->dbuf.list, list) { | |
13849 | list_del_init(&d_buf->list); | |
13850 | lpfc_in_buf_free(vport->phba, d_buf); | |
13851 | } | |
13852 | lpfc_in_buf_free(vport->phba, &dmabuf->dbuf); | |
13853 | } | |
13854 | } | |
13855 | ||
13856 | /** | |
13857 | * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences. | |
13858 | * @vport: The vport that the received sequences were sent to. | |
13859 | * | |
13860 | * This function determines whether any received sequences have timed out by | |
13861 | * first checking the vport's rcv_buffer_time_stamp. If this time_stamp | |
13862 | * indicates that there is at least one timed out sequence this routine will | |
13863 | * go through the received sequences one at a time from most inactive to most | |
13864 | * active to determine which ones need to be cleaned up. Once it has determined | |
13865 | * that a sequence needs to be cleaned up it will simply free up the resources | |
13866 | * without sending an abort. | |
13867 | **/ | |
13868 | void | |
13869 | lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport) | |
13870 | { | |
13871 | struct lpfc_dmabuf *h_buf, *hnext; | |
13872 | struct lpfc_dmabuf *d_buf, *dnext; | |
13873 | struct hbq_dmabuf *dmabuf = NULL; | |
13874 | unsigned long timeout; | |
13875 | int abort_count = 0; | |
13876 | ||
13877 | timeout = (msecs_to_jiffies(vport->phba->fc_edtov) + | |
13878 | vport->rcv_buffer_time_stamp); | |
13879 | if (list_empty(&vport->rcv_buffer_list) || | |
13880 | time_before(jiffies, timeout)) | |
13881 | return; | |
13882 | /* start with the oldest sequence on the rcv list */ | |
13883 | list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) { | |
13884 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); | |
13885 | timeout = (msecs_to_jiffies(vport->phba->fc_edtov) + | |
13886 | dmabuf->time_stamp); | |
13887 | if (time_before(jiffies, timeout)) | |
13888 | break; | |
13889 | abort_count++; | |
13890 | list_del_init(&dmabuf->hbuf.list); | |
13891 | list_for_each_entry_safe(d_buf, dnext, | |
13892 | &dmabuf->dbuf.list, list) { | |
13893 | list_del_init(&d_buf->list); | |
13894 | lpfc_in_buf_free(vport->phba, d_buf); | |
13895 | } | |
13896 | lpfc_in_buf_free(vport->phba, &dmabuf->dbuf); | |
13897 | } | |
13898 | if (abort_count) | |
13899 | lpfc_update_rcv_time_stamp(vport); | |
13900 | } | |
13901 | ||
4f774513 JS |
13902 | /** |
13903 | * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences | |
13904 | * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame | |
13905 | * | |
13906 | * This function searches through the existing incomplete sequences that have | |
13907 | * been sent to this @vport. If the frame matches one of the incomplete | |
13908 | * sequences then the dbuf in the @dmabuf is added to the list of frames that | |
13909 | * make up that sequence. If no sequence is found that matches this frame then | |
13910 | * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list | |
13911 | * This function returns a pointer to the first dmabuf in the sequence list that | |
13912 | * the frame was linked to. | |
13913 | **/ | |
13914 | static struct hbq_dmabuf * | |
13915 | lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf) | |
13916 | { | |
13917 | struct fc_frame_header *new_hdr; | |
13918 | struct fc_frame_header *temp_hdr; | |
13919 | struct lpfc_dmabuf *d_buf; | |
13920 | struct lpfc_dmabuf *h_buf; | |
13921 | struct hbq_dmabuf *seq_dmabuf = NULL; | |
13922 | struct hbq_dmabuf *temp_dmabuf = NULL; | |
13923 | ||
4d9ab994 | 13924 | INIT_LIST_HEAD(&dmabuf->dbuf.list); |
45ed1190 | 13925 | dmabuf->time_stamp = jiffies; |
4f774513 JS |
13926 | new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
13927 | /* Use the hdr_buf to find the sequence that this frame belongs to */ | |
13928 | list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) { | |
13929 | temp_hdr = (struct fc_frame_header *)h_buf->virt; | |
13930 | if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) || | |
13931 | (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) || | |
13932 | (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3))) | |
13933 | continue; | |
13934 | /* found a pending sequence that matches this frame */ | |
13935 | seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); | |
13936 | break; | |
13937 | } | |
13938 | if (!seq_dmabuf) { | |
13939 | /* | |
13940 | * This indicates first frame received for this sequence. | |
13941 | * Queue the buffer on the vport's rcv_buffer_list. | |
13942 | */ | |
13943 | list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list); | |
45ed1190 | 13944 | lpfc_update_rcv_time_stamp(vport); |
4f774513 JS |
13945 | return dmabuf; |
13946 | } | |
13947 | temp_hdr = seq_dmabuf->hbuf.virt; | |
eeead811 JS |
13948 | if (be16_to_cpu(new_hdr->fh_seq_cnt) < |
13949 | be16_to_cpu(temp_hdr->fh_seq_cnt)) { | |
4d9ab994 JS |
13950 | list_del_init(&seq_dmabuf->hbuf.list); |
13951 | list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list); | |
13952 | list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list); | |
45ed1190 | 13953 | lpfc_update_rcv_time_stamp(vport); |
4f774513 JS |
13954 | return dmabuf; |
13955 | } | |
45ed1190 JS |
13956 | /* move this sequence to the tail to indicate a young sequence */ |
13957 | list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list); | |
13958 | seq_dmabuf->time_stamp = jiffies; | |
13959 | lpfc_update_rcv_time_stamp(vport); | |
eeead811 JS |
13960 | if (list_empty(&seq_dmabuf->dbuf.list)) { |
13961 | temp_hdr = dmabuf->hbuf.virt; | |
13962 | list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list); | |
13963 | return seq_dmabuf; | |
13964 | } | |
4f774513 JS |
13965 | /* find the correct place in the sequence to insert this frame */ |
13966 | list_for_each_entry_reverse(d_buf, &seq_dmabuf->dbuf.list, list) { | |
13967 | temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf); | |
13968 | temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt; | |
13969 | /* | |
13970 | * If the frame's sequence count is greater than the frame on | |
13971 | * the list then insert the frame right after this frame | |
13972 | */ | |
eeead811 JS |
13973 | if (be16_to_cpu(new_hdr->fh_seq_cnt) > |
13974 | be16_to_cpu(temp_hdr->fh_seq_cnt)) { | |
4f774513 JS |
13975 | list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list); |
13976 | return seq_dmabuf; | |
13977 | } | |
13978 | } | |
13979 | return NULL; | |
13980 | } | |
13981 | ||
6669f9bb JS |
13982 | /** |
13983 | * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence | |
13984 | * @vport: pointer to a vitural port | |
13985 | * @dmabuf: pointer to a dmabuf that describes the FC sequence | |
13986 | * | |
13987 | * This function tries to abort from the partially assembed sequence, described | |
13988 | * by the information from basic abbort @dmabuf. It checks to see whether such | |
13989 | * partially assembled sequence held by the driver. If so, it shall free up all | |
13990 | * the frames from the partially assembled sequence. | |
13991 | * | |
13992 | * Return | |
13993 | * true -- if there is matching partially assembled sequence present and all | |
13994 | * the frames freed with the sequence; | |
13995 | * false -- if there is no matching partially assembled sequence present so | |
13996 | * nothing got aborted in the lower layer driver | |
13997 | **/ | |
13998 | static bool | |
13999 | lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport, | |
14000 | struct hbq_dmabuf *dmabuf) | |
14001 | { | |
14002 | struct fc_frame_header *new_hdr; | |
14003 | struct fc_frame_header *temp_hdr; | |
14004 | struct lpfc_dmabuf *d_buf, *n_buf, *h_buf; | |
14005 | struct hbq_dmabuf *seq_dmabuf = NULL; | |
14006 | ||
14007 | /* Use the hdr_buf to find the sequence that matches this frame */ | |
14008 | INIT_LIST_HEAD(&dmabuf->dbuf.list); | |
14009 | INIT_LIST_HEAD(&dmabuf->hbuf.list); | |
14010 | new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; | |
14011 | list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) { | |
14012 | temp_hdr = (struct fc_frame_header *)h_buf->virt; | |
14013 | if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) || | |
14014 | (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) || | |
14015 | (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3))) | |
14016 | continue; | |
14017 | /* found a pending sequence that matches this frame */ | |
14018 | seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); | |
14019 | break; | |
14020 | } | |
14021 | ||
14022 | /* Free up all the frames from the partially assembled sequence */ | |
14023 | if (seq_dmabuf) { | |
14024 | list_for_each_entry_safe(d_buf, n_buf, | |
14025 | &seq_dmabuf->dbuf.list, list) { | |
14026 | list_del_init(&d_buf->list); | |
14027 | lpfc_in_buf_free(vport->phba, d_buf); | |
14028 | } | |
14029 | return true; | |
14030 | } | |
14031 | return false; | |
14032 | } | |
14033 | ||
14034 | /** | |
546fc854 | 14035 | * lpfc_sli4_seq_abort_rsp_cmpl - BLS ABORT RSP seq abort iocb complete handler |
6669f9bb JS |
14036 | * @phba: Pointer to HBA context object. |
14037 | * @cmd_iocbq: pointer to the command iocbq structure. | |
14038 | * @rsp_iocbq: pointer to the response iocbq structure. | |
14039 | * | |
546fc854 | 14040 | * This function handles the sequence abort response iocb command complete |
6669f9bb JS |
14041 | * event. It properly releases the memory allocated to the sequence abort |
14042 | * accept iocb. | |
14043 | **/ | |
14044 | static void | |
546fc854 | 14045 | lpfc_sli4_seq_abort_rsp_cmpl(struct lpfc_hba *phba, |
6669f9bb JS |
14046 | struct lpfc_iocbq *cmd_iocbq, |
14047 | struct lpfc_iocbq *rsp_iocbq) | |
14048 | { | |
14049 | if (cmd_iocbq) | |
14050 | lpfc_sli_release_iocbq(phba, cmd_iocbq); | |
6b5151fd JS |
14051 | |
14052 | /* Failure means BLS ABORT RSP did not get delivered to remote node*/ | |
14053 | if (rsp_iocbq && rsp_iocbq->iocb.ulpStatus) | |
14054 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
14055 | "3154 BLS ABORT RSP failed, data: x%x/x%x\n", | |
14056 | rsp_iocbq->iocb.ulpStatus, | |
14057 | rsp_iocbq->iocb.un.ulpWord[4]); | |
6669f9bb JS |
14058 | } |
14059 | ||
6d368e53 JS |
14060 | /** |
14061 | * lpfc_sli4_xri_inrange - check xri is in range of xris owned by driver. | |
14062 | * @phba: Pointer to HBA context object. | |
14063 | * @xri: xri id in transaction. | |
14064 | * | |
14065 | * This function validates the xri maps to the known range of XRIs allocated an | |
14066 | * used by the driver. | |
14067 | **/ | |
7851fe2c | 14068 | uint16_t |
6d368e53 JS |
14069 | lpfc_sli4_xri_inrange(struct lpfc_hba *phba, |
14070 | uint16_t xri) | |
14071 | { | |
14072 | int i; | |
14073 | ||
14074 | for (i = 0; i < phba->sli4_hba.max_cfg_param.max_xri; i++) { | |
14075 | if (xri == phba->sli4_hba.xri_ids[i]) | |
14076 | return i; | |
14077 | } | |
14078 | return NO_XRI; | |
14079 | } | |
14080 | ||
6669f9bb | 14081 | /** |
546fc854 | 14082 | * lpfc_sli4_seq_abort_rsp - bls rsp to sequence abort |
6669f9bb JS |
14083 | * @phba: Pointer to HBA context object. |
14084 | * @fc_hdr: pointer to a FC frame header. | |
14085 | * | |
546fc854 | 14086 | * This function sends a basic response to a previous unsol sequence abort |
6669f9bb JS |
14087 | * event after aborting the sequence handling. |
14088 | **/ | |
14089 | static void | |
546fc854 | 14090 | lpfc_sli4_seq_abort_rsp(struct lpfc_hba *phba, |
6669f9bb JS |
14091 | struct fc_frame_header *fc_hdr) |
14092 | { | |
14093 | struct lpfc_iocbq *ctiocb = NULL; | |
14094 | struct lpfc_nodelist *ndlp; | |
ee0f4fe1 | 14095 | uint16_t oxid, rxid, xri, lxri; |
5ffc266e | 14096 | uint32_t sid, fctl; |
6669f9bb | 14097 | IOCB_t *icmd; |
546fc854 | 14098 | int rc; |
6669f9bb JS |
14099 | |
14100 | if (!lpfc_is_link_up(phba)) | |
14101 | return; | |
14102 | ||
14103 | sid = sli4_sid_from_fc_hdr(fc_hdr); | |
14104 | oxid = be16_to_cpu(fc_hdr->fh_ox_id); | |
5ffc266e | 14105 | rxid = be16_to_cpu(fc_hdr->fh_rx_id); |
6669f9bb JS |
14106 | |
14107 | ndlp = lpfc_findnode_did(phba->pport, sid); | |
14108 | if (!ndlp) { | |
14109 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS, | |
14110 | "1268 Find ndlp returned NULL for oxid:x%x " | |
14111 | "SID:x%x\n", oxid, sid); | |
14112 | return; | |
14113 | } | |
14114 | ||
546fc854 | 14115 | /* Allocate buffer for rsp iocb */ |
6669f9bb JS |
14116 | ctiocb = lpfc_sli_get_iocbq(phba); |
14117 | if (!ctiocb) | |
14118 | return; | |
14119 | ||
5ffc266e JS |
14120 | /* Extract the F_CTL field from FC_HDR */ |
14121 | fctl = sli4_fctl_from_fc_hdr(fc_hdr); | |
14122 | ||
6669f9bb | 14123 | icmd = &ctiocb->iocb; |
6669f9bb | 14124 | icmd->un.xseq64.bdl.bdeSize = 0; |
5ffc266e | 14125 | icmd->un.xseq64.bdl.ulpIoTag32 = 0; |
6669f9bb JS |
14126 | icmd->un.xseq64.w5.hcsw.Dfctl = 0; |
14127 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC; | |
14128 | icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS; | |
14129 | ||
14130 | /* Fill in the rest of iocb fields */ | |
14131 | icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX; | |
14132 | icmd->ulpBdeCount = 0; | |
14133 | icmd->ulpLe = 1; | |
14134 | icmd->ulpClass = CLASS3; | |
6d368e53 | 14135 | icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]; |
be858b65 | 14136 | ctiocb->context1 = ndlp; |
6669f9bb | 14137 | |
6669f9bb JS |
14138 | ctiocb->iocb_cmpl = NULL; |
14139 | ctiocb->vport = phba->pport; | |
546fc854 | 14140 | ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_rsp_cmpl; |
6d368e53 | 14141 | ctiocb->sli4_lxritag = NO_XRI; |
546fc854 JS |
14142 | ctiocb->sli4_xritag = NO_XRI; |
14143 | ||
ee0f4fe1 JS |
14144 | if (fctl & FC_FC_EX_CTX) |
14145 | /* Exchange responder sent the abort so we | |
14146 | * own the oxid. | |
14147 | */ | |
14148 | xri = oxid; | |
14149 | else | |
14150 | xri = rxid; | |
14151 | lxri = lpfc_sli4_xri_inrange(phba, xri); | |
14152 | if (lxri != NO_XRI) | |
14153 | lpfc_set_rrq_active(phba, ndlp, lxri, | |
14154 | (xri == oxid) ? rxid : oxid, 0); | |
546fc854 JS |
14155 | /* If the oxid maps to the FCP XRI range or if it is out of range, |
14156 | * send a BLS_RJT. The driver no longer has that exchange. | |
14157 | * Override the IOCB for a BA_RJT. | |
14158 | */ | |
ee0f4fe1 | 14159 | if (xri > (phba->sli4_hba.max_cfg_param.max_xri + |
546fc854 | 14160 | phba->sli4_hba.max_cfg_param.xri_base) || |
ee0f4fe1 | 14161 | xri > (lpfc_sli4_get_els_iocb_cnt(phba) + |
546fc854 JS |
14162 | phba->sli4_hba.max_cfg_param.xri_base)) { |
14163 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT; | |
14164 | bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0); | |
14165 | bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID); | |
14166 | bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE); | |
14167 | } | |
6669f9bb | 14168 | |
5ffc266e JS |
14169 | if (fctl & FC_FC_EX_CTX) { |
14170 | /* ABTS sent by responder to CT exchange, construction | |
14171 | * of BA_ACC will use OX_ID from ABTS for the XRI_TAG | |
14172 | * field and RX_ID from ABTS for RX_ID field. | |
14173 | */ | |
546fc854 | 14174 | bf_set(lpfc_abts_orig, &icmd->un.bls_rsp, LPFC_ABTS_UNSOL_RSP); |
5ffc266e JS |
14175 | } else { |
14176 | /* ABTS sent by initiator to CT exchange, construction | |
14177 | * of BA_ACC will need to allocate a new XRI as for the | |
f09c3acc | 14178 | * XRI_TAG field. |
5ffc266e | 14179 | */ |
546fc854 | 14180 | bf_set(lpfc_abts_orig, &icmd->un.bls_rsp, LPFC_ABTS_UNSOL_INT); |
5ffc266e | 14181 | } |
f09c3acc | 14182 | bf_set(lpfc_abts_rxid, &icmd->un.bls_rsp, rxid); |
546fc854 | 14183 | bf_set(lpfc_abts_oxid, &icmd->un.bls_rsp, oxid); |
5ffc266e | 14184 | |
546fc854 | 14185 | /* Xmit CT abts response on exchange <xid> */ |
6669f9bb | 14186 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
546fc854 JS |
14187 | "1200 Send BLS cmd x%x on oxid x%x Data: x%x\n", |
14188 | icmd->un.xseq64.w5.hcsw.Rctl, oxid, phba->link_state); | |
14189 | ||
14190 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0); | |
14191 | if (rc == IOCB_ERROR) { | |
14192 | lpfc_printf_log(phba, KERN_ERR, LOG_ELS, | |
14193 | "2925 Failed to issue CT ABTS RSP x%x on " | |
14194 | "xri x%x, Data x%x\n", | |
14195 | icmd->un.xseq64.w5.hcsw.Rctl, oxid, | |
14196 | phba->link_state); | |
14197 | lpfc_sli_release_iocbq(phba, ctiocb); | |
14198 | } | |
6669f9bb JS |
14199 | } |
14200 | ||
14201 | /** | |
14202 | * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event | |
14203 | * @vport: Pointer to the vport on which this sequence was received | |
14204 | * @dmabuf: pointer to a dmabuf that describes the FC sequence | |
14205 | * | |
14206 | * This function handles an SLI-4 unsolicited abort event. If the unsolicited | |
14207 | * receive sequence is only partially assembed by the driver, it shall abort | |
14208 | * the partially assembled frames for the sequence. Otherwise, if the | |
14209 | * unsolicited receive sequence has been completely assembled and passed to | |
14210 | * the Upper Layer Protocol (UPL), it then mark the per oxid status for the | |
14211 | * unsolicited sequence has been aborted. After that, it will issue a basic | |
14212 | * accept to accept the abort. | |
14213 | **/ | |
14214 | void | |
14215 | lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport, | |
14216 | struct hbq_dmabuf *dmabuf) | |
14217 | { | |
14218 | struct lpfc_hba *phba = vport->phba; | |
14219 | struct fc_frame_header fc_hdr; | |
5ffc266e | 14220 | uint32_t fctl; |
6669f9bb JS |
14221 | bool abts_par; |
14222 | ||
6669f9bb JS |
14223 | /* Make a copy of fc_hdr before the dmabuf being released */ |
14224 | memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header)); | |
5ffc266e | 14225 | fctl = sli4_fctl_from_fc_hdr(&fc_hdr); |
6669f9bb | 14226 | |
5ffc266e JS |
14227 | if (fctl & FC_FC_EX_CTX) { |
14228 | /* | |
14229 | * ABTS sent by responder to exchange, just free the buffer | |
14230 | */ | |
6669f9bb | 14231 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
5ffc266e JS |
14232 | } else { |
14233 | /* | |
14234 | * ABTS sent by initiator to exchange, need to do cleanup | |
14235 | */ | |
14236 | /* Try to abort partially assembled seq */ | |
14237 | abts_par = lpfc_sli4_abort_partial_seq(vport, dmabuf); | |
14238 | ||
14239 | /* Send abort to ULP if partially seq abort failed */ | |
14240 | if (abts_par == false) | |
14241 | lpfc_sli4_send_seq_to_ulp(vport, dmabuf); | |
14242 | else | |
14243 | lpfc_in_buf_free(phba, &dmabuf->dbuf); | |
14244 | } | |
6669f9bb | 14245 | /* Send basic accept (BA_ACC) to the abort requester */ |
546fc854 | 14246 | lpfc_sli4_seq_abort_rsp(phba, &fc_hdr); |
6669f9bb JS |
14247 | } |
14248 | ||
4f774513 JS |
14249 | /** |
14250 | * lpfc_seq_complete - Indicates if a sequence is complete | |
14251 | * @dmabuf: pointer to a dmabuf that describes the FC sequence | |
14252 | * | |
14253 | * This function checks the sequence, starting with the frame described by | |
14254 | * @dmabuf, to see if all the frames associated with this sequence are present. | |
14255 | * the frames associated with this sequence are linked to the @dmabuf using the | |
14256 | * dbuf list. This function looks for two major things. 1) That the first frame | |
14257 | * has a sequence count of zero. 2) There is a frame with last frame of sequence | |
14258 | * set. 3) That there are no holes in the sequence count. The function will | |
14259 | * return 1 when the sequence is complete, otherwise it will return 0. | |
14260 | **/ | |
14261 | static int | |
14262 | lpfc_seq_complete(struct hbq_dmabuf *dmabuf) | |
14263 | { | |
14264 | struct fc_frame_header *hdr; | |
14265 | struct lpfc_dmabuf *d_buf; | |
14266 | struct hbq_dmabuf *seq_dmabuf; | |
14267 | uint32_t fctl; | |
14268 | int seq_count = 0; | |
14269 | ||
14270 | hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; | |
14271 | /* make sure first fame of sequence has a sequence count of zero */ | |
14272 | if (hdr->fh_seq_cnt != seq_count) | |
14273 | return 0; | |
14274 | fctl = (hdr->fh_f_ctl[0] << 16 | | |
14275 | hdr->fh_f_ctl[1] << 8 | | |
14276 | hdr->fh_f_ctl[2]); | |
14277 | /* If last frame of sequence we can return success. */ | |
14278 | if (fctl & FC_FC_END_SEQ) | |
14279 | return 1; | |
14280 | list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) { | |
14281 | seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf); | |
14282 | hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; | |
14283 | /* If there is a hole in the sequence count then fail. */ | |
eeead811 | 14284 | if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt)) |
4f774513 JS |
14285 | return 0; |
14286 | fctl = (hdr->fh_f_ctl[0] << 16 | | |
14287 | hdr->fh_f_ctl[1] << 8 | | |
14288 | hdr->fh_f_ctl[2]); | |
14289 | /* If last frame of sequence we can return success. */ | |
14290 | if (fctl & FC_FC_END_SEQ) | |
14291 | return 1; | |
14292 | } | |
14293 | return 0; | |
14294 | } | |
14295 | ||
14296 | /** | |
14297 | * lpfc_prep_seq - Prep sequence for ULP processing | |
14298 | * @vport: Pointer to the vport on which this sequence was received | |
14299 | * @dmabuf: pointer to a dmabuf that describes the FC sequence | |
14300 | * | |
14301 | * This function takes a sequence, described by a list of frames, and creates | |
14302 | * a list of iocbq structures to describe the sequence. This iocbq list will be | |
14303 | * used to issue to the generic unsolicited sequence handler. This routine | |
14304 | * returns a pointer to the first iocbq in the list. If the function is unable | |
14305 | * to allocate an iocbq then it throw out the received frames that were not | |
14306 | * able to be described and return a pointer to the first iocbq. If unable to | |
14307 | * allocate any iocbqs (including the first) this function will return NULL. | |
14308 | **/ | |
14309 | static struct lpfc_iocbq * | |
14310 | lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf) | |
14311 | { | |
7851fe2c | 14312 | struct hbq_dmabuf *hbq_buf; |
4f774513 JS |
14313 | struct lpfc_dmabuf *d_buf, *n_buf; |
14314 | struct lpfc_iocbq *first_iocbq, *iocbq; | |
14315 | struct fc_frame_header *fc_hdr; | |
14316 | uint32_t sid; | |
7851fe2c | 14317 | uint32_t len, tot_len; |
eeead811 | 14318 | struct ulp_bde64 *pbde; |
4f774513 JS |
14319 | |
14320 | fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; | |
14321 | /* remove from receive buffer list */ | |
14322 | list_del_init(&seq_dmabuf->hbuf.list); | |
45ed1190 | 14323 | lpfc_update_rcv_time_stamp(vport); |
4f774513 | 14324 | /* get the Remote Port's SID */ |
6669f9bb | 14325 | sid = sli4_sid_from_fc_hdr(fc_hdr); |
7851fe2c | 14326 | tot_len = 0; |
4f774513 JS |
14327 | /* Get an iocbq struct to fill in. */ |
14328 | first_iocbq = lpfc_sli_get_iocbq(vport->phba); | |
14329 | if (first_iocbq) { | |
14330 | /* Initialize the first IOCB. */ | |
8fa38513 | 14331 | first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0; |
4f774513 | 14332 | first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS; |
939723a4 JS |
14333 | |
14334 | /* Check FC Header to see what TYPE of frame we are rcv'ing */ | |
14335 | if (sli4_type_from_fc_hdr(fc_hdr) == FC_TYPE_ELS) { | |
14336 | first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_ELS64_CX; | |
14337 | first_iocbq->iocb.un.rcvels.parmRo = | |
14338 | sli4_did_from_fc_hdr(fc_hdr); | |
14339 | first_iocbq->iocb.ulpPU = PARM_NPIV_DID; | |
14340 | } else | |
14341 | first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX; | |
7851fe2c JS |
14342 | first_iocbq->iocb.ulpContext = NO_XRI; |
14343 | first_iocbq->iocb.unsli3.rcvsli3.ox_id = | |
14344 | be16_to_cpu(fc_hdr->fh_ox_id); | |
14345 | /* iocbq is prepped for internal consumption. Physical vpi. */ | |
14346 | first_iocbq->iocb.unsli3.rcvsli3.vpi = | |
14347 | vport->phba->vpi_ids[vport->vpi]; | |
4f774513 JS |
14348 | /* put the first buffer into the first IOCBq */ |
14349 | first_iocbq->context2 = &seq_dmabuf->dbuf; | |
14350 | first_iocbq->context3 = NULL; | |
14351 | first_iocbq->iocb.ulpBdeCount = 1; | |
14352 | first_iocbq->iocb.un.cont64[0].tus.f.bdeSize = | |
14353 | LPFC_DATA_BUF_SIZE; | |
14354 | first_iocbq->iocb.un.rcvels.remoteID = sid; | |
7851fe2c | 14355 | tot_len = bf_get(lpfc_rcqe_length, |
4d9ab994 | 14356 | &seq_dmabuf->cq_event.cqe.rcqe_cmpl); |
7851fe2c | 14357 | first_iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len; |
4f774513 JS |
14358 | } |
14359 | iocbq = first_iocbq; | |
14360 | /* | |
14361 | * Each IOCBq can have two Buffers assigned, so go through the list | |
14362 | * of buffers for this sequence and save two buffers in each IOCBq | |
14363 | */ | |
14364 | list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) { | |
14365 | if (!iocbq) { | |
14366 | lpfc_in_buf_free(vport->phba, d_buf); | |
14367 | continue; | |
14368 | } | |
14369 | if (!iocbq->context3) { | |
14370 | iocbq->context3 = d_buf; | |
14371 | iocbq->iocb.ulpBdeCount++; | |
eeead811 JS |
14372 | pbde = (struct ulp_bde64 *) |
14373 | &iocbq->iocb.unsli3.sli3Words[4]; | |
14374 | pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE; | |
7851fe2c JS |
14375 | |
14376 | /* We need to get the size out of the right CQE */ | |
14377 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); | |
14378 | len = bf_get(lpfc_rcqe_length, | |
14379 | &hbq_buf->cq_event.cqe.rcqe_cmpl); | |
14380 | iocbq->iocb.unsli3.rcvsli3.acc_len += len; | |
14381 | tot_len += len; | |
4f774513 JS |
14382 | } else { |
14383 | iocbq = lpfc_sli_get_iocbq(vport->phba); | |
14384 | if (!iocbq) { | |
14385 | if (first_iocbq) { | |
14386 | first_iocbq->iocb.ulpStatus = | |
14387 | IOSTAT_FCP_RSP_ERROR; | |
14388 | first_iocbq->iocb.un.ulpWord[4] = | |
14389 | IOERR_NO_RESOURCES; | |
14390 | } | |
14391 | lpfc_in_buf_free(vport->phba, d_buf); | |
14392 | continue; | |
14393 | } | |
14394 | iocbq->context2 = d_buf; | |
14395 | iocbq->context3 = NULL; | |
14396 | iocbq->iocb.ulpBdeCount = 1; | |
14397 | iocbq->iocb.un.cont64[0].tus.f.bdeSize = | |
14398 | LPFC_DATA_BUF_SIZE; | |
7851fe2c JS |
14399 | |
14400 | /* We need to get the size out of the right CQE */ | |
14401 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); | |
14402 | len = bf_get(lpfc_rcqe_length, | |
14403 | &hbq_buf->cq_event.cqe.rcqe_cmpl); | |
14404 | tot_len += len; | |
14405 | iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len; | |
14406 | ||
4f774513 JS |
14407 | iocbq->iocb.un.rcvels.remoteID = sid; |
14408 | list_add_tail(&iocbq->list, &first_iocbq->list); | |
14409 | } | |
14410 | } | |
14411 | return first_iocbq; | |
14412 | } | |
14413 | ||
6669f9bb JS |
14414 | static void |
14415 | lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport, | |
14416 | struct hbq_dmabuf *seq_dmabuf) | |
14417 | { | |
14418 | struct fc_frame_header *fc_hdr; | |
14419 | struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb; | |
14420 | struct lpfc_hba *phba = vport->phba; | |
14421 | ||
14422 | fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; | |
14423 | iocbq = lpfc_prep_seq(vport, seq_dmabuf); | |
14424 | if (!iocbq) { | |
14425 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
14426 | "2707 Ring %d handler: Failed to allocate " | |
14427 | "iocb Rctl x%x Type x%x received\n", | |
14428 | LPFC_ELS_RING, | |
14429 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); | |
14430 | return; | |
14431 | } | |
14432 | if (!lpfc_complete_unsol_iocb(phba, | |
14433 | &phba->sli.ring[LPFC_ELS_RING], | |
14434 | iocbq, fc_hdr->fh_r_ctl, | |
14435 | fc_hdr->fh_type)) | |
6d368e53 | 14436 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
6669f9bb JS |
14437 | "2540 Ring %d handler: unexpected Rctl " |
14438 | "x%x Type x%x received\n", | |
14439 | LPFC_ELS_RING, | |
14440 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); | |
14441 | ||
14442 | /* Free iocb created in lpfc_prep_seq */ | |
14443 | list_for_each_entry_safe(curr_iocb, next_iocb, | |
14444 | &iocbq->list, list) { | |
14445 | list_del_init(&curr_iocb->list); | |
14446 | lpfc_sli_release_iocbq(phba, curr_iocb); | |
14447 | } | |
14448 | lpfc_sli_release_iocbq(phba, iocbq); | |
14449 | } | |
14450 | ||
4f774513 JS |
14451 | /** |
14452 | * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware | |
14453 | * @phba: Pointer to HBA context object. | |
14454 | * | |
14455 | * This function is called with no lock held. This function processes all | |
14456 | * the received buffers and gives it to upper layers when a received buffer | |
14457 | * indicates that it is the final frame in the sequence. The interrupt | |
14458 | * service routine processes received buffers at interrupt contexts and adds | |
14459 | * received dma buffers to the rb_pend_list queue and signals the worker thread. | |
14460 | * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the | |
14461 | * appropriate receive function when the final frame in a sequence is received. | |
14462 | **/ | |
4d9ab994 JS |
14463 | void |
14464 | lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba, | |
14465 | struct hbq_dmabuf *dmabuf) | |
4f774513 | 14466 | { |
4d9ab994 | 14467 | struct hbq_dmabuf *seq_dmabuf; |
4f774513 JS |
14468 | struct fc_frame_header *fc_hdr; |
14469 | struct lpfc_vport *vport; | |
14470 | uint32_t fcfi; | |
939723a4 | 14471 | uint32_t did; |
4f774513 | 14472 | |
4f774513 | 14473 | /* Process each received buffer */ |
4d9ab994 JS |
14474 | fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
14475 | /* check to see if this a valid type of frame */ | |
14476 | if (lpfc_fc_frame_check(phba, fc_hdr)) { | |
14477 | lpfc_in_buf_free(phba, &dmabuf->dbuf); | |
14478 | return; | |
14479 | } | |
7851fe2c JS |
14480 | if ((bf_get(lpfc_cqe_code, |
14481 | &dmabuf->cq_event.cqe.rcqe_cmpl) == CQE_CODE_RECEIVE_V1)) | |
14482 | fcfi = bf_get(lpfc_rcqe_fcf_id_v1, | |
14483 | &dmabuf->cq_event.cqe.rcqe_cmpl); | |
14484 | else | |
14485 | fcfi = bf_get(lpfc_rcqe_fcf_id, | |
14486 | &dmabuf->cq_event.cqe.rcqe_cmpl); | |
939723a4 | 14487 | |
4d9ab994 | 14488 | vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi); |
939723a4 | 14489 | if (!vport) { |
4d9ab994 JS |
14490 | /* throw out the frame */ |
14491 | lpfc_in_buf_free(phba, &dmabuf->dbuf); | |
14492 | return; | |
14493 | } | |
939723a4 JS |
14494 | |
14495 | /* d_id this frame is directed to */ | |
14496 | did = sli4_did_from_fc_hdr(fc_hdr); | |
14497 | ||
14498 | /* vport is registered unless we rcv a FLOGI directed to Fabric_DID */ | |
14499 | if (!(vport->vpi_state & LPFC_VPI_REGISTERED) && | |
14500 | (did != Fabric_DID)) { | |
14501 | /* | |
14502 | * Throw out the frame if we are not pt2pt. | |
14503 | * The pt2pt protocol allows for discovery frames | |
14504 | * to be received without a registered VPI. | |
14505 | */ | |
14506 | if (!(vport->fc_flag & FC_PT2PT) || | |
14507 | (phba->link_state == LPFC_HBA_READY)) { | |
14508 | lpfc_in_buf_free(phba, &dmabuf->dbuf); | |
14509 | return; | |
14510 | } | |
14511 | } | |
14512 | ||
6669f9bb JS |
14513 | /* Handle the basic abort sequence (BA_ABTS) event */ |
14514 | if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) { | |
14515 | lpfc_sli4_handle_unsol_abort(vport, dmabuf); | |
14516 | return; | |
14517 | } | |
14518 | ||
4d9ab994 JS |
14519 | /* Link this frame */ |
14520 | seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf); | |
14521 | if (!seq_dmabuf) { | |
14522 | /* unable to add frame to vport - throw it out */ | |
14523 | lpfc_in_buf_free(phba, &dmabuf->dbuf); | |
14524 | return; | |
14525 | } | |
14526 | /* If not last frame in sequence continue processing frames. */ | |
def9c7a9 | 14527 | if (!lpfc_seq_complete(seq_dmabuf)) |
4d9ab994 | 14528 | return; |
def9c7a9 | 14529 | |
6669f9bb JS |
14530 | /* Send the complete sequence to the upper layer protocol */ |
14531 | lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf); | |
4f774513 | 14532 | } |
6fb120a7 JS |
14533 | |
14534 | /** | |
14535 | * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port | |
14536 | * @phba: pointer to lpfc hba data structure. | |
14537 | * | |
14538 | * This routine is invoked to post rpi header templates to the | |
14539 | * HBA consistent with the SLI-4 interface spec. This routine | |
49198b37 JS |
14540 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
14541 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. | |
6fb120a7 JS |
14542 | * |
14543 | * This routine does not require any locks. It's usage is expected | |
14544 | * to be driver load or reset recovery when the driver is | |
14545 | * sequential. | |
14546 | * | |
14547 | * Return codes | |
af901ca1 | 14548 | * 0 - successful |
d439d286 | 14549 | * -EIO - The mailbox failed to complete successfully. |
6fb120a7 JS |
14550 | * When this error occurs, the driver is not guaranteed |
14551 | * to have any rpi regions posted to the device and | |
14552 | * must either attempt to repost the regions or take a | |
14553 | * fatal error. | |
14554 | **/ | |
14555 | int | |
14556 | lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba) | |
14557 | { | |
14558 | struct lpfc_rpi_hdr *rpi_page; | |
14559 | uint32_t rc = 0; | |
6d368e53 JS |
14560 | uint16_t lrpi = 0; |
14561 | ||
14562 | /* SLI4 ports that support extents do not require RPI headers. */ | |
14563 | if (!phba->sli4_hba.rpi_hdrs_in_use) | |
14564 | goto exit; | |
14565 | if (phba->sli4_hba.extents_in_use) | |
14566 | return -EIO; | |
6fb120a7 | 14567 | |
6fb120a7 | 14568 | list_for_each_entry(rpi_page, &phba->sli4_hba.lpfc_rpi_hdr_list, list) { |
6d368e53 JS |
14569 | /* |
14570 | * Assign the rpi headers a physical rpi only if the driver | |
14571 | * has not initialized those resources. A port reset only | |
14572 | * needs the headers posted. | |
14573 | */ | |
14574 | if (bf_get(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags) != | |
14575 | LPFC_RPI_RSRC_RDY) | |
14576 | rpi_page->start_rpi = phba->sli4_hba.rpi_ids[lrpi]; | |
14577 | ||
6fb120a7 JS |
14578 | rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page); |
14579 | if (rc != MBX_SUCCESS) { | |
14580 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
14581 | "2008 Error %d posting all rpi " | |
14582 | "headers\n", rc); | |
14583 | rc = -EIO; | |
14584 | break; | |
14585 | } | |
14586 | } | |
14587 | ||
6d368e53 JS |
14588 | exit: |
14589 | bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, | |
14590 | LPFC_RPI_RSRC_RDY); | |
6fb120a7 JS |
14591 | return rc; |
14592 | } | |
14593 | ||
14594 | /** | |
14595 | * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port | |
14596 | * @phba: pointer to lpfc hba data structure. | |
14597 | * @rpi_page: pointer to the rpi memory region. | |
14598 | * | |
14599 | * This routine is invoked to post a single rpi header to the | |
14600 | * HBA consistent with the SLI-4 interface spec. This memory region | |
14601 | * maps up to 64 rpi context regions. | |
14602 | * | |
14603 | * Return codes | |
af901ca1 | 14604 | * 0 - successful |
d439d286 JS |
14605 | * -ENOMEM - No available memory |
14606 | * -EIO - The mailbox failed to complete successfully. | |
6fb120a7 JS |
14607 | **/ |
14608 | int | |
14609 | lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page) | |
14610 | { | |
14611 | LPFC_MBOXQ_t *mboxq; | |
14612 | struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl; | |
14613 | uint32_t rc = 0; | |
6fb120a7 JS |
14614 | uint32_t shdr_status, shdr_add_status; |
14615 | union lpfc_sli4_cfg_shdr *shdr; | |
14616 | ||
6d368e53 JS |
14617 | /* SLI4 ports that support extents do not require RPI headers. */ |
14618 | if (!phba->sli4_hba.rpi_hdrs_in_use) | |
14619 | return rc; | |
14620 | if (phba->sli4_hba.extents_in_use) | |
14621 | return -EIO; | |
14622 | ||
6fb120a7 JS |
14623 | /* The port is notified of the header region via a mailbox command. */ |
14624 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
14625 | if (!mboxq) { | |
14626 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
14627 | "2001 Unable to allocate memory for issuing " | |
14628 | "SLI_CONFIG_SPECIAL mailbox command\n"); | |
14629 | return -ENOMEM; | |
14630 | } | |
14631 | ||
14632 | /* Post all rpi memory regions to the port. */ | |
14633 | hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl; | |
6fb120a7 JS |
14634 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, |
14635 | LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE, | |
14636 | sizeof(struct lpfc_mbx_post_hdr_tmpl) - | |
fedd3b7b JS |
14637 | sizeof(struct lpfc_sli4_cfg_mhdr), |
14638 | LPFC_SLI4_MBX_EMBED); | |
6d368e53 JS |
14639 | |
14640 | ||
14641 | /* Post the physical rpi to the port for this rpi header. */ | |
6fb120a7 JS |
14642 | bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl, |
14643 | rpi_page->start_rpi); | |
6d368e53 JS |
14644 | bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt, |
14645 | hdr_tmpl, rpi_page->page_count); | |
14646 | ||
6fb120a7 JS |
14647 | hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys); |
14648 | hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys); | |
f1126688 | 14649 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
6fb120a7 JS |
14650 | shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr; |
14651 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
14652 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
14653 | if (rc != MBX_TIMEOUT) | |
14654 | mempool_free(mboxq, phba->mbox_mem_pool); | |
14655 | if (shdr_status || shdr_add_status || rc) { | |
14656 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
14657 | "2514 POST_RPI_HDR mailbox failed with " | |
14658 | "status x%x add_status x%x, mbx status x%x\n", | |
14659 | shdr_status, shdr_add_status, rc); | |
14660 | rc = -ENXIO; | |
14661 | } | |
14662 | return rc; | |
14663 | } | |
14664 | ||
14665 | /** | |
14666 | * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range | |
14667 | * @phba: pointer to lpfc hba data structure. | |
14668 | * | |
14669 | * This routine is invoked to post rpi header templates to the | |
14670 | * HBA consistent with the SLI-4 interface spec. This routine | |
49198b37 JS |
14671 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
14672 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. | |
6fb120a7 JS |
14673 | * |
14674 | * Returns | |
af901ca1 | 14675 | * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful |
6fb120a7 JS |
14676 | * LPFC_RPI_ALLOC_ERROR if no rpis are available. |
14677 | **/ | |
14678 | int | |
14679 | lpfc_sli4_alloc_rpi(struct lpfc_hba *phba) | |
14680 | { | |
6d368e53 JS |
14681 | unsigned long rpi; |
14682 | uint16_t max_rpi, rpi_limit; | |
14683 | uint16_t rpi_remaining, lrpi = 0; | |
6fb120a7 JS |
14684 | struct lpfc_rpi_hdr *rpi_hdr; |
14685 | ||
14686 | max_rpi = phba->sli4_hba.max_cfg_param.max_rpi; | |
6fb120a7 JS |
14687 | rpi_limit = phba->sli4_hba.next_rpi; |
14688 | ||
14689 | /* | |
6d368e53 JS |
14690 | * Fetch the next logical rpi. Because this index is logical, |
14691 | * the driver starts at 0 each time. | |
6fb120a7 JS |
14692 | */ |
14693 | spin_lock_irq(&phba->hbalock); | |
6d368e53 JS |
14694 | rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, 0); |
14695 | if (rpi >= rpi_limit) | |
6fb120a7 JS |
14696 | rpi = LPFC_RPI_ALLOC_ERROR; |
14697 | else { | |
14698 | set_bit(rpi, phba->sli4_hba.rpi_bmask); | |
14699 | phba->sli4_hba.max_cfg_param.rpi_used++; | |
14700 | phba->sli4_hba.rpi_count++; | |
14701 | } | |
14702 | ||
14703 | /* | |
14704 | * Don't try to allocate more rpi header regions if the device limit | |
6d368e53 | 14705 | * has been exhausted. |
6fb120a7 JS |
14706 | */ |
14707 | if ((rpi == LPFC_RPI_ALLOC_ERROR) && | |
14708 | (phba->sli4_hba.rpi_count >= max_rpi)) { | |
14709 | spin_unlock_irq(&phba->hbalock); | |
14710 | return rpi; | |
14711 | } | |
14712 | ||
6d368e53 JS |
14713 | /* |
14714 | * RPI header postings are not required for SLI4 ports capable of | |
14715 | * extents. | |
14716 | */ | |
14717 | if (!phba->sli4_hba.rpi_hdrs_in_use) { | |
14718 | spin_unlock_irq(&phba->hbalock); | |
14719 | return rpi; | |
14720 | } | |
14721 | ||
6fb120a7 JS |
14722 | /* |
14723 | * If the driver is running low on rpi resources, allocate another | |
14724 | * page now. Note that the next_rpi value is used because | |
14725 | * it represents how many are actually in use whereas max_rpi notes | |
14726 | * how many are supported max by the device. | |
14727 | */ | |
6d368e53 | 14728 | rpi_remaining = phba->sli4_hba.next_rpi - phba->sli4_hba.rpi_count; |
6fb120a7 JS |
14729 | spin_unlock_irq(&phba->hbalock); |
14730 | if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) { | |
14731 | rpi_hdr = lpfc_sli4_create_rpi_hdr(phba); | |
14732 | if (!rpi_hdr) { | |
14733 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
14734 | "2002 Error Could not grow rpi " | |
14735 | "count\n"); | |
14736 | } else { | |
6d368e53 JS |
14737 | lrpi = rpi_hdr->start_rpi; |
14738 | rpi_hdr->start_rpi = phba->sli4_hba.rpi_ids[lrpi]; | |
6fb120a7 JS |
14739 | lpfc_sli4_post_rpi_hdr(phba, rpi_hdr); |
14740 | } | |
14741 | } | |
14742 | ||
14743 | return rpi; | |
14744 | } | |
14745 | ||
d7c47992 JS |
14746 | /** |
14747 | * lpfc_sli4_free_rpi - Release an rpi for reuse. | |
14748 | * @phba: pointer to lpfc hba data structure. | |
14749 | * | |
14750 | * This routine is invoked to release an rpi to the pool of | |
14751 | * available rpis maintained by the driver. | |
14752 | **/ | |
14753 | void | |
14754 | __lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi) | |
14755 | { | |
14756 | if (test_and_clear_bit(rpi, phba->sli4_hba.rpi_bmask)) { | |
14757 | phba->sli4_hba.rpi_count--; | |
14758 | phba->sli4_hba.max_cfg_param.rpi_used--; | |
14759 | } | |
14760 | } | |
14761 | ||
6fb120a7 JS |
14762 | /** |
14763 | * lpfc_sli4_free_rpi - Release an rpi for reuse. | |
14764 | * @phba: pointer to lpfc hba data structure. | |
14765 | * | |
14766 | * This routine is invoked to release an rpi to the pool of | |
14767 | * available rpis maintained by the driver. | |
14768 | **/ | |
14769 | void | |
14770 | lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi) | |
14771 | { | |
14772 | spin_lock_irq(&phba->hbalock); | |
d7c47992 | 14773 | __lpfc_sli4_free_rpi(phba, rpi); |
6fb120a7 JS |
14774 | spin_unlock_irq(&phba->hbalock); |
14775 | } | |
14776 | ||
14777 | /** | |
14778 | * lpfc_sli4_remove_rpis - Remove the rpi bitmask region | |
14779 | * @phba: pointer to lpfc hba data structure. | |
14780 | * | |
14781 | * This routine is invoked to remove the memory region that | |
14782 | * provided rpi via a bitmask. | |
14783 | **/ | |
14784 | void | |
14785 | lpfc_sli4_remove_rpis(struct lpfc_hba *phba) | |
14786 | { | |
14787 | kfree(phba->sli4_hba.rpi_bmask); | |
6d368e53 JS |
14788 | kfree(phba->sli4_hba.rpi_ids); |
14789 | bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); | |
6fb120a7 JS |
14790 | } |
14791 | ||
14792 | /** | |
14793 | * lpfc_sli4_resume_rpi - Remove the rpi bitmask region | |
14794 | * @phba: pointer to lpfc hba data structure. | |
14795 | * | |
14796 | * This routine is invoked to remove the memory region that | |
14797 | * provided rpi via a bitmask. | |
14798 | **/ | |
14799 | int | |
6b5151fd JS |
14800 | lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp, |
14801 | void (*cmpl)(struct lpfc_hba *, LPFC_MBOXQ_t *), void *arg) | |
6fb120a7 JS |
14802 | { |
14803 | LPFC_MBOXQ_t *mboxq; | |
14804 | struct lpfc_hba *phba = ndlp->phba; | |
14805 | int rc; | |
14806 | ||
14807 | /* The port is notified of the header region via a mailbox command. */ | |
14808 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
14809 | if (!mboxq) | |
14810 | return -ENOMEM; | |
14811 | ||
14812 | /* Post all rpi memory regions to the port. */ | |
14813 | lpfc_resume_rpi(mboxq, ndlp); | |
6b5151fd JS |
14814 | if (cmpl) { |
14815 | mboxq->mbox_cmpl = cmpl; | |
14816 | mboxq->context1 = arg; | |
14817 | mboxq->context2 = ndlp; | |
72859909 JS |
14818 | } else |
14819 | mboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
6b5151fd | 14820 | mboxq->vport = ndlp->vport; |
6fb120a7 JS |
14821 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
14822 | if (rc == MBX_NOT_FINISHED) { | |
14823 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
14824 | "2010 Resume RPI Mailbox failed " | |
14825 | "status %d, mbxStatus x%x\n", rc, | |
14826 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); | |
14827 | mempool_free(mboxq, phba->mbox_mem_pool); | |
14828 | return -EIO; | |
14829 | } | |
14830 | return 0; | |
14831 | } | |
14832 | ||
14833 | /** | |
14834 | * lpfc_sli4_init_vpi - Initialize a vpi with the port | |
76a95d75 | 14835 | * @vport: Pointer to the vport for which the vpi is being initialized |
6fb120a7 | 14836 | * |
76a95d75 | 14837 | * This routine is invoked to activate a vpi with the port. |
6fb120a7 JS |
14838 | * |
14839 | * Returns: | |
14840 | * 0 success | |
14841 | * -Evalue otherwise | |
14842 | **/ | |
14843 | int | |
76a95d75 | 14844 | lpfc_sli4_init_vpi(struct lpfc_vport *vport) |
6fb120a7 JS |
14845 | { |
14846 | LPFC_MBOXQ_t *mboxq; | |
14847 | int rc = 0; | |
6a9c52cf | 14848 | int retval = MBX_SUCCESS; |
6fb120a7 | 14849 | uint32_t mbox_tmo; |
76a95d75 | 14850 | struct lpfc_hba *phba = vport->phba; |
6fb120a7 JS |
14851 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
14852 | if (!mboxq) | |
14853 | return -ENOMEM; | |
76a95d75 | 14854 | lpfc_init_vpi(phba, mboxq, vport->vpi); |
a183a15f | 14855 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); |
6fb120a7 | 14856 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); |
6fb120a7 | 14857 | if (rc != MBX_SUCCESS) { |
76a95d75 | 14858 | lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI, |
6fb120a7 JS |
14859 | "2022 INIT VPI Mailbox failed " |
14860 | "status %d, mbxStatus x%x\n", rc, | |
14861 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); | |
6a9c52cf | 14862 | retval = -EIO; |
6fb120a7 | 14863 | } |
6a9c52cf | 14864 | if (rc != MBX_TIMEOUT) |
76a95d75 | 14865 | mempool_free(mboxq, vport->phba->mbox_mem_pool); |
6a9c52cf JS |
14866 | |
14867 | return retval; | |
6fb120a7 JS |
14868 | } |
14869 | ||
14870 | /** | |
14871 | * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler. | |
14872 | * @phba: pointer to lpfc hba data structure. | |
14873 | * @mboxq: Pointer to mailbox object. | |
14874 | * | |
14875 | * This routine is invoked to manually add a single FCF record. The caller | |
14876 | * must pass a completely initialized FCF_Record. This routine takes | |
14877 | * care of the nonembedded mailbox operations. | |
14878 | **/ | |
14879 | static void | |
14880 | lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) | |
14881 | { | |
14882 | void *virt_addr; | |
14883 | union lpfc_sli4_cfg_shdr *shdr; | |
14884 | uint32_t shdr_status, shdr_add_status; | |
14885 | ||
14886 | virt_addr = mboxq->sge_array->addr[0]; | |
14887 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
14888 | shdr = (union lpfc_sli4_cfg_shdr *) virt_addr; | |
14889 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
14890 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
14891 | ||
14892 | if ((shdr_status || shdr_add_status) && | |
14893 | (shdr_status != STATUS_FCF_IN_USE)) | |
14894 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
14895 | "2558 ADD_FCF_RECORD mailbox failed with " | |
14896 | "status x%x add_status x%x\n", | |
14897 | shdr_status, shdr_add_status); | |
14898 | ||
14899 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
14900 | } | |
14901 | ||
14902 | /** | |
14903 | * lpfc_sli4_add_fcf_record - Manually add an FCF Record. | |
14904 | * @phba: pointer to lpfc hba data structure. | |
14905 | * @fcf_record: pointer to the initialized fcf record to add. | |
14906 | * | |
14907 | * This routine is invoked to manually add a single FCF record. The caller | |
14908 | * must pass a completely initialized FCF_Record. This routine takes | |
14909 | * care of the nonembedded mailbox operations. | |
14910 | **/ | |
14911 | int | |
14912 | lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record) | |
14913 | { | |
14914 | int rc = 0; | |
14915 | LPFC_MBOXQ_t *mboxq; | |
14916 | uint8_t *bytep; | |
14917 | void *virt_addr; | |
14918 | dma_addr_t phys_addr; | |
14919 | struct lpfc_mbx_sge sge; | |
14920 | uint32_t alloc_len, req_len; | |
14921 | uint32_t fcfindex; | |
14922 | ||
14923 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
14924 | if (!mboxq) { | |
14925 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
14926 | "2009 Failed to allocate mbox for ADD_FCF cmd\n"); | |
14927 | return -ENOMEM; | |
14928 | } | |
14929 | ||
14930 | req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) + | |
14931 | sizeof(uint32_t); | |
14932 | ||
14933 | /* Allocate DMA memory and set up the non-embedded mailbox command */ | |
14934 | alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, | |
14935 | LPFC_MBOX_OPCODE_FCOE_ADD_FCF, | |
14936 | req_len, LPFC_SLI4_MBX_NEMBED); | |
14937 | if (alloc_len < req_len) { | |
14938 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
14939 | "2523 Allocated DMA memory size (x%x) is " | |
14940 | "less than the requested DMA memory " | |
14941 | "size (x%x)\n", alloc_len, req_len); | |
14942 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
14943 | return -ENOMEM; | |
14944 | } | |
14945 | ||
14946 | /* | |
14947 | * Get the first SGE entry from the non-embedded DMA memory. This | |
14948 | * routine only uses a single SGE. | |
14949 | */ | |
14950 | lpfc_sli4_mbx_sge_get(mboxq, 0, &sge); | |
14951 | phys_addr = getPaddr(sge.pa_hi, sge.pa_lo); | |
6fb120a7 JS |
14952 | virt_addr = mboxq->sge_array->addr[0]; |
14953 | /* | |
14954 | * Configure the FCF record for FCFI 0. This is the driver's | |
14955 | * hardcoded default and gets used in nonFIP mode. | |
14956 | */ | |
14957 | fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record); | |
14958 | bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr); | |
14959 | lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t)); | |
14960 | ||
14961 | /* | |
14962 | * Copy the fcf_index and the FCF Record Data. The data starts after | |
14963 | * the FCoE header plus word10. The data copy needs to be endian | |
14964 | * correct. | |
14965 | */ | |
14966 | bytep += sizeof(uint32_t); | |
14967 | lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record)); | |
14968 | mboxq->vport = phba->pport; | |
14969 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record; | |
14970 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); | |
14971 | if (rc == MBX_NOT_FINISHED) { | |
14972 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
14973 | "2515 ADD_FCF_RECORD mailbox failed with " | |
14974 | "status 0x%x\n", rc); | |
14975 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
14976 | rc = -EIO; | |
14977 | } else | |
14978 | rc = 0; | |
14979 | ||
14980 | return rc; | |
14981 | } | |
14982 | ||
14983 | /** | |
14984 | * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record. | |
14985 | * @phba: pointer to lpfc hba data structure. | |
14986 | * @fcf_record: pointer to the fcf record to write the default data. | |
14987 | * @fcf_index: FCF table entry index. | |
14988 | * | |
14989 | * This routine is invoked to build the driver's default FCF record. The | |
14990 | * values used are hardcoded. This routine handles memory initialization. | |
14991 | * | |
14992 | **/ | |
14993 | void | |
14994 | lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba, | |
14995 | struct fcf_record *fcf_record, | |
14996 | uint16_t fcf_index) | |
14997 | { | |
14998 | memset(fcf_record, 0, sizeof(struct fcf_record)); | |
14999 | fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE; | |
15000 | fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER; | |
15001 | fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY; | |
15002 | bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]); | |
15003 | bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]); | |
15004 | bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]); | |
15005 | bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3); | |
15006 | bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4); | |
15007 | bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5); | |
15008 | bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]); | |
15009 | bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]); | |
15010 | bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]); | |
15011 | bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1); | |
0c287589 | 15012 | bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1); |
6fb120a7 JS |
15013 | bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index); |
15014 | bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record, | |
15015 | LPFC_FCF_FPMA | LPFC_FCF_SPMA); | |
15016 | /* Set the VLAN bit map */ | |
15017 | if (phba->valid_vlan) { | |
15018 | fcf_record->vlan_bitmap[phba->vlan_id / 8] | |
15019 | = 1 << (phba->vlan_id % 8); | |
15020 | } | |
15021 | } | |
15022 | ||
15023 | /** | |
0c9ab6f5 | 15024 | * lpfc_sli4_fcf_scan_read_fcf_rec - Read hba fcf record for fcf scan. |
6fb120a7 JS |
15025 | * @phba: pointer to lpfc hba data structure. |
15026 | * @fcf_index: FCF table entry offset. | |
15027 | * | |
0c9ab6f5 JS |
15028 | * This routine is invoked to scan the entire FCF table by reading FCF |
15029 | * record and processing it one at a time starting from the @fcf_index | |
15030 | * for initial FCF discovery or fast FCF failover rediscovery. | |
15031 | * | |
25985edc | 15032 | * Return 0 if the mailbox command is submitted successfully, none 0 |
0c9ab6f5 | 15033 | * otherwise. |
6fb120a7 JS |
15034 | **/ |
15035 | int | |
0c9ab6f5 | 15036 | lpfc_sli4_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) |
6fb120a7 JS |
15037 | { |
15038 | int rc = 0, error; | |
15039 | LPFC_MBOXQ_t *mboxq; | |
6fb120a7 | 15040 | |
32b9793f | 15041 | phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag; |
80c17849 | 15042 | phba->fcoe_cvl_eventtag_attn = phba->fcoe_cvl_eventtag; |
6fb120a7 JS |
15043 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
15044 | if (!mboxq) { | |
15045 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
15046 | "2000 Failed to allocate mbox for " | |
15047 | "READ_FCF cmd\n"); | |
4d9ab994 | 15048 | error = -ENOMEM; |
0c9ab6f5 | 15049 | goto fail_fcf_scan; |
6fb120a7 | 15050 | } |
ecfd03c6 | 15051 | /* Construct the read FCF record mailbox command */ |
0c9ab6f5 | 15052 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
ecfd03c6 JS |
15053 | if (rc) { |
15054 | error = -EINVAL; | |
0c9ab6f5 | 15055 | goto fail_fcf_scan; |
6fb120a7 | 15056 | } |
ecfd03c6 | 15057 | /* Issue the mailbox command asynchronously */ |
6fb120a7 | 15058 | mboxq->vport = phba->pport; |
0c9ab6f5 | 15059 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec; |
a93ff37a JS |
15060 | |
15061 | spin_lock_irq(&phba->hbalock); | |
15062 | phba->hba_flag |= FCF_TS_INPROG; | |
15063 | spin_unlock_irq(&phba->hbalock); | |
15064 | ||
6fb120a7 | 15065 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
ecfd03c6 | 15066 | if (rc == MBX_NOT_FINISHED) |
6fb120a7 | 15067 | error = -EIO; |
ecfd03c6 | 15068 | else { |
38b92ef8 JS |
15069 | /* Reset eligible FCF count for new scan */ |
15070 | if (fcf_index == LPFC_FCOE_FCF_GET_FIRST) | |
999d813f | 15071 | phba->fcf.eligible_fcf_cnt = 0; |
6fb120a7 | 15072 | error = 0; |
32b9793f | 15073 | } |
0c9ab6f5 | 15074 | fail_fcf_scan: |
4d9ab994 JS |
15075 | if (error) { |
15076 | if (mboxq) | |
15077 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
a93ff37a | 15078 | /* FCF scan failed, clear FCF_TS_INPROG flag */ |
4d9ab994 | 15079 | spin_lock_irq(&phba->hbalock); |
a93ff37a | 15080 | phba->hba_flag &= ~FCF_TS_INPROG; |
4d9ab994 JS |
15081 | spin_unlock_irq(&phba->hbalock); |
15082 | } | |
6fb120a7 JS |
15083 | return error; |
15084 | } | |
a0c87cbd | 15085 | |
0c9ab6f5 | 15086 | /** |
a93ff37a | 15087 | * lpfc_sli4_fcf_rr_read_fcf_rec - Read hba fcf record for roundrobin fcf. |
0c9ab6f5 JS |
15088 | * @phba: pointer to lpfc hba data structure. |
15089 | * @fcf_index: FCF table entry offset. | |
15090 | * | |
15091 | * This routine is invoked to read an FCF record indicated by @fcf_index | |
a93ff37a | 15092 | * and to use it for FLOGI roundrobin FCF failover. |
0c9ab6f5 | 15093 | * |
25985edc | 15094 | * Return 0 if the mailbox command is submitted successfully, none 0 |
0c9ab6f5 JS |
15095 | * otherwise. |
15096 | **/ | |
15097 | int | |
15098 | lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) | |
15099 | { | |
15100 | int rc = 0, error; | |
15101 | LPFC_MBOXQ_t *mboxq; | |
15102 | ||
15103 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
15104 | if (!mboxq) { | |
15105 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT, | |
15106 | "2763 Failed to allocate mbox for " | |
15107 | "READ_FCF cmd\n"); | |
15108 | error = -ENOMEM; | |
15109 | goto fail_fcf_read; | |
15110 | } | |
15111 | /* Construct the read FCF record mailbox command */ | |
15112 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); | |
15113 | if (rc) { | |
15114 | error = -EINVAL; | |
15115 | goto fail_fcf_read; | |
15116 | } | |
15117 | /* Issue the mailbox command asynchronously */ | |
15118 | mboxq->vport = phba->pport; | |
15119 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec; | |
15120 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); | |
15121 | if (rc == MBX_NOT_FINISHED) | |
15122 | error = -EIO; | |
15123 | else | |
15124 | error = 0; | |
15125 | ||
15126 | fail_fcf_read: | |
15127 | if (error && mboxq) | |
15128 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
15129 | return error; | |
15130 | } | |
15131 | ||
15132 | /** | |
15133 | * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask. | |
15134 | * @phba: pointer to lpfc hba data structure. | |
15135 | * @fcf_index: FCF table entry offset. | |
15136 | * | |
15137 | * This routine is invoked to read an FCF record indicated by @fcf_index to | |
a93ff37a | 15138 | * determine whether it's eligible for FLOGI roundrobin failover list. |
0c9ab6f5 | 15139 | * |
25985edc | 15140 | * Return 0 if the mailbox command is submitted successfully, none 0 |
0c9ab6f5 JS |
15141 | * otherwise. |
15142 | **/ | |
15143 | int | |
15144 | lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) | |
15145 | { | |
15146 | int rc = 0, error; | |
15147 | LPFC_MBOXQ_t *mboxq; | |
15148 | ||
15149 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
15150 | if (!mboxq) { | |
15151 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT, | |
15152 | "2758 Failed to allocate mbox for " | |
15153 | "READ_FCF cmd\n"); | |
15154 | error = -ENOMEM; | |
15155 | goto fail_fcf_read; | |
15156 | } | |
15157 | /* Construct the read FCF record mailbox command */ | |
15158 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); | |
15159 | if (rc) { | |
15160 | error = -EINVAL; | |
15161 | goto fail_fcf_read; | |
15162 | } | |
15163 | /* Issue the mailbox command asynchronously */ | |
15164 | mboxq->vport = phba->pport; | |
15165 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec; | |
15166 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); | |
15167 | if (rc == MBX_NOT_FINISHED) | |
15168 | error = -EIO; | |
15169 | else | |
15170 | error = 0; | |
15171 | ||
15172 | fail_fcf_read: | |
15173 | if (error && mboxq) | |
15174 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
15175 | return error; | |
15176 | } | |
15177 | ||
7d791df7 JS |
15178 | /** |
15179 | * lpfc_check_next_fcf_pri | |
15180 | * phba pointer to the lpfc_hba struct for this port. | |
15181 | * This routine is called from the lpfc_sli4_fcf_rr_next_index_get | |
15182 | * routine when the rr_bmask is empty. The FCF indecies are put into the | |
15183 | * rr_bmask based on their priority level. Starting from the highest priority | |
15184 | * to the lowest. The most likely FCF candidate will be in the highest | |
15185 | * priority group. When this routine is called it searches the fcf_pri list for | |
15186 | * next lowest priority group and repopulates the rr_bmask with only those | |
15187 | * fcf_indexes. | |
15188 | * returns: | |
15189 | * 1=success 0=failure | |
15190 | **/ | |
15191 | int | |
15192 | lpfc_check_next_fcf_pri_level(struct lpfc_hba *phba) | |
15193 | { | |
15194 | uint16_t next_fcf_pri; | |
15195 | uint16_t last_index; | |
15196 | struct lpfc_fcf_pri *fcf_pri; | |
15197 | int rc; | |
15198 | int ret = 0; | |
15199 | ||
15200 | last_index = find_first_bit(phba->fcf.fcf_rr_bmask, | |
15201 | LPFC_SLI4_FCF_TBL_INDX_MAX); | |
15202 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, | |
15203 | "3060 Last IDX %d\n", last_index); | |
15204 | if (list_empty(&phba->fcf.fcf_pri_list)) { | |
15205 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, | |
15206 | "3061 Last IDX %d\n", last_index); | |
15207 | return 0; /* Empty rr list */ | |
15208 | } | |
15209 | next_fcf_pri = 0; | |
15210 | /* | |
15211 | * Clear the rr_bmask and set all of the bits that are at this | |
15212 | * priority. | |
15213 | */ | |
15214 | memset(phba->fcf.fcf_rr_bmask, 0, | |
15215 | sizeof(*phba->fcf.fcf_rr_bmask)); | |
15216 | spin_lock_irq(&phba->hbalock); | |
15217 | list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) { | |
15218 | if (fcf_pri->fcf_rec.flag & LPFC_FCF_FLOGI_FAILED) | |
15219 | continue; | |
15220 | /* | |
15221 | * the 1st priority that has not FLOGI failed | |
15222 | * will be the highest. | |
15223 | */ | |
15224 | if (!next_fcf_pri) | |
15225 | next_fcf_pri = fcf_pri->fcf_rec.priority; | |
15226 | spin_unlock_irq(&phba->hbalock); | |
15227 | if (fcf_pri->fcf_rec.priority == next_fcf_pri) { | |
15228 | rc = lpfc_sli4_fcf_rr_index_set(phba, | |
15229 | fcf_pri->fcf_rec.fcf_index); | |
15230 | if (rc) | |
15231 | return 0; | |
15232 | } | |
15233 | spin_lock_irq(&phba->hbalock); | |
15234 | } | |
15235 | /* | |
15236 | * if next_fcf_pri was not set above and the list is not empty then | |
15237 | * we have failed flogis on all of them. So reset flogi failed | |
15238 | * and start at the begining. | |
15239 | */ | |
15240 | if (!next_fcf_pri && !list_empty(&phba->fcf.fcf_pri_list)) { | |
15241 | list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) { | |
15242 | fcf_pri->fcf_rec.flag &= ~LPFC_FCF_FLOGI_FAILED; | |
15243 | /* | |
15244 | * the 1st priority that has not FLOGI failed | |
15245 | * will be the highest. | |
15246 | */ | |
15247 | if (!next_fcf_pri) | |
15248 | next_fcf_pri = fcf_pri->fcf_rec.priority; | |
15249 | spin_unlock_irq(&phba->hbalock); | |
15250 | if (fcf_pri->fcf_rec.priority == next_fcf_pri) { | |
15251 | rc = lpfc_sli4_fcf_rr_index_set(phba, | |
15252 | fcf_pri->fcf_rec.fcf_index); | |
15253 | if (rc) | |
15254 | return 0; | |
15255 | } | |
15256 | spin_lock_irq(&phba->hbalock); | |
15257 | } | |
15258 | } else | |
15259 | ret = 1; | |
15260 | spin_unlock_irq(&phba->hbalock); | |
15261 | ||
15262 | return ret; | |
15263 | } | |
0c9ab6f5 JS |
15264 | /** |
15265 | * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index | |
15266 | * @phba: pointer to lpfc hba data structure. | |
15267 | * | |
15268 | * This routine is to get the next eligible FCF record index in a round | |
15269 | * robin fashion. If the next eligible FCF record index equals to the | |
a93ff37a | 15270 | * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF) |
0c9ab6f5 JS |
15271 | * shall be returned, otherwise, the next eligible FCF record's index |
15272 | * shall be returned. | |
15273 | **/ | |
15274 | uint16_t | |
15275 | lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba) | |
15276 | { | |
15277 | uint16_t next_fcf_index; | |
15278 | ||
3804dc84 | 15279 | /* Search start from next bit of currently registered FCF index */ |
7d791df7 | 15280 | next_priority: |
3804dc84 JS |
15281 | next_fcf_index = (phba->fcf.current_rec.fcf_indx + 1) % |
15282 | LPFC_SLI4_FCF_TBL_INDX_MAX; | |
0c9ab6f5 JS |
15283 | next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask, |
15284 | LPFC_SLI4_FCF_TBL_INDX_MAX, | |
3804dc84 JS |
15285 | next_fcf_index); |
15286 | ||
0c9ab6f5 | 15287 | /* Wrap around condition on phba->fcf.fcf_rr_bmask */ |
7d791df7 JS |
15288 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
15289 | /* | |
15290 | * If we have wrapped then we need to clear the bits that | |
15291 | * have been tested so that we can detect when we should | |
15292 | * change the priority level. | |
15293 | */ | |
0c9ab6f5 JS |
15294 | next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask, |
15295 | LPFC_SLI4_FCF_TBL_INDX_MAX, 0); | |
7d791df7 JS |
15296 | } |
15297 | ||
3804dc84 JS |
15298 | |
15299 | /* Check roundrobin failover list empty condition */ | |
7d791df7 JS |
15300 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX || |
15301 | next_fcf_index == phba->fcf.current_rec.fcf_indx) { | |
15302 | /* | |
15303 | * If next fcf index is not found check if there are lower | |
15304 | * Priority level fcf's in the fcf_priority list. | |
15305 | * Set up the rr_bmask with all of the avaiable fcf bits | |
15306 | * at that level and continue the selection process. | |
15307 | */ | |
15308 | if (lpfc_check_next_fcf_pri_level(phba)) | |
15309 | goto next_priority; | |
3804dc84 JS |
15310 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
15311 | "2844 No roundrobin failover FCF available\n"); | |
7d791df7 JS |
15312 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) |
15313 | return LPFC_FCOE_FCF_NEXT_NONE; | |
15314 | else { | |
15315 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, | |
15316 | "3063 Only FCF available idx %d, flag %x\n", | |
15317 | next_fcf_index, | |
15318 | phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag); | |
15319 | return next_fcf_index; | |
15320 | } | |
3804dc84 JS |
15321 | } |
15322 | ||
7d791df7 JS |
15323 | if (next_fcf_index < LPFC_SLI4_FCF_TBL_INDX_MAX && |
15324 | phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag & | |
15325 | LPFC_FCF_FLOGI_FAILED) | |
15326 | goto next_priority; | |
15327 | ||
3804dc84 | 15328 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
a93ff37a JS |
15329 | "2845 Get next roundrobin failover FCF (x%x)\n", |
15330 | next_fcf_index); | |
15331 | ||
0c9ab6f5 JS |
15332 | return next_fcf_index; |
15333 | } | |
15334 | ||
15335 | /** | |
15336 | * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index | |
15337 | * @phba: pointer to lpfc hba data structure. | |
15338 | * | |
15339 | * This routine sets the FCF record index in to the eligible bmask for | |
a93ff37a | 15340 | * roundrobin failover search. It checks to make sure that the index |
0c9ab6f5 JS |
15341 | * does not go beyond the range of the driver allocated bmask dimension |
15342 | * before setting the bit. | |
15343 | * | |
15344 | * Returns 0 if the index bit successfully set, otherwise, it returns | |
15345 | * -EINVAL. | |
15346 | **/ | |
15347 | int | |
15348 | lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index) | |
15349 | { | |
15350 | if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { | |
15351 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, | |
a93ff37a JS |
15352 | "2610 FCF (x%x) reached driver's book " |
15353 | "keeping dimension:x%x\n", | |
0c9ab6f5 JS |
15354 | fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX); |
15355 | return -EINVAL; | |
15356 | } | |
15357 | /* Set the eligible FCF record index bmask */ | |
15358 | set_bit(fcf_index, phba->fcf.fcf_rr_bmask); | |
15359 | ||
3804dc84 | 15360 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
a93ff37a | 15361 | "2790 Set FCF (x%x) to roundrobin FCF failover " |
3804dc84 JS |
15362 | "bmask\n", fcf_index); |
15363 | ||
0c9ab6f5 JS |
15364 | return 0; |
15365 | } | |
15366 | ||
15367 | /** | |
3804dc84 | 15368 | * lpfc_sli4_fcf_rr_index_clear - Clear bmask from eligible fcf record index |
0c9ab6f5 JS |
15369 | * @phba: pointer to lpfc hba data structure. |
15370 | * | |
15371 | * This routine clears the FCF record index from the eligible bmask for | |
a93ff37a | 15372 | * roundrobin failover search. It checks to make sure that the index |
0c9ab6f5 JS |
15373 | * does not go beyond the range of the driver allocated bmask dimension |
15374 | * before clearing the bit. | |
15375 | **/ | |
15376 | void | |
15377 | lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index) | |
15378 | { | |
7d791df7 | 15379 | struct lpfc_fcf_pri *fcf_pri; |
0c9ab6f5 JS |
15380 | if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
15381 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, | |
a93ff37a JS |
15382 | "2762 FCF (x%x) reached driver's book " |
15383 | "keeping dimension:x%x\n", | |
0c9ab6f5 JS |
15384 | fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX); |
15385 | return; | |
15386 | } | |
15387 | /* Clear the eligible FCF record index bmask */ | |
7d791df7 JS |
15388 | spin_lock_irq(&phba->hbalock); |
15389 | list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) { | |
15390 | if (fcf_pri->fcf_rec.fcf_index == fcf_index) { | |
15391 | list_del_init(&fcf_pri->list); | |
15392 | break; | |
15393 | } | |
15394 | } | |
15395 | spin_unlock_irq(&phba->hbalock); | |
0c9ab6f5 | 15396 | clear_bit(fcf_index, phba->fcf.fcf_rr_bmask); |
3804dc84 JS |
15397 | |
15398 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, | |
a93ff37a | 15399 | "2791 Clear FCF (x%x) from roundrobin failover " |
3804dc84 | 15400 | "bmask\n", fcf_index); |
0c9ab6f5 JS |
15401 | } |
15402 | ||
ecfd03c6 JS |
15403 | /** |
15404 | * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table | |
15405 | * @phba: pointer to lpfc hba data structure. | |
15406 | * | |
15407 | * This routine is the completion routine for the rediscover FCF table mailbox | |
15408 | * command. If the mailbox command returned failure, it will try to stop the | |
15409 | * FCF rediscover wait timer. | |
15410 | **/ | |
15411 | void | |
15412 | lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox) | |
15413 | { | |
15414 | struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf; | |
15415 | uint32_t shdr_status, shdr_add_status; | |
15416 | ||
15417 | redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl; | |
15418 | ||
15419 | shdr_status = bf_get(lpfc_mbox_hdr_status, | |
15420 | &redisc_fcf->header.cfg_shdr.response); | |
15421 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, | |
15422 | &redisc_fcf->header.cfg_shdr.response); | |
15423 | if (shdr_status || shdr_add_status) { | |
0c9ab6f5 | 15424 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
ecfd03c6 JS |
15425 | "2746 Requesting for FCF rediscovery failed " |
15426 | "status x%x add_status x%x\n", | |
15427 | shdr_status, shdr_add_status); | |
0c9ab6f5 | 15428 | if (phba->fcf.fcf_flag & FCF_ACVL_DISC) { |
fc2b989b | 15429 | spin_lock_irq(&phba->hbalock); |
0c9ab6f5 | 15430 | phba->fcf.fcf_flag &= ~FCF_ACVL_DISC; |
fc2b989b JS |
15431 | spin_unlock_irq(&phba->hbalock); |
15432 | /* | |
15433 | * CVL event triggered FCF rediscover request failed, | |
15434 | * last resort to re-try current registered FCF entry. | |
15435 | */ | |
15436 | lpfc_retry_pport_discovery(phba); | |
15437 | } else { | |
15438 | spin_lock_irq(&phba->hbalock); | |
0c9ab6f5 | 15439 | phba->fcf.fcf_flag &= ~FCF_DEAD_DISC; |
fc2b989b JS |
15440 | spin_unlock_irq(&phba->hbalock); |
15441 | /* | |
15442 | * DEAD FCF event triggered FCF rediscover request | |
15443 | * failed, last resort to fail over as a link down | |
15444 | * to FCF registration. | |
15445 | */ | |
15446 | lpfc_sli4_fcf_dead_failthrough(phba); | |
15447 | } | |
0c9ab6f5 JS |
15448 | } else { |
15449 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, | |
a93ff37a | 15450 | "2775 Start FCF rediscover quiescent timer\n"); |
ecfd03c6 JS |
15451 | /* |
15452 | * Start FCF rediscovery wait timer for pending FCF | |
15453 | * before rescan FCF record table. | |
15454 | */ | |
15455 | lpfc_fcf_redisc_wait_start_timer(phba); | |
0c9ab6f5 | 15456 | } |
ecfd03c6 JS |
15457 | |
15458 | mempool_free(mbox, phba->mbox_mem_pool); | |
15459 | } | |
15460 | ||
15461 | /** | |
3804dc84 | 15462 | * lpfc_sli4_redisc_fcf_table - Request to rediscover entire FCF table by port. |
ecfd03c6 JS |
15463 | * @phba: pointer to lpfc hba data structure. |
15464 | * | |
15465 | * This routine is invoked to request for rediscovery of the entire FCF table | |
15466 | * by the port. | |
15467 | **/ | |
15468 | int | |
15469 | lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba) | |
15470 | { | |
15471 | LPFC_MBOXQ_t *mbox; | |
15472 | struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf; | |
15473 | int rc, length; | |
15474 | ||
0c9ab6f5 JS |
15475 | /* Cancel retry delay timers to all vports before FCF rediscover */ |
15476 | lpfc_cancel_all_vport_retry_delay_timer(phba); | |
15477 | ||
ecfd03c6 JS |
15478 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
15479 | if (!mbox) { | |
15480 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
15481 | "2745 Failed to allocate mbox for " | |
15482 | "requesting FCF rediscover.\n"); | |
15483 | return -ENOMEM; | |
15484 | } | |
15485 | ||
15486 | length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) - | |
15487 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
15488 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
15489 | LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF, | |
15490 | length, LPFC_SLI4_MBX_EMBED); | |
15491 | ||
15492 | redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl; | |
15493 | /* Set count to 0 for invalidating the entire FCF database */ | |
15494 | bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0); | |
15495 | ||
15496 | /* Issue the mailbox command asynchronously */ | |
15497 | mbox->vport = phba->pport; | |
15498 | mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table; | |
15499 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); | |
15500 | ||
15501 | if (rc == MBX_NOT_FINISHED) { | |
15502 | mempool_free(mbox, phba->mbox_mem_pool); | |
15503 | return -EIO; | |
15504 | } | |
15505 | return 0; | |
15506 | } | |
15507 | ||
fc2b989b JS |
15508 | /** |
15509 | * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event | |
15510 | * @phba: pointer to lpfc hba data structure. | |
15511 | * | |
15512 | * This function is the failover routine as a last resort to the FCF DEAD | |
15513 | * event when driver failed to perform fast FCF failover. | |
15514 | **/ | |
15515 | void | |
15516 | lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba) | |
15517 | { | |
15518 | uint32_t link_state; | |
15519 | ||
15520 | /* | |
15521 | * Last resort as FCF DEAD event failover will treat this as | |
15522 | * a link down, but save the link state because we don't want | |
15523 | * it to be changed to Link Down unless it is already down. | |
15524 | */ | |
15525 | link_state = phba->link_state; | |
15526 | lpfc_linkdown(phba); | |
15527 | phba->link_state = link_state; | |
15528 | ||
15529 | /* Unregister FCF if no devices connected to it */ | |
15530 | lpfc_unregister_unused_fcf(phba); | |
15531 | } | |
15532 | ||
a0c87cbd | 15533 | /** |
026abb87 | 15534 | * lpfc_sli_get_config_region23 - Get sli3 port region 23 data. |
a0c87cbd | 15535 | * @phba: pointer to lpfc hba data structure. |
026abb87 | 15536 | * @rgn23_data: pointer to configure region 23 data. |
a0c87cbd | 15537 | * |
026abb87 JS |
15538 | * This function gets SLI3 port configure region 23 data through memory dump |
15539 | * mailbox command. When it successfully retrieves data, the size of the data | |
15540 | * will be returned, otherwise, 0 will be returned. | |
a0c87cbd | 15541 | **/ |
026abb87 JS |
15542 | static uint32_t |
15543 | lpfc_sli_get_config_region23(struct lpfc_hba *phba, char *rgn23_data) | |
a0c87cbd JS |
15544 | { |
15545 | LPFC_MBOXQ_t *pmb = NULL; | |
15546 | MAILBOX_t *mb; | |
026abb87 | 15547 | uint32_t offset = 0; |
a0c87cbd JS |
15548 | int rc; |
15549 | ||
026abb87 JS |
15550 | if (!rgn23_data) |
15551 | return 0; | |
15552 | ||
a0c87cbd JS |
15553 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
15554 | if (!pmb) { | |
15555 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
026abb87 JS |
15556 | "2600 failed to allocate mailbox memory\n"); |
15557 | return 0; | |
a0c87cbd JS |
15558 | } |
15559 | mb = &pmb->u.mb; | |
15560 | ||
a0c87cbd JS |
15561 | do { |
15562 | lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23); | |
15563 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); | |
15564 | ||
15565 | if (rc != MBX_SUCCESS) { | |
15566 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
026abb87 JS |
15567 | "2601 failed to read config " |
15568 | "region 23, rc 0x%x Status 0x%x\n", | |
15569 | rc, mb->mbxStatus); | |
a0c87cbd JS |
15570 | mb->un.varDmp.word_cnt = 0; |
15571 | } | |
15572 | /* | |
15573 | * dump mem may return a zero when finished or we got a | |
15574 | * mailbox error, either way we are done. | |
15575 | */ | |
15576 | if (mb->un.varDmp.word_cnt == 0) | |
15577 | break; | |
15578 | if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset) | |
15579 | mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset; | |
15580 | ||
15581 | lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET, | |
026abb87 JS |
15582 | rgn23_data + offset, |
15583 | mb->un.varDmp.word_cnt); | |
a0c87cbd JS |
15584 | offset += mb->un.varDmp.word_cnt; |
15585 | } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE); | |
15586 | ||
026abb87 JS |
15587 | mempool_free(pmb, phba->mbox_mem_pool); |
15588 | return offset; | |
15589 | } | |
15590 | ||
15591 | /** | |
15592 | * lpfc_sli4_get_config_region23 - Get sli4 port region 23 data. | |
15593 | * @phba: pointer to lpfc hba data structure. | |
15594 | * @rgn23_data: pointer to configure region 23 data. | |
15595 | * | |
15596 | * This function gets SLI4 port configure region 23 data through memory dump | |
15597 | * mailbox command. When it successfully retrieves data, the size of the data | |
15598 | * will be returned, otherwise, 0 will be returned. | |
15599 | **/ | |
15600 | static uint32_t | |
15601 | lpfc_sli4_get_config_region23(struct lpfc_hba *phba, char *rgn23_data) | |
15602 | { | |
15603 | LPFC_MBOXQ_t *mboxq = NULL; | |
15604 | struct lpfc_dmabuf *mp = NULL; | |
15605 | struct lpfc_mqe *mqe; | |
15606 | uint32_t data_length = 0; | |
15607 | int rc; | |
15608 | ||
15609 | if (!rgn23_data) | |
15610 | return 0; | |
15611 | ||
15612 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
15613 | if (!mboxq) { | |
15614 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
15615 | "3105 failed to allocate mailbox memory\n"); | |
15616 | return 0; | |
15617 | } | |
15618 | ||
15619 | if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) | |
15620 | goto out; | |
15621 | mqe = &mboxq->u.mqe; | |
15622 | mp = (struct lpfc_dmabuf *) mboxq->context1; | |
15623 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
15624 | if (rc) | |
15625 | goto out; | |
15626 | data_length = mqe->un.mb_words[5]; | |
15627 | if (data_length == 0) | |
15628 | goto out; | |
15629 | if (data_length > DMP_RGN23_SIZE) { | |
15630 | data_length = 0; | |
15631 | goto out; | |
15632 | } | |
15633 | lpfc_sli_pcimem_bcopy((char *)mp->virt, rgn23_data, data_length); | |
15634 | out: | |
15635 | mempool_free(mboxq, phba->mbox_mem_pool); | |
15636 | if (mp) { | |
15637 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
15638 | kfree(mp); | |
15639 | } | |
15640 | return data_length; | |
15641 | } | |
15642 | ||
15643 | /** | |
15644 | * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled. | |
15645 | * @phba: pointer to lpfc hba data structure. | |
15646 | * | |
15647 | * This function read region 23 and parse TLV for port status to | |
15648 | * decide if the user disaled the port. If the TLV indicates the | |
15649 | * port is disabled, the hba_flag is set accordingly. | |
15650 | **/ | |
15651 | void | |
15652 | lpfc_sli_read_link_ste(struct lpfc_hba *phba) | |
15653 | { | |
15654 | uint8_t *rgn23_data = NULL; | |
15655 | uint32_t if_type, data_size, sub_tlv_len, tlv_offset; | |
15656 | uint32_t offset = 0; | |
15657 | ||
15658 | /* Get adapter Region 23 data */ | |
15659 | rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL); | |
15660 | if (!rgn23_data) | |
15661 | goto out; | |
15662 | ||
15663 | if (phba->sli_rev < LPFC_SLI_REV4) | |
15664 | data_size = lpfc_sli_get_config_region23(phba, rgn23_data); | |
15665 | else { | |
15666 | if_type = bf_get(lpfc_sli_intf_if_type, | |
15667 | &phba->sli4_hba.sli_intf); | |
15668 | if (if_type == LPFC_SLI_INTF_IF_TYPE_0) | |
15669 | goto out; | |
15670 | data_size = lpfc_sli4_get_config_region23(phba, rgn23_data); | |
15671 | } | |
a0c87cbd JS |
15672 | |
15673 | if (!data_size) | |
15674 | goto out; | |
15675 | ||
15676 | /* Check the region signature first */ | |
15677 | if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) { | |
15678 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
15679 | "2619 Config region 23 has bad signature\n"); | |
15680 | goto out; | |
15681 | } | |
15682 | offset += 4; | |
15683 | ||
15684 | /* Check the data structure version */ | |
15685 | if (rgn23_data[offset] != LPFC_REGION23_VERSION) { | |
15686 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
15687 | "2620 Config region 23 has bad version\n"); | |
15688 | goto out; | |
15689 | } | |
15690 | offset += 4; | |
15691 | ||
15692 | /* Parse TLV entries in the region */ | |
15693 | while (offset < data_size) { | |
15694 | if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) | |
15695 | break; | |
15696 | /* | |
15697 | * If the TLV is not driver specific TLV or driver id is | |
15698 | * not linux driver id, skip the record. | |
15699 | */ | |
15700 | if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) || | |
15701 | (rgn23_data[offset + 2] != LINUX_DRIVER_ID) || | |
15702 | (rgn23_data[offset + 3] != 0)) { | |
15703 | offset += rgn23_data[offset + 1] * 4 + 4; | |
15704 | continue; | |
15705 | } | |
15706 | ||
15707 | /* Driver found a driver specific TLV in the config region */ | |
15708 | sub_tlv_len = rgn23_data[offset + 1] * 4; | |
15709 | offset += 4; | |
15710 | tlv_offset = 0; | |
15711 | ||
15712 | /* | |
15713 | * Search for configured port state sub-TLV. | |
15714 | */ | |
15715 | while ((offset < data_size) && | |
15716 | (tlv_offset < sub_tlv_len)) { | |
15717 | if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) { | |
15718 | offset += 4; | |
15719 | tlv_offset += 4; | |
15720 | break; | |
15721 | } | |
15722 | if (rgn23_data[offset] != PORT_STE_TYPE) { | |
15723 | offset += rgn23_data[offset + 1] * 4 + 4; | |
15724 | tlv_offset += rgn23_data[offset + 1] * 4 + 4; | |
15725 | continue; | |
15726 | } | |
15727 | ||
15728 | /* This HBA contains PORT_STE configured */ | |
15729 | if (!rgn23_data[offset + 2]) | |
15730 | phba->hba_flag |= LINK_DISABLED; | |
15731 | ||
15732 | goto out; | |
15733 | } | |
15734 | } | |
026abb87 | 15735 | |
a0c87cbd | 15736 | out: |
a0c87cbd JS |
15737 | kfree(rgn23_data); |
15738 | return; | |
15739 | } | |
695a814e | 15740 | |
52d52440 JS |
15741 | /** |
15742 | * lpfc_wr_object - write an object to the firmware | |
15743 | * @phba: HBA structure that indicates port to create a queue on. | |
15744 | * @dmabuf_list: list of dmabufs to write to the port. | |
15745 | * @size: the total byte value of the objects to write to the port. | |
15746 | * @offset: the current offset to be used to start the transfer. | |
15747 | * | |
15748 | * This routine will create a wr_object mailbox command to send to the port. | |
15749 | * the mailbox command will be constructed using the dma buffers described in | |
15750 | * @dmabuf_list to create a list of BDEs. This routine will fill in as many | |
15751 | * BDEs that the imbedded mailbox can support. The @offset variable will be | |
15752 | * used to indicate the starting offset of the transfer and will also return | |
15753 | * the offset after the write object mailbox has completed. @size is used to | |
15754 | * determine the end of the object and whether the eof bit should be set. | |
15755 | * | |
15756 | * Return 0 is successful and offset will contain the the new offset to use | |
15757 | * for the next write. | |
15758 | * Return negative value for error cases. | |
15759 | **/ | |
15760 | int | |
15761 | lpfc_wr_object(struct lpfc_hba *phba, struct list_head *dmabuf_list, | |
15762 | uint32_t size, uint32_t *offset) | |
15763 | { | |
15764 | struct lpfc_mbx_wr_object *wr_object; | |
15765 | LPFC_MBOXQ_t *mbox; | |
15766 | int rc = 0, i = 0; | |
15767 | uint32_t shdr_status, shdr_add_status; | |
15768 | uint32_t mbox_tmo; | |
15769 | union lpfc_sli4_cfg_shdr *shdr; | |
15770 | struct lpfc_dmabuf *dmabuf; | |
15771 | uint32_t written = 0; | |
15772 | ||
15773 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
15774 | if (!mbox) | |
15775 | return -ENOMEM; | |
15776 | ||
15777 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
15778 | LPFC_MBOX_OPCODE_WRITE_OBJECT, | |
15779 | sizeof(struct lpfc_mbx_wr_object) - | |
15780 | sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED); | |
15781 | ||
15782 | wr_object = (struct lpfc_mbx_wr_object *)&mbox->u.mqe.un.wr_object; | |
15783 | wr_object->u.request.write_offset = *offset; | |
15784 | sprintf((uint8_t *)wr_object->u.request.object_name, "/"); | |
15785 | wr_object->u.request.object_name[0] = | |
15786 | cpu_to_le32(wr_object->u.request.object_name[0]); | |
15787 | bf_set(lpfc_wr_object_eof, &wr_object->u.request, 0); | |
15788 | list_for_each_entry(dmabuf, dmabuf_list, list) { | |
15789 | if (i >= LPFC_MBX_WR_CONFIG_MAX_BDE || written >= size) | |
15790 | break; | |
15791 | wr_object->u.request.bde[i].addrLow = putPaddrLow(dmabuf->phys); | |
15792 | wr_object->u.request.bde[i].addrHigh = | |
15793 | putPaddrHigh(dmabuf->phys); | |
15794 | if (written + SLI4_PAGE_SIZE >= size) { | |
15795 | wr_object->u.request.bde[i].tus.f.bdeSize = | |
15796 | (size - written); | |
15797 | written += (size - written); | |
15798 | bf_set(lpfc_wr_object_eof, &wr_object->u.request, 1); | |
15799 | } else { | |
15800 | wr_object->u.request.bde[i].tus.f.bdeSize = | |
15801 | SLI4_PAGE_SIZE; | |
15802 | written += SLI4_PAGE_SIZE; | |
15803 | } | |
15804 | i++; | |
15805 | } | |
15806 | wr_object->u.request.bde_count = i; | |
15807 | bf_set(lpfc_wr_object_write_length, &wr_object->u.request, written); | |
15808 | if (!phba->sli4_hba.intr_enable) | |
15809 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
15810 | else { | |
a183a15f | 15811 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
52d52440 JS |
15812 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
15813 | } | |
15814 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
15815 | shdr = (union lpfc_sli4_cfg_shdr *) &wr_object->header.cfg_shdr; | |
15816 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
15817 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
15818 | if (rc != MBX_TIMEOUT) | |
15819 | mempool_free(mbox, phba->mbox_mem_pool); | |
15820 | if (shdr_status || shdr_add_status || rc) { | |
15821 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
15822 | "3025 Write Object mailbox failed with " | |
15823 | "status x%x add_status x%x, mbx status x%x\n", | |
15824 | shdr_status, shdr_add_status, rc); | |
15825 | rc = -ENXIO; | |
15826 | } else | |
15827 | *offset += wr_object->u.response.actual_write_length; | |
15828 | return rc; | |
15829 | } | |
15830 | ||
695a814e JS |
15831 | /** |
15832 | * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands. | |
15833 | * @vport: pointer to vport data structure. | |
15834 | * | |
15835 | * This function iterate through the mailboxq and clean up all REG_LOGIN | |
15836 | * and REG_VPI mailbox commands associated with the vport. This function | |
15837 | * is called when driver want to restart discovery of the vport due to | |
15838 | * a Clear Virtual Link event. | |
15839 | **/ | |
15840 | void | |
15841 | lpfc_cleanup_pending_mbox(struct lpfc_vport *vport) | |
15842 | { | |
15843 | struct lpfc_hba *phba = vport->phba; | |
15844 | LPFC_MBOXQ_t *mb, *nextmb; | |
15845 | struct lpfc_dmabuf *mp; | |
78730cfe | 15846 | struct lpfc_nodelist *ndlp; |
d439d286 | 15847 | struct lpfc_nodelist *act_mbx_ndlp = NULL; |
589a52d6 | 15848 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
d439d286 | 15849 | LIST_HEAD(mbox_cmd_list); |
63e801ce | 15850 | uint8_t restart_loop; |
695a814e | 15851 | |
d439d286 | 15852 | /* Clean up internally queued mailbox commands with the vport */ |
695a814e JS |
15853 | spin_lock_irq(&phba->hbalock); |
15854 | list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) { | |
15855 | if (mb->vport != vport) | |
15856 | continue; | |
15857 | ||
15858 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) && | |
15859 | (mb->u.mb.mbxCommand != MBX_REG_VPI)) | |
15860 | continue; | |
15861 | ||
d439d286 JS |
15862 | list_del(&mb->list); |
15863 | list_add_tail(&mb->list, &mbox_cmd_list); | |
15864 | } | |
15865 | /* Clean up active mailbox command with the vport */ | |
15866 | mb = phba->sli.mbox_active; | |
15867 | if (mb && (mb->vport == vport)) { | |
15868 | if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) || | |
15869 | (mb->u.mb.mbxCommand == MBX_REG_VPI)) | |
15870 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
15871 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { | |
15872 | act_mbx_ndlp = (struct lpfc_nodelist *)mb->context2; | |
15873 | /* Put reference count for delayed processing */ | |
15874 | act_mbx_ndlp = lpfc_nlp_get(act_mbx_ndlp); | |
15875 | /* Unregister the RPI when mailbox complete */ | |
15876 | mb->mbox_flag |= LPFC_MBX_IMED_UNREG; | |
15877 | } | |
15878 | } | |
63e801ce JS |
15879 | /* Cleanup any mailbox completions which are not yet processed */ |
15880 | do { | |
15881 | restart_loop = 0; | |
15882 | list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) { | |
15883 | /* | |
15884 | * If this mailox is already processed or it is | |
15885 | * for another vport ignore it. | |
15886 | */ | |
15887 | if ((mb->vport != vport) || | |
15888 | (mb->mbox_flag & LPFC_MBX_IMED_UNREG)) | |
15889 | continue; | |
15890 | ||
15891 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) && | |
15892 | (mb->u.mb.mbxCommand != MBX_REG_VPI)) | |
15893 | continue; | |
15894 | ||
15895 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
15896 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { | |
15897 | ndlp = (struct lpfc_nodelist *)mb->context2; | |
15898 | /* Unregister the RPI when mailbox complete */ | |
15899 | mb->mbox_flag |= LPFC_MBX_IMED_UNREG; | |
15900 | restart_loop = 1; | |
15901 | spin_unlock_irq(&phba->hbalock); | |
15902 | spin_lock(shost->host_lock); | |
15903 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; | |
15904 | spin_unlock(shost->host_lock); | |
15905 | spin_lock_irq(&phba->hbalock); | |
15906 | break; | |
15907 | } | |
15908 | } | |
15909 | } while (restart_loop); | |
15910 | ||
d439d286 JS |
15911 | spin_unlock_irq(&phba->hbalock); |
15912 | ||
15913 | /* Release the cleaned-up mailbox commands */ | |
15914 | while (!list_empty(&mbox_cmd_list)) { | |
15915 | list_remove_head(&mbox_cmd_list, mb, LPFC_MBOXQ_t, list); | |
695a814e JS |
15916 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
15917 | mp = (struct lpfc_dmabuf *) (mb->context1); | |
15918 | if (mp) { | |
15919 | __lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
15920 | kfree(mp); | |
15921 | } | |
78730cfe | 15922 | ndlp = (struct lpfc_nodelist *) mb->context2; |
d439d286 | 15923 | mb->context2 = NULL; |
78730cfe | 15924 | if (ndlp) { |
ec21b3b0 | 15925 | spin_lock(shost->host_lock); |
589a52d6 | 15926 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
ec21b3b0 | 15927 | spin_unlock(shost->host_lock); |
78730cfe | 15928 | lpfc_nlp_put(ndlp); |
78730cfe | 15929 | } |
695a814e | 15930 | } |
695a814e JS |
15931 | mempool_free(mb, phba->mbox_mem_pool); |
15932 | } | |
d439d286 JS |
15933 | |
15934 | /* Release the ndlp with the cleaned-up active mailbox command */ | |
15935 | if (act_mbx_ndlp) { | |
15936 | spin_lock(shost->host_lock); | |
15937 | act_mbx_ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; | |
15938 | spin_unlock(shost->host_lock); | |
15939 | lpfc_nlp_put(act_mbx_ndlp); | |
695a814e | 15940 | } |
695a814e JS |
15941 | } |
15942 | ||
2a9bf3d0 JS |
15943 | /** |
15944 | * lpfc_drain_txq - Drain the txq | |
15945 | * @phba: Pointer to HBA context object. | |
15946 | * | |
15947 | * This function attempt to submit IOCBs on the txq | |
15948 | * to the adapter. For SLI4 adapters, the txq contains | |
15949 | * ELS IOCBs that have been deferred because the there | |
15950 | * are no SGLs. This congestion can occur with large | |
15951 | * vport counts during node discovery. | |
15952 | **/ | |
15953 | ||
15954 | uint32_t | |
15955 | lpfc_drain_txq(struct lpfc_hba *phba) | |
15956 | { | |
15957 | LIST_HEAD(completions); | |
15958 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; | |
15959 | struct lpfc_iocbq *piocbq = 0; | |
15960 | unsigned long iflags = 0; | |
15961 | char *fail_msg = NULL; | |
15962 | struct lpfc_sglq *sglq; | |
15963 | union lpfc_wqe wqe; | |
15964 | ||
15965 | spin_lock_irqsave(&phba->hbalock, iflags); | |
15966 | if (pring->txq_cnt > pring->txq_max) | |
15967 | pring->txq_max = pring->txq_cnt; | |
15968 | ||
15969 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
15970 | ||
15971 | while (pring->txq_cnt) { | |
15972 | spin_lock_irqsave(&phba->hbalock, iflags); | |
15973 | ||
19ca7609 | 15974 | piocbq = lpfc_sli_ringtx_get(phba, pring); |
a629852a JS |
15975 | if (!piocbq) { |
15976 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
15977 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
15978 | "2823 txq empty and txq_cnt is %d\n ", | |
15979 | pring->txq_cnt); | |
15980 | break; | |
15981 | } | |
19ca7609 | 15982 | sglq = __lpfc_sli_get_sglq(phba, piocbq); |
2a9bf3d0 | 15983 | if (!sglq) { |
19ca7609 | 15984 | __lpfc_sli_ringtx_put(phba, pring, piocbq); |
2a9bf3d0 JS |
15985 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
15986 | break; | |
2a9bf3d0 JS |
15987 | } |
15988 | ||
15989 | /* The xri and iocb resources secured, | |
15990 | * attempt to issue request | |
15991 | */ | |
6d368e53 | 15992 | piocbq->sli4_lxritag = sglq->sli4_lxritag; |
2a9bf3d0 JS |
15993 | piocbq->sli4_xritag = sglq->sli4_xritag; |
15994 | if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocbq, sglq)) | |
15995 | fail_msg = "to convert bpl to sgl"; | |
15996 | else if (lpfc_sli4_iocb2wqe(phba, piocbq, &wqe)) | |
15997 | fail_msg = "to convert iocb to wqe"; | |
15998 | else if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe)) | |
15999 | fail_msg = " - Wq is full"; | |
16000 | else | |
16001 | lpfc_sli_ringtxcmpl_put(phba, pring, piocbq); | |
16002 | ||
16003 | if (fail_msg) { | |
16004 | /* Failed means we can't issue and need to cancel */ | |
16005 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
16006 | "2822 IOCB failed %s iotag 0x%x " | |
16007 | "xri 0x%x\n", | |
16008 | fail_msg, | |
16009 | piocbq->iotag, piocbq->sli4_xritag); | |
16010 | list_add_tail(&piocbq->list, &completions); | |
16011 | } | |
16012 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
16013 | } | |
16014 | ||
2a9bf3d0 JS |
16015 | /* Cancel all the IOCBs that cannot be issued */ |
16016 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, | |
16017 | IOERR_SLI_ABORTED); | |
16018 | ||
16019 | return pring->txq_cnt; | |
16020 | } |