Commit | Line | Data |
---|---|---|
dea3101e | 1 | /******************************************************************* |
2 | * This file is part of the Emulex Linux Device Driver for * | |
c44ce173 | 3 | * Fibre Channel Host Bus Adapters. * |
16a59fb3 | 4 | * Copyright (C) 2004-2014 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); | |
e8d3c3b1 JS |
74 | static bool lpfc_sli4_mbox_completions_pending(struct lpfc_hba *phba); |
75 | static bool lpfc_sli4_process_missed_mbox_completions(struct lpfc_hba *phba); | |
0558056c | 76 | |
4f774513 JS |
77 | static IOCB_t * |
78 | lpfc_get_iocb_from_iocbq(struct lpfc_iocbq *iocbq) | |
79 | { | |
80 | return &iocbq->iocb; | |
81 | } | |
82 | ||
83 | /** | |
84 | * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue | |
85 | * @q: The Work Queue to operate on. | |
86 | * @wqe: The work Queue Entry to put on the Work queue. | |
87 | * | |
88 | * This routine will copy the contents of @wqe to the next available entry on | |
89 | * the @q. This function will then ring the Work Queue Doorbell to signal the | |
90 | * HBA to start processing the Work Queue Entry. This function returns 0 if | |
91 | * successful. If no entries are available on @q then this function will return | |
92 | * -ENOMEM. | |
93 | * The caller is expected to hold the hbalock when calling this routine. | |
94 | **/ | |
95 | static uint32_t | |
96 | lpfc_sli4_wq_put(struct lpfc_queue *q, union lpfc_wqe *wqe) | |
97 | { | |
2e90f4b5 | 98 | union lpfc_wqe *temp_wqe; |
4f774513 JS |
99 | struct lpfc_register doorbell; |
100 | uint32_t host_index; | |
027140ea | 101 | uint32_t idx; |
4f774513 | 102 | |
2e90f4b5 JS |
103 | /* sanity check on queue memory */ |
104 | if (unlikely(!q)) | |
105 | return -ENOMEM; | |
106 | temp_wqe = q->qe[q->host_index].wqe; | |
107 | ||
4f774513 | 108 | /* If the host has not yet processed the next entry then we are done */ |
027140ea JS |
109 | idx = ((q->host_index + 1) % q->entry_count); |
110 | if (idx == q->hba_index) { | |
b84daac9 | 111 | q->WQ_overflow++; |
4f774513 | 112 | return -ENOMEM; |
b84daac9 JS |
113 | } |
114 | q->WQ_posted++; | |
4f774513 | 115 | /* set consumption flag every once in a while */ |
ff78d8f9 | 116 | if (!((q->host_index + 1) % q->entry_repost)) |
f0d9bccc | 117 | bf_set(wqe_wqec, &wqe->generic.wqe_com, 1); |
fedd3b7b JS |
118 | if (q->phba->sli3_options & LPFC_SLI4_PHWQ_ENABLED) |
119 | bf_set(wqe_wqid, &wqe->generic.wqe_com, q->queue_id); | |
4f774513 JS |
120 | lpfc_sli_pcimem_bcopy(wqe, temp_wqe, q->entry_size); |
121 | ||
122 | /* Update the host index before invoking device */ | |
123 | host_index = q->host_index; | |
027140ea JS |
124 | |
125 | q->host_index = idx; | |
4f774513 JS |
126 | |
127 | /* Ring Doorbell */ | |
128 | doorbell.word0 = 0; | |
962bc51b JS |
129 | if (q->db_format == LPFC_DB_LIST_FORMAT) { |
130 | bf_set(lpfc_wq_db_list_fm_num_posted, &doorbell, 1); | |
131 | bf_set(lpfc_wq_db_list_fm_index, &doorbell, host_index); | |
132 | bf_set(lpfc_wq_db_list_fm_id, &doorbell, q->queue_id); | |
133 | } else if (q->db_format == LPFC_DB_RING_FORMAT) { | |
134 | bf_set(lpfc_wq_db_ring_fm_num_posted, &doorbell, 1); | |
135 | bf_set(lpfc_wq_db_ring_fm_id, &doorbell, q->queue_id); | |
136 | } else { | |
137 | return -EINVAL; | |
138 | } | |
139 | writel(doorbell.word0, q->db_regaddr); | |
4f774513 JS |
140 | |
141 | return 0; | |
142 | } | |
143 | ||
144 | /** | |
145 | * lpfc_sli4_wq_release - Updates internal hba index for WQ | |
146 | * @q: The Work Queue to operate on. | |
147 | * @index: The index to advance the hba index to. | |
148 | * | |
149 | * This routine will update the HBA index of a queue to reflect consumption of | |
150 | * Work Queue Entries by the HBA. When the HBA indicates that it has consumed | |
151 | * an entry the host calls this function to update the queue's internal | |
152 | * pointers. This routine returns the number of entries that were consumed by | |
153 | * the HBA. | |
154 | **/ | |
155 | static uint32_t | |
156 | lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index) | |
157 | { | |
158 | uint32_t released = 0; | |
159 | ||
2e90f4b5 JS |
160 | /* sanity check on queue memory */ |
161 | if (unlikely(!q)) | |
162 | return 0; | |
163 | ||
4f774513 JS |
164 | if (q->hba_index == index) |
165 | return 0; | |
166 | do { | |
167 | q->hba_index = ((q->hba_index + 1) % q->entry_count); | |
168 | released++; | |
169 | } while (q->hba_index != index); | |
170 | return released; | |
171 | } | |
172 | ||
173 | /** | |
174 | * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue | |
175 | * @q: The Mailbox Queue to operate on. | |
176 | * @wqe: The Mailbox Queue Entry to put on the Work queue. | |
177 | * | |
178 | * This routine will copy the contents of @mqe to the next available entry on | |
179 | * the @q. This function will then ring the Work Queue Doorbell to signal the | |
180 | * HBA to start processing the Work Queue Entry. This function returns 0 if | |
181 | * successful. If no entries are available on @q then this function will return | |
182 | * -ENOMEM. | |
183 | * The caller is expected to hold the hbalock when calling this routine. | |
184 | **/ | |
185 | static uint32_t | |
186 | lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe) | |
187 | { | |
2e90f4b5 | 188 | struct lpfc_mqe *temp_mqe; |
4f774513 JS |
189 | struct lpfc_register doorbell; |
190 | uint32_t host_index; | |
191 | ||
2e90f4b5 JS |
192 | /* sanity check on queue memory */ |
193 | if (unlikely(!q)) | |
194 | return -ENOMEM; | |
195 | temp_mqe = q->qe[q->host_index].mqe; | |
196 | ||
4f774513 JS |
197 | /* If the host has not yet processed the next entry then we are done */ |
198 | if (((q->host_index + 1) % q->entry_count) == q->hba_index) | |
199 | return -ENOMEM; | |
200 | lpfc_sli_pcimem_bcopy(mqe, temp_mqe, q->entry_size); | |
201 | /* Save off the mailbox pointer for completion */ | |
202 | q->phba->mbox = (MAILBOX_t *)temp_mqe; | |
203 | ||
204 | /* Update the host index before invoking device */ | |
205 | host_index = q->host_index; | |
206 | q->host_index = ((q->host_index + 1) % q->entry_count); | |
207 | ||
208 | /* Ring Doorbell */ | |
209 | doorbell.word0 = 0; | |
210 | bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1); | |
211 | bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id); | |
212 | writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr); | |
4f774513 JS |
213 | return 0; |
214 | } | |
215 | ||
216 | /** | |
217 | * lpfc_sli4_mq_release - Updates internal hba index for MQ | |
218 | * @q: The Mailbox Queue to operate on. | |
219 | * | |
220 | * This routine will update the HBA index of a queue to reflect consumption of | |
221 | * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed | |
222 | * an entry the host calls this function to update the queue's internal | |
223 | * pointers. This routine returns the number of entries that were consumed by | |
224 | * the HBA. | |
225 | **/ | |
226 | static uint32_t | |
227 | lpfc_sli4_mq_release(struct lpfc_queue *q) | |
228 | { | |
2e90f4b5 JS |
229 | /* sanity check on queue memory */ |
230 | if (unlikely(!q)) | |
231 | return 0; | |
232 | ||
4f774513 JS |
233 | /* Clear the mailbox pointer for completion */ |
234 | q->phba->mbox = NULL; | |
235 | q->hba_index = ((q->hba_index + 1) % q->entry_count); | |
236 | return 1; | |
237 | } | |
238 | ||
239 | /** | |
240 | * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ | |
241 | * @q: The Event Queue to get the first valid EQE from | |
242 | * | |
243 | * This routine will get the first valid Event Queue Entry from @q, update | |
244 | * the queue's internal hba index, and return the EQE. If no valid EQEs are in | |
245 | * the Queue (no more work to do), or the Queue is full of EQEs that have been | |
246 | * processed, but not popped back to the HBA then this routine will return NULL. | |
247 | **/ | |
248 | static struct lpfc_eqe * | |
249 | lpfc_sli4_eq_get(struct lpfc_queue *q) | |
250 | { | |
2e90f4b5 | 251 | struct lpfc_eqe *eqe; |
027140ea | 252 | uint32_t idx; |
2e90f4b5 JS |
253 | |
254 | /* sanity check on queue memory */ | |
255 | if (unlikely(!q)) | |
256 | return NULL; | |
257 | eqe = q->qe[q->hba_index].eqe; | |
4f774513 JS |
258 | |
259 | /* If the next EQE is not valid then we are done */ | |
cb5172ea | 260 | if (!bf_get_le32(lpfc_eqe_valid, eqe)) |
4f774513 JS |
261 | return NULL; |
262 | /* If the host has not yet processed the next entry then we are done */ | |
027140ea JS |
263 | idx = ((q->hba_index + 1) % q->entry_count); |
264 | if (idx == q->host_index) | |
4f774513 JS |
265 | return NULL; |
266 | ||
027140ea | 267 | q->hba_index = idx; |
27f344eb JS |
268 | |
269 | /* | |
270 | * insert barrier for instruction interlock : data from the hardware | |
271 | * must have the valid bit checked before it can be copied and acted | |
272 | * upon. Given what was seen in lpfc_sli4_cq_get() of speculative | |
273 | * instructions allowing action on content before valid bit checked, | |
274 | * add barrier here as well. May not be needed as "content" is a | |
275 | * single 32-bit entity here (vs multi word structure for cq's). | |
276 | */ | |
277 | mb(); | |
4f774513 JS |
278 | return eqe; |
279 | } | |
280 | ||
ba20c853 JS |
281 | /** |
282 | * lpfc_sli4_eq_clr_intr - Turn off interrupts from this EQ | |
283 | * @q: The Event Queue to disable interrupts | |
284 | * | |
285 | **/ | |
286 | static inline void | |
287 | lpfc_sli4_eq_clr_intr(struct lpfc_queue *q) | |
288 | { | |
289 | struct lpfc_register doorbell; | |
290 | ||
291 | doorbell.word0 = 0; | |
292 | bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1); | |
293 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT); | |
294 | bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell, | |
295 | (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT)); | |
296 | bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id); | |
297 | writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr); | |
298 | } | |
299 | ||
4f774513 JS |
300 | /** |
301 | * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ | |
302 | * @q: The Event Queue that the host has completed processing for. | |
303 | * @arm: Indicates whether the host wants to arms this CQ. | |
304 | * | |
305 | * This routine will mark all Event Queue Entries on @q, from the last | |
306 | * known completed entry to the last entry that was processed, as completed | |
307 | * by clearing the valid bit for each completion queue entry. Then it will | |
308 | * notify the HBA, by ringing the doorbell, that the EQEs have been processed. | |
309 | * The internal host index in the @q will be updated by this routine to indicate | |
310 | * that the host has finished processing the entries. The @arm parameter | |
311 | * indicates that the queue should be rearmed when ringing the doorbell. | |
312 | * | |
313 | * This function will return the number of EQEs that were popped. | |
314 | **/ | |
315 | uint32_t | |
316 | lpfc_sli4_eq_release(struct lpfc_queue *q, bool arm) | |
317 | { | |
318 | uint32_t released = 0; | |
319 | struct lpfc_eqe *temp_eqe; | |
320 | struct lpfc_register doorbell; | |
321 | ||
2e90f4b5 JS |
322 | /* sanity check on queue memory */ |
323 | if (unlikely(!q)) | |
324 | return 0; | |
325 | ||
4f774513 JS |
326 | /* while there are valid entries */ |
327 | while (q->hba_index != q->host_index) { | |
328 | temp_eqe = q->qe[q->host_index].eqe; | |
cb5172ea | 329 | bf_set_le32(lpfc_eqe_valid, temp_eqe, 0); |
4f774513 JS |
330 | released++; |
331 | q->host_index = ((q->host_index + 1) % q->entry_count); | |
332 | } | |
333 | if (unlikely(released == 0 && !arm)) | |
334 | return 0; | |
335 | ||
336 | /* ring doorbell for number popped */ | |
337 | doorbell.word0 = 0; | |
338 | if (arm) { | |
339 | bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1); | |
340 | bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1); | |
341 | } | |
342 | bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released); | |
343 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT); | |
6b5151fd JS |
344 | bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell, |
345 | (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT)); | |
346 | bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id); | |
4f774513 | 347 | writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr); |
a747c9ce JS |
348 | /* PCI read to flush PCI pipeline on re-arming for INTx mode */ |
349 | if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM)) | |
350 | readl(q->phba->sli4_hba.EQCQDBregaddr); | |
4f774513 JS |
351 | return released; |
352 | } | |
353 | ||
354 | /** | |
355 | * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ | |
356 | * @q: The Completion Queue to get the first valid CQE from | |
357 | * | |
358 | * This routine will get the first valid Completion Queue Entry from @q, update | |
359 | * the queue's internal hba index, and return the CQE. If no valid CQEs are in | |
360 | * the Queue (no more work to do), or the Queue is full of CQEs that have been | |
361 | * processed, but not popped back to the HBA then this routine will return NULL. | |
362 | **/ | |
363 | static struct lpfc_cqe * | |
364 | lpfc_sli4_cq_get(struct lpfc_queue *q) | |
365 | { | |
366 | struct lpfc_cqe *cqe; | |
027140ea | 367 | uint32_t idx; |
4f774513 | 368 | |
2e90f4b5 JS |
369 | /* sanity check on queue memory */ |
370 | if (unlikely(!q)) | |
371 | return NULL; | |
372 | ||
4f774513 | 373 | /* If the next CQE is not valid then we are done */ |
cb5172ea | 374 | if (!bf_get_le32(lpfc_cqe_valid, q->qe[q->hba_index].cqe)) |
4f774513 JS |
375 | return NULL; |
376 | /* If the host has not yet processed the next entry then we are done */ | |
027140ea JS |
377 | idx = ((q->hba_index + 1) % q->entry_count); |
378 | if (idx == q->host_index) | |
4f774513 JS |
379 | return NULL; |
380 | ||
381 | cqe = q->qe[q->hba_index].cqe; | |
027140ea | 382 | q->hba_index = idx; |
27f344eb JS |
383 | |
384 | /* | |
385 | * insert barrier for instruction interlock : data from the hardware | |
386 | * must have the valid bit checked before it can be copied and acted | |
387 | * upon. Speculative instructions were allowing a bcopy at the start | |
388 | * of lpfc_sli4_fp_handle_wcqe(), which is called immediately | |
389 | * after our return, to copy data before the valid bit check above | |
390 | * was done. As such, some of the copied data was stale. The barrier | |
391 | * ensures the check is before any data is copied. | |
392 | */ | |
393 | mb(); | |
4f774513 JS |
394 | return cqe; |
395 | } | |
396 | ||
397 | /** | |
398 | * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ | |
399 | * @q: The Completion Queue that the host has completed processing for. | |
400 | * @arm: Indicates whether the host wants to arms this CQ. | |
401 | * | |
402 | * This routine will mark all Completion queue entries on @q, from the last | |
403 | * known completed entry to the last entry that was processed, as completed | |
404 | * by clearing the valid bit for each completion queue entry. Then it will | |
405 | * notify the HBA, by ringing the doorbell, that the CQEs have been processed. | |
406 | * The internal host index in the @q will be updated by this routine to indicate | |
407 | * that the host has finished processing the entries. The @arm parameter | |
408 | * indicates that the queue should be rearmed when ringing the doorbell. | |
409 | * | |
410 | * This function will return the number of CQEs that were released. | |
411 | **/ | |
412 | uint32_t | |
413 | lpfc_sli4_cq_release(struct lpfc_queue *q, bool arm) | |
414 | { | |
415 | uint32_t released = 0; | |
416 | struct lpfc_cqe *temp_qe; | |
417 | struct lpfc_register doorbell; | |
418 | ||
2e90f4b5 JS |
419 | /* sanity check on queue memory */ |
420 | if (unlikely(!q)) | |
421 | return 0; | |
4f774513 JS |
422 | /* while there are valid entries */ |
423 | while (q->hba_index != q->host_index) { | |
424 | temp_qe = q->qe[q->host_index].cqe; | |
cb5172ea | 425 | bf_set_le32(lpfc_cqe_valid, temp_qe, 0); |
4f774513 JS |
426 | released++; |
427 | q->host_index = ((q->host_index + 1) % q->entry_count); | |
428 | } | |
429 | if (unlikely(released == 0 && !arm)) | |
430 | return 0; | |
431 | ||
432 | /* ring doorbell for number popped */ | |
433 | doorbell.word0 = 0; | |
434 | if (arm) | |
435 | bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1); | |
436 | bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released); | |
437 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION); | |
6b5151fd JS |
438 | bf_set(lpfc_eqcq_doorbell_cqid_hi, &doorbell, |
439 | (q->queue_id >> LPFC_CQID_HI_FIELD_SHIFT)); | |
440 | bf_set(lpfc_eqcq_doorbell_cqid_lo, &doorbell, q->queue_id); | |
4f774513 JS |
441 | writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr); |
442 | return released; | |
443 | } | |
444 | ||
445 | /** | |
446 | * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue | |
447 | * @q: The Header Receive Queue to operate on. | |
448 | * @wqe: The Receive Queue Entry to put on the Receive queue. | |
449 | * | |
450 | * This routine will copy the contents of @wqe to the next available entry on | |
451 | * the @q. This function will then ring the Receive Queue Doorbell to signal the | |
452 | * HBA to start processing the Receive Queue Entry. This function returns the | |
453 | * index that the rqe was copied to if successful. If no entries are available | |
454 | * on @q then this function will return -ENOMEM. | |
455 | * The caller is expected to hold the hbalock when calling this routine. | |
456 | **/ | |
457 | static int | |
458 | lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq, | |
459 | struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe) | |
460 | { | |
2e90f4b5 JS |
461 | struct lpfc_rqe *temp_hrqe; |
462 | struct lpfc_rqe *temp_drqe; | |
4f774513 | 463 | struct lpfc_register doorbell; |
5a25bf36 | 464 | int put_index; |
4f774513 | 465 | |
2e90f4b5 JS |
466 | /* sanity check on queue memory */ |
467 | if (unlikely(!hq) || unlikely(!dq)) | |
468 | return -ENOMEM; | |
5a25bf36 | 469 | put_index = hq->host_index; |
2e90f4b5 JS |
470 | temp_hrqe = hq->qe[hq->host_index].rqe; |
471 | temp_drqe = dq->qe[dq->host_index].rqe; | |
472 | ||
4f774513 JS |
473 | if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ) |
474 | return -EINVAL; | |
475 | if (hq->host_index != dq->host_index) | |
476 | return -EINVAL; | |
477 | /* If the host has not yet processed the next entry then we are done */ | |
478 | if (((hq->host_index + 1) % hq->entry_count) == hq->hba_index) | |
479 | return -EBUSY; | |
480 | lpfc_sli_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size); | |
481 | lpfc_sli_pcimem_bcopy(drqe, temp_drqe, dq->entry_size); | |
482 | ||
483 | /* Update the host index to point to the next slot */ | |
484 | hq->host_index = ((hq->host_index + 1) % hq->entry_count); | |
485 | dq->host_index = ((dq->host_index + 1) % dq->entry_count); | |
486 | ||
487 | /* Ring The Header Receive Queue Doorbell */ | |
73d91e50 | 488 | if (!(hq->host_index % hq->entry_repost)) { |
4f774513 | 489 | doorbell.word0 = 0; |
962bc51b JS |
490 | if (hq->db_format == LPFC_DB_RING_FORMAT) { |
491 | bf_set(lpfc_rq_db_ring_fm_num_posted, &doorbell, | |
492 | hq->entry_repost); | |
493 | bf_set(lpfc_rq_db_ring_fm_id, &doorbell, hq->queue_id); | |
494 | } else if (hq->db_format == LPFC_DB_LIST_FORMAT) { | |
495 | bf_set(lpfc_rq_db_list_fm_num_posted, &doorbell, | |
496 | hq->entry_repost); | |
497 | bf_set(lpfc_rq_db_list_fm_index, &doorbell, | |
498 | hq->host_index); | |
499 | bf_set(lpfc_rq_db_list_fm_id, &doorbell, hq->queue_id); | |
500 | } else { | |
501 | return -EINVAL; | |
502 | } | |
503 | writel(doorbell.word0, hq->db_regaddr); | |
4f774513 JS |
504 | } |
505 | return put_index; | |
506 | } | |
507 | ||
508 | /** | |
509 | * lpfc_sli4_rq_release - Updates internal hba index for RQ | |
510 | * @q: The Header Receive Queue to operate on. | |
511 | * | |
512 | * This routine will update the HBA index of a queue to reflect consumption of | |
513 | * one Receive Queue Entry by the HBA. When the HBA indicates that it has | |
514 | * consumed an entry the host calls this function to update the queue's | |
515 | * internal pointers. This routine returns the number of entries that were | |
516 | * consumed by the HBA. | |
517 | **/ | |
518 | static uint32_t | |
519 | lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq) | |
520 | { | |
2e90f4b5 JS |
521 | /* sanity check on queue memory */ |
522 | if (unlikely(!hq) || unlikely(!dq)) | |
523 | return 0; | |
524 | ||
4f774513 JS |
525 | if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ)) |
526 | return 0; | |
527 | hq->hba_index = ((hq->hba_index + 1) % hq->entry_count); | |
528 | dq->hba_index = ((dq->hba_index + 1) % dq->entry_count); | |
529 | return 1; | |
530 | } | |
531 | ||
e59058c4 | 532 | /** |
3621a710 | 533 | * lpfc_cmd_iocb - Get next command iocb entry in the ring |
e59058c4 JS |
534 | * @phba: Pointer to HBA context object. |
535 | * @pring: Pointer to driver SLI ring object. | |
536 | * | |
537 | * This function returns pointer to next command iocb entry | |
538 | * in the command ring. The caller must hold hbalock to prevent | |
539 | * other threads consume the next command iocb. | |
540 | * SLI-2/SLI-3 provide different sized iocbs. | |
541 | **/ | |
ed957684 JS |
542 | static inline IOCB_t * |
543 | lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) | |
544 | { | |
7e56aa25 JS |
545 | return (IOCB_t *) (((char *) pring->sli.sli3.cmdringaddr) + |
546 | pring->sli.sli3.cmdidx * phba->iocb_cmd_size); | |
ed957684 JS |
547 | } |
548 | ||
e59058c4 | 549 | /** |
3621a710 | 550 | * lpfc_resp_iocb - Get next response iocb entry in the ring |
e59058c4 JS |
551 | * @phba: Pointer to HBA context object. |
552 | * @pring: Pointer to driver SLI ring object. | |
553 | * | |
554 | * This function returns pointer to next response iocb entry | |
555 | * in the response ring. The caller must hold hbalock to make sure | |
556 | * that no other thread consume the next response iocb. | |
557 | * SLI-2/SLI-3 provide different sized iocbs. | |
558 | **/ | |
ed957684 JS |
559 | static inline IOCB_t * |
560 | lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) | |
561 | { | |
7e56aa25 JS |
562 | return (IOCB_t *) (((char *) pring->sli.sli3.rspringaddr) + |
563 | pring->sli.sli3.rspidx * phba->iocb_rsp_size); | |
ed957684 JS |
564 | } |
565 | ||
e59058c4 | 566 | /** |
3621a710 | 567 | * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool |
e59058c4 JS |
568 | * @phba: Pointer to HBA context object. |
569 | * | |
570 | * This function is called with hbalock held. This function | |
571 | * allocates a new driver iocb object from the iocb pool. If the | |
572 | * allocation is successful, it returns pointer to the newly | |
573 | * allocated iocb object else it returns NULL. | |
574 | **/ | |
4f2e66c6 | 575 | struct lpfc_iocbq * |
2e0fef85 | 576 | __lpfc_sli_get_iocbq(struct lpfc_hba *phba) |
0bd4ca25 JSEC |
577 | { |
578 | struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list; | |
579 | struct lpfc_iocbq * iocbq = NULL; | |
580 | ||
581 | list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list); | |
2a9bf3d0 JS |
582 | if (iocbq) |
583 | phba->iocb_cnt++; | |
584 | if (phba->iocb_cnt > phba->iocb_max) | |
585 | phba->iocb_max = phba->iocb_cnt; | |
0bd4ca25 JSEC |
586 | return iocbq; |
587 | } | |
588 | ||
da0436e9 JS |
589 | /** |
590 | * __lpfc_clear_active_sglq - Remove the active sglq for this XRI. | |
591 | * @phba: Pointer to HBA context object. | |
592 | * @xritag: XRI value. | |
593 | * | |
594 | * This function clears the sglq pointer from the array of acive | |
595 | * sglq's. The xritag that is passed in is used to index into the | |
596 | * array. Before the xritag can be used it needs to be adjusted | |
597 | * by subtracting the xribase. | |
598 | * | |
599 | * Returns sglq ponter = success, NULL = Failure. | |
600 | **/ | |
601 | static struct lpfc_sglq * | |
602 | __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag) | |
603 | { | |
da0436e9 | 604 | struct lpfc_sglq *sglq; |
6d368e53 JS |
605 | |
606 | sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag]; | |
607 | phba->sli4_hba.lpfc_sglq_active_list[xritag] = NULL; | |
da0436e9 JS |
608 | return sglq; |
609 | } | |
610 | ||
611 | /** | |
612 | * __lpfc_get_active_sglq - Get the active sglq for this XRI. | |
613 | * @phba: Pointer to HBA context object. | |
614 | * @xritag: XRI value. | |
615 | * | |
616 | * This function returns the sglq pointer from the array of acive | |
617 | * sglq's. The xritag that is passed in is used to index into the | |
618 | * array. Before the xritag can be used it needs to be adjusted | |
619 | * by subtracting the xribase. | |
620 | * | |
621 | * Returns sglq ponter = success, NULL = Failure. | |
622 | **/ | |
0f65ff68 | 623 | struct lpfc_sglq * |
da0436e9 JS |
624 | __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag) |
625 | { | |
da0436e9 | 626 | struct lpfc_sglq *sglq; |
6d368e53 JS |
627 | |
628 | sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag]; | |
da0436e9 JS |
629 | return sglq; |
630 | } | |
631 | ||
19ca7609 | 632 | /** |
1151e3ec | 633 | * lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap. |
19ca7609 JS |
634 | * @phba: Pointer to HBA context object. |
635 | * @xritag: xri used in this exchange. | |
636 | * @rrq: The RRQ to be cleared. | |
637 | * | |
19ca7609 | 638 | **/ |
1151e3ec JS |
639 | void |
640 | lpfc_clr_rrq_active(struct lpfc_hba *phba, | |
641 | uint16_t xritag, | |
642 | struct lpfc_node_rrq *rrq) | |
19ca7609 | 643 | { |
1151e3ec | 644 | struct lpfc_nodelist *ndlp = NULL; |
19ca7609 | 645 | |
1151e3ec JS |
646 | if ((rrq->vport) && NLP_CHK_NODE_ACT(rrq->ndlp)) |
647 | ndlp = lpfc_findnode_did(rrq->vport, rrq->nlp_DID); | |
19ca7609 JS |
648 | |
649 | /* The target DID could have been swapped (cable swap) | |
650 | * we should use the ndlp from the findnode if it is | |
651 | * available. | |
652 | */ | |
1151e3ec | 653 | if ((!ndlp) && rrq->ndlp) |
19ca7609 JS |
654 | ndlp = rrq->ndlp; |
655 | ||
1151e3ec JS |
656 | if (!ndlp) |
657 | goto out; | |
658 | ||
cff261f6 | 659 | if (test_and_clear_bit(xritag, ndlp->active_rrqs_xri_bitmap)) { |
19ca7609 JS |
660 | rrq->send_rrq = 0; |
661 | rrq->xritag = 0; | |
662 | rrq->rrq_stop_time = 0; | |
663 | } | |
1151e3ec | 664 | out: |
19ca7609 JS |
665 | mempool_free(rrq, phba->rrq_pool); |
666 | } | |
667 | ||
668 | /** | |
669 | * lpfc_handle_rrq_active - Checks if RRQ has waithed RATOV. | |
670 | * @phba: Pointer to HBA context object. | |
671 | * | |
672 | * This function is called with hbalock held. This function | |
673 | * Checks if stop_time (ratov from setting rrq active) has | |
674 | * been reached, if it has and the send_rrq flag is set then | |
675 | * it will call lpfc_send_rrq. If the send_rrq flag is not set | |
676 | * then it will just call the routine to clear the rrq and | |
677 | * free the rrq resource. | |
678 | * The timer is set to the next rrq that is going to expire before | |
679 | * leaving the routine. | |
680 | * | |
681 | **/ | |
682 | void | |
683 | lpfc_handle_rrq_active(struct lpfc_hba *phba) | |
684 | { | |
685 | struct lpfc_node_rrq *rrq; | |
686 | struct lpfc_node_rrq *nextrrq; | |
687 | unsigned long next_time; | |
688 | unsigned long iflags; | |
1151e3ec | 689 | LIST_HEAD(send_rrq); |
19ca7609 JS |
690 | |
691 | spin_lock_irqsave(&phba->hbalock, iflags); | |
692 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; | |
256ec0d0 | 693 | next_time = jiffies + msecs_to_jiffies(1000 * (phba->fc_ratov + 1)); |
19ca7609 | 694 | list_for_each_entry_safe(rrq, nextrrq, |
1151e3ec JS |
695 | &phba->active_rrq_list, list) { |
696 | if (time_after(jiffies, rrq->rrq_stop_time)) | |
697 | list_move(&rrq->list, &send_rrq); | |
698 | else if (time_before(rrq->rrq_stop_time, next_time)) | |
19ca7609 JS |
699 | next_time = rrq->rrq_stop_time; |
700 | } | |
701 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
06918ac5 JS |
702 | if ((!list_empty(&phba->active_rrq_list)) && |
703 | (!(phba->pport->load_flag & FC_UNLOADING))) | |
19ca7609 | 704 | mod_timer(&phba->rrq_tmr, next_time); |
1151e3ec JS |
705 | list_for_each_entry_safe(rrq, nextrrq, &send_rrq, list) { |
706 | list_del(&rrq->list); | |
707 | if (!rrq->send_rrq) | |
708 | /* this call will free the rrq */ | |
709 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); | |
710 | else if (lpfc_send_rrq(phba, rrq)) { | |
711 | /* if we send the rrq then the completion handler | |
712 | * will clear the bit in the xribitmap. | |
713 | */ | |
714 | lpfc_clr_rrq_active(phba, rrq->xritag, | |
715 | rrq); | |
716 | } | |
717 | } | |
19ca7609 JS |
718 | } |
719 | ||
720 | /** | |
721 | * lpfc_get_active_rrq - Get the active RRQ for this exchange. | |
722 | * @vport: Pointer to vport context object. | |
723 | * @xri: The xri used in the exchange. | |
724 | * @did: The targets DID for this exchange. | |
725 | * | |
726 | * returns NULL = rrq not found in the phba->active_rrq_list. | |
727 | * rrq = rrq for this xri and target. | |
728 | **/ | |
729 | struct lpfc_node_rrq * | |
730 | lpfc_get_active_rrq(struct lpfc_vport *vport, uint16_t xri, uint32_t did) | |
731 | { | |
732 | struct lpfc_hba *phba = vport->phba; | |
733 | struct lpfc_node_rrq *rrq; | |
734 | struct lpfc_node_rrq *nextrrq; | |
735 | unsigned long iflags; | |
736 | ||
737 | if (phba->sli_rev != LPFC_SLI_REV4) | |
738 | return NULL; | |
739 | spin_lock_irqsave(&phba->hbalock, iflags); | |
740 | list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) { | |
741 | if (rrq->vport == vport && rrq->xritag == xri && | |
742 | rrq->nlp_DID == did){ | |
743 | list_del(&rrq->list); | |
744 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
745 | return rrq; | |
746 | } | |
747 | } | |
748 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
749 | return NULL; | |
750 | } | |
751 | ||
752 | /** | |
753 | * lpfc_cleanup_vports_rrqs - Remove and clear the active RRQ for this vport. | |
754 | * @vport: Pointer to vport context object. | |
1151e3ec JS |
755 | * @ndlp: Pointer to the lpfc_node_list structure. |
756 | * If ndlp is NULL Remove all active RRQs for this vport from the | |
757 | * phba->active_rrq_list and clear the rrq. | |
758 | * If ndlp is not NULL then only remove rrqs for this vport & this ndlp. | |
19ca7609 JS |
759 | **/ |
760 | void | |
1151e3ec | 761 | lpfc_cleanup_vports_rrqs(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
19ca7609 JS |
762 | |
763 | { | |
764 | struct lpfc_hba *phba = vport->phba; | |
765 | struct lpfc_node_rrq *rrq; | |
766 | struct lpfc_node_rrq *nextrrq; | |
767 | unsigned long iflags; | |
1151e3ec | 768 | LIST_HEAD(rrq_list); |
19ca7609 JS |
769 | |
770 | if (phba->sli_rev != LPFC_SLI_REV4) | |
771 | return; | |
1151e3ec JS |
772 | if (!ndlp) { |
773 | lpfc_sli4_vport_delete_els_xri_aborted(vport); | |
774 | lpfc_sli4_vport_delete_fcp_xri_aborted(vport); | |
19ca7609 | 775 | } |
1151e3ec JS |
776 | spin_lock_irqsave(&phba->hbalock, iflags); |
777 | list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) | |
778 | if ((rrq->vport == vport) && (!ndlp || rrq->ndlp == ndlp)) | |
779 | list_move(&rrq->list, &rrq_list); | |
19ca7609 | 780 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
1151e3ec JS |
781 | |
782 | list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) { | |
783 | list_del(&rrq->list); | |
784 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); | |
785 | } | |
19ca7609 JS |
786 | } |
787 | ||
19ca7609 | 788 | /** |
1151e3ec | 789 | * lpfc_test_rrq_active - Test RRQ bit in xri_bitmap. |
19ca7609 JS |
790 | * @phba: Pointer to HBA context object. |
791 | * @ndlp: Targets nodelist pointer for this exchange. | |
792 | * @xritag the xri in the bitmap to test. | |
793 | * | |
794 | * This function is called with hbalock held. This function | |
795 | * returns 0 = rrq not active for this xri | |
796 | * 1 = rrq is valid for this xri. | |
797 | **/ | |
1151e3ec JS |
798 | int |
799 | lpfc_test_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, | |
19ca7609 JS |
800 | uint16_t xritag) |
801 | { | |
19ca7609 JS |
802 | if (!ndlp) |
803 | return 0; | |
cff261f6 JS |
804 | if (!ndlp->active_rrqs_xri_bitmap) |
805 | return 0; | |
806 | if (test_bit(xritag, ndlp->active_rrqs_xri_bitmap)) | |
19ca7609 JS |
807 | return 1; |
808 | else | |
809 | return 0; | |
810 | } | |
811 | ||
812 | /** | |
813 | * lpfc_set_rrq_active - set RRQ active bit in xri_bitmap. | |
814 | * @phba: Pointer to HBA context object. | |
815 | * @ndlp: nodelist pointer for this target. | |
816 | * @xritag: xri used in this exchange. | |
817 | * @rxid: Remote Exchange ID. | |
818 | * @send_rrq: Flag used to determine if we should send rrq els cmd. | |
819 | * | |
820 | * This function takes the hbalock. | |
821 | * The active bit is always set in the active rrq xri_bitmap even | |
822 | * if there is no slot avaiable for the other rrq information. | |
823 | * | |
824 | * returns 0 rrq actived for this xri | |
825 | * < 0 No memory or invalid ndlp. | |
826 | **/ | |
827 | int | |
828 | lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, | |
b42c07c8 | 829 | uint16_t xritag, uint16_t rxid, uint16_t send_rrq) |
19ca7609 | 830 | { |
19ca7609 | 831 | unsigned long iflags; |
b42c07c8 JS |
832 | struct lpfc_node_rrq *rrq; |
833 | int empty; | |
834 | ||
835 | if (!ndlp) | |
836 | return -EINVAL; | |
837 | ||
838 | if (!phba->cfg_enable_rrq) | |
839 | return -EINVAL; | |
19ca7609 JS |
840 | |
841 | spin_lock_irqsave(&phba->hbalock, iflags); | |
b42c07c8 JS |
842 | if (phba->pport->load_flag & FC_UNLOADING) { |
843 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; | |
844 | goto out; | |
845 | } | |
846 | ||
847 | /* | |
848 | * set the active bit even if there is no mem available. | |
849 | */ | |
850 | if (NLP_CHK_FREE_REQ(ndlp)) | |
851 | goto out; | |
852 | ||
853 | if (ndlp->vport && (ndlp->vport->load_flag & FC_UNLOADING)) | |
854 | goto out; | |
855 | ||
cff261f6 JS |
856 | if (!ndlp->active_rrqs_xri_bitmap) |
857 | goto out; | |
858 | ||
859 | if (test_and_set_bit(xritag, ndlp->active_rrqs_xri_bitmap)) | |
b42c07c8 JS |
860 | goto out; |
861 | ||
19ca7609 | 862 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
b42c07c8 JS |
863 | rrq = mempool_alloc(phba->rrq_pool, GFP_KERNEL); |
864 | if (!rrq) { | |
865 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
866 | "3155 Unable to allocate RRQ xri:0x%x rxid:0x%x" | |
867 | " DID:0x%x Send:%d\n", | |
868 | xritag, rxid, ndlp->nlp_DID, send_rrq); | |
869 | return -EINVAL; | |
870 | } | |
e5771b4d JS |
871 | if (phba->cfg_enable_rrq == 1) |
872 | rrq->send_rrq = send_rrq; | |
873 | else | |
874 | rrq->send_rrq = 0; | |
b42c07c8 | 875 | rrq->xritag = xritag; |
256ec0d0 JS |
876 | rrq->rrq_stop_time = jiffies + |
877 | msecs_to_jiffies(1000 * (phba->fc_ratov + 1)); | |
b42c07c8 JS |
878 | rrq->ndlp = ndlp; |
879 | rrq->nlp_DID = ndlp->nlp_DID; | |
880 | rrq->vport = ndlp->vport; | |
881 | rrq->rxid = rxid; | |
b42c07c8 JS |
882 | spin_lock_irqsave(&phba->hbalock, iflags); |
883 | empty = list_empty(&phba->active_rrq_list); | |
884 | list_add_tail(&rrq->list, &phba->active_rrq_list); | |
885 | phba->hba_flag |= HBA_RRQ_ACTIVE; | |
886 | if (empty) | |
887 | lpfc_worker_wake_up(phba); | |
888 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
889 | return 0; | |
890 | out: | |
891 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
892 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
893 | "2921 Can't set rrq active xri:0x%x rxid:0x%x" | |
894 | " DID:0x%x Send:%d\n", | |
895 | xritag, rxid, ndlp->nlp_DID, send_rrq); | |
896 | return -EINVAL; | |
19ca7609 JS |
897 | } |
898 | ||
da0436e9 JS |
899 | /** |
900 | * __lpfc_sli_get_sglq - Allocates an iocb object from sgl pool | |
901 | * @phba: Pointer to HBA context object. | |
19ca7609 | 902 | * @piocb: Pointer to the iocbq. |
da0436e9 | 903 | * |
dafe8cea | 904 | * This function is called with the ring lock held. This function |
6d368e53 | 905 | * gets a new driver sglq object from the sglq list. If the |
da0436e9 JS |
906 | * list is not empty then it is successful, it returns pointer to the newly |
907 | * allocated sglq object else it returns NULL. | |
908 | **/ | |
909 | static struct lpfc_sglq * | |
19ca7609 | 910 | __lpfc_sli_get_sglq(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq) |
da0436e9 JS |
911 | { |
912 | struct list_head *lpfc_sgl_list = &phba->sli4_hba.lpfc_sgl_list; | |
913 | struct lpfc_sglq *sglq = NULL; | |
19ca7609 | 914 | struct lpfc_sglq *start_sglq = NULL; |
19ca7609 JS |
915 | struct lpfc_scsi_buf *lpfc_cmd; |
916 | struct lpfc_nodelist *ndlp; | |
917 | int found = 0; | |
918 | ||
919 | if (piocbq->iocb_flag & LPFC_IO_FCP) { | |
920 | lpfc_cmd = (struct lpfc_scsi_buf *) piocbq->context1; | |
921 | ndlp = lpfc_cmd->rdata->pnode; | |
be858b65 JS |
922 | } else if ((piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) && |
923 | !(piocbq->iocb_flag & LPFC_IO_LIBDFC)) | |
19ca7609 | 924 | ndlp = piocbq->context_un.ndlp; |
d5ce53b7 | 925 | else if (piocbq->iocb_flag & LPFC_IO_LIBDFC) |
93d1379e | 926 | ndlp = piocbq->context_un.ndlp; |
19ca7609 JS |
927 | else |
928 | ndlp = piocbq->context1; | |
929 | ||
da0436e9 | 930 | list_remove_head(lpfc_sgl_list, sglq, struct lpfc_sglq, list); |
19ca7609 JS |
931 | start_sglq = sglq; |
932 | while (!found) { | |
933 | if (!sglq) | |
934 | return NULL; | |
ee0f4fe1 | 935 | if (lpfc_test_rrq_active(phba, ndlp, sglq->sli4_lxritag)) { |
19ca7609 JS |
936 | /* This xri has an rrq outstanding for this DID. |
937 | * put it back in the list and get another xri. | |
938 | */ | |
939 | list_add_tail(&sglq->list, lpfc_sgl_list); | |
940 | sglq = NULL; | |
941 | list_remove_head(lpfc_sgl_list, sglq, | |
942 | struct lpfc_sglq, list); | |
943 | if (sglq == start_sglq) { | |
944 | sglq = NULL; | |
945 | break; | |
946 | } else | |
947 | continue; | |
948 | } | |
949 | sglq->ndlp = ndlp; | |
950 | found = 1; | |
6d368e53 | 951 | phba->sli4_hba.lpfc_sglq_active_list[sglq->sli4_lxritag] = sglq; |
19ca7609 JS |
952 | sglq->state = SGL_ALLOCATED; |
953 | } | |
da0436e9 JS |
954 | return sglq; |
955 | } | |
956 | ||
e59058c4 | 957 | /** |
3621a710 | 958 | * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool |
e59058c4 JS |
959 | * @phba: Pointer to HBA context object. |
960 | * | |
961 | * This function is called with no lock held. This function | |
962 | * allocates a new driver iocb object from the iocb pool. If the | |
963 | * allocation is successful, it returns pointer to the newly | |
964 | * allocated iocb object else it returns NULL. | |
965 | **/ | |
2e0fef85 JS |
966 | struct lpfc_iocbq * |
967 | lpfc_sli_get_iocbq(struct lpfc_hba *phba) | |
968 | { | |
969 | struct lpfc_iocbq * iocbq = NULL; | |
970 | unsigned long iflags; | |
971 | ||
972 | spin_lock_irqsave(&phba->hbalock, iflags); | |
973 | iocbq = __lpfc_sli_get_iocbq(phba); | |
974 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
975 | return iocbq; | |
976 | } | |
977 | ||
4f774513 JS |
978 | /** |
979 | * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool | |
980 | * @phba: Pointer to HBA context object. | |
981 | * @iocbq: Pointer to driver iocb object. | |
982 | * | |
983 | * This function is called with hbalock held to release driver | |
984 | * iocb object to the iocb pool. The iotag in the iocb object | |
985 | * does not change for each use of the iocb object. This function | |
986 | * clears all other fields of the iocb object when it is freed. | |
987 | * The sqlq structure that holds the xritag and phys and virtual | |
988 | * mappings for the scatter gather list is retrieved from the | |
989 | * active array of sglq. The get of the sglq pointer also clears | |
990 | * the entry in the array. If the status of the IO indiactes that | |
991 | * this IO was aborted then the sglq entry it put on the | |
992 | * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the | |
993 | * IO has good status or fails for any other reason then the sglq | |
994 | * entry is added to the free list (lpfc_sgl_list). | |
995 | **/ | |
996 | static void | |
997 | __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) | |
998 | { | |
999 | struct lpfc_sglq *sglq; | |
1000 | size_t start_clean = offsetof(struct lpfc_iocbq, iocb); | |
2a9bf3d0 JS |
1001 | unsigned long iflag = 0; |
1002 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; | |
4f774513 JS |
1003 | |
1004 | if (iocbq->sli4_xritag == NO_XRI) | |
1005 | sglq = NULL; | |
1006 | else | |
6d368e53 JS |
1007 | sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_lxritag); |
1008 | ||
0e9bb8d7 | 1009 | |
4f774513 | 1010 | if (sglq) { |
0f65ff68 JS |
1011 | if ((iocbq->iocb_flag & LPFC_EXCHANGE_BUSY) && |
1012 | (sglq->state != SGL_XRI_ABORTED)) { | |
4f774513 JS |
1013 | spin_lock_irqsave(&phba->sli4_hba.abts_sgl_list_lock, |
1014 | iflag); | |
1015 | list_add(&sglq->list, | |
1016 | &phba->sli4_hba.lpfc_abts_els_sgl_list); | |
1017 | spin_unlock_irqrestore( | |
1018 | &phba->sli4_hba.abts_sgl_list_lock, iflag); | |
0f65ff68 | 1019 | } else { |
dafe8cea | 1020 | spin_lock_irqsave(&pring->ring_lock, iflag); |
0f65ff68 | 1021 | sglq->state = SGL_FREED; |
19ca7609 | 1022 | sglq->ndlp = NULL; |
fedd3b7b JS |
1023 | list_add_tail(&sglq->list, |
1024 | &phba->sli4_hba.lpfc_sgl_list); | |
dafe8cea | 1025 | spin_unlock_irqrestore(&pring->ring_lock, iflag); |
2a9bf3d0 JS |
1026 | |
1027 | /* Check if TXQ queue needs to be serviced */ | |
0e9bb8d7 | 1028 | if (!list_empty(&pring->txq)) |
2a9bf3d0 | 1029 | lpfc_worker_wake_up(phba); |
0f65ff68 | 1030 | } |
4f774513 JS |
1031 | } |
1032 | ||
1033 | ||
1034 | /* | |
1035 | * Clean all volatile data fields, preserve iotag and node struct. | |
1036 | */ | |
1037 | memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean); | |
6d368e53 | 1038 | iocbq->sli4_lxritag = NO_XRI; |
4f774513 JS |
1039 | iocbq->sli4_xritag = NO_XRI; |
1040 | list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); | |
1041 | } | |
1042 | ||
2a9bf3d0 | 1043 | |
e59058c4 | 1044 | /** |
3772a991 | 1045 | * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool |
e59058c4 JS |
1046 | * @phba: Pointer to HBA context object. |
1047 | * @iocbq: Pointer to driver iocb object. | |
1048 | * | |
1049 | * This function is called with hbalock held to release driver | |
1050 | * iocb object to the iocb pool. The iotag in the iocb object | |
1051 | * does not change for each use of the iocb object. This function | |
1052 | * clears all other fields of the iocb object when it is freed. | |
1053 | **/ | |
a6ababd2 | 1054 | static void |
3772a991 | 1055 | __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
604a3e30 | 1056 | { |
2e0fef85 | 1057 | size_t start_clean = offsetof(struct lpfc_iocbq, iocb); |
604a3e30 | 1058 | |
0e9bb8d7 | 1059 | |
604a3e30 JB |
1060 | /* |
1061 | * Clean all volatile data fields, preserve iotag and node struct. | |
1062 | */ | |
1063 | memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean); | |
3772a991 | 1064 | iocbq->sli4_xritag = NO_XRI; |
604a3e30 JB |
1065 | list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); |
1066 | } | |
1067 | ||
3772a991 JS |
1068 | /** |
1069 | * __lpfc_sli_release_iocbq - Release iocb to the iocb pool | |
1070 | * @phba: Pointer to HBA context object. | |
1071 | * @iocbq: Pointer to driver iocb object. | |
1072 | * | |
1073 | * This function is called with hbalock held to release driver | |
1074 | * iocb object to the iocb pool. The iotag in the iocb object | |
1075 | * does not change for each use of the iocb object. This function | |
1076 | * clears all other fields of the iocb object when it is freed. | |
1077 | **/ | |
1078 | static void | |
1079 | __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) | |
1080 | { | |
1081 | phba->__lpfc_sli_release_iocbq(phba, iocbq); | |
2a9bf3d0 | 1082 | phba->iocb_cnt--; |
3772a991 JS |
1083 | } |
1084 | ||
e59058c4 | 1085 | /** |
3621a710 | 1086 | * lpfc_sli_release_iocbq - Release iocb to the iocb pool |
e59058c4 JS |
1087 | * @phba: Pointer to HBA context object. |
1088 | * @iocbq: Pointer to driver iocb object. | |
1089 | * | |
1090 | * This function is called with no lock held to release the iocb to | |
1091 | * iocb pool. | |
1092 | **/ | |
2e0fef85 JS |
1093 | void |
1094 | lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) | |
1095 | { | |
1096 | unsigned long iflags; | |
1097 | ||
1098 | /* | |
1099 | * Clean all volatile data fields, preserve iotag and node struct. | |
1100 | */ | |
1101 | spin_lock_irqsave(&phba->hbalock, iflags); | |
1102 | __lpfc_sli_release_iocbq(phba, iocbq); | |
1103 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
1104 | } | |
1105 | ||
a257bf90 JS |
1106 | /** |
1107 | * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list. | |
1108 | * @phba: Pointer to HBA context object. | |
1109 | * @iocblist: List of IOCBs. | |
1110 | * @ulpstatus: ULP status in IOCB command field. | |
1111 | * @ulpWord4: ULP word-4 in IOCB command field. | |
1112 | * | |
1113 | * This function is called with a list of IOCBs to cancel. It cancels the IOCB | |
1114 | * on the list by invoking the complete callback function associated with the | |
1115 | * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond | |
1116 | * fields. | |
1117 | **/ | |
1118 | void | |
1119 | lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist, | |
1120 | uint32_t ulpstatus, uint32_t ulpWord4) | |
1121 | { | |
1122 | struct lpfc_iocbq *piocb; | |
1123 | ||
1124 | while (!list_empty(iocblist)) { | |
1125 | list_remove_head(iocblist, piocb, struct lpfc_iocbq, list); | |
a257bf90 JS |
1126 | if (!piocb->iocb_cmpl) |
1127 | lpfc_sli_release_iocbq(phba, piocb); | |
1128 | else { | |
1129 | piocb->iocb.ulpStatus = ulpstatus; | |
1130 | piocb->iocb.un.ulpWord[4] = ulpWord4; | |
1131 | (piocb->iocb_cmpl) (phba, piocb, piocb); | |
1132 | } | |
1133 | } | |
1134 | return; | |
1135 | } | |
1136 | ||
e59058c4 | 1137 | /** |
3621a710 JS |
1138 | * lpfc_sli_iocb_cmd_type - Get the iocb type |
1139 | * @iocb_cmnd: iocb command code. | |
e59058c4 JS |
1140 | * |
1141 | * This function is called by ring event handler function to get the iocb type. | |
1142 | * This function translates the iocb command to an iocb command type used to | |
1143 | * decide the final disposition of each completed IOCB. | |
1144 | * The function returns | |
1145 | * LPFC_UNKNOWN_IOCB if it is an unsupported iocb | |
1146 | * LPFC_SOL_IOCB if it is a solicited iocb completion | |
1147 | * LPFC_ABORT_IOCB if it is an abort iocb | |
1148 | * LPFC_UNSOL_IOCB if it is an unsolicited iocb | |
1149 | * | |
1150 | * The caller is not required to hold any lock. | |
1151 | **/ | |
dea3101e | 1152 | static lpfc_iocb_type |
1153 | lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd) | |
1154 | { | |
1155 | lpfc_iocb_type type = LPFC_UNKNOWN_IOCB; | |
1156 | ||
1157 | if (iocb_cmnd > CMD_MAX_IOCB_CMD) | |
1158 | return 0; | |
1159 | ||
1160 | switch (iocb_cmnd) { | |
1161 | case CMD_XMIT_SEQUENCE_CR: | |
1162 | case CMD_XMIT_SEQUENCE_CX: | |
1163 | case CMD_XMIT_BCAST_CN: | |
1164 | case CMD_XMIT_BCAST_CX: | |
1165 | case CMD_ELS_REQUEST_CR: | |
1166 | case CMD_ELS_REQUEST_CX: | |
1167 | case CMD_CREATE_XRI_CR: | |
1168 | case CMD_CREATE_XRI_CX: | |
1169 | case CMD_GET_RPI_CN: | |
1170 | case CMD_XMIT_ELS_RSP_CX: | |
1171 | case CMD_GET_RPI_CR: | |
1172 | case CMD_FCP_IWRITE_CR: | |
1173 | case CMD_FCP_IWRITE_CX: | |
1174 | case CMD_FCP_IREAD_CR: | |
1175 | case CMD_FCP_IREAD_CX: | |
1176 | case CMD_FCP_ICMND_CR: | |
1177 | case CMD_FCP_ICMND_CX: | |
f5603511 JS |
1178 | case CMD_FCP_TSEND_CX: |
1179 | case CMD_FCP_TRSP_CX: | |
1180 | case CMD_FCP_TRECEIVE_CX: | |
1181 | case CMD_FCP_AUTO_TRSP_CX: | |
dea3101e | 1182 | case CMD_ADAPTER_MSG: |
1183 | case CMD_ADAPTER_DUMP: | |
1184 | case CMD_XMIT_SEQUENCE64_CR: | |
1185 | case CMD_XMIT_SEQUENCE64_CX: | |
1186 | case CMD_XMIT_BCAST64_CN: | |
1187 | case CMD_XMIT_BCAST64_CX: | |
1188 | case CMD_ELS_REQUEST64_CR: | |
1189 | case CMD_ELS_REQUEST64_CX: | |
1190 | case CMD_FCP_IWRITE64_CR: | |
1191 | case CMD_FCP_IWRITE64_CX: | |
1192 | case CMD_FCP_IREAD64_CR: | |
1193 | case CMD_FCP_IREAD64_CX: | |
1194 | case CMD_FCP_ICMND64_CR: | |
1195 | case CMD_FCP_ICMND64_CX: | |
f5603511 JS |
1196 | case CMD_FCP_TSEND64_CX: |
1197 | case CMD_FCP_TRSP64_CX: | |
1198 | case CMD_FCP_TRECEIVE64_CX: | |
dea3101e | 1199 | case CMD_GEN_REQUEST64_CR: |
1200 | case CMD_GEN_REQUEST64_CX: | |
1201 | case CMD_XMIT_ELS_RSP64_CX: | |
da0436e9 JS |
1202 | case DSSCMD_IWRITE64_CR: |
1203 | case DSSCMD_IWRITE64_CX: | |
1204 | case DSSCMD_IREAD64_CR: | |
1205 | case DSSCMD_IREAD64_CX: | |
dea3101e | 1206 | type = LPFC_SOL_IOCB; |
1207 | break; | |
1208 | case CMD_ABORT_XRI_CN: | |
1209 | case CMD_ABORT_XRI_CX: | |
1210 | case CMD_CLOSE_XRI_CN: | |
1211 | case CMD_CLOSE_XRI_CX: | |
1212 | case CMD_XRI_ABORTED_CX: | |
1213 | case CMD_ABORT_MXRI64_CN: | |
6669f9bb | 1214 | case CMD_XMIT_BLS_RSP64_CX: |
dea3101e | 1215 | type = LPFC_ABORT_IOCB; |
1216 | break; | |
1217 | case CMD_RCV_SEQUENCE_CX: | |
1218 | case CMD_RCV_ELS_REQ_CX: | |
1219 | case CMD_RCV_SEQUENCE64_CX: | |
1220 | case CMD_RCV_ELS_REQ64_CX: | |
57127f15 | 1221 | case CMD_ASYNC_STATUS: |
ed957684 JS |
1222 | case CMD_IOCB_RCV_SEQ64_CX: |
1223 | case CMD_IOCB_RCV_ELS64_CX: | |
1224 | case CMD_IOCB_RCV_CONT64_CX: | |
3163f725 | 1225 | case CMD_IOCB_RET_XRI64_CX: |
dea3101e | 1226 | type = LPFC_UNSOL_IOCB; |
1227 | break; | |
3163f725 JS |
1228 | case CMD_IOCB_XMIT_MSEQ64_CR: |
1229 | case CMD_IOCB_XMIT_MSEQ64_CX: | |
1230 | case CMD_IOCB_RCV_SEQ_LIST64_CX: | |
1231 | case CMD_IOCB_RCV_ELS_LIST64_CX: | |
1232 | case CMD_IOCB_CLOSE_EXTENDED_CN: | |
1233 | case CMD_IOCB_ABORT_EXTENDED_CN: | |
1234 | case CMD_IOCB_RET_HBQE64_CN: | |
1235 | case CMD_IOCB_FCP_IBIDIR64_CR: | |
1236 | case CMD_IOCB_FCP_IBIDIR64_CX: | |
1237 | case CMD_IOCB_FCP_ITASKMGT64_CX: | |
1238 | case CMD_IOCB_LOGENTRY_CN: | |
1239 | case CMD_IOCB_LOGENTRY_ASYNC_CN: | |
1240 | printk("%s - Unhandled SLI-3 Command x%x\n", | |
cadbd4a5 | 1241 | __func__, iocb_cmnd); |
3163f725 JS |
1242 | type = LPFC_UNKNOWN_IOCB; |
1243 | break; | |
dea3101e | 1244 | default: |
1245 | type = LPFC_UNKNOWN_IOCB; | |
1246 | break; | |
1247 | } | |
1248 | ||
1249 | return type; | |
1250 | } | |
1251 | ||
e59058c4 | 1252 | /** |
3621a710 | 1253 | * lpfc_sli_ring_map - Issue config_ring mbox for all rings |
e59058c4 JS |
1254 | * @phba: Pointer to HBA context object. |
1255 | * | |
1256 | * This function is called from SLI initialization code | |
1257 | * to configure every ring of the HBA's SLI interface. The | |
1258 | * caller is not required to hold any lock. This function issues | |
1259 | * a config_ring mailbox command for each ring. | |
1260 | * This function returns zero if successful else returns a negative | |
1261 | * error code. | |
1262 | **/ | |
dea3101e | 1263 | static int |
ed957684 | 1264 | lpfc_sli_ring_map(struct lpfc_hba *phba) |
dea3101e | 1265 | { |
1266 | struct lpfc_sli *psli = &phba->sli; | |
ed957684 JS |
1267 | LPFC_MBOXQ_t *pmb; |
1268 | MAILBOX_t *pmbox; | |
1269 | int i, rc, ret = 0; | |
dea3101e | 1270 | |
ed957684 JS |
1271 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
1272 | if (!pmb) | |
1273 | return -ENOMEM; | |
04c68496 | 1274 | pmbox = &pmb->u.mb; |
ed957684 | 1275 | phba->link_state = LPFC_INIT_MBX_CMDS; |
dea3101e | 1276 | for (i = 0; i < psli->num_rings; i++) { |
dea3101e | 1277 | lpfc_config_ring(phba, i, pmb); |
1278 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); | |
1279 | if (rc != MBX_SUCCESS) { | |
92d7f7b0 | 1280 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 1281 | "0446 Adapter failed to init (%d), " |
dea3101e | 1282 | "mbxCmd x%x CFG_RING, mbxStatus x%x, " |
1283 | "ring %d\n", | |
e8b62011 JS |
1284 | rc, pmbox->mbxCommand, |
1285 | pmbox->mbxStatus, i); | |
2e0fef85 | 1286 | phba->link_state = LPFC_HBA_ERROR; |
ed957684 JS |
1287 | ret = -ENXIO; |
1288 | break; | |
dea3101e | 1289 | } |
1290 | } | |
ed957684 JS |
1291 | mempool_free(pmb, phba->mbox_mem_pool); |
1292 | return ret; | |
dea3101e | 1293 | } |
1294 | ||
e59058c4 | 1295 | /** |
3621a710 | 1296 | * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq |
e59058c4 JS |
1297 | * @phba: Pointer to HBA context object. |
1298 | * @pring: Pointer to driver SLI ring object. | |
1299 | * @piocb: Pointer to the driver iocb object. | |
1300 | * | |
1301 | * This function is called with hbalock held. The function adds the | |
1302 | * new iocb to txcmplq of the given ring. This function always returns | |
1303 | * 0. If this function is called for ELS ring, this function checks if | |
1304 | * there is a vport associated with the ELS command. This function also | |
1305 | * starts els_tmofunc timer if this is an ELS command. | |
1306 | **/ | |
dea3101e | 1307 | static int |
2e0fef85 JS |
1308 | lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
1309 | struct lpfc_iocbq *piocb) | |
dea3101e | 1310 | { |
dea3101e | 1311 | list_add_tail(&piocb->list, &pring->txcmplq); |
4f2e66c6 | 1312 | piocb->iocb_flag |= LPFC_IO_ON_TXCMPLQ; |
2a9bf3d0 | 1313 | |
92d7f7b0 JS |
1314 | if ((unlikely(pring->ringno == LPFC_ELS_RING)) && |
1315 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && | |
06918ac5 JS |
1316 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN) && |
1317 | (!(piocb->vport->load_flag & FC_UNLOADING))) { | |
92d7f7b0 JS |
1318 | if (!piocb->vport) |
1319 | BUG(); | |
1320 | else | |
1321 | mod_timer(&piocb->vport->els_tmofunc, | |
256ec0d0 JS |
1322 | jiffies + |
1323 | msecs_to_jiffies(1000 * (phba->fc_ratov << 1))); | |
92d7f7b0 JS |
1324 | } |
1325 | ||
dea3101e | 1326 | |
2e0fef85 | 1327 | return 0; |
dea3101e | 1328 | } |
1329 | ||
e59058c4 | 1330 | /** |
3621a710 | 1331 | * lpfc_sli_ringtx_get - Get first element of the txq |
e59058c4 JS |
1332 | * @phba: Pointer to HBA context object. |
1333 | * @pring: Pointer to driver SLI ring object. | |
1334 | * | |
1335 | * This function is called with hbalock held to get next | |
1336 | * iocb in txq of the given ring. If there is any iocb in | |
1337 | * the txq, the function returns first iocb in the list after | |
1338 | * removing the iocb from the list, else it returns NULL. | |
1339 | **/ | |
2a9bf3d0 | 1340 | struct lpfc_iocbq * |
2e0fef85 | 1341 | lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
dea3101e | 1342 | { |
dea3101e | 1343 | struct lpfc_iocbq *cmd_iocb; |
1344 | ||
858c9f6c | 1345 | list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list); |
2e0fef85 | 1346 | return cmd_iocb; |
dea3101e | 1347 | } |
1348 | ||
e59058c4 | 1349 | /** |
3621a710 | 1350 | * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring |
e59058c4 JS |
1351 | * @phba: Pointer to HBA context object. |
1352 | * @pring: Pointer to driver SLI ring object. | |
1353 | * | |
1354 | * This function is called with hbalock held and the caller must post the | |
1355 | * iocb without releasing the lock. If the caller releases the lock, | |
1356 | * iocb slot returned by the function is not guaranteed to be available. | |
1357 | * The function returns pointer to the next available iocb slot if there | |
1358 | * is available slot in the ring, else it returns NULL. | |
1359 | * If the get index of the ring is ahead of the put index, the function | |
1360 | * will post an error attention event to the worker thread to take the | |
1361 | * HBA to offline state. | |
1362 | **/ | |
dea3101e | 1363 | static IOCB_t * |
1364 | lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring) | |
1365 | { | |
34b02dcd | 1366 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
7e56aa25 JS |
1367 | uint32_t max_cmd_idx = pring->sli.sli3.numCiocb; |
1368 | if ((pring->sli.sli3.next_cmdidx == pring->sli.sli3.cmdidx) && | |
1369 | (++pring->sli.sli3.next_cmdidx >= max_cmd_idx)) | |
1370 | pring->sli.sli3.next_cmdidx = 0; | |
dea3101e | 1371 | |
7e56aa25 JS |
1372 | if (unlikely(pring->sli.sli3.local_getidx == |
1373 | pring->sli.sli3.next_cmdidx)) { | |
dea3101e | 1374 | |
7e56aa25 | 1375 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
dea3101e | 1376 | |
7e56aa25 | 1377 | if (unlikely(pring->sli.sli3.local_getidx >= max_cmd_idx)) { |
dea3101e | 1378 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
e8b62011 | 1379 | "0315 Ring %d issue: portCmdGet %d " |
025dfdaf | 1380 | "is bigger than cmd ring %d\n", |
e8b62011 | 1381 | pring->ringno, |
7e56aa25 JS |
1382 | pring->sli.sli3.local_getidx, |
1383 | max_cmd_idx); | |
dea3101e | 1384 | |
2e0fef85 | 1385 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e | 1386 | /* |
1387 | * All error attention handlers are posted to | |
1388 | * worker thread | |
1389 | */ | |
1390 | phba->work_ha |= HA_ERATT; | |
1391 | phba->work_hs = HS_FFER3; | |
92d7f7b0 | 1392 | |
5e9d9b82 | 1393 | lpfc_worker_wake_up(phba); |
dea3101e | 1394 | |
1395 | return NULL; | |
1396 | } | |
1397 | ||
7e56aa25 | 1398 | if (pring->sli.sli3.local_getidx == pring->sli.sli3.next_cmdidx) |
dea3101e | 1399 | return NULL; |
1400 | } | |
1401 | ||
ed957684 | 1402 | return lpfc_cmd_iocb(phba, pring); |
dea3101e | 1403 | } |
1404 | ||
e59058c4 | 1405 | /** |
3621a710 | 1406 | * lpfc_sli_next_iotag - Get an iotag for the iocb |
e59058c4 JS |
1407 | * @phba: Pointer to HBA context object. |
1408 | * @iocbq: Pointer to driver iocb object. | |
1409 | * | |
1410 | * This function gets an iotag for the iocb. If there is no unused iotag and | |
1411 | * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup | |
1412 | * array and assigns a new iotag. | |
1413 | * The function returns the allocated iotag if successful, else returns zero. | |
1414 | * Zero is not a valid iotag. | |
1415 | * The caller is not required to hold any lock. | |
1416 | **/ | |
604a3e30 | 1417 | uint16_t |
2e0fef85 | 1418 | lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
dea3101e | 1419 | { |
2e0fef85 JS |
1420 | struct lpfc_iocbq **new_arr; |
1421 | struct lpfc_iocbq **old_arr; | |
604a3e30 JB |
1422 | size_t new_len; |
1423 | struct lpfc_sli *psli = &phba->sli; | |
1424 | uint16_t iotag; | |
dea3101e | 1425 | |
2e0fef85 | 1426 | spin_lock_irq(&phba->hbalock); |
604a3e30 JB |
1427 | iotag = psli->last_iotag; |
1428 | if(++iotag < psli->iocbq_lookup_len) { | |
1429 | psli->last_iotag = iotag; | |
1430 | psli->iocbq_lookup[iotag] = iocbq; | |
2e0fef85 | 1431 | spin_unlock_irq(&phba->hbalock); |
604a3e30 JB |
1432 | iocbq->iotag = iotag; |
1433 | return iotag; | |
2e0fef85 | 1434 | } else if (psli->iocbq_lookup_len < (0xffff |
604a3e30 JB |
1435 | - LPFC_IOCBQ_LOOKUP_INCREMENT)) { |
1436 | new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT; | |
2e0fef85 JS |
1437 | spin_unlock_irq(&phba->hbalock); |
1438 | new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *), | |
604a3e30 JB |
1439 | GFP_KERNEL); |
1440 | if (new_arr) { | |
2e0fef85 | 1441 | spin_lock_irq(&phba->hbalock); |
604a3e30 JB |
1442 | old_arr = psli->iocbq_lookup; |
1443 | if (new_len <= psli->iocbq_lookup_len) { | |
1444 | /* highly unprobable case */ | |
1445 | kfree(new_arr); | |
1446 | iotag = psli->last_iotag; | |
1447 | if(++iotag < psli->iocbq_lookup_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 | return iotag; | |
1453 | } | |
2e0fef85 | 1454 | spin_unlock_irq(&phba->hbalock); |
604a3e30 JB |
1455 | return 0; |
1456 | } | |
1457 | if (psli->iocbq_lookup) | |
1458 | memcpy(new_arr, old_arr, | |
1459 | ((psli->last_iotag + 1) * | |
311464ec | 1460 | sizeof (struct lpfc_iocbq *))); |
604a3e30 JB |
1461 | psli->iocbq_lookup = new_arr; |
1462 | psli->iocbq_lookup_len = new_len; | |
1463 | psli->last_iotag = iotag; | |
1464 | psli->iocbq_lookup[iotag] = iocbq; | |
2e0fef85 | 1465 | spin_unlock_irq(&phba->hbalock); |
604a3e30 JB |
1466 | iocbq->iotag = iotag; |
1467 | kfree(old_arr); | |
1468 | return iotag; | |
1469 | } | |
8f6d98d2 | 1470 | } else |
2e0fef85 | 1471 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 1472 | |
bc73905a | 1473 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
e8b62011 JS |
1474 | "0318 Failed to allocate IOTAG.last IOTAG is %d\n", |
1475 | psli->last_iotag); | |
dea3101e | 1476 | |
604a3e30 | 1477 | return 0; |
dea3101e | 1478 | } |
1479 | ||
e59058c4 | 1480 | /** |
3621a710 | 1481 | * lpfc_sli_submit_iocb - Submit an iocb to the firmware |
e59058c4 JS |
1482 | * @phba: Pointer to HBA context object. |
1483 | * @pring: Pointer to driver SLI ring object. | |
1484 | * @iocb: Pointer to iocb slot in the ring. | |
1485 | * @nextiocb: Pointer to driver iocb object which need to be | |
1486 | * posted to firmware. | |
1487 | * | |
1488 | * This function is called with hbalock held to post a new iocb to | |
1489 | * the firmware. This function copies the new iocb to ring iocb slot and | |
1490 | * updates the ring pointers. It adds the new iocb to txcmplq if there is | |
1491 | * a completion call back for this iocb else the function will free the | |
1492 | * iocb object. | |
1493 | **/ | |
dea3101e | 1494 | static void |
1495 | lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
1496 | IOCB_t *iocb, struct lpfc_iocbq *nextiocb) | |
1497 | { | |
1498 | /* | |
604a3e30 | 1499 | * Set up an iotag |
dea3101e | 1500 | */ |
604a3e30 | 1501 | nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0; |
dea3101e | 1502 | |
e2a0a9d6 | 1503 | |
a58cbd52 JS |
1504 | if (pring->ringno == LPFC_ELS_RING) { |
1505 | lpfc_debugfs_slow_ring_trc(phba, | |
1506 | "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x", | |
1507 | *(((uint32_t *) &nextiocb->iocb) + 4), | |
1508 | *(((uint32_t *) &nextiocb->iocb) + 6), | |
1509 | *(((uint32_t *) &nextiocb->iocb) + 7)); | |
1510 | } | |
1511 | ||
dea3101e | 1512 | /* |
1513 | * Issue iocb command to adapter | |
1514 | */ | |
92d7f7b0 | 1515 | lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size); |
dea3101e | 1516 | wmb(); |
1517 | pring->stats.iocb_cmd++; | |
1518 | ||
1519 | /* | |
1520 | * If there is no completion routine to call, we can release the | |
1521 | * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF, | |
1522 | * that have no rsp ring completion, iocb_cmpl MUST be NULL. | |
1523 | */ | |
1524 | if (nextiocb->iocb_cmpl) | |
1525 | lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb); | |
604a3e30 | 1526 | else |
2e0fef85 | 1527 | __lpfc_sli_release_iocbq(phba, nextiocb); |
dea3101e | 1528 | |
1529 | /* | |
1530 | * Let the HBA know what IOCB slot will be the next one the | |
1531 | * driver will put a command into. | |
1532 | */ | |
7e56aa25 JS |
1533 | pring->sli.sli3.cmdidx = pring->sli.sli3.next_cmdidx; |
1534 | writel(pring->sli.sli3.cmdidx, &phba->host_gp[pring->ringno].cmdPutInx); | |
dea3101e | 1535 | } |
1536 | ||
e59058c4 | 1537 | /** |
3621a710 | 1538 | * lpfc_sli_update_full_ring - Update the chip attention register |
e59058c4 JS |
1539 | * @phba: Pointer to HBA context object. |
1540 | * @pring: Pointer to driver SLI ring object. | |
1541 | * | |
1542 | * The caller is not required to hold any lock for calling this function. | |
1543 | * This function updates the chip attention bits for the ring to inform firmware | |
1544 | * that there are pending work to be done for this ring and requests an | |
1545 | * interrupt when there is space available in the ring. This function is | |
1546 | * called when the driver is unable to post more iocbs to the ring due | |
1547 | * to unavailability of space in the ring. | |
1548 | **/ | |
dea3101e | 1549 | static void |
2e0fef85 | 1550 | lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
dea3101e | 1551 | { |
1552 | int ringno = pring->ringno; | |
1553 | ||
1554 | pring->flag |= LPFC_CALL_RING_AVAILABLE; | |
1555 | ||
1556 | wmb(); | |
1557 | ||
1558 | /* | |
1559 | * Set ring 'ringno' to SET R0CE_REQ in Chip Att register. | |
1560 | * The HBA will tell us when an IOCB entry is available. | |
1561 | */ | |
1562 | writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr); | |
1563 | readl(phba->CAregaddr); /* flush */ | |
1564 | ||
1565 | pring->stats.iocb_cmd_full++; | |
1566 | } | |
1567 | ||
e59058c4 | 1568 | /** |
3621a710 | 1569 | * lpfc_sli_update_ring - Update chip attention register |
e59058c4 JS |
1570 | * @phba: Pointer to HBA context object. |
1571 | * @pring: Pointer to driver SLI ring object. | |
1572 | * | |
1573 | * This function updates the chip attention register bit for the | |
1574 | * given ring to inform HBA that there is more work to be done | |
1575 | * in this ring. The caller is not required to hold any lock. | |
1576 | **/ | |
dea3101e | 1577 | static void |
2e0fef85 | 1578 | lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
dea3101e | 1579 | { |
1580 | int ringno = pring->ringno; | |
1581 | ||
1582 | /* | |
1583 | * Tell the HBA that there is work to do in this ring. | |
1584 | */ | |
34b02dcd JS |
1585 | if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) { |
1586 | wmb(); | |
1587 | writel(CA_R0ATT << (ringno * 4), phba->CAregaddr); | |
1588 | readl(phba->CAregaddr); /* flush */ | |
1589 | } | |
dea3101e | 1590 | } |
1591 | ||
e59058c4 | 1592 | /** |
3621a710 | 1593 | * lpfc_sli_resume_iocb - Process iocbs in the txq |
e59058c4 JS |
1594 | * @phba: Pointer to HBA context object. |
1595 | * @pring: Pointer to driver SLI ring object. | |
1596 | * | |
1597 | * This function is called with hbalock held to post pending iocbs | |
1598 | * in the txq to the firmware. This function is called when driver | |
1599 | * detects space available in the ring. | |
1600 | **/ | |
dea3101e | 1601 | static void |
2e0fef85 | 1602 | lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
dea3101e | 1603 | { |
1604 | IOCB_t *iocb; | |
1605 | struct lpfc_iocbq *nextiocb; | |
1606 | ||
1607 | /* | |
1608 | * Check to see if: | |
1609 | * (a) there is anything on the txq to send | |
1610 | * (b) link is up | |
1611 | * (c) link attention events can be processed (fcp ring only) | |
1612 | * (d) IOCB processing is not blocked by the outstanding mbox command. | |
1613 | */ | |
0e9bb8d7 JS |
1614 | |
1615 | if (lpfc_is_link_up(phba) && | |
1616 | (!list_empty(&pring->txq)) && | |
dea3101e | 1617 | (pring->ringno != phba->sli.fcp_ring || |
0b727fea | 1618 | phba->sli.sli_flag & LPFC_PROCESS_LA)) { |
dea3101e | 1619 | |
1620 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && | |
1621 | (nextiocb = lpfc_sli_ringtx_get(phba, pring))) | |
1622 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); | |
1623 | ||
1624 | if (iocb) | |
1625 | lpfc_sli_update_ring(phba, pring); | |
1626 | else | |
1627 | lpfc_sli_update_full_ring(phba, pring); | |
1628 | } | |
1629 | ||
1630 | return; | |
1631 | } | |
1632 | ||
e59058c4 | 1633 | /** |
3621a710 | 1634 | * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ |
e59058c4 JS |
1635 | * @phba: Pointer to HBA context object. |
1636 | * @hbqno: HBQ number. | |
1637 | * | |
1638 | * This function is called with hbalock held to get the next | |
1639 | * available slot for the given HBQ. If there is free slot | |
1640 | * available for the HBQ it will return pointer to the next available | |
1641 | * HBQ entry else it will return NULL. | |
1642 | **/ | |
a6ababd2 | 1643 | static struct lpfc_hbq_entry * |
ed957684 JS |
1644 | lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno) |
1645 | { | |
1646 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; | |
1647 | ||
1648 | if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx && | |
1649 | ++hbqp->next_hbqPutIdx >= hbqp->entry_count) | |
1650 | hbqp->next_hbqPutIdx = 0; | |
1651 | ||
1652 | if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) { | |
92d7f7b0 | 1653 | uint32_t raw_index = phba->hbq_get[hbqno]; |
ed957684 JS |
1654 | uint32_t getidx = le32_to_cpu(raw_index); |
1655 | ||
1656 | hbqp->local_hbqGetIdx = getidx; | |
1657 | ||
1658 | if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) { | |
1659 | lpfc_printf_log(phba, KERN_ERR, | |
92d7f7b0 | 1660 | LOG_SLI | LOG_VPORT, |
e8b62011 | 1661 | "1802 HBQ %d: local_hbqGetIdx " |
ed957684 | 1662 | "%u is > than hbqp->entry_count %u\n", |
e8b62011 | 1663 | hbqno, hbqp->local_hbqGetIdx, |
ed957684 JS |
1664 | hbqp->entry_count); |
1665 | ||
1666 | phba->link_state = LPFC_HBA_ERROR; | |
1667 | return NULL; | |
1668 | } | |
1669 | ||
1670 | if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx) | |
1671 | return NULL; | |
1672 | } | |
1673 | ||
51ef4c26 JS |
1674 | return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt + |
1675 | hbqp->hbqPutIdx; | |
ed957684 JS |
1676 | } |
1677 | ||
e59058c4 | 1678 | /** |
3621a710 | 1679 | * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers |
e59058c4 JS |
1680 | * @phba: Pointer to HBA context object. |
1681 | * | |
1682 | * This function is called with no lock held to free all the | |
1683 | * hbq buffers while uninitializing the SLI interface. It also | |
1684 | * frees the HBQ buffers returned by the firmware but not yet | |
1685 | * processed by the upper layers. | |
1686 | **/ | |
ed957684 JS |
1687 | void |
1688 | lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba) | |
1689 | { | |
92d7f7b0 JS |
1690 | struct lpfc_dmabuf *dmabuf, *next_dmabuf; |
1691 | struct hbq_dmabuf *hbq_buf; | |
3163f725 | 1692 | unsigned long flags; |
51ef4c26 | 1693 | int i, hbq_count; |
3163f725 | 1694 | uint32_t hbqno; |
ed957684 | 1695 | |
51ef4c26 | 1696 | hbq_count = lpfc_sli_hbq_count(); |
ed957684 | 1697 | /* Return all memory used by all HBQs */ |
3163f725 | 1698 | spin_lock_irqsave(&phba->hbalock, flags); |
51ef4c26 JS |
1699 | for (i = 0; i < hbq_count; ++i) { |
1700 | list_for_each_entry_safe(dmabuf, next_dmabuf, | |
1701 | &phba->hbqs[i].hbq_buffer_list, list) { | |
1702 | hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf); | |
1703 | list_del(&hbq_buf->dbuf.list); | |
1704 | (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf); | |
1705 | } | |
a8adb832 | 1706 | phba->hbqs[i].buffer_count = 0; |
ed957684 | 1707 | } |
3163f725 | 1708 | /* Return all HBQ buffer that are in-fly */ |
3772a991 JS |
1709 | list_for_each_entry_safe(dmabuf, next_dmabuf, &phba->rb_pend_list, |
1710 | list) { | |
3163f725 JS |
1711 | hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf); |
1712 | list_del(&hbq_buf->dbuf.list); | |
1713 | if (hbq_buf->tag == -1) { | |
1714 | (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer) | |
1715 | (phba, hbq_buf); | |
1716 | } else { | |
1717 | hbqno = hbq_buf->tag >> 16; | |
1718 | if (hbqno >= LPFC_MAX_HBQS) | |
1719 | (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer) | |
1720 | (phba, hbq_buf); | |
1721 | else | |
1722 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, | |
1723 | hbq_buf); | |
1724 | } | |
1725 | } | |
1726 | ||
1727 | /* Mark the HBQs not in use */ | |
1728 | phba->hbq_in_use = 0; | |
1729 | spin_unlock_irqrestore(&phba->hbalock, flags); | |
ed957684 JS |
1730 | } |
1731 | ||
e59058c4 | 1732 | /** |
3621a710 | 1733 | * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware |
e59058c4 JS |
1734 | * @phba: Pointer to HBA context object. |
1735 | * @hbqno: HBQ number. | |
1736 | * @hbq_buf: Pointer to HBQ buffer. | |
1737 | * | |
1738 | * This function is called with the hbalock held to post a | |
1739 | * hbq buffer to the firmware. If the function finds an empty | |
1740 | * slot in the HBQ, it will post the buffer. The function will return | |
1741 | * pointer to the hbq entry if it successfully post the buffer | |
1742 | * else it will return NULL. | |
1743 | **/ | |
3772a991 | 1744 | static int |
ed957684 | 1745 | lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno, |
92d7f7b0 | 1746 | struct hbq_dmabuf *hbq_buf) |
3772a991 JS |
1747 | { |
1748 | return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf); | |
1749 | } | |
1750 | ||
1751 | /** | |
1752 | * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware | |
1753 | * @phba: Pointer to HBA context object. | |
1754 | * @hbqno: HBQ number. | |
1755 | * @hbq_buf: Pointer to HBQ buffer. | |
1756 | * | |
1757 | * This function is called with the hbalock held to post a hbq buffer to the | |
1758 | * firmware. If the function finds an empty slot in the HBQ, it will post the | |
1759 | * buffer and place it on the hbq_buffer_list. The function will return zero if | |
1760 | * it successfully post the buffer else it will return an error. | |
1761 | **/ | |
1762 | static int | |
1763 | lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno, | |
1764 | struct hbq_dmabuf *hbq_buf) | |
ed957684 JS |
1765 | { |
1766 | struct lpfc_hbq_entry *hbqe; | |
92d7f7b0 | 1767 | dma_addr_t physaddr = hbq_buf->dbuf.phys; |
ed957684 JS |
1768 | |
1769 | /* Get next HBQ entry slot to use */ | |
1770 | hbqe = lpfc_sli_next_hbq_slot(phba, hbqno); | |
1771 | if (hbqe) { | |
1772 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; | |
1773 | ||
92d7f7b0 JS |
1774 | hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr)); |
1775 | hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr)); | |
51ef4c26 | 1776 | hbqe->bde.tus.f.bdeSize = hbq_buf->size; |
ed957684 | 1777 | hbqe->bde.tus.f.bdeFlags = 0; |
92d7f7b0 JS |
1778 | hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w); |
1779 | hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag); | |
1780 | /* Sync SLIM */ | |
ed957684 JS |
1781 | hbqp->hbqPutIdx = hbqp->next_hbqPutIdx; |
1782 | writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno); | |
92d7f7b0 | 1783 | /* flush */ |
ed957684 | 1784 | readl(phba->hbq_put + hbqno); |
51ef4c26 | 1785 | list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list); |
3772a991 JS |
1786 | return 0; |
1787 | } else | |
1788 | return -ENOMEM; | |
ed957684 JS |
1789 | } |
1790 | ||
4f774513 JS |
1791 | /** |
1792 | * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware | |
1793 | * @phba: Pointer to HBA context object. | |
1794 | * @hbqno: HBQ number. | |
1795 | * @hbq_buf: Pointer to HBQ buffer. | |
1796 | * | |
1797 | * This function is called with the hbalock held to post an RQE to the SLI4 | |
1798 | * firmware. If able to post the RQE to the RQ it will queue the hbq entry to | |
1799 | * the hbq_buffer_list and return zero, otherwise it will return an error. | |
1800 | **/ | |
1801 | static int | |
1802 | lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno, | |
1803 | struct hbq_dmabuf *hbq_buf) | |
1804 | { | |
1805 | int rc; | |
1806 | struct lpfc_rqe hrqe; | |
1807 | struct lpfc_rqe drqe; | |
1808 | ||
1809 | hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys); | |
1810 | hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys); | |
1811 | drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys); | |
1812 | drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys); | |
1813 | rc = lpfc_sli4_rq_put(phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq, | |
1814 | &hrqe, &drqe); | |
1815 | if (rc < 0) | |
1816 | return rc; | |
1817 | hbq_buf->tag = rc; | |
1818 | list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list); | |
1819 | return 0; | |
1820 | } | |
1821 | ||
e59058c4 | 1822 | /* HBQ for ELS and CT traffic. */ |
92d7f7b0 JS |
1823 | static struct lpfc_hbq_init lpfc_els_hbq = { |
1824 | .rn = 1, | |
def9c7a9 | 1825 | .entry_count = 256, |
92d7f7b0 JS |
1826 | .mask_count = 0, |
1827 | .profile = 0, | |
51ef4c26 | 1828 | .ring_mask = (1 << LPFC_ELS_RING), |
92d7f7b0 | 1829 | .buffer_count = 0, |
a257bf90 JS |
1830 | .init_count = 40, |
1831 | .add_count = 40, | |
92d7f7b0 | 1832 | }; |
ed957684 | 1833 | |
e59058c4 | 1834 | /* HBQ for the extra ring if needed */ |
51ef4c26 JS |
1835 | static struct lpfc_hbq_init lpfc_extra_hbq = { |
1836 | .rn = 1, | |
1837 | .entry_count = 200, | |
1838 | .mask_count = 0, | |
1839 | .profile = 0, | |
1840 | .ring_mask = (1 << LPFC_EXTRA_RING), | |
1841 | .buffer_count = 0, | |
1842 | .init_count = 0, | |
1843 | .add_count = 5, | |
1844 | }; | |
1845 | ||
e59058c4 | 1846 | /* Array of HBQs */ |
78b2d852 | 1847 | struct lpfc_hbq_init *lpfc_hbq_defs[] = { |
92d7f7b0 | 1848 | &lpfc_els_hbq, |
51ef4c26 | 1849 | &lpfc_extra_hbq, |
92d7f7b0 | 1850 | }; |
ed957684 | 1851 | |
e59058c4 | 1852 | /** |
3621a710 | 1853 | * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ |
e59058c4 JS |
1854 | * @phba: Pointer to HBA context object. |
1855 | * @hbqno: HBQ number. | |
1856 | * @count: Number of HBQ buffers to be posted. | |
1857 | * | |
d7c255b2 JS |
1858 | * This function is called with no lock held to post more hbq buffers to the |
1859 | * given HBQ. The function returns the number of HBQ buffers successfully | |
1860 | * posted. | |
e59058c4 | 1861 | **/ |
311464ec | 1862 | static int |
92d7f7b0 | 1863 | lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count) |
ed957684 | 1864 | { |
d7c255b2 | 1865 | uint32_t i, posted = 0; |
3163f725 | 1866 | unsigned long flags; |
92d7f7b0 | 1867 | struct hbq_dmabuf *hbq_buffer; |
d7c255b2 | 1868 | LIST_HEAD(hbq_buf_list); |
eafe1df9 | 1869 | if (!phba->hbqs[hbqno].hbq_alloc_buffer) |
51ef4c26 | 1870 | return 0; |
51ef4c26 | 1871 | |
d7c255b2 JS |
1872 | if ((phba->hbqs[hbqno].buffer_count + count) > |
1873 | lpfc_hbq_defs[hbqno]->entry_count) | |
1874 | count = lpfc_hbq_defs[hbqno]->entry_count - | |
1875 | phba->hbqs[hbqno].buffer_count; | |
1876 | if (!count) | |
1877 | return 0; | |
1878 | /* Allocate HBQ entries */ | |
1879 | for (i = 0; i < count; i++) { | |
1880 | hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba); | |
1881 | if (!hbq_buffer) | |
1882 | break; | |
1883 | list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list); | |
1884 | } | |
3163f725 JS |
1885 | /* Check whether HBQ is still in use */ |
1886 | spin_lock_irqsave(&phba->hbalock, flags); | |
eafe1df9 | 1887 | if (!phba->hbq_in_use) |
d7c255b2 JS |
1888 | goto err; |
1889 | while (!list_empty(&hbq_buf_list)) { | |
1890 | list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf, | |
1891 | dbuf.list); | |
1892 | hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count | | |
1893 | (hbqno << 16)); | |
3772a991 | 1894 | if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) { |
a8adb832 | 1895 | phba->hbqs[hbqno].buffer_count++; |
d7c255b2 JS |
1896 | posted++; |
1897 | } else | |
51ef4c26 | 1898 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
ed957684 | 1899 | } |
3163f725 | 1900 | spin_unlock_irqrestore(&phba->hbalock, flags); |
d7c255b2 JS |
1901 | return posted; |
1902 | err: | |
eafe1df9 | 1903 | spin_unlock_irqrestore(&phba->hbalock, flags); |
d7c255b2 JS |
1904 | while (!list_empty(&hbq_buf_list)) { |
1905 | list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf, | |
1906 | dbuf.list); | |
1907 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); | |
1908 | } | |
1909 | return 0; | |
ed957684 JS |
1910 | } |
1911 | ||
e59058c4 | 1912 | /** |
3621a710 | 1913 | * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware |
e59058c4 JS |
1914 | * @phba: Pointer to HBA context object. |
1915 | * @qno: HBQ number. | |
1916 | * | |
1917 | * This function posts more buffers to the HBQ. This function | |
d7c255b2 JS |
1918 | * is called with no lock held. The function returns the number of HBQ entries |
1919 | * successfully allocated. | |
e59058c4 | 1920 | **/ |
92d7f7b0 JS |
1921 | int |
1922 | lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno) | |
ed957684 | 1923 | { |
def9c7a9 JS |
1924 | if (phba->sli_rev == LPFC_SLI_REV4) |
1925 | return 0; | |
1926 | else | |
1927 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, | |
1928 | lpfc_hbq_defs[qno]->add_count); | |
92d7f7b0 | 1929 | } |
ed957684 | 1930 | |
e59058c4 | 1931 | /** |
3621a710 | 1932 | * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ |
e59058c4 JS |
1933 | * @phba: Pointer to HBA context object. |
1934 | * @qno: HBQ queue number. | |
1935 | * | |
1936 | * This function is called from SLI initialization code path with | |
1937 | * no lock held to post initial HBQ buffers to firmware. The | |
d7c255b2 | 1938 | * function returns the number of HBQ entries successfully allocated. |
e59058c4 | 1939 | **/ |
a6ababd2 | 1940 | static int |
92d7f7b0 JS |
1941 | lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno) |
1942 | { | |
def9c7a9 JS |
1943 | if (phba->sli_rev == LPFC_SLI_REV4) |
1944 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, | |
73d91e50 | 1945 | lpfc_hbq_defs[qno]->entry_count); |
def9c7a9 JS |
1946 | else |
1947 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, | |
1948 | lpfc_hbq_defs[qno]->init_count); | |
ed957684 JS |
1949 | } |
1950 | ||
3772a991 JS |
1951 | /** |
1952 | * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list | |
1953 | * @phba: Pointer to HBA context object. | |
1954 | * @hbqno: HBQ number. | |
1955 | * | |
1956 | * This function removes the first hbq buffer on an hbq list and returns a | |
1957 | * pointer to that buffer. If it finds no buffers on the list it returns NULL. | |
1958 | **/ | |
1959 | static struct hbq_dmabuf * | |
1960 | lpfc_sli_hbqbuf_get(struct list_head *rb_list) | |
1961 | { | |
1962 | struct lpfc_dmabuf *d_buf; | |
1963 | ||
1964 | list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list); | |
1965 | if (!d_buf) | |
1966 | return NULL; | |
1967 | return container_of(d_buf, struct hbq_dmabuf, dbuf); | |
1968 | } | |
1969 | ||
e59058c4 | 1970 | /** |
3621a710 | 1971 | * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag |
e59058c4 JS |
1972 | * @phba: Pointer to HBA context object. |
1973 | * @tag: Tag of the hbq buffer. | |
1974 | * | |
1975 | * This function is called with hbalock held. This function searches | |
1976 | * for the hbq buffer associated with the given tag in the hbq buffer | |
1977 | * list. If it finds the hbq buffer, it returns the hbq_buffer other wise | |
1978 | * it returns NULL. | |
1979 | **/ | |
a6ababd2 | 1980 | static struct hbq_dmabuf * |
92d7f7b0 | 1981 | lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag) |
ed957684 | 1982 | { |
92d7f7b0 JS |
1983 | struct lpfc_dmabuf *d_buf; |
1984 | struct hbq_dmabuf *hbq_buf; | |
51ef4c26 JS |
1985 | uint32_t hbqno; |
1986 | ||
1987 | hbqno = tag >> 16; | |
a0a74e45 | 1988 | if (hbqno >= LPFC_MAX_HBQS) |
51ef4c26 | 1989 | return NULL; |
ed957684 | 1990 | |
3772a991 | 1991 | spin_lock_irq(&phba->hbalock); |
51ef4c26 | 1992 | list_for_each_entry(d_buf, &phba->hbqs[hbqno].hbq_buffer_list, list) { |
92d7f7b0 | 1993 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
51ef4c26 | 1994 | if (hbq_buf->tag == tag) { |
3772a991 | 1995 | spin_unlock_irq(&phba->hbalock); |
92d7f7b0 | 1996 | return hbq_buf; |
ed957684 JS |
1997 | } |
1998 | } | |
3772a991 | 1999 | spin_unlock_irq(&phba->hbalock); |
92d7f7b0 | 2000 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT, |
e8b62011 | 2001 | "1803 Bad hbq tag. Data: x%x x%x\n", |
a8adb832 | 2002 | tag, phba->hbqs[tag >> 16].buffer_count); |
92d7f7b0 | 2003 | return NULL; |
ed957684 JS |
2004 | } |
2005 | ||
e59058c4 | 2006 | /** |
3621a710 | 2007 | * lpfc_sli_free_hbq - Give back the hbq buffer to firmware |
e59058c4 JS |
2008 | * @phba: Pointer to HBA context object. |
2009 | * @hbq_buffer: Pointer to HBQ buffer. | |
2010 | * | |
2011 | * This function is called with hbalock. This function gives back | |
2012 | * the hbq buffer to firmware. If the HBQ does not have space to | |
2013 | * post the buffer, it will free the buffer. | |
2014 | **/ | |
ed957684 | 2015 | void |
51ef4c26 | 2016 | lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer) |
ed957684 JS |
2017 | { |
2018 | uint32_t hbqno; | |
2019 | ||
51ef4c26 JS |
2020 | if (hbq_buffer) { |
2021 | hbqno = hbq_buffer->tag >> 16; | |
3772a991 | 2022 | if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) |
51ef4c26 | 2023 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
ed957684 JS |
2024 | } |
2025 | } | |
2026 | ||
e59058c4 | 2027 | /** |
3621a710 | 2028 | * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox |
e59058c4 JS |
2029 | * @mbxCommand: mailbox command code. |
2030 | * | |
2031 | * This function is called by the mailbox event handler function to verify | |
2032 | * that the completed mailbox command is a legitimate mailbox command. If the | |
2033 | * completed mailbox is not known to the function, it will return MBX_SHUTDOWN | |
2034 | * and the mailbox event handler will take the HBA offline. | |
2035 | **/ | |
dea3101e | 2036 | static int |
2037 | lpfc_sli_chk_mbx_command(uint8_t mbxCommand) | |
2038 | { | |
2039 | uint8_t ret; | |
2040 | ||
2041 | switch (mbxCommand) { | |
2042 | case MBX_LOAD_SM: | |
2043 | case MBX_READ_NV: | |
2044 | case MBX_WRITE_NV: | |
a8adb832 | 2045 | case MBX_WRITE_VPARMS: |
dea3101e | 2046 | case MBX_RUN_BIU_DIAG: |
2047 | case MBX_INIT_LINK: | |
2048 | case MBX_DOWN_LINK: | |
2049 | case MBX_CONFIG_LINK: | |
2050 | case MBX_CONFIG_RING: | |
2051 | case MBX_RESET_RING: | |
2052 | case MBX_READ_CONFIG: | |
2053 | case MBX_READ_RCONFIG: | |
2054 | case MBX_READ_SPARM: | |
2055 | case MBX_READ_STATUS: | |
2056 | case MBX_READ_RPI: | |
2057 | case MBX_READ_XRI: | |
2058 | case MBX_READ_REV: | |
2059 | case MBX_READ_LNK_STAT: | |
2060 | case MBX_REG_LOGIN: | |
2061 | case MBX_UNREG_LOGIN: | |
dea3101e | 2062 | case MBX_CLEAR_LA: |
2063 | case MBX_DUMP_MEMORY: | |
2064 | case MBX_DUMP_CONTEXT: | |
2065 | case MBX_RUN_DIAGS: | |
2066 | case MBX_RESTART: | |
2067 | case MBX_UPDATE_CFG: | |
2068 | case MBX_DOWN_LOAD: | |
2069 | case MBX_DEL_LD_ENTRY: | |
2070 | case MBX_RUN_PROGRAM: | |
2071 | case MBX_SET_MASK: | |
09372820 | 2072 | case MBX_SET_VARIABLE: |
dea3101e | 2073 | case MBX_UNREG_D_ID: |
41415862 | 2074 | case MBX_KILL_BOARD: |
dea3101e | 2075 | case MBX_CONFIG_FARP: |
41415862 | 2076 | case MBX_BEACON: |
dea3101e | 2077 | case MBX_LOAD_AREA: |
2078 | case MBX_RUN_BIU_DIAG64: | |
2079 | case MBX_CONFIG_PORT: | |
2080 | case MBX_READ_SPARM64: | |
2081 | case MBX_READ_RPI64: | |
2082 | case MBX_REG_LOGIN64: | |
76a95d75 | 2083 | case MBX_READ_TOPOLOGY: |
09372820 | 2084 | case MBX_WRITE_WWN: |
dea3101e | 2085 | case MBX_SET_DEBUG: |
2086 | case MBX_LOAD_EXP_ROM: | |
57127f15 | 2087 | case MBX_ASYNCEVT_ENABLE: |
92d7f7b0 JS |
2088 | case MBX_REG_VPI: |
2089 | case MBX_UNREG_VPI: | |
858c9f6c | 2090 | case MBX_HEARTBEAT: |
84774a4d JS |
2091 | case MBX_PORT_CAPABILITIES: |
2092 | case MBX_PORT_IOV_CONTROL: | |
04c68496 JS |
2093 | case MBX_SLI4_CONFIG: |
2094 | case MBX_SLI4_REQ_FTRS: | |
2095 | case MBX_REG_FCFI: | |
2096 | case MBX_UNREG_FCFI: | |
2097 | case MBX_REG_VFI: | |
2098 | case MBX_UNREG_VFI: | |
2099 | case MBX_INIT_VPI: | |
2100 | case MBX_INIT_VFI: | |
2101 | case MBX_RESUME_RPI: | |
c7495937 JS |
2102 | case MBX_READ_EVENT_LOG_STATUS: |
2103 | case MBX_READ_EVENT_LOG: | |
dcf2a4e0 JS |
2104 | case MBX_SECURITY_MGMT: |
2105 | case MBX_AUTH_PORT: | |
940eb687 | 2106 | case MBX_ACCESS_VDATA: |
dea3101e | 2107 | ret = mbxCommand; |
2108 | break; | |
2109 | default: | |
2110 | ret = MBX_SHUTDOWN; | |
2111 | break; | |
2112 | } | |
2e0fef85 | 2113 | return ret; |
dea3101e | 2114 | } |
e59058c4 JS |
2115 | |
2116 | /** | |
3621a710 | 2117 | * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler |
e59058c4 JS |
2118 | * @phba: Pointer to HBA context object. |
2119 | * @pmboxq: Pointer to mailbox command. | |
2120 | * | |
2121 | * This is completion handler function for mailbox commands issued from | |
2122 | * lpfc_sli_issue_mbox_wait function. This function is called by the | |
2123 | * mailbox event handler function with no lock held. This function | |
2124 | * will wake up thread waiting on the wait queue pointed by context1 | |
2125 | * of the mailbox. | |
2126 | **/ | |
04c68496 | 2127 | void |
2e0fef85 | 2128 | lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) |
dea3101e | 2129 | { |
2130 | wait_queue_head_t *pdone_q; | |
858c9f6c | 2131 | unsigned long drvr_flag; |
dea3101e | 2132 | |
2133 | /* | |
2134 | * If pdone_q is empty, the driver thread gave up waiting and | |
2135 | * continued running. | |
2136 | */ | |
7054a606 | 2137 | pmboxq->mbox_flag |= LPFC_MBX_WAKE; |
858c9f6c | 2138 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
dea3101e | 2139 | pdone_q = (wait_queue_head_t *) pmboxq->context1; |
2140 | if (pdone_q) | |
2141 | wake_up_interruptible(pdone_q); | |
858c9f6c | 2142 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
dea3101e | 2143 | return; |
2144 | } | |
2145 | ||
e59058c4 JS |
2146 | |
2147 | /** | |
3621a710 | 2148 | * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler |
e59058c4 JS |
2149 | * @phba: Pointer to HBA context object. |
2150 | * @pmb: Pointer to mailbox object. | |
2151 | * | |
2152 | * This function is the default mailbox completion handler. It | |
2153 | * frees the memory resources associated with the completed mailbox | |
2154 | * command. If the completed command is a REG_LOGIN mailbox command, | |
2155 | * this function will issue a UREG_LOGIN to re-claim the RPI. | |
2156 | **/ | |
dea3101e | 2157 | void |
2e0fef85 | 2158 | lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
dea3101e | 2159 | { |
d439d286 | 2160 | struct lpfc_vport *vport = pmb->vport; |
dea3101e | 2161 | struct lpfc_dmabuf *mp; |
d439d286 | 2162 | struct lpfc_nodelist *ndlp; |
5af5eee7 | 2163 | struct Scsi_Host *shost; |
04c68496 | 2164 | uint16_t rpi, vpi; |
7054a606 JS |
2165 | int rc; |
2166 | ||
dea3101e | 2167 | mp = (struct lpfc_dmabuf *) (pmb->context1); |
7054a606 | 2168 | |
dea3101e | 2169 | if (mp) { |
2170 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
2171 | kfree(mp); | |
2172 | } | |
7054a606 JS |
2173 | |
2174 | /* | |
2175 | * If a REG_LOGIN succeeded after node is destroyed or node | |
2176 | * is in re-discovery driver need to cleanup the RPI. | |
2177 | */ | |
2e0fef85 | 2178 | if (!(phba->pport->load_flag & FC_UNLOADING) && |
04c68496 JS |
2179 | pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 && |
2180 | !pmb->u.mb.mbxStatus) { | |
2181 | rpi = pmb->u.mb.un.varWords[0]; | |
6d368e53 | 2182 | vpi = pmb->u.mb.un.varRegLogin.vpi; |
04c68496 | 2183 | lpfc_unreg_login(phba, vpi, rpi, pmb); |
92d7f7b0 | 2184 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
7054a606 JS |
2185 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
2186 | if (rc != MBX_NOT_FINISHED) | |
2187 | return; | |
2188 | } | |
2189 | ||
695a814e JS |
2190 | if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) && |
2191 | !(phba->pport->load_flag & FC_UNLOADING) && | |
2192 | !pmb->u.mb.mbxStatus) { | |
5af5eee7 JS |
2193 | shost = lpfc_shost_from_vport(vport); |
2194 | spin_lock_irq(shost->host_lock); | |
2195 | vport->vpi_state |= LPFC_VPI_REGISTERED; | |
2196 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; | |
2197 | spin_unlock_irq(shost->host_lock); | |
695a814e JS |
2198 | } |
2199 | ||
d439d286 JS |
2200 | if (pmb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
2201 | ndlp = (struct lpfc_nodelist *)pmb->context2; | |
2202 | lpfc_nlp_put(ndlp); | |
2203 | pmb->context2 = NULL; | |
2204 | } | |
2205 | ||
dcf2a4e0 JS |
2206 | /* Check security permission status on INIT_LINK mailbox command */ |
2207 | if ((pmb->u.mb.mbxCommand == MBX_INIT_LINK) && | |
2208 | (pmb->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION)) | |
2209 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
2210 | "2860 SLI authentication is required " | |
2211 | "for INIT_LINK but has not done yet\n"); | |
2212 | ||
04c68496 JS |
2213 | if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG) |
2214 | lpfc_sli4_mbox_cmd_free(phba, pmb); | |
2215 | else | |
2216 | mempool_free(pmb, phba->mbox_mem_pool); | |
dea3101e | 2217 | } |
2218 | ||
e59058c4 | 2219 | /** |
3621a710 | 2220 | * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware |
e59058c4 JS |
2221 | * @phba: Pointer to HBA context object. |
2222 | * | |
2223 | * This function is called with no lock held. This function processes all | |
2224 | * the completed mailbox commands and gives it to upper layers. The interrupt | |
2225 | * service routine processes mailbox completion interrupt and adds completed | |
2226 | * mailbox commands to the mboxq_cmpl queue and signals the worker thread. | |
2227 | * Worker thread call lpfc_sli_handle_mb_event, which will return the | |
2228 | * completed mailbox commands in mboxq_cmpl queue to the upper layers. This | |
2229 | * function returns the mailbox commands to the upper layer by calling the | |
2230 | * completion handler function of each mailbox. | |
2231 | **/ | |
dea3101e | 2232 | int |
2e0fef85 | 2233 | lpfc_sli_handle_mb_event(struct lpfc_hba *phba) |
dea3101e | 2234 | { |
92d7f7b0 | 2235 | MAILBOX_t *pmbox; |
dea3101e | 2236 | LPFC_MBOXQ_t *pmb; |
92d7f7b0 JS |
2237 | int rc; |
2238 | LIST_HEAD(cmplq); | |
dea3101e | 2239 | |
2240 | phba->sli.slistat.mbox_event++; | |
2241 | ||
92d7f7b0 JS |
2242 | /* Get all completed mailboxe buffers into the cmplq */ |
2243 | spin_lock_irq(&phba->hbalock); | |
2244 | list_splice_init(&phba->sli.mboxq_cmpl, &cmplq); | |
2245 | spin_unlock_irq(&phba->hbalock); | |
dea3101e | 2246 | |
92d7f7b0 JS |
2247 | /* Get a Mailbox buffer to setup mailbox commands for callback */ |
2248 | do { | |
2249 | list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list); | |
2250 | if (pmb == NULL) | |
2251 | break; | |
2e0fef85 | 2252 | |
04c68496 | 2253 | pmbox = &pmb->u.mb; |
dea3101e | 2254 | |
858c9f6c JS |
2255 | if (pmbox->mbxCommand != MBX_HEARTBEAT) { |
2256 | if (pmb->vport) { | |
2257 | lpfc_debugfs_disc_trc(pmb->vport, | |
2258 | LPFC_DISC_TRC_MBOX_VPORT, | |
2259 | "MBOX cmpl vport: cmd:x%x mb:x%x x%x", | |
2260 | (uint32_t)pmbox->mbxCommand, | |
2261 | pmbox->un.varWords[0], | |
2262 | pmbox->un.varWords[1]); | |
2263 | } | |
2264 | else { | |
2265 | lpfc_debugfs_disc_trc(phba->pport, | |
2266 | LPFC_DISC_TRC_MBOX, | |
2267 | "MBOX cmpl: cmd:x%x mb:x%x x%x", | |
2268 | (uint32_t)pmbox->mbxCommand, | |
2269 | pmbox->un.varWords[0], | |
2270 | pmbox->un.varWords[1]); | |
2271 | } | |
2272 | } | |
2273 | ||
dea3101e | 2274 | /* |
2275 | * It is a fatal error if unknown mbox command completion. | |
2276 | */ | |
2277 | if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) == | |
2278 | MBX_SHUTDOWN) { | |
af901ca1 | 2279 | /* Unknown mailbox command compl */ |
92d7f7b0 | 2280 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
e8b62011 | 2281 | "(%d):0323 Unknown Mailbox command " |
a183a15f | 2282 | "x%x (x%x/x%x) Cmpl\n", |
92d7f7b0 | 2283 | pmb->vport ? pmb->vport->vpi : 0, |
04c68496 | 2284 | pmbox->mbxCommand, |
a183a15f JS |
2285 | lpfc_sli_config_mbox_subsys_get(phba, |
2286 | pmb), | |
2287 | lpfc_sli_config_mbox_opcode_get(phba, | |
2288 | pmb)); | |
2e0fef85 | 2289 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e | 2290 | phba->work_hs = HS_FFER3; |
2291 | lpfc_handle_eratt(phba); | |
92d7f7b0 | 2292 | continue; |
dea3101e | 2293 | } |
2294 | ||
dea3101e | 2295 | if (pmbox->mbxStatus) { |
2296 | phba->sli.slistat.mbox_stat_err++; | |
2297 | if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) { | |
2298 | /* Mbox cmd cmpl error - RETRYing */ | |
92d7f7b0 | 2299 | lpfc_printf_log(phba, KERN_INFO, |
a183a15f JS |
2300 | LOG_MBOX | LOG_SLI, |
2301 | "(%d):0305 Mbox cmd cmpl " | |
2302 | "error - RETRYing Data: x%x " | |
2303 | "(x%x/x%x) x%x x%x x%x\n", | |
2304 | pmb->vport ? pmb->vport->vpi : 0, | |
2305 | pmbox->mbxCommand, | |
2306 | lpfc_sli_config_mbox_subsys_get(phba, | |
2307 | pmb), | |
2308 | lpfc_sli_config_mbox_opcode_get(phba, | |
2309 | pmb), | |
2310 | pmbox->mbxStatus, | |
2311 | pmbox->un.varWords[0], | |
2312 | pmb->vport->port_state); | |
dea3101e | 2313 | pmbox->mbxStatus = 0; |
2314 | pmbox->mbxOwner = OWN_HOST; | |
dea3101e | 2315 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
04c68496 | 2316 | if (rc != MBX_NOT_FINISHED) |
92d7f7b0 | 2317 | continue; |
dea3101e | 2318 | } |
2319 | } | |
2320 | ||
2321 | /* Mailbox cmd <cmd> Cmpl <cmpl> */ | |
92d7f7b0 | 2322 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
a183a15f | 2323 | "(%d):0307 Mailbox cmd x%x (x%x/x%x) Cmpl x%p " |
e74c03c8 JS |
2324 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x " |
2325 | "x%x x%x x%x\n", | |
92d7f7b0 | 2326 | pmb->vport ? pmb->vport->vpi : 0, |
dea3101e | 2327 | pmbox->mbxCommand, |
a183a15f JS |
2328 | lpfc_sli_config_mbox_subsys_get(phba, pmb), |
2329 | lpfc_sli_config_mbox_opcode_get(phba, pmb), | |
dea3101e | 2330 | pmb->mbox_cmpl, |
2331 | *((uint32_t *) pmbox), | |
2332 | pmbox->un.varWords[0], | |
2333 | pmbox->un.varWords[1], | |
2334 | pmbox->un.varWords[2], | |
2335 | pmbox->un.varWords[3], | |
2336 | pmbox->un.varWords[4], | |
2337 | pmbox->un.varWords[5], | |
2338 | pmbox->un.varWords[6], | |
e74c03c8 JS |
2339 | pmbox->un.varWords[7], |
2340 | pmbox->un.varWords[8], | |
2341 | pmbox->un.varWords[9], | |
2342 | pmbox->un.varWords[10]); | |
dea3101e | 2343 | |
92d7f7b0 | 2344 | if (pmb->mbox_cmpl) |
dea3101e | 2345 | pmb->mbox_cmpl(phba,pmb); |
92d7f7b0 JS |
2346 | } while (1); |
2347 | return 0; | |
2348 | } | |
dea3101e | 2349 | |
e59058c4 | 2350 | /** |
3621a710 | 2351 | * lpfc_sli_get_buff - Get the buffer associated with the buffer tag |
e59058c4 JS |
2352 | * @phba: Pointer to HBA context object. |
2353 | * @pring: Pointer to driver SLI ring object. | |
2354 | * @tag: buffer tag. | |
2355 | * | |
2356 | * This function is called with no lock held. When QUE_BUFTAG_BIT bit | |
2357 | * is set in the tag the buffer is posted for a particular exchange, | |
2358 | * the function will return the buffer without replacing the buffer. | |
2359 | * If the buffer is for unsolicited ELS or CT traffic, this function | |
2360 | * returns the buffer and also posts another buffer to the firmware. | |
2361 | **/ | |
76bb24ef JS |
2362 | static struct lpfc_dmabuf * |
2363 | lpfc_sli_get_buff(struct lpfc_hba *phba, | |
9f1e1b50 JS |
2364 | struct lpfc_sli_ring *pring, |
2365 | uint32_t tag) | |
76bb24ef | 2366 | { |
9f1e1b50 JS |
2367 | struct hbq_dmabuf *hbq_entry; |
2368 | ||
76bb24ef JS |
2369 | if (tag & QUE_BUFTAG_BIT) |
2370 | return lpfc_sli_ring_taggedbuf_get(phba, pring, tag); | |
9f1e1b50 JS |
2371 | hbq_entry = lpfc_sli_hbqbuf_find(phba, tag); |
2372 | if (!hbq_entry) | |
2373 | return NULL; | |
2374 | return &hbq_entry->dbuf; | |
76bb24ef | 2375 | } |
57127f15 | 2376 | |
3772a991 JS |
2377 | /** |
2378 | * lpfc_complete_unsol_iocb - Complete an unsolicited sequence | |
2379 | * @phba: Pointer to HBA context object. | |
2380 | * @pring: Pointer to driver SLI ring object. | |
2381 | * @saveq: Pointer to the iocbq struct representing the sequence starting frame. | |
2382 | * @fch_r_ctl: the r_ctl for the first frame of the sequence. | |
2383 | * @fch_type: the type for the first frame of the sequence. | |
2384 | * | |
2385 | * This function is called with no lock held. This function uses the r_ctl and | |
2386 | * type of the received sequence to find the correct callback function to call | |
2387 | * to process the sequence. | |
2388 | **/ | |
2389 | static int | |
2390 | lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
2391 | struct lpfc_iocbq *saveq, uint32_t fch_r_ctl, | |
2392 | uint32_t fch_type) | |
2393 | { | |
2394 | int i; | |
2395 | ||
2396 | /* unSolicited Responses */ | |
2397 | if (pring->prt[0].profile) { | |
2398 | if (pring->prt[0].lpfc_sli_rcv_unsol_event) | |
2399 | (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring, | |
2400 | saveq); | |
2401 | return 1; | |
2402 | } | |
2403 | /* We must search, based on rctl / type | |
2404 | for the right routine */ | |
2405 | for (i = 0; i < pring->num_mask; i++) { | |
2406 | if ((pring->prt[i].rctl == fch_r_ctl) && | |
2407 | (pring->prt[i].type == fch_type)) { | |
2408 | if (pring->prt[i].lpfc_sli_rcv_unsol_event) | |
2409 | (pring->prt[i].lpfc_sli_rcv_unsol_event) | |
2410 | (phba, pring, saveq); | |
2411 | return 1; | |
2412 | } | |
2413 | } | |
2414 | return 0; | |
2415 | } | |
e59058c4 JS |
2416 | |
2417 | /** | |
3621a710 | 2418 | * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler |
e59058c4 JS |
2419 | * @phba: Pointer to HBA context object. |
2420 | * @pring: Pointer to driver SLI ring object. | |
2421 | * @saveq: Pointer to the unsolicited iocb. | |
2422 | * | |
2423 | * This function is called with no lock held by the ring event handler | |
2424 | * when there is an unsolicited iocb posted to the response ring by the | |
2425 | * firmware. This function gets the buffer associated with the iocbs | |
2426 | * and calls the event handler for the ring. This function handles both | |
2427 | * qring buffers and hbq buffers. | |
2428 | * When the function returns 1 the caller can free the iocb object otherwise | |
2429 | * upper layer functions will free the iocb objects. | |
2430 | **/ | |
dea3101e | 2431 | static int |
2432 | lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
2433 | struct lpfc_iocbq *saveq) | |
2434 | { | |
2435 | IOCB_t * irsp; | |
2436 | WORD5 * w5p; | |
2437 | uint32_t Rctl, Type; | |
3772a991 | 2438 | uint32_t match; |
76bb24ef | 2439 | struct lpfc_iocbq *iocbq; |
3163f725 | 2440 | struct lpfc_dmabuf *dmzbuf; |
dea3101e | 2441 | |
2442 | match = 0; | |
2443 | irsp = &(saveq->iocb); | |
57127f15 JS |
2444 | |
2445 | if (irsp->ulpCommand == CMD_ASYNC_STATUS) { | |
2446 | if (pring->lpfc_sli_rcv_async_status) | |
2447 | pring->lpfc_sli_rcv_async_status(phba, pring, saveq); | |
2448 | else | |
2449 | lpfc_printf_log(phba, | |
2450 | KERN_WARNING, | |
2451 | LOG_SLI, | |
2452 | "0316 Ring %d handler: unexpected " | |
2453 | "ASYNC_STATUS iocb received evt_code " | |
2454 | "0x%x\n", | |
2455 | pring->ringno, | |
2456 | irsp->un.asyncstat.evt_code); | |
2457 | return 1; | |
2458 | } | |
2459 | ||
3163f725 JS |
2460 | if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) && |
2461 | (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) { | |
2462 | if (irsp->ulpBdeCount > 0) { | |
2463 | dmzbuf = lpfc_sli_get_buff(phba, pring, | |
2464 | irsp->un.ulpWord[3]); | |
2465 | lpfc_in_buf_free(phba, dmzbuf); | |
2466 | } | |
2467 | ||
2468 | if (irsp->ulpBdeCount > 1) { | |
2469 | dmzbuf = lpfc_sli_get_buff(phba, pring, | |
2470 | irsp->unsli3.sli3Words[3]); | |
2471 | lpfc_in_buf_free(phba, dmzbuf); | |
2472 | } | |
2473 | ||
2474 | if (irsp->ulpBdeCount > 2) { | |
2475 | dmzbuf = lpfc_sli_get_buff(phba, pring, | |
2476 | irsp->unsli3.sli3Words[7]); | |
2477 | lpfc_in_buf_free(phba, dmzbuf); | |
2478 | } | |
2479 | ||
2480 | return 1; | |
2481 | } | |
2482 | ||
92d7f7b0 | 2483 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
76bb24ef JS |
2484 | if (irsp->ulpBdeCount != 0) { |
2485 | saveq->context2 = lpfc_sli_get_buff(phba, pring, | |
2486 | irsp->un.ulpWord[3]); | |
2487 | if (!saveq->context2) | |
2488 | lpfc_printf_log(phba, | |
2489 | KERN_ERR, | |
2490 | LOG_SLI, | |
2491 | "0341 Ring %d Cannot find buffer for " | |
2492 | "an unsolicited iocb. tag 0x%x\n", | |
2493 | pring->ringno, | |
2494 | irsp->un.ulpWord[3]); | |
76bb24ef JS |
2495 | } |
2496 | if (irsp->ulpBdeCount == 2) { | |
2497 | saveq->context3 = lpfc_sli_get_buff(phba, pring, | |
2498 | irsp->unsli3.sli3Words[7]); | |
2499 | if (!saveq->context3) | |
2500 | lpfc_printf_log(phba, | |
2501 | KERN_ERR, | |
2502 | LOG_SLI, | |
2503 | "0342 Ring %d Cannot find buffer for an" | |
2504 | " unsolicited iocb. tag 0x%x\n", | |
2505 | pring->ringno, | |
2506 | irsp->unsli3.sli3Words[7]); | |
2507 | } | |
2508 | list_for_each_entry(iocbq, &saveq->list, list) { | |
76bb24ef | 2509 | irsp = &(iocbq->iocb); |
76bb24ef JS |
2510 | if (irsp->ulpBdeCount != 0) { |
2511 | iocbq->context2 = lpfc_sli_get_buff(phba, pring, | |
2512 | irsp->un.ulpWord[3]); | |
9c2face6 | 2513 | if (!iocbq->context2) |
76bb24ef JS |
2514 | lpfc_printf_log(phba, |
2515 | KERN_ERR, | |
2516 | LOG_SLI, | |
2517 | "0343 Ring %d Cannot find " | |
2518 | "buffer for an unsolicited iocb" | |
2519 | ". tag 0x%x\n", pring->ringno, | |
92d7f7b0 | 2520 | irsp->un.ulpWord[3]); |
76bb24ef JS |
2521 | } |
2522 | if (irsp->ulpBdeCount == 2) { | |
2523 | iocbq->context3 = lpfc_sli_get_buff(phba, pring, | |
51ef4c26 | 2524 | irsp->unsli3.sli3Words[7]); |
9c2face6 | 2525 | if (!iocbq->context3) |
76bb24ef JS |
2526 | lpfc_printf_log(phba, |
2527 | KERN_ERR, | |
2528 | LOG_SLI, | |
2529 | "0344 Ring %d Cannot find " | |
2530 | "buffer for an unsolicited " | |
2531 | "iocb. tag 0x%x\n", | |
2532 | pring->ringno, | |
2533 | irsp->unsli3.sli3Words[7]); | |
2534 | } | |
2535 | } | |
92d7f7b0 | 2536 | } |
9c2face6 JS |
2537 | if (irsp->ulpBdeCount != 0 && |
2538 | (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX || | |
2539 | irsp->ulpStatus == IOSTAT_INTERMED_RSP)) { | |
2540 | int found = 0; | |
2541 | ||
2542 | /* search continue save q for same XRI */ | |
2543 | list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) { | |
7851fe2c JS |
2544 | if (iocbq->iocb.unsli3.rcvsli3.ox_id == |
2545 | saveq->iocb.unsli3.rcvsli3.ox_id) { | |
9c2face6 JS |
2546 | list_add_tail(&saveq->list, &iocbq->list); |
2547 | found = 1; | |
2548 | break; | |
2549 | } | |
2550 | } | |
2551 | if (!found) | |
2552 | list_add_tail(&saveq->clist, | |
2553 | &pring->iocb_continue_saveq); | |
2554 | if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) { | |
2555 | list_del_init(&iocbq->clist); | |
2556 | saveq = iocbq; | |
2557 | irsp = &(saveq->iocb); | |
2558 | } else | |
2559 | return 0; | |
2560 | } | |
2561 | if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) || | |
2562 | (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) || | |
2563 | (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) { | |
6a9c52cf JS |
2564 | Rctl = FC_RCTL_ELS_REQ; |
2565 | Type = FC_TYPE_ELS; | |
9c2face6 JS |
2566 | } else { |
2567 | w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]); | |
2568 | Rctl = w5p->hcsw.Rctl; | |
2569 | Type = w5p->hcsw.Type; | |
2570 | ||
2571 | /* Firmware Workaround */ | |
2572 | if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) && | |
2573 | (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX || | |
2574 | irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { | |
6a9c52cf JS |
2575 | Rctl = FC_RCTL_ELS_REQ; |
2576 | Type = FC_TYPE_ELS; | |
9c2face6 JS |
2577 | w5p->hcsw.Rctl = Rctl; |
2578 | w5p->hcsw.Type = Type; | |
2579 | } | |
2580 | } | |
92d7f7b0 | 2581 | |
3772a991 | 2582 | if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type)) |
92d7f7b0 | 2583 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
e8b62011 | 2584 | "0313 Ring %d handler: unexpected Rctl x%x " |
92d7f7b0 | 2585 | "Type x%x received\n", |
e8b62011 | 2586 | pring->ringno, Rctl, Type); |
3772a991 | 2587 | |
92d7f7b0 | 2588 | return 1; |
dea3101e | 2589 | } |
2590 | ||
e59058c4 | 2591 | /** |
3621a710 | 2592 | * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb |
e59058c4 JS |
2593 | * @phba: Pointer to HBA context object. |
2594 | * @pring: Pointer to driver SLI ring object. | |
2595 | * @prspiocb: Pointer to response iocb object. | |
2596 | * | |
2597 | * This function looks up the iocb_lookup table to get the command iocb | |
2598 | * corresponding to the given response iocb using the iotag of the | |
2599 | * response iocb. This function is called with the hbalock held. | |
2600 | * This function returns the command iocb object if it finds the command | |
2601 | * iocb else returns NULL. | |
2602 | **/ | |
dea3101e | 2603 | static struct lpfc_iocbq * |
2e0fef85 JS |
2604 | lpfc_sli_iocbq_lookup(struct lpfc_hba *phba, |
2605 | struct lpfc_sli_ring *pring, | |
2606 | struct lpfc_iocbq *prspiocb) | |
dea3101e | 2607 | { |
dea3101e | 2608 | struct lpfc_iocbq *cmd_iocb = NULL; |
2609 | uint16_t iotag; | |
2610 | ||
604a3e30 JB |
2611 | iotag = prspiocb->iocb.ulpIoTag; |
2612 | ||
2613 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { | |
2614 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; | |
92d7f7b0 | 2615 | list_del_init(&cmd_iocb->list); |
4f2e66c6 | 2616 | if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) { |
4f2e66c6 | 2617 | cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
2a9bf3d0 | 2618 | } |
604a3e30 | 2619 | return cmd_iocb; |
dea3101e | 2620 | } |
2621 | ||
dea3101e | 2622 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
e8b62011 | 2623 | "0317 iotag x%x is out off " |
604a3e30 | 2624 | "range: max iotag x%x wd0 x%x\n", |
e8b62011 | 2625 | iotag, phba->sli.last_iotag, |
604a3e30 | 2626 | *(((uint32_t *) &prspiocb->iocb) + 7)); |
dea3101e | 2627 | return NULL; |
2628 | } | |
2629 | ||
3772a991 JS |
2630 | /** |
2631 | * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag | |
2632 | * @phba: Pointer to HBA context object. | |
2633 | * @pring: Pointer to driver SLI ring object. | |
2634 | * @iotag: IOCB tag. | |
2635 | * | |
2636 | * This function looks up the iocb_lookup table to get the command iocb | |
2637 | * corresponding to the given iotag. This function is called with the | |
2638 | * hbalock held. | |
2639 | * This function returns the command iocb object if it finds the command | |
2640 | * iocb else returns NULL. | |
2641 | **/ | |
2642 | static struct lpfc_iocbq * | |
2643 | lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba, | |
2644 | struct lpfc_sli_ring *pring, uint16_t iotag) | |
2645 | { | |
2646 | struct lpfc_iocbq *cmd_iocb; | |
2647 | ||
2648 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { | |
2649 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; | |
4f2e66c6 JS |
2650 | if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) { |
2651 | /* remove from txcmpl queue list */ | |
2652 | list_del_init(&cmd_iocb->list); | |
2653 | cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; | |
4f2e66c6 | 2654 | return cmd_iocb; |
2a9bf3d0 | 2655 | } |
3772a991 | 2656 | } |
3772a991 JS |
2657 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
2658 | "0372 iotag x%x is out off range: max iotag (x%x)\n", | |
2659 | iotag, phba->sli.last_iotag); | |
2660 | return NULL; | |
2661 | } | |
2662 | ||
e59058c4 | 2663 | /** |
3621a710 | 2664 | * lpfc_sli_process_sol_iocb - process solicited iocb completion |
e59058c4 JS |
2665 | * @phba: Pointer to HBA context object. |
2666 | * @pring: Pointer to driver SLI ring object. | |
2667 | * @saveq: Pointer to the response iocb to be processed. | |
2668 | * | |
2669 | * This function is called by the ring event handler for non-fcp | |
2670 | * rings when there is a new response iocb in the response ring. | |
2671 | * The caller is not required to hold any locks. This function | |
2672 | * gets the command iocb associated with the response iocb and | |
2673 | * calls the completion handler for the command iocb. If there | |
2674 | * is no completion handler, the function will free the resources | |
2675 | * associated with command iocb. If the response iocb is for | |
2676 | * an already aborted command iocb, the status of the completion | |
2677 | * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED. | |
2678 | * This function always returns 1. | |
2679 | **/ | |
dea3101e | 2680 | static int |
2e0fef85 | 2681 | lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
dea3101e | 2682 | struct lpfc_iocbq *saveq) |
2683 | { | |
2e0fef85 | 2684 | struct lpfc_iocbq *cmdiocbp; |
dea3101e | 2685 | int rc = 1; |
2686 | unsigned long iflag; | |
2687 | ||
2688 | /* Based on the iotag field, get the cmd IOCB from the txcmplq */ | |
2e0fef85 | 2689 | spin_lock_irqsave(&phba->hbalock, iflag); |
604a3e30 | 2690 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq); |
2e0fef85 JS |
2691 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
2692 | ||
dea3101e | 2693 | if (cmdiocbp) { |
2694 | if (cmdiocbp->iocb_cmpl) { | |
ea2151b4 JS |
2695 | /* |
2696 | * If an ELS command failed send an event to mgmt | |
2697 | * application. | |
2698 | */ | |
2699 | if (saveq->iocb.ulpStatus && | |
2700 | (pring->ringno == LPFC_ELS_RING) && | |
2701 | (cmdiocbp->iocb.ulpCommand == | |
2702 | CMD_ELS_REQUEST64_CR)) | |
2703 | lpfc_send_els_failure_event(phba, | |
2704 | cmdiocbp, saveq); | |
2705 | ||
dea3101e | 2706 | /* |
2707 | * Post all ELS completions to the worker thread. | |
2708 | * All other are passed to the completion callback. | |
2709 | */ | |
2710 | if (pring->ringno == LPFC_ELS_RING) { | |
341af102 JS |
2711 | if ((phba->sli_rev < LPFC_SLI_REV4) && |
2712 | (cmdiocbp->iocb_flag & | |
2713 | LPFC_DRIVER_ABORTED)) { | |
2714 | spin_lock_irqsave(&phba->hbalock, | |
2715 | iflag); | |
07951076 JS |
2716 | cmdiocbp->iocb_flag &= |
2717 | ~LPFC_DRIVER_ABORTED; | |
341af102 JS |
2718 | spin_unlock_irqrestore(&phba->hbalock, |
2719 | iflag); | |
07951076 JS |
2720 | saveq->iocb.ulpStatus = |
2721 | IOSTAT_LOCAL_REJECT; | |
2722 | saveq->iocb.un.ulpWord[4] = | |
2723 | IOERR_SLI_ABORTED; | |
0ff10d46 JS |
2724 | |
2725 | /* Firmware could still be in progress | |
2726 | * of DMAing payload, so don't free data | |
2727 | * buffer till after a hbeat. | |
2728 | */ | |
341af102 JS |
2729 | spin_lock_irqsave(&phba->hbalock, |
2730 | iflag); | |
0ff10d46 | 2731 | saveq->iocb_flag |= LPFC_DELAY_MEM_FREE; |
341af102 JS |
2732 | spin_unlock_irqrestore(&phba->hbalock, |
2733 | iflag); | |
2734 | } | |
0f65ff68 JS |
2735 | if (phba->sli_rev == LPFC_SLI_REV4) { |
2736 | if (saveq->iocb_flag & | |
2737 | LPFC_EXCHANGE_BUSY) { | |
2738 | /* Set cmdiocb flag for the | |
2739 | * exchange busy so sgl (xri) | |
2740 | * will not be released until | |
2741 | * the abort xri is received | |
2742 | * from hba. | |
2743 | */ | |
2744 | spin_lock_irqsave( | |
2745 | &phba->hbalock, iflag); | |
2746 | cmdiocbp->iocb_flag |= | |
2747 | LPFC_EXCHANGE_BUSY; | |
2748 | spin_unlock_irqrestore( | |
2749 | &phba->hbalock, iflag); | |
2750 | } | |
2751 | if (cmdiocbp->iocb_flag & | |
2752 | LPFC_DRIVER_ABORTED) { | |
2753 | /* | |
2754 | * Clear LPFC_DRIVER_ABORTED | |
2755 | * bit in case it was driver | |
2756 | * initiated abort. | |
2757 | */ | |
2758 | spin_lock_irqsave( | |
2759 | &phba->hbalock, iflag); | |
2760 | cmdiocbp->iocb_flag &= | |
2761 | ~LPFC_DRIVER_ABORTED; | |
2762 | spin_unlock_irqrestore( | |
2763 | &phba->hbalock, iflag); | |
2764 | cmdiocbp->iocb.ulpStatus = | |
2765 | IOSTAT_LOCAL_REJECT; | |
2766 | cmdiocbp->iocb.un.ulpWord[4] = | |
2767 | IOERR_ABORT_REQUESTED; | |
2768 | /* | |
2769 | * For SLI4, irsiocb contains | |
2770 | * NO_XRI in sli_xritag, it | |
2771 | * shall not affect releasing | |
2772 | * sgl (xri) process. | |
2773 | */ | |
2774 | saveq->iocb.ulpStatus = | |
2775 | IOSTAT_LOCAL_REJECT; | |
2776 | saveq->iocb.un.ulpWord[4] = | |
2777 | IOERR_SLI_ABORTED; | |
2778 | spin_lock_irqsave( | |
2779 | &phba->hbalock, iflag); | |
2780 | saveq->iocb_flag |= | |
2781 | LPFC_DELAY_MEM_FREE; | |
2782 | spin_unlock_irqrestore( | |
2783 | &phba->hbalock, iflag); | |
2784 | } | |
07951076 | 2785 | } |
dea3101e | 2786 | } |
2e0fef85 | 2787 | (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq); |
604a3e30 JB |
2788 | } else |
2789 | lpfc_sli_release_iocbq(phba, cmdiocbp); | |
dea3101e | 2790 | } else { |
2791 | /* | |
2792 | * Unknown initiating command based on the response iotag. | |
2793 | * This could be the case on the ELS ring because of | |
2794 | * lpfc_els_abort(). | |
2795 | */ | |
2796 | if (pring->ringno != LPFC_ELS_RING) { | |
2797 | /* | |
2798 | * Ring <ringno> handler: unexpected completion IoTag | |
2799 | * <IoTag> | |
2800 | */ | |
a257bf90 | 2801 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
e8b62011 JS |
2802 | "0322 Ring %d handler: " |
2803 | "unexpected completion IoTag x%x " | |
2804 | "Data: x%x x%x x%x x%x\n", | |
2805 | pring->ringno, | |
2806 | saveq->iocb.ulpIoTag, | |
2807 | saveq->iocb.ulpStatus, | |
2808 | saveq->iocb.un.ulpWord[4], | |
2809 | saveq->iocb.ulpCommand, | |
2810 | saveq->iocb.ulpContext); | |
dea3101e | 2811 | } |
2812 | } | |
68876920 | 2813 | |
dea3101e | 2814 | return rc; |
2815 | } | |
2816 | ||
e59058c4 | 2817 | /** |
3621a710 | 2818 | * lpfc_sli_rsp_pointers_error - Response ring pointer error handler |
e59058c4 JS |
2819 | * @phba: Pointer to HBA context object. |
2820 | * @pring: Pointer to driver SLI ring object. | |
2821 | * | |
2822 | * This function is called from the iocb ring event handlers when | |
2823 | * put pointer is ahead of the get pointer for a ring. This function signal | |
2824 | * an error attention condition to the worker thread and the worker | |
2825 | * thread will transition the HBA to offline state. | |
2826 | **/ | |
2e0fef85 JS |
2827 | static void |
2828 | lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) | |
875fbdfe | 2829 | { |
34b02dcd | 2830 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
875fbdfe | 2831 | /* |
025dfdaf | 2832 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger than |
875fbdfe JSEC |
2833 | * rsp ring <portRspMax> |
2834 | */ | |
2835 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
e8b62011 | 2836 | "0312 Ring %d handler: portRspPut %d " |
025dfdaf | 2837 | "is bigger than rsp ring %d\n", |
e8b62011 | 2838 | pring->ringno, le32_to_cpu(pgp->rspPutInx), |
7e56aa25 | 2839 | pring->sli.sli3.numRiocb); |
875fbdfe | 2840 | |
2e0fef85 | 2841 | phba->link_state = LPFC_HBA_ERROR; |
875fbdfe JSEC |
2842 | |
2843 | /* | |
2844 | * All error attention handlers are posted to | |
2845 | * worker thread | |
2846 | */ | |
2847 | phba->work_ha |= HA_ERATT; | |
2848 | phba->work_hs = HS_FFER3; | |
92d7f7b0 | 2849 | |
5e9d9b82 | 2850 | lpfc_worker_wake_up(phba); |
875fbdfe JSEC |
2851 | |
2852 | return; | |
2853 | } | |
2854 | ||
9399627f | 2855 | /** |
3621a710 | 2856 | * lpfc_poll_eratt - Error attention polling timer timeout handler |
9399627f JS |
2857 | * @ptr: Pointer to address of HBA context object. |
2858 | * | |
2859 | * This function is invoked by the Error Attention polling timer when the | |
2860 | * timer times out. It will check the SLI Error Attention register for | |
2861 | * possible attention events. If so, it will post an Error Attention event | |
2862 | * and wake up worker thread to process it. Otherwise, it will set up the | |
2863 | * Error Attention polling timer for the next poll. | |
2864 | **/ | |
2865 | void lpfc_poll_eratt(unsigned long ptr) | |
2866 | { | |
2867 | struct lpfc_hba *phba; | |
aa6fbb75 JS |
2868 | uint32_t eratt = 0, rem; |
2869 | uint64_t sli_intr, cnt; | |
9399627f JS |
2870 | |
2871 | phba = (struct lpfc_hba *)ptr; | |
2872 | ||
aa6fbb75 JS |
2873 | /* Here we will also keep track of interrupts per sec of the hba */ |
2874 | sli_intr = phba->sli.slistat.sli_intr; | |
2875 | ||
2876 | if (phba->sli.slistat.sli_prev_intr > sli_intr) | |
2877 | cnt = (((uint64_t)(-1) - phba->sli.slistat.sli_prev_intr) + | |
2878 | sli_intr); | |
2879 | else | |
2880 | cnt = (sli_intr - phba->sli.slistat.sli_prev_intr); | |
2881 | ||
2882 | /* 64-bit integer division not supporte on 32-bit x86 - use do_div */ | |
2883 | rem = do_div(cnt, LPFC_ERATT_POLL_INTERVAL); | |
2884 | phba->sli.slistat.sli_ips = cnt; | |
2885 | ||
2886 | phba->sli.slistat.sli_prev_intr = sli_intr; | |
2887 | ||
9399627f JS |
2888 | /* Check chip HA register for error event */ |
2889 | eratt = lpfc_sli_check_eratt(phba); | |
2890 | ||
2891 | if (eratt) | |
2892 | /* Tell the worker thread there is work to do */ | |
2893 | lpfc_worker_wake_up(phba); | |
2894 | else | |
2895 | /* Restart the timer for next eratt poll */ | |
256ec0d0 JS |
2896 | mod_timer(&phba->eratt_poll, |
2897 | jiffies + | |
2898 | msecs_to_jiffies(1000 * LPFC_ERATT_POLL_INTERVAL)); | |
9399627f JS |
2899 | return; |
2900 | } | |
2901 | ||
875fbdfe | 2902 | |
e59058c4 | 2903 | /** |
3621a710 | 2904 | * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring |
e59058c4 JS |
2905 | * @phba: Pointer to HBA context object. |
2906 | * @pring: Pointer to driver SLI ring object. | |
2907 | * @mask: Host attention register mask for this ring. | |
2908 | * | |
2909 | * This function is called from the interrupt context when there is a ring | |
2910 | * event for the fcp ring. The caller does not hold any lock. | |
2911 | * The function processes each response iocb in the response ring until it | |
25985edc | 2912 | * finds an iocb with LE bit set and chains all the iocbs up to the iocb with |
e59058c4 JS |
2913 | * LE bit set. The function will call the completion handler of the command iocb |
2914 | * if the response iocb indicates a completion for a command iocb or it is | |
2915 | * an abort completion. The function will call lpfc_sli_process_unsol_iocb | |
2916 | * function if this is an unsolicited iocb. | |
dea3101e | 2917 | * This routine presumes LPFC_FCP_RING handling and doesn't bother |
45ed1190 JS |
2918 | * to check it explicitly. |
2919 | */ | |
2920 | int | |
2e0fef85 JS |
2921 | lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba, |
2922 | struct lpfc_sli_ring *pring, uint32_t mask) | |
dea3101e | 2923 | { |
34b02dcd | 2924 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
dea3101e | 2925 | IOCB_t *irsp = NULL; |
87f6eaff | 2926 | IOCB_t *entry = NULL; |
dea3101e | 2927 | struct lpfc_iocbq *cmdiocbq = NULL; |
2928 | struct lpfc_iocbq rspiocbq; | |
dea3101e | 2929 | uint32_t status; |
2930 | uint32_t portRspPut, portRspMax; | |
2931 | int rc = 1; | |
2932 | lpfc_iocb_type type; | |
2933 | unsigned long iflag; | |
2934 | uint32_t rsp_cmpl = 0; | |
dea3101e | 2935 | |
2e0fef85 | 2936 | spin_lock_irqsave(&phba->hbalock, iflag); |
dea3101e | 2937 | pring->stats.iocb_event++; |
2938 | ||
dea3101e | 2939 | /* |
2940 | * The next available response entry should never exceed the maximum | |
2941 | * entries. If it does, treat it as an adapter hardware error. | |
2942 | */ | |
7e56aa25 | 2943 | portRspMax = pring->sli.sli3.numRiocb; |
dea3101e | 2944 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
2945 | if (unlikely(portRspPut >= portRspMax)) { | |
875fbdfe | 2946 | lpfc_sli_rsp_pointers_error(phba, pring); |
2e0fef85 | 2947 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
dea3101e | 2948 | return 1; |
2949 | } | |
45ed1190 JS |
2950 | if (phba->fcp_ring_in_use) { |
2951 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
2952 | return 1; | |
2953 | } else | |
2954 | phba->fcp_ring_in_use = 1; | |
dea3101e | 2955 | |
2956 | rmb(); | |
7e56aa25 | 2957 | while (pring->sli.sli3.rspidx != portRspPut) { |
87f6eaff JSEC |
2958 | /* |
2959 | * Fetch an entry off the ring and copy it into a local data | |
2960 | * structure. The copy involves a byte-swap since the | |
2961 | * network byte order and pci byte orders are different. | |
2962 | */ | |
ed957684 | 2963 | entry = lpfc_resp_iocb(phba, pring); |
858c9f6c | 2964 | phba->last_completion_time = jiffies; |
875fbdfe | 2965 | |
7e56aa25 JS |
2966 | if (++pring->sli.sli3.rspidx >= portRspMax) |
2967 | pring->sli.sli3.rspidx = 0; | |
875fbdfe | 2968 | |
87f6eaff JSEC |
2969 | lpfc_sli_pcimem_bcopy((uint32_t *) entry, |
2970 | (uint32_t *) &rspiocbq.iocb, | |
ed957684 | 2971 | phba->iocb_rsp_size); |
a4bc3379 | 2972 | INIT_LIST_HEAD(&(rspiocbq.list)); |
87f6eaff JSEC |
2973 | irsp = &rspiocbq.iocb; |
2974 | ||
dea3101e | 2975 | type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK); |
2976 | pring->stats.iocb_rsp++; | |
2977 | rsp_cmpl++; | |
2978 | ||
2979 | if (unlikely(irsp->ulpStatus)) { | |
92d7f7b0 JS |
2980 | /* |
2981 | * If resource errors reported from HBA, reduce | |
2982 | * queuedepths of the SCSI device. | |
2983 | */ | |
2984 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && | |
e3d2b802 JS |
2985 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) == |
2986 | IOERR_NO_RESOURCES)) { | |
92d7f7b0 | 2987 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
3772a991 | 2988 | phba->lpfc_rampdown_queue_depth(phba); |
92d7f7b0 JS |
2989 | spin_lock_irqsave(&phba->hbalock, iflag); |
2990 | } | |
2991 | ||
dea3101e | 2992 | /* Rsp ring <ringno> error: IOCB */ |
2993 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
e8b62011 | 2994 | "0336 Rsp Ring %d error: IOCB Data: " |
92d7f7b0 | 2995 | "x%x x%x x%x x%x x%x x%x x%x x%x\n", |
e8b62011 | 2996 | pring->ringno, |
92d7f7b0 JS |
2997 | irsp->un.ulpWord[0], |
2998 | irsp->un.ulpWord[1], | |
2999 | irsp->un.ulpWord[2], | |
3000 | irsp->un.ulpWord[3], | |
3001 | irsp->un.ulpWord[4], | |
3002 | irsp->un.ulpWord[5], | |
d7c255b2 JS |
3003 | *(uint32_t *)&irsp->un1, |
3004 | *((uint32_t *)&irsp->un1 + 1)); | |
dea3101e | 3005 | } |
3006 | ||
3007 | switch (type) { | |
3008 | case LPFC_ABORT_IOCB: | |
3009 | case LPFC_SOL_IOCB: | |
3010 | /* | |
3011 | * Idle exchange closed via ABTS from port. No iocb | |
3012 | * resources need to be recovered. | |
3013 | */ | |
3014 | if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) { | |
dca9479b | 3015 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
e8b62011 | 3016 | "0333 IOCB cmd 0x%x" |
dca9479b | 3017 | " processed. Skipping" |
92d7f7b0 | 3018 | " completion\n", |
dca9479b | 3019 | irsp->ulpCommand); |
dea3101e | 3020 | break; |
3021 | } | |
3022 | ||
604a3e30 JB |
3023 | cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring, |
3024 | &rspiocbq); | |
0f65ff68 JS |
3025 | if (unlikely(!cmdiocbq)) |
3026 | break; | |
3027 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) | |
3028 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; | |
3029 | if (cmdiocbq->iocb_cmpl) { | |
3030 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
3031 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, | |
3032 | &rspiocbq); | |
3033 | spin_lock_irqsave(&phba->hbalock, iflag); | |
3034 | } | |
dea3101e | 3035 | break; |
a4bc3379 | 3036 | case LPFC_UNSOL_IOCB: |
2e0fef85 | 3037 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
a4bc3379 | 3038 | lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq); |
2e0fef85 | 3039 | spin_lock_irqsave(&phba->hbalock, iflag); |
a4bc3379 | 3040 | break; |
dea3101e | 3041 | default: |
3042 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { | |
3043 | char adaptermsg[LPFC_MAX_ADPTMSG]; | |
3044 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); | |
3045 | memcpy(&adaptermsg[0], (uint8_t *) irsp, | |
3046 | MAX_MSG_DATA); | |
898eb71c JP |
3047 | dev_warn(&((phba->pcidev)->dev), |
3048 | "lpfc%d: %s\n", | |
dea3101e | 3049 | phba->brd_no, adaptermsg); |
3050 | } else { | |
3051 | /* Unknown IOCB command */ | |
3052 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
e8b62011 | 3053 | "0334 Unknown IOCB command " |
92d7f7b0 | 3054 | "Data: x%x, x%x x%x x%x x%x\n", |
e8b62011 | 3055 | type, irsp->ulpCommand, |
92d7f7b0 JS |
3056 | irsp->ulpStatus, |
3057 | irsp->ulpIoTag, | |
3058 | irsp->ulpContext); | |
dea3101e | 3059 | } |
3060 | break; | |
3061 | } | |
3062 | ||
3063 | /* | |
3064 | * The response IOCB has been processed. Update the ring | |
3065 | * pointer in SLIM. If the port response put pointer has not | |
3066 | * been updated, sync the pgp->rspPutInx and fetch the new port | |
3067 | * response put pointer. | |
3068 | */ | |
7e56aa25 JS |
3069 | writel(pring->sli.sli3.rspidx, |
3070 | &phba->host_gp[pring->ringno].rspGetInx); | |
dea3101e | 3071 | |
7e56aa25 | 3072 | if (pring->sli.sli3.rspidx == portRspPut) |
dea3101e | 3073 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
3074 | } | |
3075 | ||
3076 | if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) { | |
3077 | pring->stats.iocb_rsp_full++; | |
3078 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); | |
3079 | writel(status, phba->CAregaddr); | |
3080 | readl(phba->CAregaddr); | |
3081 | } | |
3082 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { | |
3083 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; | |
3084 | pring->stats.iocb_cmd_empty++; | |
3085 | ||
3086 | /* Force update of the local copy of cmdGetInx */ | |
7e56aa25 | 3087 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
dea3101e | 3088 | lpfc_sli_resume_iocb(phba, pring); |
3089 | ||
3090 | if ((pring->lpfc_sli_cmd_available)) | |
3091 | (pring->lpfc_sli_cmd_available) (phba, pring); | |
3092 | ||
3093 | } | |
3094 | ||
45ed1190 | 3095 | phba->fcp_ring_in_use = 0; |
2e0fef85 | 3096 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
dea3101e | 3097 | return rc; |
3098 | } | |
3099 | ||
e59058c4 | 3100 | /** |
3772a991 JS |
3101 | * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb |
3102 | * @phba: Pointer to HBA context object. | |
3103 | * @pring: Pointer to driver SLI ring object. | |
3104 | * @rspiocbp: Pointer to driver response IOCB object. | |
3105 | * | |
3106 | * This function is called from the worker thread when there is a slow-path | |
3107 | * response IOCB to process. This function chains all the response iocbs until | |
3108 | * seeing the iocb with the LE bit set. The function will call | |
3109 | * lpfc_sli_process_sol_iocb function if the response iocb indicates a | |
3110 | * completion of a command iocb. The function will call the | |
3111 | * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb. | |
3112 | * The function frees the resources or calls the completion handler if this | |
3113 | * iocb is an abort completion. The function returns NULL when the response | |
3114 | * iocb has the LE bit set and all the chained iocbs are processed, otherwise | |
3115 | * this function shall chain the iocb on to the iocb_continueq and return the | |
3116 | * response iocb passed in. | |
3117 | **/ | |
3118 | static struct lpfc_iocbq * | |
3119 | lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
3120 | struct lpfc_iocbq *rspiocbp) | |
3121 | { | |
3122 | struct lpfc_iocbq *saveq; | |
3123 | struct lpfc_iocbq *cmdiocbp; | |
3124 | struct lpfc_iocbq *next_iocb; | |
3125 | IOCB_t *irsp = NULL; | |
3126 | uint32_t free_saveq; | |
3127 | uint8_t iocb_cmd_type; | |
3128 | lpfc_iocb_type type; | |
3129 | unsigned long iflag; | |
3130 | int rc; | |
3131 | ||
3132 | spin_lock_irqsave(&phba->hbalock, iflag); | |
3133 | /* First add the response iocb to the countinueq list */ | |
3134 | list_add_tail(&rspiocbp->list, &(pring->iocb_continueq)); | |
3135 | pring->iocb_continueq_cnt++; | |
3136 | ||
70f23fd6 | 3137 | /* Now, determine whether the list is completed for processing */ |
3772a991 JS |
3138 | irsp = &rspiocbp->iocb; |
3139 | if (irsp->ulpLe) { | |
3140 | /* | |
3141 | * By default, the driver expects to free all resources | |
3142 | * associated with this iocb completion. | |
3143 | */ | |
3144 | free_saveq = 1; | |
3145 | saveq = list_get_first(&pring->iocb_continueq, | |
3146 | struct lpfc_iocbq, list); | |
3147 | irsp = &(saveq->iocb); | |
3148 | list_del_init(&pring->iocb_continueq); | |
3149 | pring->iocb_continueq_cnt = 0; | |
3150 | ||
3151 | pring->stats.iocb_rsp++; | |
3152 | ||
3153 | /* | |
3154 | * If resource errors reported from HBA, reduce | |
3155 | * queuedepths of the SCSI device. | |
3156 | */ | |
3157 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && | |
e3d2b802 JS |
3158 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) == |
3159 | IOERR_NO_RESOURCES)) { | |
3772a991 JS |
3160 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
3161 | phba->lpfc_rampdown_queue_depth(phba); | |
3162 | spin_lock_irqsave(&phba->hbalock, iflag); | |
3163 | } | |
3164 | ||
3165 | if (irsp->ulpStatus) { | |
3166 | /* Rsp ring <ringno> error: IOCB */ | |
3167 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
3168 | "0328 Rsp Ring %d error: " | |
3169 | "IOCB Data: " | |
3170 | "x%x x%x x%x x%x " | |
3171 | "x%x x%x x%x x%x " | |
3172 | "x%x x%x x%x x%x " | |
3173 | "x%x x%x x%x x%x\n", | |
3174 | pring->ringno, | |
3175 | irsp->un.ulpWord[0], | |
3176 | irsp->un.ulpWord[1], | |
3177 | irsp->un.ulpWord[2], | |
3178 | irsp->un.ulpWord[3], | |
3179 | irsp->un.ulpWord[4], | |
3180 | irsp->un.ulpWord[5], | |
3181 | *(((uint32_t *) irsp) + 6), | |
3182 | *(((uint32_t *) irsp) + 7), | |
3183 | *(((uint32_t *) irsp) + 8), | |
3184 | *(((uint32_t *) irsp) + 9), | |
3185 | *(((uint32_t *) irsp) + 10), | |
3186 | *(((uint32_t *) irsp) + 11), | |
3187 | *(((uint32_t *) irsp) + 12), | |
3188 | *(((uint32_t *) irsp) + 13), | |
3189 | *(((uint32_t *) irsp) + 14), | |
3190 | *(((uint32_t *) irsp) + 15)); | |
3191 | } | |
3192 | ||
3193 | /* | |
3194 | * Fetch the IOCB command type and call the correct completion | |
3195 | * routine. Solicited and Unsolicited IOCBs on the ELS ring | |
3196 | * get freed back to the lpfc_iocb_list by the discovery | |
3197 | * kernel thread. | |
3198 | */ | |
3199 | iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK; | |
3200 | type = lpfc_sli_iocb_cmd_type(iocb_cmd_type); | |
3201 | switch (type) { | |
3202 | case LPFC_SOL_IOCB: | |
3203 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
3204 | rc = lpfc_sli_process_sol_iocb(phba, pring, saveq); | |
3205 | spin_lock_irqsave(&phba->hbalock, iflag); | |
3206 | break; | |
3207 | ||
3208 | case LPFC_UNSOL_IOCB: | |
3209 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
3210 | rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq); | |
3211 | spin_lock_irqsave(&phba->hbalock, iflag); | |
3212 | if (!rc) | |
3213 | free_saveq = 0; | |
3214 | break; | |
3215 | ||
3216 | case LPFC_ABORT_IOCB: | |
3217 | cmdiocbp = NULL; | |
3218 | if (irsp->ulpCommand != CMD_XRI_ABORTED_CX) | |
3219 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, | |
3220 | saveq); | |
3221 | if (cmdiocbp) { | |
3222 | /* Call the specified completion routine */ | |
3223 | if (cmdiocbp->iocb_cmpl) { | |
3224 | spin_unlock_irqrestore(&phba->hbalock, | |
3225 | iflag); | |
3226 | (cmdiocbp->iocb_cmpl)(phba, cmdiocbp, | |
3227 | saveq); | |
3228 | spin_lock_irqsave(&phba->hbalock, | |
3229 | iflag); | |
3230 | } else | |
3231 | __lpfc_sli_release_iocbq(phba, | |
3232 | cmdiocbp); | |
3233 | } | |
3234 | break; | |
3235 | ||
3236 | case LPFC_UNKNOWN_IOCB: | |
3237 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { | |
3238 | char adaptermsg[LPFC_MAX_ADPTMSG]; | |
3239 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); | |
3240 | memcpy(&adaptermsg[0], (uint8_t *)irsp, | |
3241 | MAX_MSG_DATA); | |
3242 | dev_warn(&((phba->pcidev)->dev), | |
3243 | "lpfc%d: %s\n", | |
3244 | phba->brd_no, adaptermsg); | |
3245 | } else { | |
3246 | /* Unknown IOCB command */ | |
3247 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3248 | "0335 Unknown IOCB " | |
3249 | "command Data: x%x " | |
3250 | "x%x x%x x%x\n", | |
3251 | irsp->ulpCommand, | |
3252 | irsp->ulpStatus, | |
3253 | irsp->ulpIoTag, | |
3254 | irsp->ulpContext); | |
3255 | } | |
3256 | break; | |
3257 | } | |
3258 | ||
3259 | if (free_saveq) { | |
3260 | list_for_each_entry_safe(rspiocbp, next_iocb, | |
3261 | &saveq->list, list) { | |
61f35bff | 3262 | list_del_init(&rspiocbp->list); |
3772a991 JS |
3263 | __lpfc_sli_release_iocbq(phba, rspiocbp); |
3264 | } | |
3265 | __lpfc_sli_release_iocbq(phba, saveq); | |
3266 | } | |
3267 | rspiocbp = NULL; | |
3268 | } | |
3269 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
3270 | return rspiocbp; | |
3271 | } | |
3272 | ||
3273 | /** | |
3274 | * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs | |
e59058c4 JS |
3275 | * @phba: Pointer to HBA context object. |
3276 | * @pring: Pointer to driver SLI ring object. | |
3277 | * @mask: Host attention register mask for this ring. | |
3278 | * | |
3772a991 JS |
3279 | * This routine wraps the actual slow_ring event process routine from the |
3280 | * API jump table function pointer from the lpfc_hba struct. | |
e59058c4 | 3281 | **/ |
3772a991 | 3282 | void |
2e0fef85 JS |
3283 | lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba, |
3284 | struct lpfc_sli_ring *pring, uint32_t mask) | |
3772a991 JS |
3285 | { |
3286 | phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask); | |
3287 | } | |
3288 | ||
3289 | /** | |
3290 | * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings | |
3291 | * @phba: Pointer to HBA context object. | |
3292 | * @pring: Pointer to driver SLI ring object. | |
3293 | * @mask: Host attention register mask for this ring. | |
3294 | * | |
3295 | * This function is called from the worker thread when there is a ring event | |
3296 | * for non-fcp rings. The caller does not hold any lock. The function will | |
3297 | * remove each response iocb in the response ring and calls the handle | |
3298 | * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it. | |
3299 | **/ | |
3300 | static void | |
3301 | lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba, | |
3302 | struct lpfc_sli_ring *pring, uint32_t mask) | |
dea3101e | 3303 | { |
34b02dcd | 3304 | struct lpfc_pgp *pgp; |
dea3101e | 3305 | IOCB_t *entry; |
3306 | IOCB_t *irsp = NULL; | |
3307 | struct lpfc_iocbq *rspiocbp = NULL; | |
dea3101e | 3308 | uint32_t portRspPut, portRspMax; |
dea3101e | 3309 | unsigned long iflag; |
3772a991 | 3310 | uint32_t status; |
dea3101e | 3311 | |
34b02dcd | 3312 | pgp = &phba->port_gp[pring->ringno]; |
2e0fef85 | 3313 | spin_lock_irqsave(&phba->hbalock, iflag); |
dea3101e | 3314 | pring->stats.iocb_event++; |
3315 | ||
dea3101e | 3316 | /* |
3317 | * The next available response entry should never exceed the maximum | |
3318 | * entries. If it does, treat it as an adapter hardware error. | |
3319 | */ | |
7e56aa25 | 3320 | portRspMax = pring->sli.sli3.numRiocb; |
dea3101e | 3321 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
3322 | if (portRspPut >= portRspMax) { | |
3323 | /* | |
025dfdaf | 3324 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger than |
dea3101e | 3325 | * rsp ring <portRspMax> |
3326 | */ | |
ed957684 | 3327 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
e8b62011 | 3328 | "0303 Ring %d handler: portRspPut %d " |
025dfdaf | 3329 | "is bigger than rsp ring %d\n", |
e8b62011 | 3330 | pring->ringno, portRspPut, portRspMax); |
dea3101e | 3331 | |
2e0fef85 JS |
3332 | phba->link_state = LPFC_HBA_ERROR; |
3333 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
dea3101e | 3334 | |
3335 | phba->work_hs = HS_FFER3; | |
3336 | lpfc_handle_eratt(phba); | |
3337 | ||
3772a991 | 3338 | return; |
dea3101e | 3339 | } |
3340 | ||
3341 | rmb(); | |
7e56aa25 | 3342 | while (pring->sli.sli3.rspidx != portRspPut) { |
dea3101e | 3343 | /* |
3344 | * Build a completion list and call the appropriate handler. | |
3345 | * The process is to get the next available response iocb, get | |
3346 | * a free iocb from the list, copy the response data into the | |
3347 | * free iocb, insert to the continuation list, and update the | |
3348 | * next response index to slim. This process makes response | |
3349 | * iocb's in the ring available to DMA as fast as possible but | |
3350 | * pays a penalty for a copy operation. Since the iocb is | |
3351 | * only 32 bytes, this penalty is considered small relative to | |
3352 | * the PCI reads for register values and a slim write. When | |
3353 | * the ulpLe field is set, the entire Command has been | |
3354 | * received. | |
3355 | */ | |
ed957684 JS |
3356 | entry = lpfc_resp_iocb(phba, pring); |
3357 | ||
858c9f6c | 3358 | phba->last_completion_time = jiffies; |
2e0fef85 | 3359 | rspiocbp = __lpfc_sli_get_iocbq(phba); |
dea3101e | 3360 | if (rspiocbp == NULL) { |
3361 | printk(KERN_ERR "%s: out of buffers! Failing " | |
cadbd4a5 | 3362 | "completion.\n", __func__); |
dea3101e | 3363 | break; |
3364 | } | |
3365 | ||
ed957684 JS |
3366 | lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb, |
3367 | phba->iocb_rsp_size); | |
dea3101e | 3368 | irsp = &rspiocbp->iocb; |
3369 | ||
7e56aa25 JS |
3370 | if (++pring->sli.sli3.rspidx >= portRspMax) |
3371 | pring->sli.sli3.rspidx = 0; | |
dea3101e | 3372 | |
a58cbd52 JS |
3373 | if (pring->ringno == LPFC_ELS_RING) { |
3374 | lpfc_debugfs_slow_ring_trc(phba, | |
3375 | "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x", | |
3376 | *(((uint32_t *) irsp) + 4), | |
3377 | *(((uint32_t *) irsp) + 6), | |
3378 | *(((uint32_t *) irsp) + 7)); | |
3379 | } | |
3380 | ||
7e56aa25 JS |
3381 | writel(pring->sli.sli3.rspidx, |
3382 | &phba->host_gp[pring->ringno].rspGetInx); | |
dea3101e | 3383 | |
3772a991 JS |
3384 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
3385 | /* Handle the response IOCB */ | |
3386 | rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp); | |
3387 | spin_lock_irqsave(&phba->hbalock, iflag); | |
dea3101e | 3388 | |
3389 | /* | |
3390 | * If the port response put pointer has not been updated, sync | |
3391 | * the pgp->rspPutInx in the MAILBOX_tand fetch the new port | |
3392 | * response put pointer. | |
3393 | */ | |
7e56aa25 | 3394 | if (pring->sli.sli3.rspidx == portRspPut) { |
dea3101e | 3395 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
3396 | } | |
7e56aa25 | 3397 | } /* while (pring->sli.sli3.rspidx != portRspPut) */ |
dea3101e | 3398 | |
92d7f7b0 | 3399 | if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) { |
dea3101e | 3400 | /* At least one response entry has been freed */ |
3401 | pring->stats.iocb_rsp_full++; | |
3402 | /* SET RxRE_RSP in Chip Att register */ | |
3403 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); | |
3404 | writel(status, phba->CAregaddr); | |
3405 | readl(phba->CAregaddr); /* flush */ | |
3406 | } | |
3407 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { | |
3408 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; | |
3409 | pring->stats.iocb_cmd_empty++; | |
3410 | ||
3411 | /* Force update of the local copy of cmdGetInx */ | |
7e56aa25 | 3412 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
dea3101e | 3413 | lpfc_sli_resume_iocb(phba, pring); |
3414 | ||
3415 | if ((pring->lpfc_sli_cmd_available)) | |
3416 | (pring->lpfc_sli_cmd_available) (phba, pring); | |
3417 | ||
3418 | } | |
3419 | ||
2e0fef85 | 3420 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
3772a991 | 3421 | return; |
dea3101e | 3422 | } |
3423 | ||
4f774513 JS |
3424 | /** |
3425 | * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events | |
3426 | * @phba: Pointer to HBA context object. | |
3427 | * @pring: Pointer to driver SLI ring object. | |
3428 | * @mask: Host attention register mask for this ring. | |
3429 | * | |
3430 | * This function is called from the worker thread when there is a pending | |
3431 | * ELS response iocb on the driver internal slow-path response iocb worker | |
3432 | * queue. The caller does not hold any lock. The function will remove each | |
3433 | * response iocb from the response worker queue and calls the handle | |
3434 | * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it. | |
3435 | **/ | |
3436 | static void | |
3437 | lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba, | |
3438 | struct lpfc_sli_ring *pring, uint32_t mask) | |
3439 | { | |
3440 | struct lpfc_iocbq *irspiocbq; | |
4d9ab994 JS |
3441 | struct hbq_dmabuf *dmabuf; |
3442 | struct lpfc_cq_event *cq_event; | |
4f774513 JS |
3443 | unsigned long iflag; |
3444 | ||
45ed1190 JS |
3445 | spin_lock_irqsave(&phba->hbalock, iflag); |
3446 | phba->hba_flag &= ~HBA_SP_QUEUE_EVT; | |
3447 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
3448 | while (!list_empty(&phba->sli4_hba.sp_queue_event)) { | |
4f774513 JS |
3449 | /* Get the response iocb from the head of work queue */ |
3450 | spin_lock_irqsave(&phba->hbalock, iflag); | |
45ed1190 | 3451 | list_remove_head(&phba->sli4_hba.sp_queue_event, |
4d9ab994 | 3452 | cq_event, struct lpfc_cq_event, list); |
4f774513 | 3453 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
4d9ab994 JS |
3454 | |
3455 | switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) { | |
3456 | case CQE_CODE_COMPL_WQE: | |
3457 | irspiocbq = container_of(cq_event, struct lpfc_iocbq, | |
3458 | cq_event); | |
45ed1190 JS |
3459 | /* Translate ELS WCQE to response IOCBQ */ |
3460 | irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba, | |
3461 | irspiocbq); | |
3462 | if (irspiocbq) | |
3463 | lpfc_sli_sp_handle_rspiocb(phba, pring, | |
3464 | irspiocbq); | |
4d9ab994 JS |
3465 | break; |
3466 | case CQE_CODE_RECEIVE: | |
7851fe2c | 3467 | case CQE_CODE_RECEIVE_V1: |
4d9ab994 JS |
3468 | dmabuf = container_of(cq_event, struct hbq_dmabuf, |
3469 | cq_event); | |
3470 | lpfc_sli4_handle_received_buffer(phba, dmabuf); | |
3471 | break; | |
3472 | default: | |
3473 | break; | |
3474 | } | |
4f774513 JS |
3475 | } |
3476 | } | |
3477 | ||
e59058c4 | 3478 | /** |
3621a710 | 3479 | * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring |
e59058c4 JS |
3480 | * @phba: Pointer to HBA context object. |
3481 | * @pring: Pointer to driver SLI ring object. | |
3482 | * | |
3483 | * This function aborts all iocbs in the given ring and frees all the iocb | |
3484 | * objects in txq. This function issues an abort iocb for all the iocb commands | |
3485 | * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before | |
3486 | * the return of this function. The caller is not required to hold any locks. | |
3487 | **/ | |
2e0fef85 | 3488 | void |
dea3101e | 3489 | lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
3490 | { | |
2534ba75 | 3491 | LIST_HEAD(completions); |
dea3101e | 3492 | struct lpfc_iocbq *iocb, *next_iocb; |
dea3101e | 3493 | |
92d7f7b0 JS |
3494 | if (pring->ringno == LPFC_ELS_RING) { |
3495 | lpfc_fabric_abort_hba(phba); | |
3496 | } | |
3497 | ||
dea3101e | 3498 | /* Error everything on txq and txcmplq |
3499 | * First do the txq. | |
3500 | */ | |
db55fba8 JS |
3501 | if (phba->sli_rev >= LPFC_SLI_REV4) { |
3502 | spin_lock_irq(&pring->ring_lock); | |
3503 | list_splice_init(&pring->txq, &completions); | |
3504 | pring->txq_cnt = 0; | |
3505 | spin_unlock_irq(&pring->ring_lock); | |
dea3101e | 3506 | |
db55fba8 JS |
3507 | spin_lock_irq(&phba->hbalock); |
3508 | /* Next issue ABTS for everything on the txcmplq */ | |
3509 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) | |
3510 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); | |
3511 | spin_unlock_irq(&phba->hbalock); | |
3512 | } else { | |
3513 | spin_lock_irq(&phba->hbalock); | |
3514 | list_splice_init(&pring->txq, &completions); | |
3515 | pring->txq_cnt = 0; | |
dea3101e | 3516 | |
db55fba8 JS |
3517 | /* Next issue ABTS for everything on the txcmplq */ |
3518 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) | |
3519 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); | |
3520 | spin_unlock_irq(&phba->hbalock); | |
3521 | } | |
dea3101e | 3522 | |
a257bf90 JS |
3523 | /* Cancel all the IOCBs from the completions list */ |
3524 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, | |
3525 | IOERR_SLI_ABORTED); | |
dea3101e | 3526 | } |
3527 | ||
db55fba8 JS |
3528 | /** |
3529 | * lpfc_sli_abort_fcp_rings - Abort all iocbs in all FCP rings | |
3530 | * @phba: Pointer to HBA context object. | |
3531 | * @pring: Pointer to driver SLI ring object. | |
3532 | * | |
3533 | * This function aborts all iocbs in FCP rings and frees all the iocb | |
3534 | * objects in txq. This function issues an abort iocb for all the iocb commands | |
3535 | * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before | |
3536 | * the return of this function. The caller is not required to hold any locks. | |
3537 | **/ | |
3538 | void | |
3539 | lpfc_sli_abort_fcp_rings(struct lpfc_hba *phba) | |
3540 | { | |
3541 | struct lpfc_sli *psli = &phba->sli; | |
3542 | struct lpfc_sli_ring *pring; | |
3543 | uint32_t i; | |
3544 | ||
3545 | /* Look on all the FCP Rings for the iotag */ | |
3546 | if (phba->sli_rev >= LPFC_SLI_REV4) { | |
3547 | for (i = 0; i < phba->cfg_fcp_io_channel; i++) { | |
3548 | pring = &psli->ring[i + MAX_SLI3_CONFIGURED_RINGS]; | |
3549 | lpfc_sli_abort_iocb_ring(phba, pring); | |
3550 | } | |
3551 | } else { | |
3552 | pring = &psli->ring[psli->fcp_ring]; | |
3553 | lpfc_sli_abort_iocb_ring(phba, pring); | |
3554 | } | |
3555 | } | |
3556 | ||
3557 | ||
a8e497d5 | 3558 | /** |
3621a710 | 3559 | * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring |
a8e497d5 JS |
3560 | * @phba: Pointer to HBA context object. |
3561 | * | |
3562 | * This function flushes all iocbs in the fcp ring and frees all the iocb | |
3563 | * objects in txq and txcmplq. This function will not issue abort iocbs | |
3564 | * for all the iocb commands in txcmplq, they will just be returned with | |
3565 | * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI | |
3566 | * slot has been permanently disabled. | |
3567 | **/ | |
3568 | void | |
3569 | lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba) | |
3570 | { | |
3571 | LIST_HEAD(txq); | |
3572 | LIST_HEAD(txcmplq); | |
a8e497d5 JS |
3573 | struct lpfc_sli *psli = &phba->sli; |
3574 | struct lpfc_sli_ring *pring; | |
db55fba8 | 3575 | uint32_t i; |
a8e497d5 JS |
3576 | |
3577 | spin_lock_irq(&phba->hbalock); | |
4f2e66c6 JS |
3578 | /* Indicate the I/O queues are flushed */ |
3579 | phba->hba_flag |= HBA_FCP_IOQ_FLUSH; | |
a8e497d5 JS |
3580 | spin_unlock_irq(&phba->hbalock); |
3581 | ||
db55fba8 JS |
3582 | /* Look on all the FCP Rings for the iotag */ |
3583 | if (phba->sli_rev >= LPFC_SLI_REV4) { | |
3584 | for (i = 0; i < phba->cfg_fcp_io_channel; i++) { | |
3585 | pring = &psli->ring[i + MAX_SLI3_CONFIGURED_RINGS]; | |
3586 | ||
3587 | spin_lock_irq(&pring->ring_lock); | |
3588 | /* Retrieve everything on txq */ | |
3589 | list_splice_init(&pring->txq, &txq); | |
3590 | /* Retrieve everything on the txcmplq */ | |
3591 | list_splice_init(&pring->txcmplq, &txcmplq); | |
3592 | pring->txq_cnt = 0; | |
3593 | pring->txcmplq_cnt = 0; | |
3594 | spin_unlock_irq(&pring->ring_lock); | |
3595 | ||
3596 | /* Flush the txq */ | |
3597 | lpfc_sli_cancel_iocbs(phba, &txq, | |
3598 | IOSTAT_LOCAL_REJECT, | |
3599 | IOERR_SLI_DOWN); | |
3600 | /* Flush the txcmpq */ | |
3601 | lpfc_sli_cancel_iocbs(phba, &txcmplq, | |
3602 | IOSTAT_LOCAL_REJECT, | |
3603 | IOERR_SLI_DOWN); | |
3604 | } | |
3605 | } else { | |
3606 | pring = &psli->ring[psli->fcp_ring]; | |
a8e497d5 | 3607 | |
db55fba8 JS |
3608 | spin_lock_irq(&phba->hbalock); |
3609 | /* Retrieve everything on txq */ | |
3610 | list_splice_init(&pring->txq, &txq); | |
3611 | /* Retrieve everything on the txcmplq */ | |
3612 | list_splice_init(&pring->txcmplq, &txcmplq); | |
3613 | pring->txq_cnt = 0; | |
3614 | pring->txcmplq_cnt = 0; | |
3615 | spin_unlock_irq(&phba->hbalock); | |
3616 | ||
3617 | /* Flush the txq */ | |
3618 | lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT, | |
3619 | IOERR_SLI_DOWN); | |
3620 | /* Flush the txcmpq */ | |
3621 | lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT, | |
3622 | IOERR_SLI_DOWN); | |
3623 | } | |
a8e497d5 JS |
3624 | } |
3625 | ||
e59058c4 | 3626 | /** |
3772a991 | 3627 | * lpfc_sli_brdready_s3 - Check for sli3 host ready status |
e59058c4 JS |
3628 | * @phba: Pointer to HBA context object. |
3629 | * @mask: Bit mask to be checked. | |
3630 | * | |
3631 | * This function reads the host status register and compares | |
3632 | * with the provided bit mask to check if HBA completed | |
3633 | * the restart. This function will wait in a loop for the | |
3634 | * HBA to complete restart. If the HBA does not restart within | |
3635 | * 15 iterations, the function will reset the HBA again. The | |
3636 | * function returns 1 when HBA fail to restart otherwise returns | |
3637 | * zero. | |
3638 | **/ | |
3772a991 JS |
3639 | static int |
3640 | lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask) | |
dea3101e | 3641 | { |
41415862 JW |
3642 | uint32_t status; |
3643 | int i = 0; | |
3644 | int retval = 0; | |
dea3101e | 3645 | |
41415862 | 3646 | /* Read the HBA Host Status Register */ |
9940b97b JS |
3647 | if (lpfc_readl(phba->HSregaddr, &status)) |
3648 | return 1; | |
dea3101e | 3649 | |
41415862 JW |
3650 | /* |
3651 | * Check status register every 100ms for 5 retries, then every | |
3652 | * 500ms for 5, then every 2.5 sec for 5, then reset board and | |
3653 | * every 2.5 sec for 4. | |
3654 | * Break our of the loop if errors occurred during init. | |
3655 | */ | |
3656 | while (((status & mask) != mask) && | |
3657 | !(status & HS_FFERM) && | |
3658 | i++ < 20) { | |
dea3101e | 3659 | |
41415862 JW |
3660 | if (i <= 5) |
3661 | msleep(10); | |
3662 | else if (i <= 10) | |
3663 | msleep(500); | |
3664 | else | |
3665 | msleep(2500); | |
dea3101e | 3666 | |
41415862 | 3667 | if (i == 15) { |
2e0fef85 | 3668 | /* Do post */ |
92d7f7b0 | 3669 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
41415862 JW |
3670 | lpfc_sli_brdrestart(phba); |
3671 | } | |
3672 | /* Read the HBA Host Status Register */ | |
9940b97b JS |
3673 | if (lpfc_readl(phba->HSregaddr, &status)) { |
3674 | retval = 1; | |
3675 | break; | |
3676 | } | |
41415862 | 3677 | } |
dea3101e | 3678 | |
41415862 JW |
3679 | /* Check to see if any errors occurred during init */ |
3680 | if ((status & HS_FFERM) || (i >= 20)) { | |
e40a02c1 JS |
3681 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
3682 | "2751 Adapter failed to restart, " | |
3683 | "status reg x%x, FW Data: A8 x%x AC x%x\n", | |
3684 | status, | |
3685 | readl(phba->MBslimaddr + 0xa8), | |
3686 | readl(phba->MBslimaddr + 0xac)); | |
2e0fef85 | 3687 | phba->link_state = LPFC_HBA_ERROR; |
41415862 | 3688 | retval = 1; |
dea3101e | 3689 | } |
dea3101e | 3690 | |
41415862 JW |
3691 | return retval; |
3692 | } | |
dea3101e | 3693 | |
da0436e9 JS |
3694 | /** |
3695 | * lpfc_sli_brdready_s4 - Check for sli4 host ready status | |
3696 | * @phba: Pointer to HBA context object. | |
3697 | * @mask: Bit mask to be checked. | |
3698 | * | |
3699 | * This function checks the host status register to check if HBA is | |
3700 | * ready. This function will wait in a loop for the HBA to be ready | |
3701 | * If the HBA is not ready , the function will will reset the HBA PCI | |
3702 | * function again. The function returns 1 when HBA fail to be ready | |
3703 | * otherwise returns zero. | |
3704 | **/ | |
3705 | static int | |
3706 | lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask) | |
3707 | { | |
3708 | uint32_t status; | |
3709 | int retval = 0; | |
3710 | ||
3711 | /* Read the HBA Host Status Register */ | |
3712 | status = lpfc_sli4_post_status_check(phba); | |
3713 | ||
3714 | if (status) { | |
3715 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; | |
3716 | lpfc_sli_brdrestart(phba); | |
3717 | status = lpfc_sli4_post_status_check(phba); | |
3718 | } | |
3719 | ||
3720 | /* Check to see if any errors occurred during init */ | |
3721 | if (status) { | |
3722 | phba->link_state = LPFC_HBA_ERROR; | |
3723 | retval = 1; | |
3724 | } else | |
3725 | phba->sli4_hba.intr_enable = 0; | |
3726 | ||
3727 | return retval; | |
3728 | } | |
3729 | ||
3730 | /** | |
3731 | * lpfc_sli_brdready - Wrapper func for checking the hba readyness | |
3732 | * @phba: Pointer to HBA context object. | |
3733 | * @mask: Bit mask to be checked. | |
3734 | * | |
3735 | * This routine wraps the actual SLI3 or SLI4 hba readyness check routine | |
3736 | * from the API jump table function pointer from the lpfc_hba struct. | |
3737 | **/ | |
3738 | int | |
3739 | lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask) | |
3740 | { | |
3741 | return phba->lpfc_sli_brdready(phba, mask); | |
3742 | } | |
3743 | ||
9290831f JS |
3744 | #define BARRIER_TEST_PATTERN (0xdeadbeef) |
3745 | ||
e59058c4 | 3746 | /** |
3621a710 | 3747 | * lpfc_reset_barrier - Make HBA ready for HBA reset |
e59058c4 JS |
3748 | * @phba: Pointer to HBA context object. |
3749 | * | |
1b51197d JS |
3750 | * This function is called before resetting an HBA. This function is called |
3751 | * with hbalock held and requests HBA to quiesce DMAs before a reset. | |
e59058c4 | 3752 | **/ |
2e0fef85 | 3753 | void lpfc_reset_barrier(struct lpfc_hba *phba) |
9290831f | 3754 | { |
65a29c16 JS |
3755 | uint32_t __iomem *resp_buf; |
3756 | uint32_t __iomem *mbox_buf; | |
9290831f | 3757 | volatile uint32_t mbox; |
9940b97b | 3758 | uint32_t hc_copy, ha_copy, resp_data; |
9290831f JS |
3759 | int i; |
3760 | uint8_t hdrtype; | |
3761 | ||
3762 | pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype); | |
3763 | if (hdrtype != 0x80 || | |
3764 | (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID && | |
3765 | FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID)) | |
3766 | return; | |
3767 | ||
3768 | /* | |
3769 | * Tell the other part of the chip to suspend temporarily all | |
3770 | * its DMA activity. | |
3771 | */ | |
65a29c16 | 3772 | resp_buf = phba->MBslimaddr; |
9290831f JS |
3773 | |
3774 | /* Disable the error attention */ | |
9940b97b JS |
3775 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) |
3776 | return; | |
9290831f JS |
3777 | writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr); |
3778 | readl(phba->HCregaddr); /* flush */ | |
2e0fef85 | 3779 | phba->link_flag |= LS_IGNORE_ERATT; |
9290831f | 3780 | |
9940b97b JS |
3781 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
3782 | return; | |
3783 | if (ha_copy & HA_ERATT) { | |
9290831f JS |
3784 | /* Clear Chip error bit */ |
3785 | writel(HA_ERATT, phba->HAregaddr); | |
2e0fef85 | 3786 | phba->pport->stopped = 1; |
9290831f JS |
3787 | } |
3788 | ||
3789 | mbox = 0; | |
3790 | ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD; | |
3791 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP; | |
3792 | ||
3793 | writel(BARRIER_TEST_PATTERN, (resp_buf + 1)); | |
65a29c16 | 3794 | mbox_buf = phba->MBslimaddr; |
9290831f JS |
3795 | writel(mbox, mbox_buf); |
3796 | ||
9940b97b JS |
3797 | for (i = 0; i < 50; i++) { |
3798 | if (lpfc_readl((resp_buf + 1), &resp_data)) | |
3799 | return; | |
3800 | if (resp_data != ~(BARRIER_TEST_PATTERN)) | |
3801 | mdelay(1); | |
3802 | else | |
3803 | break; | |
3804 | } | |
3805 | resp_data = 0; | |
3806 | if (lpfc_readl((resp_buf + 1), &resp_data)) | |
3807 | return; | |
3808 | if (resp_data != ~(BARRIER_TEST_PATTERN)) { | |
f4b4c68f | 3809 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE || |
2e0fef85 | 3810 | phba->pport->stopped) |
9290831f JS |
3811 | goto restore_hc; |
3812 | else | |
3813 | goto clear_errat; | |
3814 | } | |
3815 | ||
3816 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST; | |
9940b97b JS |
3817 | resp_data = 0; |
3818 | for (i = 0; i < 500; i++) { | |
3819 | if (lpfc_readl(resp_buf, &resp_data)) | |
3820 | return; | |
3821 | if (resp_data != mbox) | |
3822 | mdelay(1); | |
3823 | else | |
3824 | break; | |
3825 | } | |
9290831f JS |
3826 | |
3827 | clear_errat: | |
3828 | ||
9940b97b JS |
3829 | while (++i < 500) { |
3830 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) | |
3831 | return; | |
3832 | if (!(ha_copy & HA_ERATT)) | |
3833 | mdelay(1); | |
3834 | else | |
3835 | break; | |
3836 | } | |
9290831f JS |
3837 | |
3838 | if (readl(phba->HAregaddr) & HA_ERATT) { | |
3839 | writel(HA_ERATT, phba->HAregaddr); | |
2e0fef85 | 3840 | phba->pport->stopped = 1; |
9290831f JS |
3841 | } |
3842 | ||
3843 | restore_hc: | |
2e0fef85 | 3844 | phba->link_flag &= ~LS_IGNORE_ERATT; |
9290831f JS |
3845 | writel(hc_copy, phba->HCregaddr); |
3846 | readl(phba->HCregaddr); /* flush */ | |
3847 | } | |
3848 | ||
e59058c4 | 3849 | /** |
3621a710 | 3850 | * lpfc_sli_brdkill - Issue a kill_board mailbox command |
e59058c4 JS |
3851 | * @phba: Pointer to HBA context object. |
3852 | * | |
3853 | * This function issues a kill_board mailbox command and waits for | |
3854 | * the error attention interrupt. This function is called for stopping | |
3855 | * the firmware processing. The caller is not required to hold any | |
3856 | * locks. This function calls lpfc_hba_down_post function to free | |
3857 | * any pending commands after the kill. The function will return 1 when it | |
3858 | * fails to kill the board else will return 0. | |
3859 | **/ | |
41415862 | 3860 | int |
2e0fef85 | 3861 | lpfc_sli_brdkill(struct lpfc_hba *phba) |
41415862 JW |
3862 | { |
3863 | struct lpfc_sli *psli; | |
3864 | LPFC_MBOXQ_t *pmb; | |
3865 | uint32_t status; | |
3866 | uint32_t ha_copy; | |
3867 | int retval; | |
3868 | int i = 0; | |
dea3101e | 3869 | |
41415862 | 3870 | psli = &phba->sli; |
dea3101e | 3871 | |
41415862 | 3872 | /* Kill HBA */ |
ed957684 | 3873 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
e8b62011 JS |
3874 | "0329 Kill HBA Data: x%x x%x\n", |
3875 | phba->pport->port_state, psli->sli_flag); | |
41415862 | 3876 | |
98c9ea5c JS |
3877 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
3878 | if (!pmb) | |
41415862 | 3879 | return 1; |
41415862 JW |
3880 | |
3881 | /* Disable the error attention */ | |
2e0fef85 | 3882 | spin_lock_irq(&phba->hbalock); |
9940b97b JS |
3883 | if (lpfc_readl(phba->HCregaddr, &status)) { |
3884 | spin_unlock_irq(&phba->hbalock); | |
3885 | mempool_free(pmb, phba->mbox_mem_pool); | |
3886 | return 1; | |
3887 | } | |
41415862 JW |
3888 | status &= ~HC_ERINT_ENA; |
3889 | writel(status, phba->HCregaddr); | |
3890 | readl(phba->HCregaddr); /* flush */ | |
2e0fef85 JS |
3891 | phba->link_flag |= LS_IGNORE_ERATT; |
3892 | spin_unlock_irq(&phba->hbalock); | |
41415862 JW |
3893 | |
3894 | lpfc_kill_board(phba, pmb); | |
3895 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
3896 | retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); | |
3897 | ||
3898 | if (retval != MBX_SUCCESS) { | |
3899 | if (retval != MBX_BUSY) | |
3900 | mempool_free(pmb, phba->mbox_mem_pool); | |
e40a02c1 JS |
3901 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
3902 | "2752 KILL_BOARD command failed retval %d\n", | |
3903 | retval); | |
2e0fef85 JS |
3904 | spin_lock_irq(&phba->hbalock); |
3905 | phba->link_flag &= ~LS_IGNORE_ERATT; | |
3906 | spin_unlock_irq(&phba->hbalock); | |
41415862 JW |
3907 | return 1; |
3908 | } | |
3909 | ||
f4b4c68f JS |
3910 | spin_lock_irq(&phba->hbalock); |
3911 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; | |
3912 | spin_unlock_irq(&phba->hbalock); | |
9290831f | 3913 | |
41415862 JW |
3914 | mempool_free(pmb, phba->mbox_mem_pool); |
3915 | ||
3916 | /* There is no completion for a KILL_BOARD mbox cmd. Check for an error | |
3917 | * attention every 100ms for 3 seconds. If we don't get ERATT after | |
3918 | * 3 seconds we still set HBA_ERROR state because the status of the | |
3919 | * board is now undefined. | |
3920 | */ | |
9940b97b JS |
3921 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
3922 | return 1; | |
41415862 JW |
3923 | while ((i++ < 30) && !(ha_copy & HA_ERATT)) { |
3924 | mdelay(100); | |
9940b97b JS |
3925 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
3926 | return 1; | |
41415862 JW |
3927 | } |
3928 | ||
3929 | del_timer_sync(&psli->mbox_tmo); | |
9290831f JS |
3930 | if (ha_copy & HA_ERATT) { |
3931 | writel(HA_ERATT, phba->HAregaddr); | |
2e0fef85 | 3932 | phba->pport->stopped = 1; |
9290831f | 3933 | } |
2e0fef85 | 3934 | spin_lock_irq(&phba->hbalock); |
41415862 | 3935 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
04c68496 | 3936 | psli->mbox_active = NULL; |
2e0fef85 JS |
3937 | phba->link_flag &= ~LS_IGNORE_ERATT; |
3938 | spin_unlock_irq(&phba->hbalock); | |
41415862 | 3939 | |
41415862 | 3940 | lpfc_hba_down_post(phba); |
2e0fef85 | 3941 | phba->link_state = LPFC_HBA_ERROR; |
41415862 | 3942 | |
2e0fef85 | 3943 | return ha_copy & HA_ERATT ? 0 : 1; |
dea3101e | 3944 | } |
3945 | ||
e59058c4 | 3946 | /** |
3772a991 | 3947 | * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA |
e59058c4 JS |
3948 | * @phba: Pointer to HBA context object. |
3949 | * | |
3950 | * This function resets the HBA by writing HC_INITFF to the control | |
3951 | * register. After the HBA resets, this function resets all the iocb ring | |
3952 | * indices. This function disables PCI layer parity checking during | |
3953 | * the reset. | |
3954 | * This function returns 0 always. | |
3955 | * The caller is not required to hold any locks. | |
3956 | **/ | |
41415862 | 3957 | int |
2e0fef85 | 3958 | lpfc_sli_brdreset(struct lpfc_hba *phba) |
dea3101e | 3959 | { |
41415862 | 3960 | struct lpfc_sli *psli; |
dea3101e | 3961 | struct lpfc_sli_ring *pring; |
41415862 | 3962 | uint16_t cfg_value; |
dea3101e | 3963 | int i; |
dea3101e | 3964 | |
41415862 | 3965 | psli = &phba->sli; |
dea3101e | 3966 | |
41415862 JW |
3967 | /* Reset HBA */ |
3968 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
e8b62011 | 3969 | "0325 Reset HBA Data: x%x x%x\n", |
2e0fef85 | 3970 | phba->pport->port_state, psli->sli_flag); |
dea3101e | 3971 | |
3972 | /* perform board reset */ | |
3973 | phba->fc_eventTag = 0; | |
4d9ab994 | 3974 | phba->link_events = 0; |
2e0fef85 JS |
3975 | phba->pport->fc_myDID = 0; |
3976 | phba->pport->fc_prevDID = 0; | |
dea3101e | 3977 | |
41415862 JW |
3978 | /* Turn off parity checking and serr during the physical reset */ |
3979 | pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value); | |
3980 | pci_write_config_word(phba->pcidev, PCI_COMMAND, | |
3981 | (cfg_value & | |
3982 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); | |
3983 | ||
3772a991 JS |
3984 | psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA); |
3985 | ||
41415862 JW |
3986 | /* Now toggle INITFF bit in the Host Control Register */ |
3987 | writel(HC_INITFF, phba->HCregaddr); | |
3988 | mdelay(1); | |
3989 | readl(phba->HCregaddr); /* flush */ | |
3990 | writel(0, phba->HCregaddr); | |
3991 | readl(phba->HCregaddr); /* flush */ | |
3992 | ||
3993 | /* Restore PCI cmd register */ | |
3994 | pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); | |
dea3101e | 3995 | |
3996 | /* Initialize relevant SLI info */ | |
41415862 JW |
3997 | for (i = 0; i < psli->num_rings; i++) { |
3998 | pring = &psli->ring[i]; | |
dea3101e | 3999 | pring->flag = 0; |
7e56aa25 JS |
4000 | pring->sli.sli3.rspidx = 0; |
4001 | pring->sli.sli3.next_cmdidx = 0; | |
4002 | pring->sli.sli3.local_getidx = 0; | |
4003 | pring->sli.sli3.cmdidx = 0; | |
dea3101e | 4004 | pring->missbufcnt = 0; |
4005 | } | |
dea3101e | 4006 | |
2e0fef85 | 4007 | phba->link_state = LPFC_WARM_START; |
41415862 JW |
4008 | return 0; |
4009 | } | |
4010 | ||
e59058c4 | 4011 | /** |
da0436e9 JS |
4012 | * lpfc_sli4_brdreset - Reset a sli-4 HBA |
4013 | * @phba: Pointer to HBA context object. | |
4014 | * | |
4015 | * This function resets a SLI4 HBA. This function disables PCI layer parity | |
4016 | * checking during resets the device. The caller is not required to hold | |
4017 | * any locks. | |
4018 | * | |
4019 | * This function returns 0 always. | |
4020 | **/ | |
4021 | int | |
4022 | lpfc_sli4_brdreset(struct lpfc_hba *phba) | |
4023 | { | |
4024 | struct lpfc_sli *psli = &phba->sli; | |
4025 | uint16_t cfg_value; | |
0293635e | 4026 | int rc = 0; |
da0436e9 JS |
4027 | |
4028 | /* Reset HBA */ | |
4029 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
0293635e JS |
4030 | "0295 Reset HBA Data: x%x x%x x%x\n", |
4031 | phba->pport->port_state, psli->sli_flag, | |
4032 | phba->hba_flag); | |
da0436e9 JS |
4033 | |
4034 | /* perform board reset */ | |
4035 | phba->fc_eventTag = 0; | |
4d9ab994 | 4036 | phba->link_events = 0; |
da0436e9 JS |
4037 | phba->pport->fc_myDID = 0; |
4038 | phba->pport->fc_prevDID = 0; | |
4039 | ||
da0436e9 JS |
4040 | spin_lock_irq(&phba->hbalock); |
4041 | psli->sli_flag &= ~(LPFC_PROCESS_LA); | |
4042 | phba->fcf.fcf_flag = 0; | |
da0436e9 JS |
4043 | spin_unlock_irq(&phba->hbalock); |
4044 | ||
0293635e JS |
4045 | /* SLI4 INTF 2: if FW dump is being taken skip INIT_PORT */ |
4046 | if (phba->hba_flag & HBA_FW_DUMP_OP) { | |
4047 | phba->hba_flag &= ~HBA_FW_DUMP_OP; | |
4048 | return rc; | |
4049 | } | |
4050 | ||
da0436e9 JS |
4051 | /* Now physically reset the device */ |
4052 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
4053 | "0389 Performing PCI function reset!\n"); | |
be858b65 JS |
4054 | |
4055 | /* Turn off parity checking and serr during the physical reset */ | |
4056 | pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value); | |
4057 | pci_write_config_word(phba->pcidev, PCI_COMMAND, (cfg_value & | |
4058 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); | |
4059 | ||
88318816 | 4060 | /* Perform FCoE PCI function reset before freeing queue memory */ |
27b01b82 | 4061 | rc = lpfc_pci_function_reset(phba); |
88318816 | 4062 | lpfc_sli4_queue_destroy(phba); |
da0436e9 | 4063 | |
be858b65 JS |
4064 | /* Restore PCI cmd register */ |
4065 | pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); | |
4066 | ||
27b01b82 | 4067 | return rc; |
da0436e9 JS |
4068 | } |
4069 | ||
4070 | /** | |
4071 | * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba | |
e59058c4 JS |
4072 | * @phba: Pointer to HBA context object. |
4073 | * | |
4074 | * This function is called in the SLI initialization code path to | |
4075 | * restart the HBA. The caller is not required to hold any lock. | |
4076 | * This function writes MBX_RESTART mailbox command to the SLIM and | |
4077 | * resets the HBA. At the end of the function, it calls lpfc_hba_down_post | |
4078 | * function to free any pending commands. The function enables | |
4079 | * POST only during the first initialization. The function returns zero. | |
4080 | * The function does not guarantee completion of MBX_RESTART mailbox | |
4081 | * command before the return of this function. | |
4082 | **/ | |
da0436e9 JS |
4083 | static int |
4084 | lpfc_sli_brdrestart_s3(struct lpfc_hba *phba) | |
41415862 JW |
4085 | { |
4086 | MAILBOX_t *mb; | |
4087 | struct lpfc_sli *psli; | |
41415862 JW |
4088 | volatile uint32_t word0; |
4089 | void __iomem *to_slim; | |
0d878419 | 4090 | uint32_t hba_aer_enabled; |
41415862 | 4091 | |
2e0fef85 | 4092 | spin_lock_irq(&phba->hbalock); |
41415862 | 4093 | |
0d878419 JS |
4094 | /* Take PCIe device Advanced Error Reporting (AER) state */ |
4095 | hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED; | |
4096 | ||
41415862 JW |
4097 | psli = &phba->sli; |
4098 | ||
4099 | /* Restart HBA */ | |
4100 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
e8b62011 | 4101 | "0337 Restart HBA Data: x%x x%x\n", |
2e0fef85 | 4102 | phba->pport->port_state, psli->sli_flag); |
41415862 JW |
4103 | |
4104 | word0 = 0; | |
4105 | mb = (MAILBOX_t *) &word0; | |
4106 | mb->mbxCommand = MBX_RESTART; | |
4107 | mb->mbxHc = 1; | |
4108 | ||
9290831f JS |
4109 | lpfc_reset_barrier(phba); |
4110 | ||
41415862 JW |
4111 | to_slim = phba->MBslimaddr; |
4112 | writel(*(uint32_t *) mb, to_slim); | |
4113 | readl(to_slim); /* flush */ | |
4114 | ||
4115 | /* Only skip post after fc_ffinit is completed */ | |
eaf15d5b | 4116 | if (phba->pport->port_state) |
41415862 | 4117 | word0 = 1; /* This is really setting up word1 */ |
eaf15d5b | 4118 | else |
41415862 | 4119 | word0 = 0; /* This is really setting up word1 */ |
65a29c16 | 4120 | to_slim = phba->MBslimaddr + sizeof (uint32_t); |
41415862 JW |
4121 | writel(*(uint32_t *) mb, to_slim); |
4122 | readl(to_slim); /* flush */ | |
dea3101e | 4123 | |
41415862 | 4124 | lpfc_sli_brdreset(phba); |
2e0fef85 JS |
4125 | phba->pport->stopped = 0; |
4126 | phba->link_state = LPFC_INIT_START; | |
da0436e9 | 4127 | phba->hba_flag = 0; |
2e0fef85 | 4128 | spin_unlock_irq(&phba->hbalock); |
41415862 | 4129 | |
64ba8818 JS |
4130 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); |
4131 | psli->stats_start = get_seconds(); | |
4132 | ||
eaf15d5b JS |
4133 | /* Give the INITFF and Post time to settle. */ |
4134 | mdelay(100); | |
41415862 | 4135 | |
0d878419 JS |
4136 | /* Reset HBA AER if it was enabled, note hba_flag was reset above */ |
4137 | if (hba_aer_enabled) | |
4138 | pci_disable_pcie_error_reporting(phba->pcidev); | |
4139 | ||
41415862 | 4140 | lpfc_hba_down_post(phba); |
dea3101e | 4141 | |
4142 | return 0; | |
4143 | } | |
4144 | ||
da0436e9 JS |
4145 | /** |
4146 | * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba | |
4147 | * @phba: Pointer to HBA context object. | |
4148 | * | |
4149 | * This function is called in the SLI initialization code path to restart | |
4150 | * a SLI4 HBA. The caller is not required to hold any lock. | |
4151 | * At the end of the function, it calls lpfc_hba_down_post function to | |
4152 | * free any pending commands. | |
4153 | **/ | |
4154 | static int | |
4155 | lpfc_sli_brdrestart_s4(struct lpfc_hba *phba) | |
4156 | { | |
4157 | struct lpfc_sli *psli = &phba->sli; | |
75baf696 | 4158 | uint32_t hba_aer_enabled; |
27b01b82 | 4159 | int rc; |
da0436e9 JS |
4160 | |
4161 | /* Restart HBA */ | |
4162 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
4163 | "0296 Restart HBA Data: x%x x%x\n", | |
4164 | phba->pport->port_state, psli->sli_flag); | |
4165 | ||
75baf696 JS |
4166 | /* Take PCIe device Advanced Error Reporting (AER) state */ |
4167 | hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED; | |
4168 | ||
27b01b82 | 4169 | rc = lpfc_sli4_brdreset(phba); |
da0436e9 JS |
4170 | |
4171 | spin_lock_irq(&phba->hbalock); | |
4172 | phba->pport->stopped = 0; | |
4173 | phba->link_state = LPFC_INIT_START; | |
4174 | phba->hba_flag = 0; | |
4175 | spin_unlock_irq(&phba->hbalock); | |
4176 | ||
4177 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); | |
4178 | psli->stats_start = get_seconds(); | |
4179 | ||
75baf696 JS |
4180 | /* Reset HBA AER if it was enabled, note hba_flag was reset above */ |
4181 | if (hba_aer_enabled) | |
4182 | pci_disable_pcie_error_reporting(phba->pcidev); | |
4183 | ||
da0436e9 JS |
4184 | lpfc_hba_down_post(phba); |
4185 | ||
27b01b82 | 4186 | return rc; |
da0436e9 JS |
4187 | } |
4188 | ||
4189 | /** | |
4190 | * lpfc_sli_brdrestart - Wrapper func for restarting hba | |
4191 | * @phba: Pointer to HBA context object. | |
4192 | * | |
4193 | * This routine wraps the actual SLI3 or SLI4 hba restart routine from the | |
4194 | * API jump table function pointer from the lpfc_hba struct. | |
4195 | **/ | |
4196 | int | |
4197 | lpfc_sli_brdrestart(struct lpfc_hba *phba) | |
4198 | { | |
4199 | return phba->lpfc_sli_brdrestart(phba); | |
4200 | } | |
4201 | ||
e59058c4 | 4202 | /** |
3621a710 | 4203 | * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart |
e59058c4 JS |
4204 | * @phba: Pointer to HBA context object. |
4205 | * | |
4206 | * This function is called after a HBA restart to wait for successful | |
4207 | * restart of the HBA. Successful restart of the HBA is indicated by | |
4208 | * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15 | |
4209 | * iteration, the function will restart the HBA again. The function returns | |
4210 | * zero if HBA successfully restarted else returns negative error code. | |
4211 | **/ | |
dea3101e | 4212 | static int |
4213 | lpfc_sli_chipset_init(struct lpfc_hba *phba) | |
4214 | { | |
4215 | uint32_t status, i = 0; | |
4216 | ||
4217 | /* Read the HBA Host Status Register */ | |
9940b97b JS |
4218 | if (lpfc_readl(phba->HSregaddr, &status)) |
4219 | return -EIO; | |
dea3101e | 4220 | |
4221 | /* Check status register to see what current state is */ | |
4222 | i = 0; | |
4223 | while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) { | |
4224 | ||
dcf2a4e0 JS |
4225 | /* Check every 10ms for 10 retries, then every 100ms for 90 |
4226 | * retries, then every 1 sec for 50 retires for a total of | |
4227 | * ~60 seconds before reset the board again and check every | |
4228 | * 1 sec for 50 retries. The up to 60 seconds before the | |
4229 | * board ready is required by the Falcon FIPS zeroization | |
4230 | * complete, and any reset the board in between shall cause | |
4231 | * restart of zeroization, further delay the board ready. | |
dea3101e | 4232 | */ |
dcf2a4e0 | 4233 | if (i++ >= 200) { |
dea3101e | 4234 | /* Adapter failed to init, timeout, status reg |
4235 | <status> */ | |
ed957684 | 4236 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 4237 | "0436 Adapter failed to init, " |
09372820 JS |
4238 | "timeout, status reg x%x, " |
4239 | "FW Data: A8 x%x AC x%x\n", status, | |
4240 | readl(phba->MBslimaddr + 0xa8), | |
4241 | readl(phba->MBslimaddr + 0xac)); | |
2e0fef85 | 4242 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e | 4243 | return -ETIMEDOUT; |
4244 | } | |
4245 | ||
4246 | /* Check to see if any errors occurred during init */ | |
4247 | if (status & HS_FFERM) { | |
4248 | /* ERROR: During chipset initialization */ | |
4249 | /* Adapter failed to init, chipset, status reg | |
4250 | <status> */ | |
ed957684 | 4251 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 4252 | "0437 Adapter failed to init, " |
09372820 JS |
4253 | "chipset, status reg x%x, " |
4254 | "FW Data: A8 x%x AC x%x\n", status, | |
4255 | readl(phba->MBslimaddr + 0xa8), | |
4256 | readl(phba->MBslimaddr + 0xac)); | |
2e0fef85 | 4257 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e | 4258 | return -EIO; |
4259 | } | |
4260 | ||
dcf2a4e0 | 4261 | if (i <= 10) |
dea3101e | 4262 | msleep(10); |
dcf2a4e0 JS |
4263 | else if (i <= 100) |
4264 | msleep(100); | |
4265 | else | |
4266 | msleep(1000); | |
dea3101e | 4267 | |
dcf2a4e0 JS |
4268 | if (i == 150) { |
4269 | /* Do post */ | |
92d7f7b0 | 4270 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
41415862 | 4271 | lpfc_sli_brdrestart(phba); |
dea3101e | 4272 | } |
4273 | /* Read the HBA Host Status Register */ | |
9940b97b JS |
4274 | if (lpfc_readl(phba->HSregaddr, &status)) |
4275 | return -EIO; | |
dea3101e | 4276 | } |
4277 | ||
4278 | /* Check to see if any errors occurred during init */ | |
4279 | if (status & HS_FFERM) { | |
4280 | /* ERROR: During chipset initialization */ | |
4281 | /* Adapter failed to init, chipset, status reg <status> */ | |
ed957684 | 4282 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 4283 | "0438 Adapter failed to init, chipset, " |
09372820 JS |
4284 | "status reg x%x, " |
4285 | "FW Data: A8 x%x AC x%x\n", status, | |
4286 | readl(phba->MBslimaddr + 0xa8), | |
4287 | readl(phba->MBslimaddr + 0xac)); | |
2e0fef85 | 4288 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e | 4289 | return -EIO; |
4290 | } | |
4291 | ||
4292 | /* Clear all interrupt enable conditions */ | |
4293 | writel(0, phba->HCregaddr); | |
4294 | readl(phba->HCregaddr); /* flush */ | |
4295 | ||
4296 | /* setup host attn register */ | |
4297 | writel(0xffffffff, phba->HAregaddr); | |
4298 | readl(phba->HAregaddr); /* flush */ | |
4299 | return 0; | |
4300 | } | |
4301 | ||
e59058c4 | 4302 | /** |
3621a710 | 4303 | * lpfc_sli_hbq_count - Get the number of HBQs to be configured |
e59058c4 JS |
4304 | * |
4305 | * This function calculates and returns the number of HBQs required to be | |
4306 | * configured. | |
4307 | **/ | |
78b2d852 | 4308 | int |
ed957684 JS |
4309 | lpfc_sli_hbq_count(void) |
4310 | { | |
92d7f7b0 | 4311 | return ARRAY_SIZE(lpfc_hbq_defs); |
ed957684 JS |
4312 | } |
4313 | ||
e59058c4 | 4314 | /** |
3621a710 | 4315 | * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries |
e59058c4 JS |
4316 | * |
4317 | * This function adds the number of hbq entries in every HBQ to get | |
4318 | * the total number of hbq entries required for the HBA and returns | |
4319 | * the total count. | |
4320 | **/ | |
ed957684 JS |
4321 | static int |
4322 | lpfc_sli_hbq_entry_count(void) | |
4323 | { | |
4324 | int hbq_count = lpfc_sli_hbq_count(); | |
4325 | int count = 0; | |
4326 | int i; | |
4327 | ||
4328 | for (i = 0; i < hbq_count; ++i) | |
92d7f7b0 | 4329 | count += lpfc_hbq_defs[i]->entry_count; |
ed957684 JS |
4330 | return count; |
4331 | } | |
4332 | ||
e59058c4 | 4333 | /** |
3621a710 | 4334 | * lpfc_sli_hbq_size - Calculate memory required for all hbq entries |
e59058c4 JS |
4335 | * |
4336 | * This function calculates amount of memory required for all hbq entries | |
4337 | * to be configured and returns the total memory required. | |
4338 | **/ | |
dea3101e | 4339 | int |
ed957684 JS |
4340 | lpfc_sli_hbq_size(void) |
4341 | { | |
4342 | return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry); | |
4343 | } | |
4344 | ||
e59058c4 | 4345 | /** |
3621a710 | 4346 | * lpfc_sli_hbq_setup - configure and initialize HBQs |
e59058c4 JS |
4347 | * @phba: Pointer to HBA context object. |
4348 | * | |
4349 | * This function is called during the SLI initialization to configure | |
4350 | * all the HBQs and post buffers to the HBQ. The caller is not | |
4351 | * required to hold any locks. This function will return zero if successful | |
4352 | * else it will return negative error code. | |
4353 | **/ | |
ed957684 JS |
4354 | static int |
4355 | lpfc_sli_hbq_setup(struct lpfc_hba *phba) | |
4356 | { | |
4357 | int hbq_count = lpfc_sli_hbq_count(); | |
4358 | LPFC_MBOXQ_t *pmb; | |
4359 | MAILBOX_t *pmbox; | |
4360 | uint32_t hbqno; | |
4361 | uint32_t hbq_entry_index; | |
ed957684 | 4362 | |
92d7f7b0 JS |
4363 | /* Get a Mailbox buffer to setup mailbox |
4364 | * commands for HBA initialization | |
4365 | */ | |
ed957684 JS |
4366 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
4367 | ||
4368 | if (!pmb) | |
4369 | return -ENOMEM; | |
4370 | ||
04c68496 | 4371 | pmbox = &pmb->u.mb; |
ed957684 JS |
4372 | |
4373 | /* Initialize the struct lpfc_sli_hbq structure for each hbq */ | |
4374 | phba->link_state = LPFC_INIT_MBX_CMDS; | |
3163f725 | 4375 | phba->hbq_in_use = 1; |
ed957684 JS |
4376 | |
4377 | hbq_entry_index = 0; | |
4378 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) { | |
4379 | phba->hbqs[hbqno].next_hbqPutIdx = 0; | |
4380 | phba->hbqs[hbqno].hbqPutIdx = 0; | |
4381 | phba->hbqs[hbqno].local_hbqGetIdx = 0; | |
4382 | phba->hbqs[hbqno].entry_count = | |
92d7f7b0 | 4383 | lpfc_hbq_defs[hbqno]->entry_count; |
51ef4c26 JS |
4384 | lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno], |
4385 | hbq_entry_index, pmb); | |
ed957684 JS |
4386 | hbq_entry_index += phba->hbqs[hbqno].entry_count; |
4387 | ||
4388 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { | |
4389 | /* Adapter failed to init, mbxCmd <cmd> CFG_RING, | |
4390 | mbxStatus <status>, ring <num> */ | |
4391 | ||
4392 | lpfc_printf_log(phba, KERN_ERR, | |
92d7f7b0 | 4393 | LOG_SLI | LOG_VPORT, |
e8b62011 | 4394 | "1805 Adapter failed to init. " |
ed957684 | 4395 | "Data: x%x x%x x%x\n", |
e8b62011 | 4396 | pmbox->mbxCommand, |
ed957684 JS |
4397 | pmbox->mbxStatus, hbqno); |
4398 | ||
4399 | phba->link_state = LPFC_HBA_ERROR; | |
4400 | mempool_free(pmb, phba->mbox_mem_pool); | |
6e7288d9 | 4401 | return -ENXIO; |
ed957684 JS |
4402 | } |
4403 | } | |
4404 | phba->hbq_count = hbq_count; | |
4405 | ||
ed957684 JS |
4406 | mempool_free(pmb, phba->mbox_mem_pool); |
4407 | ||
92d7f7b0 | 4408 | /* Initially populate or replenish the HBQs */ |
d7c255b2 JS |
4409 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) |
4410 | lpfc_sli_hbqbuf_init_hbqs(phba, hbqno); | |
ed957684 JS |
4411 | return 0; |
4412 | } | |
4413 | ||
4f774513 JS |
4414 | /** |
4415 | * lpfc_sli4_rb_setup - Initialize and post RBs to HBA | |
4416 | * @phba: Pointer to HBA context object. | |
4417 | * | |
4418 | * This function is called during the SLI initialization to configure | |
4419 | * all the HBQs and post buffers to the HBQ. The caller is not | |
4420 | * required to hold any locks. This function will return zero if successful | |
4421 | * else it will return negative error code. | |
4422 | **/ | |
4423 | static int | |
4424 | lpfc_sli4_rb_setup(struct lpfc_hba *phba) | |
4425 | { | |
4426 | phba->hbq_in_use = 1; | |
4427 | phba->hbqs[0].entry_count = lpfc_hbq_defs[0]->entry_count; | |
4428 | phba->hbq_count = 1; | |
4429 | /* Initially populate or replenish the HBQs */ | |
4430 | lpfc_sli_hbqbuf_init_hbqs(phba, 0); | |
4431 | return 0; | |
4432 | } | |
4433 | ||
e59058c4 | 4434 | /** |
3621a710 | 4435 | * lpfc_sli_config_port - Issue config port mailbox command |
e59058c4 JS |
4436 | * @phba: Pointer to HBA context object. |
4437 | * @sli_mode: sli mode - 2/3 | |
4438 | * | |
4439 | * This function is called by the sli intialization code path | |
4440 | * to issue config_port mailbox command. This function restarts the | |
4441 | * HBA firmware and issues a config_port mailbox command to configure | |
4442 | * the SLI interface in the sli mode specified by sli_mode | |
4443 | * variable. The caller is not required to hold any locks. | |
4444 | * The function returns 0 if successful, else returns negative error | |
4445 | * code. | |
4446 | **/ | |
9399627f JS |
4447 | int |
4448 | lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode) | |
dea3101e | 4449 | { |
4450 | LPFC_MBOXQ_t *pmb; | |
4451 | uint32_t resetcount = 0, rc = 0, done = 0; | |
4452 | ||
4453 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
4454 | if (!pmb) { | |
2e0fef85 | 4455 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e | 4456 | return -ENOMEM; |
4457 | } | |
4458 | ||
ed957684 | 4459 | phba->sli_rev = sli_mode; |
dea3101e | 4460 | while (resetcount < 2 && !done) { |
2e0fef85 | 4461 | spin_lock_irq(&phba->hbalock); |
1c067a42 | 4462 | phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
2e0fef85 | 4463 | spin_unlock_irq(&phba->hbalock); |
92d7f7b0 | 4464 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
41415862 | 4465 | lpfc_sli_brdrestart(phba); |
dea3101e | 4466 | rc = lpfc_sli_chipset_init(phba); |
4467 | if (rc) | |
4468 | break; | |
4469 | ||
2e0fef85 | 4470 | spin_lock_irq(&phba->hbalock); |
1c067a42 | 4471 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
2e0fef85 | 4472 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 4473 | resetcount++; |
4474 | ||
ed957684 JS |
4475 | /* Call pre CONFIG_PORT mailbox command initialization. A |
4476 | * value of 0 means the call was successful. Any other | |
4477 | * nonzero value is a failure, but if ERESTART is returned, | |
4478 | * the driver may reset the HBA and try again. | |
4479 | */ | |
dea3101e | 4480 | rc = lpfc_config_port_prep(phba); |
4481 | if (rc == -ERESTART) { | |
ed957684 | 4482 | phba->link_state = LPFC_LINK_UNKNOWN; |
dea3101e | 4483 | continue; |
34b02dcd | 4484 | } else if (rc) |
dea3101e | 4485 | break; |
6d368e53 | 4486 | |
2e0fef85 | 4487 | phba->link_state = LPFC_INIT_MBX_CMDS; |
dea3101e | 4488 | lpfc_config_port(phba, pmb); |
4489 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); | |
34b02dcd JS |
4490 | phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED | |
4491 | LPFC_SLI3_HBQ_ENABLED | | |
4492 | LPFC_SLI3_CRP_ENABLED | | |
bc73905a JS |
4493 | LPFC_SLI3_BG_ENABLED | |
4494 | LPFC_SLI3_DSS_ENABLED); | |
ed957684 | 4495 | if (rc != MBX_SUCCESS) { |
dea3101e | 4496 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 4497 | "0442 Adapter failed to init, mbxCmd x%x " |
92d7f7b0 | 4498 | "CONFIG_PORT, mbxStatus x%x Data: x%x\n", |
04c68496 | 4499 | pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0); |
2e0fef85 | 4500 | spin_lock_irq(&phba->hbalock); |
04c68496 | 4501 | phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE; |
2e0fef85 JS |
4502 | spin_unlock_irq(&phba->hbalock); |
4503 | rc = -ENXIO; | |
04c68496 JS |
4504 | } else { |
4505 | /* Allow asynchronous mailbox command to go through */ | |
4506 | spin_lock_irq(&phba->hbalock); | |
4507 | phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; | |
4508 | spin_unlock_irq(&phba->hbalock); | |
ed957684 | 4509 | done = 1; |
cb69f7de JS |
4510 | |
4511 | if ((pmb->u.mb.un.varCfgPort.casabt == 1) && | |
4512 | (pmb->u.mb.un.varCfgPort.gasabt == 0)) | |
4513 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
4514 | "3110 Port did not grant ASABT\n"); | |
04c68496 | 4515 | } |
dea3101e | 4516 | } |
ed957684 JS |
4517 | if (!done) { |
4518 | rc = -EINVAL; | |
4519 | goto do_prep_failed; | |
4520 | } | |
04c68496 JS |
4521 | if (pmb->u.mb.un.varCfgPort.sli_mode == 3) { |
4522 | if (!pmb->u.mb.un.varCfgPort.cMA) { | |
34b02dcd JS |
4523 | rc = -ENXIO; |
4524 | goto do_prep_failed; | |
4525 | } | |
04c68496 | 4526 | if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) { |
34b02dcd | 4527 | phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED; |
04c68496 JS |
4528 | phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi; |
4529 | phba->max_vports = (phba->max_vpi > phba->max_vports) ? | |
4530 | phba->max_vpi : phba->max_vports; | |
4531 | ||
34b02dcd JS |
4532 | } else |
4533 | phba->max_vpi = 0; | |
bc73905a JS |
4534 | phba->fips_level = 0; |
4535 | phba->fips_spec_rev = 0; | |
4536 | if (pmb->u.mb.un.varCfgPort.gdss) { | |
04c68496 | 4537 | phba->sli3_options |= LPFC_SLI3_DSS_ENABLED; |
bc73905a JS |
4538 | phba->fips_level = pmb->u.mb.un.varCfgPort.fips_level; |
4539 | phba->fips_spec_rev = pmb->u.mb.un.varCfgPort.fips_rev; | |
4540 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
4541 | "2850 Security Crypto Active. FIPS x%d " | |
4542 | "(Spec Rev: x%d)", | |
4543 | phba->fips_level, phba->fips_spec_rev); | |
4544 | } | |
4545 | if (pmb->u.mb.un.varCfgPort.sec_err) { | |
4546 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4547 | "2856 Config Port Security Crypto " | |
4548 | "Error: x%x ", | |
4549 | pmb->u.mb.un.varCfgPort.sec_err); | |
4550 | } | |
04c68496 | 4551 | if (pmb->u.mb.un.varCfgPort.gerbm) |
34b02dcd | 4552 | phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED; |
04c68496 | 4553 | if (pmb->u.mb.un.varCfgPort.gcrp) |
34b02dcd | 4554 | phba->sli3_options |= LPFC_SLI3_CRP_ENABLED; |
6e7288d9 JS |
4555 | |
4556 | phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get; | |
4557 | phba->port_gp = phba->mbox->us.s3_pgp.port; | |
e2a0a9d6 JS |
4558 | |
4559 | if (phba->cfg_enable_bg) { | |
04c68496 | 4560 | if (pmb->u.mb.un.varCfgPort.gbg) |
e2a0a9d6 JS |
4561 | phba->sli3_options |= LPFC_SLI3_BG_ENABLED; |
4562 | else | |
4563 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4564 | "0443 Adapter did not grant " | |
4565 | "BlockGuard\n"); | |
4566 | } | |
34b02dcd | 4567 | } else { |
8f34f4ce | 4568 | phba->hbq_get = NULL; |
34b02dcd | 4569 | phba->port_gp = phba->mbox->us.s2.port; |
d7c255b2 | 4570 | phba->max_vpi = 0; |
ed957684 | 4571 | } |
92d7f7b0 | 4572 | do_prep_failed: |
ed957684 JS |
4573 | mempool_free(pmb, phba->mbox_mem_pool); |
4574 | return rc; | |
4575 | } | |
4576 | ||
e59058c4 JS |
4577 | |
4578 | /** | |
3621a710 | 4579 | * lpfc_sli_hba_setup - SLI intialization function |
e59058c4 JS |
4580 | * @phba: Pointer to HBA context object. |
4581 | * | |
4582 | * This function is the main SLI intialization function. This function | |
4583 | * is called by the HBA intialization code, HBA reset code and HBA | |
4584 | * error attention handler code. Caller is not required to hold any | |
4585 | * locks. This function issues config_port mailbox command to configure | |
4586 | * the SLI, setup iocb rings and HBQ rings. In the end the function | |
4587 | * calls the config_port_post function to issue init_link mailbox | |
4588 | * command and to start the discovery. The function will return zero | |
4589 | * if successful, else it will return negative error code. | |
4590 | **/ | |
ed957684 JS |
4591 | int |
4592 | lpfc_sli_hba_setup(struct lpfc_hba *phba) | |
4593 | { | |
4594 | uint32_t rc; | |
6d368e53 JS |
4595 | int mode = 3, i; |
4596 | int longs; | |
ed957684 JS |
4597 | |
4598 | switch (lpfc_sli_mode) { | |
4599 | case 2: | |
78b2d852 | 4600 | if (phba->cfg_enable_npiv) { |
92d7f7b0 | 4601 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
e8b62011 | 4602 | "1824 NPIV enabled: Override lpfc_sli_mode " |
92d7f7b0 | 4603 | "parameter (%d) to auto (0).\n", |
e8b62011 | 4604 | lpfc_sli_mode); |
92d7f7b0 JS |
4605 | break; |
4606 | } | |
ed957684 JS |
4607 | mode = 2; |
4608 | break; | |
4609 | case 0: | |
4610 | case 3: | |
4611 | break; | |
4612 | default: | |
92d7f7b0 | 4613 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
e8b62011 JS |
4614 | "1819 Unrecognized lpfc_sli_mode " |
4615 | "parameter: %d.\n", lpfc_sli_mode); | |
ed957684 JS |
4616 | |
4617 | break; | |
4618 | } | |
4619 | ||
9399627f JS |
4620 | rc = lpfc_sli_config_port(phba, mode); |
4621 | ||
ed957684 | 4622 | if (rc && lpfc_sli_mode == 3) |
92d7f7b0 | 4623 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
e8b62011 JS |
4624 | "1820 Unable to select SLI-3. " |
4625 | "Not supported by adapter.\n"); | |
ed957684 | 4626 | if (rc && mode != 2) |
9399627f | 4627 | rc = lpfc_sli_config_port(phba, 2); |
ed957684 | 4628 | if (rc) |
dea3101e | 4629 | goto lpfc_sli_hba_setup_error; |
4630 | ||
0d878419 JS |
4631 | /* Enable PCIe device Advanced Error Reporting (AER) if configured */ |
4632 | if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) { | |
4633 | rc = pci_enable_pcie_error_reporting(phba->pcidev); | |
4634 | if (!rc) { | |
4635 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
4636 | "2709 This device supports " | |
4637 | "Advanced Error Reporting (AER)\n"); | |
4638 | spin_lock_irq(&phba->hbalock); | |
4639 | phba->hba_flag |= HBA_AER_ENABLED; | |
4640 | spin_unlock_irq(&phba->hbalock); | |
4641 | } else { | |
4642 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
4643 | "2708 This device does not support " | |
b069d7eb JS |
4644 | "Advanced Error Reporting (AER): %d\n", |
4645 | rc); | |
0d878419 JS |
4646 | phba->cfg_aer_support = 0; |
4647 | } | |
4648 | } | |
4649 | ||
ed957684 JS |
4650 | if (phba->sli_rev == 3) { |
4651 | phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE; | |
4652 | phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE; | |
ed957684 JS |
4653 | } else { |
4654 | phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE; | |
4655 | phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE; | |
92d7f7b0 | 4656 | phba->sli3_options = 0; |
ed957684 JS |
4657 | } |
4658 | ||
4659 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
e8b62011 JS |
4660 | "0444 Firmware in SLI %x mode. Max_vpi %d\n", |
4661 | phba->sli_rev, phba->max_vpi); | |
ed957684 | 4662 | rc = lpfc_sli_ring_map(phba); |
dea3101e | 4663 | |
4664 | if (rc) | |
4665 | goto lpfc_sli_hba_setup_error; | |
4666 | ||
6d368e53 JS |
4667 | /* Initialize VPIs. */ |
4668 | if (phba->sli_rev == LPFC_SLI_REV3) { | |
4669 | /* | |
4670 | * The VPI bitmask and physical ID array are allocated | |
4671 | * and initialized once only - at driver load. A port | |
4672 | * reset doesn't need to reinitialize this memory. | |
4673 | */ | |
4674 | if ((phba->vpi_bmask == NULL) && (phba->vpi_ids == NULL)) { | |
4675 | longs = (phba->max_vpi + BITS_PER_LONG) / BITS_PER_LONG; | |
4676 | phba->vpi_bmask = kzalloc(longs * sizeof(unsigned long), | |
4677 | GFP_KERNEL); | |
4678 | if (!phba->vpi_bmask) { | |
4679 | rc = -ENOMEM; | |
4680 | goto lpfc_sli_hba_setup_error; | |
4681 | } | |
4682 | ||
4683 | phba->vpi_ids = kzalloc( | |
4684 | (phba->max_vpi+1) * sizeof(uint16_t), | |
4685 | GFP_KERNEL); | |
4686 | if (!phba->vpi_ids) { | |
4687 | kfree(phba->vpi_bmask); | |
4688 | rc = -ENOMEM; | |
4689 | goto lpfc_sli_hba_setup_error; | |
4690 | } | |
4691 | for (i = 0; i < phba->max_vpi; i++) | |
4692 | phba->vpi_ids[i] = i; | |
4693 | } | |
4694 | } | |
4695 | ||
9399627f | 4696 | /* Init HBQs */ |
ed957684 JS |
4697 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
4698 | rc = lpfc_sli_hbq_setup(phba); | |
4699 | if (rc) | |
4700 | goto lpfc_sli_hba_setup_error; | |
4701 | } | |
04c68496 | 4702 | spin_lock_irq(&phba->hbalock); |
dea3101e | 4703 | phba->sli.sli_flag |= LPFC_PROCESS_LA; |
04c68496 | 4704 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 4705 | |
4706 | rc = lpfc_config_port_post(phba); | |
4707 | if (rc) | |
4708 | goto lpfc_sli_hba_setup_error; | |
4709 | ||
ed957684 JS |
4710 | return rc; |
4711 | ||
92d7f7b0 | 4712 | lpfc_sli_hba_setup_error: |
2e0fef85 | 4713 | phba->link_state = LPFC_HBA_ERROR; |
e40a02c1 | 4714 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 4715 | "0445 Firmware initialization failed\n"); |
dea3101e | 4716 | return rc; |
4717 | } | |
4718 | ||
e59058c4 | 4719 | /** |
da0436e9 JS |
4720 | * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region |
4721 | * @phba: Pointer to HBA context object. | |
4722 | * @mboxq: mailbox pointer. | |
4723 | * This function issue a dump mailbox command to read config region | |
4724 | * 23 and parse the records in the region and populate driver | |
4725 | * data structure. | |
e59058c4 | 4726 | **/ |
da0436e9 | 4727 | static int |
ff78d8f9 | 4728 | lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba) |
dea3101e | 4729 | { |
ff78d8f9 | 4730 | LPFC_MBOXQ_t *mboxq; |
da0436e9 JS |
4731 | struct lpfc_dmabuf *mp; |
4732 | struct lpfc_mqe *mqe; | |
4733 | uint32_t data_length; | |
4734 | int rc; | |
dea3101e | 4735 | |
da0436e9 JS |
4736 | /* Program the default value of vlan_id and fc_map */ |
4737 | phba->valid_vlan = 0; | |
4738 | phba->fc_map[0] = LPFC_FCOE_FCF_MAP0; | |
4739 | phba->fc_map[1] = LPFC_FCOE_FCF_MAP1; | |
4740 | phba->fc_map[2] = LPFC_FCOE_FCF_MAP2; | |
2e0fef85 | 4741 | |
ff78d8f9 JS |
4742 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
4743 | if (!mboxq) | |
da0436e9 JS |
4744 | return -ENOMEM; |
4745 | ||
ff78d8f9 JS |
4746 | mqe = &mboxq->u.mqe; |
4747 | if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) { | |
4748 | rc = -ENOMEM; | |
4749 | goto out_free_mboxq; | |
4750 | } | |
4751 | ||
da0436e9 JS |
4752 | mp = (struct lpfc_dmabuf *) mboxq->context1; |
4753 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
4754 | ||
4755 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, | |
4756 | "(%d):2571 Mailbox cmd x%x Status x%x " | |
4757 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x " | |
4758 | "x%x x%x x%x x%x x%x x%x x%x x%x x%x " | |
4759 | "CQ: x%x x%x x%x x%x\n", | |
4760 | mboxq->vport ? mboxq->vport->vpi : 0, | |
4761 | bf_get(lpfc_mqe_command, mqe), | |
4762 | bf_get(lpfc_mqe_status, mqe), | |
4763 | mqe->un.mb_words[0], mqe->un.mb_words[1], | |
4764 | mqe->un.mb_words[2], mqe->un.mb_words[3], | |
4765 | mqe->un.mb_words[4], mqe->un.mb_words[5], | |
4766 | mqe->un.mb_words[6], mqe->un.mb_words[7], | |
4767 | mqe->un.mb_words[8], mqe->un.mb_words[9], | |
4768 | mqe->un.mb_words[10], mqe->un.mb_words[11], | |
4769 | mqe->un.mb_words[12], mqe->un.mb_words[13], | |
4770 | mqe->un.mb_words[14], mqe->un.mb_words[15], | |
4771 | mqe->un.mb_words[16], mqe->un.mb_words[50], | |
4772 | mboxq->mcqe.word0, | |
4773 | mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1, | |
4774 | mboxq->mcqe.trailer); | |
4775 | ||
4776 | if (rc) { | |
4777 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
4778 | kfree(mp); | |
ff78d8f9 JS |
4779 | rc = -EIO; |
4780 | goto out_free_mboxq; | |
da0436e9 JS |
4781 | } |
4782 | data_length = mqe->un.mb_words[5]; | |
a0c87cbd | 4783 | if (data_length > DMP_RGN23_SIZE) { |
d11e31dd JS |
4784 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
4785 | kfree(mp); | |
ff78d8f9 JS |
4786 | rc = -EIO; |
4787 | goto out_free_mboxq; | |
d11e31dd | 4788 | } |
dea3101e | 4789 | |
da0436e9 JS |
4790 | lpfc_parse_fcoe_conf(phba, mp->virt, data_length); |
4791 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
4792 | kfree(mp); | |
ff78d8f9 JS |
4793 | rc = 0; |
4794 | ||
4795 | out_free_mboxq: | |
4796 | mempool_free(mboxq, phba->mbox_mem_pool); | |
4797 | return rc; | |
da0436e9 | 4798 | } |
e59058c4 JS |
4799 | |
4800 | /** | |
da0436e9 JS |
4801 | * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data |
4802 | * @phba: pointer to lpfc hba data structure. | |
4803 | * @mboxq: pointer to the LPFC_MBOXQ_t structure. | |
4804 | * @vpd: pointer to the memory to hold resulting port vpd data. | |
4805 | * @vpd_size: On input, the number of bytes allocated to @vpd. | |
4806 | * On output, the number of data bytes in @vpd. | |
e59058c4 | 4807 | * |
da0436e9 JS |
4808 | * This routine executes a READ_REV SLI4 mailbox command. In |
4809 | * addition, this routine gets the port vpd data. | |
4810 | * | |
4811 | * Return codes | |
af901ca1 | 4812 | * 0 - successful |
d439d286 | 4813 | * -ENOMEM - could not allocated memory. |
e59058c4 | 4814 | **/ |
da0436e9 JS |
4815 | static int |
4816 | lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, | |
4817 | uint8_t *vpd, uint32_t *vpd_size) | |
dea3101e | 4818 | { |
da0436e9 JS |
4819 | int rc = 0; |
4820 | uint32_t dma_size; | |
4821 | struct lpfc_dmabuf *dmabuf; | |
4822 | struct lpfc_mqe *mqe; | |
dea3101e | 4823 | |
da0436e9 JS |
4824 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
4825 | if (!dmabuf) | |
4826 | return -ENOMEM; | |
4827 | ||
4828 | /* | |
4829 | * Get a DMA buffer for the vpd data resulting from the READ_REV | |
4830 | * mailbox command. | |
a257bf90 | 4831 | */ |
da0436e9 | 4832 | dma_size = *vpd_size; |
1aee383d JP |
4833 | dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev, dma_size, |
4834 | &dmabuf->phys, GFP_KERNEL); | |
da0436e9 JS |
4835 | if (!dmabuf->virt) { |
4836 | kfree(dmabuf); | |
4837 | return -ENOMEM; | |
a257bf90 JS |
4838 | } |
4839 | ||
da0436e9 JS |
4840 | /* |
4841 | * The SLI4 implementation of READ_REV conflicts at word1, | |
4842 | * bits 31:16 and SLI4 adds vpd functionality not present | |
4843 | * in SLI3. This code corrects the conflicts. | |
1dcb58e5 | 4844 | */ |
da0436e9 JS |
4845 | lpfc_read_rev(phba, mboxq); |
4846 | mqe = &mboxq->u.mqe; | |
4847 | mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys); | |
4848 | mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys); | |
4849 | mqe->un.read_rev.word1 &= 0x0000FFFF; | |
4850 | bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1); | |
4851 | bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size); | |
4852 | ||
4853 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
4854 | if (rc) { | |
4855 | dma_free_coherent(&phba->pcidev->dev, dma_size, | |
4856 | dmabuf->virt, dmabuf->phys); | |
def9c7a9 | 4857 | kfree(dmabuf); |
da0436e9 JS |
4858 | return -EIO; |
4859 | } | |
1dcb58e5 | 4860 | |
da0436e9 JS |
4861 | /* |
4862 | * The available vpd length cannot be bigger than the | |
4863 | * DMA buffer passed to the port. Catch the less than | |
4864 | * case and update the caller's size. | |
4865 | */ | |
4866 | if (mqe->un.read_rev.avail_vpd_len < *vpd_size) | |
4867 | *vpd_size = mqe->un.read_rev.avail_vpd_len; | |
3772a991 | 4868 | |
d7c47992 JS |
4869 | memcpy(vpd, dmabuf->virt, *vpd_size); |
4870 | ||
da0436e9 JS |
4871 | dma_free_coherent(&phba->pcidev->dev, dma_size, |
4872 | dmabuf->virt, dmabuf->phys); | |
4873 | kfree(dmabuf); | |
4874 | return 0; | |
dea3101e | 4875 | } |
4876 | ||
cd1c8301 JS |
4877 | /** |
4878 | * lpfc_sli4_retrieve_pport_name - Retrieve SLI4 device physical port name | |
4879 | * @phba: pointer to lpfc hba data structure. | |
4880 | * | |
4881 | * This routine retrieves SLI4 device physical port name this PCI function | |
4882 | * is attached to. | |
4883 | * | |
4884 | * Return codes | |
4907cb7b | 4885 | * 0 - successful |
cd1c8301 JS |
4886 | * otherwise - failed to retrieve physical port name |
4887 | **/ | |
4888 | static int | |
4889 | lpfc_sli4_retrieve_pport_name(struct lpfc_hba *phba) | |
4890 | { | |
4891 | LPFC_MBOXQ_t *mboxq; | |
cd1c8301 JS |
4892 | struct lpfc_mbx_get_cntl_attributes *mbx_cntl_attr; |
4893 | struct lpfc_controller_attribute *cntl_attr; | |
4894 | struct lpfc_mbx_get_port_name *get_port_name; | |
4895 | void *virtaddr = NULL; | |
4896 | uint32_t alloclen, reqlen; | |
4897 | uint32_t shdr_status, shdr_add_status; | |
4898 | union lpfc_sli4_cfg_shdr *shdr; | |
4899 | char cport_name = 0; | |
4900 | int rc; | |
4901 | ||
4902 | /* We assume nothing at this point */ | |
4903 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL; | |
4904 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_NON; | |
4905 | ||
4906 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
4907 | if (!mboxq) | |
4908 | return -ENOMEM; | |
cd1c8301 | 4909 | /* obtain link type and link number via READ_CONFIG */ |
ff78d8f9 JS |
4910 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL; |
4911 | lpfc_sli4_read_config(phba); | |
4912 | if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) | |
4913 | goto retrieve_ppname; | |
cd1c8301 JS |
4914 | |
4915 | /* obtain link type and link number via COMMON_GET_CNTL_ATTRIBUTES */ | |
4916 | reqlen = sizeof(struct lpfc_mbx_get_cntl_attributes); | |
4917 | alloclen = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, | |
4918 | LPFC_MBOX_OPCODE_GET_CNTL_ATTRIBUTES, reqlen, | |
4919 | LPFC_SLI4_MBX_NEMBED); | |
4920 | if (alloclen < reqlen) { | |
4921 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
4922 | "3084 Allocated DMA memory size (%d) is " | |
4923 | "less than the requested DMA memory size " | |
4924 | "(%d)\n", alloclen, reqlen); | |
4925 | rc = -ENOMEM; | |
4926 | goto out_free_mboxq; | |
4927 | } | |
4928 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
4929 | virtaddr = mboxq->sge_array->addr[0]; | |
4930 | mbx_cntl_attr = (struct lpfc_mbx_get_cntl_attributes *)virtaddr; | |
4931 | shdr = &mbx_cntl_attr->cfg_shdr; | |
4932 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
4933 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
4934 | if (shdr_status || shdr_add_status || rc) { | |
4935 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
4936 | "3085 Mailbox x%x (x%x/x%x) failed, " | |
4937 | "rc:x%x, status:x%x, add_status:x%x\n", | |
4938 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), | |
4939 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), | |
4940 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), | |
4941 | rc, shdr_status, shdr_add_status); | |
4942 | rc = -ENXIO; | |
4943 | goto out_free_mboxq; | |
4944 | } | |
4945 | cntl_attr = &mbx_cntl_attr->cntl_attr; | |
4946 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL; | |
4947 | phba->sli4_hba.lnk_info.lnk_tp = | |
4948 | bf_get(lpfc_cntl_attr_lnk_type, cntl_attr); | |
4949 | phba->sli4_hba.lnk_info.lnk_no = | |
4950 | bf_get(lpfc_cntl_attr_lnk_numb, cntl_attr); | |
4951 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
4952 | "3086 lnk_type:%d, lnk_numb:%d\n", | |
4953 | phba->sli4_hba.lnk_info.lnk_tp, | |
4954 | phba->sli4_hba.lnk_info.lnk_no); | |
4955 | ||
4956 | retrieve_ppname: | |
4957 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, | |
4958 | LPFC_MBOX_OPCODE_GET_PORT_NAME, | |
4959 | sizeof(struct lpfc_mbx_get_port_name) - | |
4960 | sizeof(struct lpfc_sli4_cfg_mhdr), | |
4961 | LPFC_SLI4_MBX_EMBED); | |
4962 | get_port_name = &mboxq->u.mqe.un.get_port_name; | |
4963 | shdr = (union lpfc_sli4_cfg_shdr *)&get_port_name->header.cfg_shdr; | |
4964 | bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_OPCODE_VERSION_1); | |
4965 | bf_set(lpfc_mbx_get_port_name_lnk_type, &get_port_name->u.request, | |
4966 | phba->sli4_hba.lnk_info.lnk_tp); | |
4967 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
4968 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
4969 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
4970 | if (shdr_status || shdr_add_status || rc) { | |
4971 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
4972 | "3087 Mailbox x%x (x%x/x%x) failed: " | |
4973 | "rc:x%x, status:x%x, add_status:x%x\n", | |
4974 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), | |
4975 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), | |
4976 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), | |
4977 | rc, shdr_status, shdr_add_status); | |
4978 | rc = -ENXIO; | |
4979 | goto out_free_mboxq; | |
4980 | } | |
4981 | switch (phba->sli4_hba.lnk_info.lnk_no) { | |
4982 | case LPFC_LINK_NUMBER_0: | |
4983 | cport_name = bf_get(lpfc_mbx_get_port_name_name0, | |
4984 | &get_port_name->u.response); | |
4985 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; | |
4986 | break; | |
4987 | case LPFC_LINK_NUMBER_1: | |
4988 | cport_name = bf_get(lpfc_mbx_get_port_name_name1, | |
4989 | &get_port_name->u.response); | |
4990 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; | |
4991 | break; | |
4992 | case LPFC_LINK_NUMBER_2: | |
4993 | cport_name = bf_get(lpfc_mbx_get_port_name_name2, | |
4994 | &get_port_name->u.response); | |
4995 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; | |
4996 | break; | |
4997 | case LPFC_LINK_NUMBER_3: | |
4998 | cport_name = bf_get(lpfc_mbx_get_port_name_name3, | |
4999 | &get_port_name->u.response); | |
5000 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; | |
5001 | break; | |
5002 | default: | |
5003 | break; | |
5004 | } | |
5005 | ||
5006 | if (phba->sli4_hba.pport_name_sta == LPFC_SLI4_PPNAME_GET) { | |
5007 | phba->Port[0] = cport_name; | |
5008 | phba->Port[1] = '\0'; | |
5009 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
5010 | "3091 SLI get port name: %s\n", phba->Port); | |
5011 | } | |
5012 | ||
5013 | out_free_mboxq: | |
5014 | if (rc != MBX_TIMEOUT) { | |
5015 | if (bf_get(lpfc_mqe_command, &mboxq->u.mqe) == MBX_SLI4_CONFIG) | |
5016 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
5017 | else | |
5018 | mempool_free(mboxq, phba->mbox_mem_pool); | |
5019 | } | |
5020 | return rc; | |
5021 | } | |
5022 | ||
e59058c4 | 5023 | /** |
da0436e9 JS |
5024 | * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues |
5025 | * @phba: pointer to lpfc hba data structure. | |
e59058c4 | 5026 | * |
da0436e9 JS |
5027 | * This routine is called to explicitly arm the SLI4 device's completion and |
5028 | * event queues | |
5029 | **/ | |
5030 | static void | |
5031 | lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba) | |
5032 | { | |
962bc51b | 5033 | int fcp_eqidx; |
da0436e9 JS |
5034 | |
5035 | lpfc_sli4_cq_release(phba->sli4_hba.mbx_cq, LPFC_QUEUE_REARM); | |
5036 | lpfc_sli4_cq_release(phba->sli4_hba.els_cq, LPFC_QUEUE_REARM); | |
0558056c | 5037 | fcp_eqidx = 0; |
2e90f4b5 | 5038 | if (phba->sli4_hba.fcp_cq) { |
67d12733 | 5039 | do { |
2e90f4b5 JS |
5040 | lpfc_sli4_cq_release(phba->sli4_hba.fcp_cq[fcp_eqidx], |
5041 | LPFC_QUEUE_REARM); | |
67d12733 | 5042 | } while (++fcp_eqidx < phba->cfg_fcp_io_channel); |
2e90f4b5 | 5043 | } |
1ba981fd | 5044 | |
f38fa0bb | 5045 | if (phba->cfg_fof) |
1ba981fd JS |
5046 | lpfc_sli4_cq_release(phba->sli4_hba.oas_cq, LPFC_QUEUE_REARM); |
5047 | ||
67d12733 JS |
5048 | if (phba->sli4_hba.hba_eq) { |
5049 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_io_channel; | |
2e90f4b5 | 5050 | fcp_eqidx++) |
67d12733 | 5051 | lpfc_sli4_eq_release(phba->sli4_hba.hba_eq[fcp_eqidx], |
2e90f4b5 JS |
5052 | LPFC_QUEUE_REARM); |
5053 | } | |
1ba981fd JS |
5054 | |
5055 | if (phba->cfg_fof) | |
5056 | lpfc_sli4_eq_release(phba->sli4_hba.fof_eq, LPFC_QUEUE_REARM); | |
da0436e9 JS |
5057 | } |
5058 | ||
6d368e53 JS |
5059 | /** |
5060 | * lpfc_sli4_get_avail_extnt_rsrc - Get available resource extent count. | |
5061 | * @phba: Pointer to HBA context object. | |
5062 | * @type: The resource extent type. | |
b76f2dc9 JS |
5063 | * @extnt_count: buffer to hold port available extent count. |
5064 | * @extnt_size: buffer to hold element count per extent. | |
6d368e53 | 5065 | * |
b76f2dc9 JS |
5066 | * This function calls the port and retrievs the number of available |
5067 | * extents and their size for a particular extent type. | |
5068 | * | |
5069 | * Returns: 0 if successful. Nonzero otherwise. | |
6d368e53 | 5070 | **/ |
b76f2dc9 | 5071 | int |
6d368e53 JS |
5072 | lpfc_sli4_get_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type, |
5073 | uint16_t *extnt_count, uint16_t *extnt_size) | |
5074 | { | |
5075 | int rc = 0; | |
5076 | uint32_t length; | |
5077 | uint32_t mbox_tmo; | |
5078 | struct lpfc_mbx_get_rsrc_extent_info *rsrc_info; | |
5079 | LPFC_MBOXQ_t *mbox; | |
5080 | ||
5081 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
5082 | if (!mbox) | |
5083 | return -ENOMEM; | |
5084 | ||
5085 | /* Find out how many extents are available for this resource type */ | |
5086 | length = (sizeof(struct lpfc_mbx_get_rsrc_extent_info) - | |
5087 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
5088 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
5089 | LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO, | |
5090 | length, LPFC_SLI4_MBX_EMBED); | |
5091 | ||
5092 | /* Send an extents count of 0 - the GET doesn't use it. */ | |
5093 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type, | |
5094 | LPFC_SLI4_MBX_EMBED); | |
5095 | if (unlikely(rc)) { | |
5096 | rc = -EIO; | |
5097 | goto err_exit; | |
5098 | } | |
5099 | ||
5100 | if (!phba->sli4_hba.intr_enable) | |
5101 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
5102 | else { | |
a183a15f | 5103 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
6d368e53 JS |
5104 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
5105 | } | |
5106 | if (unlikely(rc)) { | |
5107 | rc = -EIO; | |
5108 | goto err_exit; | |
5109 | } | |
5110 | ||
5111 | rsrc_info = &mbox->u.mqe.un.rsrc_extent_info; | |
5112 | if (bf_get(lpfc_mbox_hdr_status, | |
5113 | &rsrc_info->header.cfg_shdr.response)) { | |
5114 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, | |
5115 | "2930 Failed to get resource extents " | |
5116 | "Status 0x%x Add'l Status 0x%x\n", | |
5117 | bf_get(lpfc_mbox_hdr_status, | |
5118 | &rsrc_info->header.cfg_shdr.response), | |
5119 | bf_get(lpfc_mbox_hdr_add_status, | |
5120 | &rsrc_info->header.cfg_shdr.response)); | |
5121 | rc = -EIO; | |
5122 | goto err_exit; | |
5123 | } | |
5124 | ||
5125 | *extnt_count = bf_get(lpfc_mbx_get_rsrc_extent_info_cnt, | |
5126 | &rsrc_info->u.rsp); | |
5127 | *extnt_size = bf_get(lpfc_mbx_get_rsrc_extent_info_size, | |
5128 | &rsrc_info->u.rsp); | |
8a9d2e80 JS |
5129 | |
5130 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
5131 | "3162 Retrieved extents type-%d from port: count:%d, " | |
5132 | "size:%d\n", type, *extnt_count, *extnt_size); | |
5133 | ||
5134 | err_exit: | |
6d368e53 JS |
5135 | mempool_free(mbox, phba->mbox_mem_pool); |
5136 | return rc; | |
5137 | } | |
5138 | ||
5139 | /** | |
5140 | * lpfc_sli4_chk_avail_extnt_rsrc - Check for available SLI4 resource extents. | |
5141 | * @phba: Pointer to HBA context object. | |
5142 | * @type: The extent type to check. | |
5143 | * | |
5144 | * This function reads the current available extents from the port and checks | |
5145 | * if the extent count or extent size has changed since the last access. | |
5146 | * Callers use this routine post port reset to understand if there is a | |
5147 | * extent reprovisioning requirement. | |
5148 | * | |
5149 | * Returns: | |
5150 | * -Error: error indicates problem. | |
5151 | * 1: Extent count or size has changed. | |
5152 | * 0: No changes. | |
5153 | **/ | |
5154 | static int | |
5155 | lpfc_sli4_chk_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type) | |
5156 | { | |
5157 | uint16_t curr_ext_cnt, rsrc_ext_cnt; | |
5158 | uint16_t size_diff, rsrc_ext_size; | |
5159 | int rc = 0; | |
5160 | struct lpfc_rsrc_blks *rsrc_entry; | |
5161 | struct list_head *rsrc_blk_list = NULL; | |
5162 | ||
5163 | size_diff = 0; | |
5164 | curr_ext_cnt = 0; | |
5165 | rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type, | |
5166 | &rsrc_ext_cnt, | |
5167 | &rsrc_ext_size); | |
5168 | if (unlikely(rc)) | |
5169 | return -EIO; | |
5170 | ||
5171 | switch (type) { | |
5172 | case LPFC_RSC_TYPE_FCOE_RPI: | |
5173 | rsrc_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list; | |
5174 | break; | |
5175 | case LPFC_RSC_TYPE_FCOE_VPI: | |
5176 | rsrc_blk_list = &phba->lpfc_vpi_blk_list; | |
5177 | break; | |
5178 | case LPFC_RSC_TYPE_FCOE_XRI: | |
5179 | rsrc_blk_list = &phba->sli4_hba.lpfc_xri_blk_list; | |
5180 | break; | |
5181 | case LPFC_RSC_TYPE_FCOE_VFI: | |
5182 | rsrc_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list; | |
5183 | break; | |
5184 | default: | |
5185 | break; | |
5186 | } | |
5187 | ||
5188 | list_for_each_entry(rsrc_entry, rsrc_blk_list, list) { | |
5189 | curr_ext_cnt++; | |
5190 | if (rsrc_entry->rsrc_size != rsrc_ext_size) | |
5191 | size_diff++; | |
5192 | } | |
5193 | ||
5194 | if (curr_ext_cnt != rsrc_ext_cnt || size_diff != 0) | |
5195 | rc = 1; | |
5196 | ||
5197 | return rc; | |
5198 | } | |
5199 | ||
5200 | /** | |
5201 | * lpfc_sli4_cfg_post_extnts - | |
5202 | * @phba: Pointer to HBA context object. | |
5203 | * @extnt_cnt - number of available extents. | |
5204 | * @type - the extent type (rpi, xri, vfi, vpi). | |
5205 | * @emb - buffer to hold either MBX_EMBED or MBX_NEMBED operation. | |
5206 | * @mbox - pointer to the caller's allocated mailbox structure. | |
5207 | * | |
5208 | * This function executes the extents allocation request. It also | |
5209 | * takes care of the amount of memory needed to allocate or get the | |
5210 | * allocated extents. It is the caller's responsibility to evaluate | |
5211 | * the response. | |
5212 | * | |
5213 | * Returns: | |
5214 | * -Error: Error value describes the condition found. | |
5215 | * 0: if successful | |
5216 | **/ | |
5217 | static int | |
8a9d2e80 | 5218 | lpfc_sli4_cfg_post_extnts(struct lpfc_hba *phba, uint16_t extnt_cnt, |
6d368e53 JS |
5219 | uint16_t type, bool *emb, LPFC_MBOXQ_t *mbox) |
5220 | { | |
5221 | int rc = 0; | |
5222 | uint32_t req_len; | |
5223 | uint32_t emb_len; | |
5224 | uint32_t alloc_len, mbox_tmo; | |
5225 | ||
5226 | /* Calculate the total requested length of the dma memory */ | |
8a9d2e80 | 5227 | req_len = extnt_cnt * sizeof(uint16_t); |
6d368e53 JS |
5228 | |
5229 | /* | |
5230 | * Calculate the size of an embedded mailbox. The uint32_t | |
5231 | * accounts for extents-specific word. | |
5232 | */ | |
5233 | emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) - | |
5234 | sizeof(uint32_t); | |
5235 | ||
5236 | /* | |
5237 | * Presume the allocation and response will fit into an embedded | |
5238 | * mailbox. If not true, reconfigure to a non-embedded mailbox. | |
5239 | */ | |
5240 | *emb = LPFC_SLI4_MBX_EMBED; | |
5241 | if (req_len > emb_len) { | |
8a9d2e80 | 5242 | req_len = extnt_cnt * sizeof(uint16_t) + |
6d368e53 JS |
5243 | sizeof(union lpfc_sli4_cfg_shdr) + |
5244 | sizeof(uint32_t); | |
5245 | *emb = LPFC_SLI4_MBX_NEMBED; | |
5246 | } | |
5247 | ||
5248 | alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
5249 | LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT, | |
5250 | req_len, *emb); | |
5251 | if (alloc_len < req_len) { | |
5252 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
b76f2dc9 | 5253 | "2982 Allocated DMA memory size (x%x) is " |
6d368e53 JS |
5254 | "less than the requested DMA memory " |
5255 | "size (x%x)\n", alloc_len, req_len); | |
5256 | return -ENOMEM; | |
5257 | } | |
8a9d2e80 | 5258 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, extnt_cnt, type, *emb); |
6d368e53 JS |
5259 | if (unlikely(rc)) |
5260 | return -EIO; | |
5261 | ||
5262 | if (!phba->sli4_hba.intr_enable) | |
5263 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
5264 | else { | |
a183a15f | 5265 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
6d368e53 JS |
5266 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
5267 | } | |
5268 | ||
5269 | if (unlikely(rc)) | |
5270 | rc = -EIO; | |
5271 | return rc; | |
5272 | } | |
5273 | ||
5274 | /** | |
5275 | * lpfc_sli4_alloc_extent - Allocate an SLI4 resource extent. | |
5276 | * @phba: Pointer to HBA context object. | |
5277 | * @type: The resource extent type to allocate. | |
5278 | * | |
5279 | * This function allocates the number of elements for the specified | |
5280 | * resource type. | |
5281 | **/ | |
5282 | static int | |
5283 | lpfc_sli4_alloc_extent(struct lpfc_hba *phba, uint16_t type) | |
5284 | { | |
5285 | bool emb = false; | |
5286 | uint16_t rsrc_id_cnt, rsrc_cnt, rsrc_size; | |
5287 | uint16_t rsrc_id, rsrc_start, j, k; | |
5288 | uint16_t *ids; | |
5289 | int i, rc; | |
5290 | unsigned long longs; | |
5291 | unsigned long *bmask; | |
5292 | struct lpfc_rsrc_blks *rsrc_blks; | |
5293 | LPFC_MBOXQ_t *mbox; | |
5294 | uint32_t length; | |
5295 | struct lpfc_id_range *id_array = NULL; | |
5296 | void *virtaddr = NULL; | |
5297 | struct lpfc_mbx_nembed_rsrc_extent *n_rsrc; | |
5298 | struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext; | |
5299 | struct list_head *ext_blk_list; | |
5300 | ||
5301 | rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type, | |
5302 | &rsrc_cnt, | |
5303 | &rsrc_size); | |
5304 | if (unlikely(rc)) | |
5305 | return -EIO; | |
5306 | ||
5307 | if ((rsrc_cnt == 0) || (rsrc_size == 0)) { | |
5308 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, | |
5309 | "3009 No available Resource Extents " | |
5310 | "for resource type 0x%x: Count: 0x%x, " | |
5311 | "Size 0x%x\n", type, rsrc_cnt, | |
5312 | rsrc_size); | |
5313 | return -ENOMEM; | |
5314 | } | |
5315 | ||
8a9d2e80 JS |
5316 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_INIT | LOG_SLI, |
5317 | "2903 Post resource extents type-0x%x: " | |
5318 | "count:%d, size %d\n", type, rsrc_cnt, rsrc_size); | |
6d368e53 JS |
5319 | |
5320 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
5321 | if (!mbox) | |
5322 | return -ENOMEM; | |
5323 | ||
8a9d2e80 | 5324 | rc = lpfc_sli4_cfg_post_extnts(phba, rsrc_cnt, type, &emb, mbox); |
6d368e53 JS |
5325 | if (unlikely(rc)) { |
5326 | rc = -EIO; | |
5327 | goto err_exit; | |
5328 | } | |
5329 | ||
5330 | /* | |
5331 | * Figure out where the response is located. Then get local pointers | |
5332 | * to the response data. The port does not guarantee to respond to | |
5333 | * all extents counts request so update the local variable with the | |
5334 | * allocated count from the port. | |
5335 | */ | |
5336 | if (emb == LPFC_SLI4_MBX_EMBED) { | |
5337 | rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents; | |
5338 | id_array = &rsrc_ext->u.rsp.id[0]; | |
5339 | rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp); | |
5340 | } else { | |
5341 | virtaddr = mbox->sge_array->addr[0]; | |
5342 | n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr; | |
5343 | rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc); | |
5344 | id_array = &n_rsrc->id; | |
5345 | } | |
5346 | ||
5347 | longs = ((rsrc_cnt * rsrc_size) + BITS_PER_LONG - 1) / BITS_PER_LONG; | |
5348 | rsrc_id_cnt = rsrc_cnt * rsrc_size; | |
5349 | ||
5350 | /* | |
5351 | * Based on the resource size and count, correct the base and max | |
5352 | * resource values. | |
5353 | */ | |
5354 | length = sizeof(struct lpfc_rsrc_blks); | |
5355 | switch (type) { | |
5356 | case LPFC_RSC_TYPE_FCOE_RPI: | |
5357 | phba->sli4_hba.rpi_bmask = kzalloc(longs * | |
5358 | sizeof(unsigned long), | |
5359 | GFP_KERNEL); | |
5360 | if (unlikely(!phba->sli4_hba.rpi_bmask)) { | |
5361 | rc = -ENOMEM; | |
5362 | goto err_exit; | |
5363 | } | |
5364 | phba->sli4_hba.rpi_ids = kzalloc(rsrc_id_cnt * | |
5365 | sizeof(uint16_t), | |
5366 | GFP_KERNEL); | |
5367 | if (unlikely(!phba->sli4_hba.rpi_ids)) { | |
5368 | kfree(phba->sli4_hba.rpi_bmask); | |
5369 | rc = -ENOMEM; | |
5370 | goto err_exit; | |
5371 | } | |
5372 | ||
5373 | /* | |
5374 | * The next_rpi was initialized with the maximum available | |
5375 | * count but the port may allocate a smaller number. Catch | |
5376 | * that case and update the next_rpi. | |
5377 | */ | |
5378 | phba->sli4_hba.next_rpi = rsrc_id_cnt; | |
5379 | ||
5380 | /* Initialize local ptrs for common extent processing later. */ | |
5381 | bmask = phba->sli4_hba.rpi_bmask; | |
5382 | ids = phba->sli4_hba.rpi_ids; | |
5383 | ext_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list; | |
5384 | break; | |
5385 | case LPFC_RSC_TYPE_FCOE_VPI: | |
5386 | phba->vpi_bmask = kzalloc(longs * | |
5387 | sizeof(unsigned long), | |
5388 | GFP_KERNEL); | |
5389 | if (unlikely(!phba->vpi_bmask)) { | |
5390 | rc = -ENOMEM; | |
5391 | goto err_exit; | |
5392 | } | |
5393 | phba->vpi_ids = kzalloc(rsrc_id_cnt * | |
5394 | sizeof(uint16_t), | |
5395 | GFP_KERNEL); | |
5396 | if (unlikely(!phba->vpi_ids)) { | |
5397 | kfree(phba->vpi_bmask); | |
5398 | rc = -ENOMEM; | |
5399 | goto err_exit; | |
5400 | } | |
5401 | ||
5402 | /* Initialize local ptrs for common extent processing later. */ | |
5403 | bmask = phba->vpi_bmask; | |
5404 | ids = phba->vpi_ids; | |
5405 | ext_blk_list = &phba->lpfc_vpi_blk_list; | |
5406 | break; | |
5407 | case LPFC_RSC_TYPE_FCOE_XRI: | |
5408 | phba->sli4_hba.xri_bmask = kzalloc(longs * | |
5409 | sizeof(unsigned long), | |
5410 | GFP_KERNEL); | |
5411 | if (unlikely(!phba->sli4_hba.xri_bmask)) { | |
5412 | rc = -ENOMEM; | |
5413 | goto err_exit; | |
5414 | } | |
8a9d2e80 | 5415 | phba->sli4_hba.max_cfg_param.xri_used = 0; |
6d368e53 JS |
5416 | phba->sli4_hba.xri_ids = kzalloc(rsrc_id_cnt * |
5417 | sizeof(uint16_t), | |
5418 | GFP_KERNEL); | |
5419 | if (unlikely(!phba->sli4_hba.xri_ids)) { | |
5420 | kfree(phba->sli4_hba.xri_bmask); | |
5421 | rc = -ENOMEM; | |
5422 | goto err_exit; | |
5423 | } | |
5424 | ||
5425 | /* Initialize local ptrs for common extent processing later. */ | |
5426 | bmask = phba->sli4_hba.xri_bmask; | |
5427 | ids = phba->sli4_hba.xri_ids; | |
5428 | ext_blk_list = &phba->sli4_hba.lpfc_xri_blk_list; | |
5429 | break; | |
5430 | case LPFC_RSC_TYPE_FCOE_VFI: | |
5431 | phba->sli4_hba.vfi_bmask = kzalloc(longs * | |
5432 | sizeof(unsigned long), | |
5433 | GFP_KERNEL); | |
5434 | if (unlikely(!phba->sli4_hba.vfi_bmask)) { | |
5435 | rc = -ENOMEM; | |
5436 | goto err_exit; | |
5437 | } | |
5438 | phba->sli4_hba.vfi_ids = kzalloc(rsrc_id_cnt * | |
5439 | sizeof(uint16_t), | |
5440 | GFP_KERNEL); | |
5441 | if (unlikely(!phba->sli4_hba.vfi_ids)) { | |
5442 | kfree(phba->sli4_hba.vfi_bmask); | |
5443 | rc = -ENOMEM; | |
5444 | goto err_exit; | |
5445 | } | |
5446 | ||
5447 | /* Initialize local ptrs for common extent processing later. */ | |
5448 | bmask = phba->sli4_hba.vfi_bmask; | |
5449 | ids = phba->sli4_hba.vfi_ids; | |
5450 | ext_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list; | |
5451 | break; | |
5452 | default: | |
5453 | /* Unsupported Opcode. Fail call. */ | |
5454 | id_array = NULL; | |
5455 | bmask = NULL; | |
5456 | ids = NULL; | |
5457 | ext_blk_list = NULL; | |
5458 | goto err_exit; | |
5459 | } | |
5460 | ||
5461 | /* | |
5462 | * Complete initializing the extent configuration with the | |
5463 | * allocated ids assigned to this function. The bitmask serves | |
5464 | * as an index into the array and manages the available ids. The | |
5465 | * array just stores the ids communicated to the port via the wqes. | |
5466 | */ | |
5467 | for (i = 0, j = 0, k = 0; i < rsrc_cnt; i++) { | |
5468 | if ((i % 2) == 0) | |
5469 | rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_0, | |
5470 | &id_array[k]); | |
5471 | else | |
5472 | rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_1, | |
5473 | &id_array[k]); | |
5474 | ||
5475 | rsrc_blks = kzalloc(length, GFP_KERNEL); | |
5476 | if (unlikely(!rsrc_blks)) { | |
5477 | rc = -ENOMEM; | |
5478 | kfree(bmask); | |
5479 | kfree(ids); | |
5480 | goto err_exit; | |
5481 | } | |
5482 | rsrc_blks->rsrc_start = rsrc_id; | |
5483 | rsrc_blks->rsrc_size = rsrc_size; | |
5484 | list_add_tail(&rsrc_blks->list, ext_blk_list); | |
5485 | rsrc_start = rsrc_id; | |
5486 | if ((type == LPFC_RSC_TYPE_FCOE_XRI) && (j == 0)) | |
5487 | phba->sli4_hba.scsi_xri_start = rsrc_start + | |
5488 | lpfc_sli4_get_els_iocb_cnt(phba); | |
5489 | ||
5490 | while (rsrc_id < (rsrc_start + rsrc_size)) { | |
5491 | ids[j] = rsrc_id; | |
5492 | rsrc_id++; | |
5493 | j++; | |
5494 | } | |
5495 | /* Entire word processed. Get next word.*/ | |
5496 | if ((i % 2) == 1) | |
5497 | k++; | |
5498 | } | |
5499 | err_exit: | |
5500 | lpfc_sli4_mbox_cmd_free(phba, mbox); | |
5501 | return rc; | |
5502 | } | |
5503 | ||
5504 | /** | |
5505 | * lpfc_sli4_dealloc_extent - Deallocate an SLI4 resource extent. | |
5506 | * @phba: Pointer to HBA context object. | |
5507 | * @type: the extent's type. | |
5508 | * | |
5509 | * This function deallocates all extents of a particular resource type. | |
5510 | * SLI4 does not allow for deallocating a particular extent range. It | |
5511 | * is the caller's responsibility to release all kernel memory resources. | |
5512 | **/ | |
5513 | static int | |
5514 | lpfc_sli4_dealloc_extent(struct lpfc_hba *phba, uint16_t type) | |
5515 | { | |
5516 | int rc; | |
5517 | uint32_t length, mbox_tmo = 0; | |
5518 | LPFC_MBOXQ_t *mbox; | |
5519 | struct lpfc_mbx_dealloc_rsrc_extents *dealloc_rsrc; | |
5520 | struct lpfc_rsrc_blks *rsrc_blk, *rsrc_blk_next; | |
5521 | ||
5522 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
5523 | if (!mbox) | |
5524 | return -ENOMEM; | |
5525 | ||
5526 | /* | |
5527 | * This function sends an embedded mailbox because it only sends the | |
5528 | * the resource type. All extents of this type are released by the | |
5529 | * port. | |
5530 | */ | |
5531 | length = (sizeof(struct lpfc_mbx_dealloc_rsrc_extents) - | |
5532 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
5533 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
5534 | LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT, | |
5535 | length, LPFC_SLI4_MBX_EMBED); | |
5536 | ||
5537 | /* Send an extents count of 0 - the dealloc doesn't use it. */ | |
5538 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type, | |
5539 | LPFC_SLI4_MBX_EMBED); | |
5540 | if (unlikely(rc)) { | |
5541 | rc = -EIO; | |
5542 | goto out_free_mbox; | |
5543 | } | |
5544 | if (!phba->sli4_hba.intr_enable) | |
5545 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
5546 | else { | |
a183a15f | 5547 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
6d368e53 JS |
5548 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
5549 | } | |
5550 | if (unlikely(rc)) { | |
5551 | rc = -EIO; | |
5552 | goto out_free_mbox; | |
5553 | } | |
5554 | ||
5555 | dealloc_rsrc = &mbox->u.mqe.un.dealloc_rsrc_extents; | |
5556 | if (bf_get(lpfc_mbox_hdr_status, | |
5557 | &dealloc_rsrc->header.cfg_shdr.response)) { | |
5558 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, | |
5559 | "2919 Failed to release resource extents " | |
5560 | "for type %d - Status 0x%x Add'l Status 0x%x. " | |
5561 | "Resource memory not released.\n", | |
5562 | type, | |
5563 | bf_get(lpfc_mbox_hdr_status, | |
5564 | &dealloc_rsrc->header.cfg_shdr.response), | |
5565 | bf_get(lpfc_mbox_hdr_add_status, | |
5566 | &dealloc_rsrc->header.cfg_shdr.response)); | |
5567 | rc = -EIO; | |
5568 | goto out_free_mbox; | |
5569 | } | |
5570 | ||
5571 | /* Release kernel memory resources for the specific type. */ | |
5572 | switch (type) { | |
5573 | case LPFC_RSC_TYPE_FCOE_VPI: | |
5574 | kfree(phba->vpi_bmask); | |
5575 | kfree(phba->vpi_ids); | |
5576 | bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); | |
5577 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, | |
5578 | &phba->lpfc_vpi_blk_list, list) { | |
5579 | list_del_init(&rsrc_blk->list); | |
5580 | kfree(rsrc_blk); | |
5581 | } | |
16a3a208 | 5582 | phba->sli4_hba.max_cfg_param.vpi_used = 0; |
6d368e53 JS |
5583 | break; |
5584 | case LPFC_RSC_TYPE_FCOE_XRI: | |
5585 | kfree(phba->sli4_hba.xri_bmask); | |
5586 | kfree(phba->sli4_hba.xri_ids); | |
6d368e53 JS |
5587 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
5588 | &phba->sli4_hba.lpfc_xri_blk_list, list) { | |
5589 | list_del_init(&rsrc_blk->list); | |
5590 | kfree(rsrc_blk); | |
5591 | } | |
5592 | break; | |
5593 | case LPFC_RSC_TYPE_FCOE_VFI: | |
5594 | kfree(phba->sli4_hba.vfi_bmask); | |
5595 | kfree(phba->sli4_hba.vfi_ids); | |
5596 | bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); | |
5597 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, | |
5598 | &phba->sli4_hba.lpfc_vfi_blk_list, list) { | |
5599 | list_del_init(&rsrc_blk->list); | |
5600 | kfree(rsrc_blk); | |
5601 | } | |
5602 | break; | |
5603 | case LPFC_RSC_TYPE_FCOE_RPI: | |
5604 | /* RPI bitmask and physical id array are cleaned up earlier. */ | |
5605 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, | |
5606 | &phba->sli4_hba.lpfc_rpi_blk_list, list) { | |
5607 | list_del_init(&rsrc_blk->list); | |
5608 | kfree(rsrc_blk); | |
5609 | } | |
5610 | break; | |
5611 | default: | |
5612 | break; | |
5613 | } | |
5614 | ||
5615 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); | |
5616 | ||
5617 | out_free_mbox: | |
5618 | mempool_free(mbox, phba->mbox_mem_pool); | |
5619 | return rc; | |
5620 | } | |
5621 | ||
5622 | /** | |
5623 | * lpfc_sli4_alloc_resource_identifiers - Allocate all SLI4 resource extents. | |
5624 | * @phba: Pointer to HBA context object. | |
5625 | * | |
5626 | * This function allocates all SLI4 resource identifiers. | |
5627 | **/ | |
5628 | int | |
5629 | lpfc_sli4_alloc_resource_identifiers(struct lpfc_hba *phba) | |
5630 | { | |
5631 | int i, rc, error = 0; | |
5632 | uint16_t count, base; | |
5633 | unsigned long longs; | |
5634 | ||
ff78d8f9 JS |
5635 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
5636 | phba->sli4_hba.next_rpi = phba->sli4_hba.max_cfg_param.max_rpi; | |
6d368e53 JS |
5637 | if (phba->sli4_hba.extents_in_use) { |
5638 | /* | |
5639 | * The port supports resource extents. The XRI, VPI, VFI, RPI | |
5640 | * resource extent count must be read and allocated before | |
5641 | * provisioning the resource id arrays. | |
5642 | */ | |
5643 | if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) == | |
5644 | LPFC_IDX_RSRC_RDY) { | |
5645 | /* | |
5646 | * Extent-based resources are set - the driver could | |
5647 | * be in a port reset. Figure out if any corrective | |
5648 | * actions need to be taken. | |
5649 | */ | |
5650 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, | |
5651 | LPFC_RSC_TYPE_FCOE_VFI); | |
5652 | if (rc != 0) | |
5653 | error++; | |
5654 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, | |
5655 | LPFC_RSC_TYPE_FCOE_VPI); | |
5656 | if (rc != 0) | |
5657 | error++; | |
5658 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, | |
5659 | LPFC_RSC_TYPE_FCOE_XRI); | |
5660 | if (rc != 0) | |
5661 | error++; | |
5662 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, | |
5663 | LPFC_RSC_TYPE_FCOE_RPI); | |
5664 | if (rc != 0) | |
5665 | error++; | |
5666 | ||
5667 | /* | |
5668 | * It's possible that the number of resources | |
5669 | * provided to this port instance changed between | |
5670 | * resets. Detect this condition and reallocate | |
5671 | * resources. Otherwise, there is no action. | |
5672 | */ | |
5673 | if (error) { | |
5674 | lpfc_printf_log(phba, KERN_INFO, | |
5675 | LOG_MBOX | LOG_INIT, | |
5676 | "2931 Detected extent resource " | |
5677 | "change. Reallocating all " | |
5678 | "extents.\n"); | |
5679 | rc = lpfc_sli4_dealloc_extent(phba, | |
5680 | LPFC_RSC_TYPE_FCOE_VFI); | |
5681 | rc = lpfc_sli4_dealloc_extent(phba, | |
5682 | LPFC_RSC_TYPE_FCOE_VPI); | |
5683 | rc = lpfc_sli4_dealloc_extent(phba, | |
5684 | LPFC_RSC_TYPE_FCOE_XRI); | |
5685 | rc = lpfc_sli4_dealloc_extent(phba, | |
5686 | LPFC_RSC_TYPE_FCOE_RPI); | |
5687 | } else | |
5688 | return 0; | |
5689 | } | |
5690 | ||
5691 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI); | |
5692 | if (unlikely(rc)) | |
5693 | goto err_exit; | |
5694 | ||
5695 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI); | |
5696 | if (unlikely(rc)) | |
5697 | goto err_exit; | |
5698 | ||
5699 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI); | |
5700 | if (unlikely(rc)) | |
5701 | goto err_exit; | |
5702 | ||
5703 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI); | |
5704 | if (unlikely(rc)) | |
5705 | goto err_exit; | |
5706 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, | |
5707 | LPFC_IDX_RSRC_RDY); | |
5708 | return rc; | |
5709 | } else { | |
5710 | /* | |
5711 | * The port does not support resource extents. The XRI, VPI, | |
5712 | * VFI, RPI resource ids were determined from READ_CONFIG. | |
5713 | * Just allocate the bitmasks and provision the resource id | |
5714 | * arrays. If a port reset is active, the resources don't | |
5715 | * need any action - just exit. | |
5716 | */ | |
5717 | if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) == | |
ff78d8f9 JS |
5718 | LPFC_IDX_RSRC_RDY) { |
5719 | lpfc_sli4_dealloc_resource_identifiers(phba); | |
5720 | lpfc_sli4_remove_rpis(phba); | |
5721 | } | |
6d368e53 JS |
5722 | /* RPIs. */ |
5723 | count = phba->sli4_hba.max_cfg_param.max_rpi; | |
0a630c27 JS |
5724 | if (count <= 0) { |
5725 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
5726 | "3279 Invalid provisioning of " | |
5727 | "rpi:%d\n", count); | |
5728 | rc = -EINVAL; | |
5729 | goto err_exit; | |
5730 | } | |
6d368e53 JS |
5731 | base = phba->sli4_hba.max_cfg_param.rpi_base; |
5732 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; | |
5733 | phba->sli4_hba.rpi_bmask = kzalloc(longs * | |
5734 | sizeof(unsigned long), | |
5735 | GFP_KERNEL); | |
5736 | if (unlikely(!phba->sli4_hba.rpi_bmask)) { | |
5737 | rc = -ENOMEM; | |
5738 | goto err_exit; | |
5739 | } | |
5740 | phba->sli4_hba.rpi_ids = kzalloc(count * | |
5741 | sizeof(uint16_t), | |
5742 | GFP_KERNEL); | |
5743 | if (unlikely(!phba->sli4_hba.rpi_ids)) { | |
5744 | rc = -ENOMEM; | |
5745 | goto free_rpi_bmask; | |
5746 | } | |
5747 | ||
5748 | for (i = 0; i < count; i++) | |
5749 | phba->sli4_hba.rpi_ids[i] = base + i; | |
5750 | ||
5751 | /* VPIs. */ | |
5752 | count = phba->sli4_hba.max_cfg_param.max_vpi; | |
0a630c27 JS |
5753 | if (count <= 0) { |
5754 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
5755 | "3280 Invalid provisioning of " | |
5756 | "vpi:%d\n", count); | |
5757 | rc = -EINVAL; | |
5758 | goto free_rpi_ids; | |
5759 | } | |
6d368e53 JS |
5760 | base = phba->sli4_hba.max_cfg_param.vpi_base; |
5761 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; | |
5762 | phba->vpi_bmask = kzalloc(longs * | |
5763 | sizeof(unsigned long), | |
5764 | GFP_KERNEL); | |
5765 | if (unlikely(!phba->vpi_bmask)) { | |
5766 | rc = -ENOMEM; | |
5767 | goto free_rpi_ids; | |
5768 | } | |
5769 | phba->vpi_ids = kzalloc(count * | |
5770 | sizeof(uint16_t), | |
5771 | GFP_KERNEL); | |
5772 | if (unlikely(!phba->vpi_ids)) { | |
5773 | rc = -ENOMEM; | |
5774 | goto free_vpi_bmask; | |
5775 | } | |
5776 | ||
5777 | for (i = 0; i < count; i++) | |
5778 | phba->vpi_ids[i] = base + i; | |
5779 | ||
5780 | /* XRIs. */ | |
5781 | count = phba->sli4_hba.max_cfg_param.max_xri; | |
0a630c27 JS |
5782 | if (count <= 0) { |
5783 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
5784 | "3281 Invalid provisioning of " | |
5785 | "xri:%d\n", count); | |
5786 | rc = -EINVAL; | |
5787 | goto free_vpi_ids; | |
5788 | } | |
6d368e53 JS |
5789 | base = phba->sli4_hba.max_cfg_param.xri_base; |
5790 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; | |
5791 | phba->sli4_hba.xri_bmask = kzalloc(longs * | |
5792 | sizeof(unsigned long), | |
5793 | GFP_KERNEL); | |
5794 | if (unlikely(!phba->sli4_hba.xri_bmask)) { | |
5795 | rc = -ENOMEM; | |
5796 | goto free_vpi_ids; | |
5797 | } | |
41899be7 | 5798 | phba->sli4_hba.max_cfg_param.xri_used = 0; |
6d368e53 JS |
5799 | phba->sli4_hba.xri_ids = kzalloc(count * |
5800 | sizeof(uint16_t), | |
5801 | GFP_KERNEL); | |
5802 | if (unlikely(!phba->sli4_hba.xri_ids)) { | |
5803 | rc = -ENOMEM; | |
5804 | goto free_xri_bmask; | |
5805 | } | |
5806 | ||
5807 | for (i = 0; i < count; i++) | |
5808 | phba->sli4_hba.xri_ids[i] = base + i; | |
5809 | ||
5810 | /* VFIs. */ | |
5811 | count = phba->sli4_hba.max_cfg_param.max_vfi; | |
0a630c27 JS |
5812 | if (count <= 0) { |
5813 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
5814 | "3282 Invalid provisioning of " | |
5815 | "vfi:%d\n", count); | |
5816 | rc = -EINVAL; | |
5817 | goto free_xri_ids; | |
5818 | } | |
6d368e53 JS |
5819 | base = phba->sli4_hba.max_cfg_param.vfi_base; |
5820 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; | |
5821 | phba->sli4_hba.vfi_bmask = kzalloc(longs * | |
5822 | sizeof(unsigned long), | |
5823 | GFP_KERNEL); | |
5824 | if (unlikely(!phba->sli4_hba.vfi_bmask)) { | |
5825 | rc = -ENOMEM; | |
5826 | goto free_xri_ids; | |
5827 | } | |
5828 | phba->sli4_hba.vfi_ids = kzalloc(count * | |
5829 | sizeof(uint16_t), | |
5830 | GFP_KERNEL); | |
5831 | if (unlikely(!phba->sli4_hba.vfi_ids)) { | |
5832 | rc = -ENOMEM; | |
5833 | goto free_vfi_bmask; | |
5834 | } | |
5835 | ||
5836 | for (i = 0; i < count; i++) | |
5837 | phba->sli4_hba.vfi_ids[i] = base + i; | |
5838 | ||
5839 | /* | |
5840 | * Mark all resources ready. An HBA reset doesn't need | |
5841 | * to reset the initialization. | |
5842 | */ | |
5843 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, | |
5844 | LPFC_IDX_RSRC_RDY); | |
5845 | return 0; | |
5846 | } | |
5847 | ||
5848 | free_vfi_bmask: | |
5849 | kfree(phba->sli4_hba.vfi_bmask); | |
5850 | free_xri_ids: | |
5851 | kfree(phba->sli4_hba.xri_ids); | |
5852 | free_xri_bmask: | |
5853 | kfree(phba->sli4_hba.xri_bmask); | |
5854 | free_vpi_ids: | |
5855 | kfree(phba->vpi_ids); | |
5856 | free_vpi_bmask: | |
5857 | kfree(phba->vpi_bmask); | |
5858 | free_rpi_ids: | |
5859 | kfree(phba->sli4_hba.rpi_ids); | |
5860 | free_rpi_bmask: | |
5861 | kfree(phba->sli4_hba.rpi_bmask); | |
5862 | err_exit: | |
5863 | return rc; | |
5864 | } | |
5865 | ||
5866 | /** | |
5867 | * lpfc_sli4_dealloc_resource_identifiers - Deallocate all SLI4 resource extents. | |
5868 | * @phba: Pointer to HBA context object. | |
5869 | * | |
5870 | * This function allocates the number of elements for the specified | |
5871 | * resource type. | |
5872 | **/ | |
5873 | int | |
5874 | lpfc_sli4_dealloc_resource_identifiers(struct lpfc_hba *phba) | |
5875 | { | |
5876 | if (phba->sli4_hba.extents_in_use) { | |
5877 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI); | |
5878 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI); | |
5879 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI); | |
5880 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI); | |
5881 | } else { | |
5882 | kfree(phba->vpi_bmask); | |
16a3a208 | 5883 | phba->sli4_hba.max_cfg_param.vpi_used = 0; |
6d368e53 JS |
5884 | kfree(phba->vpi_ids); |
5885 | bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); | |
5886 | kfree(phba->sli4_hba.xri_bmask); | |
5887 | kfree(phba->sli4_hba.xri_ids); | |
6d368e53 JS |
5888 | kfree(phba->sli4_hba.vfi_bmask); |
5889 | kfree(phba->sli4_hba.vfi_ids); | |
5890 | bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); | |
5891 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); | |
5892 | } | |
5893 | ||
5894 | return 0; | |
5895 | } | |
5896 | ||
b76f2dc9 JS |
5897 | /** |
5898 | * lpfc_sli4_get_allocated_extnts - Get the port's allocated extents. | |
5899 | * @phba: Pointer to HBA context object. | |
5900 | * @type: The resource extent type. | |
5901 | * @extnt_count: buffer to hold port extent count response | |
5902 | * @extnt_size: buffer to hold port extent size response. | |
5903 | * | |
5904 | * This function calls the port to read the host allocated extents | |
5905 | * for a particular type. | |
5906 | **/ | |
5907 | int | |
5908 | lpfc_sli4_get_allocated_extnts(struct lpfc_hba *phba, uint16_t type, | |
5909 | uint16_t *extnt_cnt, uint16_t *extnt_size) | |
5910 | { | |
5911 | bool emb; | |
5912 | int rc = 0; | |
5913 | uint16_t curr_blks = 0; | |
5914 | uint32_t req_len, emb_len; | |
5915 | uint32_t alloc_len, mbox_tmo; | |
5916 | struct list_head *blk_list_head; | |
5917 | struct lpfc_rsrc_blks *rsrc_blk; | |
5918 | LPFC_MBOXQ_t *mbox; | |
5919 | void *virtaddr = NULL; | |
5920 | struct lpfc_mbx_nembed_rsrc_extent *n_rsrc; | |
5921 | struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext; | |
5922 | union lpfc_sli4_cfg_shdr *shdr; | |
5923 | ||
5924 | switch (type) { | |
5925 | case LPFC_RSC_TYPE_FCOE_VPI: | |
5926 | blk_list_head = &phba->lpfc_vpi_blk_list; | |
5927 | break; | |
5928 | case LPFC_RSC_TYPE_FCOE_XRI: | |
5929 | blk_list_head = &phba->sli4_hba.lpfc_xri_blk_list; | |
5930 | break; | |
5931 | case LPFC_RSC_TYPE_FCOE_VFI: | |
5932 | blk_list_head = &phba->sli4_hba.lpfc_vfi_blk_list; | |
5933 | break; | |
5934 | case LPFC_RSC_TYPE_FCOE_RPI: | |
5935 | blk_list_head = &phba->sli4_hba.lpfc_rpi_blk_list; | |
5936 | break; | |
5937 | default: | |
5938 | return -EIO; | |
5939 | } | |
5940 | ||
5941 | /* Count the number of extents currently allocatd for this type. */ | |
5942 | list_for_each_entry(rsrc_blk, blk_list_head, list) { | |
5943 | if (curr_blks == 0) { | |
5944 | /* | |
5945 | * The GET_ALLOCATED mailbox does not return the size, | |
5946 | * just the count. The size should be just the size | |
5947 | * stored in the current allocated block and all sizes | |
5948 | * for an extent type are the same so set the return | |
5949 | * value now. | |
5950 | */ | |
5951 | *extnt_size = rsrc_blk->rsrc_size; | |
5952 | } | |
5953 | curr_blks++; | |
5954 | } | |
5955 | ||
5956 | /* Calculate the total requested length of the dma memory. */ | |
5957 | req_len = curr_blks * sizeof(uint16_t); | |
5958 | ||
5959 | /* | |
5960 | * Calculate the size of an embedded mailbox. The uint32_t | |
5961 | * accounts for extents-specific word. | |
5962 | */ | |
5963 | emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) - | |
5964 | sizeof(uint32_t); | |
5965 | ||
5966 | /* | |
5967 | * Presume the allocation and response will fit into an embedded | |
5968 | * mailbox. If not true, reconfigure to a non-embedded mailbox. | |
5969 | */ | |
5970 | emb = LPFC_SLI4_MBX_EMBED; | |
5971 | req_len = emb_len; | |
5972 | if (req_len > emb_len) { | |
5973 | req_len = curr_blks * sizeof(uint16_t) + | |
5974 | sizeof(union lpfc_sli4_cfg_shdr) + | |
5975 | sizeof(uint32_t); | |
5976 | emb = LPFC_SLI4_MBX_NEMBED; | |
5977 | } | |
5978 | ||
5979 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
5980 | if (!mbox) | |
5981 | return -ENOMEM; | |
5982 | memset(mbox, 0, sizeof(LPFC_MBOXQ_t)); | |
5983 | ||
5984 | alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
5985 | LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT, | |
5986 | req_len, emb); | |
5987 | if (alloc_len < req_len) { | |
5988 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
5989 | "2983 Allocated DMA memory size (x%x) is " | |
5990 | "less than the requested DMA memory " | |
5991 | "size (x%x)\n", alloc_len, req_len); | |
5992 | rc = -ENOMEM; | |
5993 | goto err_exit; | |
5994 | } | |
5995 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, curr_blks, type, emb); | |
5996 | if (unlikely(rc)) { | |
5997 | rc = -EIO; | |
5998 | goto err_exit; | |
5999 | } | |
6000 | ||
6001 | if (!phba->sli4_hba.intr_enable) | |
6002 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
6003 | else { | |
a183a15f | 6004 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
b76f2dc9 JS |
6005 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
6006 | } | |
6007 | ||
6008 | if (unlikely(rc)) { | |
6009 | rc = -EIO; | |
6010 | goto err_exit; | |
6011 | } | |
6012 | ||
6013 | /* | |
6014 | * Figure out where the response is located. Then get local pointers | |
6015 | * to the response data. The port does not guarantee to respond to | |
6016 | * all extents counts request so update the local variable with the | |
6017 | * allocated count from the port. | |
6018 | */ | |
6019 | if (emb == LPFC_SLI4_MBX_EMBED) { | |
6020 | rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents; | |
6021 | shdr = &rsrc_ext->header.cfg_shdr; | |
6022 | *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp); | |
6023 | } else { | |
6024 | virtaddr = mbox->sge_array->addr[0]; | |
6025 | n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr; | |
6026 | shdr = &n_rsrc->cfg_shdr; | |
6027 | *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc); | |
6028 | } | |
6029 | ||
6030 | if (bf_get(lpfc_mbox_hdr_status, &shdr->response)) { | |
6031 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, | |
6032 | "2984 Failed to read allocated resources " | |
6033 | "for type %d - Status 0x%x Add'l Status 0x%x.\n", | |
6034 | type, | |
6035 | bf_get(lpfc_mbox_hdr_status, &shdr->response), | |
6036 | bf_get(lpfc_mbox_hdr_add_status, &shdr->response)); | |
6037 | rc = -EIO; | |
6038 | goto err_exit; | |
6039 | } | |
6040 | err_exit: | |
6041 | lpfc_sli4_mbox_cmd_free(phba, mbox); | |
6042 | return rc; | |
6043 | } | |
6044 | ||
8a9d2e80 JS |
6045 | /** |
6046 | * lpfc_sli4_repost_els_sgl_list - Repsot the els buffers sgl pages as block | |
6047 | * @phba: pointer to lpfc hba data structure. | |
6048 | * | |
6049 | * This routine walks the list of els buffers that have been allocated and | |
6050 | * repost them to the port by using SGL block post. This is needed after a | |
6051 | * pci_function_reset/warm_start or start. It attempts to construct blocks | |
6052 | * of els buffer sgls which contains contiguous xris and uses the non-embedded | |
6053 | * SGL block post mailbox commands to post them to the port. For single els | |
6054 | * buffer sgl with non-contiguous xri, if any, it shall use embedded SGL post | |
6055 | * mailbox command for posting. | |
6056 | * | |
6057 | * Returns: 0 = success, non-zero failure. | |
6058 | **/ | |
6059 | static int | |
6060 | lpfc_sli4_repost_els_sgl_list(struct lpfc_hba *phba) | |
6061 | { | |
6062 | struct lpfc_sglq *sglq_entry = NULL; | |
6063 | struct lpfc_sglq *sglq_entry_next = NULL; | |
6064 | struct lpfc_sglq *sglq_entry_first = NULL; | |
711ea882 | 6065 | int status, total_cnt, post_cnt = 0, num_posted = 0, block_cnt = 0; |
8a9d2e80 | 6066 | int last_xritag = NO_XRI; |
dafe8cea | 6067 | struct lpfc_sli_ring *pring; |
8a9d2e80 JS |
6068 | LIST_HEAD(prep_sgl_list); |
6069 | LIST_HEAD(blck_sgl_list); | |
6070 | LIST_HEAD(allc_sgl_list); | |
6071 | LIST_HEAD(post_sgl_list); | |
6072 | LIST_HEAD(free_sgl_list); | |
6073 | ||
dafe8cea | 6074 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
38c20673 | 6075 | spin_lock_irq(&phba->hbalock); |
dafe8cea | 6076 | spin_lock(&pring->ring_lock); |
8a9d2e80 | 6077 | list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &allc_sgl_list); |
dafe8cea | 6078 | spin_unlock(&pring->ring_lock); |
38c20673 | 6079 | spin_unlock_irq(&phba->hbalock); |
8a9d2e80 | 6080 | |
711ea882 | 6081 | total_cnt = phba->sli4_hba.els_xri_cnt; |
8a9d2e80 JS |
6082 | list_for_each_entry_safe(sglq_entry, sglq_entry_next, |
6083 | &allc_sgl_list, list) { | |
6084 | list_del_init(&sglq_entry->list); | |
6085 | block_cnt++; | |
6086 | if ((last_xritag != NO_XRI) && | |
6087 | (sglq_entry->sli4_xritag != last_xritag + 1)) { | |
6088 | /* a hole in xri block, form a sgl posting block */ | |
6089 | list_splice_init(&prep_sgl_list, &blck_sgl_list); | |
6090 | post_cnt = block_cnt - 1; | |
6091 | /* prepare list for next posting block */ | |
6092 | list_add_tail(&sglq_entry->list, &prep_sgl_list); | |
6093 | block_cnt = 1; | |
6094 | } else { | |
6095 | /* prepare list for next posting block */ | |
6096 | list_add_tail(&sglq_entry->list, &prep_sgl_list); | |
6097 | /* enough sgls for non-embed sgl mbox command */ | |
6098 | if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) { | |
6099 | list_splice_init(&prep_sgl_list, | |
6100 | &blck_sgl_list); | |
6101 | post_cnt = block_cnt; | |
6102 | block_cnt = 0; | |
6103 | } | |
6104 | } | |
6105 | num_posted++; | |
6106 | ||
6107 | /* keep track of last sgl's xritag */ | |
6108 | last_xritag = sglq_entry->sli4_xritag; | |
6109 | ||
6110 | /* end of repost sgl list condition for els buffers */ | |
6111 | if (num_posted == phba->sli4_hba.els_xri_cnt) { | |
6112 | if (post_cnt == 0) { | |
6113 | list_splice_init(&prep_sgl_list, | |
6114 | &blck_sgl_list); | |
6115 | post_cnt = block_cnt; | |
6116 | } else if (block_cnt == 1) { | |
6117 | status = lpfc_sli4_post_sgl(phba, | |
6118 | sglq_entry->phys, 0, | |
6119 | sglq_entry->sli4_xritag); | |
6120 | if (!status) { | |
6121 | /* successful, put sgl to posted list */ | |
6122 | list_add_tail(&sglq_entry->list, | |
6123 | &post_sgl_list); | |
6124 | } else { | |
6125 | /* Failure, put sgl to free list */ | |
6126 | lpfc_printf_log(phba, KERN_WARNING, | |
6127 | LOG_SLI, | |
6128 | "3159 Failed to post els " | |
6129 | "sgl, xritag:x%x\n", | |
6130 | sglq_entry->sli4_xritag); | |
6131 | list_add_tail(&sglq_entry->list, | |
6132 | &free_sgl_list); | |
711ea882 | 6133 | total_cnt--; |
8a9d2e80 JS |
6134 | } |
6135 | } | |
6136 | } | |
6137 | ||
6138 | /* continue until a nembed page worth of sgls */ | |
6139 | if (post_cnt == 0) | |
6140 | continue; | |
6141 | ||
6142 | /* post the els buffer list sgls as a block */ | |
6143 | status = lpfc_sli4_post_els_sgl_list(phba, &blck_sgl_list, | |
6144 | post_cnt); | |
6145 | ||
6146 | if (!status) { | |
6147 | /* success, put sgl list to posted sgl list */ | |
6148 | list_splice_init(&blck_sgl_list, &post_sgl_list); | |
6149 | } else { | |
6150 | /* Failure, put sgl list to free sgl list */ | |
6151 | sglq_entry_first = list_first_entry(&blck_sgl_list, | |
6152 | struct lpfc_sglq, | |
6153 | list); | |
6154 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
6155 | "3160 Failed to post els sgl-list, " | |
6156 | "xritag:x%x-x%x\n", | |
6157 | sglq_entry_first->sli4_xritag, | |
6158 | (sglq_entry_first->sli4_xritag + | |
6159 | post_cnt - 1)); | |
6160 | list_splice_init(&blck_sgl_list, &free_sgl_list); | |
711ea882 | 6161 | total_cnt -= post_cnt; |
8a9d2e80 JS |
6162 | } |
6163 | ||
6164 | /* don't reset xirtag due to hole in xri block */ | |
6165 | if (block_cnt == 0) | |
6166 | last_xritag = NO_XRI; | |
6167 | ||
6168 | /* reset els sgl post count for next round of posting */ | |
6169 | post_cnt = 0; | |
6170 | } | |
711ea882 JS |
6171 | /* update the number of XRIs posted for ELS */ |
6172 | phba->sli4_hba.els_xri_cnt = total_cnt; | |
8a9d2e80 JS |
6173 | |
6174 | /* free the els sgls failed to post */ | |
6175 | lpfc_free_sgl_list(phba, &free_sgl_list); | |
6176 | ||
6177 | /* push els sgls posted to the availble list */ | |
6178 | if (!list_empty(&post_sgl_list)) { | |
38c20673 | 6179 | spin_lock_irq(&phba->hbalock); |
dafe8cea | 6180 | spin_lock(&pring->ring_lock); |
8a9d2e80 JS |
6181 | list_splice_init(&post_sgl_list, |
6182 | &phba->sli4_hba.lpfc_sgl_list); | |
dafe8cea | 6183 | spin_unlock(&pring->ring_lock); |
38c20673 | 6184 | spin_unlock_irq(&phba->hbalock); |
8a9d2e80 JS |
6185 | } else { |
6186 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
6187 | "3161 Failure to post els sgl to port.\n"); | |
6188 | return -EIO; | |
6189 | } | |
6190 | return 0; | |
6191 | } | |
6192 | ||
da0436e9 JS |
6193 | /** |
6194 | * lpfc_sli4_hba_setup - SLI4 device intialization PCI function | |
6195 | * @phba: Pointer to HBA context object. | |
6196 | * | |
6197 | * This function is the main SLI4 device intialization PCI function. This | |
6198 | * function is called by the HBA intialization code, HBA reset code and | |
6199 | * HBA error attention handler code. Caller is not required to hold any | |
6200 | * locks. | |
6201 | **/ | |
6202 | int | |
6203 | lpfc_sli4_hba_setup(struct lpfc_hba *phba) | |
6204 | { | |
6205 | int rc; | |
6206 | LPFC_MBOXQ_t *mboxq; | |
6207 | struct lpfc_mqe *mqe; | |
6208 | uint8_t *vpd; | |
6209 | uint32_t vpd_size; | |
6210 | uint32_t ftr_rsp = 0; | |
6211 | struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport); | |
6212 | struct lpfc_vport *vport = phba->pport; | |
6213 | struct lpfc_dmabuf *mp; | |
6214 | ||
6215 | /* Perform a PCI function reset to start from clean */ | |
6216 | rc = lpfc_pci_function_reset(phba); | |
6217 | if (unlikely(rc)) | |
6218 | return -ENODEV; | |
6219 | ||
6220 | /* Check the HBA Host Status Register for readyness */ | |
6221 | rc = lpfc_sli4_post_status_check(phba); | |
6222 | if (unlikely(rc)) | |
6223 | return -ENODEV; | |
6224 | else { | |
6225 | spin_lock_irq(&phba->hbalock); | |
6226 | phba->sli.sli_flag |= LPFC_SLI_ACTIVE; | |
6227 | spin_unlock_irq(&phba->hbalock); | |
6228 | } | |
6229 | ||
6230 | /* | |
6231 | * Allocate a single mailbox container for initializing the | |
6232 | * port. | |
6233 | */ | |
6234 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
6235 | if (!mboxq) | |
6236 | return -ENOMEM; | |
6237 | ||
da0436e9 | 6238 | /* Issue READ_REV to collect vpd and FW information. */ |
49198b37 | 6239 | vpd_size = SLI4_PAGE_SIZE; |
da0436e9 JS |
6240 | vpd = kzalloc(vpd_size, GFP_KERNEL); |
6241 | if (!vpd) { | |
6242 | rc = -ENOMEM; | |
6243 | goto out_free_mbox; | |
6244 | } | |
6245 | ||
6246 | rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size); | |
76a95d75 JS |
6247 | if (unlikely(rc)) { |
6248 | kfree(vpd); | |
6249 | goto out_free_mbox; | |
6250 | } | |
572709e2 | 6251 | |
da0436e9 | 6252 | mqe = &mboxq->u.mqe; |
f1126688 JS |
6253 | phba->sli_rev = bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev); |
6254 | if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev)) | |
76a95d75 JS |
6255 | phba->hba_flag |= HBA_FCOE_MODE; |
6256 | else | |
6257 | phba->hba_flag &= ~HBA_FCOE_MODE; | |
45ed1190 JS |
6258 | |
6259 | if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) == | |
6260 | LPFC_DCBX_CEE_MODE) | |
6261 | phba->hba_flag |= HBA_FIP_SUPPORT; | |
6262 | else | |
6263 | phba->hba_flag &= ~HBA_FIP_SUPPORT; | |
6264 | ||
4f2e66c6 JS |
6265 | phba->hba_flag &= ~HBA_FCP_IOQ_FLUSH; |
6266 | ||
c31098ce | 6267 | if (phba->sli_rev != LPFC_SLI_REV4) { |
da0436e9 JS |
6268 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
6269 | "0376 READ_REV Error. SLI Level %d " | |
6270 | "FCoE enabled %d\n", | |
76a95d75 | 6271 | phba->sli_rev, phba->hba_flag & HBA_FCOE_MODE); |
da0436e9 | 6272 | rc = -EIO; |
76a95d75 JS |
6273 | kfree(vpd); |
6274 | goto out_free_mbox; | |
da0436e9 | 6275 | } |
cd1c8301 | 6276 | |
ff78d8f9 JS |
6277 | /* |
6278 | * Continue initialization with default values even if driver failed | |
6279 | * to read FCoE param config regions, only read parameters if the | |
6280 | * board is FCoE | |
6281 | */ | |
6282 | if (phba->hba_flag & HBA_FCOE_MODE && | |
6283 | lpfc_sli4_read_fcoe_params(phba)) | |
6284 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_INIT, | |
6285 | "2570 Failed to read FCoE parameters\n"); | |
6286 | ||
cd1c8301 JS |
6287 | /* |
6288 | * Retrieve sli4 device physical port name, failure of doing it | |
6289 | * is considered as non-fatal. | |
6290 | */ | |
6291 | rc = lpfc_sli4_retrieve_pport_name(phba); | |
6292 | if (!rc) | |
6293 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, | |
6294 | "3080 Successful retrieving SLI4 device " | |
6295 | "physical port name: %s.\n", phba->Port); | |
6296 | ||
da0436e9 JS |
6297 | /* |
6298 | * Evaluate the read rev and vpd data. Populate the driver | |
6299 | * state with the results. If this routine fails, the failure | |
6300 | * is not fatal as the driver will use generic values. | |
6301 | */ | |
6302 | rc = lpfc_parse_vpd(phba, vpd, vpd_size); | |
6303 | if (unlikely(!rc)) { | |
6304 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
6305 | "0377 Error %d parsing vpd. " | |
6306 | "Using defaults.\n", rc); | |
6307 | rc = 0; | |
6308 | } | |
76a95d75 | 6309 | kfree(vpd); |
da0436e9 | 6310 | |
f1126688 JS |
6311 | /* Save information as VPD data */ |
6312 | phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev; | |
6313 | phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev; | |
6314 | phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev; | |
6315 | phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high, | |
6316 | &mqe->un.read_rev); | |
6317 | phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low, | |
6318 | &mqe->un.read_rev); | |
6319 | phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high, | |
6320 | &mqe->un.read_rev); | |
6321 | phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low, | |
6322 | &mqe->un.read_rev); | |
6323 | phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev; | |
6324 | memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16); | |
6325 | phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev; | |
6326 | memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16); | |
6327 | phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev; | |
6328 | memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16); | |
6329 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, | |
6330 | "(%d):0380 READ_REV Status x%x " | |
6331 | "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n", | |
6332 | mboxq->vport ? mboxq->vport->vpi : 0, | |
6333 | bf_get(lpfc_mqe_status, mqe), | |
6334 | phba->vpd.rev.opFwName, | |
6335 | phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow, | |
6336 | phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow); | |
da0436e9 | 6337 | |
572709e2 JS |
6338 | /* Reset the DFT_LUN_Q_DEPTH to (max xri >> 3) */ |
6339 | rc = (phba->sli4_hba.max_cfg_param.max_xri >> 3); | |
6340 | if (phba->pport->cfg_lun_queue_depth > rc) { | |
6341 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
6342 | "3362 LUN queue depth changed from %d to %d\n", | |
6343 | phba->pport->cfg_lun_queue_depth, rc); | |
6344 | phba->pport->cfg_lun_queue_depth = rc; | |
6345 | } | |
6346 | ||
6347 | ||
da0436e9 JS |
6348 | /* |
6349 | * Discover the port's supported feature set and match it against the | |
6350 | * hosts requests. | |
6351 | */ | |
6352 | lpfc_request_features(phba, mboxq); | |
6353 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
6354 | if (unlikely(rc)) { | |
6355 | rc = -EIO; | |
76a95d75 | 6356 | goto out_free_mbox; |
da0436e9 JS |
6357 | } |
6358 | ||
6359 | /* | |
6360 | * The port must support FCP initiator mode as this is the | |
6361 | * only mode running in the host. | |
6362 | */ | |
6363 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) { | |
6364 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, | |
6365 | "0378 No support for fcpi mode.\n"); | |
6366 | ftr_rsp++; | |
6367 | } | |
fedd3b7b JS |
6368 | if (bf_get(lpfc_mbx_rq_ftr_rsp_perfh, &mqe->un.req_ftrs)) |
6369 | phba->sli3_options |= LPFC_SLI4_PERFH_ENABLED; | |
6370 | else | |
6371 | phba->sli3_options &= ~LPFC_SLI4_PERFH_ENABLED; | |
da0436e9 JS |
6372 | /* |
6373 | * If the port cannot support the host's requested features | |
6374 | * then turn off the global config parameters to disable the | |
6375 | * feature in the driver. This is not a fatal error. | |
6376 | */ | |
bf08611b JS |
6377 | phba->sli3_options &= ~LPFC_SLI3_BG_ENABLED; |
6378 | if (phba->cfg_enable_bg) { | |
6379 | if (bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)) | |
6380 | phba->sli3_options |= LPFC_SLI3_BG_ENABLED; | |
6381 | else | |
6382 | ftr_rsp++; | |
6383 | } | |
da0436e9 JS |
6384 | |
6385 | if (phba->max_vpi && phba->cfg_enable_npiv && | |
6386 | !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs))) | |
6387 | ftr_rsp++; | |
6388 | ||
6389 | if (ftr_rsp) { | |
6390 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, | |
6391 | "0379 Feature Mismatch Data: x%08x %08x " | |
6392 | "x%x x%x x%x\n", mqe->un.req_ftrs.word2, | |
6393 | mqe->un.req_ftrs.word3, phba->cfg_enable_bg, | |
6394 | phba->cfg_enable_npiv, phba->max_vpi); | |
6395 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))) | |
6396 | phba->cfg_enable_bg = 0; | |
6397 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs))) | |
6398 | phba->cfg_enable_npiv = 0; | |
6399 | } | |
6400 | ||
6401 | /* These SLI3 features are assumed in SLI4 */ | |
6402 | spin_lock_irq(&phba->hbalock); | |
6403 | phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED); | |
6404 | spin_unlock_irq(&phba->hbalock); | |
6405 | ||
6d368e53 JS |
6406 | /* |
6407 | * Allocate all resources (xri,rpi,vpi,vfi) now. Subsequent | |
6408 | * calls depends on these resources to complete port setup. | |
6409 | */ | |
6410 | rc = lpfc_sli4_alloc_resource_identifiers(phba); | |
6411 | if (rc) { | |
6412 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
6413 | "2920 Failed to alloc Resource IDs " | |
6414 | "rc = x%x\n", rc); | |
6415 | goto out_free_mbox; | |
6416 | } | |
6417 | ||
da0436e9 | 6418 | /* Read the port's service parameters. */ |
9f1177a3 JS |
6419 | rc = lpfc_read_sparam(phba, mboxq, vport->vpi); |
6420 | if (rc) { | |
6421 | phba->link_state = LPFC_HBA_ERROR; | |
6422 | rc = -ENOMEM; | |
76a95d75 | 6423 | goto out_free_mbox; |
9f1177a3 JS |
6424 | } |
6425 | ||
da0436e9 JS |
6426 | mboxq->vport = vport; |
6427 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
6428 | mp = (struct lpfc_dmabuf *) mboxq->context1; | |
6429 | if (rc == MBX_SUCCESS) { | |
6430 | memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm)); | |
6431 | rc = 0; | |
6432 | } | |
6433 | ||
6434 | /* | |
6435 | * This memory was allocated by the lpfc_read_sparam routine. Release | |
6436 | * it to the mbuf pool. | |
6437 | */ | |
6438 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
6439 | kfree(mp); | |
6440 | mboxq->context1 = NULL; | |
6441 | if (unlikely(rc)) { | |
6442 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
6443 | "0382 READ_SPARAM command failed " | |
6444 | "status %d, mbxStatus x%x\n", | |
6445 | rc, bf_get(lpfc_mqe_status, mqe)); | |
6446 | phba->link_state = LPFC_HBA_ERROR; | |
6447 | rc = -EIO; | |
76a95d75 | 6448 | goto out_free_mbox; |
da0436e9 JS |
6449 | } |
6450 | ||
0558056c | 6451 | lpfc_update_vport_wwn(vport); |
da0436e9 JS |
6452 | |
6453 | /* Update the fc_host data structures with new wwn. */ | |
6454 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); | |
6455 | fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn); | |
6456 | ||
8a9d2e80 JS |
6457 | /* update host els and scsi xri-sgl sizes and mappings */ |
6458 | rc = lpfc_sli4_xri_sgl_update(phba); | |
6459 | if (unlikely(rc)) { | |
6460 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
6461 | "1400 Failed to update xri-sgl size and " | |
6462 | "mapping: %d\n", rc); | |
6463 | goto out_free_mbox; | |
da0436e9 JS |
6464 | } |
6465 | ||
8a9d2e80 JS |
6466 | /* register the els sgl pool to the port */ |
6467 | rc = lpfc_sli4_repost_els_sgl_list(phba); | |
6468 | if (unlikely(rc)) { | |
6469 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
6470 | "0582 Error %d during els sgl post " | |
6471 | "operation\n", rc); | |
6472 | rc = -ENODEV; | |
6473 | goto out_free_mbox; | |
6474 | } | |
6475 | ||
6476 | /* register the allocated scsi sgl pool to the port */ | |
da0436e9 JS |
6477 | rc = lpfc_sli4_repost_scsi_sgl_list(phba); |
6478 | if (unlikely(rc)) { | |
6d368e53 | 6479 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
6a9c52cf JS |
6480 | "0383 Error %d during scsi sgl post " |
6481 | "operation\n", rc); | |
da0436e9 JS |
6482 | /* Some Scsi buffers were moved to the abort scsi list */ |
6483 | /* A pci function reset will repost them */ | |
6484 | rc = -ENODEV; | |
76a95d75 | 6485 | goto out_free_mbox; |
da0436e9 JS |
6486 | } |
6487 | ||
6488 | /* Post the rpi header region to the device. */ | |
6489 | rc = lpfc_sli4_post_all_rpi_hdrs(phba); | |
6490 | if (unlikely(rc)) { | |
6491 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
6492 | "0393 Error %d during rpi post operation\n", | |
6493 | rc); | |
6494 | rc = -ENODEV; | |
76a95d75 | 6495 | goto out_free_mbox; |
da0436e9 | 6496 | } |
97f2ecf1 | 6497 | lpfc_sli4_node_prep(phba); |
da0436e9 | 6498 | |
5350d872 JS |
6499 | /* Create all the SLI4 queues */ |
6500 | rc = lpfc_sli4_queue_create(phba); | |
6501 | if (rc) { | |
6502 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6503 | "3089 Failed to allocate queues\n"); | |
6504 | rc = -ENODEV; | |
6505 | goto out_stop_timers; | |
6506 | } | |
da0436e9 JS |
6507 | /* Set up all the queues to the device */ |
6508 | rc = lpfc_sli4_queue_setup(phba); | |
6509 | if (unlikely(rc)) { | |
6510 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
6511 | "0381 Error %d during queue setup.\n ", rc); | |
5350d872 | 6512 | goto out_destroy_queue; |
da0436e9 JS |
6513 | } |
6514 | ||
6515 | /* Arm the CQs and then EQs on device */ | |
6516 | lpfc_sli4_arm_cqeq_intr(phba); | |
6517 | ||
6518 | /* Indicate device interrupt mode */ | |
6519 | phba->sli4_hba.intr_enable = 1; | |
6520 | ||
6521 | /* Allow asynchronous mailbox command to go through */ | |
6522 | spin_lock_irq(&phba->hbalock); | |
6523 | phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; | |
6524 | spin_unlock_irq(&phba->hbalock); | |
6525 | ||
6526 | /* Post receive buffers to the device */ | |
6527 | lpfc_sli4_rb_setup(phba); | |
6528 | ||
fc2b989b JS |
6529 | /* Reset HBA FCF states after HBA reset */ |
6530 | phba->fcf.fcf_flag = 0; | |
6531 | phba->fcf.current_rec.flag = 0; | |
6532 | ||
da0436e9 | 6533 | /* Start the ELS watchdog timer */ |
8fa38513 | 6534 | mod_timer(&vport->els_tmofunc, |
256ec0d0 | 6535 | jiffies + msecs_to_jiffies(1000 * (phba->fc_ratov * 2))); |
da0436e9 JS |
6536 | |
6537 | /* Start heart beat timer */ | |
6538 | mod_timer(&phba->hb_tmofunc, | |
256ec0d0 | 6539 | jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL)); |
da0436e9 JS |
6540 | phba->hb_outstanding = 0; |
6541 | phba->last_completion_time = jiffies; | |
6542 | ||
6543 | /* Start error attention (ERATT) polling timer */ | |
256ec0d0 JS |
6544 | mod_timer(&phba->eratt_poll, |
6545 | jiffies + msecs_to_jiffies(1000 * LPFC_ERATT_POLL_INTERVAL)); | |
da0436e9 | 6546 | |
75baf696 JS |
6547 | /* Enable PCIe device Advanced Error Reporting (AER) if configured */ |
6548 | if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) { | |
6549 | rc = pci_enable_pcie_error_reporting(phba->pcidev); | |
6550 | if (!rc) { | |
6551 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
6552 | "2829 This device supports " | |
6553 | "Advanced Error Reporting (AER)\n"); | |
6554 | spin_lock_irq(&phba->hbalock); | |
6555 | phba->hba_flag |= HBA_AER_ENABLED; | |
6556 | spin_unlock_irq(&phba->hbalock); | |
6557 | } else { | |
6558 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
6559 | "2830 This device does not support " | |
6560 | "Advanced Error Reporting (AER)\n"); | |
6561 | phba->cfg_aer_support = 0; | |
6562 | } | |
0a96e975 | 6563 | rc = 0; |
75baf696 JS |
6564 | } |
6565 | ||
76a95d75 JS |
6566 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { |
6567 | /* | |
6568 | * The FC Port needs to register FCFI (index 0) | |
6569 | */ | |
6570 | lpfc_reg_fcfi(phba, mboxq); | |
6571 | mboxq->vport = phba->pport; | |
6572 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
9589b062 | 6573 | if (rc != MBX_SUCCESS) |
76a95d75 | 6574 | goto out_unset_queue; |
9589b062 JS |
6575 | rc = 0; |
6576 | phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, | |
6577 | &mboxq->u.mqe.un.reg_fcfi); | |
026abb87 JS |
6578 | |
6579 | /* Check if the port is configured to be disabled */ | |
6580 | lpfc_sli_read_link_ste(phba); | |
76a95d75 | 6581 | } |
026abb87 | 6582 | |
da0436e9 JS |
6583 | /* |
6584 | * The port is ready, set the host's link state to LINK_DOWN | |
6585 | * in preparation for link interrupts. | |
6586 | */ | |
da0436e9 JS |
6587 | spin_lock_irq(&phba->hbalock); |
6588 | phba->link_state = LPFC_LINK_DOWN; | |
6589 | spin_unlock_irq(&phba->hbalock); | |
026abb87 JS |
6590 | if (!(phba->hba_flag & HBA_FCOE_MODE) && |
6591 | (phba->hba_flag & LINK_DISABLED)) { | |
6592 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI, | |
6593 | "3103 Adapter Link is disabled.\n"); | |
6594 | lpfc_down_link(phba, mboxq); | |
6595 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
6596 | if (rc != MBX_SUCCESS) { | |
6597 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI, | |
6598 | "3104 Adapter failed to issue " | |
6599 | "DOWN_LINK mbox cmd, rc:x%x\n", rc); | |
6600 | goto out_unset_queue; | |
6601 | } | |
6602 | } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) { | |
1b51197d JS |
6603 | /* don't perform init_link on SLI4 FC port loopback test */ |
6604 | if (!(phba->link_flag & LS_LOOPBACK_MODE)) { | |
6605 | rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT); | |
6606 | if (rc) | |
6607 | goto out_unset_queue; | |
6608 | } | |
5350d872 JS |
6609 | } |
6610 | mempool_free(mboxq, phba->mbox_mem_pool); | |
6611 | return rc; | |
76a95d75 | 6612 | out_unset_queue: |
da0436e9 | 6613 | /* Unset all the queues set up in this routine when error out */ |
5350d872 JS |
6614 | lpfc_sli4_queue_unset(phba); |
6615 | out_destroy_queue: | |
6616 | lpfc_sli4_queue_destroy(phba); | |
da0436e9 | 6617 | out_stop_timers: |
5350d872 | 6618 | lpfc_stop_hba_timers(phba); |
da0436e9 JS |
6619 | out_free_mbox: |
6620 | mempool_free(mboxq, phba->mbox_mem_pool); | |
6621 | return rc; | |
6622 | } | |
6623 | ||
6624 | /** | |
6625 | * lpfc_mbox_timeout - Timeout call back function for mbox timer | |
6626 | * @ptr: context object - pointer to hba structure. | |
6627 | * | |
6628 | * This is the callback function for mailbox timer. The mailbox | |
6629 | * timer is armed when a new mailbox command is issued and the timer | |
6630 | * is deleted when the mailbox complete. The function is called by | |
6631 | * the kernel timer code when a mailbox does not complete within | |
6632 | * expected time. This function wakes up the worker thread to | |
6633 | * process the mailbox timeout and returns. All the processing is | |
6634 | * done by the worker thread function lpfc_mbox_timeout_handler. | |
6635 | **/ | |
6636 | void | |
6637 | lpfc_mbox_timeout(unsigned long ptr) | |
6638 | { | |
6639 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; | |
6640 | unsigned long iflag; | |
6641 | uint32_t tmo_posted; | |
6642 | ||
6643 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); | |
6644 | tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO; | |
6645 | if (!tmo_posted) | |
6646 | phba->pport->work_port_events |= WORKER_MBOX_TMO; | |
6647 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); | |
6648 | ||
6649 | if (!tmo_posted) | |
6650 | lpfc_worker_wake_up(phba); | |
6651 | return; | |
6652 | } | |
6653 | ||
e8d3c3b1 JS |
6654 | /** |
6655 | * lpfc_sli4_mbox_completions_pending - check to see if any mailbox completions | |
6656 | * are pending | |
6657 | * @phba: Pointer to HBA context object. | |
6658 | * | |
6659 | * This function checks if any mailbox completions are present on the mailbox | |
6660 | * completion queue. | |
6661 | **/ | |
6662 | bool | |
6663 | lpfc_sli4_mbox_completions_pending(struct lpfc_hba *phba) | |
6664 | { | |
6665 | ||
6666 | uint32_t idx; | |
6667 | struct lpfc_queue *mcq; | |
6668 | struct lpfc_mcqe *mcqe; | |
6669 | bool pending_completions = false; | |
6670 | ||
6671 | if (unlikely(!phba) || (phba->sli_rev != LPFC_SLI_REV4)) | |
6672 | return false; | |
6673 | ||
6674 | /* Check for completions on mailbox completion queue */ | |
6675 | ||
6676 | mcq = phba->sli4_hba.mbx_cq; | |
6677 | idx = mcq->hba_index; | |
6678 | while (bf_get_le32(lpfc_cqe_valid, mcq->qe[idx].cqe)) { | |
6679 | mcqe = (struct lpfc_mcqe *)mcq->qe[idx].cqe; | |
6680 | if (bf_get_le32(lpfc_trailer_completed, mcqe) && | |
6681 | (!bf_get_le32(lpfc_trailer_async, mcqe))) { | |
6682 | pending_completions = true; | |
6683 | break; | |
6684 | } | |
6685 | idx = (idx + 1) % mcq->entry_count; | |
6686 | if (mcq->hba_index == idx) | |
6687 | break; | |
6688 | } | |
6689 | return pending_completions; | |
6690 | ||
6691 | } | |
6692 | ||
6693 | /** | |
6694 | * lpfc_sli4_process_missed_mbox_completions - process mbox completions | |
6695 | * that were missed. | |
6696 | * @phba: Pointer to HBA context object. | |
6697 | * | |
6698 | * For sli4, it is possible to miss an interrupt. As such mbox completions | |
6699 | * maybe missed causing erroneous mailbox timeouts to occur. This function | |
6700 | * checks to see if mbox completions are on the mailbox completion queue | |
6701 | * and will process all the completions associated with the eq for the | |
6702 | * mailbox completion queue. | |
6703 | **/ | |
6704 | bool | |
6705 | lpfc_sli4_process_missed_mbox_completions(struct lpfc_hba *phba) | |
6706 | { | |
6707 | ||
6708 | uint32_t eqidx; | |
6709 | struct lpfc_queue *fpeq = NULL; | |
6710 | struct lpfc_eqe *eqe; | |
6711 | bool mbox_pending; | |
6712 | ||
6713 | if (unlikely(!phba) || (phba->sli_rev != LPFC_SLI_REV4)) | |
6714 | return false; | |
6715 | ||
6716 | /* Find the eq associated with the mcq */ | |
6717 | ||
6718 | if (phba->sli4_hba.hba_eq) | |
6719 | for (eqidx = 0; eqidx < phba->cfg_fcp_io_channel; eqidx++) | |
6720 | if (phba->sli4_hba.hba_eq[eqidx]->queue_id == | |
6721 | phba->sli4_hba.mbx_cq->assoc_qid) { | |
6722 | fpeq = phba->sli4_hba.hba_eq[eqidx]; | |
6723 | break; | |
6724 | } | |
6725 | if (!fpeq) | |
6726 | return false; | |
6727 | ||
6728 | /* Turn off interrupts from this EQ */ | |
6729 | ||
6730 | lpfc_sli4_eq_clr_intr(fpeq); | |
6731 | ||
6732 | /* Check to see if a mbox completion is pending */ | |
6733 | ||
6734 | mbox_pending = lpfc_sli4_mbox_completions_pending(phba); | |
6735 | ||
6736 | /* | |
6737 | * If a mbox completion is pending, process all the events on EQ | |
6738 | * associated with the mbox completion queue (this could include | |
6739 | * mailbox commands, async events, els commands, receive queue data | |
6740 | * and fcp commands) | |
6741 | */ | |
6742 | ||
6743 | if (mbox_pending) | |
6744 | while ((eqe = lpfc_sli4_eq_get(fpeq))) { | |
6745 | lpfc_sli4_hba_handle_eqe(phba, eqe, eqidx); | |
6746 | fpeq->EQ_processed++; | |
6747 | } | |
6748 | ||
6749 | /* Always clear and re-arm the EQ */ | |
6750 | ||
6751 | lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM); | |
6752 | ||
6753 | return mbox_pending; | |
6754 | ||
6755 | } | |
da0436e9 JS |
6756 | |
6757 | /** | |
6758 | * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout | |
6759 | * @phba: Pointer to HBA context object. | |
6760 | * | |
6761 | * This function is called from worker thread when a mailbox command times out. | |
6762 | * The caller is not required to hold any locks. This function will reset the | |
6763 | * HBA and recover all the pending commands. | |
6764 | **/ | |
6765 | void | |
6766 | lpfc_mbox_timeout_handler(struct lpfc_hba *phba) | |
6767 | { | |
6768 | LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active; | |
04c68496 | 6769 | MAILBOX_t *mb = &pmbox->u.mb; |
da0436e9 | 6770 | struct lpfc_sli *psli = &phba->sli; |
da0436e9 | 6771 | |
e8d3c3b1 JS |
6772 | /* If the mailbox completed, process the completion and return */ |
6773 | if (lpfc_sli4_process_missed_mbox_completions(phba)) | |
6774 | return; | |
6775 | ||
da0436e9 JS |
6776 | /* Check the pmbox pointer first. There is a race condition |
6777 | * between the mbox timeout handler getting executed in the | |
6778 | * worklist and the mailbox actually completing. When this | |
6779 | * race condition occurs, the mbox_active will be NULL. | |
6780 | */ | |
6781 | spin_lock_irq(&phba->hbalock); | |
6782 | if (pmbox == NULL) { | |
6783 | lpfc_printf_log(phba, KERN_WARNING, | |
6784 | LOG_MBOX | LOG_SLI, | |
6785 | "0353 Active Mailbox cleared - mailbox timeout " | |
6786 | "exiting\n"); | |
6787 | spin_unlock_irq(&phba->hbalock); | |
6788 | return; | |
6789 | } | |
6790 | ||
6791 | /* Mbox cmd <mbxCommand> timeout */ | |
6792 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
6793 | "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n", | |
6794 | mb->mbxCommand, | |
6795 | phba->pport->port_state, | |
6796 | phba->sli.sli_flag, | |
6797 | phba->sli.mbox_active); | |
6798 | spin_unlock_irq(&phba->hbalock); | |
6799 | ||
6800 | /* Setting state unknown so lpfc_sli_abort_iocb_ring | |
6801 | * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing | |
25985edc | 6802 | * it to fail all outstanding SCSI IO. |
da0436e9 JS |
6803 | */ |
6804 | spin_lock_irq(&phba->pport->work_port_lock); | |
6805 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; | |
6806 | spin_unlock_irq(&phba->pport->work_port_lock); | |
6807 | spin_lock_irq(&phba->hbalock); | |
6808 | phba->link_state = LPFC_LINK_UNKNOWN; | |
f4b4c68f | 6809 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
da0436e9 JS |
6810 | spin_unlock_irq(&phba->hbalock); |
6811 | ||
db55fba8 | 6812 | lpfc_sli_abort_fcp_rings(phba); |
da0436e9 JS |
6813 | |
6814 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
6815 | "0345 Resetting board due to mailbox timeout\n"); | |
6816 | ||
6817 | /* Reset the HBA device */ | |
6818 | lpfc_reset_hba(phba); | |
6819 | } | |
6820 | ||
6821 | /** | |
6822 | * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware | |
6823 | * @phba: Pointer to HBA context object. | |
6824 | * @pmbox: Pointer to mailbox object. | |
6825 | * @flag: Flag indicating how the mailbox need to be processed. | |
6826 | * | |
6827 | * This function is called by discovery code and HBA management code | |
6828 | * to submit a mailbox command to firmware with SLI-3 interface spec. This | |
6829 | * function gets the hbalock to protect the data structures. | |
6830 | * The mailbox command can be submitted in polling mode, in which case | |
6831 | * this function will wait in a polling loop for the completion of the | |
6832 | * mailbox. | |
6833 | * If the mailbox is submitted in no_wait mode (not polling) the | |
6834 | * function will submit the command and returns immediately without waiting | |
6835 | * for the mailbox completion. The no_wait is supported only when HBA | |
6836 | * is in SLI2/SLI3 mode - interrupts are enabled. | |
6837 | * The SLI interface allows only one mailbox pending at a time. If the | |
6838 | * mailbox is issued in polling mode and there is already a mailbox | |
6839 | * pending, then the function will return an error. If the mailbox is issued | |
6840 | * in NO_WAIT mode and there is a mailbox pending already, the function | |
6841 | * will return MBX_BUSY after queuing the mailbox into mailbox queue. | |
6842 | * The sli layer owns the mailbox object until the completion of mailbox | |
6843 | * command if this function return MBX_BUSY or MBX_SUCCESS. For all other | |
6844 | * return codes the caller owns the mailbox command after the return of | |
6845 | * the function. | |
e59058c4 | 6846 | **/ |
3772a991 JS |
6847 | static int |
6848 | lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, | |
6849 | uint32_t flag) | |
dea3101e | 6850 | { |
bf07bdea | 6851 | MAILBOX_t *mbx; |
2e0fef85 | 6852 | struct lpfc_sli *psli = &phba->sli; |
dea3101e | 6853 | uint32_t status, evtctr; |
9940b97b | 6854 | uint32_t ha_copy, hc_copy; |
dea3101e | 6855 | int i; |
09372820 | 6856 | unsigned long timeout; |
dea3101e | 6857 | unsigned long drvr_flag = 0; |
34b02dcd | 6858 | uint32_t word0, ldata; |
dea3101e | 6859 | void __iomem *to_slim; |
58da1ffb JS |
6860 | int processing_queue = 0; |
6861 | ||
6862 | spin_lock_irqsave(&phba->hbalock, drvr_flag); | |
6863 | if (!pmbox) { | |
8568a4d2 | 6864 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
58da1ffb | 6865 | /* processing mbox queue from intr_handler */ |
3772a991 JS |
6866 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
6867 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | |
6868 | return MBX_SUCCESS; | |
6869 | } | |
58da1ffb | 6870 | processing_queue = 1; |
58da1ffb JS |
6871 | pmbox = lpfc_mbox_get(phba); |
6872 | if (!pmbox) { | |
6873 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | |
6874 | return MBX_SUCCESS; | |
6875 | } | |
6876 | } | |
dea3101e | 6877 | |
ed957684 | 6878 | if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl && |
92d7f7b0 | 6879 | pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) { |
ed957684 | 6880 | if(!pmbox->vport) { |
58da1ffb | 6881 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
ed957684 | 6882 | lpfc_printf_log(phba, KERN_ERR, |
92d7f7b0 | 6883 | LOG_MBOX | LOG_VPORT, |
e8b62011 | 6884 | "1806 Mbox x%x failed. No vport\n", |
3772a991 | 6885 | pmbox->u.mb.mbxCommand); |
ed957684 | 6886 | dump_stack(); |
58da1ffb | 6887 | goto out_not_finished; |
ed957684 JS |
6888 | } |
6889 | } | |
6890 | ||
8d63f375 | 6891 | /* If the PCI channel is in offline state, do not post mbox. */ |
58da1ffb JS |
6892 | if (unlikely(pci_channel_offline(phba->pcidev))) { |
6893 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | |
6894 | goto out_not_finished; | |
6895 | } | |
8d63f375 | 6896 | |
a257bf90 JS |
6897 | /* If HBA has a deferred error attention, fail the iocb. */ |
6898 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { | |
6899 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | |
6900 | goto out_not_finished; | |
6901 | } | |
6902 | ||
dea3101e | 6903 | psli = &phba->sli; |
92d7f7b0 | 6904 | |
bf07bdea | 6905 | mbx = &pmbox->u.mb; |
dea3101e | 6906 | status = MBX_SUCCESS; |
6907 | ||
2e0fef85 JS |
6908 | if (phba->link_state == LPFC_HBA_ERROR) { |
6909 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | |
41415862 JW |
6910 | |
6911 | /* Mbox command <mbxCommand> cannot issue */ | |
3772a991 JS |
6912 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
6913 | "(%d):0311 Mailbox command x%x cannot " | |
6914 | "issue Data: x%x x%x\n", | |
6915 | pmbox->vport ? pmbox->vport->vpi : 0, | |
6916 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); | |
58da1ffb | 6917 | goto out_not_finished; |
41415862 JW |
6918 | } |
6919 | ||
bf07bdea | 6920 | if (mbx->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT) { |
9940b97b JS |
6921 | if (lpfc_readl(phba->HCregaddr, &hc_copy) || |
6922 | !(hc_copy & HC_MBINT_ENA)) { | |
6923 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | |
6924 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
3772a991 JS |
6925 | "(%d):2528 Mailbox command x%x cannot " |
6926 | "issue Data: x%x x%x\n", | |
6927 | pmbox->vport ? pmbox->vport->vpi : 0, | |
6928 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); | |
9940b97b JS |
6929 | goto out_not_finished; |
6930 | } | |
9290831f JS |
6931 | } |
6932 | ||
dea3101e | 6933 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
6934 | /* Polling for a mbox command when another one is already active | |
6935 | * is not allowed in SLI. Also, the driver must have established | |
6936 | * SLI2 mode to queue and process multiple mbox commands. | |
6937 | */ | |
6938 | ||
6939 | if (flag & MBX_POLL) { | |
2e0fef85 | 6940 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
dea3101e | 6941 | |
6942 | /* Mbox command <mbxCommand> cannot issue */ | |
3772a991 JS |
6943 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
6944 | "(%d):2529 Mailbox command x%x " | |
6945 | "cannot issue Data: x%x x%x\n", | |
6946 | pmbox->vport ? pmbox->vport->vpi : 0, | |
6947 | pmbox->u.mb.mbxCommand, | |
6948 | psli->sli_flag, flag); | |
58da1ffb | 6949 | goto out_not_finished; |
dea3101e | 6950 | } |
6951 | ||
3772a991 | 6952 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) { |
2e0fef85 | 6953 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
dea3101e | 6954 | /* Mbox command <mbxCommand> cannot issue */ |
3772a991 JS |
6955 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
6956 | "(%d):2530 Mailbox command x%x " | |
6957 | "cannot issue Data: x%x x%x\n", | |
6958 | pmbox->vport ? pmbox->vport->vpi : 0, | |
6959 | pmbox->u.mb.mbxCommand, | |
6960 | psli->sli_flag, flag); | |
58da1ffb | 6961 | goto out_not_finished; |
dea3101e | 6962 | } |
6963 | ||
dea3101e | 6964 | /* Another mailbox command is still being processed, queue this |
6965 | * command to be processed later. | |
6966 | */ | |
6967 | lpfc_mbox_put(phba, pmbox); | |
6968 | ||
6969 | /* Mbox cmd issue - BUSY */ | |
ed957684 | 6970 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
e8b62011 | 6971 | "(%d):0308 Mbox cmd issue - BUSY Data: " |
92d7f7b0 | 6972 | "x%x x%x x%x x%x\n", |
92d7f7b0 | 6973 | pmbox->vport ? pmbox->vport->vpi : 0xffffff, |
bf07bdea | 6974 | mbx->mbxCommand, phba->pport->port_state, |
92d7f7b0 | 6975 | psli->sli_flag, flag); |
dea3101e | 6976 | |
6977 | psli->slistat.mbox_busy++; | |
2e0fef85 | 6978 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
dea3101e | 6979 | |
858c9f6c JS |
6980 | if (pmbox->vport) { |
6981 | lpfc_debugfs_disc_trc(pmbox->vport, | |
6982 | LPFC_DISC_TRC_MBOX_VPORT, | |
6983 | "MBOX Bsy vport: cmd:x%x mb:x%x x%x", | |
bf07bdea RD |
6984 | (uint32_t)mbx->mbxCommand, |
6985 | mbx->un.varWords[0], mbx->un.varWords[1]); | |
858c9f6c JS |
6986 | } |
6987 | else { | |
6988 | lpfc_debugfs_disc_trc(phba->pport, | |
6989 | LPFC_DISC_TRC_MBOX, | |
6990 | "MBOX Bsy: cmd:x%x mb:x%x x%x", | |
bf07bdea RD |
6991 | (uint32_t)mbx->mbxCommand, |
6992 | mbx->un.varWords[0], mbx->un.varWords[1]); | |
858c9f6c JS |
6993 | } |
6994 | ||
2e0fef85 | 6995 | return MBX_BUSY; |
dea3101e | 6996 | } |
6997 | ||
dea3101e | 6998 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
6999 | ||
7000 | /* If we are not polling, we MUST be in SLI2 mode */ | |
7001 | if (flag != MBX_POLL) { | |
3772a991 | 7002 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE) && |
bf07bdea | 7003 | (mbx->mbxCommand != MBX_KILL_BOARD)) { |
dea3101e | 7004 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
2e0fef85 | 7005 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
dea3101e | 7006 | /* Mbox command <mbxCommand> cannot issue */ |
3772a991 JS |
7007 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
7008 | "(%d):2531 Mailbox command x%x " | |
7009 | "cannot issue Data: x%x x%x\n", | |
7010 | pmbox->vport ? pmbox->vport->vpi : 0, | |
7011 | pmbox->u.mb.mbxCommand, | |
7012 | psli->sli_flag, flag); | |
58da1ffb | 7013 | goto out_not_finished; |
dea3101e | 7014 | } |
7015 | /* timeout active mbox command */ | |
256ec0d0 JS |
7016 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) * |
7017 | 1000); | |
7018 | mod_timer(&psli->mbox_tmo, jiffies + timeout); | |
dea3101e | 7019 | } |
7020 | ||
7021 | /* Mailbox cmd <cmd> issue */ | |
ed957684 | 7022 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
e8b62011 | 7023 | "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x " |
92d7f7b0 | 7024 | "x%x\n", |
e8b62011 | 7025 | pmbox->vport ? pmbox->vport->vpi : 0, |
bf07bdea | 7026 | mbx->mbxCommand, phba->pport->port_state, |
92d7f7b0 | 7027 | psli->sli_flag, flag); |
dea3101e | 7028 | |
bf07bdea | 7029 | if (mbx->mbxCommand != MBX_HEARTBEAT) { |
858c9f6c JS |
7030 | if (pmbox->vport) { |
7031 | lpfc_debugfs_disc_trc(pmbox->vport, | |
7032 | LPFC_DISC_TRC_MBOX_VPORT, | |
7033 | "MBOX Send vport: cmd:x%x mb:x%x x%x", | |
bf07bdea RD |
7034 | (uint32_t)mbx->mbxCommand, |
7035 | mbx->un.varWords[0], mbx->un.varWords[1]); | |
858c9f6c JS |
7036 | } |
7037 | else { | |
7038 | lpfc_debugfs_disc_trc(phba->pport, | |
7039 | LPFC_DISC_TRC_MBOX, | |
7040 | "MBOX Send: cmd:x%x mb:x%x x%x", | |
bf07bdea RD |
7041 | (uint32_t)mbx->mbxCommand, |
7042 | mbx->un.varWords[0], mbx->un.varWords[1]); | |
858c9f6c JS |
7043 | } |
7044 | } | |
7045 | ||
dea3101e | 7046 | psli->slistat.mbox_cmd++; |
7047 | evtctr = psli->slistat.mbox_event; | |
7048 | ||
7049 | /* next set own bit for the adapter and copy over command word */ | |
bf07bdea | 7050 | mbx->mbxOwner = OWN_CHIP; |
dea3101e | 7051 | |
3772a991 | 7052 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
7a470277 JS |
7053 | /* Populate mbox extension offset word. */ |
7054 | if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) { | |
bf07bdea | 7055 | *(((uint32_t *)mbx) + pmbox->mbox_offset_word) |
7a470277 JS |
7056 | = (uint8_t *)phba->mbox_ext |
7057 | - (uint8_t *)phba->mbox; | |
7058 | } | |
7059 | ||
7060 | /* Copy the mailbox extension data */ | |
7061 | if (pmbox->in_ext_byte_len && pmbox->context2) { | |
7062 | lpfc_sli_pcimem_bcopy(pmbox->context2, | |
7063 | (uint8_t *)phba->mbox_ext, | |
7064 | pmbox->in_ext_byte_len); | |
7065 | } | |
7066 | /* Copy command data to host SLIM area */ | |
bf07bdea | 7067 | lpfc_sli_pcimem_bcopy(mbx, phba->mbox, MAILBOX_CMD_SIZE); |
dea3101e | 7068 | } else { |
7a470277 JS |
7069 | /* Populate mbox extension offset word. */ |
7070 | if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) | |
bf07bdea | 7071 | *(((uint32_t *)mbx) + pmbox->mbox_offset_word) |
7a470277 JS |
7072 | = MAILBOX_HBA_EXT_OFFSET; |
7073 | ||
7074 | /* Copy the mailbox extension data */ | |
7075 | if (pmbox->in_ext_byte_len && pmbox->context2) { | |
7076 | lpfc_memcpy_to_slim(phba->MBslimaddr + | |
7077 | MAILBOX_HBA_EXT_OFFSET, | |
7078 | pmbox->context2, pmbox->in_ext_byte_len); | |
7079 | ||
7080 | } | |
bf07bdea | 7081 | if (mbx->mbxCommand == MBX_CONFIG_PORT) { |
dea3101e | 7082 | /* copy command data into host mbox for cmpl */ |
bf07bdea | 7083 | lpfc_sli_pcimem_bcopy(mbx, phba->mbox, MAILBOX_CMD_SIZE); |
dea3101e | 7084 | } |
7085 | ||
7086 | /* First copy mbox command data to HBA SLIM, skip past first | |
7087 | word */ | |
7088 | to_slim = phba->MBslimaddr + sizeof (uint32_t); | |
bf07bdea | 7089 | lpfc_memcpy_to_slim(to_slim, &mbx->un.varWords[0], |
dea3101e | 7090 | MAILBOX_CMD_SIZE - sizeof (uint32_t)); |
7091 | ||
7092 | /* Next copy over first word, with mbxOwner set */ | |
bf07bdea | 7093 | ldata = *((uint32_t *)mbx); |
dea3101e | 7094 | to_slim = phba->MBslimaddr; |
7095 | writel(ldata, to_slim); | |
7096 | readl(to_slim); /* flush */ | |
7097 | ||
bf07bdea | 7098 | if (mbx->mbxCommand == MBX_CONFIG_PORT) { |
dea3101e | 7099 | /* switch over to host mailbox */ |
3772a991 | 7100 | psli->sli_flag |= LPFC_SLI_ACTIVE; |
dea3101e | 7101 | } |
7102 | } | |
7103 | ||
7104 | wmb(); | |
dea3101e | 7105 | |
7106 | switch (flag) { | |
7107 | case MBX_NOWAIT: | |
09372820 | 7108 | /* Set up reference to mailbox command */ |
dea3101e | 7109 | psli->mbox_active = pmbox; |
09372820 JS |
7110 | /* Interrupt board to do it */ |
7111 | writel(CA_MBATT, phba->CAregaddr); | |
7112 | readl(phba->CAregaddr); /* flush */ | |
7113 | /* Don't wait for it to finish, just return */ | |
dea3101e | 7114 | break; |
7115 | ||
7116 | case MBX_POLL: | |
09372820 | 7117 | /* Set up null reference to mailbox command */ |
dea3101e | 7118 | psli->mbox_active = NULL; |
09372820 JS |
7119 | /* Interrupt board to do it */ |
7120 | writel(CA_MBATT, phba->CAregaddr); | |
7121 | readl(phba->CAregaddr); /* flush */ | |
7122 | ||
3772a991 | 7123 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
dea3101e | 7124 | /* First read mbox status word */ |
34b02dcd | 7125 | word0 = *((uint32_t *)phba->mbox); |
dea3101e | 7126 | word0 = le32_to_cpu(word0); |
7127 | } else { | |
7128 | /* First read mbox status word */ | |
9940b97b JS |
7129 | if (lpfc_readl(phba->MBslimaddr, &word0)) { |
7130 | spin_unlock_irqrestore(&phba->hbalock, | |
7131 | drvr_flag); | |
7132 | goto out_not_finished; | |
7133 | } | |
dea3101e | 7134 | } |
7135 | ||
7136 | /* Read the HBA Host Attention Register */ | |
9940b97b JS |
7137 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) { |
7138 | spin_unlock_irqrestore(&phba->hbalock, | |
7139 | drvr_flag); | |
7140 | goto out_not_finished; | |
7141 | } | |
a183a15f JS |
7142 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) * |
7143 | 1000) + jiffies; | |
09372820 | 7144 | i = 0; |
dea3101e | 7145 | /* Wait for command to complete */ |
41415862 JW |
7146 | while (((word0 & OWN_CHIP) == OWN_CHIP) || |
7147 | (!(ha_copy & HA_MBATT) && | |
2e0fef85 | 7148 | (phba->link_state > LPFC_WARM_START))) { |
09372820 | 7149 | if (time_after(jiffies, timeout)) { |
dea3101e | 7150 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
2e0fef85 | 7151 | spin_unlock_irqrestore(&phba->hbalock, |
dea3101e | 7152 | drvr_flag); |
58da1ffb | 7153 | goto out_not_finished; |
dea3101e | 7154 | } |
7155 | ||
7156 | /* Check if we took a mbox interrupt while we were | |
7157 | polling */ | |
7158 | if (((word0 & OWN_CHIP) != OWN_CHIP) | |
7159 | && (evtctr != psli->slistat.mbox_event)) | |
7160 | break; | |
7161 | ||
09372820 JS |
7162 | if (i++ > 10) { |
7163 | spin_unlock_irqrestore(&phba->hbalock, | |
7164 | drvr_flag); | |
7165 | msleep(1); | |
7166 | spin_lock_irqsave(&phba->hbalock, drvr_flag); | |
7167 | } | |
dea3101e | 7168 | |
3772a991 | 7169 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
dea3101e | 7170 | /* First copy command data */ |
34b02dcd | 7171 | word0 = *((uint32_t *)phba->mbox); |
dea3101e | 7172 | word0 = le32_to_cpu(word0); |
bf07bdea | 7173 | if (mbx->mbxCommand == MBX_CONFIG_PORT) { |
dea3101e | 7174 | MAILBOX_t *slimmb; |
34b02dcd | 7175 | uint32_t slimword0; |
dea3101e | 7176 | /* Check real SLIM for any errors */ |
7177 | slimword0 = readl(phba->MBslimaddr); | |
7178 | slimmb = (MAILBOX_t *) & slimword0; | |
7179 | if (((slimword0 & OWN_CHIP) != OWN_CHIP) | |
7180 | && slimmb->mbxStatus) { | |
7181 | psli->sli_flag &= | |
3772a991 | 7182 | ~LPFC_SLI_ACTIVE; |
dea3101e | 7183 | word0 = slimword0; |
7184 | } | |
7185 | } | |
7186 | } else { | |
7187 | /* First copy command data */ | |
7188 | word0 = readl(phba->MBslimaddr); | |
7189 | } | |
7190 | /* Read the HBA Host Attention Register */ | |
9940b97b JS |
7191 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) { |
7192 | spin_unlock_irqrestore(&phba->hbalock, | |
7193 | drvr_flag); | |
7194 | goto out_not_finished; | |
7195 | } | |
dea3101e | 7196 | } |
7197 | ||
3772a991 | 7198 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
dea3101e | 7199 | /* copy results back to user */ |
bf07bdea | 7200 | lpfc_sli_pcimem_bcopy(phba->mbox, mbx, MAILBOX_CMD_SIZE); |
7a470277 JS |
7201 | /* Copy the mailbox extension data */ |
7202 | if (pmbox->out_ext_byte_len && pmbox->context2) { | |
7203 | lpfc_sli_pcimem_bcopy(phba->mbox_ext, | |
7204 | pmbox->context2, | |
7205 | pmbox->out_ext_byte_len); | |
7206 | } | |
dea3101e | 7207 | } else { |
7208 | /* First copy command data */ | |
bf07bdea | 7209 | lpfc_memcpy_from_slim(mbx, phba->MBslimaddr, |
dea3101e | 7210 | MAILBOX_CMD_SIZE); |
7a470277 JS |
7211 | /* Copy the mailbox extension data */ |
7212 | if (pmbox->out_ext_byte_len && pmbox->context2) { | |
7213 | lpfc_memcpy_from_slim(pmbox->context2, | |
7214 | phba->MBslimaddr + | |
7215 | MAILBOX_HBA_EXT_OFFSET, | |
7216 | pmbox->out_ext_byte_len); | |
dea3101e | 7217 | } |
7218 | } | |
7219 | ||
7220 | writel(HA_MBATT, phba->HAregaddr); | |
7221 | readl(phba->HAregaddr); /* flush */ | |
7222 | ||
7223 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
bf07bdea | 7224 | status = mbx->mbxStatus; |
dea3101e | 7225 | } |
7226 | ||
2e0fef85 JS |
7227 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
7228 | return status; | |
58da1ffb JS |
7229 | |
7230 | out_not_finished: | |
7231 | if (processing_queue) { | |
da0436e9 | 7232 | pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED; |
58da1ffb JS |
7233 | lpfc_mbox_cmpl_put(phba, pmbox); |
7234 | } | |
7235 | return MBX_NOT_FINISHED; | |
dea3101e | 7236 | } |
7237 | ||
f1126688 JS |
7238 | /** |
7239 | * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command | |
7240 | * @phba: Pointer to HBA context object. | |
7241 | * | |
7242 | * The function blocks the posting of SLI4 asynchronous mailbox commands from | |
7243 | * the driver internal pending mailbox queue. It will then try to wait out the | |
7244 | * possible outstanding mailbox command before return. | |
7245 | * | |
7246 | * Returns: | |
7247 | * 0 - the outstanding mailbox command completed; otherwise, the wait for | |
7248 | * the outstanding mailbox command timed out. | |
7249 | **/ | |
7250 | static int | |
7251 | lpfc_sli4_async_mbox_block(struct lpfc_hba *phba) | |
7252 | { | |
7253 | struct lpfc_sli *psli = &phba->sli; | |
f1126688 | 7254 | int rc = 0; |
a183a15f | 7255 | unsigned long timeout = 0; |
f1126688 JS |
7256 | |
7257 | /* Mark the asynchronous mailbox command posting as blocked */ | |
7258 | spin_lock_irq(&phba->hbalock); | |
7259 | psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; | |
f1126688 JS |
7260 | /* Determine how long we might wait for the active mailbox |
7261 | * command to be gracefully completed by firmware. | |
7262 | */ | |
a183a15f JS |
7263 | if (phba->sli.mbox_active) |
7264 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, | |
7265 | phba->sli.mbox_active) * | |
7266 | 1000) + jiffies; | |
7267 | spin_unlock_irq(&phba->hbalock); | |
7268 | ||
e8d3c3b1 JS |
7269 | /* Make sure the mailbox is really active */ |
7270 | if (timeout) | |
7271 | lpfc_sli4_process_missed_mbox_completions(phba); | |
7272 | ||
f1126688 JS |
7273 | /* Wait for the outstnading mailbox command to complete */ |
7274 | while (phba->sli.mbox_active) { | |
7275 | /* Check active mailbox complete status every 2ms */ | |
7276 | msleep(2); | |
7277 | if (time_after(jiffies, timeout)) { | |
7278 | /* Timeout, marked the outstanding cmd not complete */ | |
7279 | rc = 1; | |
7280 | break; | |
7281 | } | |
7282 | } | |
7283 | ||
7284 | /* Can not cleanly block async mailbox command, fails it */ | |
7285 | if (rc) { | |
7286 | spin_lock_irq(&phba->hbalock); | |
7287 | psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; | |
7288 | spin_unlock_irq(&phba->hbalock); | |
7289 | } | |
7290 | return rc; | |
7291 | } | |
7292 | ||
7293 | /** | |
7294 | * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command | |
7295 | * @phba: Pointer to HBA context object. | |
7296 | * | |
7297 | * The function unblocks and resume posting of SLI4 asynchronous mailbox | |
7298 | * commands from the driver internal pending mailbox queue. It makes sure | |
7299 | * that there is no outstanding mailbox command before resuming posting | |
7300 | * asynchronous mailbox commands. If, for any reason, there is outstanding | |
7301 | * mailbox command, it will try to wait it out before resuming asynchronous | |
7302 | * mailbox command posting. | |
7303 | **/ | |
7304 | static void | |
7305 | lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba) | |
7306 | { | |
7307 | struct lpfc_sli *psli = &phba->sli; | |
7308 | ||
7309 | spin_lock_irq(&phba->hbalock); | |
7310 | if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { | |
7311 | /* Asynchronous mailbox posting is not blocked, do nothing */ | |
7312 | spin_unlock_irq(&phba->hbalock); | |
7313 | return; | |
7314 | } | |
7315 | ||
7316 | /* Outstanding synchronous mailbox command is guaranteed to be done, | |
7317 | * successful or timeout, after timing-out the outstanding mailbox | |
7318 | * command shall always be removed, so just unblock posting async | |
7319 | * mailbox command and resume | |
7320 | */ | |
7321 | psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; | |
7322 | spin_unlock_irq(&phba->hbalock); | |
7323 | ||
7324 | /* wake up worker thread to post asynchronlous mailbox command */ | |
7325 | lpfc_worker_wake_up(phba); | |
7326 | } | |
7327 | ||
2d843edc JS |
7328 | /** |
7329 | * lpfc_sli4_wait_bmbx_ready - Wait for bootstrap mailbox register ready | |
7330 | * @phba: Pointer to HBA context object. | |
7331 | * @mboxq: Pointer to mailbox object. | |
7332 | * | |
7333 | * The function waits for the bootstrap mailbox register ready bit from | |
7334 | * port for twice the regular mailbox command timeout value. | |
7335 | * | |
7336 | * 0 - no timeout on waiting for bootstrap mailbox register ready. | |
7337 | * MBXERR_ERROR - wait for bootstrap mailbox register timed out. | |
7338 | **/ | |
7339 | static int | |
7340 | lpfc_sli4_wait_bmbx_ready(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) | |
7341 | { | |
7342 | uint32_t db_ready; | |
7343 | unsigned long timeout; | |
7344 | struct lpfc_register bmbx_reg; | |
7345 | ||
7346 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mboxq) | |
7347 | * 1000) + jiffies; | |
7348 | ||
7349 | do { | |
7350 | bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr); | |
7351 | db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg); | |
7352 | if (!db_ready) | |
7353 | msleep(2); | |
7354 | ||
7355 | if (time_after(jiffies, timeout)) | |
7356 | return MBXERR_ERROR; | |
7357 | } while (!db_ready); | |
7358 | ||
7359 | return 0; | |
7360 | } | |
7361 | ||
da0436e9 JS |
7362 | /** |
7363 | * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox | |
7364 | * @phba: Pointer to HBA context object. | |
7365 | * @mboxq: Pointer to mailbox object. | |
7366 | * | |
7367 | * The function posts a mailbox to the port. The mailbox is expected | |
7368 | * to be comletely filled in and ready for the port to operate on it. | |
7369 | * This routine executes a synchronous completion operation on the | |
7370 | * mailbox by polling for its completion. | |
7371 | * | |
7372 | * The caller must not be holding any locks when calling this routine. | |
7373 | * | |
7374 | * Returns: | |
7375 | * MBX_SUCCESS - mailbox posted successfully | |
7376 | * Any of the MBX error values. | |
7377 | **/ | |
7378 | static int | |
7379 | lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) | |
7380 | { | |
7381 | int rc = MBX_SUCCESS; | |
7382 | unsigned long iflag; | |
da0436e9 JS |
7383 | uint32_t mcqe_status; |
7384 | uint32_t mbx_cmnd; | |
da0436e9 JS |
7385 | struct lpfc_sli *psli = &phba->sli; |
7386 | struct lpfc_mqe *mb = &mboxq->u.mqe; | |
7387 | struct lpfc_bmbx_create *mbox_rgn; | |
7388 | struct dma_address *dma_address; | |
da0436e9 JS |
7389 | |
7390 | /* | |
7391 | * Only one mailbox can be active to the bootstrap mailbox region | |
7392 | * at a time and there is no queueing provided. | |
7393 | */ | |
7394 | spin_lock_irqsave(&phba->hbalock, iflag); | |
7395 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { | |
7396 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
7397 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
a183a15f | 7398 | "(%d):2532 Mailbox command x%x (x%x/x%x) " |
da0436e9 JS |
7399 | "cannot issue Data: x%x x%x\n", |
7400 | mboxq->vport ? mboxq->vport->vpi : 0, | |
7401 | mboxq->u.mb.mbxCommand, | |
a183a15f JS |
7402 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
7403 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), | |
da0436e9 JS |
7404 | psli->sli_flag, MBX_POLL); |
7405 | return MBXERR_ERROR; | |
7406 | } | |
7407 | /* The server grabs the token and owns it until release */ | |
7408 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; | |
7409 | phba->sli.mbox_active = mboxq; | |
7410 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
7411 | ||
2d843edc JS |
7412 | /* wait for bootstrap mbox register for readyness */ |
7413 | rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq); | |
7414 | if (rc) | |
7415 | goto exit; | |
7416 | ||
da0436e9 JS |
7417 | /* |
7418 | * Initialize the bootstrap memory region to avoid stale data areas | |
7419 | * in the mailbox post. Then copy the caller's mailbox contents to | |
7420 | * the bmbx mailbox region. | |
7421 | */ | |
7422 | mbx_cmnd = bf_get(lpfc_mqe_command, mb); | |
7423 | memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create)); | |
7424 | lpfc_sli_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt, | |
7425 | sizeof(struct lpfc_mqe)); | |
7426 | ||
7427 | /* Post the high mailbox dma address to the port and wait for ready. */ | |
7428 | dma_address = &phba->sli4_hba.bmbx.dma_address; | |
7429 | writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr); | |
7430 | ||
2d843edc JS |
7431 | /* wait for bootstrap mbox register for hi-address write done */ |
7432 | rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq); | |
7433 | if (rc) | |
7434 | goto exit; | |
da0436e9 JS |
7435 | |
7436 | /* Post the low mailbox dma address to the port. */ | |
7437 | writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr); | |
da0436e9 | 7438 | |
2d843edc JS |
7439 | /* wait for bootstrap mbox register for low address write done */ |
7440 | rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq); | |
7441 | if (rc) | |
7442 | goto exit; | |
da0436e9 JS |
7443 | |
7444 | /* | |
7445 | * Read the CQ to ensure the mailbox has completed. | |
7446 | * If so, update the mailbox status so that the upper layers | |
7447 | * can complete the request normally. | |
7448 | */ | |
7449 | lpfc_sli_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb, | |
7450 | sizeof(struct lpfc_mqe)); | |
7451 | mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt; | |
7452 | lpfc_sli_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe, | |
7453 | sizeof(struct lpfc_mcqe)); | |
7454 | mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe); | |
0558056c JS |
7455 | /* |
7456 | * When the CQE status indicates a failure and the mailbox status | |
7457 | * indicates success then copy the CQE status into the mailbox status | |
7458 | * (and prefix it with x4000). | |
7459 | */ | |
da0436e9 | 7460 | if (mcqe_status != MB_CQE_STATUS_SUCCESS) { |
0558056c JS |
7461 | if (bf_get(lpfc_mqe_status, mb) == MBX_SUCCESS) |
7462 | bf_set(lpfc_mqe_status, mb, | |
7463 | (LPFC_MBX_ERROR_RANGE | mcqe_status)); | |
da0436e9 | 7464 | rc = MBXERR_ERROR; |
d7c47992 JS |
7465 | } else |
7466 | lpfc_sli4_swap_str(phba, mboxq); | |
da0436e9 JS |
7467 | |
7468 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, | |
a183a15f | 7469 | "(%d):0356 Mailbox cmd x%x (x%x/x%x) Status x%x " |
da0436e9 JS |
7470 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x" |
7471 | " x%x x%x CQ: x%x x%x x%x x%x\n", | |
a183a15f JS |
7472 | mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd, |
7473 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), | |
7474 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), | |
da0436e9 JS |
7475 | bf_get(lpfc_mqe_status, mb), |
7476 | mb->un.mb_words[0], mb->un.mb_words[1], | |
7477 | mb->un.mb_words[2], mb->un.mb_words[3], | |
7478 | mb->un.mb_words[4], mb->un.mb_words[5], | |
7479 | mb->un.mb_words[6], mb->un.mb_words[7], | |
7480 | mb->un.mb_words[8], mb->un.mb_words[9], | |
7481 | mb->un.mb_words[10], mb->un.mb_words[11], | |
7482 | mb->un.mb_words[12], mboxq->mcqe.word0, | |
7483 | mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1, | |
7484 | mboxq->mcqe.trailer); | |
7485 | exit: | |
7486 | /* We are holding the token, no needed for lock when release */ | |
7487 | spin_lock_irqsave(&phba->hbalock, iflag); | |
7488 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
7489 | phba->sli.mbox_active = NULL; | |
7490 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
7491 | return rc; | |
7492 | } | |
7493 | ||
7494 | /** | |
7495 | * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware | |
7496 | * @phba: Pointer to HBA context object. | |
7497 | * @pmbox: Pointer to mailbox object. | |
7498 | * @flag: Flag indicating how the mailbox need to be processed. | |
7499 | * | |
7500 | * This function is called by discovery code and HBA management code to submit | |
7501 | * a mailbox command to firmware with SLI-4 interface spec. | |
7502 | * | |
7503 | * Return codes the caller owns the mailbox command after the return of the | |
7504 | * function. | |
7505 | **/ | |
7506 | static int | |
7507 | lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, | |
7508 | uint32_t flag) | |
7509 | { | |
7510 | struct lpfc_sli *psli = &phba->sli; | |
7511 | unsigned long iflags; | |
7512 | int rc; | |
7513 | ||
b76f2dc9 JS |
7514 | /* dump from issue mailbox command if setup */ |
7515 | lpfc_idiag_mbxacc_dump_issue_mbox(phba, &mboxq->u.mb); | |
7516 | ||
8fa38513 JS |
7517 | rc = lpfc_mbox_dev_check(phba); |
7518 | if (unlikely(rc)) { | |
7519 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
a183a15f | 7520 | "(%d):2544 Mailbox command x%x (x%x/x%x) " |
8fa38513 JS |
7521 | "cannot issue Data: x%x x%x\n", |
7522 | mboxq->vport ? mboxq->vport->vpi : 0, | |
7523 | mboxq->u.mb.mbxCommand, | |
a183a15f JS |
7524 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
7525 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), | |
8fa38513 JS |
7526 | psli->sli_flag, flag); |
7527 | goto out_not_finished; | |
7528 | } | |
7529 | ||
da0436e9 JS |
7530 | /* Detect polling mode and jump to a handler */ |
7531 | if (!phba->sli4_hba.intr_enable) { | |
7532 | if (flag == MBX_POLL) | |
7533 | rc = lpfc_sli4_post_sync_mbox(phba, mboxq); | |
7534 | else | |
7535 | rc = -EIO; | |
7536 | if (rc != MBX_SUCCESS) | |
0558056c | 7537 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
da0436e9 | 7538 | "(%d):2541 Mailbox command x%x " |
cc459f19 JS |
7539 | "(x%x/x%x) failure: " |
7540 | "mqe_sta: x%x mcqe_sta: x%x/x%x " | |
7541 | "Data: x%x x%x\n,", | |
da0436e9 JS |
7542 | mboxq->vport ? mboxq->vport->vpi : 0, |
7543 | mboxq->u.mb.mbxCommand, | |
a183a15f JS |
7544 | lpfc_sli_config_mbox_subsys_get(phba, |
7545 | mboxq), | |
7546 | lpfc_sli_config_mbox_opcode_get(phba, | |
7547 | mboxq), | |
cc459f19 JS |
7548 | bf_get(lpfc_mqe_status, &mboxq->u.mqe), |
7549 | bf_get(lpfc_mcqe_status, &mboxq->mcqe), | |
7550 | bf_get(lpfc_mcqe_ext_status, | |
7551 | &mboxq->mcqe), | |
da0436e9 JS |
7552 | psli->sli_flag, flag); |
7553 | return rc; | |
7554 | } else if (flag == MBX_POLL) { | |
f1126688 JS |
7555 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
7556 | "(%d):2542 Try to issue mailbox command " | |
a183a15f | 7557 | "x%x (x%x/x%x) synchronously ahead of async" |
f1126688 | 7558 | "mailbox command queue: x%x x%x\n", |
da0436e9 JS |
7559 | mboxq->vport ? mboxq->vport->vpi : 0, |
7560 | mboxq->u.mb.mbxCommand, | |
a183a15f JS |
7561 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
7562 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), | |
da0436e9 | 7563 | psli->sli_flag, flag); |
f1126688 JS |
7564 | /* Try to block the asynchronous mailbox posting */ |
7565 | rc = lpfc_sli4_async_mbox_block(phba); | |
7566 | if (!rc) { | |
7567 | /* Successfully blocked, now issue sync mbox cmd */ | |
7568 | rc = lpfc_sli4_post_sync_mbox(phba, mboxq); | |
7569 | if (rc != MBX_SUCCESS) | |
cc459f19 | 7570 | lpfc_printf_log(phba, KERN_WARNING, |
a183a15f | 7571 | LOG_MBOX | LOG_SLI, |
cc459f19 JS |
7572 | "(%d):2597 Sync Mailbox command " |
7573 | "x%x (x%x/x%x) failure: " | |
7574 | "mqe_sta: x%x mcqe_sta: x%x/x%x " | |
7575 | "Data: x%x x%x\n,", | |
7576 | mboxq->vport ? mboxq->vport->vpi : 0, | |
a183a15f JS |
7577 | mboxq->u.mb.mbxCommand, |
7578 | lpfc_sli_config_mbox_subsys_get(phba, | |
7579 | mboxq), | |
7580 | lpfc_sli_config_mbox_opcode_get(phba, | |
7581 | mboxq), | |
cc459f19 JS |
7582 | bf_get(lpfc_mqe_status, &mboxq->u.mqe), |
7583 | bf_get(lpfc_mcqe_status, &mboxq->mcqe), | |
7584 | bf_get(lpfc_mcqe_ext_status, | |
7585 | &mboxq->mcqe), | |
a183a15f | 7586 | psli->sli_flag, flag); |
f1126688 JS |
7587 | /* Unblock the async mailbox posting afterward */ |
7588 | lpfc_sli4_async_mbox_unblock(phba); | |
7589 | } | |
7590 | return rc; | |
da0436e9 JS |
7591 | } |
7592 | ||
7593 | /* Now, interrupt mode asynchrous mailbox command */ | |
7594 | rc = lpfc_mbox_cmd_check(phba, mboxq); | |
7595 | if (rc) { | |
7596 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
a183a15f | 7597 | "(%d):2543 Mailbox command x%x (x%x/x%x) " |
da0436e9 JS |
7598 | "cannot issue Data: x%x x%x\n", |
7599 | mboxq->vport ? mboxq->vport->vpi : 0, | |
7600 | mboxq->u.mb.mbxCommand, | |
a183a15f JS |
7601 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
7602 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), | |
da0436e9 JS |
7603 | psli->sli_flag, flag); |
7604 | goto out_not_finished; | |
7605 | } | |
da0436e9 JS |
7606 | |
7607 | /* Put the mailbox command to the driver internal FIFO */ | |
7608 | psli->slistat.mbox_busy++; | |
7609 | spin_lock_irqsave(&phba->hbalock, iflags); | |
7610 | lpfc_mbox_put(phba, mboxq); | |
7611 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
7612 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, | |
7613 | "(%d):0354 Mbox cmd issue - Enqueue Data: " | |
a183a15f | 7614 | "x%x (x%x/x%x) x%x x%x x%x\n", |
da0436e9 JS |
7615 | mboxq->vport ? mboxq->vport->vpi : 0xffffff, |
7616 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), | |
a183a15f JS |
7617 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
7618 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), | |
da0436e9 JS |
7619 | phba->pport->port_state, |
7620 | psli->sli_flag, MBX_NOWAIT); | |
7621 | /* Wake up worker thread to transport mailbox command from head */ | |
7622 | lpfc_worker_wake_up(phba); | |
7623 | ||
7624 | return MBX_BUSY; | |
7625 | ||
7626 | out_not_finished: | |
7627 | return MBX_NOT_FINISHED; | |
7628 | } | |
7629 | ||
7630 | /** | |
7631 | * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device | |
7632 | * @phba: Pointer to HBA context object. | |
7633 | * | |
7634 | * This function is called by worker thread to send a mailbox command to | |
7635 | * SLI4 HBA firmware. | |
7636 | * | |
7637 | **/ | |
7638 | int | |
7639 | lpfc_sli4_post_async_mbox(struct lpfc_hba *phba) | |
7640 | { | |
7641 | struct lpfc_sli *psli = &phba->sli; | |
7642 | LPFC_MBOXQ_t *mboxq; | |
7643 | int rc = MBX_SUCCESS; | |
7644 | unsigned long iflags; | |
7645 | struct lpfc_mqe *mqe; | |
7646 | uint32_t mbx_cmnd; | |
7647 | ||
7648 | /* Check interrupt mode before post async mailbox command */ | |
7649 | if (unlikely(!phba->sli4_hba.intr_enable)) | |
7650 | return MBX_NOT_FINISHED; | |
7651 | ||
7652 | /* Check for mailbox command service token */ | |
7653 | spin_lock_irqsave(&phba->hbalock, iflags); | |
7654 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { | |
7655 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
7656 | return MBX_NOT_FINISHED; | |
7657 | } | |
7658 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { | |
7659 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
7660 | return MBX_NOT_FINISHED; | |
7661 | } | |
7662 | if (unlikely(phba->sli.mbox_active)) { | |
7663 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
7664 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
7665 | "0384 There is pending active mailbox cmd\n"); | |
7666 | return MBX_NOT_FINISHED; | |
7667 | } | |
7668 | /* Take the mailbox command service token */ | |
7669 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; | |
7670 | ||
7671 | /* Get the next mailbox command from head of queue */ | |
7672 | mboxq = lpfc_mbox_get(phba); | |
7673 | ||
7674 | /* If no more mailbox command waiting for post, we're done */ | |
7675 | if (!mboxq) { | |
7676 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
7677 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
7678 | return MBX_SUCCESS; | |
7679 | } | |
7680 | phba->sli.mbox_active = mboxq; | |
7681 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
7682 | ||
7683 | /* Check device readiness for posting mailbox command */ | |
7684 | rc = lpfc_mbox_dev_check(phba); | |
7685 | if (unlikely(rc)) | |
7686 | /* Driver clean routine will clean up pending mailbox */ | |
7687 | goto out_not_finished; | |
7688 | ||
7689 | /* Prepare the mbox command to be posted */ | |
7690 | mqe = &mboxq->u.mqe; | |
7691 | mbx_cmnd = bf_get(lpfc_mqe_command, mqe); | |
7692 | ||
7693 | /* Start timer for the mbox_tmo and log some mailbox post messages */ | |
7694 | mod_timer(&psli->mbox_tmo, (jiffies + | |
256ec0d0 | 7695 | msecs_to_jiffies(1000 * lpfc_mbox_tmo_val(phba, mboxq)))); |
da0436e9 JS |
7696 | |
7697 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, | |
a183a15f | 7698 | "(%d):0355 Mailbox cmd x%x (x%x/x%x) issue Data: " |
da0436e9 JS |
7699 | "x%x x%x\n", |
7700 | mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd, | |
a183a15f JS |
7701 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
7702 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), | |
da0436e9 JS |
7703 | phba->pport->port_state, psli->sli_flag); |
7704 | ||
7705 | if (mbx_cmnd != MBX_HEARTBEAT) { | |
7706 | if (mboxq->vport) { | |
7707 | lpfc_debugfs_disc_trc(mboxq->vport, | |
7708 | LPFC_DISC_TRC_MBOX_VPORT, | |
7709 | "MBOX Send vport: cmd:x%x mb:x%x x%x", | |
7710 | mbx_cmnd, mqe->un.mb_words[0], | |
7711 | mqe->un.mb_words[1]); | |
7712 | } else { | |
7713 | lpfc_debugfs_disc_trc(phba->pport, | |
7714 | LPFC_DISC_TRC_MBOX, | |
7715 | "MBOX Send: cmd:x%x mb:x%x x%x", | |
7716 | mbx_cmnd, mqe->un.mb_words[0], | |
7717 | mqe->un.mb_words[1]); | |
7718 | } | |
7719 | } | |
7720 | psli->slistat.mbox_cmd++; | |
7721 | ||
7722 | /* Post the mailbox command to the port */ | |
7723 | rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe); | |
7724 | if (rc != MBX_SUCCESS) { | |
7725 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
a183a15f | 7726 | "(%d):2533 Mailbox command x%x (x%x/x%x) " |
da0436e9 JS |
7727 | "cannot issue Data: x%x x%x\n", |
7728 | mboxq->vport ? mboxq->vport->vpi : 0, | |
7729 | mboxq->u.mb.mbxCommand, | |
a183a15f JS |
7730 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
7731 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), | |
da0436e9 JS |
7732 | psli->sli_flag, MBX_NOWAIT); |
7733 | goto out_not_finished; | |
7734 | } | |
7735 | ||
7736 | return rc; | |
7737 | ||
7738 | out_not_finished: | |
7739 | spin_lock_irqsave(&phba->hbalock, iflags); | |
d7069f09 JS |
7740 | if (phba->sli.mbox_active) { |
7741 | mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED; | |
7742 | __lpfc_mbox_cmpl_put(phba, mboxq); | |
7743 | /* Release the token */ | |
7744 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
7745 | phba->sli.mbox_active = NULL; | |
7746 | } | |
da0436e9 JS |
7747 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
7748 | ||
7749 | return MBX_NOT_FINISHED; | |
7750 | } | |
7751 | ||
7752 | /** | |
7753 | * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command | |
7754 | * @phba: Pointer to HBA context object. | |
7755 | * @pmbox: Pointer to mailbox object. | |
7756 | * @flag: Flag indicating how the mailbox need to be processed. | |
7757 | * | |
7758 | * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from | |
7759 | * the API jump table function pointer from the lpfc_hba struct. | |
7760 | * | |
7761 | * Return codes the caller owns the mailbox command after the return of the | |
7762 | * function. | |
7763 | **/ | |
7764 | int | |
7765 | lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag) | |
7766 | { | |
7767 | return phba->lpfc_sli_issue_mbox(phba, pmbox, flag); | |
7768 | } | |
7769 | ||
7770 | /** | |
25985edc | 7771 | * lpfc_mbox_api_table_setup - Set up mbox api function jump table |
da0436e9 JS |
7772 | * @phba: The hba struct for which this call is being executed. |
7773 | * @dev_grp: The HBA PCI-Device group number. | |
7774 | * | |
7775 | * This routine sets up the mbox interface API function jump table in @phba | |
7776 | * struct. | |
7777 | * Returns: 0 - success, -ENODEV - failure. | |
7778 | **/ | |
7779 | int | |
7780 | lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) | |
7781 | { | |
7782 | ||
7783 | switch (dev_grp) { | |
7784 | case LPFC_PCI_DEV_LP: | |
7785 | phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3; | |
7786 | phba->lpfc_sli_handle_slow_ring_event = | |
7787 | lpfc_sli_handle_slow_ring_event_s3; | |
7788 | phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3; | |
7789 | phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3; | |
7790 | phba->lpfc_sli_brdready = lpfc_sli_brdready_s3; | |
7791 | break; | |
7792 | case LPFC_PCI_DEV_OC: | |
7793 | phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4; | |
7794 | phba->lpfc_sli_handle_slow_ring_event = | |
7795 | lpfc_sli_handle_slow_ring_event_s4; | |
7796 | phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4; | |
7797 | phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4; | |
7798 | phba->lpfc_sli_brdready = lpfc_sli_brdready_s4; | |
7799 | break; | |
7800 | default: | |
7801 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7802 | "1420 Invalid HBA PCI-device group: 0x%x\n", | |
7803 | dev_grp); | |
7804 | return -ENODEV; | |
7805 | break; | |
7806 | } | |
7807 | return 0; | |
7808 | } | |
7809 | ||
e59058c4 | 7810 | /** |
3621a710 | 7811 | * __lpfc_sli_ringtx_put - Add an iocb to the txq |
e59058c4 JS |
7812 | * @phba: Pointer to HBA context object. |
7813 | * @pring: Pointer to driver SLI ring object. | |
7814 | * @piocb: Pointer to address of newly added command iocb. | |
7815 | * | |
7816 | * This function is called with hbalock held to add a command | |
7817 | * iocb to the txq when SLI layer cannot submit the command iocb | |
7818 | * to the ring. | |
7819 | **/ | |
2a9bf3d0 | 7820 | void |
92d7f7b0 | 7821 | __lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
2e0fef85 | 7822 | struct lpfc_iocbq *piocb) |
dea3101e | 7823 | { |
7824 | /* Insert the caller's iocb in the txq tail for later processing. */ | |
7825 | list_add_tail(&piocb->list, &pring->txq); | |
dea3101e | 7826 | } |
7827 | ||
e59058c4 | 7828 | /** |
3621a710 | 7829 | * lpfc_sli_next_iocb - Get the next iocb in the txq |
e59058c4 JS |
7830 | * @phba: Pointer to HBA context object. |
7831 | * @pring: Pointer to driver SLI ring object. | |
7832 | * @piocb: Pointer to address of newly added command iocb. | |
7833 | * | |
7834 | * This function is called with hbalock held before a new | |
7835 | * iocb is submitted to the firmware. This function checks | |
7836 | * txq to flush the iocbs in txq to Firmware before | |
7837 | * submitting new iocbs to the Firmware. | |
7838 | * If there are iocbs in the txq which need to be submitted | |
7839 | * to firmware, lpfc_sli_next_iocb returns the first element | |
7840 | * of the txq after dequeuing it from txq. | |
7841 | * If there is no iocb in the txq then the function will return | |
7842 | * *piocb and *piocb is set to NULL. Caller needs to check | |
7843 | * *piocb to find if there are more commands in the txq. | |
7844 | **/ | |
dea3101e | 7845 | static struct lpfc_iocbq * |
7846 | lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
2e0fef85 | 7847 | struct lpfc_iocbq **piocb) |
dea3101e | 7848 | { |
7849 | struct lpfc_iocbq * nextiocb; | |
7850 | ||
7851 | nextiocb = lpfc_sli_ringtx_get(phba, pring); | |
7852 | if (!nextiocb) { | |
7853 | nextiocb = *piocb; | |
7854 | *piocb = NULL; | |
7855 | } | |
7856 | ||
7857 | return nextiocb; | |
7858 | } | |
7859 | ||
e59058c4 | 7860 | /** |
3772a991 | 7861 | * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb |
e59058c4 | 7862 | * @phba: Pointer to HBA context object. |
3772a991 | 7863 | * @ring_number: SLI ring number to issue iocb on. |
e59058c4 JS |
7864 | * @piocb: Pointer to command iocb. |
7865 | * @flag: Flag indicating if this command can be put into txq. | |
7866 | * | |
3772a991 JS |
7867 | * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue |
7868 | * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is | |
7869 | * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT | |
7870 | * flag is turned on, the function returns IOCB_ERROR. When the link is down, | |
7871 | * this function allows only iocbs for posting buffers. This function finds | |
7872 | * next available slot in the command ring and posts the command to the | |
7873 | * available slot and writes the port attention register to request HBA start | |
7874 | * processing new iocb. If there is no slot available in the ring and | |
7875 | * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise | |
7876 | * the function returns IOCB_BUSY. | |
e59058c4 | 7877 | * |
3772a991 JS |
7878 | * This function is called with hbalock held. The function will return success |
7879 | * after it successfully submit the iocb to firmware or after adding to the | |
7880 | * txq. | |
e59058c4 | 7881 | **/ |
98c9ea5c | 7882 | static int |
3772a991 | 7883 | __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number, |
dea3101e | 7884 | struct lpfc_iocbq *piocb, uint32_t flag) |
7885 | { | |
7886 | struct lpfc_iocbq *nextiocb; | |
7887 | IOCB_t *iocb; | |
3772a991 | 7888 | struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number]; |
dea3101e | 7889 | |
92d7f7b0 JS |
7890 | if (piocb->iocb_cmpl && (!piocb->vport) && |
7891 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && | |
7892 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { | |
7893 | lpfc_printf_log(phba, KERN_ERR, | |
7894 | LOG_SLI | LOG_VPORT, | |
e8b62011 | 7895 | "1807 IOCB x%x failed. No vport\n", |
92d7f7b0 JS |
7896 | piocb->iocb.ulpCommand); |
7897 | dump_stack(); | |
7898 | return IOCB_ERROR; | |
7899 | } | |
7900 | ||
7901 | ||
8d63f375 LV |
7902 | /* If the PCI channel is in offline state, do not post iocbs. */ |
7903 | if (unlikely(pci_channel_offline(phba->pcidev))) | |
7904 | return IOCB_ERROR; | |
7905 | ||
a257bf90 JS |
7906 | /* If HBA has a deferred error attention, fail the iocb. */ |
7907 | if (unlikely(phba->hba_flag & DEFER_ERATT)) | |
7908 | return IOCB_ERROR; | |
7909 | ||
dea3101e | 7910 | /* |
7911 | * We should never get an IOCB if we are in a < LINK_DOWN state | |
7912 | */ | |
2e0fef85 | 7913 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
dea3101e | 7914 | return IOCB_ERROR; |
7915 | ||
7916 | /* | |
7917 | * Check to see if we are blocking IOCB processing because of a | |
0b727fea | 7918 | * outstanding event. |
dea3101e | 7919 | */ |
0b727fea | 7920 | if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT)) |
dea3101e | 7921 | goto iocb_busy; |
7922 | ||
2e0fef85 | 7923 | if (unlikely(phba->link_state == LPFC_LINK_DOWN)) { |
dea3101e | 7924 | /* |
2680eeaa | 7925 | * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF |
dea3101e | 7926 | * can be issued if the link is not up. |
7927 | */ | |
7928 | switch (piocb->iocb.ulpCommand) { | |
84774a4d JS |
7929 | case CMD_GEN_REQUEST64_CR: |
7930 | case CMD_GEN_REQUEST64_CX: | |
7931 | if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) || | |
7932 | (piocb->iocb.un.genreq64.w5.hcsw.Rctl != | |
6a9c52cf | 7933 | FC_RCTL_DD_UNSOL_CMD) || |
84774a4d JS |
7934 | (piocb->iocb.un.genreq64.w5.hcsw.Type != |
7935 | MENLO_TRANSPORT_TYPE)) | |
7936 | ||
7937 | goto iocb_busy; | |
7938 | break; | |
dea3101e | 7939 | case CMD_QUE_RING_BUF_CN: |
7940 | case CMD_QUE_RING_BUF64_CN: | |
dea3101e | 7941 | /* |
7942 | * For IOCBs, like QUE_RING_BUF, that have no rsp ring | |
7943 | * completion, iocb_cmpl MUST be 0. | |
7944 | */ | |
7945 | if (piocb->iocb_cmpl) | |
7946 | piocb->iocb_cmpl = NULL; | |
7947 | /*FALLTHROUGH*/ | |
7948 | case CMD_CREATE_XRI_CR: | |
2680eeaa JS |
7949 | case CMD_CLOSE_XRI_CN: |
7950 | case CMD_CLOSE_XRI_CX: | |
dea3101e | 7951 | break; |
7952 | default: | |
7953 | goto iocb_busy; | |
7954 | } | |
7955 | ||
7956 | /* | |
7957 | * For FCP commands, we must be in a state where we can process link | |
7958 | * attention events. | |
7959 | */ | |
7960 | } else if (unlikely(pring->ringno == phba->sli.fcp_ring && | |
92d7f7b0 | 7961 | !(phba->sli.sli_flag & LPFC_PROCESS_LA))) { |
dea3101e | 7962 | goto iocb_busy; |
92d7f7b0 | 7963 | } |
dea3101e | 7964 | |
dea3101e | 7965 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && |
7966 | (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb))) | |
7967 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); | |
7968 | ||
7969 | if (iocb) | |
7970 | lpfc_sli_update_ring(phba, pring); | |
7971 | else | |
7972 | lpfc_sli_update_full_ring(phba, pring); | |
7973 | ||
7974 | if (!piocb) | |
7975 | return IOCB_SUCCESS; | |
7976 | ||
7977 | goto out_busy; | |
7978 | ||
7979 | iocb_busy: | |
7980 | pring->stats.iocb_cmd_delay++; | |
7981 | ||
7982 | out_busy: | |
7983 | ||
7984 | if (!(flag & SLI_IOCB_RET_IOCB)) { | |
92d7f7b0 | 7985 | __lpfc_sli_ringtx_put(phba, pring, piocb); |
dea3101e | 7986 | return IOCB_SUCCESS; |
7987 | } | |
7988 | ||
7989 | return IOCB_BUSY; | |
7990 | } | |
7991 | ||
3772a991 | 7992 | /** |
4f774513 JS |
7993 | * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl. |
7994 | * @phba: Pointer to HBA context object. | |
7995 | * @piocb: Pointer to command iocb. | |
7996 | * @sglq: Pointer to the scatter gather queue object. | |
7997 | * | |
7998 | * This routine converts the bpl or bde that is in the IOCB | |
7999 | * to a sgl list for the sli4 hardware. The physical address | |
8000 | * of the bpl/bde is converted back to a virtual address. | |
8001 | * If the IOCB contains a BPL then the list of BDE's is | |
8002 | * converted to sli4_sge's. If the IOCB contains a single | |
8003 | * BDE then it is converted to a single sli_sge. | |
8004 | * The IOCB is still in cpu endianess so the contents of | |
8005 | * the bpl can be used without byte swapping. | |
8006 | * | |
8007 | * Returns valid XRI = Success, NO_XRI = Failure. | |
8008 | **/ | |
8009 | static uint16_t | |
8010 | lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq, | |
8011 | struct lpfc_sglq *sglq) | |
3772a991 | 8012 | { |
4f774513 JS |
8013 | uint16_t xritag = NO_XRI; |
8014 | struct ulp_bde64 *bpl = NULL; | |
8015 | struct ulp_bde64 bde; | |
8016 | struct sli4_sge *sgl = NULL; | |
1b51197d | 8017 | struct lpfc_dmabuf *dmabuf; |
4f774513 JS |
8018 | IOCB_t *icmd; |
8019 | int numBdes = 0; | |
8020 | int i = 0; | |
63e801ce JS |
8021 | uint32_t offset = 0; /* accumulated offset in the sg request list */ |
8022 | int inbound = 0; /* number of sg reply entries inbound from firmware */ | |
3772a991 | 8023 | |
4f774513 JS |
8024 | if (!piocbq || !sglq) |
8025 | return xritag; | |
8026 | ||
8027 | sgl = (struct sli4_sge *)sglq->sgl; | |
8028 | icmd = &piocbq->iocb; | |
6b5151fd JS |
8029 | if (icmd->ulpCommand == CMD_XMIT_BLS_RSP64_CX) |
8030 | return sglq->sli4_xritag; | |
4f774513 JS |
8031 | if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) { |
8032 | numBdes = icmd->un.genreq64.bdl.bdeSize / | |
8033 | sizeof(struct ulp_bde64); | |
8034 | /* The addrHigh and addrLow fields within the IOCB | |
8035 | * have not been byteswapped yet so there is no | |
8036 | * need to swap them back. | |
8037 | */ | |
1b51197d JS |
8038 | if (piocbq->context3) |
8039 | dmabuf = (struct lpfc_dmabuf *)piocbq->context3; | |
8040 | else | |
8041 | return xritag; | |
4f774513 | 8042 | |
1b51197d | 8043 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
4f774513 JS |
8044 | if (!bpl) |
8045 | return xritag; | |
8046 | ||
8047 | for (i = 0; i < numBdes; i++) { | |
8048 | /* Should already be byte swapped. */ | |
28baac74 JS |
8049 | sgl->addr_hi = bpl->addrHigh; |
8050 | sgl->addr_lo = bpl->addrLow; | |
8051 | ||
0558056c | 8052 | sgl->word2 = le32_to_cpu(sgl->word2); |
4f774513 JS |
8053 | if ((i+1) == numBdes) |
8054 | bf_set(lpfc_sli4_sge_last, sgl, 1); | |
8055 | else | |
8056 | bf_set(lpfc_sli4_sge_last, sgl, 0); | |
28baac74 JS |
8057 | /* swap the size field back to the cpu so we |
8058 | * can assign it to the sgl. | |
8059 | */ | |
8060 | bde.tus.w = le32_to_cpu(bpl->tus.w); | |
8061 | sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize); | |
63e801ce JS |
8062 | /* The offsets in the sgl need to be accumulated |
8063 | * separately for the request and reply lists. | |
8064 | * The request is always first, the reply follows. | |
8065 | */ | |
8066 | if (piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) { | |
8067 | /* add up the reply sg entries */ | |
8068 | if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I) | |
8069 | inbound++; | |
8070 | /* first inbound? reset the offset */ | |
8071 | if (inbound == 1) | |
8072 | offset = 0; | |
8073 | bf_set(lpfc_sli4_sge_offset, sgl, offset); | |
f9bb2da1 JS |
8074 | bf_set(lpfc_sli4_sge_type, sgl, |
8075 | LPFC_SGE_TYPE_DATA); | |
63e801ce JS |
8076 | offset += bde.tus.f.bdeSize; |
8077 | } | |
546fc854 | 8078 | sgl->word2 = cpu_to_le32(sgl->word2); |
4f774513 JS |
8079 | bpl++; |
8080 | sgl++; | |
8081 | } | |
8082 | } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) { | |
8083 | /* The addrHigh and addrLow fields of the BDE have not | |
8084 | * been byteswapped yet so they need to be swapped | |
8085 | * before putting them in the sgl. | |
8086 | */ | |
8087 | sgl->addr_hi = | |
8088 | cpu_to_le32(icmd->un.genreq64.bdl.addrHigh); | |
8089 | sgl->addr_lo = | |
8090 | cpu_to_le32(icmd->un.genreq64.bdl.addrLow); | |
0558056c | 8091 | sgl->word2 = le32_to_cpu(sgl->word2); |
4f774513 JS |
8092 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
8093 | sgl->word2 = cpu_to_le32(sgl->word2); | |
28baac74 JS |
8094 | sgl->sge_len = |
8095 | cpu_to_le32(icmd->un.genreq64.bdl.bdeSize); | |
4f774513 JS |
8096 | } |
8097 | return sglq->sli4_xritag; | |
3772a991 | 8098 | } |
92d7f7b0 | 8099 | |
e59058c4 | 8100 | /** |
4f774513 | 8101 | * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution |
e59058c4 | 8102 | * @phba: Pointer to HBA context object. |
e59058c4 | 8103 | * |
a93ff37a | 8104 | * This routine performs a roundrobin SCSI command to SLI4 FCP WQ index |
8fa38513 JS |
8105 | * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock |
8106 | * held. | |
4f774513 JS |
8107 | * |
8108 | * Return: index into SLI4 fast-path FCP queue index. | |
e59058c4 | 8109 | **/ |
2a76a283 | 8110 | static inline uint32_t |
8fa38513 | 8111 | lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba *phba) |
92d7f7b0 | 8112 | { |
7bb03bbf JS |
8113 | struct lpfc_vector_map_info *cpup; |
8114 | int chann, cpu; | |
8115 | ||
76f96b6d JS |
8116 | if (phba->cfg_fcp_io_sched == LPFC_FCP_SCHED_BY_CPU |
8117 | && phba->cfg_fcp_io_channel > 1) { | |
7bb03bbf JS |
8118 | cpu = smp_processor_id(); |
8119 | if (cpu < phba->sli4_hba.num_present_cpu) { | |
8120 | cpup = phba->sli4_hba.cpu_map; | |
8121 | cpup += cpu; | |
8122 | return cpup->channel_id; | |
8123 | } | |
8124 | chann = cpu; | |
8125 | } | |
8126 | chann = atomic_add_return(1, &phba->fcp_qidx); | |
8127 | chann = (chann % phba->cfg_fcp_io_channel); | |
8128 | return chann; | |
92d7f7b0 JS |
8129 | } |
8130 | ||
e59058c4 | 8131 | /** |
4f774513 | 8132 | * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry. |
e59058c4 | 8133 | * @phba: Pointer to HBA context object. |
4f774513 JS |
8134 | * @piocb: Pointer to command iocb. |
8135 | * @wqe: Pointer to the work queue entry. | |
e59058c4 | 8136 | * |
4f774513 JS |
8137 | * This routine converts the iocb command to its Work Queue Entry |
8138 | * equivalent. The wqe pointer should not have any fields set when | |
8139 | * this routine is called because it will memcpy over them. | |
8140 | * This routine does not set the CQ_ID or the WQEC bits in the | |
8141 | * wqe. | |
e59058c4 | 8142 | * |
4f774513 | 8143 | * Returns: 0 = Success, IOCB_ERROR = Failure. |
e59058c4 | 8144 | **/ |
cf5bf97e | 8145 | static int |
4f774513 JS |
8146 | lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq, |
8147 | union lpfc_wqe *wqe) | |
cf5bf97e | 8148 | { |
5ffc266e | 8149 | uint32_t xmit_len = 0, total_len = 0; |
4f774513 JS |
8150 | uint8_t ct = 0; |
8151 | uint32_t fip; | |
8152 | uint32_t abort_tag; | |
8153 | uint8_t command_type = ELS_COMMAND_NON_FIP; | |
8154 | uint8_t cmnd; | |
8155 | uint16_t xritag; | |
dcf2a4e0 JS |
8156 | uint16_t abrt_iotag; |
8157 | struct lpfc_iocbq *abrtiocbq; | |
4f774513 | 8158 | struct ulp_bde64 *bpl = NULL; |
f0d9bccc | 8159 | uint32_t els_id = LPFC_ELS_ID_DEFAULT; |
5ffc266e JS |
8160 | int numBdes, i; |
8161 | struct ulp_bde64 bde; | |
c31098ce | 8162 | struct lpfc_nodelist *ndlp; |
ff78d8f9 | 8163 | uint32_t *pcmd; |
1b51197d | 8164 | uint32_t if_type; |
4f774513 | 8165 | |
45ed1190 | 8166 | fip = phba->hba_flag & HBA_FIP_SUPPORT; |
4f774513 | 8167 | /* The fcp commands will set command type */ |
0c287589 | 8168 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
4f774513 | 8169 | command_type = FCP_COMMAND; |
c868595d | 8170 | else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)) |
0c287589 JS |
8171 | command_type = ELS_COMMAND_FIP; |
8172 | else | |
8173 | command_type = ELS_COMMAND_NON_FIP; | |
8174 | ||
4f774513 JS |
8175 | /* Some of the fields are in the right position already */ |
8176 | memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe)); | |
8177 | abort_tag = (uint32_t) iocbq->iotag; | |
8178 | xritag = iocbq->sli4_xritag; | |
f0d9bccc | 8179 | wqe->generic.wqe_com.word7 = 0; /* The ct field has moved so reset */ |
28d7f3df | 8180 | wqe->generic.wqe_com.word10 = 0; |
4f774513 JS |
8181 | /* words0-2 bpl convert bde */ |
8182 | if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) { | |
5ffc266e JS |
8183 | numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize / |
8184 | sizeof(struct ulp_bde64); | |
4f774513 JS |
8185 | bpl = (struct ulp_bde64 *) |
8186 | ((struct lpfc_dmabuf *)iocbq->context3)->virt; | |
8187 | if (!bpl) | |
8188 | return IOCB_ERROR; | |
cf5bf97e | 8189 | |
4f774513 JS |
8190 | /* Should already be byte swapped. */ |
8191 | wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh); | |
8192 | wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow); | |
8193 | /* swap the size field back to the cpu so we | |
8194 | * can assign it to the sgl. | |
8195 | */ | |
8196 | wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w); | |
5ffc266e JS |
8197 | xmit_len = wqe->generic.bde.tus.f.bdeSize; |
8198 | total_len = 0; | |
8199 | for (i = 0; i < numBdes; i++) { | |
8200 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); | |
8201 | total_len += bde.tus.f.bdeSize; | |
8202 | } | |
4f774513 | 8203 | } else |
5ffc266e | 8204 | xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize; |
cf5bf97e | 8205 | |
4f774513 JS |
8206 | iocbq->iocb.ulpIoTag = iocbq->iotag; |
8207 | cmnd = iocbq->iocb.ulpCommand; | |
a4bc3379 | 8208 | |
4f774513 JS |
8209 | switch (iocbq->iocb.ulpCommand) { |
8210 | case CMD_ELS_REQUEST64_CR: | |
93d1379e JS |
8211 | if (iocbq->iocb_flag & LPFC_IO_LIBDFC) |
8212 | ndlp = iocbq->context_un.ndlp; | |
8213 | else | |
8214 | ndlp = (struct lpfc_nodelist *)iocbq->context1; | |
4f774513 JS |
8215 | if (!iocbq->iocb.ulpLe) { |
8216 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
8217 | "2007 Only Limited Edition cmd Format" | |
8218 | " supported 0x%x\n", | |
8219 | iocbq->iocb.ulpCommand); | |
8220 | return IOCB_ERROR; | |
8221 | } | |
ff78d8f9 | 8222 | |
5ffc266e | 8223 | wqe->els_req.payload_len = xmit_len; |
4f774513 JS |
8224 | /* Els_reguest64 has a TMO */ |
8225 | bf_set(wqe_tmo, &wqe->els_req.wqe_com, | |
8226 | iocbq->iocb.ulpTimeout); | |
8227 | /* Need a VF for word 4 set the vf bit*/ | |
8228 | bf_set(els_req64_vf, &wqe->els_req, 0); | |
8229 | /* And a VFID for word 12 */ | |
8230 | bf_set(els_req64_vfid, &wqe->els_req, 0); | |
4f774513 | 8231 | ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l); |
f0d9bccc JS |
8232 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
8233 | iocbq->iocb.ulpContext); | |
8234 | bf_set(wqe_ct, &wqe->els_req.wqe_com, ct); | |
8235 | bf_set(wqe_pu, &wqe->els_req.wqe_com, 0); | |
4f774513 | 8236 | /* CCP CCPE PV PRI in word10 were set in the memcpy */ |
ff78d8f9 | 8237 | if (command_type == ELS_COMMAND_FIP) |
c868595d JS |
8238 | els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK) |
8239 | >> LPFC_FIP_ELS_ID_SHIFT); | |
ff78d8f9 JS |
8240 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
8241 | iocbq->context2)->virt); | |
1b51197d JS |
8242 | if_type = bf_get(lpfc_sli_intf_if_type, |
8243 | &phba->sli4_hba.sli_intf); | |
8244 | if (if_type == LPFC_SLI_INTF_IF_TYPE_2) { | |
ff78d8f9 | 8245 | if (pcmd && (*pcmd == ELS_CMD_FLOGI || |
cb69f7de | 8246 | *pcmd == ELS_CMD_SCR || |
6b5151fd | 8247 | *pcmd == ELS_CMD_FDISC || |
bdcd2b92 | 8248 | *pcmd == ELS_CMD_LOGO || |
ff78d8f9 JS |
8249 | *pcmd == ELS_CMD_PLOGI)) { |
8250 | bf_set(els_req64_sp, &wqe->els_req, 1); | |
8251 | bf_set(els_req64_sid, &wqe->els_req, | |
8252 | iocbq->vport->fc_myDID); | |
939723a4 JS |
8253 | if ((*pcmd == ELS_CMD_FLOGI) && |
8254 | !(phba->fc_topology == | |
8255 | LPFC_TOPOLOGY_LOOP)) | |
8256 | bf_set(els_req64_sid, &wqe->els_req, 0); | |
ff78d8f9 JS |
8257 | bf_set(wqe_ct, &wqe->els_req.wqe_com, 1); |
8258 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, | |
a7dd9c0f | 8259 | phba->vpi_ids[iocbq->vport->vpi]); |
3ef6d24c | 8260 | } else if (pcmd && iocbq->context1) { |
ff78d8f9 JS |
8261 | bf_set(wqe_ct, &wqe->els_req.wqe_com, 0); |
8262 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, | |
8263 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); | |
8264 | } | |
c868595d | 8265 | } |
6d368e53 JS |
8266 | bf_set(wqe_temp_rpi, &wqe->els_req.wqe_com, |
8267 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); | |
f0d9bccc JS |
8268 | bf_set(wqe_els_id, &wqe->els_req.wqe_com, els_id); |
8269 | bf_set(wqe_dbde, &wqe->els_req.wqe_com, 1); | |
8270 | bf_set(wqe_iod, &wqe->els_req.wqe_com, LPFC_WQE_IOD_READ); | |
8271 | bf_set(wqe_qosd, &wqe->els_req.wqe_com, 1); | |
8272 | bf_set(wqe_lenloc, &wqe->els_req.wqe_com, LPFC_WQE_LENLOC_NONE); | |
8273 | bf_set(wqe_ebde_cnt, &wqe->els_req.wqe_com, 0); | |
af22741c | 8274 | wqe->els_req.max_response_payload_len = total_len - xmit_len; |
7851fe2c | 8275 | break; |
5ffc266e | 8276 | case CMD_XMIT_SEQUENCE64_CX: |
f0d9bccc JS |
8277 | bf_set(wqe_ctxt_tag, &wqe->xmit_sequence.wqe_com, |
8278 | iocbq->iocb.un.ulpWord[3]); | |
8279 | bf_set(wqe_rcvoxid, &wqe->xmit_sequence.wqe_com, | |
7851fe2c | 8280 | iocbq->iocb.unsli3.rcvsli3.ox_id); |
5ffc266e JS |
8281 | /* The entire sequence is transmitted for this IOCB */ |
8282 | xmit_len = total_len; | |
8283 | cmnd = CMD_XMIT_SEQUENCE64_CR; | |
1b51197d JS |
8284 | if (phba->link_flag & LS_LOOPBACK_MODE) |
8285 | bf_set(wqe_xo, &wqe->xmit_sequence.wge_ctl, 1); | |
4f774513 | 8286 | case CMD_XMIT_SEQUENCE64_CR: |
f0d9bccc JS |
8287 | /* word3 iocb=io_tag32 wqe=reserved */ |
8288 | wqe->xmit_sequence.rsvd3 = 0; | |
4f774513 JS |
8289 | /* word4 relative_offset memcpy */ |
8290 | /* word5 r_ctl/df_ctl memcpy */ | |
f0d9bccc JS |
8291 | bf_set(wqe_pu, &wqe->xmit_sequence.wqe_com, 0); |
8292 | bf_set(wqe_dbde, &wqe->xmit_sequence.wqe_com, 1); | |
8293 | bf_set(wqe_iod, &wqe->xmit_sequence.wqe_com, | |
8294 | LPFC_WQE_IOD_WRITE); | |
8295 | bf_set(wqe_lenloc, &wqe->xmit_sequence.wqe_com, | |
8296 | LPFC_WQE_LENLOC_WORD12); | |
8297 | bf_set(wqe_ebde_cnt, &wqe->xmit_sequence.wqe_com, 0); | |
5ffc266e JS |
8298 | wqe->xmit_sequence.xmit_len = xmit_len; |
8299 | command_type = OTHER_COMMAND; | |
7851fe2c | 8300 | break; |
4f774513 | 8301 | case CMD_XMIT_BCAST64_CN: |
f0d9bccc JS |
8302 | /* word3 iocb=iotag32 wqe=seq_payload_len */ |
8303 | wqe->xmit_bcast64.seq_payload_len = xmit_len; | |
4f774513 JS |
8304 | /* word4 iocb=rsvd wqe=rsvd */ |
8305 | /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */ | |
8306 | /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */ | |
f0d9bccc | 8307 | bf_set(wqe_ct, &wqe->xmit_bcast64.wqe_com, |
4f774513 | 8308 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
f0d9bccc JS |
8309 | bf_set(wqe_dbde, &wqe->xmit_bcast64.wqe_com, 1); |
8310 | bf_set(wqe_iod, &wqe->xmit_bcast64.wqe_com, LPFC_WQE_IOD_WRITE); | |
8311 | bf_set(wqe_lenloc, &wqe->xmit_bcast64.wqe_com, | |
8312 | LPFC_WQE_LENLOC_WORD3); | |
8313 | bf_set(wqe_ebde_cnt, &wqe->xmit_bcast64.wqe_com, 0); | |
7851fe2c | 8314 | break; |
4f774513 JS |
8315 | case CMD_FCP_IWRITE64_CR: |
8316 | command_type = FCP_COMMAND_DATA_OUT; | |
f0d9bccc JS |
8317 | /* word3 iocb=iotag wqe=payload_offset_len */ |
8318 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ | |
0ba4b219 JS |
8319 | bf_set(payload_offset_len, &wqe->fcp_iwrite, |
8320 | xmit_len + sizeof(struct fcp_rsp)); | |
8321 | bf_set(cmd_buff_len, &wqe->fcp_iwrite, | |
8322 | 0); | |
f0d9bccc JS |
8323 | /* word4 iocb=parameter wqe=total_xfer_length memcpy */ |
8324 | /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */ | |
8325 | bf_set(wqe_erp, &wqe->fcp_iwrite.wqe_com, | |
8326 | iocbq->iocb.ulpFCP2Rcvy); | |
8327 | bf_set(wqe_lnk, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpXS); | |
8328 | /* Always open the exchange */ | |
8329 | bf_set(wqe_xc, &wqe->fcp_iwrite.wqe_com, 0); | |
f0d9bccc JS |
8330 | bf_set(wqe_iod, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_IOD_WRITE); |
8331 | bf_set(wqe_lenloc, &wqe->fcp_iwrite.wqe_com, | |
8332 | LPFC_WQE_LENLOC_WORD4); | |
8333 | bf_set(wqe_ebde_cnt, &wqe->fcp_iwrite.wqe_com, 0); | |
8334 | bf_set(wqe_pu, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpPU); | |
acd6859b | 8335 | bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 1); |
1ba981fd JS |
8336 | if (iocbq->iocb_flag & LPFC_IO_OAS) { |
8337 | bf_set(wqe_oas, &wqe->fcp_iwrite.wqe_com, 1); | |
8338 | if (phba->cfg_XLanePriority) { | |
8339 | bf_set(wqe_ccpe, &wqe->fcp_iwrite.wqe_com, 1); | |
8340 | bf_set(wqe_ccp, &wqe->fcp_iwrite.wqe_com, | |
8341 | (phba->cfg_XLanePriority << 1)); | |
8342 | } | |
8343 | } | |
7851fe2c | 8344 | break; |
4f774513 | 8345 | case CMD_FCP_IREAD64_CR: |
f0d9bccc JS |
8346 | /* word3 iocb=iotag wqe=payload_offset_len */ |
8347 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ | |
0ba4b219 JS |
8348 | bf_set(payload_offset_len, &wqe->fcp_iread, |
8349 | xmit_len + sizeof(struct fcp_rsp)); | |
8350 | bf_set(cmd_buff_len, &wqe->fcp_iread, | |
8351 | 0); | |
f0d9bccc JS |
8352 | /* word4 iocb=parameter wqe=total_xfer_length memcpy */ |
8353 | /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */ | |
8354 | bf_set(wqe_erp, &wqe->fcp_iread.wqe_com, | |
8355 | iocbq->iocb.ulpFCP2Rcvy); | |
8356 | bf_set(wqe_lnk, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpXS); | |
f1126688 JS |
8357 | /* Always open the exchange */ |
8358 | bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0); | |
f0d9bccc JS |
8359 | bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, LPFC_WQE_IOD_READ); |
8360 | bf_set(wqe_lenloc, &wqe->fcp_iread.wqe_com, | |
8361 | LPFC_WQE_LENLOC_WORD4); | |
8362 | bf_set(wqe_ebde_cnt, &wqe->fcp_iread.wqe_com, 0); | |
8363 | bf_set(wqe_pu, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpPU); | |
acd6859b | 8364 | bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 1); |
1ba981fd JS |
8365 | if (iocbq->iocb_flag & LPFC_IO_OAS) { |
8366 | bf_set(wqe_oas, &wqe->fcp_iread.wqe_com, 1); | |
8367 | if (phba->cfg_XLanePriority) { | |
8368 | bf_set(wqe_ccpe, &wqe->fcp_iread.wqe_com, 1); | |
8369 | bf_set(wqe_ccp, &wqe->fcp_iread.wqe_com, | |
8370 | (phba->cfg_XLanePriority << 1)); | |
8371 | } | |
8372 | } | |
7851fe2c | 8373 | break; |
4f774513 | 8374 | case CMD_FCP_ICMND64_CR: |
0ba4b219 JS |
8375 | /* word3 iocb=iotag wqe=payload_offset_len */ |
8376 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ | |
8377 | bf_set(payload_offset_len, &wqe->fcp_icmd, | |
8378 | xmit_len + sizeof(struct fcp_rsp)); | |
8379 | bf_set(cmd_buff_len, &wqe->fcp_icmd, | |
8380 | 0); | |
f0d9bccc | 8381 | /* word3 iocb=IO_TAG wqe=reserved */ |
f0d9bccc | 8382 | bf_set(wqe_pu, &wqe->fcp_icmd.wqe_com, 0); |
4f774513 | 8383 | /* Always open the exchange */ |
f0d9bccc JS |
8384 | bf_set(wqe_xc, &wqe->fcp_icmd.wqe_com, 0); |
8385 | bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 1); | |
8386 | bf_set(wqe_iod, &wqe->fcp_icmd.wqe_com, LPFC_WQE_IOD_WRITE); | |
8387 | bf_set(wqe_qosd, &wqe->fcp_icmd.wqe_com, 1); | |
8388 | bf_set(wqe_lenloc, &wqe->fcp_icmd.wqe_com, | |
8389 | LPFC_WQE_LENLOC_NONE); | |
8390 | bf_set(wqe_ebde_cnt, &wqe->fcp_icmd.wqe_com, 0); | |
2a94aea4 JS |
8391 | bf_set(wqe_erp, &wqe->fcp_icmd.wqe_com, |
8392 | iocbq->iocb.ulpFCP2Rcvy); | |
1ba981fd JS |
8393 | if (iocbq->iocb_flag & LPFC_IO_OAS) { |
8394 | bf_set(wqe_oas, &wqe->fcp_icmd.wqe_com, 1); | |
8395 | if (phba->cfg_XLanePriority) { | |
8396 | bf_set(wqe_ccpe, &wqe->fcp_icmd.wqe_com, 1); | |
8397 | bf_set(wqe_ccp, &wqe->fcp_icmd.wqe_com, | |
8398 | (phba->cfg_XLanePriority << 1)); | |
8399 | } | |
8400 | } | |
7851fe2c | 8401 | break; |
4f774513 | 8402 | case CMD_GEN_REQUEST64_CR: |
63e801ce JS |
8403 | /* For this command calculate the xmit length of the |
8404 | * request bde. | |
8405 | */ | |
8406 | xmit_len = 0; | |
8407 | numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize / | |
8408 | sizeof(struct ulp_bde64); | |
8409 | for (i = 0; i < numBdes; i++) { | |
63e801ce | 8410 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
546fc854 JS |
8411 | if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64) |
8412 | break; | |
63e801ce JS |
8413 | xmit_len += bde.tus.f.bdeSize; |
8414 | } | |
f0d9bccc JS |
8415 | /* word3 iocb=IO_TAG wqe=request_payload_len */ |
8416 | wqe->gen_req.request_payload_len = xmit_len; | |
8417 | /* word4 iocb=parameter wqe=relative_offset memcpy */ | |
8418 | /* word5 [rctl, type, df_ctl, la] copied in memcpy */ | |
4f774513 JS |
8419 | /* word6 context tag copied in memcpy */ |
8420 | if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) { | |
8421 | ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l); | |
8422 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
8423 | "2015 Invalid CT %x command 0x%x\n", | |
8424 | ct, iocbq->iocb.ulpCommand); | |
8425 | return IOCB_ERROR; | |
8426 | } | |
f0d9bccc JS |
8427 | bf_set(wqe_ct, &wqe->gen_req.wqe_com, 0); |
8428 | bf_set(wqe_tmo, &wqe->gen_req.wqe_com, iocbq->iocb.ulpTimeout); | |
8429 | bf_set(wqe_pu, &wqe->gen_req.wqe_com, iocbq->iocb.ulpPU); | |
8430 | bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1); | |
8431 | bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ); | |
8432 | bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1); | |
8433 | bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE); | |
8434 | bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0); | |
af22741c | 8435 | wqe->gen_req.max_response_payload_len = total_len - xmit_len; |
4f774513 | 8436 | command_type = OTHER_COMMAND; |
7851fe2c | 8437 | break; |
4f774513 | 8438 | case CMD_XMIT_ELS_RSP64_CX: |
c31098ce | 8439 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
4f774513 | 8440 | /* words0-2 BDE memcpy */ |
f0d9bccc JS |
8441 | /* word3 iocb=iotag32 wqe=response_payload_len */ |
8442 | wqe->xmit_els_rsp.response_payload_len = xmit_len; | |
939723a4 JS |
8443 | /* word4 */ |
8444 | wqe->xmit_els_rsp.word4 = 0; | |
4f774513 JS |
8445 | /* word5 iocb=rsvd wge=did */ |
8446 | bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest, | |
939723a4 JS |
8447 | iocbq->iocb.un.xseq64.xmit_els_remoteID); |
8448 | ||
8449 | if_type = bf_get(lpfc_sli_intf_if_type, | |
8450 | &phba->sli4_hba.sli_intf); | |
8451 | if (if_type == LPFC_SLI_INTF_IF_TYPE_2) { | |
8452 | if (iocbq->vport->fc_flag & FC_PT2PT) { | |
8453 | bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1); | |
8454 | bf_set(els_rsp64_sid, &wqe->xmit_els_rsp, | |
8455 | iocbq->vport->fc_myDID); | |
8456 | if (iocbq->vport->fc_myDID == Fabric_DID) { | |
8457 | bf_set(wqe_els_did, | |
8458 | &wqe->xmit_els_rsp.wqe_dest, 0); | |
8459 | } | |
8460 | } | |
8461 | } | |
f0d9bccc JS |
8462 | bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, |
8463 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); | |
8464 | bf_set(wqe_pu, &wqe->xmit_els_rsp.wqe_com, iocbq->iocb.ulpPU); | |
8465 | bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com, | |
7851fe2c | 8466 | iocbq->iocb.unsli3.rcvsli3.ox_id); |
4f774513 | 8467 | if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l) |
f0d9bccc | 8468 | bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, |
6d368e53 | 8469 | phba->vpi_ids[iocbq->vport->vpi]); |
f0d9bccc JS |
8470 | bf_set(wqe_dbde, &wqe->xmit_els_rsp.wqe_com, 1); |
8471 | bf_set(wqe_iod, &wqe->xmit_els_rsp.wqe_com, LPFC_WQE_IOD_WRITE); | |
8472 | bf_set(wqe_qosd, &wqe->xmit_els_rsp.wqe_com, 1); | |
8473 | bf_set(wqe_lenloc, &wqe->xmit_els_rsp.wqe_com, | |
8474 | LPFC_WQE_LENLOC_WORD3); | |
8475 | bf_set(wqe_ebde_cnt, &wqe->xmit_els_rsp.wqe_com, 0); | |
6d368e53 JS |
8476 | bf_set(wqe_rsp_temp_rpi, &wqe->xmit_els_rsp, |
8477 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); | |
ff78d8f9 JS |
8478 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
8479 | iocbq->context2)->virt); | |
8480 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { | |
939723a4 JS |
8481 | bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1); |
8482 | bf_set(els_rsp64_sid, &wqe->xmit_els_rsp, | |
ff78d8f9 | 8483 | iocbq->vport->fc_myDID); |
939723a4 JS |
8484 | bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, 1); |
8485 | bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, | |
ff78d8f9 JS |
8486 | phba->vpi_ids[phba->pport->vpi]); |
8487 | } | |
4f774513 | 8488 | command_type = OTHER_COMMAND; |
7851fe2c | 8489 | break; |
4f774513 JS |
8490 | case CMD_CLOSE_XRI_CN: |
8491 | case CMD_ABORT_XRI_CN: | |
8492 | case CMD_ABORT_XRI_CX: | |
8493 | /* words 0-2 memcpy should be 0 rserved */ | |
8494 | /* port will send abts */ | |
dcf2a4e0 JS |
8495 | abrt_iotag = iocbq->iocb.un.acxri.abortContextTag; |
8496 | if (abrt_iotag != 0 && abrt_iotag <= phba->sli.last_iotag) { | |
8497 | abrtiocbq = phba->sli.iocbq_lookup[abrt_iotag]; | |
8498 | fip = abrtiocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK; | |
8499 | } else | |
8500 | fip = 0; | |
8501 | ||
8502 | if ((iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN) || fip) | |
4f774513 | 8503 | /* |
dcf2a4e0 JS |
8504 | * The link is down, or the command was ELS_FIP |
8505 | * so the fw does not need to send abts | |
4f774513 JS |
8506 | * on the wire. |
8507 | */ | |
8508 | bf_set(abort_cmd_ia, &wqe->abort_cmd, 1); | |
8509 | else | |
8510 | bf_set(abort_cmd_ia, &wqe->abort_cmd, 0); | |
8511 | bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG); | |
f0d9bccc JS |
8512 | /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */ |
8513 | wqe->abort_cmd.rsrvd5 = 0; | |
8514 | bf_set(wqe_ct, &wqe->abort_cmd.wqe_com, | |
4f774513 JS |
8515 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
8516 | abort_tag = iocbq->iocb.un.acxri.abortIoTag; | |
4f774513 JS |
8517 | /* |
8518 | * The abort handler will send us CMD_ABORT_XRI_CN or | |
8519 | * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX | |
8520 | */ | |
f0d9bccc JS |
8521 | bf_set(wqe_cmnd, &wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX); |
8522 | bf_set(wqe_qosd, &wqe->abort_cmd.wqe_com, 1); | |
8523 | bf_set(wqe_lenloc, &wqe->abort_cmd.wqe_com, | |
8524 | LPFC_WQE_LENLOC_NONE); | |
4f774513 JS |
8525 | cmnd = CMD_ABORT_XRI_CX; |
8526 | command_type = OTHER_COMMAND; | |
8527 | xritag = 0; | |
7851fe2c | 8528 | break; |
6669f9bb | 8529 | case CMD_XMIT_BLS_RSP64_CX: |
6b5151fd | 8530 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
546fc854 | 8531 | /* As BLS ABTS RSP WQE is very different from other WQEs, |
6669f9bb JS |
8532 | * we re-construct this WQE here based on information in |
8533 | * iocbq from scratch. | |
8534 | */ | |
8535 | memset(wqe, 0, sizeof(union lpfc_wqe)); | |
5ffc266e | 8536 | /* OX_ID is invariable to who sent ABTS to CT exchange */ |
6669f9bb | 8537 | bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp, |
546fc854 JS |
8538 | bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_rsp)); |
8539 | if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_rsp) == | |
5ffc266e JS |
8540 | LPFC_ABTS_UNSOL_INT) { |
8541 | /* ABTS sent by initiator to CT exchange, the | |
8542 | * RX_ID field will be filled with the newly | |
8543 | * allocated responder XRI. | |
8544 | */ | |
8545 | bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp, | |
8546 | iocbq->sli4_xritag); | |
8547 | } else { | |
8548 | /* ABTS sent by responder to CT exchange, the | |
8549 | * RX_ID field will be filled with the responder | |
8550 | * RX_ID from ABTS. | |
8551 | */ | |
8552 | bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp, | |
546fc854 | 8553 | bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_rsp)); |
5ffc266e | 8554 | } |
6669f9bb JS |
8555 | bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff); |
8556 | bf_set(wqe_xmit_bls_pt, &wqe->xmit_bls_rsp.wqe_dest, 0x1); | |
6b5151fd JS |
8557 | |
8558 | /* Use CT=VPI */ | |
8559 | bf_set(wqe_els_did, &wqe->xmit_bls_rsp.wqe_dest, | |
8560 | ndlp->nlp_DID); | |
8561 | bf_set(xmit_bls_rsp64_temprpi, &wqe->xmit_bls_rsp, | |
8562 | iocbq->iocb.ulpContext); | |
8563 | bf_set(wqe_ct, &wqe->xmit_bls_rsp.wqe_com, 1); | |
6669f9bb | 8564 | bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com, |
6b5151fd | 8565 | phba->vpi_ids[phba->pport->vpi]); |
f0d9bccc JS |
8566 | bf_set(wqe_qosd, &wqe->xmit_bls_rsp.wqe_com, 1); |
8567 | bf_set(wqe_lenloc, &wqe->xmit_bls_rsp.wqe_com, | |
8568 | LPFC_WQE_LENLOC_NONE); | |
6669f9bb JS |
8569 | /* Overwrite the pre-set comnd type with OTHER_COMMAND */ |
8570 | command_type = OTHER_COMMAND; | |
546fc854 JS |
8571 | if (iocbq->iocb.un.xseq64.w5.hcsw.Rctl == FC_RCTL_BA_RJT) { |
8572 | bf_set(xmit_bls_rsp64_rjt_vspec, &wqe->xmit_bls_rsp, | |
8573 | bf_get(lpfc_vndr_code, &iocbq->iocb.un.bls_rsp)); | |
8574 | bf_set(xmit_bls_rsp64_rjt_expc, &wqe->xmit_bls_rsp, | |
8575 | bf_get(lpfc_rsn_expln, &iocbq->iocb.un.bls_rsp)); | |
8576 | bf_set(xmit_bls_rsp64_rjt_rsnc, &wqe->xmit_bls_rsp, | |
8577 | bf_get(lpfc_rsn_code, &iocbq->iocb.un.bls_rsp)); | |
8578 | } | |
8579 | ||
7851fe2c | 8580 | break; |
4f774513 JS |
8581 | case CMD_XRI_ABORTED_CX: |
8582 | case CMD_CREATE_XRI_CR: /* Do we expect to use this? */ | |
4f774513 JS |
8583 | case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */ |
8584 | case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */ | |
8585 | case CMD_FCP_TRSP64_CX: /* Target mode rcv */ | |
8586 | case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */ | |
8587 | default: | |
8588 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
8589 | "2014 Invalid command 0x%x\n", | |
8590 | iocbq->iocb.ulpCommand); | |
8591 | return IOCB_ERROR; | |
7851fe2c | 8592 | break; |
4f774513 | 8593 | } |
6d368e53 | 8594 | |
8012cc38 JS |
8595 | if (iocbq->iocb_flag & LPFC_IO_DIF_PASS) |
8596 | bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_PASSTHRU); | |
8597 | else if (iocbq->iocb_flag & LPFC_IO_DIF_STRIP) | |
8598 | bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_STRIP); | |
8599 | else if (iocbq->iocb_flag & LPFC_IO_DIF_INSERT) | |
8600 | bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_INSERT); | |
8601 | iocbq->iocb_flag &= ~(LPFC_IO_DIF_PASS | LPFC_IO_DIF_STRIP | | |
8602 | LPFC_IO_DIF_INSERT); | |
f0d9bccc JS |
8603 | bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag); |
8604 | bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag); | |
8605 | wqe->generic.wqe_com.abort_tag = abort_tag; | |
8606 | bf_set(wqe_cmd_type, &wqe->generic.wqe_com, command_type); | |
8607 | bf_set(wqe_cmnd, &wqe->generic.wqe_com, cmnd); | |
8608 | bf_set(wqe_class, &wqe->generic.wqe_com, iocbq->iocb.ulpClass); | |
8609 | bf_set(wqe_cqid, &wqe->generic.wqe_com, LPFC_WQE_CQ_ID_DEFAULT); | |
4f774513 JS |
8610 | return 0; |
8611 | } | |
8612 | ||
8613 | /** | |
8614 | * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb | |
8615 | * @phba: Pointer to HBA context object. | |
8616 | * @ring_number: SLI ring number to issue iocb on. | |
8617 | * @piocb: Pointer to command iocb. | |
8618 | * @flag: Flag indicating if this command can be put into txq. | |
8619 | * | |
8620 | * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue | |
8621 | * an iocb command to an HBA with SLI-4 interface spec. | |
8622 | * | |
8623 | * This function is called with hbalock held. The function will return success | |
8624 | * after it successfully submit the iocb to firmware or after adding to the | |
8625 | * txq. | |
8626 | **/ | |
8627 | static int | |
8628 | __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number, | |
8629 | struct lpfc_iocbq *piocb, uint32_t flag) | |
8630 | { | |
8631 | struct lpfc_sglq *sglq; | |
4f774513 | 8632 | union lpfc_wqe wqe; |
1ba981fd | 8633 | struct lpfc_queue *wq; |
4f774513 | 8634 | struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number]; |
4f774513 JS |
8635 | |
8636 | if (piocb->sli4_xritag == NO_XRI) { | |
8637 | if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || | |
6b5151fd | 8638 | piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN) |
4f774513 JS |
8639 | sglq = NULL; |
8640 | else { | |
0e9bb8d7 | 8641 | if (!list_empty(&pring->txq)) { |
2a9bf3d0 JS |
8642 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
8643 | __lpfc_sli_ringtx_put(phba, | |
8644 | pring, piocb); | |
8645 | return IOCB_SUCCESS; | |
8646 | } else { | |
8647 | return IOCB_BUSY; | |
8648 | } | |
8649 | } else { | |
6d368e53 | 8650 | sglq = __lpfc_sli_get_sglq(phba, piocb); |
2a9bf3d0 JS |
8651 | if (!sglq) { |
8652 | if (!(flag & SLI_IOCB_RET_IOCB)) { | |
8653 | __lpfc_sli_ringtx_put(phba, | |
8654 | pring, | |
8655 | piocb); | |
8656 | return IOCB_SUCCESS; | |
8657 | } else | |
8658 | return IOCB_BUSY; | |
8659 | } | |
8660 | } | |
4f774513 JS |
8661 | } |
8662 | } else if (piocb->iocb_flag & LPFC_IO_FCP) { | |
6d368e53 JS |
8663 | /* These IO's already have an XRI and a mapped sgl. */ |
8664 | sglq = NULL; | |
4f774513 | 8665 | } else { |
6d368e53 JS |
8666 | /* |
8667 | * This is a continuation of a commandi,(CX) so this | |
4f774513 JS |
8668 | * sglq is on the active list |
8669 | */ | |
edccdc17 | 8670 | sglq = __lpfc_get_active_sglq(phba, piocb->sli4_lxritag); |
4f774513 JS |
8671 | if (!sglq) |
8672 | return IOCB_ERROR; | |
8673 | } | |
8674 | ||
8675 | if (sglq) { | |
6d368e53 | 8676 | piocb->sli4_lxritag = sglq->sli4_lxritag; |
2a9bf3d0 | 8677 | piocb->sli4_xritag = sglq->sli4_xritag; |
2a9bf3d0 | 8678 | if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocb, sglq)) |
4f774513 JS |
8679 | return IOCB_ERROR; |
8680 | } | |
8681 | ||
8682 | if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe)) | |
8683 | return IOCB_ERROR; | |
8684 | ||
341af102 | 8685 | if ((piocb->iocb_flag & LPFC_IO_FCP) || |
1ba981fd | 8686 | (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) { |
f38fa0bb | 8687 | if (!phba->cfg_fof || (!(piocb->iocb_flag & LPFC_IO_OAS))) { |
1ba981fd JS |
8688 | wq = phba->sli4_hba.fcp_wq[piocb->fcp_wqidx]; |
8689 | } else { | |
8690 | wq = phba->sli4_hba.oas_wq; | |
8691 | } | |
8692 | if (lpfc_sli4_wq_put(wq, &wqe)) | |
4f774513 JS |
8693 | return IOCB_ERROR; |
8694 | } else { | |
ea714f3d JS |
8695 | if (unlikely(!phba->sli4_hba.els_wq)) |
8696 | return IOCB_ERROR; | |
4f774513 JS |
8697 | if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe)) |
8698 | return IOCB_ERROR; | |
8699 | } | |
8700 | lpfc_sli_ringtxcmpl_put(phba, pring, piocb); | |
8701 | ||
8702 | return 0; | |
8703 | } | |
8704 | ||
8705 | /** | |
8706 | * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb | |
8707 | * | |
8708 | * This routine wraps the actual lockless version for issusing IOCB function | |
8709 | * pointer from the lpfc_hba struct. | |
8710 | * | |
8711 | * Return codes: | |
8712 | * IOCB_ERROR - Error | |
8713 | * IOCB_SUCCESS - Success | |
8714 | * IOCB_BUSY - Busy | |
8715 | **/ | |
2a9bf3d0 | 8716 | int |
4f774513 JS |
8717 | __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, |
8718 | struct lpfc_iocbq *piocb, uint32_t flag) | |
8719 | { | |
8720 | return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); | |
8721 | } | |
8722 | ||
8723 | /** | |
25985edc | 8724 | * lpfc_sli_api_table_setup - Set up sli api function jump table |
4f774513 JS |
8725 | * @phba: The hba struct for which this call is being executed. |
8726 | * @dev_grp: The HBA PCI-Device group number. | |
8727 | * | |
8728 | * This routine sets up the SLI interface API function jump table in @phba | |
8729 | * struct. | |
8730 | * Returns: 0 - success, -ENODEV - failure. | |
8731 | **/ | |
8732 | int | |
8733 | lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) | |
8734 | { | |
8735 | ||
8736 | switch (dev_grp) { | |
8737 | case LPFC_PCI_DEV_LP: | |
8738 | phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3; | |
8739 | phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3; | |
8740 | break; | |
8741 | case LPFC_PCI_DEV_OC: | |
8742 | phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4; | |
8743 | phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4; | |
8744 | break; | |
8745 | default: | |
8746 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8747 | "1419 Invalid HBA PCI-device group: 0x%x\n", | |
8748 | dev_grp); | |
8749 | return -ENODEV; | |
8750 | break; | |
8751 | } | |
8752 | phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq; | |
8753 | return 0; | |
8754 | } | |
8755 | ||
8756 | /** | |
8757 | * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb | |
8758 | * @phba: Pointer to HBA context object. | |
8759 | * @pring: Pointer to driver SLI ring object. | |
8760 | * @piocb: Pointer to command iocb. | |
8761 | * @flag: Flag indicating if this command can be put into txq. | |
8762 | * | |
8763 | * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb | |
8764 | * function. This function gets the hbalock and calls | |
8765 | * __lpfc_sli_issue_iocb function and will return the error returned | |
8766 | * by __lpfc_sli_issue_iocb function. This wrapper is used by | |
8767 | * functions which do not hold hbalock. | |
8768 | **/ | |
8769 | int | |
8770 | lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, | |
8771 | struct lpfc_iocbq *piocb, uint32_t flag) | |
8772 | { | |
ba20c853 | 8773 | struct lpfc_fcp_eq_hdl *fcp_eq_hdl; |
2a76a283 | 8774 | struct lpfc_sli_ring *pring; |
ba20c853 JS |
8775 | struct lpfc_queue *fpeq; |
8776 | struct lpfc_eqe *eqe; | |
4f774513 | 8777 | unsigned long iflags; |
2a76a283 | 8778 | int rc, idx; |
4f774513 | 8779 | |
7e56aa25 | 8780 | if (phba->sli_rev == LPFC_SLI_REV4) { |
2a76a283 | 8781 | if (piocb->iocb_flag & LPFC_IO_FCP) { |
f38fa0bb | 8782 | if (!phba->cfg_fof || (!(piocb->iocb_flag & |
1ba981fd JS |
8783 | LPFC_IO_OAS))) { |
8784 | if (unlikely(!phba->sli4_hba.fcp_wq)) | |
8785 | return IOCB_ERROR; | |
8786 | idx = lpfc_sli4_scmd_to_wqidx_distr(phba); | |
8787 | piocb->fcp_wqidx = idx; | |
8788 | ring_number = MAX_SLI3_CONFIGURED_RINGS + idx; | |
8789 | } else { | |
8790 | if (unlikely(!phba->sli4_hba.oas_wq)) | |
8791 | return IOCB_ERROR; | |
8792 | idx = 0; | |
8793 | piocb->fcp_wqidx = 0; | |
8794 | ring_number = LPFC_FCP_OAS_RING; | |
8795 | } | |
ba20c853 JS |
8796 | pring = &phba->sli.ring[ring_number]; |
8797 | spin_lock_irqsave(&pring->ring_lock, iflags); | |
8798 | rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, | |
8799 | flag); | |
8800 | spin_unlock_irqrestore(&pring->ring_lock, iflags); | |
8801 | ||
8802 | if (lpfc_fcp_look_ahead) { | |
8803 | fcp_eq_hdl = &phba->sli4_hba.fcp_eq_hdl[idx]; | |
8804 | ||
8805 | if (atomic_dec_and_test(&fcp_eq_hdl-> | |
8806 | fcp_eq_in_use)) { | |
4f774513 | 8807 | |
ba20c853 JS |
8808 | /* Get associated EQ with this index */ |
8809 | fpeq = phba->sli4_hba.hba_eq[idx]; | |
8810 | ||
8811 | /* Turn off interrupts from this EQ */ | |
8812 | lpfc_sli4_eq_clr_intr(fpeq); | |
8813 | ||
8814 | /* | |
8815 | * Process all the events on FCP EQ | |
8816 | */ | |
8817 | while ((eqe = lpfc_sli4_eq_get(fpeq))) { | |
8818 | lpfc_sli4_hba_handle_eqe(phba, | |
8819 | eqe, idx); | |
8820 | fpeq->EQ_processed++; | |
8821 | } | |
8822 | ||
8823 | /* Always clear and re-arm the EQ */ | |
8824 | lpfc_sli4_eq_release(fpeq, | |
8825 | LPFC_QUEUE_REARM); | |
8826 | } | |
8827 | atomic_inc(&fcp_eq_hdl->fcp_eq_in_use); | |
8828 | } | |
8829 | } else { | |
8830 | pring = &phba->sli.ring[ring_number]; | |
8831 | spin_lock_irqsave(&pring->ring_lock, iflags); | |
8832 | rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, | |
8833 | flag); | |
8834 | spin_unlock_irqrestore(&pring->ring_lock, iflags); | |
8835 | ||
2a76a283 | 8836 | } |
7e56aa25 JS |
8837 | } else { |
8838 | /* For now, SLI2/3 will still use hbalock */ | |
8839 | spin_lock_irqsave(&phba->hbalock, iflags); | |
8840 | rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); | |
8841 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
8842 | } | |
4f774513 JS |
8843 | return rc; |
8844 | } | |
8845 | ||
8846 | /** | |
8847 | * lpfc_extra_ring_setup - Extra ring setup function | |
8848 | * @phba: Pointer to HBA context object. | |
8849 | * | |
8850 | * This function is called while driver attaches with the | |
8851 | * HBA to setup the extra ring. The extra ring is used | |
8852 | * only when driver needs to support target mode functionality | |
8853 | * or IP over FC functionalities. | |
8854 | * | |
8855 | * This function is called with no lock held. | |
8856 | **/ | |
8857 | static int | |
8858 | lpfc_extra_ring_setup( struct lpfc_hba *phba) | |
8859 | { | |
8860 | struct lpfc_sli *psli; | |
8861 | struct lpfc_sli_ring *pring; | |
8862 | ||
8863 | psli = &phba->sli; | |
8864 | ||
8865 | /* Adjust cmd/rsp ring iocb entries more evenly */ | |
8866 | ||
8867 | /* Take some away from the FCP ring */ | |
8868 | pring = &psli->ring[psli->fcp_ring]; | |
7e56aa25 JS |
8869 | pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
8870 | pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES; | |
8871 | pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES; | |
8872 | pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES; | |
cf5bf97e | 8873 | |
a4bc3379 JS |
8874 | /* and give them to the extra ring */ |
8875 | pring = &psli->ring[psli->extra_ring]; | |
8876 | ||
7e56aa25 JS |
8877 | pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
8878 | pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES; | |
8879 | pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES; | |
8880 | pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES; | |
cf5bf97e JW |
8881 | |
8882 | /* Setup default profile for this ring */ | |
8883 | pring->iotag_max = 4096; | |
8884 | pring->num_mask = 1; | |
8885 | pring->prt[0].profile = 0; /* Mask 0 */ | |
a4bc3379 JS |
8886 | pring->prt[0].rctl = phba->cfg_multi_ring_rctl; |
8887 | pring->prt[0].type = phba->cfg_multi_ring_type; | |
cf5bf97e JW |
8888 | pring->prt[0].lpfc_sli_rcv_unsol_event = NULL; |
8889 | return 0; | |
8890 | } | |
8891 | ||
cb69f7de JS |
8892 | /* lpfc_sli_abts_err_handler - handle a failed ABTS request from an SLI3 port. |
8893 | * @phba: Pointer to HBA context object. | |
8894 | * @iocbq: Pointer to iocb object. | |
8895 | * | |
8896 | * The async_event handler calls this routine when it receives | |
8897 | * an ASYNC_STATUS_CN event from the port. The port generates | |
8898 | * this event when an Abort Sequence request to an rport fails | |
8899 | * twice in succession. The abort could be originated by the | |
8900 | * driver or by the port. The ABTS could have been for an ELS | |
8901 | * or FCP IO. The port only generates this event when an ABTS | |
8902 | * fails to complete after one retry. | |
8903 | */ | |
8904 | static void | |
8905 | lpfc_sli_abts_err_handler(struct lpfc_hba *phba, | |
8906 | struct lpfc_iocbq *iocbq) | |
8907 | { | |
8908 | struct lpfc_nodelist *ndlp = NULL; | |
8909 | uint16_t rpi = 0, vpi = 0; | |
8910 | struct lpfc_vport *vport = NULL; | |
8911 | ||
8912 | /* The rpi in the ulpContext is vport-sensitive. */ | |
8913 | vpi = iocbq->iocb.un.asyncstat.sub_ctxt_tag; | |
8914 | rpi = iocbq->iocb.ulpContext; | |
8915 | ||
8916 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
8917 | "3092 Port generated ABTS async event " | |
8918 | "on vpi %d rpi %d status 0x%x\n", | |
8919 | vpi, rpi, iocbq->iocb.ulpStatus); | |
8920 | ||
8921 | vport = lpfc_find_vport_by_vpid(phba, vpi); | |
8922 | if (!vport) | |
8923 | goto err_exit; | |
8924 | ndlp = lpfc_findnode_rpi(vport, rpi); | |
8925 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) | |
8926 | goto err_exit; | |
8927 | ||
8928 | if (iocbq->iocb.ulpStatus == IOSTAT_LOCAL_REJECT) | |
8929 | lpfc_sli_abts_recover_port(vport, ndlp); | |
8930 | return; | |
8931 | ||
8932 | err_exit: | |
8933 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
8934 | "3095 Event Context not found, no " | |
8935 | "action on vpi %d rpi %d status 0x%x, reason 0x%x\n", | |
8936 | iocbq->iocb.ulpContext, iocbq->iocb.ulpStatus, | |
8937 | vpi, rpi); | |
8938 | } | |
8939 | ||
8940 | /* lpfc_sli4_abts_err_handler - handle a failed ABTS request from an SLI4 port. | |
8941 | * @phba: pointer to HBA context object. | |
8942 | * @ndlp: nodelist pointer for the impacted rport. | |
8943 | * @axri: pointer to the wcqe containing the failed exchange. | |
8944 | * | |
8945 | * The driver calls this routine when it receives an ABORT_XRI_FCP CQE from the | |
8946 | * port. The port generates this event when an abort exchange request to an | |
8947 | * rport fails twice in succession with no reply. The abort could be originated | |
8948 | * by the driver or by the port. The ABTS could have been for an ELS or FCP IO. | |
8949 | */ | |
8950 | void | |
8951 | lpfc_sli4_abts_err_handler(struct lpfc_hba *phba, | |
8952 | struct lpfc_nodelist *ndlp, | |
8953 | struct sli4_wcqe_xri_aborted *axri) | |
8954 | { | |
8955 | struct lpfc_vport *vport; | |
5c1db2ac | 8956 | uint32_t ext_status = 0; |
cb69f7de | 8957 | |
6b5151fd | 8958 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
cb69f7de JS |
8959 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
8960 | "3115 Node Context not found, driver " | |
8961 | "ignoring abts err event\n"); | |
6b5151fd JS |
8962 | return; |
8963 | } | |
8964 | ||
cb69f7de JS |
8965 | vport = ndlp->vport; |
8966 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
8967 | "3116 Port generated FCP XRI ABORT event on " | |
5c1db2ac | 8968 | "vpi %d rpi %d xri x%x status 0x%x parameter x%x\n", |
8e668af5 | 8969 | ndlp->vport->vpi, phba->sli4_hba.rpi_ids[ndlp->nlp_rpi], |
cb69f7de | 8970 | bf_get(lpfc_wcqe_xa_xri, axri), |
5c1db2ac JS |
8971 | bf_get(lpfc_wcqe_xa_status, axri), |
8972 | axri->parameter); | |
cb69f7de | 8973 | |
5c1db2ac JS |
8974 | /* |
8975 | * Catch the ABTS protocol failure case. Older OCe FW releases returned | |
8976 | * LOCAL_REJECT and 0 for a failed ABTS exchange and later OCe and | |
8977 | * LPe FW releases returned LOCAL_REJECT and SEQUENCE_TIMEOUT. | |
8978 | */ | |
e3d2b802 | 8979 | ext_status = axri->parameter & IOERR_PARAM_MASK; |
5c1db2ac JS |
8980 | if ((bf_get(lpfc_wcqe_xa_status, axri) == IOSTAT_LOCAL_REJECT) && |
8981 | ((ext_status == IOERR_SEQUENCE_TIMEOUT) || (ext_status == 0))) | |
cb69f7de JS |
8982 | lpfc_sli_abts_recover_port(vport, ndlp); |
8983 | } | |
8984 | ||
e59058c4 | 8985 | /** |
3621a710 | 8986 | * lpfc_sli_async_event_handler - ASYNC iocb handler function |
e59058c4 JS |
8987 | * @phba: Pointer to HBA context object. |
8988 | * @pring: Pointer to driver SLI ring object. | |
8989 | * @iocbq: Pointer to iocb object. | |
8990 | * | |
8991 | * This function is called by the slow ring event handler | |
8992 | * function when there is an ASYNC event iocb in the ring. | |
8993 | * This function is called with no lock held. | |
8994 | * Currently this function handles only temperature related | |
8995 | * ASYNC events. The function decodes the temperature sensor | |
8996 | * event message and posts events for the management applications. | |
8997 | **/ | |
98c9ea5c | 8998 | static void |
57127f15 JS |
8999 | lpfc_sli_async_event_handler(struct lpfc_hba * phba, |
9000 | struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq) | |
9001 | { | |
9002 | IOCB_t *icmd; | |
9003 | uint16_t evt_code; | |
57127f15 JS |
9004 | struct temp_event temp_event_data; |
9005 | struct Scsi_Host *shost; | |
a257bf90 | 9006 | uint32_t *iocb_w; |
57127f15 JS |
9007 | |
9008 | icmd = &iocbq->iocb; | |
9009 | evt_code = icmd->un.asyncstat.evt_code; | |
57127f15 | 9010 | |
cb69f7de JS |
9011 | switch (evt_code) { |
9012 | case ASYNC_TEMP_WARN: | |
9013 | case ASYNC_TEMP_SAFE: | |
9014 | temp_event_data.data = (uint32_t) icmd->ulpContext; | |
9015 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; | |
9016 | if (evt_code == ASYNC_TEMP_WARN) { | |
9017 | temp_event_data.event_code = LPFC_THRESHOLD_TEMP; | |
9018 | lpfc_printf_log(phba, KERN_ERR, LOG_TEMP, | |
9019 | "0347 Adapter is very hot, please take " | |
9020 | "corrective action. temperature : %d Celsius\n", | |
9021 | (uint32_t) icmd->ulpContext); | |
9022 | } else { | |
9023 | temp_event_data.event_code = LPFC_NORMAL_TEMP; | |
9024 | lpfc_printf_log(phba, KERN_ERR, LOG_TEMP, | |
9025 | "0340 Adapter temperature is OK now. " | |
9026 | "temperature : %d Celsius\n", | |
9027 | (uint32_t) icmd->ulpContext); | |
9028 | } | |
9029 | ||
9030 | /* Send temperature change event to applications */ | |
9031 | shost = lpfc_shost_from_vport(phba->pport); | |
9032 | fc_host_post_vendor_event(shost, fc_get_event_number(), | |
9033 | sizeof(temp_event_data), (char *) &temp_event_data, | |
9034 | LPFC_NL_VENDOR_ID); | |
9035 | break; | |
9036 | case ASYNC_STATUS_CN: | |
9037 | lpfc_sli_abts_err_handler(phba, iocbq); | |
9038 | break; | |
9039 | default: | |
a257bf90 | 9040 | iocb_w = (uint32_t *) icmd; |
cb69f7de | 9041 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
76bb24ef | 9042 | "0346 Ring %d handler: unexpected ASYNC_STATUS" |
e4e74273 | 9043 | " evt_code 0x%x\n" |
a257bf90 JS |
9044 | "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n" |
9045 | "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n" | |
9046 | "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n" | |
9047 | "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n", | |
cb69f7de | 9048 | pring->ringno, icmd->un.asyncstat.evt_code, |
a257bf90 JS |
9049 | iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3], |
9050 | iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7], | |
9051 | iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11], | |
9052 | iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]); | |
9053 | ||
cb69f7de | 9054 | break; |
57127f15 | 9055 | } |
57127f15 JS |
9056 | } |
9057 | ||
9058 | ||
e59058c4 | 9059 | /** |
3621a710 | 9060 | * lpfc_sli_setup - SLI ring setup function |
e59058c4 JS |
9061 | * @phba: Pointer to HBA context object. |
9062 | * | |
9063 | * lpfc_sli_setup sets up rings of the SLI interface with | |
9064 | * number of iocbs per ring and iotags. This function is | |
9065 | * called while driver attach to the HBA and before the | |
9066 | * interrupts are enabled. So there is no need for locking. | |
9067 | * | |
9068 | * This function always returns 0. | |
9069 | **/ | |
dea3101e | 9070 | int |
9071 | lpfc_sli_setup(struct lpfc_hba *phba) | |
9072 | { | |
ed957684 | 9073 | int i, totiocbsize = 0; |
dea3101e | 9074 | struct lpfc_sli *psli = &phba->sli; |
9075 | struct lpfc_sli_ring *pring; | |
9076 | ||
2a76a283 JS |
9077 | psli->num_rings = MAX_SLI3_CONFIGURED_RINGS; |
9078 | if (phba->sli_rev == LPFC_SLI_REV4) | |
67d12733 | 9079 | psli->num_rings += phba->cfg_fcp_io_channel; |
dea3101e | 9080 | psli->sli_flag = 0; |
9081 | psli->fcp_ring = LPFC_FCP_RING; | |
9082 | psli->next_ring = LPFC_FCP_NEXT_RING; | |
a4bc3379 | 9083 | psli->extra_ring = LPFC_EXTRA_RING; |
dea3101e | 9084 | |
604a3e30 JB |
9085 | psli->iocbq_lookup = NULL; |
9086 | psli->iocbq_lookup_len = 0; | |
9087 | psli->last_iotag = 0; | |
9088 | ||
dea3101e | 9089 | for (i = 0; i < psli->num_rings; i++) { |
9090 | pring = &psli->ring[i]; | |
9091 | switch (i) { | |
9092 | case LPFC_FCP_RING: /* ring 0 - FCP */ | |
9093 | /* numCiocb and numRiocb are used in config_port */ | |
7e56aa25 JS |
9094 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R0_ENTRIES; |
9095 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R0_ENTRIES; | |
9096 | pring->sli.sli3.numCiocb += | |
9097 | SLI2_IOCB_CMD_R1XTRA_ENTRIES; | |
9098 | pring->sli.sli3.numRiocb += | |
9099 | SLI2_IOCB_RSP_R1XTRA_ENTRIES; | |
9100 | pring->sli.sli3.numCiocb += | |
9101 | SLI2_IOCB_CMD_R3XTRA_ENTRIES; | |
9102 | pring->sli.sli3.numRiocb += | |
9103 | SLI2_IOCB_RSP_R3XTRA_ENTRIES; | |
9104 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? | |
92d7f7b0 JS |
9105 | SLI3_IOCB_CMD_SIZE : |
9106 | SLI2_IOCB_CMD_SIZE; | |
7e56aa25 | 9107 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
92d7f7b0 JS |
9108 | SLI3_IOCB_RSP_SIZE : |
9109 | SLI2_IOCB_RSP_SIZE; | |
dea3101e | 9110 | pring->iotag_ctr = 0; |
9111 | pring->iotag_max = | |
92d7f7b0 | 9112 | (phba->cfg_hba_queue_depth * 2); |
dea3101e | 9113 | pring->fast_iotag = pring->iotag_max; |
9114 | pring->num_mask = 0; | |
9115 | break; | |
a4bc3379 | 9116 | case LPFC_EXTRA_RING: /* ring 1 - EXTRA */ |
dea3101e | 9117 | /* numCiocb and numRiocb are used in config_port */ |
7e56aa25 JS |
9118 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R1_ENTRIES; |
9119 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R1_ENTRIES; | |
9120 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? | |
92d7f7b0 JS |
9121 | SLI3_IOCB_CMD_SIZE : |
9122 | SLI2_IOCB_CMD_SIZE; | |
7e56aa25 | 9123 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
92d7f7b0 JS |
9124 | SLI3_IOCB_RSP_SIZE : |
9125 | SLI2_IOCB_RSP_SIZE; | |
2e0fef85 | 9126 | pring->iotag_max = phba->cfg_hba_queue_depth; |
dea3101e | 9127 | pring->num_mask = 0; |
9128 | break; | |
9129 | case LPFC_ELS_RING: /* ring 2 - ELS / CT */ | |
9130 | /* numCiocb and numRiocb are used in config_port */ | |
7e56aa25 JS |
9131 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R2_ENTRIES; |
9132 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R2_ENTRIES; | |
9133 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? | |
92d7f7b0 JS |
9134 | SLI3_IOCB_CMD_SIZE : |
9135 | SLI2_IOCB_CMD_SIZE; | |
7e56aa25 | 9136 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
92d7f7b0 JS |
9137 | SLI3_IOCB_RSP_SIZE : |
9138 | SLI2_IOCB_RSP_SIZE; | |
dea3101e | 9139 | pring->fast_iotag = 0; |
9140 | pring->iotag_ctr = 0; | |
9141 | pring->iotag_max = 4096; | |
57127f15 JS |
9142 | pring->lpfc_sli_rcv_async_status = |
9143 | lpfc_sli_async_event_handler; | |
6669f9bb | 9144 | pring->num_mask = LPFC_MAX_RING_MASK; |
dea3101e | 9145 | pring->prt[0].profile = 0; /* Mask 0 */ |
6a9c52cf JS |
9146 | pring->prt[0].rctl = FC_RCTL_ELS_REQ; |
9147 | pring->prt[0].type = FC_TYPE_ELS; | |
dea3101e | 9148 | pring->prt[0].lpfc_sli_rcv_unsol_event = |
92d7f7b0 | 9149 | lpfc_els_unsol_event; |
dea3101e | 9150 | pring->prt[1].profile = 0; /* Mask 1 */ |
6a9c52cf JS |
9151 | pring->prt[1].rctl = FC_RCTL_ELS_REP; |
9152 | pring->prt[1].type = FC_TYPE_ELS; | |
dea3101e | 9153 | pring->prt[1].lpfc_sli_rcv_unsol_event = |
92d7f7b0 | 9154 | lpfc_els_unsol_event; |
dea3101e | 9155 | pring->prt[2].profile = 0; /* Mask 2 */ |
9156 | /* NameServer Inquiry */ | |
6a9c52cf | 9157 | pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL; |
dea3101e | 9158 | /* NameServer */ |
6a9c52cf | 9159 | pring->prt[2].type = FC_TYPE_CT; |
dea3101e | 9160 | pring->prt[2].lpfc_sli_rcv_unsol_event = |
92d7f7b0 | 9161 | lpfc_ct_unsol_event; |
dea3101e | 9162 | pring->prt[3].profile = 0; /* Mask 3 */ |
9163 | /* NameServer response */ | |
6a9c52cf | 9164 | pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL; |
dea3101e | 9165 | /* NameServer */ |
6a9c52cf | 9166 | pring->prt[3].type = FC_TYPE_CT; |
dea3101e | 9167 | pring->prt[3].lpfc_sli_rcv_unsol_event = |
92d7f7b0 | 9168 | lpfc_ct_unsol_event; |
dea3101e | 9169 | break; |
9170 | } | |
7e56aa25 JS |
9171 | totiocbsize += (pring->sli.sli3.numCiocb * |
9172 | pring->sli.sli3.sizeCiocb) + | |
9173 | (pring->sli.sli3.numRiocb * pring->sli.sli3.sizeRiocb); | |
dea3101e | 9174 | } |
ed957684 | 9175 | if (totiocbsize > MAX_SLIM_IOCB_SIZE) { |
dea3101e | 9176 | /* Too many cmd / rsp ring entries in SLI2 SLIM */ |
e8b62011 JS |
9177 | printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in " |
9178 | "SLI2 SLIM Data: x%x x%lx\n", | |
9179 | phba->brd_no, totiocbsize, | |
9180 | (unsigned long) MAX_SLIM_IOCB_SIZE); | |
dea3101e | 9181 | } |
cf5bf97e JW |
9182 | if (phba->cfg_multi_ring_support == 2) |
9183 | lpfc_extra_ring_setup(phba); | |
dea3101e | 9184 | |
9185 | return 0; | |
9186 | } | |
9187 | ||
e59058c4 | 9188 | /** |
3621a710 | 9189 | * lpfc_sli_queue_setup - Queue initialization function |
e59058c4 JS |
9190 | * @phba: Pointer to HBA context object. |
9191 | * | |
9192 | * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each | |
9193 | * ring. This function also initializes ring indices of each ring. | |
9194 | * This function is called during the initialization of the SLI | |
9195 | * interface of an HBA. | |
9196 | * This function is called with no lock held and always returns | |
9197 | * 1. | |
9198 | **/ | |
dea3101e | 9199 | int |
2e0fef85 | 9200 | lpfc_sli_queue_setup(struct lpfc_hba *phba) |
dea3101e | 9201 | { |
9202 | struct lpfc_sli *psli; | |
9203 | struct lpfc_sli_ring *pring; | |
604a3e30 | 9204 | int i; |
dea3101e | 9205 | |
9206 | psli = &phba->sli; | |
2e0fef85 | 9207 | spin_lock_irq(&phba->hbalock); |
dea3101e | 9208 | INIT_LIST_HEAD(&psli->mboxq); |
92d7f7b0 | 9209 | INIT_LIST_HEAD(&psli->mboxq_cmpl); |
dea3101e | 9210 | /* Initialize list headers for txq and txcmplq as double linked lists */ |
9211 | for (i = 0; i < psli->num_rings; i++) { | |
9212 | pring = &psli->ring[i]; | |
9213 | pring->ringno = i; | |
7e56aa25 JS |
9214 | pring->sli.sli3.next_cmdidx = 0; |
9215 | pring->sli.sli3.local_getidx = 0; | |
9216 | pring->sli.sli3.cmdidx = 0; | |
68e814f5 | 9217 | pring->flag = 0; |
dea3101e | 9218 | INIT_LIST_HEAD(&pring->txq); |
9219 | INIT_LIST_HEAD(&pring->txcmplq); | |
9220 | INIT_LIST_HEAD(&pring->iocb_continueq); | |
9c2face6 | 9221 | INIT_LIST_HEAD(&pring->iocb_continue_saveq); |
dea3101e | 9222 | INIT_LIST_HEAD(&pring->postbufq); |
7e56aa25 | 9223 | spin_lock_init(&pring->ring_lock); |
dea3101e | 9224 | } |
2e0fef85 JS |
9225 | spin_unlock_irq(&phba->hbalock); |
9226 | return 1; | |
dea3101e | 9227 | } |
9228 | ||
04c68496 JS |
9229 | /** |
9230 | * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system | |
9231 | * @phba: Pointer to HBA context object. | |
9232 | * | |
9233 | * This routine flushes the mailbox command subsystem. It will unconditionally | |
9234 | * flush all the mailbox commands in the three possible stages in the mailbox | |
9235 | * command sub-system: pending mailbox command queue; the outstanding mailbox | |
9236 | * command; and completed mailbox command queue. It is caller's responsibility | |
9237 | * to make sure that the driver is in the proper state to flush the mailbox | |
9238 | * command sub-system. Namely, the posting of mailbox commands into the | |
9239 | * pending mailbox command queue from the various clients must be stopped; | |
9240 | * either the HBA is in a state that it will never works on the outstanding | |
9241 | * mailbox command (such as in EEH or ERATT conditions) or the outstanding | |
9242 | * mailbox command has been completed. | |
9243 | **/ | |
9244 | static void | |
9245 | lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba) | |
9246 | { | |
9247 | LIST_HEAD(completions); | |
9248 | struct lpfc_sli *psli = &phba->sli; | |
9249 | LPFC_MBOXQ_t *pmb; | |
9250 | unsigned long iflag; | |
9251 | ||
9252 | /* Flush all the mailbox commands in the mbox system */ | |
9253 | spin_lock_irqsave(&phba->hbalock, iflag); | |
9254 | /* The pending mailbox command queue */ | |
9255 | list_splice_init(&phba->sli.mboxq, &completions); | |
9256 | /* The outstanding active mailbox command */ | |
9257 | if (psli->mbox_active) { | |
9258 | list_add_tail(&psli->mbox_active->list, &completions); | |
9259 | psli->mbox_active = NULL; | |
9260 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
9261 | } | |
9262 | /* The completed mailbox command queue */ | |
9263 | list_splice_init(&phba->sli.mboxq_cmpl, &completions); | |
9264 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
9265 | ||
9266 | /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */ | |
9267 | while (!list_empty(&completions)) { | |
9268 | list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list); | |
9269 | pmb->u.mb.mbxStatus = MBX_NOT_FINISHED; | |
9270 | if (pmb->mbox_cmpl) | |
9271 | pmb->mbox_cmpl(phba, pmb); | |
9272 | } | |
9273 | } | |
9274 | ||
e59058c4 | 9275 | /** |
3621a710 | 9276 | * lpfc_sli_host_down - Vport cleanup function |
e59058c4 JS |
9277 | * @vport: Pointer to virtual port object. |
9278 | * | |
9279 | * lpfc_sli_host_down is called to clean up the resources | |
9280 | * associated with a vport before destroying virtual | |
9281 | * port data structures. | |
9282 | * This function does following operations: | |
9283 | * - Free discovery resources associated with this virtual | |
9284 | * port. | |
9285 | * - Free iocbs associated with this virtual port in | |
9286 | * the txq. | |
9287 | * - Send abort for all iocb commands associated with this | |
9288 | * vport in txcmplq. | |
9289 | * | |
9290 | * This function is called with no lock held and always returns 1. | |
9291 | **/ | |
92d7f7b0 JS |
9292 | int |
9293 | lpfc_sli_host_down(struct lpfc_vport *vport) | |
9294 | { | |
858c9f6c | 9295 | LIST_HEAD(completions); |
92d7f7b0 JS |
9296 | struct lpfc_hba *phba = vport->phba; |
9297 | struct lpfc_sli *psli = &phba->sli; | |
9298 | struct lpfc_sli_ring *pring; | |
9299 | struct lpfc_iocbq *iocb, *next_iocb; | |
92d7f7b0 JS |
9300 | int i; |
9301 | unsigned long flags = 0; | |
9302 | uint16_t prev_pring_flag; | |
9303 | ||
9304 | lpfc_cleanup_discovery_resources(vport); | |
9305 | ||
9306 | spin_lock_irqsave(&phba->hbalock, flags); | |
92d7f7b0 JS |
9307 | for (i = 0; i < psli->num_rings; i++) { |
9308 | pring = &psli->ring[i]; | |
9309 | prev_pring_flag = pring->flag; | |
5e9d9b82 JS |
9310 | /* Only slow rings */ |
9311 | if (pring->ringno == LPFC_ELS_RING) { | |
858c9f6c | 9312 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
5e9d9b82 JS |
9313 | /* Set the lpfc data pending flag */ |
9314 | set_bit(LPFC_DATA_READY, &phba->data_flags); | |
9315 | } | |
92d7f7b0 JS |
9316 | /* |
9317 | * Error everything on the txq since these iocbs have not been | |
9318 | * given to the FW yet. | |
9319 | */ | |
92d7f7b0 JS |
9320 | list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) { |
9321 | if (iocb->vport != vport) | |
9322 | continue; | |
858c9f6c | 9323 | list_move_tail(&iocb->list, &completions); |
92d7f7b0 JS |
9324 | } |
9325 | ||
9326 | /* Next issue ABTS for everything on the txcmplq */ | |
9327 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, | |
9328 | list) { | |
9329 | if (iocb->vport != vport) | |
9330 | continue; | |
9331 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); | |
9332 | } | |
9333 | ||
9334 | pring->flag = prev_pring_flag; | |
9335 | } | |
9336 | ||
9337 | spin_unlock_irqrestore(&phba->hbalock, flags); | |
9338 | ||
a257bf90 JS |
9339 | /* Cancel all the IOCBs from the completions list */ |
9340 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, | |
9341 | IOERR_SLI_DOWN); | |
92d7f7b0 JS |
9342 | return 1; |
9343 | } | |
9344 | ||
e59058c4 | 9345 | /** |
3621a710 | 9346 | * lpfc_sli_hba_down - Resource cleanup function for the HBA |
e59058c4 JS |
9347 | * @phba: Pointer to HBA context object. |
9348 | * | |
9349 | * This function cleans up all iocb, buffers, mailbox commands | |
9350 | * while shutting down the HBA. This function is called with no | |
9351 | * lock held and always returns 1. | |
9352 | * This function does the following to cleanup driver resources: | |
9353 | * - Free discovery resources for each virtual port | |
9354 | * - Cleanup any pending fabric iocbs | |
9355 | * - Iterate through the iocb txq and free each entry | |
9356 | * in the list. | |
9357 | * - Free up any buffer posted to the HBA | |
9358 | * - Free mailbox commands in the mailbox queue. | |
9359 | **/ | |
dea3101e | 9360 | int |
2e0fef85 | 9361 | lpfc_sli_hba_down(struct lpfc_hba *phba) |
dea3101e | 9362 | { |
2534ba75 | 9363 | LIST_HEAD(completions); |
2e0fef85 | 9364 | struct lpfc_sli *psli = &phba->sli; |
dea3101e | 9365 | struct lpfc_sli_ring *pring; |
0ff10d46 | 9366 | struct lpfc_dmabuf *buf_ptr; |
dea3101e | 9367 | unsigned long flags = 0; |
04c68496 JS |
9368 | int i; |
9369 | ||
9370 | /* Shutdown the mailbox command sub-system */ | |
618a5230 | 9371 | lpfc_sli_mbox_sys_shutdown(phba, LPFC_MBX_WAIT); |
dea3101e | 9372 | |
dea3101e | 9373 | lpfc_hba_down_prep(phba); |
9374 | ||
92d7f7b0 JS |
9375 | lpfc_fabric_abort_hba(phba); |
9376 | ||
2e0fef85 | 9377 | spin_lock_irqsave(&phba->hbalock, flags); |
dea3101e | 9378 | for (i = 0; i < psli->num_rings; i++) { |
9379 | pring = &psli->ring[i]; | |
5e9d9b82 JS |
9380 | /* Only slow rings */ |
9381 | if (pring->ringno == LPFC_ELS_RING) { | |
858c9f6c | 9382 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
5e9d9b82 JS |
9383 | /* Set the lpfc data pending flag */ |
9384 | set_bit(LPFC_DATA_READY, &phba->data_flags); | |
9385 | } | |
dea3101e | 9386 | |
9387 | /* | |
9388 | * Error everything on the txq since these iocbs have not been | |
9389 | * given to the FW yet. | |
9390 | */ | |
2534ba75 | 9391 | list_splice_init(&pring->txq, &completions); |
2534ba75 | 9392 | } |
2e0fef85 | 9393 | spin_unlock_irqrestore(&phba->hbalock, flags); |
dea3101e | 9394 | |
a257bf90 JS |
9395 | /* Cancel all the IOCBs from the completions list */ |
9396 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, | |
9397 | IOERR_SLI_DOWN); | |
dea3101e | 9398 | |
0ff10d46 JS |
9399 | spin_lock_irqsave(&phba->hbalock, flags); |
9400 | list_splice_init(&phba->elsbuf, &completions); | |
9401 | phba->elsbuf_cnt = 0; | |
9402 | phba->elsbuf_prev_cnt = 0; | |
9403 | spin_unlock_irqrestore(&phba->hbalock, flags); | |
9404 | ||
9405 | while (!list_empty(&completions)) { | |
9406 | list_remove_head(&completions, buf_ptr, | |
9407 | struct lpfc_dmabuf, list); | |
9408 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); | |
9409 | kfree(buf_ptr); | |
9410 | } | |
9411 | ||
dea3101e | 9412 | /* Return any active mbox cmds */ |
9413 | del_timer_sync(&psli->mbox_tmo); | |
2e0fef85 | 9414 | |
da0436e9 | 9415 | spin_lock_irqsave(&phba->pport->work_port_lock, flags); |
2e0fef85 | 9416 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
da0436e9 | 9417 | spin_unlock_irqrestore(&phba->pport->work_port_lock, flags); |
2e0fef85 | 9418 | |
da0436e9 JS |
9419 | return 1; |
9420 | } | |
9421 | ||
e59058c4 | 9422 | /** |
3621a710 | 9423 | * lpfc_sli_pcimem_bcopy - SLI memory copy function |
e59058c4 JS |
9424 | * @srcp: Source memory pointer. |
9425 | * @destp: Destination memory pointer. | |
9426 | * @cnt: Number of words required to be copied. | |
9427 | * | |
9428 | * This function is used for copying data between driver memory | |
9429 | * and the SLI memory. This function also changes the endianness | |
9430 | * of each word if native endianness is different from SLI | |
9431 | * endianness. This function can be called with or without | |
9432 | * lock. | |
9433 | **/ | |
dea3101e | 9434 | void |
9435 | lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt) | |
9436 | { | |
9437 | uint32_t *src = srcp; | |
9438 | uint32_t *dest = destp; | |
9439 | uint32_t ldata; | |
9440 | int i; | |
9441 | ||
9442 | for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) { | |
9443 | ldata = *src; | |
9444 | ldata = le32_to_cpu(ldata); | |
9445 | *dest = ldata; | |
9446 | src++; | |
9447 | dest++; | |
9448 | } | |
9449 | } | |
9450 | ||
e59058c4 | 9451 | |
a0c87cbd JS |
9452 | /** |
9453 | * lpfc_sli_bemem_bcopy - SLI memory copy function | |
9454 | * @srcp: Source memory pointer. | |
9455 | * @destp: Destination memory pointer. | |
9456 | * @cnt: Number of words required to be copied. | |
9457 | * | |
9458 | * This function is used for copying data between a data structure | |
9459 | * with big endian representation to local endianness. | |
9460 | * This function can be called with or without lock. | |
9461 | **/ | |
9462 | void | |
9463 | lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt) | |
9464 | { | |
9465 | uint32_t *src = srcp; | |
9466 | uint32_t *dest = destp; | |
9467 | uint32_t ldata; | |
9468 | int i; | |
9469 | ||
9470 | for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) { | |
9471 | ldata = *src; | |
9472 | ldata = be32_to_cpu(ldata); | |
9473 | *dest = ldata; | |
9474 | src++; | |
9475 | dest++; | |
9476 | } | |
9477 | } | |
9478 | ||
e59058c4 | 9479 | /** |
3621a710 | 9480 | * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq |
e59058c4 JS |
9481 | * @phba: Pointer to HBA context object. |
9482 | * @pring: Pointer to driver SLI ring object. | |
9483 | * @mp: Pointer to driver buffer object. | |
9484 | * | |
9485 | * This function is called with no lock held. | |
9486 | * It always return zero after adding the buffer to the postbufq | |
9487 | * buffer list. | |
9488 | **/ | |
dea3101e | 9489 | int |
2e0fef85 JS |
9490 | lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
9491 | struct lpfc_dmabuf *mp) | |
dea3101e | 9492 | { |
9493 | /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up | |
9494 | later */ | |
2e0fef85 | 9495 | spin_lock_irq(&phba->hbalock); |
dea3101e | 9496 | list_add_tail(&mp->list, &pring->postbufq); |
dea3101e | 9497 | pring->postbufq_cnt++; |
2e0fef85 | 9498 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 9499 | return 0; |
9500 | } | |
9501 | ||
e59058c4 | 9502 | /** |
3621a710 | 9503 | * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer |
e59058c4 JS |
9504 | * @phba: Pointer to HBA context object. |
9505 | * | |
9506 | * When HBQ is enabled, buffers are searched based on tags. This function | |
9507 | * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The | |
9508 | * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag | |
9509 | * does not conflict with tags of buffer posted for unsolicited events. | |
9510 | * The function returns the allocated tag. The function is called with | |
9511 | * no locks held. | |
9512 | **/ | |
76bb24ef JS |
9513 | uint32_t |
9514 | lpfc_sli_get_buffer_tag(struct lpfc_hba *phba) | |
9515 | { | |
9516 | spin_lock_irq(&phba->hbalock); | |
9517 | phba->buffer_tag_count++; | |
9518 | /* | |
9519 | * Always set the QUE_BUFTAG_BIT to distiguish between | |
9520 | * a tag assigned by HBQ. | |
9521 | */ | |
9522 | phba->buffer_tag_count |= QUE_BUFTAG_BIT; | |
9523 | spin_unlock_irq(&phba->hbalock); | |
9524 | return phba->buffer_tag_count; | |
9525 | } | |
9526 | ||
e59058c4 | 9527 | /** |
3621a710 | 9528 | * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag |
e59058c4 JS |
9529 | * @phba: Pointer to HBA context object. |
9530 | * @pring: Pointer to driver SLI ring object. | |
9531 | * @tag: Buffer tag. | |
9532 | * | |
9533 | * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq | |
9534 | * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX | |
9535 | * iocb is posted to the response ring with the tag of the buffer. | |
9536 | * This function searches the pring->postbufq list using the tag | |
9537 | * to find buffer associated with CMD_IOCB_RET_XRI64_CX | |
9538 | * iocb. If the buffer is found then lpfc_dmabuf object of the | |
9539 | * buffer is returned to the caller else NULL is returned. | |
9540 | * This function is called with no lock held. | |
9541 | **/ | |
76bb24ef JS |
9542 | struct lpfc_dmabuf * |
9543 | lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
9544 | uint32_t tag) | |
9545 | { | |
9546 | struct lpfc_dmabuf *mp, *next_mp; | |
9547 | struct list_head *slp = &pring->postbufq; | |
9548 | ||
25985edc | 9549 | /* Search postbufq, from the beginning, looking for a match on tag */ |
76bb24ef JS |
9550 | spin_lock_irq(&phba->hbalock); |
9551 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { | |
9552 | if (mp->buffer_tag == tag) { | |
9553 | list_del_init(&mp->list); | |
9554 | pring->postbufq_cnt--; | |
9555 | spin_unlock_irq(&phba->hbalock); | |
9556 | return mp; | |
9557 | } | |
9558 | } | |
9559 | ||
9560 | spin_unlock_irq(&phba->hbalock); | |
9561 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
d7c255b2 | 9562 | "0402 Cannot find virtual addr for buffer tag on " |
76bb24ef JS |
9563 | "ring %d Data x%lx x%p x%p x%x\n", |
9564 | pring->ringno, (unsigned long) tag, | |
9565 | slp->next, slp->prev, pring->postbufq_cnt); | |
9566 | ||
9567 | return NULL; | |
9568 | } | |
dea3101e | 9569 | |
e59058c4 | 9570 | /** |
3621a710 | 9571 | * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events |
e59058c4 JS |
9572 | * @phba: Pointer to HBA context object. |
9573 | * @pring: Pointer to driver SLI ring object. | |
9574 | * @phys: DMA address of the buffer. | |
9575 | * | |
9576 | * This function searches the buffer list using the dma_address | |
9577 | * of unsolicited event to find the driver's lpfc_dmabuf object | |
9578 | * corresponding to the dma_address. The function returns the | |
9579 | * lpfc_dmabuf object if a buffer is found else it returns NULL. | |
9580 | * This function is called by the ct and els unsolicited event | |
9581 | * handlers to get the buffer associated with the unsolicited | |
9582 | * event. | |
9583 | * | |
9584 | * This function is called with no lock held. | |
9585 | **/ | |
dea3101e | 9586 | struct lpfc_dmabuf * |
9587 | lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
9588 | dma_addr_t phys) | |
9589 | { | |
9590 | struct lpfc_dmabuf *mp, *next_mp; | |
9591 | struct list_head *slp = &pring->postbufq; | |
9592 | ||
25985edc | 9593 | /* Search postbufq, from the beginning, looking for a match on phys */ |
2e0fef85 | 9594 | spin_lock_irq(&phba->hbalock); |
dea3101e | 9595 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
9596 | if (mp->phys == phys) { | |
9597 | list_del_init(&mp->list); | |
9598 | pring->postbufq_cnt--; | |
2e0fef85 | 9599 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 9600 | return mp; |
9601 | } | |
9602 | } | |
9603 | ||
2e0fef85 | 9604 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 9605 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 9606 | "0410 Cannot find virtual addr for mapped buf on " |
dea3101e | 9607 | "ring %d Data x%llx x%p x%p x%x\n", |
e8b62011 | 9608 | pring->ringno, (unsigned long long)phys, |
dea3101e | 9609 | slp->next, slp->prev, pring->postbufq_cnt); |
9610 | return NULL; | |
9611 | } | |
9612 | ||
e59058c4 | 9613 | /** |
3621a710 | 9614 | * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs |
e59058c4 JS |
9615 | * @phba: Pointer to HBA context object. |
9616 | * @cmdiocb: Pointer to driver command iocb object. | |
9617 | * @rspiocb: Pointer to driver response iocb object. | |
9618 | * | |
9619 | * This function is the completion handler for the abort iocbs for | |
9620 | * ELS commands. This function is called from the ELS ring event | |
9621 | * handler with no lock held. This function frees memory resources | |
9622 | * associated with the abort iocb. | |
9623 | **/ | |
dea3101e | 9624 | static void |
2e0fef85 JS |
9625 | lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
9626 | struct lpfc_iocbq *rspiocb) | |
dea3101e | 9627 | { |
2e0fef85 | 9628 | IOCB_t *irsp = &rspiocb->iocb; |
2680eeaa | 9629 | uint16_t abort_iotag, abort_context; |
ff78d8f9 | 9630 | struct lpfc_iocbq *abort_iocb = NULL; |
2680eeaa JS |
9631 | |
9632 | if (irsp->ulpStatus) { | |
ff78d8f9 JS |
9633 | |
9634 | /* | |
9635 | * Assume that the port already completed and returned, or | |
9636 | * will return the iocb. Just Log the message. | |
9637 | */ | |
2680eeaa JS |
9638 | abort_context = cmdiocb->iocb.un.acxri.abortContextTag; |
9639 | abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag; | |
9640 | ||
2e0fef85 | 9641 | spin_lock_irq(&phba->hbalock); |
45ed1190 JS |
9642 | if (phba->sli_rev < LPFC_SLI_REV4) { |
9643 | if (abort_iotag != 0 && | |
9644 | abort_iotag <= phba->sli.last_iotag) | |
9645 | abort_iocb = | |
9646 | phba->sli.iocbq_lookup[abort_iotag]; | |
9647 | } else | |
9648 | /* For sli4 the abort_tag is the XRI, | |
9649 | * so the abort routine puts the iotag of the iocb | |
9650 | * being aborted in the context field of the abort | |
9651 | * IOCB. | |
9652 | */ | |
9653 | abort_iocb = phba->sli.iocbq_lookup[abort_context]; | |
2680eeaa | 9654 | |
2a9bf3d0 JS |
9655 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_SLI, |
9656 | "0327 Cannot abort els iocb %p " | |
9657 | "with tag %x context %x, abort status %x, " | |
9658 | "abort code %x\n", | |
9659 | abort_iocb, abort_iotag, abort_context, | |
9660 | irsp->ulpStatus, irsp->un.ulpWord[4]); | |
341af102 | 9661 | |
ff78d8f9 | 9662 | spin_unlock_irq(&phba->hbalock); |
2680eeaa | 9663 | } |
604a3e30 | 9664 | lpfc_sli_release_iocbq(phba, cmdiocb); |
dea3101e | 9665 | return; |
9666 | } | |
9667 | ||
e59058c4 | 9668 | /** |
3621a710 | 9669 | * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command |
e59058c4 JS |
9670 | * @phba: Pointer to HBA context object. |
9671 | * @cmdiocb: Pointer to driver command iocb object. | |
9672 | * @rspiocb: Pointer to driver response iocb object. | |
9673 | * | |
9674 | * The function is called from SLI ring event handler with no | |
9675 | * lock held. This function is the completion handler for ELS commands | |
9676 | * which are aborted. The function frees memory resources used for | |
9677 | * the aborted ELS commands. | |
9678 | **/ | |
92d7f7b0 JS |
9679 | static void |
9680 | lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, | |
9681 | struct lpfc_iocbq *rspiocb) | |
9682 | { | |
9683 | IOCB_t *irsp = &rspiocb->iocb; | |
9684 | ||
9685 | /* ELS cmd tag <ulpIoTag> completes */ | |
9686 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, | |
d7c255b2 | 9687 | "0139 Ignoring ELS cmd tag x%x completion Data: " |
92d7f7b0 | 9688 | "x%x x%x x%x\n", |
e8b62011 | 9689 | irsp->ulpIoTag, irsp->ulpStatus, |
92d7f7b0 | 9690 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
858c9f6c JS |
9691 | if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) |
9692 | lpfc_ct_free_iocb(phba, cmdiocb); | |
9693 | else | |
9694 | lpfc_els_free_iocb(phba, cmdiocb); | |
92d7f7b0 JS |
9695 | return; |
9696 | } | |
9697 | ||
e59058c4 | 9698 | /** |
5af5eee7 | 9699 | * lpfc_sli_abort_iotag_issue - Issue abort for a command iocb |
e59058c4 JS |
9700 | * @phba: Pointer to HBA context object. |
9701 | * @pring: Pointer to driver SLI ring object. | |
9702 | * @cmdiocb: Pointer to driver command iocb object. | |
9703 | * | |
5af5eee7 JS |
9704 | * This function issues an abort iocb for the provided command iocb down to |
9705 | * the port. Other than the case the outstanding command iocb is an abort | |
9706 | * request, this function issues abort out unconditionally. This function is | |
9707 | * called with hbalock held. The function returns 0 when it fails due to | |
9708 | * memory allocation failure or when the command iocb is an abort request. | |
e59058c4 | 9709 | **/ |
5af5eee7 JS |
9710 | static int |
9711 | lpfc_sli_abort_iotag_issue(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
2e0fef85 | 9712 | struct lpfc_iocbq *cmdiocb) |
dea3101e | 9713 | { |
2e0fef85 | 9714 | struct lpfc_vport *vport = cmdiocb->vport; |
0bd4ca25 | 9715 | struct lpfc_iocbq *abtsiocbp; |
dea3101e | 9716 | IOCB_t *icmd = NULL; |
9717 | IOCB_t *iabt = NULL; | |
5af5eee7 | 9718 | int retval; |
7e56aa25 | 9719 | unsigned long iflags; |
07951076 | 9720 | |
92d7f7b0 JS |
9721 | /* |
9722 | * There are certain command types we don't want to abort. And we | |
9723 | * don't want to abort commands that are already in the process of | |
9724 | * being aborted. | |
07951076 JS |
9725 | */ |
9726 | icmd = &cmdiocb->iocb; | |
2e0fef85 | 9727 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || |
92d7f7b0 JS |
9728 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || |
9729 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) | |
07951076 JS |
9730 | return 0; |
9731 | ||
dea3101e | 9732 | /* issue ABTS for this IOCB based on iotag */ |
92d7f7b0 | 9733 | abtsiocbp = __lpfc_sli_get_iocbq(phba); |
dea3101e | 9734 | if (abtsiocbp == NULL) |
9735 | return 0; | |
dea3101e | 9736 | |
07951076 | 9737 | /* This signals the response to set the correct status |
341af102 | 9738 | * before calling the completion handler |
07951076 JS |
9739 | */ |
9740 | cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED; | |
9741 | ||
dea3101e | 9742 | iabt = &abtsiocbp->iocb; |
07951076 JS |
9743 | iabt->un.acxri.abortType = ABORT_TYPE_ABTS; |
9744 | iabt->un.acxri.abortContextTag = icmd->ulpContext; | |
45ed1190 | 9745 | if (phba->sli_rev == LPFC_SLI_REV4) { |
da0436e9 | 9746 | iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag; |
45ed1190 JS |
9747 | iabt->un.acxri.abortContextTag = cmdiocb->iotag; |
9748 | } | |
da0436e9 JS |
9749 | else |
9750 | iabt->un.acxri.abortIoTag = icmd->ulpIoTag; | |
07951076 JS |
9751 | iabt->ulpLe = 1; |
9752 | iabt->ulpClass = icmd->ulpClass; | |
dea3101e | 9753 | |
5ffc266e JS |
9754 | /* ABTS WQE must go to the same WQ as the WQE to be aborted */ |
9755 | abtsiocbp->fcp_wqidx = cmdiocb->fcp_wqidx; | |
341af102 JS |
9756 | if (cmdiocb->iocb_flag & LPFC_IO_FCP) |
9757 | abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX; | |
5ffc266e | 9758 | |
2e0fef85 | 9759 | if (phba->link_state >= LPFC_LINK_UP) |
07951076 JS |
9760 | iabt->ulpCommand = CMD_ABORT_XRI_CN; |
9761 | else | |
9762 | iabt->ulpCommand = CMD_CLOSE_XRI_CN; | |
dea3101e | 9763 | |
07951076 | 9764 | abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl; |
5b8bd0c9 | 9765 | |
e8b62011 JS |
9766 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
9767 | "0339 Abort xri x%x, original iotag x%x, " | |
9768 | "abort cmd iotag x%x\n", | |
2a9bf3d0 | 9769 | iabt->un.acxri.abortIoTag, |
e8b62011 | 9770 | iabt->un.acxri.abortContextTag, |
2a9bf3d0 | 9771 | abtsiocbp->iotag); |
7e56aa25 JS |
9772 | |
9773 | if (phba->sli_rev == LPFC_SLI_REV4) { | |
9774 | /* Note: both hbalock and ring_lock need to be set here */ | |
9775 | spin_lock_irqsave(&pring->ring_lock, iflags); | |
9776 | retval = __lpfc_sli_issue_iocb(phba, pring->ringno, | |
9777 | abtsiocbp, 0); | |
9778 | spin_unlock_irqrestore(&pring->ring_lock, iflags); | |
9779 | } else { | |
9780 | retval = __lpfc_sli_issue_iocb(phba, pring->ringno, | |
9781 | abtsiocbp, 0); | |
9782 | } | |
dea3101e | 9783 | |
d7c255b2 JS |
9784 | if (retval) |
9785 | __lpfc_sli_release_iocbq(phba, abtsiocbp); | |
5af5eee7 JS |
9786 | |
9787 | /* | |
9788 | * Caller to this routine should check for IOCB_ERROR | |
9789 | * and handle it properly. This routine no longer removes | |
9790 | * iocb off txcmplq and call compl in case of IOCB_ERROR. | |
9791 | */ | |
9792 | return retval; | |
9793 | } | |
9794 | ||
9795 | /** | |
9796 | * lpfc_sli_issue_abort_iotag - Abort function for a command iocb | |
9797 | * @phba: Pointer to HBA context object. | |
9798 | * @pring: Pointer to driver SLI ring object. | |
9799 | * @cmdiocb: Pointer to driver command iocb object. | |
9800 | * | |
9801 | * This function issues an abort iocb for the provided command iocb. In case | |
9802 | * of unloading, the abort iocb will not be issued to commands on the ELS | |
9803 | * ring. Instead, the callback function shall be changed to those commands | |
9804 | * so that nothing happens when them finishes. This function is called with | |
9805 | * hbalock held. The function returns 0 when the command iocb is an abort | |
9806 | * request. | |
9807 | **/ | |
9808 | int | |
9809 | lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
9810 | struct lpfc_iocbq *cmdiocb) | |
9811 | { | |
9812 | struct lpfc_vport *vport = cmdiocb->vport; | |
9813 | int retval = IOCB_ERROR; | |
9814 | IOCB_t *icmd = NULL; | |
9815 | ||
9816 | /* | |
9817 | * There are certain command types we don't want to abort. And we | |
9818 | * don't want to abort commands that are already in the process of | |
9819 | * being aborted. | |
9820 | */ | |
9821 | icmd = &cmdiocb->iocb; | |
9822 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || | |
9823 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || | |
9824 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) | |
9825 | return 0; | |
9826 | ||
9827 | /* | |
9828 | * If we're unloading, don't abort iocb on the ELS ring, but change | |
9829 | * the callback so that nothing happens when it finishes. | |
9830 | */ | |
9831 | if ((vport->load_flag & FC_UNLOADING) && | |
9832 | (pring->ringno == LPFC_ELS_RING)) { | |
9833 | if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) | |
9834 | cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl; | |
9835 | else | |
9836 | cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl; | |
9837 | goto abort_iotag_exit; | |
9838 | } | |
9839 | ||
9840 | /* Now, we try to issue the abort to the cmdiocb out */ | |
9841 | retval = lpfc_sli_abort_iotag_issue(phba, pring, cmdiocb); | |
9842 | ||
07951076 | 9843 | abort_iotag_exit: |
2e0fef85 JS |
9844 | /* |
9845 | * Caller to this routine should check for IOCB_ERROR | |
9846 | * and handle it properly. This routine no longer removes | |
9847 | * iocb off txcmplq and call compl in case of IOCB_ERROR. | |
07951076 | 9848 | */ |
2e0fef85 | 9849 | return retval; |
dea3101e | 9850 | } |
9851 | ||
5af5eee7 JS |
9852 | /** |
9853 | * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba. | |
9854 | * @phba: pointer to lpfc HBA data structure. | |
9855 | * | |
9856 | * This routine will abort all pending and outstanding iocbs to an HBA. | |
9857 | **/ | |
9858 | void | |
9859 | lpfc_sli_hba_iocb_abort(struct lpfc_hba *phba) | |
9860 | { | |
9861 | struct lpfc_sli *psli = &phba->sli; | |
9862 | struct lpfc_sli_ring *pring; | |
9863 | int i; | |
9864 | ||
9865 | for (i = 0; i < psli->num_rings; i++) { | |
9866 | pring = &psli->ring[i]; | |
db55fba8 | 9867 | lpfc_sli_abort_iocb_ring(phba, pring); |
5af5eee7 JS |
9868 | } |
9869 | } | |
9870 | ||
e59058c4 | 9871 | /** |
3621a710 | 9872 | * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN |
e59058c4 JS |
9873 | * @iocbq: Pointer to driver iocb object. |
9874 | * @vport: Pointer to driver virtual port object. | |
9875 | * @tgt_id: SCSI ID of the target. | |
9876 | * @lun_id: LUN ID of the scsi device. | |
9877 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST | |
9878 | * | |
3621a710 | 9879 | * This function acts as an iocb filter for functions which abort or count |
e59058c4 JS |
9880 | * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return |
9881 | * 0 if the filtering criteria is met for the given iocb and will return | |
9882 | * 1 if the filtering criteria is not met. | |
9883 | * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the | |
9884 | * given iocb is for the SCSI device specified by vport, tgt_id and | |
9885 | * lun_id parameter. | |
9886 | * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the | |
9887 | * given iocb is for the SCSI target specified by vport and tgt_id | |
9888 | * parameters. | |
9889 | * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the | |
9890 | * given iocb is for the SCSI host associated with the given vport. | |
9891 | * This function is called with no locks held. | |
9892 | **/ | |
dea3101e | 9893 | static int |
51ef4c26 JS |
9894 | lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport, |
9895 | uint16_t tgt_id, uint64_t lun_id, | |
0bd4ca25 | 9896 | lpfc_ctx_cmd ctx_cmd) |
dea3101e | 9897 | { |
0bd4ca25 | 9898 | struct lpfc_scsi_buf *lpfc_cmd; |
dea3101e | 9899 | int rc = 1; |
9900 | ||
0bd4ca25 JSEC |
9901 | if (!(iocbq->iocb_flag & LPFC_IO_FCP)) |
9902 | return rc; | |
9903 | ||
51ef4c26 JS |
9904 | if (iocbq->vport != vport) |
9905 | return rc; | |
9906 | ||
0bd4ca25 | 9907 | lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq); |
0bd4ca25 | 9908 | |
495a714c | 9909 | if (lpfc_cmd->pCmd == NULL) |
dea3101e | 9910 | return rc; |
9911 | ||
9912 | switch (ctx_cmd) { | |
9913 | case LPFC_CTX_LUN: | |
495a714c JS |
9914 | if ((lpfc_cmd->rdata->pnode) && |
9915 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) && | |
9916 | (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id)) | |
dea3101e | 9917 | rc = 0; |
9918 | break; | |
9919 | case LPFC_CTX_TGT: | |
495a714c JS |
9920 | if ((lpfc_cmd->rdata->pnode) && |
9921 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id)) | |
dea3101e | 9922 | rc = 0; |
9923 | break; | |
dea3101e | 9924 | case LPFC_CTX_HOST: |
9925 | rc = 0; | |
9926 | break; | |
9927 | default: | |
9928 | printk(KERN_ERR "%s: Unknown context cmd type, value %d\n", | |
cadbd4a5 | 9929 | __func__, ctx_cmd); |
dea3101e | 9930 | break; |
9931 | } | |
9932 | ||
9933 | return rc; | |
9934 | } | |
9935 | ||
e59058c4 | 9936 | /** |
3621a710 | 9937 | * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending |
e59058c4 JS |
9938 | * @vport: Pointer to virtual port. |
9939 | * @tgt_id: SCSI ID of the target. | |
9940 | * @lun_id: LUN ID of the scsi device. | |
9941 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. | |
9942 | * | |
9943 | * This function returns number of FCP commands pending for the vport. | |
9944 | * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP | |
9945 | * commands pending on the vport associated with SCSI device specified | |
9946 | * by tgt_id and lun_id parameters. | |
9947 | * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP | |
9948 | * commands pending on the vport associated with SCSI target specified | |
9949 | * by tgt_id parameter. | |
9950 | * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP | |
9951 | * commands pending on the vport. | |
9952 | * This function returns the number of iocbs which satisfy the filter. | |
9953 | * This function is called without any lock held. | |
9954 | **/ | |
dea3101e | 9955 | int |
51ef4c26 JS |
9956 | lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id, |
9957 | lpfc_ctx_cmd ctx_cmd) | |
dea3101e | 9958 | { |
51ef4c26 | 9959 | struct lpfc_hba *phba = vport->phba; |
0bd4ca25 JSEC |
9960 | struct lpfc_iocbq *iocbq; |
9961 | int sum, i; | |
dea3101e | 9962 | |
0bd4ca25 JSEC |
9963 | for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) { |
9964 | iocbq = phba->sli.iocbq_lookup[i]; | |
dea3101e | 9965 | |
51ef4c26 JS |
9966 | if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id, |
9967 | ctx_cmd) == 0) | |
0bd4ca25 | 9968 | sum++; |
dea3101e | 9969 | } |
0bd4ca25 | 9970 | |
dea3101e | 9971 | return sum; |
9972 | } | |
9973 | ||
e59058c4 | 9974 | /** |
3621a710 | 9975 | * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs |
e59058c4 JS |
9976 | * @phba: Pointer to HBA context object |
9977 | * @cmdiocb: Pointer to command iocb object. | |
9978 | * @rspiocb: Pointer to response iocb object. | |
9979 | * | |
9980 | * This function is called when an aborted FCP iocb completes. This | |
9981 | * function is called by the ring event handler with no lock held. | |
9982 | * This function frees the iocb. | |
9983 | **/ | |
5eb95af0 | 9984 | void |
2e0fef85 JS |
9985 | lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
9986 | struct lpfc_iocbq *rspiocb) | |
5eb95af0 | 9987 | { |
cb69f7de | 9988 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
8e668af5 | 9989 | "3096 ABORT_XRI_CN completing on rpi x%x " |
cb69f7de JS |
9990 | "original iotag x%x, abort cmd iotag x%x " |
9991 | "status 0x%x, reason 0x%x\n", | |
9992 | cmdiocb->iocb.un.acxri.abortContextTag, | |
9993 | cmdiocb->iocb.un.acxri.abortIoTag, | |
9994 | cmdiocb->iotag, rspiocb->iocb.ulpStatus, | |
9995 | rspiocb->iocb.un.ulpWord[4]); | |
604a3e30 | 9996 | lpfc_sli_release_iocbq(phba, cmdiocb); |
5eb95af0 JSEC |
9997 | return; |
9998 | } | |
9999 | ||
e59058c4 | 10000 | /** |
3621a710 | 10001 | * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN |
e59058c4 JS |
10002 | * @vport: Pointer to virtual port. |
10003 | * @pring: Pointer to driver SLI ring object. | |
10004 | * @tgt_id: SCSI ID of the target. | |
10005 | * @lun_id: LUN ID of the scsi device. | |
10006 | * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. | |
10007 | * | |
10008 | * This function sends an abort command for every SCSI command | |
10009 | * associated with the given virtual port pending on the ring | |
10010 | * filtered by lpfc_sli_validate_fcp_iocb function. | |
10011 | * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the | |
10012 | * FCP iocbs associated with lun specified by tgt_id and lun_id | |
10013 | * parameters | |
10014 | * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the | |
10015 | * FCP iocbs associated with SCSI target specified by tgt_id parameter. | |
10016 | * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all | |
10017 | * FCP iocbs associated with virtual port. | |
10018 | * This function returns number of iocbs it failed to abort. | |
10019 | * This function is called with no locks held. | |
10020 | **/ | |
dea3101e | 10021 | int |
51ef4c26 JS |
10022 | lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring, |
10023 | uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd) | |
dea3101e | 10024 | { |
51ef4c26 | 10025 | struct lpfc_hba *phba = vport->phba; |
0bd4ca25 JSEC |
10026 | struct lpfc_iocbq *iocbq; |
10027 | struct lpfc_iocbq *abtsiocb; | |
dea3101e | 10028 | IOCB_t *cmd = NULL; |
dea3101e | 10029 | int errcnt = 0, ret_val = 0; |
0bd4ca25 | 10030 | int i; |
dea3101e | 10031 | |
0bd4ca25 JSEC |
10032 | for (i = 1; i <= phba->sli.last_iotag; i++) { |
10033 | iocbq = phba->sli.iocbq_lookup[i]; | |
dea3101e | 10034 | |
51ef4c26 | 10035 | if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id, |
2e0fef85 | 10036 | abort_cmd) != 0) |
dea3101e | 10037 | continue; |
10038 | ||
afbd8d88 JS |
10039 | /* |
10040 | * If the iocbq is already being aborted, don't take a second | |
10041 | * action, but do count it. | |
10042 | */ | |
10043 | if (iocbq->iocb_flag & LPFC_DRIVER_ABORTED) | |
10044 | continue; | |
10045 | ||
dea3101e | 10046 | /* issue ABTS for this IOCB based on iotag */ |
0bd4ca25 | 10047 | abtsiocb = lpfc_sli_get_iocbq(phba); |
dea3101e | 10048 | if (abtsiocb == NULL) { |
10049 | errcnt++; | |
10050 | continue; | |
10051 | } | |
dea3101e | 10052 | |
afbd8d88 JS |
10053 | /* indicate the IO is being aborted by the driver. */ |
10054 | iocbq->iocb_flag |= LPFC_DRIVER_ABORTED; | |
10055 | ||
0bd4ca25 | 10056 | cmd = &iocbq->iocb; |
dea3101e | 10057 | abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS; |
10058 | abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext; | |
da0436e9 JS |
10059 | if (phba->sli_rev == LPFC_SLI_REV4) |
10060 | abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag; | |
10061 | else | |
10062 | abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag; | |
dea3101e | 10063 | abtsiocb->iocb.ulpLe = 1; |
10064 | abtsiocb->iocb.ulpClass = cmd->ulpClass; | |
afbd8d88 | 10065 | abtsiocb->vport = vport; |
dea3101e | 10066 | |
5ffc266e JS |
10067 | /* ABTS WQE must go to the same WQ as the WQE to be aborted */ |
10068 | abtsiocb->fcp_wqidx = iocbq->fcp_wqidx; | |
341af102 JS |
10069 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
10070 | abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX; | |
5ffc266e | 10071 | |
2e0fef85 | 10072 | if (lpfc_is_link_up(phba)) |
dea3101e | 10073 | abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN; |
10074 | else | |
10075 | abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN; | |
10076 | ||
5eb95af0 JSEC |
10077 | /* Setup callback routine and issue the command. */ |
10078 | abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; | |
da0436e9 JS |
10079 | ret_val = lpfc_sli_issue_iocb(phba, pring->ringno, |
10080 | abtsiocb, 0); | |
dea3101e | 10081 | if (ret_val == IOCB_ERROR) { |
604a3e30 | 10082 | lpfc_sli_release_iocbq(phba, abtsiocb); |
dea3101e | 10083 | errcnt++; |
10084 | continue; | |
10085 | } | |
10086 | } | |
10087 | ||
10088 | return errcnt; | |
10089 | } | |
10090 | ||
98912dda JS |
10091 | /** |
10092 | * lpfc_sli_abort_taskmgmt - issue abort for all commands on a host/target/LUN | |
10093 | * @vport: Pointer to virtual port. | |
10094 | * @pring: Pointer to driver SLI ring object. | |
10095 | * @tgt_id: SCSI ID of the target. | |
10096 | * @lun_id: LUN ID of the scsi device. | |
10097 | * @taskmgmt_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. | |
10098 | * | |
10099 | * This function sends an abort command for every SCSI command | |
10100 | * associated with the given virtual port pending on the ring | |
10101 | * filtered by lpfc_sli_validate_fcp_iocb function. | |
10102 | * When taskmgmt_cmd == LPFC_CTX_LUN, the function sends abort only to the | |
10103 | * FCP iocbs associated with lun specified by tgt_id and lun_id | |
10104 | * parameters | |
10105 | * When taskmgmt_cmd == LPFC_CTX_TGT, the function sends abort only to the | |
10106 | * FCP iocbs associated with SCSI target specified by tgt_id parameter. | |
10107 | * When taskmgmt_cmd == LPFC_CTX_HOST, the function sends abort to all | |
10108 | * FCP iocbs associated with virtual port. | |
10109 | * This function returns number of iocbs it aborted . | |
10110 | * This function is called with no locks held right after a taskmgmt | |
10111 | * command is sent. | |
10112 | **/ | |
10113 | int | |
10114 | lpfc_sli_abort_taskmgmt(struct lpfc_vport *vport, struct lpfc_sli_ring *pring, | |
10115 | uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd cmd) | |
10116 | { | |
10117 | struct lpfc_hba *phba = vport->phba; | |
10118 | struct lpfc_iocbq *abtsiocbq; | |
10119 | struct lpfc_iocbq *iocbq; | |
10120 | IOCB_t *icmd; | |
10121 | int sum, i, ret_val; | |
10122 | unsigned long iflags; | |
10123 | struct lpfc_sli_ring *pring_s4; | |
10124 | uint32_t ring_number; | |
10125 | ||
10126 | spin_lock_irq(&phba->hbalock); | |
10127 | ||
10128 | /* all I/Os are in process of being flushed */ | |
10129 | if (phba->hba_flag & HBA_FCP_IOQ_FLUSH) { | |
10130 | spin_unlock_irq(&phba->hbalock); | |
10131 | return 0; | |
10132 | } | |
10133 | sum = 0; | |
10134 | ||
10135 | for (i = 1; i <= phba->sli.last_iotag; i++) { | |
10136 | iocbq = phba->sli.iocbq_lookup[i]; | |
10137 | ||
10138 | if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id, | |
10139 | cmd) != 0) | |
10140 | continue; | |
10141 | ||
10142 | /* | |
10143 | * If the iocbq is already being aborted, don't take a second | |
10144 | * action, but do count it. | |
10145 | */ | |
10146 | if (iocbq->iocb_flag & LPFC_DRIVER_ABORTED) | |
10147 | continue; | |
10148 | ||
10149 | /* issue ABTS for this IOCB based on iotag */ | |
10150 | abtsiocbq = __lpfc_sli_get_iocbq(phba); | |
10151 | if (abtsiocbq == NULL) | |
10152 | continue; | |
10153 | ||
10154 | icmd = &iocbq->iocb; | |
10155 | abtsiocbq->iocb.un.acxri.abortType = ABORT_TYPE_ABTS; | |
10156 | abtsiocbq->iocb.un.acxri.abortContextTag = icmd->ulpContext; | |
10157 | if (phba->sli_rev == LPFC_SLI_REV4) | |
10158 | abtsiocbq->iocb.un.acxri.abortIoTag = | |
10159 | iocbq->sli4_xritag; | |
10160 | else | |
10161 | abtsiocbq->iocb.un.acxri.abortIoTag = icmd->ulpIoTag; | |
10162 | abtsiocbq->iocb.ulpLe = 1; | |
10163 | abtsiocbq->iocb.ulpClass = icmd->ulpClass; | |
10164 | abtsiocbq->vport = vport; | |
10165 | ||
10166 | /* ABTS WQE must go to the same WQ as the WQE to be aborted */ | |
10167 | abtsiocbq->fcp_wqidx = iocbq->fcp_wqidx; | |
10168 | if (iocbq->iocb_flag & LPFC_IO_FCP) | |
10169 | abtsiocbq->iocb_flag |= LPFC_USE_FCPWQIDX; | |
10170 | ||
10171 | if (lpfc_is_link_up(phba)) | |
10172 | abtsiocbq->iocb.ulpCommand = CMD_ABORT_XRI_CN; | |
10173 | else | |
10174 | abtsiocbq->iocb.ulpCommand = CMD_CLOSE_XRI_CN; | |
10175 | ||
10176 | /* Setup callback routine and issue the command. */ | |
10177 | abtsiocbq->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; | |
10178 | ||
10179 | /* | |
10180 | * Indicate the IO is being aborted by the driver and set | |
10181 | * the caller's flag into the aborted IO. | |
10182 | */ | |
10183 | iocbq->iocb_flag |= LPFC_DRIVER_ABORTED; | |
10184 | ||
10185 | if (phba->sli_rev == LPFC_SLI_REV4) { | |
10186 | ring_number = MAX_SLI3_CONFIGURED_RINGS + | |
10187 | iocbq->fcp_wqidx; | |
10188 | pring_s4 = &phba->sli.ring[ring_number]; | |
10189 | /* Note: both hbalock and ring_lock must be set here */ | |
10190 | spin_lock_irqsave(&pring_s4->ring_lock, iflags); | |
10191 | ret_val = __lpfc_sli_issue_iocb(phba, pring_s4->ringno, | |
10192 | abtsiocbq, 0); | |
10193 | spin_unlock_irqrestore(&pring_s4->ring_lock, iflags); | |
10194 | } else { | |
10195 | ret_val = __lpfc_sli_issue_iocb(phba, pring->ringno, | |
10196 | abtsiocbq, 0); | |
10197 | } | |
10198 | ||
10199 | ||
10200 | if (ret_val == IOCB_ERROR) | |
10201 | __lpfc_sli_release_iocbq(phba, abtsiocbq); | |
10202 | else | |
10203 | sum++; | |
10204 | } | |
10205 | spin_unlock_irq(&phba->hbalock); | |
10206 | return sum; | |
10207 | } | |
10208 | ||
e59058c4 | 10209 | /** |
3621a710 | 10210 | * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler |
e59058c4 JS |
10211 | * @phba: Pointer to HBA context object. |
10212 | * @cmdiocbq: Pointer to command iocb. | |
10213 | * @rspiocbq: Pointer to response iocb. | |
10214 | * | |
10215 | * This function is the completion handler for iocbs issued using | |
10216 | * lpfc_sli_issue_iocb_wait function. This function is called by the | |
10217 | * ring event handler function without any lock held. This function | |
10218 | * can be called from both worker thread context and interrupt | |
10219 | * context. This function also can be called from other thread which | |
10220 | * cleans up the SLI layer objects. | |
10221 | * This function copy the contents of the response iocb to the | |
10222 | * response iocb memory object provided by the caller of | |
10223 | * lpfc_sli_issue_iocb_wait and then wakes up the thread which | |
10224 | * sleeps for the iocb completion. | |
10225 | **/ | |
68876920 JSEC |
10226 | static void |
10227 | lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba, | |
10228 | struct lpfc_iocbq *cmdiocbq, | |
10229 | struct lpfc_iocbq *rspiocbq) | |
dea3101e | 10230 | { |
68876920 JSEC |
10231 | wait_queue_head_t *pdone_q; |
10232 | unsigned long iflags; | |
0f65ff68 | 10233 | struct lpfc_scsi_buf *lpfc_cmd; |
dea3101e | 10234 | |
2e0fef85 | 10235 | spin_lock_irqsave(&phba->hbalock, iflags); |
5a0916b4 JS |
10236 | if (cmdiocbq->iocb_flag & LPFC_IO_WAKE_TMO) { |
10237 | ||
10238 | /* | |
10239 | * A time out has occurred for the iocb. If a time out | |
10240 | * completion handler has been supplied, call it. Otherwise, | |
10241 | * just free the iocbq. | |
10242 | */ | |
10243 | ||
10244 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
10245 | cmdiocbq->iocb_cmpl = cmdiocbq->wait_iocb_cmpl; | |
10246 | cmdiocbq->wait_iocb_cmpl = NULL; | |
10247 | if (cmdiocbq->iocb_cmpl) | |
10248 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, NULL); | |
10249 | else | |
10250 | lpfc_sli_release_iocbq(phba, cmdiocbq); | |
10251 | return; | |
10252 | } | |
10253 | ||
68876920 JSEC |
10254 | cmdiocbq->iocb_flag |= LPFC_IO_WAKE; |
10255 | if (cmdiocbq->context2 && rspiocbq) | |
10256 | memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb, | |
10257 | &rspiocbq->iocb, sizeof(IOCB_t)); | |
10258 | ||
0f65ff68 JS |
10259 | /* Set the exchange busy flag for task management commands */ |
10260 | if ((cmdiocbq->iocb_flag & LPFC_IO_FCP) && | |
10261 | !(cmdiocbq->iocb_flag & LPFC_IO_LIBDFC)) { | |
10262 | lpfc_cmd = container_of(cmdiocbq, struct lpfc_scsi_buf, | |
10263 | cur_iocbq); | |
10264 | lpfc_cmd->exch_busy = rspiocbq->iocb_flag & LPFC_EXCHANGE_BUSY; | |
10265 | } | |
10266 | ||
68876920 | 10267 | pdone_q = cmdiocbq->context_un.wait_queue; |
68876920 JSEC |
10268 | if (pdone_q) |
10269 | wake_up(pdone_q); | |
858c9f6c | 10270 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
dea3101e | 10271 | return; |
10272 | } | |
10273 | ||
d11e31dd JS |
10274 | /** |
10275 | * lpfc_chk_iocb_flg - Test IOCB flag with lock held. | |
10276 | * @phba: Pointer to HBA context object.. | |
10277 | * @piocbq: Pointer to command iocb. | |
10278 | * @flag: Flag to test. | |
10279 | * | |
10280 | * This routine grabs the hbalock and then test the iocb_flag to | |
10281 | * see if the passed in flag is set. | |
10282 | * Returns: | |
10283 | * 1 if flag is set. | |
10284 | * 0 if flag is not set. | |
10285 | **/ | |
10286 | static int | |
10287 | lpfc_chk_iocb_flg(struct lpfc_hba *phba, | |
10288 | struct lpfc_iocbq *piocbq, uint32_t flag) | |
10289 | { | |
10290 | unsigned long iflags; | |
10291 | int ret; | |
10292 | ||
10293 | spin_lock_irqsave(&phba->hbalock, iflags); | |
10294 | ret = piocbq->iocb_flag & flag; | |
10295 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
10296 | return ret; | |
10297 | ||
10298 | } | |
10299 | ||
e59058c4 | 10300 | /** |
3621a710 | 10301 | * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands |
e59058c4 JS |
10302 | * @phba: Pointer to HBA context object.. |
10303 | * @pring: Pointer to sli ring. | |
10304 | * @piocb: Pointer to command iocb. | |
10305 | * @prspiocbq: Pointer to response iocb. | |
10306 | * @timeout: Timeout in number of seconds. | |
10307 | * | |
10308 | * This function issues the iocb to firmware and waits for the | |
5a0916b4 JS |
10309 | * iocb to complete. The iocb_cmpl field of the shall be used |
10310 | * to handle iocbs which time out. If the field is NULL, the | |
10311 | * function shall free the iocbq structure. If more clean up is | |
10312 | * needed, the caller is expected to provide a completion function | |
10313 | * that will provide the needed clean up. If the iocb command is | |
10314 | * not completed within timeout seconds, the function will either | |
10315 | * free the iocbq structure (if iocb_cmpl == NULL) or execute the | |
10316 | * completion function set in the iocb_cmpl field and then return | |
10317 | * a status of IOCB_TIMEDOUT. The caller should not free the iocb | |
10318 | * resources if this function returns IOCB_TIMEDOUT. | |
e59058c4 JS |
10319 | * The function waits for the iocb completion using an |
10320 | * non-interruptible wait. | |
10321 | * This function will sleep while waiting for iocb completion. | |
10322 | * So, this function should not be called from any context which | |
10323 | * does not allow sleeping. Due to the same reason, this function | |
10324 | * cannot be called with interrupt disabled. | |
10325 | * This function assumes that the iocb completions occur while | |
10326 | * this function sleep. So, this function cannot be called from | |
10327 | * the thread which process iocb completion for this ring. | |
10328 | * This function clears the iocb_flag of the iocb object before | |
10329 | * issuing the iocb and the iocb completion handler sets this | |
10330 | * flag and wakes this thread when the iocb completes. | |
10331 | * The contents of the response iocb will be copied to prspiocbq | |
10332 | * by the completion handler when the command completes. | |
10333 | * This function returns IOCB_SUCCESS when success. | |
10334 | * This function is called with no lock held. | |
10335 | **/ | |
dea3101e | 10336 | int |
2e0fef85 | 10337 | lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba, |
da0436e9 | 10338 | uint32_t ring_number, |
2e0fef85 JS |
10339 | struct lpfc_iocbq *piocb, |
10340 | struct lpfc_iocbq *prspiocbq, | |
68876920 | 10341 | uint32_t timeout) |
dea3101e | 10342 | { |
7259f0d0 | 10343 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
68876920 JSEC |
10344 | long timeleft, timeout_req = 0; |
10345 | int retval = IOCB_SUCCESS; | |
875fbdfe | 10346 | uint32_t creg_val; |
0e9bb8d7 JS |
10347 | struct lpfc_iocbq *iocb; |
10348 | int txq_cnt = 0; | |
10349 | int txcmplq_cnt = 0; | |
2a9bf3d0 | 10350 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
5a0916b4 JS |
10351 | unsigned long iflags; |
10352 | bool iocb_completed = true; | |
10353 | ||
dea3101e | 10354 | /* |
68876920 JSEC |
10355 | * If the caller has provided a response iocbq buffer, then context2 |
10356 | * is NULL or its an error. | |
dea3101e | 10357 | */ |
68876920 JSEC |
10358 | if (prspiocbq) { |
10359 | if (piocb->context2) | |
10360 | return IOCB_ERROR; | |
10361 | piocb->context2 = prspiocbq; | |
dea3101e | 10362 | } |
10363 | ||
5a0916b4 | 10364 | piocb->wait_iocb_cmpl = piocb->iocb_cmpl; |
68876920 JSEC |
10365 | piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait; |
10366 | piocb->context_un.wait_queue = &done_q; | |
5a0916b4 | 10367 | piocb->iocb_flag &= ~(LPFC_IO_WAKE | LPFC_IO_WAKE_TMO); |
dea3101e | 10368 | |
875fbdfe | 10369 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
9940b97b JS |
10370 | if (lpfc_readl(phba->HCregaddr, &creg_val)) |
10371 | return IOCB_ERROR; | |
875fbdfe JSEC |
10372 | creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING); |
10373 | writel(creg_val, phba->HCregaddr); | |
10374 | readl(phba->HCregaddr); /* flush */ | |
10375 | } | |
10376 | ||
2a9bf3d0 JS |
10377 | retval = lpfc_sli_issue_iocb(phba, ring_number, piocb, |
10378 | SLI_IOCB_RET_IOCB); | |
68876920 | 10379 | if (retval == IOCB_SUCCESS) { |
256ec0d0 | 10380 | timeout_req = msecs_to_jiffies(timeout * 1000); |
68876920 | 10381 | timeleft = wait_event_timeout(done_q, |
d11e31dd | 10382 | lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE), |
68876920 | 10383 | timeout_req); |
5a0916b4 JS |
10384 | spin_lock_irqsave(&phba->hbalock, iflags); |
10385 | if (!(piocb->iocb_flag & LPFC_IO_WAKE)) { | |
10386 | ||
10387 | /* | |
10388 | * IOCB timed out. Inform the wake iocb wait | |
10389 | * completion function and set local status | |
10390 | */ | |
dea3101e | 10391 | |
5a0916b4 JS |
10392 | iocb_completed = false; |
10393 | piocb->iocb_flag |= LPFC_IO_WAKE_TMO; | |
10394 | } | |
10395 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
10396 | if (iocb_completed) { | |
7054a606 | 10397 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
e8b62011 | 10398 | "0331 IOCB wake signaled\n"); |
53151bbb JS |
10399 | /* Note: we are not indicating if the IOCB has a success |
10400 | * status or not - that's for the caller to check. | |
10401 | * IOCB_SUCCESS means just that the command was sent and | |
10402 | * completed. Not that it completed successfully. | |
10403 | * */ | |
7054a606 | 10404 | } else if (timeleft == 0) { |
68876920 | 10405 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
e8b62011 JS |
10406 | "0338 IOCB wait timeout error - no " |
10407 | "wake response Data x%x\n", timeout); | |
68876920 | 10408 | retval = IOCB_TIMEDOUT; |
7054a606 | 10409 | } else { |
68876920 | 10410 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
e8b62011 JS |
10411 | "0330 IOCB wake NOT set, " |
10412 | "Data x%x x%lx\n", | |
68876920 JSEC |
10413 | timeout, (timeleft / jiffies)); |
10414 | retval = IOCB_TIMEDOUT; | |
dea3101e | 10415 | } |
2a9bf3d0 | 10416 | } else if (retval == IOCB_BUSY) { |
0e9bb8d7 JS |
10417 | if (phba->cfg_log_verbose & LOG_SLI) { |
10418 | list_for_each_entry(iocb, &pring->txq, list) { | |
10419 | txq_cnt++; | |
10420 | } | |
10421 | list_for_each_entry(iocb, &pring->txcmplq, list) { | |
10422 | txcmplq_cnt++; | |
10423 | } | |
10424 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
10425 | "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n", | |
10426 | phba->iocb_cnt, txq_cnt, txcmplq_cnt); | |
10427 | } | |
2a9bf3d0 | 10428 | return retval; |
68876920 JSEC |
10429 | } else { |
10430 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
d7c255b2 | 10431 | "0332 IOCB wait issue failed, Data x%x\n", |
e8b62011 | 10432 | retval); |
68876920 | 10433 | retval = IOCB_ERROR; |
dea3101e | 10434 | } |
10435 | ||
875fbdfe | 10436 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
9940b97b JS |
10437 | if (lpfc_readl(phba->HCregaddr, &creg_val)) |
10438 | return IOCB_ERROR; | |
875fbdfe JSEC |
10439 | creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING); |
10440 | writel(creg_val, phba->HCregaddr); | |
10441 | readl(phba->HCregaddr); /* flush */ | |
10442 | } | |
10443 | ||
68876920 JSEC |
10444 | if (prspiocbq) |
10445 | piocb->context2 = NULL; | |
10446 | ||
10447 | piocb->context_un.wait_queue = NULL; | |
10448 | piocb->iocb_cmpl = NULL; | |
dea3101e | 10449 | return retval; |
10450 | } | |
68876920 | 10451 | |
e59058c4 | 10452 | /** |
3621a710 | 10453 | * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox |
e59058c4 JS |
10454 | * @phba: Pointer to HBA context object. |
10455 | * @pmboxq: Pointer to driver mailbox object. | |
10456 | * @timeout: Timeout in number of seconds. | |
10457 | * | |
10458 | * This function issues the mailbox to firmware and waits for the | |
10459 | * mailbox command to complete. If the mailbox command is not | |
10460 | * completed within timeout seconds, it returns MBX_TIMEOUT. | |
10461 | * The function waits for the mailbox completion using an | |
10462 | * interruptible wait. If the thread is woken up due to a | |
10463 | * signal, MBX_TIMEOUT error is returned to the caller. Caller | |
10464 | * should not free the mailbox resources, if this function returns | |
10465 | * MBX_TIMEOUT. | |
10466 | * This function will sleep while waiting for mailbox completion. | |
10467 | * So, this function should not be called from any context which | |
10468 | * does not allow sleeping. Due to the same reason, this function | |
10469 | * cannot be called with interrupt disabled. | |
10470 | * This function assumes that the mailbox completion occurs while | |
10471 | * this function sleep. So, this function cannot be called from | |
10472 | * the worker thread which processes mailbox completion. | |
10473 | * This function is called in the context of HBA management | |
10474 | * applications. | |
10475 | * This function returns MBX_SUCCESS when successful. | |
10476 | * This function is called with no lock held. | |
10477 | **/ | |
dea3101e | 10478 | int |
2e0fef85 | 10479 | lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq, |
dea3101e | 10480 | uint32_t timeout) |
10481 | { | |
7259f0d0 | 10482 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
b230b8a2 | 10483 | MAILBOX_t *mb = NULL; |
dea3101e | 10484 | int retval; |
858c9f6c | 10485 | unsigned long flag; |
dea3101e | 10486 | |
b230b8a2 | 10487 | /* The caller might set context1 for extended buffer */ |
98c9ea5c | 10488 | if (pmboxq->context1) |
b230b8a2 | 10489 | mb = (MAILBOX_t *)pmboxq->context1; |
dea3101e | 10490 | |
495a714c | 10491 | pmboxq->mbox_flag &= ~LPFC_MBX_WAKE; |
dea3101e | 10492 | /* setup wake call as IOCB callback */ |
10493 | pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait; | |
10494 | /* setup context field to pass wait_queue pointer to wake function */ | |
10495 | pmboxq->context1 = &done_q; | |
10496 | ||
dea3101e | 10497 | /* now issue the command */ |
10498 | retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT); | |
dea3101e | 10499 | if (retval == MBX_BUSY || retval == MBX_SUCCESS) { |
7054a606 JS |
10500 | wait_event_interruptible_timeout(done_q, |
10501 | pmboxq->mbox_flag & LPFC_MBX_WAKE, | |
256ec0d0 | 10502 | msecs_to_jiffies(timeout * 1000)); |
7054a606 | 10503 | |
858c9f6c | 10504 | spin_lock_irqsave(&phba->hbalock, flag); |
b230b8a2 JS |
10505 | /* restore the possible extended buffer for free resource */ |
10506 | pmboxq->context1 = (uint8_t *)mb; | |
7054a606 JS |
10507 | /* |
10508 | * if LPFC_MBX_WAKE flag is set the mailbox is completed | |
10509 | * else do not free the resources. | |
10510 | */ | |
d7c47992 | 10511 | if (pmboxq->mbox_flag & LPFC_MBX_WAKE) { |
dea3101e | 10512 | retval = MBX_SUCCESS; |
d7c47992 | 10513 | } else { |
7054a606 | 10514 | retval = MBX_TIMEOUT; |
858c9f6c JS |
10515 | pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
10516 | } | |
10517 | spin_unlock_irqrestore(&phba->hbalock, flag); | |
b230b8a2 JS |
10518 | } else { |
10519 | /* restore the possible extended buffer for free resource */ | |
10520 | pmboxq->context1 = (uint8_t *)mb; | |
dea3101e | 10521 | } |
10522 | ||
dea3101e | 10523 | return retval; |
10524 | } | |
10525 | ||
e59058c4 | 10526 | /** |
3772a991 | 10527 | * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system |
e59058c4 JS |
10528 | * @phba: Pointer to HBA context. |
10529 | * | |
3772a991 JS |
10530 | * This function is called to shutdown the driver's mailbox sub-system. |
10531 | * It first marks the mailbox sub-system is in a block state to prevent | |
10532 | * the asynchronous mailbox command from issued off the pending mailbox | |
10533 | * command queue. If the mailbox command sub-system shutdown is due to | |
10534 | * HBA error conditions such as EEH or ERATT, this routine shall invoke | |
10535 | * the mailbox sub-system flush routine to forcefully bring down the | |
10536 | * mailbox sub-system. Otherwise, if it is due to normal condition (such | |
10537 | * as with offline or HBA function reset), this routine will wait for the | |
10538 | * outstanding mailbox command to complete before invoking the mailbox | |
10539 | * sub-system flush routine to gracefully bring down mailbox sub-system. | |
e59058c4 | 10540 | **/ |
3772a991 | 10541 | void |
618a5230 | 10542 | lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba, int mbx_action) |
b4c02652 | 10543 | { |
3772a991 | 10544 | struct lpfc_sli *psli = &phba->sli; |
3772a991 | 10545 | unsigned long timeout; |
b4c02652 | 10546 | |
618a5230 JS |
10547 | if (mbx_action == LPFC_MBX_NO_WAIT) { |
10548 | /* delay 100ms for port state */ | |
10549 | msleep(100); | |
10550 | lpfc_sli_mbox_sys_flush(phba); | |
10551 | return; | |
10552 | } | |
a183a15f | 10553 | timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies; |
d7069f09 | 10554 | |
3772a991 JS |
10555 | spin_lock_irq(&phba->hbalock); |
10556 | psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; | |
b4c02652 | 10557 | |
3772a991 | 10558 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
3772a991 JS |
10559 | /* Determine how long we might wait for the active mailbox |
10560 | * command to be gracefully completed by firmware. | |
10561 | */ | |
a183a15f JS |
10562 | if (phba->sli.mbox_active) |
10563 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, | |
10564 | phba->sli.mbox_active) * | |
10565 | 1000) + jiffies; | |
10566 | spin_unlock_irq(&phba->hbalock); | |
10567 | ||
3772a991 JS |
10568 | while (phba->sli.mbox_active) { |
10569 | /* Check active mailbox complete status every 2ms */ | |
10570 | msleep(2); | |
10571 | if (time_after(jiffies, timeout)) | |
10572 | /* Timeout, let the mailbox flush routine to | |
10573 | * forcefully release active mailbox command | |
10574 | */ | |
10575 | break; | |
10576 | } | |
d7069f09 JS |
10577 | } else |
10578 | spin_unlock_irq(&phba->hbalock); | |
10579 | ||
3772a991 JS |
10580 | lpfc_sli_mbox_sys_flush(phba); |
10581 | } | |
ed957684 | 10582 | |
3772a991 JS |
10583 | /** |
10584 | * lpfc_sli_eratt_read - read sli-3 error attention events | |
10585 | * @phba: Pointer to HBA context. | |
10586 | * | |
10587 | * This function is called to read the SLI3 device error attention registers | |
10588 | * for possible error attention events. The caller must hold the hostlock | |
10589 | * with spin_lock_irq(). | |
10590 | * | |
25985edc | 10591 | * This function returns 1 when there is Error Attention in the Host Attention |
3772a991 JS |
10592 | * Register and returns 0 otherwise. |
10593 | **/ | |
10594 | static int | |
10595 | lpfc_sli_eratt_read(struct lpfc_hba *phba) | |
10596 | { | |
10597 | uint32_t ha_copy; | |
b4c02652 | 10598 | |
3772a991 | 10599 | /* Read chip Host Attention (HA) register */ |
9940b97b JS |
10600 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
10601 | goto unplug_err; | |
10602 | ||
3772a991 JS |
10603 | if (ha_copy & HA_ERATT) { |
10604 | /* Read host status register to retrieve error event */ | |
9940b97b JS |
10605 | if (lpfc_sli_read_hs(phba)) |
10606 | goto unplug_err; | |
b4c02652 | 10607 | |
3772a991 JS |
10608 | /* Check if there is a deferred error condition is active */ |
10609 | if ((HS_FFER1 & phba->work_hs) && | |
10610 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | | |
dcf2a4e0 | 10611 | HS_FFER6 | HS_FFER7 | HS_FFER8) & phba->work_hs)) { |
3772a991 | 10612 | phba->hba_flag |= DEFER_ERATT; |
3772a991 JS |
10613 | /* Clear all interrupt enable conditions */ |
10614 | writel(0, phba->HCregaddr); | |
10615 | readl(phba->HCregaddr); | |
10616 | } | |
10617 | ||
10618 | /* Set the driver HA work bitmap */ | |
3772a991 JS |
10619 | phba->work_ha |= HA_ERATT; |
10620 | /* Indicate polling handles this ERATT */ | |
10621 | phba->hba_flag |= HBA_ERATT_HANDLED; | |
3772a991 JS |
10622 | return 1; |
10623 | } | |
10624 | return 0; | |
9940b97b JS |
10625 | |
10626 | unplug_err: | |
10627 | /* Set the driver HS work bitmap */ | |
10628 | phba->work_hs |= UNPLUG_ERR; | |
10629 | /* Set the driver HA work bitmap */ | |
10630 | phba->work_ha |= HA_ERATT; | |
10631 | /* Indicate polling handles this ERATT */ | |
10632 | phba->hba_flag |= HBA_ERATT_HANDLED; | |
10633 | return 1; | |
b4c02652 JS |
10634 | } |
10635 | ||
da0436e9 JS |
10636 | /** |
10637 | * lpfc_sli4_eratt_read - read sli-4 error attention events | |
10638 | * @phba: Pointer to HBA context. | |
10639 | * | |
10640 | * This function is called to read the SLI4 device error attention registers | |
10641 | * for possible error attention events. The caller must hold the hostlock | |
10642 | * with spin_lock_irq(). | |
10643 | * | |
25985edc | 10644 | * This function returns 1 when there is Error Attention in the Host Attention |
da0436e9 JS |
10645 | * Register and returns 0 otherwise. |
10646 | **/ | |
10647 | static int | |
10648 | lpfc_sli4_eratt_read(struct lpfc_hba *phba) | |
10649 | { | |
10650 | uint32_t uerr_sta_hi, uerr_sta_lo; | |
2fcee4bf JS |
10651 | uint32_t if_type, portsmphr; |
10652 | struct lpfc_register portstat_reg; | |
da0436e9 | 10653 | |
2fcee4bf JS |
10654 | /* |
10655 | * For now, use the SLI4 device internal unrecoverable error | |
da0436e9 JS |
10656 | * registers for error attention. This can be changed later. |
10657 | */ | |
2fcee4bf JS |
10658 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
10659 | switch (if_type) { | |
10660 | case LPFC_SLI_INTF_IF_TYPE_0: | |
9940b97b JS |
10661 | if (lpfc_readl(phba->sli4_hba.u.if_type0.UERRLOregaddr, |
10662 | &uerr_sta_lo) || | |
10663 | lpfc_readl(phba->sli4_hba.u.if_type0.UERRHIregaddr, | |
10664 | &uerr_sta_hi)) { | |
10665 | phba->work_hs |= UNPLUG_ERR; | |
10666 | phba->work_ha |= HA_ERATT; | |
10667 | phba->hba_flag |= HBA_ERATT_HANDLED; | |
10668 | return 1; | |
10669 | } | |
2fcee4bf JS |
10670 | if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) || |
10671 | (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) { | |
10672 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
10673 | "1423 HBA Unrecoverable error: " | |
10674 | "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, " | |
10675 | "ue_mask_lo_reg=0x%x, " | |
10676 | "ue_mask_hi_reg=0x%x\n", | |
10677 | uerr_sta_lo, uerr_sta_hi, | |
10678 | phba->sli4_hba.ue_mask_lo, | |
10679 | phba->sli4_hba.ue_mask_hi); | |
10680 | phba->work_status[0] = uerr_sta_lo; | |
10681 | phba->work_status[1] = uerr_sta_hi; | |
10682 | phba->work_ha |= HA_ERATT; | |
10683 | phba->hba_flag |= HBA_ERATT_HANDLED; | |
10684 | return 1; | |
10685 | } | |
10686 | break; | |
10687 | case LPFC_SLI_INTF_IF_TYPE_2: | |
9940b97b JS |
10688 | if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr, |
10689 | &portstat_reg.word0) || | |
10690 | lpfc_readl(phba->sli4_hba.PSMPHRregaddr, | |
10691 | &portsmphr)){ | |
10692 | phba->work_hs |= UNPLUG_ERR; | |
10693 | phba->work_ha |= HA_ERATT; | |
10694 | phba->hba_flag |= HBA_ERATT_HANDLED; | |
10695 | return 1; | |
10696 | } | |
2fcee4bf JS |
10697 | if (bf_get(lpfc_sliport_status_err, &portstat_reg)) { |
10698 | phba->work_status[0] = | |
10699 | readl(phba->sli4_hba.u.if_type2.ERR1regaddr); | |
10700 | phba->work_status[1] = | |
10701 | readl(phba->sli4_hba.u.if_type2.ERR2regaddr); | |
10702 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
2e90f4b5 | 10703 | "2885 Port Status Event: " |
2fcee4bf JS |
10704 | "port status reg 0x%x, " |
10705 | "port smphr reg 0x%x, " | |
10706 | "error 1=0x%x, error 2=0x%x\n", | |
10707 | portstat_reg.word0, | |
10708 | portsmphr, | |
10709 | phba->work_status[0], | |
10710 | phba->work_status[1]); | |
10711 | phba->work_ha |= HA_ERATT; | |
10712 | phba->hba_flag |= HBA_ERATT_HANDLED; | |
10713 | return 1; | |
10714 | } | |
10715 | break; | |
10716 | case LPFC_SLI_INTF_IF_TYPE_1: | |
10717 | default: | |
a747c9ce | 10718 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
2fcee4bf JS |
10719 | "2886 HBA Error Attention on unsupported " |
10720 | "if type %d.", if_type); | |
a747c9ce | 10721 | return 1; |
da0436e9 | 10722 | } |
2fcee4bf | 10723 | |
da0436e9 JS |
10724 | return 0; |
10725 | } | |
10726 | ||
e59058c4 | 10727 | /** |
3621a710 | 10728 | * lpfc_sli_check_eratt - check error attention events |
9399627f JS |
10729 | * @phba: Pointer to HBA context. |
10730 | * | |
3772a991 | 10731 | * This function is called from timer soft interrupt context to check HBA's |
9399627f JS |
10732 | * error attention register bit for error attention events. |
10733 | * | |
25985edc | 10734 | * This function returns 1 when there is Error Attention in the Host Attention |
9399627f JS |
10735 | * Register and returns 0 otherwise. |
10736 | **/ | |
10737 | int | |
10738 | lpfc_sli_check_eratt(struct lpfc_hba *phba) | |
10739 | { | |
10740 | uint32_t ha_copy; | |
10741 | ||
10742 | /* If somebody is waiting to handle an eratt, don't process it | |
10743 | * here. The brdkill function will do this. | |
10744 | */ | |
10745 | if (phba->link_flag & LS_IGNORE_ERATT) | |
10746 | return 0; | |
10747 | ||
10748 | /* Check if interrupt handler handles this ERATT */ | |
10749 | spin_lock_irq(&phba->hbalock); | |
10750 | if (phba->hba_flag & HBA_ERATT_HANDLED) { | |
10751 | /* Interrupt handler has handled ERATT */ | |
10752 | spin_unlock_irq(&phba->hbalock); | |
10753 | return 0; | |
10754 | } | |
10755 | ||
a257bf90 JS |
10756 | /* |
10757 | * If there is deferred error attention, do not check for error | |
10758 | * attention | |
10759 | */ | |
10760 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { | |
10761 | spin_unlock_irq(&phba->hbalock); | |
10762 | return 0; | |
10763 | } | |
10764 | ||
3772a991 JS |
10765 | /* If PCI channel is offline, don't process it */ |
10766 | if (unlikely(pci_channel_offline(phba->pcidev))) { | |
9399627f | 10767 | spin_unlock_irq(&phba->hbalock); |
3772a991 JS |
10768 | return 0; |
10769 | } | |
10770 | ||
10771 | switch (phba->sli_rev) { | |
10772 | case LPFC_SLI_REV2: | |
10773 | case LPFC_SLI_REV3: | |
10774 | /* Read chip Host Attention (HA) register */ | |
10775 | ha_copy = lpfc_sli_eratt_read(phba); | |
10776 | break; | |
da0436e9 | 10777 | case LPFC_SLI_REV4: |
2fcee4bf | 10778 | /* Read device Uncoverable Error (UERR) registers */ |
da0436e9 JS |
10779 | ha_copy = lpfc_sli4_eratt_read(phba); |
10780 | break; | |
3772a991 JS |
10781 | default: |
10782 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
10783 | "0299 Invalid SLI revision (%d)\n", | |
10784 | phba->sli_rev); | |
10785 | ha_copy = 0; | |
10786 | break; | |
9399627f JS |
10787 | } |
10788 | spin_unlock_irq(&phba->hbalock); | |
3772a991 JS |
10789 | |
10790 | return ha_copy; | |
10791 | } | |
10792 | ||
10793 | /** | |
10794 | * lpfc_intr_state_check - Check device state for interrupt handling | |
10795 | * @phba: Pointer to HBA context. | |
10796 | * | |
10797 | * This inline routine checks whether a device or its PCI slot is in a state | |
10798 | * that the interrupt should be handled. | |
10799 | * | |
10800 | * This function returns 0 if the device or the PCI slot is in a state that | |
10801 | * interrupt should be handled, otherwise -EIO. | |
10802 | */ | |
10803 | static inline int | |
10804 | lpfc_intr_state_check(struct lpfc_hba *phba) | |
10805 | { | |
10806 | /* If the pci channel is offline, ignore all the interrupts */ | |
10807 | if (unlikely(pci_channel_offline(phba->pcidev))) | |
10808 | return -EIO; | |
10809 | ||
10810 | /* Update device level interrupt statistics */ | |
10811 | phba->sli.slistat.sli_intr++; | |
10812 | ||
10813 | /* Ignore all interrupts during initialization. */ | |
10814 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) | |
10815 | return -EIO; | |
10816 | ||
9399627f JS |
10817 | return 0; |
10818 | } | |
10819 | ||
10820 | /** | |
3772a991 | 10821 | * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device |
e59058c4 JS |
10822 | * @irq: Interrupt number. |
10823 | * @dev_id: The device context pointer. | |
10824 | * | |
9399627f | 10825 | * This function is directly called from the PCI layer as an interrupt |
3772a991 JS |
10826 | * service routine when device with SLI-3 interface spec is enabled with |
10827 | * MSI-X multi-message interrupt mode and there are slow-path events in | |
10828 | * the HBA. However, when the device is enabled with either MSI or Pin-IRQ | |
10829 | * interrupt mode, this function is called as part of the device-level | |
10830 | * interrupt handler. When the PCI slot is in error recovery or the HBA | |
10831 | * is undergoing initialization, the interrupt handler will not process | |
10832 | * the interrupt. The link attention and ELS ring attention events are | |
10833 | * handled by the worker thread. The interrupt handler signals the worker | |
10834 | * thread and returns for these events. This function is called without | |
10835 | * any lock held. It gets the hbalock to access and update SLI data | |
9399627f JS |
10836 | * structures. |
10837 | * | |
10838 | * This function returns IRQ_HANDLED when interrupt is handled else it | |
10839 | * returns IRQ_NONE. | |
e59058c4 | 10840 | **/ |
dea3101e | 10841 | irqreturn_t |
3772a991 | 10842 | lpfc_sli_sp_intr_handler(int irq, void *dev_id) |
dea3101e | 10843 | { |
2e0fef85 | 10844 | struct lpfc_hba *phba; |
a747c9ce | 10845 | uint32_t ha_copy, hc_copy; |
dea3101e | 10846 | uint32_t work_ha_copy; |
10847 | unsigned long status; | |
5b75da2f | 10848 | unsigned long iflag; |
dea3101e | 10849 | uint32_t control; |
10850 | ||
92d7f7b0 | 10851 | MAILBOX_t *mbox, *pmbox; |
858c9f6c JS |
10852 | struct lpfc_vport *vport; |
10853 | struct lpfc_nodelist *ndlp; | |
10854 | struct lpfc_dmabuf *mp; | |
92d7f7b0 JS |
10855 | LPFC_MBOXQ_t *pmb; |
10856 | int rc; | |
10857 | ||
dea3101e | 10858 | /* |
10859 | * Get the driver's phba structure from the dev_id and | |
10860 | * assume the HBA is not interrupting. | |
10861 | */ | |
9399627f | 10862 | phba = (struct lpfc_hba *)dev_id; |
dea3101e | 10863 | |
10864 | if (unlikely(!phba)) | |
10865 | return IRQ_NONE; | |
10866 | ||
dea3101e | 10867 | /* |
9399627f JS |
10868 | * Stuff needs to be attented to when this function is invoked as an |
10869 | * individual interrupt handler in MSI-X multi-message interrupt mode | |
dea3101e | 10870 | */ |
9399627f | 10871 | if (phba->intr_type == MSIX) { |
3772a991 JS |
10872 | /* Check device state for handling interrupt */ |
10873 | if (lpfc_intr_state_check(phba)) | |
9399627f JS |
10874 | return IRQ_NONE; |
10875 | /* Need to read HA REG for slow-path events */ | |
5b75da2f | 10876 | spin_lock_irqsave(&phba->hbalock, iflag); |
9940b97b JS |
10877 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
10878 | goto unplug_error; | |
9399627f JS |
10879 | /* If somebody is waiting to handle an eratt don't process it |
10880 | * here. The brdkill function will do this. | |
10881 | */ | |
10882 | if (phba->link_flag & LS_IGNORE_ERATT) | |
10883 | ha_copy &= ~HA_ERATT; | |
10884 | /* Check the need for handling ERATT in interrupt handler */ | |
10885 | if (ha_copy & HA_ERATT) { | |
10886 | if (phba->hba_flag & HBA_ERATT_HANDLED) | |
10887 | /* ERATT polling has handled ERATT */ | |
10888 | ha_copy &= ~HA_ERATT; | |
10889 | else | |
10890 | /* Indicate interrupt handler handles ERATT */ | |
10891 | phba->hba_flag |= HBA_ERATT_HANDLED; | |
10892 | } | |
a257bf90 JS |
10893 | |
10894 | /* | |
10895 | * If there is deferred error attention, do not check for any | |
10896 | * interrupt. | |
10897 | */ | |
10898 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { | |
3772a991 | 10899 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
a257bf90 JS |
10900 | return IRQ_NONE; |
10901 | } | |
10902 | ||
9399627f | 10903 | /* Clear up only attention source related to slow-path */ |
9940b97b JS |
10904 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) |
10905 | goto unplug_error; | |
10906 | ||
a747c9ce JS |
10907 | writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA | |
10908 | HC_LAINT_ENA | HC_ERINT_ENA), | |
10909 | phba->HCregaddr); | |
9399627f JS |
10910 | writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)), |
10911 | phba->HAregaddr); | |
a747c9ce | 10912 | writel(hc_copy, phba->HCregaddr); |
9399627f | 10913 | readl(phba->HAregaddr); /* flush */ |
5b75da2f | 10914 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
9399627f JS |
10915 | } else |
10916 | ha_copy = phba->ha_copy; | |
dea3101e | 10917 | |
dea3101e | 10918 | work_ha_copy = ha_copy & phba->work_ha_mask; |
10919 | ||
9399627f | 10920 | if (work_ha_copy) { |
dea3101e | 10921 | if (work_ha_copy & HA_LATT) { |
10922 | if (phba->sli.sli_flag & LPFC_PROCESS_LA) { | |
10923 | /* | |
10924 | * Turn off Link Attention interrupts | |
10925 | * until CLEAR_LA done | |
10926 | */ | |
5b75da2f | 10927 | spin_lock_irqsave(&phba->hbalock, iflag); |
dea3101e | 10928 | phba->sli.sli_flag &= ~LPFC_PROCESS_LA; |
9940b97b JS |
10929 | if (lpfc_readl(phba->HCregaddr, &control)) |
10930 | goto unplug_error; | |
dea3101e | 10931 | control &= ~HC_LAINT_ENA; |
10932 | writel(control, phba->HCregaddr); | |
10933 | readl(phba->HCregaddr); /* flush */ | |
5b75da2f | 10934 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
dea3101e | 10935 | } |
10936 | else | |
10937 | work_ha_copy &= ~HA_LATT; | |
10938 | } | |
10939 | ||
9399627f | 10940 | if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) { |
858c9f6c JS |
10941 | /* |
10942 | * Turn off Slow Rings interrupts, LPFC_ELS_RING is | |
10943 | * the only slow ring. | |
10944 | */ | |
10945 | status = (work_ha_copy & | |
10946 | (HA_RXMASK << (4*LPFC_ELS_RING))); | |
10947 | status >>= (4*LPFC_ELS_RING); | |
10948 | if (status & HA_RXMASK) { | |
5b75da2f | 10949 | spin_lock_irqsave(&phba->hbalock, iflag); |
9940b97b JS |
10950 | if (lpfc_readl(phba->HCregaddr, &control)) |
10951 | goto unplug_error; | |
a58cbd52 JS |
10952 | |
10953 | lpfc_debugfs_slow_ring_trc(phba, | |
10954 | "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x", | |
10955 | control, status, | |
10956 | (uint32_t)phba->sli.slistat.sli_intr); | |
10957 | ||
858c9f6c | 10958 | if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) { |
a58cbd52 JS |
10959 | lpfc_debugfs_slow_ring_trc(phba, |
10960 | "ISR Disable ring:" | |
10961 | "pwork:x%x hawork:x%x wait:x%x", | |
10962 | phba->work_ha, work_ha_copy, | |
10963 | (uint32_t)((unsigned long) | |
5e9d9b82 | 10964 | &phba->work_waitq)); |
a58cbd52 | 10965 | |
858c9f6c JS |
10966 | control &= |
10967 | ~(HC_R0INT_ENA << LPFC_ELS_RING); | |
dea3101e | 10968 | writel(control, phba->HCregaddr); |
10969 | readl(phba->HCregaddr); /* flush */ | |
dea3101e | 10970 | } |
a58cbd52 JS |
10971 | else { |
10972 | lpfc_debugfs_slow_ring_trc(phba, | |
10973 | "ISR slow ring: pwork:" | |
10974 | "x%x hawork:x%x wait:x%x", | |
10975 | phba->work_ha, work_ha_copy, | |
10976 | (uint32_t)((unsigned long) | |
5e9d9b82 | 10977 | &phba->work_waitq)); |
a58cbd52 | 10978 | } |
5b75da2f | 10979 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
dea3101e | 10980 | } |
10981 | } | |
5b75da2f | 10982 | spin_lock_irqsave(&phba->hbalock, iflag); |
a257bf90 | 10983 | if (work_ha_copy & HA_ERATT) { |
9940b97b JS |
10984 | if (lpfc_sli_read_hs(phba)) |
10985 | goto unplug_error; | |
a257bf90 JS |
10986 | /* |
10987 | * Check if there is a deferred error condition | |
10988 | * is active | |
10989 | */ | |
10990 | if ((HS_FFER1 & phba->work_hs) && | |
10991 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | | |
dcf2a4e0 JS |
10992 | HS_FFER6 | HS_FFER7 | HS_FFER8) & |
10993 | phba->work_hs)) { | |
a257bf90 JS |
10994 | phba->hba_flag |= DEFER_ERATT; |
10995 | /* Clear all interrupt enable conditions */ | |
10996 | writel(0, phba->HCregaddr); | |
10997 | readl(phba->HCregaddr); | |
10998 | } | |
10999 | } | |
11000 | ||
9399627f | 11001 | if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) { |
92d7f7b0 | 11002 | pmb = phba->sli.mbox_active; |
04c68496 | 11003 | pmbox = &pmb->u.mb; |
34b02dcd | 11004 | mbox = phba->mbox; |
858c9f6c | 11005 | vport = pmb->vport; |
92d7f7b0 JS |
11006 | |
11007 | /* First check out the status word */ | |
11008 | lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t)); | |
11009 | if (pmbox->mbxOwner != OWN_HOST) { | |
5b75da2f | 11010 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
92d7f7b0 JS |
11011 | /* |
11012 | * Stray Mailbox Interrupt, mbxCommand <cmd> | |
11013 | * mbxStatus <status> | |
11014 | */ | |
09372820 | 11015 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
92d7f7b0 | 11016 | LOG_SLI, |
e8b62011 | 11017 | "(%d):0304 Stray Mailbox " |
92d7f7b0 JS |
11018 | "Interrupt mbxCommand x%x " |
11019 | "mbxStatus x%x\n", | |
e8b62011 | 11020 | (vport ? vport->vpi : 0), |
92d7f7b0 JS |
11021 | pmbox->mbxCommand, |
11022 | pmbox->mbxStatus); | |
09372820 JS |
11023 | /* clear mailbox attention bit */ |
11024 | work_ha_copy &= ~HA_MBATT; | |
11025 | } else { | |
97eab634 | 11026 | phba->sli.mbox_active = NULL; |
5b75da2f | 11027 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
09372820 JS |
11028 | phba->last_completion_time = jiffies; |
11029 | del_timer(&phba->sli.mbox_tmo); | |
09372820 JS |
11030 | if (pmb->mbox_cmpl) { |
11031 | lpfc_sli_pcimem_bcopy(mbox, pmbox, | |
11032 | MAILBOX_CMD_SIZE); | |
7a470277 JS |
11033 | if (pmb->out_ext_byte_len && |
11034 | pmb->context2) | |
11035 | lpfc_sli_pcimem_bcopy( | |
11036 | phba->mbox_ext, | |
11037 | pmb->context2, | |
11038 | pmb->out_ext_byte_len); | |
09372820 JS |
11039 | } |
11040 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { | |
11041 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; | |
11042 | ||
11043 | lpfc_debugfs_disc_trc(vport, | |
11044 | LPFC_DISC_TRC_MBOX_VPORT, | |
11045 | "MBOX dflt rpi: : " | |
11046 | "status:x%x rpi:x%x", | |
11047 | (uint32_t)pmbox->mbxStatus, | |
11048 | pmbox->un.varWords[0], 0); | |
11049 | ||
11050 | if (!pmbox->mbxStatus) { | |
11051 | mp = (struct lpfc_dmabuf *) | |
11052 | (pmb->context1); | |
11053 | ndlp = (struct lpfc_nodelist *) | |
11054 | pmb->context2; | |
11055 | ||
11056 | /* Reg_LOGIN of dflt RPI was | |
11057 | * successful. new lets get | |
11058 | * rid of the RPI using the | |
11059 | * same mbox buffer. | |
11060 | */ | |
11061 | lpfc_unreg_login(phba, | |
11062 | vport->vpi, | |
11063 | pmbox->un.varWords[0], | |
11064 | pmb); | |
11065 | pmb->mbox_cmpl = | |
11066 | lpfc_mbx_cmpl_dflt_rpi; | |
11067 | pmb->context1 = mp; | |
11068 | pmb->context2 = ndlp; | |
11069 | pmb->vport = vport; | |
58da1ffb JS |
11070 | rc = lpfc_sli_issue_mbox(phba, |
11071 | pmb, | |
11072 | MBX_NOWAIT); | |
11073 | if (rc != MBX_BUSY) | |
11074 | lpfc_printf_log(phba, | |
11075 | KERN_ERR, | |
11076 | LOG_MBOX | LOG_SLI, | |
d7c255b2 | 11077 | "0350 rc should have" |
6a9c52cf | 11078 | "been MBX_BUSY\n"); |
3772a991 JS |
11079 | if (rc != MBX_NOT_FINISHED) |
11080 | goto send_current_mbox; | |
09372820 | 11081 | } |
858c9f6c | 11082 | } |
5b75da2f JS |
11083 | spin_lock_irqsave( |
11084 | &phba->pport->work_port_lock, | |
11085 | iflag); | |
09372820 JS |
11086 | phba->pport->work_port_events &= |
11087 | ~WORKER_MBOX_TMO; | |
5b75da2f JS |
11088 | spin_unlock_irqrestore( |
11089 | &phba->pport->work_port_lock, | |
11090 | iflag); | |
09372820 | 11091 | lpfc_mbox_cmpl_put(phba, pmb); |
858c9f6c | 11092 | } |
97eab634 | 11093 | } else |
5b75da2f | 11094 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
9399627f | 11095 | |
92d7f7b0 JS |
11096 | if ((work_ha_copy & HA_MBATT) && |
11097 | (phba->sli.mbox_active == NULL)) { | |
858c9f6c | 11098 | send_current_mbox: |
92d7f7b0 | 11099 | /* Process next mailbox command if there is one */ |
58da1ffb JS |
11100 | do { |
11101 | rc = lpfc_sli_issue_mbox(phba, NULL, | |
11102 | MBX_NOWAIT); | |
11103 | } while (rc == MBX_NOT_FINISHED); | |
11104 | if (rc != MBX_SUCCESS) | |
11105 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | | |
11106 | LOG_SLI, "0349 rc should be " | |
6a9c52cf | 11107 | "MBX_SUCCESS\n"); |
92d7f7b0 JS |
11108 | } |
11109 | ||
5b75da2f | 11110 | spin_lock_irqsave(&phba->hbalock, iflag); |
dea3101e | 11111 | phba->work_ha |= work_ha_copy; |
5b75da2f | 11112 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
5e9d9b82 | 11113 | lpfc_worker_wake_up(phba); |
dea3101e | 11114 | } |
9399627f | 11115 | return IRQ_HANDLED; |
9940b97b JS |
11116 | unplug_error: |
11117 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
11118 | return IRQ_HANDLED; | |
dea3101e | 11119 | |
3772a991 | 11120 | } /* lpfc_sli_sp_intr_handler */ |
9399627f JS |
11121 | |
11122 | /** | |
3772a991 | 11123 | * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device. |
9399627f JS |
11124 | * @irq: Interrupt number. |
11125 | * @dev_id: The device context pointer. | |
11126 | * | |
11127 | * This function is directly called from the PCI layer as an interrupt | |
3772a991 JS |
11128 | * service routine when device with SLI-3 interface spec is enabled with |
11129 | * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB | |
11130 | * ring event in the HBA. However, when the device is enabled with either | |
11131 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the | |
11132 | * device-level interrupt handler. When the PCI slot is in error recovery | |
11133 | * or the HBA is undergoing initialization, the interrupt handler will not | |
11134 | * process the interrupt. The SCSI FCP fast-path ring event are handled in | |
11135 | * the intrrupt context. This function is called without any lock held. | |
11136 | * It gets the hbalock to access and update SLI data structures. | |
9399627f JS |
11137 | * |
11138 | * This function returns IRQ_HANDLED when interrupt is handled else it | |
11139 | * returns IRQ_NONE. | |
11140 | **/ | |
11141 | irqreturn_t | |
3772a991 | 11142 | lpfc_sli_fp_intr_handler(int irq, void *dev_id) |
9399627f JS |
11143 | { |
11144 | struct lpfc_hba *phba; | |
11145 | uint32_t ha_copy; | |
11146 | unsigned long status; | |
5b75da2f | 11147 | unsigned long iflag; |
9399627f JS |
11148 | |
11149 | /* Get the driver's phba structure from the dev_id and | |
11150 | * assume the HBA is not interrupting. | |
11151 | */ | |
11152 | phba = (struct lpfc_hba *) dev_id; | |
11153 | ||
11154 | if (unlikely(!phba)) | |
11155 | return IRQ_NONE; | |
11156 | ||
11157 | /* | |
11158 | * Stuff needs to be attented to when this function is invoked as an | |
11159 | * individual interrupt handler in MSI-X multi-message interrupt mode | |
11160 | */ | |
11161 | if (phba->intr_type == MSIX) { | |
3772a991 JS |
11162 | /* Check device state for handling interrupt */ |
11163 | if (lpfc_intr_state_check(phba)) | |
9399627f JS |
11164 | return IRQ_NONE; |
11165 | /* Need to read HA REG for FCP ring and other ring events */ | |
9940b97b JS |
11166 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
11167 | return IRQ_HANDLED; | |
9399627f | 11168 | /* Clear up only attention source related to fast-path */ |
5b75da2f | 11169 | spin_lock_irqsave(&phba->hbalock, iflag); |
a257bf90 JS |
11170 | /* |
11171 | * If there is deferred error attention, do not check for | |
11172 | * any interrupt. | |
11173 | */ | |
11174 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { | |
3772a991 | 11175 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
a257bf90 JS |
11176 | return IRQ_NONE; |
11177 | } | |
9399627f JS |
11178 | writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)), |
11179 | phba->HAregaddr); | |
11180 | readl(phba->HAregaddr); /* flush */ | |
5b75da2f | 11181 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
9399627f JS |
11182 | } else |
11183 | ha_copy = phba->ha_copy; | |
dea3101e | 11184 | |
11185 | /* | |
9399627f | 11186 | * Process all events on FCP ring. Take the optimized path for FCP IO. |
dea3101e | 11187 | */ |
9399627f JS |
11188 | ha_copy &= ~(phba->work_ha_mask); |
11189 | ||
11190 | status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); | |
dea3101e | 11191 | status >>= (4*LPFC_FCP_RING); |
858c9f6c | 11192 | if (status & HA_RXMASK) |
dea3101e | 11193 | lpfc_sli_handle_fast_ring_event(phba, |
11194 | &phba->sli.ring[LPFC_FCP_RING], | |
11195 | status); | |
a4bc3379 JS |
11196 | |
11197 | if (phba->cfg_multi_ring_support == 2) { | |
11198 | /* | |
9399627f JS |
11199 | * Process all events on extra ring. Take the optimized path |
11200 | * for extra ring IO. | |
a4bc3379 | 11201 | */ |
9399627f | 11202 | status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); |
a4bc3379 | 11203 | status >>= (4*LPFC_EXTRA_RING); |
858c9f6c | 11204 | if (status & HA_RXMASK) { |
a4bc3379 JS |
11205 | lpfc_sli_handle_fast_ring_event(phba, |
11206 | &phba->sli.ring[LPFC_EXTRA_RING], | |
11207 | status); | |
11208 | } | |
11209 | } | |
dea3101e | 11210 | return IRQ_HANDLED; |
3772a991 | 11211 | } /* lpfc_sli_fp_intr_handler */ |
9399627f JS |
11212 | |
11213 | /** | |
3772a991 | 11214 | * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device |
9399627f JS |
11215 | * @irq: Interrupt number. |
11216 | * @dev_id: The device context pointer. | |
11217 | * | |
3772a991 JS |
11218 | * This function is the HBA device-level interrupt handler to device with |
11219 | * SLI-3 interface spec, called from the PCI layer when either MSI or | |
11220 | * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which | |
11221 | * requires driver attention. This function invokes the slow-path interrupt | |
11222 | * attention handling function and fast-path interrupt attention handling | |
11223 | * function in turn to process the relevant HBA attention events. This | |
11224 | * function is called without any lock held. It gets the hbalock to access | |
11225 | * and update SLI data structures. | |
9399627f JS |
11226 | * |
11227 | * This function returns IRQ_HANDLED when interrupt is handled, else it | |
11228 | * returns IRQ_NONE. | |
11229 | **/ | |
11230 | irqreturn_t | |
3772a991 | 11231 | lpfc_sli_intr_handler(int irq, void *dev_id) |
9399627f JS |
11232 | { |
11233 | struct lpfc_hba *phba; | |
11234 | irqreturn_t sp_irq_rc, fp_irq_rc; | |
11235 | unsigned long status1, status2; | |
a747c9ce | 11236 | uint32_t hc_copy; |
9399627f JS |
11237 | |
11238 | /* | |
11239 | * Get the driver's phba structure from the dev_id and | |
11240 | * assume the HBA is not interrupting. | |
11241 | */ | |
11242 | phba = (struct lpfc_hba *) dev_id; | |
11243 | ||
11244 | if (unlikely(!phba)) | |
11245 | return IRQ_NONE; | |
11246 | ||
3772a991 JS |
11247 | /* Check device state for handling interrupt */ |
11248 | if (lpfc_intr_state_check(phba)) | |
9399627f JS |
11249 | return IRQ_NONE; |
11250 | ||
11251 | spin_lock(&phba->hbalock); | |
9940b97b JS |
11252 | if (lpfc_readl(phba->HAregaddr, &phba->ha_copy)) { |
11253 | spin_unlock(&phba->hbalock); | |
11254 | return IRQ_HANDLED; | |
11255 | } | |
11256 | ||
9399627f JS |
11257 | if (unlikely(!phba->ha_copy)) { |
11258 | spin_unlock(&phba->hbalock); | |
11259 | return IRQ_NONE; | |
11260 | } else if (phba->ha_copy & HA_ERATT) { | |
11261 | if (phba->hba_flag & HBA_ERATT_HANDLED) | |
11262 | /* ERATT polling has handled ERATT */ | |
11263 | phba->ha_copy &= ~HA_ERATT; | |
11264 | else | |
11265 | /* Indicate interrupt handler handles ERATT */ | |
11266 | phba->hba_flag |= HBA_ERATT_HANDLED; | |
11267 | } | |
11268 | ||
a257bf90 JS |
11269 | /* |
11270 | * If there is deferred error attention, do not check for any interrupt. | |
11271 | */ | |
11272 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { | |
ec21b3b0 | 11273 | spin_unlock(&phba->hbalock); |
a257bf90 JS |
11274 | return IRQ_NONE; |
11275 | } | |
11276 | ||
9399627f | 11277 | /* Clear attention sources except link and error attentions */ |
9940b97b JS |
11278 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) { |
11279 | spin_unlock(&phba->hbalock); | |
11280 | return IRQ_HANDLED; | |
11281 | } | |
a747c9ce JS |
11282 | writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA |
11283 | | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA), | |
11284 | phba->HCregaddr); | |
9399627f | 11285 | writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr); |
a747c9ce | 11286 | writel(hc_copy, phba->HCregaddr); |
9399627f JS |
11287 | readl(phba->HAregaddr); /* flush */ |
11288 | spin_unlock(&phba->hbalock); | |
11289 | ||
11290 | /* | |
11291 | * Invokes slow-path host attention interrupt handling as appropriate. | |
11292 | */ | |
11293 | ||
11294 | /* status of events with mailbox and link attention */ | |
11295 | status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT); | |
11296 | ||
11297 | /* status of events with ELS ring */ | |
11298 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING))); | |
11299 | status2 >>= (4*LPFC_ELS_RING); | |
11300 | ||
11301 | if (status1 || (status2 & HA_RXMASK)) | |
3772a991 | 11302 | sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id); |
9399627f JS |
11303 | else |
11304 | sp_irq_rc = IRQ_NONE; | |
11305 | ||
11306 | /* | |
11307 | * Invoke fast-path host attention interrupt handling as appropriate. | |
11308 | */ | |
11309 | ||
11310 | /* status of events with FCP ring */ | |
11311 | status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); | |
11312 | status1 >>= (4*LPFC_FCP_RING); | |
11313 | ||
11314 | /* status of events with extra ring */ | |
11315 | if (phba->cfg_multi_ring_support == 2) { | |
11316 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); | |
11317 | status2 >>= (4*LPFC_EXTRA_RING); | |
11318 | } else | |
11319 | status2 = 0; | |
11320 | ||
11321 | if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK)) | |
3772a991 | 11322 | fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id); |
9399627f JS |
11323 | else |
11324 | fp_irq_rc = IRQ_NONE; | |
dea3101e | 11325 | |
9399627f JS |
11326 | /* Return device-level interrupt handling status */ |
11327 | return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc; | |
3772a991 | 11328 | } /* lpfc_sli_intr_handler */ |
4f774513 JS |
11329 | |
11330 | /** | |
11331 | * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event | |
11332 | * @phba: pointer to lpfc hba data structure. | |
11333 | * | |
11334 | * This routine is invoked by the worker thread to process all the pending | |
11335 | * SLI4 FCP abort XRI events. | |
11336 | **/ | |
11337 | void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *phba) | |
11338 | { | |
11339 | struct lpfc_cq_event *cq_event; | |
11340 | ||
11341 | /* First, declare the fcp xri abort event has been handled */ | |
11342 | spin_lock_irq(&phba->hbalock); | |
11343 | phba->hba_flag &= ~FCP_XRI_ABORT_EVENT; | |
11344 | spin_unlock_irq(&phba->hbalock); | |
11345 | /* Now, handle all the fcp xri abort events */ | |
11346 | while (!list_empty(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue)) { | |
11347 | /* Get the first event from the head of the event queue */ | |
11348 | spin_lock_irq(&phba->hbalock); | |
11349 | list_remove_head(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue, | |
11350 | cq_event, struct lpfc_cq_event, list); | |
11351 | spin_unlock_irq(&phba->hbalock); | |
11352 | /* Notify aborted XRI for FCP work queue */ | |
11353 | lpfc_sli4_fcp_xri_aborted(phba, &cq_event->cqe.wcqe_axri); | |
11354 | /* Free the event processed back to the free pool */ | |
11355 | lpfc_sli4_cq_event_release(phba, cq_event); | |
11356 | } | |
11357 | } | |
11358 | ||
11359 | /** | |
11360 | * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event | |
11361 | * @phba: pointer to lpfc hba data structure. | |
11362 | * | |
11363 | * This routine is invoked by the worker thread to process all the pending | |
11364 | * SLI4 els abort xri events. | |
11365 | **/ | |
11366 | void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba) | |
11367 | { | |
11368 | struct lpfc_cq_event *cq_event; | |
11369 | ||
11370 | /* First, declare the els xri abort event has been handled */ | |
11371 | spin_lock_irq(&phba->hbalock); | |
11372 | phba->hba_flag &= ~ELS_XRI_ABORT_EVENT; | |
11373 | spin_unlock_irq(&phba->hbalock); | |
11374 | /* Now, handle all the els xri abort events */ | |
11375 | while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) { | |
11376 | /* Get the first event from the head of the event queue */ | |
11377 | spin_lock_irq(&phba->hbalock); | |
11378 | list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue, | |
11379 | cq_event, struct lpfc_cq_event, list); | |
11380 | spin_unlock_irq(&phba->hbalock); | |
11381 | /* Notify aborted XRI for ELS work queue */ | |
11382 | lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri); | |
11383 | /* Free the event processed back to the free pool */ | |
11384 | lpfc_sli4_cq_event_release(phba, cq_event); | |
11385 | } | |
11386 | } | |
11387 | ||
341af102 JS |
11388 | /** |
11389 | * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn | |
11390 | * @phba: pointer to lpfc hba data structure | |
11391 | * @pIocbIn: pointer to the rspiocbq | |
11392 | * @pIocbOut: pointer to the cmdiocbq | |
11393 | * @wcqe: pointer to the complete wcqe | |
11394 | * | |
11395 | * This routine transfers the fields of a command iocbq to a response iocbq | |
11396 | * by copying all the IOCB fields from command iocbq and transferring the | |
11397 | * completion status information from the complete wcqe. | |
11398 | **/ | |
4f774513 | 11399 | static void |
341af102 JS |
11400 | lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba, |
11401 | struct lpfc_iocbq *pIocbIn, | |
4f774513 JS |
11402 | struct lpfc_iocbq *pIocbOut, |
11403 | struct lpfc_wcqe_complete *wcqe) | |
11404 | { | |
af22741c | 11405 | int numBdes, i; |
341af102 | 11406 | unsigned long iflags; |
af22741c JS |
11407 | uint32_t status, max_response; |
11408 | struct lpfc_dmabuf *dmabuf; | |
11409 | struct ulp_bde64 *bpl, bde; | |
4f774513 JS |
11410 | size_t offset = offsetof(struct lpfc_iocbq, iocb); |
11411 | ||
11412 | memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset, | |
11413 | sizeof(struct lpfc_iocbq) - offset); | |
4f774513 | 11414 | /* Map WCQE parameters into irspiocb parameters */ |
acd6859b JS |
11415 | status = bf_get(lpfc_wcqe_c_status, wcqe); |
11416 | pIocbIn->iocb.ulpStatus = (status & LPFC_IOCB_STATUS_MASK); | |
4f774513 JS |
11417 | if (pIocbOut->iocb_flag & LPFC_IO_FCP) |
11418 | if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR) | |
11419 | pIocbIn->iocb.un.fcpi.fcpi_parm = | |
11420 | pIocbOut->iocb.un.fcpi.fcpi_parm - | |
11421 | wcqe->total_data_placed; | |
11422 | else | |
11423 | pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter; | |
695a814e | 11424 | else { |
4f774513 | 11425 | pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter; |
af22741c JS |
11426 | switch (pIocbOut->iocb.ulpCommand) { |
11427 | case CMD_ELS_REQUEST64_CR: | |
11428 | dmabuf = (struct lpfc_dmabuf *)pIocbOut->context3; | |
11429 | bpl = (struct ulp_bde64 *)dmabuf->virt; | |
11430 | bde.tus.w = le32_to_cpu(bpl[1].tus.w); | |
11431 | max_response = bde.tus.f.bdeSize; | |
11432 | break; | |
11433 | case CMD_GEN_REQUEST64_CR: | |
11434 | max_response = 0; | |
11435 | if (!pIocbOut->context3) | |
11436 | break; | |
11437 | numBdes = pIocbOut->iocb.un.genreq64.bdl.bdeSize/ | |
11438 | sizeof(struct ulp_bde64); | |
11439 | dmabuf = (struct lpfc_dmabuf *)pIocbOut->context3; | |
11440 | bpl = (struct ulp_bde64 *)dmabuf->virt; | |
11441 | for (i = 0; i < numBdes; i++) { | |
11442 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); | |
11443 | if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64) | |
11444 | max_response += bde.tus.f.bdeSize; | |
11445 | } | |
11446 | break; | |
11447 | default: | |
11448 | max_response = wcqe->total_data_placed; | |
11449 | break; | |
11450 | } | |
11451 | if (max_response < wcqe->total_data_placed) | |
11452 | pIocbIn->iocb.un.genreq64.bdl.bdeSize = max_response; | |
11453 | else | |
11454 | pIocbIn->iocb.un.genreq64.bdl.bdeSize = | |
11455 | wcqe->total_data_placed; | |
695a814e | 11456 | } |
341af102 | 11457 | |
acd6859b JS |
11458 | /* Convert BG errors for completion status */ |
11459 | if (status == CQE_STATUS_DI_ERROR) { | |
11460 | pIocbIn->iocb.ulpStatus = IOSTAT_LOCAL_REJECT; | |
11461 | ||
11462 | if (bf_get(lpfc_wcqe_c_bg_edir, wcqe)) | |
11463 | pIocbIn->iocb.un.ulpWord[4] = IOERR_RX_DMA_FAILED; | |
11464 | else | |
11465 | pIocbIn->iocb.un.ulpWord[4] = IOERR_TX_DMA_FAILED; | |
11466 | ||
11467 | pIocbIn->iocb.unsli3.sli3_bg.bgstat = 0; | |
11468 | if (bf_get(lpfc_wcqe_c_bg_ge, wcqe)) /* Guard Check failed */ | |
11469 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= | |
11470 | BGS_GUARD_ERR_MASK; | |
11471 | if (bf_get(lpfc_wcqe_c_bg_ae, wcqe)) /* App Tag Check failed */ | |
11472 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= | |
11473 | BGS_APPTAG_ERR_MASK; | |
11474 | if (bf_get(lpfc_wcqe_c_bg_re, wcqe)) /* Ref Tag Check failed */ | |
11475 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= | |
11476 | BGS_REFTAG_ERR_MASK; | |
11477 | ||
11478 | /* Check to see if there was any good data before the error */ | |
11479 | if (bf_get(lpfc_wcqe_c_bg_tdpv, wcqe)) { | |
11480 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= | |
11481 | BGS_HI_WATER_MARK_PRESENT_MASK; | |
11482 | pIocbIn->iocb.unsli3.sli3_bg.bghm = | |
11483 | wcqe->total_data_placed; | |
11484 | } | |
11485 | ||
11486 | /* | |
11487 | * Set ALL the error bits to indicate we don't know what | |
11488 | * type of error it is. | |
11489 | */ | |
11490 | if (!pIocbIn->iocb.unsli3.sli3_bg.bgstat) | |
11491 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= | |
11492 | (BGS_REFTAG_ERR_MASK | BGS_APPTAG_ERR_MASK | | |
11493 | BGS_GUARD_ERR_MASK); | |
11494 | } | |
11495 | ||
341af102 JS |
11496 | /* Pick up HBA exchange busy condition */ |
11497 | if (bf_get(lpfc_wcqe_c_xb, wcqe)) { | |
11498 | spin_lock_irqsave(&phba->hbalock, iflags); | |
11499 | pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY; | |
11500 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
11501 | } | |
4f774513 JS |
11502 | } |
11503 | ||
45ed1190 JS |
11504 | /** |
11505 | * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe | |
11506 | * @phba: Pointer to HBA context object. | |
11507 | * @wcqe: Pointer to work-queue completion queue entry. | |
11508 | * | |
11509 | * This routine handles an ELS work-queue completion event and construct | |
11510 | * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common | |
11511 | * discovery engine to handle. | |
11512 | * | |
11513 | * Return: Pointer to the receive IOCBQ, NULL otherwise. | |
11514 | **/ | |
11515 | static struct lpfc_iocbq * | |
11516 | lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba, | |
11517 | struct lpfc_iocbq *irspiocbq) | |
11518 | { | |
11519 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; | |
11520 | struct lpfc_iocbq *cmdiocbq; | |
11521 | struct lpfc_wcqe_complete *wcqe; | |
11522 | unsigned long iflags; | |
11523 | ||
11524 | wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl; | |
7e56aa25 | 11525 | spin_lock_irqsave(&pring->ring_lock, iflags); |
45ed1190 JS |
11526 | pring->stats.iocb_event++; |
11527 | /* Look up the ELS command IOCB and create pseudo response IOCB */ | |
11528 | cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring, | |
11529 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); | |
7e56aa25 | 11530 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
45ed1190 JS |
11531 | |
11532 | if (unlikely(!cmdiocbq)) { | |
11533 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
11534 | "0386 ELS complete with no corresponding " | |
11535 | "cmdiocb: iotag (%d)\n", | |
11536 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); | |
11537 | lpfc_sli_release_iocbq(phba, irspiocbq); | |
11538 | return NULL; | |
11539 | } | |
11540 | ||
11541 | /* Fake the irspiocbq and copy necessary response information */ | |
341af102 | 11542 | lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe); |
45ed1190 JS |
11543 | |
11544 | return irspiocbq; | |
11545 | } | |
11546 | ||
04c68496 JS |
11547 | /** |
11548 | * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event | |
11549 | * @phba: Pointer to HBA context object. | |
11550 | * @cqe: Pointer to mailbox completion queue entry. | |
11551 | * | |
11552 | * This routine process a mailbox completion queue entry with asynchrous | |
11553 | * event. | |
11554 | * | |
11555 | * Return: true if work posted to worker thread, otherwise false. | |
11556 | **/ | |
11557 | static bool | |
11558 | lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe) | |
11559 | { | |
11560 | struct lpfc_cq_event *cq_event; | |
11561 | unsigned long iflags; | |
11562 | ||
11563 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
11564 | "0392 Async Event: word0:x%x, word1:x%x, " | |
11565 | "word2:x%x, word3:x%x\n", mcqe->word0, | |
11566 | mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer); | |
11567 | ||
11568 | /* Allocate a new internal CQ_EVENT entry */ | |
11569 | cq_event = lpfc_sli4_cq_event_alloc(phba); | |
11570 | if (!cq_event) { | |
11571 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
11572 | "0394 Failed to allocate CQ_EVENT entry\n"); | |
11573 | return false; | |
11574 | } | |
11575 | ||
11576 | /* Move the CQE into an asynchronous event entry */ | |
11577 | memcpy(&cq_event->cqe, mcqe, sizeof(struct lpfc_mcqe)); | |
11578 | spin_lock_irqsave(&phba->hbalock, iflags); | |
11579 | list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue); | |
11580 | /* Set the async event flag */ | |
11581 | phba->hba_flag |= ASYNC_EVENT; | |
11582 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
11583 | ||
11584 | return true; | |
11585 | } | |
11586 | ||
11587 | /** | |
11588 | * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event | |
11589 | * @phba: Pointer to HBA context object. | |
11590 | * @cqe: Pointer to mailbox completion queue entry. | |
11591 | * | |
11592 | * This routine process a mailbox completion queue entry with mailbox | |
11593 | * completion event. | |
11594 | * | |
11595 | * Return: true if work posted to worker thread, otherwise false. | |
11596 | **/ | |
11597 | static bool | |
11598 | lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe) | |
11599 | { | |
11600 | uint32_t mcqe_status; | |
11601 | MAILBOX_t *mbox, *pmbox; | |
11602 | struct lpfc_mqe *mqe; | |
11603 | struct lpfc_vport *vport; | |
11604 | struct lpfc_nodelist *ndlp; | |
11605 | struct lpfc_dmabuf *mp; | |
11606 | unsigned long iflags; | |
11607 | LPFC_MBOXQ_t *pmb; | |
11608 | bool workposted = false; | |
11609 | int rc; | |
11610 | ||
11611 | /* If not a mailbox complete MCQE, out by checking mailbox consume */ | |
11612 | if (!bf_get(lpfc_trailer_completed, mcqe)) | |
11613 | goto out_no_mqe_complete; | |
11614 | ||
11615 | /* Get the reference to the active mbox command */ | |
11616 | spin_lock_irqsave(&phba->hbalock, iflags); | |
11617 | pmb = phba->sli.mbox_active; | |
11618 | if (unlikely(!pmb)) { | |
11619 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, | |
11620 | "1832 No pending MBOX command to handle\n"); | |
11621 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
11622 | goto out_no_mqe_complete; | |
11623 | } | |
11624 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
11625 | mqe = &pmb->u.mqe; | |
11626 | pmbox = (MAILBOX_t *)&pmb->u.mqe; | |
11627 | mbox = phba->mbox; | |
11628 | vport = pmb->vport; | |
11629 | ||
11630 | /* Reset heartbeat timer */ | |
11631 | phba->last_completion_time = jiffies; | |
11632 | del_timer(&phba->sli.mbox_tmo); | |
11633 | ||
11634 | /* Move mbox data to caller's mailbox region, do endian swapping */ | |
11635 | if (pmb->mbox_cmpl && mbox) | |
11636 | lpfc_sli_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe)); | |
04c68496 | 11637 | |
73d91e50 JS |
11638 | /* |
11639 | * For mcqe errors, conditionally move a modified error code to | |
11640 | * the mbox so that the error will not be missed. | |
11641 | */ | |
11642 | mcqe_status = bf_get(lpfc_mcqe_status, mcqe); | |
11643 | if (mcqe_status != MB_CQE_STATUS_SUCCESS) { | |
11644 | if (bf_get(lpfc_mqe_status, mqe) == MBX_SUCCESS) | |
11645 | bf_set(lpfc_mqe_status, mqe, | |
11646 | (LPFC_MBX_ERROR_RANGE | mcqe_status)); | |
11647 | } | |
04c68496 JS |
11648 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { |
11649 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; | |
11650 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT, | |
11651 | "MBOX dflt rpi: status:x%x rpi:x%x", | |
11652 | mcqe_status, | |
11653 | pmbox->un.varWords[0], 0); | |
11654 | if (mcqe_status == MB_CQE_STATUS_SUCCESS) { | |
11655 | mp = (struct lpfc_dmabuf *)(pmb->context1); | |
11656 | ndlp = (struct lpfc_nodelist *)pmb->context2; | |
11657 | /* Reg_LOGIN of dflt RPI was successful. Now lets get | |
11658 | * RID of the PPI using the same mbox buffer. | |
11659 | */ | |
11660 | lpfc_unreg_login(phba, vport->vpi, | |
11661 | pmbox->un.varWords[0], pmb); | |
11662 | pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; | |
11663 | pmb->context1 = mp; | |
11664 | pmb->context2 = ndlp; | |
11665 | pmb->vport = vport; | |
11666 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); | |
11667 | if (rc != MBX_BUSY) | |
11668 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | | |
11669 | LOG_SLI, "0385 rc should " | |
11670 | "have been MBX_BUSY\n"); | |
11671 | if (rc != MBX_NOT_FINISHED) | |
11672 | goto send_current_mbox; | |
11673 | } | |
11674 | } | |
11675 | spin_lock_irqsave(&phba->pport->work_port_lock, iflags); | |
11676 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; | |
11677 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); | |
11678 | ||
11679 | /* There is mailbox completion work to do */ | |
11680 | spin_lock_irqsave(&phba->hbalock, iflags); | |
11681 | __lpfc_mbox_cmpl_put(phba, pmb); | |
11682 | phba->work_ha |= HA_MBATT; | |
11683 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
11684 | workposted = true; | |
11685 | ||
11686 | send_current_mbox: | |
11687 | spin_lock_irqsave(&phba->hbalock, iflags); | |
11688 | /* Release the mailbox command posting token */ | |
11689 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
11690 | /* Setting active mailbox pointer need to be in sync to flag clear */ | |
11691 | phba->sli.mbox_active = NULL; | |
11692 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
11693 | /* Wake up worker thread to post the next pending mailbox command */ | |
11694 | lpfc_worker_wake_up(phba); | |
11695 | out_no_mqe_complete: | |
11696 | if (bf_get(lpfc_trailer_consumed, mcqe)) | |
11697 | lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq); | |
11698 | return workposted; | |
11699 | } | |
11700 | ||
11701 | /** | |
11702 | * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry | |
11703 | * @phba: Pointer to HBA context object. | |
11704 | * @cqe: Pointer to mailbox completion queue entry. | |
11705 | * | |
11706 | * This routine process a mailbox completion queue entry, it invokes the | |
11707 | * proper mailbox complete handling or asynchrous event handling routine | |
11708 | * according to the MCQE's async bit. | |
11709 | * | |
11710 | * Return: true if work posted to worker thread, otherwise false. | |
11711 | **/ | |
11712 | static bool | |
11713 | lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe) | |
11714 | { | |
11715 | struct lpfc_mcqe mcqe; | |
11716 | bool workposted; | |
11717 | ||
11718 | /* Copy the mailbox MCQE and convert endian order as needed */ | |
11719 | lpfc_sli_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe)); | |
11720 | ||
11721 | /* Invoke the proper event handling routine */ | |
11722 | if (!bf_get(lpfc_trailer_async, &mcqe)) | |
11723 | workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe); | |
11724 | else | |
11725 | workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe); | |
11726 | return workposted; | |
11727 | } | |
11728 | ||
4f774513 JS |
11729 | /** |
11730 | * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event | |
11731 | * @phba: Pointer to HBA context object. | |
2a76a283 | 11732 | * @cq: Pointer to associated CQ |
4f774513 JS |
11733 | * @wcqe: Pointer to work-queue completion queue entry. |
11734 | * | |
11735 | * This routine handles an ELS work-queue completion event. | |
11736 | * | |
11737 | * Return: true if work posted to worker thread, otherwise false. | |
11738 | **/ | |
11739 | static bool | |
2a76a283 | 11740 | lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
4f774513 JS |
11741 | struct lpfc_wcqe_complete *wcqe) |
11742 | { | |
4f774513 JS |
11743 | struct lpfc_iocbq *irspiocbq; |
11744 | unsigned long iflags; | |
2a76a283 | 11745 | struct lpfc_sli_ring *pring = cq->pring; |
0e9bb8d7 JS |
11746 | int txq_cnt = 0; |
11747 | int txcmplq_cnt = 0; | |
11748 | int fcp_txcmplq_cnt = 0; | |
4f774513 | 11749 | |
45ed1190 | 11750 | /* Get an irspiocbq for later ELS response processing use */ |
4f774513 JS |
11751 | irspiocbq = lpfc_sli_get_iocbq(phba); |
11752 | if (!irspiocbq) { | |
0e9bb8d7 JS |
11753 | if (!list_empty(&pring->txq)) |
11754 | txq_cnt++; | |
11755 | if (!list_empty(&pring->txcmplq)) | |
11756 | txcmplq_cnt++; | |
11757 | if (!list_empty(&phba->sli.ring[LPFC_FCP_RING].txcmplq)) | |
11758 | fcp_txcmplq_cnt++; | |
4f774513 | 11759 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
2a9bf3d0 JS |
11760 | "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d " |
11761 | "fcp_txcmplq_cnt=%d, els_txcmplq_cnt=%d\n", | |
0e9bb8d7 JS |
11762 | txq_cnt, phba->iocb_cnt, |
11763 | fcp_txcmplq_cnt, | |
11764 | txcmplq_cnt); | |
45ed1190 | 11765 | return false; |
4f774513 | 11766 | } |
4f774513 | 11767 | |
45ed1190 JS |
11768 | /* Save off the slow-path queue event for work thread to process */ |
11769 | memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe)); | |
4f774513 | 11770 | spin_lock_irqsave(&phba->hbalock, iflags); |
4d9ab994 | 11771 | list_add_tail(&irspiocbq->cq_event.list, |
45ed1190 JS |
11772 | &phba->sli4_hba.sp_queue_event); |
11773 | phba->hba_flag |= HBA_SP_QUEUE_EVT; | |
4f774513 | 11774 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
4f774513 | 11775 | |
45ed1190 | 11776 | return true; |
4f774513 JS |
11777 | } |
11778 | ||
11779 | /** | |
11780 | * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event | |
11781 | * @phba: Pointer to HBA context object. | |
11782 | * @wcqe: Pointer to work-queue completion queue entry. | |
11783 | * | |
11784 | * This routine handles slow-path WQ entry comsumed event by invoking the | |
11785 | * proper WQ release routine to the slow-path WQ. | |
11786 | **/ | |
11787 | static void | |
11788 | lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba, | |
11789 | struct lpfc_wcqe_release *wcqe) | |
11790 | { | |
2e90f4b5 JS |
11791 | /* sanity check on queue memory */ |
11792 | if (unlikely(!phba->sli4_hba.els_wq)) | |
11793 | return; | |
4f774513 JS |
11794 | /* Check for the slow-path ELS work queue */ |
11795 | if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id) | |
11796 | lpfc_sli4_wq_release(phba->sli4_hba.els_wq, | |
11797 | bf_get(lpfc_wcqe_r_wqe_index, wcqe)); | |
11798 | else | |
11799 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
11800 | "2579 Slow-path wqe consume event carries " | |
11801 | "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n", | |
11802 | bf_get(lpfc_wcqe_r_wqe_index, wcqe), | |
11803 | phba->sli4_hba.els_wq->queue_id); | |
11804 | } | |
11805 | ||
11806 | /** | |
11807 | * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event | |
11808 | * @phba: Pointer to HBA context object. | |
11809 | * @cq: Pointer to a WQ completion queue. | |
11810 | * @wcqe: Pointer to work-queue completion queue entry. | |
11811 | * | |
11812 | * This routine handles an XRI abort event. | |
11813 | * | |
11814 | * Return: true if work posted to worker thread, otherwise false. | |
11815 | **/ | |
11816 | static bool | |
11817 | lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba, | |
11818 | struct lpfc_queue *cq, | |
11819 | struct sli4_wcqe_xri_aborted *wcqe) | |
11820 | { | |
11821 | bool workposted = false; | |
11822 | struct lpfc_cq_event *cq_event; | |
11823 | unsigned long iflags; | |
11824 | ||
11825 | /* Allocate a new internal CQ_EVENT entry */ | |
11826 | cq_event = lpfc_sli4_cq_event_alloc(phba); | |
11827 | if (!cq_event) { | |
11828 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
11829 | "0602 Failed to allocate CQ_EVENT entry\n"); | |
11830 | return false; | |
11831 | } | |
11832 | ||
11833 | /* Move the CQE into the proper xri abort event list */ | |
11834 | memcpy(&cq_event->cqe, wcqe, sizeof(struct sli4_wcqe_xri_aborted)); | |
11835 | switch (cq->subtype) { | |
11836 | case LPFC_FCP: | |
11837 | spin_lock_irqsave(&phba->hbalock, iflags); | |
11838 | list_add_tail(&cq_event->list, | |
11839 | &phba->sli4_hba.sp_fcp_xri_aborted_work_queue); | |
11840 | /* Set the fcp xri abort event flag */ | |
11841 | phba->hba_flag |= FCP_XRI_ABORT_EVENT; | |
11842 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
11843 | workposted = true; | |
11844 | break; | |
11845 | case LPFC_ELS: | |
11846 | spin_lock_irqsave(&phba->hbalock, iflags); | |
11847 | list_add_tail(&cq_event->list, | |
11848 | &phba->sli4_hba.sp_els_xri_aborted_work_queue); | |
11849 | /* Set the els xri abort event flag */ | |
11850 | phba->hba_flag |= ELS_XRI_ABORT_EVENT; | |
11851 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
11852 | workposted = true; | |
11853 | break; | |
11854 | default: | |
11855 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
11856 | "0603 Invalid work queue CQE subtype (x%x)\n", | |
11857 | cq->subtype); | |
11858 | workposted = false; | |
11859 | break; | |
11860 | } | |
11861 | return workposted; | |
11862 | } | |
11863 | ||
4f774513 JS |
11864 | /** |
11865 | * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry | |
11866 | * @phba: Pointer to HBA context object. | |
11867 | * @rcqe: Pointer to receive-queue completion queue entry. | |
11868 | * | |
11869 | * This routine process a receive-queue completion queue entry. | |
11870 | * | |
11871 | * Return: true if work posted to worker thread, otherwise false. | |
11872 | **/ | |
11873 | static bool | |
4d9ab994 | 11874 | lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe) |
4f774513 | 11875 | { |
4f774513 JS |
11876 | bool workposted = false; |
11877 | struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq; | |
11878 | struct lpfc_queue *drq = phba->sli4_hba.dat_rq; | |
11879 | struct hbq_dmabuf *dma_buf; | |
7851fe2c | 11880 | uint32_t status, rq_id; |
4f774513 JS |
11881 | unsigned long iflags; |
11882 | ||
2e90f4b5 JS |
11883 | /* sanity check on queue memory */ |
11884 | if (unlikely(!hrq) || unlikely(!drq)) | |
11885 | return workposted; | |
11886 | ||
7851fe2c JS |
11887 | if (bf_get(lpfc_cqe_code, rcqe) == CQE_CODE_RECEIVE_V1) |
11888 | rq_id = bf_get(lpfc_rcqe_rq_id_v1, rcqe); | |
11889 | else | |
11890 | rq_id = bf_get(lpfc_rcqe_rq_id, rcqe); | |
11891 | if (rq_id != hrq->queue_id) | |
4f774513 JS |
11892 | goto out; |
11893 | ||
4d9ab994 | 11894 | status = bf_get(lpfc_rcqe_status, rcqe); |
4f774513 JS |
11895 | switch (status) { |
11896 | case FC_STATUS_RQ_BUF_LEN_EXCEEDED: | |
11897 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
11898 | "2537 Receive Frame Truncated!!\n"); | |
b84daac9 | 11899 | hrq->RQ_buf_trunc++; |
4f774513 | 11900 | case FC_STATUS_RQ_SUCCESS: |
5ffc266e | 11901 | lpfc_sli4_rq_release(hrq, drq); |
4f774513 JS |
11902 | spin_lock_irqsave(&phba->hbalock, iflags); |
11903 | dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list); | |
11904 | if (!dma_buf) { | |
b84daac9 | 11905 | hrq->RQ_no_buf_found++; |
4f774513 JS |
11906 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
11907 | goto out; | |
11908 | } | |
b84daac9 | 11909 | hrq->RQ_rcv_buf++; |
4d9ab994 | 11910 | memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe)); |
4f774513 | 11911 | /* save off the frame for the word thread to process */ |
4d9ab994 | 11912 | list_add_tail(&dma_buf->cq_event.list, |
45ed1190 | 11913 | &phba->sli4_hba.sp_queue_event); |
4f774513 | 11914 | /* Frame received */ |
45ed1190 | 11915 | phba->hba_flag |= HBA_SP_QUEUE_EVT; |
4f774513 JS |
11916 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
11917 | workposted = true; | |
11918 | break; | |
11919 | case FC_STATUS_INSUFF_BUF_NEED_BUF: | |
11920 | case FC_STATUS_INSUFF_BUF_FRM_DISC: | |
b84daac9 | 11921 | hrq->RQ_no_posted_buf++; |
4f774513 JS |
11922 | /* Post more buffers if possible */ |
11923 | spin_lock_irqsave(&phba->hbalock, iflags); | |
11924 | phba->hba_flag |= HBA_POST_RECEIVE_BUFFER; | |
11925 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
11926 | workposted = true; | |
11927 | break; | |
11928 | } | |
11929 | out: | |
11930 | return workposted; | |
4f774513 JS |
11931 | } |
11932 | ||
4d9ab994 JS |
11933 | /** |
11934 | * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry | |
11935 | * @phba: Pointer to HBA context object. | |
11936 | * @cq: Pointer to the completion queue. | |
11937 | * @wcqe: Pointer to a completion queue entry. | |
11938 | * | |
25985edc | 11939 | * This routine process a slow-path work-queue or receive queue completion queue |
4d9ab994 JS |
11940 | * entry. |
11941 | * | |
11942 | * Return: true if work posted to worker thread, otherwise false. | |
11943 | **/ | |
11944 | static bool | |
11945 | lpfc_sli4_sp_handle_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq, | |
11946 | struct lpfc_cqe *cqe) | |
11947 | { | |
45ed1190 | 11948 | struct lpfc_cqe cqevt; |
4d9ab994 JS |
11949 | bool workposted = false; |
11950 | ||
11951 | /* Copy the work queue CQE and convert endian order if needed */ | |
45ed1190 | 11952 | lpfc_sli_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe)); |
4d9ab994 JS |
11953 | |
11954 | /* Check and process for different type of WCQE and dispatch */ | |
45ed1190 | 11955 | switch (bf_get(lpfc_cqe_code, &cqevt)) { |
4d9ab994 | 11956 | case CQE_CODE_COMPL_WQE: |
45ed1190 | 11957 | /* Process the WQ/RQ complete event */ |
bc73905a | 11958 | phba->last_completion_time = jiffies; |
2a76a283 | 11959 | workposted = lpfc_sli4_sp_handle_els_wcqe(phba, cq, |
45ed1190 | 11960 | (struct lpfc_wcqe_complete *)&cqevt); |
4d9ab994 JS |
11961 | break; |
11962 | case CQE_CODE_RELEASE_WQE: | |
11963 | /* Process the WQ release event */ | |
11964 | lpfc_sli4_sp_handle_rel_wcqe(phba, | |
45ed1190 | 11965 | (struct lpfc_wcqe_release *)&cqevt); |
4d9ab994 JS |
11966 | break; |
11967 | case CQE_CODE_XRI_ABORTED: | |
11968 | /* Process the WQ XRI abort event */ | |
bc73905a | 11969 | phba->last_completion_time = jiffies; |
4d9ab994 | 11970 | workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq, |
45ed1190 | 11971 | (struct sli4_wcqe_xri_aborted *)&cqevt); |
4d9ab994 JS |
11972 | break; |
11973 | case CQE_CODE_RECEIVE: | |
7851fe2c | 11974 | case CQE_CODE_RECEIVE_V1: |
4d9ab994 | 11975 | /* Process the RQ event */ |
bc73905a | 11976 | phba->last_completion_time = jiffies; |
4d9ab994 | 11977 | workposted = lpfc_sli4_sp_handle_rcqe(phba, |
45ed1190 | 11978 | (struct lpfc_rcqe *)&cqevt); |
4d9ab994 JS |
11979 | break; |
11980 | default: | |
11981 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
11982 | "0388 Not a valid WCQE code: x%x\n", | |
45ed1190 | 11983 | bf_get(lpfc_cqe_code, &cqevt)); |
4d9ab994 JS |
11984 | break; |
11985 | } | |
11986 | return workposted; | |
11987 | } | |
11988 | ||
4f774513 JS |
11989 | /** |
11990 | * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry | |
11991 | * @phba: Pointer to HBA context object. | |
11992 | * @eqe: Pointer to fast-path event queue entry. | |
11993 | * | |
11994 | * This routine process a event queue entry from the slow-path event queue. | |
11995 | * It will check the MajorCode and MinorCode to determine this is for a | |
11996 | * completion event on a completion queue, if not, an error shall be logged | |
11997 | * and just return. Otherwise, it will get to the corresponding completion | |
11998 | * queue and process all the entries on that completion queue, rearm the | |
11999 | * completion queue, and then return. | |
12000 | * | |
12001 | **/ | |
12002 | static void | |
67d12733 JS |
12003 | lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe, |
12004 | struct lpfc_queue *speq) | |
4f774513 | 12005 | { |
67d12733 | 12006 | struct lpfc_queue *cq = NULL, *childq; |
4f774513 JS |
12007 | struct lpfc_cqe *cqe; |
12008 | bool workposted = false; | |
12009 | int ecount = 0; | |
12010 | uint16_t cqid; | |
12011 | ||
4f774513 | 12012 | /* Get the reference to the corresponding CQ */ |
cb5172ea | 12013 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
4f774513 | 12014 | |
4f774513 JS |
12015 | list_for_each_entry(childq, &speq->child_list, list) { |
12016 | if (childq->queue_id == cqid) { | |
12017 | cq = childq; | |
12018 | break; | |
12019 | } | |
12020 | } | |
12021 | if (unlikely(!cq)) { | |
75baf696 JS |
12022 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) |
12023 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
12024 | "0365 Slow-path CQ identifier " | |
12025 | "(%d) does not exist\n", cqid); | |
4f774513 JS |
12026 | return; |
12027 | } | |
12028 | ||
12029 | /* Process all the entries to the CQ */ | |
12030 | switch (cq->type) { | |
12031 | case LPFC_MCQ: | |
12032 | while ((cqe = lpfc_sli4_cq_get(cq))) { | |
12033 | workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe); | |
73d91e50 | 12034 | if (!(++ecount % cq->entry_repost)) |
4f774513 | 12035 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM); |
b84daac9 | 12036 | cq->CQ_mbox++; |
4f774513 JS |
12037 | } |
12038 | break; | |
12039 | case LPFC_WCQ: | |
12040 | while ((cqe = lpfc_sli4_cq_get(cq))) { | |
0558056c JS |
12041 | if (cq->subtype == LPFC_FCP) |
12042 | workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, | |
12043 | cqe); | |
12044 | else | |
12045 | workposted |= lpfc_sli4_sp_handle_cqe(phba, cq, | |
12046 | cqe); | |
73d91e50 | 12047 | if (!(++ecount % cq->entry_repost)) |
4f774513 JS |
12048 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM); |
12049 | } | |
b84daac9 JS |
12050 | |
12051 | /* Track the max number of CQEs processed in 1 EQ */ | |
12052 | if (ecount > cq->CQ_max_cqe) | |
12053 | cq->CQ_max_cqe = ecount; | |
4f774513 JS |
12054 | break; |
12055 | default: | |
12056 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
12057 | "0370 Invalid completion queue type (%d)\n", | |
12058 | cq->type); | |
12059 | return; | |
12060 | } | |
12061 | ||
12062 | /* Catch the no cq entry condition, log an error */ | |
12063 | if (unlikely(ecount == 0)) | |
12064 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
12065 | "0371 No entry from the CQ: identifier " | |
12066 | "(x%x), type (%d)\n", cq->queue_id, cq->type); | |
12067 | ||
12068 | /* In any case, flash and re-arm the RCQ */ | |
12069 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM); | |
12070 | ||
12071 | /* wake up worker thread if there are works to be done */ | |
12072 | if (workposted) | |
12073 | lpfc_worker_wake_up(phba); | |
12074 | } | |
12075 | ||
12076 | /** | |
12077 | * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry | |
2a76a283 JS |
12078 | * @phba: Pointer to HBA context object. |
12079 | * @cq: Pointer to associated CQ | |
12080 | * @wcqe: Pointer to work-queue completion queue entry. | |
4f774513 JS |
12081 | * |
12082 | * This routine process a fast-path work queue completion entry from fast-path | |
12083 | * event queue for FCP command response completion. | |
12084 | **/ | |
12085 | static void | |
2a76a283 | 12086 | lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
4f774513 JS |
12087 | struct lpfc_wcqe_complete *wcqe) |
12088 | { | |
2a76a283 | 12089 | struct lpfc_sli_ring *pring = cq->pring; |
4f774513 JS |
12090 | struct lpfc_iocbq *cmdiocbq; |
12091 | struct lpfc_iocbq irspiocbq; | |
12092 | unsigned long iflags; | |
12093 | ||
4f774513 JS |
12094 | /* Check for response status */ |
12095 | if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) { | |
12096 | /* If resource errors reported from HBA, reduce queue | |
12097 | * depth of the SCSI device. | |
12098 | */ | |
e3d2b802 JS |
12099 | if (((bf_get(lpfc_wcqe_c_status, wcqe) == |
12100 | IOSTAT_LOCAL_REJECT)) && | |
12101 | ((wcqe->parameter & IOERR_PARAM_MASK) == | |
12102 | IOERR_NO_RESOURCES)) | |
4f774513 | 12103 | phba->lpfc_rampdown_queue_depth(phba); |
e3d2b802 | 12104 | |
4f774513 JS |
12105 | /* Log the error status */ |
12106 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
12107 | "0373 FCP complete error: status=x%x, " | |
12108 | "hw_status=x%x, total_data_specified=%d, " | |
12109 | "parameter=x%x, word3=x%x\n", | |
12110 | bf_get(lpfc_wcqe_c_status, wcqe), | |
12111 | bf_get(lpfc_wcqe_c_hw_status, wcqe), | |
12112 | wcqe->total_data_placed, wcqe->parameter, | |
12113 | wcqe->word3); | |
12114 | } | |
12115 | ||
12116 | /* Look up the FCP command IOCB and create pseudo response IOCB */ | |
7e56aa25 JS |
12117 | spin_lock_irqsave(&pring->ring_lock, iflags); |
12118 | pring->stats.iocb_event++; | |
4f774513 JS |
12119 | cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring, |
12120 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); | |
7e56aa25 | 12121 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
4f774513 JS |
12122 | if (unlikely(!cmdiocbq)) { |
12123 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
12124 | "0374 FCP complete with no corresponding " | |
12125 | "cmdiocb: iotag (%d)\n", | |
12126 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); | |
12127 | return; | |
12128 | } | |
12129 | if (unlikely(!cmdiocbq->iocb_cmpl)) { | |
12130 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
12131 | "0375 FCP cmdiocb not callback function " | |
12132 | "iotag: (%d)\n", | |
12133 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); | |
12134 | return; | |
12135 | } | |
12136 | ||
12137 | /* Fake the irspiocb and copy necessary response information */ | |
341af102 | 12138 | lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe); |
4f774513 | 12139 | |
0f65ff68 JS |
12140 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) { |
12141 | spin_lock_irqsave(&phba->hbalock, iflags); | |
12142 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; | |
12143 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
12144 | } | |
12145 | ||
4f774513 JS |
12146 | /* Pass the cmd_iocb and the rsp state to the upper layer */ |
12147 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq); | |
12148 | } | |
12149 | ||
12150 | /** | |
12151 | * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event | |
12152 | * @phba: Pointer to HBA context object. | |
12153 | * @cq: Pointer to completion queue. | |
12154 | * @wcqe: Pointer to work-queue completion queue entry. | |
12155 | * | |
12156 | * This routine handles an fast-path WQ entry comsumed event by invoking the | |
12157 | * proper WQ release routine to the slow-path WQ. | |
12158 | **/ | |
12159 | static void | |
12160 | lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, | |
12161 | struct lpfc_wcqe_release *wcqe) | |
12162 | { | |
12163 | struct lpfc_queue *childwq; | |
12164 | bool wqid_matched = false; | |
12165 | uint16_t fcp_wqid; | |
12166 | ||
12167 | /* Check for fast-path FCP work queue release */ | |
12168 | fcp_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe); | |
12169 | list_for_each_entry(childwq, &cq->child_list, list) { | |
12170 | if (childwq->queue_id == fcp_wqid) { | |
12171 | lpfc_sli4_wq_release(childwq, | |
12172 | bf_get(lpfc_wcqe_r_wqe_index, wcqe)); | |
12173 | wqid_matched = true; | |
12174 | break; | |
12175 | } | |
12176 | } | |
12177 | /* Report warning log message if no match found */ | |
12178 | if (wqid_matched != true) | |
12179 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
12180 | "2580 Fast-path wqe consume event carries " | |
12181 | "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid); | |
12182 | } | |
12183 | ||
12184 | /** | |
12185 | * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry | |
12186 | * @cq: Pointer to the completion queue. | |
12187 | * @eqe: Pointer to fast-path completion queue entry. | |
12188 | * | |
12189 | * This routine process a fast-path work queue completion entry from fast-path | |
12190 | * event queue for FCP command response completion. | |
12191 | **/ | |
12192 | static int | |
12193 | lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, | |
12194 | struct lpfc_cqe *cqe) | |
12195 | { | |
12196 | struct lpfc_wcqe_release wcqe; | |
12197 | bool workposted = false; | |
12198 | ||
12199 | /* Copy the work queue CQE and convert endian order if needed */ | |
12200 | lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe)); | |
12201 | ||
12202 | /* Check and process for different type of WCQE and dispatch */ | |
12203 | switch (bf_get(lpfc_wcqe_c_code, &wcqe)) { | |
12204 | case CQE_CODE_COMPL_WQE: | |
b84daac9 | 12205 | cq->CQ_wq++; |
4f774513 | 12206 | /* Process the WQ complete event */ |
98fc5dd9 | 12207 | phba->last_completion_time = jiffies; |
2a76a283 | 12208 | lpfc_sli4_fp_handle_fcp_wcqe(phba, cq, |
4f774513 JS |
12209 | (struct lpfc_wcqe_complete *)&wcqe); |
12210 | break; | |
12211 | case CQE_CODE_RELEASE_WQE: | |
b84daac9 | 12212 | cq->CQ_release_wqe++; |
4f774513 JS |
12213 | /* Process the WQ release event */ |
12214 | lpfc_sli4_fp_handle_rel_wcqe(phba, cq, | |
12215 | (struct lpfc_wcqe_release *)&wcqe); | |
12216 | break; | |
12217 | case CQE_CODE_XRI_ABORTED: | |
b84daac9 | 12218 | cq->CQ_xri_aborted++; |
4f774513 | 12219 | /* Process the WQ XRI abort event */ |
bc73905a | 12220 | phba->last_completion_time = jiffies; |
4f774513 JS |
12221 | workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq, |
12222 | (struct sli4_wcqe_xri_aborted *)&wcqe); | |
12223 | break; | |
12224 | default: | |
12225 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
12226 | "0144 Not a valid WCQE code: x%x\n", | |
12227 | bf_get(lpfc_wcqe_c_code, &wcqe)); | |
12228 | break; | |
12229 | } | |
12230 | return workposted; | |
12231 | } | |
12232 | ||
12233 | /** | |
67d12733 | 12234 | * lpfc_sli4_hba_handle_eqe - Process a fast-path event queue entry |
4f774513 JS |
12235 | * @phba: Pointer to HBA context object. |
12236 | * @eqe: Pointer to fast-path event queue entry. | |
12237 | * | |
12238 | * This routine process a event queue entry from the fast-path event queue. | |
12239 | * It will check the MajorCode and MinorCode to determine this is for a | |
12240 | * completion event on a completion queue, if not, an error shall be logged | |
12241 | * and just return. Otherwise, it will get to the corresponding completion | |
12242 | * queue and process all the entries on the completion queue, rearm the | |
12243 | * completion queue, and then return. | |
12244 | **/ | |
12245 | static void | |
67d12733 JS |
12246 | lpfc_sli4_hba_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe, |
12247 | uint32_t qidx) | |
4f774513 JS |
12248 | { |
12249 | struct lpfc_queue *cq; | |
12250 | struct lpfc_cqe *cqe; | |
12251 | bool workposted = false; | |
12252 | uint16_t cqid; | |
12253 | int ecount = 0; | |
12254 | ||
cb5172ea | 12255 | if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) { |
4f774513 | 12256 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
67d12733 | 12257 | "0366 Not a valid completion " |
4f774513 | 12258 | "event: majorcode=x%x, minorcode=x%x\n", |
cb5172ea JS |
12259 | bf_get_le32(lpfc_eqe_major_code, eqe), |
12260 | bf_get_le32(lpfc_eqe_minor_code, eqe)); | |
4f774513 JS |
12261 | return; |
12262 | } | |
12263 | ||
67d12733 JS |
12264 | /* Get the reference to the corresponding CQ */ |
12265 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); | |
12266 | ||
12267 | /* Check if this is a Slow path event */ | |
12268 | if (unlikely(cqid != phba->sli4_hba.fcp_cq_map[qidx])) { | |
12269 | lpfc_sli4_sp_handle_eqe(phba, eqe, | |
12270 | phba->sli4_hba.hba_eq[qidx]); | |
12271 | return; | |
12272 | } | |
12273 | ||
2e90f4b5 JS |
12274 | if (unlikely(!phba->sli4_hba.fcp_cq)) { |
12275 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
12276 | "3146 Fast-path completion queues " | |
12277 | "does not exist\n"); | |
12278 | return; | |
12279 | } | |
67d12733 | 12280 | cq = phba->sli4_hba.fcp_cq[qidx]; |
4f774513 | 12281 | if (unlikely(!cq)) { |
75baf696 JS |
12282 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) |
12283 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
12284 | "0367 Fast-path completion queue " | |
67d12733 | 12285 | "(%d) does not exist\n", qidx); |
4f774513 JS |
12286 | return; |
12287 | } | |
12288 | ||
4f774513 JS |
12289 | if (unlikely(cqid != cq->queue_id)) { |
12290 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
12291 | "0368 Miss-matched fast-path completion " | |
12292 | "queue identifier: eqcqid=%d, fcpcqid=%d\n", | |
12293 | cqid, cq->queue_id); | |
12294 | return; | |
12295 | } | |
12296 | ||
12297 | /* Process all the entries to the CQ */ | |
12298 | while ((cqe = lpfc_sli4_cq_get(cq))) { | |
12299 | workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe); | |
73d91e50 | 12300 | if (!(++ecount % cq->entry_repost)) |
4f774513 JS |
12301 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM); |
12302 | } | |
12303 | ||
b84daac9 JS |
12304 | /* Track the max number of CQEs processed in 1 EQ */ |
12305 | if (ecount > cq->CQ_max_cqe) | |
12306 | cq->CQ_max_cqe = ecount; | |
12307 | ||
4f774513 JS |
12308 | /* Catch the no cq entry condition */ |
12309 | if (unlikely(ecount == 0)) | |
12310 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
12311 | "0369 No entry from fast-path completion " | |
12312 | "queue fcpcqid=%d\n", cq->queue_id); | |
12313 | ||
12314 | /* In any case, flash and re-arm the CQ */ | |
12315 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM); | |
12316 | ||
12317 | /* wake up worker thread if there are works to be done */ | |
12318 | if (workposted) | |
12319 | lpfc_worker_wake_up(phba); | |
12320 | } | |
12321 | ||
12322 | static void | |
12323 | lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq) | |
12324 | { | |
12325 | struct lpfc_eqe *eqe; | |
12326 | ||
12327 | /* walk all the EQ entries and drop on the floor */ | |
12328 | while ((eqe = lpfc_sli4_eq_get(eq))) | |
12329 | ; | |
12330 | ||
12331 | /* Clear and re-arm the EQ */ | |
12332 | lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM); | |
12333 | } | |
12334 | ||
1ba981fd JS |
12335 | |
12336 | /** | |
12337 | * lpfc_sli4_fof_handle_eqe - Process a Flash Optimized Fabric event queue | |
12338 | * entry | |
12339 | * @phba: Pointer to HBA context object. | |
12340 | * @eqe: Pointer to fast-path event queue entry. | |
12341 | * | |
12342 | * This routine process a event queue entry from the Flash Optimized Fabric | |
12343 | * event queue. It will check the MajorCode and MinorCode to determine this | |
12344 | * is for a completion event on a completion queue, if not, an error shall be | |
12345 | * logged and just return. Otherwise, it will get to the corresponding | |
12346 | * completion queue and process all the entries on the completion queue, rearm | |
12347 | * the completion queue, and then return. | |
12348 | **/ | |
12349 | static void | |
12350 | lpfc_sli4_fof_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe) | |
12351 | { | |
12352 | struct lpfc_queue *cq; | |
12353 | struct lpfc_cqe *cqe; | |
12354 | bool workposted = false; | |
12355 | uint16_t cqid; | |
12356 | int ecount = 0; | |
12357 | ||
12358 | if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) { | |
12359 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
12360 | "9147 Not a valid completion " | |
12361 | "event: majorcode=x%x, minorcode=x%x\n", | |
12362 | bf_get_le32(lpfc_eqe_major_code, eqe), | |
12363 | bf_get_le32(lpfc_eqe_minor_code, eqe)); | |
12364 | return; | |
12365 | } | |
12366 | ||
12367 | /* Get the reference to the corresponding CQ */ | |
12368 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); | |
12369 | ||
12370 | /* Next check for OAS */ | |
12371 | cq = phba->sli4_hba.oas_cq; | |
12372 | if (unlikely(!cq)) { | |
12373 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) | |
12374 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
12375 | "9148 OAS completion queue " | |
12376 | "does not exist\n"); | |
12377 | return; | |
12378 | } | |
12379 | ||
12380 | if (unlikely(cqid != cq->queue_id)) { | |
12381 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
12382 | "9149 Miss-matched fast-path compl " | |
12383 | "queue id: eqcqid=%d, fcpcqid=%d\n", | |
12384 | cqid, cq->queue_id); | |
12385 | return; | |
12386 | } | |
12387 | ||
12388 | /* Process all the entries to the OAS CQ */ | |
12389 | while ((cqe = lpfc_sli4_cq_get(cq))) { | |
12390 | workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe); | |
12391 | if (!(++ecount % cq->entry_repost)) | |
12392 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM); | |
12393 | } | |
12394 | ||
12395 | /* Track the max number of CQEs processed in 1 EQ */ | |
12396 | if (ecount > cq->CQ_max_cqe) | |
12397 | cq->CQ_max_cqe = ecount; | |
12398 | ||
12399 | /* Catch the no cq entry condition */ | |
12400 | if (unlikely(ecount == 0)) | |
12401 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
12402 | "9153 No entry from fast-path completion " | |
12403 | "queue fcpcqid=%d\n", cq->queue_id); | |
12404 | ||
12405 | /* In any case, flash and re-arm the CQ */ | |
12406 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM); | |
12407 | ||
12408 | /* wake up worker thread if there are works to be done */ | |
12409 | if (workposted) | |
12410 | lpfc_worker_wake_up(phba); | |
12411 | } | |
12412 | ||
12413 | /** | |
12414 | * lpfc_sli4_fof_intr_handler - HBA interrupt handler to SLI-4 device | |
12415 | * @irq: Interrupt number. | |
12416 | * @dev_id: The device context pointer. | |
12417 | * | |
12418 | * This function is directly called from the PCI layer as an interrupt | |
12419 | * service routine when device with SLI-4 interface spec is enabled with | |
12420 | * MSI-X multi-message interrupt mode and there is a Flash Optimized Fabric | |
12421 | * IOCB ring event in the HBA. However, when the device is enabled with either | |
12422 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the | |
12423 | * device-level interrupt handler. When the PCI slot is in error recovery | |
12424 | * or the HBA is undergoing initialization, the interrupt handler will not | |
12425 | * process the interrupt. The Flash Optimized Fabric ring event are handled in | |
12426 | * the intrrupt context. This function is called without any lock held. | |
12427 | * It gets the hbalock to access and update SLI data structures. Note that, | |
12428 | * the EQ to CQ are one-to-one map such that the EQ index is | |
12429 | * equal to that of CQ index. | |
12430 | * | |
12431 | * This function returns IRQ_HANDLED when interrupt is handled else it | |
12432 | * returns IRQ_NONE. | |
12433 | **/ | |
12434 | irqreturn_t | |
12435 | lpfc_sli4_fof_intr_handler(int irq, void *dev_id) | |
12436 | { | |
12437 | struct lpfc_hba *phba; | |
12438 | struct lpfc_fcp_eq_hdl *fcp_eq_hdl; | |
12439 | struct lpfc_queue *eq; | |
12440 | struct lpfc_eqe *eqe; | |
12441 | unsigned long iflag; | |
12442 | int ecount = 0; | |
12443 | uint32_t eqidx; | |
12444 | ||
12445 | /* Get the driver's phba structure from the dev_id */ | |
12446 | fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id; | |
12447 | phba = fcp_eq_hdl->phba; | |
12448 | eqidx = fcp_eq_hdl->idx; | |
12449 | ||
12450 | if (unlikely(!phba)) | |
12451 | return IRQ_NONE; | |
12452 | ||
12453 | /* Get to the EQ struct associated with this vector */ | |
12454 | eq = phba->sli4_hba.fof_eq; | |
12455 | if (unlikely(!eq)) | |
12456 | return IRQ_NONE; | |
12457 | ||
12458 | /* Check device state for handling interrupt */ | |
12459 | if (unlikely(lpfc_intr_state_check(phba))) { | |
12460 | eq->EQ_badstate++; | |
12461 | /* Check again for link_state with lock held */ | |
12462 | spin_lock_irqsave(&phba->hbalock, iflag); | |
12463 | if (phba->link_state < LPFC_LINK_DOWN) | |
12464 | /* Flush, clear interrupt, and rearm the EQ */ | |
12465 | lpfc_sli4_eq_flush(phba, eq); | |
12466 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
12467 | return IRQ_NONE; | |
12468 | } | |
12469 | ||
12470 | /* | |
12471 | * Process all the event on FCP fast-path EQ | |
12472 | */ | |
12473 | while ((eqe = lpfc_sli4_eq_get(eq))) { | |
12474 | lpfc_sli4_fof_handle_eqe(phba, eqe); | |
12475 | if (!(++ecount % eq->entry_repost)) | |
12476 | lpfc_sli4_eq_release(eq, LPFC_QUEUE_NOARM); | |
12477 | eq->EQ_processed++; | |
12478 | } | |
12479 | ||
12480 | /* Track the max number of EQEs processed in 1 intr */ | |
12481 | if (ecount > eq->EQ_max_eqe) | |
12482 | eq->EQ_max_eqe = ecount; | |
12483 | ||
12484 | ||
12485 | if (unlikely(ecount == 0)) { | |
12486 | eq->EQ_no_entry++; | |
12487 | ||
12488 | if (phba->intr_type == MSIX) | |
12489 | /* MSI-X treated interrupt served as no EQ share INT */ | |
12490 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
12491 | "9145 MSI-X interrupt with no EQE\n"); | |
12492 | else { | |
12493 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
12494 | "9146 ISR interrupt with no EQE\n"); | |
12495 | /* Non MSI-X treated on interrupt as EQ share INT */ | |
12496 | return IRQ_NONE; | |
12497 | } | |
12498 | } | |
12499 | /* Always clear and re-arm the fast-path EQ */ | |
12500 | lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM); | |
12501 | return IRQ_HANDLED; | |
12502 | } | |
12503 | ||
4f774513 | 12504 | /** |
67d12733 | 12505 | * lpfc_sli4_hba_intr_handler - HBA interrupt handler to SLI-4 device |
4f774513 JS |
12506 | * @irq: Interrupt number. |
12507 | * @dev_id: The device context pointer. | |
12508 | * | |
12509 | * This function is directly called from the PCI layer as an interrupt | |
12510 | * service routine when device with SLI-4 interface spec is enabled with | |
12511 | * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB | |
12512 | * ring event in the HBA. However, when the device is enabled with either | |
12513 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the | |
12514 | * device-level interrupt handler. When the PCI slot is in error recovery | |
12515 | * or the HBA is undergoing initialization, the interrupt handler will not | |
12516 | * process the interrupt. The SCSI FCP fast-path ring event are handled in | |
12517 | * the intrrupt context. This function is called without any lock held. | |
12518 | * It gets the hbalock to access and update SLI data structures. Note that, | |
12519 | * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is | |
12520 | * equal to that of FCP CQ index. | |
12521 | * | |
67d12733 JS |
12522 | * The link attention and ELS ring attention events are handled |
12523 | * by the worker thread. The interrupt handler signals the worker thread | |
12524 | * and returns for these events. This function is called without any lock | |
12525 | * held. It gets the hbalock to access and update SLI data structures. | |
12526 | * | |
4f774513 JS |
12527 | * This function returns IRQ_HANDLED when interrupt is handled else it |
12528 | * returns IRQ_NONE. | |
12529 | **/ | |
12530 | irqreturn_t | |
67d12733 | 12531 | lpfc_sli4_hba_intr_handler(int irq, void *dev_id) |
4f774513 JS |
12532 | { |
12533 | struct lpfc_hba *phba; | |
12534 | struct lpfc_fcp_eq_hdl *fcp_eq_hdl; | |
12535 | struct lpfc_queue *fpeq; | |
12536 | struct lpfc_eqe *eqe; | |
12537 | unsigned long iflag; | |
12538 | int ecount = 0; | |
962bc51b | 12539 | int fcp_eqidx; |
4f774513 JS |
12540 | |
12541 | /* Get the driver's phba structure from the dev_id */ | |
12542 | fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id; | |
12543 | phba = fcp_eq_hdl->phba; | |
12544 | fcp_eqidx = fcp_eq_hdl->idx; | |
12545 | ||
12546 | if (unlikely(!phba)) | |
12547 | return IRQ_NONE; | |
67d12733 | 12548 | if (unlikely(!phba->sli4_hba.hba_eq)) |
5350d872 | 12549 | return IRQ_NONE; |
4f774513 JS |
12550 | |
12551 | /* Get to the EQ struct associated with this vector */ | |
67d12733 | 12552 | fpeq = phba->sli4_hba.hba_eq[fcp_eqidx]; |
2e90f4b5 JS |
12553 | if (unlikely(!fpeq)) |
12554 | return IRQ_NONE; | |
4f774513 | 12555 | |
ba20c853 JS |
12556 | if (lpfc_fcp_look_ahead) { |
12557 | if (atomic_dec_and_test(&fcp_eq_hdl->fcp_eq_in_use)) | |
12558 | lpfc_sli4_eq_clr_intr(fpeq); | |
12559 | else { | |
12560 | atomic_inc(&fcp_eq_hdl->fcp_eq_in_use); | |
12561 | return IRQ_NONE; | |
12562 | } | |
12563 | } | |
12564 | ||
4f774513 JS |
12565 | /* Check device state for handling interrupt */ |
12566 | if (unlikely(lpfc_intr_state_check(phba))) { | |
b84daac9 | 12567 | fpeq->EQ_badstate++; |
4f774513 JS |
12568 | /* Check again for link_state with lock held */ |
12569 | spin_lock_irqsave(&phba->hbalock, iflag); | |
12570 | if (phba->link_state < LPFC_LINK_DOWN) | |
12571 | /* Flush, clear interrupt, and rearm the EQ */ | |
12572 | lpfc_sli4_eq_flush(phba, fpeq); | |
12573 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
ba20c853 JS |
12574 | if (lpfc_fcp_look_ahead) |
12575 | atomic_inc(&fcp_eq_hdl->fcp_eq_in_use); | |
4f774513 JS |
12576 | return IRQ_NONE; |
12577 | } | |
12578 | ||
12579 | /* | |
12580 | * Process all the event on FCP fast-path EQ | |
12581 | */ | |
12582 | while ((eqe = lpfc_sli4_eq_get(fpeq))) { | |
67d12733 | 12583 | lpfc_sli4_hba_handle_eqe(phba, eqe, fcp_eqidx); |
73d91e50 | 12584 | if (!(++ecount % fpeq->entry_repost)) |
4f774513 | 12585 | lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_NOARM); |
b84daac9 | 12586 | fpeq->EQ_processed++; |
4f774513 JS |
12587 | } |
12588 | ||
b84daac9 JS |
12589 | /* Track the max number of EQEs processed in 1 intr */ |
12590 | if (ecount > fpeq->EQ_max_eqe) | |
12591 | fpeq->EQ_max_eqe = ecount; | |
12592 | ||
4f774513 JS |
12593 | /* Always clear and re-arm the fast-path EQ */ |
12594 | lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM); | |
12595 | ||
12596 | if (unlikely(ecount == 0)) { | |
b84daac9 | 12597 | fpeq->EQ_no_entry++; |
ba20c853 JS |
12598 | |
12599 | if (lpfc_fcp_look_ahead) { | |
12600 | atomic_inc(&fcp_eq_hdl->fcp_eq_in_use); | |
12601 | return IRQ_NONE; | |
12602 | } | |
12603 | ||
4f774513 JS |
12604 | if (phba->intr_type == MSIX) |
12605 | /* MSI-X treated interrupt served as no EQ share INT */ | |
12606 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
12607 | "0358 MSI-X interrupt with no EQE\n"); | |
12608 | else | |
12609 | /* Non MSI-X treated on interrupt as EQ share INT */ | |
12610 | return IRQ_NONE; | |
12611 | } | |
12612 | ||
ba20c853 JS |
12613 | if (lpfc_fcp_look_ahead) |
12614 | atomic_inc(&fcp_eq_hdl->fcp_eq_in_use); | |
4f774513 JS |
12615 | return IRQ_HANDLED; |
12616 | } /* lpfc_sli4_fp_intr_handler */ | |
12617 | ||
12618 | /** | |
12619 | * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device | |
12620 | * @irq: Interrupt number. | |
12621 | * @dev_id: The device context pointer. | |
12622 | * | |
12623 | * This function is the device-level interrupt handler to device with SLI-4 | |
12624 | * interface spec, called from the PCI layer when either MSI or Pin-IRQ | |
12625 | * interrupt mode is enabled and there is an event in the HBA which requires | |
12626 | * driver attention. This function invokes the slow-path interrupt attention | |
12627 | * handling function and fast-path interrupt attention handling function in | |
12628 | * turn to process the relevant HBA attention events. This function is called | |
12629 | * without any lock held. It gets the hbalock to access and update SLI data | |
12630 | * structures. | |
12631 | * | |
12632 | * This function returns IRQ_HANDLED when interrupt is handled, else it | |
12633 | * returns IRQ_NONE. | |
12634 | **/ | |
12635 | irqreturn_t | |
12636 | lpfc_sli4_intr_handler(int irq, void *dev_id) | |
12637 | { | |
12638 | struct lpfc_hba *phba; | |
67d12733 JS |
12639 | irqreturn_t hba_irq_rc; |
12640 | bool hba_handled = false; | |
962bc51b | 12641 | int fcp_eqidx; |
4f774513 JS |
12642 | |
12643 | /* Get the driver's phba structure from the dev_id */ | |
12644 | phba = (struct lpfc_hba *)dev_id; | |
12645 | ||
12646 | if (unlikely(!phba)) | |
12647 | return IRQ_NONE; | |
12648 | ||
4f774513 JS |
12649 | /* |
12650 | * Invoke fast-path host attention interrupt handling as appropriate. | |
12651 | */ | |
67d12733 JS |
12652 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_io_channel; fcp_eqidx++) { |
12653 | hba_irq_rc = lpfc_sli4_hba_intr_handler(irq, | |
4f774513 | 12654 | &phba->sli4_hba.fcp_eq_hdl[fcp_eqidx]); |
67d12733 JS |
12655 | if (hba_irq_rc == IRQ_HANDLED) |
12656 | hba_handled |= true; | |
4f774513 JS |
12657 | } |
12658 | ||
1ba981fd JS |
12659 | if (phba->cfg_fof) { |
12660 | hba_irq_rc = lpfc_sli4_fof_intr_handler(irq, | |
12661 | &phba->sli4_hba.fcp_eq_hdl[0]); | |
12662 | if (hba_irq_rc == IRQ_HANDLED) | |
12663 | hba_handled |= true; | |
12664 | } | |
12665 | ||
67d12733 | 12666 | return (hba_handled == true) ? IRQ_HANDLED : IRQ_NONE; |
4f774513 JS |
12667 | } /* lpfc_sli4_intr_handler */ |
12668 | ||
12669 | /** | |
12670 | * lpfc_sli4_queue_free - free a queue structure and associated memory | |
12671 | * @queue: The queue structure to free. | |
12672 | * | |
b595076a | 12673 | * This function frees a queue structure and the DMAable memory used for |
4f774513 JS |
12674 | * the host resident queue. This function must be called after destroying the |
12675 | * queue on the HBA. | |
12676 | **/ | |
12677 | void | |
12678 | lpfc_sli4_queue_free(struct lpfc_queue *queue) | |
12679 | { | |
12680 | struct lpfc_dmabuf *dmabuf; | |
12681 | ||
12682 | if (!queue) | |
12683 | return; | |
12684 | ||
12685 | while (!list_empty(&queue->page_list)) { | |
12686 | list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf, | |
12687 | list); | |
49198b37 | 12688 | dma_free_coherent(&queue->phba->pcidev->dev, SLI4_PAGE_SIZE, |
4f774513 JS |
12689 | dmabuf->virt, dmabuf->phys); |
12690 | kfree(dmabuf); | |
12691 | } | |
12692 | kfree(queue); | |
12693 | return; | |
12694 | } | |
12695 | ||
12696 | /** | |
12697 | * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure | |
12698 | * @phba: The HBA that this queue is being created on. | |
12699 | * @entry_size: The size of each queue entry for this queue. | |
12700 | * @entry count: The number of entries that this queue will handle. | |
12701 | * | |
12702 | * This function allocates a queue structure and the DMAable memory used for | |
12703 | * the host resident queue. This function must be called before creating the | |
12704 | * queue on the HBA. | |
12705 | **/ | |
12706 | struct lpfc_queue * | |
12707 | lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t entry_size, | |
12708 | uint32_t entry_count) | |
12709 | { | |
12710 | struct lpfc_queue *queue; | |
12711 | struct lpfc_dmabuf *dmabuf; | |
12712 | int x, total_qe_count; | |
12713 | void *dma_pointer; | |
cb5172ea | 12714 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
4f774513 | 12715 | |
cb5172ea JS |
12716 | if (!phba->sli4_hba.pc_sli4_params.supported) |
12717 | hw_page_size = SLI4_PAGE_SIZE; | |
12718 | ||
4f774513 JS |
12719 | queue = kzalloc(sizeof(struct lpfc_queue) + |
12720 | (sizeof(union sli4_qe) * entry_count), GFP_KERNEL); | |
12721 | if (!queue) | |
12722 | return NULL; | |
cb5172ea JS |
12723 | queue->page_count = (ALIGN(entry_size * entry_count, |
12724 | hw_page_size))/hw_page_size; | |
4f774513 JS |
12725 | INIT_LIST_HEAD(&queue->list); |
12726 | INIT_LIST_HEAD(&queue->page_list); | |
12727 | INIT_LIST_HEAD(&queue->child_list); | |
12728 | for (x = 0, total_qe_count = 0; x < queue->page_count; x++) { | |
12729 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | |
12730 | if (!dmabuf) | |
12731 | goto out_fail; | |
1aee383d JP |
12732 | dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev, |
12733 | hw_page_size, &dmabuf->phys, | |
12734 | GFP_KERNEL); | |
4f774513 JS |
12735 | if (!dmabuf->virt) { |
12736 | kfree(dmabuf); | |
12737 | goto out_fail; | |
12738 | } | |
12739 | dmabuf->buffer_tag = x; | |
12740 | list_add_tail(&dmabuf->list, &queue->page_list); | |
12741 | /* initialize queue's entry array */ | |
12742 | dma_pointer = dmabuf->virt; | |
12743 | for (; total_qe_count < entry_count && | |
cb5172ea | 12744 | dma_pointer < (hw_page_size + dmabuf->virt); |
4f774513 JS |
12745 | total_qe_count++, dma_pointer += entry_size) { |
12746 | queue->qe[total_qe_count].address = dma_pointer; | |
12747 | } | |
12748 | } | |
12749 | queue->entry_size = entry_size; | |
12750 | queue->entry_count = entry_count; | |
73d91e50 JS |
12751 | |
12752 | /* | |
12753 | * entry_repost is calculated based on the number of entries in the | |
12754 | * queue. This works out except for RQs. If buffers are NOT initially | |
12755 | * posted for every RQE, entry_repost should be adjusted accordingly. | |
12756 | */ | |
12757 | queue->entry_repost = (entry_count >> 3); | |
12758 | if (queue->entry_repost < LPFC_QUEUE_MIN_REPOST) | |
12759 | queue->entry_repost = LPFC_QUEUE_MIN_REPOST; | |
4f774513 JS |
12760 | queue->phba = phba; |
12761 | ||
12762 | return queue; | |
12763 | out_fail: | |
12764 | lpfc_sli4_queue_free(queue); | |
12765 | return NULL; | |
12766 | } | |
12767 | ||
962bc51b JS |
12768 | /** |
12769 | * lpfc_dual_chute_pci_bar_map - Map pci base address register to host memory | |
12770 | * @phba: HBA structure that indicates port to create a queue on. | |
12771 | * @pci_barset: PCI BAR set flag. | |
12772 | * | |
12773 | * This function shall perform iomap of the specified PCI BAR address to host | |
12774 | * memory address if not already done so and return it. The returned host | |
12775 | * memory address can be NULL. | |
12776 | */ | |
12777 | static void __iomem * | |
12778 | lpfc_dual_chute_pci_bar_map(struct lpfc_hba *phba, uint16_t pci_barset) | |
12779 | { | |
12780 | struct pci_dev *pdev; | |
962bc51b JS |
12781 | |
12782 | if (!phba->pcidev) | |
12783 | return NULL; | |
12784 | else | |
12785 | pdev = phba->pcidev; | |
12786 | ||
12787 | switch (pci_barset) { | |
12788 | case WQ_PCI_BAR_0_AND_1: | |
962bc51b JS |
12789 | return phba->pci_bar0_memmap_p; |
12790 | case WQ_PCI_BAR_2_AND_3: | |
962bc51b JS |
12791 | return phba->pci_bar2_memmap_p; |
12792 | case WQ_PCI_BAR_4_AND_5: | |
962bc51b JS |
12793 | return phba->pci_bar4_memmap_p; |
12794 | default: | |
12795 | break; | |
12796 | } | |
12797 | return NULL; | |
12798 | } | |
12799 | ||
173edbb2 JS |
12800 | /** |
12801 | * lpfc_modify_fcp_eq_delay - Modify Delay Multiplier on FCP EQs | |
12802 | * @phba: HBA structure that indicates port to create a queue on. | |
12803 | * @startq: The starting FCP EQ to modify | |
12804 | * | |
12805 | * This function sends an MODIFY_EQ_DELAY mailbox command to the HBA. | |
12806 | * | |
12807 | * The @phba struct is used to send mailbox command to HBA. The @startq | |
12808 | * is used to get the starting FCP EQ to change. | |
12809 | * This function is asynchronous and will wait for the mailbox | |
12810 | * command to finish before continuing. | |
12811 | * | |
12812 | * On success this function will return a zero. If unable to allocate enough | |
12813 | * memory this function will return -ENOMEM. If the queue create mailbox command | |
12814 | * fails this function will return -ENXIO. | |
12815 | **/ | |
12816 | uint32_t | |
12817 | lpfc_modify_fcp_eq_delay(struct lpfc_hba *phba, uint16_t startq) | |
12818 | { | |
12819 | struct lpfc_mbx_modify_eq_delay *eq_delay; | |
12820 | LPFC_MBOXQ_t *mbox; | |
12821 | struct lpfc_queue *eq; | |
12822 | int cnt, rc, length, status = 0; | |
12823 | uint32_t shdr_status, shdr_add_status; | |
ee02006b | 12824 | uint32_t result; |
173edbb2 JS |
12825 | int fcp_eqidx; |
12826 | union lpfc_sli4_cfg_shdr *shdr; | |
12827 | uint16_t dmult; | |
12828 | ||
67d12733 | 12829 | if (startq >= phba->cfg_fcp_io_channel) |
173edbb2 JS |
12830 | return 0; |
12831 | ||
12832 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
12833 | if (!mbox) | |
12834 | return -ENOMEM; | |
12835 | length = (sizeof(struct lpfc_mbx_modify_eq_delay) - | |
12836 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
12837 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
12838 | LPFC_MBOX_OPCODE_MODIFY_EQ_DELAY, | |
12839 | length, LPFC_SLI4_MBX_EMBED); | |
12840 | eq_delay = &mbox->u.mqe.un.eq_delay; | |
12841 | ||
12842 | /* Calculate delay multiper from maximum interrupt per second */ | |
ee02006b JS |
12843 | result = phba->cfg_fcp_imax / phba->cfg_fcp_io_channel; |
12844 | if (result > LPFC_DMULT_CONST) | |
12845 | dmult = 0; | |
12846 | else | |
12847 | dmult = LPFC_DMULT_CONST/result - 1; | |
173edbb2 JS |
12848 | |
12849 | cnt = 0; | |
67d12733 | 12850 | for (fcp_eqidx = startq; fcp_eqidx < phba->cfg_fcp_io_channel; |
173edbb2 | 12851 | fcp_eqidx++) { |
67d12733 | 12852 | eq = phba->sli4_hba.hba_eq[fcp_eqidx]; |
173edbb2 JS |
12853 | if (!eq) |
12854 | continue; | |
12855 | eq_delay->u.request.eq[cnt].eq_id = eq->queue_id; | |
12856 | eq_delay->u.request.eq[cnt].phase = 0; | |
12857 | eq_delay->u.request.eq[cnt].delay_multi = dmult; | |
12858 | cnt++; | |
12859 | if (cnt >= LPFC_MAX_EQ_DELAY) | |
12860 | break; | |
12861 | } | |
12862 | eq_delay->u.request.num_eq = cnt; | |
12863 | ||
12864 | mbox->vport = phba->pport; | |
12865 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
12866 | mbox->context1 = NULL; | |
12867 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
12868 | shdr = (union lpfc_sli4_cfg_shdr *) &eq_delay->header.cfg_shdr; | |
12869 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
12870 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
12871 | if (shdr_status || shdr_add_status || rc) { | |
12872 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
12873 | "2512 MODIFY_EQ_DELAY mailbox failed with " | |
12874 | "status x%x add_status x%x, mbx status x%x\n", | |
12875 | shdr_status, shdr_add_status, rc); | |
12876 | status = -ENXIO; | |
12877 | } | |
12878 | mempool_free(mbox, phba->mbox_mem_pool); | |
12879 | return status; | |
12880 | } | |
12881 | ||
4f774513 JS |
12882 | /** |
12883 | * lpfc_eq_create - Create an Event Queue on the HBA | |
12884 | * @phba: HBA structure that indicates port to create a queue on. | |
12885 | * @eq: The queue structure to use to create the event queue. | |
12886 | * @imax: The maximum interrupt per second limit. | |
12887 | * | |
12888 | * This function creates an event queue, as detailed in @eq, on a port, | |
12889 | * described by @phba by sending an EQ_CREATE mailbox command to the HBA. | |
12890 | * | |
12891 | * The @phba struct is used to send mailbox command to HBA. The @eq struct | |
12892 | * is used to get the entry count and entry size that are necessary to | |
12893 | * determine the number of pages to allocate and use for this queue. This | |
12894 | * function will send the EQ_CREATE mailbox command to the HBA to setup the | |
12895 | * event queue. This function is asynchronous and will wait for the mailbox | |
12896 | * command to finish before continuing. | |
12897 | * | |
12898 | * On success this function will return a zero. If unable to allocate enough | |
d439d286 JS |
12899 | * memory this function will return -ENOMEM. If the queue create mailbox command |
12900 | * fails this function will return -ENXIO. | |
4f774513 JS |
12901 | **/ |
12902 | uint32_t | |
ee02006b | 12903 | lpfc_eq_create(struct lpfc_hba *phba, struct lpfc_queue *eq, uint32_t imax) |
4f774513 JS |
12904 | { |
12905 | struct lpfc_mbx_eq_create *eq_create; | |
12906 | LPFC_MBOXQ_t *mbox; | |
12907 | int rc, length, status = 0; | |
12908 | struct lpfc_dmabuf *dmabuf; | |
12909 | uint32_t shdr_status, shdr_add_status; | |
12910 | union lpfc_sli4_cfg_shdr *shdr; | |
12911 | uint16_t dmult; | |
49198b37 JS |
12912 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
12913 | ||
2e90f4b5 JS |
12914 | /* sanity check on queue memory */ |
12915 | if (!eq) | |
12916 | return -ENODEV; | |
49198b37 JS |
12917 | if (!phba->sli4_hba.pc_sli4_params.supported) |
12918 | hw_page_size = SLI4_PAGE_SIZE; | |
4f774513 JS |
12919 | |
12920 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
12921 | if (!mbox) | |
12922 | return -ENOMEM; | |
12923 | length = (sizeof(struct lpfc_mbx_eq_create) - | |
12924 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
12925 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
12926 | LPFC_MBOX_OPCODE_EQ_CREATE, | |
12927 | length, LPFC_SLI4_MBX_EMBED); | |
12928 | eq_create = &mbox->u.mqe.un.eq_create; | |
12929 | bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request, | |
12930 | eq->page_count); | |
12931 | bf_set(lpfc_eq_context_size, &eq_create->u.request.context, | |
12932 | LPFC_EQE_SIZE); | |
12933 | bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1); | |
12934 | /* Calculate delay multiper from maximum interrupt per second */ | |
ee02006b JS |
12935 | if (imax > LPFC_DMULT_CONST) |
12936 | dmult = 0; | |
12937 | else | |
12938 | dmult = LPFC_DMULT_CONST/imax - 1; | |
4f774513 JS |
12939 | bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context, |
12940 | dmult); | |
12941 | switch (eq->entry_count) { | |
12942 | default: | |
12943 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
12944 | "0360 Unsupported EQ count. (%d)\n", | |
12945 | eq->entry_count); | |
12946 | if (eq->entry_count < 256) | |
12947 | return -EINVAL; | |
12948 | /* otherwise default to smallest count (drop through) */ | |
12949 | case 256: | |
12950 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, | |
12951 | LPFC_EQ_CNT_256); | |
12952 | break; | |
12953 | case 512: | |
12954 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, | |
12955 | LPFC_EQ_CNT_512); | |
12956 | break; | |
12957 | case 1024: | |
12958 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, | |
12959 | LPFC_EQ_CNT_1024); | |
12960 | break; | |
12961 | case 2048: | |
12962 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, | |
12963 | LPFC_EQ_CNT_2048); | |
12964 | break; | |
12965 | case 4096: | |
12966 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, | |
12967 | LPFC_EQ_CNT_4096); | |
12968 | break; | |
12969 | } | |
12970 | list_for_each_entry(dmabuf, &eq->page_list, list) { | |
49198b37 | 12971 | memset(dmabuf->virt, 0, hw_page_size); |
4f774513 JS |
12972 | eq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
12973 | putPaddrLow(dmabuf->phys); | |
12974 | eq_create->u.request.page[dmabuf->buffer_tag].addr_hi = | |
12975 | putPaddrHigh(dmabuf->phys); | |
12976 | } | |
12977 | mbox->vport = phba->pport; | |
12978 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
12979 | mbox->context1 = NULL; | |
12980 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
12981 | shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr; | |
12982 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
12983 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
12984 | if (shdr_status || shdr_add_status || rc) { | |
12985 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
12986 | "2500 EQ_CREATE mailbox failed with " | |
12987 | "status x%x add_status x%x, mbx status x%x\n", | |
12988 | shdr_status, shdr_add_status, rc); | |
12989 | status = -ENXIO; | |
12990 | } | |
12991 | eq->type = LPFC_EQ; | |
12992 | eq->subtype = LPFC_NONE; | |
12993 | eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response); | |
12994 | if (eq->queue_id == 0xFFFF) | |
12995 | status = -ENXIO; | |
12996 | eq->host_index = 0; | |
12997 | eq->hba_index = 0; | |
12998 | ||
8fa38513 | 12999 | mempool_free(mbox, phba->mbox_mem_pool); |
4f774513 JS |
13000 | return status; |
13001 | } | |
13002 | ||
13003 | /** | |
13004 | * lpfc_cq_create - Create a Completion Queue on the HBA | |
13005 | * @phba: HBA structure that indicates port to create a queue on. | |
13006 | * @cq: The queue structure to use to create the completion queue. | |
13007 | * @eq: The event queue to bind this completion queue to. | |
13008 | * | |
13009 | * This function creates a completion queue, as detailed in @wq, on a port, | |
13010 | * described by @phba by sending a CQ_CREATE mailbox command to the HBA. | |
13011 | * | |
13012 | * The @phba struct is used to send mailbox command to HBA. The @cq struct | |
13013 | * is used to get the entry count and entry size that are necessary to | |
13014 | * determine the number of pages to allocate and use for this queue. The @eq | |
13015 | * is used to indicate which event queue to bind this completion queue to. This | |
13016 | * function will send the CQ_CREATE mailbox command to the HBA to setup the | |
13017 | * completion queue. This function is asynchronous and will wait for the mailbox | |
13018 | * command to finish before continuing. | |
13019 | * | |
13020 | * On success this function will return a zero. If unable to allocate enough | |
d439d286 JS |
13021 | * memory this function will return -ENOMEM. If the queue create mailbox command |
13022 | * fails this function will return -ENXIO. | |
4f774513 JS |
13023 | **/ |
13024 | uint32_t | |
13025 | lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq, | |
13026 | struct lpfc_queue *eq, uint32_t type, uint32_t subtype) | |
13027 | { | |
13028 | struct lpfc_mbx_cq_create *cq_create; | |
13029 | struct lpfc_dmabuf *dmabuf; | |
13030 | LPFC_MBOXQ_t *mbox; | |
13031 | int rc, length, status = 0; | |
13032 | uint32_t shdr_status, shdr_add_status; | |
13033 | union lpfc_sli4_cfg_shdr *shdr; | |
49198b37 JS |
13034 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
13035 | ||
2e90f4b5 JS |
13036 | /* sanity check on queue memory */ |
13037 | if (!cq || !eq) | |
13038 | return -ENODEV; | |
49198b37 JS |
13039 | if (!phba->sli4_hba.pc_sli4_params.supported) |
13040 | hw_page_size = SLI4_PAGE_SIZE; | |
13041 | ||
4f774513 JS |
13042 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
13043 | if (!mbox) | |
13044 | return -ENOMEM; | |
13045 | length = (sizeof(struct lpfc_mbx_cq_create) - | |
13046 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
13047 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
13048 | LPFC_MBOX_OPCODE_CQ_CREATE, | |
13049 | length, LPFC_SLI4_MBX_EMBED); | |
13050 | cq_create = &mbox->u.mqe.un.cq_create; | |
5a6f133e | 13051 | shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr; |
4f774513 JS |
13052 | bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request, |
13053 | cq->page_count); | |
13054 | bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1); | |
13055 | bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1); | |
5a6f133e JS |
13056 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
13057 | phba->sli4_hba.pc_sli4_params.cqv); | |
13058 | if (phba->sli4_hba.pc_sli4_params.cqv == LPFC_Q_CREATE_VERSION_2) { | |
c31098ce JS |
13059 | /* FW only supports 1. Should be PAGE_SIZE/SLI4_PAGE_SIZE */ |
13060 | bf_set(lpfc_mbx_cq_create_page_size, &cq_create->u.request, 1); | |
5a6f133e JS |
13061 | bf_set(lpfc_cq_eq_id_2, &cq_create->u.request.context, |
13062 | eq->queue_id); | |
13063 | } else { | |
13064 | bf_set(lpfc_cq_eq_id, &cq_create->u.request.context, | |
13065 | eq->queue_id); | |
13066 | } | |
4f774513 JS |
13067 | switch (cq->entry_count) { |
13068 | default: | |
13069 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
13070 | "0361 Unsupported CQ count. (%d)\n", | |
13071 | cq->entry_count); | |
4f4c1863 JS |
13072 | if (cq->entry_count < 256) { |
13073 | status = -EINVAL; | |
13074 | goto out; | |
13075 | } | |
4f774513 JS |
13076 | /* otherwise default to smallest count (drop through) */ |
13077 | case 256: | |
13078 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, | |
13079 | LPFC_CQ_CNT_256); | |
13080 | break; | |
13081 | case 512: | |
13082 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, | |
13083 | LPFC_CQ_CNT_512); | |
13084 | break; | |
13085 | case 1024: | |
13086 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, | |
13087 | LPFC_CQ_CNT_1024); | |
13088 | break; | |
13089 | } | |
13090 | list_for_each_entry(dmabuf, &cq->page_list, list) { | |
49198b37 | 13091 | memset(dmabuf->virt, 0, hw_page_size); |
4f774513 JS |
13092 | cq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
13093 | putPaddrLow(dmabuf->phys); | |
13094 | cq_create->u.request.page[dmabuf->buffer_tag].addr_hi = | |
13095 | putPaddrHigh(dmabuf->phys); | |
13096 | } | |
13097 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
13098 | ||
13099 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
4f774513 JS |
13100 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
13101 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
13102 | if (shdr_status || shdr_add_status || rc) { | |
13103 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
13104 | "2501 CQ_CREATE mailbox failed with " | |
13105 | "status x%x add_status x%x, mbx status x%x\n", | |
13106 | shdr_status, shdr_add_status, rc); | |
13107 | status = -ENXIO; | |
13108 | goto out; | |
13109 | } | |
13110 | cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response); | |
13111 | if (cq->queue_id == 0xFFFF) { | |
13112 | status = -ENXIO; | |
13113 | goto out; | |
13114 | } | |
13115 | /* link the cq onto the parent eq child list */ | |
13116 | list_add_tail(&cq->list, &eq->child_list); | |
13117 | /* Set up completion queue's type and subtype */ | |
13118 | cq->type = type; | |
13119 | cq->subtype = subtype; | |
13120 | cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response); | |
2a622bfb | 13121 | cq->assoc_qid = eq->queue_id; |
4f774513 JS |
13122 | cq->host_index = 0; |
13123 | cq->hba_index = 0; | |
4f774513 | 13124 | |
8fa38513 JS |
13125 | out: |
13126 | mempool_free(mbox, phba->mbox_mem_pool); | |
4f774513 JS |
13127 | return status; |
13128 | } | |
13129 | ||
b19a061a JS |
13130 | /** |
13131 | * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration | |
13132 | * @phba: HBA structure that indicates port to create a queue on. | |
13133 | * @mq: The queue structure to use to create the mailbox queue. | |
13134 | * @mbox: An allocated pointer to type LPFC_MBOXQ_t | |
13135 | * @cq: The completion queue to associate with this cq. | |
13136 | * | |
13137 | * This function provides failback (fb) functionality when the | |
13138 | * mq_create_ext fails on older FW generations. It's purpose is identical | |
13139 | * to mq_create_ext otherwise. | |
13140 | * | |
13141 | * This routine cannot fail as all attributes were previously accessed and | |
13142 | * initialized in mq_create_ext. | |
13143 | **/ | |
13144 | static void | |
13145 | lpfc_mq_create_fb_init(struct lpfc_hba *phba, struct lpfc_queue *mq, | |
13146 | LPFC_MBOXQ_t *mbox, struct lpfc_queue *cq) | |
13147 | { | |
13148 | struct lpfc_mbx_mq_create *mq_create; | |
13149 | struct lpfc_dmabuf *dmabuf; | |
13150 | int length; | |
13151 | ||
13152 | length = (sizeof(struct lpfc_mbx_mq_create) - | |
13153 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
13154 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
13155 | LPFC_MBOX_OPCODE_MQ_CREATE, | |
13156 | length, LPFC_SLI4_MBX_EMBED); | |
13157 | mq_create = &mbox->u.mqe.un.mq_create; | |
13158 | bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request, | |
13159 | mq->page_count); | |
13160 | bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context, | |
13161 | cq->queue_id); | |
13162 | bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1); | |
13163 | switch (mq->entry_count) { | |
13164 | case 16: | |
5a6f133e JS |
13165 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
13166 | LPFC_MQ_RING_SIZE_16); | |
b19a061a JS |
13167 | break; |
13168 | case 32: | |
5a6f133e JS |
13169 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
13170 | LPFC_MQ_RING_SIZE_32); | |
b19a061a JS |
13171 | break; |
13172 | case 64: | |
5a6f133e JS |
13173 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
13174 | LPFC_MQ_RING_SIZE_64); | |
b19a061a JS |
13175 | break; |
13176 | case 128: | |
5a6f133e JS |
13177 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
13178 | LPFC_MQ_RING_SIZE_128); | |
b19a061a JS |
13179 | break; |
13180 | } | |
13181 | list_for_each_entry(dmabuf, &mq->page_list, list) { | |
13182 | mq_create->u.request.page[dmabuf->buffer_tag].addr_lo = | |
13183 | putPaddrLow(dmabuf->phys); | |
13184 | mq_create->u.request.page[dmabuf->buffer_tag].addr_hi = | |
13185 | putPaddrHigh(dmabuf->phys); | |
13186 | } | |
13187 | } | |
13188 | ||
04c68496 JS |
13189 | /** |
13190 | * lpfc_mq_create - Create a mailbox Queue on the HBA | |
13191 | * @phba: HBA structure that indicates port to create a queue on. | |
13192 | * @mq: The queue structure to use to create the mailbox queue. | |
b19a061a JS |
13193 | * @cq: The completion queue to associate with this cq. |
13194 | * @subtype: The queue's subtype. | |
04c68496 JS |
13195 | * |
13196 | * This function creates a mailbox queue, as detailed in @mq, on a port, | |
13197 | * described by @phba by sending a MQ_CREATE mailbox command to the HBA. | |
13198 | * | |
13199 | * The @phba struct is used to send mailbox command to HBA. The @cq struct | |
13200 | * is used to get the entry count and entry size that are necessary to | |
13201 | * determine the number of pages to allocate and use for this queue. This | |
13202 | * function will send the MQ_CREATE mailbox command to the HBA to setup the | |
13203 | * mailbox queue. This function is asynchronous and will wait for the mailbox | |
13204 | * command to finish before continuing. | |
13205 | * | |
13206 | * On success this function will return a zero. If unable to allocate enough | |
d439d286 JS |
13207 | * memory this function will return -ENOMEM. If the queue create mailbox command |
13208 | * fails this function will return -ENXIO. | |
04c68496 | 13209 | **/ |
b19a061a | 13210 | int32_t |
04c68496 JS |
13211 | lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq, |
13212 | struct lpfc_queue *cq, uint32_t subtype) | |
13213 | { | |
13214 | struct lpfc_mbx_mq_create *mq_create; | |
b19a061a | 13215 | struct lpfc_mbx_mq_create_ext *mq_create_ext; |
04c68496 JS |
13216 | struct lpfc_dmabuf *dmabuf; |
13217 | LPFC_MBOXQ_t *mbox; | |
13218 | int rc, length, status = 0; | |
13219 | uint32_t shdr_status, shdr_add_status; | |
13220 | union lpfc_sli4_cfg_shdr *shdr; | |
49198b37 | 13221 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
04c68496 | 13222 | |
2e90f4b5 JS |
13223 | /* sanity check on queue memory */ |
13224 | if (!mq || !cq) | |
13225 | return -ENODEV; | |
49198b37 JS |
13226 | if (!phba->sli4_hba.pc_sli4_params.supported) |
13227 | hw_page_size = SLI4_PAGE_SIZE; | |
b19a061a | 13228 | |
04c68496 JS |
13229 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
13230 | if (!mbox) | |
13231 | return -ENOMEM; | |
b19a061a | 13232 | length = (sizeof(struct lpfc_mbx_mq_create_ext) - |
04c68496 JS |
13233 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
13234 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
b19a061a | 13235 | LPFC_MBOX_OPCODE_MQ_CREATE_EXT, |
04c68496 | 13236 | length, LPFC_SLI4_MBX_EMBED); |
b19a061a JS |
13237 | |
13238 | mq_create_ext = &mbox->u.mqe.un.mq_create_ext; | |
5a6f133e | 13239 | shdr = (union lpfc_sli4_cfg_shdr *) &mq_create_ext->header.cfg_shdr; |
70f3c073 JS |
13240 | bf_set(lpfc_mbx_mq_create_ext_num_pages, |
13241 | &mq_create_ext->u.request, mq->page_count); | |
13242 | bf_set(lpfc_mbx_mq_create_ext_async_evt_link, | |
13243 | &mq_create_ext->u.request, 1); | |
13244 | bf_set(lpfc_mbx_mq_create_ext_async_evt_fip, | |
b19a061a JS |
13245 | &mq_create_ext->u.request, 1); |
13246 | bf_set(lpfc_mbx_mq_create_ext_async_evt_group5, | |
13247 | &mq_create_ext->u.request, 1); | |
70f3c073 JS |
13248 | bf_set(lpfc_mbx_mq_create_ext_async_evt_fc, |
13249 | &mq_create_ext->u.request, 1); | |
13250 | bf_set(lpfc_mbx_mq_create_ext_async_evt_sli, | |
13251 | &mq_create_ext->u.request, 1); | |
b19a061a | 13252 | bf_set(lpfc_mq_context_valid, &mq_create_ext->u.request.context, 1); |
5a6f133e JS |
13253 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
13254 | phba->sli4_hba.pc_sli4_params.mqv); | |
13255 | if (phba->sli4_hba.pc_sli4_params.mqv == LPFC_Q_CREATE_VERSION_1) | |
13256 | bf_set(lpfc_mbx_mq_create_ext_cq_id, &mq_create_ext->u.request, | |
13257 | cq->queue_id); | |
13258 | else | |
13259 | bf_set(lpfc_mq_context_cq_id, &mq_create_ext->u.request.context, | |
13260 | cq->queue_id); | |
04c68496 JS |
13261 | switch (mq->entry_count) { |
13262 | default: | |
13263 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
13264 | "0362 Unsupported MQ count. (%d)\n", | |
13265 | mq->entry_count); | |
4f4c1863 JS |
13266 | if (mq->entry_count < 16) { |
13267 | status = -EINVAL; | |
13268 | goto out; | |
13269 | } | |
04c68496 JS |
13270 | /* otherwise default to smallest count (drop through) */ |
13271 | case 16: | |
5a6f133e JS |
13272 | bf_set(lpfc_mq_context_ring_size, |
13273 | &mq_create_ext->u.request.context, | |
13274 | LPFC_MQ_RING_SIZE_16); | |
04c68496 JS |
13275 | break; |
13276 | case 32: | |
5a6f133e JS |
13277 | bf_set(lpfc_mq_context_ring_size, |
13278 | &mq_create_ext->u.request.context, | |
13279 | LPFC_MQ_RING_SIZE_32); | |
04c68496 JS |
13280 | break; |
13281 | case 64: | |
5a6f133e JS |
13282 | bf_set(lpfc_mq_context_ring_size, |
13283 | &mq_create_ext->u.request.context, | |
13284 | LPFC_MQ_RING_SIZE_64); | |
04c68496 JS |
13285 | break; |
13286 | case 128: | |
5a6f133e JS |
13287 | bf_set(lpfc_mq_context_ring_size, |
13288 | &mq_create_ext->u.request.context, | |
13289 | LPFC_MQ_RING_SIZE_128); | |
04c68496 JS |
13290 | break; |
13291 | } | |
13292 | list_for_each_entry(dmabuf, &mq->page_list, list) { | |
49198b37 | 13293 | memset(dmabuf->virt, 0, hw_page_size); |
b19a061a | 13294 | mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_lo = |
04c68496 | 13295 | putPaddrLow(dmabuf->phys); |
b19a061a | 13296 | mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_hi = |
04c68496 JS |
13297 | putPaddrHigh(dmabuf->phys); |
13298 | } | |
13299 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
b19a061a JS |
13300 | mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, |
13301 | &mq_create_ext->u.response); | |
13302 | if (rc != MBX_SUCCESS) { | |
13303 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
13304 | "2795 MQ_CREATE_EXT failed with " | |
13305 | "status x%x. Failback to MQ_CREATE.\n", | |
13306 | rc); | |
13307 | lpfc_mq_create_fb_init(phba, mq, mbox, cq); | |
13308 | mq_create = &mbox->u.mqe.un.mq_create; | |
13309 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
13310 | shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr; | |
13311 | mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, | |
13312 | &mq_create->u.response); | |
13313 | } | |
13314 | ||
04c68496 | 13315 | /* The IOCTL status is embedded in the mailbox subheader. */ |
04c68496 JS |
13316 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
13317 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
13318 | if (shdr_status || shdr_add_status || rc) { | |
13319 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
13320 | "2502 MQ_CREATE mailbox failed with " | |
13321 | "status x%x add_status x%x, mbx status x%x\n", | |
13322 | shdr_status, shdr_add_status, rc); | |
13323 | status = -ENXIO; | |
13324 | goto out; | |
13325 | } | |
04c68496 JS |
13326 | if (mq->queue_id == 0xFFFF) { |
13327 | status = -ENXIO; | |
13328 | goto out; | |
13329 | } | |
13330 | mq->type = LPFC_MQ; | |
2a622bfb | 13331 | mq->assoc_qid = cq->queue_id; |
04c68496 JS |
13332 | mq->subtype = subtype; |
13333 | mq->host_index = 0; | |
13334 | mq->hba_index = 0; | |
13335 | ||
13336 | /* link the mq onto the parent cq child list */ | |
13337 | list_add_tail(&mq->list, &cq->child_list); | |
13338 | out: | |
8fa38513 | 13339 | mempool_free(mbox, phba->mbox_mem_pool); |
04c68496 JS |
13340 | return status; |
13341 | } | |
13342 | ||
4f774513 JS |
13343 | /** |
13344 | * lpfc_wq_create - Create a Work Queue on the HBA | |
13345 | * @phba: HBA structure that indicates port to create a queue on. | |
13346 | * @wq: The queue structure to use to create the work queue. | |
13347 | * @cq: The completion queue to bind this work queue to. | |
13348 | * @subtype: The subtype of the work queue indicating its functionality. | |
13349 | * | |
13350 | * This function creates a work queue, as detailed in @wq, on a port, described | |
13351 | * by @phba by sending a WQ_CREATE mailbox command to the HBA. | |
13352 | * | |
13353 | * The @phba struct is used to send mailbox command to HBA. The @wq struct | |
13354 | * is used to get the entry count and entry size that are necessary to | |
13355 | * determine the number of pages to allocate and use for this queue. The @cq | |
13356 | * is used to indicate which completion queue to bind this work queue to. This | |
13357 | * function will send the WQ_CREATE mailbox command to the HBA to setup the | |
13358 | * work queue. This function is asynchronous and will wait for the mailbox | |
13359 | * command to finish before continuing. | |
13360 | * | |
13361 | * On success this function will return a zero. If unable to allocate enough | |
d439d286 JS |
13362 | * memory this function will return -ENOMEM. If the queue create mailbox command |
13363 | * fails this function will return -ENXIO. | |
4f774513 JS |
13364 | **/ |
13365 | uint32_t | |
13366 | lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq, | |
13367 | struct lpfc_queue *cq, uint32_t subtype) | |
13368 | { | |
13369 | struct lpfc_mbx_wq_create *wq_create; | |
13370 | struct lpfc_dmabuf *dmabuf; | |
13371 | LPFC_MBOXQ_t *mbox; | |
13372 | int rc, length, status = 0; | |
13373 | uint32_t shdr_status, shdr_add_status; | |
13374 | union lpfc_sli4_cfg_shdr *shdr; | |
49198b37 | 13375 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
5a6f133e | 13376 | struct dma_address *page; |
962bc51b JS |
13377 | void __iomem *bar_memmap_p; |
13378 | uint32_t db_offset; | |
13379 | uint16_t pci_barset; | |
49198b37 | 13380 | |
2e90f4b5 JS |
13381 | /* sanity check on queue memory */ |
13382 | if (!wq || !cq) | |
13383 | return -ENODEV; | |
49198b37 JS |
13384 | if (!phba->sli4_hba.pc_sli4_params.supported) |
13385 | hw_page_size = SLI4_PAGE_SIZE; | |
4f774513 JS |
13386 | |
13387 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
13388 | if (!mbox) | |
13389 | return -ENOMEM; | |
13390 | length = (sizeof(struct lpfc_mbx_wq_create) - | |
13391 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
13392 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
13393 | LPFC_MBOX_OPCODE_FCOE_WQ_CREATE, | |
13394 | length, LPFC_SLI4_MBX_EMBED); | |
13395 | wq_create = &mbox->u.mqe.un.wq_create; | |
5a6f133e | 13396 | shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr; |
4f774513 JS |
13397 | bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request, |
13398 | wq->page_count); | |
13399 | bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request, | |
13400 | cq->queue_id); | |
0c651878 JS |
13401 | |
13402 | /* wqv is the earliest version supported, NOT the latest */ | |
5a6f133e JS |
13403 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
13404 | phba->sli4_hba.pc_sli4_params.wqv); | |
962bc51b | 13405 | |
0c651878 JS |
13406 | switch (phba->sli4_hba.pc_sli4_params.wqv) { |
13407 | case LPFC_Q_CREATE_VERSION_0: | |
13408 | switch (wq->entry_size) { | |
13409 | default: | |
13410 | case 64: | |
13411 | /* Nothing to do, version 0 ONLY supports 64 byte */ | |
13412 | page = wq_create->u.request.page; | |
13413 | break; | |
13414 | case 128: | |
13415 | if (!(phba->sli4_hba.pc_sli4_params.wqsize & | |
13416 | LPFC_WQ_SZ128_SUPPORT)) { | |
13417 | status = -ERANGE; | |
13418 | goto out; | |
13419 | } | |
13420 | /* If we get here the HBA MUST also support V1 and | |
13421 | * we MUST use it | |
13422 | */ | |
13423 | bf_set(lpfc_mbox_hdr_version, &shdr->request, | |
13424 | LPFC_Q_CREATE_VERSION_1); | |
13425 | ||
13426 | bf_set(lpfc_mbx_wq_create_wqe_count, | |
13427 | &wq_create->u.request_1, wq->entry_count); | |
13428 | bf_set(lpfc_mbx_wq_create_wqe_size, | |
13429 | &wq_create->u.request_1, | |
13430 | LPFC_WQ_WQE_SIZE_128); | |
13431 | bf_set(lpfc_mbx_wq_create_page_size, | |
13432 | &wq_create->u.request_1, | |
13433 | (PAGE_SIZE/SLI4_PAGE_SIZE)); | |
13434 | page = wq_create->u.request_1.page; | |
13435 | break; | |
13436 | } | |
13437 | break; | |
13438 | case LPFC_Q_CREATE_VERSION_1: | |
5a6f133e JS |
13439 | bf_set(lpfc_mbx_wq_create_wqe_count, &wq_create->u.request_1, |
13440 | wq->entry_count); | |
13441 | switch (wq->entry_size) { | |
13442 | default: | |
13443 | case 64: | |
13444 | bf_set(lpfc_mbx_wq_create_wqe_size, | |
13445 | &wq_create->u.request_1, | |
13446 | LPFC_WQ_WQE_SIZE_64); | |
13447 | break; | |
13448 | case 128: | |
0c651878 JS |
13449 | if (!(phba->sli4_hba.pc_sli4_params.wqsize & |
13450 | LPFC_WQ_SZ128_SUPPORT)) { | |
13451 | status = -ERANGE; | |
13452 | goto out; | |
13453 | } | |
5a6f133e JS |
13454 | bf_set(lpfc_mbx_wq_create_wqe_size, |
13455 | &wq_create->u.request_1, | |
13456 | LPFC_WQ_WQE_SIZE_128); | |
13457 | break; | |
13458 | } | |
13459 | bf_set(lpfc_mbx_wq_create_page_size, &wq_create->u.request_1, | |
13460 | (PAGE_SIZE/SLI4_PAGE_SIZE)); | |
13461 | page = wq_create->u.request_1.page; | |
0c651878 JS |
13462 | break; |
13463 | default: | |
13464 | status = -ERANGE; | |
13465 | goto out; | |
5a6f133e | 13466 | } |
0c651878 | 13467 | |
4f774513 | 13468 | list_for_each_entry(dmabuf, &wq->page_list, list) { |
49198b37 | 13469 | memset(dmabuf->virt, 0, hw_page_size); |
5a6f133e JS |
13470 | page[dmabuf->buffer_tag].addr_lo = putPaddrLow(dmabuf->phys); |
13471 | page[dmabuf->buffer_tag].addr_hi = putPaddrHigh(dmabuf->phys); | |
4f774513 | 13472 | } |
962bc51b JS |
13473 | |
13474 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) | |
13475 | bf_set(lpfc_mbx_wq_create_dua, &wq_create->u.request, 1); | |
13476 | ||
4f774513 JS |
13477 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
13478 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
4f774513 JS |
13479 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
13480 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
13481 | if (shdr_status || shdr_add_status || rc) { | |
13482 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
13483 | "2503 WQ_CREATE mailbox failed with " | |
13484 | "status x%x add_status x%x, mbx status x%x\n", | |
13485 | shdr_status, shdr_add_status, rc); | |
13486 | status = -ENXIO; | |
13487 | goto out; | |
13488 | } | |
13489 | wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, &wq_create->u.response); | |
13490 | if (wq->queue_id == 0xFFFF) { | |
13491 | status = -ENXIO; | |
13492 | goto out; | |
13493 | } | |
962bc51b JS |
13494 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) { |
13495 | wq->db_format = bf_get(lpfc_mbx_wq_create_db_format, | |
13496 | &wq_create->u.response); | |
13497 | if ((wq->db_format != LPFC_DB_LIST_FORMAT) && | |
13498 | (wq->db_format != LPFC_DB_RING_FORMAT)) { | |
13499 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
13500 | "3265 WQ[%d] doorbell format not " | |
13501 | "supported: x%x\n", wq->queue_id, | |
13502 | wq->db_format); | |
13503 | status = -EINVAL; | |
13504 | goto out; | |
13505 | } | |
13506 | pci_barset = bf_get(lpfc_mbx_wq_create_bar_set, | |
13507 | &wq_create->u.response); | |
13508 | bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, pci_barset); | |
13509 | if (!bar_memmap_p) { | |
13510 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
13511 | "3263 WQ[%d] failed to memmap pci " | |
13512 | "barset:x%x\n", wq->queue_id, | |
13513 | pci_barset); | |
13514 | status = -ENOMEM; | |
13515 | goto out; | |
13516 | } | |
13517 | db_offset = wq_create->u.response.doorbell_offset; | |
13518 | if ((db_offset != LPFC_ULP0_WQ_DOORBELL) && | |
13519 | (db_offset != LPFC_ULP1_WQ_DOORBELL)) { | |
13520 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
13521 | "3252 WQ[%d] doorbell offset not " | |
13522 | "supported: x%x\n", wq->queue_id, | |
13523 | db_offset); | |
13524 | status = -EINVAL; | |
13525 | goto out; | |
13526 | } | |
13527 | wq->db_regaddr = bar_memmap_p + db_offset; | |
13528 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
a22e7db3 JS |
13529 | "3264 WQ[%d]: barset:x%x, offset:x%x, " |
13530 | "format:x%x\n", wq->queue_id, pci_barset, | |
13531 | db_offset, wq->db_format); | |
962bc51b JS |
13532 | } else { |
13533 | wq->db_format = LPFC_DB_LIST_FORMAT; | |
13534 | wq->db_regaddr = phba->sli4_hba.WQDBregaddr; | |
13535 | } | |
4f774513 | 13536 | wq->type = LPFC_WQ; |
2a622bfb | 13537 | wq->assoc_qid = cq->queue_id; |
4f774513 JS |
13538 | wq->subtype = subtype; |
13539 | wq->host_index = 0; | |
13540 | wq->hba_index = 0; | |
ff78d8f9 | 13541 | wq->entry_repost = LPFC_RELEASE_NOTIFICATION_INTERVAL; |
4f774513 JS |
13542 | |
13543 | /* link the wq onto the parent cq child list */ | |
13544 | list_add_tail(&wq->list, &cq->child_list); | |
13545 | out: | |
8fa38513 | 13546 | mempool_free(mbox, phba->mbox_mem_pool); |
4f774513 JS |
13547 | return status; |
13548 | } | |
13549 | ||
73d91e50 JS |
13550 | /** |
13551 | * lpfc_rq_adjust_repost - Adjust entry_repost for an RQ | |
13552 | * @phba: HBA structure that indicates port to create a queue on. | |
13553 | * @rq: The queue structure to use for the receive queue. | |
13554 | * @qno: The associated HBQ number | |
13555 | * | |
13556 | * | |
13557 | * For SLI4 we need to adjust the RQ repost value based on | |
13558 | * the number of buffers that are initially posted to the RQ. | |
13559 | */ | |
13560 | void | |
13561 | lpfc_rq_adjust_repost(struct lpfc_hba *phba, struct lpfc_queue *rq, int qno) | |
13562 | { | |
13563 | uint32_t cnt; | |
13564 | ||
2e90f4b5 JS |
13565 | /* sanity check on queue memory */ |
13566 | if (!rq) | |
13567 | return; | |
73d91e50 JS |
13568 | cnt = lpfc_hbq_defs[qno]->entry_count; |
13569 | ||
13570 | /* Recalc repost for RQs based on buffers initially posted */ | |
13571 | cnt = (cnt >> 3); | |
13572 | if (cnt < LPFC_QUEUE_MIN_REPOST) | |
13573 | cnt = LPFC_QUEUE_MIN_REPOST; | |
13574 | ||
13575 | rq->entry_repost = cnt; | |
13576 | } | |
13577 | ||
4f774513 JS |
13578 | /** |
13579 | * lpfc_rq_create - Create a Receive Queue on the HBA | |
13580 | * @phba: HBA structure that indicates port to create a queue on. | |
13581 | * @hrq: The queue structure to use to create the header receive queue. | |
13582 | * @drq: The queue structure to use to create the data receive queue. | |
13583 | * @cq: The completion queue to bind this work queue to. | |
13584 | * | |
13585 | * This function creates a receive buffer queue pair , as detailed in @hrq and | |
13586 | * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command | |
13587 | * to the HBA. | |
13588 | * | |
13589 | * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq | |
13590 | * struct is used to get the entry count that is necessary to determine the | |
13591 | * number of pages to use for this queue. The @cq is used to indicate which | |
13592 | * completion queue to bind received buffers that are posted to these queues to. | |
13593 | * This function will send the RQ_CREATE mailbox command to the HBA to setup the | |
13594 | * receive queue pair. This function is asynchronous and will wait for the | |
13595 | * mailbox command to finish before continuing. | |
13596 | * | |
13597 | * On success this function will return a zero. If unable to allocate enough | |
d439d286 JS |
13598 | * memory this function will return -ENOMEM. If the queue create mailbox command |
13599 | * fails this function will return -ENXIO. | |
4f774513 JS |
13600 | **/ |
13601 | uint32_t | |
13602 | lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq, | |
13603 | struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype) | |
13604 | { | |
13605 | struct lpfc_mbx_rq_create *rq_create; | |
13606 | struct lpfc_dmabuf *dmabuf; | |
13607 | LPFC_MBOXQ_t *mbox; | |
13608 | int rc, length, status = 0; | |
13609 | uint32_t shdr_status, shdr_add_status; | |
13610 | union lpfc_sli4_cfg_shdr *shdr; | |
49198b37 | 13611 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
962bc51b JS |
13612 | void __iomem *bar_memmap_p; |
13613 | uint32_t db_offset; | |
13614 | uint16_t pci_barset; | |
49198b37 | 13615 | |
2e90f4b5 JS |
13616 | /* sanity check on queue memory */ |
13617 | if (!hrq || !drq || !cq) | |
13618 | return -ENODEV; | |
49198b37 JS |
13619 | if (!phba->sli4_hba.pc_sli4_params.supported) |
13620 | hw_page_size = SLI4_PAGE_SIZE; | |
4f774513 JS |
13621 | |
13622 | if (hrq->entry_count != drq->entry_count) | |
13623 | return -EINVAL; | |
13624 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
13625 | if (!mbox) | |
13626 | return -ENOMEM; | |
13627 | length = (sizeof(struct lpfc_mbx_rq_create) - | |
13628 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
13629 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
13630 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, | |
13631 | length, LPFC_SLI4_MBX_EMBED); | |
13632 | rq_create = &mbox->u.mqe.un.rq_create; | |
5a6f133e JS |
13633 | shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr; |
13634 | bf_set(lpfc_mbox_hdr_version, &shdr->request, | |
13635 | phba->sli4_hba.pc_sli4_params.rqv); | |
13636 | if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) { | |
13637 | bf_set(lpfc_rq_context_rqe_count_1, | |
13638 | &rq_create->u.request.context, | |
13639 | hrq->entry_count); | |
13640 | rq_create->u.request.context.buffer_size = LPFC_HDR_BUF_SIZE; | |
c31098ce JS |
13641 | bf_set(lpfc_rq_context_rqe_size, |
13642 | &rq_create->u.request.context, | |
13643 | LPFC_RQE_SIZE_8); | |
13644 | bf_set(lpfc_rq_context_page_size, | |
13645 | &rq_create->u.request.context, | |
13646 | (PAGE_SIZE/SLI4_PAGE_SIZE)); | |
5a6f133e JS |
13647 | } else { |
13648 | switch (hrq->entry_count) { | |
13649 | default: | |
13650 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
13651 | "2535 Unsupported RQ count. (%d)\n", | |
13652 | hrq->entry_count); | |
4f4c1863 JS |
13653 | if (hrq->entry_count < 512) { |
13654 | status = -EINVAL; | |
13655 | goto out; | |
13656 | } | |
5a6f133e JS |
13657 | /* otherwise default to smallest count (drop through) */ |
13658 | case 512: | |
13659 | bf_set(lpfc_rq_context_rqe_count, | |
13660 | &rq_create->u.request.context, | |
13661 | LPFC_RQ_RING_SIZE_512); | |
13662 | break; | |
13663 | case 1024: | |
13664 | bf_set(lpfc_rq_context_rqe_count, | |
13665 | &rq_create->u.request.context, | |
13666 | LPFC_RQ_RING_SIZE_1024); | |
13667 | break; | |
13668 | case 2048: | |
13669 | bf_set(lpfc_rq_context_rqe_count, | |
13670 | &rq_create->u.request.context, | |
13671 | LPFC_RQ_RING_SIZE_2048); | |
13672 | break; | |
13673 | case 4096: | |
13674 | bf_set(lpfc_rq_context_rqe_count, | |
13675 | &rq_create->u.request.context, | |
13676 | LPFC_RQ_RING_SIZE_4096); | |
13677 | break; | |
13678 | } | |
13679 | bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context, | |
13680 | LPFC_HDR_BUF_SIZE); | |
4f774513 JS |
13681 | } |
13682 | bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context, | |
13683 | cq->queue_id); | |
13684 | bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request, | |
13685 | hrq->page_count); | |
4f774513 | 13686 | list_for_each_entry(dmabuf, &hrq->page_list, list) { |
49198b37 | 13687 | memset(dmabuf->virt, 0, hw_page_size); |
4f774513 JS |
13688 | rq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
13689 | putPaddrLow(dmabuf->phys); | |
13690 | rq_create->u.request.page[dmabuf->buffer_tag].addr_hi = | |
13691 | putPaddrHigh(dmabuf->phys); | |
13692 | } | |
962bc51b JS |
13693 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) |
13694 | bf_set(lpfc_mbx_rq_create_dua, &rq_create->u.request, 1); | |
13695 | ||
4f774513 JS |
13696 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
13697 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
4f774513 JS |
13698 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
13699 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
13700 | if (shdr_status || shdr_add_status || rc) { | |
13701 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
13702 | "2504 RQ_CREATE mailbox failed with " | |
13703 | "status x%x add_status x%x, mbx status x%x\n", | |
13704 | shdr_status, shdr_add_status, rc); | |
13705 | status = -ENXIO; | |
13706 | goto out; | |
13707 | } | |
13708 | hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); | |
13709 | if (hrq->queue_id == 0xFFFF) { | |
13710 | status = -ENXIO; | |
13711 | goto out; | |
13712 | } | |
962bc51b JS |
13713 | |
13714 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) { | |
13715 | hrq->db_format = bf_get(lpfc_mbx_rq_create_db_format, | |
13716 | &rq_create->u.response); | |
13717 | if ((hrq->db_format != LPFC_DB_LIST_FORMAT) && | |
13718 | (hrq->db_format != LPFC_DB_RING_FORMAT)) { | |
13719 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
13720 | "3262 RQ [%d] doorbell format not " | |
13721 | "supported: x%x\n", hrq->queue_id, | |
13722 | hrq->db_format); | |
13723 | status = -EINVAL; | |
13724 | goto out; | |
13725 | } | |
13726 | ||
13727 | pci_barset = bf_get(lpfc_mbx_rq_create_bar_set, | |
13728 | &rq_create->u.response); | |
13729 | bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, pci_barset); | |
13730 | if (!bar_memmap_p) { | |
13731 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
13732 | "3269 RQ[%d] failed to memmap pci " | |
13733 | "barset:x%x\n", hrq->queue_id, | |
13734 | pci_barset); | |
13735 | status = -ENOMEM; | |
13736 | goto out; | |
13737 | } | |
13738 | ||
13739 | db_offset = rq_create->u.response.doorbell_offset; | |
13740 | if ((db_offset != LPFC_ULP0_RQ_DOORBELL) && | |
13741 | (db_offset != LPFC_ULP1_RQ_DOORBELL)) { | |
13742 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
13743 | "3270 RQ[%d] doorbell offset not " | |
13744 | "supported: x%x\n", hrq->queue_id, | |
13745 | db_offset); | |
13746 | status = -EINVAL; | |
13747 | goto out; | |
13748 | } | |
13749 | hrq->db_regaddr = bar_memmap_p + db_offset; | |
13750 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
a22e7db3 JS |
13751 | "3266 RQ[qid:%d]: barset:x%x, offset:x%x, " |
13752 | "format:x%x\n", hrq->queue_id, pci_barset, | |
13753 | db_offset, hrq->db_format); | |
962bc51b JS |
13754 | } else { |
13755 | hrq->db_format = LPFC_DB_RING_FORMAT; | |
13756 | hrq->db_regaddr = phba->sli4_hba.RQDBregaddr; | |
13757 | } | |
4f774513 | 13758 | hrq->type = LPFC_HRQ; |
2a622bfb | 13759 | hrq->assoc_qid = cq->queue_id; |
4f774513 JS |
13760 | hrq->subtype = subtype; |
13761 | hrq->host_index = 0; | |
13762 | hrq->hba_index = 0; | |
13763 | ||
13764 | /* now create the data queue */ | |
13765 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
13766 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, | |
13767 | length, LPFC_SLI4_MBX_EMBED); | |
5a6f133e JS |
13768 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
13769 | phba->sli4_hba.pc_sli4_params.rqv); | |
13770 | if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) { | |
13771 | bf_set(lpfc_rq_context_rqe_count_1, | |
c31098ce | 13772 | &rq_create->u.request.context, hrq->entry_count); |
5a6f133e | 13773 | rq_create->u.request.context.buffer_size = LPFC_DATA_BUF_SIZE; |
c31098ce JS |
13774 | bf_set(lpfc_rq_context_rqe_size, &rq_create->u.request.context, |
13775 | LPFC_RQE_SIZE_8); | |
13776 | bf_set(lpfc_rq_context_page_size, &rq_create->u.request.context, | |
13777 | (PAGE_SIZE/SLI4_PAGE_SIZE)); | |
5a6f133e JS |
13778 | } else { |
13779 | switch (drq->entry_count) { | |
13780 | default: | |
13781 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
13782 | "2536 Unsupported RQ count. (%d)\n", | |
13783 | drq->entry_count); | |
4f4c1863 JS |
13784 | if (drq->entry_count < 512) { |
13785 | status = -EINVAL; | |
13786 | goto out; | |
13787 | } | |
5a6f133e JS |
13788 | /* otherwise default to smallest count (drop through) */ |
13789 | case 512: | |
13790 | bf_set(lpfc_rq_context_rqe_count, | |
13791 | &rq_create->u.request.context, | |
13792 | LPFC_RQ_RING_SIZE_512); | |
13793 | break; | |
13794 | case 1024: | |
13795 | bf_set(lpfc_rq_context_rqe_count, | |
13796 | &rq_create->u.request.context, | |
13797 | LPFC_RQ_RING_SIZE_1024); | |
13798 | break; | |
13799 | case 2048: | |
13800 | bf_set(lpfc_rq_context_rqe_count, | |
13801 | &rq_create->u.request.context, | |
13802 | LPFC_RQ_RING_SIZE_2048); | |
13803 | break; | |
13804 | case 4096: | |
13805 | bf_set(lpfc_rq_context_rqe_count, | |
13806 | &rq_create->u.request.context, | |
13807 | LPFC_RQ_RING_SIZE_4096); | |
13808 | break; | |
13809 | } | |
13810 | bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context, | |
13811 | LPFC_DATA_BUF_SIZE); | |
4f774513 JS |
13812 | } |
13813 | bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context, | |
13814 | cq->queue_id); | |
13815 | bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request, | |
13816 | drq->page_count); | |
4f774513 JS |
13817 | list_for_each_entry(dmabuf, &drq->page_list, list) { |
13818 | rq_create->u.request.page[dmabuf->buffer_tag].addr_lo = | |
13819 | putPaddrLow(dmabuf->phys); | |
13820 | rq_create->u.request.page[dmabuf->buffer_tag].addr_hi = | |
13821 | putPaddrHigh(dmabuf->phys); | |
13822 | } | |
962bc51b JS |
13823 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) |
13824 | bf_set(lpfc_mbx_rq_create_dua, &rq_create->u.request, 1); | |
4f774513 JS |
13825 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
13826 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
13827 | shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr; | |
13828 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
13829 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
13830 | if (shdr_status || shdr_add_status || rc) { | |
13831 | status = -ENXIO; | |
13832 | goto out; | |
13833 | } | |
13834 | drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); | |
13835 | if (drq->queue_id == 0xFFFF) { | |
13836 | status = -ENXIO; | |
13837 | goto out; | |
13838 | } | |
13839 | drq->type = LPFC_DRQ; | |
2a622bfb | 13840 | drq->assoc_qid = cq->queue_id; |
4f774513 JS |
13841 | drq->subtype = subtype; |
13842 | drq->host_index = 0; | |
13843 | drq->hba_index = 0; | |
13844 | ||
13845 | /* link the header and data RQs onto the parent cq child list */ | |
13846 | list_add_tail(&hrq->list, &cq->child_list); | |
13847 | list_add_tail(&drq->list, &cq->child_list); | |
13848 | ||
13849 | out: | |
8fa38513 | 13850 | mempool_free(mbox, phba->mbox_mem_pool); |
4f774513 JS |
13851 | return status; |
13852 | } | |
13853 | ||
13854 | /** | |
13855 | * lpfc_eq_destroy - Destroy an event Queue on the HBA | |
13856 | * @eq: The queue structure associated with the queue to destroy. | |
13857 | * | |
13858 | * This function destroys a queue, as detailed in @eq by sending an mailbox | |
13859 | * command, specific to the type of queue, to the HBA. | |
13860 | * | |
13861 | * The @eq struct is used to get the queue ID of the queue to destroy. | |
13862 | * | |
13863 | * On success this function will return a zero. If the queue destroy mailbox | |
d439d286 | 13864 | * command fails this function will return -ENXIO. |
4f774513 JS |
13865 | **/ |
13866 | uint32_t | |
13867 | lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq) | |
13868 | { | |
13869 | LPFC_MBOXQ_t *mbox; | |
13870 | int rc, length, status = 0; | |
13871 | uint32_t shdr_status, shdr_add_status; | |
13872 | union lpfc_sli4_cfg_shdr *shdr; | |
13873 | ||
2e90f4b5 | 13874 | /* sanity check on queue memory */ |
4f774513 JS |
13875 | if (!eq) |
13876 | return -ENODEV; | |
13877 | mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL); | |
13878 | if (!mbox) | |
13879 | return -ENOMEM; | |
13880 | length = (sizeof(struct lpfc_mbx_eq_destroy) - | |
13881 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
13882 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
13883 | LPFC_MBOX_OPCODE_EQ_DESTROY, | |
13884 | length, LPFC_SLI4_MBX_EMBED); | |
13885 | bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request, | |
13886 | eq->queue_id); | |
13887 | mbox->vport = eq->phba->pport; | |
13888 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
13889 | ||
13890 | rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL); | |
13891 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
13892 | shdr = (union lpfc_sli4_cfg_shdr *) | |
13893 | &mbox->u.mqe.un.eq_destroy.header.cfg_shdr; | |
13894 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
13895 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
13896 | if (shdr_status || shdr_add_status || rc) { | |
13897 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
13898 | "2505 EQ_DESTROY mailbox failed with " | |
13899 | "status x%x add_status x%x, mbx status x%x\n", | |
13900 | shdr_status, shdr_add_status, rc); | |
13901 | status = -ENXIO; | |
13902 | } | |
13903 | ||
13904 | /* Remove eq from any list */ | |
13905 | list_del_init(&eq->list); | |
8fa38513 | 13906 | mempool_free(mbox, eq->phba->mbox_mem_pool); |
4f774513 JS |
13907 | return status; |
13908 | } | |
13909 | ||
13910 | /** | |
13911 | * lpfc_cq_destroy - Destroy a Completion Queue on the HBA | |
13912 | * @cq: The queue structure associated with the queue to destroy. | |
13913 | * | |
13914 | * This function destroys a queue, as detailed in @cq by sending an mailbox | |
13915 | * command, specific to the type of queue, to the HBA. | |
13916 | * | |
13917 | * The @cq struct is used to get the queue ID of the queue to destroy. | |
13918 | * | |
13919 | * On success this function will return a zero. If the queue destroy mailbox | |
d439d286 | 13920 | * command fails this function will return -ENXIO. |
4f774513 JS |
13921 | **/ |
13922 | uint32_t | |
13923 | lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq) | |
13924 | { | |
13925 | LPFC_MBOXQ_t *mbox; | |
13926 | int rc, length, status = 0; | |
13927 | uint32_t shdr_status, shdr_add_status; | |
13928 | union lpfc_sli4_cfg_shdr *shdr; | |
13929 | ||
2e90f4b5 | 13930 | /* sanity check on queue memory */ |
4f774513 JS |
13931 | if (!cq) |
13932 | return -ENODEV; | |
13933 | mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL); | |
13934 | if (!mbox) | |
13935 | return -ENOMEM; | |
13936 | length = (sizeof(struct lpfc_mbx_cq_destroy) - | |
13937 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
13938 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
13939 | LPFC_MBOX_OPCODE_CQ_DESTROY, | |
13940 | length, LPFC_SLI4_MBX_EMBED); | |
13941 | bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request, | |
13942 | cq->queue_id); | |
13943 | mbox->vport = cq->phba->pport; | |
13944 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
13945 | rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL); | |
13946 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
13947 | shdr = (union lpfc_sli4_cfg_shdr *) | |
13948 | &mbox->u.mqe.un.wq_create.header.cfg_shdr; | |
13949 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
13950 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
13951 | if (shdr_status || shdr_add_status || rc) { | |
13952 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
13953 | "2506 CQ_DESTROY mailbox failed with " | |
13954 | "status x%x add_status x%x, mbx status x%x\n", | |
13955 | shdr_status, shdr_add_status, rc); | |
13956 | status = -ENXIO; | |
13957 | } | |
13958 | /* Remove cq from any list */ | |
13959 | list_del_init(&cq->list); | |
8fa38513 | 13960 | mempool_free(mbox, cq->phba->mbox_mem_pool); |
4f774513 JS |
13961 | return status; |
13962 | } | |
13963 | ||
04c68496 JS |
13964 | /** |
13965 | * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA | |
13966 | * @qm: The queue structure associated with the queue to destroy. | |
13967 | * | |
13968 | * This function destroys a queue, as detailed in @mq by sending an mailbox | |
13969 | * command, specific to the type of queue, to the HBA. | |
13970 | * | |
13971 | * The @mq struct is used to get the queue ID of the queue to destroy. | |
13972 | * | |
13973 | * On success this function will return a zero. If the queue destroy mailbox | |
d439d286 | 13974 | * command fails this function will return -ENXIO. |
04c68496 JS |
13975 | **/ |
13976 | uint32_t | |
13977 | lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq) | |
13978 | { | |
13979 | LPFC_MBOXQ_t *mbox; | |
13980 | int rc, length, status = 0; | |
13981 | uint32_t shdr_status, shdr_add_status; | |
13982 | union lpfc_sli4_cfg_shdr *shdr; | |
13983 | ||
2e90f4b5 | 13984 | /* sanity check on queue memory */ |
04c68496 JS |
13985 | if (!mq) |
13986 | return -ENODEV; | |
13987 | mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL); | |
13988 | if (!mbox) | |
13989 | return -ENOMEM; | |
13990 | length = (sizeof(struct lpfc_mbx_mq_destroy) - | |
13991 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
13992 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
13993 | LPFC_MBOX_OPCODE_MQ_DESTROY, | |
13994 | length, LPFC_SLI4_MBX_EMBED); | |
13995 | bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request, | |
13996 | mq->queue_id); | |
13997 | mbox->vport = mq->phba->pport; | |
13998 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
13999 | rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL); | |
14000 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
14001 | shdr = (union lpfc_sli4_cfg_shdr *) | |
14002 | &mbox->u.mqe.un.mq_destroy.header.cfg_shdr; | |
14003 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
14004 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
14005 | if (shdr_status || shdr_add_status || rc) { | |
14006 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
14007 | "2507 MQ_DESTROY mailbox failed with " | |
14008 | "status x%x add_status x%x, mbx status x%x\n", | |
14009 | shdr_status, shdr_add_status, rc); | |
14010 | status = -ENXIO; | |
14011 | } | |
14012 | /* Remove mq from any list */ | |
14013 | list_del_init(&mq->list); | |
8fa38513 | 14014 | mempool_free(mbox, mq->phba->mbox_mem_pool); |
04c68496 JS |
14015 | return status; |
14016 | } | |
14017 | ||
4f774513 JS |
14018 | /** |
14019 | * lpfc_wq_destroy - Destroy a Work Queue on the HBA | |
14020 | * @wq: The queue structure associated with the queue to destroy. | |
14021 | * | |
14022 | * This function destroys a queue, as detailed in @wq by sending an mailbox | |
14023 | * command, specific to the type of queue, to the HBA. | |
14024 | * | |
14025 | * The @wq struct is used to get the queue ID of the queue to destroy. | |
14026 | * | |
14027 | * On success this function will return a zero. If the queue destroy mailbox | |
d439d286 | 14028 | * command fails this function will return -ENXIO. |
4f774513 JS |
14029 | **/ |
14030 | uint32_t | |
14031 | lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq) | |
14032 | { | |
14033 | LPFC_MBOXQ_t *mbox; | |
14034 | int rc, length, status = 0; | |
14035 | uint32_t shdr_status, shdr_add_status; | |
14036 | union lpfc_sli4_cfg_shdr *shdr; | |
14037 | ||
2e90f4b5 | 14038 | /* sanity check on queue memory */ |
4f774513 JS |
14039 | if (!wq) |
14040 | return -ENODEV; | |
14041 | mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL); | |
14042 | if (!mbox) | |
14043 | return -ENOMEM; | |
14044 | length = (sizeof(struct lpfc_mbx_wq_destroy) - | |
14045 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
14046 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
14047 | LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY, | |
14048 | length, LPFC_SLI4_MBX_EMBED); | |
14049 | bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request, | |
14050 | wq->queue_id); | |
14051 | mbox->vport = wq->phba->pport; | |
14052 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
14053 | rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL); | |
14054 | shdr = (union lpfc_sli4_cfg_shdr *) | |
14055 | &mbox->u.mqe.un.wq_destroy.header.cfg_shdr; | |
14056 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
14057 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
14058 | if (shdr_status || shdr_add_status || rc) { | |
14059 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
14060 | "2508 WQ_DESTROY mailbox failed with " | |
14061 | "status x%x add_status x%x, mbx status x%x\n", | |
14062 | shdr_status, shdr_add_status, rc); | |
14063 | status = -ENXIO; | |
14064 | } | |
14065 | /* Remove wq from any list */ | |
14066 | list_del_init(&wq->list); | |
8fa38513 | 14067 | mempool_free(mbox, wq->phba->mbox_mem_pool); |
4f774513 JS |
14068 | return status; |
14069 | } | |
14070 | ||
14071 | /** | |
14072 | * lpfc_rq_destroy - Destroy a Receive Queue on the HBA | |
14073 | * @rq: The queue structure associated with the queue to destroy. | |
14074 | * | |
14075 | * This function destroys a queue, as detailed in @rq by sending an mailbox | |
14076 | * command, specific to the type of queue, to the HBA. | |
14077 | * | |
14078 | * The @rq struct is used to get the queue ID of the queue to destroy. | |
14079 | * | |
14080 | * On success this function will return a zero. If the queue destroy mailbox | |
d439d286 | 14081 | * command fails this function will return -ENXIO. |
4f774513 JS |
14082 | **/ |
14083 | uint32_t | |
14084 | lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq, | |
14085 | struct lpfc_queue *drq) | |
14086 | { | |
14087 | LPFC_MBOXQ_t *mbox; | |
14088 | int rc, length, status = 0; | |
14089 | uint32_t shdr_status, shdr_add_status; | |
14090 | union lpfc_sli4_cfg_shdr *shdr; | |
14091 | ||
2e90f4b5 | 14092 | /* sanity check on queue memory */ |
4f774513 JS |
14093 | if (!hrq || !drq) |
14094 | return -ENODEV; | |
14095 | mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL); | |
14096 | if (!mbox) | |
14097 | return -ENOMEM; | |
14098 | length = (sizeof(struct lpfc_mbx_rq_destroy) - | |
fedd3b7b | 14099 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
4f774513 JS |
14100 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
14101 | LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY, | |
14102 | length, LPFC_SLI4_MBX_EMBED); | |
14103 | bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request, | |
14104 | hrq->queue_id); | |
14105 | mbox->vport = hrq->phba->pport; | |
14106 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
14107 | rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL); | |
14108 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
14109 | shdr = (union lpfc_sli4_cfg_shdr *) | |
14110 | &mbox->u.mqe.un.rq_destroy.header.cfg_shdr; | |
14111 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
14112 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
14113 | if (shdr_status || shdr_add_status || rc) { | |
14114 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
14115 | "2509 RQ_DESTROY mailbox failed with " | |
14116 | "status x%x add_status x%x, mbx status x%x\n", | |
14117 | shdr_status, shdr_add_status, rc); | |
14118 | if (rc != MBX_TIMEOUT) | |
14119 | mempool_free(mbox, hrq->phba->mbox_mem_pool); | |
14120 | return -ENXIO; | |
14121 | } | |
14122 | bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request, | |
14123 | drq->queue_id); | |
14124 | rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL); | |
14125 | shdr = (union lpfc_sli4_cfg_shdr *) | |
14126 | &mbox->u.mqe.un.rq_destroy.header.cfg_shdr; | |
14127 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
14128 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
14129 | if (shdr_status || shdr_add_status || rc) { | |
14130 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
14131 | "2510 RQ_DESTROY mailbox failed with " | |
14132 | "status x%x add_status x%x, mbx status x%x\n", | |
14133 | shdr_status, shdr_add_status, rc); | |
14134 | status = -ENXIO; | |
14135 | } | |
14136 | list_del_init(&hrq->list); | |
14137 | list_del_init(&drq->list); | |
8fa38513 | 14138 | mempool_free(mbox, hrq->phba->mbox_mem_pool); |
4f774513 JS |
14139 | return status; |
14140 | } | |
14141 | ||
14142 | /** | |
14143 | * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA | |
14144 | * @phba: The virtual port for which this call being executed. | |
14145 | * @pdma_phys_addr0: Physical address of the 1st SGL page. | |
14146 | * @pdma_phys_addr1: Physical address of the 2nd SGL page. | |
14147 | * @xritag: the xritag that ties this io to the SGL pages. | |
14148 | * | |
14149 | * This routine will post the sgl pages for the IO that has the xritag | |
14150 | * that is in the iocbq structure. The xritag is assigned during iocbq | |
14151 | * creation and persists for as long as the driver is loaded. | |
14152 | * if the caller has fewer than 256 scatter gather segments to map then | |
14153 | * pdma_phys_addr1 should be 0. | |
14154 | * If the caller needs to map more than 256 scatter gather segment then | |
14155 | * pdma_phys_addr1 should be a valid physical address. | |
14156 | * physical address for SGLs must be 64 byte aligned. | |
14157 | * If you are going to map 2 SGL's then the first one must have 256 entries | |
14158 | * the second sgl can have between 1 and 256 entries. | |
14159 | * | |
14160 | * Return codes: | |
14161 | * 0 - Success | |
14162 | * -ENXIO, -ENOMEM - Failure | |
14163 | **/ | |
14164 | int | |
14165 | lpfc_sli4_post_sgl(struct lpfc_hba *phba, | |
14166 | dma_addr_t pdma_phys_addr0, | |
14167 | dma_addr_t pdma_phys_addr1, | |
14168 | uint16_t xritag) | |
14169 | { | |
14170 | struct lpfc_mbx_post_sgl_pages *post_sgl_pages; | |
14171 | LPFC_MBOXQ_t *mbox; | |
14172 | int rc; | |
14173 | uint32_t shdr_status, shdr_add_status; | |
6d368e53 | 14174 | uint32_t mbox_tmo; |
4f774513 JS |
14175 | union lpfc_sli4_cfg_shdr *shdr; |
14176 | ||
14177 | if (xritag == NO_XRI) { | |
14178 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
14179 | "0364 Invalid param:\n"); | |
14180 | return -EINVAL; | |
14181 | } | |
14182 | ||
14183 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
14184 | if (!mbox) | |
14185 | return -ENOMEM; | |
14186 | ||
14187 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
14188 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, | |
14189 | sizeof(struct lpfc_mbx_post_sgl_pages) - | |
fedd3b7b | 14190 | sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED); |
4f774513 JS |
14191 | |
14192 | post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *) | |
14193 | &mbox->u.mqe.un.post_sgl_pages; | |
14194 | bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag); | |
14195 | bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1); | |
14196 | ||
14197 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo = | |
14198 | cpu_to_le32(putPaddrLow(pdma_phys_addr0)); | |
14199 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi = | |
14200 | cpu_to_le32(putPaddrHigh(pdma_phys_addr0)); | |
14201 | ||
14202 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo = | |
14203 | cpu_to_le32(putPaddrLow(pdma_phys_addr1)); | |
14204 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi = | |
14205 | cpu_to_le32(putPaddrHigh(pdma_phys_addr1)); | |
14206 | if (!phba->sli4_hba.intr_enable) | |
14207 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
6d368e53 | 14208 | else { |
a183a15f | 14209 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
6d368e53 JS |
14210 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
14211 | } | |
4f774513 JS |
14212 | /* The IOCTL status is embedded in the mailbox subheader. */ |
14213 | shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr; | |
14214 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
14215 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
14216 | if (rc != MBX_TIMEOUT) | |
14217 | mempool_free(mbox, phba->mbox_mem_pool); | |
14218 | if (shdr_status || shdr_add_status || rc) { | |
14219 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
14220 | "2511 POST_SGL mailbox failed with " | |
14221 | "status x%x add_status x%x, mbx status x%x\n", | |
14222 | shdr_status, shdr_add_status, rc); | |
14223 | rc = -ENXIO; | |
14224 | } | |
14225 | return 0; | |
14226 | } | |
4f774513 | 14227 | |
6d368e53 | 14228 | /** |
88a2cfbb | 14229 | * lpfc_sli4_alloc_xri - Get an available rpi in the device's range |
6d368e53 JS |
14230 | * @phba: pointer to lpfc hba data structure. |
14231 | * | |
14232 | * This routine is invoked to post rpi header templates to the | |
88a2cfbb JS |
14233 | * HBA consistent with the SLI-4 interface spec. This routine |
14234 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to | |
14235 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. | |
6d368e53 | 14236 | * |
88a2cfbb JS |
14237 | * Returns |
14238 | * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful | |
14239 | * LPFC_RPI_ALLOC_ERROR if no rpis are available. | |
14240 | **/ | |
5d8b8167 | 14241 | static uint16_t |
6d368e53 JS |
14242 | lpfc_sli4_alloc_xri(struct lpfc_hba *phba) |
14243 | { | |
14244 | unsigned long xri; | |
14245 | ||
14246 | /* | |
14247 | * Fetch the next logical xri. Because this index is logical, | |
14248 | * the driver starts at 0 each time. | |
14249 | */ | |
14250 | spin_lock_irq(&phba->hbalock); | |
14251 | xri = find_next_zero_bit(phba->sli4_hba.xri_bmask, | |
14252 | phba->sli4_hba.max_cfg_param.max_xri, 0); | |
14253 | if (xri >= phba->sli4_hba.max_cfg_param.max_xri) { | |
14254 | spin_unlock_irq(&phba->hbalock); | |
14255 | return NO_XRI; | |
14256 | } else { | |
14257 | set_bit(xri, phba->sli4_hba.xri_bmask); | |
14258 | phba->sli4_hba.max_cfg_param.xri_used++; | |
6d368e53 | 14259 | } |
6d368e53 JS |
14260 | spin_unlock_irq(&phba->hbalock); |
14261 | return xri; | |
14262 | } | |
14263 | ||
14264 | /** | |
14265 | * lpfc_sli4_free_xri - Release an xri for reuse. | |
14266 | * @phba: pointer to lpfc hba data structure. | |
14267 | * | |
14268 | * This routine is invoked to release an xri to the pool of | |
14269 | * available rpis maintained by the driver. | |
14270 | **/ | |
5d8b8167 | 14271 | static void |
6d368e53 JS |
14272 | __lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri) |
14273 | { | |
14274 | if (test_and_clear_bit(xri, phba->sli4_hba.xri_bmask)) { | |
6d368e53 JS |
14275 | phba->sli4_hba.max_cfg_param.xri_used--; |
14276 | } | |
14277 | } | |
14278 | ||
14279 | /** | |
14280 | * lpfc_sli4_free_xri - Release an xri for reuse. | |
14281 | * @phba: pointer to lpfc hba data structure. | |
14282 | * | |
14283 | * This routine is invoked to release an xri to the pool of | |
14284 | * available rpis maintained by the driver. | |
14285 | **/ | |
14286 | void | |
14287 | lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri) | |
14288 | { | |
14289 | spin_lock_irq(&phba->hbalock); | |
14290 | __lpfc_sli4_free_xri(phba, xri); | |
14291 | spin_unlock_irq(&phba->hbalock); | |
14292 | } | |
14293 | ||
4f774513 JS |
14294 | /** |
14295 | * lpfc_sli4_next_xritag - Get an xritag for the io | |
14296 | * @phba: Pointer to HBA context object. | |
14297 | * | |
14298 | * This function gets an xritag for the iocb. If there is no unused xritag | |
14299 | * it will return 0xffff. | |
14300 | * The function returns the allocated xritag if successful, else returns zero. | |
14301 | * Zero is not a valid xritag. | |
14302 | * The caller is not required to hold any lock. | |
14303 | **/ | |
14304 | uint16_t | |
14305 | lpfc_sli4_next_xritag(struct lpfc_hba *phba) | |
14306 | { | |
6d368e53 | 14307 | uint16_t xri_index; |
4f774513 | 14308 | |
6d368e53 | 14309 | xri_index = lpfc_sli4_alloc_xri(phba); |
81378052 JS |
14310 | if (xri_index == NO_XRI) |
14311 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
14312 | "2004 Failed to allocate XRI.last XRITAG is %d" | |
14313 | " Max XRI is %d, Used XRI is %d\n", | |
14314 | xri_index, | |
14315 | phba->sli4_hba.max_cfg_param.max_xri, | |
14316 | phba->sli4_hba.max_cfg_param.xri_used); | |
14317 | return xri_index; | |
4f774513 JS |
14318 | } |
14319 | ||
14320 | /** | |
6d368e53 | 14321 | * lpfc_sli4_post_els_sgl_list - post a block of ELS sgls to the port. |
4f774513 | 14322 | * @phba: pointer to lpfc hba data structure. |
8a9d2e80 JS |
14323 | * @post_sgl_list: pointer to els sgl entry list. |
14324 | * @count: number of els sgl entries on the list. | |
4f774513 JS |
14325 | * |
14326 | * This routine is invoked to post a block of driver's sgl pages to the | |
14327 | * HBA using non-embedded mailbox command. No Lock is held. This routine | |
14328 | * is only called when the driver is loading and after all IO has been | |
14329 | * stopped. | |
14330 | **/ | |
8a9d2e80 JS |
14331 | static int |
14332 | lpfc_sli4_post_els_sgl_list(struct lpfc_hba *phba, | |
14333 | struct list_head *post_sgl_list, | |
14334 | int post_cnt) | |
4f774513 | 14335 | { |
8a9d2e80 | 14336 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
4f774513 JS |
14337 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; |
14338 | struct sgl_page_pairs *sgl_pg_pairs; | |
14339 | void *viraddr; | |
14340 | LPFC_MBOXQ_t *mbox; | |
14341 | uint32_t reqlen, alloclen, pg_pairs; | |
14342 | uint32_t mbox_tmo; | |
8a9d2e80 JS |
14343 | uint16_t xritag_start = 0; |
14344 | int rc = 0; | |
4f774513 JS |
14345 | uint32_t shdr_status, shdr_add_status; |
14346 | union lpfc_sli4_cfg_shdr *shdr; | |
14347 | ||
8a9d2e80 | 14348 | reqlen = phba->sli4_hba.els_xri_cnt * sizeof(struct sgl_page_pairs) + |
4f774513 | 14349 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); |
49198b37 | 14350 | if (reqlen > SLI4_PAGE_SIZE) { |
4f774513 JS |
14351 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
14352 | "2559 Block sgl registration required DMA " | |
14353 | "size (%d) great than a page\n", reqlen); | |
14354 | return -ENOMEM; | |
14355 | } | |
14356 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
6d368e53 | 14357 | if (!mbox) |
4f774513 | 14358 | return -ENOMEM; |
4f774513 JS |
14359 | |
14360 | /* Allocate DMA memory and set up the non-embedded mailbox command */ | |
14361 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
14362 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen, | |
14363 | LPFC_SLI4_MBX_NEMBED); | |
14364 | ||
14365 | if (alloclen < reqlen) { | |
14366 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
14367 | "0285 Allocated DMA memory size (%d) is " | |
14368 | "less than the requested DMA memory " | |
14369 | "size (%d)\n", alloclen, reqlen); | |
14370 | lpfc_sli4_mbox_cmd_free(phba, mbox); | |
14371 | return -ENOMEM; | |
14372 | } | |
4f774513 | 14373 | /* Set up the SGL pages in the non-embedded DMA pages */ |
6d368e53 | 14374 | viraddr = mbox->sge_array->addr[0]; |
4f774513 JS |
14375 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; |
14376 | sgl_pg_pairs = &sgl->sgl_pg_pairs; | |
14377 | ||
8a9d2e80 JS |
14378 | pg_pairs = 0; |
14379 | list_for_each_entry_safe(sglq_entry, sglq_next, post_sgl_list, list) { | |
4f774513 JS |
14380 | /* Set up the sge entry */ |
14381 | sgl_pg_pairs->sgl_pg0_addr_lo = | |
14382 | cpu_to_le32(putPaddrLow(sglq_entry->phys)); | |
14383 | sgl_pg_pairs->sgl_pg0_addr_hi = | |
14384 | cpu_to_le32(putPaddrHigh(sglq_entry->phys)); | |
14385 | sgl_pg_pairs->sgl_pg1_addr_lo = | |
14386 | cpu_to_le32(putPaddrLow(0)); | |
14387 | sgl_pg_pairs->sgl_pg1_addr_hi = | |
14388 | cpu_to_le32(putPaddrHigh(0)); | |
6d368e53 | 14389 | |
4f774513 JS |
14390 | /* Keep the first xritag on the list */ |
14391 | if (pg_pairs == 0) | |
14392 | xritag_start = sglq_entry->sli4_xritag; | |
14393 | sgl_pg_pairs++; | |
8a9d2e80 | 14394 | pg_pairs++; |
4f774513 | 14395 | } |
6d368e53 JS |
14396 | |
14397 | /* Complete initialization and perform endian conversion. */ | |
4f774513 | 14398 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); |
8a9d2e80 | 14399 | bf_set(lpfc_post_sgl_pages_xricnt, sgl, phba->sli4_hba.els_xri_cnt); |
4f774513 | 14400 | sgl->word0 = cpu_to_le32(sgl->word0); |
4f774513 JS |
14401 | if (!phba->sli4_hba.intr_enable) |
14402 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
14403 | else { | |
a183a15f | 14404 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
4f774513 JS |
14405 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
14406 | } | |
14407 | shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr; | |
14408 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
14409 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
14410 | if (rc != MBX_TIMEOUT) | |
14411 | lpfc_sli4_mbox_cmd_free(phba, mbox); | |
14412 | if (shdr_status || shdr_add_status || rc) { | |
14413 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
14414 | "2513 POST_SGL_BLOCK mailbox command failed " | |
14415 | "status x%x add_status x%x mbx status x%x\n", | |
14416 | shdr_status, shdr_add_status, rc); | |
14417 | rc = -ENXIO; | |
14418 | } | |
14419 | return rc; | |
14420 | } | |
14421 | ||
14422 | /** | |
14423 | * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware | |
14424 | * @phba: pointer to lpfc hba data structure. | |
14425 | * @sblist: pointer to scsi buffer list. | |
14426 | * @count: number of scsi buffers on the list. | |
14427 | * | |
14428 | * This routine is invoked to post a block of @count scsi sgl pages from a | |
14429 | * SCSI buffer list @sblist to the HBA using non-embedded mailbox command. | |
14430 | * No Lock is held. | |
14431 | * | |
14432 | **/ | |
14433 | int | |
8a9d2e80 JS |
14434 | lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba, |
14435 | struct list_head *sblist, | |
14436 | int count) | |
4f774513 JS |
14437 | { |
14438 | struct lpfc_scsi_buf *psb; | |
14439 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; | |
14440 | struct sgl_page_pairs *sgl_pg_pairs; | |
14441 | void *viraddr; | |
14442 | LPFC_MBOXQ_t *mbox; | |
14443 | uint32_t reqlen, alloclen, pg_pairs; | |
14444 | uint32_t mbox_tmo; | |
14445 | uint16_t xritag_start = 0; | |
14446 | int rc = 0; | |
14447 | uint32_t shdr_status, shdr_add_status; | |
14448 | dma_addr_t pdma_phys_bpl1; | |
14449 | union lpfc_sli4_cfg_shdr *shdr; | |
14450 | ||
14451 | /* Calculate the requested length of the dma memory */ | |
8a9d2e80 | 14452 | reqlen = count * sizeof(struct sgl_page_pairs) + |
4f774513 | 14453 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); |
49198b37 | 14454 | if (reqlen > SLI4_PAGE_SIZE) { |
4f774513 JS |
14455 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
14456 | "0217 Block sgl registration required DMA " | |
14457 | "size (%d) great than a page\n", reqlen); | |
14458 | return -ENOMEM; | |
14459 | } | |
14460 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
14461 | if (!mbox) { | |
14462 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
14463 | "0283 Failed to allocate mbox cmd memory\n"); | |
14464 | return -ENOMEM; | |
14465 | } | |
14466 | ||
14467 | /* Allocate DMA memory and set up the non-embedded mailbox command */ | |
14468 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
14469 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen, | |
14470 | LPFC_SLI4_MBX_NEMBED); | |
14471 | ||
14472 | if (alloclen < reqlen) { | |
14473 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
14474 | "2561 Allocated DMA memory size (%d) is " | |
14475 | "less than the requested DMA memory " | |
14476 | "size (%d)\n", alloclen, reqlen); | |
14477 | lpfc_sli4_mbox_cmd_free(phba, mbox); | |
14478 | return -ENOMEM; | |
14479 | } | |
6d368e53 | 14480 | |
4f774513 | 14481 | /* Get the first SGE entry from the non-embedded DMA memory */ |
4f774513 JS |
14482 | viraddr = mbox->sge_array->addr[0]; |
14483 | ||
14484 | /* Set up the SGL pages in the non-embedded DMA pages */ | |
14485 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; | |
14486 | sgl_pg_pairs = &sgl->sgl_pg_pairs; | |
14487 | ||
14488 | pg_pairs = 0; | |
14489 | list_for_each_entry(psb, sblist, list) { | |
14490 | /* Set up the sge entry */ | |
14491 | sgl_pg_pairs->sgl_pg0_addr_lo = | |
14492 | cpu_to_le32(putPaddrLow(psb->dma_phys_bpl)); | |
14493 | sgl_pg_pairs->sgl_pg0_addr_hi = | |
14494 | cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl)); | |
14495 | if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE) | |
14496 | pdma_phys_bpl1 = psb->dma_phys_bpl + SGL_PAGE_SIZE; | |
14497 | else | |
14498 | pdma_phys_bpl1 = 0; | |
14499 | sgl_pg_pairs->sgl_pg1_addr_lo = | |
14500 | cpu_to_le32(putPaddrLow(pdma_phys_bpl1)); | |
14501 | sgl_pg_pairs->sgl_pg1_addr_hi = | |
14502 | cpu_to_le32(putPaddrHigh(pdma_phys_bpl1)); | |
14503 | /* Keep the first xritag on the list */ | |
14504 | if (pg_pairs == 0) | |
14505 | xritag_start = psb->cur_iocbq.sli4_xritag; | |
14506 | sgl_pg_pairs++; | |
14507 | pg_pairs++; | |
14508 | } | |
14509 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); | |
14510 | bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs); | |
14511 | /* Perform endian conversion if necessary */ | |
14512 | sgl->word0 = cpu_to_le32(sgl->word0); | |
14513 | ||
14514 | if (!phba->sli4_hba.intr_enable) | |
14515 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
14516 | else { | |
a183a15f | 14517 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
4f774513 JS |
14518 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
14519 | } | |
14520 | shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr; | |
14521 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
14522 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
14523 | if (rc != MBX_TIMEOUT) | |
14524 | lpfc_sli4_mbox_cmd_free(phba, mbox); | |
14525 | if (shdr_status || shdr_add_status || rc) { | |
14526 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
14527 | "2564 POST_SGL_BLOCK mailbox command failed " | |
14528 | "status x%x add_status x%x mbx status x%x\n", | |
14529 | shdr_status, shdr_add_status, rc); | |
14530 | rc = -ENXIO; | |
14531 | } | |
14532 | return rc; | |
14533 | } | |
14534 | ||
14535 | /** | |
14536 | * lpfc_fc_frame_check - Check that this frame is a valid frame to handle | |
14537 | * @phba: pointer to lpfc_hba struct that the frame was received on | |
14538 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) | |
14539 | * | |
14540 | * This function checks the fields in the @fc_hdr to see if the FC frame is a | |
14541 | * valid type of frame that the LPFC driver will handle. This function will | |
14542 | * return a zero if the frame is a valid frame or a non zero value when the | |
14543 | * frame does not pass the check. | |
14544 | **/ | |
14545 | static int | |
14546 | lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr) | |
14547 | { | |
474ffb74 TH |
14548 | /* make rctl_names static to save stack space */ |
14549 | static char *rctl_names[] = FC_RCTL_NAMES_INIT; | |
4f774513 JS |
14550 | char *type_names[] = FC_TYPE_NAMES_INIT; |
14551 | struct fc_vft_header *fc_vft_hdr; | |
546fc854 | 14552 | uint32_t *header = (uint32_t *) fc_hdr; |
4f774513 JS |
14553 | |
14554 | switch (fc_hdr->fh_r_ctl) { | |
14555 | case FC_RCTL_DD_UNCAT: /* uncategorized information */ | |
14556 | case FC_RCTL_DD_SOL_DATA: /* solicited data */ | |
14557 | case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */ | |
14558 | case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */ | |
14559 | case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */ | |
14560 | case FC_RCTL_DD_DATA_DESC: /* data descriptor */ | |
14561 | case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */ | |
14562 | case FC_RCTL_DD_CMD_STATUS: /* command status */ | |
14563 | case FC_RCTL_ELS_REQ: /* extended link services request */ | |
14564 | case FC_RCTL_ELS_REP: /* extended link services reply */ | |
14565 | case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */ | |
14566 | case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */ | |
14567 | case FC_RCTL_BA_NOP: /* basic link service NOP */ | |
14568 | case FC_RCTL_BA_ABTS: /* basic link service abort */ | |
14569 | case FC_RCTL_BA_RMC: /* remove connection */ | |
14570 | case FC_RCTL_BA_ACC: /* basic accept */ | |
14571 | case FC_RCTL_BA_RJT: /* basic reject */ | |
14572 | case FC_RCTL_BA_PRMT: | |
14573 | case FC_RCTL_ACK_1: /* acknowledge_1 */ | |
14574 | case FC_RCTL_ACK_0: /* acknowledge_0 */ | |
14575 | case FC_RCTL_P_RJT: /* port reject */ | |
14576 | case FC_RCTL_F_RJT: /* fabric reject */ | |
14577 | case FC_RCTL_P_BSY: /* port busy */ | |
14578 | case FC_RCTL_F_BSY: /* fabric busy to data frame */ | |
14579 | case FC_RCTL_F_BSYL: /* fabric busy to link control frame */ | |
14580 | case FC_RCTL_LCR: /* link credit reset */ | |
14581 | case FC_RCTL_END: /* end */ | |
14582 | break; | |
14583 | case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */ | |
14584 | fc_vft_hdr = (struct fc_vft_header *)fc_hdr; | |
14585 | fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1]; | |
14586 | return lpfc_fc_frame_check(phba, fc_hdr); | |
14587 | default: | |
14588 | goto drop; | |
14589 | } | |
14590 | switch (fc_hdr->fh_type) { | |
14591 | case FC_TYPE_BLS: | |
14592 | case FC_TYPE_ELS: | |
14593 | case FC_TYPE_FCP: | |
14594 | case FC_TYPE_CT: | |
14595 | break; | |
14596 | case FC_TYPE_IP: | |
14597 | case FC_TYPE_ILS: | |
14598 | default: | |
14599 | goto drop; | |
14600 | } | |
546fc854 | 14601 | |
4f774513 | 14602 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
88f43a08 JS |
14603 | "2538 Received frame rctl:%s (x%x), type:%s (x%x), " |
14604 | "frame Data:%08x %08x %08x %08x %08x %08x %08x\n", | |
14605 | rctl_names[fc_hdr->fh_r_ctl], fc_hdr->fh_r_ctl, | |
14606 | type_names[fc_hdr->fh_type], fc_hdr->fh_type, | |
546fc854 JS |
14607 | be32_to_cpu(header[0]), be32_to_cpu(header[1]), |
14608 | be32_to_cpu(header[2]), be32_to_cpu(header[3]), | |
88f43a08 JS |
14609 | be32_to_cpu(header[4]), be32_to_cpu(header[5]), |
14610 | be32_to_cpu(header[6])); | |
4f774513 JS |
14611 | return 0; |
14612 | drop: | |
14613 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS, | |
14614 | "2539 Dropped frame rctl:%s type:%s\n", | |
14615 | rctl_names[fc_hdr->fh_r_ctl], | |
14616 | type_names[fc_hdr->fh_type]); | |
14617 | return 1; | |
14618 | } | |
14619 | ||
14620 | /** | |
14621 | * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame | |
14622 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) | |
14623 | * | |
14624 | * This function processes the FC header to retrieve the VFI from the VF | |
14625 | * header, if one exists. This function will return the VFI if one exists | |
14626 | * or 0 if no VSAN Header exists. | |
14627 | **/ | |
14628 | static uint32_t | |
14629 | lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr) | |
14630 | { | |
14631 | struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr; | |
14632 | ||
14633 | if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH) | |
14634 | return 0; | |
14635 | return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr); | |
14636 | } | |
14637 | ||
14638 | /** | |
14639 | * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to | |
14640 | * @phba: Pointer to the HBA structure to search for the vport on | |
14641 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) | |
14642 | * @fcfi: The FC Fabric ID that the frame came from | |
14643 | * | |
14644 | * This function searches the @phba for a vport that matches the content of the | |
14645 | * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the | |
14646 | * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function | |
14647 | * returns the matching vport pointer or NULL if unable to match frame to a | |
14648 | * vport. | |
14649 | **/ | |
14650 | static struct lpfc_vport * | |
14651 | lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr, | |
14652 | uint16_t fcfi) | |
14653 | { | |
14654 | struct lpfc_vport **vports; | |
14655 | struct lpfc_vport *vport = NULL; | |
14656 | int i; | |
14657 | uint32_t did = (fc_hdr->fh_d_id[0] << 16 | | |
14658 | fc_hdr->fh_d_id[1] << 8 | | |
14659 | fc_hdr->fh_d_id[2]); | |
939723a4 | 14660 | |
bf08611b JS |
14661 | if (did == Fabric_DID) |
14662 | return phba->pport; | |
939723a4 JS |
14663 | if ((phba->pport->fc_flag & FC_PT2PT) && |
14664 | !(phba->link_state == LPFC_HBA_READY)) | |
14665 | return phba->pport; | |
14666 | ||
4f774513 JS |
14667 | vports = lpfc_create_vport_work_array(phba); |
14668 | if (vports != NULL) | |
14669 | for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) { | |
14670 | if (phba->fcf.fcfi == fcfi && | |
14671 | vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) && | |
14672 | vports[i]->fc_myDID == did) { | |
14673 | vport = vports[i]; | |
14674 | break; | |
14675 | } | |
14676 | } | |
14677 | lpfc_destroy_vport_work_array(phba, vports); | |
14678 | return vport; | |
14679 | } | |
14680 | ||
45ed1190 JS |
14681 | /** |
14682 | * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp | |
14683 | * @vport: The vport to work on. | |
14684 | * | |
14685 | * This function updates the receive sequence time stamp for this vport. The | |
14686 | * receive sequence time stamp indicates the time that the last frame of the | |
14687 | * the sequence that has been idle for the longest amount of time was received. | |
14688 | * the driver uses this time stamp to indicate if any received sequences have | |
14689 | * timed out. | |
14690 | **/ | |
5d8b8167 | 14691 | static void |
45ed1190 JS |
14692 | lpfc_update_rcv_time_stamp(struct lpfc_vport *vport) |
14693 | { | |
14694 | struct lpfc_dmabuf *h_buf; | |
14695 | struct hbq_dmabuf *dmabuf = NULL; | |
14696 | ||
14697 | /* get the oldest sequence on the rcv list */ | |
14698 | h_buf = list_get_first(&vport->rcv_buffer_list, | |
14699 | struct lpfc_dmabuf, list); | |
14700 | if (!h_buf) | |
14701 | return; | |
14702 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); | |
14703 | vport->rcv_buffer_time_stamp = dmabuf->time_stamp; | |
14704 | } | |
14705 | ||
14706 | /** | |
14707 | * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences. | |
14708 | * @vport: The vport that the received sequences were sent to. | |
14709 | * | |
14710 | * This function cleans up all outstanding received sequences. This is called | |
14711 | * by the driver when a link event or user action invalidates all the received | |
14712 | * sequences. | |
14713 | **/ | |
14714 | void | |
14715 | lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport) | |
14716 | { | |
14717 | struct lpfc_dmabuf *h_buf, *hnext; | |
14718 | struct lpfc_dmabuf *d_buf, *dnext; | |
14719 | struct hbq_dmabuf *dmabuf = NULL; | |
14720 | ||
14721 | /* start with the oldest sequence on the rcv list */ | |
14722 | list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) { | |
14723 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); | |
14724 | list_del_init(&dmabuf->hbuf.list); | |
14725 | list_for_each_entry_safe(d_buf, dnext, | |
14726 | &dmabuf->dbuf.list, list) { | |
14727 | list_del_init(&d_buf->list); | |
14728 | lpfc_in_buf_free(vport->phba, d_buf); | |
14729 | } | |
14730 | lpfc_in_buf_free(vport->phba, &dmabuf->dbuf); | |
14731 | } | |
14732 | } | |
14733 | ||
14734 | /** | |
14735 | * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences. | |
14736 | * @vport: The vport that the received sequences were sent to. | |
14737 | * | |
14738 | * This function determines whether any received sequences have timed out by | |
14739 | * first checking the vport's rcv_buffer_time_stamp. If this time_stamp | |
14740 | * indicates that there is at least one timed out sequence this routine will | |
14741 | * go through the received sequences one at a time from most inactive to most | |
14742 | * active to determine which ones need to be cleaned up. Once it has determined | |
14743 | * that a sequence needs to be cleaned up it will simply free up the resources | |
14744 | * without sending an abort. | |
14745 | **/ | |
14746 | void | |
14747 | lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport) | |
14748 | { | |
14749 | struct lpfc_dmabuf *h_buf, *hnext; | |
14750 | struct lpfc_dmabuf *d_buf, *dnext; | |
14751 | struct hbq_dmabuf *dmabuf = NULL; | |
14752 | unsigned long timeout; | |
14753 | int abort_count = 0; | |
14754 | ||
14755 | timeout = (msecs_to_jiffies(vport->phba->fc_edtov) + | |
14756 | vport->rcv_buffer_time_stamp); | |
14757 | if (list_empty(&vport->rcv_buffer_list) || | |
14758 | time_before(jiffies, timeout)) | |
14759 | return; | |
14760 | /* start with the oldest sequence on the rcv list */ | |
14761 | list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) { | |
14762 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); | |
14763 | timeout = (msecs_to_jiffies(vport->phba->fc_edtov) + | |
14764 | dmabuf->time_stamp); | |
14765 | if (time_before(jiffies, timeout)) | |
14766 | break; | |
14767 | abort_count++; | |
14768 | list_del_init(&dmabuf->hbuf.list); | |
14769 | list_for_each_entry_safe(d_buf, dnext, | |
14770 | &dmabuf->dbuf.list, list) { | |
14771 | list_del_init(&d_buf->list); | |
14772 | lpfc_in_buf_free(vport->phba, d_buf); | |
14773 | } | |
14774 | lpfc_in_buf_free(vport->phba, &dmabuf->dbuf); | |
14775 | } | |
14776 | if (abort_count) | |
14777 | lpfc_update_rcv_time_stamp(vport); | |
14778 | } | |
14779 | ||
4f774513 JS |
14780 | /** |
14781 | * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences | |
14782 | * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame | |
14783 | * | |
14784 | * This function searches through the existing incomplete sequences that have | |
14785 | * been sent to this @vport. If the frame matches one of the incomplete | |
14786 | * sequences then the dbuf in the @dmabuf is added to the list of frames that | |
14787 | * make up that sequence. If no sequence is found that matches this frame then | |
14788 | * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list | |
14789 | * This function returns a pointer to the first dmabuf in the sequence list that | |
14790 | * the frame was linked to. | |
14791 | **/ | |
14792 | static struct hbq_dmabuf * | |
14793 | lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf) | |
14794 | { | |
14795 | struct fc_frame_header *new_hdr; | |
14796 | struct fc_frame_header *temp_hdr; | |
14797 | struct lpfc_dmabuf *d_buf; | |
14798 | struct lpfc_dmabuf *h_buf; | |
14799 | struct hbq_dmabuf *seq_dmabuf = NULL; | |
14800 | struct hbq_dmabuf *temp_dmabuf = NULL; | |
14801 | ||
4d9ab994 | 14802 | INIT_LIST_HEAD(&dmabuf->dbuf.list); |
45ed1190 | 14803 | dmabuf->time_stamp = jiffies; |
4f774513 JS |
14804 | new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
14805 | /* Use the hdr_buf to find the sequence that this frame belongs to */ | |
14806 | list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) { | |
14807 | temp_hdr = (struct fc_frame_header *)h_buf->virt; | |
14808 | if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) || | |
14809 | (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) || | |
14810 | (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3))) | |
14811 | continue; | |
14812 | /* found a pending sequence that matches this frame */ | |
14813 | seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); | |
14814 | break; | |
14815 | } | |
14816 | if (!seq_dmabuf) { | |
14817 | /* | |
14818 | * This indicates first frame received for this sequence. | |
14819 | * Queue the buffer on the vport's rcv_buffer_list. | |
14820 | */ | |
14821 | list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list); | |
45ed1190 | 14822 | lpfc_update_rcv_time_stamp(vport); |
4f774513 JS |
14823 | return dmabuf; |
14824 | } | |
14825 | temp_hdr = seq_dmabuf->hbuf.virt; | |
eeead811 JS |
14826 | if (be16_to_cpu(new_hdr->fh_seq_cnt) < |
14827 | be16_to_cpu(temp_hdr->fh_seq_cnt)) { | |
4d9ab994 JS |
14828 | list_del_init(&seq_dmabuf->hbuf.list); |
14829 | list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list); | |
14830 | list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list); | |
45ed1190 | 14831 | lpfc_update_rcv_time_stamp(vport); |
4f774513 JS |
14832 | return dmabuf; |
14833 | } | |
45ed1190 JS |
14834 | /* move this sequence to the tail to indicate a young sequence */ |
14835 | list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list); | |
14836 | seq_dmabuf->time_stamp = jiffies; | |
14837 | lpfc_update_rcv_time_stamp(vport); | |
eeead811 JS |
14838 | if (list_empty(&seq_dmabuf->dbuf.list)) { |
14839 | temp_hdr = dmabuf->hbuf.virt; | |
14840 | list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list); | |
14841 | return seq_dmabuf; | |
14842 | } | |
4f774513 JS |
14843 | /* find the correct place in the sequence to insert this frame */ |
14844 | list_for_each_entry_reverse(d_buf, &seq_dmabuf->dbuf.list, list) { | |
14845 | temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf); | |
14846 | temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt; | |
14847 | /* | |
14848 | * If the frame's sequence count is greater than the frame on | |
14849 | * the list then insert the frame right after this frame | |
14850 | */ | |
eeead811 JS |
14851 | if (be16_to_cpu(new_hdr->fh_seq_cnt) > |
14852 | be16_to_cpu(temp_hdr->fh_seq_cnt)) { | |
4f774513 JS |
14853 | list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list); |
14854 | return seq_dmabuf; | |
14855 | } | |
14856 | } | |
14857 | return NULL; | |
14858 | } | |
14859 | ||
6669f9bb JS |
14860 | /** |
14861 | * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence | |
14862 | * @vport: pointer to a vitural port | |
14863 | * @dmabuf: pointer to a dmabuf that describes the FC sequence | |
14864 | * | |
14865 | * This function tries to abort from the partially assembed sequence, described | |
14866 | * by the information from basic abbort @dmabuf. It checks to see whether such | |
14867 | * partially assembled sequence held by the driver. If so, it shall free up all | |
14868 | * the frames from the partially assembled sequence. | |
14869 | * | |
14870 | * Return | |
14871 | * true -- if there is matching partially assembled sequence present and all | |
14872 | * the frames freed with the sequence; | |
14873 | * false -- if there is no matching partially assembled sequence present so | |
14874 | * nothing got aborted in the lower layer driver | |
14875 | **/ | |
14876 | static bool | |
14877 | lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport, | |
14878 | struct hbq_dmabuf *dmabuf) | |
14879 | { | |
14880 | struct fc_frame_header *new_hdr; | |
14881 | struct fc_frame_header *temp_hdr; | |
14882 | struct lpfc_dmabuf *d_buf, *n_buf, *h_buf; | |
14883 | struct hbq_dmabuf *seq_dmabuf = NULL; | |
14884 | ||
14885 | /* Use the hdr_buf to find the sequence that matches this frame */ | |
14886 | INIT_LIST_HEAD(&dmabuf->dbuf.list); | |
14887 | INIT_LIST_HEAD(&dmabuf->hbuf.list); | |
14888 | new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; | |
14889 | list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) { | |
14890 | temp_hdr = (struct fc_frame_header *)h_buf->virt; | |
14891 | if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) || | |
14892 | (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) || | |
14893 | (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3))) | |
14894 | continue; | |
14895 | /* found a pending sequence that matches this frame */ | |
14896 | seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); | |
14897 | break; | |
14898 | } | |
14899 | ||
14900 | /* Free up all the frames from the partially assembled sequence */ | |
14901 | if (seq_dmabuf) { | |
14902 | list_for_each_entry_safe(d_buf, n_buf, | |
14903 | &seq_dmabuf->dbuf.list, list) { | |
14904 | list_del_init(&d_buf->list); | |
14905 | lpfc_in_buf_free(vport->phba, d_buf); | |
14906 | } | |
14907 | return true; | |
14908 | } | |
14909 | return false; | |
14910 | } | |
14911 | ||
6dd9e31c JS |
14912 | /** |
14913 | * lpfc_sli4_abort_ulp_seq - Abort assembled unsol sequence from ulp | |
14914 | * @vport: pointer to a vitural port | |
14915 | * @dmabuf: pointer to a dmabuf that describes the FC sequence | |
14916 | * | |
14917 | * This function tries to abort from the assembed sequence from upper level | |
14918 | * protocol, described by the information from basic abbort @dmabuf. It | |
14919 | * checks to see whether such pending context exists at upper level protocol. | |
14920 | * If so, it shall clean up the pending context. | |
14921 | * | |
14922 | * Return | |
14923 | * true -- if there is matching pending context of the sequence cleaned | |
14924 | * at ulp; | |
14925 | * false -- if there is no matching pending context of the sequence present | |
14926 | * at ulp. | |
14927 | **/ | |
14928 | static bool | |
14929 | lpfc_sli4_abort_ulp_seq(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf) | |
14930 | { | |
14931 | struct lpfc_hba *phba = vport->phba; | |
14932 | int handled; | |
14933 | ||
14934 | /* Accepting abort at ulp with SLI4 only */ | |
14935 | if (phba->sli_rev < LPFC_SLI_REV4) | |
14936 | return false; | |
14937 | ||
14938 | /* Register all caring upper level protocols to attend abort */ | |
14939 | handled = lpfc_ct_handle_unsol_abort(phba, dmabuf); | |
14940 | if (handled) | |
14941 | return true; | |
14942 | ||
14943 | return false; | |
14944 | } | |
14945 | ||
6669f9bb | 14946 | /** |
546fc854 | 14947 | * lpfc_sli4_seq_abort_rsp_cmpl - BLS ABORT RSP seq abort iocb complete handler |
6669f9bb JS |
14948 | * @phba: Pointer to HBA context object. |
14949 | * @cmd_iocbq: pointer to the command iocbq structure. | |
14950 | * @rsp_iocbq: pointer to the response iocbq structure. | |
14951 | * | |
546fc854 | 14952 | * This function handles the sequence abort response iocb command complete |
6669f9bb JS |
14953 | * event. It properly releases the memory allocated to the sequence abort |
14954 | * accept iocb. | |
14955 | **/ | |
14956 | static void | |
546fc854 | 14957 | lpfc_sli4_seq_abort_rsp_cmpl(struct lpfc_hba *phba, |
6669f9bb JS |
14958 | struct lpfc_iocbq *cmd_iocbq, |
14959 | struct lpfc_iocbq *rsp_iocbq) | |
14960 | { | |
6dd9e31c JS |
14961 | struct lpfc_nodelist *ndlp; |
14962 | ||
14963 | if (cmd_iocbq) { | |
14964 | ndlp = (struct lpfc_nodelist *)cmd_iocbq->context1; | |
14965 | lpfc_nlp_put(ndlp); | |
14966 | lpfc_nlp_not_used(ndlp); | |
6669f9bb | 14967 | lpfc_sli_release_iocbq(phba, cmd_iocbq); |
6dd9e31c | 14968 | } |
6b5151fd JS |
14969 | |
14970 | /* Failure means BLS ABORT RSP did not get delivered to remote node*/ | |
14971 | if (rsp_iocbq && rsp_iocbq->iocb.ulpStatus) | |
14972 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
14973 | "3154 BLS ABORT RSP failed, data: x%x/x%x\n", | |
14974 | rsp_iocbq->iocb.ulpStatus, | |
14975 | rsp_iocbq->iocb.un.ulpWord[4]); | |
6669f9bb JS |
14976 | } |
14977 | ||
6d368e53 JS |
14978 | /** |
14979 | * lpfc_sli4_xri_inrange - check xri is in range of xris owned by driver. | |
14980 | * @phba: Pointer to HBA context object. | |
14981 | * @xri: xri id in transaction. | |
14982 | * | |
14983 | * This function validates the xri maps to the known range of XRIs allocated an | |
14984 | * used by the driver. | |
14985 | **/ | |
7851fe2c | 14986 | uint16_t |
6d368e53 JS |
14987 | lpfc_sli4_xri_inrange(struct lpfc_hba *phba, |
14988 | uint16_t xri) | |
14989 | { | |
14990 | int i; | |
14991 | ||
14992 | for (i = 0; i < phba->sli4_hba.max_cfg_param.max_xri; i++) { | |
14993 | if (xri == phba->sli4_hba.xri_ids[i]) | |
14994 | return i; | |
14995 | } | |
14996 | return NO_XRI; | |
14997 | } | |
14998 | ||
6669f9bb | 14999 | /** |
546fc854 | 15000 | * lpfc_sli4_seq_abort_rsp - bls rsp to sequence abort |
6669f9bb JS |
15001 | * @phba: Pointer to HBA context object. |
15002 | * @fc_hdr: pointer to a FC frame header. | |
15003 | * | |
546fc854 | 15004 | * This function sends a basic response to a previous unsol sequence abort |
6669f9bb JS |
15005 | * event after aborting the sequence handling. |
15006 | **/ | |
15007 | static void | |
6dd9e31c JS |
15008 | lpfc_sli4_seq_abort_rsp(struct lpfc_vport *vport, |
15009 | struct fc_frame_header *fc_hdr, bool aborted) | |
6669f9bb | 15010 | { |
6dd9e31c | 15011 | struct lpfc_hba *phba = vport->phba; |
6669f9bb JS |
15012 | struct lpfc_iocbq *ctiocb = NULL; |
15013 | struct lpfc_nodelist *ndlp; | |
ee0f4fe1 | 15014 | uint16_t oxid, rxid, xri, lxri; |
5ffc266e | 15015 | uint32_t sid, fctl; |
6669f9bb | 15016 | IOCB_t *icmd; |
546fc854 | 15017 | int rc; |
6669f9bb JS |
15018 | |
15019 | if (!lpfc_is_link_up(phba)) | |
15020 | return; | |
15021 | ||
15022 | sid = sli4_sid_from_fc_hdr(fc_hdr); | |
15023 | oxid = be16_to_cpu(fc_hdr->fh_ox_id); | |
5ffc266e | 15024 | rxid = be16_to_cpu(fc_hdr->fh_rx_id); |
6669f9bb | 15025 | |
6dd9e31c | 15026 | ndlp = lpfc_findnode_did(vport, sid); |
6669f9bb | 15027 | if (!ndlp) { |
6dd9e31c JS |
15028 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
15029 | if (!ndlp) { | |
15030 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS, | |
15031 | "1268 Failed to allocate ndlp for " | |
15032 | "oxid:x%x SID:x%x\n", oxid, sid); | |
15033 | return; | |
15034 | } | |
15035 | lpfc_nlp_init(vport, ndlp, sid); | |
15036 | /* Put ndlp onto pport node list */ | |
15037 | lpfc_enqueue_node(vport, ndlp); | |
15038 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { | |
15039 | /* re-setup ndlp without removing from node list */ | |
15040 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); | |
15041 | if (!ndlp) { | |
15042 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS, | |
15043 | "3275 Failed to active ndlp found " | |
15044 | "for oxid:x%x SID:x%x\n", oxid, sid); | |
15045 | return; | |
15046 | } | |
6669f9bb JS |
15047 | } |
15048 | ||
546fc854 | 15049 | /* Allocate buffer for rsp iocb */ |
6669f9bb JS |
15050 | ctiocb = lpfc_sli_get_iocbq(phba); |
15051 | if (!ctiocb) | |
15052 | return; | |
15053 | ||
5ffc266e JS |
15054 | /* Extract the F_CTL field from FC_HDR */ |
15055 | fctl = sli4_fctl_from_fc_hdr(fc_hdr); | |
15056 | ||
6669f9bb | 15057 | icmd = &ctiocb->iocb; |
6669f9bb | 15058 | icmd->un.xseq64.bdl.bdeSize = 0; |
5ffc266e | 15059 | icmd->un.xseq64.bdl.ulpIoTag32 = 0; |
6669f9bb JS |
15060 | icmd->un.xseq64.w5.hcsw.Dfctl = 0; |
15061 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC; | |
15062 | icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS; | |
15063 | ||
15064 | /* Fill in the rest of iocb fields */ | |
15065 | icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX; | |
15066 | icmd->ulpBdeCount = 0; | |
15067 | icmd->ulpLe = 1; | |
15068 | icmd->ulpClass = CLASS3; | |
6d368e53 | 15069 | icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]; |
6dd9e31c | 15070 | ctiocb->context1 = lpfc_nlp_get(ndlp); |
6669f9bb | 15071 | |
6669f9bb JS |
15072 | ctiocb->iocb_cmpl = NULL; |
15073 | ctiocb->vport = phba->pport; | |
546fc854 | 15074 | ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_rsp_cmpl; |
6d368e53 | 15075 | ctiocb->sli4_lxritag = NO_XRI; |
546fc854 JS |
15076 | ctiocb->sli4_xritag = NO_XRI; |
15077 | ||
ee0f4fe1 JS |
15078 | if (fctl & FC_FC_EX_CTX) |
15079 | /* Exchange responder sent the abort so we | |
15080 | * own the oxid. | |
15081 | */ | |
15082 | xri = oxid; | |
15083 | else | |
15084 | xri = rxid; | |
15085 | lxri = lpfc_sli4_xri_inrange(phba, xri); | |
15086 | if (lxri != NO_XRI) | |
15087 | lpfc_set_rrq_active(phba, ndlp, lxri, | |
15088 | (xri == oxid) ? rxid : oxid, 0); | |
6dd9e31c JS |
15089 | /* For BA_ABTS from exchange responder, if the logical xri with |
15090 | * the oxid maps to the FCP XRI range, the port no longer has | |
15091 | * that exchange context, send a BLS_RJT. Override the IOCB for | |
15092 | * a BA_RJT. | |
15093 | */ | |
15094 | if ((fctl & FC_FC_EX_CTX) && | |
15095 | (lxri > lpfc_sli4_get_els_iocb_cnt(phba))) { | |
15096 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT; | |
15097 | bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0); | |
15098 | bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID); | |
15099 | bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE); | |
15100 | } | |
15101 | ||
15102 | /* If BA_ABTS failed to abort a partially assembled receive sequence, | |
15103 | * the driver no longer has that exchange, send a BLS_RJT. Override | |
15104 | * the IOCB for a BA_RJT. | |
546fc854 | 15105 | */ |
6dd9e31c | 15106 | if (aborted == false) { |
546fc854 JS |
15107 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT; |
15108 | bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0); | |
15109 | bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID); | |
15110 | bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE); | |
15111 | } | |
6669f9bb | 15112 | |
5ffc266e JS |
15113 | if (fctl & FC_FC_EX_CTX) { |
15114 | /* ABTS sent by responder to CT exchange, construction | |
15115 | * of BA_ACC will use OX_ID from ABTS for the XRI_TAG | |
15116 | * field and RX_ID from ABTS for RX_ID field. | |
15117 | */ | |
546fc854 | 15118 | bf_set(lpfc_abts_orig, &icmd->un.bls_rsp, LPFC_ABTS_UNSOL_RSP); |
5ffc266e JS |
15119 | } else { |
15120 | /* ABTS sent by initiator to CT exchange, construction | |
15121 | * of BA_ACC will need to allocate a new XRI as for the | |
f09c3acc | 15122 | * XRI_TAG field. |
5ffc266e | 15123 | */ |
546fc854 | 15124 | bf_set(lpfc_abts_orig, &icmd->un.bls_rsp, LPFC_ABTS_UNSOL_INT); |
5ffc266e | 15125 | } |
f09c3acc | 15126 | bf_set(lpfc_abts_rxid, &icmd->un.bls_rsp, rxid); |
546fc854 | 15127 | bf_set(lpfc_abts_oxid, &icmd->un.bls_rsp, oxid); |
5ffc266e | 15128 | |
546fc854 | 15129 | /* Xmit CT abts response on exchange <xid> */ |
6dd9e31c JS |
15130 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
15131 | "1200 Send BLS cmd x%x on oxid x%x Data: x%x\n", | |
15132 | icmd->un.xseq64.w5.hcsw.Rctl, oxid, phba->link_state); | |
546fc854 JS |
15133 | |
15134 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0); | |
15135 | if (rc == IOCB_ERROR) { | |
6dd9e31c JS |
15136 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
15137 | "2925 Failed to issue CT ABTS RSP x%x on " | |
15138 | "xri x%x, Data x%x\n", | |
15139 | icmd->un.xseq64.w5.hcsw.Rctl, oxid, | |
15140 | phba->link_state); | |
15141 | lpfc_nlp_put(ndlp); | |
15142 | ctiocb->context1 = NULL; | |
546fc854 JS |
15143 | lpfc_sli_release_iocbq(phba, ctiocb); |
15144 | } | |
6669f9bb JS |
15145 | } |
15146 | ||
15147 | /** | |
15148 | * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event | |
15149 | * @vport: Pointer to the vport on which this sequence was received | |
15150 | * @dmabuf: pointer to a dmabuf that describes the FC sequence | |
15151 | * | |
15152 | * This function handles an SLI-4 unsolicited abort event. If the unsolicited | |
15153 | * receive sequence is only partially assembed by the driver, it shall abort | |
15154 | * the partially assembled frames for the sequence. Otherwise, if the | |
15155 | * unsolicited receive sequence has been completely assembled and passed to | |
15156 | * the Upper Layer Protocol (UPL), it then mark the per oxid status for the | |
15157 | * unsolicited sequence has been aborted. After that, it will issue a basic | |
15158 | * accept to accept the abort. | |
15159 | **/ | |
5d8b8167 | 15160 | static void |
6669f9bb JS |
15161 | lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport, |
15162 | struct hbq_dmabuf *dmabuf) | |
15163 | { | |
15164 | struct lpfc_hba *phba = vport->phba; | |
15165 | struct fc_frame_header fc_hdr; | |
5ffc266e | 15166 | uint32_t fctl; |
6dd9e31c | 15167 | bool aborted; |
6669f9bb | 15168 | |
6669f9bb JS |
15169 | /* Make a copy of fc_hdr before the dmabuf being released */ |
15170 | memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header)); | |
5ffc266e | 15171 | fctl = sli4_fctl_from_fc_hdr(&fc_hdr); |
6669f9bb | 15172 | |
5ffc266e | 15173 | if (fctl & FC_FC_EX_CTX) { |
6dd9e31c JS |
15174 | /* ABTS by responder to exchange, no cleanup needed */ |
15175 | aborted = true; | |
5ffc266e | 15176 | } else { |
6dd9e31c JS |
15177 | /* ABTS by initiator to exchange, need to do cleanup */ |
15178 | aborted = lpfc_sli4_abort_partial_seq(vport, dmabuf); | |
15179 | if (aborted == false) | |
15180 | aborted = lpfc_sli4_abort_ulp_seq(vport, dmabuf); | |
5ffc266e | 15181 | } |
6dd9e31c JS |
15182 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
15183 | ||
15184 | /* Respond with BA_ACC or BA_RJT accordingly */ | |
15185 | lpfc_sli4_seq_abort_rsp(vport, &fc_hdr, aborted); | |
6669f9bb JS |
15186 | } |
15187 | ||
4f774513 JS |
15188 | /** |
15189 | * lpfc_seq_complete - Indicates if a sequence is complete | |
15190 | * @dmabuf: pointer to a dmabuf that describes the FC sequence | |
15191 | * | |
15192 | * This function checks the sequence, starting with the frame described by | |
15193 | * @dmabuf, to see if all the frames associated with this sequence are present. | |
15194 | * the frames associated with this sequence are linked to the @dmabuf using the | |
15195 | * dbuf list. This function looks for two major things. 1) That the first frame | |
15196 | * has a sequence count of zero. 2) There is a frame with last frame of sequence | |
15197 | * set. 3) That there are no holes in the sequence count. The function will | |
15198 | * return 1 when the sequence is complete, otherwise it will return 0. | |
15199 | **/ | |
15200 | static int | |
15201 | lpfc_seq_complete(struct hbq_dmabuf *dmabuf) | |
15202 | { | |
15203 | struct fc_frame_header *hdr; | |
15204 | struct lpfc_dmabuf *d_buf; | |
15205 | struct hbq_dmabuf *seq_dmabuf; | |
15206 | uint32_t fctl; | |
15207 | int seq_count = 0; | |
15208 | ||
15209 | hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; | |
15210 | /* make sure first fame of sequence has a sequence count of zero */ | |
15211 | if (hdr->fh_seq_cnt != seq_count) | |
15212 | return 0; | |
15213 | fctl = (hdr->fh_f_ctl[0] << 16 | | |
15214 | hdr->fh_f_ctl[1] << 8 | | |
15215 | hdr->fh_f_ctl[2]); | |
15216 | /* If last frame of sequence we can return success. */ | |
15217 | if (fctl & FC_FC_END_SEQ) | |
15218 | return 1; | |
15219 | list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) { | |
15220 | seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf); | |
15221 | hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; | |
15222 | /* If there is a hole in the sequence count then fail. */ | |
eeead811 | 15223 | if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt)) |
4f774513 JS |
15224 | return 0; |
15225 | fctl = (hdr->fh_f_ctl[0] << 16 | | |
15226 | hdr->fh_f_ctl[1] << 8 | | |
15227 | hdr->fh_f_ctl[2]); | |
15228 | /* If last frame of sequence we can return success. */ | |
15229 | if (fctl & FC_FC_END_SEQ) | |
15230 | return 1; | |
15231 | } | |
15232 | return 0; | |
15233 | } | |
15234 | ||
15235 | /** | |
15236 | * lpfc_prep_seq - Prep sequence for ULP processing | |
15237 | * @vport: Pointer to the vport on which this sequence was received | |
15238 | * @dmabuf: pointer to a dmabuf that describes the FC sequence | |
15239 | * | |
15240 | * This function takes a sequence, described by a list of frames, and creates | |
15241 | * a list of iocbq structures to describe the sequence. This iocbq list will be | |
15242 | * used to issue to the generic unsolicited sequence handler. This routine | |
15243 | * returns a pointer to the first iocbq in the list. If the function is unable | |
15244 | * to allocate an iocbq then it throw out the received frames that were not | |
15245 | * able to be described and return a pointer to the first iocbq. If unable to | |
15246 | * allocate any iocbqs (including the first) this function will return NULL. | |
15247 | **/ | |
15248 | static struct lpfc_iocbq * | |
15249 | lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf) | |
15250 | { | |
7851fe2c | 15251 | struct hbq_dmabuf *hbq_buf; |
4f774513 JS |
15252 | struct lpfc_dmabuf *d_buf, *n_buf; |
15253 | struct lpfc_iocbq *first_iocbq, *iocbq; | |
15254 | struct fc_frame_header *fc_hdr; | |
15255 | uint32_t sid; | |
7851fe2c | 15256 | uint32_t len, tot_len; |
eeead811 | 15257 | struct ulp_bde64 *pbde; |
4f774513 JS |
15258 | |
15259 | fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; | |
15260 | /* remove from receive buffer list */ | |
15261 | list_del_init(&seq_dmabuf->hbuf.list); | |
45ed1190 | 15262 | lpfc_update_rcv_time_stamp(vport); |
4f774513 | 15263 | /* get the Remote Port's SID */ |
6669f9bb | 15264 | sid = sli4_sid_from_fc_hdr(fc_hdr); |
7851fe2c | 15265 | tot_len = 0; |
4f774513 JS |
15266 | /* Get an iocbq struct to fill in. */ |
15267 | first_iocbq = lpfc_sli_get_iocbq(vport->phba); | |
15268 | if (first_iocbq) { | |
15269 | /* Initialize the first IOCB. */ | |
8fa38513 | 15270 | first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0; |
4f774513 | 15271 | first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS; |
939723a4 JS |
15272 | |
15273 | /* Check FC Header to see what TYPE of frame we are rcv'ing */ | |
15274 | if (sli4_type_from_fc_hdr(fc_hdr) == FC_TYPE_ELS) { | |
15275 | first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_ELS64_CX; | |
15276 | first_iocbq->iocb.un.rcvels.parmRo = | |
15277 | sli4_did_from_fc_hdr(fc_hdr); | |
15278 | first_iocbq->iocb.ulpPU = PARM_NPIV_DID; | |
15279 | } else | |
15280 | first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX; | |
7851fe2c JS |
15281 | first_iocbq->iocb.ulpContext = NO_XRI; |
15282 | first_iocbq->iocb.unsli3.rcvsli3.ox_id = | |
15283 | be16_to_cpu(fc_hdr->fh_ox_id); | |
15284 | /* iocbq is prepped for internal consumption. Physical vpi. */ | |
15285 | first_iocbq->iocb.unsli3.rcvsli3.vpi = | |
15286 | vport->phba->vpi_ids[vport->vpi]; | |
4f774513 | 15287 | /* put the first buffer into the first IOCBq */ |
48a5a664 JS |
15288 | tot_len = bf_get(lpfc_rcqe_length, |
15289 | &seq_dmabuf->cq_event.cqe.rcqe_cmpl); | |
15290 | ||
4f774513 JS |
15291 | first_iocbq->context2 = &seq_dmabuf->dbuf; |
15292 | first_iocbq->context3 = NULL; | |
15293 | first_iocbq->iocb.ulpBdeCount = 1; | |
48a5a664 JS |
15294 | if (tot_len > LPFC_DATA_BUF_SIZE) |
15295 | first_iocbq->iocb.un.cont64[0].tus.f.bdeSize = | |
4f774513 | 15296 | LPFC_DATA_BUF_SIZE; |
48a5a664 JS |
15297 | else |
15298 | first_iocbq->iocb.un.cont64[0].tus.f.bdeSize = tot_len; | |
15299 | ||
4f774513 | 15300 | first_iocbq->iocb.un.rcvels.remoteID = sid; |
48a5a664 | 15301 | |
7851fe2c | 15302 | first_iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len; |
4f774513 JS |
15303 | } |
15304 | iocbq = first_iocbq; | |
15305 | /* | |
15306 | * Each IOCBq can have two Buffers assigned, so go through the list | |
15307 | * of buffers for this sequence and save two buffers in each IOCBq | |
15308 | */ | |
15309 | list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) { | |
15310 | if (!iocbq) { | |
15311 | lpfc_in_buf_free(vport->phba, d_buf); | |
15312 | continue; | |
15313 | } | |
15314 | if (!iocbq->context3) { | |
15315 | iocbq->context3 = d_buf; | |
15316 | iocbq->iocb.ulpBdeCount++; | |
7851fe2c JS |
15317 | /* We need to get the size out of the right CQE */ |
15318 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); | |
15319 | len = bf_get(lpfc_rcqe_length, | |
15320 | &hbq_buf->cq_event.cqe.rcqe_cmpl); | |
48a5a664 JS |
15321 | pbde = (struct ulp_bde64 *) |
15322 | &iocbq->iocb.unsli3.sli3Words[4]; | |
15323 | if (len > LPFC_DATA_BUF_SIZE) | |
15324 | pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE; | |
15325 | else | |
15326 | pbde->tus.f.bdeSize = len; | |
15327 | ||
7851fe2c JS |
15328 | iocbq->iocb.unsli3.rcvsli3.acc_len += len; |
15329 | tot_len += len; | |
4f774513 JS |
15330 | } else { |
15331 | iocbq = lpfc_sli_get_iocbq(vport->phba); | |
15332 | if (!iocbq) { | |
15333 | if (first_iocbq) { | |
15334 | first_iocbq->iocb.ulpStatus = | |
15335 | IOSTAT_FCP_RSP_ERROR; | |
15336 | first_iocbq->iocb.un.ulpWord[4] = | |
15337 | IOERR_NO_RESOURCES; | |
15338 | } | |
15339 | lpfc_in_buf_free(vport->phba, d_buf); | |
15340 | continue; | |
15341 | } | |
48a5a664 JS |
15342 | /* We need to get the size out of the right CQE */ |
15343 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); | |
15344 | len = bf_get(lpfc_rcqe_length, | |
15345 | &hbq_buf->cq_event.cqe.rcqe_cmpl); | |
4f774513 JS |
15346 | iocbq->context2 = d_buf; |
15347 | iocbq->context3 = NULL; | |
15348 | iocbq->iocb.ulpBdeCount = 1; | |
48a5a664 JS |
15349 | if (len > LPFC_DATA_BUF_SIZE) |
15350 | iocbq->iocb.un.cont64[0].tus.f.bdeSize = | |
4f774513 | 15351 | LPFC_DATA_BUF_SIZE; |
48a5a664 JS |
15352 | else |
15353 | iocbq->iocb.un.cont64[0].tus.f.bdeSize = len; | |
7851fe2c | 15354 | |
7851fe2c JS |
15355 | tot_len += len; |
15356 | iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len; | |
15357 | ||
4f774513 JS |
15358 | iocbq->iocb.un.rcvels.remoteID = sid; |
15359 | list_add_tail(&iocbq->list, &first_iocbq->list); | |
15360 | } | |
15361 | } | |
15362 | return first_iocbq; | |
15363 | } | |
15364 | ||
6669f9bb JS |
15365 | static void |
15366 | lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport, | |
15367 | struct hbq_dmabuf *seq_dmabuf) | |
15368 | { | |
15369 | struct fc_frame_header *fc_hdr; | |
15370 | struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb; | |
15371 | struct lpfc_hba *phba = vport->phba; | |
15372 | ||
15373 | fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; | |
15374 | iocbq = lpfc_prep_seq(vport, seq_dmabuf); | |
15375 | if (!iocbq) { | |
15376 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
15377 | "2707 Ring %d handler: Failed to allocate " | |
15378 | "iocb Rctl x%x Type x%x received\n", | |
15379 | LPFC_ELS_RING, | |
15380 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); | |
15381 | return; | |
15382 | } | |
15383 | if (!lpfc_complete_unsol_iocb(phba, | |
15384 | &phba->sli.ring[LPFC_ELS_RING], | |
15385 | iocbq, fc_hdr->fh_r_ctl, | |
15386 | fc_hdr->fh_type)) | |
6d368e53 | 15387 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
6669f9bb JS |
15388 | "2540 Ring %d handler: unexpected Rctl " |
15389 | "x%x Type x%x received\n", | |
15390 | LPFC_ELS_RING, | |
15391 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); | |
15392 | ||
15393 | /* Free iocb created in lpfc_prep_seq */ | |
15394 | list_for_each_entry_safe(curr_iocb, next_iocb, | |
15395 | &iocbq->list, list) { | |
15396 | list_del_init(&curr_iocb->list); | |
15397 | lpfc_sli_release_iocbq(phba, curr_iocb); | |
15398 | } | |
15399 | lpfc_sli_release_iocbq(phba, iocbq); | |
15400 | } | |
15401 | ||
4f774513 JS |
15402 | /** |
15403 | * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware | |
15404 | * @phba: Pointer to HBA context object. | |
15405 | * | |
15406 | * This function is called with no lock held. This function processes all | |
15407 | * the received buffers and gives it to upper layers when a received buffer | |
15408 | * indicates that it is the final frame in the sequence. The interrupt | |
15409 | * service routine processes received buffers at interrupt contexts and adds | |
15410 | * received dma buffers to the rb_pend_list queue and signals the worker thread. | |
15411 | * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the | |
15412 | * appropriate receive function when the final frame in a sequence is received. | |
15413 | **/ | |
4d9ab994 JS |
15414 | void |
15415 | lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba, | |
15416 | struct hbq_dmabuf *dmabuf) | |
4f774513 | 15417 | { |
4d9ab994 | 15418 | struct hbq_dmabuf *seq_dmabuf; |
4f774513 JS |
15419 | struct fc_frame_header *fc_hdr; |
15420 | struct lpfc_vport *vport; | |
15421 | uint32_t fcfi; | |
939723a4 | 15422 | uint32_t did; |
4f774513 | 15423 | |
4f774513 | 15424 | /* Process each received buffer */ |
4d9ab994 JS |
15425 | fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
15426 | /* check to see if this a valid type of frame */ | |
15427 | if (lpfc_fc_frame_check(phba, fc_hdr)) { | |
15428 | lpfc_in_buf_free(phba, &dmabuf->dbuf); | |
15429 | return; | |
15430 | } | |
7851fe2c JS |
15431 | if ((bf_get(lpfc_cqe_code, |
15432 | &dmabuf->cq_event.cqe.rcqe_cmpl) == CQE_CODE_RECEIVE_V1)) | |
15433 | fcfi = bf_get(lpfc_rcqe_fcf_id_v1, | |
15434 | &dmabuf->cq_event.cqe.rcqe_cmpl); | |
15435 | else | |
15436 | fcfi = bf_get(lpfc_rcqe_fcf_id, | |
15437 | &dmabuf->cq_event.cqe.rcqe_cmpl); | |
939723a4 | 15438 | |
4d9ab994 | 15439 | vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi); |
939723a4 | 15440 | if (!vport) { |
4d9ab994 JS |
15441 | /* throw out the frame */ |
15442 | lpfc_in_buf_free(phba, &dmabuf->dbuf); | |
15443 | return; | |
15444 | } | |
939723a4 JS |
15445 | |
15446 | /* d_id this frame is directed to */ | |
15447 | did = sli4_did_from_fc_hdr(fc_hdr); | |
15448 | ||
15449 | /* vport is registered unless we rcv a FLOGI directed to Fabric_DID */ | |
15450 | if (!(vport->vpi_state & LPFC_VPI_REGISTERED) && | |
15451 | (did != Fabric_DID)) { | |
15452 | /* | |
15453 | * Throw out the frame if we are not pt2pt. | |
15454 | * The pt2pt protocol allows for discovery frames | |
15455 | * to be received without a registered VPI. | |
15456 | */ | |
15457 | if (!(vport->fc_flag & FC_PT2PT) || | |
15458 | (phba->link_state == LPFC_HBA_READY)) { | |
15459 | lpfc_in_buf_free(phba, &dmabuf->dbuf); | |
15460 | return; | |
15461 | } | |
15462 | } | |
15463 | ||
6669f9bb JS |
15464 | /* Handle the basic abort sequence (BA_ABTS) event */ |
15465 | if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) { | |
15466 | lpfc_sli4_handle_unsol_abort(vport, dmabuf); | |
15467 | return; | |
15468 | } | |
15469 | ||
4d9ab994 JS |
15470 | /* Link this frame */ |
15471 | seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf); | |
15472 | if (!seq_dmabuf) { | |
15473 | /* unable to add frame to vport - throw it out */ | |
15474 | lpfc_in_buf_free(phba, &dmabuf->dbuf); | |
15475 | return; | |
15476 | } | |
15477 | /* If not last frame in sequence continue processing frames. */ | |
def9c7a9 | 15478 | if (!lpfc_seq_complete(seq_dmabuf)) |
4d9ab994 | 15479 | return; |
def9c7a9 | 15480 | |
6669f9bb JS |
15481 | /* Send the complete sequence to the upper layer protocol */ |
15482 | lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf); | |
4f774513 | 15483 | } |
6fb120a7 JS |
15484 | |
15485 | /** | |
15486 | * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port | |
15487 | * @phba: pointer to lpfc hba data structure. | |
15488 | * | |
15489 | * This routine is invoked to post rpi header templates to the | |
15490 | * HBA consistent with the SLI-4 interface spec. This routine | |
49198b37 JS |
15491 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
15492 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. | |
6fb120a7 JS |
15493 | * |
15494 | * This routine does not require any locks. It's usage is expected | |
15495 | * to be driver load or reset recovery when the driver is | |
15496 | * sequential. | |
15497 | * | |
15498 | * Return codes | |
af901ca1 | 15499 | * 0 - successful |
d439d286 | 15500 | * -EIO - The mailbox failed to complete successfully. |
6fb120a7 JS |
15501 | * When this error occurs, the driver is not guaranteed |
15502 | * to have any rpi regions posted to the device and | |
15503 | * must either attempt to repost the regions or take a | |
15504 | * fatal error. | |
15505 | **/ | |
15506 | int | |
15507 | lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba) | |
15508 | { | |
15509 | struct lpfc_rpi_hdr *rpi_page; | |
15510 | uint32_t rc = 0; | |
6d368e53 JS |
15511 | uint16_t lrpi = 0; |
15512 | ||
15513 | /* SLI4 ports that support extents do not require RPI headers. */ | |
15514 | if (!phba->sli4_hba.rpi_hdrs_in_use) | |
15515 | goto exit; | |
15516 | if (phba->sli4_hba.extents_in_use) | |
15517 | return -EIO; | |
6fb120a7 | 15518 | |
6fb120a7 | 15519 | list_for_each_entry(rpi_page, &phba->sli4_hba.lpfc_rpi_hdr_list, list) { |
6d368e53 JS |
15520 | /* |
15521 | * Assign the rpi headers a physical rpi only if the driver | |
15522 | * has not initialized those resources. A port reset only | |
15523 | * needs the headers posted. | |
15524 | */ | |
15525 | if (bf_get(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags) != | |
15526 | LPFC_RPI_RSRC_RDY) | |
15527 | rpi_page->start_rpi = phba->sli4_hba.rpi_ids[lrpi]; | |
15528 | ||
6fb120a7 JS |
15529 | rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page); |
15530 | if (rc != MBX_SUCCESS) { | |
15531 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
15532 | "2008 Error %d posting all rpi " | |
15533 | "headers\n", rc); | |
15534 | rc = -EIO; | |
15535 | break; | |
15536 | } | |
15537 | } | |
15538 | ||
6d368e53 JS |
15539 | exit: |
15540 | bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, | |
15541 | LPFC_RPI_RSRC_RDY); | |
6fb120a7 JS |
15542 | return rc; |
15543 | } | |
15544 | ||
15545 | /** | |
15546 | * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port | |
15547 | * @phba: pointer to lpfc hba data structure. | |
15548 | * @rpi_page: pointer to the rpi memory region. | |
15549 | * | |
15550 | * This routine is invoked to post a single rpi header to the | |
15551 | * HBA consistent with the SLI-4 interface spec. This memory region | |
15552 | * maps up to 64 rpi context regions. | |
15553 | * | |
15554 | * Return codes | |
af901ca1 | 15555 | * 0 - successful |
d439d286 JS |
15556 | * -ENOMEM - No available memory |
15557 | * -EIO - The mailbox failed to complete successfully. | |
6fb120a7 JS |
15558 | **/ |
15559 | int | |
15560 | lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page) | |
15561 | { | |
15562 | LPFC_MBOXQ_t *mboxq; | |
15563 | struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl; | |
15564 | uint32_t rc = 0; | |
6fb120a7 JS |
15565 | uint32_t shdr_status, shdr_add_status; |
15566 | union lpfc_sli4_cfg_shdr *shdr; | |
15567 | ||
6d368e53 JS |
15568 | /* SLI4 ports that support extents do not require RPI headers. */ |
15569 | if (!phba->sli4_hba.rpi_hdrs_in_use) | |
15570 | return rc; | |
15571 | if (phba->sli4_hba.extents_in_use) | |
15572 | return -EIO; | |
15573 | ||
6fb120a7 JS |
15574 | /* The port is notified of the header region via a mailbox command. */ |
15575 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
15576 | if (!mboxq) { | |
15577 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
15578 | "2001 Unable to allocate memory for issuing " | |
15579 | "SLI_CONFIG_SPECIAL mailbox command\n"); | |
15580 | return -ENOMEM; | |
15581 | } | |
15582 | ||
15583 | /* Post all rpi memory regions to the port. */ | |
15584 | hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl; | |
6fb120a7 JS |
15585 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, |
15586 | LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE, | |
15587 | sizeof(struct lpfc_mbx_post_hdr_tmpl) - | |
fedd3b7b JS |
15588 | sizeof(struct lpfc_sli4_cfg_mhdr), |
15589 | LPFC_SLI4_MBX_EMBED); | |
6d368e53 JS |
15590 | |
15591 | ||
15592 | /* Post the physical rpi to the port for this rpi header. */ | |
6fb120a7 JS |
15593 | bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl, |
15594 | rpi_page->start_rpi); | |
6d368e53 JS |
15595 | bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt, |
15596 | hdr_tmpl, rpi_page->page_count); | |
15597 | ||
6fb120a7 JS |
15598 | hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys); |
15599 | hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys); | |
f1126688 | 15600 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
6fb120a7 JS |
15601 | shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr; |
15602 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
15603 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
15604 | if (rc != MBX_TIMEOUT) | |
15605 | mempool_free(mboxq, phba->mbox_mem_pool); | |
15606 | if (shdr_status || shdr_add_status || rc) { | |
15607 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
15608 | "2514 POST_RPI_HDR mailbox failed with " | |
15609 | "status x%x add_status x%x, mbx status x%x\n", | |
15610 | shdr_status, shdr_add_status, rc); | |
15611 | rc = -ENXIO; | |
15612 | } | |
15613 | return rc; | |
15614 | } | |
15615 | ||
15616 | /** | |
15617 | * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range | |
15618 | * @phba: pointer to lpfc hba data structure. | |
15619 | * | |
15620 | * This routine is invoked to post rpi header templates to the | |
15621 | * HBA consistent with the SLI-4 interface spec. This routine | |
49198b37 JS |
15622 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
15623 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. | |
6fb120a7 JS |
15624 | * |
15625 | * Returns | |
af901ca1 | 15626 | * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful |
6fb120a7 JS |
15627 | * LPFC_RPI_ALLOC_ERROR if no rpis are available. |
15628 | **/ | |
15629 | int | |
15630 | lpfc_sli4_alloc_rpi(struct lpfc_hba *phba) | |
15631 | { | |
6d368e53 JS |
15632 | unsigned long rpi; |
15633 | uint16_t max_rpi, rpi_limit; | |
15634 | uint16_t rpi_remaining, lrpi = 0; | |
6fb120a7 | 15635 | struct lpfc_rpi_hdr *rpi_hdr; |
4902b381 | 15636 | unsigned long iflag; |
6fb120a7 JS |
15637 | |
15638 | max_rpi = phba->sli4_hba.max_cfg_param.max_rpi; | |
6fb120a7 JS |
15639 | rpi_limit = phba->sli4_hba.next_rpi; |
15640 | ||
15641 | /* | |
6d368e53 JS |
15642 | * Fetch the next logical rpi. Because this index is logical, |
15643 | * the driver starts at 0 each time. | |
6fb120a7 | 15644 | */ |
4902b381 | 15645 | spin_lock_irqsave(&phba->hbalock, iflag); |
6d368e53 JS |
15646 | rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, 0); |
15647 | if (rpi >= rpi_limit) | |
6fb120a7 JS |
15648 | rpi = LPFC_RPI_ALLOC_ERROR; |
15649 | else { | |
15650 | set_bit(rpi, phba->sli4_hba.rpi_bmask); | |
15651 | phba->sli4_hba.max_cfg_param.rpi_used++; | |
15652 | phba->sli4_hba.rpi_count++; | |
15653 | } | |
15654 | ||
15655 | /* | |
15656 | * Don't try to allocate more rpi header regions if the device limit | |
6d368e53 | 15657 | * has been exhausted. |
6fb120a7 JS |
15658 | */ |
15659 | if ((rpi == LPFC_RPI_ALLOC_ERROR) && | |
15660 | (phba->sli4_hba.rpi_count >= max_rpi)) { | |
4902b381 | 15661 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
6fb120a7 JS |
15662 | return rpi; |
15663 | } | |
15664 | ||
6d368e53 JS |
15665 | /* |
15666 | * RPI header postings are not required for SLI4 ports capable of | |
15667 | * extents. | |
15668 | */ | |
15669 | if (!phba->sli4_hba.rpi_hdrs_in_use) { | |
4902b381 | 15670 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
6d368e53 JS |
15671 | return rpi; |
15672 | } | |
15673 | ||
6fb120a7 JS |
15674 | /* |
15675 | * If the driver is running low on rpi resources, allocate another | |
15676 | * page now. Note that the next_rpi value is used because | |
15677 | * it represents how many are actually in use whereas max_rpi notes | |
15678 | * how many are supported max by the device. | |
15679 | */ | |
6d368e53 | 15680 | rpi_remaining = phba->sli4_hba.next_rpi - phba->sli4_hba.rpi_count; |
4902b381 | 15681 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
6fb120a7 JS |
15682 | if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) { |
15683 | rpi_hdr = lpfc_sli4_create_rpi_hdr(phba); | |
15684 | if (!rpi_hdr) { | |
15685 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
15686 | "2002 Error Could not grow rpi " | |
15687 | "count\n"); | |
15688 | } else { | |
6d368e53 JS |
15689 | lrpi = rpi_hdr->start_rpi; |
15690 | rpi_hdr->start_rpi = phba->sli4_hba.rpi_ids[lrpi]; | |
6fb120a7 JS |
15691 | lpfc_sli4_post_rpi_hdr(phba, rpi_hdr); |
15692 | } | |
15693 | } | |
15694 | ||
15695 | return rpi; | |
15696 | } | |
15697 | ||
d7c47992 JS |
15698 | /** |
15699 | * lpfc_sli4_free_rpi - Release an rpi for reuse. | |
15700 | * @phba: pointer to lpfc hba data structure. | |
15701 | * | |
15702 | * This routine is invoked to release an rpi to the pool of | |
15703 | * available rpis maintained by the driver. | |
15704 | **/ | |
5d8b8167 | 15705 | static void |
d7c47992 JS |
15706 | __lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi) |
15707 | { | |
15708 | if (test_and_clear_bit(rpi, phba->sli4_hba.rpi_bmask)) { | |
15709 | phba->sli4_hba.rpi_count--; | |
15710 | phba->sli4_hba.max_cfg_param.rpi_used--; | |
15711 | } | |
15712 | } | |
15713 | ||
6fb120a7 JS |
15714 | /** |
15715 | * lpfc_sli4_free_rpi - Release an rpi for reuse. | |
15716 | * @phba: pointer to lpfc hba data structure. | |
15717 | * | |
15718 | * This routine is invoked to release an rpi to the pool of | |
15719 | * available rpis maintained by the driver. | |
15720 | **/ | |
15721 | void | |
15722 | lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi) | |
15723 | { | |
15724 | spin_lock_irq(&phba->hbalock); | |
d7c47992 | 15725 | __lpfc_sli4_free_rpi(phba, rpi); |
6fb120a7 JS |
15726 | spin_unlock_irq(&phba->hbalock); |
15727 | } | |
15728 | ||
15729 | /** | |
15730 | * lpfc_sli4_remove_rpis - Remove the rpi bitmask region | |
15731 | * @phba: pointer to lpfc hba data structure. | |
15732 | * | |
15733 | * This routine is invoked to remove the memory region that | |
15734 | * provided rpi via a bitmask. | |
15735 | **/ | |
15736 | void | |
15737 | lpfc_sli4_remove_rpis(struct lpfc_hba *phba) | |
15738 | { | |
15739 | kfree(phba->sli4_hba.rpi_bmask); | |
6d368e53 JS |
15740 | kfree(phba->sli4_hba.rpi_ids); |
15741 | bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); | |
6fb120a7 JS |
15742 | } |
15743 | ||
15744 | /** | |
15745 | * lpfc_sli4_resume_rpi - Remove the rpi bitmask region | |
15746 | * @phba: pointer to lpfc hba data structure. | |
15747 | * | |
15748 | * This routine is invoked to remove the memory region that | |
15749 | * provided rpi via a bitmask. | |
15750 | **/ | |
15751 | int | |
6b5151fd JS |
15752 | lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp, |
15753 | void (*cmpl)(struct lpfc_hba *, LPFC_MBOXQ_t *), void *arg) | |
6fb120a7 JS |
15754 | { |
15755 | LPFC_MBOXQ_t *mboxq; | |
15756 | struct lpfc_hba *phba = ndlp->phba; | |
15757 | int rc; | |
15758 | ||
15759 | /* The port is notified of the header region via a mailbox command. */ | |
15760 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
15761 | if (!mboxq) | |
15762 | return -ENOMEM; | |
15763 | ||
15764 | /* Post all rpi memory regions to the port. */ | |
15765 | lpfc_resume_rpi(mboxq, ndlp); | |
6b5151fd JS |
15766 | if (cmpl) { |
15767 | mboxq->mbox_cmpl = cmpl; | |
15768 | mboxq->context1 = arg; | |
15769 | mboxq->context2 = ndlp; | |
72859909 JS |
15770 | } else |
15771 | mboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
6b5151fd | 15772 | mboxq->vport = ndlp->vport; |
6fb120a7 JS |
15773 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
15774 | if (rc == MBX_NOT_FINISHED) { | |
15775 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
15776 | "2010 Resume RPI Mailbox failed " | |
15777 | "status %d, mbxStatus x%x\n", rc, | |
15778 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); | |
15779 | mempool_free(mboxq, phba->mbox_mem_pool); | |
15780 | return -EIO; | |
15781 | } | |
15782 | return 0; | |
15783 | } | |
15784 | ||
15785 | /** | |
15786 | * lpfc_sli4_init_vpi - Initialize a vpi with the port | |
76a95d75 | 15787 | * @vport: Pointer to the vport for which the vpi is being initialized |
6fb120a7 | 15788 | * |
76a95d75 | 15789 | * This routine is invoked to activate a vpi with the port. |
6fb120a7 JS |
15790 | * |
15791 | * Returns: | |
15792 | * 0 success | |
15793 | * -Evalue otherwise | |
15794 | **/ | |
15795 | int | |
76a95d75 | 15796 | lpfc_sli4_init_vpi(struct lpfc_vport *vport) |
6fb120a7 JS |
15797 | { |
15798 | LPFC_MBOXQ_t *mboxq; | |
15799 | int rc = 0; | |
6a9c52cf | 15800 | int retval = MBX_SUCCESS; |
6fb120a7 | 15801 | uint32_t mbox_tmo; |
76a95d75 | 15802 | struct lpfc_hba *phba = vport->phba; |
6fb120a7 JS |
15803 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
15804 | if (!mboxq) | |
15805 | return -ENOMEM; | |
76a95d75 | 15806 | lpfc_init_vpi(phba, mboxq, vport->vpi); |
a183a15f | 15807 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); |
6fb120a7 | 15808 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); |
6fb120a7 | 15809 | if (rc != MBX_SUCCESS) { |
76a95d75 | 15810 | lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI, |
6fb120a7 JS |
15811 | "2022 INIT VPI Mailbox failed " |
15812 | "status %d, mbxStatus x%x\n", rc, | |
15813 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); | |
6a9c52cf | 15814 | retval = -EIO; |
6fb120a7 | 15815 | } |
6a9c52cf | 15816 | if (rc != MBX_TIMEOUT) |
76a95d75 | 15817 | mempool_free(mboxq, vport->phba->mbox_mem_pool); |
6a9c52cf JS |
15818 | |
15819 | return retval; | |
6fb120a7 JS |
15820 | } |
15821 | ||
15822 | /** | |
15823 | * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler. | |
15824 | * @phba: pointer to lpfc hba data structure. | |
15825 | * @mboxq: Pointer to mailbox object. | |
15826 | * | |
15827 | * This routine is invoked to manually add a single FCF record. The caller | |
15828 | * must pass a completely initialized FCF_Record. This routine takes | |
15829 | * care of the nonembedded mailbox operations. | |
15830 | **/ | |
15831 | static void | |
15832 | lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) | |
15833 | { | |
15834 | void *virt_addr; | |
15835 | union lpfc_sli4_cfg_shdr *shdr; | |
15836 | uint32_t shdr_status, shdr_add_status; | |
15837 | ||
15838 | virt_addr = mboxq->sge_array->addr[0]; | |
15839 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
15840 | shdr = (union lpfc_sli4_cfg_shdr *) virt_addr; | |
15841 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
15842 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
15843 | ||
15844 | if ((shdr_status || shdr_add_status) && | |
15845 | (shdr_status != STATUS_FCF_IN_USE)) | |
15846 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
15847 | "2558 ADD_FCF_RECORD mailbox failed with " | |
15848 | "status x%x add_status x%x\n", | |
15849 | shdr_status, shdr_add_status); | |
15850 | ||
15851 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
15852 | } | |
15853 | ||
15854 | /** | |
15855 | * lpfc_sli4_add_fcf_record - Manually add an FCF Record. | |
15856 | * @phba: pointer to lpfc hba data structure. | |
15857 | * @fcf_record: pointer to the initialized fcf record to add. | |
15858 | * | |
15859 | * This routine is invoked to manually add a single FCF record. The caller | |
15860 | * must pass a completely initialized FCF_Record. This routine takes | |
15861 | * care of the nonembedded mailbox operations. | |
15862 | **/ | |
15863 | int | |
15864 | lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record) | |
15865 | { | |
15866 | int rc = 0; | |
15867 | LPFC_MBOXQ_t *mboxq; | |
15868 | uint8_t *bytep; | |
15869 | void *virt_addr; | |
15870 | dma_addr_t phys_addr; | |
15871 | struct lpfc_mbx_sge sge; | |
15872 | uint32_t alloc_len, req_len; | |
15873 | uint32_t fcfindex; | |
15874 | ||
15875 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
15876 | if (!mboxq) { | |
15877 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
15878 | "2009 Failed to allocate mbox for ADD_FCF cmd\n"); | |
15879 | return -ENOMEM; | |
15880 | } | |
15881 | ||
15882 | req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) + | |
15883 | sizeof(uint32_t); | |
15884 | ||
15885 | /* Allocate DMA memory and set up the non-embedded mailbox command */ | |
15886 | alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, | |
15887 | LPFC_MBOX_OPCODE_FCOE_ADD_FCF, | |
15888 | req_len, LPFC_SLI4_MBX_NEMBED); | |
15889 | if (alloc_len < req_len) { | |
15890 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
15891 | "2523 Allocated DMA memory size (x%x) is " | |
15892 | "less than the requested DMA memory " | |
15893 | "size (x%x)\n", alloc_len, req_len); | |
15894 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
15895 | return -ENOMEM; | |
15896 | } | |
15897 | ||
15898 | /* | |
15899 | * Get the first SGE entry from the non-embedded DMA memory. This | |
15900 | * routine only uses a single SGE. | |
15901 | */ | |
15902 | lpfc_sli4_mbx_sge_get(mboxq, 0, &sge); | |
15903 | phys_addr = getPaddr(sge.pa_hi, sge.pa_lo); | |
6fb120a7 JS |
15904 | virt_addr = mboxq->sge_array->addr[0]; |
15905 | /* | |
15906 | * Configure the FCF record for FCFI 0. This is the driver's | |
15907 | * hardcoded default and gets used in nonFIP mode. | |
15908 | */ | |
15909 | fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record); | |
15910 | bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr); | |
15911 | lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t)); | |
15912 | ||
15913 | /* | |
15914 | * Copy the fcf_index and the FCF Record Data. The data starts after | |
15915 | * the FCoE header plus word10. The data copy needs to be endian | |
15916 | * correct. | |
15917 | */ | |
15918 | bytep += sizeof(uint32_t); | |
15919 | lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record)); | |
15920 | mboxq->vport = phba->pport; | |
15921 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record; | |
15922 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); | |
15923 | if (rc == MBX_NOT_FINISHED) { | |
15924 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
15925 | "2515 ADD_FCF_RECORD mailbox failed with " | |
15926 | "status 0x%x\n", rc); | |
15927 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
15928 | rc = -EIO; | |
15929 | } else | |
15930 | rc = 0; | |
15931 | ||
15932 | return rc; | |
15933 | } | |
15934 | ||
15935 | /** | |
15936 | * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record. | |
15937 | * @phba: pointer to lpfc hba data structure. | |
15938 | * @fcf_record: pointer to the fcf record to write the default data. | |
15939 | * @fcf_index: FCF table entry index. | |
15940 | * | |
15941 | * This routine is invoked to build the driver's default FCF record. The | |
15942 | * values used are hardcoded. This routine handles memory initialization. | |
15943 | * | |
15944 | **/ | |
15945 | void | |
15946 | lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba, | |
15947 | struct fcf_record *fcf_record, | |
15948 | uint16_t fcf_index) | |
15949 | { | |
15950 | memset(fcf_record, 0, sizeof(struct fcf_record)); | |
15951 | fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE; | |
15952 | fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER; | |
15953 | fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY; | |
15954 | bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]); | |
15955 | bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]); | |
15956 | bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]); | |
15957 | bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3); | |
15958 | bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4); | |
15959 | bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5); | |
15960 | bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]); | |
15961 | bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]); | |
15962 | bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]); | |
15963 | bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1); | |
0c287589 | 15964 | bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1); |
6fb120a7 JS |
15965 | bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index); |
15966 | bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record, | |
15967 | LPFC_FCF_FPMA | LPFC_FCF_SPMA); | |
15968 | /* Set the VLAN bit map */ | |
15969 | if (phba->valid_vlan) { | |
15970 | fcf_record->vlan_bitmap[phba->vlan_id / 8] | |
15971 | = 1 << (phba->vlan_id % 8); | |
15972 | } | |
15973 | } | |
15974 | ||
15975 | /** | |
0c9ab6f5 | 15976 | * lpfc_sli4_fcf_scan_read_fcf_rec - Read hba fcf record for fcf scan. |
6fb120a7 JS |
15977 | * @phba: pointer to lpfc hba data structure. |
15978 | * @fcf_index: FCF table entry offset. | |
15979 | * | |
0c9ab6f5 JS |
15980 | * This routine is invoked to scan the entire FCF table by reading FCF |
15981 | * record and processing it one at a time starting from the @fcf_index | |
15982 | * for initial FCF discovery or fast FCF failover rediscovery. | |
15983 | * | |
25985edc | 15984 | * Return 0 if the mailbox command is submitted successfully, none 0 |
0c9ab6f5 | 15985 | * otherwise. |
6fb120a7 JS |
15986 | **/ |
15987 | int | |
0c9ab6f5 | 15988 | lpfc_sli4_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) |
6fb120a7 JS |
15989 | { |
15990 | int rc = 0, error; | |
15991 | LPFC_MBOXQ_t *mboxq; | |
6fb120a7 | 15992 | |
32b9793f | 15993 | phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag; |
80c17849 | 15994 | phba->fcoe_cvl_eventtag_attn = phba->fcoe_cvl_eventtag; |
6fb120a7 JS |
15995 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
15996 | if (!mboxq) { | |
15997 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
15998 | "2000 Failed to allocate mbox for " | |
15999 | "READ_FCF cmd\n"); | |
4d9ab994 | 16000 | error = -ENOMEM; |
0c9ab6f5 | 16001 | goto fail_fcf_scan; |
6fb120a7 | 16002 | } |
ecfd03c6 | 16003 | /* Construct the read FCF record mailbox command */ |
0c9ab6f5 | 16004 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
ecfd03c6 JS |
16005 | if (rc) { |
16006 | error = -EINVAL; | |
0c9ab6f5 | 16007 | goto fail_fcf_scan; |
6fb120a7 | 16008 | } |
ecfd03c6 | 16009 | /* Issue the mailbox command asynchronously */ |
6fb120a7 | 16010 | mboxq->vport = phba->pport; |
0c9ab6f5 | 16011 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec; |
a93ff37a JS |
16012 | |
16013 | spin_lock_irq(&phba->hbalock); | |
16014 | phba->hba_flag |= FCF_TS_INPROG; | |
16015 | spin_unlock_irq(&phba->hbalock); | |
16016 | ||
6fb120a7 | 16017 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
ecfd03c6 | 16018 | if (rc == MBX_NOT_FINISHED) |
6fb120a7 | 16019 | error = -EIO; |
ecfd03c6 | 16020 | else { |
38b92ef8 JS |
16021 | /* Reset eligible FCF count for new scan */ |
16022 | if (fcf_index == LPFC_FCOE_FCF_GET_FIRST) | |
999d813f | 16023 | phba->fcf.eligible_fcf_cnt = 0; |
6fb120a7 | 16024 | error = 0; |
32b9793f | 16025 | } |
0c9ab6f5 | 16026 | fail_fcf_scan: |
4d9ab994 JS |
16027 | if (error) { |
16028 | if (mboxq) | |
16029 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
a93ff37a | 16030 | /* FCF scan failed, clear FCF_TS_INPROG flag */ |
4d9ab994 | 16031 | spin_lock_irq(&phba->hbalock); |
a93ff37a | 16032 | phba->hba_flag &= ~FCF_TS_INPROG; |
4d9ab994 JS |
16033 | spin_unlock_irq(&phba->hbalock); |
16034 | } | |
6fb120a7 JS |
16035 | return error; |
16036 | } | |
a0c87cbd | 16037 | |
0c9ab6f5 | 16038 | /** |
a93ff37a | 16039 | * lpfc_sli4_fcf_rr_read_fcf_rec - Read hba fcf record for roundrobin fcf. |
0c9ab6f5 JS |
16040 | * @phba: pointer to lpfc hba data structure. |
16041 | * @fcf_index: FCF table entry offset. | |
16042 | * | |
16043 | * This routine is invoked to read an FCF record indicated by @fcf_index | |
a93ff37a | 16044 | * and to use it for FLOGI roundrobin FCF failover. |
0c9ab6f5 | 16045 | * |
25985edc | 16046 | * Return 0 if the mailbox command is submitted successfully, none 0 |
0c9ab6f5 JS |
16047 | * otherwise. |
16048 | **/ | |
16049 | int | |
16050 | lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) | |
16051 | { | |
16052 | int rc = 0, error; | |
16053 | LPFC_MBOXQ_t *mboxq; | |
16054 | ||
16055 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
16056 | if (!mboxq) { | |
16057 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT, | |
16058 | "2763 Failed to allocate mbox for " | |
16059 | "READ_FCF cmd\n"); | |
16060 | error = -ENOMEM; | |
16061 | goto fail_fcf_read; | |
16062 | } | |
16063 | /* Construct the read FCF record mailbox command */ | |
16064 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); | |
16065 | if (rc) { | |
16066 | error = -EINVAL; | |
16067 | goto fail_fcf_read; | |
16068 | } | |
16069 | /* Issue the mailbox command asynchronously */ | |
16070 | mboxq->vport = phba->pport; | |
16071 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec; | |
16072 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); | |
16073 | if (rc == MBX_NOT_FINISHED) | |
16074 | error = -EIO; | |
16075 | else | |
16076 | error = 0; | |
16077 | ||
16078 | fail_fcf_read: | |
16079 | if (error && mboxq) | |
16080 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
16081 | return error; | |
16082 | } | |
16083 | ||
16084 | /** | |
16085 | * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask. | |
16086 | * @phba: pointer to lpfc hba data structure. | |
16087 | * @fcf_index: FCF table entry offset. | |
16088 | * | |
16089 | * This routine is invoked to read an FCF record indicated by @fcf_index to | |
a93ff37a | 16090 | * determine whether it's eligible for FLOGI roundrobin failover list. |
0c9ab6f5 | 16091 | * |
25985edc | 16092 | * Return 0 if the mailbox command is submitted successfully, none 0 |
0c9ab6f5 JS |
16093 | * otherwise. |
16094 | **/ | |
16095 | int | |
16096 | lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) | |
16097 | { | |
16098 | int rc = 0, error; | |
16099 | LPFC_MBOXQ_t *mboxq; | |
16100 | ||
16101 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
16102 | if (!mboxq) { | |
16103 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT, | |
16104 | "2758 Failed to allocate mbox for " | |
16105 | "READ_FCF cmd\n"); | |
16106 | error = -ENOMEM; | |
16107 | goto fail_fcf_read; | |
16108 | } | |
16109 | /* Construct the read FCF record mailbox command */ | |
16110 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); | |
16111 | if (rc) { | |
16112 | error = -EINVAL; | |
16113 | goto fail_fcf_read; | |
16114 | } | |
16115 | /* Issue the mailbox command asynchronously */ | |
16116 | mboxq->vport = phba->pport; | |
16117 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec; | |
16118 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); | |
16119 | if (rc == MBX_NOT_FINISHED) | |
16120 | error = -EIO; | |
16121 | else | |
16122 | error = 0; | |
16123 | ||
16124 | fail_fcf_read: | |
16125 | if (error && mboxq) | |
16126 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
16127 | return error; | |
16128 | } | |
16129 | ||
7d791df7 JS |
16130 | /** |
16131 | * lpfc_check_next_fcf_pri | |
16132 | * phba pointer to the lpfc_hba struct for this port. | |
16133 | * This routine is called from the lpfc_sli4_fcf_rr_next_index_get | |
16134 | * routine when the rr_bmask is empty. The FCF indecies are put into the | |
16135 | * rr_bmask based on their priority level. Starting from the highest priority | |
16136 | * to the lowest. The most likely FCF candidate will be in the highest | |
16137 | * priority group. When this routine is called it searches the fcf_pri list for | |
16138 | * next lowest priority group and repopulates the rr_bmask with only those | |
16139 | * fcf_indexes. | |
16140 | * returns: | |
16141 | * 1=success 0=failure | |
16142 | **/ | |
5d8b8167 | 16143 | static int |
7d791df7 JS |
16144 | lpfc_check_next_fcf_pri_level(struct lpfc_hba *phba) |
16145 | { | |
16146 | uint16_t next_fcf_pri; | |
16147 | uint16_t last_index; | |
16148 | struct lpfc_fcf_pri *fcf_pri; | |
16149 | int rc; | |
16150 | int ret = 0; | |
16151 | ||
16152 | last_index = find_first_bit(phba->fcf.fcf_rr_bmask, | |
16153 | LPFC_SLI4_FCF_TBL_INDX_MAX); | |
16154 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, | |
16155 | "3060 Last IDX %d\n", last_index); | |
2562669c JS |
16156 | |
16157 | /* Verify the priority list has 2 or more entries */ | |
16158 | spin_lock_irq(&phba->hbalock); | |
16159 | if (list_empty(&phba->fcf.fcf_pri_list) || | |
16160 | list_is_singular(&phba->fcf.fcf_pri_list)) { | |
16161 | spin_unlock_irq(&phba->hbalock); | |
7d791df7 JS |
16162 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
16163 | "3061 Last IDX %d\n", last_index); | |
16164 | return 0; /* Empty rr list */ | |
16165 | } | |
2562669c JS |
16166 | spin_unlock_irq(&phba->hbalock); |
16167 | ||
7d791df7 JS |
16168 | next_fcf_pri = 0; |
16169 | /* | |
16170 | * Clear the rr_bmask and set all of the bits that are at this | |
16171 | * priority. | |
16172 | */ | |
16173 | memset(phba->fcf.fcf_rr_bmask, 0, | |
16174 | sizeof(*phba->fcf.fcf_rr_bmask)); | |
16175 | spin_lock_irq(&phba->hbalock); | |
16176 | list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) { | |
16177 | if (fcf_pri->fcf_rec.flag & LPFC_FCF_FLOGI_FAILED) | |
16178 | continue; | |
16179 | /* | |
16180 | * the 1st priority that has not FLOGI failed | |
16181 | * will be the highest. | |
16182 | */ | |
16183 | if (!next_fcf_pri) | |
16184 | next_fcf_pri = fcf_pri->fcf_rec.priority; | |
16185 | spin_unlock_irq(&phba->hbalock); | |
16186 | if (fcf_pri->fcf_rec.priority == next_fcf_pri) { | |
16187 | rc = lpfc_sli4_fcf_rr_index_set(phba, | |
16188 | fcf_pri->fcf_rec.fcf_index); | |
16189 | if (rc) | |
16190 | return 0; | |
16191 | } | |
16192 | spin_lock_irq(&phba->hbalock); | |
16193 | } | |
16194 | /* | |
16195 | * if next_fcf_pri was not set above and the list is not empty then | |
16196 | * we have failed flogis on all of them. So reset flogi failed | |
4907cb7b | 16197 | * and start at the beginning. |
7d791df7 JS |
16198 | */ |
16199 | if (!next_fcf_pri && !list_empty(&phba->fcf.fcf_pri_list)) { | |
16200 | list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) { | |
16201 | fcf_pri->fcf_rec.flag &= ~LPFC_FCF_FLOGI_FAILED; | |
16202 | /* | |
16203 | * the 1st priority that has not FLOGI failed | |
16204 | * will be the highest. | |
16205 | */ | |
16206 | if (!next_fcf_pri) | |
16207 | next_fcf_pri = fcf_pri->fcf_rec.priority; | |
16208 | spin_unlock_irq(&phba->hbalock); | |
16209 | if (fcf_pri->fcf_rec.priority == next_fcf_pri) { | |
16210 | rc = lpfc_sli4_fcf_rr_index_set(phba, | |
16211 | fcf_pri->fcf_rec.fcf_index); | |
16212 | if (rc) | |
16213 | return 0; | |
16214 | } | |
16215 | spin_lock_irq(&phba->hbalock); | |
16216 | } | |
16217 | } else | |
16218 | ret = 1; | |
16219 | spin_unlock_irq(&phba->hbalock); | |
16220 | ||
16221 | return ret; | |
16222 | } | |
0c9ab6f5 JS |
16223 | /** |
16224 | * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index | |
16225 | * @phba: pointer to lpfc hba data structure. | |
16226 | * | |
16227 | * This routine is to get the next eligible FCF record index in a round | |
16228 | * robin fashion. If the next eligible FCF record index equals to the | |
a93ff37a | 16229 | * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF) |
0c9ab6f5 JS |
16230 | * shall be returned, otherwise, the next eligible FCF record's index |
16231 | * shall be returned. | |
16232 | **/ | |
16233 | uint16_t | |
16234 | lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba) | |
16235 | { | |
16236 | uint16_t next_fcf_index; | |
16237 | ||
421c6622 | 16238 | initial_priority: |
3804dc84 | 16239 | /* Search start from next bit of currently registered FCF index */ |
421c6622 JS |
16240 | next_fcf_index = phba->fcf.current_rec.fcf_indx; |
16241 | ||
7d791df7 | 16242 | next_priority: |
421c6622 JS |
16243 | /* Determine the next fcf index to check */ |
16244 | next_fcf_index = (next_fcf_index + 1) % LPFC_SLI4_FCF_TBL_INDX_MAX; | |
0c9ab6f5 JS |
16245 | next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask, |
16246 | LPFC_SLI4_FCF_TBL_INDX_MAX, | |
3804dc84 JS |
16247 | next_fcf_index); |
16248 | ||
0c9ab6f5 | 16249 | /* Wrap around condition on phba->fcf.fcf_rr_bmask */ |
7d791df7 JS |
16250 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
16251 | /* | |
16252 | * If we have wrapped then we need to clear the bits that | |
16253 | * have been tested so that we can detect when we should | |
16254 | * change the priority level. | |
16255 | */ | |
0c9ab6f5 JS |
16256 | next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask, |
16257 | LPFC_SLI4_FCF_TBL_INDX_MAX, 0); | |
7d791df7 JS |
16258 | } |
16259 | ||
3804dc84 JS |
16260 | |
16261 | /* Check roundrobin failover list empty condition */ | |
7d791df7 JS |
16262 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX || |
16263 | next_fcf_index == phba->fcf.current_rec.fcf_indx) { | |
16264 | /* | |
16265 | * If next fcf index is not found check if there are lower | |
16266 | * Priority level fcf's in the fcf_priority list. | |
16267 | * Set up the rr_bmask with all of the avaiable fcf bits | |
16268 | * at that level and continue the selection process. | |
16269 | */ | |
16270 | if (lpfc_check_next_fcf_pri_level(phba)) | |
421c6622 | 16271 | goto initial_priority; |
3804dc84 JS |
16272 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
16273 | "2844 No roundrobin failover FCF available\n"); | |
7d791df7 JS |
16274 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) |
16275 | return LPFC_FCOE_FCF_NEXT_NONE; | |
16276 | else { | |
16277 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, | |
16278 | "3063 Only FCF available idx %d, flag %x\n", | |
16279 | next_fcf_index, | |
16280 | phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag); | |
16281 | return next_fcf_index; | |
16282 | } | |
3804dc84 JS |
16283 | } |
16284 | ||
7d791df7 JS |
16285 | if (next_fcf_index < LPFC_SLI4_FCF_TBL_INDX_MAX && |
16286 | phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag & | |
16287 | LPFC_FCF_FLOGI_FAILED) | |
16288 | goto next_priority; | |
16289 | ||
3804dc84 | 16290 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
a93ff37a JS |
16291 | "2845 Get next roundrobin failover FCF (x%x)\n", |
16292 | next_fcf_index); | |
16293 | ||
0c9ab6f5 JS |
16294 | return next_fcf_index; |
16295 | } | |
16296 | ||
16297 | /** | |
16298 | * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index | |
16299 | * @phba: pointer to lpfc hba data structure. | |
16300 | * | |
16301 | * This routine sets the FCF record index in to the eligible bmask for | |
a93ff37a | 16302 | * roundrobin failover search. It checks to make sure that the index |
0c9ab6f5 JS |
16303 | * does not go beyond the range of the driver allocated bmask dimension |
16304 | * before setting the bit. | |
16305 | * | |
16306 | * Returns 0 if the index bit successfully set, otherwise, it returns | |
16307 | * -EINVAL. | |
16308 | **/ | |
16309 | int | |
16310 | lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index) | |
16311 | { | |
16312 | if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { | |
16313 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, | |
a93ff37a JS |
16314 | "2610 FCF (x%x) reached driver's book " |
16315 | "keeping dimension:x%x\n", | |
0c9ab6f5 JS |
16316 | fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX); |
16317 | return -EINVAL; | |
16318 | } | |
16319 | /* Set the eligible FCF record index bmask */ | |
16320 | set_bit(fcf_index, phba->fcf.fcf_rr_bmask); | |
16321 | ||
3804dc84 | 16322 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
a93ff37a | 16323 | "2790 Set FCF (x%x) to roundrobin FCF failover " |
3804dc84 JS |
16324 | "bmask\n", fcf_index); |
16325 | ||
0c9ab6f5 JS |
16326 | return 0; |
16327 | } | |
16328 | ||
16329 | /** | |
3804dc84 | 16330 | * lpfc_sli4_fcf_rr_index_clear - Clear bmask from eligible fcf record index |
0c9ab6f5 JS |
16331 | * @phba: pointer to lpfc hba data structure. |
16332 | * | |
16333 | * This routine clears the FCF record index from the eligible bmask for | |
a93ff37a | 16334 | * roundrobin failover search. It checks to make sure that the index |
0c9ab6f5 JS |
16335 | * does not go beyond the range of the driver allocated bmask dimension |
16336 | * before clearing the bit. | |
16337 | **/ | |
16338 | void | |
16339 | lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index) | |
16340 | { | |
9a803a74 | 16341 | struct lpfc_fcf_pri *fcf_pri, *fcf_pri_next; |
0c9ab6f5 JS |
16342 | if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
16343 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, | |
a93ff37a JS |
16344 | "2762 FCF (x%x) reached driver's book " |
16345 | "keeping dimension:x%x\n", | |
0c9ab6f5 JS |
16346 | fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX); |
16347 | return; | |
16348 | } | |
16349 | /* Clear the eligible FCF record index bmask */ | |
7d791df7 | 16350 | spin_lock_irq(&phba->hbalock); |
9a803a74 JS |
16351 | list_for_each_entry_safe(fcf_pri, fcf_pri_next, &phba->fcf.fcf_pri_list, |
16352 | list) { | |
7d791df7 JS |
16353 | if (fcf_pri->fcf_rec.fcf_index == fcf_index) { |
16354 | list_del_init(&fcf_pri->list); | |
16355 | break; | |
16356 | } | |
16357 | } | |
16358 | spin_unlock_irq(&phba->hbalock); | |
0c9ab6f5 | 16359 | clear_bit(fcf_index, phba->fcf.fcf_rr_bmask); |
3804dc84 JS |
16360 | |
16361 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, | |
a93ff37a | 16362 | "2791 Clear FCF (x%x) from roundrobin failover " |
3804dc84 | 16363 | "bmask\n", fcf_index); |
0c9ab6f5 JS |
16364 | } |
16365 | ||
ecfd03c6 JS |
16366 | /** |
16367 | * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table | |
16368 | * @phba: pointer to lpfc hba data structure. | |
16369 | * | |
16370 | * This routine is the completion routine for the rediscover FCF table mailbox | |
16371 | * command. If the mailbox command returned failure, it will try to stop the | |
16372 | * FCF rediscover wait timer. | |
16373 | **/ | |
5d8b8167 | 16374 | static void |
ecfd03c6 JS |
16375 | lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox) |
16376 | { | |
16377 | struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf; | |
16378 | uint32_t shdr_status, shdr_add_status; | |
16379 | ||
16380 | redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl; | |
16381 | ||
16382 | shdr_status = bf_get(lpfc_mbox_hdr_status, | |
16383 | &redisc_fcf->header.cfg_shdr.response); | |
16384 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, | |
16385 | &redisc_fcf->header.cfg_shdr.response); | |
16386 | if (shdr_status || shdr_add_status) { | |
0c9ab6f5 | 16387 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
ecfd03c6 JS |
16388 | "2746 Requesting for FCF rediscovery failed " |
16389 | "status x%x add_status x%x\n", | |
16390 | shdr_status, shdr_add_status); | |
0c9ab6f5 | 16391 | if (phba->fcf.fcf_flag & FCF_ACVL_DISC) { |
fc2b989b | 16392 | spin_lock_irq(&phba->hbalock); |
0c9ab6f5 | 16393 | phba->fcf.fcf_flag &= ~FCF_ACVL_DISC; |
fc2b989b JS |
16394 | spin_unlock_irq(&phba->hbalock); |
16395 | /* | |
16396 | * CVL event triggered FCF rediscover request failed, | |
16397 | * last resort to re-try current registered FCF entry. | |
16398 | */ | |
16399 | lpfc_retry_pport_discovery(phba); | |
16400 | } else { | |
16401 | spin_lock_irq(&phba->hbalock); | |
0c9ab6f5 | 16402 | phba->fcf.fcf_flag &= ~FCF_DEAD_DISC; |
fc2b989b JS |
16403 | spin_unlock_irq(&phba->hbalock); |
16404 | /* | |
16405 | * DEAD FCF event triggered FCF rediscover request | |
16406 | * failed, last resort to fail over as a link down | |
16407 | * to FCF registration. | |
16408 | */ | |
16409 | lpfc_sli4_fcf_dead_failthrough(phba); | |
16410 | } | |
0c9ab6f5 JS |
16411 | } else { |
16412 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, | |
a93ff37a | 16413 | "2775 Start FCF rediscover quiescent timer\n"); |
ecfd03c6 JS |
16414 | /* |
16415 | * Start FCF rediscovery wait timer for pending FCF | |
16416 | * before rescan FCF record table. | |
16417 | */ | |
16418 | lpfc_fcf_redisc_wait_start_timer(phba); | |
0c9ab6f5 | 16419 | } |
ecfd03c6 JS |
16420 | |
16421 | mempool_free(mbox, phba->mbox_mem_pool); | |
16422 | } | |
16423 | ||
16424 | /** | |
3804dc84 | 16425 | * lpfc_sli4_redisc_fcf_table - Request to rediscover entire FCF table by port. |
ecfd03c6 JS |
16426 | * @phba: pointer to lpfc hba data structure. |
16427 | * | |
16428 | * This routine is invoked to request for rediscovery of the entire FCF table | |
16429 | * by the port. | |
16430 | **/ | |
16431 | int | |
16432 | lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba) | |
16433 | { | |
16434 | LPFC_MBOXQ_t *mbox; | |
16435 | struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf; | |
16436 | int rc, length; | |
16437 | ||
0c9ab6f5 JS |
16438 | /* Cancel retry delay timers to all vports before FCF rediscover */ |
16439 | lpfc_cancel_all_vport_retry_delay_timer(phba); | |
16440 | ||
ecfd03c6 JS |
16441 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
16442 | if (!mbox) { | |
16443 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
16444 | "2745 Failed to allocate mbox for " | |
16445 | "requesting FCF rediscover.\n"); | |
16446 | return -ENOMEM; | |
16447 | } | |
16448 | ||
16449 | length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) - | |
16450 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
16451 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
16452 | LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF, | |
16453 | length, LPFC_SLI4_MBX_EMBED); | |
16454 | ||
16455 | redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl; | |
16456 | /* Set count to 0 for invalidating the entire FCF database */ | |
16457 | bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0); | |
16458 | ||
16459 | /* Issue the mailbox command asynchronously */ | |
16460 | mbox->vport = phba->pport; | |
16461 | mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table; | |
16462 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); | |
16463 | ||
16464 | if (rc == MBX_NOT_FINISHED) { | |
16465 | mempool_free(mbox, phba->mbox_mem_pool); | |
16466 | return -EIO; | |
16467 | } | |
16468 | return 0; | |
16469 | } | |
16470 | ||
fc2b989b JS |
16471 | /** |
16472 | * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event | |
16473 | * @phba: pointer to lpfc hba data structure. | |
16474 | * | |
16475 | * This function is the failover routine as a last resort to the FCF DEAD | |
16476 | * event when driver failed to perform fast FCF failover. | |
16477 | **/ | |
16478 | void | |
16479 | lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba) | |
16480 | { | |
16481 | uint32_t link_state; | |
16482 | ||
16483 | /* | |
16484 | * Last resort as FCF DEAD event failover will treat this as | |
16485 | * a link down, but save the link state because we don't want | |
16486 | * it to be changed to Link Down unless it is already down. | |
16487 | */ | |
16488 | link_state = phba->link_state; | |
16489 | lpfc_linkdown(phba); | |
16490 | phba->link_state = link_state; | |
16491 | ||
16492 | /* Unregister FCF if no devices connected to it */ | |
16493 | lpfc_unregister_unused_fcf(phba); | |
16494 | } | |
16495 | ||
a0c87cbd | 16496 | /** |
026abb87 | 16497 | * lpfc_sli_get_config_region23 - Get sli3 port region 23 data. |
a0c87cbd | 16498 | * @phba: pointer to lpfc hba data structure. |
026abb87 | 16499 | * @rgn23_data: pointer to configure region 23 data. |
a0c87cbd | 16500 | * |
026abb87 JS |
16501 | * This function gets SLI3 port configure region 23 data through memory dump |
16502 | * mailbox command. When it successfully retrieves data, the size of the data | |
16503 | * will be returned, otherwise, 0 will be returned. | |
a0c87cbd | 16504 | **/ |
026abb87 JS |
16505 | static uint32_t |
16506 | lpfc_sli_get_config_region23(struct lpfc_hba *phba, char *rgn23_data) | |
a0c87cbd JS |
16507 | { |
16508 | LPFC_MBOXQ_t *pmb = NULL; | |
16509 | MAILBOX_t *mb; | |
026abb87 | 16510 | uint32_t offset = 0; |
a0c87cbd JS |
16511 | int rc; |
16512 | ||
026abb87 JS |
16513 | if (!rgn23_data) |
16514 | return 0; | |
16515 | ||
a0c87cbd JS |
16516 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
16517 | if (!pmb) { | |
16518 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
026abb87 JS |
16519 | "2600 failed to allocate mailbox memory\n"); |
16520 | return 0; | |
a0c87cbd JS |
16521 | } |
16522 | mb = &pmb->u.mb; | |
16523 | ||
a0c87cbd JS |
16524 | do { |
16525 | lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23); | |
16526 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); | |
16527 | ||
16528 | if (rc != MBX_SUCCESS) { | |
16529 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
026abb87 JS |
16530 | "2601 failed to read config " |
16531 | "region 23, rc 0x%x Status 0x%x\n", | |
16532 | rc, mb->mbxStatus); | |
a0c87cbd JS |
16533 | mb->un.varDmp.word_cnt = 0; |
16534 | } | |
16535 | /* | |
16536 | * dump mem may return a zero when finished or we got a | |
16537 | * mailbox error, either way we are done. | |
16538 | */ | |
16539 | if (mb->un.varDmp.word_cnt == 0) | |
16540 | break; | |
16541 | if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset) | |
16542 | mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset; | |
16543 | ||
16544 | lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET, | |
026abb87 JS |
16545 | rgn23_data + offset, |
16546 | mb->un.varDmp.word_cnt); | |
a0c87cbd JS |
16547 | offset += mb->un.varDmp.word_cnt; |
16548 | } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE); | |
16549 | ||
026abb87 JS |
16550 | mempool_free(pmb, phba->mbox_mem_pool); |
16551 | return offset; | |
16552 | } | |
16553 | ||
16554 | /** | |
16555 | * lpfc_sli4_get_config_region23 - Get sli4 port region 23 data. | |
16556 | * @phba: pointer to lpfc hba data structure. | |
16557 | * @rgn23_data: pointer to configure region 23 data. | |
16558 | * | |
16559 | * This function gets SLI4 port configure region 23 data through memory dump | |
16560 | * mailbox command. When it successfully retrieves data, the size of the data | |
16561 | * will be returned, otherwise, 0 will be returned. | |
16562 | **/ | |
16563 | static uint32_t | |
16564 | lpfc_sli4_get_config_region23(struct lpfc_hba *phba, char *rgn23_data) | |
16565 | { | |
16566 | LPFC_MBOXQ_t *mboxq = NULL; | |
16567 | struct lpfc_dmabuf *mp = NULL; | |
16568 | struct lpfc_mqe *mqe; | |
16569 | uint32_t data_length = 0; | |
16570 | int rc; | |
16571 | ||
16572 | if (!rgn23_data) | |
16573 | return 0; | |
16574 | ||
16575 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
16576 | if (!mboxq) { | |
16577 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
16578 | "3105 failed to allocate mailbox memory\n"); | |
16579 | return 0; | |
16580 | } | |
16581 | ||
16582 | if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) | |
16583 | goto out; | |
16584 | mqe = &mboxq->u.mqe; | |
16585 | mp = (struct lpfc_dmabuf *) mboxq->context1; | |
16586 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
16587 | if (rc) | |
16588 | goto out; | |
16589 | data_length = mqe->un.mb_words[5]; | |
16590 | if (data_length == 0) | |
16591 | goto out; | |
16592 | if (data_length > DMP_RGN23_SIZE) { | |
16593 | data_length = 0; | |
16594 | goto out; | |
16595 | } | |
16596 | lpfc_sli_pcimem_bcopy((char *)mp->virt, rgn23_data, data_length); | |
16597 | out: | |
16598 | mempool_free(mboxq, phba->mbox_mem_pool); | |
16599 | if (mp) { | |
16600 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
16601 | kfree(mp); | |
16602 | } | |
16603 | return data_length; | |
16604 | } | |
16605 | ||
16606 | /** | |
16607 | * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled. | |
16608 | * @phba: pointer to lpfc hba data structure. | |
16609 | * | |
16610 | * This function read region 23 and parse TLV for port status to | |
16611 | * decide if the user disaled the port. If the TLV indicates the | |
16612 | * port is disabled, the hba_flag is set accordingly. | |
16613 | **/ | |
16614 | void | |
16615 | lpfc_sli_read_link_ste(struct lpfc_hba *phba) | |
16616 | { | |
16617 | uint8_t *rgn23_data = NULL; | |
16618 | uint32_t if_type, data_size, sub_tlv_len, tlv_offset; | |
16619 | uint32_t offset = 0; | |
16620 | ||
16621 | /* Get adapter Region 23 data */ | |
16622 | rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL); | |
16623 | if (!rgn23_data) | |
16624 | goto out; | |
16625 | ||
16626 | if (phba->sli_rev < LPFC_SLI_REV4) | |
16627 | data_size = lpfc_sli_get_config_region23(phba, rgn23_data); | |
16628 | else { | |
16629 | if_type = bf_get(lpfc_sli_intf_if_type, | |
16630 | &phba->sli4_hba.sli_intf); | |
16631 | if (if_type == LPFC_SLI_INTF_IF_TYPE_0) | |
16632 | goto out; | |
16633 | data_size = lpfc_sli4_get_config_region23(phba, rgn23_data); | |
16634 | } | |
a0c87cbd JS |
16635 | |
16636 | if (!data_size) | |
16637 | goto out; | |
16638 | ||
16639 | /* Check the region signature first */ | |
16640 | if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) { | |
16641 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
16642 | "2619 Config region 23 has bad signature\n"); | |
16643 | goto out; | |
16644 | } | |
16645 | offset += 4; | |
16646 | ||
16647 | /* Check the data structure version */ | |
16648 | if (rgn23_data[offset] != LPFC_REGION23_VERSION) { | |
16649 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
16650 | "2620 Config region 23 has bad version\n"); | |
16651 | goto out; | |
16652 | } | |
16653 | offset += 4; | |
16654 | ||
16655 | /* Parse TLV entries in the region */ | |
16656 | while (offset < data_size) { | |
16657 | if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) | |
16658 | break; | |
16659 | /* | |
16660 | * If the TLV is not driver specific TLV or driver id is | |
16661 | * not linux driver id, skip the record. | |
16662 | */ | |
16663 | if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) || | |
16664 | (rgn23_data[offset + 2] != LINUX_DRIVER_ID) || | |
16665 | (rgn23_data[offset + 3] != 0)) { | |
16666 | offset += rgn23_data[offset + 1] * 4 + 4; | |
16667 | continue; | |
16668 | } | |
16669 | ||
16670 | /* Driver found a driver specific TLV in the config region */ | |
16671 | sub_tlv_len = rgn23_data[offset + 1] * 4; | |
16672 | offset += 4; | |
16673 | tlv_offset = 0; | |
16674 | ||
16675 | /* | |
16676 | * Search for configured port state sub-TLV. | |
16677 | */ | |
16678 | while ((offset < data_size) && | |
16679 | (tlv_offset < sub_tlv_len)) { | |
16680 | if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) { | |
16681 | offset += 4; | |
16682 | tlv_offset += 4; | |
16683 | break; | |
16684 | } | |
16685 | if (rgn23_data[offset] != PORT_STE_TYPE) { | |
16686 | offset += rgn23_data[offset + 1] * 4 + 4; | |
16687 | tlv_offset += rgn23_data[offset + 1] * 4 + 4; | |
16688 | continue; | |
16689 | } | |
16690 | ||
16691 | /* This HBA contains PORT_STE configured */ | |
16692 | if (!rgn23_data[offset + 2]) | |
16693 | phba->hba_flag |= LINK_DISABLED; | |
16694 | ||
16695 | goto out; | |
16696 | } | |
16697 | } | |
026abb87 | 16698 | |
a0c87cbd | 16699 | out: |
a0c87cbd JS |
16700 | kfree(rgn23_data); |
16701 | return; | |
16702 | } | |
695a814e | 16703 | |
52d52440 JS |
16704 | /** |
16705 | * lpfc_wr_object - write an object to the firmware | |
16706 | * @phba: HBA structure that indicates port to create a queue on. | |
16707 | * @dmabuf_list: list of dmabufs to write to the port. | |
16708 | * @size: the total byte value of the objects to write to the port. | |
16709 | * @offset: the current offset to be used to start the transfer. | |
16710 | * | |
16711 | * This routine will create a wr_object mailbox command to send to the port. | |
16712 | * the mailbox command will be constructed using the dma buffers described in | |
16713 | * @dmabuf_list to create a list of BDEs. This routine will fill in as many | |
16714 | * BDEs that the imbedded mailbox can support. The @offset variable will be | |
16715 | * used to indicate the starting offset of the transfer and will also return | |
16716 | * the offset after the write object mailbox has completed. @size is used to | |
16717 | * determine the end of the object and whether the eof bit should be set. | |
16718 | * | |
16719 | * Return 0 is successful and offset will contain the the new offset to use | |
16720 | * for the next write. | |
16721 | * Return negative value for error cases. | |
16722 | **/ | |
16723 | int | |
16724 | lpfc_wr_object(struct lpfc_hba *phba, struct list_head *dmabuf_list, | |
16725 | uint32_t size, uint32_t *offset) | |
16726 | { | |
16727 | struct lpfc_mbx_wr_object *wr_object; | |
16728 | LPFC_MBOXQ_t *mbox; | |
16729 | int rc = 0, i = 0; | |
16730 | uint32_t shdr_status, shdr_add_status; | |
16731 | uint32_t mbox_tmo; | |
16732 | union lpfc_sli4_cfg_shdr *shdr; | |
16733 | struct lpfc_dmabuf *dmabuf; | |
16734 | uint32_t written = 0; | |
16735 | ||
16736 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
16737 | if (!mbox) | |
16738 | return -ENOMEM; | |
16739 | ||
16740 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
16741 | LPFC_MBOX_OPCODE_WRITE_OBJECT, | |
16742 | sizeof(struct lpfc_mbx_wr_object) - | |
16743 | sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED); | |
16744 | ||
16745 | wr_object = (struct lpfc_mbx_wr_object *)&mbox->u.mqe.un.wr_object; | |
16746 | wr_object->u.request.write_offset = *offset; | |
16747 | sprintf((uint8_t *)wr_object->u.request.object_name, "/"); | |
16748 | wr_object->u.request.object_name[0] = | |
16749 | cpu_to_le32(wr_object->u.request.object_name[0]); | |
16750 | bf_set(lpfc_wr_object_eof, &wr_object->u.request, 0); | |
16751 | list_for_each_entry(dmabuf, dmabuf_list, list) { | |
16752 | if (i >= LPFC_MBX_WR_CONFIG_MAX_BDE || written >= size) | |
16753 | break; | |
16754 | wr_object->u.request.bde[i].addrLow = putPaddrLow(dmabuf->phys); | |
16755 | wr_object->u.request.bde[i].addrHigh = | |
16756 | putPaddrHigh(dmabuf->phys); | |
16757 | if (written + SLI4_PAGE_SIZE >= size) { | |
16758 | wr_object->u.request.bde[i].tus.f.bdeSize = | |
16759 | (size - written); | |
16760 | written += (size - written); | |
16761 | bf_set(lpfc_wr_object_eof, &wr_object->u.request, 1); | |
16762 | } else { | |
16763 | wr_object->u.request.bde[i].tus.f.bdeSize = | |
16764 | SLI4_PAGE_SIZE; | |
16765 | written += SLI4_PAGE_SIZE; | |
16766 | } | |
16767 | i++; | |
16768 | } | |
16769 | wr_object->u.request.bde_count = i; | |
16770 | bf_set(lpfc_wr_object_write_length, &wr_object->u.request, written); | |
16771 | if (!phba->sli4_hba.intr_enable) | |
16772 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
16773 | else { | |
a183a15f | 16774 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
52d52440 JS |
16775 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
16776 | } | |
16777 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
16778 | shdr = (union lpfc_sli4_cfg_shdr *) &wr_object->header.cfg_shdr; | |
16779 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
16780 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
16781 | if (rc != MBX_TIMEOUT) | |
16782 | mempool_free(mbox, phba->mbox_mem_pool); | |
16783 | if (shdr_status || shdr_add_status || rc) { | |
16784 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
16785 | "3025 Write Object mailbox failed with " | |
16786 | "status x%x add_status x%x, mbx status x%x\n", | |
16787 | shdr_status, shdr_add_status, rc); | |
16788 | rc = -ENXIO; | |
16789 | } else | |
16790 | *offset += wr_object->u.response.actual_write_length; | |
16791 | return rc; | |
16792 | } | |
16793 | ||
695a814e JS |
16794 | /** |
16795 | * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands. | |
16796 | * @vport: pointer to vport data structure. | |
16797 | * | |
16798 | * This function iterate through the mailboxq and clean up all REG_LOGIN | |
16799 | * and REG_VPI mailbox commands associated with the vport. This function | |
16800 | * is called when driver want to restart discovery of the vport due to | |
16801 | * a Clear Virtual Link event. | |
16802 | **/ | |
16803 | void | |
16804 | lpfc_cleanup_pending_mbox(struct lpfc_vport *vport) | |
16805 | { | |
16806 | struct lpfc_hba *phba = vport->phba; | |
16807 | LPFC_MBOXQ_t *mb, *nextmb; | |
16808 | struct lpfc_dmabuf *mp; | |
78730cfe | 16809 | struct lpfc_nodelist *ndlp; |
d439d286 | 16810 | struct lpfc_nodelist *act_mbx_ndlp = NULL; |
589a52d6 | 16811 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
d439d286 | 16812 | LIST_HEAD(mbox_cmd_list); |
63e801ce | 16813 | uint8_t restart_loop; |
695a814e | 16814 | |
d439d286 | 16815 | /* Clean up internally queued mailbox commands with the vport */ |
695a814e JS |
16816 | spin_lock_irq(&phba->hbalock); |
16817 | list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) { | |
16818 | if (mb->vport != vport) | |
16819 | continue; | |
16820 | ||
16821 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) && | |
16822 | (mb->u.mb.mbxCommand != MBX_REG_VPI)) | |
16823 | continue; | |
16824 | ||
d439d286 JS |
16825 | list_del(&mb->list); |
16826 | list_add_tail(&mb->list, &mbox_cmd_list); | |
16827 | } | |
16828 | /* Clean up active mailbox command with the vport */ | |
16829 | mb = phba->sli.mbox_active; | |
16830 | if (mb && (mb->vport == vport)) { | |
16831 | if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) || | |
16832 | (mb->u.mb.mbxCommand == MBX_REG_VPI)) | |
16833 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
16834 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { | |
16835 | act_mbx_ndlp = (struct lpfc_nodelist *)mb->context2; | |
16836 | /* Put reference count for delayed processing */ | |
16837 | act_mbx_ndlp = lpfc_nlp_get(act_mbx_ndlp); | |
16838 | /* Unregister the RPI when mailbox complete */ | |
16839 | mb->mbox_flag |= LPFC_MBX_IMED_UNREG; | |
16840 | } | |
16841 | } | |
63e801ce JS |
16842 | /* Cleanup any mailbox completions which are not yet processed */ |
16843 | do { | |
16844 | restart_loop = 0; | |
16845 | list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) { | |
16846 | /* | |
16847 | * If this mailox is already processed or it is | |
16848 | * for another vport ignore it. | |
16849 | */ | |
16850 | if ((mb->vport != vport) || | |
16851 | (mb->mbox_flag & LPFC_MBX_IMED_UNREG)) | |
16852 | continue; | |
16853 | ||
16854 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) && | |
16855 | (mb->u.mb.mbxCommand != MBX_REG_VPI)) | |
16856 | continue; | |
16857 | ||
16858 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
16859 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { | |
16860 | ndlp = (struct lpfc_nodelist *)mb->context2; | |
16861 | /* Unregister the RPI when mailbox complete */ | |
16862 | mb->mbox_flag |= LPFC_MBX_IMED_UNREG; | |
16863 | restart_loop = 1; | |
16864 | spin_unlock_irq(&phba->hbalock); | |
16865 | spin_lock(shost->host_lock); | |
16866 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; | |
16867 | spin_unlock(shost->host_lock); | |
16868 | spin_lock_irq(&phba->hbalock); | |
16869 | break; | |
16870 | } | |
16871 | } | |
16872 | } while (restart_loop); | |
16873 | ||
d439d286 JS |
16874 | spin_unlock_irq(&phba->hbalock); |
16875 | ||
16876 | /* Release the cleaned-up mailbox commands */ | |
16877 | while (!list_empty(&mbox_cmd_list)) { | |
16878 | list_remove_head(&mbox_cmd_list, mb, LPFC_MBOXQ_t, list); | |
695a814e JS |
16879 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
16880 | mp = (struct lpfc_dmabuf *) (mb->context1); | |
16881 | if (mp) { | |
16882 | __lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
16883 | kfree(mp); | |
16884 | } | |
78730cfe | 16885 | ndlp = (struct lpfc_nodelist *) mb->context2; |
d439d286 | 16886 | mb->context2 = NULL; |
78730cfe | 16887 | if (ndlp) { |
ec21b3b0 | 16888 | spin_lock(shost->host_lock); |
589a52d6 | 16889 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
ec21b3b0 | 16890 | spin_unlock(shost->host_lock); |
78730cfe | 16891 | lpfc_nlp_put(ndlp); |
78730cfe | 16892 | } |
695a814e | 16893 | } |
695a814e JS |
16894 | mempool_free(mb, phba->mbox_mem_pool); |
16895 | } | |
d439d286 JS |
16896 | |
16897 | /* Release the ndlp with the cleaned-up active mailbox command */ | |
16898 | if (act_mbx_ndlp) { | |
16899 | spin_lock(shost->host_lock); | |
16900 | act_mbx_ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; | |
16901 | spin_unlock(shost->host_lock); | |
16902 | lpfc_nlp_put(act_mbx_ndlp); | |
695a814e | 16903 | } |
695a814e JS |
16904 | } |
16905 | ||
2a9bf3d0 JS |
16906 | /** |
16907 | * lpfc_drain_txq - Drain the txq | |
16908 | * @phba: Pointer to HBA context object. | |
16909 | * | |
16910 | * This function attempt to submit IOCBs on the txq | |
16911 | * to the adapter. For SLI4 adapters, the txq contains | |
16912 | * ELS IOCBs that have been deferred because the there | |
16913 | * are no SGLs. This congestion can occur with large | |
16914 | * vport counts during node discovery. | |
16915 | **/ | |
16916 | ||
16917 | uint32_t | |
16918 | lpfc_drain_txq(struct lpfc_hba *phba) | |
16919 | { | |
16920 | LIST_HEAD(completions); | |
16921 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; | |
2e706377 | 16922 | struct lpfc_iocbq *piocbq = NULL; |
2a9bf3d0 JS |
16923 | unsigned long iflags = 0; |
16924 | char *fail_msg = NULL; | |
16925 | struct lpfc_sglq *sglq; | |
16926 | union lpfc_wqe wqe; | |
0e9bb8d7 | 16927 | int txq_cnt = 0; |
2a9bf3d0 | 16928 | |
398d81c9 | 16929 | spin_lock_irqsave(&pring->ring_lock, iflags); |
0e9bb8d7 JS |
16930 | list_for_each_entry(piocbq, &pring->txq, list) { |
16931 | txq_cnt++; | |
16932 | } | |
16933 | ||
16934 | if (txq_cnt > pring->txq_max) | |
16935 | pring->txq_max = txq_cnt; | |
2a9bf3d0 | 16936 | |
398d81c9 | 16937 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
2a9bf3d0 | 16938 | |
0e9bb8d7 | 16939 | while (!list_empty(&pring->txq)) { |
398d81c9 | 16940 | spin_lock_irqsave(&pring->ring_lock, iflags); |
2a9bf3d0 | 16941 | |
19ca7609 | 16942 | piocbq = lpfc_sli_ringtx_get(phba, pring); |
a629852a | 16943 | if (!piocbq) { |
398d81c9 | 16944 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
a629852a JS |
16945 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
16946 | "2823 txq empty and txq_cnt is %d\n ", | |
0e9bb8d7 | 16947 | txq_cnt); |
a629852a JS |
16948 | break; |
16949 | } | |
19ca7609 | 16950 | sglq = __lpfc_sli_get_sglq(phba, piocbq); |
2a9bf3d0 | 16951 | if (!sglq) { |
19ca7609 | 16952 | __lpfc_sli_ringtx_put(phba, pring, piocbq); |
398d81c9 | 16953 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
2a9bf3d0 | 16954 | break; |
2a9bf3d0 | 16955 | } |
0e9bb8d7 | 16956 | txq_cnt--; |
2a9bf3d0 JS |
16957 | |
16958 | /* The xri and iocb resources secured, | |
16959 | * attempt to issue request | |
16960 | */ | |
6d368e53 | 16961 | piocbq->sli4_lxritag = sglq->sli4_lxritag; |
2a9bf3d0 JS |
16962 | piocbq->sli4_xritag = sglq->sli4_xritag; |
16963 | if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocbq, sglq)) | |
16964 | fail_msg = "to convert bpl to sgl"; | |
16965 | else if (lpfc_sli4_iocb2wqe(phba, piocbq, &wqe)) | |
16966 | fail_msg = "to convert iocb to wqe"; | |
16967 | else if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe)) | |
16968 | fail_msg = " - Wq is full"; | |
16969 | else | |
16970 | lpfc_sli_ringtxcmpl_put(phba, pring, piocbq); | |
16971 | ||
16972 | if (fail_msg) { | |
16973 | /* Failed means we can't issue and need to cancel */ | |
16974 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
16975 | "2822 IOCB failed %s iotag 0x%x " | |
16976 | "xri 0x%x\n", | |
16977 | fail_msg, | |
16978 | piocbq->iotag, piocbq->sli4_xritag); | |
16979 | list_add_tail(&piocbq->list, &completions); | |
16980 | } | |
398d81c9 | 16981 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
2a9bf3d0 JS |
16982 | } |
16983 | ||
2a9bf3d0 JS |
16984 | /* Cancel all the IOCBs that cannot be issued */ |
16985 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, | |
16986 | IOERR_SLI_ABORTED); | |
16987 | ||
0e9bb8d7 | 16988 | return txq_cnt; |
2a9bf3d0 | 16989 | } |