]>
Commit | Line | Data |
---|---|---|
dea3101e JB |
1 | /******************************************************************* |
2 | * This file is part of the Emulex Linux Device Driver for * | |
c44ce173 | 3 | * Fibre Channel Host Bus Adapters. * |
50611577 | 4 | * Copyright (C) 2004-2016 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 JB |
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 JB |
20 | *******************************************************************/ |
21 | ||
dea3101e JB |
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> |
1c2ba475 | 27 | #include <linux/lockdep.h> |
dea3101e | 28 | |
91886523 | 29 | #include <scsi/scsi.h> |
dea3101e JB |
30 | #include <scsi/scsi_cmnd.h> |
31 | #include <scsi/scsi_device.h> | |
32 | #include <scsi/scsi_host.h> | |
f888ba3c | 33 | #include <scsi/scsi_transport_fc.h> |
da0436e9 | 34 | #include <scsi/fc/fc_fs.h> |
0d878419 | 35 | #include <linux/aer.h> |
dea3101e | 36 | |
da0436e9 | 37 | #include "lpfc_hw4.h" |
dea3101e JB |
38 | #include "lpfc_hw.h" |
39 | #include "lpfc_sli.h" | |
da0436e9 | 40 | #include "lpfc_sli4.h" |
ea2151b4 | 41 | #include "lpfc_nl.h" |
dea3101e JB |
42 | #include "lpfc_disc.h" |
43 | #include "lpfc_scsi.h" | |
44 | #include "lpfc.h" | |
45 | #include "lpfc_crtn.h" | |
46 | #include "lpfc_logmsg.h" | |
47 | #include "lpfc_compat.h" | |
858c9f6c | 48 | #include "lpfc_debugfs.h" |
04c68496 | 49 | #include "lpfc_vport.h" |
dea3101e JB |
50 | |
51 | /* There are only four IOCB completion types. */ | |
52 | typedef enum _lpfc_iocb_type { | |
53 | LPFC_UNKNOWN_IOCB, | |
54 | LPFC_UNSOL_IOCB, | |
55 | LPFC_SOL_IOCB, | |
56 | LPFC_ABORT_IOCB | |
57 | } lpfc_iocb_type; | |
58 | ||
4f774513 JS |
59 | |
60 | /* Provide function prototypes local to this module. */ | |
61 | static int lpfc_sli_issue_mbox_s4(struct lpfc_hba *, LPFC_MBOXQ_t *, | |
62 | uint32_t); | |
63 | static int lpfc_sli4_read_rev(struct lpfc_hba *, LPFC_MBOXQ_t *, | |
45ed1190 JS |
64 | uint8_t *, uint32_t *); |
65 | static struct lpfc_iocbq *lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *, | |
66 | struct lpfc_iocbq *); | |
6669f9bb JS |
67 | static void lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *, |
68 | struct hbq_dmabuf *); | |
0558056c JS |
69 | static int lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *, struct lpfc_queue *, |
70 | struct lpfc_cqe *); | |
8a9d2e80 JS |
71 | static int lpfc_sli4_post_els_sgl_list(struct lpfc_hba *, struct list_head *, |
72 | int); | |
ba20c853 JS |
73 | static void lpfc_sli4_hba_handle_eqe(struct lpfc_hba *, struct lpfc_eqe *, |
74 | uint32_t); | |
e8d3c3b1 JS |
75 | static bool lpfc_sli4_mbox_completions_pending(struct lpfc_hba *phba); |
76 | static bool lpfc_sli4_process_missed_mbox_completions(struct lpfc_hba *phba); | |
0558056c | 77 | |
4f774513 JS |
78 | static IOCB_t * |
79 | lpfc_get_iocb_from_iocbq(struct lpfc_iocbq *iocbq) | |
80 | { | |
81 | return &iocbq->iocb; | |
82 | } | |
83 | ||
84 | /** | |
85 | * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue | |
86 | * @q: The Work Queue to operate on. | |
87 | * @wqe: The work Queue Entry to put on the Work queue. | |
88 | * | |
89 | * This routine will copy the contents of @wqe to the next available entry on | |
90 | * the @q. This function will then ring the Work Queue Doorbell to signal the | |
91 | * HBA to start processing the Work Queue Entry. This function returns 0 if | |
92 | * successful. If no entries are available on @q then this function will return | |
93 | * -ENOMEM. | |
94 | * The caller is expected to hold the hbalock when calling this routine. | |
95 | **/ | |
96 | static uint32_t | |
97 | lpfc_sli4_wq_put(struct lpfc_queue *q, union lpfc_wqe *wqe) | |
98 | { | |
2e90f4b5 | 99 | union lpfc_wqe *temp_wqe; |
4f774513 JS |
100 | struct lpfc_register doorbell; |
101 | uint32_t host_index; | |
027140ea | 102 | uint32_t idx; |
4f774513 | 103 | |
2e90f4b5 JS |
104 | /* sanity check on queue memory */ |
105 | if (unlikely(!q)) | |
106 | return -ENOMEM; | |
107 | temp_wqe = q->qe[q->host_index].wqe; | |
108 | ||
4f774513 | 109 | /* If the host has not yet processed the next entry then we are done */ |
027140ea JS |
110 | idx = ((q->host_index + 1) % q->entry_count); |
111 | if (idx == q->hba_index) { | |
b84daac9 | 112 | q->WQ_overflow++; |
4f774513 | 113 | return -ENOMEM; |
b84daac9 JS |
114 | } |
115 | q->WQ_posted++; | |
4f774513 | 116 | /* set consumption flag every once in a while */ |
ff78d8f9 | 117 | if (!((q->host_index + 1) % q->entry_repost)) |
f0d9bccc | 118 | bf_set(wqe_wqec, &wqe->generic.wqe_com, 1); |
fedd3b7b JS |
119 | if (q->phba->sli3_options & LPFC_SLI4_PHWQ_ENABLED) |
120 | bf_set(wqe_wqid, &wqe->generic.wqe_com, q->queue_id); | |
4f774513 JS |
121 | lpfc_sli_pcimem_bcopy(wqe, temp_wqe, q->entry_size); |
122 | ||
123 | /* Update the host index before invoking device */ | |
124 | host_index = q->host_index; | |
027140ea JS |
125 | |
126 | q->host_index = idx; | |
4f774513 JS |
127 | |
128 | /* Ring Doorbell */ | |
129 | doorbell.word0 = 0; | |
962bc51b JS |
130 | if (q->db_format == LPFC_DB_LIST_FORMAT) { |
131 | bf_set(lpfc_wq_db_list_fm_num_posted, &doorbell, 1); | |
132 | bf_set(lpfc_wq_db_list_fm_index, &doorbell, host_index); | |
133 | bf_set(lpfc_wq_db_list_fm_id, &doorbell, q->queue_id); | |
134 | } else if (q->db_format == LPFC_DB_RING_FORMAT) { | |
135 | bf_set(lpfc_wq_db_ring_fm_num_posted, &doorbell, 1); | |
136 | bf_set(lpfc_wq_db_ring_fm_id, &doorbell, q->queue_id); | |
137 | } else { | |
138 | return -EINVAL; | |
139 | } | |
140 | writel(doorbell.word0, q->db_regaddr); | |
4f774513 JS |
141 | |
142 | return 0; | |
143 | } | |
144 | ||
145 | /** | |
146 | * lpfc_sli4_wq_release - Updates internal hba index for WQ | |
147 | * @q: The Work Queue to operate on. | |
148 | * @index: The index to advance the hba index to. | |
149 | * | |
150 | * This routine will update the HBA index of a queue to reflect consumption of | |
151 | * Work Queue Entries by the HBA. When the HBA indicates that it has consumed | |
152 | * an entry the host calls this function to update the queue's internal | |
153 | * pointers. This routine returns the number of entries that were consumed by | |
154 | * the HBA. | |
155 | **/ | |
156 | static uint32_t | |
157 | lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index) | |
158 | { | |
159 | uint32_t released = 0; | |
160 | ||
2e90f4b5 JS |
161 | /* sanity check on queue memory */ |
162 | if (unlikely(!q)) | |
163 | return 0; | |
164 | ||
4f774513 JS |
165 | if (q->hba_index == index) |
166 | return 0; | |
167 | do { | |
168 | q->hba_index = ((q->hba_index + 1) % q->entry_count); | |
169 | released++; | |
170 | } while (q->hba_index != index); | |
171 | return released; | |
172 | } | |
173 | ||
174 | /** | |
175 | * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue | |
176 | * @q: The Mailbox Queue to operate on. | |
177 | * @wqe: The Mailbox Queue Entry to put on the Work queue. | |
178 | * | |
179 | * This routine will copy the contents of @mqe to the next available entry on | |
180 | * the @q. This function will then ring the Work Queue Doorbell to signal the | |
181 | * HBA to start processing the Work Queue Entry. This function returns 0 if | |
182 | * successful. If no entries are available on @q then this function will return | |
183 | * -ENOMEM. | |
184 | * The caller is expected to hold the hbalock when calling this routine. | |
185 | **/ | |
186 | static uint32_t | |
187 | lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe) | |
188 | { | |
2e90f4b5 | 189 | struct lpfc_mqe *temp_mqe; |
4f774513 | 190 | struct lpfc_register doorbell; |
4f774513 | 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 */ | |
4f774513 JS |
205 | q->host_index = ((q->host_index + 1) % q->entry_count); |
206 | ||
207 | /* Ring Doorbell */ | |
208 | doorbell.word0 = 0; | |
209 | bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1); | |
210 | bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id); | |
211 | writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr); | |
4f774513 JS |
212 | return 0; |
213 | } | |
214 | ||
215 | /** | |
216 | * lpfc_sli4_mq_release - Updates internal hba index for MQ | |
217 | * @q: The Mailbox Queue to operate on. | |
218 | * | |
219 | * This routine will update the HBA index of a queue to reflect consumption of | |
220 | * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed | |
221 | * an entry the host calls this function to update the queue's internal | |
222 | * pointers. This routine returns the number of entries that were consumed by | |
223 | * the HBA. | |
224 | **/ | |
225 | static uint32_t | |
226 | lpfc_sli4_mq_release(struct lpfc_queue *q) | |
227 | { | |
2e90f4b5 JS |
228 | /* sanity check on queue memory */ |
229 | if (unlikely(!q)) | |
230 | return 0; | |
231 | ||
4f774513 JS |
232 | /* Clear the mailbox pointer for completion */ |
233 | q->phba->mbox = NULL; | |
234 | q->hba_index = ((q->hba_index + 1) % q->entry_count); | |
235 | return 1; | |
236 | } | |
237 | ||
238 | /** | |
239 | * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ | |
240 | * @q: The Event Queue to get the first valid EQE from | |
241 | * | |
242 | * This routine will get the first valid Event Queue Entry from @q, update | |
243 | * the queue's internal hba index, and return the EQE. If no valid EQEs are in | |
244 | * the Queue (no more work to do), or the Queue is full of EQEs that have been | |
245 | * processed, but not popped back to the HBA then this routine will return NULL. | |
246 | **/ | |
247 | static struct lpfc_eqe * | |
248 | lpfc_sli4_eq_get(struct lpfc_queue *q) | |
249 | { | |
2e90f4b5 | 250 | struct lpfc_eqe *eqe; |
027140ea | 251 | uint32_t idx; |
2e90f4b5 JS |
252 | |
253 | /* sanity check on queue memory */ | |
254 | if (unlikely(!q)) | |
255 | return NULL; | |
256 | eqe = q->qe[q->hba_index].eqe; | |
4f774513 JS |
257 | |
258 | /* If the next EQE is not valid then we are done */ | |
cb5172ea | 259 | if (!bf_get_le32(lpfc_eqe_valid, eqe)) |
4f774513 JS |
260 | return NULL; |
261 | /* If the host has not yet processed the next entry then we are done */ | |
027140ea JS |
262 | idx = ((q->hba_index + 1) % q->entry_count); |
263 | if (idx == q->host_index) | |
4f774513 JS |
264 | return NULL; |
265 | ||
027140ea | 266 | q->hba_index = idx; |
27f344eb JS |
267 | |
268 | /* | |
269 | * insert barrier for instruction interlock : data from the hardware | |
270 | * must have the valid bit checked before it can be copied and acted | |
271 | * upon. Given what was seen in lpfc_sli4_cq_get() of speculative | |
272 | * instructions allowing action on content before valid bit checked, | |
273 | * add barrier here as well. May not be needed as "content" is a | |
274 | * single 32-bit entity here (vs multi word structure for cq's). | |
275 | */ | |
276 | mb(); | |
4f774513 JS |
277 | return eqe; |
278 | } | |
279 | ||
ba20c853 JS |
280 | /** |
281 | * lpfc_sli4_eq_clr_intr - Turn off interrupts from this EQ | |
282 | * @q: The Event Queue to disable interrupts | |
283 | * | |
284 | **/ | |
285 | static inline void | |
286 | lpfc_sli4_eq_clr_intr(struct lpfc_queue *q) | |
287 | { | |
288 | struct lpfc_register doorbell; | |
289 | ||
290 | doorbell.word0 = 0; | |
291 | bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1); | |
292 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT); | |
293 | bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell, | |
294 | (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT)); | |
295 | bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id); | |
296 | writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr); | |
297 | } | |
298 | ||
4f774513 JS |
299 | /** |
300 | * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ | |
301 | * @q: The Event Queue that the host has completed processing for. | |
302 | * @arm: Indicates whether the host wants to arms this CQ. | |
303 | * | |
304 | * This routine will mark all Event Queue Entries on @q, from the last | |
305 | * known completed entry to the last entry that was processed, as completed | |
306 | * by clearing the valid bit for each completion queue entry. Then it will | |
307 | * notify the HBA, by ringing the doorbell, that the EQEs have been processed. | |
308 | * The internal host index in the @q will be updated by this routine to indicate | |
309 | * that the host has finished processing the entries. The @arm parameter | |
310 | * indicates that the queue should be rearmed when ringing the doorbell. | |
311 | * | |
312 | * This function will return the number of EQEs that were popped. | |
313 | **/ | |
314 | uint32_t | |
315 | lpfc_sli4_eq_release(struct lpfc_queue *q, bool arm) | |
316 | { | |
317 | uint32_t released = 0; | |
318 | struct lpfc_eqe *temp_eqe; | |
319 | struct lpfc_register doorbell; | |
320 | ||
2e90f4b5 JS |
321 | /* sanity check on queue memory */ |
322 | if (unlikely(!q)) | |
323 | return 0; | |
324 | ||
4f774513 JS |
325 | /* while there are valid entries */ |
326 | while (q->hba_index != q->host_index) { | |
327 | temp_eqe = q->qe[q->host_index].eqe; | |
cb5172ea | 328 | bf_set_le32(lpfc_eqe_valid, temp_eqe, 0); |
4f774513 JS |
329 | released++; |
330 | q->host_index = ((q->host_index + 1) % q->entry_count); | |
331 | } | |
332 | if (unlikely(released == 0 && !arm)) | |
333 | return 0; | |
334 | ||
335 | /* ring doorbell for number popped */ | |
336 | doorbell.word0 = 0; | |
337 | if (arm) { | |
338 | bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1); | |
339 | bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1); | |
340 | } | |
341 | bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released); | |
342 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT); | |
6b5151fd JS |
343 | bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell, |
344 | (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT)); | |
345 | bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id); | |
4f774513 | 346 | writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr); |
a747c9ce JS |
347 | /* PCI read to flush PCI pipeline on re-arming for INTx mode */ |
348 | if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM)) | |
349 | readl(q->phba->sli4_hba.EQCQDBregaddr); | |
4f774513 JS |
350 | return released; |
351 | } | |
352 | ||
353 | /** | |
354 | * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ | |
355 | * @q: The Completion Queue to get the first valid CQE from | |
356 | * | |
357 | * This routine will get the first valid Completion Queue Entry from @q, update | |
358 | * the queue's internal hba index, and return the CQE. If no valid CQEs are in | |
359 | * the Queue (no more work to do), or the Queue is full of CQEs that have been | |
360 | * processed, but not popped back to the HBA then this routine will return NULL. | |
361 | **/ | |
362 | static struct lpfc_cqe * | |
363 | lpfc_sli4_cq_get(struct lpfc_queue *q) | |
364 | { | |
365 | struct lpfc_cqe *cqe; | |
027140ea | 366 | uint32_t idx; |
4f774513 | 367 | |
2e90f4b5 JS |
368 | /* sanity check on queue memory */ |
369 | if (unlikely(!q)) | |
370 | return NULL; | |
371 | ||
4f774513 | 372 | /* If the next CQE is not valid then we are done */ |
cb5172ea | 373 | if (!bf_get_le32(lpfc_cqe_valid, q->qe[q->hba_index].cqe)) |
4f774513 JS |
374 | return NULL; |
375 | /* If the host has not yet processed the next entry then we are done */ | |
027140ea JS |
376 | idx = ((q->hba_index + 1) % q->entry_count); |
377 | if (idx == q->host_index) | |
4f774513 JS |
378 | return NULL; |
379 | ||
380 | cqe = q->qe[q->hba_index].cqe; | |
027140ea | 381 | q->hba_index = idx; |
27f344eb JS |
382 | |
383 | /* | |
384 | * insert barrier for instruction interlock : data from the hardware | |
385 | * must have the valid bit checked before it can be copied and acted | |
386 | * upon. Speculative instructions were allowing a bcopy at the start | |
387 | * of lpfc_sli4_fp_handle_wcqe(), which is called immediately | |
388 | * after our return, to copy data before the valid bit check above | |
389 | * was done. As such, some of the copied data was stale. The barrier | |
390 | * ensures the check is before any data is copied. | |
391 | */ | |
392 | mb(); | |
4f774513 JS |
393 | return cqe; |
394 | } | |
395 | ||
396 | /** | |
397 | * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ | |
398 | * @q: The Completion Queue that the host has completed processing for. | |
399 | * @arm: Indicates whether the host wants to arms this CQ. | |
400 | * | |
401 | * This routine will mark all Completion queue entries on @q, from the last | |
402 | * known completed entry to the last entry that was processed, as completed | |
403 | * by clearing the valid bit for each completion queue entry. Then it will | |
404 | * notify the HBA, by ringing the doorbell, that the CQEs have been processed. | |
405 | * The internal host index in the @q will be updated by this routine to indicate | |
406 | * that the host has finished processing the entries. The @arm parameter | |
407 | * indicates that the queue should be rearmed when ringing the doorbell. | |
408 | * | |
409 | * This function will return the number of CQEs that were released. | |
410 | **/ | |
411 | uint32_t | |
412 | lpfc_sli4_cq_release(struct lpfc_queue *q, bool arm) | |
413 | { | |
414 | uint32_t released = 0; | |
415 | struct lpfc_cqe *temp_qe; | |
416 | struct lpfc_register doorbell; | |
417 | ||
2e90f4b5 JS |
418 | /* sanity check on queue memory */ |
419 | if (unlikely(!q)) | |
420 | return 0; | |
4f774513 JS |
421 | /* while there are valid entries */ |
422 | while (q->hba_index != q->host_index) { | |
423 | temp_qe = q->qe[q->host_index].cqe; | |
cb5172ea | 424 | bf_set_le32(lpfc_cqe_valid, temp_qe, 0); |
4f774513 JS |
425 | released++; |
426 | q->host_index = ((q->host_index + 1) % q->entry_count); | |
427 | } | |
428 | if (unlikely(released == 0 && !arm)) | |
429 | return 0; | |
430 | ||
431 | /* ring doorbell for number popped */ | |
432 | doorbell.word0 = 0; | |
433 | if (arm) | |
434 | bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1); | |
435 | bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released); | |
436 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION); | |
6b5151fd JS |
437 | bf_set(lpfc_eqcq_doorbell_cqid_hi, &doorbell, |
438 | (q->queue_id >> LPFC_CQID_HI_FIELD_SHIFT)); | |
439 | bf_set(lpfc_eqcq_doorbell_cqid_lo, &doorbell, q->queue_id); | |
4f774513 JS |
440 | writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr); |
441 | return released; | |
442 | } | |
443 | ||
444 | /** | |
445 | * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue | |
446 | * @q: The Header Receive Queue to operate on. | |
447 | * @wqe: The Receive Queue Entry to put on the Receive queue. | |
448 | * | |
449 | * This routine will copy the contents of @wqe to the next available entry on | |
450 | * the @q. This function will then ring the Receive Queue Doorbell to signal the | |
451 | * HBA to start processing the Receive Queue Entry. This function returns the | |
452 | * index that the rqe was copied to if successful. If no entries are available | |
453 | * on @q then this function will return -ENOMEM. | |
454 | * The caller is expected to hold the hbalock when calling this routine. | |
455 | **/ | |
456 | static int | |
457 | lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq, | |
458 | struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe) | |
459 | { | |
2e90f4b5 JS |
460 | struct lpfc_rqe *temp_hrqe; |
461 | struct lpfc_rqe *temp_drqe; | |
4f774513 | 462 | struct lpfc_register doorbell; |
5a25bf36 | 463 | int put_index; |
4f774513 | 464 | |
2e90f4b5 JS |
465 | /* sanity check on queue memory */ |
466 | if (unlikely(!hq) || unlikely(!dq)) | |
467 | return -ENOMEM; | |
5a25bf36 | 468 | put_index = hq->host_index; |
2e90f4b5 JS |
469 | temp_hrqe = hq->qe[hq->host_index].rqe; |
470 | temp_drqe = dq->qe[dq->host_index].rqe; | |
471 | ||
4f774513 JS |
472 | if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ) |
473 | return -EINVAL; | |
474 | if (hq->host_index != dq->host_index) | |
475 | return -EINVAL; | |
476 | /* If the host has not yet processed the next entry then we are done */ | |
477 | if (((hq->host_index + 1) % hq->entry_count) == hq->hba_index) | |
478 | return -EBUSY; | |
479 | lpfc_sli_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size); | |
480 | lpfc_sli_pcimem_bcopy(drqe, temp_drqe, dq->entry_size); | |
481 | ||
482 | /* Update the host index to point to the next slot */ | |
483 | hq->host_index = ((hq->host_index + 1) % hq->entry_count); | |
484 | dq->host_index = ((dq->host_index + 1) % dq->entry_count); | |
485 | ||
486 | /* Ring The Header Receive Queue Doorbell */ | |
73d91e50 | 487 | if (!(hq->host_index % hq->entry_repost)) { |
4f774513 | 488 | doorbell.word0 = 0; |
962bc51b JS |
489 | if (hq->db_format == LPFC_DB_RING_FORMAT) { |
490 | bf_set(lpfc_rq_db_ring_fm_num_posted, &doorbell, | |
491 | hq->entry_repost); | |
492 | bf_set(lpfc_rq_db_ring_fm_id, &doorbell, hq->queue_id); | |
493 | } else if (hq->db_format == LPFC_DB_LIST_FORMAT) { | |
494 | bf_set(lpfc_rq_db_list_fm_num_posted, &doorbell, | |
495 | hq->entry_repost); | |
496 | bf_set(lpfc_rq_db_list_fm_index, &doorbell, | |
497 | hq->host_index); | |
498 | bf_set(lpfc_rq_db_list_fm_id, &doorbell, hq->queue_id); | |
499 | } else { | |
500 | return -EINVAL; | |
501 | } | |
502 | writel(doorbell.word0, hq->db_regaddr); | |
4f774513 JS |
503 | } |
504 | return put_index; | |
505 | } | |
506 | ||
507 | /** | |
508 | * lpfc_sli4_rq_release - Updates internal hba index for RQ | |
509 | * @q: The Header Receive Queue to operate on. | |
510 | * | |
511 | * This routine will update the HBA index of a queue to reflect consumption of | |
512 | * one Receive Queue Entry by the HBA. When the HBA indicates that it has | |
513 | * consumed an entry the host calls this function to update the queue's | |
514 | * internal pointers. This routine returns the number of entries that were | |
515 | * consumed by the HBA. | |
516 | **/ | |
517 | static uint32_t | |
518 | lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq) | |
519 | { | |
2e90f4b5 JS |
520 | /* sanity check on queue memory */ |
521 | if (unlikely(!hq) || unlikely(!dq)) | |
522 | return 0; | |
523 | ||
4f774513 JS |
524 | if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ)) |
525 | return 0; | |
526 | hq->hba_index = ((hq->hba_index + 1) % hq->entry_count); | |
527 | dq->hba_index = ((dq->hba_index + 1) % dq->entry_count); | |
528 | return 1; | |
529 | } | |
530 | ||
e59058c4 | 531 | /** |
3621a710 | 532 | * lpfc_cmd_iocb - Get next command iocb entry in the ring |
e59058c4 JS |
533 | * @phba: Pointer to HBA context object. |
534 | * @pring: Pointer to driver SLI ring object. | |
535 | * | |
536 | * This function returns pointer to next command iocb entry | |
537 | * in the command ring. The caller must hold hbalock to prevent | |
538 | * other threads consume the next command iocb. | |
539 | * SLI-2/SLI-3 provide different sized iocbs. | |
540 | **/ | |
ed957684 JS |
541 | static inline IOCB_t * |
542 | lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) | |
543 | { | |
7e56aa25 JS |
544 | return (IOCB_t *) (((char *) pring->sli.sli3.cmdringaddr) + |
545 | pring->sli.sli3.cmdidx * phba->iocb_cmd_size); | |
ed957684 JS |
546 | } |
547 | ||
e59058c4 | 548 | /** |
3621a710 | 549 | * lpfc_resp_iocb - Get next response iocb entry in the ring |
e59058c4 JS |
550 | * @phba: Pointer to HBA context object. |
551 | * @pring: Pointer to driver SLI ring object. | |
552 | * | |
553 | * This function returns pointer to next response iocb entry | |
554 | * in the response ring. The caller must hold hbalock to make sure | |
555 | * that no other thread consume the next response iocb. | |
556 | * SLI-2/SLI-3 provide different sized iocbs. | |
557 | **/ | |
ed957684 JS |
558 | static inline IOCB_t * |
559 | lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) | |
560 | { | |
7e56aa25 JS |
561 | return (IOCB_t *) (((char *) pring->sli.sli3.rspringaddr) + |
562 | pring->sli.sli3.rspidx * phba->iocb_rsp_size); | |
ed957684 JS |
563 | } |
564 | ||
e59058c4 | 565 | /** |
3621a710 | 566 | * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool |
e59058c4 JS |
567 | * @phba: Pointer to HBA context object. |
568 | * | |
569 | * This function is called with hbalock held. This function | |
570 | * allocates a new driver iocb object from the iocb pool. If the | |
571 | * allocation is successful, it returns pointer to the newly | |
572 | * allocated iocb object else it returns NULL. | |
573 | **/ | |
4f2e66c6 | 574 | struct lpfc_iocbq * |
2e0fef85 | 575 | __lpfc_sli_get_iocbq(struct lpfc_hba *phba) |
0bd4ca25 JSEC |
576 | { |
577 | struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list; | |
578 | struct lpfc_iocbq * iocbq = NULL; | |
579 | ||
1c2ba475 JT |
580 | lockdep_assert_held(&phba->hbalock); |
581 | ||
0bd4ca25 | 582 | list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list); |
2a9bf3d0 JS |
583 | if (iocbq) |
584 | phba->iocb_cnt++; | |
585 | if (phba->iocb_cnt > phba->iocb_max) | |
586 | phba->iocb_max = phba->iocb_cnt; | |
0bd4ca25 JSEC |
587 | return iocbq; |
588 | } | |
589 | ||
da0436e9 JS |
590 | /** |
591 | * __lpfc_clear_active_sglq - Remove the active sglq for this XRI. | |
592 | * @phba: Pointer to HBA context object. | |
593 | * @xritag: XRI value. | |
594 | * | |
595 | * This function clears the sglq pointer from the array of acive | |
596 | * sglq's. The xritag that is passed in is used to index into the | |
597 | * array. Before the xritag can be used it needs to be adjusted | |
598 | * by subtracting the xribase. | |
599 | * | |
600 | * Returns sglq ponter = success, NULL = Failure. | |
601 | **/ | |
602 | static struct lpfc_sglq * | |
603 | __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag) | |
604 | { | |
da0436e9 | 605 | struct lpfc_sglq *sglq; |
6d368e53 JS |
606 | |
607 | sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag]; | |
608 | phba->sli4_hba.lpfc_sglq_active_list[xritag] = NULL; | |
da0436e9 JS |
609 | return sglq; |
610 | } | |
611 | ||
612 | /** | |
613 | * __lpfc_get_active_sglq - Get the active sglq for this XRI. | |
614 | * @phba: Pointer to HBA context object. | |
615 | * @xritag: XRI value. | |
616 | * | |
617 | * This function returns the sglq pointer from the array of acive | |
618 | * sglq's. The xritag that is passed in is used to index into the | |
619 | * array. Before the xritag can be used it needs to be adjusted | |
620 | * by subtracting the xribase. | |
621 | * | |
622 | * Returns sglq ponter = success, NULL = Failure. | |
623 | **/ | |
0f65ff68 | 624 | struct lpfc_sglq * |
da0436e9 JS |
625 | __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag) |
626 | { | |
da0436e9 | 627 | struct lpfc_sglq *sglq; |
6d368e53 JS |
628 | |
629 | sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag]; | |
da0436e9 JS |
630 | return sglq; |
631 | } | |
632 | ||
19ca7609 | 633 | /** |
1151e3ec | 634 | * lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap. |
19ca7609 JS |
635 | * @phba: Pointer to HBA context object. |
636 | * @xritag: xri used in this exchange. | |
637 | * @rrq: The RRQ to be cleared. | |
638 | * | |
19ca7609 | 639 | **/ |
1151e3ec JS |
640 | void |
641 | lpfc_clr_rrq_active(struct lpfc_hba *phba, | |
642 | uint16_t xritag, | |
643 | struct lpfc_node_rrq *rrq) | |
19ca7609 | 644 | { |
1151e3ec | 645 | struct lpfc_nodelist *ndlp = NULL; |
19ca7609 | 646 | |
1151e3ec JS |
647 | if ((rrq->vport) && NLP_CHK_NODE_ACT(rrq->ndlp)) |
648 | ndlp = lpfc_findnode_did(rrq->vport, rrq->nlp_DID); | |
19ca7609 JS |
649 | |
650 | /* The target DID could have been swapped (cable swap) | |
651 | * we should use the ndlp from the findnode if it is | |
652 | * available. | |
653 | */ | |
1151e3ec | 654 | if ((!ndlp) && rrq->ndlp) |
19ca7609 JS |
655 | ndlp = rrq->ndlp; |
656 | ||
1151e3ec JS |
657 | if (!ndlp) |
658 | goto out; | |
659 | ||
cff261f6 | 660 | if (test_and_clear_bit(xritag, ndlp->active_rrqs_xri_bitmap)) { |
19ca7609 JS |
661 | rrq->send_rrq = 0; |
662 | rrq->xritag = 0; | |
663 | rrq->rrq_stop_time = 0; | |
664 | } | |
1151e3ec | 665 | out: |
19ca7609 JS |
666 | mempool_free(rrq, phba->rrq_pool); |
667 | } | |
668 | ||
669 | /** | |
670 | * lpfc_handle_rrq_active - Checks if RRQ has waithed RATOV. | |
671 | * @phba: Pointer to HBA context object. | |
672 | * | |
673 | * This function is called with hbalock held. This function | |
674 | * Checks if stop_time (ratov from setting rrq active) has | |
675 | * been reached, if it has and the send_rrq flag is set then | |
676 | * it will call lpfc_send_rrq. If the send_rrq flag is not set | |
677 | * then it will just call the routine to clear the rrq and | |
678 | * free the rrq resource. | |
679 | * The timer is set to the next rrq that is going to expire before | |
680 | * leaving the routine. | |
681 | * | |
682 | **/ | |
683 | void | |
684 | lpfc_handle_rrq_active(struct lpfc_hba *phba) | |
685 | { | |
686 | struct lpfc_node_rrq *rrq; | |
687 | struct lpfc_node_rrq *nextrrq; | |
688 | unsigned long next_time; | |
689 | unsigned long iflags; | |
1151e3ec | 690 | LIST_HEAD(send_rrq); |
19ca7609 JS |
691 | |
692 | spin_lock_irqsave(&phba->hbalock, iflags); | |
693 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; | |
256ec0d0 | 694 | next_time = jiffies + msecs_to_jiffies(1000 * (phba->fc_ratov + 1)); |
19ca7609 | 695 | list_for_each_entry_safe(rrq, nextrrq, |
1151e3ec JS |
696 | &phba->active_rrq_list, list) { |
697 | if (time_after(jiffies, rrq->rrq_stop_time)) | |
698 | list_move(&rrq->list, &send_rrq); | |
699 | else if (time_before(rrq->rrq_stop_time, next_time)) | |
19ca7609 JS |
700 | next_time = rrq->rrq_stop_time; |
701 | } | |
702 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
06918ac5 JS |
703 | if ((!list_empty(&phba->active_rrq_list)) && |
704 | (!(phba->pport->load_flag & FC_UNLOADING))) | |
19ca7609 | 705 | mod_timer(&phba->rrq_tmr, next_time); |
1151e3ec JS |
706 | list_for_each_entry_safe(rrq, nextrrq, &send_rrq, list) { |
707 | list_del(&rrq->list); | |
708 | if (!rrq->send_rrq) | |
709 | /* this call will free the rrq */ | |
710 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); | |
711 | else if (lpfc_send_rrq(phba, rrq)) { | |
712 | /* if we send the rrq then the completion handler | |
713 | * will clear the bit in the xribitmap. | |
714 | */ | |
715 | lpfc_clr_rrq_active(phba, rrq->xritag, | |
716 | rrq); | |
717 | } | |
718 | } | |
19ca7609 JS |
719 | } |
720 | ||
721 | /** | |
722 | * lpfc_get_active_rrq - Get the active RRQ for this exchange. | |
723 | * @vport: Pointer to vport context object. | |
724 | * @xri: The xri used in the exchange. | |
725 | * @did: The targets DID for this exchange. | |
726 | * | |
727 | * returns NULL = rrq not found in the phba->active_rrq_list. | |
728 | * rrq = rrq for this xri and target. | |
729 | **/ | |
730 | struct lpfc_node_rrq * | |
731 | lpfc_get_active_rrq(struct lpfc_vport *vport, uint16_t xri, uint32_t did) | |
732 | { | |
733 | struct lpfc_hba *phba = vport->phba; | |
734 | struct lpfc_node_rrq *rrq; | |
735 | struct lpfc_node_rrq *nextrrq; | |
736 | unsigned long iflags; | |
737 | ||
738 | if (phba->sli_rev != LPFC_SLI_REV4) | |
739 | return NULL; | |
740 | spin_lock_irqsave(&phba->hbalock, iflags); | |
741 | list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) { | |
742 | if (rrq->vport == vport && rrq->xritag == xri && | |
743 | rrq->nlp_DID == did){ | |
744 | list_del(&rrq->list); | |
745 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
746 | return rrq; | |
747 | } | |
748 | } | |
749 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
750 | return NULL; | |
751 | } | |
752 | ||
753 | /** | |
754 | * lpfc_cleanup_vports_rrqs - Remove and clear the active RRQ for this vport. | |
755 | * @vport: Pointer to vport context object. | |
1151e3ec JS |
756 | * @ndlp: Pointer to the lpfc_node_list structure. |
757 | * If ndlp is NULL Remove all active RRQs for this vport from the | |
758 | * phba->active_rrq_list and clear the rrq. | |
759 | * If ndlp is not NULL then only remove rrqs for this vport & this ndlp. | |
19ca7609 JS |
760 | **/ |
761 | void | |
1151e3ec | 762 | lpfc_cleanup_vports_rrqs(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
19ca7609 JS |
763 | |
764 | { | |
765 | struct lpfc_hba *phba = vport->phba; | |
766 | struct lpfc_node_rrq *rrq; | |
767 | struct lpfc_node_rrq *nextrrq; | |
768 | unsigned long iflags; | |
1151e3ec | 769 | LIST_HEAD(rrq_list); |
19ca7609 JS |
770 | |
771 | if (phba->sli_rev != LPFC_SLI_REV4) | |
772 | return; | |
1151e3ec JS |
773 | if (!ndlp) { |
774 | lpfc_sli4_vport_delete_els_xri_aborted(vport); | |
775 | lpfc_sli4_vport_delete_fcp_xri_aborted(vport); | |
19ca7609 | 776 | } |
1151e3ec JS |
777 | spin_lock_irqsave(&phba->hbalock, iflags); |
778 | list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) | |
779 | if ((rrq->vport == vport) && (!ndlp || rrq->ndlp == ndlp)) | |
780 | list_move(&rrq->list, &rrq_list); | |
19ca7609 | 781 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
1151e3ec JS |
782 | |
783 | list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) { | |
784 | list_del(&rrq->list); | |
785 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); | |
786 | } | |
19ca7609 JS |
787 | } |
788 | ||
19ca7609 | 789 | /** |
1151e3ec | 790 | * lpfc_test_rrq_active - Test RRQ bit in xri_bitmap. |
19ca7609 JS |
791 | * @phba: Pointer to HBA context object. |
792 | * @ndlp: Targets nodelist pointer for this exchange. | |
793 | * @xritag the xri in the bitmap to test. | |
794 | * | |
795 | * This function is called with hbalock held. This function | |
796 | * returns 0 = rrq not active for this xri | |
797 | * 1 = rrq is valid for this xri. | |
798 | **/ | |
1151e3ec JS |
799 | int |
800 | lpfc_test_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, | |
19ca7609 JS |
801 | uint16_t xritag) |
802 | { | |
1c2ba475 | 803 | lockdep_assert_held(&phba->hbalock); |
19ca7609 JS |
804 | if (!ndlp) |
805 | return 0; | |
cff261f6 JS |
806 | if (!ndlp->active_rrqs_xri_bitmap) |
807 | return 0; | |
808 | if (test_bit(xritag, ndlp->active_rrqs_xri_bitmap)) | |
19ca7609 JS |
809 | return 1; |
810 | else | |
811 | return 0; | |
812 | } | |
813 | ||
814 | /** | |
815 | * lpfc_set_rrq_active - set RRQ active bit in xri_bitmap. | |
816 | * @phba: Pointer to HBA context object. | |
817 | * @ndlp: nodelist pointer for this target. | |
818 | * @xritag: xri used in this exchange. | |
819 | * @rxid: Remote Exchange ID. | |
820 | * @send_rrq: Flag used to determine if we should send rrq els cmd. | |
821 | * | |
822 | * This function takes the hbalock. | |
823 | * The active bit is always set in the active rrq xri_bitmap even | |
824 | * if there is no slot avaiable for the other rrq information. | |
825 | * | |
826 | * returns 0 rrq actived for this xri | |
827 | * < 0 No memory or invalid ndlp. | |
828 | **/ | |
829 | int | |
830 | lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, | |
b42c07c8 | 831 | uint16_t xritag, uint16_t rxid, uint16_t send_rrq) |
19ca7609 | 832 | { |
19ca7609 | 833 | unsigned long iflags; |
b42c07c8 JS |
834 | struct lpfc_node_rrq *rrq; |
835 | int empty; | |
836 | ||
837 | if (!ndlp) | |
838 | return -EINVAL; | |
839 | ||
840 | if (!phba->cfg_enable_rrq) | |
841 | return -EINVAL; | |
19ca7609 JS |
842 | |
843 | spin_lock_irqsave(&phba->hbalock, iflags); | |
b42c07c8 JS |
844 | if (phba->pport->load_flag & FC_UNLOADING) { |
845 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; | |
846 | goto out; | |
847 | } | |
848 | ||
849 | /* | |
850 | * set the active bit even if there is no mem available. | |
851 | */ | |
852 | if (NLP_CHK_FREE_REQ(ndlp)) | |
853 | goto out; | |
854 | ||
855 | if (ndlp->vport && (ndlp->vport->load_flag & FC_UNLOADING)) | |
856 | goto out; | |
857 | ||
cff261f6 JS |
858 | if (!ndlp->active_rrqs_xri_bitmap) |
859 | goto out; | |
860 | ||
861 | if (test_and_set_bit(xritag, ndlp->active_rrqs_xri_bitmap)) | |
b42c07c8 JS |
862 | goto out; |
863 | ||
19ca7609 | 864 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
b42c07c8 JS |
865 | rrq = mempool_alloc(phba->rrq_pool, GFP_KERNEL); |
866 | if (!rrq) { | |
867 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
868 | "3155 Unable to allocate RRQ xri:0x%x rxid:0x%x" | |
869 | " DID:0x%x Send:%d\n", | |
870 | xritag, rxid, ndlp->nlp_DID, send_rrq); | |
871 | return -EINVAL; | |
872 | } | |
e5771b4d JS |
873 | if (phba->cfg_enable_rrq == 1) |
874 | rrq->send_rrq = send_rrq; | |
875 | else | |
876 | rrq->send_rrq = 0; | |
b42c07c8 | 877 | rrq->xritag = xritag; |
256ec0d0 JS |
878 | rrq->rrq_stop_time = jiffies + |
879 | msecs_to_jiffies(1000 * (phba->fc_ratov + 1)); | |
b42c07c8 JS |
880 | rrq->ndlp = ndlp; |
881 | rrq->nlp_DID = ndlp->nlp_DID; | |
882 | rrq->vport = ndlp->vport; | |
883 | rrq->rxid = rxid; | |
b42c07c8 JS |
884 | spin_lock_irqsave(&phba->hbalock, iflags); |
885 | empty = list_empty(&phba->active_rrq_list); | |
886 | list_add_tail(&rrq->list, &phba->active_rrq_list); | |
887 | phba->hba_flag |= HBA_RRQ_ACTIVE; | |
888 | if (empty) | |
889 | lpfc_worker_wake_up(phba); | |
890 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
891 | return 0; | |
892 | out: | |
893 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
894 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
895 | "2921 Can't set rrq active xri:0x%x rxid:0x%x" | |
896 | " DID:0x%x Send:%d\n", | |
897 | xritag, rxid, ndlp->nlp_DID, send_rrq); | |
898 | return -EINVAL; | |
19ca7609 JS |
899 | } |
900 | ||
da0436e9 JS |
901 | /** |
902 | * __lpfc_sli_get_sglq - Allocates an iocb object from sgl pool | |
903 | * @phba: Pointer to HBA context object. | |
19ca7609 | 904 | * @piocb: Pointer to the iocbq. |
da0436e9 | 905 | * |
dafe8cea | 906 | * This function is called with the ring lock held. This function |
6d368e53 | 907 | * gets a new driver sglq object from the sglq list. If the |
da0436e9 JS |
908 | * list is not empty then it is successful, it returns pointer to the newly |
909 | * allocated sglq object else it returns NULL. | |
910 | **/ | |
911 | static struct lpfc_sglq * | |
19ca7609 | 912 | __lpfc_sli_get_sglq(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq) |
da0436e9 JS |
913 | { |
914 | struct list_head *lpfc_sgl_list = &phba->sli4_hba.lpfc_sgl_list; | |
915 | struct lpfc_sglq *sglq = NULL; | |
19ca7609 | 916 | struct lpfc_sglq *start_sglq = NULL; |
19ca7609 JS |
917 | struct lpfc_scsi_buf *lpfc_cmd; |
918 | struct lpfc_nodelist *ndlp; | |
919 | int found = 0; | |
920 | ||
1c2ba475 JT |
921 | lockdep_assert_held(&phba->hbalock); |
922 | ||
19ca7609 JS |
923 | if (piocbq->iocb_flag & LPFC_IO_FCP) { |
924 | lpfc_cmd = (struct lpfc_scsi_buf *) piocbq->context1; | |
925 | ndlp = lpfc_cmd->rdata->pnode; | |
be858b65 | 926 | } else if ((piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) && |
6c7cf486 | 927 | !(piocbq->iocb_flag & LPFC_IO_LIBDFC)) { |
19ca7609 | 928 | ndlp = piocbq->context_un.ndlp; |
6c7cf486 JS |
929 | } else if (piocbq->iocb_flag & LPFC_IO_LIBDFC) { |
930 | if (piocbq->iocb_flag & LPFC_IO_LOOPBACK) | |
931 | ndlp = NULL; | |
932 | else | |
933 | ndlp = piocbq->context_un.ndlp; | |
934 | } else { | |
19ca7609 | 935 | ndlp = piocbq->context1; |
6c7cf486 | 936 | } |
19ca7609 | 937 | |
da0436e9 | 938 | list_remove_head(lpfc_sgl_list, sglq, struct lpfc_sglq, list); |
19ca7609 JS |
939 | start_sglq = sglq; |
940 | while (!found) { | |
941 | if (!sglq) | |
942 | return NULL; | |
ee0f4fe1 | 943 | if (lpfc_test_rrq_active(phba, ndlp, sglq->sli4_lxritag)) { |
19ca7609 JS |
944 | /* This xri has an rrq outstanding for this DID. |
945 | * put it back in the list and get another xri. | |
946 | */ | |
947 | list_add_tail(&sglq->list, lpfc_sgl_list); | |
948 | sglq = NULL; | |
949 | list_remove_head(lpfc_sgl_list, sglq, | |
950 | struct lpfc_sglq, list); | |
951 | if (sglq == start_sglq) { | |
952 | sglq = NULL; | |
953 | break; | |
954 | } else | |
955 | continue; | |
956 | } | |
957 | sglq->ndlp = ndlp; | |
958 | found = 1; | |
6d368e53 | 959 | phba->sli4_hba.lpfc_sglq_active_list[sglq->sli4_lxritag] = sglq; |
19ca7609 JS |
960 | sglq->state = SGL_ALLOCATED; |
961 | } | |
da0436e9 JS |
962 | return sglq; |
963 | } | |
964 | ||
e59058c4 | 965 | /** |
3621a710 | 966 | * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool |
e59058c4 JS |
967 | * @phba: Pointer to HBA context object. |
968 | * | |
969 | * This function is called with no lock held. This function | |
970 | * allocates a new driver iocb object from the iocb pool. If the | |
971 | * allocation is successful, it returns pointer to the newly | |
972 | * allocated iocb object else it returns NULL. | |
973 | **/ | |
2e0fef85 JS |
974 | struct lpfc_iocbq * |
975 | lpfc_sli_get_iocbq(struct lpfc_hba *phba) | |
976 | { | |
977 | struct lpfc_iocbq * iocbq = NULL; | |
978 | unsigned long iflags; | |
979 | ||
980 | spin_lock_irqsave(&phba->hbalock, iflags); | |
981 | iocbq = __lpfc_sli_get_iocbq(phba); | |
982 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
983 | return iocbq; | |
984 | } | |
985 | ||
4f774513 JS |
986 | /** |
987 | * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool | |
988 | * @phba: Pointer to HBA context object. | |
989 | * @iocbq: Pointer to driver iocb object. | |
990 | * | |
991 | * This function is called with hbalock held to release driver | |
992 | * iocb object to the iocb pool. The iotag in the iocb object | |
993 | * does not change for each use of the iocb object. This function | |
994 | * clears all other fields of the iocb object when it is freed. | |
995 | * The sqlq structure that holds the xritag and phys and virtual | |
996 | * mappings for the scatter gather list is retrieved from the | |
997 | * active array of sglq. The get of the sglq pointer also clears | |
998 | * the entry in the array. If the status of the IO indiactes that | |
999 | * this IO was aborted then the sglq entry it put on the | |
1000 | * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the | |
1001 | * IO has good status or fails for any other reason then the sglq | |
1002 | * entry is added to the free list (lpfc_sgl_list). | |
1003 | **/ | |
1004 | static void | |
1005 | __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) | |
1006 | { | |
1007 | struct lpfc_sglq *sglq; | |
1008 | size_t start_clean = offsetof(struct lpfc_iocbq, iocb); | |
2a9bf3d0 JS |
1009 | unsigned long iflag = 0; |
1010 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; | |
4f774513 | 1011 | |
1c2ba475 JT |
1012 | lockdep_assert_held(&phba->hbalock); |
1013 | ||
4f774513 JS |
1014 | if (iocbq->sli4_xritag == NO_XRI) |
1015 | sglq = NULL; | |
1016 | else | |
6d368e53 JS |
1017 | sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_lxritag); |
1018 | ||
0e9bb8d7 | 1019 | |
4f774513 | 1020 | if (sglq) { |
0f65ff68 JS |
1021 | if ((iocbq->iocb_flag & LPFC_EXCHANGE_BUSY) && |
1022 | (sglq->state != SGL_XRI_ABORTED)) { | |
4f774513 JS |
1023 | spin_lock_irqsave(&phba->sli4_hba.abts_sgl_list_lock, |
1024 | iflag); | |
1025 | list_add(&sglq->list, | |
1026 | &phba->sli4_hba.lpfc_abts_els_sgl_list); | |
1027 | spin_unlock_irqrestore( | |
1028 | &phba->sli4_hba.abts_sgl_list_lock, iflag); | |
0f65ff68 | 1029 | } else { |
dafe8cea | 1030 | spin_lock_irqsave(&pring->ring_lock, iflag); |
0f65ff68 | 1031 | sglq->state = SGL_FREED; |
19ca7609 | 1032 | sglq->ndlp = NULL; |
fedd3b7b JS |
1033 | list_add_tail(&sglq->list, |
1034 | &phba->sli4_hba.lpfc_sgl_list); | |
dafe8cea | 1035 | spin_unlock_irqrestore(&pring->ring_lock, iflag); |
2a9bf3d0 JS |
1036 | |
1037 | /* Check if TXQ queue needs to be serviced */ | |
0e9bb8d7 | 1038 | if (!list_empty(&pring->txq)) |
2a9bf3d0 | 1039 | lpfc_worker_wake_up(phba); |
0f65ff68 | 1040 | } |
4f774513 JS |
1041 | } |
1042 | ||
1043 | ||
1044 | /* | |
1045 | * Clean all volatile data fields, preserve iotag and node struct. | |
1046 | */ | |
1047 | memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean); | |
6d368e53 | 1048 | iocbq->sli4_lxritag = NO_XRI; |
4f774513 JS |
1049 | iocbq->sli4_xritag = NO_XRI; |
1050 | list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); | |
1051 | } | |
1052 | ||
2a9bf3d0 | 1053 | |
e59058c4 | 1054 | /** |
3772a991 | 1055 | * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool |
e59058c4 JS |
1056 | * @phba: Pointer to HBA context object. |
1057 | * @iocbq: Pointer to driver iocb object. | |
1058 | * | |
1059 | * This function is called with hbalock held to release driver | |
1060 | * iocb object to the iocb pool. The iotag in the iocb object | |
1061 | * does not change for each use of the iocb object. This function | |
1062 | * clears all other fields of the iocb object when it is freed. | |
1063 | **/ | |
a6ababd2 | 1064 | static void |
3772a991 | 1065 | __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
604a3e30 | 1066 | { |
2e0fef85 | 1067 | size_t start_clean = offsetof(struct lpfc_iocbq, iocb); |
604a3e30 | 1068 | |
1c2ba475 | 1069 | lockdep_assert_held(&phba->hbalock); |
0e9bb8d7 | 1070 | |
604a3e30 JB |
1071 | /* |
1072 | * Clean all volatile data fields, preserve iotag and node struct. | |
1073 | */ | |
1074 | memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean); | |
3772a991 | 1075 | iocbq->sli4_xritag = NO_XRI; |
604a3e30 JB |
1076 | list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); |
1077 | } | |
1078 | ||
3772a991 JS |
1079 | /** |
1080 | * __lpfc_sli_release_iocbq - Release iocb to the iocb pool | |
1081 | * @phba: Pointer to HBA context object. | |
1082 | * @iocbq: Pointer to driver iocb object. | |
1083 | * | |
1084 | * This function is called with hbalock held to release driver | |
1085 | * iocb object to the iocb pool. The iotag in the iocb object | |
1086 | * does not change for each use of the iocb object. This function | |
1087 | * clears all other fields of the iocb object when it is freed. | |
1088 | **/ | |
1089 | static void | |
1090 | __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) | |
1091 | { | |
1c2ba475 JT |
1092 | lockdep_assert_held(&phba->hbalock); |
1093 | ||
3772a991 | 1094 | phba->__lpfc_sli_release_iocbq(phba, iocbq); |
2a9bf3d0 | 1095 | phba->iocb_cnt--; |
3772a991 JS |
1096 | } |
1097 | ||
e59058c4 | 1098 | /** |
3621a710 | 1099 | * lpfc_sli_release_iocbq - Release iocb to the iocb pool |
e59058c4 JS |
1100 | * @phba: Pointer to HBA context object. |
1101 | * @iocbq: Pointer to driver iocb object. | |
1102 | * | |
1103 | * This function is called with no lock held to release the iocb to | |
1104 | * iocb pool. | |
1105 | **/ | |
2e0fef85 JS |
1106 | void |
1107 | lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) | |
1108 | { | |
1109 | unsigned long iflags; | |
1110 | ||
1111 | /* | |
1112 | * Clean all volatile data fields, preserve iotag and node struct. | |
1113 | */ | |
1114 | spin_lock_irqsave(&phba->hbalock, iflags); | |
1115 | __lpfc_sli_release_iocbq(phba, iocbq); | |
1116 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
1117 | } | |
1118 | ||
a257bf90 JS |
1119 | /** |
1120 | * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list. | |
1121 | * @phba: Pointer to HBA context object. | |
1122 | * @iocblist: List of IOCBs. | |
1123 | * @ulpstatus: ULP status in IOCB command field. | |
1124 | * @ulpWord4: ULP word-4 in IOCB command field. | |
1125 | * | |
1126 | * This function is called with a list of IOCBs to cancel. It cancels the IOCB | |
1127 | * on the list by invoking the complete callback function associated with the | |
1128 | * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond | |
1129 | * fields. | |
1130 | **/ | |
1131 | void | |
1132 | lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist, | |
1133 | uint32_t ulpstatus, uint32_t ulpWord4) | |
1134 | { | |
1135 | struct lpfc_iocbq *piocb; | |
1136 | ||
1137 | while (!list_empty(iocblist)) { | |
1138 | list_remove_head(iocblist, piocb, struct lpfc_iocbq, list); | |
a257bf90 JS |
1139 | if (!piocb->iocb_cmpl) |
1140 | lpfc_sli_release_iocbq(phba, piocb); | |
1141 | else { | |
1142 | piocb->iocb.ulpStatus = ulpstatus; | |
1143 | piocb->iocb.un.ulpWord[4] = ulpWord4; | |
1144 | (piocb->iocb_cmpl) (phba, piocb, piocb); | |
1145 | } | |
1146 | } | |
1147 | return; | |
1148 | } | |
1149 | ||
e59058c4 | 1150 | /** |
3621a710 JS |
1151 | * lpfc_sli_iocb_cmd_type - Get the iocb type |
1152 | * @iocb_cmnd: iocb command code. | |
e59058c4 JS |
1153 | * |
1154 | * This function is called by ring event handler function to get the iocb type. | |
1155 | * This function translates the iocb command to an iocb command type used to | |
1156 | * decide the final disposition of each completed IOCB. | |
1157 | * The function returns | |
1158 | * LPFC_UNKNOWN_IOCB if it is an unsupported iocb | |
1159 | * LPFC_SOL_IOCB if it is a solicited iocb completion | |
1160 | * LPFC_ABORT_IOCB if it is an abort iocb | |
1161 | * LPFC_UNSOL_IOCB if it is an unsolicited iocb | |
1162 | * | |
1163 | * The caller is not required to hold any lock. | |
1164 | **/ | |
dea3101e JB |
1165 | static lpfc_iocb_type |
1166 | lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd) | |
1167 | { | |
1168 | lpfc_iocb_type type = LPFC_UNKNOWN_IOCB; | |
1169 | ||
1170 | if (iocb_cmnd > CMD_MAX_IOCB_CMD) | |
1171 | return 0; | |
1172 | ||
1173 | switch (iocb_cmnd) { | |
1174 | case CMD_XMIT_SEQUENCE_CR: | |
1175 | case CMD_XMIT_SEQUENCE_CX: | |
1176 | case CMD_XMIT_BCAST_CN: | |
1177 | case CMD_XMIT_BCAST_CX: | |
1178 | case CMD_ELS_REQUEST_CR: | |
1179 | case CMD_ELS_REQUEST_CX: | |
1180 | case CMD_CREATE_XRI_CR: | |
1181 | case CMD_CREATE_XRI_CX: | |
1182 | case CMD_GET_RPI_CN: | |
1183 | case CMD_XMIT_ELS_RSP_CX: | |
1184 | case CMD_GET_RPI_CR: | |
1185 | case CMD_FCP_IWRITE_CR: | |
1186 | case CMD_FCP_IWRITE_CX: | |
1187 | case CMD_FCP_IREAD_CR: | |
1188 | case CMD_FCP_IREAD_CX: | |
1189 | case CMD_FCP_ICMND_CR: | |
1190 | case CMD_FCP_ICMND_CX: | |
f5603511 JS |
1191 | case CMD_FCP_TSEND_CX: |
1192 | case CMD_FCP_TRSP_CX: | |
1193 | case CMD_FCP_TRECEIVE_CX: | |
1194 | case CMD_FCP_AUTO_TRSP_CX: | |
dea3101e JB |
1195 | case CMD_ADAPTER_MSG: |
1196 | case CMD_ADAPTER_DUMP: | |
1197 | case CMD_XMIT_SEQUENCE64_CR: | |
1198 | case CMD_XMIT_SEQUENCE64_CX: | |
1199 | case CMD_XMIT_BCAST64_CN: | |
1200 | case CMD_XMIT_BCAST64_CX: | |
1201 | case CMD_ELS_REQUEST64_CR: | |
1202 | case CMD_ELS_REQUEST64_CX: | |
1203 | case CMD_FCP_IWRITE64_CR: | |
1204 | case CMD_FCP_IWRITE64_CX: | |
1205 | case CMD_FCP_IREAD64_CR: | |
1206 | case CMD_FCP_IREAD64_CX: | |
1207 | case CMD_FCP_ICMND64_CR: | |
1208 | case CMD_FCP_ICMND64_CX: | |
f5603511 JS |
1209 | case CMD_FCP_TSEND64_CX: |
1210 | case CMD_FCP_TRSP64_CX: | |
1211 | case CMD_FCP_TRECEIVE64_CX: | |
dea3101e JB |
1212 | case CMD_GEN_REQUEST64_CR: |
1213 | case CMD_GEN_REQUEST64_CX: | |
1214 | case CMD_XMIT_ELS_RSP64_CX: | |
da0436e9 JS |
1215 | case DSSCMD_IWRITE64_CR: |
1216 | case DSSCMD_IWRITE64_CX: | |
1217 | case DSSCMD_IREAD64_CR: | |
1218 | case DSSCMD_IREAD64_CX: | |
dea3101e JB |
1219 | type = LPFC_SOL_IOCB; |
1220 | break; | |
1221 | case CMD_ABORT_XRI_CN: | |
1222 | case CMD_ABORT_XRI_CX: | |
1223 | case CMD_CLOSE_XRI_CN: | |
1224 | case CMD_CLOSE_XRI_CX: | |
1225 | case CMD_XRI_ABORTED_CX: | |
1226 | case CMD_ABORT_MXRI64_CN: | |
6669f9bb | 1227 | case CMD_XMIT_BLS_RSP64_CX: |
dea3101e JB |
1228 | type = LPFC_ABORT_IOCB; |
1229 | break; | |
1230 | case CMD_RCV_SEQUENCE_CX: | |
1231 | case CMD_RCV_ELS_REQ_CX: | |
1232 | case CMD_RCV_SEQUENCE64_CX: | |
1233 | case CMD_RCV_ELS_REQ64_CX: | |
57127f15 | 1234 | case CMD_ASYNC_STATUS: |
ed957684 JS |
1235 | case CMD_IOCB_RCV_SEQ64_CX: |
1236 | case CMD_IOCB_RCV_ELS64_CX: | |
1237 | case CMD_IOCB_RCV_CONT64_CX: | |
3163f725 | 1238 | case CMD_IOCB_RET_XRI64_CX: |
dea3101e JB |
1239 | type = LPFC_UNSOL_IOCB; |
1240 | break; | |
3163f725 JS |
1241 | case CMD_IOCB_XMIT_MSEQ64_CR: |
1242 | case CMD_IOCB_XMIT_MSEQ64_CX: | |
1243 | case CMD_IOCB_RCV_SEQ_LIST64_CX: | |
1244 | case CMD_IOCB_RCV_ELS_LIST64_CX: | |
1245 | case CMD_IOCB_CLOSE_EXTENDED_CN: | |
1246 | case CMD_IOCB_ABORT_EXTENDED_CN: | |
1247 | case CMD_IOCB_RET_HBQE64_CN: | |
1248 | case CMD_IOCB_FCP_IBIDIR64_CR: | |
1249 | case CMD_IOCB_FCP_IBIDIR64_CX: | |
1250 | case CMD_IOCB_FCP_ITASKMGT64_CX: | |
1251 | case CMD_IOCB_LOGENTRY_CN: | |
1252 | case CMD_IOCB_LOGENTRY_ASYNC_CN: | |
1253 | printk("%s - Unhandled SLI-3 Command x%x\n", | |
cadbd4a5 | 1254 | __func__, iocb_cmnd); |
3163f725 JS |
1255 | type = LPFC_UNKNOWN_IOCB; |
1256 | break; | |
dea3101e JB |
1257 | default: |
1258 | type = LPFC_UNKNOWN_IOCB; | |
1259 | break; | |
1260 | } | |
1261 | ||
1262 | return type; | |
1263 | } | |
1264 | ||
e59058c4 | 1265 | /** |
3621a710 | 1266 | * lpfc_sli_ring_map - Issue config_ring mbox for all rings |
e59058c4 JS |
1267 | * @phba: Pointer to HBA context object. |
1268 | * | |
1269 | * This function is called from SLI initialization code | |
1270 | * to configure every ring of the HBA's SLI interface. The | |
1271 | * caller is not required to hold any lock. This function issues | |
1272 | * a config_ring mailbox command for each ring. | |
1273 | * This function returns zero if successful else returns a negative | |
1274 | * error code. | |
1275 | **/ | |
dea3101e | 1276 | static int |
ed957684 | 1277 | lpfc_sli_ring_map(struct lpfc_hba *phba) |
dea3101e JB |
1278 | { |
1279 | struct lpfc_sli *psli = &phba->sli; | |
ed957684 JS |
1280 | LPFC_MBOXQ_t *pmb; |
1281 | MAILBOX_t *pmbox; | |
1282 | int i, rc, ret = 0; | |
dea3101e | 1283 | |
ed957684 JS |
1284 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
1285 | if (!pmb) | |
1286 | return -ENOMEM; | |
04c68496 | 1287 | pmbox = &pmb->u.mb; |
ed957684 | 1288 | phba->link_state = LPFC_INIT_MBX_CMDS; |
dea3101e | 1289 | for (i = 0; i < psli->num_rings; i++) { |
dea3101e JB |
1290 | lpfc_config_ring(phba, i, pmb); |
1291 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); | |
1292 | if (rc != MBX_SUCCESS) { | |
92d7f7b0 | 1293 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 1294 | "0446 Adapter failed to init (%d), " |
dea3101e JB |
1295 | "mbxCmd x%x CFG_RING, mbxStatus x%x, " |
1296 | "ring %d\n", | |
e8b62011 JS |
1297 | rc, pmbox->mbxCommand, |
1298 | pmbox->mbxStatus, i); | |
2e0fef85 | 1299 | phba->link_state = LPFC_HBA_ERROR; |
ed957684 JS |
1300 | ret = -ENXIO; |
1301 | break; | |
dea3101e JB |
1302 | } |
1303 | } | |
ed957684 JS |
1304 | mempool_free(pmb, phba->mbox_mem_pool); |
1305 | return ret; | |
dea3101e JB |
1306 | } |
1307 | ||
e59058c4 | 1308 | /** |
3621a710 | 1309 | * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq |
e59058c4 JS |
1310 | * @phba: Pointer to HBA context object. |
1311 | * @pring: Pointer to driver SLI ring object. | |
1312 | * @piocb: Pointer to the driver iocb object. | |
1313 | * | |
1314 | * This function is called with hbalock held. The function adds the | |
1315 | * new iocb to txcmplq of the given ring. This function always returns | |
1316 | * 0. If this function is called for ELS ring, this function checks if | |
1317 | * there is a vport associated with the ELS command. This function also | |
1318 | * starts els_tmofunc timer if this is an ELS command. | |
1319 | **/ | |
dea3101e | 1320 | static int |
2e0fef85 JS |
1321 | lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
1322 | struct lpfc_iocbq *piocb) | |
dea3101e | 1323 | { |
1c2ba475 JT |
1324 | lockdep_assert_held(&phba->hbalock); |
1325 | ||
dea3101e | 1326 | list_add_tail(&piocb->list, &pring->txcmplq); |
4f2e66c6 | 1327 | piocb->iocb_flag |= LPFC_IO_ON_TXCMPLQ; |
2a9bf3d0 | 1328 | |
92d7f7b0 JS |
1329 | if ((unlikely(pring->ringno == LPFC_ELS_RING)) && |
1330 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && | |
06918ac5 JS |
1331 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN) && |
1332 | (!(piocb->vport->load_flag & FC_UNLOADING))) { | |
92d7f7b0 JS |
1333 | if (!piocb->vport) |
1334 | BUG(); | |
1335 | else | |
1336 | mod_timer(&piocb->vport->els_tmofunc, | |
256ec0d0 JS |
1337 | jiffies + |
1338 | msecs_to_jiffies(1000 * (phba->fc_ratov << 1))); | |
92d7f7b0 JS |
1339 | } |
1340 | ||
dea3101e | 1341 | |
2e0fef85 | 1342 | return 0; |
dea3101e JB |
1343 | } |
1344 | ||
e59058c4 | 1345 | /** |
3621a710 | 1346 | * lpfc_sli_ringtx_get - Get first element of the txq |
e59058c4 JS |
1347 | * @phba: Pointer to HBA context object. |
1348 | * @pring: Pointer to driver SLI ring object. | |
1349 | * | |
1350 | * This function is called with hbalock held to get next | |
1351 | * iocb in txq of the given ring. If there is any iocb in | |
1352 | * the txq, the function returns first iocb in the list after | |
1353 | * removing the iocb from the list, else it returns NULL. | |
1354 | **/ | |
2a9bf3d0 | 1355 | struct lpfc_iocbq * |
2e0fef85 | 1356 | lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
dea3101e | 1357 | { |
dea3101e JB |
1358 | struct lpfc_iocbq *cmd_iocb; |
1359 | ||
1c2ba475 JT |
1360 | lockdep_assert_held(&phba->hbalock); |
1361 | ||
858c9f6c | 1362 | list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list); |
2e0fef85 | 1363 | return cmd_iocb; |
dea3101e JB |
1364 | } |
1365 | ||
e59058c4 | 1366 | /** |
3621a710 | 1367 | * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring |
e59058c4 JS |
1368 | * @phba: Pointer to HBA context object. |
1369 | * @pring: Pointer to driver SLI ring object. | |
1370 | * | |
1371 | * This function is called with hbalock held and the caller must post the | |
1372 | * iocb without releasing the lock. If the caller releases the lock, | |
1373 | * iocb slot returned by the function is not guaranteed to be available. | |
1374 | * The function returns pointer to the next available iocb slot if there | |
1375 | * is available slot in the ring, else it returns NULL. | |
1376 | * If the get index of the ring is ahead of the put index, the function | |
1377 | * will post an error attention event to the worker thread to take the | |
1378 | * HBA to offline state. | |
1379 | **/ | |
dea3101e JB |
1380 | static IOCB_t * |
1381 | lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring) | |
1382 | { | |
34b02dcd | 1383 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
7e56aa25 | 1384 | uint32_t max_cmd_idx = pring->sli.sli3.numCiocb; |
1c2ba475 JT |
1385 | |
1386 | lockdep_assert_held(&phba->hbalock); | |
1387 | ||
7e56aa25 JS |
1388 | if ((pring->sli.sli3.next_cmdidx == pring->sli.sli3.cmdidx) && |
1389 | (++pring->sli.sli3.next_cmdidx >= max_cmd_idx)) | |
1390 | pring->sli.sli3.next_cmdidx = 0; | |
dea3101e | 1391 | |
7e56aa25 JS |
1392 | if (unlikely(pring->sli.sli3.local_getidx == |
1393 | pring->sli.sli3.next_cmdidx)) { | |
dea3101e | 1394 | |
7e56aa25 | 1395 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
dea3101e | 1396 | |
7e56aa25 | 1397 | if (unlikely(pring->sli.sli3.local_getidx >= max_cmd_idx)) { |
dea3101e | 1398 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
e8b62011 | 1399 | "0315 Ring %d issue: portCmdGet %d " |
025dfdaf | 1400 | "is bigger than cmd ring %d\n", |
e8b62011 | 1401 | pring->ringno, |
7e56aa25 JS |
1402 | pring->sli.sli3.local_getidx, |
1403 | max_cmd_idx); | |
dea3101e | 1404 | |
2e0fef85 | 1405 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e JB |
1406 | /* |
1407 | * All error attention handlers are posted to | |
1408 | * worker thread | |
1409 | */ | |
1410 | phba->work_ha |= HA_ERATT; | |
1411 | phba->work_hs = HS_FFER3; | |
92d7f7b0 | 1412 | |
5e9d9b82 | 1413 | lpfc_worker_wake_up(phba); |
dea3101e JB |
1414 | |
1415 | return NULL; | |
1416 | } | |
1417 | ||
7e56aa25 | 1418 | if (pring->sli.sli3.local_getidx == pring->sli.sli3.next_cmdidx) |
dea3101e JB |
1419 | return NULL; |
1420 | } | |
1421 | ||
ed957684 | 1422 | return lpfc_cmd_iocb(phba, pring); |
dea3101e JB |
1423 | } |
1424 | ||
e59058c4 | 1425 | /** |
3621a710 | 1426 | * lpfc_sli_next_iotag - Get an iotag for the iocb |
e59058c4 JS |
1427 | * @phba: Pointer to HBA context object. |
1428 | * @iocbq: Pointer to driver iocb object. | |
1429 | * | |
1430 | * This function gets an iotag for the iocb. If there is no unused iotag and | |
1431 | * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup | |
1432 | * array and assigns a new iotag. | |
1433 | * The function returns the allocated iotag if successful, else returns zero. | |
1434 | * Zero is not a valid iotag. | |
1435 | * The caller is not required to hold any lock. | |
1436 | **/ | |
604a3e30 | 1437 | uint16_t |
2e0fef85 | 1438 | lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
dea3101e | 1439 | { |
2e0fef85 JS |
1440 | struct lpfc_iocbq **new_arr; |
1441 | struct lpfc_iocbq **old_arr; | |
604a3e30 JB |
1442 | size_t new_len; |
1443 | struct lpfc_sli *psli = &phba->sli; | |
1444 | uint16_t iotag; | |
dea3101e | 1445 | |
2e0fef85 | 1446 | spin_lock_irq(&phba->hbalock); |
604a3e30 JB |
1447 | iotag = psli->last_iotag; |
1448 | if(++iotag < psli->iocbq_lookup_len) { | |
1449 | psli->last_iotag = iotag; | |
1450 | psli->iocbq_lookup[iotag] = iocbq; | |
2e0fef85 | 1451 | spin_unlock_irq(&phba->hbalock); |
604a3e30 JB |
1452 | iocbq->iotag = iotag; |
1453 | return iotag; | |
2e0fef85 | 1454 | } else if (psli->iocbq_lookup_len < (0xffff |
604a3e30 JB |
1455 | - LPFC_IOCBQ_LOOKUP_INCREMENT)) { |
1456 | new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT; | |
2e0fef85 JS |
1457 | spin_unlock_irq(&phba->hbalock); |
1458 | new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *), | |
604a3e30 JB |
1459 | GFP_KERNEL); |
1460 | if (new_arr) { | |
2e0fef85 | 1461 | spin_lock_irq(&phba->hbalock); |
604a3e30 JB |
1462 | old_arr = psli->iocbq_lookup; |
1463 | if (new_len <= psli->iocbq_lookup_len) { | |
1464 | /* highly unprobable case */ | |
1465 | kfree(new_arr); | |
1466 | iotag = psli->last_iotag; | |
1467 | if(++iotag < psli->iocbq_lookup_len) { | |
1468 | psli->last_iotag = iotag; | |
1469 | psli->iocbq_lookup[iotag] = iocbq; | |
2e0fef85 | 1470 | spin_unlock_irq(&phba->hbalock); |
604a3e30 JB |
1471 | iocbq->iotag = iotag; |
1472 | return iotag; | |
1473 | } | |
2e0fef85 | 1474 | spin_unlock_irq(&phba->hbalock); |
604a3e30 JB |
1475 | return 0; |
1476 | } | |
1477 | if (psli->iocbq_lookup) | |
1478 | memcpy(new_arr, old_arr, | |
1479 | ((psli->last_iotag + 1) * | |
311464ec | 1480 | sizeof (struct lpfc_iocbq *))); |
604a3e30 JB |
1481 | psli->iocbq_lookup = new_arr; |
1482 | psli->iocbq_lookup_len = new_len; | |
1483 | psli->last_iotag = iotag; | |
1484 | psli->iocbq_lookup[iotag] = iocbq; | |
2e0fef85 | 1485 | spin_unlock_irq(&phba->hbalock); |
604a3e30 JB |
1486 | iocbq->iotag = iotag; |
1487 | kfree(old_arr); | |
1488 | return iotag; | |
1489 | } | |
8f6d98d2 | 1490 | } else |
2e0fef85 | 1491 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 1492 | |
bc73905a | 1493 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
e8b62011 JS |
1494 | "0318 Failed to allocate IOTAG.last IOTAG is %d\n", |
1495 | psli->last_iotag); | |
dea3101e | 1496 | |
604a3e30 | 1497 | return 0; |
dea3101e JB |
1498 | } |
1499 | ||
e59058c4 | 1500 | /** |
3621a710 | 1501 | * lpfc_sli_submit_iocb - Submit an iocb to the firmware |
e59058c4 JS |
1502 | * @phba: Pointer to HBA context object. |
1503 | * @pring: Pointer to driver SLI ring object. | |
1504 | * @iocb: Pointer to iocb slot in the ring. | |
1505 | * @nextiocb: Pointer to driver iocb object which need to be | |
1506 | * posted to firmware. | |
1507 | * | |
1508 | * This function is called with hbalock held to post a new iocb to | |
1509 | * the firmware. This function copies the new iocb to ring iocb slot and | |
1510 | * updates the ring pointers. It adds the new iocb to txcmplq if there is | |
1511 | * a completion call back for this iocb else the function will free the | |
1512 | * iocb object. | |
1513 | **/ | |
dea3101e JB |
1514 | static void |
1515 | lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
1516 | IOCB_t *iocb, struct lpfc_iocbq *nextiocb) | |
1517 | { | |
1c2ba475 | 1518 | lockdep_assert_held(&phba->hbalock); |
dea3101e | 1519 | /* |
604a3e30 | 1520 | * Set up an iotag |
dea3101e | 1521 | */ |
604a3e30 | 1522 | nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0; |
dea3101e | 1523 | |
e2a0a9d6 | 1524 | |
a58cbd52 JS |
1525 | if (pring->ringno == LPFC_ELS_RING) { |
1526 | lpfc_debugfs_slow_ring_trc(phba, | |
1527 | "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x", | |
1528 | *(((uint32_t *) &nextiocb->iocb) + 4), | |
1529 | *(((uint32_t *) &nextiocb->iocb) + 6), | |
1530 | *(((uint32_t *) &nextiocb->iocb) + 7)); | |
1531 | } | |
1532 | ||
dea3101e JB |
1533 | /* |
1534 | * Issue iocb command to adapter | |
1535 | */ | |
92d7f7b0 | 1536 | lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size); |
dea3101e JB |
1537 | wmb(); |
1538 | pring->stats.iocb_cmd++; | |
1539 | ||
1540 | /* | |
1541 | * If there is no completion routine to call, we can release the | |
1542 | * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF, | |
1543 | * that have no rsp ring completion, iocb_cmpl MUST be NULL. | |
1544 | */ | |
1545 | if (nextiocb->iocb_cmpl) | |
1546 | lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb); | |
604a3e30 | 1547 | else |
2e0fef85 | 1548 | __lpfc_sli_release_iocbq(phba, nextiocb); |
dea3101e JB |
1549 | |
1550 | /* | |
1551 | * Let the HBA know what IOCB slot will be the next one the | |
1552 | * driver will put a command into. | |
1553 | */ | |
7e56aa25 JS |
1554 | pring->sli.sli3.cmdidx = pring->sli.sli3.next_cmdidx; |
1555 | writel(pring->sli.sli3.cmdidx, &phba->host_gp[pring->ringno].cmdPutInx); | |
dea3101e JB |
1556 | } |
1557 | ||
e59058c4 | 1558 | /** |
3621a710 | 1559 | * lpfc_sli_update_full_ring - Update the chip attention register |
e59058c4 JS |
1560 | * @phba: Pointer to HBA context object. |
1561 | * @pring: Pointer to driver SLI ring object. | |
1562 | * | |
1563 | * The caller is not required to hold any lock for calling this function. | |
1564 | * This function updates the chip attention bits for the ring to inform firmware | |
1565 | * that there are pending work to be done for this ring and requests an | |
1566 | * interrupt when there is space available in the ring. This function is | |
1567 | * called when the driver is unable to post more iocbs to the ring due | |
1568 | * to unavailability of space in the ring. | |
1569 | **/ | |
dea3101e | 1570 | static void |
2e0fef85 | 1571 | lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
dea3101e JB |
1572 | { |
1573 | int ringno = pring->ringno; | |
1574 | ||
1575 | pring->flag |= LPFC_CALL_RING_AVAILABLE; | |
1576 | ||
1577 | wmb(); | |
1578 | ||
1579 | /* | |
1580 | * Set ring 'ringno' to SET R0CE_REQ in Chip Att register. | |
1581 | * The HBA will tell us when an IOCB entry is available. | |
1582 | */ | |
1583 | writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr); | |
1584 | readl(phba->CAregaddr); /* flush */ | |
1585 | ||
1586 | pring->stats.iocb_cmd_full++; | |
1587 | } | |
1588 | ||
e59058c4 | 1589 | /** |
3621a710 | 1590 | * lpfc_sli_update_ring - Update chip attention register |
e59058c4 JS |
1591 | * @phba: Pointer to HBA context object. |
1592 | * @pring: Pointer to driver SLI ring object. | |
1593 | * | |
1594 | * This function updates the chip attention register bit for the | |
1595 | * given ring to inform HBA that there is more work to be done | |
1596 | * in this ring. The caller is not required to hold any lock. | |
1597 | **/ | |
dea3101e | 1598 | static void |
2e0fef85 | 1599 | lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
dea3101e JB |
1600 | { |
1601 | int ringno = pring->ringno; | |
1602 | ||
1603 | /* | |
1604 | * Tell the HBA that there is work to do in this ring. | |
1605 | */ | |
34b02dcd JS |
1606 | if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) { |
1607 | wmb(); | |
1608 | writel(CA_R0ATT << (ringno * 4), phba->CAregaddr); | |
1609 | readl(phba->CAregaddr); /* flush */ | |
1610 | } | |
dea3101e JB |
1611 | } |
1612 | ||
e59058c4 | 1613 | /** |
3621a710 | 1614 | * lpfc_sli_resume_iocb - Process iocbs in the txq |
e59058c4 JS |
1615 | * @phba: Pointer to HBA context object. |
1616 | * @pring: Pointer to driver SLI ring object. | |
1617 | * | |
1618 | * This function is called with hbalock held to post pending iocbs | |
1619 | * in the txq to the firmware. This function is called when driver | |
1620 | * detects space available in the ring. | |
1621 | **/ | |
dea3101e | 1622 | static void |
2e0fef85 | 1623 | lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
dea3101e JB |
1624 | { |
1625 | IOCB_t *iocb; | |
1626 | struct lpfc_iocbq *nextiocb; | |
1627 | ||
1c2ba475 JT |
1628 | lockdep_assert_held(&phba->hbalock); |
1629 | ||
dea3101e JB |
1630 | /* |
1631 | * Check to see if: | |
1632 | * (a) there is anything on the txq to send | |
1633 | * (b) link is up | |
1634 | * (c) link attention events can be processed (fcp ring only) | |
1635 | * (d) IOCB processing is not blocked by the outstanding mbox command. | |
1636 | */ | |
0e9bb8d7 JS |
1637 | |
1638 | if (lpfc_is_link_up(phba) && | |
1639 | (!list_empty(&pring->txq)) && | |
dea3101e | 1640 | (pring->ringno != phba->sli.fcp_ring || |
0b727fea | 1641 | phba->sli.sli_flag & LPFC_PROCESS_LA)) { |
dea3101e JB |
1642 | |
1643 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && | |
1644 | (nextiocb = lpfc_sli_ringtx_get(phba, pring))) | |
1645 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); | |
1646 | ||
1647 | if (iocb) | |
1648 | lpfc_sli_update_ring(phba, pring); | |
1649 | else | |
1650 | lpfc_sli_update_full_ring(phba, pring); | |
1651 | } | |
1652 | ||
1653 | return; | |
1654 | } | |
1655 | ||
e59058c4 | 1656 | /** |
3621a710 | 1657 | * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ |
e59058c4 JS |
1658 | * @phba: Pointer to HBA context object. |
1659 | * @hbqno: HBQ number. | |
1660 | * | |
1661 | * This function is called with hbalock held to get the next | |
1662 | * available slot for the given HBQ. If there is free slot | |
1663 | * available for the HBQ it will return pointer to the next available | |
1664 | * HBQ entry else it will return NULL. | |
1665 | **/ | |
a6ababd2 | 1666 | static struct lpfc_hbq_entry * |
ed957684 JS |
1667 | lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno) |
1668 | { | |
1669 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; | |
1670 | ||
1c2ba475 JT |
1671 | lockdep_assert_held(&phba->hbalock); |
1672 | ||
ed957684 JS |
1673 | if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx && |
1674 | ++hbqp->next_hbqPutIdx >= hbqp->entry_count) | |
1675 | hbqp->next_hbqPutIdx = 0; | |
1676 | ||
1677 | if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) { | |
92d7f7b0 | 1678 | uint32_t raw_index = phba->hbq_get[hbqno]; |
ed957684 JS |
1679 | uint32_t getidx = le32_to_cpu(raw_index); |
1680 | ||
1681 | hbqp->local_hbqGetIdx = getidx; | |
1682 | ||
1683 | if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) { | |
1684 | lpfc_printf_log(phba, KERN_ERR, | |
92d7f7b0 | 1685 | LOG_SLI | LOG_VPORT, |
e8b62011 | 1686 | "1802 HBQ %d: local_hbqGetIdx " |
ed957684 | 1687 | "%u is > than hbqp->entry_count %u\n", |
e8b62011 | 1688 | hbqno, hbqp->local_hbqGetIdx, |
ed957684 JS |
1689 | hbqp->entry_count); |
1690 | ||
1691 | phba->link_state = LPFC_HBA_ERROR; | |
1692 | return NULL; | |
1693 | } | |
1694 | ||
1695 | if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx) | |
1696 | return NULL; | |
1697 | } | |
1698 | ||
51ef4c26 JS |
1699 | return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt + |
1700 | hbqp->hbqPutIdx; | |
ed957684 JS |
1701 | } |
1702 | ||
e59058c4 | 1703 | /** |
3621a710 | 1704 | * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers |
e59058c4 JS |
1705 | * @phba: Pointer to HBA context object. |
1706 | * | |
1707 | * This function is called with no lock held to free all the | |
1708 | * hbq buffers while uninitializing the SLI interface. It also | |
1709 | * frees the HBQ buffers returned by the firmware but not yet | |
1710 | * processed by the upper layers. | |
1711 | **/ | |
ed957684 JS |
1712 | void |
1713 | lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba) | |
1714 | { | |
92d7f7b0 JS |
1715 | struct lpfc_dmabuf *dmabuf, *next_dmabuf; |
1716 | struct hbq_dmabuf *hbq_buf; | |
3163f725 | 1717 | unsigned long flags; |
51ef4c26 | 1718 | int i, hbq_count; |
3163f725 | 1719 | uint32_t hbqno; |
ed957684 | 1720 | |
51ef4c26 | 1721 | hbq_count = lpfc_sli_hbq_count(); |
ed957684 | 1722 | /* Return all memory used by all HBQs */ |
3163f725 | 1723 | spin_lock_irqsave(&phba->hbalock, flags); |
51ef4c26 JS |
1724 | for (i = 0; i < hbq_count; ++i) { |
1725 | list_for_each_entry_safe(dmabuf, next_dmabuf, | |
1726 | &phba->hbqs[i].hbq_buffer_list, list) { | |
1727 | hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf); | |
1728 | list_del(&hbq_buf->dbuf.list); | |
1729 | (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf); | |
1730 | } | |
a8adb832 | 1731 | phba->hbqs[i].buffer_count = 0; |
ed957684 | 1732 | } |
3163f725 | 1733 | /* Return all HBQ buffer that are in-fly */ |
3772a991 JS |
1734 | list_for_each_entry_safe(dmabuf, next_dmabuf, &phba->rb_pend_list, |
1735 | list) { | |
3163f725 JS |
1736 | hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf); |
1737 | list_del(&hbq_buf->dbuf.list); | |
1738 | if (hbq_buf->tag == -1) { | |
1739 | (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer) | |
1740 | (phba, hbq_buf); | |
1741 | } else { | |
1742 | hbqno = hbq_buf->tag >> 16; | |
1743 | if (hbqno >= LPFC_MAX_HBQS) | |
1744 | (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer) | |
1745 | (phba, hbq_buf); | |
1746 | else | |
1747 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, | |
1748 | hbq_buf); | |
1749 | } | |
1750 | } | |
1751 | ||
1752 | /* Mark the HBQs not in use */ | |
1753 | phba->hbq_in_use = 0; | |
1754 | spin_unlock_irqrestore(&phba->hbalock, flags); | |
ed957684 JS |
1755 | } |
1756 | ||
e59058c4 | 1757 | /** |
3621a710 | 1758 | * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware |
e59058c4 JS |
1759 | * @phba: Pointer to HBA context object. |
1760 | * @hbqno: HBQ number. | |
1761 | * @hbq_buf: Pointer to HBQ buffer. | |
1762 | * | |
1763 | * This function is called with the hbalock held to post a | |
1764 | * hbq buffer to the firmware. If the function finds an empty | |
1765 | * slot in the HBQ, it will post the buffer. The function will return | |
1766 | * pointer to the hbq entry if it successfully post the buffer | |
1767 | * else it will return NULL. | |
1768 | **/ | |
3772a991 | 1769 | static int |
ed957684 | 1770 | lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno, |
92d7f7b0 | 1771 | struct hbq_dmabuf *hbq_buf) |
3772a991 | 1772 | { |
1c2ba475 | 1773 | lockdep_assert_held(&phba->hbalock); |
3772a991 JS |
1774 | return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf); |
1775 | } | |
1776 | ||
1777 | /** | |
1778 | * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware | |
1779 | * @phba: Pointer to HBA context object. | |
1780 | * @hbqno: HBQ number. | |
1781 | * @hbq_buf: Pointer to HBQ buffer. | |
1782 | * | |
1783 | * This function is called with the hbalock held to post a hbq buffer to the | |
1784 | * firmware. If the function finds an empty slot in the HBQ, it will post the | |
1785 | * buffer and place it on the hbq_buffer_list. The function will return zero if | |
1786 | * it successfully post the buffer else it will return an error. | |
1787 | **/ | |
1788 | static int | |
1789 | lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno, | |
1790 | struct hbq_dmabuf *hbq_buf) | |
ed957684 JS |
1791 | { |
1792 | struct lpfc_hbq_entry *hbqe; | |
92d7f7b0 | 1793 | dma_addr_t physaddr = hbq_buf->dbuf.phys; |
ed957684 | 1794 | |
1c2ba475 | 1795 | lockdep_assert_held(&phba->hbalock); |
ed957684 JS |
1796 | /* Get next HBQ entry slot to use */ |
1797 | hbqe = lpfc_sli_next_hbq_slot(phba, hbqno); | |
1798 | if (hbqe) { | |
1799 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; | |
1800 | ||
92d7f7b0 JS |
1801 | hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr)); |
1802 | hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr)); | |
51ef4c26 | 1803 | hbqe->bde.tus.f.bdeSize = hbq_buf->size; |
ed957684 | 1804 | hbqe->bde.tus.f.bdeFlags = 0; |
92d7f7b0 JS |
1805 | hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w); |
1806 | hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag); | |
1807 | /* Sync SLIM */ | |
ed957684 JS |
1808 | hbqp->hbqPutIdx = hbqp->next_hbqPutIdx; |
1809 | writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno); | |
92d7f7b0 | 1810 | /* flush */ |
ed957684 | 1811 | readl(phba->hbq_put + hbqno); |
51ef4c26 | 1812 | list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list); |
3772a991 JS |
1813 | return 0; |
1814 | } else | |
1815 | return -ENOMEM; | |
ed957684 JS |
1816 | } |
1817 | ||
4f774513 JS |
1818 | /** |
1819 | * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware | |
1820 | * @phba: Pointer to HBA context object. | |
1821 | * @hbqno: HBQ number. | |
1822 | * @hbq_buf: Pointer to HBQ buffer. | |
1823 | * | |
1824 | * This function is called with the hbalock held to post an RQE to the SLI4 | |
1825 | * firmware. If able to post the RQE to the RQ it will queue the hbq entry to | |
1826 | * the hbq_buffer_list and return zero, otherwise it will return an error. | |
1827 | **/ | |
1828 | static int | |
1829 | lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno, | |
1830 | struct hbq_dmabuf *hbq_buf) | |
1831 | { | |
1832 | int rc; | |
1833 | struct lpfc_rqe hrqe; | |
1834 | struct lpfc_rqe drqe; | |
1835 | ||
1c2ba475 | 1836 | lockdep_assert_held(&phba->hbalock); |
4f774513 JS |
1837 | hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys); |
1838 | hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys); | |
1839 | drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys); | |
1840 | drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys); | |
1841 | rc = lpfc_sli4_rq_put(phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq, | |
1842 | &hrqe, &drqe); | |
1843 | if (rc < 0) | |
1844 | return rc; | |
1845 | hbq_buf->tag = rc; | |
1846 | list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list); | |
1847 | return 0; | |
1848 | } | |
1849 | ||
e59058c4 | 1850 | /* HBQ for ELS and CT traffic. */ |
92d7f7b0 JS |
1851 | static struct lpfc_hbq_init lpfc_els_hbq = { |
1852 | .rn = 1, | |
def9c7a9 | 1853 | .entry_count = 256, |
92d7f7b0 JS |
1854 | .mask_count = 0, |
1855 | .profile = 0, | |
51ef4c26 | 1856 | .ring_mask = (1 << LPFC_ELS_RING), |
92d7f7b0 | 1857 | .buffer_count = 0, |
a257bf90 JS |
1858 | .init_count = 40, |
1859 | .add_count = 40, | |
92d7f7b0 | 1860 | }; |
ed957684 | 1861 | |
e59058c4 | 1862 | /* HBQ for the extra ring if needed */ |
51ef4c26 JS |
1863 | static struct lpfc_hbq_init lpfc_extra_hbq = { |
1864 | .rn = 1, | |
1865 | .entry_count = 200, | |
1866 | .mask_count = 0, | |
1867 | .profile = 0, | |
1868 | .ring_mask = (1 << LPFC_EXTRA_RING), | |
1869 | .buffer_count = 0, | |
1870 | .init_count = 0, | |
1871 | .add_count = 5, | |
1872 | }; | |
1873 | ||
e59058c4 | 1874 | /* Array of HBQs */ |
78b2d852 | 1875 | struct lpfc_hbq_init *lpfc_hbq_defs[] = { |
92d7f7b0 | 1876 | &lpfc_els_hbq, |
51ef4c26 | 1877 | &lpfc_extra_hbq, |
92d7f7b0 | 1878 | }; |
ed957684 | 1879 | |
e59058c4 | 1880 | /** |
3621a710 | 1881 | * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ |
e59058c4 JS |
1882 | * @phba: Pointer to HBA context object. |
1883 | * @hbqno: HBQ number. | |
1884 | * @count: Number of HBQ buffers to be posted. | |
1885 | * | |
d7c255b2 JS |
1886 | * This function is called with no lock held to post more hbq buffers to the |
1887 | * given HBQ. The function returns the number of HBQ buffers successfully | |
1888 | * posted. | |
e59058c4 | 1889 | **/ |
311464ec | 1890 | static int |
92d7f7b0 | 1891 | lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count) |
ed957684 | 1892 | { |
d7c255b2 | 1893 | uint32_t i, posted = 0; |
3163f725 | 1894 | unsigned long flags; |
92d7f7b0 | 1895 | struct hbq_dmabuf *hbq_buffer; |
d7c255b2 | 1896 | LIST_HEAD(hbq_buf_list); |
eafe1df9 | 1897 | if (!phba->hbqs[hbqno].hbq_alloc_buffer) |
51ef4c26 | 1898 | return 0; |
51ef4c26 | 1899 | |
d7c255b2 JS |
1900 | if ((phba->hbqs[hbqno].buffer_count + count) > |
1901 | lpfc_hbq_defs[hbqno]->entry_count) | |
1902 | count = lpfc_hbq_defs[hbqno]->entry_count - | |
1903 | phba->hbqs[hbqno].buffer_count; | |
1904 | if (!count) | |
1905 | return 0; | |
1906 | /* Allocate HBQ entries */ | |
1907 | for (i = 0; i < count; i++) { | |
1908 | hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba); | |
1909 | if (!hbq_buffer) | |
1910 | break; | |
1911 | list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list); | |
1912 | } | |
3163f725 JS |
1913 | /* Check whether HBQ is still in use */ |
1914 | spin_lock_irqsave(&phba->hbalock, flags); | |
eafe1df9 | 1915 | if (!phba->hbq_in_use) |
d7c255b2 JS |
1916 | goto err; |
1917 | while (!list_empty(&hbq_buf_list)) { | |
1918 | list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf, | |
1919 | dbuf.list); | |
1920 | hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count | | |
1921 | (hbqno << 16)); | |
3772a991 | 1922 | if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) { |
a8adb832 | 1923 | phba->hbqs[hbqno].buffer_count++; |
d7c255b2 JS |
1924 | posted++; |
1925 | } else | |
51ef4c26 | 1926 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
ed957684 | 1927 | } |
3163f725 | 1928 | spin_unlock_irqrestore(&phba->hbalock, flags); |
d7c255b2 JS |
1929 | return posted; |
1930 | err: | |
eafe1df9 | 1931 | spin_unlock_irqrestore(&phba->hbalock, flags); |
d7c255b2 JS |
1932 | while (!list_empty(&hbq_buf_list)) { |
1933 | list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf, | |
1934 | dbuf.list); | |
1935 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); | |
1936 | } | |
1937 | return 0; | |
ed957684 JS |
1938 | } |
1939 | ||
e59058c4 | 1940 | /** |
3621a710 | 1941 | * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware |
e59058c4 JS |
1942 | * @phba: Pointer to HBA context object. |
1943 | * @qno: HBQ number. | |
1944 | * | |
1945 | * This function posts more buffers to the HBQ. This function | |
d7c255b2 JS |
1946 | * is called with no lock held. The function returns the number of HBQ entries |
1947 | * successfully allocated. | |
e59058c4 | 1948 | **/ |
92d7f7b0 JS |
1949 | int |
1950 | lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno) | |
ed957684 | 1951 | { |
def9c7a9 JS |
1952 | if (phba->sli_rev == LPFC_SLI_REV4) |
1953 | return 0; | |
1954 | else | |
1955 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, | |
1956 | lpfc_hbq_defs[qno]->add_count); | |
92d7f7b0 | 1957 | } |
ed957684 | 1958 | |
e59058c4 | 1959 | /** |
3621a710 | 1960 | * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ |
e59058c4 JS |
1961 | * @phba: Pointer to HBA context object. |
1962 | * @qno: HBQ queue number. | |
1963 | * | |
1964 | * This function is called from SLI initialization code path with | |
1965 | * no lock held to post initial HBQ buffers to firmware. The | |
d7c255b2 | 1966 | * function returns the number of HBQ entries successfully allocated. |
e59058c4 | 1967 | **/ |
a6ababd2 | 1968 | static int |
92d7f7b0 JS |
1969 | lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno) |
1970 | { | |
def9c7a9 JS |
1971 | if (phba->sli_rev == LPFC_SLI_REV4) |
1972 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, | |
73d91e50 | 1973 | lpfc_hbq_defs[qno]->entry_count); |
def9c7a9 JS |
1974 | else |
1975 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, | |
1976 | lpfc_hbq_defs[qno]->init_count); | |
ed957684 JS |
1977 | } |
1978 | ||
3772a991 JS |
1979 | /** |
1980 | * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list | |
1981 | * @phba: Pointer to HBA context object. | |
1982 | * @hbqno: HBQ number. | |
1983 | * | |
1984 | * This function removes the first hbq buffer on an hbq list and returns a | |
1985 | * pointer to that buffer. If it finds no buffers on the list it returns NULL. | |
1986 | **/ | |
1987 | static struct hbq_dmabuf * | |
1988 | lpfc_sli_hbqbuf_get(struct list_head *rb_list) | |
1989 | { | |
1990 | struct lpfc_dmabuf *d_buf; | |
1991 | ||
1992 | list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list); | |
1993 | if (!d_buf) | |
1994 | return NULL; | |
1995 | return container_of(d_buf, struct hbq_dmabuf, dbuf); | |
1996 | } | |
1997 | ||
e59058c4 | 1998 | /** |
3621a710 | 1999 | * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag |
e59058c4 JS |
2000 | * @phba: Pointer to HBA context object. |
2001 | * @tag: Tag of the hbq buffer. | |
2002 | * | |
71892418 SH |
2003 | * This function searches for the hbq buffer associated with the given tag in |
2004 | * the hbq buffer list. If it finds the hbq buffer, it returns the hbq_buffer | |
2005 | * otherwise it returns NULL. | |
e59058c4 | 2006 | **/ |
a6ababd2 | 2007 | static struct hbq_dmabuf * |
92d7f7b0 | 2008 | lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag) |
ed957684 | 2009 | { |
92d7f7b0 JS |
2010 | struct lpfc_dmabuf *d_buf; |
2011 | struct hbq_dmabuf *hbq_buf; | |
51ef4c26 JS |
2012 | uint32_t hbqno; |
2013 | ||
2014 | hbqno = tag >> 16; | |
a0a74e45 | 2015 | if (hbqno >= LPFC_MAX_HBQS) |
51ef4c26 | 2016 | return NULL; |
ed957684 | 2017 | |
3772a991 | 2018 | spin_lock_irq(&phba->hbalock); |
51ef4c26 | 2019 | list_for_each_entry(d_buf, &phba->hbqs[hbqno].hbq_buffer_list, list) { |
92d7f7b0 | 2020 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
51ef4c26 | 2021 | if (hbq_buf->tag == tag) { |
3772a991 | 2022 | spin_unlock_irq(&phba->hbalock); |
92d7f7b0 | 2023 | return hbq_buf; |
ed957684 JS |
2024 | } |
2025 | } | |
3772a991 | 2026 | spin_unlock_irq(&phba->hbalock); |
92d7f7b0 | 2027 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT, |
e8b62011 | 2028 | "1803 Bad hbq tag. Data: x%x x%x\n", |
a8adb832 | 2029 | tag, phba->hbqs[tag >> 16].buffer_count); |
92d7f7b0 | 2030 | return NULL; |
ed957684 JS |
2031 | } |
2032 | ||
e59058c4 | 2033 | /** |
3621a710 | 2034 | * lpfc_sli_free_hbq - Give back the hbq buffer to firmware |
e59058c4 JS |
2035 | * @phba: Pointer to HBA context object. |
2036 | * @hbq_buffer: Pointer to HBQ buffer. | |
2037 | * | |
2038 | * This function is called with hbalock. This function gives back | |
2039 | * the hbq buffer to firmware. If the HBQ does not have space to | |
2040 | * post the buffer, it will free the buffer. | |
2041 | **/ | |
ed957684 | 2042 | void |
51ef4c26 | 2043 | lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer) |
ed957684 JS |
2044 | { |
2045 | uint32_t hbqno; | |
2046 | ||
51ef4c26 JS |
2047 | if (hbq_buffer) { |
2048 | hbqno = hbq_buffer->tag >> 16; | |
3772a991 | 2049 | if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) |
51ef4c26 | 2050 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
ed957684 JS |
2051 | } |
2052 | } | |
2053 | ||
e59058c4 | 2054 | /** |
3621a710 | 2055 | * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox |
e59058c4 JS |
2056 | * @mbxCommand: mailbox command code. |
2057 | * | |
2058 | * This function is called by the mailbox event handler function to verify | |
2059 | * that the completed mailbox command is a legitimate mailbox command. If the | |
2060 | * completed mailbox is not known to the function, it will return MBX_SHUTDOWN | |
2061 | * and the mailbox event handler will take the HBA offline. | |
2062 | **/ | |
dea3101e JB |
2063 | static int |
2064 | lpfc_sli_chk_mbx_command(uint8_t mbxCommand) | |
2065 | { | |
2066 | uint8_t ret; | |
2067 | ||
2068 | switch (mbxCommand) { | |
2069 | case MBX_LOAD_SM: | |
2070 | case MBX_READ_NV: | |
2071 | case MBX_WRITE_NV: | |
a8adb832 | 2072 | case MBX_WRITE_VPARMS: |
dea3101e JB |
2073 | case MBX_RUN_BIU_DIAG: |
2074 | case MBX_INIT_LINK: | |
2075 | case MBX_DOWN_LINK: | |
2076 | case MBX_CONFIG_LINK: | |
2077 | case MBX_CONFIG_RING: | |
2078 | case MBX_RESET_RING: | |
2079 | case MBX_READ_CONFIG: | |
2080 | case MBX_READ_RCONFIG: | |
2081 | case MBX_READ_SPARM: | |
2082 | case MBX_READ_STATUS: | |
2083 | case MBX_READ_RPI: | |
2084 | case MBX_READ_XRI: | |
2085 | case MBX_READ_REV: | |
2086 | case MBX_READ_LNK_STAT: | |
2087 | case MBX_REG_LOGIN: | |
2088 | case MBX_UNREG_LOGIN: | |
dea3101e JB |
2089 | case MBX_CLEAR_LA: |
2090 | case MBX_DUMP_MEMORY: | |
2091 | case MBX_DUMP_CONTEXT: | |
2092 | case MBX_RUN_DIAGS: | |
2093 | case MBX_RESTART: | |
2094 | case MBX_UPDATE_CFG: | |
2095 | case MBX_DOWN_LOAD: | |
2096 | case MBX_DEL_LD_ENTRY: | |
2097 | case MBX_RUN_PROGRAM: | |
2098 | case MBX_SET_MASK: | |
09372820 | 2099 | case MBX_SET_VARIABLE: |
dea3101e | 2100 | case MBX_UNREG_D_ID: |
41415862 | 2101 | case MBX_KILL_BOARD: |
dea3101e | 2102 | case MBX_CONFIG_FARP: |
41415862 | 2103 | case MBX_BEACON: |
dea3101e JB |
2104 | case MBX_LOAD_AREA: |
2105 | case MBX_RUN_BIU_DIAG64: | |
2106 | case MBX_CONFIG_PORT: | |
2107 | case MBX_READ_SPARM64: | |
2108 | case MBX_READ_RPI64: | |
2109 | case MBX_REG_LOGIN64: | |
76a95d75 | 2110 | case MBX_READ_TOPOLOGY: |
09372820 | 2111 | case MBX_WRITE_WWN: |
dea3101e JB |
2112 | case MBX_SET_DEBUG: |
2113 | case MBX_LOAD_EXP_ROM: | |
57127f15 | 2114 | case MBX_ASYNCEVT_ENABLE: |
92d7f7b0 JS |
2115 | case MBX_REG_VPI: |
2116 | case MBX_UNREG_VPI: | |
858c9f6c | 2117 | case MBX_HEARTBEAT: |
84774a4d JS |
2118 | case MBX_PORT_CAPABILITIES: |
2119 | case MBX_PORT_IOV_CONTROL: | |
04c68496 JS |
2120 | case MBX_SLI4_CONFIG: |
2121 | case MBX_SLI4_REQ_FTRS: | |
2122 | case MBX_REG_FCFI: | |
2123 | case MBX_UNREG_FCFI: | |
2124 | case MBX_REG_VFI: | |
2125 | case MBX_UNREG_VFI: | |
2126 | case MBX_INIT_VPI: | |
2127 | case MBX_INIT_VFI: | |
2128 | case MBX_RESUME_RPI: | |
c7495937 JS |
2129 | case MBX_READ_EVENT_LOG_STATUS: |
2130 | case MBX_READ_EVENT_LOG: | |
dcf2a4e0 JS |
2131 | case MBX_SECURITY_MGMT: |
2132 | case MBX_AUTH_PORT: | |
940eb687 | 2133 | case MBX_ACCESS_VDATA: |
dea3101e JB |
2134 | ret = mbxCommand; |
2135 | break; | |
2136 | default: | |
2137 | ret = MBX_SHUTDOWN; | |
2138 | break; | |
2139 | } | |
2e0fef85 | 2140 | return ret; |
dea3101e | 2141 | } |
e59058c4 JS |
2142 | |
2143 | /** | |
3621a710 | 2144 | * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler |
e59058c4 JS |
2145 | * @phba: Pointer to HBA context object. |
2146 | * @pmboxq: Pointer to mailbox command. | |
2147 | * | |
2148 | * This is completion handler function for mailbox commands issued from | |
2149 | * lpfc_sli_issue_mbox_wait function. This function is called by the | |
2150 | * mailbox event handler function with no lock held. This function | |
2151 | * will wake up thread waiting on the wait queue pointed by context1 | |
2152 | * of the mailbox. | |
2153 | **/ | |
04c68496 | 2154 | void |
2e0fef85 | 2155 | lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) |
dea3101e JB |
2156 | { |
2157 | wait_queue_head_t *pdone_q; | |
858c9f6c | 2158 | unsigned long drvr_flag; |
dea3101e JB |
2159 | |
2160 | /* | |
2161 | * If pdone_q is empty, the driver thread gave up waiting and | |
2162 | * continued running. | |
2163 | */ | |
7054a606 | 2164 | pmboxq->mbox_flag |= LPFC_MBX_WAKE; |
858c9f6c | 2165 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
dea3101e JB |
2166 | pdone_q = (wait_queue_head_t *) pmboxq->context1; |
2167 | if (pdone_q) | |
2168 | wake_up_interruptible(pdone_q); | |
858c9f6c | 2169 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
dea3101e JB |
2170 | return; |
2171 | } | |
2172 | ||
e59058c4 JS |
2173 | |
2174 | /** | |
3621a710 | 2175 | * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler |
e59058c4 JS |
2176 | * @phba: Pointer to HBA context object. |
2177 | * @pmb: Pointer to mailbox object. | |
2178 | * | |
2179 | * This function is the default mailbox completion handler. It | |
2180 | * frees the memory resources associated with the completed mailbox | |
2181 | * command. If the completed command is a REG_LOGIN mailbox command, | |
2182 | * this function will issue a UREG_LOGIN to re-claim the RPI. | |
2183 | **/ | |
dea3101e | 2184 | void |
2e0fef85 | 2185 | lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
dea3101e | 2186 | { |
d439d286 | 2187 | struct lpfc_vport *vport = pmb->vport; |
dea3101e | 2188 | struct lpfc_dmabuf *mp; |
d439d286 | 2189 | struct lpfc_nodelist *ndlp; |
5af5eee7 | 2190 | struct Scsi_Host *shost; |
04c68496 | 2191 | uint16_t rpi, vpi; |
7054a606 JS |
2192 | int rc; |
2193 | ||
dea3101e | 2194 | mp = (struct lpfc_dmabuf *) (pmb->context1); |
7054a606 | 2195 | |
dea3101e JB |
2196 | if (mp) { |
2197 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
2198 | kfree(mp); | |
2199 | } | |
7054a606 JS |
2200 | |
2201 | /* | |
2202 | * If a REG_LOGIN succeeded after node is destroyed or node | |
2203 | * is in re-discovery driver need to cleanup the RPI. | |
2204 | */ | |
2e0fef85 | 2205 | if (!(phba->pport->load_flag & FC_UNLOADING) && |
04c68496 JS |
2206 | pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 && |
2207 | !pmb->u.mb.mbxStatus) { | |
2208 | rpi = pmb->u.mb.un.varWords[0]; | |
6d368e53 | 2209 | vpi = pmb->u.mb.un.varRegLogin.vpi; |
04c68496 | 2210 | lpfc_unreg_login(phba, vpi, rpi, pmb); |
de96e9c5 | 2211 | pmb->vport = vport; |
92d7f7b0 | 2212 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
7054a606 JS |
2213 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
2214 | if (rc != MBX_NOT_FINISHED) | |
2215 | return; | |
2216 | } | |
2217 | ||
695a814e JS |
2218 | if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) && |
2219 | !(phba->pport->load_flag & FC_UNLOADING) && | |
2220 | !pmb->u.mb.mbxStatus) { | |
5af5eee7 JS |
2221 | shost = lpfc_shost_from_vport(vport); |
2222 | spin_lock_irq(shost->host_lock); | |
2223 | vport->vpi_state |= LPFC_VPI_REGISTERED; | |
2224 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; | |
2225 | spin_unlock_irq(shost->host_lock); | |
695a814e JS |
2226 | } |
2227 | ||
d439d286 JS |
2228 | if (pmb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
2229 | ndlp = (struct lpfc_nodelist *)pmb->context2; | |
2230 | lpfc_nlp_put(ndlp); | |
2231 | pmb->context2 = NULL; | |
2232 | } | |
2233 | ||
dcf2a4e0 JS |
2234 | /* Check security permission status on INIT_LINK mailbox command */ |
2235 | if ((pmb->u.mb.mbxCommand == MBX_INIT_LINK) && | |
2236 | (pmb->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION)) | |
2237 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
2238 | "2860 SLI authentication is required " | |
2239 | "for INIT_LINK but has not done yet\n"); | |
2240 | ||
04c68496 JS |
2241 | if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG) |
2242 | lpfc_sli4_mbox_cmd_free(phba, pmb); | |
2243 | else | |
2244 | mempool_free(pmb, phba->mbox_mem_pool); | |
dea3101e | 2245 | } |
be6bb941 JS |
2246 | /** |
2247 | * lpfc_sli4_unreg_rpi_cmpl_clr - mailbox completion handler | |
2248 | * @phba: Pointer to HBA context object. | |
2249 | * @pmb: Pointer to mailbox object. | |
2250 | * | |
2251 | * This function is the unreg rpi mailbox completion handler. It | |
2252 | * frees the memory resources associated with the completed mailbox | |
2253 | * command. An additional refrenece is put on the ndlp to prevent | |
2254 | * lpfc_nlp_release from freeing the rpi bit in the bitmask before | |
2255 | * the unreg mailbox command completes, this routine puts the | |
2256 | * reference back. | |
2257 | * | |
2258 | **/ | |
2259 | void | |
2260 | lpfc_sli4_unreg_rpi_cmpl_clr(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) | |
2261 | { | |
2262 | struct lpfc_vport *vport = pmb->vport; | |
2263 | struct lpfc_nodelist *ndlp; | |
2264 | ||
2265 | ndlp = pmb->context1; | |
2266 | if (pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) { | |
2267 | if (phba->sli_rev == LPFC_SLI_REV4 && | |
2268 | (bf_get(lpfc_sli_intf_if_type, | |
2269 | &phba->sli4_hba.sli_intf) == | |
2270 | LPFC_SLI_INTF_IF_TYPE_2)) { | |
2271 | if (ndlp) { | |
2272 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, | |
2273 | "0010 UNREG_LOGIN vpi:%x " | |
2274 | "rpi:%x DID:%x map:%x %p\n", | |
2275 | vport->vpi, ndlp->nlp_rpi, | |
2276 | ndlp->nlp_DID, | |
2277 | ndlp->nlp_usg_map, ndlp); | |
7c5e518c | 2278 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
be6bb941 JS |
2279 | lpfc_nlp_put(ndlp); |
2280 | } | |
2281 | } | |
2282 | } | |
2283 | ||
2284 | mempool_free(pmb, phba->mbox_mem_pool); | |
2285 | } | |
dea3101e | 2286 | |
e59058c4 | 2287 | /** |
3621a710 | 2288 | * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware |
e59058c4 JS |
2289 | * @phba: Pointer to HBA context object. |
2290 | * | |
2291 | * This function is called with no lock held. This function processes all | |
2292 | * the completed mailbox commands and gives it to upper layers. The interrupt | |
2293 | * service routine processes mailbox completion interrupt and adds completed | |
2294 | * mailbox commands to the mboxq_cmpl queue and signals the worker thread. | |
2295 | * Worker thread call lpfc_sli_handle_mb_event, which will return the | |
2296 | * completed mailbox commands in mboxq_cmpl queue to the upper layers. This | |
2297 | * function returns the mailbox commands to the upper layer by calling the | |
2298 | * completion handler function of each mailbox. | |
2299 | **/ | |
dea3101e | 2300 | int |
2e0fef85 | 2301 | lpfc_sli_handle_mb_event(struct lpfc_hba *phba) |
dea3101e | 2302 | { |
92d7f7b0 | 2303 | MAILBOX_t *pmbox; |
dea3101e | 2304 | LPFC_MBOXQ_t *pmb; |
92d7f7b0 JS |
2305 | int rc; |
2306 | LIST_HEAD(cmplq); | |
dea3101e JB |
2307 | |
2308 | phba->sli.slistat.mbox_event++; | |
2309 | ||
92d7f7b0 JS |
2310 | /* Get all completed mailboxe buffers into the cmplq */ |
2311 | spin_lock_irq(&phba->hbalock); | |
2312 | list_splice_init(&phba->sli.mboxq_cmpl, &cmplq); | |
2313 | spin_unlock_irq(&phba->hbalock); | |
dea3101e | 2314 | |
92d7f7b0 JS |
2315 | /* Get a Mailbox buffer to setup mailbox commands for callback */ |
2316 | do { | |
2317 | list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list); | |
2318 | if (pmb == NULL) | |
2319 | break; | |
2e0fef85 | 2320 | |
04c68496 | 2321 | pmbox = &pmb->u.mb; |
dea3101e | 2322 | |
858c9f6c JS |
2323 | if (pmbox->mbxCommand != MBX_HEARTBEAT) { |
2324 | if (pmb->vport) { | |
2325 | lpfc_debugfs_disc_trc(pmb->vport, | |
2326 | LPFC_DISC_TRC_MBOX_VPORT, | |
2327 | "MBOX cmpl vport: cmd:x%x mb:x%x x%x", | |
2328 | (uint32_t)pmbox->mbxCommand, | |
2329 | pmbox->un.varWords[0], | |
2330 | pmbox->un.varWords[1]); | |
2331 | } | |
2332 | else { | |
2333 | lpfc_debugfs_disc_trc(phba->pport, | |
2334 | LPFC_DISC_TRC_MBOX, | |
2335 | "MBOX cmpl: cmd:x%x mb:x%x x%x", | |
2336 | (uint32_t)pmbox->mbxCommand, | |
2337 | pmbox->un.varWords[0], | |
2338 | pmbox->un.varWords[1]); | |
2339 | } | |
2340 | } | |
2341 | ||
dea3101e JB |
2342 | /* |
2343 | * It is a fatal error if unknown mbox command completion. | |
2344 | */ | |
2345 | if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) == | |
2346 | MBX_SHUTDOWN) { | |
af901ca1 | 2347 | /* Unknown mailbox command compl */ |
92d7f7b0 | 2348 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
e8b62011 | 2349 | "(%d):0323 Unknown Mailbox command " |
a183a15f | 2350 | "x%x (x%x/x%x) Cmpl\n", |
92d7f7b0 | 2351 | pmb->vport ? pmb->vport->vpi : 0, |
04c68496 | 2352 | pmbox->mbxCommand, |
a183a15f JS |
2353 | lpfc_sli_config_mbox_subsys_get(phba, |
2354 | pmb), | |
2355 | lpfc_sli_config_mbox_opcode_get(phba, | |
2356 | pmb)); | |
2e0fef85 | 2357 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e JB |
2358 | phba->work_hs = HS_FFER3; |
2359 | lpfc_handle_eratt(phba); | |
92d7f7b0 | 2360 | continue; |
dea3101e JB |
2361 | } |
2362 | ||
dea3101e JB |
2363 | if (pmbox->mbxStatus) { |
2364 | phba->sli.slistat.mbox_stat_err++; | |
2365 | if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) { | |
2366 | /* Mbox cmd cmpl error - RETRYing */ | |
92d7f7b0 | 2367 | lpfc_printf_log(phba, KERN_INFO, |
a183a15f JS |
2368 | LOG_MBOX | LOG_SLI, |
2369 | "(%d):0305 Mbox cmd cmpl " | |
2370 | "error - RETRYing Data: x%x " | |
2371 | "(x%x/x%x) x%x x%x x%x\n", | |
2372 | pmb->vport ? pmb->vport->vpi : 0, | |
2373 | pmbox->mbxCommand, | |
2374 | lpfc_sli_config_mbox_subsys_get(phba, | |
2375 | pmb), | |
2376 | lpfc_sli_config_mbox_opcode_get(phba, | |
2377 | pmb), | |
2378 | pmbox->mbxStatus, | |
2379 | pmbox->un.varWords[0], | |
2380 | pmb->vport->port_state); | |
dea3101e JB |
2381 | pmbox->mbxStatus = 0; |
2382 | pmbox->mbxOwner = OWN_HOST; | |
dea3101e | 2383 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
04c68496 | 2384 | if (rc != MBX_NOT_FINISHED) |
92d7f7b0 | 2385 | continue; |
dea3101e JB |
2386 | } |
2387 | } | |
2388 | ||
2389 | /* Mailbox cmd <cmd> Cmpl <cmpl> */ | |
92d7f7b0 | 2390 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
a183a15f | 2391 | "(%d):0307 Mailbox cmd x%x (x%x/x%x) Cmpl x%p " |
e74c03c8 JS |
2392 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x " |
2393 | "x%x x%x x%x\n", | |
92d7f7b0 | 2394 | pmb->vport ? pmb->vport->vpi : 0, |
dea3101e | 2395 | pmbox->mbxCommand, |
a183a15f JS |
2396 | lpfc_sli_config_mbox_subsys_get(phba, pmb), |
2397 | lpfc_sli_config_mbox_opcode_get(phba, pmb), | |
dea3101e JB |
2398 | pmb->mbox_cmpl, |
2399 | *((uint32_t *) pmbox), | |
2400 | pmbox->un.varWords[0], | |
2401 | pmbox->un.varWords[1], | |
2402 | pmbox->un.varWords[2], | |
2403 | pmbox->un.varWords[3], | |
2404 | pmbox->un.varWords[4], | |
2405 | pmbox->un.varWords[5], | |
2406 | pmbox->un.varWords[6], | |
e74c03c8 JS |
2407 | pmbox->un.varWords[7], |
2408 | pmbox->un.varWords[8], | |
2409 | pmbox->un.varWords[9], | |
2410 | pmbox->un.varWords[10]); | |
dea3101e | 2411 | |
92d7f7b0 | 2412 | if (pmb->mbox_cmpl) |
dea3101e | 2413 | pmb->mbox_cmpl(phba,pmb); |
92d7f7b0 JS |
2414 | } while (1); |
2415 | return 0; | |
2416 | } | |
dea3101e | 2417 | |
e59058c4 | 2418 | /** |
3621a710 | 2419 | * lpfc_sli_get_buff - Get the buffer associated with the buffer tag |
e59058c4 JS |
2420 | * @phba: Pointer to HBA context object. |
2421 | * @pring: Pointer to driver SLI ring object. | |
2422 | * @tag: buffer tag. | |
2423 | * | |
2424 | * This function is called with no lock held. When QUE_BUFTAG_BIT bit | |
2425 | * is set in the tag the buffer is posted for a particular exchange, | |
2426 | * the function will return the buffer without replacing the buffer. | |
2427 | * If the buffer is for unsolicited ELS or CT traffic, this function | |
2428 | * returns the buffer and also posts another buffer to the firmware. | |
2429 | **/ | |
76bb24ef JS |
2430 | static struct lpfc_dmabuf * |
2431 | lpfc_sli_get_buff(struct lpfc_hba *phba, | |
9f1e1b50 JS |
2432 | struct lpfc_sli_ring *pring, |
2433 | uint32_t tag) | |
76bb24ef | 2434 | { |
9f1e1b50 JS |
2435 | struct hbq_dmabuf *hbq_entry; |
2436 | ||
76bb24ef JS |
2437 | if (tag & QUE_BUFTAG_BIT) |
2438 | return lpfc_sli_ring_taggedbuf_get(phba, pring, tag); | |
9f1e1b50 JS |
2439 | hbq_entry = lpfc_sli_hbqbuf_find(phba, tag); |
2440 | if (!hbq_entry) | |
2441 | return NULL; | |
2442 | return &hbq_entry->dbuf; | |
76bb24ef | 2443 | } |
57127f15 | 2444 | |
3772a991 JS |
2445 | /** |
2446 | * lpfc_complete_unsol_iocb - Complete an unsolicited sequence | |
2447 | * @phba: Pointer to HBA context object. | |
2448 | * @pring: Pointer to driver SLI ring object. | |
2449 | * @saveq: Pointer to the iocbq struct representing the sequence starting frame. | |
2450 | * @fch_r_ctl: the r_ctl for the first frame of the sequence. | |
2451 | * @fch_type: the type for the first frame of the sequence. | |
2452 | * | |
2453 | * This function is called with no lock held. This function uses the r_ctl and | |
2454 | * type of the received sequence to find the correct callback function to call | |
2455 | * to process the sequence. | |
2456 | **/ | |
2457 | static int | |
2458 | lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
2459 | struct lpfc_iocbq *saveq, uint32_t fch_r_ctl, | |
2460 | uint32_t fch_type) | |
2461 | { | |
2462 | int i; | |
2463 | ||
2464 | /* unSolicited Responses */ | |
2465 | if (pring->prt[0].profile) { | |
2466 | if (pring->prt[0].lpfc_sli_rcv_unsol_event) | |
2467 | (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring, | |
2468 | saveq); | |
2469 | return 1; | |
2470 | } | |
2471 | /* We must search, based on rctl / type | |
2472 | for the right routine */ | |
2473 | for (i = 0; i < pring->num_mask; i++) { | |
2474 | if ((pring->prt[i].rctl == fch_r_ctl) && | |
2475 | (pring->prt[i].type == fch_type)) { | |
2476 | if (pring->prt[i].lpfc_sli_rcv_unsol_event) | |
2477 | (pring->prt[i].lpfc_sli_rcv_unsol_event) | |
2478 | (phba, pring, saveq); | |
2479 | return 1; | |
2480 | } | |
2481 | } | |
2482 | return 0; | |
2483 | } | |
e59058c4 JS |
2484 | |
2485 | /** | |
3621a710 | 2486 | * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler |
e59058c4 JS |
2487 | * @phba: Pointer to HBA context object. |
2488 | * @pring: Pointer to driver SLI ring object. | |
2489 | * @saveq: Pointer to the unsolicited iocb. | |
2490 | * | |
2491 | * This function is called with no lock held by the ring event handler | |
2492 | * when there is an unsolicited iocb posted to the response ring by the | |
2493 | * firmware. This function gets the buffer associated with the iocbs | |
2494 | * and calls the event handler for the ring. This function handles both | |
2495 | * qring buffers and hbq buffers. | |
2496 | * When the function returns 1 the caller can free the iocb object otherwise | |
2497 | * upper layer functions will free the iocb objects. | |
2498 | **/ | |
dea3101e JB |
2499 | static int |
2500 | lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
2501 | struct lpfc_iocbq *saveq) | |
2502 | { | |
2503 | IOCB_t * irsp; | |
2504 | WORD5 * w5p; | |
2505 | uint32_t Rctl, Type; | |
76bb24ef | 2506 | struct lpfc_iocbq *iocbq; |
3163f725 | 2507 | struct lpfc_dmabuf *dmzbuf; |
dea3101e | 2508 | |
dea3101e | 2509 | irsp = &(saveq->iocb); |
57127f15 JS |
2510 | |
2511 | if (irsp->ulpCommand == CMD_ASYNC_STATUS) { | |
2512 | if (pring->lpfc_sli_rcv_async_status) | |
2513 | pring->lpfc_sli_rcv_async_status(phba, pring, saveq); | |
2514 | else | |
2515 | lpfc_printf_log(phba, | |
2516 | KERN_WARNING, | |
2517 | LOG_SLI, | |
2518 | "0316 Ring %d handler: unexpected " | |
2519 | "ASYNC_STATUS iocb received evt_code " | |
2520 | "0x%x\n", | |
2521 | pring->ringno, | |
2522 | irsp->un.asyncstat.evt_code); | |
2523 | return 1; | |
2524 | } | |
2525 | ||
3163f725 JS |
2526 | if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) && |
2527 | (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) { | |
2528 | if (irsp->ulpBdeCount > 0) { | |
2529 | dmzbuf = lpfc_sli_get_buff(phba, pring, | |
2530 | irsp->un.ulpWord[3]); | |
2531 | lpfc_in_buf_free(phba, dmzbuf); | |
2532 | } | |
2533 | ||
2534 | if (irsp->ulpBdeCount > 1) { | |
2535 | dmzbuf = lpfc_sli_get_buff(phba, pring, | |
2536 | irsp->unsli3.sli3Words[3]); | |
2537 | lpfc_in_buf_free(phba, dmzbuf); | |
2538 | } | |
2539 | ||
2540 | if (irsp->ulpBdeCount > 2) { | |
2541 | dmzbuf = lpfc_sli_get_buff(phba, pring, | |
2542 | irsp->unsli3.sli3Words[7]); | |
2543 | lpfc_in_buf_free(phba, dmzbuf); | |
2544 | } | |
2545 | ||
2546 | return 1; | |
2547 | } | |
2548 | ||
92d7f7b0 | 2549 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
76bb24ef JS |
2550 | if (irsp->ulpBdeCount != 0) { |
2551 | saveq->context2 = lpfc_sli_get_buff(phba, pring, | |
2552 | irsp->un.ulpWord[3]); | |
2553 | if (!saveq->context2) | |
2554 | lpfc_printf_log(phba, | |
2555 | KERN_ERR, | |
2556 | LOG_SLI, | |
2557 | "0341 Ring %d Cannot find buffer for " | |
2558 | "an unsolicited iocb. tag 0x%x\n", | |
2559 | pring->ringno, | |
2560 | irsp->un.ulpWord[3]); | |
76bb24ef JS |
2561 | } |
2562 | if (irsp->ulpBdeCount == 2) { | |
2563 | saveq->context3 = lpfc_sli_get_buff(phba, pring, | |
2564 | irsp->unsli3.sli3Words[7]); | |
2565 | if (!saveq->context3) | |
2566 | lpfc_printf_log(phba, | |
2567 | KERN_ERR, | |
2568 | LOG_SLI, | |
2569 | "0342 Ring %d Cannot find buffer for an" | |
2570 | " unsolicited iocb. tag 0x%x\n", | |
2571 | pring->ringno, | |
2572 | irsp->unsli3.sli3Words[7]); | |
2573 | } | |
2574 | list_for_each_entry(iocbq, &saveq->list, list) { | |
76bb24ef | 2575 | irsp = &(iocbq->iocb); |
76bb24ef JS |
2576 | if (irsp->ulpBdeCount != 0) { |
2577 | iocbq->context2 = lpfc_sli_get_buff(phba, pring, | |
2578 | irsp->un.ulpWord[3]); | |
9c2face6 | 2579 | if (!iocbq->context2) |
76bb24ef JS |
2580 | lpfc_printf_log(phba, |
2581 | KERN_ERR, | |
2582 | LOG_SLI, | |
2583 | "0343 Ring %d Cannot find " | |
2584 | "buffer for an unsolicited iocb" | |
2585 | ". tag 0x%x\n", pring->ringno, | |
92d7f7b0 | 2586 | irsp->un.ulpWord[3]); |
76bb24ef JS |
2587 | } |
2588 | if (irsp->ulpBdeCount == 2) { | |
2589 | iocbq->context3 = lpfc_sli_get_buff(phba, pring, | |
51ef4c26 | 2590 | irsp->unsli3.sli3Words[7]); |
9c2face6 | 2591 | if (!iocbq->context3) |
76bb24ef JS |
2592 | lpfc_printf_log(phba, |
2593 | KERN_ERR, | |
2594 | LOG_SLI, | |
2595 | "0344 Ring %d Cannot find " | |
2596 | "buffer for an unsolicited " | |
2597 | "iocb. tag 0x%x\n", | |
2598 | pring->ringno, | |
2599 | irsp->unsli3.sli3Words[7]); | |
2600 | } | |
2601 | } | |
92d7f7b0 | 2602 | } |
9c2face6 JS |
2603 | if (irsp->ulpBdeCount != 0 && |
2604 | (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX || | |
2605 | irsp->ulpStatus == IOSTAT_INTERMED_RSP)) { | |
2606 | int found = 0; | |
2607 | ||
2608 | /* search continue save q for same XRI */ | |
2609 | list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) { | |
7851fe2c JS |
2610 | if (iocbq->iocb.unsli3.rcvsli3.ox_id == |
2611 | saveq->iocb.unsli3.rcvsli3.ox_id) { | |
9c2face6 JS |
2612 | list_add_tail(&saveq->list, &iocbq->list); |
2613 | found = 1; | |
2614 | break; | |
2615 | } | |
2616 | } | |
2617 | if (!found) | |
2618 | list_add_tail(&saveq->clist, | |
2619 | &pring->iocb_continue_saveq); | |
2620 | if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) { | |
2621 | list_del_init(&iocbq->clist); | |
2622 | saveq = iocbq; | |
2623 | irsp = &(saveq->iocb); | |
2624 | } else | |
2625 | return 0; | |
2626 | } | |
2627 | if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) || | |
2628 | (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) || | |
2629 | (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) { | |
6a9c52cf JS |
2630 | Rctl = FC_RCTL_ELS_REQ; |
2631 | Type = FC_TYPE_ELS; | |
9c2face6 JS |
2632 | } else { |
2633 | w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]); | |
2634 | Rctl = w5p->hcsw.Rctl; | |
2635 | Type = w5p->hcsw.Type; | |
2636 | ||
2637 | /* Firmware Workaround */ | |
2638 | if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) && | |
2639 | (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX || | |
2640 | irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { | |
6a9c52cf JS |
2641 | Rctl = FC_RCTL_ELS_REQ; |
2642 | Type = FC_TYPE_ELS; | |
9c2face6 JS |
2643 | w5p->hcsw.Rctl = Rctl; |
2644 | w5p->hcsw.Type = Type; | |
2645 | } | |
2646 | } | |
92d7f7b0 | 2647 | |
3772a991 | 2648 | if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type)) |
92d7f7b0 | 2649 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
e8b62011 | 2650 | "0313 Ring %d handler: unexpected Rctl x%x " |
92d7f7b0 | 2651 | "Type x%x received\n", |
e8b62011 | 2652 | pring->ringno, Rctl, Type); |
3772a991 | 2653 | |
92d7f7b0 | 2654 | return 1; |
dea3101e JB |
2655 | } |
2656 | ||
e59058c4 | 2657 | /** |
3621a710 | 2658 | * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb |
e59058c4 JS |
2659 | * @phba: Pointer to HBA context object. |
2660 | * @pring: Pointer to driver SLI ring object. | |
2661 | * @prspiocb: Pointer to response iocb object. | |
2662 | * | |
2663 | * This function looks up the iocb_lookup table to get the command iocb | |
2664 | * corresponding to the given response iocb using the iotag of the | |
2665 | * response iocb. This function is called with the hbalock held. | |
2666 | * This function returns the command iocb object if it finds the command | |
2667 | * iocb else returns NULL. | |
2668 | **/ | |
dea3101e | 2669 | static struct lpfc_iocbq * |
2e0fef85 JS |
2670 | lpfc_sli_iocbq_lookup(struct lpfc_hba *phba, |
2671 | struct lpfc_sli_ring *pring, | |
2672 | struct lpfc_iocbq *prspiocb) | |
dea3101e | 2673 | { |
dea3101e JB |
2674 | struct lpfc_iocbq *cmd_iocb = NULL; |
2675 | uint16_t iotag; | |
1c2ba475 | 2676 | lockdep_assert_held(&phba->hbalock); |
dea3101e | 2677 | |
604a3e30 JB |
2678 | iotag = prspiocb->iocb.ulpIoTag; |
2679 | ||
2680 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { | |
2681 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; | |
92d7f7b0 | 2682 | list_del_init(&cmd_iocb->list); |
4f2e66c6 | 2683 | if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) { |
4f2e66c6 | 2684 | cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
2a9bf3d0 | 2685 | } |
604a3e30 | 2686 | return cmd_iocb; |
dea3101e JB |
2687 | } |
2688 | ||
dea3101e | 2689 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
e8b62011 | 2690 | "0317 iotag x%x is out off " |
604a3e30 | 2691 | "range: max iotag x%x wd0 x%x\n", |
e8b62011 | 2692 | iotag, phba->sli.last_iotag, |
604a3e30 | 2693 | *(((uint32_t *) &prspiocb->iocb) + 7)); |
dea3101e JB |
2694 | return NULL; |
2695 | } | |
2696 | ||
3772a991 JS |
2697 | /** |
2698 | * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag | |
2699 | * @phba: Pointer to HBA context object. | |
2700 | * @pring: Pointer to driver SLI ring object. | |
2701 | * @iotag: IOCB tag. | |
2702 | * | |
2703 | * This function looks up the iocb_lookup table to get the command iocb | |
2704 | * corresponding to the given iotag. This function is called with the | |
2705 | * hbalock held. | |
2706 | * This function returns the command iocb object if it finds the command | |
2707 | * iocb else returns NULL. | |
2708 | **/ | |
2709 | static struct lpfc_iocbq * | |
2710 | lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba, | |
2711 | struct lpfc_sli_ring *pring, uint16_t iotag) | |
2712 | { | |
2713 | struct lpfc_iocbq *cmd_iocb; | |
2714 | ||
1c2ba475 | 2715 | lockdep_assert_held(&phba->hbalock); |
3772a991 JS |
2716 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { |
2717 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; | |
4f2e66c6 JS |
2718 | if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) { |
2719 | /* remove from txcmpl queue list */ | |
2720 | list_del_init(&cmd_iocb->list); | |
2721 | cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; | |
4f2e66c6 | 2722 | return cmd_iocb; |
2a9bf3d0 | 2723 | } |
3772a991 | 2724 | } |
3772a991 JS |
2725 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
2726 | "0372 iotag x%x is out off range: max iotag (x%x)\n", | |
2727 | iotag, phba->sli.last_iotag); | |
2728 | return NULL; | |
2729 | } | |
2730 | ||
e59058c4 | 2731 | /** |
3621a710 | 2732 | * lpfc_sli_process_sol_iocb - process solicited iocb completion |
e59058c4 JS |
2733 | * @phba: Pointer to HBA context object. |
2734 | * @pring: Pointer to driver SLI ring object. | |
2735 | * @saveq: Pointer to the response iocb to be processed. | |
2736 | * | |
2737 | * This function is called by the ring event handler for non-fcp | |
2738 | * rings when there is a new response iocb in the response ring. | |
2739 | * The caller is not required to hold any locks. This function | |
2740 | * gets the command iocb associated with the response iocb and | |
2741 | * calls the completion handler for the command iocb. If there | |
2742 | * is no completion handler, the function will free the resources | |
2743 | * associated with command iocb. If the response iocb is for | |
2744 | * an already aborted command iocb, the status of the completion | |
2745 | * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED. | |
2746 | * This function always returns 1. | |
2747 | **/ | |
dea3101e | 2748 | static int |
2e0fef85 | 2749 | lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
dea3101e JB |
2750 | struct lpfc_iocbq *saveq) |
2751 | { | |
2e0fef85 | 2752 | struct lpfc_iocbq *cmdiocbp; |
dea3101e JB |
2753 | int rc = 1; |
2754 | unsigned long iflag; | |
2755 | ||
2756 | /* Based on the iotag field, get the cmd IOCB from the txcmplq */ | |
2e0fef85 | 2757 | spin_lock_irqsave(&phba->hbalock, iflag); |
604a3e30 | 2758 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq); |
2e0fef85 JS |
2759 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
2760 | ||
dea3101e JB |
2761 | if (cmdiocbp) { |
2762 | if (cmdiocbp->iocb_cmpl) { | |
ea2151b4 JS |
2763 | /* |
2764 | * If an ELS command failed send an event to mgmt | |
2765 | * application. | |
2766 | */ | |
2767 | if (saveq->iocb.ulpStatus && | |
2768 | (pring->ringno == LPFC_ELS_RING) && | |
2769 | (cmdiocbp->iocb.ulpCommand == | |
2770 | CMD_ELS_REQUEST64_CR)) | |
2771 | lpfc_send_els_failure_event(phba, | |
2772 | cmdiocbp, saveq); | |
2773 | ||
dea3101e JB |
2774 | /* |
2775 | * Post all ELS completions to the worker thread. | |
2776 | * All other are passed to the completion callback. | |
2777 | */ | |
2778 | if (pring->ringno == LPFC_ELS_RING) { | |
341af102 JS |
2779 | if ((phba->sli_rev < LPFC_SLI_REV4) && |
2780 | (cmdiocbp->iocb_flag & | |
2781 | LPFC_DRIVER_ABORTED)) { | |
2782 | spin_lock_irqsave(&phba->hbalock, | |
2783 | iflag); | |
07951076 JS |
2784 | cmdiocbp->iocb_flag &= |
2785 | ~LPFC_DRIVER_ABORTED; | |
341af102 JS |
2786 | spin_unlock_irqrestore(&phba->hbalock, |
2787 | iflag); | |
07951076 JS |
2788 | saveq->iocb.ulpStatus = |
2789 | IOSTAT_LOCAL_REJECT; | |
2790 | saveq->iocb.un.ulpWord[4] = | |
2791 | IOERR_SLI_ABORTED; | |
0ff10d46 JS |
2792 | |
2793 | /* Firmware could still be in progress | |
2794 | * of DMAing payload, so don't free data | |
2795 | * buffer till after a hbeat. | |
2796 | */ | |
341af102 JS |
2797 | spin_lock_irqsave(&phba->hbalock, |
2798 | iflag); | |
0ff10d46 | 2799 | saveq->iocb_flag |= LPFC_DELAY_MEM_FREE; |
341af102 JS |
2800 | spin_unlock_irqrestore(&phba->hbalock, |
2801 | iflag); | |
2802 | } | |
0f65ff68 JS |
2803 | if (phba->sli_rev == LPFC_SLI_REV4) { |
2804 | if (saveq->iocb_flag & | |
2805 | LPFC_EXCHANGE_BUSY) { | |
2806 | /* Set cmdiocb flag for the | |
2807 | * exchange busy so sgl (xri) | |
2808 | * will not be released until | |
2809 | * the abort xri is received | |
2810 | * from hba. | |
2811 | */ | |
2812 | spin_lock_irqsave( | |
2813 | &phba->hbalock, iflag); | |
2814 | cmdiocbp->iocb_flag |= | |
2815 | LPFC_EXCHANGE_BUSY; | |
2816 | spin_unlock_irqrestore( | |
2817 | &phba->hbalock, iflag); | |
2818 | } | |
2819 | if (cmdiocbp->iocb_flag & | |
2820 | LPFC_DRIVER_ABORTED) { | |
2821 | /* | |
2822 | * Clear LPFC_DRIVER_ABORTED | |
2823 | * bit in case it was driver | |
2824 | * initiated abort. | |
2825 | */ | |
2826 | spin_lock_irqsave( | |
2827 | &phba->hbalock, iflag); | |
2828 | cmdiocbp->iocb_flag &= | |
2829 | ~LPFC_DRIVER_ABORTED; | |
2830 | spin_unlock_irqrestore( | |
2831 | &phba->hbalock, iflag); | |
2832 | cmdiocbp->iocb.ulpStatus = | |
2833 | IOSTAT_LOCAL_REJECT; | |
2834 | cmdiocbp->iocb.un.ulpWord[4] = | |
2835 | IOERR_ABORT_REQUESTED; | |
2836 | /* | |
2837 | * For SLI4, irsiocb contains | |
2838 | * NO_XRI in sli_xritag, it | |
2839 | * shall not affect releasing | |
2840 | * sgl (xri) process. | |
2841 | */ | |
2842 | saveq->iocb.ulpStatus = | |
2843 | IOSTAT_LOCAL_REJECT; | |
2844 | saveq->iocb.un.ulpWord[4] = | |
2845 | IOERR_SLI_ABORTED; | |
2846 | spin_lock_irqsave( | |
2847 | &phba->hbalock, iflag); | |
2848 | saveq->iocb_flag |= | |
2849 | LPFC_DELAY_MEM_FREE; | |
2850 | spin_unlock_irqrestore( | |
2851 | &phba->hbalock, iflag); | |
2852 | } | |
07951076 | 2853 | } |
dea3101e | 2854 | } |
2e0fef85 | 2855 | (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq); |
604a3e30 JB |
2856 | } else |
2857 | lpfc_sli_release_iocbq(phba, cmdiocbp); | |
dea3101e JB |
2858 | } else { |
2859 | /* | |
2860 | * Unknown initiating command based on the response iotag. | |
2861 | * This could be the case on the ELS ring because of | |
2862 | * lpfc_els_abort(). | |
2863 | */ | |
2864 | if (pring->ringno != LPFC_ELS_RING) { | |
2865 | /* | |
2866 | * Ring <ringno> handler: unexpected completion IoTag | |
2867 | * <IoTag> | |
2868 | */ | |
a257bf90 | 2869 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
e8b62011 JS |
2870 | "0322 Ring %d handler: " |
2871 | "unexpected completion IoTag x%x " | |
2872 | "Data: x%x x%x x%x x%x\n", | |
2873 | pring->ringno, | |
2874 | saveq->iocb.ulpIoTag, | |
2875 | saveq->iocb.ulpStatus, | |
2876 | saveq->iocb.un.ulpWord[4], | |
2877 | saveq->iocb.ulpCommand, | |
2878 | saveq->iocb.ulpContext); | |
dea3101e JB |
2879 | } |
2880 | } | |
68876920 | 2881 | |
dea3101e JB |
2882 | return rc; |
2883 | } | |
2884 | ||
e59058c4 | 2885 | /** |
3621a710 | 2886 | * lpfc_sli_rsp_pointers_error - Response ring pointer error handler |
e59058c4 JS |
2887 | * @phba: Pointer to HBA context object. |
2888 | * @pring: Pointer to driver SLI ring object. | |
2889 | * | |
2890 | * This function is called from the iocb ring event handlers when | |
2891 | * put pointer is ahead of the get pointer for a ring. This function signal | |
2892 | * an error attention condition to the worker thread and the worker | |
2893 | * thread will transition the HBA to offline state. | |
2894 | **/ | |
2e0fef85 JS |
2895 | static void |
2896 | lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) | |
875fbdfe | 2897 | { |
34b02dcd | 2898 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
875fbdfe | 2899 | /* |
025dfdaf | 2900 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger than |
875fbdfe JSEC |
2901 | * rsp ring <portRspMax> |
2902 | */ | |
2903 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
e8b62011 | 2904 | "0312 Ring %d handler: portRspPut %d " |
025dfdaf | 2905 | "is bigger than rsp ring %d\n", |
e8b62011 | 2906 | pring->ringno, le32_to_cpu(pgp->rspPutInx), |
7e56aa25 | 2907 | pring->sli.sli3.numRiocb); |
875fbdfe | 2908 | |
2e0fef85 | 2909 | phba->link_state = LPFC_HBA_ERROR; |
875fbdfe JSEC |
2910 | |
2911 | /* | |
2912 | * All error attention handlers are posted to | |
2913 | * worker thread | |
2914 | */ | |
2915 | phba->work_ha |= HA_ERATT; | |
2916 | phba->work_hs = HS_FFER3; | |
92d7f7b0 | 2917 | |
5e9d9b82 | 2918 | lpfc_worker_wake_up(phba); |
875fbdfe JSEC |
2919 | |
2920 | return; | |
2921 | } | |
2922 | ||
9399627f | 2923 | /** |
3621a710 | 2924 | * lpfc_poll_eratt - Error attention polling timer timeout handler |
9399627f JS |
2925 | * @ptr: Pointer to address of HBA context object. |
2926 | * | |
2927 | * This function is invoked by the Error Attention polling timer when the | |
2928 | * timer times out. It will check the SLI Error Attention register for | |
2929 | * possible attention events. If so, it will post an Error Attention event | |
2930 | * and wake up worker thread to process it. Otherwise, it will set up the | |
2931 | * Error Attention polling timer for the next poll. | |
2932 | **/ | |
2933 | void lpfc_poll_eratt(unsigned long ptr) | |
2934 | { | |
2935 | struct lpfc_hba *phba; | |
eb016566 | 2936 | uint32_t eratt = 0; |
aa6fbb75 | 2937 | uint64_t sli_intr, cnt; |
9399627f JS |
2938 | |
2939 | phba = (struct lpfc_hba *)ptr; | |
2940 | ||
aa6fbb75 JS |
2941 | /* Here we will also keep track of interrupts per sec of the hba */ |
2942 | sli_intr = phba->sli.slistat.sli_intr; | |
2943 | ||
2944 | if (phba->sli.slistat.sli_prev_intr > sli_intr) | |
2945 | cnt = (((uint64_t)(-1) - phba->sli.slistat.sli_prev_intr) + | |
2946 | sli_intr); | |
2947 | else | |
2948 | cnt = (sli_intr - phba->sli.slistat.sli_prev_intr); | |
2949 | ||
65791f1f JS |
2950 | /* 64-bit integer division not supported on 32-bit x86 - use do_div */ |
2951 | do_div(cnt, phba->eratt_poll_interval); | |
aa6fbb75 JS |
2952 | phba->sli.slistat.sli_ips = cnt; |
2953 | ||
2954 | phba->sli.slistat.sli_prev_intr = sli_intr; | |
2955 | ||
9399627f JS |
2956 | /* Check chip HA register for error event */ |
2957 | eratt = lpfc_sli_check_eratt(phba); | |
2958 | ||
2959 | if (eratt) | |
2960 | /* Tell the worker thread there is work to do */ | |
2961 | lpfc_worker_wake_up(phba); | |
2962 | else | |
2963 | /* Restart the timer for next eratt poll */ | |
256ec0d0 JS |
2964 | mod_timer(&phba->eratt_poll, |
2965 | jiffies + | |
65791f1f | 2966 | msecs_to_jiffies(1000 * phba->eratt_poll_interval)); |
9399627f JS |
2967 | return; |
2968 | } | |
2969 | ||
875fbdfe | 2970 | |
e59058c4 | 2971 | /** |
3621a710 | 2972 | * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring |
e59058c4 JS |
2973 | * @phba: Pointer to HBA context object. |
2974 | * @pring: Pointer to driver SLI ring object. | |
2975 | * @mask: Host attention register mask for this ring. | |
2976 | * | |
2977 | * This function is called from the interrupt context when there is a ring | |
2978 | * event for the fcp ring. The caller does not hold any lock. | |
2979 | * The function processes each response iocb in the response ring until it | |
25985edc | 2980 | * finds an iocb with LE bit set and chains all the iocbs up to the iocb with |
e59058c4 JS |
2981 | * LE bit set. The function will call the completion handler of the command iocb |
2982 | * if the response iocb indicates a completion for a command iocb or it is | |
2983 | * an abort completion. The function will call lpfc_sli_process_unsol_iocb | |
2984 | * function if this is an unsolicited iocb. | |
dea3101e | 2985 | * This routine presumes LPFC_FCP_RING handling and doesn't bother |
45ed1190 JS |
2986 | * to check it explicitly. |
2987 | */ | |
2988 | int | |
2e0fef85 JS |
2989 | lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba, |
2990 | struct lpfc_sli_ring *pring, uint32_t mask) | |
dea3101e | 2991 | { |
34b02dcd | 2992 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
dea3101e | 2993 | IOCB_t *irsp = NULL; |
87f6eaff | 2994 | IOCB_t *entry = NULL; |
dea3101e JB |
2995 | struct lpfc_iocbq *cmdiocbq = NULL; |
2996 | struct lpfc_iocbq rspiocbq; | |
dea3101e JB |
2997 | uint32_t status; |
2998 | uint32_t portRspPut, portRspMax; | |
2999 | int rc = 1; | |
3000 | lpfc_iocb_type type; | |
3001 | unsigned long iflag; | |
3002 | uint32_t rsp_cmpl = 0; | |
dea3101e | 3003 | |
2e0fef85 | 3004 | spin_lock_irqsave(&phba->hbalock, iflag); |
dea3101e JB |
3005 | pring->stats.iocb_event++; |
3006 | ||
dea3101e JB |
3007 | /* |
3008 | * The next available response entry should never exceed the maximum | |
3009 | * entries. If it does, treat it as an adapter hardware error. | |
3010 | */ | |
7e56aa25 | 3011 | portRspMax = pring->sli.sli3.numRiocb; |
dea3101e JB |
3012 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
3013 | if (unlikely(portRspPut >= portRspMax)) { | |
875fbdfe | 3014 | lpfc_sli_rsp_pointers_error(phba, pring); |
2e0fef85 | 3015 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
dea3101e JB |
3016 | return 1; |
3017 | } | |
45ed1190 JS |
3018 | if (phba->fcp_ring_in_use) { |
3019 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
3020 | return 1; | |
3021 | } else | |
3022 | phba->fcp_ring_in_use = 1; | |
dea3101e JB |
3023 | |
3024 | rmb(); | |
7e56aa25 | 3025 | while (pring->sli.sli3.rspidx != portRspPut) { |
87f6eaff JSEC |
3026 | /* |
3027 | * Fetch an entry off the ring and copy it into a local data | |
3028 | * structure. The copy involves a byte-swap since the | |
3029 | * network byte order and pci byte orders are different. | |
3030 | */ | |
ed957684 | 3031 | entry = lpfc_resp_iocb(phba, pring); |
858c9f6c | 3032 | phba->last_completion_time = jiffies; |
875fbdfe | 3033 | |
7e56aa25 JS |
3034 | if (++pring->sli.sli3.rspidx >= portRspMax) |
3035 | pring->sli.sli3.rspidx = 0; | |
875fbdfe | 3036 | |
87f6eaff JSEC |
3037 | lpfc_sli_pcimem_bcopy((uint32_t *) entry, |
3038 | (uint32_t *) &rspiocbq.iocb, | |
ed957684 | 3039 | phba->iocb_rsp_size); |
a4bc3379 | 3040 | INIT_LIST_HEAD(&(rspiocbq.list)); |
87f6eaff JSEC |
3041 | irsp = &rspiocbq.iocb; |
3042 | ||
dea3101e JB |
3043 | type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK); |
3044 | pring->stats.iocb_rsp++; | |
3045 | rsp_cmpl++; | |
3046 | ||
3047 | if (unlikely(irsp->ulpStatus)) { | |
92d7f7b0 JS |
3048 | /* |
3049 | * If resource errors reported from HBA, reduce | |
3050 | * queuedepths of the SCSI device. | |
3051 | */ | |
3052 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && | |
e3d2b802 JS |
3053 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) == |
3054 | IOERR_NO_RESOURCES)) { | |
92d7f7b0 | 3055 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
3772a991 | 3056 | phba->lpfc_rampdown_queue_depth(phba); |
92d7f7b0 JS |
3057 | spin_lock_irqsave(&phba->hbalock, iflag); |
3058 | } | |
3059 | ||
dea3101e JB |
3060 | /* Rsp ring <ringno> error: IOCB */ |
3061 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
e8b62011 | 3062 | "0336 Rsp Ring %d error: IOCB Data: " |
92d7f7b0 | 3063 | "x%x x%x x%x x%x x%x x%x x%x x%x\n", |
e8b62011 | 3064 | pring->ringno, |
92d7f7b0 JS |
3065 | irsp->un.ulpWord[0], |
3066 | irsp->un.ulpWord[1], | |
3067 | irsp->un.ulpWord[2], | |
3068 | irsp->un.ulpWord[3], | |
3069 | irsp->un.ulpWord[4], | |
3070 | irsp->un.ulpWord[5], | |
d7c255b2 JS |
3071 | *(uint32_t *)&irsp->un1, |
3072 | *((uint32_t *)&irsp->un1 + 1)); | |
dea3101e JB |
3073 | } |
3074 | ||
3075 | switch (type) { | |
3076 | case LPFC_ABORT_IOCB: | |
3077 | case LPFC_SOL_IOCB: | |
3078 | /* | |
3079 | * Idle exchange closed via ABTS from port. No iocb | |
3080 | * resources need to be recovered. | |
3081 | */ | |
3082 | if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) { | |
dca9479b | 3083 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
e8b62011 | 3084 | "0333 IOCB cmd 0x%x" |
dca9479b | 3085 | " processed. Skipping" |
92d7f7b0 | 3086 | " completion\n", |
dca9479b | 3087 | irsp->ulpCommand); |
dea3101e JB |
3088 | break; |
3089 | } | |
3090 | ||
604a3e30 JB |
3091 | cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring, |
3092 | &rspiocbq); | |
0f65ff68 JS |
3093 | if (unlikely(!cmdiocbq)) |
3094 | break; | |
3095 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) | |
3096 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; | |
3097 | if (cmdiocbq->iocb_cmpl) { | |
3098 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
3099 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, | |
3100 | &rspiocbq); | |
3101 | spin_lock_irqsave(&phba->hbalock, iflag); | |
3102 | } | |
dea3101e | 3103 | break; |
a4bc3379 | 3104 | case LPFC_UNSOL_IOCB: |
2e0fef85 | 3105 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
a4bc3379 | 3106 | lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq); |
2e0fef85 | 3107 | spin_lock_irqsave(&phba->hbalock, iflag); |
a4bc3379 | 3108 | break; |
dea3101e JB |
3109 | default: |
3110 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { | |
3111 | char adaptermsg[LPFC_MAX_ADPTMSG]; | |
3112 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); | |
3113 | memcpy(&adaptermsg[0], (uint8_t *) irsp, | |
3114 | MAX_MSG_DATA); | |
898eb71c JP |
3115 | dev_warn(&((phba->pcidev)->dev), |
3116 | "lpfc%d: %s\n", | |
dea3101e JB |
3117 | phba->brd_no, adaptermsg); |
3118 | } else { | |
3119 | /* Unknown IOCB command */ | |
3120 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
e8b62011 | 3121 | "0334 Unknown IOCB command " |
92d7f7b0 | 3122 | "Data: x%x, x%x x%x x%x x%x\n", |
e8b62011 | 3123 | type, irsp->ulpCommand, |
92d7f7b0 JS |
3124 | irsp->ulpStatus, |
3125 | irsp->ulpIoTag, | |
3126 | irsp->ulpContext); | |
dea3101e JB |
3127 | } |
3128 | break; | |
3129 | } | |
3130 | ||
3131 | /* | |
3132 | * The response IOCB has been processed. Update the ring | |
3133 | * pointer in SLIM. If the port response put pointer has not | |
3134 | * been updated, sync the pgp->rspPutInx and fetch the new port | |
3135 | * response put pointer. | |
3136 | */ | |
7e56aa25 JS |
3137 | writel(pring->sli.sli3.rspidx, |
3138 | &phba->host_gp[pring->ringno].rspGetInx); | |
dea3101e | 3139 | |
7e56aa25 | 3140 | if (pring->sli.sli3.rspidx == portRspPut) |
dea3101e JB |
3141 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
3142 | } | |
3143 | ||
3144 | if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) { | |
3145 | pring->stats.iocb_rsp_full++; | |
3146 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); | |
3147 | writel(status, phba->CAregaddr); | |
3148 | readl(phba->CAregaddr); | |
3149 | } | |
3150 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { | |
3151 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; | |
3152 | pring->stats.iocb_cmd_empty++; | |
3153 | ||
3154 | /* Force update of the local copy of cmdGetInx */ | |
7e56aa25 | 3155 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
dea3101e JB |
3156 | lpfc_sli_resume_iocb(phba, pring); |
3157 | ||
3158 | if ((pring->lpfc_sli_cmd_available)) | |
3159 | (pring->lpfc_sli_cmd_available) (phba, pring); | |
3160 | ||
3161 | } | |
3162 | ||
45ed1190 | 3163 | phba->fcp_ring_in_use = 0; |
2e0fef85 | 3164 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
dea3101e JB |
3165 | return rc; |
3166 | } | |
3167 | ||
e59058c4 | 3168 | /** |
3772a991 JS |
3169 | * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb |
3170 | * @phba: Pointer to HBA context object. | |
3171 | * @pring: Pointer to driver SLI ring object. | |
3172 | * @rspiocbp: Pointer to driver response IOCB object. | |
3173 | * | |
3174 | * This function is called from the worker thread when there is a slow-path | |
3175 | * response IOCB to process. This function chains all the response iocbs until | |
3176 | * seeing the iocb with the LE bit set. The function will call | |
3177 | * lpfc_sli_process_sol_iocb function if the response iocb indicates a | |
3178 | * completion of a command iocb. The function will call the | |
3179 | * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb. | |
3180 | * The function frees the resources or calls the completion handler if this | |
3181 | * iocb is an abort completion. The function returns NULL when the response | |
3182 | * iocb has the LE bit set and all the chained iocbs are processed, otherwise | |
3183 | * this function shall chain the iocb on to the iocb_continueq and return the | |
3184 | * response iocb passed in. | |
3185 | **/ | |
3186 | static struct lpfc_iocbq * | |
3187 | lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
3188 | struct lpfc_iocbq *rspiocbp) | |
3189 | { | |
3190 | struct lpfc_iocbq *saveq; | |
3191 | struct lpfc_iocbq *cmdiocbp; | |
3192 | struct lpfc_iocbq *next_iocb; | |
3193 | IOCB_t *irsp = NULL; | |
3194 | uint32_t free_saveq; | |
3195 | uint8_t iocb_cmd_type; | |
3196 | lpfc_iocb_type type; | |
3197 | unsigned long iflag; | |
3198 | int rc; | |
3199 | ||
3200 | spin_lock_irqsave(&phba->hbalock, iflag); | |
3201 | /* First add the response iocb to the countinueq list */ | |
3202 | list_add_tail(&rspiocbp->list, &(pring->iocb_continueq)); | |
3203 | pring->iocb_continueq_cnt++; | |
3204 | ||
70f23fd6 | 3205 | /* Now, determine whether the list is completed for processing */ |
3772a991 JS |
3206 | irsp = &rspiocbp->iocb; |
3207 | if (irsp->ulpLe) { | |
3208 | /* | |
3209 | * By default, the driver expects to free all resources | |
3210 | * associated with this iocb completion. | |
3211 | */ | |
3212 | free_saveq = 1; | |
3213 | saveq = list_get_first(&pring->iocb_continueq, | |
3214 | struct lpfc_iocbq, list); | |
3215 | irsp = &(saveq->iocb); | |
3216 | list_del_init(&pring->iocb_continueq); | |
3217 | pring->iocb_continueq_cnt = 0; | |
3218 | ||
3219 | pring->stats.iocb_rsp++; | |
3220 | ||
3221 | /* | |
3222 | * If resource errors reported from HBA, reduce | |
3223 | * queuedepths of the SCSI device. | |
3224 | */ | |
3225 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && | |
e3d2b802 JS |
3226 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) == |
3227 | IOERR_NO_RESOURCES)) { | |
3772a991 JS |
3228 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
3229 | phba->lpfc_rampdown_queue_depth(phba); | |
3230 | spin_lock_irqsave(&phba->hbalock, iflag); | |
3231 | } | |
3232 | ||
3233 | if (irsp->ulpStatus) { | |
3234 | /* Rsp ring <ringno> error: IOCB */ | |
3235 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
3236 | "0328 Rsp Ring %d error: " | |
3237 | "IOCB Data: " | |
3238 | "x%x x%x x%x x%x " | |
3239 | "x%x x%x x%x x%x " | |
3240 | "x%x x%x x%x x%x " | |
3241 | "x%x x%x x%x x%x\n", | |
3242 | pring->ringno, | |
3243 | irsp->un.ulpWord[0], | |
3244 | irsp->un.ulpWord[1], | |
3245 | irsp->un.ulpWord[2], | |
3246 | irsp->un.ulpWord[3], | |
3247 | irsp->un.ulpWord[4], | |
3248 | irsp->un.ulpWord[5], | |
3249 | *(((uint32_t *) irsp) + 6), | |
3250 | *(((uint32_t *) irsp) + 7), | |
3251 | *(((uint32_t *) irsp) + 8), | |
3252 | *(((uint32_t *) irsp) + 9), | |
3253 | *(((uint32_t *) irsp) + 10), | |
3254 | *(((uint32_t *) irsp) + 11), | |
3255 | *(((uint32_t *) irsp) + 12), | |
3256 | *(((uint32_t *) irsp) + 13), | |
3257 | *(((uint32_t *) irsp) + 14), | |
3258 | *(((uint32_t *) irsp) + 15)); | |
3259 | } | |
3260 | ||
3261 | /* | |
3262 | * Fetch the IOCB command type and call the correct completion | |
3263 | * routine. Solicited and Unsolicited IOCBs on the ELS ring | |
3264 | * get freed back to the lpfc_iocb_list by the discovery | |
3265 | * kernel thread. | |
3266 | */ | |
3267 | iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK; | |
3268 | type = lpfc_sli_iocb_cmd_type(iocb_cmd_type); | |
3269 | switch (type) { | |
3270 | case LPFC_SOL_IOCB: | |
3271 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
3272 | rc = lpfc_sli_process_sol_iocb(phba, pring, saveq); | |
3273 | spin_lock_irqsave(&phba->hbalock, iflag); | |
3274 | break; | |
3275 | ||
3276 | case LPFC_UNSOL_IOCB: | |
3277 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
3278 | rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq); | |
3279 | spin_lock_irqsave(&phba->hbalock, iflag); | |
3280 | if (!rc) | |
3281 | free_saveq = 0; | |
3282 | break; | |
3283 | ||
3284 | case LPFC_ABORT_IOCB: | |
3285 | cmdiocbp = NULL; | |
3286 | if (irsp->ulpCommand != CMD_XRI_ABORTED_CX) | |
3287 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, | |
3288 | saveq); | |
3289 | if (cmdiocbp) { | |
3290 | /* Call the specified completion routine */ | |
3291 | if (cmdiocbp->iocb_cmpl) { | |
3292 | spin_unlock_irqrestore(&phba->hbalock, | |
3293 | iflag); | |
3294 | (cmdiocbp->iocb_cmpl)(phba, cmdiocbp, | |
3295 | saveq); | |
3296 | spin_lock_irqsave(&phba->hbalock, | |
3297 | iflag); | |
3298 | } else | |
3299 | __lpfc_sli_release_iocbq(phba, | |
3300 | cmdiocbp); | |
3301 | } | |
3302 | break; | |
3303 | ||
3304 | case LPFC_UNKNOWN_IOCB: | |
3305 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { | |
3306 | char adaptermsg[LPFC_MAX_ADPTMSG]; | |
3307 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); | |
3308 | memcpy(&adaptermsg[0], (uint8_t *)irsp, | |
3309 | MAX_MSG_DATA); | |
3310 | dev_warn(&((phba->pcidev)->dev), | |
3311 | "lpfc%d: %s\n", | |
3312 | phba->brd_no, adaptermsg); | |
3313 | } else { | |
3314 | /* Unknown IOCB command */ | |
3315 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3316 | "0335 Unknown IOCB " | |
3317 | "command Data: x%x " | |
3318 | "x%x x%x x%x\n", | |
3319 | irsp->ulpCommand, | |
3320 | irsp->ulpStatus, | |
3321 | irsp->ulpIoTag, | |
3322 | irsp->ulpContext); | |
3323 | } | |
3324 | break; | |
3325 | } | |
3326 | ||
3327 | if (free_saveq) { | |
3328 | list_for_each_entry_safe(rspiocbp, next_iocb, | |
3329 | &saveq->list, list) { | |
61f35bff | 3330 | list_del_init(&rspiocbp->list); |
3772a991 JS |
3331 | __lpfc_sli_release_iocbq(phba, rspiocbp); |
3332 | } | |
3333 | __lpfc_sli_release_iocbq(phba, saveq); | |
3334 | } | |
3335 | rspiocbp = NULL; | |
3336 | } | |
3337 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
3338 | return rspiocbp; | |
3339 | } | |
3340 | ||
3341 | /** | |
3342 | * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs | |
e59058c4 JS |
3343 | * @phba: Pointer to HBA context object. |
3344 | * @pring: Pointer to driver SLI ring object. | |
3345 | * @mask: Host attention register mask for this ring. | |
3346 | * | |
3772a991 JS |
3347 | * This routine wraps the actual slow_ring event process routine from the |
3348 | * API jump table function pointer from the lpfc_hba struct. | |
e59058c4 | 3349 | **/ |
3772a991 | 3350 | void |
2e0fef85 JS |
3351 | lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba, |
3352 | struct lpfc_sli_ring *pring, uint32_t mask) | |
3772a991 JS |
3353 | { |
3354 | phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask); | |
3355 | } | |
3356 | ||
3357 | /** | |
3358 | * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings | |
3359 | * @phba: Pointer to HBA context object. | |
3360 | * @pring: Pointer to driver SLI ring object. | |
3361 | * @mask: Host attention register mask for this ring. | |
3362 | * | |
3363 | * This function is called from the worker thread when there is a ring event | |
3364 | * for non-fcp rings. The caller does not hold any lock. The function will | |
3365 | * remove each response iocb in the response ring and calls the handle | |
3366 | * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it. | |
3367 | **/ | |
3368 | static void | |
3369 | lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba, | |
3370 | struct lpfc_sli_ring *pring, uint32_t mask) | |
dea3101e | 3371 | { |
34b02dcd | 3372 | struct lpfc_pgp *pgp; |
dea3101e JB |
3373 | IOCB_t *entry; |
3374 | IOCB_t *irsp = NULL; | |
3375 | struct lpfc_iocbq *rspiocbp = NULL; | |
dea3101e | 3376 | uint32_t portRspPut, portRspMax; |
dea3101e | 3377 | unsigned long iflag; |
3772a991 | 3378 | uint32_t status; |
dea3101e | 3379 | |
34b02dcd | 3380 | pgp = &phba->port_gp[pring->ringno]; |
2e0fef85 | 3381 | spin_lock_irqsave(&phba->hbalock, iflag); |
dea3101e JB |
3382 | pring->stats.iocb_event++; |
3383 | ||
dea3101e JB |
3384 | /* |
3385 | * The next available response entry should never exceed the maximum | |
3386 | * entries. If it does, treat it as an adapter hardware error. | |
3387 | */ | |
7e56aa25 | 3388 | portRspMax = pring->sli.sli3.numRiocb; |
dea3101e JB |
3389 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
3390 | if (portRspPut >= portRspMax) { | |
3391 | /* | |
025dfdaf | 3392 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger than |
dea3101e JB |
3393 | * rsp ring <portRspMax> |
3394 | */ | |
ed957684 | 3395 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
e8b62011 | 3396 | "0303 Ring %d handler: portRspPut %d " |
025dfdaf | 3397 | "is bigger than rsp ring %d\n", |
e8b62011 | 3398 | pring->ringno, portRspPut, portRspMax); |
dea3101e | 3399 | |
2e0fef85 JS |
3400 | phba->link_state = LPFC_HBA_ERROR; |
3401 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
dea3101e JB |
3402 | |
3403 | phba->work_hs = HS_FFER3; | |
3404 | lpfc_handle_eratt(phba); | |
3405 | ||
3772a991 | 3406 | return; |
dea3101e JB |
3407 | } |
3408 | ||
3409 | rmb(); | |
7e56aa25 | 3410 | while (pring->sli.sli3.rspidx != portRspPut) { |
dea3101e JB |
3411 | /* |
3412 | * Build a completion list and call the appropriate handler. | |
3413 | * The process is to get the next available response iocb, get | |
3414 | * a free iocb from the list, copy the response data into the | |
3415 | * free iocb, insert to the continuation list, and update the | |
3416 | * next response index to slim. This process makes response | |
3417 | * iocb's in the ring available to DMA as fast as possible but | |
3418 | * pays a penalty for a copy operation. Since the iocb is | |
3419 | * only 32 bytes, this penalty is considered small relative to | |
3420 | * the PCI reads for register values and a slim write. When | |
3421 | * the ulpLe field is set, the entire Command has been | |
3422 | * received. | |
3423 | */ | |
ed957684 JS |
3424 | entry = lpfc_resp_iocb(phba, pring); |
3425 | ||
858c9f6c | 3426 | phba->last_completion_time = jiffies; |
2e0fef85 | 3427 | rspiocbp = __lpfc_sli_get_iocbq(phba); |
dea3101e JB |
3428 | if (rspiocbp == NULL) { |
3429 | printk(KERN_ERR "%s: out of buffers! Failing " | |
cadbd4a5 | 3430 | "completion.\n", __func__); |
dea3101e JB |
3431 | break; |
3432 | } | |
3433 | ||
ed957684 JS |
3434 | lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb, |
3435 | phba->iocb_rsp_size); | |
dea3101e JB |
3436 | irsp = &rspiocbp->iocb; |
3437 | ||
7e56aa25 JS |
3438 | if (++pring->sli.sli3.rspidx >= portRspMax) |
3439 | pring->sli.sli3.rspidx = 0; | |
dea3101e | 3440 | |
a58cbd52 JS |
3441 | if (pring->ringno == LPFC_ELS_RING) { |
3442 | lpfc_debugfs_slow_ring_trc(phba, | |
3443 | "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x", | |
3444 | *(((uint32_t *) irsp) + 4), | |
3445 | *(((uint32_t *) irsp) + 6), | |
3446 | *(((uint32_t *) irsp) + 7)); | |
3447 | } | |
3448 | ||
7e56aa25 JS |
3449 | writel(pring->sli.sli3.rspidx, |
3450 | &phba->host_gp[pring->ringno].rspGetInx); | |
dea3101e | 3451 | |
3772a991 JS |
3452 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
3453 | /* Handle the response IOCB */ | |
3454 | rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp); | |
3455 | spin_lock_irqsave(&phba->hbalock, iflag); | |
dea3101e JB |
3456 | |
3457 | /* | |
3458 | * If the port response put pointer has not been updated, sync | |
3459 | * the pgp->rspPutInx in the MAILBOX_tand fetch the new port | |
3460 | * response put pointer. | |
3461 | */ | |
7e56aa25 | 3462 | if (pring->sli.sli3.rspidx == portRspPut) { |
dea3101e JB |
3463 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
3464 | } | |
7e56aa25 | 3465 | } /* while (pring->sli.sli3.rspidx != portRspPut) */ |
dea3101e | 3466 | |
92d7f7b0 | 3467 | if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) { |
dea3101e JB |
3468 | /* At least one response entry has been freed */ |
3469 | pring->stats.iocb_rsp_full++; | |
3470 | /* SET RxRE_RSP in Chip Att register */ | |
3471 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); | |
3472 | writel(status, phba->CAregaddr); | |
3473 | readl(phba->CAregaddr); /* flush */ | |
3474 | } | |
3475 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { | |
3476 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; | |
3477 | pring->stats.iocb_cmd_empty++; | |
3478 | ||
3479 | /* Force update of the local copy of cmdGetInx */ | |
7e56aa25 | 3480 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
dea3101e JB |
3481 | lpfc_sli_resume_iocb(phba, pring); |
3482 | ||
3483 | if ((pring->lpfc_sli_cmd_available)) | |
3484 | (pring->lpfc_sli_cmd_available) (phba, pring); | |
3485 | ||
3486 | } | |
3487 | ||
2e0fef85 | 3488 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
3772a991 | 3489 | return; |
dea3101e JB |
3490 | } |
3491 | ||
4f774513 JS |
3492 | /** |
3493 | * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events | |
3494 | * @phba: Pointer to HBA context object. | |
3495 | * @pring: Pointer to driver SLI ring object. | |
3496 | * @mask: Host attention register mask for this ring. | |
3497 | * | |
3498 | * This function is called from the worker thread when there is a pending | |
3499 | * ELS response iocb on the driver internal slow-path response iocb worker | |
3500 | * queue. The caller does not hold any lock. The function will remove each | |
3501 | * response iocb from the response worker queue and calls the handle | |
3502 | * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it. | |
3503 | **/ | |
3504 | static void | |
3505 | lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba, | |
3506 | struct lpfc_sli_ring *pring, uint32_t mask) | |
3507 | { | |
3508 | struct lpfc_iocbq *irspiocbq; | |
4d9ab994 JS |
3509 | struct hbq_dmabuf *dmabuf; |
3510 | struct lpfc_cq_event *cq_event; | |
4f774513 JS |
3511 | unsigned long iflag; |
3512 | ||
45ed1190 JS |
3513 | spin_lock_irqsave(&phba->hbalock, iflag); |
3514 | phba->hba_flag &= ~HBA_SP_QUEUE_EVT; | |
3515 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
3516 | while (!list_empty(&phba->sli4_hba.sp_queue_event)) { | |
4f774513 JS |
3517 | /* Get the response iocb from the head of work queue */ |
3518 | spin_lock_irqsave(&phba->hbalock, iflag); | |
45ed1190 | 3519 | list_remove_head(&phba->sli4_hba.sp_queue_event, |
4d9ab994 | 3520 | cq_event, struct lpfc_cq_event, list); |
4f774513 | 3521 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
4d9ab994 JS |
3522 | |
3523 | switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) { | |
3524 | case CQE_CODE_COMPL_WQE: | |
3525 | irspiocbq = container_of(cq_event, struct lpfc_iocbq, | |
3526 | cq_event); | |
45ed1190 JS |
3527 | /* Translate ELS WCQE to response IOCBQ */ |
3528 | irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba, | |
3529 | irspiocbq); | |
3530 | if (irspiocbq) | |
3531 | lpfc_sli_sp_handle_rspiocb(phba, pring, | |
3532 | irspiocbq); | |
4d9ab994 JS |
3533 | break; |
3534 | case CQE_CODE_RECEIVE: | |
7851fe2c | 3535 | case CQE_CODE_RECEIVE_V1: |
4d9ab994 JS |
3536 | dmabuf = container_of(cq_event, struct hbq_dmabuf, |
3537 | cq_event); | |
3538 | lpfc_sli4_handle_received_buffer(phba, dmabuf); | |
3539 | break; | |
3540 | default: | |
3541 | break; | |
3542 | } | |
4f774513 JS |
3543 | } |
3544 | } | |
3545 | ||
e59058c4 | 3546 | /** |
3621a710 | 3547 | * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring |
e59058c4 JS |
3548 | * @phba: Pointer to HBA context object. |
3549 | * @pring: Pointer to driver SLI ring object. | |
3550 | * | |
3551 | * This function aborts all iocbs in the given ring and frees all the iocb | |
3552 | * objects in txq. This function issues an abort iocb for all the iocb commands | |
3553 | * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before | |
3554 | * the return of this function. The caller is not required to hold any locks. | |
3555 | **/ | |
2e0fef85 | 3556 | void |
dea3101e JB |
3557 | lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
3558 | { | |
2534ba75 | 3559 | LIST_HEAD(completions); |
dea3101e | 3560 | struct lpfc_iocbq *iocb, *next_iocb; |
dea3101e | 3561 | |
92d7f7b0 JS |
3562 | if (pring->ringno == LPFC_ELS_RING) { |
3563 | lpfc_fabric_abort_hba(phba); | |
3564 | } | |
3565 | ||
dea3101e JB |
3566 | /* Error everything on txq and txcmplq |
3567 | * First do the txq. | |
3568 | */ | |
db55fba8 JS |
3569 | if (phba->sli_rev >= LPFC_SLI_REV4) { |
3570 | spin_lock_irq(&pring->ring_lock); | |
3571 | list_splice_init(&pring->txq, &completions); | |
3572 | pring->txq_cnt = 0; | |
3573 | spin_unlock_irq(&pring->ring_lock); | |
dea3101e | 3574 | |
db55fba8 JS |
3575 | spin_lock_irq(&phba->hbalock); |
3576 | /* Next issue ABTS for everything on the txcmplq */ | |
3577 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) | |
3578 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); | |
3579 | spin_unlock_irq(&phba->hbalock); | |
3580 | } else { | |
3581 | spin_lock_irq(&phba->hbalock); | |
3582 | list_splice_init(&pring->txq, &completions); | |
3583 | pring->txq_cnt = 0; | |
dea3101e | 3584 | |
db55fba8 JS |
3585 | /* Next issue ABTS for everything on the txcmplq */ |
3586 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) | |
3587 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); | |
3588 | spin_unlock_irq(&phba->hbalock); | |
3589 | } | |
dea3101e | 3590 | |
a257bf90 JS |
3591 | /* Cancel all the IOCBs from the completions list */ |
3592 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, | |
3593 | IOERR_SLI_ABORTED); | |
dea3101e JB |
3594 | } |
3595 | ||
db55fba8 JS |
3596 | /** |
3597 | * lpfc_sli_abort_fcp_rings - Abort all iocbs in all FCP rings | |
3598 | * @phba: Pointer to HBA context object. | |
3599 | * @pring: Pointer to driver SLI ring object. | |
3600 | * | |
3601 | * This function aborts all iocbs in FCP rings and frees all the iocb | |
3602 | * objects in txq. This function issues an abort iocb for all the iocb commands | |
3603 | * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before | |
3604 | * the return of this function. The caller is not required to hold any locks. | |
3605 | **/ | |
3606 | void | |
3607 | lpfc_sli_abort_fcp_rings(struct lpfc_hba *phba) | |
3608 | { | |
3609 | struct lpfc_sli *psli = &phba->sli; | |
3610 | struct lpfc_sli_ring *pring; | |
3611 | uint32_t i; | |
3612 | ||
3613 | /* Look on all the FCP Rings for the iotag */ | |
3614 | if (phba->sli_rev >= LPFC_SLI_REV4) { | |
3615 | for (i = 0; i < phba->cfg_fcp_io_channel; i++) { | |
3616 | pring = &psli->ring[i + MAX_SLI3_CONFIGURED_RINGS]; | |
3617 | lpfc_sli_abort_iocb_ring(phba, pring); | |
3618 | } | |
3619 | } else { | |
3620 | pring = &psli->ring[psli->fcp_ring]; | |
3621 | lpfc_sli_abort_iocb_ring(phba, pring); | |
3622 | } | |
3623 | } | |
3624 | ||
3625 | ||
a8e497d5 | 3626 | /** |
3621a710 | 3627 | * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring |
a8e497d5 JS |
3628 | * @phba: Pointer to HBA context object. |
3629 | * | |
3630 | * This function flushes all iocbs in the fcp ring and frees all the iocb | |
3631 | * objects in txq and txcmplq. This function will not issue abort iocbs | |
3632 | * for all the iocb commands in txcmplq, they will just be returned with | |
3633 | * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI | |
3634 | * slot has been permanently disabled. | |
3635 | **/ | |
3636 | void | |
3637 | lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba) | |
3638 | { | |
3639 | LIST_HEAD(txq); | |
3640 | LIST_HEAD(txcmplq); | |
a8e497d5 JS |
3641 | struct lpfc_sli *psli = &phba->sli; |
3642 | struct lpfc_sli_ring *pring; | |
db55fba8 | 3643 | uint32_t i; |
a8e497d5 JS |
3644 | |
3645 | spin_lock_irq(&phba->hbalock); | |
4f2e66c6 JS |
3646 | /* Indicate the I/O queues are flushed */ |
3647 | phba->hba_flag |= HBA_FCP_IOQ_FLUSH; | |
a8e497d5 JS |
3648 | spin_unlock_irq(&phba->hbalock); |
3649 | ||
db55fba8 JS |
3650 | /* Look on all the FCP Rings for the iotag */ |
3651 | if (phba->sli_rev >= LPFC_SLI_REV4) { | |
3652 | for (i = 0; i < phba->cfg_fcp_io_channel; i++) { | |
3653 | pring = &psli->ring[i + MAX_SLI3_CONFIGURED_RINGS]; | |
3654 | ||
3655 | spin_lock_irq(&pring->ring_lock); | |
3656 | /* Retrieve everything on txq */ | |
3657 | list_splice_init(&pring->txq, &txq); | |
3658 | /* Retrieve everything on the txcmplq */ | |
3659 | list_splice_init(&pring->txcmplq, &txcmplq); | |
3660 | pring->txq_cnt = 0; | |
3661 | pring->txcmplq_cnt = 0; | |
3662 | spin_unlock_irq(&pring->ring_lock); | |
3663 | ||
3664 | /* Flush the txq */ | |
3665 | lpfc_sli_cancel_iocbs(phba, &txq, | |
3666 | IOSTAT_LOCAL_REJECT, | |
3667 | IOERR_SLI_DOWN); | |
3668 | /* Flush the txcmpq */ | |
3669 | lpfc_sli_cancel_iocbs(phba, &txcmplq, | |
3670 | IOSTAT_LOCAL_REJECT, | |
3671 | IOERR_SLI_DOWN); | |
3672 | } | |
3673 | } else { | |
3674 | pring = &psli->ring[psli->fcp_ring]; | |
a8e497d5 | 3675 | |
db55fba8 JS |
3676 | spin_lock_irq(&phba->hbalock); |
3677 | /* Retrieve everything on txq */ | |
3678 | list_splice_init(&pring->txq, &txq); | |
3679 | /* Retrieve everything on the txcmplq */ | |
3680 | list_splice_init(&pring->txcmplq, &txcmplq); | |
3681 | pring->txq_cnt = 0; | |
3682 | pring->txcmplq_cnt = 0; | |
3683 | spin_unlock_irq(&phba->hbalock); | |
3684 | ||
3685 | /* Flush the txq */ | |
3686 | lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT, | |
3687 | IOERR_SLI_DOWN); | |
3688 | /* Flush the txcmpq */ | |
3689 | lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT, | |
3690 | IOERR_SLI_DOWN); | |
3691 | } | |
a8e497d5 JS |
3692 | } |
3693 | ||
e59058c4 | 3694 | /** |
3772a991 | 3695 | * lpfc_sli_brdready_s3 - Check for sli3 host ready status |
e59058c4 JS |
3696 | * @phba: Pointer to HBA context object. |
3697 | * @mask: Bit mask to be checked. | |
3698 | * | |
3699 | * This function reads the host status register and compares | |
3700 | * with the provided bit mask to check if HBA completed | |
3701 | * the restart. This function will wait in a loop for the | |
3702 | * HBA to complete restart. If the HBA does not restart within | |
3703 | * 15 iterations, the function will reset the HBA again. The | |
3704 | * function returns 1 when HBA fail to restart otherwise returns | |
3705 | * zero. | |
3706 | **/ | |
3772a991 JS |
3707 | static int |
3708 | lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask) | |
dea3101e | 3709 | { |
41415862 JW |
3710 | uint32_t status; |
3711 | int i = 0; | |
3712 | int retval = 0; | |
dea3101e | 3713 | |
41415862 | 3714 | /* Read the HBA Host Status Register */ |
9940b97b JS |
3715 | if (lpfc_readl(phba->HSregaddr, &status)) |
3716 | return 1; | |
dea3101e | 3717 | |
41415862 JW |
3718 | /* |
3719 | * Check status register every 100ms for 5 retries, then every | |
3720 | * 500ms for 5, then every 2.5 sec for 5, then reset board and | |
3721 | * every 2.5 sec for 4. | |
3722 | * Break our of the loop if errors occurred during init. | |
3723 | */ | |
3724 | while (((status & mask) != mask) && | |
3725 | !(status & HS_FFERM) && | |
3726 | i++ < 20) { | |
dea3101e | 3727 | |
41415862 JW |
3728 | if (i <= 5) |
3729 | msleep(10); | |
3730 | else if (i <= 10) | |
3731 | msleep(500); | |
3732 | else | |
3733 | msleep(2500); | |
dea3101e | 3734 | |
41415862 | 3735 | if (i == 15) { |
2e0fef85 | 3736 | /* Do post */ |
92d7f7b0 | 3737 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
41415862 JW |
3738 | lpfc_sli_brdrestart(phba); |
3739 | } | |
3740 | /* Read the HBA Host Status Register */ | |
9940b97b JS |
3741 | if (lpfc_readl(phba->HSregaddr, &status)) { |
3742 | retval = 1; | |
3743 | break; | |
3744 | } | |
41415862 | 3745 | } |
dea3101e | 3746 | |
41415862 JW |
3747 | /* Check to see if any errors occurred during init */ |
3748 | if ((status & HS_FFERM) || (i >= 20)) { | |
e40a02c1 JS |
3749 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
3750 | "2751 Adapter failed to restart, " | |
3751 | "status reg x%x, FW Data: A8 x%x AC x%x\n", | |
3752 | status, | |
3753 | readl(phba->MBslimaddr + 0xa8), | |
3754 | readl(phba->MBslimaddr + 0xac)); | |
2e0fef85 | 3755 | phba->link_state = LPFC_HBA_ERROR; |
41415862 | 3756 | retval = 1; |
dea3101e | 3757 | } |
dea3101e | 3758 | |
41415862 JW |
3759 | return retval; |
3760 | } | |
dea3101e | 3761 | |
da0436e9 JS |
3762 | /** |
3763 | * lpfc_sli_brdready_s4 - Check for sli4 host ready status | |
3764 | * @phba: Pointer to HBA context object. | |
3765 | * @mask: Bit mask to be checked. | |
3766 | * | |
3767 | * This function checks the host status register to check if HBA is | |
3768 | * ready. This function will wait in a loop for the HBA to be ready | |
3769 | * If the HBA is not ready , the function will will reset the HBA PCI | |
3770 | * function again. The function returns 1 when HBA fail to be ready | |
3771 | * otherwise returns zero. | |
3772 | **/ | |
3773 | static int | |
3774 | lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask) | |
3775 | { | |
3776 | uint32_t status; | |
3777 | int retval = 0; | |
3778 | ||
3779 | /* Read the HBA Host Status Register */ | |
3780 | status = lpfc_sli4_post_status_check(phba); | |
3781 | ||
3782 | if (status) { | |
3783 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; | |
3784 | lpfc_sli_brdrestart(phba); | |
3785 | status = lpfc_sli4_post_status_check(phba); | |
3786 | } | |
3787 | ||
3788 | /* Check to see if any errors occurred during init */ | |
3789 | if (status) { | |
3790 | phba->link_state = LPFC_HBA_ERROR; | |
3791 | retval = 1; | |
3792 | } else | |
3793 | phba->sli4_hba.intr_enable = 0; | |
3794 | ||
3795 | return retval; | |
3796 | } | |
3797 | ||
3798 | /** | |
3799 | * lpfc_sli_brdready - Wrapper func for checking the hba readyness | |
3800 | * @phba: Pointer to HBA context object. | |
3801 | * @mask: Bit mask to be checked. | |
3802 | * | |
3803 | * This routine wraps the actual SLI3 or SLI4 hba readyness check routine | |
3804 | * from the API jump table function pointer from the lpfc_hba struct. | |
3805 | **/ | |
3806 | int | |
3807 | lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask) | |
3808 | { | |
3809 | return phba->lpfc_sli_brdready(phba, mask); | |
3810 | } | |
3811 | ||
9290831f JS |
3812 | #define BARRIER_TEST_PATTERN (0xdeadbeef) |
3813 | ||
e59058c4 | 3814 | /** |
3621a710 | 3815 | * lpfc_reset_barrier - Make HBA ready for HBA reset |
e59058c4 JS |
3816 | * @phba: Pointer to HBA context object. |
3817 | * | |
1b51197d JS |
3818 | * This function is called before resetting an HBA. This function is called |
3819 | * with hbalock held and requests HBA to quiesce DMAs before a reset. | |
e59058c4 | 3820 | **/ |
2e0fef85 | 3821 | void lpfc_reset_barrier(struct lpfc_hba *phba) |
9290831f | 3822 | { |
65a29c16 JS |
3823 | uint32_t __iomem *resp_buf; |
3824 | uint32_t __iomem *mbox_buf; | |
9290831f | 3825 | volatile uint32_t mbox; |
9940b97b | 3826 | uint32_t hc_copy, ha_copy, resp_data; |
9290831f JS |
3827 | int i; |
3828 | uint8_t hdrtype; | |
3829 | ||
1c2ba475 JT |
3830 | lockdep_assert_held(&phba->hbalock); |
3831 | ||
9290831f JS |
3832 | pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype); |
3833 | if (hdrtype != 0x80 || | |
3834 | (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID && | |
3835 | FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID)) | |
3836 | return; | |
3837 | ||
3838 | /* | |
3839 | * Tell the other part of the chip to suspend temporarily all | |
3840 | * its DMA activity. | |
3841 | */ | |
65a29c16 | 3842 | resp_buf = phba->MBslimaddr; |
9290831f JS |
3843 | |
3844 | /* Disable the error attention */ | |
9940b97b JS |
3845 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) |
3846 | return; | |
9290831f JS |
3847 | writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr); |
3848 | readl(phba->HCregaddr); /* flush */ | |
2e0fef85 | 3849 | phba->link_flag |= LS_IGNORE_ERATT; |
9290831f | 3850 | |
9940b97b JS |
3851 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
3852 | return; | |
3853 | if (ha_copy & HA_ERATT) { | |
9290831f JS |
3854 | /* Clear Chip error bit */ |
3855 | writel(HA_ERATT, phba->HAregaddr); | |
2e0fef85 | 3856 | phba->pport->stopped = 1; |
9290831f JS |
3857 | } |
3858 | ||
3859 | mbox = 0; | |
3860 | ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD; | |
3861 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP; | |
3862 | ||
3863 | writel(BARRIER_TEST_PATTERN, (resp_buf + 1)); | |
65a29c16 | 3864 | mbox_buf = phba->MBslimaddr; |
9290831f JS |
3865 | writel(mbox, mbox_buf); |
3866 | ||
9940b97b JS |
3867 | for (i = 0; i < 50; i++) { |
3868 | if (lpfc_readl((resp_buf + 1), &resp_data)) | |
3869 | return; | |
3870 | if (resp_data != ~(BARRIER_TEST_PATTERN)) | |
3871 | mdelay(1); | |
3872 | else | |
3873 | break; | |
3874 | } | |
3875 | resp_data = 0; | |
3876 | if (lpfc_readl((resp_buf + 1), &resp_data)) | |
3877 | return; | |
3878 | if (resp_data != ~(BARRIER_TEST_PATTERN)) { | |
f4b4c68f | 3879 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE || |
2e0fef85 | 3880 | phba->pport->stopped) |
9290831f JS |
3881 | goto restore_hc; |
3882 | else | |
3883 | goto clear_errat; | |
3884 | } | |
3885 | ||
3886 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST; | |
9940b97b JS |
3887 | resp_data = 0; |
3888 | for (i = 0; i < 500; i++) { | |
3889 | if (lpfc_readl(resp_buf, &resp_data)) | |
3890 | return; | |
3891 | if (resp_data != mbox) | |
3892 | mdelay(1); | |
3893 | else | |
3894 | break; | |
3895 | } | |
9290831f JS |
3896 | |
3897 | clear_errat: | |
3898 | ||
9940b97b JS |
3899 | while (++i < 500) { |
3900 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) | |
3901 | return; | |
3902 | if (!(ha_copy & HA_ERATT)) | |
3903 | mdelay(1); | |
3904 | else | |
3905 | break; | |
3906 | } | |
9290831f JS |
3907 | |
3908 | if (readl(phba->HAregaddr) & HA_ERATT) { | |
3909 | writel(HA_ERATT, phba->HAregaddr); | |
2e0fef85 | 3910 | phba->pport->stopped = 1; |
9290831f JS |
3911 | } |
3912 | ||
3913 | restore_hc: | |
2e0fef85 | 3914 | phba->link_flag &= ~LS_IGNORE_ERATT; |
9290831f JS |
3915 | writel(hc_copy, phba->HCregaddr); |
3916 | readl(phba->HCregaddr); /* flush */ | |
3917 | } | |
3918 | ||
e59058c4 | 3919 | /** |
3621a710 | 3920 | * lpfc_sli_brdkill - Issue a kill_board mailbox command |
e59058c4 JS |
3921 | * @phba: Pointer to HBA context object. |
3922 | * | |
3923 | * This function issues a kill_board mailbox command and waits for | |
3924 | * the error attention interrupt. This function is called for stopping | |
3925 | * the firmware processing. The caller is not required to hold any | |
3926 | * locks. This function calls lpfc_hba_down_post function to free | |
3927 | * any pending commands after the kill. The function will return 1 when it | |
3928 | * fails to kill the board else will return 0. | |
3929 | **/ | |
41415862 | 3930 | int |
2e0fef85 | 3931 | lpfc_sli_brdkill(struct lpfc_hba *phba) |
41415862 JW |
3932 | { |
3933 | struct lpfc_sli *psli; | |
3934 | LPFC_MBOXQ_t *pmb; | |
3935 | uint32_t status; | |
3936 | uint32_t ha_copy; | |
3937 | int retval; | |
3938 | int i = 0; | |
dea3101e | 3939 | |
41415862 | 3940 | psli = &phba->sli; |
dea3101e | 3941 | |
41415862 | 3942 | /* Kill HBA */ |
ed957684 | 3943 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
e8b62011 JS |
3944 | "0329 Kill HBA Data: x%x x%x\n", |
3945 | phba->pport->port_state, psli->sli_flag); | |
41415862 | 3946 | |
98c9ea5c JS |
3947 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
3948 | if (!pmb) | |
41415862 | 3949 | return 1; |
41415862 JW |
3950 | |
3951 | /* Disable the error attention */ | |
2e0fef85 | 3952 | spin_lock_irq(&phba->hbalock); |
9940b97b JS |
3953 | if (lpfc_readl(phba->HCregaddr, &status)) { |
3954 | spin_unlock_irq(&phba->hbalock); | |
3955 | mempool_free(pmb, phba->mbox_mem_pool); | |
3956 | return 1; | |
3957 | } | |
41415862 JW |
3958 | status &= ~HC_ERINT_ENA; |
3959 | writel(status, phba->HCregaddr); | |
3960 | readl(phba->HCregaddr); /* flush */ | |
2e0fef85 JS |
3961 | phba->link_flag |= LS_IGNORE_ERATT; |
3962 | spin_unlock_irq(&phba->hbalock); | |
41415862 JW |
3963 | |
3964 | lpfc_kill_board(phba, pmb); | |
3965 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
3966 | retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); | |
3967 | ||
3968 | if (retval != MBX_SUCCESS) { | |
3969 | if (retval != MBX_BUSY) | |
3970 | mempool_free(pmb, phba->mbox_mem_pool); | |
e40a02c1 JS |
3971 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
3972 | "2752 KILL_BOARD command failed retval %d\n", | |
3973 | retval); | |
2e0fef85 JS |
3974 | spin_lock_irq(&phba->hbalock); |
3975 | phba->link_flag &= ~LS_IGNORE_ERATT; | |
3976 | spin_unlock_irq(&phba->hbalock); | |
41415862 JW |
3977 | return 1; |
3978 | } | |
3979 | ||
f4b4c68f JS |
3980 | spin_lock_irq(&phba->hbalock); |
3981 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; | |
3982 | spin_unlock_irq(&phba->hbalock); | |
9290831f | 3983 | |
41415862 JW |
3984 | mempool_free(pmb, phba->mbox_mem_pool); |
3985 | ||
3986 | /* There is no completion for a KILL_BOARD mbox cmd. Check for an error | |
3987 | * attention every 100ms for 3 seconds. If we don't get ERATT after | |
3988 | * 3 seconds we still set HBA_ERROR state because the status of the | |
3989 | * board is now undefined. | |
3990 | */ | |
9940b97b JS |
3991 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
3992 | return 1; | |
41415862 JW |
3993 | while ((i++ < 30) && !(ha_copy & HA_ERATT)) { |
3994 | mdelay(100); | |
9940b97b JS |
3995 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
3996 | return 1; | |
41415862 JW |
3997 | } |
3998 | ||
3999 | del_timer_sync(&psli->mbox_tmo); | |
9290831f JS |
4000 | if (ha_copy & HA_ERATT) { |
4001 | writel(HA_ERATT, phba->HAregaddr); | |
2e0fef85 | 4002 | phba->pport->stopped = 1; |
9290831f | 4003 | } |
2e0fef85 | 4004 | spin_lock_irq(&phba->hbalock); |
41415862 | 4005 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
04c68496 | 4006 | psli->mbox_active = NULL; |
2e0fef85 JS |
4007 | phba->link_flag &= ~LS_IGNORE_ERATT; |
4008 | spin_unlock_irq(&phba->hbalock); | |
41415862 | 4009 | |
41415862 | 4010 | lpfc_hba_down_post(phba); |
2e0fef85 | 4011 | phba->link_state = LPFC_HBA_ERROR; |
41415862 | 4012 | |
2e0fef85 | 4013 | return ha_copy & HA_ERATT ? 0 : 1; |
dea3101e JB |
4014 | } |
4015 | ||
e59058c4 | 4016 | /** |
3772a991 | 4017 | * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA |
e59058c4 JS |
4018 | * @phba: Pointer to HBA context object. |
4019 | * | |
4020 | * This function resets the HBA by writing HC_INITFF to the control | |
4021 | * register. After the HBA resets, this function resets all the iocb ring | |
4022 | * indices. This function disables PCI layer parity checking during | |
4023 | * the reset. | |
4024 | * This function returns 0 always. | |
4025 | * The caller is not required to hold any locks. | |
4026 | **/ | |
41415862 | 4027 | int |
2e0fef85 | 4028 | lpfc_sli_brdreset(struct lpfc_hba *phba) |
dea3101e | 4029 | { |
41415862 | 4030 | struct lpfc_sli *psli; |
dea3101e | 4031 | struct lpfc_sli_ring *pring; |
41415862 | 4032 | uint16_t cfg_value; |
dea3101e | 4033 | int i; |
dea3101e | 4034 | |
41415862 | 4035 | psli = &phba->sli; |
dea3101e | 4036 | |
41415862 JW |
4037 | /* Reset HBA */ |
4038 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
e8b62011 | 4039 | "0325 Reset HBA Data: x%x x%x\n", |
2e0fef85 | 4040 | phba->pport->port_state, psli->sli_flag); |
dea3101e JB |
4041 | |
4042 | /* perform board reset */ | |
4043 | phba->fc_eventTag = 0; | |
4d9ab994 | 4044 | phba->link_events = 0; |
2e0fef85 JS |
4045 | phba->pport->fc_myDID = 0; |
4046 | phba->pport->fc_prevDID = 0; | |
dea3101e | 4047 | |
41415862 JW |
4048 | /* Turn off parity checking and serr during the physical reset */ |
4049 | pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value); | |
4050 | pci_write_config_word(phba->pcidev, PCI_COMMAND, | |
4051 | (cfg_value & | |
4052 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); | |
4053 | ||
3772a991 JS |
4054 | psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA); |
4055 | ||
41415862 JW |
4056 | /* Now toggle INITFF bit in the Host Control Register */ |
4057 | writel(HC_INITFF, phba->HCregaddr); | |
4058 | mdelay(1); | |
4059 | readl(phba->HCregaddr); /* flush */ | |
4060 | writel(0, phba->HCregaddr); | |
4061 | readl(phba->HCregaddr); /* flush */ | |
4062 | ||
4063 | /* Restore PCI cmd register */ | |
4064 | pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); | |
dea3101e JB |
4065 | |
4066 | /* Initialize relevant SLI info */ | |
41415862 JW |
4067 | for (i = 0; i < psli->num_rings; i++) { |
4068 | pring = &psli->ring[i]; | |
dea3101e | 4069 | pring->flag = 0; |
7e56aa25 JS |
4070 | pring->sli.sli3.rspidx = 0; |
4071 | pring->sli.sli3.next_cmdidx = 0; | |
4072 | pring->sli.sli3.local_getidx = 0; | |
4073 | pring->sli.sli3.cmdidx = 0; | |
dea3101e JB |
4074 | pring->missbufcnt = 0; |
4075 | } | |
dea3101e | 4076 | |
2e0fef85 | 4077 | phba->link_state = LPFC_WARM_START; |
41415862 JW |
4078 | return 0; |
4079 | } | |
4080 | ||
e59058c4 | 4081 | /** |
da0436e9 JS |
4082 | * lpfc_sli4_brdreset - Reset a sli-4 HBA |
4083 | * @phba: Pointer to HBA context object. | |
4084 | * | |
4085 | * This function resets a SLI4 HBA. This function disables PCI layer parity | |
4086 | * checking during resets the device. The caller is not required to hold | |
4087 | * any locks. | |
4088 | * | |
4089 | * This function returns 0 always. | |
4090 | **/ | |
4091 | int | |
4092 | lpfc_sli4_brdreset(struct lpfc_hba *phba) | |
4093 | { | |
4094 | struct lpfc_sli *psli = &phba->sli; | |
4095 | uint16_t cfg_value; | |
0293635e | 4096 | int rc = 0; |
da0436e9 JS |
4097 | |
4098 | /* Reset HBA */ | |
4099 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
0293635e JS |
4100 | "0295 Reset HBA Data: x%x x%x x%x\n", |
4101 | phba->pport->port_state, psli->sli_flag, | |
4102 | phba->hba_flag); | |
da0436e9 JS |
4103 | |
4104 | /* perform board reset */ | |
4105 | phba->fc_eventTag = 0; | |
4d9ab994 | 4106 | phba->link_events = 0; |
da0436e9 JS |
4107 | phba->pport->fc_myDID = 0; |
4108 | phba->pport->fc_prevDID = 0; | |
4109 | ||
da0436e9 JS |
4110 | spin_lock_irq(&phba->hbalock); |
4111 | psli->sli_flag &= ~(LPFC_PROCESS_LA); | |
4112 | phba->fcf.fcf_flag = 0; | |
da0436e9 JS |
4113 | spin_unlock_irq(&phba->hbalock); |
4114 | ||
0293635e JS |
4115 | /* SLI4 INTF 2: if FW dump is being taken skip INIT_PORT */ |
4116 | if (phba->hba_flag & HBA_FW_DUMP_OP) { | |
4117 | phba->hba_flag &= ~HBA_FW_DUMP_OP; | |
4118 | return rc; | |
4119 | } | |
4120 | ||
da0436e9 JS |
4121 | /* Now physically reset the device */ |
4122 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
4123 | "0389 Performing PCI function reset!\n"); | |
be858b65 JS |
4124 | |
4125 | /* Turn off parity checking and serr during the physical reset */ | |
4126 | pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value); | |
4127 | pci_write_config_word(phba->pcidev, PCI_COMMAND, (cfg_value & | |
4128 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); | |
4129 | ||
88318816 | 4130 | /* Perform FCoE PCI function reset before freeing queue memory */ |
27b01b82 | 4131 | rc = lpfc_pci_function_reset(phba); |
88318816 | 4132 | lpfc_sli4_queue_destroy(phba); |
da0436e9 | 4133 | |
be858b65 JS |
4134 | /* Restore PCI cmd register */ |
4135 | pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); | |
4136 | ||
27b01b82 | 4137 | return rc; |
da0436e9 JS |
4138 | } |
4139 | ||
4140 | /** | |
4141 | * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba | |
e59058c4 JS |
4142 | * @phba: Pointer to HBA context object. |
4143 | * | |
4144 | * This function is called in the SLI initialization code path to | |
4145 | * restart the HBA. The caller is not required to hold any lock. | |
4146 | * This function writes MBX_RESTART mailbox command to the SLIM and | |
4147 | * resets the HBA. At the end of the function, it calls lpfc_hba_down_post | |
4148 | * function to free any pending commands. The function enables | |
4149 | * POST only during the first initialization. The function returns zero. | |
4150 | * The function does not guarantee completion of MBX_RESTART mailbox | |
4151 | * command before the return of this function. | |
4152 | **/ | |
da0436e9 JS |
4153 | static int |
4154 | lpfc_sli_brdrestart_s3(struct lpfc_hba *phba) | |
41415862 JW |
4155 | { |
4156 | MAILBOX_t *mb; | |
4157 | struct lpfc_sli *psli; | |
41415862 JW |
4158 | volatile uint32_t word0; |
4159 | void __iomem *to_slim; | |
0d878419 | 4160 | uint32_t hba_aer_enabled; |
41415862 | 4161 | |
2e0fef85 | 4162 | spin_lock_irq(&phba->hbalock); |
41415862 | 4163 | |
0d878419 JS |
4164 | /* Take PCIe device Advanced Error Reporting (AER) state */ |
4165 | hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED; | |
4166 | ||
41415862 JW |
4167 | psli = &phba->sli; |
4168 | ||
4169 | /* Restart HBA */ | |
4170 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
e8b62011 | 4171 | "0337 Restart HBA Data: x%x x%x\n", |
2e0fef85 | 4172 | phba->pport->port_state, psli->sli_flag); |
41415862 JW |
4173 | |
4174 | word0 = 0; | |
4175 | mb = (MAILBOX_t *) &word0; | |
4176 | mb->mbxCommand = MBX_RESTART; | |
4177 | mb->mbxHc = 1; | |
4178 | ||
9290831f JS |
4179 | lpfc_reset_barrier(phba); |
4180 | ||
41415862 JW |
4181 | to_slim = phba->MBslimaddr; |
4182 | writel(*(uint32_t *) mb, to_slim); | |
4183 | readl(to_slim); /* flush */ | |
4184 | ||
4185 | /* Only skip post after fc_ffinit is completed */ | |
eaf15d5b | 4186 | if (phba->pport->port_state) |
41415862 | 4187 | word0 = 1; /* This is really setting up word1 */ |
eaf15d5b | 4188 | else |
41415862 | 4189 | word0 = 0; /* This is really setting up word1 */ |
65a29c16 | 4190 | to_slim = phba->MBslimaddr + sizeof (uint32_t); |
41415862 JW |
4191 | writel(*(uint32_t *) mb, to_slim); |
4192 | readl(to_slim); /* flush */ | |
dea3101e | 4193 | |
41415862 | 4194 | lpfc_sli_brdreset(phba); |
2e0fef85 JS |
4195 | phba->pport->stopped = 0; |
4196 | phba->link_state = LPFC_INIT_START; | |
da0436e9 | 4197 | phba->hba_flag = 0; |
2e0fef85 | 4198 | spin_unlock_irq(&phba->hbalock); |
41415862 | 4199 | |
64ba8818 JS |
4200 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); |
4201 | psli->stats_start = get_seconds(); | |
4202 | ||
eaf15d5b JS |
4203 | /* Give the INITFF and Post time to settle. */ |
4204 | mdelay(100); | |
41415862 | 4205 | |
0d878419 JS |
4206 | /* Reset HBA AER if it was enabled, note hba_flag was reset above */ |
4207 | if (hba_aer_enabled) | |
4208 | pci_disable_pcie_error_reporting(phba->pcidev); | |
4209 | ||
41415862 | 4210 | lpfc_hba_down_post(phba); |
dea3101e JB |
4211 | |
4212 | return 0; | |
4213 | } | |
4214 | ||
da0436e9 JS |
4215 | /** |
4216 | * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba | |
4217 | * @phba: Pointer to HBA context object. | |
4218 | * | |
4219 | * This function is called in the SLI initialization code path to restart | |
4220 | * a SLI4 HBA. The caller is not required to hold any lock. | |
4221 | * At the end of the function, it calls lpfc_hba_down_post function to | |
4222 | * free any pending commands. | |
4223 | **/ | |
4224 | static int | |
4225 | lpfc_sli_brdrestart_s4(struct lpfc_hba *phba) | |
4226 | { | |
4227 | struct lpfc_sli *psli = &phba->sli; | |
75baf696 | 4228 | uint32_t hba_aer_enabled; |
27b01b82 | 4229 | int rc; |
da0436e9 JS |
4230 | |
4231 | /* Restart HBA */ | |
4232 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
4233 | "0296 Restart HBA Data: x%x x%x\n", | |
4234 | phba->pport->port_state, psli->sli_flag); | |
4235 | ||
75baf696 JS |
4236 | /* Take PCIe device Advanced Error Reporting (AER) state */ |
4237 | hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED; | |
4238 | ||
27b01b82 | 4239 | rc = lpfc_sli4_brdreset(phba); |
da0436e9 JS |
4240 | |
4241 | spin_lock_irq(&phba->hbalock); | |
4242 | phba->pport->stopped = 0; | |
4243 | phba->link_state = LPFC_INIT_START; | |
4244 | phba->hba_flag = 0; | |
4245 | spin_unlock_irq(&phba->hbalock); | |
4246 | ||
4247 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); | |
4248 | psli->stats_start = get_seconds(); | |
4249 | ||
75baf696 JS |
4250 | /* Reset HBA AER if it was enabled, note hba_flag was reset above */ |
4251 | if (hba_aer_enabled) | |
4252 | pci_disable_pcie_error_reporting(phba->pcidev); | |
4253 | ||
da0436e9 JS |
4254 | lpfc_hba_down_post(phba); |
4255 | ||
27b01b82 | 4256 | return rc; |
da0436e9 JS |
4257 | } |
4258 | ||
4259 | /** | |
4260 | * lpfc_sli_brdrestart - Wrapper func for restarting hba | |
4261 | * @phba: Pointer to HBA context object. | |
4262 | * | |
4263 | * This routine wraps the actual SLI3 or SLI4 hba restart routine from the | |
4264 | * API jump table function pointer from the lpfc_hba struct. | |
4265 | **/ | |
4266 | int | |
4267 | lpfc_sli_brdrestart(struct lpfc_hba *phba) | |
4268 | { | |
4269 | return phba->lpfc_sli_brdrestart(phba); | |
4270 | } | |
4271 | ||
e59058c4 | 4272 | /** |
3621a710 | 4273 | * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart |
e59058c4 JS |
4274 | * @phba: Pointer to HBA context object. |
4275 | * | |
4276 | * This function is called after a HBA restart to wait for successful | |
4277 | * restart of the HBA. Successful restart of the HBA is indicated by | |
4278 | * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15 | |
4279 | * iteration, the function will restart the HBA again. The function returns | |
4280 | * zero if HBA successfully restarted else returns negative error code. | |
4281 | **/ | |
dea3101e JB |
4282 | static int |
4283 | lpfc_sli_chipset_init(struct lpfc_hba *phba) | |
4284 | { | |
4285 | uint32_t status, i = 0; | |
4286 | ||
4287 | /* Read the HBA Host Status Register */ | |
9940b97b JS |
4288 | if (lpfc_readl(phba->HSregaddr, &status)) |
4289 | return -EIO; | |
dea3101e JB |
4290 | |
4291 | /* Check status register to see what current state is */ | |
4292 | i = 0; | |
4293 | while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) { | |
4294 | ||
dcf2a4e0 JS |
4295 | /* Check every 10ms for 10 retries, then every 100ms for 90 |
4296 | * retries, then every 1 sec for 50 retires for a total of | |
4297 | * ~60 seconds before reset the board again and check every | |
4298 | * 1 sec for 50 retries. The up to 60 seconds before the | |
4299 | * board ready is required by the Falcon FIPS zeroization | |
4300 | * complete, and any reset the board in between shall cause | |
4301 | * restart of zeroization, further delay the board ready. | |
dea3101e | 4302 | */ |
dcf2a4e0 | 4303 | if (i++ >= 200) { |
dea3101e JB |
4304 | /* Adapter failed to init, timeout, status reg |
4305 | <status> */ | |
ed957684 | 4306 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 4307 | "0436 Adapter failed to init, " |
09372820 JS |
4308 | "timeout, status reg x%x, " |
4309 | "FW Data: A8 x%x AC x%x\n", status, | |
4310 | readl(phba->MBslimaddr + 0xa8), | |
4311 | readl(phba->MBslimaddr + 0xac)); | |
2e0fef85 | 4312 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e JB |
4313 | return -ETIMEDOUT; |
4314 | } | |
4315 | ||
4316 | /* Check to see if any errors occurred during init */ | |
4317 | if (status & HS_FFERM) { | |
4318 | /* ERROR: During chipset initialization */ | |
4319 | /* Adapter failed to init, chipset, status reg | |
4320 | <status> */ | |
ed957684 | 4321 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 4322 | "0437 Adapter failed to init, " |
09372820 JS |
4323 | "chipset, status reg x%x, " |
4324 | "FW Data: A8 x%x AC x%x\n", status, | |
4325 | readl(phba->MBslimaddr + 0xa8), | |
4326 | readl(phba->MBslimaddr + 0xac)); | |
2e0fef85 | 4327 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e JB |
4328 | return -EIO; |
4329 | } | |
4330 | ||
dcf2a4e0 | 4331 | if (i <= 10) |
dea3101e | 4332 | msleep(10); |
dcf2a4e0 JS |
4333 | else if (i <= 100) |
4334 | msleep(100); | |
4335 | else | |
4336 | msleep(1000); | |
dea3101e | 4337 | |
dcf2a4e0 JS |
4338 | if (i == 150) { |
4339 | /* Do post */ | |
92d7f7b0 | 4340 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
41415862 | 4341 | lpfc_sli_brdrestart(phba); |
dea3101e JB |
4342 | } |
4343 | /* Read the HBA Host Status Register */ | |
9940b97b JS |
4344 | if (lpfc_readl(phba->HSregaddr, &status)) |
4345 | return -EIO; | |
dea3101e JB |
4346 | } |
4347 | ||
4348 | /* Check to see if any errors occurred during init */ | |
4349 | if (status & HS_FFERM) { | |
4350 | /* ERROR: During chipset initialization */ | |
4351 | /* Adapter failed to init, chipset, status reg <status> */ | |
ed957684 | 4352 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 4353 | "0438 Adapter failed to init, chipset, " |
09372820 JS |
4354 | "status reg x%x, " |
4355 | "FW Data: A8 x%x AC x%x\n", status, | |
4356 | readl(phba->MBslimaddr + 0xa8), | |
4357 | readl(phba->MBslimaddr + 0xac)); | |
2e0fef85 | 4358 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e JB |
4359 | return -EIO; |
4360 | } | |
4361 | ||
4362 | /* Clear all interrupt enable conditions */ | |
4363 | writel(0, phba->HCregaddr); | |
4364 | readl(phba->HCregaddr); /* flush */ | |
4365 | ||
4366 | /* setup host attn register */ | |
4367 | writel(0xffffffff, phba->HAregaddr); | |
4368 | readl(phba->HAregaddr); /* flush */ | |
4369 | return 0; | |
4370 | } | |
4371 | ||
e59058c4 | 4372 | /** |
3621a710 | 4373 | * lpfc_sli_hbq_count - Get the number of HBQs to be configured |
e59058c4 JS |
4374 | * |
4375 | * This function calculates and returns the number of HBQs required to be | |
4376 | * configured. | |
4377 | **/ | |
78b2d852 | 4378 | int |
ed957684 JS |
4379 | lpfc_sli_hbq_count(void) |
4380 | { | |
92d7f7b0 | 4381 | return ARRAY_SIZE(lpfc_hbq_defs); |
ed957684 JS |
4382 | } |
4383 | ||
e59058c4 | 4384 | /** |
3621a710 | 4385 | * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries |
e59058c4 JS |
4386 | * |
4387 | * This function adds the number of hbq entries in every HBQ to get | |
4388 | * the total number of hbq entries required for the HBA and returns | |
4389 | * the total count. | |
4390 | **/ | |
ed957684 JS |
4391 | static int |
4392 | lpfc_sli_hbq_entry_count(void) | |
4393 | { | |
4394 | int hbq_count = lpfc_sli_hbq_count(); | |
4395 | int count = 0; | |
4396 | int i; | |
4397 | ||
4398 | for (i = 0; i < hbq_count; ++i) | |
92d7f7b0 | 4399 | count += lpfc_hbq_defs[i]->entry_count; |
ed957684 JS |
4400 | return count; |
4401 | } | |
4402 | ||
e59058c4 | 4403 | /** |
3621a710 | 4404 | * lpfc_sli_hbq_size - Calculate memory required for all hbq entries |
e59058c4 JS |
4405 | * |
4406 | * This function calculates amount of memory required for all hbq entries | |
4407 | * to be configured and returns the total memory required. | |
4408 | **/ | |
dea3101e | 4409 | int |
ed957684 JS |
4410 | lpfc_sli_hbq_size(void) |
4411 | { | |
4412 | return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry); | |
4413 | } | |
4414 | ||
e59058c4 | 4415 | /** |
3621a710 | 4416 | * lpfc_sli_hbq_setup - configure and initialize HBQs |
e59058c4 JS |
4417 | * @phba: Pointer to HBA context object. |
4418 | * | |
4419 | * This function is called during the SLI initialization to configure | |
4420 | * all the HBQs and post buffers to the HBQ. The caller is not | |
4421 | * required to hold any locks. This function will return zero if successful | |
4422 | * else it will return negative error code. | |
4423 | **/ | |
ed957684 JS |
4424 | static int |
4425 | lpfc_sli_hbq_setup(struct lpfc_hba *phba) | |
4426 | { | |
4427 | int hbq_count = lpfc_sli_hbq_count(); | |
4428 | LPFC_MBOXQ_t *pmb; | |
4429 | MAILBOX_t *pmbox; | |
4430 | uint32_t hbqno; | |
4431 | uint32_t hbq_entry_index; | |
ed957684 | 4432 | |
92d7f7b0 JS |
4433 | /* Get a Mailbox buffer to setup mailbox |
4434 | * commands for HBA initialization | |
4435 | */ | |
ed957684 JS |
4436 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
4437 | ||
4438 | if (!pmb) | |
4439 | return -ENOMEM; | |
4440 | ||
04c68496 | 4441 | pmbox = &pmb->u.mb; |
ed957684 JS |
4442 | |
4443 | /* Initialize the struct lpfc_sli_hbq structure for each hbq */ | |
4444 | phba->link_state = LPFC_INIT_MBX_CMDS; | |
3163f725 | 4445 | phba->hbq_in_use = 1; |
ed957684 JS |
4446 | |
4447 | hbq_entry_index = 0; | |
4448 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) { | |
4449 | phba->hbqs[hbqno].next_hbqPutIdx = 0; | |
4450 | phba->hbqs[hbqno].hbqPutIdx = 0; | |
4451 | phba->hbqs[hbqno].local_hbqGetIdx = 0; | |
4452 | phba->hbqs[hbqno].entry_count = | |
92d7f7b0 | 4453 | lpfc_hbq_defs[hbqno]->entry_count; |
51ef4c26 JS |
4454 | lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno], |
4455 | hbq_entry_index, pmb); | |
ed957684 JS |
4456 | hbq_entry_index += phba->hbqs[hbqno].entry_count; |
4457 | ||
4458 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { | |
4459 | /* Adapter failed to init, mbxCmd <cmd> CFG_RING, | |
4460 | mbxStatus <status>, ring <num> */ | |
4461 | ||
4462 | lpfc_printf_log(phba, KERN_ERR, | |
92d7f7b0 | 4463 | LOG_SLI | LOG_VPORT, |
e8b62011 | 4464 | "1805 Adapter failed to init. " |
ed957684 | 4465 | "Data: x%x x%x x%x\n", |
e8b62011 | 4466 | pmbox->mbxCommand, |
ed957684 JS |
4467 | pmbox->mbxStatus, hbqno); |
4468 | ||
4469 | phba->link_state = LPFC_HBA_ERROR; | |
4470 | mempool_free(pmb, phba->mbox_mem_pool); | |
6e7288d9 | 4471 | return -ENXIO; |
ed957684 JS |
4472 | } |
4473 | } | |
4474 | phba->hbq_count = hbq_count; | |
4475 | ||
ed957684 JS |
4476 | mempool_free(pmb, phba->mbox_mem_pool); |
4477 | ||
92d7f7b0 | 4478 | /* Initially populate or replenish the HBQs */ |
d7c255b2 JS |
4479 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) |
4480 | lpfc_sli_hbqbuf_init_hbqs(phba, hbqno); | |
ed957684 JS |
4481 | return 0; |
4482 | } | |
4483 | ||
4f774513 JS |
4484 | /** |
4485 | * lpfc_sli4_rb_setup - Initialize and post RBs to HBA | |
4486 | * @phba: Pointer to HBA context object. | |
4487 | * | |
4488 | * This function is called during the SLI initialization to configure | |
4489 | * all the HBQs and post buffers to the HBQ. The caller is not | |
4490 | * required to hold any locks. This function will return zero if successful | |
4491 | * else it will return negative error code. | |
4492 | **/ | |
4493 | static int | |
4494 | lpfc_sli4_rb_setup(struct lpfc_hba *phba) | |
4495 | { | |
4496 | phba->hbq_in_use = 1; | |
4497 | phba->hbqs[0].entry_count = lpfc_hbq_defs[0]->entry_count; | |
4498 | phba->hbq_count = 1; | |
4499 | /* Initially populate or replenish the HBQs */ | |
4500 | lpfc_sli_hbqbuf_init_hbqs(phba, 0); | |
4501 | return 0; | |
4502 | } | |
4503 | ||
e59058c4 | 4504 | /** |
3621a710 | 4505 | * lpfc_sli_config_port - Issue config port mailbox command |
e59058c4 JS |
4506 | * @phba: Pointer to HBA context object. |
4507 | * @sli_mode: sli mode - 2/3 | |
4508 | * | |
4509 | * This function is called by the sli intialization code path | |
4510 | * to issue config_port mailbox command. This function restarts the | |
4511 | * HBA firmware and issues a config_port mailbox command to configure | |
4512 | * the SLI interface in the sli mode specified by sli_mode | |
4513 | * variable. The caller is not required to hold any locks. | |
4514 | * The function returns 0 if successful, else returns negative error | |
4515 | * code. | |
4516 | **/ | |
9399627f JS |
4517 | int |
4518 | lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode) | |
dea3101e JB |
4519 | { |
4520 | LPFC_MBOXQ_t *pmb; | |
4521 | uint32_t resetcount = 0, rc = 0, done = 0; | |
4522 | ||
4523 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
4524 | if (!pmb) { | |
2e0fef85 | 4525 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e JB |
4526 | return -ENOMEM; |
4527 | } | |
4528 | ||
ed957684 | 4529 | phba->sli_rev = sli_mode; |
dea3101e | 4530 | while (resetcount < 2 && !done) { |
2e0fef85 | 4531 | spin_lock_irq(&phba->hbalock); |
1c067a42 | 4532 | phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
2e0fef85 | 4533 | spin_unlock_irq(&phba->hbalock); |
92d7f7b0 | 4534 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
41415862 | 4535 | lpfc_sli_brdrestart(phba); |
dea3101e JB |
4536 | rc = lpfc_sli_chipset_init(phba); |
4537 | if (rc) | |
4538 | break; | |
4539 | ||
2e0fef85 | 4540 | spin_lock_irq(&phba->hbalock); |
1c067a42 | 4541 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
2e0fef85 | 4542 | spin_unlock_irq(&phba->hbalock); |
dea3101e JB |
4543 | resetcount++; |
4544 | ||
ed957684 JS |
4545 | /* Call pre CONFIG_PORT mailbox command initialization. A |
4546 | * value of 0 means the call was successful. Any other | |
4547 | * nonzero value is a failure, but if ERESTART is returned, | |
4548 | * the driver may reset the HBA and try again. | |
4549 | */ | |
dea3101e JB |
4550 | rc = lpfc_config_port_prep(phba); |
4551 | if (rc == -ERESTART) { | |
ed957684 | 4552 | phba->link_state = LPFC_LINK_UNKNOWN; |
dea3101e | 4553 | continue; |
34b02dcd | 4554 | } else if (rc) |
dea3101e | 4555 | break; |
6d368e53 | 4556 | |
2e0fef85 | 4557 | phba->link_state = LPFC_INIT_MBX_CMDS; |
dea3101e JB |
4558 | lpfc_config_port(phba, pmb); |
4559 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); | |
34b02dcd JS |
4560 | phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED | |
4561 | LPFC_SLI3_HBQ_ENABLED | | |
4562 | LPFC_SLI3_CRP_ENABLED | | |
bc73905a JS |
4563 | LPFC_SLI3_BG_ENABLED | |
4564 | LPFC_SLI3_DSS_ENABLED); | |
ed957684 | 4565 | if (rc != MBX_SUCCESS) { |
dea3101e | 4566 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 4567 | "0442 Adapter failed to init, mbxCmd x%x " |
92d7f7b0 | 4568 | "CONFIG_PORT, mbxStatus x%x Data: x%x\n", |
04c68496 | 4569 | pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0); |
2e0fef85 | 4570 | spin_lock_irq(&phba->hbalock); |
04c68496 | 4571 | phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE; |
2e0fef85 JS |
4572 | spin_unlock_irq(&phba->hbalock); |
4573 | rc = -ENXIO; | |
04c68496 JS |
4574 | } else { |
4575 | /* Allow asynchronous mailbox command to go through */ | |
4576 | spin_lock_irq(&phba->hbalock); | |
4577 | phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; | |
4578 | spin_unlock_irq(&phba->hbalock); | |
ed957684 | 4579 | done = 1; |
cb69f7de JS |
4580 | |
4581 | if ((pmb->u.mb.un.varCfgPort.casabt == 1) && | |
4582 | (pmb->u.mb.un.varCfgPort.gasabt == 0)) | |
4583 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
4584 | "3110 Port did not grant ASABT\n"); | |
04c68496 | 4585 | } |
dea3101e | 4586 | } |
ed957684 JS |
4587 | if (!done) { |
4588 | rc = -EINVAL; | |
4589 | goto do_prep_failed; | |
4590 | } | |
04c68496 JS |
4591 | if (pmb->u.mb.un.varCfgPort.sli_mode == 3) { |
4592 | if (!pmb->u.mb.un.varCfgPort.cMA) { | |
34b02dcd JS |
4593 | rc = -ENXIO; |
4594 | goto do_prep_failed; | |
4595 | } | |
04c68496 | 4596 | if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) { |
34b02dcd | 4597 | phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED; |
04c68496 JS |
4598 | phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi; |
4599 | phba->max_vports = (phba->max_vpi > phba->max_vports) ? | |
4600 | phba->max_vpi : phba->max_vports; | |
4601 | ||
34b02dcd JS |
4602 | } else |
4603 | phba->max_vpi = 0; | |
bc73905a JS |
4604 | phba->fips_level = 0; |
4605 | phba->fips_spec_rev = 0; | |
4606 | if (pmb->u.mb.un.varCfgPort.gdss) { | |
04c68496 | 4607 | phba->sli3_options |= LPFC_SLI3_DSS_ENABLED; |
bc73905a JS |
4608 | phba->fips_level = pmb->u.mb.un.varCfgPort.fips_level; |
4609 | phba->fips_spec_rev = pmb->u.mb.un.varCfgPort.fips_rev; | |
4610 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
4611 | "2850 Security Crypto Active. FIPS x%d " | |
4612 | "(Spec Rev: x%d)", | |
4613 | phba->fips_level, phba->fips_spec_rev); | |
4614 | } | |
4615 | if (pmb->u.mb.un.varCfgPort.sec_err) { | |
4616 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4617 | "2856 Config Port Security Crypto " | |
4618 | "Error: x%x ", | |
4619 | pmb->u.mb.un.varCfgPort.sec_err); | |
4620 | } | |
04c68496 | 4621 | if (pmb->u.mb.un.varCfgPort.gerbm) |
34b02dcd | 4622 | phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED; |
04c68496 | 4623 | if (pmb->u.mb.un.varCfgPort.gcrp) |
34b02dcd | 4624 | phba->sli3_options |= LPFC_SLI3_CRP_ENABLED; |
6e7288d9 JS |
4625 | |
4626 | phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get; | |
4627 | phba->port_gp = phba->mbox->us.s3_pgp.port; | |
e2a0a9d6 JS |
4628 | |
4629 | if (phba->cfg_enable_bg) { | |
04c68496 | 4630 | if (pmb->u.mb.un.varCfgPort.gbg) |
e2a0a9d6 JS |
4631 | phba->sli3_options |= LPFC_SLI3_BG_ENABLED; |
4632 | else | |
4633 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4634 | "0443 Adapter did not grant " | |
4635 | "BlockGuard\n"); | |
4636 | } | |
34b02dcd | 4637 | } else { |
8f34f4ce | 4638 | phba->hbq_get = NULL; |
34b02dcd | 4639 | phba->port_gp = phba->mbox->us.s2.port; |
d7c255b2 | 4640 | phba->max_vpi = 0; |
ed957684 | 4641 | } |
92d7f7b0 | 4642 | do_prep_failed: |
ed957684 JS |
4643 | mempool_free(pmb, phba->mbox_mem_pool); |
4644 | return rc; | |
4645 | } | |
4646 | ||
e59058c4 JS |
4647 | |
4648 | /** | |
3621a710 | 4649 | * lpfc_sli_hba_setup - SLI intialization function |
e59058c4 JS |
4650 | * @phba: Pointer to HBA context object. |
4651 | * | |
4652 | * This function is the main SLI intialization function. This function | |
4653 | * is called by the HBA intialization code, HBA reset code and HBA | |
4654 | * error attention handler code. Caller is not required to hold any | |
4655 | * locks. This function issues config_port mailbox command to configure | |
4656 | * the SLI, setup iocb rings and HBQ rings. In the end the function | |
4657 | * calls the config_port_post function to issue init_link mailbox | |
4658 | * command and to start the discovery. The function will return zero | |
4659 | * if successful, else it will return negative error code. | |
4660 | **/ | |
ed957684 JS |
4661 | int |
4662 | lpfc_sli_hba_setup(struct lpfc_hba *phba) | |
4663 | { | |
4664 | uint32_t rc; | |
6d368e53 JS |
4665 | int mode = 3, i; |
4666 | int longs; | |
ed957684 JS |
4667 | |
4668 | switch (lpfc_sli_mode) { | |
4669 | case 2: | |
78b2d852 | 4670 | if (phba->cfg_enable_npiv) { |
92d7f7b0 | 4671 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
e8b62011 | 4672 | "1824 NPIV enabled: Override lpfc_sli_mode " |
92d7f7b0 | 4673 | "parameter (%d) to auto (0).\n", |
e8b62011 | 4674 | lpfc_sli_mode); |
92d7f7b0 JS |
4675 | break; |
4676 | } | |
ed957684 JS |
4677 | mode = 2; |
4678 | break; | |
4679 | case 0: | |
4680 | case 3: | |
4681 | break; | |
4682 | default: | |
92d7f7b0 | 4683 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
e8b62011 JS |
4684 | "1819 Unrecognized lpfc_sli_mode " |
4685 | "parameter: %d.\n", lpfc_sli_mode); | |
ed957684 JS |
4686 | |
4687 | break; | |
4688 | } | |
b5c53958 | 4689 | phba->fcp_embed_io = 0; /* SLI4 FC support only */ |
ed957684 | 4690 | |
9399627f JS |
4691 | rc = lpfc_sli_config_port(phba, mode); |
4692 | ||
ed957684 | 4693 | if (rc && lpfc_sli_mode == 3) |
92d7f7b0 | 4694 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
e8b62011 JS |
4695 | "1820 Unable to select SLI-3. " |
4696 | "Not supported by adapter.\n"); | |
ed957684 | 4697 | if (rc && mode != 2) |
9399627f | 4698 | rc = lpfc_sli_config_port(phba, 2); |
4597663f JS |
4699 | else if (rc && mode == 2) |
4700 | rc = lpfc_sli_config_port(phba, 3); | |
ed957684 | 4701 | if (rc) |
dea3101e JB |
4702 | goto lpfc_sli_hba_setup_error; |
4703 | ||
0d878419 JS |
4704 | /* Enable PCIe device Advanced Error Reporting (AER) if configured */ |
4705 | if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) { | |
4706 | rc = pci_enable_pcie_error_reporting(phba->pcidev); | |
4707 | if (!rc) { | |
4708 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
4709 | "2709 This device supports " | |
4710 | "Advanced Error Reporting (AER)\n"); | |
4711 | spin_lock_irq(&phba->hbalock); | |
4712 | phba->hba_flag |= HBA_AER_ENABLED; | |
4713 | spin_unlock_irq(&phba->hbalock); | |
4714 | } else { | |
4715 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
4716 | "2708 This device does not support " | |
b069d7eb JS |
4717 | "Advanced Error Reporting (AER): %d\n", |
4718 | rc); | |
0d878419 JS |
4719 | phba->cfg_aer_support = 0; |
4720 | } | |
4721 | } | |
4722 | ||
ed957684 JS |
4723 | if (phba->sli_rev == 3) { |
4724 | phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE; | |
4725 | phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE; | |
ed957684 JS |
4726 | } else { |
4727 | phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE; | |
4728 | phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE; | |
92d7f7b0 | 4729 | phba->sli3_options = 0; |
ed957684 JS |
4730 | } |
4731 | ||
4732 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
e8b62011 JS |
4733 | "0444 Firmware in SLI %x mode. Max_vpi %d\n", |
4734 | phba->sli_rev, phba->max_vpi); | |
ed957684 | 4735 | rc = lpfc_sli_ring_map(phba); |
dea3101e JB |
4736 | |
4737 | if (rc) | |
4738 | goto lpfc_sli_hba_setup_error; | |
4739 | ||
6d368e53 JS |
4740 | /* Initialize VPIs. */ |
4741 | if (phba->sli_rev == LPFC_SLI_REV3) { | |
4742 | /* | |
4743 | * The VPI bitmask and physical ID array are allocated | |
4744 | * and initialized once only - at driver load. A port | |
4745 | * reset doesn't need to reinitialize this memory. | |
4746 | */ | |
4747 | if ((phba->vpi_bmask == NULL) && (phba->vpi_ids == NULL)) { | |
4748 | longs = (phba->max_vpi + BITS_PER_LONG) / BITS_PER_LONG; | |
4749 | phba->vpi_bmask = kzalloc(longs * sizeof(unsigned long), | |
4750 | GFP_KERNEL); | |
4751 | if (!phba->vpi_bmask) { | |
4752 | rc = -ENOMEM; | |
4753 | goto lpfc_sli_hba_setup_error; | |
4754 | } | |
4755 | ||
4756 | phba->vpi_ids = kzalloc( | |
4757 | (phba->max_vpi+1) * sizeof(uint16_t), | |
4758 | GFP_KERNEL); | |
4759 | if (!phba->vpi_ids) { | |
4760 | kfree(phba->vpi_bmask); | |
4761 | rc = -ENOMEM; | |
4762 | goto lpfc_sli_hba_setup_error; | |
4763 | } | |
4764 | for (i = 0; i < phba->max_vpi; i++) | |
4765 | phba->vpi_ids[i] = i; | |
4766 | } | |
4767 | } | |
4768 | ||
9399627f | 4769 | /* Init HBQs */ |
ed957684 JS |
4770 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
4771 | rc = lpfc_sli_hbq_setup(phba); | |
4772 | if (rc) | |
4773 | goto lpfc_sli_hba_setup_error; | |
4774 | } | |
04c68496 | 4775 | spin_lock_irq(&phba->hbalock); |
dea3101e | 4776 | phba->sli.sli_flag |= LPFC_PROCESS_LA; |
04c68496 | 4777 | spin_unlock_irq(&phba->hbalock); |
dea3101e JB |
4778 | |
4779 | rc = lpfc_config_port_post(phba); | |
4780 | if (rc) | |
4781 | goto lpfc_sli_hba_setup_error; | |
4782 | ||
ed957684 JS |
4783 | return rc; |
4784 | ||
92d7f7b0 | 4785 | lpfc_sli_hba_setup_error: |
2e0fef85 | 4786 | phba->link_state = LPFC_HBA_ERROR; |
e40a02c1 | 4787 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 4788 | "0445 Firmware initialization failed\n"); |
dea3101e JB |
4789 | return rc; |
4790 | } | |
4791 | ||
e59058c4 | 4792 | /** |
da0436e9 JS |
4793 | * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region |
4794 | * @phba: Pointer to HBA context object. | |
4795 | * @mboxq: mailbox pointer. | |
4796 | * This function issue a dump mailbox command to read config region | |
4797 | * 23 and parse the records in the region and populate driver | |
4798 | * data structure. | |
e59058c4 | 4799 | **/ |
da0436e9 | 4800 | static int |
ff78d8f9 | 4801 | lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba) |
dea3101e | 4802 | { |
ff78d8f9 | 4803 | LPFC_MBOXQ_t *mboxq; |
da0436e9 JS |
4804 | struct lpfc_dmabuf *mp; |
4805 | struct lpfc_mqe *mqe; | |
4806 | uint32_t data_length; | |
4807 | int rc; | |
dea3101e | 4808 | |
da0436e9 JS |
4809 | /* Program the default value of vlan_id and fc_map */ |
4810 | phba->valid_vlan = 0; | |
4811 | phba->fc_map[0] = LPFC_FCOE_FCF_MAP0; | |
4812 | phba->fc_map[1] = LPFC_FCOE_FCF_MAP1; | |
4813 | phba->fc_map[2] = LPFC_FCOE_FCF_MAP2; | |
2e0fef85 | 4814 | |
ff78d8f9 JS |
4815 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
4816 | if (!mboxq) | |
da0436e9 JS |
4817 | return -ENOMEM; |
4818 | ||
ff78d8f9 JS |
4819 | mqe = &mboxq->u.mqe; |
4820 | if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) { | |
4821 | rc = -ENOMEM; | |
4822 | goto out_free_mboxq; | |
4823 | } | |
4824 | ||
da0436e9 JS |
4825 | mp = (struct lpfc_dmabuf *) mboxq->context1; |
4826 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
4827 | ||
4828 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, | |
4829 | "(%d):2571 Mailbox cmd x%x Status x%x " | |
4830 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x " | |
4831 | "x%x x%x x%x x%x x%x x%x x%x x%x x%x " | |
4832 | "CQ: x%x x%x x%x x%x\n", | |
4833 | mboxq->vport ? mboxq->vport->vpi : 0, | |
4834 | bf_get(lpfc_mqe_command, mqe), | |
4835 | bf_get(lpfc_mqe_status, mqe), | |
4836 | mqe->un.mb_words[0], mqe->un.mb_words[1], | |
4837 | mqe->un.mb_words[2], mqe->un.mb_words[3], | |
4838 | mqe->un.mb_words[4], mqe->un.mb_words[5], | |
4839 | mqe->un.mb_words[6], mqe->un.mb_words[7], | |
4840 | mqe->un.mb_words[8], mqe->un.mb_words[9], | |
4841 | mqe->un.mb_words[10], mqe->un.mb_words[11], | |
4842 | mqe->un.mb_words[12], mqe->un.mb_words[13], | |
4843 | mqe->un.mb_words[14], mqe->un.mb_words[15], | |
4844 | mqe->un.mb_words[16], mqe->un.mb_words[50], | |
4845 | mboxq->mcqe.word0, | |
4846 | mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1, | |
4847 | mboxq->mcqe.trailer); | |
4848 | ||
4849 | if (rc) { | |
4850 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
4851 | kfree(mp); | |
ff78d8f9 JS |
4852 | rc = -EIO; |
4853 | goto out_free_mboxq; | |
da0436e9 JS |
4854 | } |
4855 | data_length = mqe->un.mb_words[5]; | |
a0c87cbd | 4856 | if (data_length > DMP_RGN23_SIZE) { |
d11e31dd JS |
4857 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
4858 | kfree(mp); | |
ff78d8f9 JS |
4859 | rc = -EIO; |
4860 | goto out_free_mboxq; | |
d11e31dd | 4861 | } |
dea3101e | 4862 | |
da0436e9 JS |
4863 | lpfc_parse_fcoe_conf(phba, mp->virt, data_length); |
4864 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
4865 | kfree(mp); | |
ff78d8f9 JS |
4866 | rc = 0; |
4867 | ||
4868 | out_free_mboxq: | |
4869 | mempool_free(mboxq, phba->mbox_mem_pool); | |
4870 | return rc; | |
da0436e9 | 4871 | } |
e59058c4 JS |
4872 | |
4873 | /** | |
da0436e9 JS |
4874 | * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data |
4875 | * @phba: pointer to lpfc hba data structure. | |
4876 | * @mboxq: pointer to the LPFC_MBOXQ_t structure. | |
4877 | * @vpd: pointer to the memory to hold resulting port vpd data. | |
4878 | * @vpd_size: On input, the number of bytes allocated to @vpd. | |
4879 | * On output, the number of data bytes in @vpd. | |
e59058c4 | 4880 | * |
da0436e9 JS |
4881 | * This routine executes a READ_REV SLI4 mailbox command. In |
4882 | * addition, this routine gets the port vpd data. | |
4883 | * | |
4884 | * Return codes | |
af901ca1 | 4885 | * 0 - successful |
d439d286 | 4886 | * -ENOMEM - could not allocated memory. |
e59058c4 | 4887 | **/ |
da0436e9 JS |
4888 | static int |
4889 | lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, | |
4890 | uint8_t *vpd, uint32_t *vpd_size) | |
dea3101e | 4891 | { |
da0436e9 JS |
4892 | int rc = 0; |
4893 | uint32_t dma_size; | |
4894 | struct lpfc_dmabuf *dmabuf; | |
4895 | struct lpfc_mqe *mqe; | |
dea3101e | 4896 | |
da0436e9 JS |
4897 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
4898 | if (!dmabuf) | |
4899 | return -ENOMEM; | |
4900 | ||
4901 | /* | |
4902 | * Get a DMA buffer for the vpd data resulting from the READ_REV | |
4903 | * mailbox command. | |
a257bf90 | 4904 | */ |
da0436e9 | 4905 | dma_size = *vpd_size; |
1aee383d JP |
4906 | dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev, dma_size, |
4907 | &dmabuf->phys, GFP_KERNEL); | |
da0436e9 JS |
4908 | if (!dmabuf->virt) { |
4909 | kfree(dmabuf); | |
4910 | return -ENOMEM; | |
a257bf90 JS |
4911 | } |
4912 | ||
da0436e9 JS |
4913 | /* |
4914 | * The SLI4 implementation of READ_REV conflicts at word1, | |
4915 | * bits 31:16 and SLI4 adds vpd functionality not present | |
4916 | * in SLI3. This code corrects the conflicts. | |
1dcb58e5 | 4917 | */ |
da0436e9 JS |
4918 | lpfc_read_rev(phba, mboxq); |
4919 | mqe = &mboxq->u.mqe; | |
4920 | mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys); | |
4921 | mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys); | |
4922 | mqe->un.read_rev.word1 &= 0x0000FFFF; | |
4923 | bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1); | |
4924 | bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size); | |
4925 | ||
4926 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
4927 | if (rc) { | |
4928 | dma_free_coherent(&phba->pcidev->dev, dma_size, | |
4929 | dmabuf->virt, dmabuf->phys); | |
def9c7a9 | 4930 | kfree(dmabuf); |
da0436e9 JS |
4931 | return -EIO; |
4932 | } | |
1dcb58e5 | 4933 | |
da0436e9 JS |
4934 | /* |
4935 | * The available vpd length cannot be bigger than the | |
4936 | * DMA buffer passed to the port. Catch the less than | |
4937 | * case and update the caller's size. | |
4938 | */ | |
4939 | if (mqe->un.read_rev.avail_vpd_len < *vpd_size) | |
4940 | *vpd_size = mqe->un.read_rev.avail_vpd_len; | |
3772a991 | 4941 | |
d7c47992 JS |
4942 | memcpy(vpd, dmabuf->virt, *vpd_size); |
4943 | ||
da0436e9 JS |
4944 | dma_free_coherent(&phba->pcidev->dev, dma_size, |
4945 | dmabuf->virt, dmabuf->phys); | |
4946 | kfree(dmabuf); | |
4947 | return 0; | |
dea3101e JB |
4948 | } |
4949 | ||
cd1c8301 JS |
4950 | /** |
4951 | * lpfc_sli4_retrieve_pport_name - Retrieve SLI4 device physical port name | |
4952 | * @phba: pointer to lpfc hba data structure. | |
4953 | * | |
4954 | * This routine retrieves SLI4 device physical port name this PCI function | |
4955 | * is attached to. | |
4956 | * | |
4957 | * Return codes | |
4907cb7b | 4958 | * 0 - successful |
cd1c8301 JS |
4959 | * otherwise - failed to retrieve physical port name |
4960 | **/ | |
4961 | static int | |
4962 | lpfc_sli4_retrieve_pport_name(struct lpfc_hba *phba) | |
4963 | { | |
4964 | LPFC_MBOXQ_t *mboxq; | |
cd1c8301 JS |
4965 | struct lpfc_mbx_get_cntl_attributes *mbx_cntl_attr; |
4966 | struct lpfc_controller_attribute *cntl_attr; | |
4967 | struct lpfc_mbx_get_port_name *get_port_name; | |
4968 | void *virtaddr = NULL; | |
4969 | uint32_t alloclen, reqlen; | |
4970 | uint32_t shdr_status, shdr_add_status; | |
4971 | union lpfc_sli4_cfg_shdr *shdr; | |
4972 | char cport_name = 0; | |
4973 | int rc; | |
4974 | ||
4975 | /* We assume nothing at this point */ | |
4976 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL; | |
4977 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_NON; | |
4978 | ||
4979 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
4980 | if (!mboxq) | |
4981 | return -ENOMEM; | |
cd1c8301 | 4982 | /* obtain link type and link number via READ_CONFIG */ |
ff78d8f9 JS |
4983 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL; |
4984 | lpfc_sli4_read_config(phba); | |
4985 | if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) | |
4986 | goto retrieve_ppname; | |
cd1c8301 JS |
4987 | |
4988 | /* obtain link type and link number via COMMON_GET_CNTL_ATTRIBUTES */ | |
4989 | reqlen = sizeof(struct lpfc_mbx_get_cntl_attributes); | |
4990 | alloclen = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, | |
4991 | LPFC_MBOX_OPCODE_GET_CNTL_ATTRIBUTES, reqlen, | |
4992 | LPFC_SLI4_MBX_NEMBED); | |
4993 | if (alloclen < reqlen) { | |
4994 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
4995 | "3084 Allocated DMA memory size (%d) is " | |
4996 | "less than the requested DMA memory size " | |
4997 | "(%d)\n", alloclen, reqlen); | |
4998 | rc = -ENOMEM; | |
4999 | goto out_free_mboxq; | |
5000 | } | |
5001 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
5002 | virtaddr = mboxq->sge_array->addr[0]; | |
5003 | mbx_cntl_attr = (struct lpfc_mbx_get_cntl_attributes *)virtaddr; | |
5004 | shdr = &mbx_cntl_attr->cfg_shdr; | |
5005 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
5006 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
5007 | if (shdr_status || shdr_add_status || rc) { | |
5008 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
5009 | "3085 Mailbox x%x (x%x/x%x) failed, " | |
5010 | "rc:x%x, status:x%x, add_status:x%x\n", | |
5011 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), | |
5012 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), | |
5013 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), | |
5014 | rc, shdr_status, shdr_add_status); | |
5015 | rc = -ENXIO; | |
5016 | goto out_free_mboxq; | |
5017 | } | |
5018 | cntl_attr = &mbx_cntl_attr->cntl_attr; | |
5019 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL; | |
5020 | phba->sli4_hba.lnk_info.lnk_tp = | |
5021 | bf_get(lpfc_cntl_attr_lnk_type, cntl_attr); | |
5022 | phba->sli4_hba.lnk_info.lnk_no = | |
5023 | bf_get(lpfc_cntl_attr_lnk_numb, cntl_attr); | |
5024 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
5025 | "3086 lnk_type:%d, lnk_numb:%d\n", | |
5026 | phba->sli4_hba.lnk_info.lnk_tp, | |
5027 | phba->sli4_hba.lnk_info.lnk_no); | |
5028 | ||
5029 | retrieve_ppname: | |
5030 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, | |
5031 | LPFC_MBOX_OPCODE_GET_PORT_NAME, | |
5032 | sizeof(struct lpfc_mbx_get_port_name) - | |
5033 | sizeof(struct lpfc_sli4_cfg_mhdr), | |
5034 | LPFC_SLI4_MBX_EMBED); | |
5035 | get_port_name = &mboxq->u.mqe.un.get_port_name; | |
5036 | shdr = (union lpfc_sli4_cfg_shdr *)&get_port_name->header.cfg_shdr; | |
5037 | bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_OPCODE_VERSION_1); | |
5038 | bf_set(lpfc_mbx_get_port_name_lnk_type, &get_port_name->u.request, | |
5039 | phba->sli4_hba.lnk_info.lnk_tp); | |
5040 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
5041 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
5042 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
5043 | if (shdr_status || shdr_add_status || rc) { | |
5044 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
5045 | "3087 Mailbox x%x (x%x/x%x) failed: " | |
5046 | "rc:x%x, status:x%x, add_status:x%x\n", | |
5047 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), | |
5048 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), | |
5049 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), | |
5050 | rc, shdr_status, shdr_add_status); | |
5051 | rc = -ENXIO; | |
5052 | goto out_free_mboxq; | |
5053 | } | |
5054 | switch (phba->sli4_hba.lnk_info.lnk_no) { | |
5055 | case LPFC_LINK_NUMBER_0: | |
5056 | cport_name = bf_get(lpfc_mbx_get_port_name_name0, | |
5057 | &get_port_name->u.response); | |
5058 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; | |
5059 | break; | |
5060 | case LPFC_LINK_NUMBER_1: | |
5061 | cport_name = bf_get(lpfc_mbx_get_port_name_name1, | |
5062 | &get_port_name->u.response); | |
5063 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; | |
5064 | break; | |
5065 | case LPFC_LINK_NUMBER_2: | |
5066 | cport_name = bf_get(lpfc_mbx_get_port_name_name2, | |
5067 | &get_port_name->u.response); | |
5068 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; | |
5069 | break; | |
5070 | case LPFC_LINK_NUMBER_3: | |
5071 | cport_name = bf_get(lpfc_mbx_get_port_name_name3, | |
5072 | &get_port_name->u.response); | |
5073 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; | |
5074 | break; | |
5075 | default: | |
5076 | break; | |
5077 | } | |
5078 | ||
5079 | if (phba->sli4_hba.pport_name_sta == LPFC_SLI4_PPNAME_GET) { | |
5080 | phba->Port[0] = cport_name; | |
5081 | phba->Port[1] = '\0'; | |
5082 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
5083 | "3091 SLI get port name: %s\n", phba->Port); | |
5084 | } | |
5085 | ||
5086 | out_free_mboxq: | |
5087 | if (rc != MBX_TIMEOUT) { | |
5088 | if (bf_get(lpfc_mqe_command, &mboxq->u.mqe) == MBX_SLI4_CONFIG) | |
5089 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
5090 | else | |
5091 | mempool_free(mboxq, phba->mbox_mem_pool); | |
5092 | } | |
5093 | return rc; | |
5094 | } | |
5095 | ||
e59058c4 | 5096 | /** |
da0436e9 JS |
5097 | * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues |
5098 | * @phba: pointer to lpfc hba data structure. | |
e59058c4 | 5099 | * |
da0436e9 JS |
5100 | * This routine is called to explicitly arm the SLI4 device's completion and |
5101 | * event queues | |
5102 | **/ | |
5103 | static void | |
5104 | lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba) | |
5105 | { | |
962bc51b | 5106 | int fcp_eqidx; |
da0436e9 JS |
5107 | |
5108 | lpfc_sli4_cq_release(phba->sli4_hba.mbx_cq, LPFC_QUEUE_REARM); | |
5109 | lpfc_sli4_cq_release(phba->sli4_hba.els_cq, LPFC_QUEUE_REARM); | |
0558056c | 5110 | fcp_eqidx = 0; |
2e90f4b5 | 5111 | if (phba->sli4_hba.fcp_cq) { |
67d12733 | 5112 | do { |
2e90f4b5 JS |
5113 | lpfc_sli4_cq_release(phba->sli4_hba.fcp_cq[fcp_eqidx], |
5114 | LPFC_QUEUE_REARM); | |
67d12733 | 5115 | } while (++fcp_eqidx < phba->cfg_fcp_io_channel); |
2e90f4b5 | 5116 | } |
1ba981fd | 5117 | |
f38fa0bb | 5118 | if (phba->cfg_fof) |
1ba981fd JS |
5119 | lpfc_sli4_cq_release(phba->sli4_hba.oas_cq, LPFC_QUEUE_REARM); |
5120 | ||
67d12733 JS |
5121 | if (phba->sli4_hba.hba_eq) { |
5122 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_io_channel; | |
2e90f4b5 | 5123 | fcp_eqidx++) |
67d12733 | 5124 | lpfc_sli4_eq_release(phba->sli4_hba.hba_eq[fcp_eqidx], |
2e90f4b5 JS |
5125 | LPFC_QUEUE_REARM); |
5126 | } | |
1ba981fd JS |
5127 | |
5128 | if (phba->cfg_fof) | |
5129 | lpfc_sli4_eq_release(phba->sli4_hba.fof_eq, LPFC_QUEUE_REARM); | |
da0436e9 JS |
5130 | } |
5131 | ||
6d368e53 JS |
5132 | /** |
5133 | * lpfc_sli4_get_avail_extnt_rsrc - Get available resource extent count. | |
5134 | * @phba: Pointer to HBA context object. | |
5135 | * @type: The resource extent type. | |
b76f2dc9 JS |
5136 | * @extnt_count: buffer to hold port available extent count. |
5137 | * @extnt_size: buffer to hold element count per extent. | |
6d368e53 | 5138 | * |
b76f2dc9 JS |
5139 | * This function calls the port and retrievs the number of available |
5140 | * extents and their size for a particular extent type. | |
5141 | * | |
5142 | * Returns: 0 if successful. Nonzero otherwise. | |
6d368e53 | 5143 | **/ |
b76f2dc9 | 5144 | int |
6d368e53 JS |
5145 | lpfc_sli4_get_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type, |
5146 | uint16_t *extnt_count, uint16_t *extnt_size) | |
5147 | { | |
5148 | int rc = 0; | |
5149 | uint32_t length; | |
5150 | uint32_t mbox_tmo; | |
5151 | struct lpfc_mbx_get_rsrc_extent_info *rsrc_info; | |
5152 | LPFC_MBOXQ_t *mbox; | |
5153 | ||
5154 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
5155 | if (!mbox) | |
5156 | return -ENOMEM; | |
5157 | ||
5158 | /* Find out how many extents are available for this resource type */ | |
5159 | length = (sizeof(struct lpfc_mbx_get_rsrc_extent_info) - | |
5160 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
5161 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
5162 | LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO, | |
5163 | length, LPFC_SLI4_MBX_EMBED); | |
5164 | ||
5165 | /* Send an extents count of 0 - the GET doesn't use it. */ | |
5166 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type, | |
5167 | LPFC_SLI4_MBX_EMBED); | |
5168 | if (unlikely(rc)) { | |
5169 | rc = -EIO; | |
5170 | goto err_exit; | |
5171 | } | |
5172 | ||
5173 | if (!phba->sli4_hba.intr_enable) | |
5174 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
5175 | else { | |
a183a15f | 5176 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
6d368e53 JS |
5177 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
5178 | } | |
5179 | if (unlikely(rc)) { | |
5180 | rc = -EIO; | |
5181 | goto err_exit; | |
5182 | } | |
5183 | ||
5184 | rsrc_info = &mbox->u.mqe.un.rsrc_extent_info; | |
5185 | if (bf_get(lpfc_mbox_hdr_status, | |
5186 | &rsrc_info->header.cfg_shdr.response)) { | |
5187 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, | |
5188 | "2930 Failed to get resource extents " | |
5189 | "Status 0x%x Add'l Status 0x%x\n", | |
5190 | bf_get(lpfc_mbox_hdr_status, | |
5191 | &rsrc_info->header.cfg_shdr.response), | |
5192 | bf_get(lpfc_mbox_hdr_add_status, | |
5193 | &rsrc_info->header.cfg_shdr.response)); | |
5194 | rc = -EIO; | |
5195 | goto err_exit; | |
5196 | } | |
5197 | ||
5198 | *extnt_count = bf_get(lpfc_mbx_get_rsrc_extent_info_cnt, | |
5199 | &rsrc_info->u.rsp); | |
5200 | *extnt_size = bf_get(lpfc_mbx_get_rsrc_extent_info_size, | |
5201 | &rsrc_info->u.rsp); | |
8a9d2e80 JS |
5202 | |
5203 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
5204 | "3162 Retrieved extents type-%d from port: count:%d, " | |
5205 | "size:%d\n", type, *extnt_count, *extnt_size); | |
5206 | ||
5207 | err_exit: | |
6d368e53 JS |
5208 | mempool_free(mbox, phba->mbox_mem_pool); |
5209 | return rc; | |
5210 | } | |
5211 | ||
5212 | /** | |
5213 | * lpfc_sli4_chk_avail_extnt_rsrc - Check for available SLI4 resource extents. | |
5214 | * @phba: Pointer to HBA context object. | |
5215 | * @type: The extent type to check. | |
5216 | * | |
5217 | * This function reads the current available extents from the port and checks | |
5218 | * if the extent count or extent size has changed since the last access. | |
5219 | * Callers use this routine post port reset to understand if there is a | |
5220 | * extent reprovisioning requirement. | |
5221 | * | |
5222 | * Returns: | |
5223 | * -Error: error indicates problem. | |
5224 | * 1: Extent count or size has changed. | |
5225 | * 0: No changes. | |
5226 | **/ | |
5227 | static int | |
5228 | lpfc_sli4_chk_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type) | |
5229 | { | |
5230 | uint16_t curr_ext_cnt, rsrc_ext_cnt; | |
5231 | uint16_t size_diff, rsrc_ext_size; | |
5232 | int rc = 0; | |
5233 | struct lpfc_rsrc_blks *rsrc_entry; | |
5234 | struct list_head *rsrc_blk_list = NULL; | |
5235 | ||
5236 | size_diff = 0; | |
5237 | curr_ext_cnt = 0; | |
5238 | rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type, | |
5239 | &rsrc_ext_cnt, | |
5240 | &rsrc_ext_size); | |
5241 | if (unlikely(rc)) | |
5242 | return -EIO; | |
5243 | ||
5244 | switch (type) { | |
5245 | case LPFC_RSC_TYPE_FCOE_RPI: | |
5246 | rsrc_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list; | |
5247 | break; | |
5248 | case LPFC_RSC_TYPE_FCOE_VPI: | |
5249 | rsrc_blk_list = &phba->lpfc_vpi_blk_list; | |
5250 | break; | |
5251 | case LPFC_RSC_TYPE_FCOE_XRI: | |
5252 | rsrc_blk_list = &phba->sli4_hba.lpfc_xri_blk_list; | |
5253 | break; | |
5254 | case LPFC_RSC_TYPE_FCOE_VFI: | |
5255 | rsrc_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list; | |
5256 | break; | |
5257 | default: | |
5258 | break; | |
5259 | } | |
5260 | ||
5261 | list_for_each_entry(rsrc_entry, rsrc_blk_list, list) { | |
5262 | curr_ext_cnt++; | |
5263 | if (rsrc_entry->rsrc_size != rsrc_ext_size) | |
5264 | size_diff++; | |
5265 | } | |
5266 | ||
5267 | if (curr_ext_cnt != rsrc_ext_cnt || size_diff != 0) | |
5268 | rc = 1; | |
5269 | ||
5270 | return rc; | |
5271 | } | |
5272 | ||
5273 | /** | |
5274 | * lpfc_sli4_cfg_post_extnts - | |
5275 | * @phba: Pointer to HBA context object. | |
5276 | * @extnt_cnt - number of available extents. | |
5277 | * @type - the extent type (rpi, xri, vfi, vpi). | |
5278 | * @emb - buffer to hold either MBX_EMBED or MBX_NEMBED operation. | |
5279 | * @mbox - pointer to the caller's allocated mailbox structure. | |
5280 | * | |
5281 | * This function executes the extents allocation request. It also | |
5282 | * takes care of the amount of memory needed to allocate or get the | |
5283 | * allocated extents. It is the caller's responsibility to evaluate | |
5284 | * the response. | |
5285 | * | |
5286 | * Returns: | |
5287 | * -Error: Error value describes the condition found. | |
5288 | * 0: if successful | |
5289 | **/ | |
5290 | static int | |
8a9d2e80 | 5291 | lpfc_sli4_cfg_post_extnts(struct lpfc_hba *phba, uint16_t extnt_cnt, |
6d368e53 JS |
5292 | uint16_t type, bool *emb, LPFC_MBOXQ_t *mbox) |
5293 | { | |
5294 | int rc = 0; | |
5295 | uint32_t req_len; | |
5296 | uint32_t emb_len; | |
5297 | uint32_t alloc_len, mbox_tmo; | |
5298 | ||
5299 | /* Calculate the total requested length of the dma memory */ | |
8a9d2e80 | 5300 | req_len = extnt_cnt * sizeof(uint16_t); |
6d368e53 JS |
5301 | |
5302 | /* | |
5303 | * Calculate the size of an embedded mailbox. The uint32_t | |
5304 | * accounts for extents-specific word. | |
5305 | */ | |
5306 | emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) - | |
5307 | sizeof(uint32_t); | |
5308 | ||
5309 | /* | |
5310 | * Presume the allocation and response will fit into an embedded | |
5311 | * mailbox. If not true, reconfigure to a non-embedded mailbox. | |
5312 | */ | |
5313 | *emb = LPFC_SLI4_MBX_EMBED; | |
5314 | if (req_len > emb_len) { | |
8a9d2e80 | 5315 | req_len = extnt_cnt * sizeof(uint16_t) + |
6d368e53 JS |
5316 | sizeof(union lpfc_sli4_cfg_shdr) + |
5317 | sizeof(uint32_t); | |
5318 | *emb = LPFC_SLI4_MBX_NEMBED; | |
5319 | } | |
5320 | ||
5321 | alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
5322 | LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT, | |
5323 | req_len, *emb); | |
5324 | if (alloc_len < req_len) { | |
5325 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
b76f2dc9 | 5326 | "2982 Allocated DMA memory size (x%x) is " |
6d368e53 JS |
5327 | "less than the requested DMA memory " |
5328 | "size (x%x)\n", alloc_len, req_len); | |
5329 | return -ENOMEM; | |
5330 | } | |
8a9d2e80 | 5331 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, extnt_cnt, type, *emb); |
6d368e53 JS |
5332 | if (unlikely(rc)) |
5333 | return -EIO; | |
5334 | ||
5335 | if (!phba->sli4_hba.intr_enable) | |
5336 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
5337 | else { | |
a183a15f | 5338 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
6d368e53 JS |
5339 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
5340 | } | |
5341 | ||
5342 | if (unlikely(rc)) | |
5343 | rc = -EIO; | |
5344 | return rc; | |
5345 | } | |
5346 | ||
5347 | /** | |
5348 | * lpfc_sli4_alloc_extent - Allocate an SLI4 resource extent. | |
5349 | * @phba: Pointer to HBA context object. | |
5350 | * @type: The resource extent type to allocate. | |
5351 | * | |
5352 | * This function allocates the number of elements for the specified | |
5353 | * resource type. | |
5354 | **/ | |
5355 | static int | |
5356 | lpfc_sli4_alloc_extent(struct lpfc_hba *phba, uint16_t type) | |
5357 | { | |
5358 | bool emb = false; | |
5359 | uint16_t rsrc_id_cnt, rsrc_cnt, rsrc_size; | |
5360 | uint16_t rsrc_id, rsrc_start, j, k; | |
5361 | uint16_t *ids; | |
5362 | int i, rc; | |
5363 | unsigned long longs; | |
5364 | unsigned long *bmask; | |
5365 | struct lpfc_rsrc_blks *rsrc_blks; | |
5366 | LPFC_MBOXQ_t *mbox; | |
5367 | uint32_t length; | |
5368 | struct lpfc_id_range *id_array = NULL; | |
5369 | void *virtaddr = NULL; | |
5370 | struct lpfc_mbx_nembed_rsrc_extent *n_rsrc; | |
5371 | struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext; | |
5372 | struct list_head *ext_blk_list; | |
5373 | ||
5374 | rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type, | |
5375 | &rsrc_cnt, | |
5376 | &rsrc_size); | |
5377 | if (unlikely(rc)) | |
5378 | return -EIO; | |
5379 | ||
5380 | if ((rsrc_cnt == 0) || (rsrc_size == 0)) { | |
5381 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, | |
5382 | "3009 No available Resource Extents " | |
5383 | "for resource type 0x%x: Count: 0x%x, " | |
5384 | "Size 0x%x\n", type, rsrc_cnt, | |
5385 | rsrc_size); | |
5386 | return -ENOMEM; | |
5387 | } | |
5388 | ||
8a9d2e80 JS |
5389 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_INIT | LOG_SLI, |
5390 | "2903 Post resource extents type-0x%x: " | |
5391 | "count:%d, size %d\n", type, rsrc_cnt, rsrc_size); | |
6d368e53 JS |
5392 | |
5393 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
5394 | if (!mbox) | |
5395 | return -ENOMEM; | |
5396 | ||
8a9d2e80 | 5397 | rc = lpfc_sli4_cfg_post_extnts(phba, rsrc_cnt, type, &emb, mbox); |
6d368e53 JS |
5398 | if (unlikely(rc)) { |
5399 | rc = -EIO; | |
5400 | goto err_exit; | |
5401 | } | |
5402 | ||
5403 | /* | |
5404 | * Figure out where the response is located. Then get local pointers | |
5405 | * to the response data. The port does not guarantee to respond to | |
5406 | * all extents counts request so update the local variable with the | |
5407 | * allocated count from the port. | |
5408 | */ | |
5409 | if (emb == LPFC_SLI4_MBX_EMBED) { | |
5410 | rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents; | |
5411 | id_array = &rsrc_ext->u.rsp.id[0]; | |
5412 | rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp); | |
5413 | } else { | |
5414 | virtaddr = mbox->sge_array->addr[0]; | |
5415 | n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr; | |
5416 | rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc); | |
5417 | id_array = &n_rsrc->id; | |
5418 | } | |
5419 | ||
5420 | longs = ((rsrc_cnt * rsrc_size) + BITS_PER_LONG - 1) / BITS_PER_LONG; | |
5421 | rsrc_id_cnt = rsrc_cnt * rsrc_size; | |
5422 | ||
5423 | /* | |
5424 | * Based on the resource size and count, correct the base and max | |
5425 | * resource values. | |
5426 | */ | |
5427 | length = sizeof(struct lpfc_rsrc_blks); | |
5428 | switch (type) { | |
5429 | case LPFC_RSC_TYPE_FCOE_RPI: | |
5430 | phba->sli4_hba.rpi_bmask = kzalloc(longs * | |
5431 | sizeof(unsigned long), | |
5432 | GFP_KERNEL); | |
5433 | if (unlikely(!phba->sli4_hba.rpi_bmask)) { | |
5434 | rc = -ENOMEM; | |
5435 | goto err_exit; | |
5436 | } | |
5437 | phba->sli4_hba.rpi_ids = kzalloc(rsrc_id_cnt * | |
5438 | sizeof(uint16_t), | |
5439 | GFP_KERNEL); | |
5440 | if (unlikely(!phba->sli4_hba.rpi_ids)) { | |
5441 | kfree(phba->sli4_hba.rpi_bmask); | |
5442 | rc = -ENOMEM; | |
5443 | goto err_exit; | |
5444 | } | |
5445 | ||
5446 | /* | |
5447 | * The next_rpi was initialized with the maximum available | |
5448 | * count but the port may allocate a smaller number. Catch | |
5449 | * that case and update the next_rpi. | |
5450 | */ | |
5451 | phba->sli4_hba.next_rpi = rsrc_id_cnt; | |
5452 | ||
5453 | /* Initialize local ptrs for common extent processing later. */ | |
5454 | bmask = phba->sli4_hba.rpi_bmask; | |
5455 | ids = phba->sli4_hba.rpi_ids; | |
5456 | ext_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list; | |
5457 | break; | |
5458 | case LPFC_RSC_TYPE_FCOE_VPI: | |
5459 | phba->vpi_bmask = kzalloc(longs * | |
5460 | sizeof(unsigned long), | |
5461 | GFP_KERNEL); | |
5462 | if (unlikely(!phba->vpi_bmask)) { | |
5463 | rc = -ENOMEM; | |
5464 | goto err_exit; | |
5465 | } | |
5466 | phba->vpi_ids = kzalloc(rsrc_id_cnt * | |
5467 | sizeof(uint16_t), | |
5468 | GFP_KERNEL); | |
5469 | if (unlikely(!phba->vpi_ids)) { | |
5470 | kfree(phba->vpi_bmask); | |
5471 | rc = -ENOMEM; | |
5472 | goto err_exit; | |
5473 | } | |
5474 | ||
5475 | /* Initialize local ptrs for common extent processing later. */ | |
5476 | bmask = phba->vpi_bmask; | |
5477 | ids = phba->vpi_ids; | |
5478 | ext_blk_list = &phba->lpfc_vpi_blk_list; | |
5479 | break; | |
5480 | case LPFC_RSC_TYPE_FCOE_XRI: | |
5481 | phba->sli4_hba.xri_bmask = kzalloc(longs * | |
5482 | sizeof(unsigned long), | |
5483 | GFP_KERNEL); | |
5484 | if (unlikely(!phba->sli4_hba.xri_bmask)) { | |
5485 | rc = -ENOMEM; | |
5486 | goto err_exit; | |
5487 | } | |
8a9d2e80 | 5488 | phba->sli4_hba.max_cfg_param.xri_used = 0; |
6d368e53 JS |
5489 | phba->sli4_hba.xri_ids = kzalloc(rsrc_id_cnt * |
5490 | sizeof(uint16_t), | |
5491 | GFP_KERNEL); | |
5492 | if (unlikely(!phba->sli4_hba.xri_ids)) { | |
5493 | kfree(phba->sli4_hba.xri_bmask); | |
5494 | rc = -ENOMEM; | |
5495 | goto err_exit; | |
5496 | } | |
5497 | ||
5498 | /* Initialize local ptrs for common extent processing later. */ | |
5499 | bmask = phba->sli4_hba.xri_bmask; | |
5500 | ids = phba->sli4_hba.xri_ids; | |
5501 | ext_blk_list = &phba->sli4_hba.lpfc_xri_blk_list; | |
5502 | break; | |
5503 | case LPFC_RSC_TYPE_FCOE_VFI: | |
5504 | phba->sli4_hba.vfi_bmask = kzalloc(longs * | |
5505 | sizeof(unsigned long), | |
5506 | GFP_KERNEL); | |
5507 | if (unlikely(!phba->sli4_hba.vfi_bmask)) { | |
5508 | rc = -ENOMEM; | |
5509 | goto err_exit; | |
5510 | } | |
5511 | phba->sli4_hba.vfi_ids = kzalloc(rsrc_id_cnt * | |
5512 | sizeof(uint16_t), | |
5513 | GFP_KERNEL); | |
5514 | if (unlikely(!phba->sli4_hba.vfi_ids)) { | |
5515 | kfree(phba->sli4_hba.vfi_bmask); | |
5516 | rc = -ENOMEM; | |
5517 | goto err_exit; | |
5518 | } | |
5519 | ||
5520 | /* Initialize local ptrs for common extent processing later. */ | |
5521 | bmask = phba->sli4_hba.vfi_bmask; | |
5522 | ids = phba->sli4_hba.vfi_ids; | |
5523 | ext_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list; | |
5524 | break; | |
5525 | default: | |
5526 | /* Unsupported Opcode. Fail call. */ | |
5527 | id_array = NULL; | |
5528 | bmask = NULL; | |
5529 | ids = NULL; | |
5530 | ext_blk_list = NULL; | |
5531 | goto err_exit; | |
5532 | } | |
5533 | ||
5534 | /* | |
5535 | * Complete initializing the extent configuration with the | |
5536 | * allocated ids assigned to this function. The bitmask serves | |
5537 | * as an index into the array and manages the available ids. The | |
5538 | * array just stores the ids communicated to the port via the wqes. | |
5539 | */ | |
5540 | for (i = 0, j = 0, k = 0; i < rsrc_cnt; i++) { | |
5541 | if ((i % 2) == 0) | |
5542 | rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_0, | |
5543 | &id_array[k]); | |
5544 | else | |
5545 | rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_1, | |
5546 | &id_array[k]); | |
5547 | ||
5548 | rsrc_blks = kzalloc(length, GFP_KERNEL); | |
5549 | if (unlikely(!rsrc_blks)) { | |
5550 | rc = -ENOMEM; | |
5551 | kfree(bmask); | |
5552 | kfree(ids); | |
5553 | goto err_exit; | |
5554 | } | |
5555 | rsrc_blks->rsrc_start = rsrc_id; | |
5556 | rsrc_blks->rsrc_size = rsrc_size; | |
5557 | list_add_tail(&rsrc_blks->list, ext_blk_list); | |
5558 | rsrc_start = rsrc_id; | |
5559 | if ((type == LPFC_RSC_TYPE_FCOE_XRI) && (j == 0)) | |
5560 | phba->sli4_hba.scsi_xri_start = rsrc_start + | |
5561 | lpfc_sli4_get_els_iocb_cnt(phba); | |
5562 | ||
5563 | while (rsrc_id < (rsrc_start + rsrc_size)) { | |
5564 | ids[j] = rsrc_id; | |
5565 | rsrc_id++; | |
5566 | j++; | |
5567 | } | |
5568 | /* Entire word processed. Get next word.*/ | |
5569 | if ((i % 2) == 1) | |
5570 | k++; | |
5571 | } | |
5572 | err_exit: | |
5573 | lpfc_sli4_mbox_cmd_free(phba, mbox); | |
5574 | return rc; | |
5575 | } | |
5576 | ||
5577 | /** | |
5578 | * lpfc_sli4_dealloc_extent - Deallocate an SLI4 resource extent. | |
5579 | * @phba: Pointer to HBA context object. | |
5580 | * @type: the extent's type. | |
5581 | * | |
5582 | * This function deallocates all extents of a particular resource type. | |
5583 | * SLI4 does not allow for deallocating a particular extent range. It | |
5584 | * is the caller's responsibility to release all kernel memory resources. | |
5585 | **/ | |
5586 | static int | |
5587 | lpfc_sli4_dealloc_extent(struct lpfc_hba *phba, uint16_t type) | |
5588 | { | |
5589 | int rc; | |
5590 | uint32_t length, mbox_tmo = 0; | |
5591 | LPFC_MBOXQ_t *mbox; | |
5592 | struct lpfc_mbx_dealloc_rsrc_extents *dealloc_rsrc; | |
5593 | struct lpfc_rsrc_blks *rsrc_blk, *rsrc_blk_next; | |
5594 | ||
5595 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
5596 | if (!mbox) | |
5597 | return -ENOMEM; | |
5598 | ||
5599 | /* | |
5600 | * This function sends an embedded mailbox because it only sends the | |
5601 | * the resource type. All extents of this type are released by the | |
5602 | * port. | |
5603 | */ | |
5604 | length = (sizeof(struct lpfc_mbx_dealloc_rsrc_extents) - | |
5605 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
5606 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
5607 | LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT, | |
5608 | length, LPFC_SLI4_MBX_EMBED); | |
5609 | ||
5610 | /* Send an extents count of 0 - the dealloc doesn't use it. */ | |
5611 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type, | |
5612 | LPFC_SLI4_MBX_EMBED); | |
5613 | if (unlikely(rc)) { | |
5614 | rc = -EIO; | |
5615 | goto out_free_mbox; | |
5616 | } | |
5617 | if (!phba->sli4_hba.intr_enable) | |
5618 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
5619 | else { | |
a183a15f | 5620 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
6d368e53 JS |
5621 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
5622 | } | |
5623 | if (unlikely(rc)) { | |
5624 | rc = -EIO; | |
5625 | goto out_free_mbox; | |
5626 | } | |
5627 | ||
5628 | dealloc_rsrc = &mbox->u.mqe.un.dealloc_rsrc_extents; | |
5629 | if (bf_get(lpfc_mbox_hdr_status, | |
5630 | &dealloc_rsrc->header.cfg_shdr.response)) { | |
5631 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, | |
5632 | "2919 Failed to release resource extents " | |
5633 | "for type %d - Status 0x%x Add'l Status 0x%x. " | |
5634 | "Resource memory not released.\n", | |
5635 | type, | |
5636 | bf_get(lpfc_mbox_hdr_status, | |
5637 | &dealloc_rsrc->header.cfg_shdr.response), | |
5638 | bf_get(lpfc_mbox_hdr_add_status, | |
5639 | &dealloc_rsrc->header.cfg_shdr.response)); | |
5640 | rc = -EIO; | |
5641 | goto out_free_mbox; | |
5642 | } | |
5643 | ||
5644 | /* Release kernel memory resources for the specific type. */ | |
5645 | switch (type) { | |
5646 | case LPFC_RSC_TYPE_FCOE_VPI: | |
5647 | kfree(phba->vpi_bmask); | |
5648 | kfree(phba->vpi_ids); | |
5649 | bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); | |
5650 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, | |
5651 | &phba->lpfc_vpi_blk_list, list) { | |
5652 | list_del_init(&rsrc_blk->list); | |
5653 | kfree(rsrc_blk); | |
5654 | } | |
16a3a208 | 5655 | phba->sli4_hba.max_cfg_param.vpi_used = 0; |
6d368e53 JS |
5656 | break; |
5657 | case LPFC_RSC_TYPE_FCOE_XRI: | |
5658 | kfree(phba->sli4_hba.xri_bmask); | |
5659 | kfree(phba->sli4_hba.xri_ids); | |
6d368e53 JS |
5660 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
5661 | &phba->sli4_hba.lpfc_xri_blk_list, list) { | |
5662 | list_del_init(&rsrc_blk->list); | |
5663 | kfree(rsrc_blk); | |
5664 | } | |
5665 | break; | |
5666 | case LPFC_RSC_TYPE_FCOE_VFI: | |
5667 | kfree(phba->sli4_hba.vfi_bmask); | |
5668 | kfree(phba->sli4_hba.vfi_ids); | |
5669 | bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); | |
5670 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, | |
5671 | &phba->sli4_hba.lpfc_vfi_blk_list, list) { | |
5672 | list_del_init(&rsrc_blk->list); | |
5673 | kfree(rsrc_blk); | |
5674 | } | |
5675 | break; | |
5676 | case LPFC_RSC_TYPE_FCOE_RPI: | |
5677 | /* RPI bitmask and physical id array are cleaned up earlier. */ | |
5678 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, | |
5679 | &phba->sli4_hba.lpfc_rpi_blk_list, list) { | |
5680 | list_del_init(&rsrc_blk->list); | |
5681 | kfree(rsrc_blk); | |
5682 | } | |
5683 | break; | |
5684 | default: | |
5685 | break; | |
5686 | } | |
5687 | ||
5688 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); | |
5689 | ||
5690 | out_free_mbox: | |
5691 | mempool_free(mbox, phba->mbox_mem_pool); | |
5692 | return rc; | |
5693 | } | |
5694 | ||
65791f1f | 5695 | void |
7bdedb34 JS |
5696 | lpfc_set_features(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox, |
5697 | uint32_t feature) | |
65791f1f | 5698 | { |
65791f1f | 5699 | uint32_t len; |
65791f1f | 5700 | |
65791f1f JS |
5701 | len = sizeof(struct lpfc_mbx_set_feature) - |
5702 | sizeof(struct lpfc_sli4_cfg_mhdr); | |
5703 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
5704 | LPFC_MBOX_OPCODE_SET_FEATURES, len, | |
5705 | LPFC_SLI4_MBX_EMBED); | |
7bdedb34 JS |
5706 | |
5707 | switch (feature) { | |
5708 | case LPFC_SET_UE_RECOVERY: | |
5709 | bf_set(lpfc_mbx_set_feature_UER, | |
5710 | &mbox->u.mqe.un.set_feature, 1); | |
5711 | mbox->u.mqe.un.set_feature.feature = LPFC_SET_UE_RECOVERY; | |
5712 | mbox->u.mqe.un.set_feature.param_len = 8; | |
5713 | break; | |
5714 | case LPFC_SET_MDS_DIAGS: | |
5715 | bf_set(lpfc_mbx_set_feature_mds, | |
5716 | &mbox->u.mqe.un.set_feature, 1); | |
5717 | bf_set(lpfc_mbx_set_feature_mds_deep_loopbk, | |
5718 | &mbox->u.mqe.un.set_feature, 0); | |
5719 | mbox->u.mqe.un.set_feature.feature = LPFC_SET_MDS_DIAGS; | |
5720 | mbox->u.mqe.un.set_feature.param_len = 8; | |
5721 | break; | |
65791f1f | 5722 | } |
7bdedb34 JS |
5723 | |
5724 | return; | |
65791f1f JS |
5725 | } |
5726 | ||
6d368e53 JS |
5727 | /** |
5728 | * lpfc_sli4_alloc_resource_identifiers - Allocate all SLI4 resource extents. | |
5729 | * @phba: Pointer to HBA context object. | |
5730 | * | |
5731 | * This function allocates all SLI4 resource identifiers. | |
5732 | **/ | |
5733 | int | |
5734 | lpfc_sli4_alloc_resource_identifiers(struct lpfc_hba *phba) | |
5735 | { | |
5736 | int i, rc, error = 0; | |
5737 | uint16_t count, base; | |
5738 | unsigned long longs; | |
5739 | ||
ff78d8f9 JS |
5740 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
5741 | phba->sli4_hba.next_rpi = phba->sli4_hba.max_cfg_param.max_rpi; | |
6d368e53 JS |
5742 | if (phba->sli4_hba.extents_in_use) { |
5743 | /* | |
5744 | * The port supports resource extents. The XRI, VPI, VFI, RPI | |
5745 | * resource extent count must be read and allocated before | |
5746 | * provisioning the resource id arrays. | |
5747 | */ | |
5748 | if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) == | |
5749 | LPFC_IDX_RSRC_RDY) { | |
5750 | /* | |
5751 | * Extent-based resources are set - the driver could | |
5752 | * be in a port reset. Figure out if any corrective | |
5753 | * actions need to be taken. | |
5754 | */ | |
5755 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, | |
5756 | LPFC_RSC_TYPE_FCOE_VFI); | |
5757 | if (rc != 0) | |
5758 | error++; | |
5759 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, | |
5760 | LPFC_RSC_TYPE_FCOE_VPI); | |
5761 | if (rc != 0) | |
5762 | error++; | |
5763 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, | |
5764 | LPFC_RSC_TYPE_FCOE_XRI); | |
5765 | if (rc != 0) | |
5766 | error++; | |
5767 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, | |
5768 | LPFC_RSC_TYPE_FCOE_RPI); | |
5769 | if (rc != 0) | |
5770 | error++; | |
5771 | ||
5772 | /* | |
5773 | * It's possible that the number of resources | |
5774 | * provided to this port instance changed between | |
5775 | * resets. Detect this condition and reallocate | |
5776 | * resources. Otherwise, there is no action. | |
5777 | */ | |
5778 | if (error) { | |
5779 | lpfc_printf_log(phba, KERN_INFO, | |
5780 | LOG_MBOX | LOG_INIT, | |
5781 | "2931 Detected extent resource " | |
5782 | "change. Reallocating all " | |
5783 | "extents.\n"); | |
5784 | rc = lpfc_sli4_dealloc_extent(phba, | |
5785 | LPFC_RSC_TYPE_FCOE_VFI); | |
5786 | rc = lpfc_sli4_dealloc_extent(phba, | |
5787 | LPFC_RSC_TYPE_FCOE_VPI); | |
5788 | rc = lpfc_sli4_dealloc_extent(phba, | |
5789 | LPFC_RSC_TYPE_FCOE_XRI); | |
5790 | rc = lpfc_sli4_dealloc_extent(phba, | |
5791 | LPFC_RSC_TYPE_FCOE_RPI); | |
5792 | } else | |
5793 | return 0; | |
5794 | } | |
5795 | ||
5796 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI); | |
5797 | if (unlikely(rc)) | |
5798 | goto err_exit; | |
5799 | ||
5800 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI); | |
5801 | if (unlikely(rc)) | |
5802 | goto err_exit; | |
5803 | ||
5804 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI); | |
5805 | if (unlikely(rc)) | |
5806 | goto err_exit; | |
5807 | ||
5808 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI); | |
5809 | if (unlikely(rc)) | |
5810 | goto err_exit; | |
5811 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, | |
5812 | LPFC_IDX_RSRC_RDY); | |
5813 | return rc; | |
5814 | } else { | |
5815 | /* | |
5816 | * The port does not support resource extents. The XRI, VPI, | |
5817 | * VFI, RPI resource ids were determined from READ_CONFIG. | |
5818 | * Just allocate the bitmasks and provision the resource id | |
5819 | * arrays. If a port reset is active, the resources don't | |
5820 | * need any action - just exit. | |
5821 | */ | |
5822 | if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) == | |
ff78d8f9 JS |
5823 | LPFC_IDX_RSRC_RDY) { |
5824 | lpfc_sli4_dealloc_resource_identifiers(phba); | |
5825 | lpfc_sli4_remove_rpis(phba); | |
5826 | } | |
6d368e53 JS |
5827 | /* RPIs. */ |
5828 | count = phba->sli4_hba.max_cfg_param.max_rpi; | |
0a630c27 JS |
5829 | if (count <= 0) { |
5830 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
5831 | "3279 Invalid provisioning of " | |
5832 | "rpi:%d\n", count); | |
5833 | rc = -EINVAL; | |
5834 | goto err_exit; | |
5835 | } | |
6d368e53 JS |
5836 | base = phba->sli4_hba.max_cfg_param.rpi_base; |
5837 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; | |
5838 | phba->sli4_hba.rpi_bmask = kzalloc(longs * | |
5839 | sizeof(unsigned long), | |
5840 | GFP_KERNEL); | |
5841 | if (unlikely(!phba->sli4_hba.rpi_bmask)) { | |
5842 | rc = -ENOMEM; | |
5843 | goto err_exit; | |
5844 | } | |
5845 | phba->sli4_hba.rpi_ids = kzalloc(count * | |
5846 | sizeof(uint16_t), | |
5847 | GFP_KERNEL); | |
5848 | if (unlikely(!phba->sli4_hba.rpi_ids)) { | |
5849 | rc = -ENOMEM; | |
5850 | goto free_rpi_bmask; | |
5851 | } | |
5852 | ||
5853 | for (i = 0; i < count; i++) | |
5854 | phba->sli4_hba.rpi_ids[i] = base + i; | |
5855 | ||
5856 | /* VPIs. */ | |
5857 | count = phba->sli4_hba.max_cfg_param.max_vpi; | |
0a630c27 JS |
5858 | if (count <= 0) { |
5859 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
5860 | "3280 Invalid provisioning of " | |
5861 | "vpi:%d\n", count); | |
5862 | rc = -EINVAL; | |
5863 | goto free_rpi_ids; | |
5864 | } | |
6d368e53 JS |
5865 | base = phba->sli4_hba.max_cfg_param.vpi_base; |
5866 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; | |
5867 | phba->vpi_bmask = kzalloc(longs * | |
5868 | sizeof(unsigned long), | |
5869 | GFP_KERNEL); | |
5870 | if (unlikely(!phba->vpi_bmask)) { | |
5871 | rc = -ENOMEM; | |
5872 | goto free_rpi_ids; | |
5873 | } | |
5874 | phba->vpi_ids = kzalloc(count * | |
5875 | sizeof(uint16_t), | |
5876 | GFP_KERNEL); | |
5877 | if (unlikely(!phba->vpi_ids)) { | |
5878 | rc = -ENOMEM; | |
5879 | goto free_vpi_bmask; | |
5880 | } | |
5881 | ||
5882 | for (i = 0; i < count; i++) | |
5883 | phba->vpi_ids[i] = base + i; | |
5884 | ||
5885 | /* XRIs. */ | |
5886 | count = phba->sli4_hba.max_cfg_param.max_xri; | |
0a630c27 JS |
5887 | if (count <= 0) { |
5888 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
5889 | "3281 Invalid provisioning of " | |
5890 | "xri:%d\n", count); | |
5891 | rc = -EINVAL; | |
5892 | goto free_vpi_ids; | |
5893 | } | |
6d368e53 JS |
5894 | base = phba->sli4_hba.max_cfg_param.xri_base; |
5895 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; | |
5896 | phba->sli4_hba.xri_bmask = kzalloc(longs * | |
5897 | sizeof(unsigned long), | |
5898 | GFP_KERNEL); | |
5899 | if (unlikely(!phba->sli4_hba.xri_bmask)) { | |
5900 | rc = -ENOMEM; | |
5901 | goto free_vpi_ids; | |
5902 | } | |
41899be7 | 5903 | phba->sli4_hba.max_cfg_param.xri_used = 0; |
6d368e53 JS |
5904 | phba->sli4_hba.xri_ids = kzalloc(count * |
5905 | sizeof(uint16_t), | |
5906 | GFP_KERNEL); | |
5907 | if (unlikely(!phba->sli4_hba.xri_ids)) { | |
5908 | rc = -ENOMEM; | |
5909 | goto free_xri_bmask; | |
5910 | } | |
5911 | ||
5912 | for (i = 0; i < count; i++) | |
5913 | phba->sli4_hba.xri_ids[i] = base + i; | |
5914 | ||
5915 | /* VFIs. */ | |
5916 | count = phba->sli4_hba.max_cfg_param.max_vfi; | |
0a630c27 JS |
5917 | if (count <= 0) { |
5918 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
5919 | "3282 Invalid provisioning of " | |
5920 | "vfi:%d\n", count); | |
5921 | rc = -EINVAL; | |
5922 | goto free_xri_ids; | |
5923 | } | |
6d368e53 JS |
5924 | base = phba->sli4_hba.max_cfg_param.vfi_base; |
5925 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; | |
5926 | phba->sli4_hba.vfi_bmask = kzalloc(longs * | |
5927 | sizeof(unsigned long), | |
5928 | GFP_KERNEL); | |
5929 | if (unlikely(!phba->sli4_hba.vfi_bmask)) { | |
5930 | rc = -ENOMEM; | |
5931 | goto free_xri_ids; | |
5932 | } | |
5933 | phba->sli4_hba.vfi_ids = kzalloc(count * | |
5934 | sizeof(uint16_t), | |
5935 | GFP_KERNEL); | |
5936 | if (unlikely(!phba->sli4_hba.vfi_ids)) { | |
5937 | rc = -ENOMEM; | |
5938 | goto free_vfi_bmask; | |
5939 | } | |
5940 | ||
5941 | for (i = 0; i < count; i++) | |
5942 | phba->sli4_hba.vfi_ids[i] = base + i; | |
5943 | ||
5944 | /* | |
5945 | * Mark all resources ready. An HBA reset doesn't need | |
5946 | * to reset the initialization. | |
5947 | */ | |
5948 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, | |
5949 | LPFC_IDX_RSRC_RDY); | |
5950 | return 0; | |
5951 | } | |
5952 | ||
5953 | free_vfi_bmask: | |
5954 | kfree(phba->sli4_hba.vfi_bmask); | |
5955 | free_xri_ids: | |
5956 | kfree(phba->sli4_hba.xri_ids); | |
5957 | free_xri_bmask: | |
5958 | kfree(phba->sli4_hba.xri_bmask); | |
5959 | free_vpi_ids: | |
5960 | kfree(phba->vpi_ids); | |
5961 | free_vpi_bmask: | |
5962 | kfree(phba->vpi_bmask); | |
5963 | free_rpi_ids: | |
5964 | kfree(phba->sli4_hba.rpi_ids); | |
5965 | free_rpi_bmask: | |
5966 | kfree(phba->sli4_hba.rpi_bmask); | |
5967 | err_exit: | |
5968 | return rc; | |
5969 | } | |
5970 | ||
5971 | /** | |
5972 | * lpfc_sli4_dealloc_resource_identifiers - Deallocate all SLI4 resource extents. | |
5973 | * @phba: Pointer to HBA context object. | |
5974 | * | |
5975 | * This function allocates the number of elements for the specified | |
5976 | * resource type. | |
5977 | **/ | |
5978 | int | |
5979 | lpfc_sli4_dealloc_resource_identifiers(struct lpfc_hba *phba) | |
5980 | { | |
5981 | if (phba->sli4_hba.extents_in_use) { | |
5982 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI); | |
5983 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI); | |
5984 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI); | |
5985 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI); | |
5986 | } else { | |
5987 | kfree(phba->vpi_bmask); | |
16a3a208 | 5988 | phba->sli4_hba.max_cfg_param.vpi_used = 0; |
6d368e53 JS |
5989 | kfree(phba->vpi_ids); |
5990 | bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); | |
5991 | kfree(phba->sli4_hba.xri_bmask); | |
5992 | kfree(phba->sli4_hba.xri_ids); | |
6d368e53 JS |
5993 | kfree(phba->sli4_hba.vfi_bmask); |
5994 | kfree(phba->sli4_hba.vfi_ids); | |
5995 | bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); | |
5996 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); | |
5997 | } | |
5998 | ||
5999 | return 0; | |
6000 | } | |
6001 | ||
b76f2dc9 JS |
6002 | /** |
6003 | * lpfc_sli4_get_allocated_extnts - Get the port's allocated extents. | |
6004 | * @phba: Pointer to HBA context object. | |
6005 | * @type: The resource extent type. | |
6006 | * @extnt_count: buffer to hold port extent count response | |
6007 | * @extnt_size: buffer to hold port extent size response. | |
6008 | * | |
6009 | * This function calls the port to read the host allocated extents | |
6010 | * for a particular type. | |
6011 | **/ | |
6012 | int | |
6013 | lpfc_sli4_get_allocated_extnts(struct lpfc_hba *phba, uint16_t type, | |
6014 | uint16_t *extnt_cnt, uint16_t *extnt_size) | |
6015 | { | |
6016 | bool emb; | |
6017 | int rc = 0; | |
6018 | uint16_t curr_blks = 0; | |
6019 | uint32_t req_len, emb_len; | |
6020 | uint32_t alloc_len, mbox_tmo; | |
6021 | struct list_head *blk_list_head; | |
6022 | struct lpfc_rsrc_blks *rsrc_blk; | |
6023 | LPFC_MBOXQ_t *mbox; | |
6024 | void *virtaddr = NULL; | |
6025 | struct lpfc_mbx_nembed_rsrc_extent *n_rsrc; | |
6026 | struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext; | |
6027 | union lpfc_sli4_cfg_shdr *shdr; | |
6028 | ||
6029 | switch (type) { | |
6030 | case LPFC_RSC_TYPE_FCOE_VPI: | |
6031 | blk_list_head = &phba->lpfc_vpi_blk_list; | |
6032 | break; | |
6033 | case LPFC_RSC_TYPE_FCOE_XRI: | |
6034 | blk_list_head = &phba->sli4_hba.lpfc_xri_blk_list; | |
6035 | break; | |
6036 | case LPFC_RSC_TYPE_FCOE_VFI: | |
6037 | blk_list_head = &phba->sli4_hba.lpfc_vfi_blk_list; | |
6038 | break; | |
6039 | case LPFC_RSC_TYPE_FCOE_RPI: | |
6040 | blk_list_head = &phba->sli4_hba.lpfc_rpi_blk_list; | |
6041 | break; | |
6042 | default: | |
6043 | return -EIO; | |
6044 | } | |
6045 | ||
6046 | /* Count the number of extents currently allocatd for this type. */ | |
6047 | list_for_each_entry(rsrc_blk, blk_list_head, list) { | |
6048 | if (curr_blks == 0) { | |
6049 | /* | |
6050 | * The GET_ALLOCATED mailbox does not return the size, | |
6051 | * just the count. The size should be just the size | |
6052 | * stored in the current allocated block and all sizes | |
6053 | * for an extent type are the same so set the return | |
6054 | * value now. | |
6055 | */ | |
6056 | *extnt_size = rsrc_blk->rsrc_size; | |
6057 | } | |
6058 | curr_blks++; | |
6059 | } | |
6060 | ||
b76f2dc9 JS |
6061 | /* |
6062 | * Calculate the size of an embedded mailbox. The uint32_t | |
6063 | * accounts for extents-specific word. | |
6064 | */ | |
6065 | emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) - | |
6066 | sizeof(uint32_t); | |
6067 | ||
6068 | /* | |
6069 | * Presume the allocation and response will fit into an embedded | |
6070 | * mailbox. If not true, reconfigure to a non-embedded mailbox. | |
6071 | */ | |
6072 | emb = LPFC_SLI4_MBX_EMBED; | |
6073 | req_len = emb_len; | |
6074 | if (req_len > emb_len) { | |
6075 | req_len = curr_blks * sizeof(uint16_t) + | |
6076 | sizeof(union lpfc_sli4_cfg_shdr) + | |
6077 | sizeof(uint32_t); | |
6078 | emb = LPFC_SLI4_MBX_NEMBED; | |
6079 | } | |
6080 | ||
6081 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
6082 | if (!mbox) | |
6083 | return -ENOMEM; | |
6084 | memset(mbox, 0, sizeof(LPFC_MBOXQ_t)); | |
6085 | ||
6086 | alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
6087 | LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT, | |
6088 | req_len, emb); | |
6089 | if (alloc_len < req_len) { | |
6090 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6091 | "2983 Allocated DMA memory size (x%x) is " | |
6092 | "less than the requested DMA memory " | |
6093 | "size (x%x)\n", alloc_len, req_len); | |
6094 | rc = -ENOMEM; | |
6095 | goto err_exit; | |
6096 | } | |
6097 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, curr_blks, type, emb); | |
6098 | if (unlikely(rc)) { | |
6099 | rc = -EIO; | |
6100 | goto err_exit; | |
6101 | } | |
6102 | ||
6103 | if (!phba->sli4_hba.intr_enable) | |
6104 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
6105 | else { | |
a183a15f | 6106 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
b76f2dc9 JS |
6107 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
6108 | } | |
6109 | ||
6110 | if (unlikely(rc)) { | |
6111 | rc = -EIO; | |
6112 | goto err_exit; | |
6113 | } | |
6114 | ||
6115 | /* | |
6116 | * Figure out where the response is located. Then get local pointers | |
6117 | * to the response data. The port does not guarantee to respond to | |
6118 | * all extents counts request so update the local variable with the | |
6119 | * allocated count from the port. | |
6120 | */ | |
6121 | if (emb == LPFC_SLI4_MBX_EMBED) { | |
6122 | rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents; | |
6123 | shdr = &rsrc_ext->header.cfg_shdr; | |
6124 | *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp); | |
6125 | } else { | |
6126 | virtaddr = mbox->sge_array->addr[0]; | |
6127 | n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr; | |
6128 | shdr = &n_rsrc->cfg_shdr; | |
6129 | *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc); | |
6130 | } | |
6131 | ||
6132 | if (bf_get(lpfc_mbox_hdr_status, &shdr->response)) { | |
6133 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, | |
6134 | "2984 Failed to read allocated resources " | |
6135 | "for type %d - Status 0x%x Add'l Status 0x%x.\n", | |
6136 | type, | |
6137 | bf_get(lpfc_mbox_hdr_status, &shdr->response), | |
6138 | bf_get(lpfc_mbox_hdr_add_status, &shdr->response)); | |
6139 | rc = -EIO; | |
6140 | goto err_exit; | |
6141 | } | |
6142 | err_exit: | |
6143 | lpfc_sli4_mbox_cmd_free(phba, mbox); | |
6144 | return rc; | |
6145 | } | |
6146 | ||
8a9d2e80 JS |
6147 | /** |
6148 | * lpfc_sli4_repost_els_sgl_list - Repsot the els buffers sgl pages as block | |
6149 | * @phba: pointer to lpfc hba data structure. | |
6150 | * | |
6151 | * This routine walks the list of els buffers that have been allocated and | |
6152 | * repost them to the port by using SGL block post. This is needed after a | |
6153 | * pci_function_reset/warm_start or start. It attempts to construct blocks | |
6154 | * of els buffer sgls which contains contiguous xris and uses the non-embedded | |
6155 | * SGL block post mailbox commands to post them to the port. For single els | |
6156 | * buffer sgl with non-contiguous xri, if any, it shall use embedded SGL post | |
6157 | * mailbox command for posting. | |
6158 | * | |
6159 | * Returns: 0 = success, non-zero failure. | |
6160 | **/ | |
6161 | static int | |
6162 | lpfc_sli4_repost_els_sgl_list(struct lpfc_hba *phba) | |
6163 | { | |
6164 | struct lpfc_sglq *sglq_entry = NULL; | |
6165 | struct lpfc_sglq *sglq_entry_next = NULL; | |
6166 | struct lpfc_sglq *sglq_entry_first = NULL; | |
711ea882 | 6167 | int status, total_cnt, post_cnt = 0, num_posted = 0, block_cnt = 0; |
8a9d2e80 | 6168 | int last_xritag = NO_XRI; |
dafe8cea | 6169 | struct lpfc_sli_ring *pring; |
8a9d2e80 JS |
6170 | LIST_HEAD(prep_sgl_list); |
6171 | LIST_HEAD(blck_sgl_list); | |
6172 | LIST_HEAD(allc_sgl_list); | |
6173 | LIST_HEAD(post_sgl_list); | |
6174 | LIST_HEAD(free_sgl_list); | |
6175 | ||
dafe8cea | 6176 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
38c20673 | 6177 | spin_lock_irq(&phba->hbalock); |
dafe8cea | 6178 | spin_lock(&pring->ring_lock); |
8a9d2e80 | 6179 | list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &allc_sgl_list); |
dafe8cea | 6180 | spin_unlock(&pring->ring_lock); |
38c20673 | 6181 | spin_unlock_irq(&phba->hbalock); |
8a9d2e80 | 6182 | |
711ea882 | 6183 | total_cnt = phba->sli4_hba.els_xri_cnt; |
8a9d2e80 JS |
6184 | list_for_each_entry_safe(sglq_entry, sglq_entry_next, |
6185 | &allc_sgl_list, list) { | |
6186 | list_del_init(&sglq_entry->list); | |
6187 | block_cnt++; | |
6188 | if ((last_xritag != NO_XRI) && | |
6189 | (sglq_entry->sli4_xritag != last_xritag + 1)) { | |
6190 | /* a hole in xri block, form a sgl posting block */ | |
6191 | list_splice_init(&prep_sgl_list, &blck_sgl_list); | |
6192 | post_cnt = block_cnt - 1; | |
6193 | /* prepare list for next posting block */ | |
6194 | list_add_tail(&sglq_entry->list, &prep_sgl_list); | |
6195 | block_cnt = 1; | |
6196 | } else { | |
6197 | /* prepare list for next posting block */ | |
6198 | list_add_tail(&sglq_entry->list, &prep_sgl_list); | |
6199 | /* enough sgls for non-embed sgl mbox command */ | |
6200 | if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) { | |
6201 | list_splice_init(&prep_sgl_list, | |
6202 | &blck_sgl_list); | |
6203 | post_cnt = block_cnt; | |
6204 | block_cnt = 0; | |
6205 | } | |
6206 | } | |
6207 | num_posted++; | |
6208 | ||
6209 | /* keep track of last sgl's xritag */ | |
6210 | last_xritag = sglq_entry->sli4_xritag; | |
6211 | ||
6212 | /* end of repost sgl list condition for els buffers */ | |
6213 | if (num_posted == phba->sli4_hba.els_xri_cnt) { | |
6214 | if (post_cnt == 0) { | |
6215 | list_splice_init(&prep_sgl_list, | |
6216 | &blck_sgl_list); | |
6217 | post_cnt = block_cnt; | |
6218 | } else if (block_cnt == 1) { | |
6219 | status = lpfc_sli4_post_sgl(phba, | |
6220 | sglq_entry->phys, 0, | |
6221 | sglq_entry->sli4_xritag); | |
6222 | if (!status) { | |
6223 | /* successful, put sgl to posted list */ | |
6224 | list_add_tail(&sglq_entry->list, | |
6225 | &post_sgl_list); | |
6226 | } else { | |
6227 | /* Failure, put sgl to free list */ | |
6228 | lpfc_printf_log(phba, KERN_WARNING, | |
6229 | LOG_SLI, | |
6230 | "3159 Failed to post els " | |
6231 | "sgl, xritag:x%x\n", | |
6232 | sglq_entry->sli4_xritag); | |
6233 | list_add_tail(&sglq_entry->list, | |
6234 | &free_sgl_list); | |
711ea882 | 6235 | total_cnt--; |
8a9d2e80 JS |
6236 | } |
6237 | } | |
6238 | } | |
6239 | ||
6240 | /* continue until a nembed page worth of sgls */ | |
6241 | if (post_cnt == 0) | |
6242 | continue; | |
6243 | ||
6244 | /* post the els buffer list sgls as a block */ | |
6245 | status = lpfc_sli4_post_els_sgl_list(phba, &blck_sgl_list, | |
6246 | post_cnt); | |
6247 | ||
6248 | if (!status) { | |
6249 | /* success, put sgl list to posted sgl list */ | |
6250 | list_splice_init(&blck_sgl_list, &post_sgl_list); | |
6251 | } else { | |
6252 | /* Failure, put sgl list to free sgl list */ | |
6253 | sglq_entry_first = list_first_entry(&blck_sgl_list, | |
6254 | struct lpfc_sglq, | |
6255 | list); | |
6256 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
6257 | "3160 Failed to post els sgl-list, " | |
6258 | "xritag:x%x-x%x\n", | |
6259 | sglq_entry_first->sli4_xritag, | |
6260 | (sglq_entry_first->sli4_xritag + | |
6261 | post_cnt - 1)); | |
6262 | list_splice_init(&blck_sgl_list, &free_sgl_list); | |
711ea882 | 6263 | total_cnt -= post_cnt; |
8a9d2e80 JS |
6264 | } |
6265 | ||
6266 | /* don't reset xirtag due to hole in xri block */ | |
6267 | if (block_cnt == 0) | |
6268 | last_xritag = NO_XRI; | |
6269 | ||
6270 | /* reset els sgl post count for next round of posting */ | |
6271 | post_cnt = 0; | |
6272 | } | |
711ea882 JS |
6273 | /* update the number of XRIs posted for ELS */ |
6274 | phba->sli4_hba.els_xri_cnt = total_cnt; | |
8a9d2e80 JS |
6275 | |
6276 | /* free the els sgls failed to post */ | |
6277 | lpfc_free_sgl_list(phba, &free_sgl_list); | |
6278 | ||
6279 | /* push els sgls posted to the availble list */ | |
6280 | if (!list_empty(&post_sgl_list)) { | |
38c20673 | 6281 | spin_lock_irq(&phba->hbalock); |
dafe8cea | 6282 | spin_lock(&pring->ring_lock); |
8a9d2e80 JS |
6283 | list_splice_init(&post_sgl_list, |
6284 | &phba->sli4_hba.lpfc_sgl_list); | |
dafe8cea | 6285 | spin_unlock(&pring->ring_lock); |
38c20673 | 6286 | spin_unlock_irq(&phba->hbalock); |
8a9d2e80 JS |
6287 | } else { |
6288 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
6289 | "3161 Failure to post els sgl to port.\n"); | |
6290 | return -EIO; | |
6291 | } | |
6292 | return 0; | |
6293 | } | |
6294 | ||
da0436e9 JS |
6295 | /** |
6296 | * lpfc_sli4_hba_setup - SLI4 device intialization PCI function | |
6297 | * @phba: Pointer to HBA context object. | |
6298 | * | |
6299 | * This function is the main SLI4 device intialization PCI function. This | |
6300 | * function is called by the HBA intialization code, HBA reset code and | |
6301 | * HBA error attention handler code. Caller is not required to hold any | |
6302 | * locks. | |
6303 | **/ | |
6304 | int | |
6305 | lpfc_sli4_hba_setup(struct lpfc_hba *phba) | |
6306 | { | |
6307 | int rc; | |
6308 | LPFC_MBOXQ_t *mboxq; | |
6309 | struct lpfc_mqe *mqe; | |
6310 | uint8_t *vpd; | |
6311 | uint32_t vpd_size; | |
6312 | uint32_t ftr_rsp = 0; | |
6313 | struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport); | |
6314 | struct lpfc_vport *vport = phba->pport; | |
6315 | struct lpfc_dmabuf *mp; | |
6316 | ||
6317 | /* Perform a PCI function reset to start from clean */ | |
6318 | rc = lpfc_pci_function_reset(phba); | |
6319 | if (unlikely(rc)) | |
6320 | return -ENODEV; | |
6321 | ||
6322 | /* Check the HBA Host Status Register for readyness */ | |
6323 | rc = lpfc_sli4_post_status_check(phba); | |
6324 | if (unlikely(rc)) | |
6325 | return -ENODEV; | |
6326 | else { | |
6327 | spin_lock_irq(&phba->hbalock); | |
6328 | phba->sli.sli_flag |= LPFC_SLI_ACTIVE; | |
6329 | spin_unlock_irq(&phba->hbalock); | |
6330 | } | |
6331 | ||
6332 | /* | |
6333 | * Allocate a single mailbox container for initializing the | |
6334 | * port. | |
6335 | */ | |
6336 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
6337 | if (!mboxq) | |
6338 | return -ENOMEM; | |
6339 | ||
da0436e9 | 6340 | /* Issue READ_REV to collect vpd and FW information. */ |
49198b37 | 6341 | vpd_size = SLI4_PAGE_SIZE; |
da0436e9 JS |
6342 | vpd = kzalloc(vpd_size, GFP_KERNEL); |
6343 | if (!vpd) { | |
6344 | rc = -ENOMEM; | |
6345 | goto out_free_mbox; | |
6346 | } | |
6347 | ||
6348 | rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size); | |
76a95d75 JS |
6349 | if (unlikely(rc)) { |
6350 | kfree(vpd); | |
6351 | goto out_free_mbox; | |
6352 | } | |
572709e2 | 6353 | |
da0436e9 | 6354 | mqe = &mboxq->u.mqe; |
f1126688 | 6355 | phba->sli_rev = bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev); |
b5c53958 | 6356 | if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev)) { |
76a95d75 | 6357 | phba->hba_flag |= HBA_FCOE_MODE; |
b5c53958 JS |
6358 | phba->fcp_embed_io = 0; /* SLI4 FC support only */ |
6359 | } else { | |
76a95d75 | 6360 | phba->hba_flag &= ~HBA_FCOE_MODE; |
b5c53958 | 6361 | } |
45ed1190 JS |
6362 | |
6363 | if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) == | |
6364 | LPFC_DCBX_CEE_MODE) | |
6365 | phba->hba_flag |= HBA_FIP_SUPPORT; | |
6366 | else | |
6367 | phba->hba_flag &= ~HBA_FIP_SUPPORT; | |
6368 | ||
4f2e66c6 JS |
6369 | phba->hba_flag &= ~HBA_FCP_IOQ_FLUSH; |
6370 | ||
c31098ce | 6371 | if (phba->sli_rev != LPFC_SLI_REV4) { |
da0436e9 JS |
6372 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
6373 | "0376 READ_REV Error. SLI Level %d " | |
6374 | "FCoE enabled %d\n", | |
76a95d75 | 6375 | phba->sli_rev, phba->hba_flag & HBA_FCOE_MODE); |
da0436e9 | 6376 | rc = -EIO; |
76a95d75 JS |
6377 | kfree(vpd); |
6378 | goto out_free_mbox; | |
da0436e9 | 6379 | } |
cd1c8301 | 6380 | |
ff78d8f9 JS |
6381 | /* |
6382 | * Continue initialization with default values even if driver failed | |
6383 | * to read FCoE param config regions, only read parameters if the | |
6384 | * board is FCoE | |
6385 | */ | |
6386 | if (phba->hba_flag & HBA_FCOE_MODE && | |
6387 | lpfc_sli4_read_fcoe_params(phba)) | |
6388 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_INIT, | |
6389 | "2570 Failed to read FCoE parameters\n"); | |
6390 | ||
cd1c8301 JS |
6391 | /* |
6392 | * Retrieve sli4 device physical port name, failure of doing it | |
6393 | * is considered as non-fatal. | |
6394 | */ | |
6395 | rc = lpfc_sli4_retrieve_pport_name(phba); | |
6396 | if (!rc) | |
6397 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, | |
6398 | "3080 Successful retrieving SLI4 device " | |
6399 | "physical port name: %s.\n", phba->Port); | |
6400 | ||
da0436e9 JS |
6401 | /* |
6402 | * Evaluate the read rev and vpd data. Populate the driver | |
6403 | * state with the results. If this routine fails, the failure | |
6404 | * is not fatal as the driver will use generic values. | |
6405 | */ | |
6406 | rc = lpfc_parse_vpd(phba, vpd, vpd_size); | |
6407 | if (unlikely(!rc)) { | |
6408 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
6409 | "0377 Error %d parsing vpd. " | |
6410 | "Using defaults.\n", rc); | |
6411 | rc = 0; | |
6412 | } | |
76a95d75 | 6413 | kfree(vpd); |
da0436e9 | 6414 | |
f1126688 JS |
6415 | /* Save information as VPD data */ |
6416 | phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev; | |
6417 | phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev; | |
6418 | phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev; | |
6419 | phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high, | |
6420 | &mqe->un.read_rev); | |
6421 | phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low, | |
6422 | &mqe->un.read_rev); | |
6423 | phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high, | |
6424 | &mqe->un.read_rev); | |
6425 | phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low, | |
6426 | &mqe->un.read_rev); | |
6427 | phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev; | |
6428 | memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16); | |
6429 | phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev; | |
6430 | memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16); | |
6431 | phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev; | |
6432 | memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16); | |
6433 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, | |
6434 | "(%d):0380 READ_REV Status x%x " | |
6435 | "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n", | |
6436 | mboxq->vport ? mboxq->vport->vpi : 0, | |
6437 | bf_get(lpfc_mqe_status, mqe), | |
6438 | phba->vpd.rev.opFwName, | |
6439 | phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow, | |
6440 | phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow); | |
da0436e9 | 6441 | |
572709e2 JS |
6442 | /* Reset the DFT_LUN_Q_DEPTH to (max xri >> 3) */ |
6443 | rc = (phba->sli4_hba.max_cfg_param.max_xri >> 3); | |
6444 | if (phba->pport->cfg_lun_queue_depth > rc) { | |
6445 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
6446 | "3362 LUN queue depth changed from %d to %d\n", | |
6447 | phba->pport->cfg_lun_queue_depth, rc); | |
6448 | phba->pport->cfg_lun_queue_depth = rc; | |
6449 | } | |
6450 | ||
65791f1f | 6451 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
7bdedb34 JS |
6452 | LPFC_SLI_INTF_IF_TYPE_0) { |
6453 | lpfc_set_features(phba, mboxq, LPFC_SET_UE_RECOVERY); | |
6454 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
6455 | if (rc == MBX_SUCCESS) { | |
6456 | phba->hba_flag |= HBA_RECOVERABLE_UE; | |
6457 | /* Set 1Sec interval to detect UE */ | |
6458 | phba->eratt_poll_interval = 1; | |
6459 | phba->sli4_hba.ue_to_sr = bf_get( | |
6460 | lpfc_mbx_set_feature_UESR, | |
6461 | &mboxq->u.mqe.un.set_feature); | |
6462 | phba->sli4_hba.ue_to_rp = bf_get( | |
6463 | lpfc_mbx_set_feature_UERP, | |
6464 | &mboxq->u.mqe.un.set_feature); | |
6465 | } | |
6466 | } | |
6467 | ||
6468 | if (phba->cfg_enable_mds_diags && phba->mds_diags_support) { | |
6469 | /* Enable MDS Diagnostics only if the SLI Port supports it */ | |
6470 | lpfc_set_features(phba, mboxq, LPFC_SET_MDS_DIAGS); | |
6471 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
6472 | if (rc != MBX_SUCCESS) | |
6473 | phba->mds_diags_support = 0; | |
6474 | } | |
572709e2 | 6475 | |
da0436e9 JS |
6476 | /* |
6477 | * Discover the port's supported feature set and match it against the | |
6478 | * hosts requests. | |
6479 | */ | |
6480 | lpfc_request_features(phba, mboxq); | |
6481 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
6482 | if (unlikely(rc)) { | |
6483 | rc = -EIO; | |
76a95d75 | 6484 | goto out_free_mbox; |
da0436e9 JS |
6485 | } |
6486 | ||
6487 | /* | |
6488 | * The port must support FCP initiator mode as this is the | |
6489 | * only mode running in the host. | |
6490 | */ | |
6491 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) { | |
6492 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, | |
6493 | "0378 No support for fcpi mode.\n"); | |
6494 | ftr_rsp++; | |
6495 | } | |
fedd3b7b JS |
6496 | if (bf_get(lpfc_mbx_rq_ftr_rsp_perfh, &mqe->un.req_ftrs)) |
6497 | phba->sli3_options |= LPFC_SLI4_PERFH_ENABLED; | |
6498 | else | |
6499 | phba->sli3_options &= ~LPFC_SLI4_PERFH_ENABLED; | |
da0436e9 JS |
6500 | /* |
6501 | * If the port cannot support the host's requested features | |
6502 | * then turn off the global config parameters to disable the | |
6503 | * feature in the driver. This is not a fatal error. | |
6504 | */ | |
bf08611b JS |
6505 | phba->sli3_options &= ~LPFC_SLI3_BG_ENABLED; |
6506 | if (phba->cfg_enable_bg) { | |
6507 | if (bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)) | |
6508 | phba->sli3_options |= LPFC_SLI3_BG_ENABLED; | |
6509 | else | |
6510 | ftr_rsp++; | |
6511 | } | |
da0436e9 JS |
6512 | |
6513 | if (phba->max_vpi && phba->cfg_enable_npiv && | |
6514 | !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs))) | |
6515 | ftr_rsp++; | |
6516 | ||
6517 | if (ftr_rsp) { | |
6518 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, | |
6519 | "0379 Feature Mismatch Data: x%08x %08x " | |
6520 | "x%x x%x x%x\n", mqe->un.req_ftrs.word2, | |
6521 | mqe->un.req_ftrs.word3, phba->cfg_enable_bg, | |
6522 | phba->cfg_enable_npiv, phba->max_vpi); | |
6523 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))) | |
6524 | phba->cfg_enable_bg = 0; | |
6525 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs))) | |
6526 | phba->cfg_enable_npiv = 0; | |
6527 | } | |
6528 | ||
6529 | /* These SLI3 features are assumed in SLI4 */ | |
6530 | spin_lock_irq(&phba->hbalock); | |
6531 | phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED); | |
6532 | spin_unlock_irq(&phba->hbalock); | |
6533 | ||
6d368e53 JS |
6534 | /* |
6535 | * Allocate all resources (xri,rpi,vpi,vfi) now. Subsequent | |
6536 | * calls depends on these resources to complete port setup. | |
6537 | */ | |
6538 | rc = lpfc_sli4_alloc_resource_identifiers(phba); | |
6539 | if (rc) { | |
6540 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
6541 | "2920 Failed to alloc Resource IDs " | |
6542 | "rc = x%x\n", rc); | |
6543 | goto out_free_mbox; | |
6544 | } | |
6545 | ||
da0436e9 | 6546 | /* Read the port's service parameters. */ |
9f1177a3 JS |
6547 | rc = lpfc_read_sparam(phba, mboxq, vport->vpi); |
6548 | if (rc) { | |
6549 | phba->link_state = LPFC_HBA_ERROR; | |
6550 | rc = -ENOMEM; | |
76a95d75 | 6551 | goto out_free_mbox; |
9f1177a3 JS |
6552 | } |
6553 | ||
da0436e9 JS |
6554 | mboxq->vport = vport; |
6555 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
6556 | mp = (struct lpfc_dmabuf *) mboxq->context1; | |
6557 | if (rc == MBX_SUCCESS) { | |
6558 | memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm)); | |
6559 | rc = 0; | |
6560 | } | |
6561 | ||
6562 | /* | |
6563 | * This memory was allocated by the lpfc_read_sparam routine. Release | |
6564 | * it to the mbuf pool. | |
6565 | */ | |
6566 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
6567 | kfree(mp); | |
6568 | mboxq->context1 = NULL; | |
6569 | if (unlikely(rc)) { | |
6570 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
6571 | "0382 READ_SPARAM command failed " | |
6572 | "status %d, mbxStatus x%x\n", | |
6573 | rc, bf_get(lpfc_mqe_status, mqe)); | |
6574 | phba->link_state = LPFC_HBA_ERROR; | |
6575 | rc = -EIO; | |
76a95d75 | 6576 | goto out_free_mbox; |
da0436e9 JS |
6577 | } |
6578 | ||
0558056c | 6579 | lpfc_update_vport_wwn(vport); |
da0436e9 JS |
6580 | |
6581 | /* Update the fc_host data structures with new wwn. */ | |
6582 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); | |
6583 | fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn); | |
6584 | ||
8a9d2e80 JS |
6585 | /* update host els and scsi xri-sgl sizes and mappings */ |
6586 | rc = lpfc_sli4_xri_sgl_update(phba); | |
6587 | if (unlikely(rc)) { | |
6588 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
6589 | "1400 Failed to update xri-sgl size and " | |
6590 | "mapping: %d\n", rc); | |
6591 | goto out_free_mbox; | |
da0436e9 JS |
6592 | } |
6593 | ||
8a9d2e80 JS |
6594 | /* register the els sgl pool to the port */ |
6595 | rc = lpfc_sli4_repost_els_sgl_list(phba); | |
6596 | if (unlikely(rc)) { | |
6597 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
6598 | "0582 Error %d during els sgl post " | |
6599 | "operation\n", rc); | |
6600 | rc = -ENODEV; | |
6601 | goto out_free_mbox; | |
6602 | } | |
6603 | ||
6604 | /* register the allocated scsi sgl pool to the port */ | |
da0436e9 JS |
6605 | rc = lpfc_sli4_repost_scsi_sgl_list(phba); |
6606 | if (unlikely(rc)) { | |
6d368e53 | 6607 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
6a9c52cf JS |
6608 | "0383 Error %d during scsi sgl post " |
6609 | "operation\n", rc); | |
da0436e9 JS |
6610 | /* Some Scsi buffers were moved to the abort scsi list */ |
6611 | /* A pci function reset will repost them */ | |
6612 | rc = -ENODEV; | |
76a95d75 | 6613 | goto out_free_mbox; |
da0436e9 JS |
6614 | } |
6615 | ||
6616 | /* Post the rpi header region to the device. */ | |
6617 | rc = lpfc_sli4_post_all_rpi_hdrs(phba); | |
6618 | if (unlikely(rc)) { | |
6619 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
6620 | "0393 Error %d during rpi post operation\n", | |
6621 | rc); | |
6622 | rc = -ENODEV; | |
76a95d75 | 6623 | goto out_free_mbox; |
da0436e9 | 6624 | } |
97f2ecf1 | 6625 | lpfc_sli4_node_prep(phba); |
da0436e9 | 6626 | |
5350d872 JS |
6627 | /* Create all the SLI4 queues */ |
6628 | rc = lpfc_sli4_queue_create(phba); | |
6629 | if (rc) { | |
6630 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6631 | "3089 Failed to allocate queues\n"); | |
6632 | rc = -ENODEV; | |
6633 | goto out_stop_timers; | |
6634 | } | |
da0436e9 JS |
6635 | /* Set up all the queues to the device */ |
6636 | rc = lpfc_sli4_queue_setup(phba); | |
6637 | if (unlikely(rc)) { | |
6638 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
6639 | "0381 Error %d during queue setup.\n ", rc); | |
5350d872 | 6640 | goto out_destroy_queue; |
da0436e9 JS |
6641 | } |
6642 | ||
6643 | /* Arm the CQs and then EQs on device */ | |
6644 | lpfc_sli4_arm_cqeq_intr(phba); | |
6645 | ||
6646 | /* Indicate device interrupt mode */ | |
6647 | phba->sli4_hba.intr_enable = 1; | |
6648 | ||
6649 | /* Allow asynchronous mailbox command to go through */ | |
6650 | spin_lock_irq(&phba->hbalock); | |
6651 | phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; | |
6652 | spin_unlock_irq(&phba->hbalock); | |
6653 | ||
6654 | /* Post receive buffers to the device */ | |
6655 | lpfc_sli4_rb_setup(phba); | |
6656 | ||
fc2b989b JS |
6657 | /* Reset HBA FCF states after HBA reset */ |
6658 | phba->fcf.fcf_flag = 0; | |
6659 | phba->fcf.current_rec.flag = 0; | |
6660 | ||
da0436e9 | 6661 | /* Start the ELS watchdog timer */ |
8fa38513 | 6662 | mod_timer(&vport->els_tmofunc, |
256ec0d0 | 6663 | jiffies + msecs_to_jiffies(1000 * (phba->fc_ratov * 2))); |
da0436e9 JS |
6664 | |
6665 | /* Start heart beat timer */ | |
6666 | mod_timer(&phba->hb_tmofunc, | |
256ec0d0 | 6667 | jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL)); |
da0436e9 JS |
6668 | phba->hb_outstanding = 0; |
6669 | phba->last_completion_time = jiffies; | |
6670 | ||
6671 | /* Start error attention (ERATT) polling timer */ | |
256ec0d0 | 6672 | mod_timer(&phba->eratt_poll, |
65791f1f | 6673 | jiffies + msecs_to_jiffies(1000 * phba->eratt_poll_interval)); |
da0436e9 | 6674 | |
75baf696 JS |
6675 | /* Enable PCIe device Advanced Error Reporting (AER) if configured */ |
6676 | if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) { | |
6677 | rc = pci_enable_pcie_error_reporting(phba->pcidev); | |
6678 | if (!rc) { | |
6679 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
6680 | "2829 This device supports " | |
6681 | "Advanced Error Reporting (AER)\n"); | |
6682 | spin_lock_irq(&phba->hbalock); | |
6683 | phba->hba_flag |= HBA_AER_ENABLED; | |
6684 | spin_unlock_irq(&phba->hbalock); | |
6685 | } else { | |
6686 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
6687 | "2830 This device does not support " | |
6688 | "Advanced Error Reporting (AER)\n"); | |
6689 | phba->cfg_aer_support = 0; | |
6690 | } | |
0a96e975 | 6691 | rc = 0; |
75baf696 JS |
6692 | } |
6693 | ||
76a95d75 JS |
6694 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { |
6695 | /* | |
6696 | * The FC Port needs to register FCFI (index 0) | |
6697 | */ | |
6698 | lpfc_reg_fcfi(phba, mboxq); | |
6699 | mboxq->vport = phba->pport; | |
6700 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
9589b062 | 6701 | if (rc != MBX_SUCCESS) |
76a95d75 | 6702 | goto out_unset_queue; |
9589b062 JS |
6703 | rc = 0; |
6704 | phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, | |
6705 | &mboxq->u.mqe.un.reg_fcfi); | |
026abb87 JS |
6706 | |
6707 | /* Check if the port is configured to be disabled */ | |
6708 | lpfc_sli_read_link_ste(phba); | |
76a95d75 | 6709 | } |
026abb87 | 6710 | |
da0436e9 JS |
6711 | /* |
6712 | * The port is ready, set the host's link state to LINK_DOWN | |
6713 | * in preparation for link interrupts. | |
6714 | */ | |
da0436e9 JS |
6715 | spin_lock_irq(&phba->hbalock); |
6716 | phba->link_state = LPFC_LINK_DOWN; | |
6717 | spin_unlock_irq(&phba->hbalock); | |
026abb87 JS |
6718 | if (!(phba->hba_flag & HBA_FCOE_MODE) && |
6719 | (phba->hba_flag & LINK_DISABLED)) { | |
6720 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI, | |
6721 | "3103 Adapter Link is disabled.\n"); | |
6722 | lpfc_down_link(phba, mboxq); | |
6723 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
6724 | if (rc != MBX_SUCCESS) { | |
6725 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI, | |
6726 | "3104 Adapter failed to issue " | |
6727 | "DOWN_LINK mbox cmd, rc:x%x\n", rc); | |
6728 | goto out_unset_queue; | |
6729 | } | |
6730 | } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) { | |
1b51197d JS |
6731 | /* don't perform init_link on SLI4 FC port loopback test */ |
6732 | if (!(phba->link_flag & LS_LOOPBACK_MODE)) { | |
6733 | rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT); | |
6734 | if (rc) | |
6735 | goto out_unset_queue; | |
6736 | } | |
5350d872 JS |
6737 | } |
6738 | mempool_free(mboxq, phba->mbox_mem_pool); | |
6739 | return rc; | |
76a95d75 | 6740 | out_unset_queue: |
da0436e9 | 6741 | /* Unset all the queues set up in this routine when error out */ |
5350d872 JS |
6742 | lpfc_sli4_queue_unset(phba); |
6743 | out_destroy_queue: | |
6744 | lpfc_sli4_queue_destroy(phba); | |
da0436e9 | 6745 | out_stop_timers: |
5350d872 | 6746 | lpfc_stop_hba_timers(phba); |
da0436e9 JS |
6747 | out_free_mbox: |
6748 | mempool_free(mboxq, phba->mbox_mem_pool); | |
6749 | return rc; | |
6750 | } | |
6751 | ||
6752 | /** | |
6753 | * lpfc_mbox_timeout - Timeout call back function for mbox timer | |
6754 | * @ptr: context object - pointer to hba structure. | |
6755 | * | |
6756 | * This is the callback function for mailbox timer. The mailbox | |
6757 | * timer is armed when a new mailbox command is issued and the timer | |
6758 | * is deleted when the mailbox complete. The function is called by | |
6759 | * the kernel timer code when a mailbox does not complete within | |
6760 | * expected time. This function wakes up the worker thread to | |
6761 | * process the mailbox timeout and returns. All the processing is | |
6762 | * done by the worker thread function lpfc_mbox_timeout_handler. | |
6763 | **/ | |
6764 | void | |
6765 | lpfc_mbox_timeout(unsigned long ptr) | |
6766 | { | |
6767 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; | |
6768 | unsigned long iflag; | |
6769 | uint32_t tmo_posted; | |
6770 | ||
6771 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); | |
6772 | tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO; | |
6773 | if (!tmo_posted) | |
6774 | phba->pport->work_port_events |= WORKER_MBOX_TMO; | |
6775 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); | |
6776 | ||
6777 | if (!tmo_posted) | |
6778 | lpfc_worker_wake_up(phba); | |
6779 | return; | |
6780 | } | |
6781 | ||
e8d3c3b1 JS |
6782 | /** |
6783 | * lpfc_sli4_mbox_completions_pending - check to see if any mailbox completions | |
6784 | * are pending | |
6785 | * @phba: Pointer to HBA context object. | |
6786 | * | |
6787 | * This function checks if any mailbox completions are present on the mailbox | |
6788 | * completion queue. | |
6789 | **/ | |
3bb11fc5 | 6790 | static bool |
e8d3c3b1 JS |
6791 | lpfc_sli4_mbox_completions_pending(struct lpfc_hba *phba) |
6792 | { | |
6793 | ||
6794 | uint32_t idx; | |
6795 | struct lpfc_queue *mcq; | |
6796 | struct lpfc_mcqe *mcqe; | |
6797 | bool pending_completions = false; | |
6798 | ||
6799 | if (unlikely(!phba) || (phba->sli_rev != LPFC_SLI_REV4)) | |
6800 | return false; | |
6801 | ||
6802 | /* Check for completions on mailbox completion queue */ | |
6803 | ||
6804 | mcq = phba->sli4_hba.mbx_cq; | |
6805 | idx = mcq->hba_index; | |
6806 | while (bf_get_le32(lpfc_cqe_valid, mcq->qe[idx].cqe)) { | |
6807 | mcqe = (struct lpfc_mcqe *)mcq->qe[idx].cqe; | |
6808 | if (bf_get_le32(lpfc_trailer_completed, mcqe) && | |
6809 | (!bf_get_le32(lpfc_trailer_async, mcqe))) { | |
6810 | pending_completions = true; | |
6811 | break; | |
6812 | } | |
6813 | idx = (idx + 1) % mcq->entry_count; | |
6814 | if (mcq->hba_index == idx) | |
6815 | break; | |
6816 | } | |
6817 | return pending_completions; | |
6818 | ||
6819 | } | |
6820 | ||
6821 | /** | |
6822 | * lpfc_sli4_process_missed_mbox_completions - process mbox completions | |
6823 | * that were missed. | |
6824 | * @phba: Pointer to HBA context object. | |
6825 | * | |
6826 | * For sli4, it is possible to miss an interrupt. As such mbox completions | |
6827 | * maybe missed causing erroneous mailbox timeouts to occur. This function | |
6828 | * checks to see if mbox completions are on the mailbox completion queue | |
6829 | * and will process all the completions associated with the eq for the | |
6830 | * mailbox completion queue. | |
6831 | **/ | |
6832 | bool | |
6833 | lpfc_sli4_process_missed_mbox_completions(struct lpfc_hba *phba) | |
6834 | { | |
6835 | ||
6836 | uint32_t eqidx; | |
6837 | struct lpfc_queue *fpeq = NULL; | |
6838 | struct lpfc_eqe *eqe; | |
6839 | bool mbox_pending; | |
6840 | ||
6841 | if (unlikely(!phba) || (phba->sli_rev != LPFC_SLI_REV4)) | |
6842 | return false; | |
6843 | ||
6844 | /* Find the eq associated with the mcq */ | |
6845 | ||
6846 | if (phba->sli4_hba.hba_eq) | |
6847 | for (eqidx = 0; eqidx < phba->cfg_fcp_io_channel; eqidx++) | |
6848 | if (phba->sli4_hba.hba_eq[eqidx]->queue_id == | |
6849 | phba->sli4_hba.mbx_cq->assoc_qid) { | |
6850 | fpeq = phba->sli4_hba.hba_eq[eqidx]; | |
6851 | break; | |
6852 | } | |
6853 | if (!fpeq) | |
6854 | return false; | |
6855 | ||
6856 | /* Turn off interrupts from this EQ */ | |
6857 | ||
6858 | lpfc_sli4_eq_clr_intr(fpeq); | |
6859 | ||
6860 | /* Check to see if a mbox completion is pending */ | |
6861 | ||
6862 | mbox_pending = lpfc_sli4_mbox_completions_pending(phba); | |
6863 | ||
6864 | /* | |
6865 | * If a mbox completion is pending, process all the events on EQ | |
6866 | * associated with the mbox completion queue (this could include | |
6867 | * mailbox commands, async events, els commands, receive queue data | |
6868 | * and fcp commands) | |
6869 | */ | |
6870 | ||
6871 | if (mbox_pending) | |
6872 | while ((eqe = lpfc_sli4_eq_get(fpeq))) { | |
6873 | lpfc_sli4_hba_handle_eqe(phba, eqe, eqidx); | |
6874 | fpeq->EQ_processed++; | |
6875 | } | |
6876 | ||
6877 | /* Always clear and re-arm the EQ */ | |
6878 | ||
6879 | lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM); | |
6880 | ||
6881 | return mbox_pending; | |
6882 | ||
6883 | } | |
da0436e9 JS |
6884 | |
6885 | /** | |
6886 | * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout | |
6887 | * @phba: Pointer to HBA context object. | |
6888 | * | |
6889 | * This function is called from worker thread when a mailbox command times out. | |
6890 | * The caller is not required to hold any locks. This function will reset the | |
6891 | * HBA and recover all the pending commands. | |
6892 | **/ | |
6893 | void | |
6894 | lpfc_mbox_timeout_handler(struct lpfc_hba *phba) | |
6895 | { | |
6896 | LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active; | |
eb016566 JS |
6897 | MAILBOX_t *mb = NULL; |
6898 | ||
da0436e9 | 6899 | struct lpfc_sli *psli = &phba->sli; |
da0436e9 | 6900 | |
e8d3c3b1 JS |
6901 | /* If the mailbox completed, process the completion and return */ |
6902 | if (lpfc_sli4_process_missed_mbox_completions(phba)) | |
6903 | return; | |
6904 | ||
eb016566 JS |
6905 | if (pmbox != NULL) |
6906 | mb = &pmbox->u.mb; | |
da0436e9 JS |
6907 | /* Check the pmbox pointer first. There is a race condition |
6908 | * between the mbox timeout handler getting executed in the | |
6909 | * worklist and the mailbox actually completing. When this | |
6910 | * race condition occurs, the mbox_active will be NULL. | |
6911 | */ | |
6912 | spin_lock_irq(&phba->hbalock); | |
6913 | if (pmbox == NULL) { | |
6914 | lpfc_printf_log(phba, KERN_WARNING, | |
6915 | LOG_MBOX | LOG_SLI, | |
6916 | "0353 Active Mailbox cleared - mailbox timeout " | |
6917 | "exiting\n"); | |
6918 | spin_unlock_irq(&phba->hbalock); | |
6919 | return; | |
6920 | } | |
6921 | ||
6922 | /* Mbox cmd <mbxCommand> timeout */ | |
6923 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
6924 | "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n", | |
6925 | mb->mbxCommand, | |
6926 | phba->pport->port_state, | |
6927 | phba->sli.sli_flag, | |
6928 | phba->sli.mbox_active); | |
6929 | spin_unlock_irq(&phba->hbalock); | |
6930 | ||
6931 | /* Setting state unknown so lpfc_sli_abort_iocb_ring | |
6932 | * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing | |
25985edc | 6933 | * it to fail all outstanding SCSI IO. |
da0436e9 JS |
6934 | */ |
6935 | spin_lock_irq(&phba->pport->work_port_lock); | |
6936 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; | |
6937 | spin_unlock_irq(&phba->pport->work_port_lock); | |
6938 | spin_lock_irq(&phba->hbalock); | |
6939 | phba->link_state = LPFC_LINK_UNKNOWN; | |
f4b4c68f | 6940 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
da0436e9 JS |
6941 | spin_unlock_irq(&phba->hbalock); |
6942 | ||
db55fba8 | 6943 | lpfc_sli_abort_fcp_rings(phba); |
da0436e9 JS |
6944 | |
6945 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
6946 | "0345 Resetting board due to mailbox timeout\n"); | |
6947 | ||
6948 | /* Reset the HBA device */ | |
6949 | lpfc_reset_hba(phba); | |
6950 | } | |
6951 | ||
6952 | /** | |
6953 | * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware | |
6954 | * @phba: Pointer to HBA context object. | |
6955 | * @pmbox: Pointer to mailbox object. | |
6956 | * @flag: Flag indicating how the mailbox need to be processed. | |
6957 | * | |
6958 | * This function is called by discovery code and HBA management code | |
6959 | * to submit a mailbox command to firmware with SLI-3 interface spec. This | |
6960 | * function gets the hbalock to protect the data structures. | |
6961 | * The mailbox command can be submitted in polling mode, in which case | |
6962 | * this function will wait in a polling loop for the completion of the | |
6963 | * mailbox. | |
6964 | * If the mailbox is submitted in no_wait mode (not polling) the | |
6965 | * function will submit the command and returns immediately without waiting | |
6966 | * for the mailbox completion. The no_wait is supported only when HBA | |
6967 | * is in SLI2/SLI3 mode - interrupts are enabled. | |
6968 | * The SLI interface allows only one mailbox pending at a time. If the | |
6969 | * mailbox is issued in polling mode and there is already a mailbox | |
6970 | * pending, then the function will return an error. If the mailbox is issued | |
6971 | * in NO_WAIT mode and there is a mailbox pending already, the function | |
6972 | * will return MBX_BUSY after queuing the mailbox into mailbox queue. | |
6973 | * The sli layer owns the mailbox object until the completion of mailbox | |
6974 | * command if this function return MBX_BUSY or MBX_SUCCESS. For all other | |
6975 | * return codes the caller owns the mailbox command after the return of | |
6976 | * the function. | |
e59058c4 | 6977 | **/ |
3772a991 JS |
6978 | static int |
6979 | lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, | |
6980 | uint32_t flag) | |
dea3101e | 6981 | { |
bf07bdea | 6982 | MAILBOX_t *mbx; |
2e0fef85 | 6983 | struct lpfc_sli *psli = &phba->sli; |
dea3101e | 6984 | uint32_t status, evtctr; |
9940b97b | 6985 | uint32_t ha_copy, hc_copy; |
dea3101e | 6986 | int i; |
09372820 | 6987 | unsigned long timeout; |
dea3101e | 6988 | unsigned long drvr_flag = 0; |
34b02dcd | 6989 | uint32_t word0, ldata; |
dea3101e | 6990 | void __iomem *to_slim; |
58da1ffb JS |
6991 | int processing_queue = 0; |
6992 | ||
6993 | spin_lock_irqsave(&phba->hbalock, drvr_flag); | |
6994 | if (!pmbox) { | |
8568a4d2 | 6995 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
58da1ffb | 6996 | /* processing mbox queue from intr_handler */ |
3772a991 JS |
6997 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
6998 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | |
6999 | return MBX_SUCCESS; | |
7000 | } | |
58da1ffb | 7001 | processing_queue = 1; |
58da1ffb JS |
7002 | pmbox = lpfc_mbox_get(phba); |
7003 | if (!pmbox) { | |
7004 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | |
7005 | return MBX_SUCCESS; | |
7006 | } | |
7007 | } | |
dea3101e | 7008 | |
ed957684 | 7009 | if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl && |
92d7f7b0 | 7010 | pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) { |
ed957684 | 7011 | if(!pmbox->vport) { |
58da1ffb | 7012 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
ed957684 | 7013 | lpfc_printf_log(phba, KERN_ERR, |
92d7f7b0 | 7014 | LOG_MBOX | LOG_VPORT, |
e8b62011 | 7015 | "1806 Mbox x%x failed. No vport\n", |
3772a991 | 7016 | pmbox->u.mb.mbxCommand); |
ed957684 | 7017 | dump_stack(); |
58da1ffb | 7018 | goto out_not_finished; |
ed957684 JS |
7019 | } |
7020 | } | |
7021 | ||
8d63f375 | 7022 | /* If the PCI channel is in offline state, do not post mbox. */ |
58da1ffb JS |
7023 | if (unlikely(pci_channel_offline(phba->pcidev))) { |
7024 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | |
7025 | goto out_not_finished; | |
7026 | } | |
8d63f375 | 7027 | |
a257bf90 JS |
7028 | /* If HBA has a deferred error attention, fail the iocb. */ |
7029 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { | |
7030 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | |
7031 | goto out_not_finished; | |
7032 | } | |
7033 | ||
dea3101e | 7034 | psli = &phba->sli; |
92d7f7b0 | 7035 | |
bf07bdea | 7036 | mbx = &pmbox->u.mb; |
dea3101e JB |
7037 | status = MBX_SUCCESS; |
7038 | ||
2e0fef85 JS |
7039 | if (phba->link_state == LPFC_HBA_ERROR) { |
7040 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | |
41415862 JW |
7041 | |
7042 | /* Mbox command <mbxCommand> cannot issue */ | |
3772a991 JS |
7043 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
7044 | "(%d):0311 Mailbox command x%x cannot " | |
7045 | "issue Data: x%x x%x\n", | |
7046 | pmbox->vport ? pmbox->vport->vpi : 0, | |
7047 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); | |
58da1ffb | 7048 | goto out_not_finished; |
41415862 JW |
7049 | } |
7050 | ||
bf07bdea | 7051 | if (mbx->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT) { |
9940b97b JS |
7052 | if (lpfc_readl(phba->HCregaddr, &hc_copy) || |
7053 | !(hc_copy & HC_MBINT_ENA)) { | |
7054 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | |
7055 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
3772a991 JS |
7056 | "(%d):2528 Mailbox command x%x cannot " |
7057 | "issue Data: x%x x%x\n", | |
7058 | pmbox->vport ? pmbox->vport->vpi : 0, | |
7059 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); | |
9940b97b JS |
7060 | goto out_not_finished; |
7061 | } | |
9290831f JS |
7062 | } |
7063 | ||
dea3101e JB |
7064 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
7065 | /* Polling for a mbox command when another one is already active | |
7066 | * is not allowed in SLI. Also, the driver must have established | |
7067 | * SLI2 mode to queue and process multiple mbox commands. | |
7068 | */ | |
7069 | ||
7070 | if (flag & MBX_POLL) { | |
2e0fef85 | 7071 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
dea3101e JB |
7072 | |
7073 | /* Mbox command <mbxCommand> cannot issue */ | |
3772a991 JS |
7074 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
7075 | "(%d):2529 Mailbox command x%x " | |
7076 | "cannot issue Data: x%x x%x\n", | |
7077 | pmbox->vport ? pmbox->vport->vpi : 0, | |
7078 | pmbox->u.mb.mbxCommand, | |
7079 | psli->sli_flag, flag); | |
58da1ffb | 7080 | goto out_not_finished; |
dea3101e JB |
7081 | } |
7082 | ||
3772a991 | 7083 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) { |
2e0fef85 | 7084 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
dea3101e | 7085 | /* Mbox command <mbxCommand> cannot issue */ |
3772a991 JS |
7086 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
7087 | "(%d):2530 Mailbox command x%x " | |
7088 | "cannot issue Data: x%x x%x\n", | |
7089 | pmbox->vport ? pmbox->vport->vpi : 0, | |
7090 | pmbox->u.mb.mbxCommand, | |
7091 | psli->sli_flag, flag); | |
58da1ffb | 7092 | goto out_not_finished; |
dea3101e JB |
7093 | } |
7094 | ||
dea3101e JB |
7095 | /* Another mailbox command is still being processed, queue this |
7096 | * command to be processed later. | |
7097 | */ | |
7098 | lpfc_mbox_put(phba, pmbox); | |
7099 | ||
7100 | /* Mbox cmd issue - BUSY */ | |
ed957684 | 7101 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
e8b62011 | 7102 | "(%d):0308 Mbox cmd issue - BUSY Data: " |
92d7f7b0 | 7103 | "x%x x%x x%x x%x\n", |
92d7f7b0 | 7104 | pmbox->vport ? pmbox->vport->vpi : 0xffffff, |
bf07bdea | 7105 | mbx->mbxCommand, phba->pport->port_state, |
92d7f7b0 | 7106 | psli->sli_flag, flag); |
dea3101e JB |
7107 | |
7108 | psli->slistat.mbox_busy++; | |
2e0fef85 | 7109 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
dea3101e | 7110 | |
858c9f6c JS |
7111 | if (pmbox->vport) { |
7112 | lpfc_debugfs_disc_trc(pmbox->vport, | |
7113 | LPFC_DISC_TRC_MBOX_VPORT, | |
7114 | "MBOX Bsy vport: cmd:x%x mb:x%x x%x", | |
bf07bdea RD |
7115 | (uint32_t)mbx->mbxCommand, |
7116 | mbx->un.varWords[0], mbx->un.varWords[1]); | |
858c9f6c JS |
7117 | } |
7118 | else { | |
7119 | lpfc_debugfs_disc_trc(phba->pport, | |
7120 | LPFC_DISC_TRC_MBOX, | |
7121 | "MBOX Bsy: cmd:x%x mb:x%x x%x", | |
bf07bdea RD |
7122 | (uint32_t)mbx->mbxCommand, |
7123 | mbx->un.varWords[0], mbx->un.varWords[1]); | |
858c9f6c JS |
7124 | } |
7125 | ||
2e0fef85 | 7126 | return MBX_BUSY; |
dea3101e JB |
7127 | } |
7128 | ||
dea3101e JB |
7129 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
7130 | ||
7131 | /* If we are not polling, we MUST be in SLI2 mode */ | |
7132 | if (flag != MBX_POLL) { | |
3772a991 | 7133 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE) && |
bf07bdea | 7134 | (mbx->mbxCommand != MBX_KILL_BOARD)) { |
dea3101e | 7135 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
2e0fef85 | 7136 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
dea3101e | 7137 | /* Mbox command <mbxCommand> cannot issue */ |
3772a991 JS |
7138 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
7139 | "(%d):2531 Mailbox command x%x " | |
7140 | "cannot issue Data: x%x x%x\n", | |
7141 | pmbox->vport ? pmbox->vport->vpi : 0, | |
7142 | pmbox->u.mb.mbxCommand, | |
7143 | psli->sli_flag, flag); | |
58da1ffb | 7144 | goto out_not_finished; |
dea3101e JB |
7145 | } |
7146 | /* timeout active mbox command */ | |
256ec0d0 JS |
7147 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) * |
7148 | 1000); | |
7149 | mod_timer(&psli->mbox_tmo, jiffies + timeout); | |
dea3101e JB |
7150 | } |
7151 | ||
7152 | /* Mailbox cmd <cmd> issue */ | |
ed957684 | 7153 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
e8b62011 | 7154 | "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x " |
92d7f7b0 | 7155 | "x%x\n", |
e8b62011 | 7156 | pmbox->vport ? pmbox->vport->vpi : 0, |
bf07bdea | 7157 | mbx->mbxCommand, phba->pport->port_state, |
92d7f7b0 | 7158 | psli->sli_flag, flag); |
dea3101e | 7159 | |
bf07bdea | 7160 | if (mbx->mbxCommand != MBX_HEARTBEAT) { |
858c9f6c JS |
7161 | if (pmbox->vport) { |
7162 | lpfc_debugfs_disc_trc(pmbox->vport, | |
7163 | LPFC_DISC_TRC_MBOX_VPORT, | |
7164 | "MBOX Send vport: cmd:x%x mb:x%x x%x", | |
bf07bdea RD |
7165 | (uint32_t)mbx->mbxCommand, |
7166 | mbx->un.varWords[0], mbx->un.varWords[1]); | |
858c9f6c JS |
7167 | } |
7168 | else { | |
7169 | lpfc_debugfs_disc_trc(phba->pport, | |
7170 | LPFC_DISC_TRC_MBOX, | |
7171 | "MBOX Send: cmd:x%x mb:x%x x%x", | |
bf07bdea RD |
7172 | (uint32_t)mbx->mbxCommand, |
7173 | mbx->un.varWords[0], mbx->un.varWords[1]); | |
858c9f6c JS |
7174 | } |
7175 | } | |
7176 | ||
dea3101e JB |
7177 | psli->slistat.mbox_cmd++; |
7178 | evtctr = psli->slistat.mbox_event; | |
7179 | ||
7180 | /* next set own bit for the adapter and copy over command word */ | |
bf07bdea | 7181 | mbx->mbxOwner = OWN_CHIP; |
dea3101e | 7182 | |
3772a991 | 7183 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
7a470277 JS |
7184 | /* Populate mbox extension offset word. */ |
7185 | if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) { | |
bf07bdea | 7186 | *(((uint32_t *)mbx) + pmbox->mbox_offset_word) |
7a470277 JS |
7187 | = (uint8_t *)phba->mbox_ext |
7188 | - (uint8_t *)phba->mbox; | |
7189 | } | |
7190 | ||
7191 | /* Copy the mailbox extension data */ | |
7192 | if (pmbox->in_ext_byte_len && pmbox->context2) { | |
7193 | lpfc_sli_pcimem_bcopy(pmbox->context2, | |
7194 | (uint8_t *)phba->mbox_ext, | |
7195 | pmbox->in_ext_byte_len); | |
7196 | } | |
7197 | /* Copy command data to host SLIM area */ | |
bf07bdea | 7198 | lpfc_sli_pcimem_bcopy(mbx, phba->mbox, MAILBOX_CMD_SIZE); |
dea3101e | 7199 | } else { |
7a470277 JS |
7200 | /* Populate mbox extension offset word. */ |
7201 | if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) | |
bf07bdea | 7202 | *(((uint32_t *)mbx) + pmbox->mbox_offset_word) |
7a470277 JS |
7203 | = MAILBOX_HBA_EXT_OFFSET; |
7204 | ||
7205 | /* Copy the mailbox extension data */ | |
7206 | if (pmbox->in_ext_byte_len && pmbox->context2) { | |
7207 | lpfc_memcpy_to_slim(phba->MBslimaddr + | |
7208 | MAILBOX_HBA_EXT_OFFSET, | |
7209 | pmbox->context2, pmbox->in_ext_byte_len); | |
7210 | ||
7211 | } | |
bf07bdea | 7212 | if (mbx->mbxCommand == MBX_CONFIG_PORT) { |
dea3101e | 7213 | /* copy command data into host mbox for cmpl */ |
bf07bdea | 7214 | lpfc_sli_pcimem_bcopy(mbx, phba->mbox, MAILBOX_CMD_SIZE); |
dea3101e JB |
7215 | } |
7216 | ||
7217 | /* First copy mbox command data to HBA SLIM, skip past first | |
7218 | word */ | |
7219 | to_slim = phba->MBslimaddr + sizeof (uint32_t); | |
bf07bdea | 7220 | lpfc_memcpy_to_slim(to_slim, &mbx->un.varWords[0], |
dea3101e JB |
7221 | MAILBOX_CMD_SIZE - sizeof (uint32_t)); |
7222 | ||
7223 | /* Next copy over first word, with mbxOwner set */ | |
bf07bdea | 7224 | ldata = *((uint32_t *)mbx); |
dea3101e JB |
7225 | to_slim = phba->MBslimaddr; |
7226 | writel(ldata, to_slim); | |
7227 | readl(to_slim); /* flush */ | |
7228 | ||
bf07bdea | 7229 | if (mbx->mbxCommand == MBX_CONFIG_PORT) { |
dea3101e | 7230 | /* switch over to host mailbox */ |
3772a991 | 7231 | psli->sli_flag |= LPFC_SLI_ACTIVE; |
dea3101e JB |
7232 | } |
7233 | } | |
7234 | ||
7235 | wmb(); | |
dea3101e JB |
7236 | |
7237 | switch (flag) { | |
7238 | case MBX_NOWAIT: | |
09372820 | 7239 | /* Set up reference to mailbox command */ |
dea3101e | 7240 | psli->mbox_active = pmbox; |
09372820 JS |
7241 | /* Interrupt board to do it */ |
7242 | writel(CA_MBATT, phba->CAregaddr); | |
7243 | readl(phba->CAregaddr); /* flush */ | |
7244 | /* Don't wait for it to finish, just return */ | |
dea3101e JB |
7245 | break; |
7246 | ||
7247 | case MBX_POLL: | |
09372820 | 7248 | /* Set up null reference to mailbox command */ |
dea3101e | 7249 | psli->mbox_active = NULL; |
09372820 JS |
7250 | /* Interrupt board to do it */ |
7251 | writel(CA_MBATT, phba->CAregaddr); | |
7252 | readl(phba->CAregaddr); /* flush */ | |
7253 | ||
3772a991 | 7254 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
dea3101e | 7255 | /* First read mbox status word */ |
34b02dcd | 7256 | word0 = *((uint32_t *)phba->mbox); |
dea3101e JB |
7257 | word0 = le32_to_cpu(word0); |
7258 | } else { | |
7259 | /* First read mbox status word */ | |
9940b97b JS |
7260 | if (lpfc_readl(phba->MBslimaddr, &word0)) { |
7261 | spin_unlock_irqrestore(&phba->hbalock, | |
7262 | drvr_flag); | |
7263 | goto out_not_finished; | |
7264 | } | |
dea3101e JB |
7265 | } |
7266 | ||
7267 | /* Read the HBA Host Attention Register */ | |
9940b97b JS |
7268 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) { |
7269 | spin_unlock_irqrestore(&phba->hbalock, | |
7270 | drvr_flag); | |
7271 | goto out_not_finished; | |
7272 | } | |
a183a15f JS |
7273 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) * |
7274 | 1000) + jiffies; | |
09372820 | 7275 | i = 0; |
dea3101e | 7276 | /* Wait for command to complete */ |
41415862 JW |
7277 | while (((word0 & OWN_CHIP) == OWN_CHIP) || |
7278 | (!(ha_copy & HA_MBATT) && | |
2e0fef85 | 7279 | (phba->link_state > LPFC_WARM_START))) { |
09372820 | 7280 | if (time_after(jiffies, timeout)) { |
dea3101e | 7281 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
2e0fef85 | 7282 | spin_unlock_irqrestore(&phba->hbalock, |
dea3101e | 7283 | drvr_flag); |
58da1ffb | 7284 | goto out_not_finished; |
dea3101e JB |
7285 | } |
7286 | ||
7287 | /* Check if we took a mbox interrupt while we were | |
7288 | polling */ | |
7289 | if (((word0 & OWN_CHIP) != OWN_CHIP) | |
7290 | && (evtctr != psli->slistat.mbox_event)) | |
7291 | break; | |
7292 | ||
09372820 JS |
7293 | if (i++ > 10) { |
7294 | spin_unlock_irqrestore(&phba->hbalock, | |
7295 | drvr_flag); | |
7296 | msleep(1); | |
7297 | spin_lock_irqsave(&phba->hbalock, drvr_flag); | |
7298 | } | |
dea3101e | 7299 | |
3772a991 | 7300 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
dea3101e | 7301 | /* First copy command data */ |
34b02dcd | 7302 | word0 = *((uint32_t *)phba->mbox); |
dea3101e | 7303 | word0 = le32_to_cpu(word0); |
bf07bdea | 7304 | if (mbx->mbxCommand == MBX_CONFIG_PORT) { |
dea3101e | 7305 | MAILBOX_t *slimmb; |
34b02dcd | 7306 | uint32_t slimword0; |
dea3101e JB |
7307 | /* Check real SLIM for any errors */ |
7308 | slimword0 = readl(phba->MBslimaddr); | |
7309 | slimmb = (MAILBOX_t *) & slimword0; | |
7310 | if (((slimword0 & OWN_CHIP) != OWN_CHIP) | |
7311 | && slimmb->mbxStatus) { | |
7312 | psli->sli_flag &= | |
3772a991 | 7313 | ~LPFC_SLI_ACTIVE; |
dea3101e JB |
7314 | word0 = slimword0; |
7315 | } | |
7316 | } | |
7317 | } else { | |
7318 | /* First copy command data */ | |
7319 | word0 = readl(phba->MBslimaddr); | |
7320 | } | |
7321 | /* Read the HBA Host Attention Register */ | |
9940b97b JS |
7322 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) { |
7323 | spin_unlock_irqrestore(&phba->hbalock, | |
7324 | drvr_flag); | |
7325 | goto out_not_finished; | |
7326 | } | |
dea3101e JB |
7327 | } |
7328 | ||
3772a991 | 7329 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
dea3101e | 7330 | /* copy results back to user */ |
bf07bdea | 7331 | lpfc_sli_pcimem_bcopy(phba->mbox, mbx, MAILBOX_CMD_SIZE); |
7a470277 JS |
7332 | /* Copy the mailbox extension data */ |
7333 | if (pmbox->out_ext_byte_len && pmbox->context2) { | |
7334 | lpfc_sli_pcimem_bcopy(phba->mbox_ext, | |
7335 | pmbox->context2, | |
7336 | pmbox->out_ext_byte_len); | |
7337 | } | |
dea3101e JB |
7338 | } else { |
7339 | /* First copy command data */ | |
bf07bdea | 7340 | lpfc_memcpy_from_slim(mbx, phba->MBslimaddr, |
dea3101e | 7341 | MAILBOX_CMD_SIZE); |
7a470277 JS |
7342 | /* Copy the mailbox extension data */ |
7343 | if (pmbox->out_ext_byte_len && pmbox->context2) { | |
7344 | lpfc_memcpy_from_slim(pmbox->context2, | |
7345 | phba->MBslimaddr + | |
7346 | MAILBOX_HBA_EXT_OFFSET, | |
7347 | pmbox->out_ext_byte_len); | |
dea3101e JB |
7348 | } |
7349 | } | |
7350 | ||
7351 | writel(HA_MBATT, phba->HAregaddr); | |
7352 | readl(phba->HAregaddr); /* flush */ | |
7353 | ||
7354 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
bf07bdea | 7355 | status = mbx->mbxStatus; |
dea3101e JB |
7356 | } |
7357 | ||
2e0fef85 JS |
7358 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
7359 | return status; | |
58da1ffb JS |
7360 | |
7361 | out_not_finished: | |
7362 | if (processing_queue) { | |
da0436e9 | 7363 | pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED; |
58da1ffb JS |
7364 | lpfc_mbox_cmpl_put(phba, pmbox); |
7365 | } | |
7366 | return MBX_NOT_FINISHED; | |
dea3101e JB |
7367 | } |
7368 | ||
f1126688 JS |
7369 | /** |
7370 | * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command | |
7371 | * @phba: Pointer to HBA context object. | |
7372 | * | |
7373 | * The function blocks the posting of SLI4 asynchronous mailbox commands from | |
7374 | * the driver internal pending mailbox queue. It will then try to wait out the | |
7375 | * possible outstanding mailbox command before return. | |
7376 | * | |
7377 | * Returns: | |
7378 | * 0 - the outstanding mailbox command completed; otherwise, the wait for | |
7379 | * the outstanding mailbox command timed out. | |
7380 | **/ | |
7381 | static int | |
7382 | lpfc_sli4_async_mbox_block(struct lpfc_hba *phba) | |
7383 | { | |
7384 | struct lpfc_sli *psli = &phba->sli; | |
f1126688 | 7385 | int rc = 0; |
a183a15f | 7386 | unsigned long timeout = 0; |
f1126688 JS |
7387 | |
7388 | /* Mark the asynchronous mailbox command posting as blocked */ | |
7389 | spin_lock_irq(&phba->hbalock); | |
7390 | psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; | |
f1126688 JS |
7391 | /* Determine how long we might wait for the active mailbox |
7392 | * command to be gracefully completed by firmware. | |
7393 | */ | |
a183a15f JS |
7394 | if (phba->sli.mbox_active) |
7395 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, | |
7396 | phba->sli.mbox_active) * | |
7397 | 1000) + jiffies; | |
7398 | spin_unlock_irq(&phba->hbalock); | |
7399 | ||
e8d3c3b1 JS |
7400 | /* Make sure the mailbox is really active */ |
7401 | if (timeout) | |
7402 | lpfc_sli4_process_missed_mbox_completions(phba); | |
7403 | ||
f1126688 JS |
7404 | /* Wait for the outstnading mailbox command to complete */ |
7405 | while (phba->sli.mbox_active) { | |
7406 | /* Check active mailbox complete status every 2ms */ | |
7407 | msleep(2); | |
7408 | if (time_after(jiffies, timeout)) { | |
7409 | /* Timeout, marked the outstanding cmd not complete */ | |
7410 | rc = 1; | |
7411 | break; | |
7412 | } | |
7413 | } | |
7414 | ||
7415 | /* Can not cleanly block async mailbox command, fails it */ | |
7416 | if (rc) { | |
7417 | spin_lock_irq(&phba->hbalock); | |
7418 | psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; | |
7419 | spin_unlock_irq(&phba->hbalock); | |
7420 | } | |
7421 | return rc; | |
7422 | } | |
7423 | ||
7424 | /** | |
7425 | * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command | |
7426 | * @phba: Pointer to HBA context object. | |
7427 | * | |
7428 | * The function unblocks and resume posting of SLI4 asynchronous mailbox | |
7429 | * commands from the driver internal pending mailbox queue. It makes sure | |
7430 | * that there is no outstanding mailbox command before resuming posting | |
7431 | * asynchronous mailbox commands. If, for any reason, there is outstanding | |
7432 | * mailbox command, it will try to wait it out before resuming asynchronous | |
7433 | * mailbox command posting. | |
7434 | **/ | |
7435 | static void | |
7436 | lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba) | |
7437 | { | |
7438 | struct lpfc_sli *psli = &phba->sli; | |
7439 | ||
7440 | spin_lock_irq(&phba->hbalock); | |
7441 | if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { | |
7442 | /* Asynchronous mailbox posting is not blocked, do nothing */ | |
7443 | spin_unlock_irq(&phba->hbalock); | |
7444 | return; | |
7445 | } | |
7446 | ||
7447 | /* Outstanding synchronous mailbox command is guaranteed to be done, | |
7448 | * successful or timeout, after timing-out the outstanding mailbox | |
7449 | * command shall always be removed, so just unblock posting async | |
7450 | * mailbox command and resume | |
7451 | */ | |
7452 | psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; | |
7453 | spin_unlock_irq(&phba->hbalock); | |
7454 | ||
7455 | /* wake up worker thread to post asynchronlous mailbox command */ | |
7456 | lpfc_worker_wake_up(phba); | |
7457 | } | |
7458 | ||
2d843edc JS |
7459 | /** |
7460 | * lpfc_sli4_wait_bmbx_ready - Wait for bootstrap mailbox register ready | |
7461 | * @phba: Pointer to HBA context object. | |
7462 | * @mboxq: Pointer to mailbox object. | |
7463 | * | |
7464 | * The function waits for the bootstrap mailbox register ready bit from | |
7465 | * port for twice the regular mailbox command timeout value. | |
7466 | * | |
7467 | * 0 - no timeout on waiting for bootstrap mailbox register ready. | |
7468 | * MBXERR_ERROR - wait for bootstrap mailbox register timed out. | |
7469 | **/ | |
7470 | static int | |
7471 | lpfc_sli4_wait_bmbx_ready(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) | |
7472 | { | |
7473 | uint32_t db_ready; | |
7474 | unsigned long timeout; | |
7475 | struct lpfc_register bmbx_reg; | |
7476 | ||
7477 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mboxq) | |
7478 | * 1000) + jiffies; | |
7479 | ||
7480 | do { | |
7481 | bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr); | |
7482 | db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg); | |
7483 | if (!db_ready) | |
7484 | msleep(2); | |
7485 | ||
7486 | if (time_after(jiffies, timeout)) | |
7487 | return MBXERR_ERROR; | |
7488 | } while (!db_ready); | |
7489 | ||
7490 | return 0; | |
7491 | } | |
7492 | ||
da0436e9 JS |
7493 | /** |
7494 | * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox | |
7495 | * @phba: Pointer to HBA context object. | |
7496 | * @mboxq: Pointer to mailbox object. | |
7497 | * | |
7498 | * The function posts a mailbox to the port. The mailbox is expected | |
7499 | * to be comletely filled in and ready for the port to operate on it. | |
7500 | * This routine executes a synchronous completion operation on the | |
7501 | * mailbox by polling for its completion. | |
7502 | * | |
7503 | * The caller must not be holding any locks when calling this routine. | |
7504 | * | |
7505 | * Returns: | |
7506 | * MBX_SUCCESS - mailbox posted successfully | |
7507 | * Any of the MBX error values. | |
7508 | **/ | |
7509 | static int | |
7510 | lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) | |
7511 | { | |
7512 | int rc = MBX_SUCCESS; | |
7513 | unsigned long iflag; | |
da0436e9 JS |
7514 | uint32_t mcqe_status; |
7515 | uint32_t mbx_cmnd; | |
da0436e9 JS |
7516 | struct lpfc_sli *psli = &phba->sli; |
7517 | struct lpfc_mqe *mb = &mboxq->u.mqe; | |
7518 | struct lpfc_bmbx_create *mbox_rgn; | |
7519 | struct dma_address *dma_address; | |
da0436e9 JS |
7520 | |
7521 | /* | |
7522 | * Only one mailbox can be active to the bootstrap mailbox region | |
7523 | * at a time and there is no queueing provided. | |
7524 | */ | |
7525 | spin_lock_irqsave(&phba->hbalock, iflag); | |
7526 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { | |
7527 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
7528 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
a183a15f | 7529 | "(%d):2532 Mailbox command x%x (x%x/x%x) " |
da0436e9 JS |
7530 | "cannot issue Data: x%x x%x\n", |
7531 | mboxq->vport ? mboxq->vport->vpi : 0, | |
7532 | mboxq->u.mb.mbxCommand, | |
a183a15f JS |
7533 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
7534 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), | |
da0436e9 JS |
7535 | psli->sli_flag, MBX_POLL); |
7536 | return MBXERR_ERROR; | |
7537 | } | |
7538 | /* The server grabs the token and owns it until release */ | |
7539 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; | |
7540 | phba->sli.mbox_active = mboxq; | |
7541 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
7542 | ||
2d843edc JS |
7543 | /* wait for bootstrap mbox register for readyness */ |
7544 | rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq); | |
7545 | if (rc) | |
7546 | goto exit; | |
7547 | ||
da0436e9 JS |
7548 | /* |
7549 | * Initialize the bootstrap memory region to avoid stale data areas | |
7550 | * in the mailbox post. Then copy the caller's mailbox contents to | |
7551 | * the bmbx mailbox region. | |
7552 | */ | |
7553 | mbx_cmnd = bf_get(lpfc_mqe_command, mb); | |
7554 | memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create)); | |
7555 | lpfc_sli_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt, | |
7556 | sizeof(struct lpfc_mqe)); | |
7557 | ||
7558 | /* Post the high mailbox dma address to the port and wait for ready. */ | |
7559 | dma_address = &phba->sli4_hba.bmbx.dma_address; | |
7560 | writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr); | |
7561 | ||
2d843edc JS |
7562 | /* wait for bootstrap mbox register for hi-address write done */ |
7563 | rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq); | |
7564 | if (rc) | |
7565 | goto exit; | |
da0436e9 JS |
7566 | |
7567 | /* Post the low mailbox dma address to the port. */ | |
7568 | writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr); | |
da0436e9 | 7569 | |
2d843edc JS |
7570 | /* wait for bootstrap mbox register for low address write done */ |
7571 | rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq); | |
7572 | if (rc) | |
7573 | goto exit; | |
da0436e9 JS |
7574 | |
7575 | /* | |
7576 | * Read the CQ to ensure the mailbox has completed. | |
7577 | * If so, update the mailbox status so that the upper layers | |
7578 | * can complete the request normally. | |
7579 | */ | |
7580 | lpfc_sli_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb, | |
7581 | sizeof(struct lpfc_mqe)); | |
7582 | mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt; | |
7583 | lpfc_sli_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe, | |
7584 | sizeof(struct lpfc_mcqe)); | |
7585 | mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe); | |
0558056c JS |
7586 | /* |
7587 | * When the CQE status indicates a failure and the mailbox status | |
7588 | * indicates success then copy the CQE status into the mailbox status | |
7589 | * (and prefix it with x4000). | |
7590 | */ | |
da0436e9 | 7591 | if (mcqe_status != MB_CQE_STATUS_SUCCESS) { |
0558056c JS |
7592 | if (bf_get(lpfc_mqe_status, mb) == MBX_SUCCESS) |
7593 | bf_set(lpfc_mqe_status, mb, | |
7594 | (LPFC_MBX_ERROR_RANGE | mcqe_status)); | |
da0436e9 | 7595 | rc = MBXERR_ERROR; |
d7c47992 JS |
7596 | } else |
7597 | lpfc_sli4_swap_str(phba, mboxq); | |
da0436e9 JS |
7598 | |
7599 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, | |
a183a15f | 7600 | "(%d):0356 Mailbox cmd x%x (x%x/x%x) Status x%x " |
da0436e9 JS |
7601 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x" |
7602 | " x%x x%x CQ: x%x x%x x%x x%x\n", | |
a183a15f JS |
7603 | mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd, |
7604 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), | |
7605 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), | |
da0436e9 JS |
7606 | bf_get(lpfc_mqe_status, mb), |
7607 | mb->un.mb_words[0], mb->un.mb_words[1], | |
7608 | mb->un.mb_words[2], mb->un.mb_words[3], | |
7609 | mb->un.mb_words[4], mb->un.mb_words[5], | |
7610 | mb->un.mb_words[6], mb->un.mb_words[7], | |
7611 | mb->un.mb_words[8], mb->un.mb_words[9], | |
7612 | mb->un.mb_words[10], mb->un.mb_words[11], | |
7613 | mb->un.mb_words[12], mboxq->mcqe.word0, | |
7614 | mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1, | |
7615 | mboxq->mcqe.trailer); | |
7616 | exit: | |
7617 | /* We are holding the token, no needed for lock when release */ | |
7618 | spin_lock_irqsave(&phba->hbalock, iflag); | |
7619 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
7620 | phba->sli.mbox_active = NULL; | |
7621 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
7622 | return rc; | |
7623 | } | |
7624 | ||
7625 | /** | |
7626 | * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware | |
7627 | * @phba: Pointer to HBA context object. | |
7628 | * @pmbox: Pointer to mailbox object. | |
7629 | * @flag: Flag indicating how the mailbox need to be processed. | |
7630 | * | |
7631 | * This function is called by discovery code and HBA management code to submit | |
7632 | * a mailbox command to firmware with SLI-4 interface spec. | |
7633 | * | |
7634 | * Return codes the caller owns the mailbox command after the return of the | |
7635 | * function. | |
7636 | **/ | |
7637 | static int | |
7638 | lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, | |
7639 | uint32_t flag) | |
7640 | { | |
7641 | struct lpfc_sli *psli = &phba->sli; | |
7642 | unsigned long iflags; | |
7643 | int rc; | |
7644 | ||
b76f2dc9 JS |
7645 | /* dump from issue mailbox command if setup */ |
7646 | lpfc_idiag_mbxacc_dump_issue_mbox(phba, &mboxq->u.mb); | |
7647 | ||
8fa38513 JS |
7648 | rc = lpfc_mbox_dev_check(phba); |
7649 | if (unlikely(rc)) { | |
7650 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
a183a15f | 7651 | "(%d):2544 Mailbox command x%x (x%x/x%x) " |
8fa38513 JS |
7652 | "cannot issue Data: x%x x%x\n", |
7653 | mboxq->vport ? mboxq->vport->vpi : 0, | |
7654 | mboxq->u.mb.mbxCommand, | |
a183a15f JS |
7655 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
7656 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), | |
8fa38513 JS |
7657 | psli->sli_flag, flag); |
7658 | goto out_not_finished; | |
7659 | } | |
7660 | ||
da0436e9 JS |
7661 | /* Detect polling mode and jump to a handler */ |
7662 | if (!phba->sli4_hba.intr_enable) { | |
7663 | if (flag == MBX_POLL) | |
7664 | rc = lpfc_sli4_post_sync_mbox(phba, mboxq); | |
7665 | else | |
7666 | rc = -EIO; | |
7667 | if (rc != MBX_SUCCESS) | |
0558056c | 7668 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
da0436e9 | 7669 | "(%d):2541 Mailbox command x%x " |
cc459f19 JS |
7670 | "(x%x/x%x) failure: " |
7671 | "mqe_sta: x%x mcqe_sta: x%x/x%x " | |
7672 | "Data: x%x x%x\n,", | |
da0436e9 JS |
7673 | mboxq->vport ? mboxq->vport->vpi : 0, |
7674 | mboxq->u.mb.mbxCommand, | |
a183a15f JS |
7675 | lpfc_sli_config_mbox_subsys_get(phba, |
7676 | mboxq), | |
7677 | lpfc_sli_config_mbox_opcode_get(phba, | |
7678 | mboxq), | |
cc459f19 JS |
7679 | bf_get(lpfc_mqe_status, &mboxq->u.mqe), |
7680 | bf_get(lpfc_mcqe_status, &mboxq->mcqe), | |
7681 | bf_get(lpfc_mcqe_ext_status, | |
7682 | &mboxq->mcqe), | |
da0436e9 JS |
7683 | psli->sli_flag, flag); |
7684 | return rc; | |
7685 | } else if (flag == MBX_POLL) { | |
f1126688 JS |
7686 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
7687 | "(%d):2542 Try to issue mailbox command " | |
a183a15f | 7688 | "x%x (x%x/x%x) synchronously ahead of async" |
f1126688 | 7689 | "mailbox command queue: x%x x%x\n", |
da0436e9 JS |
7690 | mboxq->vport ? mboxq->vport->vpi : 0, |
7691 | mboxq->u.mb.mbxCommand, | |
a183a15f JS |
7692 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
7693 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), | |
da0436e9 | 7694 | psli->sli_flag, flag); |
f1126688 JS |
7695 | /* Try to block the asynchronous mailbox posting */ |
7696 | rc = lpfc_sli4_async_mbox_block(phba); | |
7697 | if (!rc) { | |
7698 | /* Successfully blocked, now issue sync mbox cmd */ | |
7699 | rc = lpfc_sli4_post_sync_mbox(phba, mboxq); | |
7700 | if (rc != MBX_SUCCESS) | |
cc459f19 | 7701 | lpfc_printf_log(phba, KERN_WARNING, |
a183a15f | 7702 | LOG_MBOX | LOG_SLI, |
cc459f19 JS |
7703 | "(%d):2597 Sync Mailbox command " |
7704 | "x%x (x%x/x%x) failure: " | |
7705 | "mqe_sta: x%x mcqe_sta: x%x/x%x " | |
7706 | "Data: x%x x%x\n,", | |
7707 | mboxq->vport ? mboxq->vport->vpi : 0, | |
a183a15f JS |
7708 | mboxq->u.mb.mbxCommand, |
7709 | lpfc_sli_config_mbox_subsys_get(phba, | |
7710 | mboxq), | |
7711 | lpfc_sli_config_mbox_opcode_get(phba, | |
7712 | mboxq), | |
cc459f19 JS |
7713 | bf_get(lpfc_mqe_status, &mboxq->u.mqe), |
7714 | bf_get(lpfc_mcqe_status, &mboxq->mcqe), | |
7715 | bf_get(lpfc_mcqe_ext_status, | |
7716 | &mboxq->mcqe), | |
a183a15f | 7717 | psli->sli_flag, flag); |
f1126688 JS |
7718 | /* Unblock the async mailbox posting afterward */ |
7719 | lpfc_sli4_async_mbox_unblock(phba); | |
7720 | } | |
7721 | return rc; | |
da0436e9 JS |
7722 | } |
7723 | ||
7724 | /* Now, interrupt mode asynchrous mailbox command */ | |
7725 | rc = lpfc_mbox_cmd_check(phba, mboxq); | |
7726 | if (rc) { | |
7727 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
a183a15f | 7728 | "(%d):2543 Mailbox command x%x (x%x/x%x) " |
da0436e9 JS |
7729 | "cannot issue Data: x%x x%x\n", |
7730 | mboxq->vport ? mboxq->vport->vpi : 0, | |
7731 | mboxq->u.mb.mbxCommand, | |
a183a15f JS |
7732 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
7733 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), | |
da0436e9 JS |
7734 | psli->sli_flag, flag); |
7735 | goto out_not_finished; | |
7736 | } | |
da0436e9 JS |
7737 | |
7738 | /* Put the mailbox command to the driver internal FIFO */ | |
7739 | psli->slistat.mbox_busy++; | |
7740 | spin_lock_irqsave(&phba->hbalock, iflags); | |
7741 | lpfc_mbox_put(phba, mboxq); | |
7742 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
7743 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, | |
7744 | "(%d):0354 Mbox cmd issue - Enqueue Data: " | |
a183a15f | 7745 | "x%x (x%x/x%x) x%x x%x x%x\n", |
da0436e9 JS |
7746 | mboxq->vport ? mboxq->vport->vpi : 0xffffff, |
7747 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), | |
a183a15f JS |
7748 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
7749 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), | |
da0436e9 JS |
7750 | phba->pport->port_state, |
7751 | psli->sli_flag, MBX_NOWAIT); | |
7752 | /* Wake up worker thread to transport mailbox command from head */ | |
7753 | lpfc_worker_wake_up(phba); | |
7754 | ||
7755 | return MBX_BUSY; | |
7756 | ||
7757 | out_not_finished: | |
7758 | return MBX_NOT_FINISHED; | |
7759 | } | |
7760 | ||
7761 | /** | |
7762 | * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device | |
7763 | * @phba: Pointer to HBA context object. | |
7764 | * | |
7765 | * This function is called by worker thread to send a mailbox command to | |
7766 | * SLI4 HBA firmware. | |
7767 | * | |
7768 | **/ | |
7769 | int | |
7770 | lpfc_sli4_post_async_mbox(struct lpfc_hba *phba) | |
7771 | { | |
7772 | struct lpfc_sli *psli = &phba->sli; | |
7773 | LPFC_MBOXQ_t *mboxq; | |
7774 | int rc = MBX_SUCCESS; | |
7775 | unsigned long iflags; | |
7776 | struct lpfc_mqe *mqe; | |
7777 | uint32_t mbx_cmnd; | |
7778 | ||
7779 | /* Check interrupt mode before post async mailbox command */ | |
7780 | if (unlikely(!phba->sli4_hba.intr_enable)) | |
7781 | return MBX_NOT_FINISHED; | |
7782 | ||
7783 | /* Check for mailbox command service token */ | |
7784 | spin_lock_irqsave(&phba->hbalock, iflags); | |
7785 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { | |
7786 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
7787 | return MBX_NOT_FINISHED; | |
7788 | } | |
7789 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { | |
7790 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
7791 | return MBX_NOT_FINISHED; | |
7792 | } | |
7793 | if (unlikely(phba->sli.mbox_active)) { | |
7794 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
7795 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
7796 | "0384 There is pending active mailbox cmd\n"); | |
7797 | return MBX_NOT_FINISHED; | |
7798 | } | |
7799 | /* Take the mailbox command service token */ | |
7800 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; | |
7801 | ||
7802 | /* Get the next mailbox command from head of queue */ | |
7803 | mboxq = lpfc_mbox_get(phba); | |
7804 | ||
7805 | /* If no more mailbox command waiting for post, we're done */ | |
7806 | if (!mboxq) { | |
7807 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
7808 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
7809 | return MBX_SUCCESS; | |
7810 | } | |
7811 | phba->sli.mbox_active = mboxq; | |
7812 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
7813 | ||
7814 | /* Check device readiness for posting mailbox command */ | |
7815 | rc = lpfc_mbox_dev_check(phba); | |
7816 | if (unlikely(rc)) | |
7817 | /* Driver clean routine will clean up pending mailbox */ | |
7818 | goto out_not_finished; | |
7819 | ||
7820 | /* Prepare the mbox command to be posted */ | |
7821 | mqe = &mboxq->u.mqe; | |
7822 | mbx_cmnd = bf_get(lpfc_mqe_command, mqe); | |
7823 | ||
7824 | /* Start timer for the mbox_tmo and log some mailbox post messages */ | |
7825 | mod_timer(&psli->mbox_tmo, (jiffies + | |
256ec0d0 | 7826 | msecs_to_jiffies(1000 * lpfc_mbox_tmo_val(phba, mboxq)))); |
da0436e9 JS |
7827 | |
7828 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, | |
a183a15f | 7829 | "(%d):0355 Mailbox cmd x%x (x%x/x%x) issue Data: " |
da0436e9 JS |
7830 | "x%x x%x\n", |
7831 | mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd, | |
a183a15f JS |
7832 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
7833 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), | |
da0436e9 JS |
7834 | phba->pport->port_state, psli->sli_flag); |
7835 | ||
7836 | if (mbx_cmnd != MBX_HEARTBEAT) { | |
7837 | if (mboxq->vport) { | |
7838 | lpfc_debugfs_disc_trc(mboxq->vport, | |
7839 | LPFC_DISC_TRC_MBOX_VPORT, | |
7840 | "MBOX Send vport: cmd:x%x mb:x%x x%x", | |
7841 | mbx_cmnd, mqe->un.mb_words[0], | |
7842 | mqe->un.mb_words[1]); | |
7843 | } else { | |
7844 | lpfc_debugfs_disc_trc(phba->pport, | |
7845 | LPFC_DISC_TRC_MBOX, | |
7846 | "MBOX Send: cmd:x%x mb:x%x x%x", | |
7847 | mbx_cmnd, mqe->un.mb_words[0], | |
7848 | mqe->un.mb_words[1]); | |
7849 | } | |
7850 | } | |
7851 | psli->slistat.mbox_cmd++; | |
7852 | ||
7853 | /* Post the mailbox command to the port */ | |
7854 | rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe); | |
7855 | if (rc != MBX_SUCCESS) { | |
7856 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
a183a15f | 7857 | "(%d):2533 Mailbox command x%x (x%x/x%x) " |
da0436e9 JS |
7858 | "cannot issue Data: x%x x%x\n", |
7859 | mboxq->vport ? mboxq->vport->vpi : 0, | |
7860 | mboxq->u.mb.mbxCommand, | |
a183a15f JS |
7861 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
7862 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), | |
da0436e9 JS |
7863 | psli->sli_flag, MBX_NOWAIT); |
7864 | goto out_not_finished; | |
7865 | } | |
7866 | ||
7867 | return rc; | |
7868 | ||
7869 | out_not_finished: | |
7870 | spin_lock_irqsave(&phba->hbalock, iflags); | |
d7069f09 JS |
7871 | if (phba->sli.mbox_active) { |
7872 | mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED; | |
7873 | __lpfc_mbox_cmpl_put(phba, mboxq); | |
7874 | /* Release the token */ | |
7875 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
7876 | phba->sli.mbox_active = NULL; | |
7877 | } | |
da0436e9 JS |
7878 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
7879 | ||
7880 | return MBX_NOT_FINISHED; | |
7881 | } | |
7882 | ||
7883 | /** | |
7884 | * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command | |
7885 | * @phba: Pointer to HBA context object. | |
7886 | * @pmbox: Pointer to mailbox object. | |
7887 | * @flag: Flag indicating how the mailbox need to be processed. | |
7888 | * | |
7889 | * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from | |
7890 | * the API jump table function pointer from the lpfc_hba struct. | |
7891 | * | |
7892 | * Return codes the caller owns the mailbox command after the return of the | |
7893 | * function. | |
7894 | **/ | |
7895 | int | |
7896 | lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag) | |
7897 | { | |
7898 | return phba->lpfc_sli_issue_mbox(phba, pmbox, flag); | |
7899 | } | |
7900 | ||
7901 | /** | |
25985edc | 7902 | * lpfc_mbox_api_table_setup - Set up mbox api function jump table |
da0436e9 JS |
7903 | * @phba: The hba struct for which this call is being executed. |
7904 | * @dev_grp: The HBA PCI-Device group number. | |
7905 | * | |
7906 | * This routine sets up the mbox interface API function jump table in @phba | |
7907 | * struct. | |
7908 | * Returns: 0 - success, -ENODEV - failure. | |
7909 | **/ | |
7910 | int | |
7911 | lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) | |
7912 | { | |
7913 | ||
7914 | switch (dev_grp) { | |
7915 | case LPFC_PCI_DEV_LP: | |
7916 | phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3; | |
7917 | phba->lpfc_sli_handle_slow_ring_event = | |
7918 | lpfc_sli_handle_slow_ring_event_s3; | |
7919 | phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3; | |
7920 | phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3; | |
7921 | phba->lpfc_sli_brdready = lpfc_sli_brdready_s3; | |
7922 | break; | |
7923 | case LPFC_PCI_DEV_OC: | |
7924 | phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4; | |
7925 | phba->lpfc_sli_handle_slow_ring_event = | |
7926 | lpfc_sli_handle_slow_ring_event_s4; | |
7927 | phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4; | |
7928 | phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4; | |
7929 | phba->lpfc_sli_brdready = lpfc_sli_brdready_s4; | |
7930 | break; | |
7931 | default: | |
7932 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7933 | "1420 Invalid HBA PCI-device group: 0x%x\n", | |
7934 | dev_grp); | |
7935 | return -ENODEV; | |
7936 | break; | |
7937 | } | |
7938 | return 0; | |
7939 | } | |
7940 | ||
e59058c4 | 7941 | /** |
3621a710 | 7942 | * __lpfc_sli_ringtx_put - Add an iocb to the txq |
e59058c4 JS |
7943 | * @phba: Pointer to HBA context object. |
7944 | * @pring: Pointer to driver SLI ring object. | |
7945 | * @piocb: Pointer to address of newly added command iocb. | |
7946 | * | |
7947 | * This function is called with hbalock held to add a command | |
7948 | * iocb to the txq when SLI layer cannot submit the command iocb | |
7949 | * to the ring. | |
7950 | **/ | |
2a9bf3d0 | 7951 | void |
92d7f7b0 | 7952 | __lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
2e0fef85 | 7953 | struct lpfc_iocbq *piocb) |
dea3101e | 7954 | { |
1c2ba475 | 7955 | lockdep_assert_held(&phba->hbalock); |
dea3101e JB |
7956 | /* Insert the caller's iocb in the txq tail for later processing. */ |
7957 | list_add_tail(&piocb->list, &pring->txq); | |
dea3101e JB |
7958 | } |
7959 | ||
e59058c4 | 7960 | /** |
3621a710 | 7961 | * lpfc_sli_next_iocb - Get the next iocb in the txq |
e59058c4 JS |
7962 | * @phba: Pointer to HBA context object. |
7963 | * @pring: Pointer to driver SLI ring object. | |
7964 | * @piocb: Pointer to address of newly added command iocb. | |
7965 | * | |
7966 | * This function is called with hbalock held before a new | |
7967 | * iocb is submitted to the firmware. This function checks | |
7968 | * txq to flush the iocbs in txq to Firmware before | |
7969 | * submitting new iocbs to the Firmware. | |
7970 | * If there are iocbs in the txq which need to be submitted | |
7971 | * to firmware, lpfc_sli_next_iocb returns the first element | |
7972 | * of the txq after dequeuing it from txq. | |
7973 | * If there is no iocb in the txq then the function will return | |
7974 | * *piocb and *piocb is set to NULL. Caller needs to check | |
7975 | * *piocb to find if there are more commands in the txq. | |
7976 | **/ | |
dea3101e JB |
7977 | static struct lpfc_iocbq * |
7978 | lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
2e0fef85 | 7979 | struct lpfc_iocbq **piocb) |
dea3101e JB |
7980 | { |
7981 | struct lpfc_iocbq * nextiocb; | |
7982 | ||
1c2ba475 JT |
7983 | lockdep_assert_held(&phba->hbalock); |
7984 | ||
dea3101e JB |
7985 | nextiocb = lpfc_sli_ringtx_get(phba, pring); |
7986 | if (!nextiocb) { | |
7987 | nextiocb = *piocb; | |
7988 | *piocb = NULL; | |
7989 | } | |
7990 | ||
7991 | return nextiocb; | |
7992 | } | |
7993 | ||
e59058c4 | 7994 | /** |
3772a991 | 7995 | * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb |
e59058c4 | 7996 | * @phba: Pointer to HBA context object. |
3772a991 | 7997 | * @ring_number: SLI ring number to issue iocb on. |
e59058c4 JS |
7998 | * @piocb: Pointer to command iocb. |
7999 | * @flag: Flag indicating if this command can be put into txq. | |
8000 | * | |
3772a991 JS |
8001 | * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue |
8002 | * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is | |
8003 | * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT | |
8004 | * flag is turned on, the function returns IOCB_ERROR. When the link is down, | |
8005 | * this function allows only iocbs for posting buffers. This function finds | |
8006 | * next available slot in the command ring and posts the command to the | |
8007 | * available slot and writes the port attention register to request HBA start | |
8008 | * processing new iocb. If there is no slot available in the ring and | |
8009 | * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise | |
8010 | * the function returns IOCB_BUSY. | |
e59058c4 | 8011 | * |
3772a991 JS |
8012 | * This function is called with hbalock held. The function will return success |
8013 | * after it successfully submit the iocb to firmware or after adding to the | |
8014 | * txq. | |
e59058c4 | 8015 | **/ |
98c9ea5c | 8016 | static int |
3772a991 | 8017 | __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number, |
dea3101e JB |
8018 | struct lpfc_iocbq *piocb, uint32_t flag) |
8019 | { | |
8020 | struct lpfc_iocbq *nextiocb; | |
8021 | IOCB_t *iocb; | |
3772a991 | 8022 | struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number]; |
dea3101e | 8023 | |
1c2ba475 JT |
8024 | lockdep_assert_held(&phba->hbalock); |
8025 | ||
92d7f7b0 JS |
8026 | if (piocb->iocb_cmpl && (!piocb->vport) && |
8027 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && | |
8028 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { | |
8029 | lpfc_printf_log(phba, KERN_ERR, | |
8030 | LOG_SLI | LOG_VPORT, | |
e8b62011 | 8031 | "1807 IOCB x%x failed. No vport\n", |
92d7f7b0 JS |
8032 | piocb->iocb.ulpCommand); |
8033 | dump_stack(); | |
8034 | return IOCB_ERROR; | |
8035 | } | |
8036 | ||
8037 | ||
8d63f375 LV |
8038 | /* If the PCI channel is in offline state, do not post iocbs. */ |
8039 | if (unlikely(pci_channel_offline(phba->pcidev))) | |
8040 | return IOCB_ERROR; | |
8041 | ||
a257bf90 JS |
8042 | /* If HBA has a deferred error attention, fail the iocb. */ |
8043 | if (unlikely(phba->hba_flag & DEFER_ERATT)) | |
8044 | return IOCB_ERROR; | |
8045 | ||
dea3101e JB |
8046 | /* |
8047 | * We should never get an IOCB if we are in a < LINK_DOWN state | |
8048 | */ | |
2e0fef85 | 8049 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
dea3101e JB |
8050 | return IOCB_ERROR; |
8051 | ||
8052 | /* | |
8053 | * Check to see if we are blocking IOCB processing because of a | |
0b727fea | 8054 | * outstanding event. |
dea3101e | 8055 | */ |
0b727fea | 8056 | if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT)) |
dea3101e JB |
8057 | goto iocb_busy; |
8058 | ||
2e0fef85 | 8059 | if (unlikely(phba->link_state == LPFC_LINK_DOWN)) { |
dea3101e | 8060 | /* |
2680eeaa | 8061 | * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF |
dea3101e JB |
8062 | * can be issued if the link is not up. |
8063 | */ | |
8064 | switch (piocb->iocb.ulpCommand) { | |
84774a4d JS |
8065 | case CMD_GEN_REQUEST64_CR: |
8066 | case CMD_GEN_REQUEST64_CX: | |
8067 | if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) || | |
8068 | (piocb->iocb.un.genreq64.w5.hcsw.Rctl != | |
6a9c52cf | 8069 | FC_RCTL_DD_UNSOL_CMD) || |
84774a4d JS |
8070 | (piocb->iocb.un.genreq64.w5.hcsw.Type != |
8071 | MENLO_TRANSPORT_TYPE)) | |
8072 | ||
8073 | goto iocb_busy; | |
8074 | break; | |
dea3101e JB |
8075 | case CMD_QUE_RING_BUF_CN: |
8076 | case CMD_QUE_RING_BUF64_CN: | |
dea3101e JB |
8077 | /* |
8078 | * For IOCBs, like QUE_RING_BUF, that have no rsp ring | |
8079 | * completion, iocb_cmpl MUST be 0. | |
8080 | */ | |
8081 | if (piocb->iocb_cmpl) | |
8082 | piocb->iocb_cmpl = NULL; | |
8083 | /*FALLTHROUGH*/ | |
8084 | case CMD_CREATE_XRI_CR: | |
2680eeaa JS |
8085 | case CMD_CLOSE_XRI_CN: |
8086 | case CMD_CLOSE_XRI_CX: | |
dea3101e JB |
8087 | break; |
8088 | default: | |
8089 | goto iocb_busy; | |
8090 | } | |
8091 | ||
8092 | /* | |
8093 | * For FCP commands, we must be in a state where we can process link | |
8094 | * attention events. | |
8095 | */ | |
8096 | } else if (unlikely(pring->ringno == phba->sli.fcp_ring && | |
92d7f7b0 | 8097 | !(phba->sli.sli_flag & LPFC_PROCESS_LA))) { |
dea3101e | 8098 | goto iocb_busy; |
92d7f7b0 | 8099 | } |
dea3101e | 8100 | |
dea3101e JB |
8101 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && |
8102 | (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb))) | |
8103 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); | |
8104 | ||
8105 | if (iocb) | |
8106 | lpfc_sli_update_ring(phba, pring); | |
8107 | else | |
8108 | lpfc_sli_update_full_ring(phba, pring); | |
8109 | ||
8110 | if (!piocb) | |
8111 | return IOCB_SUCCESS; | |
8112 | ||
8113 | goto out_busy; | |
8114 | ||
8115 | iocb_busy: | |
8116 | pring->stats.iocb_cmd_delay++; | |
8117 | ||
8118 | out_busy: | |
8119 | ||
8120 | if (!(flag & SLI_IOCB_RET_IOCB)) { | |
92d7f7b0 | 8121 | __lpfc_sli_ringtx_put(phba, pring, piocb); |
dea3101e JB |
8122 | return IOCB_SUCCESS; |
8123 | } | |
8124 | ||
8125 | return IOCB_BUSY; | |
8126 | } | |
8127 | ||
3772a991 | 8128 | /** |
4f774513 JS |
8129 | * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl. |
8130 | * @phba: Pointer to HBA context object. | |
8131 | * @piocb: Pointer to command iocb. | |
8132 | * @sglq: Pointer to the scatter gather queue object. | |
8133 | * | |
8134 | * This routine converts the bpl or bde that is in the IOCB | |
8135 | * to a sgl list for the sli4 hardware. The physical address | |
8136 | * of the bpl/bde is converted back to a virtual address. | |
8137 | * If the IOCB contains a BPL then the list of BDE's is | |
8138 | * converted to sli4_sge's. If the IOCB contains a single | |
8139 | * BDE then it is converted to a single sli_sge. | |
8140 | * The IOCB is still in cpu endianess so the contents of | |
8141 | * the bpl can be used without byte swapping. | |
8142 | * | |
8143 | * Returns valid XRI = Success, NO_XRI = Failure. | |
8144 | **/ | |
8145 | static uint16_t | |
8146 | lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq, | |
8147 | struct lpfc_sglq *sglq) | |
3772a991 | 8148 | { |
4f774513 JS |
8149 | uint16_t xritag = NO_XRI; |
8150 | struct ulp_bde64 *bpl = NULL; | |
8151 | struct ulp_bde64 bde; | |
8152 | struct sli4_sge *sgl = NULL; | |
1b51197d | 8153 | struct lpfc_dmabuf *dmabuf; |
4f774513 JS |
8154 | IOCB_t *icmd; |
8155 | int numBdes = 0; | |
8156 | int i = 0; | |
63e801ce JS |
8157 | uint32_t offset = 0; /* accumulated offset in the sg request list */ |
8158 | int inbound = 0; /* number of sg reply entries inbound from firmware */ | |
3772a991 | 8159 | |
4f774513 JS |
8160 | if (!piocbq || !sglq) |
8161 | return xritag; | |
8162 | ||
8163 | sgl = (struct sli4_sge *)sglq->sgl; | |
8164 | icmd = &piocbq->iocb; | |
6b5151fd JS |
8165 | if (icmd->ulpCommand == CMD_XMIT_BLS_RSP64_CX) |
8166 | return sglq->sli4_xritag; | |
4f774513 JS |
8167 | if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) { |
8168 | numBdes = icmd->un.genreq64.bdl.bdeSize / | |
8169 | sizeof(struct ulp_bde64); | |
8170 | /* The addrHigh and addrLow fields within the IOCB | |
8171 | * have not been byteswapped yet so there is no | |
8172 | * need to swap them back. | |
8173 | */ | |
1b51197d JS |
8174 | if (piocbq->context3) |
8175 | dmabuf = (struct lpfc_dmabuf *)piocbq->context3; | |
8176 | else | |
8177 | return xritag; | |
4f774513 | 8178 | |
1b51197d | 8179 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
4f774513 JS |
8180 | if (!bpl) |
8181 | return xritag; | |
8182 | ||
8183 | for (i = 0; i < numBdes; i++) { | |
8184 | /* Should already be byte swapped. */ | |
28baac74 JS |
8185 | sgl->addr_hi = bpl->addrHigh; |
8186 | sgl->addr_lo = bpl->addrLow; | |
8187 | ||
0558056c | 8188 | sgl->word2 = le32_to_cpu(sgl->word2); |
4f774513 JS |
8189 | if ((i+1) == numBdes) |
8190 | bf_set(lpfc_sli4_sge_last, sgl, 1); | |
8191 | else | |
8192 | bf_set(lpfc_sli4_sge_last, sgl, 0); | |
28baac74 JS |
8193 | /* swap the size field back to the cpu so we |
8194 | * can assign it to the sgl. | |
8195 | */ | |
8196 | bde.tus.w = le32_to_cpu(bpl->tus.w); | |
8197 | sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize); | |
63e801ce JS |
8198 | /* The offsets in the sgl need to be accumulated |
8199 | * separately for the request and reply lists. | |
8200 | * The request is always first, the reply follows. | |
8201 | */ | |
8202 | if (piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) { | |
8203 | /* add up the reply sg entries */ | |
8204 | if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I) | |
8205 | inbound++; | |
8206 | /* first inbound? reset the offset */ | |
8207 | if (inbound == 1) | |
8208 | offset = 0; | |
8209 | bf_set(lpfc_sli4_sge_offset, sgl, offset); | |
f9bb2da1 JS |
8210 | bf_set(lpfc_sli4_sge_type, sgl, |
8211 | LPFC_SGE_TYPE_DATA); | |
63e801ce JS |
8212 | offset += bde.tus.f.bdeSize; |
8213 | } | |
546fc854 | 8214 | sgl->word2 = cpu_to_le32(sgl->word2); |
4f774513 JS |
8215 | bpl++; |
8216 | sgl++; | |
8217 | } | |
8218 | } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) { | |
8219 | /* The addrHigh and addrLow fields of the BDE have not | |
8220 | * been byteswapped yet so they need to be swapped | |
8221 | * before putting them in the sgl. | |
8222 | */ | |
8223 | sgl->addr_hi = | |
8224 | cpu_to_le32(icmd->un.genreq64.bdl.addrHigh); | |
8225 | sgl->addr_lo = | |
8226 | cpu_to_le32(icmd->un.genreq64.bdl.addrLow); | |
0558056c | 8227 | sgl->word2 = le32_to_cpu(sgl->word2); |
4f774513 JS |
8228 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
8229 | sgl->word2 = cpu_to_le32(sgl->word2); | |
28baac74 JS |
8230 | sgl->sge_len = |
8231 | cpu_to_le32(icmd->un.genreq64.bdl.bdeSize); | |
4f774513 JS |
8232 | } |
8233 | return sglq->sli4_xritag; | |
3772a991 | 8234 | } |
92d7f7b0 | 8235 | |
e59058c4 | 8236 | /** |
4f774513 | 8237 | * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry. |
e59058c4 | 8238 | * @phba: Pointer to HBA context object. |
4f774513 JS |
8239 | * @piocb: Pointer to command iocb. |
8240 | * @wqe: Pointer to the work queue entry. | |
e59058c4 | 8241 | * |
4f774513 JS |
8242 | * This routine converts the iocb command to its Work Queue Entry |
8243 | * equivalent. The wqe pointer should not have any fields set when | |
8244 | * this routine is called because it will memcpy over them. | |
8245 | * This routine does not set the CQ_ID or the WQEC bits in the | |
8246 | * wqe. | |
e59058c4 | 8247 | * |
4f774513 | 8248 | * Returns: 0 = Success, IOCB_ERROR = Failure. |
e59058c4 | 8249 | **/ |
cf5bf97e | 8250 | static int |
4f774513 JS |
8251 | lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq, |
8252 | union lpfc_wqe *wqe) | |
cf5bf97e | 8253 | { |
5ffc266e | 8254 | uint32_t xmit_len = 0, total_len = 0; |
4f774513 JS |
8255 | uint8_t ct = 0; |
8256 | uint32_t fip; | |
8257 | uint32_t abort_tag; | |
8258 | uint8_t command_type = ELS_COMMAND_NON_FIP; | |
8259 | uint8_t cmnd; | |
8260 | uint16_t xritag; | |
dcf2a4e0 JS |
8261 | uint16_t abrt_iotag; |
8262 | struct lpfc_iocbq *abrtiocbq; | |
4f774513 | 8263 | struct ulp_bde64 *bpl = NULL; |
f0d9bccc | 8264 | uint32_t els_id = LPFC_ELS_ID_DEFAULT; |
5ffc266e JS |
8265 | int numBdes, i; |
8266 | struct ulp_bde64 bde; | |
c31098ce | 8267 | struct lpfc_nodelist *ndlp; |
ff78d8f9 | 8268 | uint32_t *pcmd; |
1b51197d | 8269 | uint32_t if_type; |
4f774513 | 8270 | |
45ed1190 | 8271 | fip = phba->hba_flag & HBA_FIP_SUPPORT; |
4f774513 | 8272 | /* The fcp commands will set command type */ |
0c287589 | 8273 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
4f774513 | 8274 | command_type = FCP_COMMAND; |
c868595d | 8275 | else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)) |
0c287589 JS |
8276 | command_type = ELS_COMMAND_FIP; |
8277 | else | |
8278 | command_type = ELS_COMMAND_NON_FIP; | |
8279 | ||
b5c53958 JS |
8280 | if (phba->fcp_embed_io) |
8281 | memset(wqe, 0, sizeof(union lpfc_wqe128)); | |
4f774513 JS |
8282 | /* Some of the fields are in the right position already */ |
8283 | memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe)); | |
f0d9bccc | 8284 | wqe->generic.wqe_com.word7 = 0; /* The ct field has moved so reset */ |
28d7f3df | 8285 | wqe->generic.wqe_com.word10 = 0; |
b5c53958 JS |
8286 | |
8287 | abort_tag = (uint32_t) iocbq->iotag; | |
8288 | xritag = iocbq->sli4_xritag; | |
4f774513 JS |
8289 | /* words0-2 bpl convert bde */ |
8290 | if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) { | |
5ffc266e JS |
8291 | numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize / |
8292 | sizeof(struct ulp_bde64); | |
4f774513 JS |
8293 | bpl = (struct ulp_bde64 *) |
8294 | ((struct lpfc_dmabuf *)iocbq->context3)->virt; | |
8295 | if (!bpl) | |
8296 | return IOCB_ERROR; | |
cf5bf97e | 8297 | |
4f774513 JS |
8298 | /* Should already be byte swapped. */ |
8299 | wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh); | |
8300 | wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow); | |
8301 | /* swap the size field back to the cpu so we | |
8302 | * can assign it to the sgl. | |
8303 | */ | |
8304 | wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w); | |
5ffc266e JS |
8305 | xmit_len = wqe->generic.bde.tus.f.bdeSize; |
8306 | total_len = 0; | |
8307 | for (i = 0; i < numBdes; i++) { | |
8308 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); | |
8309 | total_len += bde.tus.f.bdeSize; | |
8310 | } | |
4f774513 | 8311 | } else |
5ffc266e | 8312 | xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize; |
cf5bf97e | 8313 | |
4f774513 JS |
8314 | iocbq->iocb.ulpIoTag = iocbq->iotag; |
8315 | cmnd = iocbq->iocb.ulpCommand; | |
a4bc3379 | 8316 | |
4f774513 JS |
8317 | switch (iocbq->iocb.ulpCommand) { |
8318 | case CMD_ELS_REQUEST64_CR: | |
93d1379e JS |
8319 | if (iocbq->iocb_flag & LPFC_IO_LIBDFC) |
8320 | ndlp = iocbq->context_un.ndlp; | |
8321 | else | |
8322 | ndlp = (struct lpfc_nodelist *)iocbq->context1; | |
4f774513 JS |
8323 | if (!iocbq->iocb.ulpLe) { |
8324 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
8325 | "2007 Only Limited Edition cmd Format" | |
8326 | " supported 0x%x\n", | |
8327 | iocbq->iocb.ulpCommand); | |
8328 | return IOCB_ERROR; | |
8329 | } | |
ff78d8f9 | 8330 | |
5ffc266e | 8331 | wqe->els_req.payload_len = xmit_len; |
4f774513 JS |
8332 | /* Els_reguest64 has a TMO */ |
8333 | bf_set(wqe_tmo, &wqe->els_req.wqe_com, | |
8334 | iocbq->iocb.ulpTimeout); | |
8335 | /* Need a VF for word 4 set the vf bit*/ | |
8336 | bf_set(els_req64_vf, &wqe->els_req, 0); | |
8337 | /* And a VFID for word 12 */ | |
8338 | bf_set(els_req64_vfid, &wqe->els_req, 0); | |
4f774513 | 8339 | ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l); |
f0d9bccc JS |
8340 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
8341 | iocbq->iocb.ulpContext); | |
8342 | bf_set(wqe_ct, &wqe->els_req.wqe_com, ct); | |
8343 | bf_set(wqe_pu, &wqe->els_req.wqe_com, 0); | |
4f774513 | 8344 | /* CCP CCPE PV PRI in word10 were set in the memcpy */ |
ff78d8f9 | 8345 | if (command_type == ELS_COMMAND_FIP) |
c868595d JS |
8346 | els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK) |
8347 | >> LPFC_FIP_ELS_ID_SHIFT); | |
ff78d8f9 JS |
8348 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
8349 | iocbq->context2)->virt); | |
1b51197d JS |
8350 | if_type = bf_get(lpfc_sli_intf_if_type, |
8351 | &phba->sli4_hba.sli_intf); | |
8352 | if (if_type == LPFC_SLI_INTF_IF_TYPE_2) { | |
ff78d8f9 | 8353 | if (pcmd && (*pcmd == ELS_CMD_FLOGI || |
cb69f7de | 8354 | *pcmd == ELS_CMD_SCR || |
6b5151fd | 8355 | *pcmd == ELS_CMD_FDISC || |
bdcd2b92 | 8356 | *pcmd == ELS_CMD_LOGO || |
ff78d8f9 JS |
8357 | *pcmd == ELS_CMD_PLOGI)) { |
8358 | bf_set(els_req64_sp, &wqe->els_req, 1); | |
8359 | bf_set(els_req64_sid, &wqe->els_req, | |
8360 | iocbq->vport->fc_myDID); | |
939723a4 JS |
8361 | if ((*pcmd == ELS_CMD_FLOGI) && |
8362 | !(phba->fc_topology == | |
8363 | LPFC_TOPOLOGY_LOOP)) | |
8364 | bf_set(els_req64_sid, &wqe->els_req, 0); | |
ff78d8f9 JS |
8365 | bf_set(wqe_ct, &wqe->els_req.wqe_com, 1); |
8366 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, | |
a7dd9c0f | 8367 | phba->vpi_ids[iocbq->vport->vpi]); |
3ef6d24c | 8368 | } else if (pcmd && iocbq->context1) { |
ff78d8f9 JS |
8369 | bf_set(wqe_ct, &wqe->els_req.wqe_com, 0); |
8370 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, | |
8371 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); | |
8372 | } | |
c868595d | 8373 | } |
6d368e53 JS |
8374 | bf_set(wqe_temp_rpi, &wqe->els_req.wqe_com, |
8375 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); | |
f0d9bccc JS |
8376 | bf_set(wqe_els_id, &wqe->els_req.wqe_com, els_id); |
8377 | bf_set(wqe_dbde, &wqe->els_req.wqe_com, 1); | |
8378 | bf_set(wqe_iod, &wqe->els_req.wqe_com, LPFC_WQE_IOD_READ); | |
8379 | bf_set(wqe_qosd, &wqe->els_req.wqe_com, 1); | |
8380 | bf_set(wqe_lenloc, &wqe->els_req.wqe_com, LPFC_WQE_LENLOC_NONE); | |
8381 | bf_set(wqe_ebde_cnt, &wqe->els_req.wqe_com, 0); | |
af22741c | 8382 | wqe->els_req.max_response_payload_len = total_len - xmit_len; |
7851fe2c | 8383 | break; |
5ffc266e | 8384 | case CMD_XMIT_SEQUENCE64_CX: |
f0d9bccc JS |
8385 | bf_set(wqe_ctxt_tag, &wqe->xmit_sequence.wqe_com, |
8386 | iocbq->iocb.un.ulpWord[3]); | |
8387 | bf_set(wqe_rcvoxid, &wqe->xmit_sequence.wqe_com, | |
7851fe2c | 8388 | iocbq->iocb.unsli3.rcvsli3.ox_id); |
5ffc266e JS |
8389 | /* The entire sequence is transmitted for this IOCB */ |
8390 | xmit_len = total_len; | |
8391 | cmnd = CMD_XMIT_SEQUENCE64_CR; | |
1b51197d JS |
8392 | if (phba->link_flag & LS_LOOPBACK_MODE) |
8393 | bf_set(wqe_xo, &wqe->xmit_sequence.wge_ctl, 1); | |
4f774513 | 8394 | case CMD_XMIT_SEQUENCE64_CR: |
f0d9bccc JS |
8395 | /* word3 iocb=io_tag32 wqe=reserved */ |
8396 | wqe->xmit_sequence.rsvd3 = 0; | |
4f774513 JS |
8397 | /* word4 relative_offset memcpy */ |
8398 | /* word5 r_ctl/df_ctl memcpy */ | |
f0d9bccc JS |
8399 | bf_set(wqe_pu, &wqe->xmit_sequence.wqe_com, 0); |
8400 | bf_set(wqe_dbde, &wqe->xmit_sequence.wqe_com, 1); | |
8401 | bf_set(wqe_iod, &wqe->xmit_sequence.wqe_com, | |
8402 | LPFC_WQE_IOD_WRITE); | |
8403 | bf_set(wqe_lenloc, &wqe->xmit_sequence.wqe_com, | |
8404 | LPFC_WQE_LENLOC_WORD12); | |
8405 | bf_set(wqe_ebde_cnt, &wqe->xmit_sequence.wqe_com, 0); | |
5ffc266e JS |
8406 | wqe->xmit_sequence.xmit_len = xmit_len; |
8407 | command_type = OTHER_COMMAND; | |
7851fe2c | 8408 | break; |
4f774513 | 8409 | case CMD_XMIT_BCAST64_CN: |
f0d9bccc JS |
8410 | /* word3 iocb=iotag32 wqe=seq_payload_len */ |
8411 | wqe->xmit_bcast64.seq_payload_len = xmit_len; | |
4f774513 JS |
8412 | /* word4 iocb=rsvd wqe=rsvd */ |
8413 | /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */ | |
8414 | /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */ | |
f0d9bccc | 8415 | bf_set(wqe_ct, &wqe->xmit_bcast64.wqe_com, |
4f774513 | 8416 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
f0d9bccc JS |
8417 | bf_set(wqe_dbde, &wqe->xmit_bcast64.wqe_com, 1); |
8418 | bf_set(wqe_iod, &wqe->xmit_bcast64.wqe_com, LPFC_WQE_IOD_WRITE); | |
8419 | bf_set(wqe_lenloc, &wqe->xmit_bcast64.wqe_com, | |
8420 | LPFC_WQE_LENLOC_WORD3); | |
8421 | bf_set(wqe_ebde_cnt, &wqe->xmit_bcast64.wqe_com, 0); | |
7851fe2c | 8422 | break; |
4f774513 JS |
8423 | case CMD_FCP_IWRITE64_CR: |
8424 | command_type = FCP_COMMAND_DATA_OUT; | |
f0d9bccc JS |
8425 | /* word3 iocb=iotag wqe=payload_offset_len */ |
8426 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ | |
0ba4b219 JS |
8427 | bf_set(payload_offset_len, &wqe->fcp_iwrite, |
8428 | xmit_len + sizeof(struct fcp_rsp)); | |
8429 | bf_set(cmd_buff_len, &wqe->fcp_iwrite, | |
8430 | 0); | |
f0d9bccc JS |
8431 | /* word4 iocb=parameter wqe=total_xfer_length memcpy */ |
8432 | /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */ | |
8433 | bf_set(wqe_erp, &wqe->fcp_iwrite.wqe_com, | |
8434 | iocbq->iocb.ulpFCP2Rcvy); | |
8435 | bf_set(wqe_lnk, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpXS); | |
8436 | /* Always open the exchange */ | |
f0d9bccc JS |
8437 | bf_set(wqe_iod, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_IOD_WRITE); |
8438 | bf_set(wqe_lenloc, &wqe->fcp_iwrite.wqe_com, | |
8439 | LPFC_WQE_LENLOC_WORD4); | |
f0d9bccc | 8440 | bf_set(wqe_pu, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpPU); |
acd6859b | 8441 | bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 1); |
1ba981fd JS |
8442 | if (iocbq->iocb_flag & LPFC_IO_OAS) { |
8443 | bf_set(wqe_oas, &wqe->fcp_iwrite.wqe_com, 1); | |
8444 | if (phba->cfg_XLanePriority) { | |
8445 | bf_set(wqe_ccpe, &wqe->fcp_iwrite.wqe_com, 1); | |
8446 | bf_set(wqe_ccp, &wqe->fcp_iwrite.wqe_com, | |
8447 | (phba->cfg_XLanePriority << 1)); | |
8448 | } | |
8449 | } | |
b5c53958 JS |
8450 | /* Note, word 10 is already initialized to 0 */ |
8451 | ||
8452 | if (phba->fcp_embed_io) { | |
8453 | struct lpfc_scsi_buf *lpfc_cmd; | |
8454 | struct sli4_sge *sgl; | |
8455 | union lpfc_wqe128 *wqe128; | |
8456 | struct fcp_cmnd *fcp_cmnd; | |
8457 | uint32_t *ptr; | |
8458 | ||
8459 | /* 128 byte wqe support here */ | |
8460 | wqe128 = (union lpfc_wqe128 *)wqe; | |
8461 | ||
8462 | lpfc_cmd = iocbq->context1; | |
8463 | sgl = (struct sli4_sge *)lpfc_cmd->fcp_bpl; | |
8464 | fcp_cmnd = lpfc_cmd->fcp_cmnd; | |
8465 | ||
8466 | /* Word 0-2 - FCP_CMND */ | |
8467 | wqe128->generic.bde.tus.f.bdeFlags = | |
8468 | BUFF_TYPE_BDE_IMMED; | |
8469 | wqe128->generic.bde.tus.f.bdeSize = sgl->sge_len; | |
8470 | wqe128->generic.bde.addrHigh = 0; | |
8471 | wqe128->generic.bde.addrLow = 88; /* Word 22 */ | |
8472 | ||
8473 | bf_set(wqe_wqes, &wqe128->fcp_iwrite.wqe_com, 1); | |
8474 | ||
8475 | /* Word 22-29 FCP CMND Payload */ | |
8476 | ptr = &wqe128->words[22]; | |
8477 | memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd)); | |
8478 | } | |
7851fe2c | 8479 | break; |
4f774513 | 8480 | case CMD_FCP_IREAD64_CR: |
f0d9bccc JS |
8481 | /* word3 iocb=iotag wqe=payload_offset_len */ |
8482 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ | |
0ba4b219 JS |
8483 | bf_set(payload_offset_len, &wqe->fcp_iread, |
8484 | xmit_len + sizeof(struct fcp_rsp)); | |
8485 | bf_set(cmd_buff_len, &wqe->fcp_iread, | |
8486 | 0); | |
f0d9bccc JS |
8487 | /* word4 iocb=parameter wqe=total_xfer_length memcpy */ |
8488 | /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */ | |
8489 | bf_set(wqe_erp, &wqe->fcp_iread.wqe_com, | |
8490 | iocbq->iocb.ulpFCP2Rcvy); | |
8491 | bf_set(wqe_lnk, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpXS); | |
f1126688 | 8492 | /* Always open the exchange */ |
f0d9bccc JS |
8493 | bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, LPFC_WQE_IOD_READ); |
8494 | bf_set(wqe_lenloc, &wqe->fcp_iread.wqe_com, | |
8495 | LPFC_WQE_LENLOC_WORD4); | |
f0d9bccc | 8496 | bf_set(wqe_pu, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpPU); |
acd6859b | 8497 | bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 1); |
1ba981fd JS |
8498 | if (iocbq->iocb_flag & LPFC_IO_OAS) { |
8499 | bf_set(wqe_oas, &wqe->fcp_iread.wqe_com, 1); | |
8500 | if (phba->cfg_XLanePriority) { | |
8501 | bf_set(wqe_ccpe, &wqe->fcp_iread.wqe_com, 1); | |
8502 | bf_set(wqe_ccp, &wqe->fcp_iread.wqe_com, | |
8503 | (phba->cfg_XLanePriority << 1)); | |
8504 | } | |
8505 | } | |
b5c53958 JS |
8506 | /* Note, word 10 is already initialized to 0 */ |
8507 | ||
8508 | if (phba->fcp_embed_io) { | |
8509 | struct lpfc_scsi_buf *lpfc_cmd; | |
8510 | struct sli4_sge *sgl; | |
8511 | union lpfc_wqe128 *wqe128; | |
8512 | struct fcp_cmnd *fcp_cmnd; | |
8513 | uint32_t *ptr; | |
8514 | ||
8515 | /* 128 byte wqe support here */ | |
8516 | wqe128 = (union lpfc_wqe128 *)wqe; | |
8517 | ||
8518 | lpfc_cmd = iocbq->context1; | |
8519 | sgl = (struct sli4_sge *)lpfc_cmd->fcp_bpl; | |
8520 | fcp_cmnd = lpfc_cmd->fcp_cmnd; | |
8521 | ||
8522 | /* Word 0-2 - FCP_CMND */ | |
8523 | wqe128->generic.bde.tus.f.bdeFlags = | |
8524 | BUFF_TYPE_BDE_IMMED; | |
8525 | wqe128->generic.bde.tus.f.bdeSize = sgl->sge_len; | |
8526 | wqe128->generic.bde.addrHigh = 0; | |
8527 | wqe128->generic.bde.addrLow = 88; /* Word 22 */ | |
8528 | ||
8529 | bf_set(wqe_wqes, &wqe128->fcp_iread.wqe_com, 1); | |
8530 | ||
8531 | /* Word 22-29 FCP CMND Payload */ | |
8532 | ptr = &wqe128->words[22]; | |
8533 | memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd)); | |
8534 | } | |
7851fe2c | 8535 | break; |
4f774513 | 8536 | case CMD_FCP_ICMND64_CR: |
0ba4b219 JS |
8537 | /* word3 iocb=iotag wqe=payload_offset_len */ |
8538 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ | |
8539 | bf_set(payload_offset_len, &wqe->fcp_icmd, | |
8540 | xmit_len + sizeof(struct fcp_rsp)); | |
8541 | bf_set(cmd_buff_len, &wqe->fcp_icmd, | |
8542 | 0); | |
f0d9bccc | 8543 | /* word3 iocb=IO_TAG wqe=reserved */ |
f0d9bccc | 8544 | bf_set(wqe_pu, &wqe->fcp_icmd.wqe_com, 0); |
4f774513 | 8545 | /* Always open the exchange */ |
f0d9bccc JS |
8546 | bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 1); |
8547 | bf_set(wqe_iod, &wqe->fcp_icmd.wqe_com, LPFC_WQE_IOD_WRITE); | |
8548 | bf_set(wqe_qosd, &wqe->fcp_icmd.wqe_com, 1); | |
8549 | bf_set(wqe_lenloc, &wqe->fcp_icmd.wqe_com, | |
8550 | LPFC_WQE_LENLOC_NONE); | |
2a94aea4 JS |
8551 | bf_set(wqe_erp, &wqe->fcp_icmd.wqe_com, |
8552 | iocbq->iocb.ulpFCP2Rcvy); | |
1ba981fd JS |
8553 | if (iocbq->iocb_flag & LPFC_IO_OAS) { |
8554 | bf_set(wqe_oas, &wqe->fcp_icmd.wqe_com, 1); | |
8555 | if (phba->cfg_XLanePriority) { | |
8556 | bf_set(wqe_ccpe, &wqe->fcp_icmd.wqe_com, 1); | |
8557 | bf_set(wqe_ccp, &wqe->fcp_icmd.wqe_com, | |
8558 | (phba->cfg_XLanePriority << 1)); | |
8559 | } | |
8560 | } | |
b5c53958 JS |
8561 | /* Note, word 10 is already initialized to 0 */ |
8562 | ||
8563 | if (phba->fcp_embed_io) { | |
8564 | struct lpfc_scsi_buf *lpfc_cmd; | |
8565 | struct sli4_sge *sgl; | |
8566 | union lpfc_wqe128 *wqe128; | |
8567 | struct fcp_cmnd *fcp_cmnd; | |
8568 | uint32_t *ptr; | |
8569 | ||
8570 | /* 128 byte wqe support here */ | |
8571 | wqe128 = (union lpfc_wqe128 *)wqe; | |
8572 | ||
8573 | lpfc_cmd = iocbq->context1; | |
8574 | sgl = (struct sli4_sge *)lpfc_cmd->fcp_bpl; | |
8575 | fcp_cmnd = lpfc_cmd->fcp_cmnd; | |
8576 | ||
8577 | /* Word 0-2 - FCP_CMND */ | |
8578 | wqe128->generic.bde.tus.f.bdeFlags = | |
8579 | BUFF_TYPE_BDE_IMMED; | |
8580 | wqe128->generic.bde.tus.f.bdeSize = sgl->sge_len; | |
8581 | wqe128->generic.bde.addrHigh = 0; | |
8582 | wqe128->generic.bde.addrLow = 88; /* Word 22 */ | |
8583 | ||
8584 | bf_set(wqe_wqes, &wqe128->fcp_icmd.wqe_com, 1); | |
8585 | ||
8586 | /* Word 22-29 FCP CMND Payload */ | |
8587 | ptr = &wqe128->words[22]; | |
8588 | memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd)); | |
8589 | } | |
7851fe2c | 8590 | break; |
4f774513 | 8591 | case CMD_GEN_REQUEST64_CR: |
63e801ce JS |
8592 | /* For this command calculate the xmit length of the |
8593 | * request bde. | |
8594 | */ | |
8595 | xmit_len = 0; | |
8596 | numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize / | |
8597 | sizeof(struct ulp_bde64); | |
8598 | for (i = 0; i < numBdes; i++) { | |
63e801ce | 8599 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
546fc854 JS |
8600 | if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64) |
8601 | break; | |
63e801ce JS |
8602 | xmit_len += bde.tus.f.bdeSize; |
8603 | } | |
f0d9bccc JS |
8604 | /* word3 iocb=IO_TAG wqe=request_payload_len */ |
8605 | wqe->gen_req.request_payload_len = xmit_len; | |
8606 | /* word4 iocb=parameter wqe=relative_offset memcpy */ | |
8607 | /* word5 [rctl, type, df_ctl, la] copied in memcpy */ | |
4f774513 JS |
8608 | /* word6 context tag copied in memcpy */ |
8609 | if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) { | |
8610 | ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l); | |
8611 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
8612 | "2015 Invalid CT %x command 0x%x\n", | |
8613 | ct, iocbq->iocb.ulpCommand); | |
8614 | return IOCB_ERROR; | |
8615 | } | |
f0d9bccc JS |
8616 | bf_set(wqe_ct, &wqe->gen_req.wqe_com, 0); |
8617 | bf_set(wqe_tmo, &wqe->gen_req.wqe_com, iocbq->iocb.ulpTimeout); | |
8618 | bf_set(wqe_pu, &wqe->gen_req.wqe_com, iocbq->iocb.ulpPU); | |
8619 | bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1); | |
8620 | bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ); | |
8621 | bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1); | |
8622 | bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE); | |
8623 | bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0); | |
af22741c | 8624 | wqe->gen_req.max_response_payload_len = total_len - xmit_len; |
4f774513 | 8625 | command_type = OTHER_COMMAND; |
7851fe2c | 8626 | break; |
4f774513 | 8627 | case CMD_XMIT_ELS_RSP64_CX: |
c31098ce | 8628 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
4f774513 | 8629 | /* words0-2 BDE memcpy */ |
f0d9bccc JS |
8630 | /* word3 iocb=iotag32 wqe=response_payload_len */ |
8631 | wqe->xmit_els_rsp.response_payload_len = xmit_len; | |
939723a4 JS |
8632 | /* word4 */ |
8633 | wqe->xmit_els_rsp.word4 = 0; | |
4f774513 JS |
8634 | /* word5 iocb=rsvd wge=did */ |
8635 | bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest, | |
939723a4 JS |
8636 | iocbq->iocb.un.xseq64.xmit_els_remoteID); |
8637 | ||
8638 | if_type = bf_get(lpfc_sli_intf_if_type, | |
8639 | &phba->sli4_hba.sli_intf); | |
8640 | if (if_type == LPFC_SLI_INTF_IF_TYPE_2) { | |
8641 | if (iocbq->vport->fc_flag & FC_PT2PT) { | |
8642 | bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1); | |
8643 | bf_set(els_rsp64_sid, &wqe->xmit_els_rsp, | |
8644 | iocbq->vport->fc_myDID); | |
8645 | if (iocbq->vport->fc_myDID == Fabric_DID) { | |
8646 | bf_set(wqe_els_did, | |
8647 | &wqe->xmit_els_rsp.wqe_dest, 0); | |
8648 | } | |
8649 | } | |
8650 | } | |
f0d9bccc JS |
8651 | bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, |
8652 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); | |
8653 | bf_set(wqe_pu, &wqe->xmit_els_rsp.wqe_com, iocbq->iocb.ulpPU); | |
8654 | bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com, | |
7851fe2c | 8655 | iocbq->iocb.unsli3.rcvsli3.ox_id); |
4f774513 | 8656 | if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l) |
f0d9bccc | 8657 | bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, |
6d368e53 | 8658 | phba->vpi_ids[iocbq->vport->vpi]); |
f0d9bccc JS |
8659 | bf_set(wqe_dbde, &wqe->xmit_els_rsp.wqe_com, 1); |
8660 | bf_set(wqe_iod, &wqe->xmit_els_rsp.wqe_com, LPFC_WQE_IOD_WRITE); | |
8661 | bf_set(wqe_qosd, &wqe->xmit_els_rsp.wqe_com, 1); | |
8662 | bf_set(wqe_lenloc, &wqe->xmit_els_rsp.wqe_com, | |
8663 | LPFC_WQE_LENLOC_WORD3); | |
8664 | bf_set(wqe_ebde_cnt, &wqe->xmit_els_rsp.wqe_com, 0); | |
6d368e53 JS |
8665 | bf_set(wqe_rsp_temp_rpi, &wqe->xmit_els_rsp, |
8666 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); | |
ff78d8f9 JS |
8667 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
8668 | iocbq->context2)->virt); | |
8669 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { | |
939723a4 JS |
8670 | bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1); |
8671 | bf_set(els_rsp64_sid, &wqe->xmit_els_rsp, | |
ff78d8f9 | 8672 | iocbq->vport->fc_myDID); |
939723a4 JS |
8673 | bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, 1); |
8674 | bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, | |
ff78d8f9 JS |
8675 | phba->vpi_ids[phba->pport->vpi]); |
8676 | } | |
4f774513 | 8677 | command_type = OTHER_COMMAND; |
7851fe2c | 8678 | break; |
4f774513 JS |
8679 | case CMD_CLOSE_XRI_CN: |
8680 | case CMD_ABORT_XRI_CN: | |
8681 | case CMD_ABORT_XRI_CX: | |
8682 | /* words 0-2 memcpy should be 0 rserved */ | |
8683 | /* port will send abts */ | |
dcf2a4e0 JS |
8684 | abrt_iotag = iocbq->iocb.un.acxri.abortContextTag; |
8685 | if (abrt_iotag != 0 && abrt_iotag <= phba->sli.last_iotag) { | |
8686 | abrtiocbq = phba->sli.iocbq_lookup[abrt_iotag]; | |
8687 | fip = abrtiocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK; | |
8688 | } else | |
8689 | fip = 0; | |
8690 | ||
8691 | if ((iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN) || fip) | |
4f774513 | 8692 | /* |
dcf2a4e0 JS |
8693 | * The link is down, or the command was ELS_FIP |
8694 | * so the fw does not need to send abts | |
4f774513 JS |
8695 | * on the wire. |
8696 | */ | |
8697 | bf_set(abort_cmd_ia, &wqe->abort_cmd, 1); | |
8698 | else | |
8699 | bf_set(abort_cmd_ia, &wqe->abort_cmd, 0); | |
8700 | bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG); | |
f0d9bccc JS |
8701 | /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */ |
8702 | wqe->abort_cmd.rsrvd5 = 0; | |
8703 | bf_set(wqe_ct, &wqe->abort_cmd.wqe_com, | |
4f774513 JS |
8704 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
8705 | abort_tag = iocbq->iocb.un.acxri.abortIoTag; | |
4f774513 JS |
8706 | /* |
8707 | * The abort handler will send us CMD_ABORT_XRI_CN or | |
8708 | * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX | |
8709 | */ | |
f0d9bccc JS |
8710 | bf_set(wqe_cmnd, &wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX); |
8711 | bf_set(wqe_qosd, &wqe->abort_cmd.wqe_com, 1); | |
8712 | bf_set(wqe_lenloc, &wqe->abort_cmd.wqe_com, | |
8713 | LPFC_WQE_LENLOC_NONE); | |
4f774513 JS |
8714 | cmnd = CMD_ABORT_XRI_CX; |
8715 | command_type = OTHER_COMMAND; | |
8716 | xritag = 0; | |
7851fe2c | 8717 | break; |
6669f9bb | 8718 | case CMD_XMIT_BLS_RSP64_CX: |
6b5151fd | 8719 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
546fc854 | 8720 | /* As BLS ABTS RSP WQE is very different from other WQEs, |
6669f9bb JS |
8721 | * we re-construct this WQE here based on information in |
8722 | * iocbq from scratch. | |
8723 | */ | |
8724 | memset(wqe, 0, sizeof(union lpfc_wqe)); | |
5ffc266e | 8725 | /* OX_ID is invariable to who sent ABTS to CT exchange */ |
6669f9bb | 8726 | bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp, |
546fc854 JS |
8727 | bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_rsp)); |
8728 | if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_rsp) == | |
5ffc266e JS |
8729 | LPFC_ABTS_UNSOL_INT) { |
8730 | /* ABTS sent by initiator to CT exchange, the | |
8731 | * RX_ID field will be filled with the newly | |
8732 | * allocated responder XRI. | |
8733 | */ | |
8734 | bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp, | |
8735 | iocbq->sli4_xritag); | |
8736 | } else { | |
8737 | /* ABTS sent by responder to CT exchange, the | |
8738 | * RX_ID field will be filled with the responder | |
8739 | * RX_ID from ABTS. | |
8740 | */ | |
8741 | bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp, | |
546fc854 | 8742 | bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_rsp)); |
5ffc266e | 8743 | } |
6669f9bb JS |
8744 | bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff); |
8745 | bf_set(wqe_xmit_bls_pt, &wqe->xmit_bls_rsp.wqe_dest, 0x1); | |
6b5151fd JS |
8746 | |
8747 | /* Use CT=VPI */ | |
8748 | bf_set(wqe_els_did, &wqe->xmit_bls_rsp.wqe_dest, | |
8749 | ndlp->nlp_DID); | |
8750 | bf_set(xmit_bls_rsp64_temprpi, &wqe->xmit_bls_rsp, | |
8751 | iocbq->iocb.ulpContext); | |
8752 | bf_set(wqe_ct, &wqe->xmit_bls_rsp.wqe_com, 1); | |
6669f9bb | 8753 | bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com, |
6b5151fd | 8754 | phba->vpi_ids[phba->pport->vpi]); |
f0d9bccc JS |
8755 | bf_set(wqe_qosd, &wqe->xmit_bls_rsp.wqe_com, 1); |
8756 | bf_set(wqe_lenloc, &wqe->xmit_bls_rsp.wqe_com, | |
8757 | LPFC_WQE_LENLOC_NONE); | |
6669f9bb JS |
8758 | /* Overwrite the pre-set comnd type with OTHER_COMMAND */ |
8759 | command_type = OTHER_COMMAND; | |
546fc854 JS |
8760 | if (iocbq->iocb.un.xseq64.w5.hcsw.Rctl == FC_RCTL_BA_RJT) { |
8761 | bf_set(xmit_bls_rsp64_rjt_vspec, &wqe->xmit_bls_rsp, | |
8762 | bf_get(lpfc_vndr_code, &iocbq->iocb.un.bls_rsp)); | |
8763 | bf_set(xmit_bls_rsp64_rjt_expc, &wqe->xmit_bls_rsp, | |
8764 | bf_get(lpfc_rsn_expln, &iocbq->iocb.un.bls_rsp)); | |
8765 | bf_set(xmit_bls_rsp64_rjt_rsnc, &wqe->xmit_bls_rsp, | |
8766 | bf_get(lpfc_rsn_code, &iocbq->iocb.un.bls_rsp)); | |
8767 | } | |
8768 | ||
7851fe2c | 8769 | break; |
4f774513 JS |
8770 | case CMD_XRI_ABORTED_CX: |
8771 | case CMD_CREATE_XRI_CR: /* Do we expect to use this? */ | |
4f774513 JS |
8772 | case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */ |
8773 | case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */ | |
8774 | case CMD_FCP_TRSP64_CX: /* Target mode rcv */ | |
8775 | case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */ | |
8776 | default: | |
8777 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
8778 | "2014 Invalid command 0x%x\n", | |
8779 | iocbq->iocb.ulpCommand); | |
8780 | return IOCB_ERROR; | |
7851fe2c | 8781 | break; |
4f774513 | 8782 | } |
6d368e53 | 8783 | |
8012cc38 JS |
8784 | if (iocbq->iocb_flag & LPFC_IO_DIF_PASS) |
8785 | bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_PASSTHRU); | |
8786 | else if (iocbq->iocb_flag & LPFC_IO_DIF_STRIP) | |
8787 | bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_STRIP); | |
8788 | else if (iocbq->iocb_flag & LPFC_IO_DIF_INSERT) | |
8789 | bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_INSERT); | |
8790 | iocbq->iocb_flag &= ~(LPFC_IO_DIF_PASS | LPFC_IO_DIF_STRIP | | |
8791 | LPFC_IO_DIF_INSERT); | |
f0d9bccc JS |
8792 | bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag); |
8793 | bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag); | |
8794 | wqe->generic.wqe_com.abort_tag = abort_tag; | |
8795 | bf_set(wqe_cmd_type, &wqe->generic.wqe_com, command_type); | |
8796 | bf_set(wqe_cmnd, &wqe->generic.wqe_com, cmnd); | |
8797 | bf_set(wqe_class, &wqe->generic.wqe_com, iocbq->iocb.ulpClass); | |
8798 | bf_set(wqe_cqid, &wqe->generic.wqe_com, LPFC_WQE_CQ_ID_DEFAULT); | |
4f774513 JS |
8799 | return 0; |
8800 | } | |
8801 | ||
8802 | /** | |
8803 | * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb | |
8804 | * @phba: Pointer to HBA context object. | |
8805 | * @ring_number: SLI ring number to issue iocb on. | |
8806 | * @piocb: Pointer to command iocb. | |
8807 | * @flag: Flag indicating if this command can be put into txq. | |
8808 | * | |
8809 | * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue | |
8810 | * an iocb command to an HBA with SLI-4 interface spec. | |
8811 | * | |
8812 | * This function is called with hbalock held. The function will return success | |
8813 | * after it successfully submit the iocb to firmware or after adding to the | |
8814 | * txq. | |
8815 | **/ | |
8816 | static int | |
8817 | __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number, | |
8818 | struct lpfc_iocbq *piocb, uint32_t flag) | |
8819 | { | |
8820 | struct lpfc_sglq *sglq; | |
b5c53958 JS |
8821 | union lpfc_wqe *wqe; |
8822 | union lpfc_wqe128 wqe128; | |
1ba981fd | 8823 | struct lpfc_queue *wq; |
4f774513 | 8824 | struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number]; |
4f774513 | 8825 | |
1c2ba475 JT |
8826 | lockdep_assert_held(&phba->hbalock); |
8827 | ||
b5c53958 JS |
8828 | /* |
8829 | * The WQE can be either 64 or 128 bytes, | |
8830 | * so allocate space on the stack assuming the largest. | |
8831 | */ | |
8832 | wqe = (union lpfc_wqe *)&wqe128; | |
8833 | ||
4f774513 JS |
8834 | if (piocb->sli4_xritag == NO_XRI) { |
8835 | if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || | |
6b5151fd | 8836 | piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN) |
4f774513 JS |
8837 | sglq = NULL; |
8838 | else { | |
0e9bb8d7 | 8839 | if (!list_empty(&pring->txq)) { |
2a9bf3d0 JS |
8840 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
8841 | __lpfc_sli_ringtx_put(phba, | |
8842 | pring, piocb); | |
8843 | return IOCB_SUCCESS; | |
8844 | } else { | |
8845 | return IOCB_BUSY; | |
8846 | } | |
8847 | } else { | |
6d368e53 | 8848 | sglq = __lpfc_sli_get_sglq(phba, piocb); |
2a9bf3d0 JS |
8849 | if (!sglq) { |
8850 | if (!(flag & SLI_IOCB_RET_IOCB)) { | |
8851 | __lpfc_sli_ringtx_put(phba, | |
8852 | pring, | |
8853 | piocb); | |
8854 | return IOCB_SUCCESS; | |
8855 | } else | |
8856 | return IOCB_BUSY; | |
8857 | } | |
8858 | } | |
4f774513 JS |
8859 | } |
8860 | } else if (piocb->iocb_flag & LPFC_IO_FCP) { | |
6d368e53 JS |
8861 | /* These IO's already have an XRI and a mapped sgl. */ |
8862 | sglq = NULL; | |
4f774513 | 8863 | } else { |
6d368e53 JS |
8864 | /* |
8865 | * This is a continuation of a commandi,(CX) so this | |
4f774513 JS |
8866 | * sglq is on the active list |
8867 | */ | |
edccdc17 | 8868 | sglq = __lpfc_get_active_sglq(phba, piocb->sli4_lxritag); |
4f774513 JS |
8869 | if (!sglq) |
8870 | return IOCB_ERROR; | |
8871 | } | |
8872 | ||
8873 | if (sglq) { | |
6d368e53 | 8874 | piocb->sli4_lxritag = sglq->sli4_lxritag; |
2a9bf3d0 | 8875 | piocb->sli4_xritag = sglq->sli4_xritag; |
2a9bf3d0 | 8876 | if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocb, sglq)) |
4f774513 JS |
8877 | return IOCB_ERROR; |
8878 | } | |
8879 | ||
b5c53958 | 8880 | if (lpfc_sli4_iocb2wqe(phba, piocb, wqe)) |
4f774513 JS |
8881 | return IOCB_ERROR; |
8882 | ||
341af102 | 8883 | if ((piocb->iocb_flag & LPFC_IO_FCP) || |
1ba981fd | 8884 | (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) { |
f38fa0bb | 8885 | if (!phba->cfg_fof || (!(piocb->iocb_flag & LPFC_IO_OAS))) { |
1ba981fd JS |
8886 | wq = phba->sli4_hba.fcp_wq[piocb->fcp_wqidx]; |
8887 | } else { | |
8888 | wq = phba->sli4_hba.oas_wq; | |
8889 | } | |
b5c53958 | 8890 | if (lpfc_sli4_wq_put(wq, wqe)) |
4f774513 JS |
8891 | return IOCB_ERROR; |
8892 | } else { | |
ea714f3d JS |
8893 | if (unlikely(!phba->sli4_hba.els_wq)) |
8894 | return IOCB_ERROR; | |
b5c53958 | 8895 | if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, wqe)) |
4f774513 JS |
8896 | return IOCB_ERROR; |
8897 | } | |
8898 | lpfc_sli_ringtxcmpl_put(phba, pring, piocb); | |
8899 | ||
8900 | return 0; | |
8901 | } | |
8902 | ||
8903 | /** | |
8904 | * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb | |
8905 | * | |
8906 | * This routine wraps the actual lockless version for issusing IOCB function | |
8907 | * pointer from the lpfc_hba struct. | |
8908 | * | |
8909 | * Return codes: | |
b5c53958 JS |
8910 | * IOCB_ERROR - Error |
8911 | * IOCB_SUCCESS - Success | |
8912 | * IOCB_BUSY - Busy | |
4f774513 | 8913 | **/ |
2a9bf3d0 | 8914 | int |
4f774513 JS |
8915 | __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, |
8916 | struct lpfc_iocbq *piocb, uint32_t flag) | |
8917 | { | |
8918 | return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); | |
8919 | } | |
8920 | ||
8921 | /** | |
25985edc | 8922 | * lpfc_sli_api_table_setup - Set up sli api function jump table |
4f774513 JS |
8923 | * @phba: The hba struct for which this call is being executed. |
8924 | * @dev_grp: The HBA PCI-Device group number. | |
8925 | * | |
8926 | * This routine sets up the SLI interface API function jump table in @phba | |
8927 | * struct. | |
8928 | * Returns: 0 - success, -ENODEV - failure. | |
8929 | **/ | |
8930 | int | |
8931 | lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) | |
8932 | { | |
8933 | ||
8934 | switch (dev_grp) { | |
8935 | case LPFC_PCI_DEV_LP: | |
8936 | phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3; | |
8937 | phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3; | |
8938 | break; | |
8939 | case LPFC_PCI_DEV_OC: | |
8940 | phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4; | |
8941 | phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4; | |
8942 | break; | |
8943 | default: | |
8944 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8945 | "1419 Invalid HBA PCI-device group: 0x%x\n", | |
8946 | dev_grp); | |
8947 | return -ENODEV; | |
8948 | break; | |
8949 | } | |
8950 | phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq; | |
8951 | return 0; | |
8952 | } | |
8953 | ||
a1efe163 JS |
8954 | /** |
8955 | * lpfc_sli_calc_ring - Calculates which ring to use | |
8956 | * @phba: Pointer to HBA context object. | |
8957 | * @ring_number: Initial ring | |
8958 | * @piocb: Pointer to command iocb. | |
8959 | * | |
8960 | * For SLI4, FCP IO can deferred to one fo many WQs, based on | |
8961 | * fcp_wqidx, thus we need to calculate the corresponding ring. | |
8962 | * Since ABORTS must go on the same WQ of the command they are | |
8963 | * aborting, we use command's fcp_wqidx. | |
8964 | */ | |
9bd2bff5 JS |
8965 | int |
8966 | lpfc_sli_calc_ring(struct lpfc_hba *phba, uint32_t ring_number, | |
8967 | struct lpfc_iocbq *piocb) | |
8968 | { | |
8b0dff14 JS |
8969 | if (phba->sli_rev < LPFC_SLI_REV4) |
8970 | return ring_number; | |
8971 | ||
8972 | if (piocb->iocb_flag & (LPFC_IO_FCP | LPFC_USE_FCPWQIDX)) { | |
8973 | if (!(phba->cfg_fof) || | |
8974 | (!(piocb->iocb_flag & LPFC_IO_FOF))) { | |
8975 | if (unlikely(!phba->sli4_hba.fcp_wq)) | |
8976 | return LPFC_HBA_ERROR; | |
8977 | /* | |
8978 | * for abort iocb fcp_wqidx should already | |
8979 | * be setup based on what work queue we used. | |
8980 | */ | |
8981 | if (!(piocb->iocb_flag & LPFC_USE_FCPWQIDX)) | |
8982 | piocb->fcp_wqidx = | |
8983 | lpfc_sli4_scmd_to_wqidx_distr(phba, | |
8984 | piocb->context1); | |
8985 | ring_number = MAX_SLI3_CONFIGURED_RINGS + | |
8986 | piocb->fcp_wqidx; | |
8987 | } else { | |
8988 | if (unlikely(!phba->sli4_hba.oas_wq)) | |
8989 | return LPFC_HBA_ERROR; | |
8990 | piocb->fcp_wqidx = 0; | |
8991 | ring_number = LPFC_FCP_OAS_RING; | |
9bd2bff5 JS |
8992 | } |
8993 | } | |
8994 | return ring_number; | |
8995 | } | |
8996 | ||
4f774513 JS |
8997 | /** |
8998 | * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb | |
8999 | * @phba: Pointer to HBA context object. | |
9000 | * @pring: Pointer to driver SLI ring object. | |
9001 | * @piocb: Pointer to command iocb. | |
9002 | * @flag: Flag indicating if this command can be put into txq. | |
9003 | * | |
9004 | * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb | |
9005 | * function. This function gets the hbalock and calls | |
9006 | * __lpfc_sli_issue_iocb function and will return the error returned | |
9007 | * by __lpfc_sli_issue_iocb function. This wrapper is used by | |
9008 | * functions which do not hold hbalock. | |
9009 | **/ | |
9010 | int | |
9011 | lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, | |
9012 | struct lpfc_iocbq *piocb, uint32_t flag) | |
9013 | { | |
ba20c853 | 9014 | struct lpfc_fcp_eq_hdl *fcp_eq_hdl; |
2a76a283 | 9015 | struct lpfc_sli_ring *pring; |
ba20c853 JS |
9016 | struct lpfc_queue *fpeq; |
9017 | struct lpfc_eqe *eqe; | |
4f774513 | 9018 | unsigned long iflags; |
2a76a283 | 9019 | int rc, idx; |
4f774513 | 9020 | |
7e56aa25 | 9021 | if (phba->sli_rev == LPFC_SLI_REV4) { |
9bd2bff5 JS |
9022 | ring_number = lpfc_sli_calc_ring(phba, ring_number, piocb); |
9023 | if (unlikely(ring_number == LPFC_HBA_ERROR)) | |
9024 | return IOCB_ERROR; | |
9025 | idx = piocb->fcp_wqidx; | |
ba20c853 | 9026 | |
9bd2bff5 JS |
9027 | pring = &phba->sli.ring[ring_number]; |
9028 | spin_lock_irqsave(&pring->ring_lock, iflags); | |
9029 | rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); | |
9030 | spin_unlock_irqrestore(&pring->ring_lock, iflags); | |
ba20c853 | 9031 | |
9bd2bff5 JS |
9032 | if (lpfc_fcp_look_ahead && (piocb->iocb_flag & LPFC_IO_FCP)) { |
9033 | fcp_eq_hdl = &phba->sli4_hba.fcp_eq_hdl[idx]; | |
4f774513 | 9034 | |
9bd2bff5 JS |
9035 | if (atomic_dec_and_test(&fcp_eq_hdl-> |
9036 | fcp_eq_in_use)) { | |
ba20c853 | 9037 | |
9bd2bff5 JS |
9038 | /* Get associated EQ with this index */ |
9039 | fpeq = phba->sli4_hba.hba_eq[idx]; | |
ba20c853 | 9040 | |
9bd2bff5 JS |
9041 | /* Turn off interrupts from this EQ */ |
9042 | lpfc_sli4_eq_clr_intr(fpeq); | |
ba20c853 | 9043 | |
9bd2bff5 JS |
9044 | /* |
9045 | * Process all the events on FCP EQ | |
9046 | */ | |
9047 | while ((eqe = lpfc_sli4_eq_get(fpeq))) { | |
9048 | lpfc_sli4_hba_handle_eqe(phba, | |
9049 | eqe, idx); | |
9050 | fpeq->EQ_processed++; | |
ba20c853 | 9051 | } |
ba20c853 | 9052 | |
9bd2bff5 JS |
9053 | /* Always clear and re-arm the EQ */ |
9054 | lpfc_sli4_eq_release(fpeq, | |
9055 | LPFC_QUEUE_REARM); | |
9056 | } | |
9057 | atomic_inc(&fcp_eq_hdl->fcp_eq_in_use); | |
2a76a283 | 9058 | } |
7e56aa25 JS |
9059 | } else { |
9060 | /* For now, SLI2/3 will still use hbalock */ | |
9061 | spin_lock_irqsave(&phba->hbalock, iflags); | |
9062 | rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); | |
9063 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
9064 | } | |
4f774513 JS |
9065 | return rc; |
9066 | } | |
9067 | ||
9068 | /** | |
9069 | * lpfc_extra_ring_setup - Extra ring setup function | |
9070 | * @phba: Pointer to HBA context object. | |
9071 | * | |
9072 | * This function is called while driver attaches with the | |
9073 | * HBA to setup the extra ring. The extra ring is used | |
9074 | * only when driver needs to support target mode functionality | |
9075 | * or IP over FC functionalities. | |
9076 | * | |
9077 | * This function is called with no lock held. | |
9078 | **/ | |
9079 | static int | |
9080 | lpfc_extra_ring_setup( struct lpfc_hba *phba) | |
9081 | { | |
9082 | struct lpfc_sli *psli; | |
9083 | struct lpfc_sli_ring *pring; | |
9084 | ||
9085 | psli = &phba->sli; | |
9086 | ||
9087 | /* Adjust cmd/rsp ring iocb entries more evenly */ | |
9088 | ||
9089 | /* Take some away from the FCP ring */ | |
9090 | pring = &psli->ring[psli->fcp_ring]; | |
7e56aa25 JS |
9091 | pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
9092 | pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES; | |
9093 | pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES; | |
9094 | pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES; | |
cf5bf97e | 9095 | |
a4bc3379 JS |
9096 | /* and give them to the extra ring */ |
9097 | pring = &psli->ring[psli->extra_ring]; | |
9098 | ||
7e56aa25 JS |
9099 | pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
9100 | pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES; | |
9101 | pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES; | |
9102 | pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES; | |
cf5bf97e JW |
9103 | |
9104 | /* Setup default profile for this ring */ | |
9105 | pring->iotag_max = 4096; | |
9106 | pring->num_mask = 1; | |
9107 | pring->prt[0].profile = 0; /* Mask 0 */ | |
a4bc3379 JS |
9108 | pring->prt[0].rctl = phba->cfg_multi_ring_rctl; |
9109 | pring->prt[0].type = phba->cfg_multi_ring_type; | |
cf5bf97e JW |
9110 | pring->prt[0].lpfc_sli_rcv_unsol_event = NULL; |
9111 | return 0; | |
9112 | } | |
9113 | ||
cb69f7de JS |
9114 | /* lpfc_sli_abts_err_handler - handle a failed ABTS request from an SLI3 port. |
9115 | * @phba: Pointer to HBA context object. | |
9116 | * @iocbq: Pointer to iocb object. | |
9117 | * | |
9118 | * The async_event handler calls this routine when it receives | |
9119 | * an ASYNC_STATUS_CN event from the port. The port generates | |
9120 | * this event when an Abort Sequence request to an rport fails | |
9121 | * twice in succession. The abort could be originated by the | |
9122 | * driver or by the port. The ABTS could have been for an ELS | |
9123 | * or FCP IO. The port only generates this event when an ABTS | |
9124 | * fails to complete after one retry. | |
9125 | */ | |
9126 | static void | |
9127 | lpfc_sli_abts_err_handler(struct lpfc_hba *phba, | |
9128 | struct lpfc_iocbq *iocbq) | |
9129 | { | |
9130 | struct lpfc_nodelist *ndlp = NULL; | |
9131 | uint16_t rpi = 0, vpi = 0; | |
9132 | struct lpfc_vport *vport = NULL; | |
9133 | ||
9134 | /* The rpi in the ulpContext is vport-sensitive. */ | |
9135 | vpi = iocbq->iocb.un.asyncstat.sub_ctxt_tag; | |
9136 | rpi = iocbq->iocb.ulpContext; | |
9137 | ||
9138 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
9139 | "3092 Port generated ABTS async event " | |
9140 | "on vpi %d rpi %d status 0x%x\n", | |
9141 | vpi, rpi, iocbq->iocb.ulpStatus); | |
9142 | ||
9143 | vport = lpfc_find_vport_by_vpid(phba, vpi); | |
9144 | if (!vport) | |
9145 | goto err_exit; | |
9146 | ndlp = lpfc_findnode_rpi(vport, rpi); | |
9147 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) | |
9148 | goto err_exit; | |
9149 | ||
9150 | if (iocbq->iocb.ulpStatus == IOSTAT_LOCAL_REJECT) | |
9151 | lpfc_sli_abts_recover_port(vport, ndlp); | |
9152 | return; | |
9153 | ||
9154 | err_exit: | |
9155 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
9156 | "3095 Event Context not found, no " | |
9157 | "action on vpi %d rpi %d status 0x%x, reason 0x%x\n", | |
9158 | iocbq->iocb.ulpContext, iocbq->iocb.ulpStatus, | |
9159 | vpi, rpi); | |
9160 | } | |
9161 | ||
9162 | /* lpfc_sli4_abts_err_handler - handle a failed ABTS request from an SLI4 port. | |
9163 | * @phba: pointer to HBA context object. | |
9164 | * @ndlp: nodelist pointer for the impacted rport. | |
9165 | * @axri: pointer to the wcqe containing the failed exchange. | |
9166 | * | |
9167 | * The driver calls this routine when it receives an ABORT_XRI_FCP CQE from the | |
9168 | * port. The port generates this event when an abort exchange request to an | |
9169 | * rport fails twice in succession with no reply. The abort could be originated | |
9170 | * by the driver or by the port. The ABTS could have been for an ELS or FCP IO. | |
9171 | */ | |
9172 | void | |
9173 | lpfc_sli4_abts_err_handler(struct lpfc_hba *phba, | |
9174 | struct lpfc_nodelist *ndlp, | |
9175 | struct sli4_wcqe_xri_aborted *axri) | |
9176 | { | |
9177 | struct lpfc_vport *vport; | |
5c1db2ac | 9178 | uint32_t ext_status = 0; |
cb69f7de | 9179 | |
6b5151fd | 9180 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
cb69f7de JS |
9181 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
9182 | "3115 Node Context not found, driver " | |
9183 | "ignoring abts err event\n"); | |
6b5151fd JS |
9184 | return; |
9185 | } | |
9186 | ||
cb69f7de JS |
9187 | vport = ndlp->vport; |
9188 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
9189 | "3116 Port generated FCP XRI ABORT event on " | |
5c1db2ac | 9190 | "vpi %d rpi %d xri x%x status 0x%x parameter x%x\n", |
8e668af5 | 9191 | ndlp->vport->vpi, phba->sli4_hba.rpi_ids[ndlp->nlp_rpi], |
cb69f7de | 9192 | bf_get(lpfc_wcqe_xa_xri, axri), |
5c1db2ac JS |
9193 | bf_get(lpfc_wcqe_xa_status, axri), |
9194 | axri->parameter); | |
cb69f7de | 9195 | |
5c1db2ac JS |
9196 | /* |
9197 | * Catch the ABTS protocol failure case. Older OCe FW releases returned | |
9198 | * LOCAL_REJECT and 0 for a failed ABTS exchange and later OCe and | |
9199 | * LPe FW releases returned LOCAL_REJECT and SEQUENCE_TIMEOUT. | |
9200 | */ | |
e3d2b802 | 9201 | ext_status = axri->parameter & IOERR_PARAM_MASK; |
5c1db2ac JS |
9202 | if ((bf_get(lpfc_wcqe_xa_status, axri) == IOSTAT_LOCAL_REJECT) && |
9203 | ((ext_status == IOERR_SEQUENCE_TIMEOUT) || (ext_status == 0))) | |
cb69f7de JS |
9204 | lpfc_sli_abts_recover_port(vport, ndlp); |
9205 | } | |
9206 | ||
e59058c4 | 9207 | /** |
3621a710 | 9208 | * lpfc_sli_async_event_handler - ASYNC iocb handler function |
e59058c4 JS |
9209 | * @phba: Pointer to HBA context object. |
9210 | * @pring: Pointer to driver SLI ring object. | |
9211 | * @iocbq: Pointer to iocb object. | |
9212 | * | |
9213 | * This function is called by the slow ring event handler | |
9214 | * function when there is an ASYNC event iocb in the ring. | |
9215 | * This function is called with no lock held. | |
9216 | * Currently this function handles only temperature related | |
9217 | * ASYNC events. The function decodes the temperature sensor | |
9218 | * event message and posts events for the management applications. | |
9219 | **/ | |
98c9ea5c | 9220 | static void |
57127f15 JS |
9221 | lpfc_sli_async_event_handler(struct lpfc_hba * phba, |
9222 | struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq) | |
9223 | { | |
9224 | IOCB_t *icmd; | |
9225 | uint16_t evt_code; | |
57127f15 JS |
9226 | struct temp_event temp_event_data; |
9227 | struct Scsi_Host *shost; | |
a257bf90 | 9228 | uint32_t *iocb_w; |
57127f15 JS |
9229 | |
9230 | icmd = &iocbq->iocb; | |
9231 | evt_code = icmd->un.asyncstat.evt_code; | |
57127f15 | 9232 | |
cb69f7de JS |
9233 | switch (evt_code) { |
9234 | case ASYNC_TEMP_WARN: | |
9235 | case ASYNC_TEMP_SAFE: | |
9236 | temp_event_data.data = (uint32_t) icmd->ulpContext; | |
9237 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; | |
9238 | if (evt_code == ASYNC_TEMP_WARN) { | |
9239 | temp_event_data.event_code = LPFC_THRESHOLD_TEMP; | |
9240 | lpfc_printf_log(phba, KERN_ERR, LOG_TEMP, | |
9241 | "0347 Adapter is very hot, please take " | |
9242 | "corrective action. temperature : %d Celsius\n", | |
9243 | (uint32_t) icmd->ulpContext); | |
9244 | } else { | |
9245 | temp_event_data.event_code = LPFC_NORMAL_TEMP; | |
9246 | lpfc_printf_log(phba, KERN_ERR, LOG_TEMP, | |
9247 | "0340 Adapter temperature is OK now. " | |
9248 | "temperature : %d Celsius\n", | |
9249 | (uint32_t) icmd->ulpContext); | |
9250 | } | |
9251 | ||
9252 | /* Send temperature change event to applications */ | |
9253 | shost = lpfc_shost_from_vport(phba->pport); | |
9254 | fc_host_post_vendor_event(shost, fc_get_event_number(), | |
9255 | sizeof(temp_event_data), (char *) &temp_event_data, | |
9256 | LPFC_NL_VENDOR_ID); | |
9257 | break; | |
9258 | case ASYNC_STATUS_CN: | |
9259 | lpfc_sli_abts_err_handler(phba, iocbq); | |
9260 | break; | |
9261 | default: | |
a257bf90 | 9262 | iocb_w = (uint32_t *) icmd; |
cb69f7de | 9263 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
76bb24ef | 9264 | "0346 Ring %d handler: unexpected ASYNC_STATUS" |
e4e74273 | 9265 | " evt_code 0x%x\n" |
a257bf90 JS |
9266 | "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n" |
9267 | "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n" | |
9268 | "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n" | |
9269 | "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n", | |
cb69f7de | 9270 | pring->ringno, icmd->un.asyncstat.evt_code, |
a257bf90 JS |
9271 | iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3], |
9272 | iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7], | |
9273 | iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11], | |
9274 | iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]); | |
9275 | ||
cb69f7de | 9276 | break; |
57127f15 | 9277 | } |
57127f15 JS |
9278 | } |
9279 | ||
9280 | ||
e59058c4 | 9281 | /** |
3621a710 | 9282 | * lpfc_sli_setup - SLI ring setup function |
e59058c4 JS |
9283 | * @phba: Pointer to HBA context object. |
9284 | * | |
9285 | * lpfc_sli_setup sets up rings of the SLI interface with | |
9286 | * number of iocbs per ring and iotags. This function is | |
9287 | * called while driver attach to the HBA and before the | |
9288 | * interrupts are enabled. So there is no need for locking. | |
9289 | * | |
9290 | * This function always returns 0. | |
9291 | **/ | |
dea3101e JB |
9292 | int |
9293 | lpfc_sli_setup(struct lpfc_hba *phba) | |
9294 | { | |
ed957684 | 9295 | int i, totiocbsize = 0; |
dea3101e JB |
9296 | struct lpfc_sli *psli = &phba->sli; |
9297 | struct lpfc_sli_ring *pring; | |
9298 | ||
2a76a283 JS |
9299 | psli->num_rings = MAX_SLI3_CONFIGURED_RINGS; |
9300 | if (phba->sli_rev == LPFC_SLI_REV4) | |
67d12733 | 9301 | psli->num_rings += phba->cfg_fcp_io_channel; |
dea3101e JB |
9302 | psli->sli_flag = 0; |
9303 | psli->fcp_ring = LPFC_FCP_RING; | |
9304 | psli->next_ring = LPFC_FCP_NEXT_RING; | |
a4bc3379 | 9305 | psli->extra_ring = LPFC_EXTRA_RING; |
dea3101e | 9306 | |
604a3e30 JB |
9307 | psli->iocbq_lookup = NULL; |
9308 | psli->iocbq_lookup_len = 0; | |
9309 | psli->last_iotag = 0; | |
9310 | ||
dea3101e JB |
9311 | for (i = 0; i < psli->num_rings; i++) { |
9312 | pring = &psli->ring[i]; | |
9313 | switch (i) { | |
9314 | case LPFC_FCP_RING: /* ring 0 - FCP */ | |
9315 | /* numCiocb and numRiocb are used in config_port */ | |
7e56aa25 JS |
9316 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R0_ENTRIES; |
9317 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R0_ENTRIES; | |
9318 | pring->sli.sli3.numCiocb += | |
9319 | SLI2_IOCB_CMD_R1XTRA_ENTRIES; | |
9320 | pring->sli.sli3.numRiocb += | |
9321 | SLI2_IOCB_RSP_R1XTRA_ENTRIES; | |
9322 | pring->sli.sli3.numCiocb += | |
9323 | SLI2_IOCB_CMD_R3XTRA_ENTRIES; | |
9324 | pring->sli.sli3.numRiocb += | |
9325 | SLI2_IOCB_RSP_R3XTRA_ENTRIES; | |
9326 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? | |
92d7f7b0 JS |
9327 | SLI3_IOCB_CMD_SIZE : |
9328 | SLI2_IOCB_CMD_SIZE; | |
7e56aa25 | 9329 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
92d7f7b0 JS |
9330 | SLI3_IOCB_RSP_SIZE : |
9331 | SLI2_IOCB_RSP_SIZE; | |
dea3101e JB |
9332 | pring->iotag_ctr = 0; |
9333 | pring->iotag_max = | |
92d7f7b0 | 9334 | (phba->cfg_hba_queue_depth * 2); |
dea3101e JB |
9335 | pring->fast_iotag = pring->iotag_max; |
9336 | pring->num_mask = 0; | |
9337 | break; | |
a4bc3379 | 9338 | case LPFC_EXTRA_RING: /* ring 1 - EXTRA */ |
dea3101e | 9339 | /* numCiocb and numRiocb are used in config_port */ |
7e56aa25 JS |
9340 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R1_ENTRIES; |
9341 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R1_ENTRIES; | |
9342 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? | |
92d7f7b0 JS |
9343 | SLI3_IOCB_CMD_SIZE : |
9344 | SLI2_IOCB_CMD_SIZE; | |
7e56aa25 | 9345 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
92d7f7b0 JS |
9346 | SLI3_IOCB_RSP_SIZE : |
9347 | SLI2_IOCB_RSP_SIZE; | |
2e0fef85 | 9348 | pring->iotag_max = phba->cfg_hba_queue_depth; |
dea3101e JB |
9349 | pring->num_mask = 0; |
9350 | break; | |
9351 | case LPFC_ELS_RING: /* ring 2 - ELS / CT */ | |
9352 | /* numCiocb and numRiocb are used in config_port */ | |
7e56aa25 JS |
9353 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R2_ENTRIES; |
9354 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R2_ENTRIES; | |
9355 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? | |
92d7f7b0 JS |
9356 | SLI3_IOCB_CMD_SIZE : |
9357 | SLI2_IOCB_CMD_SIZE; | |
7e56aa25 | 9358 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
92d7f7b0 JS |
9359 | SLI3_IOCB_RSP_SIZE : |
9360 | SLI2_IOCB_RSP_SIZE; | |
dea3101e JB |
9361 | pring->fast_iotag = 0; |
9362 | pring->iotag_ctr = 0; | |
9363 | pring->iotag_max = 4096; | |
57127f15 JS |
9364 | pring->lpfc_sli_rcv_async_status = |
9365 | lpfc_sli_async_event_handler; | |
6669f9bb | 9366 | pring->num_mask = LPFC_MAX_RING_MASK; |
dea3101e | 9367 | pring->prt[0].profile = 0; /* Mask 0 */ |
6a9c52cf JS |
9368 | pring->prt[0].rctl = FC_RCTL_ELS_REQ; |
9369 | pring->prt[0].type = FC_TYPE_ELS; | |
dea3101e | 9370 | pring->prt[0].lpfc_sli_rcv_unsol_event = |
92d7f7b0 | 9371 | lpfc_els_unsol_event; |
dea3101e | 9372 | pring->prt[1].profile = 0; /* Mask 1 */ |
6a9c52cf JS |
9373 | pring->prt[1].rctl = FC_RCTL_ELS_REP; |
9374 | pring->prt[1].type = FC_TYPE_ELS; | |
dea3101e | 9375 | pring->prt[1].lpfc_sli_rcv_unsol_event = |
92d7f7b0 | 9376 | lpfc_els_unsol_event; |
dea3101e JB |
9377 | pring->prt[2].profile = 0; /* Mask 2 */ |
9378 | /* NameServer Inquiry */ | |
6a9c52cf | 9379 | pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL; |
dea3101e | 9380 | /* NameServer */ |
6a9c52cf | 9381 | pring->prt[2].type = FC_TYPE_CT; |
dea3101e | 9382 | pring->prt[2].lpfc_sli_rcv_unsol_event = |
92d7f7b0 | 9383 | lpfc_ct_unsol_event; |
dea3101e JB |
9384 | pring->prt[3].profile = 0; /* Mask 3 */ |
9385 | /* NameServer response */ | |
6a9c52cf | 9386 | pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL; |
dea3101e | 9387 | /* NameServer */ |
6a9c52cf | 9388 | pring->prt[3].type = FC_TYPE_CT; |
dea3101e | 9389 | pring->prt[3].lpfc_sli_rcv_unsol_event = |
92d7f7b0 | 9390 | lpfc_ct_unsol_event; |
dea3101e JB |
9391 | break; |
9392 | } | |
7e56aa25 JS |
9393 | totiocbsize += (pring->sli.sli3.numCiocb * |
9394 | pring->sli.sli3.sizeCiocb) + | |
9395 | (pring->sli.sli3.numRiocb * pring->sli.sli3.sizeRiocb); | |
dea3101e | 9396 | } |
ed957684 | 9397 | if (totiocbsize > MAX_SLIM_IOCB_SIZE) { |
dea3101e | 9398 | /* Too many cmd / rsp ring entries in SLI2 SLIM */ |
e8b62011 JS |
9399 | printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in " |
9400 | "SLI2 SLIM Data: x%x x%lx\n", | |
9401 | phba->brd_no, totiocbsize, | |
9402 | (unsigned long) MAX_SLIM_IOCB_SIZE); | |
dea3101e | 9403 | } |
cf5bf97e JW |
9404 | if (phba->cfg_multi_ring_support == 2) |
9405 | lpfc_extra_ring_setup(phba); | |
dea3101e JB |
9406 | |
9407 | return 0; | |
9408 | } | |
9409 | ||
e59058c4 | 9410 | /** |
3621a710 | 9411 | * lpfc_sli_queue_setup - Queue initialization function |
e59058c4 JS |
9412 | * @phba: Pointer to HBA context object. |
9413 | * | |
9414 | * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each | |
9415 | * ring. This function also initializes ring indices of each ring. | |
9416 | * This function is called during the initialization of the SLI | |
9417 | * interface of an HBA. | |
9418 | * This function is called with no lock held and always returns | |
9419 | * 1. | |
9420 | **/ | |
dea3101e | 9421 | int |
2e0fef85 | 9422 | lpfc_sli_queue_setup(struct lpfc_hba *phba) |
dea3101e JB |
9423 | { |
9424 | struct lpfc_sli *psli; | |
9425 | struct lpfc_sli_ring *pring; | |
604a3e30 | 9426 | int i; |
dea3101e JB |
9427 | |
9428 | psli = &phba->sli; | |
2e0fef85 | 9429 | spin_lock_irq(&phba->hbalock); |
dea3101e | 9430 | INIT_LIST_HEAD(&psli->mboxq); |
92d7f7b0 | 9431 | INIT_LIST_HEAD(&psli->mboxq_cmpl); |
dea3101e JB |
9432 | /* Initialize list headers for txq and txcmplq as double linked lists */ |
9433 | for (i = 0; i < psli->num_rings; i++) { | |
9434 | pring = &psli->ring[i]; | |
9435 | pring->ringno = i; | |
7e56aa25 JS |
9436 | pring->sli.sli3.next_cmdidx = 0; |
9437 | pring->sli.sli3.local_getidx = 0; | |
9438 | pring->sli.sli3.cmdidx = 0; | |
68e814f5 | 9439 | pring->flag = 0; |
dea3101e JB |
9440 | INIT_LIST_HEAD(&pring->txq); |
9441 | INIT_LIST_HEAD(&pring->txcmplq); | |
9442 | INIT_LIST_HEAD(&pring->iocb_continueq); | |
9c2face6 | 9443 | INIT_LIST_HEAD(&pring->iocb_continue_saveq); |
dea3101e | 9444 | INIT_LIST_HEAD(&pring->postbufq); |
7e56aa25 | 9445 | spin_lock_init(&pring->ring_lock); |
dea3101e | 9446 | } |
2e0fef85 JS |
9447 | spin_unlock_irq(&phba->hbalock); |
9448 | return 1; | |
dea3101e JB |
9449 | } |
9450 | ||
04c68496 JS |
9451 | /** |
9452 | * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system | |
9453 | * @phba: Pointer to HBA context object. | |
9454 | * | |
9455 | * This routine flushes the mailbox command subsystem. It will unconditionally | |
9456 | * flush all the mailbox commands in the three possible stages in the mailbox | |
9457 | * command sub-system: pending mailbox command queue; the outstanding mailbox | |
9458 | * command; and completed mailbox command queue. It is caller's responsibility | |
9459 | * to make sure that the driver is in the proper state to flush the mailbox | |
9460 | * command sub-system. Namely, the posting of mailbox commands into the | |
9461 | * pending mailbox command queue from the various clients must be stopped; | |
9462 | * either the HBA is in a state that it will never works on the outstanding | |
9463 | * mailbox command (such as in EEH or ERATT conditions) or the outstanding | |
9464 | * mailbox command has been completed. | |
9465 | **/ | |
9466 | static void | |
9467 | lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba) | |
9468 | { | |
9469 | LIST_HEAD(completions); | |
9470 | struct lpfc_sli *psli = &phba->sli; | |
9471 | LPFC_MBOXQ_t *pmb; | |
9472 | unsigned long iflag; | |
9473 | ||
9474 | /* Flush all the mailbox commands in the mbox system */ | |
9475 | spin_lock_irqsave(&phba->hbalock, iflag); | |
9476 | /* The pending mailbox command queue */ | |
9477 | list_splice_init(&phba->sli.mboxq, &completions); | |
9478 | /* The outstanding active mailbox command */ | |
9479 | if (psli->mbox_active) { | |
9480 | list_add_tail(&psli->mbox_active->list, &completions); | |
9481 | psli->mbox_active = NULL; | |
9482 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
9483 | } | |
9484 | /* The completed mailbox command queue */ | |
9485 | list_splice_init(&phba->sli.mboxq_cmpl, &completions); | |
9486 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
9487 | ||
9488 | /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */ | |
9489 | while (!list_empty(&completions)) { | |
9490 | list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list); | |
9491 | pmb->u.mb.mbxStatus = MBX_NOT_FINISHED; | |
9492 | if (pmb->mbox_cmpl) | |
9493 | pmb->mbox_cmpl(phba, pmb); | |
9494 | } | |
9495 | } | |
9496 | ||
e59058c4 | 9497 | /** |
3621a710 | 9498 | * lpfc_sli_host_down - Vport cleanup function |
e59058c4 JS |
9499 | * @vport: Pointer to virtual port object. |
9500 | * | |
9501 | * lpfc_sli_host_down is called to clean up the resources | |
9502 | * associated with a vport before destroying virtual | |
9503 | * port data structures. | |
9504 | * This function does following operations: | |
9505 | * - Free discovery resources associated with this virtual | |
9506 | * port. | |
9507 | * - Free iocbs associated with this virtual port in | |
9508 | * the txq. | |
9509 | * - Send abort for all iocb commands associated with this | |
9510 | * vport in txcmplq. | |
9511 | * | |
9512 | * This function is called with no lock held and always returns 1. | |
9513 | **/ | |
92d7f7b0 JS |
9514 | int |
9515 | lpfc_sli_host_down(struct lpfc_vport *vport) | |
9516 | { | |
858c9f6c | 9517 | LIST_HEAD(completions); |
92d7f7b0 JS |
9518 | struct lpfc_hba *phba = vport->phba; |
9519 | struct lpfc_sli *psli = &phba->sli; | |
9520 | struct lpfc_sli_ring *pring; | |
9521 | struct lpfc_iocbq *iocb, *next_iocb; | |
92d7f7b0 JS |
9522 | int i; |
9523 | unsigned long flags = 0; | |
9524 | uint16_t prev_pring_flag; | |
9525 | ||
9526 | lpfc_cleanup_discovery_resources(vport); | |
9527 | ||
9528 | spin_lock_irqsave(&phba->hbalock, flags); | |
92d7f7b0 JS |
9529 | for (i = 0; i < psli->num_rings; i++) { |
9530 | pring = &psli->ring[i]; | |
9531 | prev_pring_flag = pring->flag; | |
5e9d9b82 JS |
9532 | /* Only slow rings */ |
9533 | if (pring->ringno == LPFC_ELS_RING) { | |
858c9f6c | 9534 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
5e9d9b82 JS |
9535 | /* Set the lpfc data pending flag */ |
9536 | set_bit(LPFC_DATA_READY, &phba->data_flags); | |
9537 | } | |
92d7f7b0 JS |
9538 | /* |
9539 | * Error everything on the txq since these iocbs have not been | |
9540 | * given to the FW yet. | |
9541 | */ | |
92d7f7b0 JS |
9542 | list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) { |
9543 | if (iocb->vport != vport) | |
9544 | continue; | |
858c9f6c | 9545 | list_move_tail(&iocb->list, &completions); |
92d7f7b0 JS |
9546 | } |
9547 | ||
9548 | /* Next issue ABTS for everything on the txcmplq */ | |
9549 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, | |
9550 | list) { | |
9551 | if (iocb->vport != vport) | |
9552 | continue; | |
9553 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); | |
9554 | } | |
9555 | ||
9556 | pring->flag = prev_pring_flag; | |
9557 | } | |
9558 | ||
9559 | spin_unlock_irqrestore(&phba->hbalock, flags); | |
9560 | ||
a257bf90 JS |
9561 | /* Cancel all the IOCBs from the completions list */ |
9562 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, | |
9563 | IOERR_SLI_DOWN); | |
92d7f7b0 JS |
9564 | return 1; |
9565 | } | |
9566 | ||
e59058c4 | 9567 | /** |
3621a710 | 9568 | * lpfc_sli_hba_down - Resource cleanup function for the HBA |
e59058c4 JS |
9569 | * @phba: Pointer to HBA context object. |
9570 | * | |
9571 | * This function cleans up all iocb, buffers, mailbox commands | |
9572 | * while shutting down the HBA. This function is called with no | |
9573 | * lock held and always returns 1. | |
9574 | * This function does the following to cleanup driver resources: | |
9575 | * - Free discovery resources for each virtual port | |
9576 | * - Cleanup any pending fabric iocbs | |
9577 | * - Iterate through the iocb txq and free each entry | |
9578 | * in the list. | |
9579 | * - Free up any buffer posted to the HBA | |
9580 | * - Free mailbox commands in the mailbox queue. | |
9581 | **/ | |
dea3101e | 9582 | int |
2e0fef85 | 9583 | lpfc_sli_hba_down(struct lpfc_hba *phba) |
dea3101e | 9584 | { |
2534ba75 | 9585 | LIST_HEAD(completions); |
2e0fef85 | 9586 | struct lpfc_sli *psli = &phba->sli; |
dea3101e | 9587 | struct lpfc_sli_ring *pring; |
0ff10d46 | 9588 | struct lpfc_dmabuf *buf_ptr; |
dea3101e | 9589 | unsigned long flags = 0; |
04c68496 JS |
9590 | int i; |
9591 | ||
9592 | /* Shutdown the mailbox command sub-system */ | |
618a5230 | 9593 | lpfc_sli_mbox_sys_shutdown(phba, LPFC_MBX_WAIT); |
dea3101e | 9594 | |
dea3101e JB |
9595 | lpfc_hba_down_prep(phba); |
9596 | ||
92d7f7b0 JS |
9597 | lpfc_fabric_abort_hba(phba); |
9598 | ||
2e0fef85 | 9599 | spin_lock_irqsave(&phba->hbalock, flags); |
dea3101e JB |
9600 | for (i = 0; i < psli->num_rings; i++) { |
9601 | pring = &psli->ring[i]; | |
5e9d9b82 JS |
9602 | /* Only slow rings */ |
9603 | if (pring->ringno == LPFC_ELS_RING) { | |
858c9f6c | 9604 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
5e9d9b82 JS |
9605 | /* Set the lpfc data pending flag */ |
9606 | set_bit(LPFC_DATA_READY, &phba->data_flags); | |
9607 | } | |
dea3101e JB |
9608 | |
9609 | /* | |
9610 | * Error everything on the txq since these iocbs have not been | |
9611 | * given to the FW yet. | |
9612 | */ | |
2534ba75 | 9613 | list_splice_init(&pring->txq, &completions); |
2534ba75 | 9614 | } |
2e0fef85 | 9615 | spin_unlock_irqrestore(&phba->hbalock, flags); |
dea3101e | 9616 | |
a257bf90 JS |
9617 | /* Cancel all the IOCBs from the completions list */ |
9618 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, | |
9619 | IOERR_SLI_DOWN); | |
dea3101e | 9620 | |
0ff10d46 JS |
9621 | spin_lock_irqsave(&phba->hbalock, flags); |
9622 | list_splice_init(&phba->elsbuf, &completions); | |
9623 | phba->elsbuf_cnt = 0; | |
9624 | phba->elsbuf_prev_cnt = 0; | |
9625 | spin_unlock_irqrestore(&phba->hbalock, flags); | |
9626 | ||
9627 | while (!list_empty(&completions)) { | |
9628 | list_remove_head(&completions, buf_ptr, | |
9629 | struct lpfc_dmabuf, list); | |
9630 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); | |
9631 | kfree(buf_ptr); | |
9632 | } | |
9633 | ||
dea3101e JB |
9634 | /* Return any active mbox cmds */ |
9635 | del_timer_sync(&psli->mbox_tmo); | |
2e0fef85 | 9636 | |
da0436e9 | 9637 | spin_lock_irqsave(&phba->pport->work_port_lock, flags); |
2e0fef85 | 9638 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
da0436e9 | 9639 | spin_unlock_irqrestore(&phba->pport->work_port_lock, flags); |
2e0fef85 | 9640 | |
da0436e9 JS |
9641 | return 1; |
9642 | } | |
9643 | ||
e59058c4 | 9644 | /** |
3621a710 | 9645 | * lpfc_sli_pcimem_bcopy - SLI memory copy function |
e59058c4 JS |
9646 | * @srcp: Source memory pointer. |
9647 | * @destp: Destination memory pointer. | |
9648 | * @cnt: Number of words required to be copied. | |
9649 | * | |
9650 | * This function is used for copying data between driver memory | |
9651 | * and the SLI memory. This function also changes the endianness | |
9652 | * of each word if native endianness is different from SLI | |
9653 | * endianness. This function can be called with or without | |
9654 | * lock. | |
9655 | **/ | |
dea3101e JB |
9656 | void |
9657 | lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt) | |
9658 | { | |
9659 | uint32_t *src = srcp; | |
9660 | uint32_t *dest = destp; | |
9661 | uint32_t ldata; | |
9662 | int i; | |
9663 | ||
9664 | for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) { | |
9665 | ldata = *src; | |
9666 | ldata = le32_to_cpu(ldata); | |
9667 | *dest = ldata; | |
9668 | src++; | |
9669 | dest++; | |
9670 | } | |
9671 | } | |
9672 | ||
e59058c4 | 9673 | |
a0c87cbd JS |
9674 | /** |
9675 | * lpfc_sli_bemem_bcopy - SLI memory copy function | |
9676 | * @srcp: Source memory pointer. | |
9677 | * @destp: Destination memory pointer. | |
9678 | * @cnt: Number of words required to be copied. | |
9679 | * | |
9680 | * This function is used for copying data between a data structure | |
9681 | * with big endian representation to local endianness. | |
9682 | * This function can be called with or without lock. | |
9683 | **/ | |
9684 | void | |
9685 | lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt) | |
9686 | { | |
9687 | uint32_t *src = srcp; | |
9688 | uint32_t *dest = destp; | |
9689 | uint32_t ldata; | |
9690 | int i; | |
9691 | ||
9692 | for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) { | |
9693 | ldata = *src; | |
9694 | ldata = be32_to_cpu(ldata); | |
9695 | *dest = ldata; | |
9696 | src++; | |
9697 | dest++; | |
9698 | } | |
9699 | } | |
9700 | ||
e59058c4 | 9701 | /** |
3621a710 | 9702 | * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq |
e59058c4 JS |
9703 | * @phba: Pointer to HBA context object. |
9704 | * @pring: Pointer to driver SLI ring object. | |
9705 | * @mp: Pointer to driver buffer object. | |
9706 | * | |
9707 | * This function is called with no lock held. | |
9708 | * It always return zero after adding the buffer to the postbufq | |
9709 | * buffer list. | |
9710 | **/ | |
dea3101e | 9711 | int |
2e0fef85 JS |
9712 | lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
9713 | struct lpfc_dmabuf *mp) | |
dea3101e JB |
9714 | { |
9715 | /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up | |
9716 | later */ | |
2e0fef85 | 9717 | spin_lock_irq(&phba->hbalock); |
dea3101e | 9718 | list_add_tail(&mp->list, &pring->postbufq); |
dea3101e | 9719 | pring->postbufq_cnt++; |
2e0fef85 | 9720 | spin_unlock_irq(&phba->hbalock); |
dea3101e JB |
9721 | return 0; |
9722 | } | |
9723 | ||
e59058c4 | 9724 | /** |
3621a710 | 9725 | * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer |
e59058c4 JS |
9726 | * @phba: Pointer to HBA context object. |
9727 | * | |
9728 | * When HBQ is enabled, buffers are searched based on tags. This function | |
9729 | * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The | |
9730 | * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag | |
9731 | * does not conflict with tags of buffer posted for unsolicited events. | |
9732 | * The function returns the allocated tag. The function is called with | |
9733 | * no locks held. | |
9734 | **/ | |
76bb24ef JS |
9735 | uint32_t |
9736 | lpfc_sli_get_buffer_tag(struct lpfc_hba *phba) | |
9737 | { | |
9738 | spin_lock_irq(&phba->hbalock); | |
9739 | phba->buffer_tag_count++; | |
9740 | /* | |
9741 | * Always set the QUE_BUFTAG_BIT to distiguish between | |
9742 | * a tag assigned by HBQ. | |
9743 | */ | |
9744 | phba->buffer_tag_count |= QUE_BUFTAG_BIT; | |
9745 | spin_unlock_irq(&phba->hbalock); | |
9746 | return phba->buffer_tag_count; | |
9747 | } | |
9748 | ||
e59058c4 | 9749 | /** |
3621a710 | 9750 | * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag |
e59058c4 JS |
9751 | * @phba: Pointer to HBA context object. |
9752 | * @pring: Pointer to driver SLI ring object. | |
9753 | * @tag: Buffer tag. | |
9754 | * | |
9755 | * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq | |
9756 | * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX | |
9757 | * iocb is posted to the response ring with the tag of the buffer. | |
9758 | * This function searches the pring->postbufq list using the tag | |
9759 | * to find buffer associated with CMD_IOCB_RET_XRI64_CX | |
9760 | * iocb. If the buffer is found then lpfc_dmabuf object of the | |
9761 | * buffer is returned to the caller else NULL is returned. | |
9762 | * This function is called with no lock held. | |
9763 | **/ | |
76bb24ef JS |
9764 | struct lpfc_dmabuf * |
9765 | lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
9766 | uint32_t tag) | |
9767 | { | |
9768 | struct lpfc_dmabuf *mp, *next_mp; | |
9769 | struct list_head *slp = &pring->postbufq; | |
9770 | ||
25985edc | 9771 | /* Search postbufq, from the beginning, looking for a match on tag */ |
76bb24ef JS |
9772 | spin_lock_irq(&phba->hbalock); |
9773 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { | |
9774 | if (mp->buffer_tag == tag) { | |
9775 | list_del_init(&mp->list); | |
9776 | pring->postbufq_cnt--; | |
9777 | spin_unlock_irq(&phba->hbalock); | |
9778 | return mp; | |
9779 | } | |
9780 | } | |
9781 | ||
9782 | spin_unlock_irq(&phba->hbalock); | |
9783 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
d7c255b2 | 9784 | "0402 Cannot find virtual addr for buffer tag on " |
76bb24ef JS |
9785 | "ring %d Data x%lx x%p x%p x%x\n", |
9786 | pring->ringno, (unsigned long) tag, | |
9787 | slp->next, slp->prev, pring->postbufq_cnt); | |
9788 | ||
9789 | return NULL; | |
9790 | } | |
dea3101e | 9791 | |
e59058c4 | 9792 | /** |
3621a710 | 9793 | * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events |
e59058c4 JS |
9794 | * @phba: Pointer to HBA context object. |
9795 | * @pring: Pointer to driver SLI ring object. | |
9796 | * @phys: DMA address of the buffer. | |
9797 | * | |
9798 | * This function searches the buffer list using the dma_address | |
9799 | * of unsolicited event to find the driver's lpfc_dmabuf object | |
9800 | * corresponding to the dma_address. The function returns the | |
9801 | * lpfc_dmabuf object if a buffer is found else it returns NULL. | |
9802 | * This function is called by the ct and els unsolicited event | |
9803 | * handlers to get the buffer associated with the unsolicited | |
9804 | * event. | |
9805 | * | |
9806 | * This function is called with no lock held. | |
9807 | **/ | |
dea3101e JB |
9808 | struct lpfc_dmabuf * |
9809 | lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
9810 | dma_addr_t phys) | |
9811 | { | |
9812 | struct lpfc_dmabuf *mp, *next_mp; | |
9813 | struct list_head *slp = &pring->postbufq; | |
9814 | ||
25985edc | 9815 | /* Search postbufq, from the beginning, looking for a match on phys */ |
2e0fef85 | 9816 | spin_lock_irq(&phba->hbalock); |
dea3101e JB |
9817 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
9818 | if (mp->phys == phys) { | |
9819 | list_del_init(&mp->list); | |
9820 | pring->postbufq_cnt--; | |
2e0fef85 | 9821 | spin_unlock_irq(&phba->hbalock); |
dea3101e JB |
9822 | return mp; |
9823 | } | |
9824 | } | |
9825 | ||
2e0fef85 | 9826 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 9827 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 9828 | "0410 Cannot find virtual addr for mapped buf on " |
dea3101e | 9829 | "ring %d Data x%llx x%p x%p x%x\n", |
e8b62011 | 9830 | pring->ringno, (unsigned long long)phys, |
dea3101e JB |
9831 | slp->next, slp->prev, pring->postbufq_cnt); |
9832 | return NULL; | |
9833 | } | |
9834 | ||
e59058c4 | 9835 | /** |
3621a710 | 9836 | * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs |
e59058c4 JS |
9837 | * @phba: Pointer to HBA context object. |
9838 | * @cmdiocb: Pointer to driver command iocb object. | |
9839 | * @rspiocb: Pointer to driver response iocb object. | |
9840 | * | |
9841 | * This function is the completion handler for the abort iocbs for | |
9842 | * ELS commands. This function is called from the ELS ring event | |
9843 | * handler with no lock held. This function frees memory resources | |
9844 | * associated with the abort iocb. | |
9845 | **/ | |
dea3101e | 9846 | static void |
2e0fef85 JS |
9847 | lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
9848 | struct lpfc_iocbq *rspiocb) | |
dea3101e | 9849 | { |
2e0fef85 | 9850 | IOCB_t *irsp = &rspiocb->iocb; |
2680eeaa | 9851 | uint16_t abort_iotag, abort_context; |
ff78d8f9 | 9852 | struct lpfc_iocbq *abort_iocb = NULL; |
2680eeaa JS |
9853 | |
9854 | if (irsp->ulpStatus) { | |
ff78d8f9 JS |
9855 | |
9856 | /* | |
9857 | * Assume that the port already completed and returned, or | |
9858 | * will return the iocb. Just Log the message. | |
9859 | */ | |
2680eeaa JS |
9860 | abort_context = cmdiocb->iocb.un.acxri.abortContextTag; |
9861 | abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag; | |
9862 | ||
2e0fef85 | 9863 | spin_lock_irq(&phba->hbalock); |
45ed1190 JS |
9864 | if (phba->sli_rev < LPFC_SLI_REV4) { |
9865 | if (abort_iotag != 0 && | |
9866 | abort_iotag <= phba->sli.last_iotag) | |
9867 | abort_iocb = | |
9868 | phba->sli.iocbq_lookup[abort_iotag]; | |
9869 | } else | |
9870 | /* For sli4 the abort_tag is the XRI, | |
9871 | * so the abort routine puts the iotag of the iocb | |
9872 | * being aborted in the context field of the abort | |
9873 | * IOCB. | |
9874 | */ | |
9875 | abort_iocb = phba->sli.iocbq_lookup[abort_context]; | |
2680eeaa | 9876 | |
2a9bf3d0 JS |
9877 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_SLI, |
9878 | "0327 Cannot abort els iocb %p " | |
9879 | "with tag %x context %x, abort status %x, " | |
9880 | "abort code %x\n", | |
9881 | abort_iocb, abort_iotag, abort_context, | |
9882 | irsp->ulpStatus, irsp->un.ulpWord[4]); | |
341af102 | 9883 | |
ff78d8f9 | 9884 | spin_unlock_irq(&phba->hbalock); |
2680eeaa | 9885 | } |
604a3e30 | 9886 | lpfc_sli_release_iocbq(phba, cmdiocb); |
dea3101e JB |
9887 | return; |
9888 | } | |
9889 | ||
e59058c4 | 9890 | /** |
3621a710 | 9891 | * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command |
e59058c4 JS |
9892 | * @phba: Pointer to HBA context object. |
9893 | * @cmdiocb: Pointer to driver command iocb object. | |
9894 | * @rspiocb: Pointer to driver response iocb object. | |
9895 | * | |
9896 | * The function is called from SLI ring event handler with no | |
9897 | * lock held. This function is the completion handler for ELS commands | |
9898 | * which are aborted. The function frees memory resources used for | |
9899 | * the aborted ELS commands. | |
9900 | **/ | |
92d7f7b0 JS |
9901 | static void |
9902 | lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, | |
9903 | struct lpfc_iocbq *rspiocb) | |
9904 | { | |
9905 | IOCB_t *irsp = &rspiocb->iocb; | |
9906 | ||
9907 | /* ELS cmd tag <ulpIoTag> completes */ | |
9908 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, | |
d7c255b2 | 9909 | "0139 Ignoring ELS cmd tag x%x completion Data: " |
92d7f7b0 | 9910 | "x%x x%x x%x\n", |
e8b62011 | 9911 | irsp->ulpIoTag, irsp->ulpStatus, |
92d7f7b0 | 9912 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
858c9f6c JS |
9913 | if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) |
9914 | lpfc_ct_free_iocb(phba, cmdiocb); | |
9915 | else | |
9916 | lpfc_els_free_iocb(phba, cmdiocb); | |
92d7f7b0 JS |
9917 | return; |
9918 | } | |
9919 | ||
e59058c4 | 9920 | /** |
5af5eee7 | 9921 | * lpfc_sli_abort_iotag_issue - Issue abort for a command iocb |
e59058c4 JS |
9922 | * @phba: Pointer to HBA context object. |
9923 | * @pring: Pointer to driver SLI ring object. | |
9924 | * @cmdiocb: Pointer to driver command iocb object. | |
9925 | * | |
5af5eee7 JS |
9926 | * This function issues an abort iocb for the provided command iocb down to |
9927 | * the port. Other than the case the outstanding command iocb is an abort | |
9928 | * request, this function issues abort out unconditionally. This function is | |
9929 | * called with hbalock held. The function returns 0 when it fails due to | |
9930 | * memory allocation failure or when the command iocb is an abort request. | |
e59058c4 | 9931 | **/ |
5af5eee7 JS |
9932 | static int |
9933 | lpfc_sli_abort_iotag_issue(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
2e0fef85 | 9934 | struct lpfc_iocbq *cmdiocb) |
dea3101e | 9935 | { |
2e0fef85 | 9936 | struct lpfc_vport *vport = cmdiocb->vport; |
0bd4ca25 | 9937 | struct lpfc_iocbq *abtsiocbp; |
dea3101e JB |
9938 | IOCB_t *icmd = NULL; |
9939 | IOCB_t *iabt = NULL; | |
9bd2bff5 | 9940 | int ring_number; |
5af5eee7 | 9941 | int retval; |
7e56aa25 | 9942 | unsigned long iflags; |
07951076 | 9943 | |
1c2ba475 JT |
9944 | lockdep_assert_held(&phba->hbalock); |
9945 | ||
92d7f7b0 JS |
9946 | /* |
9947 | * There are certain command types we don't want to abort. And we | |
9948 | * don't want to abort commands that are already in the process of | |
9949 | * being aborted. | |
07951076 JS |
9950 | */ |
9951 | icmd = &cmdiocb->iocb; | |
2e0fef85 | 9952 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || |
92d7f7b0 JS |
9953 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || |
9954 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) | |
07951076 JS |
9955 | return 0; |
9956 | ||
dea3101e | 9957 | /* issue ABTS for this IOCB based on iotag */ |
92d7f7b0 | 9958 | abtsiocbp = __lpfc_sli_get_iocbq(phba); |
dea3101e JB |
9959 | if (abtsiocbp == NULL) |
9960 | return 0; | |
dea3101e | 9961 | |
07951076 | 9962 | /* This signals the response to set the correct status |
341af102 | 9963 | * before calling the completion handler |
07951076 JS |
9964 | */ |
9965 | cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED; | |
9966 | ||
dea3101e | 9967 | iabt = &abtsiocbp->iocb; |
07951076 JS |
9968 | iabt->un.acxri.abortType = ABORT_TYPE_ABTS; |
9969 | iabt->un.acxri.abortContextTag = icmd->ulpContext; | |
45ed1190 | 9970 | if (phba->sli_rev == LPFC_SLI_REV4) { |
da0436e9 | 9971 | iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag; |
45ed1190 JS |
9972 | iabt->un.acxri.abortContextTag = cmdiocb->iotag; |
9973 | } | |
da0436e9 JS |
9974 | else |
9975 | iabt->un.acxri.abortIoTag = icmd->ulpIoTag; | |
07951076 JS |
9976 | iabt->ulpLe = 1; |
9977 | iabt->ulpClass = icmd->ulpClass; | |
dea3101e | 9978 | |
5ffc266e JS |
9979 | /* ABTS WQE must go to the same WQ as the WQE to be aborted */ |
9980 | abtsiocbp->fcp_wqidx = cmdiocb->fcp_wqidx; | |
341af102 JS |
9981 | if (cmdiocb->iocb_flag & LPFC_IO_FCP) |
9982 | abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX; | |
9bd2bff5 JS |
9983 | if (cmdiocb->iocb_flag & LPFC_IO_FOF) |
9984 | abtsiocbp->iocb_flag |= LPFC_IO_FOF; | |
5ffc266e | 9985 | |
2e0fef85 | 9986 | if (phba->link_state >= LPFC_LINK_UP) |
07951076 JS |
9987 | iabt->ulpCommand = CMD_ABORT_XRI_CN; |
9988 | else | |
9989 | iabt->ulpCommand = CMD_CLOSE_XRI_CN; | |
dea3101e | 9990 | |
07951076 | 9991 | abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl; |
5b8bd0c9 | 9992 | |
e8b62011 JS |
9993 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
9994 | "0339 Abort xri x%x, original iotag x%x, " | |
9995 | "abort cmd iotag x%x\n", | |
2a9bf3d0 | 9996 | iabt->un.acxri.abortIoTag, |
e8b62011 | 9997 | iabt->un.acxri.abortContextTag, |
2a9bf3d0 | 9998 | abtsiocbp->iotag); |
7e56aa25 JS |
9999 | |
10000 | if (phba->sli_rev == LPFC_SLI_REV4) { | |
9bd2bff5 JS |
10001 | ring_number = |
10002 | lpfc_sli_calc_ring(phba, pring->ringno, abtsiocbp); | |
10003 | if (unlikely(ring_number == LPFC_HBA_ERROR)) | |
10004 | return 0; | |
10005 | pring = &phba->sli.ring[ring_number]; | |
7e56aa25 JS |
10006 | /* Note: both hbalock and ring_lock need to be set here */ |
10007 | spin_lock_irqsave(&pring->ring_lock, iflags); | |
10008 | retval = __lpfc_sli_issue_iocb(phba, pring->ringno, | |
10009 | abtsiocbp, 0); | |
10010 | spin_unlock_irqrestore(&pring->ring_lock, iflags); | |
10011 | } else { | |
10012 | retval = __lpfc_sli_issue_iocb(phba, pring->ringno, | |
10013 | abtsiocbp, 0); | |
10014 | } | |
dea3101e | 10015 | |
d7c255b2 JS |
10016 | if (retval) |
10017 | __lpfc_sli_release_iocbq(phba, abtsiocbp); | |
5af5eee7 JS |
10018 | |
10019 | /* | |
10020 | * Caller to this routine should check for IOCB_ERROR | |
10021 | * and handle it properly. This routine no longer removes | |
10022 | * iocb off txcmplq and call compl in case of IOCB_ERROR. | |
10023 | */ | |
10024 | return retval; | |
10025 | } | |
10026 | ||
10027 | /** | |
10028 | * lpfc_sli_issue_abort_iotag - Abort function for a command iocb | |
10029 | * @phba: Pointer to HBA context object. | |
10030 | * @pring: Pointer to driver SLI ring object. | |
10031 | * @cmdiocb: Pointer to driver command iocb object. | |
10032 | * | |
10033 | * This function issues an abort iocb for the provided command iocb. In case | |
10034 | * of unloading, the abort iocb will not be issued to commands on the ELS | |
10035 | * ring. Instead, the callback function shall be changed to those commands | |
10036 | * so that nothing happens when them finishes. This function is called with | |
10037 | * hbalock held. The function returns 0 when the command iocb is an abort | |
10038 | * request. | |
10039 | **/ | |
10040 | int | |
10041 | lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
10042 | struct lpfc_iocbq *cmdiocb) | |
10043 | { | |
10044 | struct lpfc_vport *vport = cmdiocb->vport; | |
10045 | int retval = IOCB_ERROR; | |
10046 | IOCB_t *icmd = NULL; | |
10047 | ||
1c2ba475 JT |
10048 | lockdep_assert_held(&phba->hbalock); |
10049 | ||
5af5eee7 JS |
10050 | /* |
10051 | * There are certain command types we don't want to abort. And we | |
10052 | * don't want to abort commands that are already in the process of | |
10053 | * being aborted. | |
10054 | */ | |
10055 | icmd = &cmdiocb->iocb; | |
10056 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || | |
10057 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || | |
10058 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) | |
10059 | return 0; | |
10060 | ||
10061 | /* | |
10062 | * If we're unloading, don't abort iocb on the ELS ring, but change | |
10063 | * the callback so that nothing happens when it finishes. | |
10064 | */ | |
10065 | if ((vport->load_flag & FC_UNLOADING) && | |
10066 | (pring->ringno == LPFC_ELS_RING)) { | |
10067 | if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) | |
10068 | cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl; | |
10069 | else | |
10070 | cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl; | |
10071 | goto abort_iotag_exit; | |
10072 | } | |
10073 | ||
10074 | /* Now, we try to issue the abort to the cmdiocb out */ | |
10075 | retval = lpfc_sli_abort_iotag_issue(phba, pring, cmdiocb); | |
10076 | ||
07951076 | 10077 | abort_iotag_exit: |
2e0fef85 JS |
10078 | /* |
10079 | * Caller to this routine should check for IOCB_ERROR | |
10080 | * and handle it properly. This routine no longer removes | |
10081 | * iocb off txcmplq and call compl in case of IOCB_ERROR. | |
07951076 | 10082 | */ |
2e0fef85 | 10083 | return retval; |
dea3101e JB |
10084 | } |
10085 | ||
5af5eee7 JS |
10086 | /** |
10087 | * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba. | |
10088 | * @phba: pointer to lpfc HBA data structure. | |
10089 | * | |
10090 | * This routine will abort all pending and outstanding iocbs to an HBA. | |
10091 | **/ | |
10092 | void | |
10093 | lpfc_sli_hba_iocb_abort(struct lpfc_hba *phba) | |
10094 | { | |
10095 | struct lpfc_sli *psli = &phba->sli; | |
10096 | struct lpfc_sli_ring *pring; | |
10097 | int i; | |
10098 | ||
10099 | for (i = 0; i < psli->num_rings; i++) { | |
10100 | pring = &psli->ring[i]; | |
db55fba8 | 10101 | lpfc_sli_abort_iocb_ring(phba, pring); |
5af5eee7 JS |
10102 | } |
10103 | } | |
10104 | ||
e59058c4 | 10105 | /** |
3621a710 | 10106 | * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN |
e59058c4 JS |
10107 | * @iocbq: Pointer to driver iocb object. |
10108 | * @vport: Pointer to driver virtual port object. | |
10109 | * @tgt_id: SCSI ID of the target. | |
10110 | * @lun_id: LUN ID of the scsi device. | |
10111 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST | |
10112 | * | |
3621a710 | 10113 | * This function acts as an iocb filter for functions which abort or count |
e59058c4 JS |
10114 | * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return |
10115 | * 0 if the filtering criteria is met for the given iocb and will return | |
10116 | * 1 if the filtering criteria is not met. | |
10117 | * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the | |
10118 | * given iocb is for the SCSI device specified by vport, tgt_id and | |
10119 | * lun_id parameter. | |
10120 | * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the | |
10121 | * given iocb is for the SCSI target specified by vport and tgt_id | |
10122 | * parameters. | |
10123 | * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the | |
10124 | * given iocb is for the SCSI host associated with the given vport. | |
10125 | * This function is called with no locks held. | |
10126 | **/ | |
dea3101e | 10127 | static int |
51ef4c26 JS |
10128 | lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport, |
10129 | uint16_t tgt_id, uint64_t lun_id, | |
0bd4ca25 | 10130 | lpfc_ctx_cmd ctx_cmd) |
dea3101e | 10131 | { |
0bd4ca25 | 10132 | struct lpfc_scsi_buf *lpfc_cmd; |
dea3101e JB |
10133 | int rc = 1; |
10134 | ||
0bd4ca25 JSEC |
10135 | if (!(iocbq->iocb_flag & LPFC_IO_FCP)) |
10136 | return rc; | |
10137 | ||
51ef4c26 JS |
10138 | if (iocbq->vport != vport) |
10139 | return rc; | |
10140 | ||
0bd4ca25 | 10141 | lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq); |
0bd4ca25 | 10142 | |
495a714c | 10143 | if (lpfc_cmd->pCmd == NULL) |
dea3101e JB |
10144 | return rc; |
10145 | ||
10146 | switch (ctx_cmd) { | |
10147 | case LPFC_CTX_LUN: | |
495a714c JS |
10148 | if ((lpfc_cmd->rdata->pnode) && |
10149 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) && | |
10150 | (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id)) | |
dea3101e JB |
10151 | rc = 0; |
10152 | break; | |
10153 | case LPFC_CTX_TGT: | |
495a714c JS |
10154 | if ((lpfc_cmd->rdata->pnode) && |
10155 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id)) | |
dea3101e JB |
10156 | rc = 0; |
10157 | break; | |
dea3101e JB |
10158 | case LPFC_CTX_HOST: |
10159 | rc = 0; | |
10160 | break; | |
10161 | default: | |
10162 | printk(KERN_ERR "%s: Unknown context cmd type, value %d\n", | |
cadbd4a5 | 10163 | __func__, ctx_cmd); |
dea3101e JB |
10164 | break; |
10165 | } | |
10166 | ||
10167 | return rc; | |
10168 | } | |
10169 | ||
e59058c4 | 10170 | /** |
3621a710 | 10171 | * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending |
e59058c4 JS |
10172 | * @vport: Pointer to virtual port. |
10173 | * @tgt_id: SCSI ID of the target. | |
10174 | * @lun_id: LUN ID of the scsi device. | |
10175 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. | |
10176 | * | |
10177 | * This function returns number of FCP commands pending for the vport. | |
10178 | * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP | |
10179 | * commands pending on the vport associated with SCSI device specified | |
10180 | * by tgt_id and lun_id parameters. | |
10181 | * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP | |
10182 | * commands pending on the vport associated with SCSI target specified | |
10183 | * by tgt_id parameter. | |
10184 | * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP | |
10185 | * commands pending on the vport. | |
10186 | * This function returns the number of iocbs which satisfy the filter. | |
10187 | * This function is called without any lock held. | |
10188 | **/ | |
dea3101e | 10189 | int |
51ef4c26 JS |
10190 | lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id, |
10191 | lpfc_ctx_cmd ctx_cmd) | |
dea3101e | 10192 | { |
51ef4c26 | 10193 | struct lpfc_hba *phba = vport->phba; |
0bd4ca25 JSEC |
10194 | struct lpfc_iocbq *iocbq; |
10195 | int sum, i; | |
dea3101e | 10196 | |
0bd4ca25 JSEC |
10197 | for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) { |
10198 | iocbq = phba->sli.iocbq_lookup[i]; | |
dea3101e | 10199 | |
51ef4c26 JS |
10200 | if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id, |
10201 | ctx_cmd) == 0) | |
0bd4ca25 | 10202 | sum++; |
dea3101e | 10203 | } |
0bd4ca25 | 10204 | |
dea3101e JB |
10205 | return sum; |
10206 | } | |
10207 | ||
e59058c4 | 10208 | /** |
3621a710 | 10209 | * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs |
e59058c4 JS |
10210 | * @phba: Pointer to HBA context object |
10211 | * @cmdiocb: Pointer to command iocb object. | |
10212 | * @rspiocb: Pointer to response iocb object. | |
10213 | * | |
10214 | * This function is called when an aborted FCP iocb completes. This | |
10215 | * function is called by the ring event handler with no lock held. | |
10216 | * This function frees the iocb. | |
10217 | **/ | |
5eb95af0 | 10218 | void |
2e0fef85 JS |
10219 | lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
10220 | struct lpfc_iocbq *rspiocb) | |
5eb95af0 | 10221 | { |
cb69f7de | 10222 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
8e668af5 | 10223 | "3096 ABORT_XRI_CN completing on rpi x%x " |
cb69f7de JS |
10224 | "original iotag x%x, abort cmd iotag x%x " |
10225 | "status 0x%x, reason 0x%x\n", | |
10226 | cmdiocb->iocb.un.acxri.abortContextTag, | |
10227 | cmdiocb->iocb.un.acxri.abortIoTag, | |
10228 | cmdiocb->iotag, rspiocb->iocb.ulpStatus, | |
10229 | rspiocb->iocb.un.ulpWord[4]); | |
604a3e30 | 10230 | lpfc_sli_release_iocbq(phba, cmdiocb); |
5eb95af0 JSEC |
10231 | return; |
10232 | } | |
10233 | ||
e59058c4 | 10234 | /** |
3621a710 | 10235 | * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN |
e59058c4 JS |
10236 | * @vport: Pointer to virtual port. |
10237 | * @pring: Pointer to driver SLI ring object. | |
10238 | * @tgt_id: SCSI ID of the target. | |
10239 | * @lun_id: LUN ID of the scsi device. | |
10240 | * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. | |
10241 | * | |
10242 | * This function sends an abort command for every SCSI command | |
10243 | * associated with the given virtual port pending on the ring | |
10244 | * filtered by lpfc_sli_validate_fcp_iocb function. | |
10245 | * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the | |
10246 | * FCP iocbs associated with lun specified by tgt_id and lun_id | |
10247 | * parameters | |
10248 | * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the | |
10249 | * FCP iocbs associated with SCSI target specified by tgt_id parameter. | |
10250 | * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all | |
10251 | * FCP iocbs associated with virtual port. | |
10252 | * This function returns number of iocbs it failed to abort. | |
10253 | * This function is called with no locks held. | |
10254 | **/ | |
dea3101e | 10255 | int |
51ef4c26 JS |
10256 | lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring, |
10257 | uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd) | |
dea3101e | 10258 | { |
51ef4c26 | 10259 | struct lpfc_hba *phba = vport->phba; |
0bd4ca25 JSEC |
10260 | struct lpfc_iocbq *iocbq; |
10261 | struct lpfc_iocbq *abtsiocb; | |
dea3101e | 10262 | IOCB_t *cmd = NULL; |
dea3101e | 10263 | int errcnt = 0, ret_val = 0; |
0bd4ca25 | 10264 | int i; |
dea3101e | 10265 | |
0bd4ca25 JSEC |
10266 | for (i = 1; i <= phba->sli.last_iotag; i++) { |
10267 | iocbq = phba->sli.iocbq_lookup[i]; | |
dea3101e | 10268 | |
51ef4c26 | 10269 | if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id, |
2e0fef85 | 10270 | abort_cmd) != 0) |
dea3101e JB |
10271 | continue; |
10272 | ||
afbd8d88 JS |
10273 | /* |
10274 | * If the iocbq is already being aborted, don't take a second | |
10275 | * action, but do count it. | |
10276 | */ | |
10277 | if (iocbq->iocb_flag & LPFC_DRIVER_ABORTED) | |
10278 | continue; | |
10279 | ||
dea3101e | 10280 | /* issue ABTS for this IOCB based on iotag */ |
0bd4ca25 | 10281 | abtsiocb = lpfc_sli_get_iocbq(phba); |
dea3101e JB |
10282 | if (abtsiocb == NULL) { |
10283 | errcnt++; | |
10284 | continue; | |
10285 | } | |
dea3101e | 10286 | |
afbd8d88 JS |
10287 | /* indicate the IO is being aborted by the driver. */ |
10288 | iocbq->iocb_flag |= LPFC_DRIVER_ABORTED; | |
10289 | ||
0bd4ca25 | 10290 | cmd = &iocbq->iocb; |
dea3101e JB |
10291 | abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS; |
10292 | abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext; | |
da0436e9 JS |
10293 | if (phba->sli_rev == LPFC_SLI_REV4) |
10294 | abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag; | |
10295 | else | |
10296 | abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag; | |
dea3101e JB |
10297 | abtsiocb->iocb.ulpLe = 1; |
10298 | abtsiocb->iocb.ulpClass = cmd->ulpClass; | |
afbd8d88 | 10299 | abtsiocb->vport = vport; |
dea3101e | 10300 | |
5ffc266e JS |
10301 | /* ABTS WQE must go to the same WQ as the WQE to be aborted */ |
10302 | abtsiocb->fcp_wqidx = iocbq->fcp_wqidx; | |
341af102 JS |
10303 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
10304 | abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX; | |
9bd2bff5 JS |
10305 | if (iocbq->iocb_flag & LPFC_IO_FOF) |
10306 | abtsiocb->iocb_flag |= LPFC_IO_FOF; | |
5ffc266e | 10307 | |
2e0fef85 | 10308 | if (lpfc_is_link_up(phba)) |
dea3101e JB |
10309 | abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN; |
10310 | else | |
10311 | abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN; | |
10312 | ||
5eb95af0 JSEC |
10313 | /* Setup callback routine and issue the command. */ |
10314 | abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; | |
da0436e9 JS |
10315 | ret_val = lpfc_sli_issue_iocb(phba, pring->ringno, |
10316 | abtsiocb, 0); | |
dea3101e | 10317 | if (ret_val == IOCB_ERROR) { |
604a3e30 | 10318 | lpfc_sli_release_iocbq(phba, abtsiocb); |
dea3101e JB |
10319 | errcnt++; |
10320 | continue; | |
10321 | } | |
10322 | } | |
10323 | ||
10324 | return errcnt; | |
10325 | } | |
10326 | ||
98912dda JS |
10327 | /** |
10328 | * lpfc_sli_abort_taskmgmt - issue abort for all commands on a host/target/LUN | |
10329 | * @vport: Pointer to virtual port. | |
10330 | * @pring: Pointer to driver SLI ring object. | |
10331 | * @tgt_id: SCSI ID of the target. | |
10332 | * @lun_id: LUN ID of the scsi device. | |
10333 | * @taskmgmt_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. | |
10334 | * | |
10335 | * This function sends an abort command for every SCSI command | |
10336 | * associated with the given virtual port pending on the ring | |
10337 | * filtered by lpfc_sli_validate_fcp_iocb function. | |
10338 | * When taskmgmt_cmd == LPFC_CTX_LUN, the function sends abort only to the | |
10339 | * FCP iocbs associated with lun specified by tgt_id and lun_id | |
10340 | * parameters | |
10341 | * When taskmgmt_cmd == LPFC_CTX_TGT, the function sends abort only to the | |
10342 | * FCP iocbs associated with SCSI target specified by tgt_id parameter. | |
10343 | * When taskmgmt_cmd == LPFC_CTX_HOST, the function sends abort to all | |
10344 | * FCP iocbs associated with virtual port. | |
10345 | * This function returns number of iocbs it aborted . | |
10346 | * This function is called with no locks held right after a taskmgmt | |
10347 | * command is sent. | |
10348 | **/ | |
10349 | int | |
10350 | lpfc_sli_abort_taskmgmt(struct lpfc_vport *vport, struct lpfc_sli_ring *pring, | |
10351 | uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd cmd) | |
10352 | { | |
10353 | struct lpfc_hba *phba = vport->phba; | |
8c50d25c | 10354 | struct lpfc_scsi_buf *lpfc_cmd; |
98912dda | 10355 | struct lpfc_iocbq *abtsiocbq; |
8c50d25c | 10356 | struct lpfc_nodelist *ndlp; |
98912dda JS |
10357 | struct lpfc_iocbq *iocbq; |
10358 | IOCB_t *icmd; | |
10359 | int sum, i, ret_val; | |
10360 | unsigned long iflags; | |
10361 | struct lpfc_sli_ring *pring_s4; | |
10362 | uint32_t ring_number; | |
10363 | ||
10364 | spin_lock_irq(&phba->hbalock); | |
10365 | ||
10366 | /* all I/Os are in process of being flushed */ | |
10367 | if (phba->hba_flag & HBA_FCP_IOQ_FLUSH) { | |
10368 | spin_unlock_irq(&phba->hbalock); | |
10369 | return 0; | |
10370 | } | |
10371 | sum = 0; | |
10372 | ||
10373 | for (i = 1; i <= phba->sli.last_iotag; i++) { | |
10374 | iocbq = phba->sli.iocbq_lookup[i]; | |
10375 | ||
10376 | if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id, | |
10377 | cmd) != 0) | |
10378 | continue; | |
10379 | ||
10380 | /* | |
10381 | * If the iocbq is already being aborted, don't take a second | |
10382 | * action, but do count it. | |
10383 | */ | |
10384 | if (iocbq->iocb_flag & LPFC_DRIVER_ABORTED) | |
10385 | continue; | |
10386 | ||
10387 | /* issue ABTS for this IOCB based on iotag */ | |
10388 | abtsiocbq = __lpfc_sli_get_iocbq(phba); | |
10389 | if (abtsiocbq == NULL) | |
10390 | continue; | |
10391 | ||
10392 | icmd = &iocbq->iocb; | |
10393 | abtsiocbq->iocb.un.acxri.abortType = ABORT_TYPE_ABTS; | |
10394 | abtsiocbq->iocb.un.acxri.abortContextTag = icmd->ulpContext; | |
10395 | if (phba->sli_rev == LPFC_SLI_REV4) | |
10396 | abtsiocbq->iocb.un.acxri.abortIoTag = | |
10397 | iocbq->sli4_xritag; | |
10398 | else | |
10399 | abtsiocbq->iocb.un.acxri.abortIoTag = icmd->ulpIoTag; | |
10400 | abtsiocbq->iocb.ulpLe = 1; | |
10401 | abtsiocbq->iocb.ulpClass = icmd->ulpClass; | |
10402 | abtsiocbq->vport = vport; | |
10403 | ||
10404 | /* ABTS WQE must go to the same WQ as the WQE to be aborted */ | |
10405 | abtsiocbq->fcp_wqidx = iocbq->fcp_wqidx; | |
10406 | if (iocbq->iocb_flag & LPFC_IO_FCP) | |
10407 | abtsiocbq->iocb_flag |= LPFC_USE_FCPWQIDX; | |
9bd2bff5 JS |
10408 | if (iocbq->iocb_flag & LPFC_IO_FOF) |
10409 | abtsiocbq->iocb_flag |= LPFC_IO_FOF; | |
98912dda | 10410 | |
8c50d25c JS |
10411 | lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq); |
10412 | ndlp = lpfc_cmd->rdata->pnode; | |
10413 | ||
10414 | if (lpfc_is_link_up(phba) && | |
10415 | (ndlp && ndlp->nlp_state == NLP_STE_MAPPED_NODE)) | |
98912dda JS |
10416 | abtsiocbq->iocb.ulpCommand = CMD_ABORT_XRI_CN; |
10417 | else | |
10418 | abtsiocbq->iocb.ulpCommand = CMD_CLOSE_XRI_CN; | |
10419 | ||
10420 | /* Setup callback routine and issue the command. */ | |
10421 | abtsiocbq->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; | |
10422 | ||
10423 | /* | |
10424 | * Indicate the IO is being aborted by the driver and set | |
10425 | * the caller's flag into the aborted IO. | |
10426 | */ | |
10427 | iocbq->iocb_flag |= LPFC_DRIVER_ABORTED; | |
10428 | ||
10429 | if (phba->sli_rev == LPFC_SLI_REV4) { | |
10430 | ring_number = MAX_SLI3_CONFIGURED_RINGS + | |
10431 | iocbq->fcp_wqidx; | |
10432 | pring_s4 = &phba->sli.ring[ring_number]; | |
10433 | /* Note: both hbalock and ring_lock must be set here */ | |
10434 | spin_lock_irqsave(&pring_s4->ring_lock, iflags); | |
10435 | ret_val = __lpfc_sli_issue_iocb(phba, pring_s4->ringno, | |
10436 | abtsiocbq, 0); | |
10437 | spin_unlock_irqrestore(&pring_s4->ring_lock, iflags); | |
10438 | } else { | |
10439 | ret_val = __lpfc_sli_issue_iocb(phba, pring->ringno, | |
10440 | abtsiocbq, 0); | |
10441 | } | |
10442 | ||
10443 | ||
10444 | if (ret_val == IOCB_ERROR) | |
10445 | __lpfc_sli_release_iocbq(phba, abtsiocbq); | |
10446 | else | |
10447 | sum++; | |
10448 | } | |
10449 | spin_unlock_irq(&phba->hbalock); | |
10450 | return sum; | |
10451 | } | |
10452 | ||
e59058c4 | 10453 | /** |
3621a710 | 10454 | * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler |
e59058c4 JS |
10455 | * @phba: Pointer to HBA context object. |
10456 | * @cmdiocbq: Pointer to command iocb. | |
10457 | * @rspiocbq: Pointer to response iocb. | |
10458 | * | |
10459 | * This function is the completion handler for iocbs issued using | |
10460 | * lpfc_sli_issue_iocb_wait function. This function is called by the | |
10461 | * ring event handler function without any lock held. This function | |
10462 | * can be called from both worker thread context and interrupt | |
10463 | * context. This function also can be called from other thread which | |
10464 | * cleans up the SLI layer objects. | |
10465 | * This function copy the contents of the response iocb to the | |
10466 | * response iocb memory object provided by the caller of | |
10467 | * lpfc_sli_issue_iocb_wait and then wakes up the thread which | |
10468 | * sleeps for the iocb completion. | |
10469 | **/ | |
68876920 JSEC |
10470 | static void |
10471 | lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba, | |
10472 | struct lpfc_iocbq *cmdiocbq, | |
10473 | struct lpfc_iocbq *rspiocbq) | |
dea3101e | 10474 | { |
68876920 JSEC |
10475 | wait_queue_head_t *pdone_q; |
10476 | unsigned long iflags; | |
0f65ff68 | 10477 | struct lpfc_scsi_buf *lpfc_cmd; |
dea3101e | 10478 | |
2e0fef85 | 10479 | spin_lock_irqsave(&phba->hbalock, iflags); |
5a0916b4 JS |
10480 | if (cmdiocbq->iocb_flag & LPFC_IO_WAKE_TMO) { |
10481 | ||
10482 | /* | |
10483 | * A time out has occurred for the iocb. If a time out | |
10484 | * completion handler has been supplied, call it. Otherwise, | |
10485 | * just free the iocbq. | |
10486 | */ | |
10487 | ||
10488 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
10489 | cmdiocbq->iocb_cmpl = cmdiocbq->wait_iocb_cmpl; | |
10490 | cmdiocbq->wait_iocb_cmpl = NULL; | |
10491 | if (cmdiocbq->iocb_cmpl) | |
10492 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, NULL); | |
10493 | else | |
10494 | lpfc_sli_release_iocbq(phba, cmdiocbq); | |
10495 | return; | |
10496 | } | |
10497 | ||
68876920 JSEC |
10498 | cmdiocbq->iocb_flag |= LPFC_IO_WAKE; |
10499 | if (cmdiocbq->context2 && rspiocbq) | |
10500 | memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb, | |
10501 | &rspiocbq->iocb, sizeof(IOCB_t)); | |
10502 | ||
0f65ff68 JS |
10503 | /* Set the exchange busy flag for task management commands */ |
10504 | if ((cmdiocbq->iocb_flag & LPFC_IO_FCP) && | |
10505 | !(cmdiocbq->iocb_flag & LPFC_IO_LIBDFC)) { | |
10506 | lpfc_cmd = container_of(cmdiocbq, struct lpfc_scsi_buf, | |
10507 | cur_iocbq); | |
10508 | lpfc_cmd->exch_busy = rspiocbq->iocb_flag & LPFC_EXCHANGE_BUSY; | |
10509 | } | |
10510 | ||
68876920 | 10511 | pdone_q = cmdiocbq->context_un.wait_queue; |
68876920 JSEC |
10512 | if (pdone_q) |
10513 | wake_up(pdone_q); | |
858c9f6c | 10514 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
dea3101e JB |
10515 | return; |
10516 | } | |
10517 | ||
d11e31dd JS |
10518 | /** |
10519 | * lpfc_chk_iocb_flg - Test IOCB flag with lock held. | |
10520 | * @phba: Pointer to HBA context object.. | |
10521 | * @piocbq: Pointer to command iocb. | |
10522 | * @flag: Flag to test. | |
10523 | * | |
10524 | * This routine grabs the hbalock and then test the iocb_flag to | |
10525 | * see if the passed in flag is set. | |
10526 | * Returns: | |
10527 | * 1 if flag is set. | |
10528 | * 0 if flag is not set. | |
10529 | **/ | |
10530 | static int | |
10531 | lpfc_chk_iocb_flg(struct lpfc_hba *phba, | |
10532 | struct lpfc_iocbq *piocbq, uint32_t flag) | |
10533 | { | |
10534 | unsigned long iflags; | |
10535 | int ret; | |
10536 | ||
10537 | spin_lock_irqsave(&phba->hbalock, iflags); | |
10538 | ret = piocbq->iocb_flag & flag; | |
10539 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
10540 | return ret; | |
10541 | ||
10542 | } | |
10543 | ||
e59058c4 | 10544 | /** |
3621a710 | 10545 | * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands |
e59058c4 JS |
10546 | * @phba: Pointer to HBA context object.. |
10547 | * @pring: Pointer to sli ring. | |
10548 | * @piocb: Pointer to command iocb. | |
10549 | * @prspiocbq: Pointer to response iocb. | |
10550 | * @timeout: Timeout in number of seconds. | |
10551 | * | |
10552 | * This function issues the iocb to firmware and waits for the | |
5a0916b4 JS |
10553 | * iocb to complete. The iocb_cmpl field of the shall be used |
10554 | * to handle iocbs which time out. If the field is NULL, the | |
10555 | * function shall free the iocbq structure. If more clean up is | |
10556 | * needed, the caller is expected to provide a completion function | |
10557 | * that will provide the needed clean up. If the iocb command is | |
10558 | * not completed within timeout seconds, the function will either | |
10559 | * free the iocbq structure (if iocb_cmpl == NULL) or execute the | |
10560 | * completion function set in the iocb_cmpl field and then return | |
10561 | * a status of IOCB_TIMEDOUT. The caller should not free the iocb | |
10562 | * resources if this function returns IOCB_TIMEDOUT. | |
e59058c4 JS |
10563 | * The function waits for the iocb completion using an |
10564 | * non-interruptible wait. | |
10565 | * This function will sleep while waiting for iocb completion. | |
10566 | * So, this function should not be called from any context which | |
10567 | * does not allow sleeping. Due to the same reason, this function | |
10568 | * cannot be called with interrupt disabled. | |
10569 | * This function assumes that the iocb completions occur while | |
10570 | * this function sleep. So, this function cannot be called from | |
10571 | * the thread which process iocb completion for this ring. | |
10572 | * This function clears the iocb_flag of the iocb object before | |
10573 | * issuing the iocb and the iocb completion handler sets this | |
10574 | * flag and wakes this thread when the iocb completes. | |
10575 | * The contents of the response iocb will be copied to prspiocbq | |
10576 | * by the completion handler when the command completes. | |
10577 | * This function returns IOCB_SUCCESS when success. | |
10578 | * This function is called with no lock held. | |
10579 | **/ | |
dea3101e | 10580 | int |
2e0fef85 | 10581 | lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba, |
da0436e9 | 10582 | uint32_t ring_number, |
2e0fef85 JS |
10583 | struct lpfc_iocbq *piocb, |
10584 | struct lpfc_iocbq *prspiocbq, | |
68876920 | 10585 | uint32_t timeout) |
dea3101e | 10586 | { |
7259f0d0 | 10587 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
68876920 JSEC |
10588 | long timeleft, timeout_req = 0; |
10589 | int retval = IOCB_SUCCESS; | |
875fbdfe | 10590 | uint32_t creg_val; |
0e9bb8d7 JS |
10591 | struct lpfc_iocbq *iocb; |
10592 | int txq_cnt = 0; | |
10593 | int txcmplq_cnt = 0; | |
2a9bf3d0 | 10594 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
5a0916b4 JS |
10595 | unsigned long iflags; |
10596 | bool iocb_completed = true; | |
10597 | ||
dea3101e | 10598 | /* |
68876920 JSEC |
10599 | * If the caller has provided a response iocbq buffer, then context2 |
10600 | * is NULL or its an error. | |
dea3101e | 10601 | */ |
68876920 JSEC |
10602 | if (prspiocbq) { |
10603 | if (piocb->context2) | |
10604 | return IOCB_ERROR; | |
10605 | piocb->context2 = prspiocbq; | |
dea3101e JB |
10606 | } |
10607 | ||
5a0916b4 | 10608 | piocb->wait_iocb_cmpl = piocb->iocb_cmpl; |
68876920 JSEC |
10609 | piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait; |
10610 | piocb->context_un.wait_queue = &done_q; | |
5a0916b4 | 10611 | piocb->iocb_flag &= ~(LPFC_IO_WAKE | LPFC_IO_WAKE_TMO); |
dea3101e | 10612 | |
875fbdfe | 10613 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
9940b97b JS |
10614 | if (lpfc_readl(phba->HCregaddr, &creg_val)) |
10615 | return IOCB_ERROR; | |
875fbdfe JSEC |
10616 | creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING); |
10617 | writel(creg_val, phba->HCregaddr); | |
10618 | readl(phba->HCregaddr); /* flush */ | |
10619 | } | |
10620 | ||
2a9bf3d0 JS |
10621 | retval = lpfc_sli_issue_iocb(phba, ring_number, piocb, |
10622 | SLI_IOCB_RET_IOCB); | |
68876920 | 10623 | if (retval == IOCB_SUCCESS) { |
256ec0d0 | 10624 | timeout_req = msecs_to_jiffies(timeout * 1000); |
68876920 | 10625 | timeleft = wait_event_timeout(done_q, |
d11e31dd | 10626 | lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE), |
68876920 | 10627 | timeout_req); |
5a0916b4 JS |
10628 | spin_lock_irqsave(&phba->hbalock, iflags); |
10629 | if (!(piocb->iocb_flag & LPFC_IO_WAKE)) { | |
10630 | ||
10631 | /* | |
10632 | * IOCB timed out. Inform the wake iocb wait | |
10633 | * completion function and set local status | |
10634 | */ | |
dea3101e | 10635 | |
5a0916b4 JS |
10636 | iocb_completed = false; |
10637 | piocb->iocb_flag |= LPFC_IO_WAKE_TMO; | |
10638 | } | |
10639 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
10640 | if (iocb_completed) { | |
7054a606 | 10641 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
e8b62011 | 10642 | "0331 IOCB wake signaled\n"); |
53151bbb JS |
10643 | /* Note: we are not indicating if the IOCB has a success |
10644 | * status or not - that's for the caller to check. | |
10645 | * IOCB_SUCCESS means just that the command was sent and | |
10646 | * completed. Not that it completed successfully. | |
10647 | * */ | |
7054a606 | 10648 | } else if (timeleft == 0) { |
68876920 | 10649 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
e8b62011 JS |
10650 | "0338 IOCB wait timeout error - no " |
10651 | "wake response Data x%x\n", timeout); | |
68876920 | 10652 | retval = IOCB_TIMEDOUT; |
7054a606 | 10653 | } else { |
68876920 | 10654 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
e8b62011 JS |
10655 | "0330 IOCB wake NOT set, " |
10656 | "Data x%x x%lx\n", | |
68876920 JSEC |
10657 | timeout, (timeleft / jiffies)); |
10658 | retval = IOCB_TIMEDOUT; | |
dea3101e | 10659 | } |
2a9bf3d0 | 10660 | } else if (retval == IOCB_BUSY) { |
0e9bb8d7 JS |
10661 | if (phba->cfg_log_verbose & LOG_SLI) { |
10662 | list_for_each_entry(iocb, &pring->txq, list) { | |
10663 | txq_cnt++; | |
10664 | } | |
10665 | list_for_each_entry(iocb, &pring->txcmplq, list) { | |
10666 | txcmplq_cnt++; | |
10667 | } | |
10668 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
10669 | "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n", | |
10670 | phba->iocb_cnt, txq_cnt, txcmplq_cnt); | |
10671 | } | |
2a9bf3d0 | 10672 | return retval; |
68876920 JSEC |
10673 | } else { |
10674 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
d7c255b2 | 10675 | "0332 IOCB wait issue failed, Data x%x\n", |
e8b62011 | 10676 | retval); |
68876920 | 10677 | retval = IOCB_ERROR; |
dea3101e JB |
10678 | } |
10679 | ||
875fbdfe | 10680 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
9940b97b JS |
10681 | if (lpfc_readl(phba->HCregaddr, &creg_val)) |
10682 | return IOCB_ERROR; | |
875fbdfe JSEC |
10683 | creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING); |
10684 | writel(creg_val, phba->HCregaddr); | |
10685 | readl(phba->HCregaddr); /* flush */ | |
10686 | } | |
10687 | ||
68876920 JSEC |
10688 | if (prspiocbq) |
10689 | piocb->context2 = NULL; | |
10690 | ||
10691 | piocb->context_un.wait_queue = NULL; | |
10692 | piocb->iocb_cmpl = NULL; | |
dea3101e JB |
10693 | return retval; |
10694 | } | |
68876920 | 10695 | |
e59058c4 | 10696 | /** |
3621a710 | 10697 | * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox |
e59058c4 JS |
10698 | * @phba: Pointer to HBA context object. |
10699 | * @pmboxq: Pointer to driver mailbox object. | |
10700 | * @timeout: Timeout in number of seconds. | |
10701 | * | |
10702 | * This function issues the mailbox to firmware and waits for the | |
10703 | * mailbox command to complete. If the mailbox command is not | |
10704 | * completed within timeout seconds, it returns MBX_TIMEOUT. | |
10705 | * The function waits for the mailbox completion using an | |
10706 | * interruptible wait. If the thread is woken up due to a | |
10707 | * signal, MBX_TIMEOUT error is returned to the caller. Caller | |
10708 | * should not free the mailbox resources, if this function returns | |
10709 | * MBX_TIMEOUT. | |
10710 | * This function will sleep while waiting for mailbox completion. | |
10711 | * So, this function should not be called from any context which | |
10712 | * does not allow sleeping. Due to the same reason, this function | |
10713 | * cannot be called with interrupt disabled. | |
10714 | * This function assumes that the mailbox completion occurs while | |
10715 | * this function sleep. So, this function cannot be called from | |
10716 | * the worker thread which processes mailbox completion. | |
10717 | * This function is called in the context of HBA management | |
10718 | * applications. | |
10719 | * This function returns MBX_SUCCESS when successful. | |
10720 | * This function is called with no lock held. | |
10721 | **/ | |
dea3101e | 10722 | int |
2e0fef85 | 10723 | lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq, |
dea3101e JB |
10724 | uint32_t timeout) |
10725 | { | |
7259f0d0 | 10726 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
b230b8a2 | 10727 | MAILBOX_t *mb = NULL; |
dea3101e | 10728 | int retval; |
858c9f6c | 10729 | unsigned long flag; |
dea3101e | 10730 | |
b230b8a2 | 10731 | /* The caller might set context1 for extended buffer */ |
98c9ea5c | 10732 | if (pmboxq->context1) |
b230b8a2 | 10733 | mb = (MAILBOX_t *)pmboxq->context1; |
dea3101e | 10734 | |
495a714c | 10735 | pmboxq->mbox_flag &= ~LPFC_MBX_WAKE; |
dea3101e JB |
10736 | /* setup wake call as IOCB callback */ |
10737 | pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait; | |
10738 | /* setup context field to pass wait_queue pointer to wake function */ | |
10739 | pmboxq->context1 = &done_q; | |
10740 | ||
dea3101e JB |
10741 | /* now issue the command */ |
10742 | retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT); | |
dea3101e | 10743 | if (retval == MBX_BUSY || retval == MBX_SUCCESS) { |
7054a606 JS |
10744 | wait_event_interruptible_timeout(done_q, |
10745 | pmboxq->mbox_flag & LPFC_MBX_WAKE, | |
256ec0d0 | 10746 | msecs_to_jiffies(timeout * 1000)); |
7054a606 | 10747 | |
858c9f6c | 10748 | spin_lock_irqsave(&phba->hbalock, flag); |
b230b8a2 JS |
10749 | /* restore the possible extended buffer for free resource */ |
10750 | pmboxq->context1 = (uint8_t *)mb; | |
7054a606 JS |
10751 | /* |
10752 | * if LPFC_MBX_WAKE flag is set the mailbox is completed | |
10753 | * else do not free the resources. | |
10754 | */ | |
d7c47992 | 10755 | if (pmboxq->mbox_flag & LPFC_MBX_WAKE) { |
dea3101e | 10756 | retval = MBX_SUCCESS; |
d7c47992 | 10757 | } else { |
7054a606 | 10758 | retval = MBX_TIMEOUT; |
858c9f6c JS |
10759 | pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
10760 | } | |
10761 | spin_unlock_irqrestore(&phba->hbalock, flag); | |
b230b8a2 JS |
10762 | } else { |
10763 | /* restore the possible extended buffer for free resource */ | |
10764 | pmboxq->context1 = (uint8_t *)mb; | |
dea3101e JB |
10765 | } |
10766 | ||
dea3101e JB |
10767 | return retval; |
10768 | } | |
10769 | ||
e59058c4 | 10770 | /** |
3772a991 | 10771 | * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system |
e59058c4 JS |
10772 | * @phba: Pointer to HBA context. |
10773 | * | |
3772a991 JS |
10774 | * This function is called to shutdown the driver's mailbox sub-system. |
10775 | * It first marks the mailbox sub-system is in a block state to prevent | |
10776 | * the asynchronous mailbox command from issued off the pending mailbox | |
10777 | * command queue. If the mailbox command sub-system shutdown is due to | |
10778 | * HBA error conditions such as EEH or ERATT, this routine shall invoke | |
10779 | * the mailbox sub-system flush routine to forcefully bring down the | |
10780 | * mailbox sub-system. Otherwise, if it is due to normal condition (such | |
10781 | * as with offline or HBA function reset), this routine will wait for the | |
10782 | * outstanding mailbox command to complete before invoking the mailbox | |
10783 | * sub-system flush routine to gracefully bring down mailbox sub-system. | |
e59058c4 | 10784 | **/ |
3772a991 | 10785 | void |
618a5230 | 10786 | lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba, int mbx_action) |
b4c02652 | 10787 | { |
3772a991 | 10788 | struct lpfc_sli *psli = &phba->sli; |
3772a991 | 10789 | unsigned long timeout; |
b4c02652 | 10790 | |
618a5230 JS |
10791 | if (mbx_action == LPFC_MBX_NO_WAIT) { |
10792 | /* delay 100ms for port state */ | |
10793 | msleep(100); | |
10794 | lpfc_sli_mbox_sys_flush(phba); | |
10795 | return; | |
10796 | } | |
a183a15f | 10797 | timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies; |
d7069f09 | 10798 | |
3772a991 JS |
10799 | spin_lock_irq(&phba->hbalock); |
10800 | psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; | |
b4c02652 | 10801 | |
3772a991 | 10802 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
3772a991 JS |
10803 | /* Determine how long we might wait for the active mailbox |
10804 | * command to be gracefully completed by firmware. | |
10805 | */ | |
a183a15f JS |
10806 | if (phba->sli.mbox_active) |
10807 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, | |
10808 | phba->sli.mbox_active) * | |
10809 | 1000) + jiffies; | |
10810 | spin_unlock_irq(&phba->hbalock); | |
10811 | ||
3772a991 JS |
10812 | while (phba->sli.mbox_active) { |
10813 | /* Check active mailbox complete status every 2ms */ | |
10814 | msleep(2); | |
10815 | if (time_after(jiffies, timeout)) | |
10816 | /* Timeout, let the mailbox flush routine to | |
10817 | * forcefully release active mailbox command | |
10818 | */ | |
10819 | break; | |
10820 | } | |
d7069f09 JS |
10821 | } else |
10822 | spin_unlock_irq(&phba->hbalock); | |
10823 | ||
3772a991 JS |
10824 | lpfc_sli_mbox_sys_flush(phba); |
10825 | } | |
ed957684 | 10826 | |
3772a991 JS |
10827 | /** |
10828 | * lpfc_sli_eratt_read - read sli-3 error attention events | |
10829 | * @phba: Pointer to HBA context. | |
10830 | * | |
10831 | * This function is called to read the SLI3 device error attention registers | |
10832 | * for possible error attention events. The caller must hold the hostlock | |
10833 | * with spin_lock_irq(). | |
10834 | * | |
25985edc | 10835 | * This function returns 1 when there is Error Attention in the Host Attention |
3772a991 JS |
10836 | * Register and returns 0 otherwise. |
10837 | **/ | |
10838 | static int | |
10839 | lpfc_sli_eratt_read(struct lpfc_hba *phba) | |
10840 | { | |
10841 | uint32_t ha_copy; | |
b4c02652 | 10842 | |
3772a991 | 10843 | /* Read chip Host Attention (HA) register */ |
9940b97b JS |
10844 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
10845 | goto unplug_err; | |
10846 | ||
3772a991 JS |
10847 | if (ha_copy & HA_ERATT) { |
10848 | /* Read host status register to retrieve error event */ | |
9940b97b JS |
10849 | if (lpfc_sli_read_hs(phba)) |
10850 | goto unplug_err; | |
b4c02652 | 10851 | |
3772a991 JS |
10852 | /* Check if there is a deferred error condition is active */ |
10853 | if ((HS_FFER1 & phba->work_hs) && | |
10854 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | | |
dcf2a4e0 | 10855 | HS_FFER6 | HS_FFER7 | HS_FFER8) & phba->work_hs)) { |
3772a991 | 10856 | phba->hba_flag |= DEFER_ERATT; |
3772a991 JS |
10857 | /* Clear all interrupt enable conditions */ |
10858 | writel(0, phba->HCregaddr); | |
10859 | readl(phba->HCregaddr); | |
10860 | } | |
10861 | ||
10862 | /* Set the driver HA work bitmap */ | |
3772a991 JS |
10863 | phba->work_ha |= HA_ERATT; |
10864 | /* Indicate polling handles this ERATT */ | |
10865 | phba->hba_flag |= HBA_ERATT_HANDLED; | |
3772a991 JS |
10866 | return 1; |
10867 | } | |
10868 | return 0; | |
9940b97b JS |
10869 | |
10870 | unplug_err: | |
10871 | /* Set the driver HS work bitmap */ | |
10872 | phba->work_hs |= UNPLUG_ERR; | |
10873 | /* Set the driver HA work bitmap */ | |
10874 | phba->work_ha |= HA_ERATT; | |
10875 | /* Indicate polling handles this ERATT */ | |
10876 | phba->hba_flag |= HBA_ERATT_HANDLED; | |
10877 | return 1; | |
b4c02652 JS |
10878 | } |
10879 | ||
da0436e9 JS |
10880 | /** |
10881 | * lpfc_sli4_eratt_read - read sli-4 error attention events | |
10882 | * @phba: Pointer to HBA context. | |
10883 | * | |
10884 | * This function is called to read the SLI4 device error attention registers | |
10885 | * for possible error attention events. The caller must hold the hostlock | |
10886 | * with spin_lock_irq(). | |
10887 | * | |
25985edc | 10888 | * This function returns 1 when there is Error Attention in the Host Attention |
da0436e9 JS |
10889 | * Register and returns 0 otherwise. |
10890 | **/ | |
10891 | static int | |
10892 | lpfc_sli4_eratt_read(struct lpfc_hba *phba) | |
10893 | { | |
10894 | uint32_t uerr_sta_hi, uerr_sta_lo; | |
2fcee4bf JS |
10895 | uint32_t if_type, portsmphr; |
10896 | struct lpfc_register portstat_reg; | |
da0436e9 | 10897 | |
2fcee4bf JS |
10898 | /* |
10899 | * For now, use the SLI4 device internal unrecoverable error | |
da0436e9 JS |
10900 | * registers for error attention. This can be changed later. |
10901 | */ | |
2fcee4bf JS |
10902 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
10903 | switch (if_type) { | |
10904 | case LPFC_SLI_INTF_IF_TYPE_0: | |
9940b97b JS |
10905 | if (lpfc_readl(phba->sli4_hba.u.if_type0.UERRLOregaddr, |
10906 | &uerr_sta_lo) || | |
10907 | lpfc_readl(phba->sli4_hba.u.if_type0.UERRHIregaddr, | |
10908 | &uerr_sta_hi)) { | |
10909 | phba->work_hs |= UNPLUG_ERR; | |
10910 | phba->work_ha |= HA_ERATT; | |
10911 | phba->hba_flag |= HBA_ERATT_HANDLED; | |
10912 | return 1; | |
10913 | } | |
2fcee4bf JS |
10914 | if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) || |
10915 | (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) { | |
10916 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
10917 | "1423 HBA Unrecoverable error: " | |
10918 | "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, " | |
10919 | "ue_mask_lo_reg=0x%x, " | |
10920 | "ue_mask_hi_reg=0x%x\n", | |
10921 | uerr_sta_lo, uerr_sta_hi, | |
10922 | phba->sli4_hba.ue_mask_lo, | |
10923 | phba->sli4_hba.ue_mask_hi); | |
10924 | phba->work_status[0] = uerr_sta_lo; | |
10925 | phba->work_status[1] = uerr_sta_hi; | |
10926 | phba->work_ha |= HA_ERATT; | |
10927 | phba->hba_flag |= HBA_ERATT_HANDLED; | |
10928 | return 1; | |
10929 | } | |
10930 | break; | |
10931 | case LPFC_SLI_INTF_IF_TYPE_2: | |
9940b97b JS |
10932 | if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr, |
10933 | &portstat_reg.word0) || | |
10934 | lpfc_readl(phba->sli4_hba.PSMPHRregaddr, | |
10935 | &portsmphr)){ | |
10936 | phba->work_hs |= UNPLUG_ERR; | |
10937 | phba->work_ha |= HA_ERATT; | |
10938 | phba->hba_flag |= HBA_ERATT_HANDLED; | |
10939 | return 1; | |
10940 | } | |
2fcee4bf JS |
10941 | if (bf_get(lpfc_sliport_status_err, &portstat_reg)) { |
10942 | phba->work_status[0] = | |
10943 | readl(phba->sli4_hba.u.if_type2.ERR1regaddr); | |
10944 | phba->work_status[1] = | |
10945 | readl(phba->sli4_hba.u.if_type2.ERR2regaddr); | |
10946 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
2e90f4b5 | 10947 | "2885 Port Status Event: " |
2fcee4bf JS |
10948 | "port status reg 0x%x, " |
10949 | "port smphr reg 0x%x, " | |
10950 | "error 1=0x%x, error 2=0x%x\n", | |
10951 | portstat_reg.word0, | |
10952 | portsmphr, | |
10953 | phba->work_status[0], | |
10954 | phba->work_status[1]); | |
10955 | phba->work_ha |= HA_ERATT; | |
10956 | phba->hba_flag |= HBA_ERATT_HANDLED; | |
10957 | return 1; | |
10958 | } | |
10959 | break; | |
10960 | case LPFC_SLI_INTF_IF_TYPE_1: | |
10961 | default: | |
a747c9ce | 10962 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
2fcee4bf JS |
10963 | "2886 HBA Error Attention on unsupported " |
10964 | "if type %d.", if_type); | |
a747c9ce | 10965 | return 1; |
da0436e9 | 10966 | } |
2fcee4bf | 10967 | |
da0436e9 JS |
10968 | return 0; |
10969 | } | |
10970 | ||
e59058c4 | 10971 | /** |
3621a710 | 10972 | * lpfc_sli_check_eratt - check error attention events |
9399627f JS |
10973 | * @phba: Pointer to HBA context. |
10974 | * | |
3772a991 | 10975 | * This function is called from timer soft interrupt context to check HBA's |
9399627f JS |
10976 | * error attention register bit for error attention events. |
10977 | * | |
25985edc | 10978 | * This function returns 1 when there is Error Attention in the Host Attention |
9399627f JS |
10979 | * Register and returns 0 otherwise. |
10980 | **/ | |
10981 | int | |
10982 | lpfc_sli_check_eratt(struct lpfc_hba *phba) | |
10983 | { | |
10984 | uint32_t ha_copy; | |
10985 | ||
10986 | /* If somebody is waiting to handle an eratt, don't process it | |
10987 | * here. The brdkill function will do this. | |
10988 | */ | |
10989 | if (phba->link_flag & LS_IGNORE_ERATT) | |
10990 | return 0; | |
10991 | ||
10992 | /* Check if interrupt handler handles this ERATT */ | |
10993 | spin_lock_irq(&phba->hbalock); | |
10994 | if (phba->hba_flag & HBA_ERATT_HANDLED) { | |
10995 | /* Interrupt handler has handled ERATT */ | |
10996 | spin_unlock_irq(&phba->hbalock); | |
10997 | return 0; | |
10998 | } | |
10999 | ||
a257bf90 JS |
11000 | /* |
11001 | * If there is deferred error attention, do not check for error | |
11002 | * attention | |
11003 | */ | |
11004 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { | |
11005 | spin_unlock_irq(&phba->hbalock); | |
11006 | return 0; | |
11007 | } | |
11008 | ||
3772a991 JS |
11009 | /* If PCI channel is offline, don't process it */ |
11010 | if (unlikely(pci_channel_offline(phba->pcidev))) { | |
9399627f | 11011 | spin_unlock_irq(&phba->hbalock); |
3772a991 JS |
11012 | return 0; |
11013 | } | |
11014 | ||
11015 | switch (phba->sli_rev) { | |
11016 | case LPFC_SLI_REV2: | |
11017 | case LPFC_SLI_REV3: | |
11018 | /* Read chip Host Attention (HA) register */ | |
11019 | ha_copy = lpfc_sli_eratt_read(phba); | |
11020 | break; | |
da0436e9 | 11021 | case LPFC_SLI_REV4: |
2fcee4bf | 11022 | /* Read device Uncoverable Error (UERR) registers */ |
da0436e9 JS |
11023 | ha_copy = lpfc_sli4_eratt_read(phba); |
11024 | break; | |
3772a991 JS |
11025 | default: |
11026 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
11027 | "0299 Invalid SLI revision (%d)\n", | |
11028 | phba->sli_rev); | |
11029 | ha_copy = 0; | |
11030 | break; | |
9399627f JS |
11031 | } |
11032 | spin_unlock_irq(&phba->hbalock); | |
3772a991 JS |
11033 | |
11034 | return ha_copy; | |
11035 | } | |
11036 | ||
11037 | /** | |
11038 | * lpfc_intr_state_check - Check device state for interrupt handling | |
11039 | * @phba: Pointer to HBA context. | |
11040 | * | |
11041 | * This inline routine checks whether a device or its PCI slot is in a state | |
11042 | * that the interrupt should be handled. | |
11043 | * | |
11044 | * This function returns 0 if the device or the PCI slot is in a state that | |
11045 | * interrupt should be handled, otherwise -EIO. | |
11046 | */ | |
11047 | static inline int | |
11048 | lpfc_intr_state_check(struct lpfc_hba *phba) | |
11049 | { | |
11050 | /* If the pci channel is offline, ignore all the interrupts */ | |
11051 | if (unlikely(pci_channel_offline(phba->pcidev))) | |
11052 | return -EIO; | |
11053 | ||
11054 | /* Update device level interrupt statistics */ | |
11055 | phba->sli.slistat.sli_intr++; | |
11056 | ||
11057 | /* Ignore all interrupts during initialization. */ | |
11058 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) | |
11059 | return -EIO; | |
11060 | ||
9399627f JS |
11061 | return 0; |
11062 | } | |
11063 | ||
11064 | /** | |
3772a991 | 11065 | * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device |
e59058c4 JS |
11066 | * @irq: Interrupt number. |
11067 | * @dev_id: The device context pointer. | |
11068 | * | |
9399627f | 11069 | * This function is directly called from the PCI layer as an interrupt |
3772a991 JS |
11070 | * service routine when device with SLI-3 interface spec is enabled with |
11071 | * MSI-X multi-message interrupt mode and there are slow-path events in | |
11072 | * the HBA. However, when the device is enabled with either MSI or Pin-IRQ | |
11073 | * interrupt mode, this function is called as part of the device-level | |
11074 | * interrupt handler. When the PCI slot is in error recovery or the HBA | |
11075 | * is undergoing initialization, the interrupt handler will not process | |
11076 | * the interrupt. The link attention and ELS ring attention events are | |
11077 | * handled by the worker thread. The interrupt handler signals the worker | |
11078 | * thread and returns for these events. This function is called without | |
11079 | * any lock held. It gets the hbalock to access and update SLI data | |
9399627f JS |
11080 | * structures. |
11081 | * | |
11082 | * This function returns IRQ_HANDLED when interrupt is handled else it | |
11083 | * returns IRQ_NONE. | |
e59058c4 | 11084 | **/ |
dea3101e | 11085 | irqreturn_t |
3772a991 | 11086 | lpfc_sli_sp_intr_handler(int irq, void *dev_id) |
dea3101e | 11087 | { |
2e0fef85 | 11088 | struct lpfc_hba *phba; |
a747c9ce | 11089 | uint32_t ha_copy, hc_copy; |
dea3101e JB |
11090 | uint32_t work_ha_copy; |
11091 | unsigned long status; | |
5b75da2f | 11092 | unsigned long iflag; |
dea3101e JB |
11093 | uint32_t control; |
11094 | ||
92d7f7b0 | 11095 | MAILBOX_t *mbox, *pmbox; |
858c9f6c JS |
11096 | struct lpfc_vport *vport; |
11097 | struct lpfc_nodelist *ndlp; | |
11098 | struct lpfc_dmabuf *mp; | |
92d7f7b0 JS |
11099 | LPFC_MBOXQ_t *pmb; |
11100 | int rc; | |
11101 | ||
dea3101e JB |
11102 | /* |
11103 | * Get the driver's phba structure from the dev_id and | |
11104 | * assume the HBA is not interrupting. | |
11105 | */ | |
9399627f | 11106 | phba = (struct lpfc_hba *)dev_id; |
dea3101e JB |
11107 | |
11108 | if (unlikely(!phba)) | |
11109 | return IRQ_NONE; | |
11110 | ||
dea3101e | 11111 | /* |
9399627f JS |
11112 | * Stuff needs to be attented to when this function is invoked as an |
11113 | * individual interrupt handler in MSI-X multi-message interrupt mode | |
dea3101e | 11114 | */ |
9399627f | 11115 | if (phba->intr_type == MSIX) { |
3772a991 JS |
11116 | /* Check device state for handling interrupt */ |
11117 | if (lpfc_intr_state_check(phba)) | |
9399627f JS |
11118 | return IRQ_NONE; |
11119 | /* Need to read HA REG for slow-path events */ | |
5b75da2f | 11120 | spin_lock_irqsave(&phba->hbalock, iflag); |
9940b97b JS |
11121 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
11122 | goto unplug_error; | |
9399627f JS |
11123 | /* If somebody is waiting to handle an eratt don't process it |
11124 | * here. The brdkill function will do this. | |
11125 | */ | |
11126 | if (phba->link_flag & LS_IGNORE_ERATT) | |
11127 | ha_copy &= ~HA_ERATT; | |
11128 | /* Check the need for handling ERATT in interrupt handler */ | |
11129 | if (ha_copy & HA_ERATT) { | |
11130 | if (phba->hba_flag & HBA_ERATT_HANDLED) | |
11131 | /* ERATT polling has handled ERATT */ | |
11132 | ha_copy &= ~HA_ERATT; | |
11133 | else | |
11134 | /* Indicate interrupt handler handles ERATT */ | |
11135 | phba->hba_flag |= HBA_ERATT_HANDLED; | |
11136 | } | |
a257bf90 JS |
11137 | |
11138 | /* | |
11139 | * If there is deferred error attention, do not check for any | |
11140 | * interrupt. | |
11141 | */ | |
11142 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { | |
3772a991 | 11143 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
a257bf90 JS |
11144 | return IRQ_NONE; |
11145 | } | |
11146 | ||
9399627f | 11147 | /* Clear up only attention source related to slow-path */ |
9940b97b JS |
11148 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) |
11149 | goto unplug_error; | |
11150 | ||
a747c9ce JS |
11151 | writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA | |
11152 | HC_LAINT_ENA | HC_ERINT_ENA), | |
11153 | phba->HCregaddr); | |
9399627f JS |
11154 | writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)), |
11155 | phba->HAregaddr); | |
a747c9ce | 11156 | writel(hc_copy, phba->HCregaddr); |
9399627f | 11157 | readl(phba->HAregaddr); /* flush */ |
5b75da2f | 11158 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
9399627f JS |
11159 | } else |
11160 | ha_copy = phba->ha_copy; | |
dea3101e | 11161 | |
dea3101e JB |
11162 | work_ha_copy = ha_copy & phba->work_ha_mask; |
11163 | ||
9399627f | 11164 | if (work_ha_copy) { |
dea3101e JB |
11165 | if (work_ha_copy & HA_LATT) { |
11166 | if (phba->sli.sli_flag & LPFC_PROCESS_LA) { | |
11167 | /* | |
11168 | * Turn off Link Attention interrupts | |
11169 | * until CLEAR_LA done | |
11170 | */ | |
5b75da2f | 11171 | spin_lock_irqsave(&phba->hbalock, iflag); |
dea3101e | 11172 | phba->sli.sli_flag &= ~LPFC_PROCESS_LA; |
9940b97b JS |
11173 | if (lpfc_readl(phba->HCregaddr, &control)) |
11174 | goto unplug_error; | |
dea3101e JB |
11175 | control &= ~HC_LAINT_ENA; |
11176 | writel(control, phba->HCregaddr); | |
11177 | readl(phba->HCregaddr); /* flush */ | |
5b75da2f | 11178 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
dea3101e JB |
11179 | } |
11180 | else | |
11181 | work_ha_copy &= ~HA_LATT; | |
11182 | } | |
11183 | ||
9399627f | 11184 | if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) { |
858c9f6c JS |
11185 | /* |
11186 | * Turn off Slow Rings interrupts, LPFC_ELS_RING is | |
11187 | * the only slow ring. | |
11188 | */ | |
11189 | status = (work_ha_copy & | |
11190 | (HA_RXMASK << (4*LPFC_ELS_RING))); | |
11191 | status >>= (4*LPFC_ELS_RING); | |
11192 | if (status & HA_RXMASK) { | |
5b75da2f | 11193 | spin_lock_irqsave(&phba->hbalock, iflag); |
9940b97b JS |
11194 | if (lpfc_readl(phba->HCregaddr, &control)) |
11195 | goto unplug_error; | |
a58cbd52 JS |
11196 | |
11197 | lpfc_debugfs_slow_ring_trc(phba, | |
11198 | "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x", | |
11199 | control, status, | |
11200 | (uint32_t)phba->sli.slistat.sli_intr); | |
11201 | ||
858c9f6c | 11202 | if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) { |
a58cbd52 JS |
11203 | lpfc_debugfs_slow_ring_trc(phba, |
11204 | "ISR Disable ring:" | |
11205 | "pwork:x%x hawork:x%x wait:x%x", | |
11206 | phba->work_ha, work_ha_copy, | |
11207 | (uint32_t)((unsigned long) | |
5e9d9b82 | 11208 | &phba->work_waitq)); |
a58cbd52 | 11209 | |
858c9f6c JS |
11210 | control &= |
11211 | ~(HC_R0INT_ENA << LPFC_ELS_RING); | |
dea3101e JB |
11212 | writel(control, phba->HCregaddr); |
11213 | readl(phba->HCregaddr); /* flush */ | |
dea3101e | 11214 | } |
a58cbd52 JS |
11215 | else { |
11216 | lpfc_debugfs_slow_ring_trc(phba, | |
11217 | "ISR slow ring: pwork:" | |
11218 | "x%x hawork:x%x wait:x%x", | |
11219 | phba->work_ha, work_ha_copy, | |
11220 | (uint32_t)((unsigned long) | |
5e9d9b82 | 11221 | &phba->work_waitq)); |
a58cbd52 | 11222 | } |
5b75da2f | 11223 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
dea3101e JB |
11224 | } |
11225 | } | |
5b75da2f | 11226 | spin_lock_irqsave(&phba->hbalock, iflag); |
a257bf90 | 11227 | if (work_ha_copy & HA_ERATT) { |
9940b97b JS |
11228 | if (lpfc_sli_read_hs(phba)) |
11229 | goto unplug_error; | |
a257bf90 JS |
11230 | /* |
11231 | * Check if there is a deferred error condition | |
11232 | * is active | |
11233 | */ | |
11234 | if ((HS_FFER1 & phba->work_hs) && | |
11235 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | | |
dcf2a4e0 JS |
11236 | HS_FFER6 | HS_FFER7 | HS_FFER8) & |
11237 | phba->work_hs)) { | |
a257bf90 JS |
11238 | phba->hba_flag |= DEFER_ERATT; |
11239 | /* Clear all interrupt enable conditions */ | |
11240 | writel(0, phba->HCregaddr); | |
11241 | readl(phba->HCregaddr); | |
11242 | } | |
11243 | } | |
11244 | ||
9399627f | 11245 | if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) { |
92d7f7b0 | 11246 | pmb = phba->sli.mbox_active; |
04c68496 | 11247 | pmbox = &pmb->u.mb; |
34b02dcd | 11248 | mbox = phba->mbox; |
858c9f6c | 11249 | vport = pmb->vport; |
92d7f7b0 JS |
11250 | |
11251 | /* First check out the status word */ | |
11252 | lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t)); | |
11253 | if (pmbox->mbxOwner != OWN_HOST) { | |
5b75da2f | 11254 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
92d7f7b0 JS |
11255 | /* |
11256 | * Stray Mailbox Interrupt, mbxCommand <cmd> | |
11257 | * mbxStatus <status> | |
11258 | */ | |
09372820 | 11259 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
92d7f7b0 | 11260 | LOG_SLI, |
e8b62011 | 11261 | "(%d):0304 Stray Mailbox " |
92d7f7b0 JS |
11262 | "Interrupt mbxCommand x%x " |
11263 | "mbxStatus x%x\n", | |
e8b62011 | 11264 | (vport ? vport->vpi : 0), |
92d7f7b0 JS |
11265 | pmbox->mbxCommand, |
11266 | pmbox->mbxStatus); | |
09372820 JS |
11267 | /* clear mailbox attention bit */ |
11268 | work_ha_copy &= ~HA_MBATT; | |
11269 | } else { | |
97eab634 | 11270 | phba->sli.mbox_active = NULL; |
5b75da2f | 11271 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
09372820 JS |
11272 | phba->last_completion_time = jiffies; |
11273 | del_timer(&phba->sli.mbox_tmo); | |
09372820 JS |
11274 | if (pmb->mbox_cmpl) { |
11275 | lpfc_sli_pcimem_bcopy(mbox, pmbox, | |
11276 | MAILBOX_CMD_SIZE); | |
7a470277 JS |
11277 | if (pmb->out_ext_byte_len && |
11278 | pmb->context2) | |
11279 | lpfc_sli_pcimem_bcopy( | |
11280 | phba->mbox_ext, | |
11281 | pmb->context2, | |
11282 | pmb->out_ext_byte_len); | |
09372820 JS |
11283 | } |
11284 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { | |
11285 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; | |
11286 | ||
11287 | lpfc_debugfs_disc_trc(vport, | |
11288 | LPFC_DISC_TRC_MBOX_VPORT, | |
11289 | "MBOX dflt rpi: : " | |
11290 | "status:x%x rpi:x%x", | |
11291 | (uint32_t)pmbox->mbxStatus, | |
11292 | pmbox->un.varWords[0], 0); | |
11293 | ||
11294 | if (!pmbox->mbxStatus) { | |
11295 | mp = (struct lpfc_dmabuf *) | |
11296 | (pmb->context1); | |
11297 | ndlp = (struct lpfc_nodelist *) | |
11298 | pmb->context2; | |
11299 | ||
11300 | /* Reg_LOGIN of dflt RPI was | |
11301 | * successful. new lets get | |
11302 | * rid of the RPI using the | |
11303 | * same mbox buffer. | |
11304 | */ | |
11305 | lpfc_unreg_login(phba, | |
11306 | vport->vpi, | |
11307 | pmbox->un.varWords[0], | |
11308 | pmb); | |
11309 | pmb->mbox_cmpl = | |
11310 | lpfc_mbx_cmpl_dflt_rpi; | |
11311 | pmb->context1 = mp; | |
11312 | pmb->context2 = ndlp; | |
11313 | pmb->vport = vport; | |
58da1ffb JS |
11314 | rc = lpfc_sli_issue_mbox(phba, |
11315 | pmb, | |
11316 | MBX_NOWAIT); | |
11317 | if (rc != MBX_BUSY) | |
11318 | lpfc_printf_log(phba, | |
11319 | KERN_ERR, | |
11320 | LOG_MBOX | LOG_SLI, | |
d7c255b2 | 11321 | "0350 rc should have" |
6a9c52cf | 11322 | "been MBX_BUSY\n"); |
3772a991 JS |
11323 | if (rc != MBX_NOT_FINISHED) |
11324 | goto send_current_mbox; | |
09372820 | 11325 | } |
858c9f6c | 11326 | } |
5b75da2f JS |
11327 | spin_lock_irqsave( |
11328 | &phba->pport->work_port_lock, | |
11329 | iflag); | |
09372820 JS |
11330 | phba->pport->work_port_events &= |
11331 | ~WORKER_MBOX_TMO; | |
5b75da2f JS |
11332 | spin_unlock_irqrestore( |
11333 | &phba->pport->work_port_lock, | |
11334 | iflag); | |
09372820 | 11335 | lpfc_mbox_cmpl_put(phba, pmb); |
858c9f6c | 11336 | } |
97eab634 | 11337 | } else |
5b75da2f | 11338 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
9399627f | 11339 | |
92d7f7b0 JS |
11340 | if ((work_ha_copy & HA_MBATT) && |
11341 | (phba->sli.mbox_active == NULL)) { | |
858c9f6c | 11342 | send_current_mbox: |
92d7f7b0 | 11343 | /* Process next mailbox command if there is one */ |
58da1ffb JS |
11344 | do { |
11345 | rc = lpfc_sli_issue_mbox(phba, NULL, | |
11346 | MBX_NOWAIT); | |
11347 | } while (rc == MBX_NOT_FINISHED); | |
11348 | if (rc != MBX_SUCCESS) | |
11349 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | | |
11350 | LOG_SLI, "0349 rc should be " | |
6a9c52cf | 11351 | "MBX_SUCCESS\n"); |
92d7f7b0 JS |
11352 | } |
11353 | ||
5b75da2f | 11354 | spin_lock_irqsave(&phba->hbalock, iflag); |
dea3101e | 11355 | phba->work_ha |= work_ha_copy; |
5b75da2f | 11356 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
5e9d9b82 | 11357 | lpfc_worker_wake_up(phba); |
dea3101e | 11358 | } |
9399627f | 11359 | return IRQ_HANDLED; |
9940b97b JS |
11360 | unplug_error: |
11361 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
11362 | return IRQ_HANDLED; | |
dea3101e | 11363 | |
3772a991 | 11364 | } /* lpfc_sli_sp_intr_handler */ |
9399627f JS |
11365 | |
11366 | /** | |
3772a991 | 11367 | * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device. |
9399627f JS |
11368 | * @irq: Interrupt number. |
11369 | * @dev_id: The device context pointer. | |
11370 | * | |
11371 | * This function is directly called from the PCI layer as an interrupt | |
3772a991 JS |
11372 | * service routine when device with SLI-3 interface spec is enabled with |
11373 | * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB | |
11374 | * ring event in the HBA. However, when the device is enabled with either | |
11375 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the | |
11376 | * device-level interrupt handler. When the PCI slot is in error recovery | |
11377 | * or the HBA is undergoing initialization, the interrupt handler will not | |
11378 | * process the interrupt. The SCSI FCP fast-path ring event are handled in | |
11379 | * the intrrupt context. This function is called without any lock held. | |
11380 | * It gets the hbalock to access and update SLI data structures. | |
9399627f JS |
11381 | * |
11382 | * This function returns IRQ_HANDLED when interrupt is handled else it | |
11383 | * returns IRQ_NONE. | |
11384 | **/ | |
11385 | irqreturn_t | |
3772a991 | 11386 | lpfc_sli_fp_intr_handler(int irq, void *dev_id) |
9399627f JS |
11387 | { |
11388 | struct lpfc_hba *phba; | |
11389 | uint32_t ha_copy; | |
11390 | unsigned long status; | |
5b75da2f | 11391 | unsigned long iflag; |
9399627f JS |
11392 | |
11393 | /* Get the driver's phba structure from the dev_id and | |
11394 | * assume the HBA is not interrupting. | |
11395 | */ | |
11396 | phba = (struct lpfc_hba *) dev_id; | |
11397 | ||
11398 | if (unlikely(!phba)) | |
11399 | return IRQ_NONE; | |
11400 | ||
11401 | /* | |
11402 | * Stuff needs to be attented to when this function is invoked as an | |
11403 | * individual interrupt handler in MSI-X multi-message interrupt mode | |
11404 | */ | |
11405 | if (phba->intr_type == MSIX) { | |
3772a991 JS |
11406 | /* Check device state for handling interrupt */ |
11407 | if (lpfc_intr_state_check(phba)) | |
9399627f JS |
11408 | return IRQ_NONE; |
11409 | /* Need to read HA REG for FCP ring and other ring events */ | |
9940b97b JS |
11410 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
11411 | return IRQ_HANDLED; | |
9399627f | 11412 | /* Clear up only attention source related to fast-path */ |
5b75da2f | 11413 | spin_lock_irqsave(&phba->hbalock, iflag); |
a257bf90 JS |
11414 | /* |
11415 | * If there is deferred error attention, do not check for | |
11416 | * any interrupt. | |
11417 | */ | |
11418 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { | |
3772a991 | 11419 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
a257bf90 JS |
11420 | return IRQ_NONE; |
11421 | } | |
9399627f JS |
11422 | writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)), |
11423 | phba->HAregaddr); | |
11424 | readl(phba->HAregaddr); /* flush */ | |
5b75da2f | 11425 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
9399627f JS |
11426 | } else |
11427 | ha_copy = phba->ha_copy; | |
dea3101e JB |
11428 | |
11429 | /* | |
9399627f | 11430 | * Process all events on FCP ring. Take the optimized path for FCP IO. |
dea3101e | 11431 | */ |
9399627f JS |
11432 | ha_copy &= ~(phba->work_ha_mask); |
11433 | ||
11434 | status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); | |
dea3101e | 11435 | status >>= (4*LPFC_FCP_RING); |
858c9f6c | 11436 | if (status & HA_RXMASK) |
dea3101e JB |
11437 | lpfc_sli_handle_fast_ring_event(phba, |
11438 | &phba->sli.ring[LPFC_FCP_RING], | |
11439 | status); | |
a4bc3379 JS |
11440 | |
11441 | if (phba->cfg_multi_ring_support == 2) { | |
11442 | /* | |
9399627f JS |
11443 | * Process all events on extra ring. Take the optimized path |
11444 | * for extra ring IO. | |
a4bc3379 | 11445 | */ |
9399627f | 11446 | status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); |
a4bc3379 | 11447 | status >>= (4*LPFC_EXTRA_RING); |
858c9f6c | 11448 | if (status & HA_RXMASK) { |
a4bc3379 JS |
11449 | lpfc_sli_handle_fast_ring_event(phba, |
11450 | &phba->sli.ring[LPFC_EXTRA_RING], | |
11451 | status); | |
11452 | } | |
11453 | } | |
dea3101e | 11454 | return IRQ_HANDLED; |
3772a991 | 11455 | } /* lpfc_sli_fp_intr_handler */ |
9399627f JS |
11456 | |
11457 | /** | |
3772a991 | 11458 | * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device |
9399627f JS |
11459 | * @irq: Interrupt number. |
11460 | * @dev_id: The device context pointer. | |
11461 | * | |
3772a991 JS |
11462 | * This function is the HBA device-level interrupt handler to device with |
11463 | * SLI-3 interface spec, called from the PCI layer when either MSI or | |
11464 | * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which | |
11465 | * requires driver attention. This function invokes the slow-path interrupt | |
11466 | * attention handling function and fast-path interrupt attention handling | |
11467 | * function in turn to process the relevant HBA attention events. This | |
11468 | * function is called without any lock held. It gets the hbalock to access | |
11469 | * and update SLI data structures. | |
9399627f JS |
11470 | * |
11471 | * This function returns IRQ_HANDLED when interrupt is handled, else it | |
11472 | * returns IRQ_NONE. | |
11473 | **/ | |
11474 | irqreturn_t | |
3772a991 | 11475 | lpfc_sli_intr_handler(int irq, void *dev_id) |
9399627f JS |
11476 | { |
11477 | struct lpfc_hba *phba; | |
11478 | irqreturn_t sp_irq_rc, fp_irq_rc; | |
11479 | unsigned long status1, status2; | |
a747c9ce | 11480 | uint32_t hc_copy; |
9399627f JS |
11481 | |
11482 | /* | |
11483 | * Get the driver's phba structure from the dev_id and | |
11484 | * assume the HBA is not interrupting. | |
11485 | */ | |
11486 | phba = (struct lpfc_hba *) dev_id; | |
11487 | ||
11488 | if (unlikely(!phba)) | |
11489 | return IRQ_NONE; | |
11490 | ||
3772a991 JS |
11491 | /* Check device state for handling interrupt */ |
11492 | if (lpfc_intr_state_check(phba)) | |
9399627f JS |
11493 | return IRQ_NONE; |
11494 | ||
11495 | spin_lock(&phba->hbalock); | |
9940b97b JS |
11496 | if (lpfc_readl(phba->HAregaddr, &phba->ha_copy)) { |
11497 | spin_unlock(&phba->hbalock); | |
11498 | return IRQ_HANDLED; | |
11499 | } | |
11500 | ||
9399627f JS |
11501 | if (unlikely(!phba->ha_copy)) { |
11502 | spin_unlock(&phba->hbalock); | |
11503 | return IRQ_NONE; | |
11504 | } else if (phba->ha_copy & HA_ERATT) { | |
11505 | if (phba->hba_flag & HBA_ERATT_HANDLED) | |
11506 | /* ERATT polling has handled ERATT */ | |
11507 | phba->ha_copy &= ~HA_ERATT; | |
11508 | else | |
11509 | /* Indicate interrupt handler handles ERATT */ | |
11510 | phba->hba_flag |= HBA_ERATT_HANDLED; | |
11511 | } | |
11512 | ||
a257bf90 JS |
11513 | /* |
11514 | * If there is deferred error attention, do not check for any interrupt. | |
11515 | */ | |
11516 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { | |
ec21b3b0 | 11517 | spin_unlock(&phba->hbalock); |
a257bf90 JS |
11518 | return IRQ_NONE; |
11519 | } | |
11520 | ||
9399627f | 11521 | /* Clear attention sources except link and error attentions */ |
9940b97b JS |
11522 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) { |
11523 | spin_unlock(&phba->hbalock); | |
11524 | return IRQ_HANDLED; | |
11525 | } | |
a747c9ce JS |
11526 | writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA |
11527 | | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA), | |
11528 | phba->HCregaddr); | |
9399627f | 11529 | writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr); |
a747c9ce | 11530 | writel(hc_copy, phba->HCregaddr); |
9399627f JS |
11531 | readl(phba->HAregaddr); /* flush */ |
11532 | spin_unlock(&phba->hbalock); | |
11533 | ||
11534 | /* | |
11535 | * Invokes slow-path host attention interrupt handling as appropriate. | |
11536 | */ | |
11537 | ||
11538 | /* status of events with mailbox and link attention */ | |
11539 | status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT); | |
11540 | ||
11541 | /* status of events with ELS ring */ | |
11542 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING))); | |
11543 | status2 >>= (4*LPFC_ELS_RING); | |
11544 | ||
11545 | if (status1 || (status2 & HA_RXMASK)) | |
3772a991 | 11546 | sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id); |
9399627f JS |
11547 | else |
11548 | sp_irq_rc = IRQ_NONE; | |
11549 | ||
11550 | /* | |
11551 | * Invoke fast-path host attention interrupt handling as appropriate. | |
11552 | */ | |
11553 | ||
11554 | /* status of events with FCP ring */ | |
11555 | status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); | |
11556 | status1 >>= (4*LPFC_FCP_RING); | |
11557 | ||
11558 | /* status of events with extra ring */ | |
11559 | if (phba->cfg_multi_ring_support == 2) { | |
11560 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); | |
11561 | status2 >>= (4*LPFC_EXTRA_RING); | |
11562 | } else | |
11563 | status2 = 0; | |
11564 | ||
11565 | if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK)) | |
3772a991 | 11566 | fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id); |
9399627f JS |
11567 | else |
11568 | fp_irq_rc = IRQ_NONE; | |
dea3101e | 11569 | |
9399627f JS |
11570 | /* Return device-level interrupt handling status */ |
11571 | return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc; | |
3772a991 | 11572 | } /* lpfc_sli_intr_handler */ |
4f774513 JS |
11573 | |
11574 | /** | |
11575 | * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event | |
11576 | * @phba: pointer to lpfc hba data structure. | |
11577 | * | |
11578 | * This routine is invoked by the worker thread to process all the pending | |
11579 | * SLI4 FCP abort XRI events. | |
11580 | **/ | |
11581 | void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *phba) | |
11582 | { | |
11583 | struct lpfc_cq_event *cq_event; | |
11584 | ||
11585 | /* First, declare the fcp xri abort event has been handled */ | |
11586 | spin_lock_irq(&phba->hbalock); | |
11587 | phba->hba_flag &= ~FCP_XRI_ABORT_EVENT; | |
11588 | spin_unlock_irq(&phba->hbalock); | |
11589 | /* Now, handle all the fcp xri abort events */ | |
11590 | while (!list_empty(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue)) { | |
11591 | /* Get the first event from the head of the event queue */ | |
11592 | spin_lock_irq(&phba->hbalock); | |
11593 | list_remove_head(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue, | |
11594 | cq_event, struct lpfc_cq_event, list); | |
11595 | spin_unlock_irq(&phba->hbalock); | |
11596 | /* Notify aborted XRI for FCP work queue */ | |
11597 | lpfc_sli4_fcp_xri_aborted(phba, &cq_event->cqe.wcqe_axri); | |
11598 | /* Free the event processed back to the free pool */ | |
11599 | lpfc_sli4_cq_event_release(phba, cq_event); | |
11600 | } | |
11601 | } | |
11602 | ||
11603 | /** | |
11604 | * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event | |
11605 | * @phba: pointer to lpfc hba data structure. | |
11606 | * | |
11607 | * This routine is invoked by the worker thread to process all the pending | |
11608 | * SLI4 els abort xri events. | |
11609 | **/ | |
11610 | void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba) | |
11611 | { | |
11612 | struct lpfc_cq_event *cq_event; | |
11613 | ||
11614 | /* First, declare the els xri abort event has been handled */ | |
11615 | spin_lock_irq(&phba->hbalock); | |
11616 | phba->hba_flag &= ~ELS_XRI_ABORT_EVENT; | |
11617 | spin_unlock_irq(&phba->hbalock); | |
11618 | /* Now, handle all the els xri abort events */ | |
11619 | while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) { | |
11620 | /* Get the first event from the head of the event queue */ | |
11621 | spin_lock_irq(&phba->hbalock); | |
11622 | list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue, | |
11623 | cq_event, struct lpfc_cq_event, list); | |
11624 | spin_unlock_irq(&phba->hbalock); | |
11625 | /* Notify aborted XRI for ELS work queue */ | |
11626 | lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri); | |
11627 | /* Free the event processed back to the free pool */ | |
11628 | lpfc_sli4_cq_event_release(phba, cq_event); | |
11629 | } | |
11630 | } | |
11631 | ||
341af102 JS |
11632 | /** |
11633 | * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn | |
11634 | * @phba: pointer to lpfc hba data structure | |
11635 | * @pIocbIn: pointer to the rspiocbq | |
11636 | * @pIocbOut: pointer to the cmdiocbq | |
11637 | * @wcqe: pointer to the complete wcqe | |
11638 | * | |
11639 | * This routine transfers the fields of a command iocbq to a response iocbq | |
11640 | * by copying all the IOCB fields from command iocbq and transferring the | |
11641 | * completion status information from the complete wcqe. | |
11642 | **/ | |
4f774513 | 11643 | static void |
341af102 JS |
11644 | lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba, |
11645 | struct lpfc_iocbq *pIocbIn, | |
4f774513 JS |
11646 | struct lpfc_iocbq *pIocbOut, |
11647 | struct lpfc_wcqe_complete *wcqe) | |
11648 | { | |
af22741c | 11649 | int numBdes, i; |
341af102 | 11650 | unsigned long iflags; |
af22741c JS |
11651 | uint32_t status, max_response; |
11652 | struct lpfc_dmabuf *dmabuf; | |
11653 | struct ulp_bde64 *bpl, bde; | |
4f774513 JS |
11654 | size_t offset = offsetof(struct lpfc_iocbq, iocb); |
11655 | ||
11656 | memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset, | |
11657 | sizeof(struct lpfc_iocbq) - offset); | |
4f774513 | 11658 | /* Map WCQE parameters into irspiocb parameters */ |
acd6859b JS |
11659 | status = bf_get(lpfc_wcqe_c_status, wcqe); |
11660 | pIocbIn->iocb.ulpStatus = (status & LPFC_IOCB_STATUS_MASK); | |
4f774513 JS |
11661 | if (pIocbOut->iocb_flag & LPFC_IO_FCP) |
11662 | if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR) | |
11663 | pIocbIn->iocb.un.fcpi.fcpi_parm = | |
11664 | pIocbOut->iocb.un.fcpi.fcpi_parm - | |
11665 | wcqe->total_data_placed; | |
11666 | else | |
11667 | pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter; | |
695a814e | 11668 | else { |
4f774513 | 11669 | pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter; |
af22741c JS |
11670 | switch (pIocbOut->iocb.ulpCommand) { |
11671 | case CMD_ELS_REQUEST64_CR: | |
11672 | dmabuf = (struct lpfc_dmabuf *)pIocbOut->context3; | |
11673 | bpl = (struct ulp_bde64 *)dmabuf->virt; | |
11674 | bde.tus.w = le32_to_cpu(bpl[1].tus.w); | |
11675 | max_response = bde.tus.f.bdeSize; | |
11676 | break; | |
11677 | case CMD_GEN_REQUEST64_CR: | |
11678 | max_response = 0; | |
11679 | if (!pIocbOut->context3) | |
11680 | break; | |
11681 | numBdes = pIocbOut->iocb.un.genreq64.bdl.bdeSize/ | |
11682 | sizeof(struct ulp_bde64); | |
11683 | dmabuf = (struct lpfc_dmabuf *)pIocbOut->context3; | |
11684 | bpl = (struct ulp_bde64 *)dmabuf->virt; | |
11685 | for (i = 0; i < numBdes; i++) { | |
11686 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); | |
11687 | if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64) | |
11688 | max_response += bde.tus.f.bdeSize; | |
11689 | } | |
11690 | break; | |
11691 | default: | |
11692 | max_response = wcqe->total_data_placed; | |
11693 | break; | |
11694 | } | |
11695 | if (max_response < wcqe->total_data_placed) | |
11696 | pIocbIn->iocb.un.genreq64.bdl.bdeSize = max_response; | |
11697 | else | |
11698 | pIocbIn->iocb.un.genreq64.bdl.bdeSize = | |
11699 | wcqe->total_data_placed; | |
695a814e | 11700 | } |
341af102 | 11701 | |
acd6859b JS |
11702 | /* Convert BG errors for completion status */ |
11703 | if (status == CQE_STATUS_DI_ERROR) { | |
11704 | pIocbIn->iocb.ulpStatus = IOSTAT_LOCAL_REJECT; | |
11705 | ||
11706 | if (bf_get(lpfc_wcqe_c_bg_edir, wcqe)) | |
11707 | pIocbIn->iocb.un.ulpWord[4] = IOERR_RX_DMA_FAILED; | |
11708 | else | |
11709 | pIocbIn->iocb.un.ulpWord[4] = IOERR_TX_DMA_FAILED; | |
11710 | ||
11711 | pIocbIn->iocb.unsli3.sli3_bg.bgstat = 0; | |
11712 | if (bf_get(lpfc_wcqe_c_bg_ge, wcqe)) /* Guard Check failed */ | |
11713 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= | |
11714 | BGS_GUARD_ERR_MASK; | |
11715 | if (bf_get(lpfc_wcqe_c_bg_ae, wcqe)) /* App Tag Check failed */ | |
11716 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= | |
11717 | BGS_APPTAG_ERR_MASK; | |
11718 | if (bf_get(lpfc_wcqe_c_bg_re, wcqe)) /* Ref Tag Check failed */ | |
11719 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= | |
11720 | BGS_REFTAG_ERR_MASK; | |
11721 | ||
11722 | /* Check to see if there was any good data before the error */ | |
11723 | if (bf_get(lpfc_wcqe_c_bg_tdpv, wcqe)) { | |
11724 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= | |
11725 | BGS_HI_WATER_MARK_PRESENT_MASK; | |
11726 | pIocbIn->iocb.unsli3.sli3_bg.bghm = | |
11727 | wcqe->total_data_placed; | |
11728 | } | |
11729 | ||
11730 | /* | |
11731 | * Set ALL the error bits to indicate we don't know what | |
11732 | * type of error it is. | |
11733 | */ | |
11734 | if (!pIocbIn->iocb.unsli3.sli3_bg.bgstat) | |
11735 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= | |
11736 | (BGS_REFTAG_ERR_MASK | BGS_APPTAG_ERR_MASK | | |
11737 | BGS_GUARD_ERR_MASK); | |
11738 | } | |
11739 | ||
341af102 JS |
11740 | /* Pick up HBA exchange busy condition */ |
11741 | if (bf_get(lpfc_wcqe_c_xb, wcqe)) { | |
11742 | spin_lock_irqsave(&phba->hbalock, iflags); | |
11743 | pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY; | |
11744 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
11745 | } | |
4f774513 JS |
11746 | } |
11747 | ||
45ed1190 JS |
11748 | /** |
11749 | * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe | |
11750 | * @phba: Pointer to HBA context object. | |
11751 | * @wcqe: Pointer to work-queue completion queue entry. | |
11752 | * | |
11753 | * This routine handles an ELS work-queue completion event and construct | |
11754 | * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common | |
11755 | * discovery engine to handle. | |
11756 | * | |
11757 | * Return: Pointer to the receive IOCBQ, NULL otherwise. | |
11758 | **/ | |
11759 | static struct lpfc_iocbq * | |
11760 | lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba, | |
11761 | struct lpfc_iocbq *irspiocbq) | |
11762 | { | |
11763 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; | |
11764 | struct lpfc_iocbq *cmdiocbq; | |
11765 | struct lpfc_wcqe_complete *wcqe; | |
11766 | unsigned long iflags; | |
11767 | ||
11768 | wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl; | |
7e56aa25 | 11769 | spin_lock_irqsave(&pring->ring_lock, iflags); |
45ed1190 JS |
11770 | pring->stats.iocb_event++; |
11771 | /* Look up the ELS command IOCB and create pseudo response IOCB */ | |
11772 | cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring, | |
11773 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); | |
7e56aa25 | 11774 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
45ed1190 JS |
11775 | |
11776 | if (unlikely(!cmdiocbq)) { | |
11777 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
11778 | "0386 ELS complete with no corresponding " | |
11779 | "cmdiocb: iotag (%d)\n", | |
11780 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); | |
11781 | lpfc_sli_release_iocbq(phba, irspiocbq); | |
11782 | return NULL; | |
11783 | } | |
11784 | ||
11785 | /* Fake the irspiocbq and copy necessary response information */ | |
341af102 | 11786 | lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe); |
45ed1190 JS |
11787 | |
11788 | return irspiocbq; | |
11789 | } | |
11790 | ||
04c68496 JS |
11791 | /** |
11792 | * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event | |
11793 | * @phba: Pointer to HBA context object. | |
11794 | * @cqe: Pointer to mailbox completion queue entry. | |
11795 | * | |
11796 | * This routine process a mailbox completion queue entry with asynchrous | |
11797 | * event. | |
11798 | * | |
11799 | * Return: true if work posted to worker thread, otherwise false. | |
11800 | **/ | |
11801 | static bool | |
11802 | lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe) | |
11803 | { | |
11804 | struct lpfc_cq_event *cq_event; | |
11805 | unsigned long iflags; | |
11806 | ||
11807 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
11808 | "0392 Async Event: word0:x%x, word1:x%x, " | |
11809 | "word2:x%x, word3:x%x\n", mcqe->word0, | |
11810 | mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer); | |
11811 | ||
11812 | /* Allocate a new internal CQ_EVENT entry */ | |
11813 | cq_event = lpfc_sli4_cq_event_alloc(phba); | |
11814 | if (!cq_event) { | |
11815 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
11816 | "0394 Failed to allocate CQ_EVENT entry\n"); | |
11817 | return false; | |
11818 | } | |
11819 | ||
11820 | /* Move the CQE into an asynchronous event entry */ | |
11821 | memcpy(&cq_event->cqe, mcqe, sizeof(struct lpfc_mcqe)); | |
11822 | spin_lock_irqsave(&phba->hbalock, iflags); | |
11823 | list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue); | |
11824 | /* Set the async event flag */ | |
11825 | phba->hba_flag |= ASYNC_EVENT; | |
11826 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
11827 | ||
11828 | return true; | |
11829 | } | |
11830 | ||
11831 | /** | |
11832 | * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event | |
11833 | * @phba: Pointer to HBA context object. | |
11834 | * @cqe: Pointer to mailbox completion queue entry. | |
11835 | * | |
11836 | * This routine process a mailbox completion queue entry with mailbox | |
11837 | * completion event. | |
11838 | * | |
11839 | * Return: true if work posted to worker thread, otherwise false. | |
11840 | **/ | |
11841 | static bool | |
11842 | lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe) | |
11843 | { | |
11844 | uint32_t mcqe_status; | |
11845 | MAILBOX_t *mbox, *pmbox; | |
11846 | struct lpfc_mqe *mqe; | |
11847 | struct lpfc_vport *vport; | |
11848 | struct lpfc_nodelist *ndlp; | |
11849 | struct lpfc_dmabuf *mp; | |
11850 | unsigned long iflags; | |
11851 | LPFC_MBOXQ_t *pmb; | |
11852 | bool workposted = false; | |
11853 | int rc; | |
11854 | ||
11855 | /* If not a mailbox complete MCQE, out by checking mailbox consume */ | |
11856 | if (!bf_get(lpfc_trailer_completed, mcqe)) | |
11857 | goto out_no_mqe_complete; | |
11858 | ||
11859 | /* Get the reference to the active mbox command */ | |
11860 | spin_lock_irqsave(&phba->hbalock, iflags); | |
11861 | pmb = phba->sli.mbox_active; | |
11862 | if (unlikely(!pmb)) { | |
11863 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, | |
11864 | "1832 No pending MBOX command to handle\n"); | |
11865 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
11866 | goto out_no_mqe_complete; | |
11867 | } | |
11868 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
11869 | mqe = &pmb->u.mqe; | |
11870 | pmbox = (MAILBOX_t *)&pmb->u.mqe; | |
11871 | mbox = phba->mbox; | |
11872 | vport = pmb->vport; | |
11873 | ||
11874 | /* Reset heartbeat timer */ | |
11875 | phba->last_completion_time = jiffies; | |
11876 | del_timer(&phba->sli.mbox_tmo); | |
11877 | ||
11878 | /* Move mbox data to caller's mailbox region, do endian swapping */ | |
11879 | if (pmb->mbox_cmpl && mbox) | |
11880 | lpfc_sli_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe)); | |
04c68496 | 11881 | |
73d91e50 JS |
11882 | /* |
11883 | * For mcqe errors, conditionally move a modified error code to | |
11884 | * the mbox so that the error will not be missed. | |
11885 | */ | |
11886 | mcqe_status = bf_get(lpfc_mcqe_status, mcqe); | |
11887 | if (mcqe_status != MB_CQE_STATUS_SUCCESS) { | |
11888 | if (bf_get(lpfc_mqe_status, mqe) == MBX_SUCCESS) | |
11889 | bf_set(lpfc_mqe_status, mqe, | |
11890 | (LPFC_MBX_ERROR_RANGE | mcqe_status)); | |
11891 | } | |
04c68496 JS |
11892 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { |
11893 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; | |
11894 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT, | |
11895 | "MBOX dflt rpi: status:x%x rpi:x%x", | |
11896 | mcqe_status, | |
11897 | pmbox->un.varWords[0], 0); | |
11898 | if (mcqe_status == MB_CQE_STATUS_SUCCESS) { | |
11899 | mp = (struct lpfc_dmabuf *)(pmb->context1); | |
11900 | ndlp = (struct lpfc_nodelist *)pmb->context2; | |
11901 | /* Reg_LOGIN of dflt RPI was successful. Now lets get | |
11902 | * RID of the PPI using the same mbox buffer. | |
11903 | */ | |
11904 | lpfc_unreg_login(phba, vport->vpi, | |
11905 | pmbox->un.varWords[0], pmb); | |
11906 | pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; | |
11907 | pmb->context1 = mp; | |
11908 | pmb->context2 = ndlp; | |
11909 | pmb->vport = vport; | |
11910 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); | |
11911 | if (rc != MBX_BUSY) | |
11912 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | | |
11913 | LOG_SLI, "0385 rc should " | |
11914 | "have been MBX_BUSY\n"); | |
11915 | if (rc != MBX_NOT_FINISHED) | |
11916 | goto send_current_mbox; | |
11917 | } | |
11918 | } | |
11919 | spin_lock_irqsave(&phba->pport->work_port_lock, iflags); | |
11920 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; | |
11921 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); | |
11922 | ||
11923 | /* There is mailbox completion work to do */ | |
11924 | spin_lock_irqsave(&phba->hbalock, iflags); | |
11925 | __lpfc_mbox_cmpl_put(phba, pmb); | |
11926 | phba->work_ha |= HA_MBATT; | |
11927 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
11928 | workposted = true; | |
11929 | ||
11930 | send_current_mbox: | |
11931 | spin_lock_irqsave(&phba->hbalock, iflags); | |
11932 | /* Release the mailbox command posting token */ | |
11933 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
11934 | /* Setting active mailbox pointer need to be in sync to flag clear */ | |
11935 | phba->sli.mbox_active = NULL; | |
11936 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
11937 | /* Wake up worker thread to post the next pending mailbox command */ | |
11938 | lpfc_worker_wake_up(phba); | |
11939 | out_no_mqe_complete: | |
11940 | if (bf_get(lpfc_trailer_consumed, mcqe)) | |
11941 | lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq); | |
11942 | return workposted; | |
11943 | } | |
11944 | ||
11945 | /** | |
11946 | * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry | |
11947 | * @phba: Pointer to HBA context object. | |
11948 | * @cqe: Pointer to mailbox completion queue entry. | |
11949 | * | |
11950 | * This routine process a mailbox completion queue entry, it invokes the | |
11951 | * proper mailbox complete handling or asynchrous event handling routine | |
11952 | * according to the MCQE's async bit. | |
11953 | * | |
11954 | * Return: true if work posted to worker thread, otherwise false. | |
11955 | **/ | |
11956 | static bool | |
11957 | lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe) | |
11958 | { | |
11959 | struct lpfc_mcqe mcqe; | |
11960 | bool workposted; | |
11961 | ||
11962 | /* Copy the mailbox MCQE and convert endian order as needed */ | |
11963 | lpfc_sli_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe)); | |
11964 | ||
11965 | /* Invoke the proper event handling routine */ | |
11966 | if (!bf_get(lpfc_trailer_async, &mcqe)) | |
11967 | workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe); | |
11968 | else | |
11969 | workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe); | |
11970 | return workposted; | |
11971 | } | |
11972 | ||
4f774513 JS |
11973 | /** |
11974 | * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event | |
11975 | * @phba: Pointer to HBA context object. | |
2a76a283 | 11976 | * @cq: Pointer to associated CQ |
4f774513 JS |
11977 | * @wcqe: Pointer to work-queue completion queue entry. |
11978 | * | |
11979 | * This routine handles an ELS work-queue completion event. | |
11980 | * | |
11981 | * Return: true if work posted to worker thread, otherwise false. | |
11982 | **/ | |
11983 | static bool | |
2a76a283 | 11984 | lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
4f774513 JS |
11985 | struct lpfc_wcqe_complete *wcqe) |
11986 | { | |
4f774513 JS |
11987 | struct lpfc_iocbq *irspiocbq; |
11988 | unsigned long iflags; | |
2a76a283 | 11989 | struct lpfc_sli_ring *pring = cq->pring; |
0e9bb8d7 JS |
11990 | int txq_cnt = 0; |
11991 | int txcmplq_cnt = 0; | |
11992 | int fcp_txcmplq_cnt = 0; | |
4f774513 | 11993 | |
45ed1190 | 11994 | /* Get an irspiocbq for later ELS response processing use */ |
4f774513 JS |
11995 | irspiocbq = lpfc_sli_get_iocbq(phba); |
11996 | if (!irspiocbq) { | |
0e9bb8d7 JS |
11997 | if (!list_empty(&pring->txq)) |
11998 | txq_cnt++; | |
11999 | if (!list_empty(&pring->txcmplq)) | |
12000 | txcmplq_cnt++; | |
12001 | if (!list_empty(&phba->sli.ring[LPFC_FCP_RING].txcmplq)) | |
12002 | fcp_txcmplq_cnt++; | |
4f774513 | 12003 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
2a9bf3d0 JS |
12004 | "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d " |
12005 | "fcp_txcmplq_cnt=%d, els_txcmplq_cnt=%d\n", | |
0e9bb8d7 JS |
12006 | txq_cnt, phba->iocb_cnt, |
12007 | fcp_txcmplq_cnt, | |
12008 | txcmplq_cnt); | |
45ed1190 | 12009 | return false; |
4f774513 | 12010 | } |
4f774513 | 12011 | |
45ed1190 JS |
12012 | /* Save off the slow-path queue event for work thread to process */ |
12013 | memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe)); | |
4f774513 | 12014 | spin_lock_irqsave(&phba->hbalock, iflags); |
4d9ab994 | 12015 | list_add_tail(&irspiocbq->cq_event.list, |
45ed1190 JS |
12016 | &phba->sli4_hba.sp_queue_event); |
12017 | phba->hba_flag |= HBA_SP_QUEUE_EVT; | |
4f774513 | 12018 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
4f774513 | 12019 | |
45ed1190 | 12020 | return true; |
4f774513 JS |
12021 | } |
12022 | ||
12023 | /** | |
12024 | * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event | |
12025 | * @phba: Pointer to HBA context object. | |
12026 | * @wcqe: Pointer to work-queue completion queue entry. | |
12027 | * | |
12028 | * This routine handles slow-path WQ entry comsumed event by invoking the | |
12029 | * proper WQ release routine to the slow-path WQ. | |
12030 | **/ | |
12031 | static void | |
12032 | lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba, | |
12033 | struct lpfc_wcqe_release *wcqe) | |
12034 | { | |
2e90f4b5 JS |
12035 | /* sanity check on queue memory */ |
12036 | if (unlikely(!phba->sli4_hba.els_wq)) | |
12037 | return; | |
4f774513 JS |
12038 | /* Check for the slow-path ELS work queue */ |
12039 | if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id) | |
12040 | lpfc_sli4_wq_release(phba->sli4_hba.els_wq, | |
12041 | bf_get(lpfc_wcqe_r_wqe_index, wcqe)); | |
12042 | else | |
12043 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
12044 | "2579 Slow-path wqe consume event carries " | |
12045 | "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n", | |
12046 | bf_get(lpfc_wcqe_r_wqe_index, wcqe), | |
12047 | phba->sli4_hba.els_wq->queue_id); | |
12048 | } | |
12049 | ||
12050 | /** | |
12051 | * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event | |
12052 | * @phba: Pointer to HBA context object. | |
12053 | * @cq: Pointer to a WQ completion queue. | |
12054 | * @wcqe: Pointer to work-queue completion queue entry. | |
12055 | * | |
12056 | * This routine handles an XRI abort event. | |
12057 | * | |
12058 | * Return: true if work posted to worker thread, otherwise false. | |
12059 | **/ | |
12060 | static bool | |
12061 | lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba, | |
12062 | struct lpfc_queue *cq, | |
12063 | struct sli4_wcqe_xri_aborted *wcqe) | |
12064 | { | |
12065 | bool workposted = false; | |
12066 | struct lpfc_cq_event *cq_event; | |
12067 | unsigned long iflags; | |
12068 | ||
12069 | /* Allocate a new internal CQ_EVENT entry */ | |
12070 | cq_event = lpfc_sli4_cq_event_alloc(phba); | |
12071 | if (!cq_event) { | |
12072 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
12073 | "0602 Failed to allocate CQ_EVENT entry\n"); | |
12074 | return false; | |
12075 | } | |
12076 | ||
12077 | /* Move the CQE into the proper xri abort event list */ | |
12078 | memcpy(&cq_event->cqe, wcqe, sizeof(struct sli4_wcqe_xri_aborted)); | |
12079 | switch (cq->subtype) { | |
12080 | case LPFC_FCP: | |
12081 | spin_lock_irqsave(&phba->hbalock, iflags); | |
12082 | list_add_tail(&cq_event->list, | |
12083 | &phba->sli4_hba.sp_fcp_xri_aborted_work_queue); | |
12084 | /* Set the fcp xri abort event flag */ | |
12085 | phba->hba_flag |= FCP_XRI_ABORT_EVENT; | |
12086 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
12087 | workposted = true; | |
12088 | break; | |
12089 | case LPFC_ELS: | |
12090 | spin_lock_irqsave(&phba->hbalock, iflags); | |
12091 | list_add_tail(&cq_event->list, | |
12092 | &phba->sli4_hba.sp_els_xri_aborted_work_queue); | |
12093 | /* Set the els xri abort event flag */ | |
12094 | phba->hba_flag |= ELS_XRI_ABORT_EVENT; | |
12095 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
12096 | workposted = true; | |
12097 | break; | |
12098 | default: | |
12099 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
12100 | "0603 Invalid work queue CQE subtype (x%x)\n", | |
12101 | cq->subtype); | |
12102 | workposted = false; | |
12103 | break; | |
12104 | } | |
12105 | return workposted; | |
12106 | } | |
12107 | ||
4f774513 JS |
12108 | /** |
12109 | * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry | |
12110 | * @phba: Pointer to HBA context object. | |
12111 | * @rcqe: Pointer to receive-queue completion queue entry. | |
12112 | * | |
12113 | * This routine process a receive-queue completion queue entry. | |
12114 | * | |
12115 | * Return: true if work posted to worker thread, otherwise false. | |
12116 | **/ | |
12117 | static bool | |
4d9ab994 | 12118 | lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe) |
4f774513 | 12119 | { |
4f774513 JS |
12120 | bool workposted = false; |
12121 | struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq; | |
12122 | struct lpfc_queue *drq = phba->sli4_hba.dat_rq; | |
12123 | struct hbq_dmabuf *dma_buf; | |
7851fe2c | 12124 | uint32_t status, rq_id; |
4f774513 JS |
12125 | unsigned long iflags; |
12126 | ||
2e90f4b5 JS |
12127 | /* sanity check on queue memory */ |
12128 | if (unlikely(!hrq) || unlikely(!drq)) | |
12129 | return workposted; | |
12130 | ||
7851fe2c JS |
12131 | if (bf_get(lpfc_cqe_code, rcqe) == CQE_CODE_RECEIVE_V1) |
12132 | rq_id = bf_get(lpfc_rcqe_rq_id_v1, rcqe); | |
12133 | else | |
12134 | rq_id = bf_get(lpfc_rcqe_rq_id, rcqe); | |
12135 | if (rq_id != hrq->queue_id) | |
4f774513 JS |
12136 | goto out; |
12137 | ||
4d9ab994 | 12138 | status = bf_get(lpfc_rcqe_status, rcqe); |
4f774513 JS |
12139 | switch (status) { |
12140 | case FC_STATUS_RQ_BUF_LEN_EXCEEDED: | |
12141 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
12142 | "2537 Receive Frame Truncated!!\n"); | |
b84daac9 | 12143 | hrq->RQ_buf_trunc++; |
4f774513 | 12144 | case FC_STATUS_RQ_SUCCESS: |
5ffc266e | 12145 | lpfc_sli4_rq_release(hrq, drq); |
4f774513 JS |
12146 | spin_lock_irqsave(&phba->hbalock, iflags); |
12147 | dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list); | |
12148 | if (!dma_buf) { | |
b84daac9 | 12149 | hrq->RQ_no_buf_found++; |
4f774513 JS |
12150 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
12151 | goto out; | |
12152 | } | |
b84daac9 | 12153 | hrq->RQ_rcv_buf++; |
4d9ab994 | 12154 | memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe)); |
4f774513 | 12155 | /* save off the frame for the word thread to process */ |
4d9ab994 | 12156 | list_add_tail(&dma_buf->cq_event.list, |
45ed1190 | 12157 | &phba->sli4_hba.sp_queue_event); |
4f774513 | 12158 | /* Frame received */ |
45ed1190 | 12159 | phba->hba_flag |= HBA_SP_QUEUE_EVT; |
4f774513 JS |
12160 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
12161 | workposted = true; | |
12162 | break; | |
12163 | case FC_STATUS_INSUFF_BUF_NEED_BUF: | |
12164 | case FC_STATUS_INSUFF_BUF_FRM_DISC: | |
b84daac9 | 12165 | hrq->RQ_no_posted_buf++; |
4f774513 JS |
12166 | /* Post more buffers if possible */ |
12167 | spin_lock_irqsave(&phba->hbalock, iflags); | |
12168 | phba->hba_flag |= HBA_POST_RECEIVE_BUFFER; | |
12169 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
12170 | workposted = true; | |
12171 | break; | |
12172 | } | |
12173 | out: | |
12174 | return workposted; | |
4f774513 JS |
12175 | } |
12176 | ||
4d9ab994 JS |
12177 | /** |
12178 | * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry | |
12179 | * @phba: Pointer to HBA context object. | |
12180 | * @cq: Pointer to the completion queue. | |
12181 | * @wcqe: Pointer to a completion queue entry. | |
12182 | * | |
25985edc | 12183 | * This routine process a slow-path work-queue or receive queue completion queue |
4d9ab994 JS |
12184 | * entry. |
12185 | * | |
12186 | * Return: true if work posted to worker thread, otherwise false. | |
12187 | **/ | |
12188 | static bool | |
12189 | lpfc_sli4_sp_handle_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq, | |
12190 | struct lpfc_cqe *cqe) | |
12191 | { | |
45ed1190 | 12192 | struct lpfc_cqe cqevt; |
4d9ab994 JS |
12193 | bool workposted = false; |
12194 | ||
12195 | /* Copy the work queue CQE and convert endian order if needed */ | |
45ed1190 | 12196 | lpfc_sli_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe)); |
4d9ab994 JS |
12197 | |
12198 | /* Check and process for different type of WCQE and dispatch */ | |
45ed1190 | 12199 | switch (bf_get(lpfc_cqe_code, &cqevt)) { |
4d9ab994 | 12200 | case CQE_CODE_COMPL_WQE: |
45ed1190 | 12201 | /* Process the WQ/RQ complete event */ |
bc73905a | 12202 | phba->last_completion_time = jiffies; |
2a76a283 | 12203 | workposted = lpfc_sli4_sp_handle_els_wcqe(phba, cq, |
45ed1190 | 12204 | (struct lpfc_wcqe_complete *)&cqevt); |
4d9ab994 JS |
12205 | break; |
12206 | case CQE_CODE_RELEASE_WQE: | |
12207 | /* Process the WQ release event */ | |
12208 | lpfc_sli4_sp_handle_rel_wcqe(phba, | |
45ed1190 | 12209 | (struct lpfc_wcqe_release *)&cqevt); |
4d9ab994 JS |
12210 | break; |
12211 | case CQE_CODE_XRI_ABORTED: | |
12212 | /* Process the WQ XRI abort event */ | |
bc73905a | 12213 | phba->last_completion_time = jiffies; |
4d9ab994 | 12214 | workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq, |
45ed1190 | 12215 | (struct sli4_wcqe_xri_aborted *)&cqevt); |
4d9ab994 JS |
12216 | break; |
12217 | case CQE_CODE_RECEIVE: | |
7851fe2c | 12218 | case CQE_CODE_RECEIVE_V1: |
4d9ab994 | 12219 | /* Process the RQ event */ |
bc73905a | 12220 | phba->last_completion_time = jiffies; |
4d9ab994 | 12221 | workposted = lpfc_sli4_sp_handle_rcqe(phba, |
45ed1190 | 12222 | (struct lpfc_rcqe *)&cqevt); |
4d9ab994 JS |
12223 | break; |
12224 | default: | |
12225 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
12226 | "0388 Not a valid WCQE code: x%x\n", | |
45ed1190 | 12227 | bf_get(lpfc_cqe_code, &cqevt)); |
4d9ab994 JS |
12228 | break; |
12229 | } | |
12230 | return workposted; | |
12231 | } | |
12232 | ||
4f774513 JS |
12233 | /** |
12234 | * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry | |
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 slow-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 that completion queue, rearm the | |
12243 | * completion queue, and then return. | |
12244 | * | |
12245 | **/ | |
12246 | static void | |
67d12733 JS |
12247 | lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe, |
12248 | struct lpfc_queue *speq) | |
4f774513 | 12249 | { |
67d12733 | 12250 | struct lpfc_queue *cq = NULL, *childq; |
4f774513 JS |
12251 | struct lpfc_cqe *cqe; |
12252 | bool workposted = false; | |
12253 | int ecount = 0; | |
12254 | uint16_t cqid; | |
12255 | ||
4f774513 | 12256 | /* Get the reference to the corresponding CQ */ |
cb5172ea | 12257 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
4f774513 | 12258 | |
4f774513 JS |
12259 | list_for_each_entry(childq, &speq->child_list, list) { |
12260 | if (childq->queue_id == cqid) { | |
12261 | cq = childq; | |
12262 | break; | |
12263 | } | |
12264 | } | |
12265 | if (unlikely(!cq)) { | |
75baf696 JS |
12266 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) |
12267 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
12268 | "0365 Slow-path CQ identifier " | |
12269 | "(%d) does not exist\n", cqid); | |
4f774513 JS |
12270 | return; |
12271 | } | |
12272 | ||
12273 | /* Process all the entries to the CQ */ | |
12274 | switch (cq->type) { | |
12275 | case LPFC_MCQ: | |
12276 | while ((cqe = lpfc_sli4_cq_get(cq))) { | |
12277 | workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe); | |
73d91e50 | 12278 | if (!(++ecount % cq->entry_repost)) |
4f774513 | 12279 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM); |
b84daac9 | 12280 | cq->CQ_mbox++; |
4f774513 JS |
12281 | } |
12282 | break; | |
12283 | case LPFC_WCQ: | |
12284 | while ((cqe = lpfc_sli4_cq_get(cq))) { | |
0558056c JS |
12285 | if (cq->subtype == LPFC_FCP) |
12286 | workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, | |
12287 | cqe); | |
12288 | else | |
12289 | workposted |= lpfc_sli4_sp_handle_cqe(phba, cq, | |
12290 | cqe); | |
73d91e50 | 12291 | if (!(++ecount % cq->entry_repost)) |
4f774513 JS |
12292 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM); |
12293 | } | |
b84daac9 JS |
12294 | |
12295 | /* Track the max number of CQEs processed in 1 EQ */ | |
12296 | if (ecount > cq->CQ_max_cqe) | |
12297 | cq->CQ_max_cqe = ecount; | |
4f774513 JS |
12298 | break; |
12299 | default: | |
12300 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
12301 | "0370 Invalid completion queue type (%d)\n", | |
12302 | cq->type); | |
12303 | return; | |
12304 | } | |
12305 | ||
12306 | /* Catch the no cq entry condition, log an error */ | |
12307 | if (unlikely(ecount == 0)) | |
12308 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
12309 | "0371 No entry from the CQ: identifier " | |
12310 | "(x%x), type (%d)\n", cq->queue_id, cq->type); | |
12311 | ||
12312 | /* In any case, flash and re-arm the RCQ */ | |
12313 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM); | |
12314 | ||
12315 | /* wake up worker thread if there are works to be done */ | |
12316 | if (workposted) | |
12317 | lpfc_worker_wake_up(phba); | |
12318 | } | |
12319 | ||
12320 | /** | |
12321 | * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry | |
2a76a283 JS |
12322 | * @phba: Pointer to HBA context object. |
12323 | * @cq: Pointer to associated CQ | |
12324 | * @wcqe: Pointer to work-queue completion queue entry. | |
4f774513 JS |
12325 | * |
12326 | * This routine process a fast-path work queue completion entry from fast-path | |
12327 | * event queue for FCP command response completion. | |
12328 | **/ | |
12329 | static void | |
2a76a283 | 12330 | lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
4f774513 JS |
12331 | struct lpfc_wcqe_complete *wcqe) |
12332 | { | |
2a76a283 | 12333 | struct lpfc_sli_ring *pring = cq->pring; |
4f774513 JS |
12334 | struct lpfc_iocbq *cmdiocbq; |
12335 | struct lpfc_iocbq irspiocbq; | |
12336 | unsigned long iflags; | |
12337 | ||
4f774513 JS |
12338 | /* Check for response status */ |
12339 | if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) { | |
12340 | /* If resource errors reported from HBA, reduce queue | |
12341 | * depth of the SCSI device. | |
12342 | */ | |
e3d2b802 JS |
12343 | if (((bf_get(lpfc_wcqe_c_status, wcqe) == |
12344 | IOSTAT_LOCAL_REJECT)) && | |
12345 | ((wcqe->parameter & IOERR_PARAM_MASK) == | |
12346 | IOERR_NO_RESOURCES)) | |
4f774513 | 12347 | phba->lpfc_rampdown_queue_depth(phba); |
e3d2b802 | 12348 | |
4f774513 JS |
12349 | /* Log the error status */ |
12350 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
12351 | "0373 FCP complete error: status=x%x, " | |
12352 | "hw_status=x%x, total_data_specified=%d, " | |
12353 | "parameter=x%x, word3=x%x\n", | |
12354 | bf_get(lpfc_wcqe_c_status, wcqe), | |
12355 | bf_get(lpfc_wcqe_c_hw_status, wcqe), | |
12356 | wcqe->total_data_placed, wcqe->parameter, | |
12357 | wcqe->word3); | |
12358 | } | |
12359 | ||
12360 | /* Look up the FCP command IOCB and create pseudo response IOCB */ | |
7e56aa25 JS |
12361 | spin_lock_irqsave(&pring->ring_lock, iflags); |
12362 | pring->stats.iocb_event++; | |
4f774513 JS |
12363 | cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring, |
12364 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); | |
7e56aa25 | 12365 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
4f774513 JS |
12366 | if (unlikely(!cmdiocbq)) { |
12367 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
12368 | "0374 FCP complete with no corresponding " | |
12369 | "cmdiocb: iotag (%d)\n", | |
12370 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); | |
12371 | return; | |
12372 | } | |
12373 | if (unlikely(!cmdiocbq->iocb_cmpl)) { | |
12374 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
12375 | "0375 FCP cmdiocb not callback function " | |
12376 | "iotag: (%d)\n", | |
12377 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); | |
12378 | return; | |
12379 | } | |
12380 | ||
12381 | /* Fake the irspiocb and copy necessary response information */ | |
341af102 | 12382 | lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe); |
4f774513 | 12383 | |
0f65ff68 JS |
12384 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) { |
12385 | spin_lock_irqsave(&phba->hbalock, iflags); | |
12386 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; | |
12387 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
12388 | } | |
12389 | ||
4f774513 JS |
12390 | /* Pass the cmd_iocb and the rsp state to the upper layer */ |
12391 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq); | |
12392 | } | |
12393 | ||
12394 | /** | |
12395 | * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event | |
12396 | * @phba: Pointer to HBA context object. | |
12397 | * @cq: Pointer to completion queue. | |
12398 | * @wcqe: Pointer to work-queue completion queue entry. | |
12399 | * | |
12400 | * This routine handles an fast-path WQ entry comsumed event by invoking the | |
12401 | * proper WQ release routine to the slow-path WQ. | |
12402 | **/ | |
12403 | static void | |
12404 | lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, | |
12405 | struct lpfc_wcqe_release *wcqe) | |
12406 | { | |
12407 | struct lpfc_queue *childwq; | |
12408 | bool wqid_matched = false; | |
12409 | uint16_t fcp_wqid; | |
12410 | ||
12411 | /* Check for fast-path FCP work queue release */ | |
12412 | fcp_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe); | |
12413 | list_for_each_entry(childwq, &cq->child_list, list) { | |
12414 | if (childwq->queue_id == fcp_wqid) { | |
12415 | lpfc_sli4_wq_release(childwq, | |
12416 | bf_get(lpfc_wcqe_r_wqe_index, wcqe)); | |
12417 | wqid_matched = true; | |
12418 | break; | |
12419 | } | |
12420 | } | |
12421 | /* Report warning log message if no match found */ | |
12422 | if (wqid_matched != true) | |
12423 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
12424 | "2580 Fast-path wqe consume event carries " | |
12425 | "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid); | |
12426 | } | |
12427 | ||
12428 | /** | |
12429 | * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry | |
12430 | * @cq: Pointer to the completion queue. | |
12431 | * @eqe: Pointer to fast-path completion queue entry. | |
12432 | * | |
12433 | * This routine process a fast-path work queue completion entry from fast-path | |
12434 | * event queue for FCP command response completion. | |
12435 | **/ | |
12436 | static int | |
12437 | lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, | |
12438 | struct lpfc_cqe *cqe) | |
12439 | { | |
12440 | struct lpfc_wcqe_release wcqe; | |
12441 | bool workposted = false; | |
12442 | ||
12443 | /* Copy the work queue CQE and convert endian order if needed */ | |
12444 | lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe)); | |
12445 | ||
12446 | /* Check and process for different type of WCQE and dispatch */ | |
12447 | switch (bf_get(lpfc_wcqe_c_code, &wcqe)) { | |
12448 | case CQE_CODE_COMPL_WQE: | |
b84daac9 | 12449 | cq->CQ_wq++; |
4f774513 | 12450 | /* Process the WQ complete event */ |
98fc5dd9 | 12451 | phba->last_completion_time = jiffies; |
2a76a283 | 12452 | lpfc_sli4_fp_handle_fcp_wcqe(phba, cq, |
4f774513 JS |
12453 | (struct lpfc_wcqe_complete *)&wcqe); |
12454 | break; | |
12455 | case CQE_CODE_RELEASE_WQE: | |
b84daac9 | 12456 | cq->CQ_release_wqe++; |
4f774513 JS |
12457 | /* Process the WQ release event */ |
12458 | lpfc_sli4_fp_handle_rel_wcqe(phba, cq, | |
12459 | (struct lpfc_wcqe_release *)&wcqe); | |
12460 | break; | |
12461 | case CQE_CODE_XRI_ABORTED: | |
b84daac9 | 12462 | cq->CQ_xri_aborted++; |
4f774513 | 12463 | /* Process the WQ XRI abort event */ |
bc73905a | 12464 | phba->last_completion_time = jiffies; |
4f774513 JS |
12465 | workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq, |
12466 | (struct sli4_wcqe_xri_aborted *)&wcqe); | |
12467 | break; | |
12468 | default: | |
12469 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
12470 | "0144 Not a valid WCQE code: x%x\n", | |
12471 | bf_get(lpfc_wcqe_c_code, &wcqe)); | |
12472 | break; | |
12473 | } | |
12474 | return workposted; | |
12475 | } | |
12476 | ||
12477 | /** | |
67d12733 | 12478 | * lpfc_sli4_hba_handle_eqe - Process a fast-path event queue entry |
4f774513 JS |
12479 | * @phba: Pointer to HBA context object. |
12480 | * @eqe: Pointer to fast-path event queue entry. | |
12481 | * | |
12482 | * This routine process a event queue entry from the fast-path event queue. | |
12483 | * It will check the MajorCode and MinorCode to determine this is for a | |
12484 | * completion event on a completion queue, if not, an error shall be logged | |
12485 | * and just return. Otherwise, it will get to the corresponding completion | |
12486 | * queue and process all the entries on the completion queue, rearm the | |
12487 | * completion queue, and then return. | |
12488 | **/ | |
12489 | static void | |
67d12733 JS |
12490 | lpfc_sli4_hba_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe, |
12491 | uint32_t qidx) | |
4f774513 JS |
12492 | { |
12493 | struct lpfc_queue *cq; | |
12494 | struct lpfc_cqe *cqe; | |
12495 | bool workposted = false; | |
12496 | uint16_t cqid; | |
12497 | int ecount = 0; | |
12498 | ||
cb5172ea | 12499 | if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) { |
4f774513 | 12500 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
67d12733 | 12501 | "0366 Not a valid completion " |
4f774513 | 12502 | "event: majorcode=x%x, minorcode=x%x\n", |
cb5172ea JS |
12503 | bf_get_le32(lpfc_eqe_major_code, eqe), |
12504 | bf_get_le32(lpfc_eqe_minor_code, eqe)); | |
4f774513 JS |
12505 | return; |
12506 | } | |
12507 | ||
67d12733 JS |
12508 | /* Get the reference to the corresponding CQ */ |
12509 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); | |
12510 | ||
12511 | /* Check if this is a Slow path event */ | |
12512 | if (unlikely(cqid != phba->sli4_hba.fcp_cq_map[qidx])) { | |
12513 | lpfc_sli4_sp_handle_eqe(phba, eqe, | |
12514 | phba->sli4_hba.hba_eq[qidx]); | |
12515 | return; | |
12516 | } | |
12517 | ||
2e90f4b5 JS |
12518 | if (unlikely(!phba->sli4_hba.fcp_cq)) { |
12519 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
12520 | "3146 Fast-path completion queues " | |
12521 | "does not exist\n"); | |
12522 | return; | |
12523 | } | |
67d12733 | 12524 | cq = phba->sli4_hba.fcp_cq[qidx]; |
4f774513 | 12525 | if (unlikely(!cq)) { |
75baf696 JS |
12526 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) |
12527 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
12528 | "0367 Fast-path completion queue " | |
67d12733 | 12529 | "(%d) does not exist\n", qidx); |
4f774513 JS |
12530 | return; |
12531 | } | |
12532 | ||
4f774513 JS |
12533 | if (unlikely(cqid != cq->queue_id)) { |
12534 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
12535 | "0368 Miss-matched fast-path completion " | |
12536 | "queue identifier: eqcqid=%d, fcpcqid=%d\n", | |
12537 | cqid, cq->queue_id); | |
12538 | return; | |
12539 | } | |
12540 | ||
12541 | /* Process all the entries to the CQ */ | |
12542 | while ((cqe = lpfc_sli4_cq_get(cq))) { | |
12543 | workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe); | |
73d91e50 | 12544 | if (!(++ecount % cq->entry_repost)) |
4f774513 JS |
12545 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM); |
12546 | } | |
12547 | ||
b84daac9 JS |
12548 | /* Track the max number of CQEs processed in 1 EQ */ |
12549 | if (ecount > cq->CQ_max_cqe) | |
12550 | cq->CQ_max_cqe = ecount; | |
12551 | ||
4f774513 JS |
12552 | /* Catch the no cq entry condition */ |
12553 | if (unlikely(ecount == 0)) | |
12554 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
12555 | "0369 No entry from fast-path completion " | |
12556 | "queue fcpcqid=%d\n", cq->queue_id); | |
12557 | ||
12558 | /* In any case, flash and re-arm the CQ */ | |
12559 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM); | |
12560 | ||
12561 | /* wake up worker thread if there are works to be done */ | |
12562 | if (workposted) | |
12563 | lpfc_worker_wake_up(phba); | |
12564 | } | |
12565 | ||
12566 | static void | |
12567 | lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq) | |
12568 | { | |
12569 | struct lpfc_eqe *eqe; | |
12570 | ||
12571 | /* walk all the EQ entries and drop on the floor */ | |
12572 | while ((eqe = lpfc_sli4_eq_get(eq))) | |
12573 | ; | |
12574 | ||
12575 | /* Clear and re-arm the EQ */ | |
12576 | lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM); | |
12577 | } | |
12578 | ||
1ba981fd JS |
12579 | |
12580 | /** | |
12581 | * lpfc_sli4_fof_handle_eqe - Process a Flash Optimized Fabric event queue | |
12582 | * entry | |
12583 | * @phba: Pointer to HBA context object. | |
12584 | * @eqe: Pointer to fast-path event queue entry. | |
12585 | * | |
12586 | * This routine process a event queue entry from the Flash Optimized Fabric | |
12587 | * event queue. It will check the MajorCode and MinorCode to determine this | |
12588 | * is for a completion event on a completion queue, if not, an error shall be | |
12589 | * logged and just return. Otherwise, it will get to the corresponding | |
12590 | * completion queue and process all the entries on the completion queue, rearm | |
12591 | * the completion queue, and then return. | |
12592 | **/ | |
12593 | static void | |
12594 | lpfc_sli4_fof_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe) | |
12595 | { | |
12596 | struct lpfc_queue *cq; | |
12597 | struct lpfc_cqe *cqe; | |
12598 | bool workposted = false; | |
12599 | uint16_t cqid; | |
12600 | int ecount = 0; | |
12601 | ||
12602 | if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) { | |
12603 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
12604 | "9147 Not a valid completion " | |
12605 | "event: majorcode=x%x, minorcode=x%x\n", | |
12606 | bf_get_le32(lpfc_eqe_major_code, eqe), | |
12607 | bf_get_le32(lpfc_eqe_minor_code, eqe)); | |
12608 | return; | |
12609 | } | |
12610 | ||
12611 | /* Get the reference to the corresponding CQ */ | |
12612 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); | |
12613 | ||
12614 | /* Next check for OAS */ | |
12615 | cq = phba->sli4_hba.oas_cq; | |
12616 | if (unlikely(!cq)) { | |
12617 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) | |
12618 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
12619 | "9148 OAS completion queue " | |
12620 | "does not exist\n"); | |
12621 | return; | |
12622 | } | |
12623 | ||
12624 | if (unlikely(cqid != cq->queue_id)) { | |
12625 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
12626 | "9149 Miss-matched fast-path compl " | |
12627 | "queue id: eqcqid=%d, fcpcqid=%d\n", | |
12628 | cqid, cq->queue_id); | |
12629 | return; | |
12630 | } | |
12631 | ||
12632 | /* Process all the entries to the OAS CQ */ | |
12633 | while ((cqe = lpfc_sli4_cq_get(cq))) { | |
12634 | workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe); | |
12635 | if (!(++ecount % cq->entry_repost)) | |
12636 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM); | |
12637 | } | |
12638 | ||
12639 | /* Track the max number of CQEs processed in 1 EQ */ | |
12640 | if (ecount > cq->CQ_max_cqe) | |
12641 | cq->CQ_max_cqe = ecount; | |
12642 | ||
12643 | /* Catch the no cq entry condition */ | |
12644 | if (unlikely(ecount == 0)) | |
12645 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
12646 | "9153 No entry from fast-path completion " | |
12647 | "queue fcpcqid=%d\n", cq->queue_id); | |
12648 | ||
12649 | /* In any case, flash and re-arm the CQ */ | |
12650 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM); | |
12651 | ||
12652 | /* wake up worker thread if there are works to be done */ | |
12653 | if (workposted) | |
12654 | lpfc_worker_wake_up(phba); | |
12655 | } | |
12656 | ||
12657 | /** | |
12658 | * lpfc_sli4_fof_intr_handler - HBA interrupt handler to SLI-4 device | |
12659 | * @irq: Interrupt number. | |
12660 | * @dev_id: The device context pointer. | |
12661 | * | |
12662 | * This function is directly called from the PCI layer as an interrupt | |
12663 | * service routine when device with SLI-4 interface spec is enabled with | |
12664 | * MSI-X multi-message interrupt mode and there is a Flash Optimized Fabric | |
12665 | * IOCB ring event in the HBA. However, when the device is enabled with either | |
12666 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the | |
12667 | * device-level interrupt handler. When the PCI slot is in error recovery | |
12668 | * or the HBA is undergoing initialization, the interrupt handler will not | |
12669 | * process the interrupt. The Flash Optimized Fabric ring event are handled in | |
12670 | * the intrrupt context. This function is called without any lock held. | |
12671 | * It gets the hbalock to access and update SLI data structures. Note that, | |
12672 | * the EQ to CQ are one-to-one map such that the EQ index is | |
12673 | * equal to that of CQ index. | |
12674 | * | |
12675 | * This function returns IRQ_HANDLED when interrupt is handled else it | |
12676 | * returns IRQ_NONE. | |
12677 | **/ | |
12678 | irqreturn_t | |
12679 | lpfc_sli4_fof_intr_handler(int irq, void *dev_id) | |
12680 | { | |
12681 | struct lpfc_hba *phba; | |
12682 | struct lpfc_fcp_eq_hdl *fcp_eq_hdl; | |
12683 | struct lpfc_queue *eq; | |
12684 | struct lpfc_eqe *eqe; | |
12685 | unsigned long iflag; | |
12686 | int ecount = 0; | |
1ba981fd JS |
12687 | |
12688 | /* Get the driver's phba structure from the dev_id */ | |
12689 | fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id; | |
12690 | phba = fcp_eq_hdl->phba; | |
1ba981fd JS |
12691 | |
12692 | if (unlikely(!phba)) | |
12693 | return IRQ_NONE; | |
12694 | ||
12695 | /* Get to the EQ struct associated with this vector */ | |
12696 | eq = phba->sli4_hba.fof_eq; | |
12697 | if (unlikely(!eq)) | |
12698 | return IRQ_NONE; | |
12699 | ||
12700 | /* Check device state for handling interrupt */ | |
12701 | if (unlikely(lpfc_intr_state_check(phba))) { | |
12702 | eq->EQ_badstate++; | |
12703 | /* Check again for link_state with lock held */ | |
12704 | spin_lock_irqsave(&phba->hbalock, iflag); | |
12705 | if (phba->link_state < LPFC_LINK_DOWN) | |
12706 | /* Flush, clear interrupt, and rearm the EQ */ | |
12707 | lpfc_sli4_eq_flush(phba, eq); | |
12708 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
12709 | return IRQ_NONE; | |
12710 | } | |
12711 | ||
12712 | /* | |
12713 | * Process all the event on FCP fast-path EQ | |
12714 | */ | |
12715 | while ((eqe = lpfc_sli4_eq_get(eq))) { | |
12716 | lpfc_sli4_fof_handle_eqe(phba, eqe); | |
12717 | if (!(++ecount % eq->entry_repost)) | |
12718 | lpfc_sli4_eq_release(eq, LPFC_QUEUE_NOARM); | |
12719 | eq->EQ_processed++; | |
12720 | } | |
12721 | ||
12722 | /* Track the max number of EQEs processed in 1 intr */ | |
12723 | if (ecount > eq->EQ_max_eqe) | |
12724 | eq->EQ_max_eqe = ecount; | |
12725 | ||
12726 | ||
12727 | if (unlikely(ecount == 0)) { | |
12728 | eq->EQ_no_entry++; | |
12729 | ||
12730 | if (phba->intr_type == MSIX) | |
12731 | /* MSI-X treated interrupt served as no EQ share INT */ | |
12732 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
12733 | "9145 MSI-X interrupt with no EQE\n"); | |
12734 | else { | |
12735 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
12736 | "9146 ISR interrupt with no EQE\n"); | |
12737 | /* Non MSI-X treated on interrupt as EQ share INT */ | |
12738 | return IRQ_NONE; | |
12739 | } | |
12740 | } | |
12741 | /* Always clear and re-arm the fast-path EQ */ | |
12742 | lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM); | |
12743 | return IRQ_HANDLED; | |
12744 | } | |
12745 | ||
4f774513 | 12746 | /** |
67d12733 | 12747 | * lpfc_sli4_hba_intr_handler - HBA interrupt handler to SLI-4 device |
4f774513 JS |
12748 | * @irq: Interrupt number. |
12749 | * @dev_id: The device context pointer. | |
12750 | * | |
12751 | * This function is directly called from the PCI layer as an interrupt | |
12752 | * service routine when device with SLI-4 interface spec is enabled with | |
12753 | * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB | |
12754 | * ring event in the HBA. However, when the device is enabled with either | |
12755 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the | |
12756 | * device-level interrupt handler. When the PCI slot is in error recovery | |
12757 | * or the HBA is undergoing initialization, the interrupt handler will not | |
12758 | * process the interrupt. The SCSI FCP fast-path ring event are handled in | |
12759 | * the intrrupt context. This function is called without any lock held. | |
12760 | * It gets the hbalock to access and update SLI data structures. Note that, | |
12761 | * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is | |
12762 | * equal to that of FCP CQ index. | |
12763 | * | |
67d12733 JS |
12764 | * The link attention and ELS ring attention events are handled |
12765 | * by the worker thread. The interrupt handler signals the worker thread | |
12766 | * and returns for these events. This function is called without any lock | |
12767 | * held. It gets the hbalock to access and update SLI data structures. | |
12768 | * | |
4f774513 JS |
12769 | * This function returns IRQ_HANDLED when interrupt is handled else it |
12770 | * returns IRQ_NONE. | |
12771 | **/ | |
12772 | irqreturn_t | |
67d12733 | 12773 | lpfc_sli4_hba_intr_handler(int irq, void *dev_id) |
4f774513 JS |
12774 | { |
12775 | struct lpfc_hba *phba; | |
12776 | struct lpfc_fcp_eq_hdl *fcp_eq_hdl; | |
12777 | struct lpfc_queue *fpeq; | |
12778 | struct lpfc_eqe *eqe; | |
12779 | unsigned long iflag; | |
12780 | int ecount = 0; | |
962bc51b | 12781 | int fcp_eqidx; |
4f774513 JS |
12782 | |
12783 | /* Get the driver's phba structure from the dev_id */ | |
12784 | fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id; | |
12785 | phba = fcp_eq_hdl->phba; | |
12786 | fcp_eqidx = fcp_eq_hdl->idx; | |
12787 | ||
12788 | if (unlikely(!phba)) | |
12789 | return IRQ_NONE; | |
67d12733 | 12790 | if (unlikely(!phba->sli4_hba.hba_eq)) |
5350d872 | 12791 | return IRQ_NONE; |
4f774513 JS |
12792 | |
12793 | /* Get to the EQ struct associated with this vector */ | |
67d12733 | 12794 | fpeq = phba->sli4_hba.hba_eq[fcp_eqidx]; |
2e90f4b5 JS |
12795 | if (unlikely(!fpeq)) |
12796 | return IRQ_NONE; | |
4f774513 | 12797 | |
ba20c853 JS |
12798 | if (lpfc_fcp_look_ahead) { |
12799 | if (atomic_dec_and_test(&fcp_eq_hdl->fcp_eq_in_use)) | |
12800 | lpfc_sli4_eq_clr_intr(fpeq); | |
12801 | else { | |
12802 | atomic_inc(&fcp_eq_hdl->fcp_eq_in_use); | |
12803 | return IRQ_NONE; | |
12804 | } | |
12805 | } | |
12806 | ||
4f774513 JS |
12807 | /* Check device state for handling interrupt */ |
12808 | if (unlikely(lpfc_intr_state_check(phba))) { | |
b84daac9 | 12809 | fpeq->EQ_badstate++; |
4f774513 JS |
12810 | /* Check again for link_state with lock held */ |
12811 | spin_lock_irqsave(&phba->hbalock, iflag); | |
12812 | if (phba->link_state < LPFC_LINK_DOWN) | |
12813 | /* Flush, clear interrupt, and rearm the EQ */ | |
12814 | lpfc_sli4_eq_flush(phba, fpeq); | |
12815 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
ba20c853 JS |
12816 | if (lpfc_fcp_look_ahead) |
12817 | atomic_inc(&fcp_eq_hdl->fcp_eq_in_use); | |
4f774513 JS |
12818 | return IRQ_NONE; |
12819 | } | |
12820 | ||
12821 | /* | |
12822 | * Process all the event on FCP fast-path EQ | |
12823 | */ | |
12824 | while ((eqe = lpfc_sli4_eq_get(fpeq))) { | |
eb016566 JS |
12825 | if (eqe == NULL) |
12826 | break; | |
12827 | ||
67d12733 | 12828 | lpfc_sli4_hba_handle_eqe(phba, eqe, fcp_eqidx); |
73d91e50 | 12829 | if (!(++ecount % fpeq->entry_repost)) |
4f774513 | 12830 | lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_NOARM); |
b84daac9 | 12831 | fpeq->EQ_processed++; |
4f774513 JS |
12832 | } |
12833 | ||
b84daac9 JS |
12834 | /* Track the max number of EQEs processed in 1 intr */ |
12835 | if (ecount > fpeq->EQ_max_eqe) | |
12836 | fpeq->EQ_max_eqe = ecount; | |
12837 | ||
4f774513 JS |
12838 | /* Always clear and re-arm the fast-path EQ */ |
12839 | lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM); | |
12840 | ||
12841 | if (unlikely(ecount == 0)) { | |
b84daac9 | 12842 | fpeq->EQ_no_entry++; |
ba20c853 JS |
12843 | |
12844 | if (lpfc_fcp_look_ahead) { | |
12845 | atomic_inc(&fcp_eq_hdl->fcp_eq_in_use); | |
12846 | return IRQ_NONE; | |
12847 | } | |
12848 | ||
4f774513 JS |
12849 | if (phba->intr_type == MSIX) |
12850 | /* MSI-X treated interrupt served as no EQ share INT */ | |
12851 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
12852 | "0358 MSI-X interrupt with no EQE\n"); | |
12853 | else | |
12854 | /* Non MSI-X treated on interrupt as EQ share INT */ | |
12855 | return IRQ_NONE; | |
12856 | } | |
12857 | ||
ba20c853 JS |
12858 | if (lpfc_fcp_look_ahead) |
12859 | atomic_inc(&fcp_eq_hdl->fcp_eq_in_use); | |
4f774513 JS |
12860 | return IRQ_HANDLED; |
12861 | } /* lpfc_sli4_fp_intr_handler */ | |
12862 | ||
12863 | /** | |
12864 | * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device | |
12865 | * @irq: Interrupt number. | |
12866 | * @dev_id: The device context pointer. | |
12867 | * | |
12868 | * This function is the device-level interrupt handler to device with SLI-4 | |
12869 | * interface spec, called from the PCI layer when either MSI or Pin-IRQ | |
12870 | * interrupt mode is enabled and there is an event in the HBA which requires | |
12871 | * driver attention. This function invokes the slow-path interrupt attention | |
12872 | * handling function and fast-path interrupt attention handling function in | |
12873 | * turn to process the relevant HBA attention events. This function is called | |
12874 | * without any lock held. It gets the hbalock to access and update SLI data | |
12875 | * structures. | |
12876 | * | |
12877 | * This function returns IRQ_HANDLED when interrupt is handled, else it | |
12878 | * returns IRQ_NONE. | |
12879 | **/ | |
12880 | irqreturn_t | |
12881 | lpfc_sli4_intr_handler(int irq, void *dev_id) | |
12882 | { | |
12883 | struct lpfc_hba *phba; | |
67d12733 JS |
12884 | irqreturn_t hba_irq_rc; |
12885 | bool hba_handled = false; | |
962bc51b | 12886 | int fcp_eqidx; |
4f774513 JS |
12887 | |
12888 | /* Get the driver's phba structure from the dev_id */ | |
12889 | phba = (struct lpfc_hba *)dev_id; | |
12890 | ||
12891 | if (unlikely(!phba)) | |
12892 | return IRQ_NONE; | |
12893 | ||
4f774513 JS |
12894 | /* |
12895 | * Invoke fast-path host attention interrupt handling as appropriate. | |
12896 | */ | |
67d12733 JS |
12897 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_io_channel; fcp_eqidx++) { |
12898 | hba_irq_rc = lpfc_sli4_hba_intr_handler(irq, | |
4f774513 | 12899 | &phba->sli4_hba.fcp_eq_hdl[fcp_eqidx]); |
67d12733 JS |
12900 | if (hba_irq_rc == IRQ_HANDLED) |
12901 | hba_handled |= true; | |
4f774513 JS |
12902 | } |
12903 | ||
1ba981fd JS |
12904 | if (phba->cfg_fof) { |
12905 | hba_irq_rc = lpfc_sli4_fof_intr_handler(irq, | |
12906 | &phba->sli4_hba.fcp_eq_hdl[0]); | |
12907 | if (hba_irq_rc == IRQ_HANDLED) | |
12908 | hba_handled |= true; | |
12909 | } | |
12910 | ||
67d12733 | 12911 | return (hba_handled == true) ? IRQ_HANDLED : IRQ_NONE; |
4f774513 JS |
12912 | } /* lpfc_sli4_intr_handler */ |
12913 | ||
12914 | /** | |
12915 | * lpfc_sli4_queue_free - free a queue structure and associated memory | |
12916 | * @queue: The queue structure to free. | |
12917 | * | |
b595076a | 12918 | * This function frees a queue structure and the DMAable memory used for |
4f774513 JS |
12919 | * the host resident queue. This function must be called after destroying the |
12920 | * queue on the HBA. | |
12921 | **/ | |
12922 | void | |
12923 | lpfc_sli4_queue_free(struct lpfc_queue *queue) | |
12924 | { | |
12925 | struct lpfc_dmabuf *dmabuf; | |
12926 | ||
12927 | if (!queue) | |
12928 | return; | |
12929 | ||
12930 | while (!list_empty(&queue->page_list)) { | |
12931 | list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf, | |
12932 | list); | |
49198b37 | 12933 | dma_free_coherent(&queue->phba->pcidev->dev, SLI4_PAGE_SIZE, |
4f774513 JS |
12934 | dmabuf->virt, dmabuf->phys); |
12935 | kfree(dmabuf); | |
12936 | } | |
12937 | kfree(queue); | |
12938 | return; | |
12939 | } | |
12940 | ||
12941 | /** | |
12942 | * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure | |
12943 | * @phba: The HBA that this queue is being created on. | |
12944 | * @entry_size: The size of each queue entry for this queue. | |
12945 | * @entry count: The number of entries that this queue will handle. | |
12946 | * | |
12947 | * This function allocates a queue structure and the DMAable memory used for | |
12948 | * the host resident queue. This function must be called before creating the | |
12949 | * queue on the HBA. | |
12950 | **/ | |
12951 | struct lpfc_queue * | |
12952 | lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t entry_size, | |
12953 | uint32_t entry_count) | |
12954 | { | |
12955 | struct lpfc_queue *queue; | |
12956 | struct lpfc_dmabuf *dmabuf; | |
12957 | int x, total_qe_count; | |
12958 | void *dma_pointer; | |
cb5172ea | 12959 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
4f774513 | 12960 | |
cb5172ea JS |
12961 | if (!phba->sli4_hba.pc_sli4_params.supported) |
12962 | hw_page_size = SLI4_PAGE_SIZE; | |
12963 | ||
4f774513 JS |
12964 | queue = kzalloc(sizeof(struct lpfc_queue) + |
12965 | (sizeof(union sli4_qe) * entry_count), GFP_KERNEL); | |
12966 | if (!queue) | |
12967 | return NULL; | |
cb5172ea JS |
12968 | queue->page_count = (ALIGN(entry_size * entry_count, |
12969 | hw_page_size))/hw_page_size; | |
4f774513 JS |
12970 | INIT_LIST_HEAD(&queue->list); |
12971 | INIT_LIST_HEAD(&queue->page_list); | |
12972 | INIT_LIST_HEAD(&queue->child_list); | |
12973 | for (x = 0, total_qe_count = 0; x < queue->page_count; x++) { | |
12974 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | |
12975 | if (!dmabuf) | |
12976 | goto out_fail; | |
1aee383d JP |
12977 | dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev, |
12978 | hw_page_size, &dmabuf->phys, | |
12979 | GFP_KERNEL); | |
4f774513 JS |
12980 | if (!dmabuf->virt) { |
12981 | kfree(dmabuf); | |
12982 | goto out_fail; | |
12983 | } | |
12984 | dmabuf->buffer_tag = x; | |
12985 | list_add_tail(&dmabuf->list, &queue->page_list); | |
12986 | /* initialize queue's entry array */ | |
12987 | dma_pointer = dmabuf->virt; | |
12988 | for (; total_qe_count < entry_count && | |
cb5172ea | 12989 | dma_pointer < (hw_page_size + dmabuf->virt); |
4f774513 JS |
12990 | total_qe_count++, dma_pointer += entry_size) { |
12991 | queue->qe[total_qe_count].address = dma_pointer; | |
12992 | } | |
12993 | } | |
12994 | queue->entry_size = entry_size; | |
12995 | queue->entry_count = entry_count; | |
73d91e50 JS |
12996 | |
12997 | /* | |
12998 | * entry_repost is calculated based on the number of entries in the | |
12999 | * queue. This works out except for RQs. If buffers are NOT initially | |
13000 | * posted for every RQE, entry_repost should be adjusted accordingly. | |
13001 | */ | |
13002 | queue->entry_repost = (entry_count >> 3); | |
13003 | if (queue->entry_repost < LPFC_QUEUE_MIN_REPOST) | |
13004 | queue->entry_repost = LPFC_QUEUE_MIN_REPOST; | |
4f774513 JS |
13005 | queue->phba = phba; |
13006 | ||
13007 | return queue; | |
13008 | out_fail: | |
13009 | lpfc_sli4_queue_free(queue); | |
13010 | return NULL; | |
13011 | } | |
13012 | ||
962bc51b JS |
13013 | /** |
13014 | * lpfc_dual_chute_pci_bar_map - Map pci base address register to host memory | |
13015 | * @phba: HBA structure that indicates port to create a queue on. | |
13016 | * @pci_barset: PCI BAR set flag. | |
13017 | * | |
13018 | * This function shall perform iomap of the specified PCI BAR address to host | |
13019 | * memory address if not already done so and return it. The returned host | |
13020 | * memory address can be NULL. | |
13021 | */ | |
13022 | static void __iomem * | |
13023 | lpfc_dual_chute_pci_bar_map(struct lpfc_hba *phba, uint16_t pci_barset) | |
13024 | { | |
962bc51b JS |
13025 | if (!phba->pcidev) |
13026 | return NULL; | |
962bc51b JS |
13027 | |
13028 | switch (pci_barset) { | |
13029 | case WQ_PCI_BAR_0_AND_1: | |
962bc51b JS |
13030 | return phba->pci_bar0_memmap_p; |
13031 | case WQ_PCI_BAR_2_AND_3: | |
962bc51b JS |
13032 | return phba->pci_bar2_memmap_p; |
13033 | case WQ_PCI_BAR_4_AND_5: | |
962bc51b JS |
13034 | return phba->pci_bar4_memmap_p; |
13035 | default: | |
13036 | break; | |
13037 | } | |
13038 | return NULL; | |
13039 | } | |
13040 | ||
173edbb2 JS |
13041 | /** |
13042 | * lpfc_modify_fcp_eq_delay - Modify Delay Multiplier on FCP EQs | |
13043 | * @phba: HBA structure that indicates port to create a queue on. | |
13044 | * @startq: The starting FCP EQ to modify | |
13045 | * | |
13046 | * This function sends an MODIFY_EQ_DELAY mailbox command to the HBA. | |
13047 | * | |
13048 | * The @phba struct is used to send mailbox command to HBA. The @startq | |
13049 | * is used to get the starting FCP EQ to change. | |
13050 | * This function is asynchronous and will wait for the mailbox | |
13051 | * command to finish before continuing. | |
13052 | * | |
13053 | * On success this function will return a zero. If unable to allocate enough | |
13054 | * memory this function will return -ENOMEM. If the queue create mailbox command | |
13055 | * fails this function will return -ENXIO. | |
13056 | **/ | |
a2fc4aef | 13057 | int |
2c9c5a00 | 13058 | lpfc_modify_fcp_eq_delay(struct lpfc_hba *phba, uint32_t startq) |
173edbb2 JS |
13059 | { |
13060 | struct lpfc_mbx_modify_eq_delay *eq_delay; | |
13061 | LPFC_MBOXQ_t *mbox; | |
13062 | struct lpfc_queue *eq; | |
13063 | int cnt, rc, length, status = 0; | |
13064 | uint32_t shdr_status, shdr_add_status; | |
ee02006b | 13065 | uint32_t result; |
173edbb2 JS |
13066 | int fcp_eqidx; |
13067 | union lpfc_sli4_cfg_shdr *shdr; | |
13068 | uint16_t dmult; | |
13069 | ||
67d12733 | 13070 | if (startq >= phba->cfg_fcp_io_channel) |
173edbb2 JS |
13071 | return 0; |
13072 | ||
13073 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
13074 | if (!mbox) | |
13075 | return -ENOMEM; | |
13076 | length = (sizeof(struct lpfc_mbx_modify_eq_delay) - | |
13077 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
13078 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
13079 | LPFC_MBOX_OPCODE_MODIFY_EQ_DELAY, | |
13080 | length, LPFC_SLI4_MBX_EMBED); | |
13081 | eq_delay = &mbox->u.mqe.un.eq_delay; | |
13082 | ||
13083 | /* Calculate delay multiper from maximum interrupt per second */ | |
ee02006b JS |
13084 | result = phba->cfg_fcp_imax / phba->cfg_fcp_io_channel; |
13085 | if (result > LPFC_DMULT_CONST) | |
13086 | dmult = 0; | |
13087 | else | |
13088 | dmult = LPFC_DMULT_CONST/result - 1; | |
173edbb2 JS |
13089 | |
13090 | cnt = 0; | |
67d12733 | 13091 | for (fcp_eqidx = startq; fcp_eqidx < phba->cfg_fcp_io_channel; |
173edbb2 | 13092 | fcp_eqidx++) { |
67d12733 | 13093 | eq = phba->sli4_hba.hba_eq[fcp_eqidx]; |
173edbb2 JS |
13094 | if (!eq) |
13095 | continue; | |
13096 | eq_delay->u.request.eq[cnt].eq_id = eq->queue_id; | |
13097 | eq_delay->u.request.eq[cnt].phase = 0; | |
13098 | eq_delay->u.request.eq[cnt].delay_multi = dmult; | |
13099 | cnt++; | |
13100 | if (cnt >= LPFC_MAX_EQ_DELAY) | |
13101 | break; | |
13102 | } | |
13103 | eq_delay->u.request.num_eq = cnt; | |
13104 | ||
13105 | mbox->vport = phba->pport; | |
13106 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
13107 | mbox->context1 = NULL; | |
13108 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
13109 | shdr = (union lpfc_sli4_cfg_shdr *) &eq_delay->header.cfg_shdr; | |
13110 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
13111 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
13112 | if (shdr_status || shdr_add_status || rc) { | |
13113 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
13114 | "2512 MODIFY_EQ_DELAY mailbox failed with " | |
13115 | "status x%x add_status x%x, mbx status x%x\n", | |
13116 | shdr_status, shdr_add_status, rc); | |
13117 | status = -ENXIO; | |
13118 | } | |
13119 | mempool_free(mbox, phba->mbox_mem_pool); | |
13120 | return status; | |
13121 | } | |
13122 | ||
4f774513 JS |
13123 | /** |
13124 | * lpfc_eq_create - Create an Event Queue on the HBA | |
13125 | * @phba: HBA structure that indicates port to create a queue on. | |
13126 | * @eq: The queue structure to use to create the event queue. | |
13127 | * @imax: The maximum interrupt per second limit. | |
13128 | * | |
13129 | * This function creates an event queue, as detailed in @eq, on a port, | |
13130 | * described by @phba by sending an EQ_CREATE mailbox command to the HBA. | |
13131 | * | |
13132 | * The @phba struct is used to send mailbox command to HBA. The @eq struct | |
13133 | * is used to get the entry count and entry size that are necessary to | |
13134 | * determine the number of pages to allocate and use for this queue. This | |
13135 | * function will send the EQ_CREATE mailbox command to the HBA to setup the | |
13136 | * event queue. This function is asynchronous and will wait for the mailbox | |
13137 | * command to finish before continuing. | |
13138 | * | |
13139 | * On success this function will return a zero. If unable to allocate enough | |
d439d286 JS |
13140 | * memory this function will return -ENOMEM. If the queue create mailbox command |
13141 | * fails this function will return -ENXIO. | |
4f774513 | 13142 | **/ |
a2fc4aef | 13143 | int |
ee02006b | 13144 | lpfc_eq_create(struct lpfc_hba *phba, struct lpfc_queue *eq, uint32_t imax) |
4f774513 JS |
13145 | { |
13146 | struct lpfc_mbx_eq_create *eq_create; | |
13147 | LPFC_MBOXQ_t *mbox; | |
13148 | int rc, length, status = 0; | |
13149 | struct lpfc_dmabuf *dmabuf; | |
13150 | uint32_t shdr_status, shdr_add_status; | |
13151 | union lpfc_sli4_cfg_shdr *shdr; | |
13152 | uint16_t dmult; | |
49198b37 JS |
13153 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
13154 | ||
2e90f4b5 JS |
13155 | /* sanity check on queue memory */ |
13156 | if (!eq) | |
13157 | return -ENODEV; | |
49198b37 JS |
13158 | if (!phba->sli4_hba.pc_sli4_params.supported) |
13159 | hw_page_size = SLI4_PAGE_SIZE; | |
4f774513 JS |
13160 | |
13161 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
13162 | if (!mbox) | |
13163 | return -ENOMEM; | |
13164 | length = (sizeof(struct lpfc_mbx_eq_create) - | |
13165 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
13166 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
13167 | LPFC_MBOX_OPCODE_EQ_CREATE, | |
13168 | length, LPFC_SLI4_MBX_EMBED); | |
13169 | eq_create = &mbox->u.mqe.un.eq_create; | |
13170 | bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request, | |
13171 | eq->page_count); | |
13172 | bf_set(lpfc_eq_context_size, &eq_create->u.request.context, | |
13173 | LPFC_EQE_SIZE); | |
13174 | bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1); | |
2c9c5a00 JS |
13175 | /* don't setup delay multiplier using EQ_CREATE */ |
13176 | dmult = 0; | |
4f774513 JS |
13177 | bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context, |
13178 | dmult); | |
13179 | switch (eq->entry_count) { | |
13180 | default: | |
13181 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
13182 | "0360 Unsupported EQ count. (%d)\n", | |
13183 | eq->entry_count); | |
13184 | if (eq->entry_count < 256) | |
13185 | return -EINVAL; | |
13186 | /* otherwise default to smallest count (drop through) */ | |
13187 | case 256: | |
13188 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, | |
13189 | LPFC_EQ_CNT_256); | |
13190 | break; | |
13191 | case 512: | |
13192 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, | |
13193 | LPFC_EQ_CNT_512); | |
13194 | break; | |
13195 | case 1024: | |
13196 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, | |
13197 | LPFC_EQ_CNT_1024); | |
13198 | break; | |
13199 | case 2048: | |
13200 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, | |
13201 | LPFC_EQ_CNT_2048); | |
13202 | break; | |
13203 | case 4096: | |
13204 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, | |
13205 | LPFC_EQ_CNT_4096); | |
13206 | break; | |
13207 | } | |
13208 | list_for_each_entry(dmabuf, &eq->page_list, list) { | |
49198b37 | 13209 | memset(dmabuf->virt, 0, hw_page_size); |
4f774513 JS |
13210 | eq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
13211 | putPaddrLow(dmabuf->phys); | |
13212 | eq_create->u.request.page[dmabuf->buffer_tag].addr_hi = | |
13213 | putPaddrHigh(dmabuf->phys); | |
13214 | } | |
13215 | mbox->vport = phba->pport; | |
13216 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
13217 | mbox->context1 = NULL; | |
13218 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
13219 | shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr; | |
13220 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
13221 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
13222 | if (shdr_status || shdr_add_status || rc) { | |
13223 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
13224 | "2500 EQ_CREATE mailbox failed with " | |
13225 | "status x%x add_status x%x, mbx status x%x\n", | |
13226 | shdr_status, shdr_add_status, rc); | |
13227 | status = -ENXIO; | |
13228 | } | |
13229 | eq->type = LPFC_EQ; | |
13230 | eq->subtype = LPFC_NONE; | |
13231 | eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response); | |
13232 | if (eq->queue_id == 0xFFFF) | |
13233 | status = -ENXIO; | |
13234 | eq->host_index = 0; | |
13235 | eq->hba_index = 0; | |
13236 | ||
8fa38513 | 13237 | mempool_free(mbox, phba->mbox_mem_pool); |
4f774513 JS |
13238 | return status; |
13239 | } | |
13240 | ||
13241 | /** | |
13242 | * lpfc_cq_create - Create a Completion Queue on the HBA | |
13243 | * @phba: HBA structure that indicates port to create a queue on. | |
13244 | * @cq: The queue structure to use to create the completion queue. | |
13245 | * @eq: The event queue to bind this completion queue to. | |
13246 | * | |
13247 | * This function creates a completion queue, as detailed in @wq, on a port, | |
13248 | * described by @phba by sending a CQ_CREATE mailbox command to the HBA. | |
13249 | * | |
13250 | * The @phba struct is used to send mailbox command to HBA. The @cq struct | |
13251 | * is used to get the entry count and entry size that are necessary to | |
13252 | * determine the number of pages to allocate and use for this queue. The @eq | |
13253 | * is used to indicate which event queue to bind this completion queue to. This | |
13254 | * function will send the CQ_CREATE mailbox command to the HBA to setup the | |
13255 | * completion queue. This function is asynchronous and will wait for the mailbox | |
13256 | * command to finish before continuing. | |
13257 | * | |
13258 | * On success this function will return a zero. If unable to allocate enough | |
d439d286 JS |
13259 | * memory this function will return -ENOMEM. If the queue create mailbox command |
13260 | * fails this function will return -ENXIO. | |
4f774513 | 13261 | **/ |
a2fc4aef | 13262 | int |
4f774513 JS |
13263 | lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq, |
13264 | struct lpfc_queue *eq, uint32_t type, uint32_t subtype) | |
13265 | { | |
13266 | struct lpfc_mbx_cq_create *cq_create; | |
13267 | struct lpfc_dmabuf *dmabuf; | |
13268 | LPFC_MBOXQ_t *mbox; | |
13269 | int rc, length, status = 0; | |
13270 | uint32_t shdr_status, shdr_add_status; | |
13271 | union lpfc_sli4_cfg_shdr *shdr; | |
49198b37 JS |
13272 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
13273 | ||
2e90f4b5 JS |
13274 | /* sanity check on queue memory */ |
13275 | if (!cq || !eq) | |
13276 | return -ENODEV; | |
49198b37 JS |
13277 | if (!phba->sli4_hba.pc_sli4_params.supported) |
13278 | hw_page_size = SLI4_PAGE_SIZE; | |
13279 | ||
4f774513 JS |
13280 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
13281 | if (!mbox) | |
13282 | return -ENOMEM; | |
13283 | length = (sizeof(struct lpfc_mbx_cq_create) - | |
13284 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
13285 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
13286 | LPFC_MBOX_OPCODE_CQ_CREATE, | |
13287 | length, LPFC_SLI4_MBX_EMBED); | |
13288 | cq_create = &mbox->u.mqe.un.cq_create; | |
5a6f133e | 13289 | shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr; |
4f774513 JS |
13290 | bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request, |
13291 | cq->page_count); | |
13292 | bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1); | |
13293 | bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1); | |
5a6f133e JS |
13294 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
13295 | phba->sli4_hba.pc_sli4_params.cqv); | |
13296 | if (phba->sli4_hba.pc_sli4_params.cqv == LPFC_Q_CREATE_VERSION_2) { | |
c31098ce JS |
13297 | /* FW only supports 1. Should be PAGE_SIZE/SLI4_PAGE_SIZE */ |
13298 | bf_set(lpfc_mbx_cq_create_page_size, &cq_create->u.request, 1); | |
5a6f133e JS |
13299 | bf_set(lpfc_cq_eq_id_2, &cq_create->u.request.context, |
13300 | eq->queue_id); | |
13301 | } else { | |
13302 | bf_set(lpfc_cq_eq_id, &cq_create->u.request.context, | |
13303 | eq->queue_id); | |
13304 | } | |
4f774513 JS |
13305 | switch (cq->entry_count) { |
13306 | default: | |
13307 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
13308 | "0361 Unsupported CQ count. (%d)\n", | |
13309 | cq->entry_count); | |
4f4c1863 JS |
13310 | if (cq->entry_count < 256) { |
13311 | status = -EINVAL; | |
13312 | goto out; | |
13313 | } | |
4f774513 JS |
13314 | /* otherwise default to smallest count (drop through) */ |
13315 | case 256: | |
13316 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, | |
13317 | LPFC_CQ_CNT_256); | |
13318 | break; | |
13319 | case 512: | |
13320 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, | |
13321 | LPFC_CQ_CNT_512); | |
13322 | break; | |
13323 | case 1024: | |
13324 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, | |
13325 | LPFC_CQ_CNT_1024); | |
13326 | break; | |
13327 | } | |
13328 | list_for_each_entry(dmabuf, &cq->page_list, list) { | |
49198b37 | 13329 | memset(dmabuf->virt, 0, hw_page_size); |
4f774513 JS |
13330 | cq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
13331 | putPaddrLow(dmabuf->phys); | |
13332 | cq_create->u.request.page[dmabuf->buffer_tag].addr_hi = | |
13333 | putPaddrHigh(dmabuf->phys); | |
13334 | } | |
13335 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
13336 | ||
13337 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
4f774513 JS |
13338 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
13339 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
13340 | if (shdr_status || shdr_add_status || rc) { | |
13341 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
13342 | "2501 CQ_CREATE mailbox failed with " | |
13343 | "status x%x add_status x%x, mbx status x%x\n", | |
13344 | shdr_status, shdr_add_status, rc); | |
13345 | status = -ENXIO; | |
13346 | goto out; | |
13347 | } | |
13348 | cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response); | |
13349 | if (cq->queue_id == 0xFFFF) { | |
13350 | status = -ENXIO; | |
13351 | goto out; | |
13352 | } | |
13353 | /* link the cq onto the parent eq child list */ | |
13354 | list_add_tail(&cq->list, &eq->child_list); | |
13355 | /* Set up completion queue's type and subtype */ | |
13356 | cq->type = type; | |
13357 | cq->subtype = subtype; | |
13358 | cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response); | |
2a622bfb | 13359 | cq->assoc_qid = eq->queue_id; |
4f774513 JS |
13360 | cq->host_index = 0; |
13361 | cq->hba_index = 0; | |
4f774513 | 13362 | |
8fa38513 JS |
13363 | out: |
13364 | mempool_free(mbox, phba->mbox_mem_pool); | |
4f774513 JS |
13365 | return status; |
13366 | } | |
13367 | ||
b19a061a JS |
13368 | /** |
13369 | * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration | |
13370 | * @phba: HBA structure that indicates port to create a queue on. | |
13371 | * @mq: The queue structure to use to create the mailbox queue. | |
13372 | * @mbox: An allocated pointer to type LPFC_MBOXQ_t | |
13373 | * @cq: The completion queue to associate with this cq. | |
13374 | * | |
13375 | * This function provides failback (fb) functionality when the | |
13376 | * mq_create_ext fails on older FW generations. It's purpose is identical | |
13377 | * to mq_create_ext otherwise. | |
13378 | * | |
13379 | * This routine cannot fail as all attributes were previously accessed and | |
13380 | * initialized in mq_create_ext. | |
13381 | **/ | |
13382 | static void | |
13383 | lpfc_mq_create_fb_init(struct lpfc_hba *phba, struct lpfc_queue *mq, | |
13384 | LPFC_MBOXQ_t *mbox, struct lpfc_queue *cq) | |
13385 | { | |
13386 | struct lpfc_mbx_mq_create *mq_create; | |
13387 | struct lpfc_dmabuf *dmabuf; | |
13388 | int length; | |
13389 | ||
13390 | length = (sizeof(struct lpfc_mbx_mq_create) - | |
13391 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
13392 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
13393 | LPFC_MBOX_OPCODE_MQ_CREATE, | |
13394 | length, LPFC_SLI4_MBX_EMBED); | |
13395 | mq_create = &mbox->u.mqe.un.mq_create; | |
13396 | bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request, | |
13397 | mq->page_count); | |
13398 | bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context, | |
13399 | cq->queue_id); | |
13400 | bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1); | |
13401 | switch (mq->entry_count) { | |
13402 | case 16: | |
5a6f133e JS |
13403 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
13404 | LPFC_MQ_RING_SIZE_16); | |
b19a061a JS |
13405 | break; |
13406 | case 32: | |
5a6f133e JS |
13407 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
13408 | LPFC_MQ_RING_SIZE_32); | |
b19a061a JS |
13409 | break; |
13410 | case 64: | |
5a6f133e JS |
13411 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
13412 | LPFC_MQ_RING_SIZE_64); | |
b19a061a JS |
13413 | break; |
13414 | case 128: | |
5a6f133e JS |
13415 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
13416 | LPFC_MQ_RING_SIZE_128); | |
b19a061a JS |
13417 | break; |
13418 | } | |
13419 | list_for_each_entry(dmabuf, &mq->page_list, list) { | |
13420 | mq_create->u.request.page[dmabuf->buffer_tag].addr_lo = | |
13421 | putPaddrLow(dmabuf->phys); | |
13422 | mq_create->u.request.page[dmabuf->buffer_tag].addr_hi = | |
13423 | putPaddrHigh(dmabuf->phys); | |
13424 | } | |
13425 | } | |
13426 | ||
04c68496 JS |
13427 | /** |
13428 | * lpfc_mq_create - Create a mailbox Queue on the HBA | |
13429 | * @phba: HBA structure that indicates port to create a queue on. | |
13430 | * @mq: The queue structure to use to create the mailbox queue. | |
b19a061a JS |
13431 | * @cq: The completion queue to associate with this cq. |
13432 | * @subtype: The queue's subtype. | |
04c68496 JS |
13433 | * |
13434 | * This function creates a mailbox queue, as detailed in @mq, on a port, | |
13435 | * described by @phba by sending a MQ_CREATE mailbox command to the HBA. | |
13436 | * | |
13437 | * The @phba struct is used to send mailbox command to HBA. The @cq struct | |
13438 | * is used to get the entry count and entry size that are necessary to | |
13439 | * determine the number of pages to allocate and use for this queue. This | |
13440 | * function will send the MQ_CREATE mailbox command to the HBA to setup the | |
13441 | * mailbox queue. This function is asynchronous and will wait for the mailbox | |
13442 | * command to finish before continuing. | |
13443 | * | |
13444 | * On success this function will return a zero. If unable to allocate enough | |
d439d286 JS |
13445 | * memory this function will return -ENOMEM. If the queue create mailbox command |
13446 | * fails this function will return -ENXIO. | |
04c68496 | 13447 | **/ |
b19a061a | 13448 | int32_t |
04c68496 JS |
13449 | lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq, |
13450 | struct lpfc_queue *cq, uint32_t subtype) | |
13451 | { | |
13452 | struct lpfc_mbx_mq_create *mq_create; | |
b19a061a | 13453 | struct lpfc_mbx_mq_create_ext *mq_create_ext; |
04c68496 JS |
13454 | struct lpfc_dmabuf *dmabuf; |
13455 | LPFC_MBOXQ_t *mbox; | |
13456 | int rc, length, status = 0; | |
13457 | uint32_t shdr_status, shdr_add_status; | |
13458 | union lpfc_sli4_cfg_shdr *shdr; | |
49198b37 | 13459 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
04c68496 | 13460 | |
2e90f4b5 JS |
13461 | /* sanity check on queue memory */ |
13462 | if (!mq || !cq) | |
13463 | return -ENODEV; | |
49198b37 JS |
13464 | if (!phba->sli4_hba.pc_sli4_params.supported) |
13465 | hw_page_size = SLI4_PAGE_SIZE; | |
b19a061a | 13466 | |
04c68496 JS |
13467 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
13468 | if (!mbox) | |
13469 | return -ENOMEM; | |
b19a061a | 13470 | length = (sizeof(struct lpfc_mbx_mq_create_ext) - |
04c68496 JS |
13471 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
13472 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
b19a061a | 13473 | LPFC_MBOX_OPCODE_MQ_CREATE_EXT, |
04c68496 | 13474 | length, LPFC_SLI4_MBX_EMBED); |
b19a061a JS |
13475 | |
13476 | mq_create_ext = &mbox->u.mqe.un.mq_create_ext; | |
5a6f133e | 13477 | shdr = (union lpfc_sli4_cfg_shdr *) &mq_create_ext->header.cfg_shdr; |
70f3c073 JS |
13478 | bf_set(lpfc_mbx_mq_create_ext_num_pages, |
13479 | &mq_create_ext->u.request, mq->page_count); | |
13480 | bf_set(lpfc_mbx_mq_create_ext_async_evt_link, | |
13481 | &mq_create_ext->u.request, 1); | |
13482 | bf_set(lpfc_mbx_mq_create_ext_async_evt_fip, | |
b19a061a JS |
13483 | &mq_create_ext->u.request, 1); |
13484 | bf_set(lpfc_mbx_mq_create_ext_async_evt_group5, | |
13485 | &mq_create_ext->u.request, 1); | |
70f3c073 JS |
13486 | bf_set(lpfc_mbx_mq_create_ext_async_evt_fc, |
13487 | &mq_create_ext->u.request, 1); | |
13488 | bf_set(lpfc_mbx_mq_create_ext_async_evt_sli, | |
13489 | &mq_create_ext->u.request, 1); | |
b19a061a | 13490 | bf_set(lpfc_mq_context_valid, &mq_create_ext->u.request.context, 1); |
5a6f133e JS |
13491 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
13492 | phba->sli4_hba.pc_sli4_params.mqv); | |
13493 | if (phba->sli4_hba.pc_sli4_params.mqv == LPFC_Q_CREATE_VERSION_1) | |
13494 | bf_set(lpfc_mbx_mq_create_ext_cq_id, &mq_create_ext->u.request, | |
13495 | cq->queue_id); | |
13496 | else | |
13497 | bf_set(lpfc_mq_context_cq_id, &mq_create_ext->u.request.context, | |
13498 | cq->queue_id); | |
04c68496 JS |
13499 | switch (mq->entry_count) { |
13500 | default: | |
13501 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
13502 | "0362 Unsupported MQ count. (%d)\n", | |
13503 | mq->entry_count); | |
4f4c1863 JS |
13504 | if (mq->entry_count < 16) { |
13505 | status = -EINVAL; | |
13506 | goto out; | |
13507 | } | |
04c68496 JS |
13508 | /* otherwise default to smallest count (drop through) */ |
13509 | case 16: | |
5a6f133e JS |
13510 | bf_set(lpfc_mq_context_ring_size, |
13511 | &mq_create_ext->u.request.context, | |
13512 | LPFC_MQ_RING_SIZE_16); | |
04c68496 JS |
13513 | break; |
13514 | case 32: | |
5a6f133e JS |
13515 | bf_set(lpfc_mq_context_ring_size, |
13516 | &mq_create_ext->u.request.context, | |
13517 | LPFC_MQ_RING_SIZE_32); | |
04c68496 JS |
13518 | break; |
13519 | case 64: | |
5a6f133e JS |
13520 | bf_set(lpfc_mq_context_ring_size, |
13521 | &mq_create_ext->u.request.context, | |
13522 | LPFC_MQ_RING_SIZE_64); | |
04c68496 JS |
13523 | break; |
13524 | case 128: | |
5a6f133e JS |
13525 | bf_set(lpfc_mq_context_ring_size, |
13526 | &mq_create_ext->u.request.context, | |
13527 | LPFC_MQ_RING_SIZE_128); | |
04c68496 JS |
13528 | break; |
13529 | } | |
13530 | list_for_each_entry(dmabuf, &mq->page_list, list) { | |
49198b37 | 13531 | memset(dmabuf->virt, 0, hw_page_size); |
b19a061a | 13532 | mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_lo = |
04c68496 | 13533 | putPaddrLow(dmabuf->phys); |
b19a061a | 13534 | mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_hi = |
04c68496 JS |
13535 | putPaddrHigh(dmabuf->phys); |
13536 | } | |
13537 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
b19a061a JS |
13538 | mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, |
13539 | &mq_create_ext->u.response); | |
13540 | if (rc != MBX_SUCCESS) { | |
13541 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
13542 | "2795 MQ_CREATE_EXT failed with " | |
13543 | "status x%x. Failback to MQ_CREATE.\n", | |
13544 | rc); | |
13545 | lpfc_mq_create_fb_init(phba, mq, mbox, cq); | |
13546 | mq_create = &mbox->u.mqe.un.mq_create; | |
13547 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
13548 | shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr; | |
13549 | mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, | |
13550 | &mq_create->u.response); | |
13551 | } | |
13552 | ||
04c68496 | 13553 | /* The IOCTL status is embedded in the mailbox subheader. */ |
04c68496 JS |
13554 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
13555 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
13556 | if (shdr_status || shdr_add_status || rc) { | |
13557 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
13558 | "2502 MQ_CREATE mailbox failed with " | |
13559 | "status x%x add_status x%x, mbx status x%x\n", | |
13560 | shdr_status, shdr_add_status, rc); | |
13561 | status = -ENXIO; | |
13562 | goto out; | |
13563 | } | |
04c68496 JS |
13564 | if (mq->queue_id == 0xFFFF) { |
13565 | status = -ENXIO; | |
13566 | goto out; | |
13567 | } | |
13568 | mq->type = LPFC_MQ; | |
2a622bfb | 13569 | mq->assoc_qid = cq->queue_id; |
04c68496 JS |
13570 | mq->subtype = subtype; |
13571 | mq->host_index = 0; | |
13572 | mq->hba_index = 0; | |
13573 | ||
13574 | /* link the mq onto the parent cq child list */ | |
13575 | list_add_tail(&mq->list, &cq->child_list); | |
13576 | out: | |
8fa38513 | 13577 | mempool_free(mbox, phba->mbox_mem_pool); |
04c68496 JS |
13578 | return status; |
13579 | } | |
13580 | ||
4f774513 JS |
13581 | /** |
13582 | * lpfc_wq_create - Create a Work Queue on the HBA | |
13583 | * @phba: HBA structure that indicates port to create a queue on. | |
13584 | * @wq: The queue structure to use to create the work queue. | |
13585 | * @cq: The completion queue to bind this work queue to. | |
13586 | * @subtype: The subtype of the work queue indicating its functionality. | |
13587 | * | |
13588 | * This function creates a work queue, as detailed in @wq, on a port, described | |
13589 | * by @phba by sending a WQ_CREATE mailbox command to the HBA. | |
13590 | * | |
13591 | * The @phba struct is used to send mailbox command to HBA. The @wq struct | |
13592 | * is used to get the entry count and entry size that are necessary to | |
13593 | * determine the number of pages to allocate and use for this queue. The @cq | |
13594 | * is used to indicate which completion queue to bind this work queue to. This | |
13595 | * function will send the WQ_CREATE mailbox command to the HBA to setup the | |
13596 | * work queue. This function is asynchronous and will wait for the mailbox | |
13597 | * command to finish before continuing. | |
13598 | * | |
13599 | * On success this function will return a zero. If unable to allocate enough | |
d439d286 JS |
13600 | * memory this function will return -ENOMEM. If the queue create mailbox command |
13601 | * fails this function will return -ENXIO. | |
4f774513 | 13602 | **/ |
a2fc4aef | 13603 | int |
4f774513 JS |
13604 | lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq, |
13605 | struct lpfc_queue *cq, uint32_t subtype) | |
13606 | { | |
13607 | struct lpfc_mbx_wq_create *wq_create; | |
13608 | struct lpfc_dmabuf *dmabuf; | |
13609 | LPFC_MBOXQ_t *mbox; | |
13610 | int rc, length, status = 0; | |
13611 | uint32_t shdr_status, shdr_add_status; | |
13612 | union lpfc_sli4_cfg_shdr *shdr; | |
49198b37 | 13613 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
5a6f133e | 13614 | struct dma_address *page; |
962bc51b JS |
13615 | void __iomem *bar_memmap_p; |
13616 | uint32_t db_offset; | |
13617 | uint16_t pci_barset; | |
49198b37 | 13618 | |
2e90f4b5 JS |
13619 | /* sanity check on queue memory */ |
13620 | if (!wq || !cq) | |
13621 | return -ENODEV; | |
49198b37 JS |
13622 | if (!phba->sli4_hba.pc_sli4_params.supported) |
13623 | hw_page_size = SLI4_PAGE_SIZE; | |
4f774513 JS |
13624 | |
13625 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
13626 | if (!mbox) | |
13627 | return -ENOMEM; | |
13628 | length = (sizeof(struct lpfc_mbx_wq_create) - | |
13629 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
13630 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
13631 | LPFC_MBOX_OPCODE_FCOE_WQ_CREATE, | |
13632 | length, LPFC_SLI4_MBX_EMBED); | |
13633 | wq_create = &mbox->u.mqe.un.wq_create; | |
5a6f133e | 13634 | shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr; |
4f774513 JS |
13635 | bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request, |
13636 | wq->page_count); | |
13637 | bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request, | |
13638 | cq->queue_id); | |
0c651878 JS |
13639 | |
13640 | /* wqv is the earliest version supported, NOT the latest */ | |
5a6f133e JS |
13641 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
13642 | phba->sli4_hba.pc_sli4_params.wqv); | |
962bc51b | 13643 | |
0c651878 JS |
13644 | switch (phba->sli4_hba.pc_sli4_params.wqv) { |
13645 | case LPFC_Q_CREATE_VERSION_0: | |
13646 | switch (wq->entry_size) { | |
13647 | default: | |
13648 | case 64: | |
13649 | /* Nothing to do, version 0 ONLY supports 64 byte */ | |
13650 | page = wq_create->u.request.page; | |
13651 | break; | |
13652 | case 128: | |
13653 | if (!(phba->sli4_hba.pc_sli4_params.wqsize & | |
13654 | LPFC_WQ_SZ128_SUPPORT)) { | |
13655 | status = -ERANGE; | |
13656 | goto out; | |
13657 | } | |
13658 | /* If we get here the HBA MUST also support V1 and | |
13659 | * we MUST use it | |
13660 | */ | |
13661 | bf_set(lpfc_mbox_hdr_version, &shdr->request, | |
13662 | LPFC_Q_CREATE_VERSION_1); | |
13663 | ||
13664 | bf_set(lpfc_mbx_wq_create_wqe_count, | |
13665 | &wq_create->u.request_1, wq->entry_count); | |
13666 | bf_set(lpfc_mbx_wq_create_wqe_size, | |
13667 | &wq_create->u.request_1, | |
13668 | LPFC_WQ_WQE_SIZE_128); | |
13669 | bf_set(lpfc_mbx_wq_create_page_size, | |
13670 | &wq_create->u.request_1, | |
13671 | (PAGE_SIZE/SLI4_PAGE_SIZE)); | |
13672 | page = wq_create->u.request_1.page; | |
13673 | break; | |
13674 | } | |
13675 | break; | |
13676 | case LPFC_Q_CREATE_VERSION_1: | |
5a6f133e JS |
13677 | bf_set(lpfc_mbx_wq_create_wqe_count, &wq_create->u.request_1, |
13678 | wq->entry_count); | |
13679 | switch (wq->entry_size) { | |
13680 | default: | |
13681 | case 64: | |
13682 | bf_set(lpfc_mbx_wq_create_wqe_size, | |
13683 | &wq_create->u.request_1, | |
13684 | LPFC_WQ_WQE_SIZE_64); | |
13685 | break; | |
13686 | case 128: | |
0c651878 JS |
13687 | if (!(phba->sli4_hba.pc_sli4_params.wqsize & |
13688 | LPFC_WQ_SZ128_SUPPORT)) { | |
13689 | status = -ERANGE; | |
13690 | goto out; | |
13691 | } | |
5a6f133e JS |
13692 | bf_set(lpfc_mbx_wq_create_wqe_size, |
13693 | &wq_create->u.request_1, | |
13694 | LPFC_WQ_WQE_SIZE_128); | |
13695 | break; | |
13696 | } | |
13697 | bf_set(lpfc_mbx_wq_create_page_size, &wq_create->u.request_1, | |
13698 | (PAGE_SIZE/SLI4_PAGE_SIZE)); | |
13699 | page = wq_create->u.request_1.page; | |
0c651878 JS |
13700 | break; |
13701 | default: | |
13702 | status = -ERANGE; | |
13703 | goto out; | |
5a6f133e | 13704 | } |
0c651878 | 13705 | |
4f774513 | 13706 | list_for_each_entry(dmabuf, &wq->page_list, list) { |
49198b37 | 13707 | memset(dmabuf->virt, 0, hw_page_size); |
5a6f133e JS |
13708 | page[dmabuf->buffer_tag].addr_lo = putPaddrLow(dmabuf->phys); |
13709 | page[dmabuf->buffer_tag].addr_hi = putPaddrHigh(dmabuf->phys); | |
4f774513 | 13710 | } |
962bc51b JS |
13711 | |
13712 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) | |
13713 | bf_set(lpfc_mbx_wq_create_dua, &wq_create->u.request, 1); | |
13714 | ||
4f774513 JS |
13715 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
13716 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
4f774513 JS |
13717 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
13718 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
13719 | if (shdr_status || shdr_add_status || rc) { | |
13720 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
13721 | "2503 WQ_CREATE mailbox failed with " | |
13722 | "status x%x add_status x%x, mbx status x%x\n", | |
13723 | shdr_status, shdr_add_status, rc); | |
13724 | status = -ENXIO; | |
13725 | goto out; | |
13726 | } | |
13727 | wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, &wq_create->u.response); | |
13728 | if (wq->queue_id == 0xFFFF) { | |
13729 | status = -ENXIO; | |
13730 | goto out; | |
13731 | } | |
962bc51b JS |
13732 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) { |
13733 | wq->db_format = bf_get(lpfc_mbx_wq_create_db_format, | |
13734 | &wq_create->u.response); | |
13735 | if ((wq->db_format != LPFC_DB_LIST_FORMAT) && | |
13736 | (wq->db_format != LPFC_DB_RING_FORMAT)) { | |
13737 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
13738 | "3265 WQ[%d] doorbell format not " | |
13739 | "supported: x%x\n", wq->queue_id, | |
13740 | wq->db_format); | |
13741 | status = -EINVAL; | |
13742 | goto out; | |
13743 | } | |
13744 | pci_barset = bf_get(lpfc_mbx_wq_create_bar_set, | |
13745 | &wq_create->u.response); | |
13746 | bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, pci_barset); | |
13747 | if (!bar_memmap_p) { | |
13748 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
13749 | "3263 WQ[%d] failed to memmap pci " | |
13750 | "barset:x%x\n", wq->queue_id, | |
13751 | pci_barset); | |
13752 | status = -ENOMEM; | |
13753 | goto out; | |
13754 | } | |
13755 | db_offset = wq_create->u.response.doorbell_offset; | |
13756 | if ((db_offset != LPFC_ULP0_WQ_DOORBELL) && | |
13757 | (db_offset != LPFC_ULP1_WQ_DOORBELL)) { | |
13758 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
13759 | "3252 WQ[%d] doorbell offset not " | |
13760 | "supported: x%x\n", wq->queue_id, | |
13761 | db_offset); | |
13762 | status = -EINVAL; | |
13763 | goto out; | |
13764 | } | |
13765 | wq->db_regaddr = bar_memmap_p + db_offset; | |
13766 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
a22e7db3 JS |
13767 | "3264 WQ[%d]: barset:x%x, offset:x%x, " |
13768 | "format:x%x\n", wq->queue_id, pci_barset, | |
13769 | db_offset, wq->db_format); | |
962bc51b JS |
13770 | } else { |
13771 | wq->db_format = LPFC_DB_LIST_FORMAT; | |
13772 | wq->db_regaddr = phba->sli4_hba.WQDBregaddr; | |
13773 | } | |
4f774513 | 13774 | wq->type = LPFC_WQ; |
2a622bfb | 13775 | wq->assoc_qid = cq->queue_id; |
4f774513 JS |
13776 | wq->subtype = subtype; |
13777 | wq->host_index = 0; | |
13778 | wq->hba_index = 0; | |
ff78d8f9 | 13779 | wq->entry_repost = LPFC_RELEASE_NOTIFICATION_INTERVAL; |
4f774513 JS |
13780 | |
13781 | /* link the wq onto the parent cq child list */ | |
13782 | list_add_tail(&wq->list, &cq->child_list); | |
13783 | out: | |
8fa38513 | 13784 | mempool_free(mbox, phba->mbox_mem_pool); |
4f774513 JS |
13785 | return status; |
13786 | } | |
13787 | ||
73d91e50 JS |
13788 | /** |
13789 | * lpfc_rq_adjust_repost - Adjust entry_repost for an RQ | |
13790 | * @phba: HBA structure that indicates port to create a queue on. | |
13791 | * @rq: The queue structure to use for the receive queue. | |
13792 | * @qno: The associated HBQ number | |
13793 | * | |
13794 | * | |
13795 | * For SLI4 we need to adjust the RQ repost value based on | |
13796 | * the number of buffers that are initially posted to the RQ. | |
13797 | */ | |
13798 | void | |
13799 | lpfc_rq_adjust_repost(struct lpfc_hba *phba, struct lpfc_queue *rq, int qno) | |
13800 | { | |
13801 | uint32_t cnt; | |
13802 | ||
2e90f4b5 JS |
13803 | /* sanity check on queue memory */ |
13804 | if (!rq) | |
13805 | return; | |
73d91e50 JS |
13806 | cnt = lpfc_hbq_defs[qno]->entry_count; |
13807 | ||
13808 | /* Recalc repost for RQs based on buffers initially posted */ | |
13809 | cnt = (cnt >> 3); | |
13810 | if (cnt < LPFC_QUEUE_MIN_REPOST) | |
13811 | cnt = LPFC_QUEUE_MIN_REPOST; | |
13812 | ||
13813 | rq->entry_repost = cnt; | |
13814 | } | |
13815 | ||
4f774513 JS |
13816 | /** |
13817 | * lpfc_rq_create - Create a Receive Queue on the HBA | |
13818 | * @phba: HBA structure that indicates port to create a queue on. | |
13819 | * @hrq: The queue structure to use to create the header receive queue. | |
13820 | * @drq: The queue structure to use to create the data receive queue. | |
13821 | * @cq: The completion queue to bind this work queue to. | |
13822 | * | |
13823 | * This function creates a receive buffer queue pair , as detailed in @hrq and | |
13824 | * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command | |
13825 | * to the HBA. | |
13826 | * | |
13827 | * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq | |
13828 | * struct is used to get the entry count that is necessary to determine the | |
13829 | * number of pages to use for this queue. The @cq is used to indicate which | |
13830 | * completion queue to bind received buffers that are posted to these queues to. | |
13831 | * This function will send the RQ_CREATE mailbox command to the HBA to setup the | |
13832 | * receive queue pair. This function is asynchronous and will wait for the | |
13833 | * mailbox command to finish before continuing. | |
13834 | * | |
13835 | * On success this function will return a zero. If unable to allocate enough | |
d439d286 JS |
13836 | * memory this function will return -ENOMEM. If the queue create mailbox command |
13837 | * fails this function will return -ENXIO. | |
4f774513 | 13838 | **/ |
a2fc4aef | 13839 | int |
4f774513 JS |
13840 | lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq, |
13841 | struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype) | |
13842 | { | |
13843 | struct lpfc_mbx_rq_create *rq_create; | |
13844 | struct lpfc_dmabuf *dmabuf; | |
13845 | LPFC_MBOXQ_t *mbox; | |
13846 | int rc, length, status = 0; | |
13847 | uint32_t shdr_status, shdr_add_status; | |
13848 | union lpfc_sli4_cfg_shdr *shdr; | |
49198b37 | 13849 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
962bc51b JS |
13850 | void __iomem *bar_memmap_p; |
13851 | uint32_t db_offset; | |
13852 | uint16_t pci_barset; | |
49198b37 | 13853 | |
2e90f4b5 JS |
13854 | /* sanity check on queue memory */ |
13855 | if (!hrq || !drq || !cq) | |
13856 | return -ENODEV; | |
49198b37 JS |
13857 | if (!phba->sli4_hba.pc_sli4_params.supported) |
13858 | hw_page_size = SLI4_PAGE_SIZE; | |
4f774513 JS |
13859 | |
13860 | if (hrq->entry_count != drq->entry_count) | |
13861 | return -EINVAL; | |
13862 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
13863 | if (!mbox) | |
13864 | return -ENOMEM; | |
13865 | length = (sizeof(struct lpfc_mbx_rq_create) - | |
13866 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
13867 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
13868 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, | |
13869 | length, LPFC_SLI4_MBX_EMBED); | |
13870 | rq_create = &mbox->u.mqe.un.rq_create; | |
5a6f133e JS |
13871 | shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr; |
13872 | bf_set(lpfc_mbox_hdr_version, &shdr->request, | |
13873 | phba->sli4_hba.pc_sli4_params.rqv); | |
13874 | if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) { | |
13875 | bf_set(lpfc_rq_context_rqe_count_1, | |
13876 | &rq_create->u.request.context, | |
13877 | hrq->entry_count); | |
13878 | rq_create->u.request.context.buffer_size = LPFC_HDR_BUF_SIZE; | |
c31098ce JS |
13879 | bf_set(lpfc_rq_context_rqe_size, |
13880 | &rq_create->u.request.context, | |
13881 | LPFC_RQE_SIZE_8); | |
13882 | bf_set(lpfc_rq_context_page_size, | |
13883 | &rq_create->u.request.context, | |
13884 | (PAGE_SIZE/SLI4_PAGE_SIZE)); | |
5a6f133e JS |
13885 | } else { |
13886 | switch (hrq->entry_count) { | |
13887 | default: | |
13888 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
13889 | "2535 Unsupported RQ count. (%d)\n", | |
13890 | hrq->entry_count); | |
4f4c1863 JS |
13891 | if (hrq->entry_count < 512) { |
13892 | status = -EINVAL; | |
13893 | goto out; | |
13894 | } | |
5a6f133e JS |
13895 | /* otherwise default to smallest count (drop through) */ |
13896 | case 512: | |
13897 | bf_set(lpfc_rq_context_rqe_count, | |
13898 | &rq_create->u.request.context, | |
13899 | LPFC_RQ_RING_SIZE_512); | |
13900 | break; | |
13901 | case 1024: | |
13902 | bf_set(lpfc_rq_context_rqe_count, | |
13903 | &rq_create->u.request.context, | |
13904 | LPFC_RQ_RING_SIZE_1024); | |
13905 | break; | |
13906 | case 2048: | |
13907 | bf_set(lpfc_rq_context_rqe_count, | |
13908 | &rq_create->u.request.context, | |
13909 | LPFC_RQ_RING_SIZE_2048); | |
13910 | break; | |
13911 | case 4096: | |
13912 | bf_set(lpfc_rq_context_rqe_count, | |
13913 | &rq_create->u.request.context, | |
13914 | LPFC_RQ_RING_SIZE_4096); | |
13915 | break; | |
13916 | } | |
13917 | bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context, | |
13918 | LPFC_HDR_BUF_SIZE); | |
4f774513 JS |
13919 | } |
13920 | bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context, | |
13921 | cq->queue_id); | |
13922 | bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request, | |
13923 | hrq->page_count); | |
4f774513 | 13924 | list_for_each_entry(dmabuf, &hrq->page_list, list) { |
49198b37 | 13925 | memset(dmabuf->virt, 0, hw_page_size); |
4f774513 JS |
13926 | rq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
13927 | putPaddrLow(dmabuf->phys); | |
13928 | rq_create->u.request.page[dmabuf->buffer_tag].addr_hi = | |
13929 | putPaddrHigh(dmabuf->phys); | |
13930 | } | |
962bc51b JS |
13931 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) |
13932 | bf_set(lpfc_mbx_rq_create_dua, &rq_create->u.request, 1); | |
13933 | ||
4f774513 JS |
13934 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
13935 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
4f774513 JS |
13936 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
13937 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
13938 | if (shdr_status || shdr_add_status || rc) { | |
13939 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
13940 | "2504 RQ_CREATE mailbox failed with " | |
13941 | "status x%x add_status x%x, mbx status x%x\n", | |
13942 | shdr_status, shdr_add_status, rc); | |
13943 | status = -ENXIO; | |
13944 | goto out; | |
13945 | } | |
13946 | hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); | |
13947 | if (hrq->queue_id == 0xFFFF) { | |
13948 | status = -ENXIO; | |
13949 | goto out; | |
13950 | } | |
962bc51b JS |
13951 | |
13952 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) { | |
13953 | hrq->db_format = bf_get(lpfc_mbx_rq_create_db_format, | |
13954 | &rq_create->u.response); | |
13955 | if ((hrq->db_format != LPFC_DB_LIST_FORMAT) && | |
13956 | (hrq->db_format != LPFC_DB_RING_FORMAT)) { | |
13957 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
13958 | "3262 RQ [%d] doorbell format not " | |
13959 | "supported: x%x\n", hrq->queue_id, | |
13960 | hrq->db_format); | |
13961 | status = -EINVAL; | |
13962 | goto out; | |
13963 | } | |
13964 | ||
13965 | pci_barset = bf_get(lpfc_mbx_rq_create_bar_set, | |
13966 | &rq_create->u.response); | |
13967 | bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, pci_barset); | |
13968 | if (!bar_memmap_p) { | |
13969 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
13970 | "3269 RQ[%d] failed to memmap pci " | |
13971 | "barset:x%x\n", hrq->queue_id, | |
13972 | pci_barset); | |
13973 | status = -ENOMEM; | |
13974 | goto out; | |
13975 | } | |
13976 | ||
13977 | db_offset = rq_create->u.response.doorbell_offset; | |
13978 | if ((db_offset != LPFC_ULP0_RQ_DOORBELL) && | |
13979 | (db_offset != LPFC_ULP1_RQ_DOORBELL)) { | |
13980 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
13981 | "3270 RQ[%d] doorbell offset not " | |
13982 | "supported: x%x\n", hrq->queue_id, | |
13983 | db_offset); | |
13984 | status = -EINVAL; | |
13985 | goto out; | |
13986 | } | |
13987 | hrq->db_regaddr = bar_memmap_p + db_offset; | |
13988 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
a22e7db3 JS |
13989 | "3266 RQ[qid:%d]: barset:x%x, offset:x%x, " |
13990 | "format:x%x\n", hrq->queue_id, pci_barset, | |
13991 | db_offset, hrq->db_format); | |
962bc51b JS |
13992 | } else { |
13993 | hrq->db_format = LPFC_DB_RING_FORMAT; | |
13994 | hrq->db_regaddr = phba->sli4_hba.RQDBregaddr; | |
13995 | } | |
4f774513 | 13996 | hrq->type = LPFC_HRQ; |
2a622bfb | 13997 | hrq->assoc_qid = cq->queue_id; |
4f774513 JS |
13998 | hrq->subtype = subtype; |
13999 | hrq->host_index = 0; | |
14000 | hrq->hba_index = 0; | |
14001 | ||
14002 | /* now create the data queue */ | |
14003 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
14004 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, | |
14005 | length, LPFC_SLI4_MBX_EMBED); | |
5a6f133e JS |
14006 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
14007 | phba->sli4_hba.pc_sli4_params.rqv); | |
14008 | if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) { | |
14009 | bf_set(lpfc_rq_context_rqe_count_1, | |
c31098ce | 14010 | &rq_create->u.request.context, hrq->entry_count); |
5a6f133e | 14011 | rq_create->u.request.context.buffer_size = LPFC_DATA_BUF_SIZE; |
c31098ce JS |
14012 | bf_set(lpfc_rq_context_rqe_size, &rq_create->u.request.context, |
14013 | LPFC_RQE_SIZE_8); | |
14014 | bf_set(lpfc_rq_context_page_size, &rq_create->u.request.context, | |
14015 | (PAGE_SIZE/SLI4_PAGE_SIZE)); | |
5a6f133e JS |
14016 | } else { |
14017 | switch (drq->entry_count) { | |
14018 | default: | |
14019 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
14020 | "2536 Unsupported RQ count. (%d)\n", | |
14021 | drq->entry_count); | |
4f4c1863 JS |
14022 | if (drq->entry_count < 512) { |
14023 | status = -EINVAL; | |
14024 | goto out; | |
14025 | } | |
5a6f133e JS |
14026 | /* otherwise default to smallest count (drop through) */ |
14027 | case 512: | |
14028 | bf_set(lpfc_rq_context_rqe_count, | |
14029 | &rq_create->u.request.context, | |
14030 | LPFC_RQ_RING_SIZE_512); | |
14031 | break; | |
14032 | case 1024: | |
14033 | bf_set(lpfc_rq_context_rqe_count, | |
14034 | &rq_create->u.request.context, | |
14035 | LPFC_RQ_RING_SIZE_1024); | |
14036 | break; | |
14037 | case 2048: | |
14038 | bf_set(lpfc_rq_context_rqe_count, | |
14039 | &rq_create->u.request.context, | |
14040 | LPFC_RQ_RING_SIZE_2048); | |
14041 | break; | |
14042 | case 4096: | |
14043 | bf_set(lpfc_rq_context_rqe_count, | |
14044 | &rq_create->u.request.context, | |
14045 | LPFC_RQ_RING_SIZE_4096); | |
14046 | break; | |
14047 | } | |
14048 | bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context, | |
14049 | LPFC_DATA_BUF_SIZE); | |
4f774513 JS |
14050 | } |
14051 | bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context, | |
14052 | cq->queue_id); | |
14053 | bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request, | |
14054 | drq->page_count); | |
4f774513 JS |
14055 | list_for_each_entry(dmabuf, &drq->page_list, list) { |
14056 | rq_create->u.request.page[dmabuf->buffer_tag].addr_lo = | |
14057 | putPaddrLow(dmabuf->phys); | |
14058 | rq_create->u.request.page[dmabuf->buffer_tag].addr_hi = | |
14059 | putPaddrHigh(dmabuf->phys); | |
14060 | } | |
962bc51b JS |
14061 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) |
14062 | bf_set(lpfc_mbx_rq_create_dua, &rq_create->u.request, 1); | |
4f774513 JS |
14063 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
14064 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
14065 | shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr; | |
14066 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
14067 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
14068 | if (shdr_status || shdr_add_status || rc) { | |
14069 | status = -ENXIO; | |
14070 | goto out; | |
14071 | } | |
14072 | drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); | |
14073 | if (drq->queue_id == 0xFFFF) { | |
14074 | status = -ENXIO; | |
14075 | goto out; | |
14076 | } | |
14077 | drq->type = LPFC_DRQ; | |
2a622bfb | 14078 | drq->assoc_qid = cq->queue_id; |
4f774513 JS |
14079 | drq->subtype = subtype; |
14080 | drq->host_index = 0; | |
14081 | drq->hba_index = 0; | |
14082 | ||
14083 | /* link the header and data RQs onto the parent cq child list */ | |
14084 | list_add_tail(&hrq->list, &cq->child_list); | |
14085 | list_add_tail(&drq->list, &cq->child_list); | |
14086 | ||
14087 | out: | |
8fa38513 | 14088 | mempool_free(mbox, phba->mbox_mem_pool); |
4f774513 JS |
14089 | return status; |
14090 | } | |
14091 | ||
14092 | /** | |
14093 | * lpfc_eq_destroy - Destroy an event Queue on the HBA | |
14094 | * @eq: The queue structure associated with the queue to destroy. | |
14095 | * | |
14096 | * This function destroys a queue, as detailed in @eq by sending an mailbox | |
14097 | * command, specific to the type of queue, to the HBA. | |
14098 | * | |
14099 | * The @eq struct is used to get the queue ID of the queue to destroy. | |
14100 | * | |
14101 | * On success this function will return a zero. If the queue destroy mailbox | |
d439d286 | 14102 | * command fails this function will return -ENXIO. |
4f774513 | 14103 | **/ |
a2fc4aef | 14104 | int |
4f774513 JS |
14105 | lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq) |
14106 | { | |
14107 | LPFC_MBOXQ_t *mbox; | |
14108 | int rc, length, status = 0; | |
14109 | uint32_t shdr_status, shdr_add_status; | |
14110 | union lpfc_sli4_cfg_shdr *shdr; | |
14111 | ||
2e90f4b5 | 14112 | /* sanity check on queue memory */ |
4f774513 JS |
14113 | if (!eq) |
14114 | return -ENODEV; | |
14115 | mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL); | |
14116 | if (!mbox) | |
14117 | return -ENOMEM; | |
14118 | length = (sizeof(struct lpfc_mbx_eq_destroy) - | |
14119 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
14120 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
14121 | LPFC_MBOX_OPCODE_EQ_DESTROY, | |
14122 | length, LPFC_SLI4_MBX_EMBED); | |
14123 | bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request, | |
14124 | eq->queue_id); | |
14125 | mbox->vport = eq->phba->pport; | |
14126 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
14127 | ||
14128 | rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL); | |
14129 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
14130 | shdr = (union lpfc_sli4_cfg_shdr *) | |
14131 | &mbox->u.mqe.un.eq_destroy.header.cfg_shdr; | |
14132 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
14133 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
14134 | if (shdr_status || shdr_add_status || rc) { | |
14135 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
14136 | "2505 EQ_DESTROY mailbox failed with " | |
14137 | "status x%x add_status x%x, mbx status x%x\n", | |
14138 | shdr_status, shdr_add_status, rc); | |
14139 | status = -ENXIO; | |
14140 | } | |
14141 | ||
14142 | /* Remove eq from any list */ | |
14143 | list_del_init(&eq->list); | |
8fa38513 | 14144 | mempool_free(mbox, eq->phba->mbox_mem_pool); |
4f774513 JS |
14145 | return status; |
14146 | } | |
14147 | ||
14148 | /** | |
14149 | * lpfc_cq_destroy - Destroy a Completion Queue on the HBA | |
14150 | * @cq: The queue structure associated with the queue to destroy. | |
14151 | * | |
14152 | * This function destroys a queue, as detailed in @cq by sending an mailbox | |
14153 | * command, specific to the type of queue, to the HBA. | |
14154 | * | |
14155 | * The @cq struct is used to get the queue ID of the queue to destroy. | |
14156 | * | |
14157 | * On success this function will return a zero. If the queue destroy mailbox | |
d439d286 | 14158 | * command fails this function will return -ENXIO. |
4f774513 | 14159 | **/ |
a2fc4aef | 14160 | int |
4f774513 JS |
14161 | lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq) |
14162 | { | |
14163 | LPFC_MBOXQ_t *mbox; | |
14164 | int rc, length, status = 0; | |
14165 | uint32_t shdr_status, shdr_add_status; | |
14166 | union lpfc_sli4_cfg_shdr *shdr; | |
14167 | ||
2e90f4b5 | 14168 | /* sanity check on queue memory */ |
4f774513 JS |
14169 | if (!cq) |
14170 | return -ENODEV; | |
14171 | mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL); | |
14172 | if (!mbox) | |
14173 | return -ENOMEM; | |
14174 | length = (sizeof(struct lpfc_mbx_cq_destroy) - | |
14175 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
14176 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
14177 | LPFC_MBOX_OPCODE_CQ_DESTROY, | |
14178 | length, LPFC_SLI4_MBX_EMBED); | |
14179 | bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request, | |
14180 | cq->queue_id); | |
14181 | mbox->vport = cq->phba->pport; | |
14182 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
14183 | rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL); | |
14184 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
14185 | shdr = (union lpfc_sli4_cfg_shdr *) | |
14186 | &mbox->u.mqe.un.wq_create.header.cfg_shdr; | |
14187 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
14188 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
14189 | if (shdr_status || shdr_add_status || rc) { | |
14190 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
14191 | "2506 CQ_DESTROY mailbox failed with " | |
14192 | "status x%x add_status x%x, mbx status x%x\n", | |
14193 | shdr_status, shdr_add_status, rc); | |
14194 | status = -ENXIO; | |
14195 | } | |
14196 | /* Remove cq from any list */ | |
14197 | list_del_init(&cq->list); | |
8fa38513 | 14198 | mempool_free(mbox, cq->phba->mbox_mem_pool); |
4f774513 JS |
14199 | return status; |
14200 | } | |
14201 | ||
04c68496 JS |
14202 | /** |
14203 | * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA | |
14204 | * @qm: The queue structure associated with the queue to destroy. | |
14205 | * | |
14206 | * This function destroys a queue, as detailed in @mq by sending an mailbox | |
14207 | * command, specific to the type of queue, to the HBA. | |
14208 | * | |
14209 | * The @mq struct is used to get the queue ID of the queue to destroy. | |
14210 | * | |
14211 | * On success this function will return a zero. If the queue destroy mailbox | |
d439d286 | 14212 | * command fails this function will return -ENXIO. |
04c68496 | 14213 | **/ |
a2fc4aef | 14214 | int |
04c68496 JS |
14215 | lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq) |
14216 | { | |
14217 | LPFC_MBOXQ_t *mbox; | |
14218 | int rc, length, status = 0; | |
14219 | uint32_t shdr_status, shdr_add_status; | |
14220 | union lpfc_sli4_cfg_shdr *shdr; | |
14221 | ||
2e90f4b5 | 14222 | /* sanity check on queue memory */ |
04c68496 JS |
14223 | if (!mq) |
14224 | return -ENODEV; | |
14225 | mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL); | |
14226 | if (!mbox) | |
14227 | return -ENOMEM; | |
14228 | length = (sizeof(struct lpfc_mbx_mq_destroy) - | |
14229 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
14230 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
14231 | LPFC_MBOX_OPCODE_MQ_DESTROY, | |
14232 | length, LPFC_SLI4_MBX_EMBED); | |
14233 | bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request, | |
14234 | mq->queue_id); | |
14235 | mbox->vport = mq->phba->pport; | |
14236 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
14237 | rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL); | |
14238 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
14239 | shdr = (union lpfc_sli4_cfg_shdr *) | |
14240 | &mbox->u.mqe.un.mq_destroy.header.cfg_shdr; | |
14241 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
14242 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
14243 | if (shdr_status || shdr_add_status || rc) { | |
14244 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
14245 | "2507 MQ_DESTROY mailbox failed with " | |
14246 | "status x%x add_status x%x, mbx status x%x\n", | |
14247 | shdr_status, shdr_add_status, rc); | |
14248 | status = -ENXIO; | |
14249 | } | |
14250 | /* Remove mq from any list */ | |
14251 | list_del_init(&mq->list); | |
8fa38513 | 14252 | mempool_free(mbox, mq->phba->mbox_mem_pool); |
04c68496 JS |
14253 | return status; |
14254 | } | |
14255 | ||
4f774513 JS |
14256 | /** |
14257 | * lpfc_wq_destroy - Destroy a Work Queue on the HBA | |
14258 | * @wq: The queue structure associated with the queue to destroy. | |
14259 | * | |
14260 | * This function destroys a queue, as detailed in @wq by sending an mailbox | |
14261 | * command, specific to the type of queue, to the HBA. | |
14262 | * | |
14263 | * The @wq struct is used to get the queue ID of the queue to destroy. | |
14264 | * | |
14265 | * On success this function will return a zero. If the queue destroy mailbox | |
d439d286 | 14266 | * command fails this function will return -ENXIO. |
4f774513 | 14267 | **/ |
a2fc4aef | 14268 | int |
4f774513 JS |
14269 | lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq) |
14270 | { | |
14271 | LPFC_MBOXQ_t *mbox; | |
14272 | int rc, length, status = 0; | |
14273 | uint32_t shdr_status, shdr_add_status; | |
14274 | union lpfc_sli4_cfg_shdr *shdr; | |
14275 | ||
2e90f4b5 | 14276 | /* sanity check on queue memory */ |
4f774513 JS |
14277 | if (!wq) |
14278 | return -ENODEV; | |
14279 | mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL); | |
14280 | if (!mbox) | |
14281 | return -ENOMEM; | |
14282 | length = (sizeof(struct lpfc_mbx_wq_destroy) - | |
14283 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
14284 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
14285 | LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY, | |
14286 | length, LPFC_SLI4_MBX_EMBED); | |
14287 | bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request, | |
14288 | wq->queue_id); | |
14289 | mbox->vport = wq->phba->pport; | |
14290 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
14291 | rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL); | |
14292 | shdr = (union lpfc_sli4_cfg_shdr *) | |
14293 | &mbox->u.mqe.un.wq_destroy.header.cfg_shdr; | |
14294 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
14295 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
14296 | if (shdr_status || shdr_add_status || rc) { | |
14297 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
14298 | "2508 WQ_DESTROY mailbox failed with " | |
14299 | "status x%x add_status x%x, mbx status x%x\n", | |
14300 | shdr_status, shdr_add_status, rc); | |
14301 | status = -ENXIO; | |
14302 | } | |
14303 | /* Remove wq from any list */ | |
14304 | list_del_init(&wq->list); | |
8fa38513 | 14305 | mempool_free(mbox, wq->phba->mbox_mem_pool); |
4f774513 JS |
14306 | return status; |
14307 | } | |
14308 | ||
14309 | /** | |
14310 | * lpfc_rq_destroy - Destroy a Receive Queue on the HBA | |
14311 | * @rq: The queue structure associated with the queue to destroy. | |
14312 | * | |
14313 | * This function destroys a queue, as detailed in @rq by sending an mailbox | |
14314 | * command, specific to the type of queue, to the HBA. | |
14315 | * | |
14316 | * The @rq struct is used to get the queue ID of the queue to destroy. | |
14317 | * | |
14318 | * On success this function will return a zero. If the queue destroy mailbox | |
d439d286 | 14319 | * command fails this function will return -ENXIO. |
4f774513 | 14320 | **/ |
a2fc4aef | 14321 | int |
4f774513 JS |
14322 | lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq, |
14323 | struct lpfc_queue *drq) | |
14324 | { | |
14325 | LPFC_MBOXQ_t *mbox; | |
14326 | int rc, length, status = 0; | |
14327 | uint32_t shdr_status, shdr_add_status; | |
14328 | union lpfc_sli4_cfg_shdr *shdr; | |
14329 | ||
2e90f4b5 | 14330 | /* sanity check on queue memory */ |
4f774513 JS |
14331 | if (!hrq || !drq) |
14332 | return -ENODEV; | |
14333 | mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL); | |
14334 | if (!mbox) | |
14335 | return -ENOMEM; | |
14336 | length = (sizeof(struct lpfc_mbx_rq_destroy) - | |
fedd3b7b | 14337 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
4f774513 JS |
14338 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
14339 | LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY, | |
14340 | length, LPFC_SLI4_MBX_EMBED); | |
14341 | bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request, | |
14342 | hrq->queue_id); | |
14343 | mbox->vport = hrq->phba->pport; | |
14344 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
14345 | rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL); | |
14346 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
14347 | shdr = (union lpfc_sli4_cfg_shdr *) | |
14348 | &mbox->u.mqe.un.rq_destroy.header.cfg_shdr; | |
14349 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
14350 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
14351 | if (shdr_status || shdr_add_status || rc) { | |
14352 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
14353 | "2509 RQ_DESTROY mailbox failed with " | |
14354 | "status x%x add_status x%x, mbx status x%x\n", | |
14355 | shdr_status, shdr_add_status, rc); | |
14356 | if (rc != MBX_TIMEOUT) | |
14357 | mempool_free(mbox, hrq->phba->mbox_mem_pool); | |
14358 | return -ENXIO; | |
14359 | } | |
14360 | bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request, | |
14361 | drq->queue_id); | |
14362 | rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL); | |
14363 | shdr = (union lpfc_sli4_cfg_shdr *) | |
14364 | &mbox->u.mqe.un.rq_destroy.header.cfg_shdr; | |
14365 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
14366 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
14367 | if (shdr_status || shdr_add_status || rc) { | |
14368 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
14369 | "2510 RQ_DESTROY mailbox failed with " | |
14370 | "status x%x add_status x%x, mbx status x%x\n", | |
14371 | shdr_status, shdr_add_status, rc); | |
14372 | status = -ENXIO; | |
14373 | } | |
14374 | list_del_init(&hrq->list); | |
14375 | list_del_init(&drq->list); | |
8fa38513 | 14376 | mempool_free(mbox, hrq->phba->mbox_mem_pool); |
4f774513 JS |
14377 | return status; |
14378 | } | |
14379 | ||
14380 | /** | |
14381 | * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA | |
14382 | * @phba: The virtual port for which this call being executed. | |
14383 | * @pdma_phys_addr0: Physical address of the 1st SGL page. | |
14384 | * @pdma_phys_addr1: Physical address of the 2nd SGL page. | |
14385 | * @xritag: the xritag that ties this io to the SGL pages. | |
14386 | * | |
14387 | * This routine will post the sgl pages for the IO that has the xritag | |
14388 | * that is in the iocbq structure. The xritag is assigned during iocbq | |
14389 | * creation and persists for as long as the driver is loaded. | |
14390 | * if the caller has fewer than 256 scatter gather segments to map then | |
14391 | * pdma_phys_addr1 should be 0. | |
14392 | * If the caller needs to map more than 256 scatter gather segment then | |
14393 | * pdma_phys_addr1 should be a valid physical address. | |
14394 | * physical address for SGLs must be 64 byte aligned. | |
14395 | * If you are going to map 2 SGL's then the first one must have 256 entries | |
14396 | * the second sgl can have between 1 and 256 entries. | |
14397 | * | |
14398 | * Return codes: | |
14399 | * 0 - Success | |
14400 | * -ENXIO, -ENOMEM - Failure | |
14401 | **/ | |
14402 | int | |
14403 | lpfc_sli4_post_sgl(struct lpfc_hba *phba, | |
14404 | dma_addr_t pdma_phys_addr0, | |
14405 | dma_addr_t pdma_phys_addr1, | |
14406 | uint16_t xritag) | |
14407 | { | |
14408 | struct lpfc_mbx_post_sgl_pages *post_sgl_pages; | |
14409 | LPFC_MBOXQ_t *mbox; | |
14410 | int rc; | |
14411 | uint32_t shdr_status, shdr_add_status; | |
6d368e53 | 14412 | uint32_t mbox_tmo; |
4f774513 JS |
14413 | union lpfc_sli4_cfg_shdr *shdr; |
14414 | ||
14415 | if (xritag == NO_XRI) { | |
14416 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
14417 | "0364 Invalid param:\n"); | |
14418 | return -EINVAL; | |
14419 | } | |
14420 | ||
14421 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
14422 | if (!mbox) | |
14423 | return -ENOMEM; | |
14424 | ||
14425 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
14426 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, | |
14427 | sizeof(struct lpfc_mbx_post_sgl_pages) - | |
fedd3b7b | 14428 | sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED); |
4f774513 JS |
14429 | |
14430 | post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *) | |
14431 | &mbox->u.mqe.un.post_sgl_pages; | |
14432 | bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag); | |
14433 | bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1); | |
14434 | ||
14435 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo = | |
14436 | cpu_to_le32(putPaddrLow(pdma_phys_addr0)); | |
14437 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi = | |
14438 | cpu_to_le32(putPaddrHigh(pdma_phys_addr0)); | |
14439 | ||
14440 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo = | |
14441 | cpu_to_le32(putPaddrLow(pdma_phys_addr1)); | |
14442 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi = | |
14443 | cpu_to_le32(putPaddrHigh(pdma_phys_addr1)); | |
14444 | if (!phba->sli4_hba.intr_enable) | |
14445 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
6d368e53 | 14446 | else { |
a183a15f | 14447 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
6d368e53 JS |
14448 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
14449 | } | |
4f774513 JS |
14450 | /* The IOCTL status is embedded in the mailbox subheader. */ |
14451 | shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr; | |
14452 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
14453 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
14454 | if (rc != MBX_TIMEOUT) | |
14455 | mempool_free(mbox, phba->mbox_mem_pool); | |
14456 | if (shdr_status || shdr_add_status || rc) { | |
14457 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
14458 | "2511 POST_SGL mailbox failed with " | |
14459 | "status x%x add_status x%x, mbx status x%x\n", | |
14460 | shdr_status, shdr_add_status, rc); | |
4f774513 JS |
14461 | } |
14462 | return 0; | |
14463 | } | |
4f774513 | 14464 | |
6d368e53 | 14465 | /** |
88a2cfbb | 14466 | * lpfc_sli4_alloc_xri - Get an available rpi in the device's range |
6d368e53 JS |
14467 | * @phba: pointer to lpfc hba data structure. |
14468 | * | |
14469 | * This routine is invoked to post rpi header templates to the | |
88a2cfbb JS |
14470 | * HBA consistent with the SLI-4 interface spec. This routine |
14471 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to | |
14472 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. | |
6d368e53 | 14473 | * |
88a2cfbb JS |
14474 | * Returns |
14475 | * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful | |
14476 | * LPFC_RPI_ALLOC_ERROR if no rpis are available. | |
14477 | **/ | |
5d8b8167 | 14478 | static uint16_t |
6d368e53 JS |
14479 | lpfc_sli4_alloc_xri(struct lpfc_hba *phba) |
14480 | { | |
14481 | unsigned long xri; | |
14482 | ||
14483 | /* | |
14484 | * Fetch the next logical xri. Because this index is logical, | |
14485 | * the driver starts at 0 each time. | |
14486 | */ | |
14487 | spin_lock_irq(&phba->hbalock); | |
14488 | xri = find_next_zero_bit(phba->sli4_hba.xri_bmask, | |
14489 | phba->sli4_hba.max_cfg_param.max_xri, 0); | |
14490 | if (xri >= phba->sli4_hba.max_cfg_param.max_xri) { | |
14491 | spin_unlock_irq(&phba->hbalock); | |
14492 | return NO_XRI; | |
14493 | } else { | |
14494 | set_bit(xri, phba->sli4_hba.xri_bmask); | |
14495 | phba->sli4_hba.max_cfg_param.xri_used++; | |
6d368e53 | 14496 | } |
6d368e53 JS |
14497 | spin_unlock_irq(&phba->hbalock); |
14498 | return xri; | |
14499 | } | |
14500 | ||
14501 | /** | |
14502 | * lpfc_sli4_free_xri - Release an xri for reuse. | |
14503 | * @phba: pointer to lpfc hba data structure. | |
14504 | * | |
14505 | * This routine is invoked to release an xri to the pool of | |
14506 | * available rpis maintained by the driver. | |
14507 | **/ | |
5d8b8167 | 14508 | static void |
6d368e53 JS |
14509 | __lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri) |
14510 | { | |
14511 | if (test_and_clear_bit(xri, phba->sli4_hba.xri_bmask)) { | |
6d368e53 JS |
14512 | phba->sli4_hba.max_cfg_param.xri_used--; |
14513 | } | |
14514 | } | |
14515 | ||
14516 | /** | |
14517 | * lpfc_sli4_free_xri - Release an xri for reuse. | |
14518 | * @phba: pointer to lpfc hba data structure. | |
14519 | * | |
14520 | * This routine is invoked to release an xri to the pool of | |
14521 | * available rpis maintained by the driver. | |
14522 | **/ | |
14523 | void | |
14524 | lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri) | |
14525 | { | |
14526 | spin_lock_irq(&phba->hbalock); | |
14527 | __lpfc_sli4_free_xri(phba, xri); | |
14528 | spin_unlock_irq(&phba->hbalock); | |
14529 | } | |
14530 | ||
4f774513 JS |
14531 | /** |
14532 | * lpfc_sli4_next_xritag - Get an xritag for the io | |
14533 | * @phba: Pointer to HBA context object. | |
14534 | * | |
14535 | * This function gets an xritag for the iocb. If there is no unused xritag | |
14536 | * it will return 0xffff. | |
14537 | * The function returns the allocated xritag if successful, else returns zero. | |
14538 | * Zero is not a valid xritag. | |
14539 | * The caller is not required to hold any lock. | |
14540 | **/ | |
14541 | uint16_t | |
14542 | lpfc_sli4_next_xritag(struct lpfc_hba *phba) | |
14543 | { | |
6d368e53 | 14544 | uint16_t xri_index; |
4f774513 | 14545 | |
6d368e53 | 14546 | xri_index = lpfc_sli4_alloc_xri(phba); |
81378052 JS |
14547 | if (xri_index == NO_XRI) |
14548 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
14549 | "2004 Failed to allocate XRI.last XRITAG is %d" | |
14550 | " Max XRI is %d, Used XRI is %d\n", | |
14551 | xri_index, | |
14552 | phba->sli4_hba.max_cfg_param.max_xri, | |
14553 | phba->sli4_hba.max_cfg_param.xri_used); | |
14554 | return xri_index; | |
4f774513 JS |
14555 | } |
14556 | ||
14557 | /** | |
6d368e53 | 14558 | * lpfc_sli4_post_els_sgl_list - post a block of ELS sgls to the port. |
4f774513 | 14559 | * @phba: pointer to lpfc hba data structure. |
8a9d2e80 JS |
14560 | * @post_sgl_list: pointer to els sgl entry list. |
14561 | * @count: number of els sgl entries on the list. | |
4f774513 JS |
14562 | * |
14563 | * This routine is invoked to post a block of driver's sgl pages to the | |
14564 | * HBA using non-embedded mailbox command. No Lock is held. This routine | |
14565 | * is only called when the driver is loading and after all IO has been | |
14566 | * stopped. | |
14567 | **/ | |
8a9d2e80 JS |
14568 | static int |
14569 | lpfc_sli4_post_els_sgl_list(struct lpfc_hba *phba, | |
14570 | struct list_head *post_sgl_list, | |
14571 | int post_cnt) | |
4f774513 | 14572 | { |
8a9d2e80 | 14573 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
4f774513 JS |
14574 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; |
14575 | struct sgl_page_pairs *sgl_pg_pairs; | |
14576 | void *viraddr; | |
14577 | LPFC_MBOXQ_t *mbox; | |
14578 | uint32_t reqlen, alloclen, pg_pairs; | |
14579 | uint32_t mbox_tmo; | |
8a9d2e80 JS |
14580 | uint16_t xritag_start = 0; |
14581 | int rc = 0; | |
4f774513 JS |
14582 | uint32_t shdr_status, shdr_add_status; |
14583 | union lpfc_sli4_cfg_shdr *shdr; | |
14584 | ||
8a9d2e80 | 14585 | reqlen = phba->sli4_hba.els_xri_cnt * sizeof(struct sgl_page_pairs) + |
4f774513 | 14586 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); |
49198b37 | 14587 | if (reqlen > SLI4_PAGE_SIZE) { |
4f774513 JS |
14588 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
14589 | "2559 Block sgl registration required DMA " | |
14590 | "size (%d) great than a page\n", reqlen); | |
14591 | return -ENOMEM; | |
14592 | } | |
14593 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
6d368e53 | 14594 | if (!mbox) |
4f774513 | 14595 | return -ENOMEM; |
4f774513 JS |
14596 | |
14597 | /* Allocate DMA memory and set up the non-embedded mailbox command */ | |
14598 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
14599 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen, | |
14600 | LPFC_SLI4_MBX_NEMBED); | |
14601 | ||
14602 | if (alloclen < reqlen) { | |
14603 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
14604 | "0285 Allocated DMA memory size (%d) is " | |
14605 | "less than the requested DMA memory " | |
14606 | "size (%d)\n", alloclen, reqlen); | |
14607 | lpfc_sli4_mbox_cmd_free(phba, mbox); | |
14608 | return -ENOMEM; | |
14609 | } | |
4f774513 | 14610 | /* Set up the SGL pages in the non-embedded DMA pages */ |
6d368e53 | 14611 | viraddr = mbox->sge_array->addr[0]; |
4f774513 JS |
14612 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; |
14613 | sgl_pg_pairs = &sgl->sgl_pg_pairs; | |
14614 | ||
8a9d2e80 JS |
14615 | pg_pairs = 0; |
14616 | list_for_each_entry_safe(sglq_entry, sglq_next, post_sgl_list, list) { | |
4f774513 JS |
14617 | /* Set up the sge entry */ |
14618 | sgl_pg_pairs->sgl_pg0_addr_lo = | |
14619 | cpu_to_le32(putPaddrLow(sglq_entry->phys)); | |
14620 | sgl_pg_pairs->sgl_pg0_addr_hi = | |
14621 | cpu_to_le32(putPaddrHigh(sglq_entry->phys)); | |
14622 | sgl_pg_pairs->sgl_pg1_addr_lo = | |
14623 | cpu_to_le32(putPaddrLow(0)); | |
14624 | sgl_pg_pairs->sgl_pg1_addr_hi = | |
14625 | cpu_to_le32(putPaddrHigh(0)); | |
6d368e53 | 14626 | |
4f774513 JS |
14627 | /* Keep the first xritag on the list */ |
14628 | if (pg_pairs == 0) | |
14629 | xritag_start = sglq_entry->sli4_xritag; | |
14630 | sgl_pg_pairs++; | |
8a9d2e80 | 14631 | pg_pairs++; |
4f774513 | 14632 | } |
6d368e53 JS |
14633 | |
14634 | /* Complete initialization and perform endian conversion. */ | |
4f774513 | 14635 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); |
8a9d2e80 | 14636 | bf_set(lpfc_post_sgl_pages_xricnt, sgl, phba->sli4_hba.els_xri_cnt); |
4f774513 | 14637 | sgl->word0 = cpu_to_le32(sgl->word0); |
4f774513 JS |
14638 | if (!phba->sli4_hba.intr_enable) |
14639 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
14640 | else { | |
a183a15f | 14641 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
4f774513 JS |
14642 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
14643 | } | |
14644 | shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr; | |
14645 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
14646 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
14647 | if (rc != MBX_TIMEOUT) | |
14648 | lpfc_sli4_mbox_cmd_free(phba, mbox); | |
14649 | if (shdr_status || shdr_add_status || rc) { | |
14650 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
14651 | "2513 POST_SGL_BLOCK mailbox command failed " | |
14652 | "status x%x add_status x%x mbx status x%x\n", | |
14653 | shdr_status, shdr_add_status, rc); | |
14654 | rc = -ENXIO; | |
14655 | } | |
14656 | return rc; | |
14657 | } | |
14658 | ||
14659 | /** | |
14660 | * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware | |
14661 | * @phba: pointer to lpfc hba data structure. | |
14662 | * @sblist: pointer to scsi buffer list. | |
14663 | * @count: number of scsi buffers on the list. | |
14664 | * | |
14665 | * This routine is invoked to post a block of @count scsi sgl pages from a | |
14666 | * SCSI buffer list @sblist to the HBA using non-embedded mailbox command. | |
14667 | * No Lock is held. | |
14668 | * | |
14669 | **/ | |
14670 | int | |
8a9d2e80 JS |
14671 | lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba, |
14672 | struct list_head *sblist, | |
14673 | int count) | |
4f774513 JS |
14674 | { |
14675 | struct lpfc_scsi_buf *psb; | |
14676 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; | |
14677 | struct sgl_page_pairs *sgl_pg_pairs; | |
14678 | void *viraddr; | |
14679 | LPFC_MBOXQ_t *mbox; | |
14680 | uint32_t reqlen, alloclen, pg_pairs; | |
14681 | uint32_t mbox_tmo; | |
14682 | uint16_t xritag_start = 0; | |
14683 | int rc = 0; | |
14684 | uint32_t shdr_status, shdr_add_status; | |
14685 | dma_addr_t pdma_phys_bpl1; | |
14686 | union lpfc_sli4_cfg_shdr *shdr; | |
14687 | ||
14688 | /* Calculate the requested length of the dma memory */ | |
8a9d2e80 | 14689 | reqlen = count * sizeof(struct sgl_page_pairs) + |
4f774513 | 14690 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); |
49198b37 | 14691 | if (reqlen > SLI4_PAGE_SIZE) { |
4f774513 JS |
14692 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
14693 | "0217 Block sgl registration required DMA " | |
14694 | "size (%d) great than a page\n", reqlen); | |
14695 | return -ENOMEM; | |
14696 | } | |
14697 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
14698 | if (!mbox) { | |
14699 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
14700 | "0283 Failed to allocate mbox cmd memory\n"); | |
14701 | return -ENOMEM; | |
14702 | } | |
14703 | ||
14704 | /* Allocate DMA memory and set up the non-embedded mailbox command */ | |
14705 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
14706 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen, | |
14707 | LPFC_SLI4_MBX_NEMBED); | |
14708 | ||
14709 | if (alloclen < reqlen) { | |
14710 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
14711 | "2561 Allocated DMA memory size (%d) is " | |
14712 | "less than the requested DMA memory " | |
14713 | "size (%d)\n", alloclen, reqlen); | |
14714 | lpfc_sli4_mbox_cmd_free(phba, mbox); | |
14715 | return -ENOMEM; | |
14716 | } | |
6d368e53 | 14717 | |
4f774513 | 14718 | /* Get the first SGE entry from the non-embedded DMA memory */ |
4f774513 JS |
14719 | viraddr = mbox->sge_array->addr[0]; |
14720 | ||
14721 | /* Set up the SGL pages in the non-embedded DMA pages */ | |
14722 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; | |
14723 | sgl_pg_pairs = &sgl->sgl_pg_pairs; | |
14724 | ||
14725 | pg_pairs = 0; | |
14726 | list_for_each_entry(psb, sblist, list) { | |
14727 | /* Set up the sge entry */ | |
14728 | sgl_pg_pairs->sgl_pg0_addr_lo = | |
14729 | cpu_to_le32(putPaddrLow(psb->dma_phys_bpl)); | |
14730 | sgl_pg_pairs->sgl_pg0_addr_hi = | |
14731 | cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl)); | |
14732 | if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE) | |
14733 | pdma_phys_bpl1 = psb->dma_phys_bpl + SGL_PAGE_SIZE; | |
14734 | else | |
14735 | pdma_phys_bpl1 = 0; | |
14736 | sgl_pg_pairs->sgl_pg1_addr_lo = | |
14737 | cpu_to_le32(putPaddrLow(pdma_phys_bpl1)); | |
14738 | sgl_pg_pairs->sgl_pg1_addr_hi = | |
14739 | cpu_to_le32(putPaddrHigh(pdma_phys_bpl1)); | |
14740 | /* Keep the first xritag on the list */ | |
14741 | if (pg_pairs == 0) | |
14742 | xritag_start = psb->cur_iocbq.sli4_xritag; | |
14743 | sgl_pg_pairs++; | |
14744 | pg_pairs++; | |
14745 | } | |
14746 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); | |
14747 | bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs); | |
14748 | /* Perform endian conversion if necessary */ | |
14749 | sgl->word0 = cpu_to_le32(sgl->word0); | |
14750 | ||
14751 | if (!phba->sli4_hba.intr_enable) | |
14752 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
14753 | else { | |
a183a15f | 14754 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
4f774513 JS |
14755 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
14756 | } | |
14757 | shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr; | |
14758 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
14759 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
14760 | if (rc != MBX_TIMEOUT) | |
14761 | lpfc_sli4_mbox_cmd_free(phba, mbox); | |
14762 | if (shdr_status || shdr_add_status || rc) { | |
14763 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
14764 | "2564 POST_SGL_BLOCK mailbox command failed " | |
14765 | "status x%x add_status x%x mbx status x%x\n", | |
14766 | shdr_status, shdr_add_status, rc); | |
14767 | rc = -ENXIO; | |
14768 | } | |
14769 | return rc; | |
14770 | } | |
14771 | ||
14772 | /** | |
14773 | * lpfc_fc_frame_check - Check that this frame is a valid frame to handle | |
14774 | * @phba: pointer to lpfc_hba struct that the frame was received on | |
14775 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) | |
14776 | * | |
14777 | * This function checks the fields in the @fc_hdr to see if the FC frame is a | |
14778 | * valid type of frame that the LPFC driver will handle. This function will | |
14779 | * return a zero if the frame is a valid frame or a non zero value when the | |
14780 | * frame does not pass the check. | |
14781 | **/ | |
14782 | static int | |
14783 | lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr) | |
14784 | { | |
474ffb74 TH |
14785 | /* make rctl_names static to save stack space */ |
14786 | static char *rctl_names[] = FC_RCTL_NAMES_INIT; | |
4f774513 JS |
14787 | char *type_names[] = FC_TYPE_NAMES_INIT; |
14788 | struct fc_vft_header *fc_vft_hdr; | |
546fc854 | 14789 | uint32_t *header = (uint32_t *) fc_hdr; |
4f774513 JS |
14790 | |
14791 | switch (fc_hdr->fh_r_ctl) { | |
14792 | case FC_RCTL_DD_UNCAT: /* uncategorized information */ | |
14793 | case FC_RCTL_DD_SOL_DATA: /* solicited data */ | |
14794 | case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */ | |
14795 | case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */ | |
14796 | case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */ | |
14797 | case FC_RCTL_DD_DATA_DESC: /* data descriptor */ | |
14798 | case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */ | |
14799 | case FC_RCTL_DD_CMD_STATUS: /* command status */ | |
14800 | case FC_RCTL_ELS_REQ: /* extended link services request */ | |
14801 | case FC_RCTL_ELS_REP: /* extended link services reply */ | |
14802 | case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */ | |
14803 | case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */ | |
14804 | case FC_RCTL_BA_NOP: /* basic link service NOP */ | |
14805 | case FC_RCTL_BA_ABTS: /* basic link service abort */ | |
14806 | case FC_RCTL_BA_RMC: /* remove connection */ | |
14807 | case FC_RCTL_BA_ACC: /* basic accept */ | |
14808 | case FC_RCTL_BA_RJT: /* basic reject */ | |
14809 | case FC_RCTL_BA_PRMT: | |
14810 | case FC_RCTL_ACK_1: /* acknowledge_1 */ | |
14811 | case FC_RCTL_ACK_0: /* acknowledge_0 */ | |
14812 | case FC_RCTL_P_RJT: /* port reject */ | |
14813 | case FC_RCTL_F_RJT: /* fabric reject */ | |
14814 | case FC_RCTL_P_BSY: /* port busy */ | |
14815 | case FC_RCTL_F_BSY: /* fabric busy to data frame */ | |
14816 | case FC_RCTL_F_BSYL: /* fabric busy to link control frame */ | |
14817 | case FC_RCTL_LCR: /* link credit reset */ | |
14818 | case FC_RCTL_END: /* end */ | |
14819 | break; | |
14820 | case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */ | |
14821 | fc_vft_hdr = (struct fc_vft_header *)fc_hdr; | |
14822 | fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1]; | |
14823 | return lpfc_fc_frame_check(phba, fc_hdr); | |
14824 | default: | |
14825 | goto drop; | |
14826 | } | |
14827 | switch (fc_hdr->fh_type) { | |
14828 | case FC_TYPE_BLS: | |
14829 | case FC_TYPE_ELS: | |
14830 | case FC_TYPE_FCP: | |
14831 | case FC_TYPE_CT: | |
14832 | break; | |
14833 | case FC_TYPE_IP: | |
14834 | case FC_TYPE_ILS: | |
14835 | default: | |
14836 | goto drop; | |
14837 | } | |
546fc854 | 14838 | |
4f774513 | 14839 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
88f43a08 JS |
14840 | "2538 Received frame rctl:%s (x%x), type:%s (x%x), " |
14841 | "frame Data:%08x %08x %08x %08x %08x %08x %08x\n", | |
14842 | rctl_names[fc_hdr->fh_r_ctl], fc_hdr->fh_r_ctl, | |
14843 | type_names[fc_hdr->fh_type], fc_hdr->fh_type, | |
546fc854 JS |
14844 | be32_to_cpu(header[0]), be32_to_cpu(header[1]), |
14845 | be32_to_cpu(header[2]), be32_to_cpu(header[3]), | |
88f43a08 JS |
14846 | be32_to_cpu(header[4]), be32_to_cpu(header[5]), |
14847 | be32_to_cpu(header[6])); | |
4f774513 JS |
14848 | return 0; |
14849 | drop: | |
14850 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS, | |
14851 | "2539 Dropped frame rctl:%s type:%s\n", | |
14852 | rctl_names[fc_hdr->fh_r_ctl], | |
14853 | type_names[fc_hdr->fh_type]); | |
14854 | return 1; | |
14855 | } | |
14856 | ||
14857 | /** | |
14858 | * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame | |
14859 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) | |
14860 | * | |
14861 | * This function processes the FC header to retrieve the VFI from the VF | |
14862 | * header, if one exists. This function will return the VFI if one exists | |
14863 | * or 0 if no VSAN Header exists. | |
14864 | **/ | |
14865 | static uint32_t | |
14866 | lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr) | |
14867 | { | |
14868 | struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr; | |
14869 | ||
14870 | if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH) | |
14871 | return 0; | |
14872 | return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr); | |
14873 | } | |
14874 | ||
14875 | /** | |
14876 | * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to | |
14877 | * @phba: Pointer to the HBA structure to search for the vport on | |
14878 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) | |
14879 | * @fcfi: The FC Fabric ID that the frame came from | |
14880 | * | |
14881 | * This function searches the @phba for a vport that matches the content of the | |
14882 | * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the | |
14883 | * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function | |
14884 | * returns the matching vport pointer or NULL if unable to match frame to a | |
14885 | * vport. | |
14886 | **/ | |
14887 | static struct lpfc_vport * | |
14888 | lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr, | |
14889 | uint16_t fcfi) | |
14890 | { | |
14891 | struct lpfc_vport **vports; | |
14892 | struct lpfc_vport *vport = NULL; | |
14893 | int i; | |
14894 | uint32_t did = (fc_hdr->fh_d_id[0] << 16 | | |
14895 | fc_hdr->fh_d_id[1] << 8 | | |
14896 | fc_hdr->fh_d_id[2]); | |
939723a4 | 14897 | |
bf08611b JS |
14898 | if (did == Fabric_DID) |
14899 | return phba->pport; | |
939723a4 JS |
14900 | if ((phba->pport->fc_flag & FC_PT2PT) && |
14901 | !(phba->link_state == LPFC_HBA_READY)) | |
14902 | return phba->pport; | |
14903 | ||
4f774513 JS |
14904 | vports = lpfc_create_vport_work_array(phba); |
14905 | if (vports != NULL) | |
14906 | for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) { | |
14907 | if (phba->fcf.fcfi == fcfi && | |
14908 | vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) && | |
14909 | vports[i]->fc_myDID == did) { | |
14910 | vport = vports[i]; | |
14911 | break; | |
14912 | } | |
14913 | } | |
14914 | lpfc_destroy_vport_work_array(phba, vports); | |
14915 | return vport; | |
14916 | } | |
14917 | ||
45ed1190 JS |
14918 | /** |
14919 | * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp | |
14920 | * @vport: The vport to work on. | |
14921 | * | |
14922 | * This function updates the receive sequence time stamp for this vport. The | |
14923 | * receive sequence time stamp indicates the time that the last frame of the | |
14924 | * the sequence that has been idle for the longest amount of time was received. | |
14925 | * the driver uses this time stamp to indicate if any received sequences have | |
14926 | * timed out. | |
14927 | **/ | |
5d8b8167 | 14928 | static void |
45ed1190 JS |
14929 | lpfc_update_rcv_time_stamp(struct lpfc_vport *vport) |
14930 | { | |
14931 | struct lpfc_dmabuf *h_buf; | |
14932 | struct hbq_dmabuf *dmabuf = NULL; | |
14933 | ||
14934 | /* get the oldest sequence on the rcv list */ | |
14935 | h_buf = list_get_first(&vport->rcv_buffer_list, | |
14936 | struct lpfc_dmabuf, list); | |
14937 | if (!h_buf) | |
14938 | return; | |
14939 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); | |
14940 | vport->rcv_buffer_time_stamp = dmabuf->time_stamp; | |
14941 | } | |
14942 | ||
14943 | /** | |
14944 | * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences. | |
14945 | * @vport: The vport that the received sequences were sent to. | |
14946 | * | |
14947 | * This function cleans up all outstanding received sequences. This is called | |
14948 | * by the driver when a link event or user action invalidates all the received | |
14949 | * sequences. | |
14950 | **/ | |
14951 | void | |
14952 | lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport) | |
14953 | { | |
14954 | struct lpfc_dmabuf *h_buf, *hnext; | |
14955 | struct lpfc_dmabuf *d_buf, *dnext; | |
14956 | struct hbq_dmabuf *dmabuf = NULL; | |
14957 | ||
14958 | /* start with the oldest sequence on the rcv list */ | |
14959 | list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) { | |
14960 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); | |
14961 | list_del_init(&dmabuf->hbuf.list); | |
14962 | list_for_each_entry_safe(d_buf, dnext, | |
14963 | &dmabuf->dbuf.list, list) { | |
14964 | list_del_init(&d_buf->list); | |
14965 | lpfc_in_buf_free(vport->phba, d_buf); | |
14966 | } | |
14967 | lpfc_in_buf_free(vport->phba, &dmabuf->dbuf); | |
14968 | } | |
14969 | } | |
14970 | ||
14971 | /** | |
14972 | * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences. | |
14973 | * @vport: The vport that the received sequences were sent to. | |
14974 | * | |
14975 | * This function determines whether any received sequences have timed out by | |
14976 | * first checking the vport's rcv_buffer_time_stamp. If this time_stamp | |
14977 | * indicates that there is at least one timed out sequence this routine will | |
14978 | * go through the received sequences one at a time from most inactive to most | |
14979 | * active to determine which ones need to be cleaned up. Once it has determined | |
14980 | * that a sequence needs to be cleaned up it will simply free up the resources | |
14981 | * without sending an abort. | |
14982 | **/ | |
14983 | void | |
14984 | lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport) | |
14985 | { | |
14986 | struct lpfc_dmabuf *h_buf, *hnext; | |
14987 | struct lpfc_dmabuf *d_buf, *dnext; | |
14988 | struct hbq_dmabuf *dmabuf = NULL; | |
14989 | unsigned long timeout; | |
14990 | int abort_count = 0; | |
14991 | ||
14992 | timeout = (msecs_to_jiffies(vport->phba->fc_edtov) + | |
14993 | vport->rcv_buffer_time_stamp); | |
14994 | if (list_empty(&vport->rcv_buffer_list) || | |
14995 | time_before(jiffies, timeout)) | |
14996 | return; | |
14997 | /* start with the oldest sequence on the rcv list */ | |
14998 | list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) { | |
14999 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); | |
15000 | timeout = (msecs_to_jiffies(vport->phba->fc_edtov) + | |
15001 | dmabuf->time_stamp); | |
15002 | if (time_before(jiffies, timeout)) | |
15003 | break; | |
15004 | abort_count++; | |
15005 | list_del_init(&dmabuf->hbuf.list); | |
15006 | list_for_each_entry_safe(d_buf, dnext, | |
15007 | &dmabuf->dbuf.list, list) { | |
15008 | list_del_init(&d_buf->list); | |
15009 | lpfc_in_buf_free(vport->phba, d_buf); | |
15010 | } | |
15011 | lpfc_in_buf_free(vport->phba, &dmabuf->dbuf); | |
15012 | } | |
15013 | if (abort_count) | |
15014 | lpfc_update_rcv_time_stamp(vport); | |
15015 | } | |
15016 | ||
4f774513 JS |
15017 | /** |
15018 | * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences | |
15019 | * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame | |
15020 | * | |
15021 | * This function searches through the existing incomplete sequences that have | |
15022 | * been sent to this @vport. If the frame matches one of the incomplete | |
15023 | * sequences then the dbuf in the @dmabuf is added to the list of frames that | |
15024 | * make up that sequence. If no sequence is found that matches this frame then | |
15025 | * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list | |
15026 | * This function returns a pointer to the first dmabuf in the sequence list that | |
15027 | * the frame was linked to. | |
15028 | **/ | |
15029 | static struct hbq_dmabuf * | |
15030 | lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf) | |
15031 | { | |
15032 | struct fc_frame_header *new_hdr; | |
15033 | struct fc_frame_header *temp_hdr; | |
15034 | struct lpfc_dmabuf *d_buf; | |
15035 | struct lpfc_dmabuf *h_buf; | |
15036 | struct hbq_dmabuf *seq_dmabuf = NULL; | |
15037 | struct hbq_dmabuf *temp_dmabuf = NULL; | |
4360ca9c | 15038 | uint8_t found = 0; |
4f774513 | 15039 | |
4d9ab994 | 15040 | INIT_LIST_HEAD(&dmabuf->dbuf.list); |
45ed1190 | 15041 | dmabuf->time_stamp = jiffies; |
4f774513 | 15042 | new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
4360ca9c | 15043 | |
4f774513 JS |
15044 | /* Use the hdr_buf to find the sequence that this frame belongs to */ |
15045 | list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) { | |
15046 | temp_hdr = (struct fc_frame_header *)h_buf->virt; | |
15047 | if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) || | |
15048 | (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) || | |
15049 | (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3))) | |
15050 | continue; | |
15051 | /* found a pending sequence that matches this frame */ | |
15052 | seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); | |
15053 | break; | |
15054 | } | |
15055 | if (!seq_dmabuf) { | |
15056 | /* | |
15057 | * This indicates first frame received for this sequence. | |
15058 | * Queue the buffer on the vport's rcv_buffer_list. | |
15059 | */ | |
15060 | list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list); | |
45ed1190 | 15061 | lpfc_update_rcv_time_stamp(vport); |
4f774513 JS |
15062 | return dmabuf; |
15063 | } | |
15064 | temp_hdr = seq_dmabuf->hbuf.virt; | |
eeead811 JS |
15065 | if (be16_to_cpu(new_hdr->fh_seq_cnt) < |
15066 | be16_to_cpu(temp_hdr->fh_seq_cnt)) { | |
4d9ab994 JS |
15067 | list_del_init(&seq_dmabuf->hbuf.list); |
15068 | list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list); | |
15069 | list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list); | |
45ed1190 | 15070 | lpfc_update_rcv_time_stamp(vport); |
4f774513 JS |
15071 | return dmabuf; |
15072 | } | |
45ed1190 JS |
15073 | /* move this sequence to the tail to indicate a young sequence */ |
15074 | list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list); | |
15075 | seq_dmabuf->time_stamp = jiffies; | |
15076 | lpfc_update_rcv_time_stamp(vport); | |
eeead811 JS |
15077 | if (list_empty(&seq_dmabuf->dbuf.list)) { |
15078 | temp_hdr = dmabuf->hbuf.virt; | |
15079 | list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list); | |
15080 | return seq_dmabuf; | |
15081 | } | |
4f774513 | 15082 | /* find the correct place in the sequence to insert this frame */ |
4360ca9c JS |
15083 | d_buf = list_entry(seq_dmabuf->dbuf.list.prev, typeof(*d_buf), list); |
15084 | while (!found) { | |
4f774513 JS |
15085 | temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
15086 | temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt; | |
15087 | /* | |
15088 | * If the frame's sequence count is greater than the frame on | |
15089 | * the list then insert the frame right after this frame | |
15090 | */ | |
eeead811 JS |
15091 | if (be16_to_cpu(new_hdr->fh_seq_cnt) > |
15092 | be16_to_cpu(temp_hdr->fh_seq_cnt)) { | |
4f774513 | 15093 | list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list); |
4360ca9c JS |
15094 | found = 1; |
15095 | break; | |
4f774513 | 15096 | } |
4360ca9c JS |
15097 | |
15098 | if (&d_buf->list == &seq_dmabuf->dbuf.list) | |
15099 | break; | |
15100 | d_buf = list_entry(d_buf->list.prev, typeof(*d_buf), list); | |
4f774513 | 15101 | } |
4360ca9c JS |
15102 | |
15103 | if (found) | |
15104 | return seq_dmabuf; | |
4f774513 JS |
15105 | return NULL; |
15106 | } | |
15107 | ||
6669f9bb JS |
15108 | /** |
15109 | * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence | |
15110 | * @vport: pointer to a vitural port | |
15111 | * @dmabuf: pointer to a dmabuf that describes the FC sequence | |
15112 | * | |
15113 | * This function tries to abort from the partially assembed sequence, described | |
15114 | * by the information from basic abbort @dmabuf. It checks to see whether such | |
15115 | * partially assembled sequence held by the driver. If so, it shall free up all | |
15116 | * the frames from the partially assembled sequence. | |
15117 | * | |
15118 | * Return | |
15119 | * true -- if there is matching partially assembled sequence present and all | |
15120 | * the frames freed with the sequence; | |
15121 | * false -- if there is no matching partially assembled sequence present so | |
15122 | * nothing got aborted in the lower layer driver | |
15123 | **/ | |
15124 | static bool | |
15125 | lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport, | |
15126 | struct hbq_dmabuf *dmabuf) | |
15127 | { | |
15128 | struct fc_frame_header *new_hdr; | |
15129 | struct fc_frame_header *temp_hdr; | |
15130 | struct lpfc_dmabuf *d_buf, *n_buf, *h_buf; | |
15131 | struct hbq_dmabuf *seq_dmabuf = NULL; | |
15132 | ||
15133 | /* Use the hdr_buf to find the sequence that matches this frame */ | |
15134 | INIT_LIST_HEAD(&dmabuf->dbuf.list); | |
15135 | INIT_LIST_HEAD(&dmabuf->hbuf.list); | |
15136 | new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; | |
15137 | list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) { | |
15138 | temp_hdr = (struct fc_frame_header *)h_buf->virt; | |
15139 | if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) || | |
15140 | (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) || | |
15141 | (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3))) | |
15142 | continue; | |
15143 | /* found a pending sequence that matches this frame */ | |
15144 | seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); | |
15145 | break; | |
15146 | } | |
15147 | ||
15148 | /* Free up all the frames from the partially assembled sequence */ | |
15149 | if (seq_dmabuf) { | |
15150 | list_for_each_entry_safe(d_buf, n_buf, | |
15151 | &seq_dmabuf->dbuf.list, list) { | |
15152 | list_del_init(&d_buf->list); | |
15153 | lpfc_in_buf_free(vport->phba, d_buf); | |
15154 | } | |
15155 | return true; | |
15156 | } | |
15157 | return false; | |
15158 | } | |
15159 | ||
6dd9e31c JS |
15160 | /** |
15161 | * lpfc_sli4_abort_ulp_seq - Abort assembled unsol sequence from ulp | |
15162 | * @vport: pointer to a vitural port | |
15163 | * @dmabuf: pointer to a dmabuf that describes the FC sequence | |
15164 | * | |
15165 | * This function tries to abort from the assembed sequence from upper level | |
15166 | * protocol, described by the information from basic abbort @dmabuf. It | |
15167 | * checks to see whether such pending context exists at upper level protocol. | |
15168 | * If so, it shall clean up the pending context. | |
15169 | * | |
15170 | * Return | |
15171 | * true -- if there is matching pending context of the sequence cleaned | |
15172 | * at ulp; | |
15173 | * false -- if there is no matching pending context of the sequence present | |
15174 | * at ulp. | |
15175 | **/ | |
15176 | static bool | |
15177 | lpfc_sli4_abort_ulp_seq(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf) | |
15178 | { | |
15179 | struct lpfc_hba *phba = vport->phba; | |
15180 | int handled; | |
15181 | ||
15182 | /* Accepting abort at ulp with SLI4 only */ | |
15183 | if (phba->sli_rev < LPFC_SLI_REV4) | |
15184 | return false; | |
15185 | ||
15186 | /* Register all caring upper level protocols to attend abort */ | |
15187 | handled = lpfc_ct_handle_unsol_abort(phba, dmabuf); | |
15188 | if (handled) | |
15189 | return true; | |
15190 | ||
15191 | return false; | |
15192 | } | |
15193 | ||
6669f9bb | 15194 | /** |
546fc854 | 15195 | * lpfc_sli4_seq_abort_rsp_cmpl - BLS ABORT RSP seq abort iocb complete handler |
6669f9bb JS |
15196 | * @phba: Pointer to HBA context object. |
15197 | * @cmd_iocbq: pointer to the command iocbq structure. | |
15198 | * @rsp_iocbq: pointer to the response iocbq structure. | |
15199 | * | |
546fc854 | 15200 | * This function handles the sequence abort response iocb command complete |
6669f9bb JS |
15201 | * event. It properly releases the memory allocated to the sequence abort |
15202 | * accept iocb. | |
15203 | **/ | |
15204 | static void | |
546fc854 | 15205 | lpfc_sli4_seq_abort_rsp_cmpl(struct lpfc_hba *phba, |
6669f9bb JS |
15206 | struct lpfc_iocbq *cmd_iocbq, |
15207 | struct lpfc_iocbq *rsp_iocbq) | |
15208 | { | |
6dd9e31c JS |
15209 | struct lpfc_nodelist *ndlp; |
15210 | ||
15211 | if (cmd_iocbq) { | |
15212 | ndlp = (struct lpfc_nodelist *)cmd_iocbq->context1; | |
15213 | lpfc_nlp_put(ndlp); | |
15214 | lpfc_nlp_not_used(ndlp); | |
6669f9bb | 15215 | lpfc_sli_release_iocbq(phba, cmd_iocbq); |
6dd9e31c | 15216 | } |
6b5151fd JS |
15217 | |
15218 | /* Failure means BLS ABORT RSP did not get delivered to remote node*/ | |
15219 | if (rsp_iocbq && rsp_iocbq->iocb.ulpStatus) | |
15220 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
15221 | "3154 BLS ABORT RSP failed, data: x%x/x%x\n", | |
15222 | rsp_iocbq->iocb.ulpStatus, | |
15223 | rsp_iocbq->iocb.un.ulpWord[4]); | |
6669f9bb JS |
15224 | } |
15225 | ||
6d368e53 JS |
15226 | /** |
15227 | * lpfc_sli4_xri_inrange - check xri is in range of xris owned by driver. | |
15228 | * @phba: Pointer to HBA context object. | |
15229 | * @xri: xri id in transaction. | |
15230 | * | |
15231 | * This function validates the xri maps to the known range of XRIs allocated an | |
15232 | * used by the driver. | |
15233 | **/ | |
7851fe2c | 15234 | uint16_t |
6d368e53 JS |
15235 | lpfc_sli4_xri_inrange(struct lpfc_hba *phba, |
15236 | uint16_t xri) | |
15237 | { | |
a2fc4aef | 15238 | uint16_t i; |
6d368e53 JS |
15239 | |
15240 | for (i = 0; i < phba->sli4_hba.max_cfg_param.max_xri; i++) { | |
15241 | if (xri == phba->sli4_hba.xri_ids[i]) | |
15242 | return i; | |
15243 | } | |
15244 | return NO_XRI; | |
15245 | } | |
15246 | ||
6669f9bb | 15247 | /** |
546fc854 | 15248 | * lpfc_sli4_seq_abort_rsp - bls rsp to sequence abort |
6669f9bb JS |
15249 | * @phba: Pointer to HBA context object. |
15250 | * @fc_hdr: pointer to a FC frame header. | |
15251 | * | |
546fc854 | 15252 | * This function sends a basic response to a previous unsol sequence abort |
6669f9bb JS |
15253 | * event after aborting the sequence handling. |
15254 | **/ | |
15255 | static void | |
6dd9e31c JS |
15256 | lpfc_sli4_seq_abort_rsp(struct lpfc_vport *vport, |
15257 | struct fc_frame_header *fc_hdr, bool aborted) | |
6669f9bb | 15258 | { |
6dd9e31c | 15259 | struct lpfc_hba *phba = vport->phba; |
6669f9bb JS |
15260 | struct lpfc_iocbq *ctiocb = NULL; |
15261 | struct lpfc_nodelist *ndlp; | |
ee0f4fe1 | 15262 | uint16_t oxid, rxid, xri, lxri; |
5ffc266e | 15263 | uint32_t sid, fctl; |
6669f9bb | 15264 | IOCB_t *icmd; |
546fc854 | 15265 | int rc; |
6669f9bb JS |
15266 | |
15267 | if (!lpfc_is_link_up(phba)) | |
15268 | return; | |
15269 | ||
15270 | sid = sli4_sid_from_fc_hdr(fc_hdr); | |
15271 | oxid = be16_to_cpu(fc_hdr->fh_ox_id); | |
5ffc266e | 15272 | rxid = be16_to_cpu(fc_hdr->fh_rx_id); |
6669f9bb | 15273 | |
6dd9e31c | 15274 | ndlp = lpfc_findnode_did(vport, sid); |
6669f9bb | 15275 | if (!ndlp) { |
6dd9e31c JS |
15276 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
15277 | if (!ndlp) { | |
15278 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS, | |
15279 | "1268 Failed to allocate ndlp for " | |
15280 | "oxid:x%x SID:x%x\n", oxid, sid); | |
15281 | return; | |
15282 | } | |
15283 | lpfc_nlp_init(vport, ndlp, sid); | |
15284 | /* Put ndlp onto pport node list */ | |
15285 | lpfc_enqueue_node(vport, ndlp); | |
15286 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { | |
15287 | /* re-setup ndlp without removing from node list */ | |
15288 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); | |
15289 | if (!ndlp) { | |
15290 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS, | |
15291 | "3275 Failed to active ndlp found " | |
15292 | "for oxid:x%x SID:x%x\n", oxid, sid); | |
15293 | return; | |
15294 | } | |
6669f9bb JS |
15295 | } |
15296 | ||
546fc854 | 15297 | /* Allocate buffer for rsp iocb */ |
6669f9bb JS |
15298 | ctiocb = lpfc_sli_get_iocbq(phba); |
15299 | if (!ctiocb) | |
15300 | return; | |
15301 | ||
5ffc266e JS |
15302 | /* Extract the F_CTL field from FC_HDR */ |
15303 | fctl = sli4_fctl_from_fc_hdr(fc_hdr); | |
15304 | ||
6669f9bb | 15305 | icmd = &ctiocb->iocb; |
6669f9bb | 15306 | icmd->un.xseq64.bdl.bdeSize = 0; |
5ffc266e | 15307 | icmd->un.xseq64.bdl.ulpIoTag32 = 0; |
6669f9bb JS |
15308 | icmd->un.xseq64.w5.hcsw.Dfctl = 0; |
15309 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC; | |
15310 | icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS; | |
15311 | ||
15312 | /* Fill in the rest of iocb fields */ | |
15313 | icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX; | |
15314 | icmd->ulpBdeCount = 0; | |
15315 | icmd->ulpLe = 1; | |
15316 | icmd->ulpClass = CLASS3; | |
6d368e53 | 15317 | icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]; |
6dd9e31c | 15318 | ctiocb->context1 = lpfc_nlp_get(ndlp); |
6669f9bb | 15319 | |
6669f9bb JS |
15320 | ctiocb->iocb_cmpl = NULL; |
15321 | ctiocb->vport = phba->pport; | |
546fc854 | 15322 | ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_rsp_cmpl; |
6d368e53 | 15323 | ctiocb->sli4_lxritag = NO_XRI; |
546fc854 JS |
15324 | ctiocb->sli4_xritag = NO_XRI; |
15325 | ||
ee0f4fe1 JS |
15326 | if (fctl & FC_FC_EX_CTX) |
15327 | /* Exchange responder sent the abort so we | |
15328 | * own the oxid. | |
15329 | */ | |
15330 | xri = oxid; | |
15331 | else | |
15332 | xri = rxid; | |
15333 | lxri = lpfc_sli4_xri_inrange(phba, xri); | |
15334 | if (lxri != NO_XRI) | |
15335 | lpfc_set_rrq_active(phba, ndlp, lxri, | |
15336 | (xri == oxid) ? rxid : oxid, 0); | |
6dd9e31c JS |
15337 | /* For BA_ABTS from exchange responder, if the logical xri with |
15338 | * the oxid maps to the FCP XRI range, the port no longer has | |
15339 | * that exchange context, send a BLS_RJT. Override the IOCB for | |
15340 | * a BA_RJT. | |
15341 | */ | |
15342 | if ((fctl & FC_FC_EX_CTX) && | |
15343 | (lxri > lpfc_sli4_get_els_iocb_cnt(phba))) { | |
15344 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT; | |
15345 | bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0); | |
15346 | bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID); | |
15347 | bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE); | |
15348 | } | |
15349 | ||
15350 | /* If BA_ABTS failed to abort a partially assembled receive sequence, | |
15351 | * the driver no longer has that exchange, send a BLS_RJT. Override | |
15352 | * the IOCB for a BA_RJT. | |
546fc854 | 15353 | */ |
6dd9e31c | 15354 | if (aborted == false) { |
546fc854 JS |
15355 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT; |
15356 | bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0); | |
15357 | bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID); | |
15358 | bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE); | |
15359 | } | |
6669f9bb | 15360 | |
5ffc266e JS |
15361 | if (fctl & FC_FC_EX_CTX) { |
15362 | /* ABTS sent by responder to CT exchange, construction | |
15363 | * of BA_ACC will use OX_ID from ABTS for the XRI_TAG | |
15364 | * field and RX_ID from ABTS for RX_ID field. | |
15365 | */ | |
546fc854 | 15366 | bf_set(lpfc_abts_orig, &icmd->un.bls_rsp, LPFC_ABTS_UNSOL_RSP); |
5ffc266e JS |
15367 | } else { |
15368 | /* ABTS sent by initiator to CT exchange, construction | |
15369 | * of BA_ACC will need to allocate a new XRI as for the | |
f09c3acc | 15370 | * XRI_TAG field. |
5ffc266e | 15371 | */ |
546fc854 | 15372 | bf_set(lpfc_abts_orig, &icmd->un.bls_rsp, LPFC_ABTS_UNSOL_INT); |
5ffc266e | 15373 | } |
f09c3acc | 15374 | bf_set(lpfc_abts_rxid, &icmd->un.bls_rsp, rxid); |
546fc854 | 15375 | bf_set(lpfc_abts_oxid, &icmd->un.bls_rsp, oxid); |
5ffc266e | 15376 | |
546fc854 | 15377 | /* Xmit CT abts response on exchange <xid> */ |
6dd9e31c JS |
15378 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
15379 | "1200 Send BLS cmd x%x on oxid x%x Data: x%x\n", | |
15380 | icmd->un.xseq64.w5.hcsw.Rctl, oxid, phba->link_state); | |
546fc854 JS |
15381 | |
15382 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0); | |
15383 | if (rc == IOCB_ERROR) { | |
6dd9e31c JS |
15384 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
15385 | "2925 Failed to issue CT ABTS RSP x%x on " | |
15386 | "xri x%x, Data x%x\n", | |
15387 | icmd->un.xseq64.w5.hcsw.Rctl, oxid, | |
15388 | phba->link_state); | |
15389 | lpfc_nlp_put(ndlp); | |
15390 | ctiocb->context1 = NULL; | |
546fc854 JS |
15391 | lpfc_sli_release_iocbq(phba, ctiocb); |
15392 | } | |
6669f9bb JS |
15393 | } |
15394 | ||
15395 | /** | |
15396 | * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event | |
15397 | * @vport: Pointer to the vport on which this sequence was received | |
15398 | * @dmabuf: pointer to a dmabuf that describes the FC sequence | |
15399 | * | |
15400 | * This function handles an SLI-4 unsolicited abort event. If the unsolicited | |
15401 | * receive sequence is only partially assembed by the driver, it shall abort | |
15402 | * the partially assembled frames for the sequence. Otherwise, if the | |
15403 | * unsolicited receive sequence has been completely assembled and passed to | |
15404 | * the Upper Layer Protocol (UPL), it then mark the per oxid status for the | |
15405 | * unsolicited sequence has been aborted. After that, it will issue a basic | |
15406 | * accept to accept the abort. | |
15407 | **/ | |
5d8b8167 | 15408 | static void |
6669f9bb JS |
15409 | lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport, |
15410 | struct hbq_dmabuf *dmabuf) | |
15411 | { | |
15412 | struct lpfc_hba *phba = vport->phba; | |
15413 | struct fc_frame_header fc_hdr; | |
5ffc266e | 15414 | uint32_t fctl; |
6dd9e31c | 15415 | bool aborted; |
6669f9bb | 15416 | |
6669f9bb JS |
15417 | /* Make a copy of fc_hdr before the dmabuf being released */ |
15418 | memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header)); | |
5ffc266e | 15419 | fctl = sli4_fctl_from_fc_hdr(&fc_hdr); |
6669f9bb | 15420 | |
5ffc266e | 15421 | if (fctl & FC_FC_EX_CTX) { |
6dd9e31c JS |
15422 | /* ABTS by responder to exchange, no cleanup needed */ |
15423 | aborted = true; | |
5ffc266e | 15424 | } else { |
6dd9e31c JS |
15425 | /* ABTS by initiator to exchange, need to do cleanup */ |
15426 | aborted = lpfc_sli4_abort_partial_seq(vport, dmabuf); | |
15427 | if (aborted == false) | |
15428 | aborted = lpfc_sli4_abort_ulp_seq(vport, dmabuf); | |
5ffc266e | 15429 | } |
6dd9e31c JS |
15430 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
15431 | ||
15432 | /* Respond with BA_ACC or BA_RJT accordingly */ | |
15433 | lpfc_sli4_seq_abort_rsp(vport, &fc_hdr, aborted); | |
6669f9bb JS |
15434 | } |
15435 | ||
4f774513 JS |
15436 | /** |
15437 | * lpfc_seq_complete - Indicates if a sequence is complete | |
15438 | * @dmabuf: pointer to a dmabuf that describes the FC sequence | |
15439 | * | |
15440 | * This function checks the sequence, starting with the frame described by | |
15441 | * @dmabuf, to see if all the frames associated with this sequence are present. | |
15442 | * the frames associated with this sequence are linked to the @dmabuf using the | |
15443 | * dbuf list. This function looks for two major things. 1) That the first frame | |
15444 | * has a sequence count of zero. 2) There is a frame with last frame of sequence | |
15445 | * set. 3) That there are no holes in the sequence count. The function will | |
15446 | * return 1 when the sequence is complete, otherwise it will return 0. | |
15447 | **/ | |
15448 | static int | |
15449 | lpfc_seq_complete(struct hbq_dmabuf *dmabuf) | |
15450 | { | |
15451 | struct fc_frame_header *hdr; | |
15452 | struct lpfc_dmabuf *d_buf; | |
15453 | struct hbq_dmabuf *seq_dmabuf; | |
15454 | uint32_t fctl; | |
15455 | int seq_count = 0; | |
15456 | ||
15457 | hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; | |
15458 | /* make sure first fame of sequence has a sequence count of zero */ | |
15459 | if (hdr->fh_seq_cnt != seq_count) | |
15460 | return 0; | |
15461 | fctl = (hdr->fh_f_ctl[0] << 16 | | |
15462 | hdr->fh_f_ctl[1] << 8 | | |
15463 | hdr->fh_f_ctl[2]); | |
15464 | /* If last frame of sequence we can return success. */ | |
15465 | if (fctl & FC_FC_END_SEQ) | |
15466 | return 1; | |
15467 | list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) { | |
15468 | seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf); | |
15469 | hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; | |
15470 | /* If there is a hole in the sequence count then fail. */ | |
eeead811 | 15471 | if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt)) |
4f774513 JS |
15472 | return 0; |
15473 | fctl = (hdr->fh_f_ctl[0] << 16 | | |
15474 | hdr->fh_f_ctl[1] << 8 | | |
15475 | hdr->fh_f_ctl[2]); | |
15476 | /* If last frame of sequence we can return success. */ | |
15477 | if (fctl & FC_FC_END_SEQ) | |
15478 | return 1; | |
15479 | } | |
15480 | return 0; | |
15481 | } | |
15482 | ||
15483 | /** | |
15484 | * lpfc_prep_seq - Prep sequence for ULP processing | |
15485 | * @vport: Pointer to the vport on which this sequence was received | |
15486 | * @dmabuf: pointer to a dmabuf that describes the FC sequence | |
15487 | * | |
15488 | * This function takes a sequence, described by a list of frames, and creates | |
15489 | * a list of iocbq structures to describe the sequence. This iocbq list will be | |
15490 | * used to issue to the generic unsolicited sequence handler. This routine | |
15491 | * returns a pointer to the first iocbq in the list. If the function is unable | |
15492 | * to allocate an iocbq then it throw out the received frames that were not | |
15493 | * able to be described and return a pointer to the first iocbq. If unable to | |
15494 | * allocate any iocbqs (including the first) this function will return NULL. | |
15495 | **/ | |
15496 | static struct lpfc_iocbq * | |
15497 | lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf) | |
15498 | { | |
7851fe2c | 15499 | struct hbq_dmabuf *hbq_buf; |
4f774513 JS |
15500 | struct lpfc_dmabuf *d_buf, *n_buf; |
15501 | struct lpfc_iocbq *first_iocbq, *iocbq; | |
15502 | struct fc_frame_header *fc_hdr; | |
15503 | uint32_t sid; | |
7851fe2c | 15504 | uint32_t len, tot_len; |
eeead811 | 15505 | struct ulp_bde64 *pbde; |
4f774513 JS |
15506 | |
15507 | fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; | |
15508 | /* remove from receive buffer list */ | |
15509 | list_del_init(&seq_dmabuf->hbuf.list); | |
45ed1190 | 15510 | lpfc_update_rcv_time_stamp(vport); |
4f774513 | 15511 | /* get the Remote Port's SID */ |
6669f9bb | 15512 | sid = sli4_sid_from_fc_hdr(fc_hdr); |
7851fe2c | 15513 | tot_len = 0; |
4f774513 JS |
15514 | /* Get an iocbq struct to fill in. */ |
15515 | first_iocbq = lpfc_sli_get_iocbq(vport->phba); | |
15516 | if (first_iocbq) { | |
15517 | /* Initialize the first IOCB. */ | |
8fa38513 | 15518 | first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0; |
4f774513 | 15519 | first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS; |
939723a4 JS |
15520 | |
15521 | /* Check FC Header to see what TYPE of frame we are rcv'ing */ | |
15522 | if (sli4_type_from_fc_hdr(fc_hdr) == FC_TYPE_ELS) { | |
15523 | first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_ELS64_CX; | |
15524 | first_iocbq->iocb.un.rcvels.parmRo = | |
15525 | sli4_did_from_fc_hdr(fc_hdr); | |
15526 | first_iocbq->iocb.ulpPU = PARM_NPIV_DID; | |
15527 | } else | |
15528 | first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX; | |
7851fe2c JS |
15529 | first_iocbq->iocb.ulpContext = NO_XRI; |
15530 | first_iocbq->iocb.unsli3.rcvsli3.ox_id = | |
15531 | be16_to_cpu(fc_hdr->fh_ox_id); | |
15532 | /* iocbq is prepped for internal consumption. Physical vpi. */ | |
15533 | first_iocbq->iocb.unsli3.rcvsli3.vpi = | |
15534 | vport->phba->vpi_ids[vport->vpi]; | |
4f774513 | 15535 | /* put the first buffer into the first IOCBq */ |
48a5a664 JS |
15536 | tot_len = bf_get(lpfc_rcqe_length, |
15537 | &seq_dmabuf->cq_event.cqe.rcqe_cmpl); | |
15538 | ||
4f774513 JS |
15539 | first_iocbq->context2 = &seq_dmabuf->dbuf; |
15540 | first_iocbq->context3 = NULL; | |
15541 | first_iocbq->iocb.ulpBdeCount = 1; | |
48a5a664 JS |
15542 | if (tot_len > LPFC_DATA_BUF_SIZE) |
15543 | first_iocbq->iocb.un.cont64[0].tus.f.bdeSize = | |
4f774513 | 15544 | LPFC_DATA_BUF_SIZE; |
48a5a664 JS |
15545 | else |
15546 | first_iocbq->iocb.un.cont64[0].tus.f.bdeSize = tot_len; | |
15547 | ||
4f774513 | 15548 | first_iocbq->iocb.un.rcvels.remoteID = sid; |
48a5a664 | 15549 | |
7851fe2c | 15550 | first_iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len; |
4f774513 JS |
15551 | } |
15552 | iocbq = first_iocbq; | |
15553 | /* | |
15554 | * Each IOCBq can have two Buffers assigned, so go through the list | |
15555 | * of buffers for this sequence and save two buffers in each IOCBq | |
15556 | */ | |
15557 | list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) { | |
15558 | if (!iocbq) { | |
15559 | lpfc_in_buf_free(vport->phba, d_buf); | |
15560 | continue; | |
15561 | } | |
15562 | if (!iocbq->context3) { | |
15563 | iocbq->context3 = d_buf; | |
15564 | iocbq->iocb.ulpBdeCount++; | |
7851fe2c JS |
15565 | /* We need to get the size out of the right CQE */ |
15566 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); | |
15567 | len = bf_get(lpfc_rcqe_length, | |
15568 | &hbq_buf->cq_event.cqe.rcqe_cmpl); | |
48a5a664 JS |
15569 | pbde = (struct ulp_bde64 *) |
15570 | &iocbq->iocb.unsli3.sli3Words[4]; | |
15571 | if (len > LPFC_DATA_BUF_SIZE) | |
15572 | pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE; | |
15573 | else | |
15574 | pbde->tus.f.bdeSize = len; | |
15575 | ||
7851fe2c JS |
15576 | iocbq->iocb.unsli3.rcvsli3.acc_len += len; |
15577 | tot_len += len; | |
4f774513 JS |
15578 | } else { |
15579 | iocbq = lpfc_sli_get_iocbq(vport->phba); | |
15580 | if (!iocbq) { | |
15581 | if (first_iocbq) { | |
15582 | first_iocbq->iocb.ulpStatus = | |
15583 | IOSTAT_FCP_RSP_ERROR; | |
15584 | first_iocbq->iocb.un.ulpWord[4] = | |
15585 | IOERR_NO_RESOURCES; | |
15586 | } | |
15587 | lpfc_in_buf_free(vport->phba, d_buf); | |
15588 | continue; | |
15589 | } | |
48a5a664 JS |
15590 | /* We need to get the size out of the right CQE */ |
15591 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); | |
15592 | len = bf_get(lpfc_rcqe_length, | |
15593 | &hbq_buf->cq_event.cqe.rcqe_cmpl); | |
4f774513 JS |
15594 | iocbq->context2 = d_buf; |
15595 | iocbq->context3 = NULL; | |
15596 | iocbq->iocb.ulpBdeCount = 1; | |
48a5a664 JS |
15597 | if (len > LPFC_DATA_BUF_SIZE) |
15598 | iocbq->iocb.un.cont64[0].tus.f.bdeSize = | |
4f774513 | 15599 | LPFC_DATA_BUF_SIZE; |
48a5a664 JS |
15600 | else |
15601 | iocbq->iocb.un.cont64[0].tus.f.bdeSize = len; | |
7851fe2c | 15602 | |
7851fe2c JS |
15603 | tot_len += len; |
15604 | iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len; | |
15605 | ||
4f774513 JS |
15606 | iocbq->iocb.un.rcvels.remoteID = sid; |
15607 | list_add_tail(&iocbq->list, &first_iocbq->list); | |
15608 | } | |
15609 | } | |
15610 | return first_iocbq; | |
15611 | } | |
15612 | ||
6669f9bb JS |
15613 | static void |
15614 | lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport, | |
15615 | struct hbq_dmabuf *seq_dmabuf) | |
15616 | { | |
15617 | struct fc_frame_header *fc_hdr; | |
15618 | struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb; | |
15619 | struct lpfc_hba *phba = vport->phba; | |
15620 | ||
15621 | fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; | |
15622 | iocbq = lpfc_prep_seq(vport, seq_dmabuf); | |
15623 | if (!iocbq) { | |
15624 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
15625 | "2707 Ring %d handler: Failed to allocate " | |
15626 | "iocb Rctl x%x Type x%x received\n", | |
15627 | LPFC_ELS_RING, | |
15628 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); | |
15629 | return; | |
15630 | } | |
15631 | if (!lpfc_complete_unsol_iocb(phba, | |
15632 | &phba->sli.ring[LPFC_ELS_RING], | |
15633 | iocbq, fc_hdr->fh_r_ctl, | |
15634 | fc_hdr->fh_type)) | |
6d368e53 | 15635 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
6669f9bb JS |
15636 | "2540 Ring %d handler: unexpected Rctl " |
15637 | "x%x Type x%x received\n", | |
15638 | LPFC_ELS_RING, | |
15639 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); | |
15640 | ||
15641 | /* Free iocb created in lpfc_prep_seq */ | |
15642 | list_for_each_entry_safe(curr_iocb, next_iocb, | |
15643 | &iocbq->list, list) { | |
15644 | list_del_init(&curr_iocb->list); | |
15645 | lpfc_sli_release_iocbq(phba, curr_iocb); | |
15646 | } | |
15647 | lpfc_sli_release_iocbq(phba, iocbq); | |
15648 | } | |
15649 | ||
4f774513 JS |
15650 | /** |
15651 | * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware | |
15652 | * @phba: Pointer to HBA context object. | |
15653 | * | |
15654 | * This function is called with no lock held. This function processes all | |
15655 | * the received buffers and gives it to upper layers when a received buffer | |
15656 | * indicates that it is the final frame in the sequence. The interrupt | |
15657 | * service routine processes received buffers at interrupt contexts and adds | |
15658 | * received dma buffers to the rb_pend_list queue and signals the worker thread. | |
15659 | * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the | |
15660 | * appropriate receive function when the final frame in a sequence is received. | |
15661 | **/ | |
4d9ab994 JS |
15662 | void |
15663 | lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba, | |
15664 | struct hbq_dmabuf *dmabuf) | |
4f774513 | 15665 | { |
4d9ab994 | 15666 | struct hbq_dmabuf *seq_dmabuf; |
4f774513 JS |
15667 | struct fc_frame_header *fc_hdr; |
15668 | struct lpfc_vport *vport; | |
15669 | uint32_t fcfi; | |
939723a4 | 15670 | uint32_t did; |
4f774513 | 15671 | |
4f774513 | 15672 | /* Process each received buffer */ |
4d9ab994 JS |
15673 | fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
15674 | /* check to see if this a valid type of frame */ | |
15675 | if (lpfc_fc_frame_check(phba, fc_hdr)) { | |
15676 | lpfc_in_buf_free(phba, &dmabuf->dbuf); | |
15677 | return; | |
15678 | } | |
7851fe2c JS |
15679 | if ((bf_get(lpfc_cqe_code, |
15680 | &dmabuf->cq_event.cqe.rcqe_cmpl) == CQE_CODE_RECEIVE_V1)) | |
15681 | fcfi = bf_get(lpfc_rcqe_fcf_id_v1, | |
15682 | &dmabuf->cq_event.cqe.rcqe_cmpl); | |
15683 | else | |
15684 | fcfi = bf_get(lpfc_rcqe_fcf_id, | |
15685 | &dmabuf->cq_event.cqe.rcqe_cmpl); | |
939723a4 | 15686 | |
4d9ab994 | 15687 | vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi); |
939723a4 | 15688 | if (!vport) { |
4d9ab994 JS |
15689 | /* throw out the frame */ |
15690 | lpfc_in_buf_free(phba, &dmabuf->dbuf); | |
15691 | return; | |
15692 | } | |
939723a4 JS |
15693 | |
15694 | /* d_id this frame is directed to */ | |
15695 | did = sli4_did_from_fc_hdr(fc_hdr); | |
15696 | ||
15697 | /* vport is registered unless we rcv a FLOGI directed to Fabric_DID */ | |
15698 | if (!(vport->vpi_state & LPFC_VPI_REGISTERED) && | |
15699 | (did != Fabric_DID)) { | |
15700 | /* | |
15701 | * Throw out the frame if we are not pt2pt. | |
15702 | * The pt2pt protocol allows for discovery frames | |
15703 | * to be received without a registered VPI. | |
15704 | */ | |
15705 | if (!(vport->fc_flag & FC_PT2PT) || | |
15706 | (phba->link_state == LPFC_HBA_READY)) { | |
15707 | lpfc_in_buf_free(phba, &dmabuf->dbuf); | |
15708 | return; | |
15709 | } | |
15710 | } | |
15711 | ||
6669f9bb JS |
15712 | /* Handle the basic abort sequence (BA_ABTS) event */ |
15713 | if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) { | |
15714 | lpfc_sli4_handle_unsol_abort(vport, dmabuf); | |
15715 | return; | |
15716 | } | |
15717 | ||
4d9ab994 JS |
15718 | /* Link this frame */ |
15719 | seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf); | |
15720 | if (!seq_dmabuf) { | |
15721 | /* unable to add frame to vport - throw it out */ | |
15722 | lpfc_in_buf_free(phba, &dmabuf->dbuf); | |
15723 | return; | |
15724 | } | |
15725 | /* If not last frame in sequence continue processing frames. */ | |
def9c7a9 | 15726 | if (!lpfc_seq_complete(seq_dmabuf)) |
4d9ab994 | 15727 | return; |
def9c7a9 | 15728 | |
6669f9bb JS |
15729 | /* Send the complete sequence to the upper layer protocol */ |
15730 | lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf); | |
4f774513 | 15731 | } |
6fb120a7 JS |
15732 | |
15733 | /** | |
15734 | * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port | |
15735 | * @phba: pointer to lpfc hba data structure. | |
15736 | * | |
15737 | * This routine is invoked to post rpi header templates to the | |
15738 | * HBA consistent with the SLI-4 interface spec. This routine | |
49198b37 JS |
15739 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
15740 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. | |
6fb120a7 JS |
15741 | * |
15742 | * This routine does not require any locks. It's usage is expected | |
15743 | * to be driver load or reset recovery when the driver is | |
15744 | * sequential. | |
15745 | * | |
15746 | * Return codes | |
af901ca1 | 15747 | * 0 - successful |
d439d286 | 15748 | * -EIO - The mailbox failed to complete successfully. |
6fb120a7 JS |
15749 | * When this error occurs, the driver is not guaranteed |
15750 | * to have any rpi regions posted to the device and | |
15751 | * must either attempt to repost the regions or take a | |
15752 | * fatal error. | |
15753 | **/ | |
15754 | int | |
15755 | lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba) | |
15756 | { | |
15757 | struct lpfc_rpi_hdr *rpi_page; | |
15758 | uint32_t rc = 0; | |
6d368e53 JS |
15759 | uint16_t lrpi = 0; |
15760 | ||
15761 | /* SLI4 ports that support extents do not require RPI headers. */ | |
15762 | if (!phba->sli4_hba.rpi_hdrs_in_use) | |
15763 | goto exit; | |
15764 | if (phba->sli4_hba.extents_in_use) | |
15765 | return -EIO; | |
6fb120a7 | 15766 | |
6fb120a7 | 15767 | list_for_each_entry(rpi_page, &phba->sli4_hba.lpfc_rpi_hdr_list, list) { |
6d368e53 JS |
15768 | /* |
15769 | * Assign the rpi headers a physical rpi only if the driver | |
15770 | * has not initialized those resources. A port reset only | |
15771 | * needs the headers posted. | |
15772 | */ | |
15773 | if (bf_get(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags) != | |
15774 | LPFC_RPI_RSRC_RDY) | |
15775 | rpi_page->start_rpi = phba->sli4_hba.rpi_ids[lrpi]; | |
15776 | ||
6fb120a7 JS |
15777 | rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page); |
15778 | if (rc != MBX_SUCCESS) { | |
15779 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
15780 | "2008 Error %d posting all rpi " | |
15781 | "headers\n", rc); | |
15782 | rc = -EIO; | |
15783 | break; | |
15784 | } | |
15785 | } | |
15786 | ||
6d368e53 JS |
15787 | exit: |
15788 | bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, | |
15789 | LPFC_RPI_RSRC_RDY); | |
6fb120a7 JS |
15790 | return rc; |
15791 | } | |
15792 | ||
15793 | /** | |
15794 | * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port | |
15795 | * @phba: pointer to lpfc hba data structure. | |
15796 | * @rpi_page: pointer to the rpi memory region. | |
15797 | * | |
15798 | * This routine is invoked to post a single rpi header to the | |
15799 | * HBA consistent with the SLI-4 interface spec. This memory region | |
15800 | * maps up to 64 rpi context regions. | |
15801 | * | |
15802 | * Return codes | |
af901ca1 | 15803 | * 0 - successful |
d439d286 JS |
15804 | * -ENOMEM - No available memory |
15805 | * -EIO - The mailbox failed to complete successfully. | |
6fb120a7 JS |
15806 | **/ |
15807 | int | |
15808 | lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page) | |
15809 | { | |
15810 | LPFC_MBOXQ_t *mboxq; | |
15811 | struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl; | |
15812 | uint32_t rc = 0; | |
6fb120a7 JS |
15813 | uint32_t shdr_status, shdr_add_status; |
15814 | union lpfc_sli4_cfg_shdr *shdr; | |
15815 | ||
6d368e53 JS |
15816 | /* SLI4 ports that support extents do not require RPI headers. */ |
15817 | if (!phba->sli4_hba.rpi_hdrs_in_use) | |
15818 | return rc; | |
15819 | if (phba->sli4_hba.extents_in_use) | |
15820 | return -EIO; | |
15821 | ||
6fb120a7 JS |
15822 | /* The port is notified of the header region via a mailbox command. */ |
15823 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
15824 | if (!mboxq) { | |
15825 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
15826 | "2001 Unable to allocate memory for issuing " | |
15827 | "SLI_CONFIG_SPECIAL mailbox command\n"); | |
15828 | return -ENOMEM; | |
15829 | } | |
15830 | ||
15831 | /* Post all rpi memory regions to the port. */ | |
15832 | hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl; | |
6fb120a7 JS |
15833 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, |
15834 | LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE, | |
15835 | sizeof(struct lpfc_mbx_post_hdr_tmpl) - | |
fedd3b7b JS |
15836 | sizeof(struct lpfc_sli4_cfg_mhdr), |
15837 | LPFC_SLI4_MBX_EMBED); | |
6d368e53 JS |
15838 | |
15839 | ||
15840 | /* Post the physical rpi to the port for this rpi header. */ | |
6fb120a7 JS |
15841 | bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl, |
15842 | rpi_page->start_rpi); | |
6d368e53 JS |
15843 | bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt, |
15844 | hdr_tmpl, rpi_page->page_count); | |
15845 | ||
6fb120a7 JS |
15846 | hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys); |
15847 | hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys); | |
f1126688 | 15848 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
6fb120a7 JS |
15849 | shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr; |
15850 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
15851 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
15852 | if (rc != MBX_TIMEOUT) | |
15853 | mempool_free(mboxq, phba->mbox_mem_pool); | |
15854 | if (shdr_status || shdr_add_status || rc) { | |
15855 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
15856 | "2514 POST_RPI_HDR mailbox failed with " | |
15857 | "status x%x add_status x%x, mbx status x%x\n", | |
15858 | shdr_status, shdr_add_status, rc); | |
15859 | rc = -ENXIO; | |
15860 | } | |
15861 | return rc; | |
15862 | } | |
15863 | ||
15864 | /** | |
15865 | * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range | |
15866 | * @phba: pointer to lpfc hba data structure. | |
15867 | * | |
15868 | * This routine is invoked to post rpi header templates to the | |
15869 | * HBA consistent with the SLI-4 interface spec. This routine | |
49198b37 JS |
15870 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
15871 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. | |
6fb120a7 JS |
15872 | * |
15873 | * Returns | |
af901ca1 | 15874 | * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful |
6fb120a7 JS |
15875 | * LPFC_RPI_ALLOC_ERROR if no rpis are available. |
15876 | **/ | |
15877 | int | |
15878 | lpfc_sli4_alloc_rpi(struct lpfc_hba *phba) | |
15879 | { | |
6d368e53 JS |
15880 | unsigned long rpi; |
15881 | uint16_t max_rpi, rpi_limit; | |
15882 | uint16_t rpi_remaining, lrpi = 0; | |
6fb120a7 | 15883 | struct lpfc_rpi_hdr *rpi_hdr; |
4902b381 | 15884 | unsigned long iflag; |
6fb120a7 | 15885 | |
6fb120a7 | 15886 | /* |
6d368e53 JS |
15887 | * Fetch the next logical rpi. Because this index is logical, |
15888 | * the driver starts at 0 each time. | |
6fb120a7 | 15889 | */ |
4902b381 | 15890 | spin_lock_irqsave(&phba->hbalock, iflag); |
be6bb941 JS |
15891 | max_rpi = phba->sli4_hba.max_cfg_param.max_rpi; |
15892 | rpi_limit = phba->sli4_hba.next_rpi; | |
15893 | ||
6d368e53 JS |
15894 | rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, 0); |
15895 | if (rpi >= rpi_limit) | |
6fb120a7 JS |
15896 | rpi = LPFC_RPI_ALLOC_ERROR; |
15897 | else { | |
15898 | set_bit(rpi, phba->sli4_hba.rpi_bmask); | |
15899 | phba->sli4_hba.max_cfg_param.rpi_used++; | |
15900 | phba->sli4_hba.rpi_count++; | |
15901 | } | |
be6bb941 JS |
15902 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
15903 | "0001 rpi:%x max:%x lim:%x\n", | |
15904 | (int) rpi, max_rpi, rpi_limit); | |
6fb120a7 JS |
15905 | |
15906 | /* | |
15907 | * Don't try to allocate more rpi header regions if the device limit | |
6d368e53 | 15908 | * has been exhausted. |
6fb120a7 JS |
15909 | */ |
15910 | if ((rpi == LPFC_RPI_ALLOC_ERROR) && | |
15911 | (phba->sli4_hba.rpi_count >= max_rpi)) { | |
4902b381 | 15912 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
6fb120a7 JS |
15913 | return rpi; |
15914 | } | |
15915 | ||
6d368e53 JS |
15916 | /* |
15917 | * RPI header postings are not required for SLI4 ports capable of | |
15918 | * extents. | |
15919 | */ | |
15920 | if (!phba->sli4_hba.rpi_hdrs_in_use) { | |
4902b381 | 15921 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
6d368e53 JS |
15922 | return rpi; |
15923 | } | |
15924 | ||
6fb120a7 JS |
15925 | /* |
15926 | * If the driver is running low on rpi resources, allocate another | |
15927 | * page now. Note that the next_rpi value is used because | |
15928 | * it represents how many are actually in use whereas max_rpi notes | |
15929 | * how many are supported max by the device. | |
15930 | */ | |
6d368e53 | 15931 | rpi_remaining = phba->sli4_hba.next_rpi - phba->sli4_hba.rpi_count; |
4902b381 | 15932 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
6fb120a7 JS |
15933 | if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) { |
15934 | rpi_hdr = lpfc_sli4_create_rpi_hdr(phba); | |
15935 | if (!rpi_hdr) { | |
15936 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
15937 | "2002 Error Could not grow rpi " | |
15938 | "count\n"); | |
15939 | } else { | |
6d368e53 JS |
15940 | lrpi = rpi_hdr->start_rpi; |
15941 | rpi_hdr->start_rpi = phba->sli4_hba.rpi_ids[lrpi]; | |
6fb120a7 JS |
15942 | lpfc_sli4_post_rpi_hdr(phba, rpi_hdr); |
15943 | } | |
15944 | } | |
15945 | ||
15946 | return rpi; | |
15947 | } | |
15948 | ||
d7c47992 JS |
15949 | /** |
15950 | * lpfc_sli4_free_rpi - Release an rpi for reuse. | |
15951 | * @phba: pointer to lpfc hba data structure. | |
15952 | * | |
15953 | * This routine is invoked to release an rpi to the pool of | |
15954 | * available rpis maintained by the driver. | |
15955 | **/ | |
5d8b8167 | 15956 | static void |
d7c47992 JS |
15957 | __lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi) |
15958 | { | |
15959 | if (test_and_clear_bit(rpi, phba->sli4_hba.rpi_bmask)) { | |
15960 | phba->sli4_hba.rpi_count--; | |
15961 | phba->sli4_hba.max_cfg_param.rpi_used--; | |
15962 | } | |
15963 | } | |
15964 | ||
6fb120a7 JS |
15965 | /** |
15966 | * lpfc_sli4_free_rpi - Release an rpi for reuse. | |
15967 | * @phba: pointer to lpfc hba data structure. | |
15968 | * | |
15969 | * This routine is invoked to release an rpi to the pool of | |
15970 | * available rpis maintained by the driver. | |
15971 | **/ | |
15972 | void | |
15973 | lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi) | |
15974 | { | |
15975 | spin_lock_irq(&phba->hbalock); | |
d7c47992 | 15976 | __lpfc_sli4_free_rpi(phba, rpi); |
6fb120a7 JS |
15977 | spin_unlock_irq(&phba->hbalock); |
15978 | } | |
15979 | ||
15980 | /** | |
15981 | * lpfc_sli4_remove_rpis - Remove the rpi bitmask region | |
15982 | * @phba: pointer to lpfc hba data structure. | |
15983 | * | |
15984 | * This routine is invoked to remove the memory region that | |
15985 | * provided rpi via a bitmask. | |
15986 | **/ | |
15987 | void | |
15988 | lpfc_sli4_remove_rpis(struct lpfc_hba *phba) | |
15989 | { | |
15990 | kfree(phba->sli4_hba.rpi_bmask); | |
6d368e53 JS |
15991 | kfree(phba->sli4_hba.rpi_ids); |
15992 | bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); | |
6fb120a7 JS |
15993 | } |
15994 | ||
15995 | /** | |
15996 | * lpfc_sli4_resume_rpi - Remove the rpi bitmask region | |
15997 | * @phba: pointer to lpfc hba data structure. | |
15998 | * | |
15999 | * This routine is invoked to remove the memory region that | |
16000 | * provided rpi via a bitmask. | |
16001 | **/ | |
16002 | int | |
6b5151fd JS |
16003 | lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp, |
16004 | void (*cmpl)(struct lpfc_hba *, LPFC_MBOXQ_t *), void *arg) | |
6fb120a7 JS |
16005 | { |
16006 | LPFC_MBOXQ_t *mboxq; | |
16007 | struct lpfc_hba *phba = ndlp->phba; | |
16008 | int rc; | |
16009 | ||
16010 | /* The port is notified of the header region via a mailbox command. */ | |
16011 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
16012 | if (!mboxq) | |
16013 | return -ENOMEM; | |
16014 | ||
16015 | /* Post all rpi memory regions to the port. */ | |
16016 | lpfc_resume_rpi(mboxq, ndlp); | |
6b5151fd JS |
16017 | if (cmpl) { |
16018 | mboxq->mbox_cmpl = cmpl; | |
16019 | mboxq->context1 = arg; | |
16020 | mboxq->context2 = ndlp; | |
72859909 JS |
16021 | } else |
16022 | mboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
6b5151fd | 16023 | mboxq->vport = ndlp->vport; |
6fb120a7 JS |
16024 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
16025 | if (rc == MBX_NOT_FINISHED) { | |
16026 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
16027 | "2010 Resume RPI Mailbox failed " | |
16028 | "status %d, mbxStatus x%x\n", rc, | |
16029 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); | |
16030 | mempool_free(mboxq, phba->mbox_mem_pool); | |
16031 | return -EIO; | |
16032 | } | |
16033 | return 0; | |
16034 | } | |
16035 | ||
16036 | /** | |
16037 | * lpfc_sli4_init_vpi - Initialize a vpi with the port | |
76a95d75 | 16038 | * @vport: Pointer to the vport for which the vpi is being initialized |
6fb120a7 | 16039 | * |
76a95d75 | 16040 | * This routine is invoked to activate a vpi with the port. |
6fb120a7 JS |
16041 | * |
16042 | * Returns: | |
16043 | * 0 success | |
16044 | * -Evalue otherwise | |
16045 | **/ | |
16046 | int | |
76a95d75 | 16047 | lpfc_sli4_init_vpi(struct lpfc_vport *vport) |
6fb120a7 JS |
16048 | { |
16049 | LPFC_MBOXQ_t *mboxq; | |
16050 | int rc = 0; | |
6a9c52cf | 16051 | int retval = MBX_SUCCESS; |
6fb120a7 | 16052 | uint32_t mbox_tmo; |
76a95d75 | 16053 | struct lpfc_hba *phba = vport->phba; |
6fb120a7 JS |
16054 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
16055 | if (!mboxq) | |
16056 | return -ENOMEM; | |
76a95d75 | 16057 | lpfc_init_vpi(phba, mboxq, vport->vpi); |
a183a15f | 16058 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); |
6fb120a7 | 16059 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); |
6fb120a7 | 16060 | if (rc != MBX_SUCCESS) { |
76a95d75 | 16061 | lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI, |
6fb120a7 JS |
16062 | "2022 INIT VPI Mailbox failed " |
16063 | "status %d, mbxStatus x%x\n", rc, | |
16064 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); | |
6a9c52cf | 16065 | retval = -EIO; |
6fb120a7 | 16066 | } |
6a9c52cf | 16067 | if (rc != MBX_TIMEOUT) |
76a95d75 | 16068 | mempool_free(mboxq, vport->phba->mbox_mem_pool); |
6a9c52cf JS |
16069 | |
16070 | return retval; | |
6fb120a7 JS |
16071 | } |
16072 | ||
16073 | /** | |
16074 | * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler. | |
16075 | * @phba: pointer to lpfc hba data structure. | |
16076 | * @mboxq: Pointer to mailbox object. | |
16077 | * | |
16078 | * This routine is invoked to manually add a single FCF record. The caller | |
16079 | * must pass a completely initialized FCF_Record. This routine takes | |
16080 | * care of the nonembedded mailbox operations. | |
16081 | **/ | |
16082 | static void | |
16083 | lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) | |
16084 | { | |
16085 | void *virt_addr; | |
16086 | union lpfc_sli4_cfg_shdr *shdr; | |
16087 | uint32_t shdr_status, shdr_add_status; | |
16088 | ||
16089 | virt_addr = mboxq->sge_array->addr[0]; | |
16090 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
16091 | shdr = (union lpfc_sli4_cfg_shdr *) virt_addr; | |
16092 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
16093 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
16094 | ||
16095 | if ((shdr_status || shdr_add_status) && | |
16096 | (shdr_status != STATUS_FCF_IN_USE)) | |
16097 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
16098 | "2558 ADD_FCF_RECORD mailbox failed with " | |
16099 | "status x%x add_status x%x\n", | |
16100 | shdr_status, shdr_add_status); | |
16101 | ||
16102 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
16103 | } | |
16104 | ||
16105 | /** | |
16106 | * lpfc_sli4_add_fcf_record - Manually add an FCF Record. | |
16107 | * @phba: pointer to lpfc hba data structure. | |
16108 | * @fcf_record: pointer to the initialized fcf record to add. | |
16109 | * | |
16110 | * This routine is invoked to manually add a single FCF record. The caller | |
16111 | * must pass a completely initialized FCF_Record. This routine takes | |
16112 | * care of the nonembedded mailbox operations. | |
16113 | **/ | |
16114 | int | |
16115 | lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record) | |
16116 | { | |
16117 | int rc = 0; | |
16118 | LPFC_MBOXQ_t *mboxq; | |
16119 | uint8_t *bytep; | |
16120 | void *virt_addr; | |
6fb120a7 JS |
16121 | struct lpfc_mbx_sge sge; |
16122 | uint32_t alloc_len, req_len; | |
16123 | uint32_t fcfindex; | |
16124 | ||
16125 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
16126 | if (!mboxq) { | |
16127 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
16128 | "2009 Failed to allocate mbox for ADD_FCF cmd\n"); | |
16129 | return -ENOMEM; | |
16130 | } | |
16131 | ||
16132 | req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) + | |
16133 | sizeof(uint32_t); | |
16134 | ||
16135 | /* Allocate DMA memory and set up the non-embedded mailbox command */ | |
16136 | alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, | |
16137 | LPFC_MBOX_OPCODE_FCOE_ADD_FCF, | |
16138 | req_len, LPFC_SLI4_MBX_NEMBED); | |
16139 | if (alloc_len < req_len) { | |
16140 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
16141 | "2523 Allocated DMA memory size (x%x) is " | |
16142 | "less than the requested DMA memory " | |
16143 | "size (x%x)\n", alloc_len, req_len); | |
16144 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
16145 | return -ENOMEM; | |
16146 | } | |
16147 | ||
16148 | /* | |
16149 | * Get the first SGE entry from the non-embedded DMA memory. This | |
16150 | * routine only uses a single SGE. | |
16151 | */ | |
16152 | lpfc_sli4_mbx_sge_get(mboxq, 0, &sge); | |
6fb120a7 JS |
16153 | virt_addr = mboxq->sge_array->addr[0]; |
16154 | /* | |
16155 | * Configure the FCF record for FCFI 0. This is the driver's | |
16156 | * hardcoded default and gets used in nonFIP mode. | |
16157 | */ | |
16158 | fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record); | |
16159 | bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr); | |
16160 | lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t)); | |
16161 | ||
16162 | /* | |
16163 | * Copy the fcf_index and the FCF Record Data. The data starts after | |
16164 | * the FCoE header plus word10. The data copy needs to be endian | |
16165 | * correct. | |
16166 | */ | |
16167 | bytep += sizeof(uint32_t); | |
16168 | lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record)); | |
16169 | mboxq->vport = phba->pport; | |
16170 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record; | |
16171 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); | |
16172 | if (rc == MBX_NOT_FINISHED) { | |
16173 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
16174 | "2515 ADD_FCF_RECORD mailbox failed with " | |
16175 | "status 0x%x\n", rc); | |
16176 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
16177 | rc = -EIO; | |
16178 | } else | |
16179 | rc = 0; | |
16180 | ||
16181 | return rc; | |
16182 | } | |
16183 | ||
16184 | /** | |
16185 | * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record. | |
16186 | * @phba: pointer to lpfc hba data structure. | |
16187 | * @fcf_record: pointer to the fcf record to write the default data. | |
16188 | * @fcf_index: FCF table entry index. | |
16189 | * | |
16190 | * This routine is invoked to build the driver's default FCF record. The | |
16191 | * values used are hardcoded. This routine handles memory initialization. | |
16192 | * | |
16193 | **/ | |
16194 | void | |
16195 | lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba, | |
16196 | struct fcf_record *fcf_record, | |
16197 | uint16_t fcf_index) | |
16198 | { | |
16199 | memset(fcf_record, 0, sizeof(struct fcf_record)); | |
16200 | fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE; | |
16201 | fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER; | |
16202 | fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY; | |
16203 | bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]); | |
16204 | bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]); | |
16205 | bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]); | |
16206 | bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3); | |
16207 | bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4); | |
16208 | bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5); | |
16209 | bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]); | |
16210 | bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]); | |
16211 | bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]); | |
16212 | bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1); | |
0c287589 | 16213 | bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1); |
6fb120a7 JS |
16214 | bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index); |
16215 | bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record, | |
16216 | LPFC_FCF_FPMA | LPFC_FCF_SPMA); | |
16217 | /* Set the VLAN bit map */ | |
16218 | if (phba->valid_vlan) { | |
16219 | fcf_record->vlan_bitmap[phba->vlan_id / 8] | |
16220 | = 1 << (phba->vlan_id % 8); | |
16221 | } | |
16222 | } | |
16223 | ||
16224 | /** | |
0c9ab6f5 | 16225 | * lpfc_sli4_fcf_scan_read_fcf_rec - Read hba fcf record for fcf scan. |
6fb120a7 JS |
16226 | * @phba: pointer to lpfc hba data structure. |
16227 | * @fcf_index: FCF table entry offset. | |
16228 | * | |
0c9ab6f5 JS |
16229 | * This routine is invoked to scan the entire FCF table by reading FCF |
16230 | * record and processing it one at a time starting from the @fcf_index | |
16231 | * for initial FCF discovery or fast FCF failover rediscovery. | |
16232 | * | |
25985edc | 16233 | * Return 0 if the mailbox command is submitted successfully, none 0 |
0c9ab6f5 | 16234 | * otherwise. |
6fb120a7 JS |
16235 | **/ |
16236 | int | |
0c9ab6f5 | 16237 | lpfc_sli4_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) |
6fb120a7 JS |
16238 | { |
16239 | int rc = 0, error; | |
16240 | LPFC_MBOXQ_t *mboxq; | |
6fb120a7 | 16241 | |
32b9793f | 16242 | phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag; |
80c17849 | 16243 | phba->fcoe_cvl_eventtag_attn = phba->fcoe_cvl_eventtag; |
6fb120a7 JS |
16244 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
16245 | if (!mboxq) { | |
16246 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
16247 | "2000 Failed to allocate mbox for " | |
16248 | "READ_FCF cmd\n"); | |
4d9ab994 | 16249 | error = -ENOMEM; |
0c9ab6f5 | 16250 | goto fail_fcf_scan; |
6fb120a7 | 16251 | } |
ecfd03c6 | 16252 | /* Construct the read FCF record mailbox command */ |
0c9ab6f5 | 16253 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
ecfd03c6 JS |
16254 | if (rc) { |
16255 | error = -EINVAL; | |
0c9ab6f5 | 16256 | goto fail_fcf_scan; |
6fb120a7 | 16257 | } |
ecfd03c6 | 16258 | /* Issue the mailbox command asynchronously */ |
6fb120a7 | 16259 | mboxq->vport = phba->pport; |
0c9ab6f5 | 16260 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec; |
a93ff37a JS |
16261 | |
16262 | spin_lock_irq(&phba->hbalock); | |
16263 | phba->hba_flag |= FCF_TS_INPROG; | |
16264 | spin_unlock_irq(&phba->hbalock); | |
16265 | ||
6fb120a7 | 16266 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
ecfd03c6 | 16267 | if (rc == MBX_NOT_FINISHED) |
6fb120a7 | 16268 | error = -EIO; |
ecfd03c6 | 16269 | else { |
38b92ef8 JS |
16270 | /* Reset eligible FCF count for new scan */ |
16271 | if (fcf_index == LPFC_FCOE_FCF_GET_FIRST) | |
999d813f | 16272 | phba->fcf.eligible_fcf_cnt = 0; |
6fb120a7 | 16273 | error = 0; |
32b9793f | 16274 | } |
0c9ab6f5 | 16275 | fail_fcf_scan: |
4d9ab994 JS |
16276 | if (error) { |
16277 | if (mboxq) | |
16278 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
a93ff37a | 16279 | /* FCF scan failed, clear FCF_TS_INPROG flag */ |
4d9ab994 | 16280 | spin_lock_irq(&phba->hbalock); |
a93ff37a | 16281 | phba->hba_flag &= ~FCF_TS_INPROG; |
4d9ab994 JS |
16282 | spin_unlock_irq(&phba->hbalock); |
16283 | } | |
6fb120a7 JS |
16284 | return error; |
16285 | } | |
a0c87cbd | 16286 | |
0c9ab6f5 | 16287 | /** |
a93ff37a | 16288 | * lpfc_sli4_fcf_rr_read_fcf_rec - Read hba fcf record for roundrobin fcf. |
0c9ab6f5 JS |
16289 | * @phba: pointer to lpfc hba data structure. |
16290 | * @fcf_index: FCF table entry offset. | |
16291 | * | |
16292 | * This routine is invoked to read an FCF record indicated by @fcf_index | |
a93ff37a | 16293 | * and to use it for FLOGI roundrobin FCF failover. |
0c9ab6f5 | 16294 | * |
25985edc | 16295 | * Return 0 if the mailbox command is submitted successfully, none 0 |
0c9ab6f5 JS |
16296 | * otherwise. |
16297 | **/ | |
16298 | int | |
16299 | lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) | |
16300 | { | |
16301 | int rc = 0, error; | |
16302 | LPFC_MBOXQ_t *mboxq; | |
16303 | ||
16304 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
16305 | if (!mboxq) { | |
16306 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT, | |
16307 | "2763 Failed to allocate mbox for " | |
16308 | "READ_FCF cmd\n"); | |
16309 | error = -ENOMEM; | |
16310 | goto fail_fcf_read; | |
16311 | } | |
16312 | /* Construct the read FCF record mailbox command */ | |
16313 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); | |
16314 | if (rc) { | |
16315 | error = -EINVAL; | |
16316 | goto fail_fcf_read; | |
16317 | } | |
16318 | /* Issue the mailbox command asynchronously */ | |
16319 | mboxq->vport = phba->pport; | |
16320 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec; | |
16321 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); | |
16322 | if (rc == MBX_NOT_FINISHED) | |
16323 | error = -EIO; | |
16324 | else | |
16325 | error = 0; | |
16326 | ||
16327 | fail_fcf_read: | |
16328 | if (error && mboxq) | |
16329 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
16330 | return error; | |
16331 | } | |
16332 | ||
16333 | /** | |
16334 | * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask. | |
16335 | * @phba: pointer to lpfc hba data structure. | |
16336 | * @fcf_index: FCF table entry offset. | |
16337 | * | |
16338 | * This routine is invoked to read an FCF record indicated by @fcf_index to | |
a93ff37a | 16339 | * determine whether it's eligible for FLOGI roundrobin failover list. |
0c9ab6f5 | 16340 | * |
25985edc | 16341 | * Return 0 if the mailbox command is submitted successfully, none 0 |
0c9ab6f5 JS |
16342 | * otherwise. |
16343 | **/ | |
16344 | int | |
16345 | lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) | |
16346 | { | |
16347 | int rc = 0, error; | |
16348 | LPFC_MBOXQ_t *mboxq; | |
16349 | ||
16350 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
16351 | if (!mboxq) { | |
16352 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT, | |
16353 | "2758 Failed to allocate mbox for " | |
16354 | "READ_FCF cmd\n"); | |
16355 | error = -ENOMEM; | |
16356 | goto fail_fcf_read; | |
16357 | } | |
16358 | /* Construct the read FCF record mailbox command */ | |
16359 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); | |
16360 | if (rc) { | |
16361 | error = -EINVAL; | |
16362 | goto fail_fcf_read; | |
16363 | } | |
16364 | /* Issue the mailbox command asynchronously */ | |
16365 | mboxq->vport = phba->pport; | |
16366 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec; | |
16367 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); | |
16368 | if (rc == MBX_NOT_FINISHED) | |
16369 | error = -EIO; | |
16370 | else | |
16371 | error = 0; | |
16372 | ||
16373 | fail_fcf_read: | |
16374 | if (error && mboxq) | |
16375 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
16376 | return error; | |
16377 | } | |
16378 | ||
7d791df7 | 16379 | /** |
f5cb5304 | 16380 | * lpfc_check_next_fcf_pri_level |
7d791df7 JS |
16381 | * phba pointer to the lpfc_hba struct for this port. |
16382 | * This routine is called from the lpfc_sli4_fcf_rr_next_index_get | |
16383 | * routine when the rr_bmask is empty. The FCF indecies are put into the | |
16384 | * rr_bmask based on their priority level. Starting from the highest priority | |
16385 | * to the lowest. The most likely FCF candidate will be in the highest | |
16386 | * priority group. When this routine is called it searches the fcf_pri list for | |
16387 | * next lowest priority group and repopulates the rr_bmask with only those | |
16388 | * fcf_indexes. | |
16389 | * returns: | |
16390 | * 1=success 0=failure | |
16391 | **/ | |
5d8b8167 | 16392 | static int |
7d791df7 JS |
16393 | lpfc_check_next_fcf_pri_level(struct lpfc_hba *phba) |
16394 | { | |
16395 | uint16_t next_fcf_pri; | |
16396 | uint16_t last_index; | |
16397 | struct lpfc_fcf_pri *fcf_pri; | |
16398 | int rc; | |
16399 | int ret = 0; | |
16400 | ||
16401 | last_index = find_first_bit(phba->fcf.fcf_rr_bmask, | |
16402 | LPFC_SLI4_FCF_TBL_INDX_MAX); | |
16403 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, | |
16404 | "3060 Last IDX %d\n", last_index); | |
2562669c JS |
16405 | |
16406 | /* Verify the priority list has 2 or more entries */ | |
16407 | spin_lock_irq(&phba->hbalock); | |
16408 | if (list_empty(&phba->fcf.fcf_pri_list) || | |
16409 | list_is_singular(&phba->fcf.fcf_pri_list)) { | |
16410 | spin_unlock_irq(&phba->hbalock); | |
7d791df7 JS |
16411 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
16412 | "3061 Last IDX %d\n", last_index); | |
16413 | return 0; /* Empty rr list */ | |
16414 | } | |
2562669c JS |
16415 | spin_unlock_irq(&phba->hbalock); |
16416 | ||
7d791df7 JS |
16417 | next_fcf_pri = 0; |
16418 | /* | |
16419 | * Clear the rr_bmask and set all of the bits that are at this | |
16420 | * priority. | |
16421 | */ | |
16422 | memset(phba->fcf.fcf_rr_bmask, 0, | |
16423 | sizeof(*phba->fcf.fcf_rr_bmask)); | |
16424 | spin_lock_irq(&phba->hbalock); | |
16425 | list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) { | |
16426 | if (fcf_pri->fcf_rec.flag & LPFC_FCF_FLOGI_FAILED) | |
16427 | continue; | |
16428 | /* | |
16429 | * the 1st priority that has not FLOGI failed | |
16430 | * will be the highest. | |
16431 | */ | |
16432 | if (!next_fcf_pri) | |
16433 | next_fcf_pri = fcf_pri->fcf_rec.priority; | |
16434 | spin_unlock_irq(&phba->hbalock); | |
16435 | if (fcf_pri->fcf_rec.priority == next_fcf_pri) { | |
16436 | rc = lpfc_sli4_fcf_rr_index_set(phba, | |
16437 | fcf_pri->fcf_rec.fcf_index); | |
16438 | if (rc) | |
16439 | return 0; | |
16440 | } | |
16441 | spin_lock_irq(&phba->hbalock); | |
16442 | } | |
16443 | /* | |
16444 | * if next_fcf_pri was not set above and the list is not empty then | |
16445 | * we have failed flogis on all of them. So reset flogi failed | |
4907cb7b | 16446 | * and start at the beginning. |
7d791df7 JS |
16447 | */ |
16448 | if (!next_fcf_pri && !list_empty(&phba->fcf.fcf_pri_list)) { | |
16449 | list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) { | |
16450 | fcf_pri->fcf_rec.flag &= ~LPFC_FCF_FLOGI_FAILED; | |
16451 | /* | |
16452 | * the 1st priority that has not FLOGI failed | |
16453 | * will be the highest. | |
16454 | */ | |
16455 | if (!next_fcf_pri) | |
16456 | next_fcf_pri = fcf_pri->fcf_rec.priority; | |
16457 | spin_unlock_irq(&phba->hbalock); | |
16458 | if (fcf_pri->fcf_rec.priority == next_fcf_pri) { | |
16459 | rc = lpfc_sli4_fcf_rr_index_set(phba, | |
16460 | fcf_pri->fcf_rec.fcf_index); | |
16461 | if (rc) | |
16462 | return 0; | |
16463 | } | |
16464 | spin_lock_irq(&phba->hbalock); | |
16465 | } | |
16466 | } else | |
16467 | ret = 1; | |
16468 | spin_unlock_irq(&phba->hbalock); | |
16469 | ||
16470 | return ret; | |
16471 | } | |
0c9ab6f5 JS |
16472 | /** |
16473 | * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index | |
16474 | * @phba: pointer to lpfc hba data structure. | |
16475 | * | |
16476 | * This routine is to get the next eligible FCF record index in a round | |
16477 | * robin fashion. If the next eligible FCF record index equals to the | |
a93ff37a | 16478 | * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF) |
0c9ab6f5 JS |
16479 | * shall be returned, otherwise, the next eligible FCF record's index |
16480 | * shall be returned. | |
16481 | **/ | |
16482 | uint16_t | |
16483 | lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba) | |
16484 | { | |
16485 | uint16_t next_fcf_index; | |
16486 | ||
421c6622 | 16487 | initial_priority: |
3804dc84 | 16488 | /* Search start from next bit of currently registered FCF index */ |
421c6622 JS |
16489 | next_fcf_index = phba->fcf.current_rec.fcf_indx; |
16490 | ||
7d791df7 | 16491 | next_priority: |
421c6622 JS |
16492 | /* Determine the next fcf index to check */ |
16493 | next_fcf_index = (next_fcf_index + 1) % LPFC_SLI4_FCF_TBL_INDX_MAX; | |
0c9ab6f5 JS |
16494 | next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask, |
16495 | LPFC_SLI4_FCF_TBL_INDX_MAX, | |
3804dc84 JS |
16496 | next_fcf_index); |
16497 | ||
0c9ab6f5 | 16498 | /* Wrap around condition on phba->fcf.fcf_rr_bmask */ |
7d791df7 JS |
16499 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
16500 | /* | |
16501 | * If we have wrapped then we need to clear the bits that | |
16502 | * have been tested so that we can detect when we should | |
16503 | * change the priority level. | |
16504 | */ | |
0c9ab6f5 JS |
16505 | next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask, |
16506 | LPFC_SLI4_FCF_TBL_INDX_MAX, 0); | |
7d791df7 JS |
16507 | } |
16508 | ||
3804dc84 JS |
16509 | |
16510 | /* Check roundrobin failover list empty condition */ | |
7d791df7 JS |
16511 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX || |
16512 | next_fcf_index == phba->fcf.current_rec.fcf_indx) { | |
16513 | /* | |
16514 | * If next fcf index is not found check if there are lower | |
16515 | * Priority level fcf's in the fcf_priority list. | |
16516 | * Set up the rr_bmask with all of the avaiable fcf bits | |
16517 | * at that level and continue the selection process. | |
16518 | */ | |
16519 | if (lpfc_check_next_fcf_pri_level(phba)) | |
421c6622 | 16520 | goto initial_priority; |
3804dc84 JS |
16521 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
16522 | "2844 No roundrobin failover FCF available\n"); | |
7d791df7 JS |
16523 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) |
16524 | return LPFC_FCOE_FCF_NEXT_NONE; | |
16525 | else { | |
16526 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, | |
16527 | "3063 Only FCF available idx %d, flag %x\n", | |
16528 | next_fcf_index, | |
16529 | phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag); | |
16530 | return next_fcf_index; | |
16531 | } | |
3804dc84 JS |
16532 | } |
16533 | ||
7d791df7 JS |
16534 | if (next_fcf_index < LPFC_SLI4_FCF_TBL_INDX_MAX && |
16535 | phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag & | |
f5cb5304 JS |
16536 | LPFC_FCF_FLOGI_FAILED) { |
16537 | if (list_is_singular(&phba->fcf.fcf_pri_list)) | |
16538 | return LPFC_FCOE_FCF_NEXT_NONE; | |
16539 | ||
7d791df7 | 16540 | goto next_priority; |
f5cb5304 | 16541 | } |
7d791df7 | 16542 | |
3804dc84 | 16543 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
a93ff37a JS |
16544 | "2845 Get next roundrobin failover FCF (x%x)\n", |
16545 | next_fcf_index); | |
16546 | ||
0c9ab6f5 JS |
16547 | return next_fcf_index; |
16548 | } | |
16549 | ||
16550 | /** | |
16551 | * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index | |
16552 | * @phba: pointer to lpfc hba data structure. | |
16553 | * | |
16554 | * This routine sets the FCF record index in to the eligible bmask for | |
a93ff37a | 16555 | * roundrobin failover search. It checks to make sure that the index |
0c9ab6f5 JS |
16556 | * does not go beyond the range of the driver allocated bmask dimension |
16557 | * before setting the bit. | |
16558 | * | |
16559 | * Returns 0 if the index bit successfully set, otherwise, it returns | |
16560 | * -EINVAL. | |
16561 | **/ | |
16562 | int | |
16563 | lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index) | |
16564 | { | |
16565 | if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { | |
16566 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, | |
a93ff37a JS |
16567 | "2610 FCF (x%x) reached driver's book " |
16568 | "keeping dimension:x%x\n", | |
0c9ab6f5 JS |
16569 | fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX); |
16570 | return -EINVAL; | |
16571 | } | |
16572 | /* Set the eligible FCF record index bmask */ | |
16573 | set_bit(fcf_index, phba->fcf.fcf_rr_bmask); | |
16574 | ||
3804dc84 | 16575 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
a93ff37a | 16576 | "2790 Set FCF (x%x) to roundrobin FCF failover " |
3804dc84 JS |
16577 | "bmask\n", fcf_index); |
16578 | ||
0c9ab6f5 JS |
16579 | return 0; |
16580 | } | |
16581 | ||
16582 | /** | |
3804dc84 | 16583 | * lpfc_sli4_fcf_rr_index_clear - Clear bmask from eligible fcf record index |
0c9ab6f5 JS |
16584 | * @phba: pointer to lpfc hba data structure. |
16585 | * | |
16586 | * This routine clears the FCF record index from the eligible bmask for | |
a93ff37a | 16587 | * roundrobin failover search. It checks to make sure that the index |
0c9ab6f5 JS |
16588 | * does not go beyond the range of the driver allocated bmask dimension |
16589 | * before clearing the bit. | |
16590 | **/ | |
16591 | void | |
16592 | lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index) | |
16593 | { | |
9a803a74 | 16594 | struct lpfc_fcf_pri *fcf_pri, *fcf_pri_next; |
0c9ab6f5 JS |
16595 | if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
16596 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, | |
a93ff37a JS |
16597 | "2762 FCF (x%x) reached driver's book " |
16598 | "keeping dimension:x%x\n", | |
0c9ab6f5 JS |
16599 | fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX); |
16600 | return; | |
16601 | } | |
16602 | /* Clear the eligible FCF record index bmask */ | |
7d791df7 | 16603 | spin_lock_irq(&phba->hbalock); |
9a803a74 JS |
16604 | list_for_each_entry_safe(fcf_pri, fcf_pri_next, &phba->fcf.fcf_pri_list, |
16605 | list) { | |
7d791df7 JS |
16606 | if (fcf_pri->fcf_rec.fcf_index == fcf_index) { |
16607 | list_del_init(&fcf_pri->list); | |
16608 | break; | |
16609 | } | |
16610 | } | |
16611 | spin_unlock_irq(&phba->hbalock); | |
0c9ab6f5 | 16612 | clear_bit(fcf_index, phba->fcf.fcf_rr_bmask); |
3804dc84 JS |
16613 | |
16614 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, | |
a93ff37a | 16615 | "2791 Clear FCF (x%x) from roundrobin failover " |
3804dc84 | 16616 | "bmask\n", fcf_index); |
0c9ab6f5 JS |
16617 | } |
16618 | ||
ecfd03c6 JS |
16619 | /** |
16620 | * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table | |
16621 | * @phba: pointer to lpfc hba data structure. | |
16622 | * | |
16623 | * This routine is the completion routine for the rediscover FCF table mailbox | |
16624 | * command. If the mailbox command returned failure, it will try to stop the | |
16625 | * FCF rediscover wait timer. | |
16626 | **/ | |
5d8b8167 | 16627 | static void |
ecfd03c6 JS |
16628 | lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox) |
16629 | { | |
16630 | struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf; | |
16631 | uint32_t shdr_status, shdr_add_status; | |
16632 | ||
16633 | redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl; | |
16634 | ||
16635 | shdr_status = bf_get(lpfc_mbox_hdr_status, | |
16636 | &redisc_fcf->header.cfg_shdr.response); | |
16637 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, | |
16638 | &redisc_fcf->header.cfg_shdr.response); | |
16639 | if (shdr_status || shdr_add_status) { | |
0c9ab6f5 | 16640 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
ecfd03c6 JS |
16641 | "2746 Requesting for FCF rediscovery failed " |
16642 | "status x%x add_status x%x\n", | |
16643 | shdr_status, shdr_add_status); | |
0c9ab6f5 | 16644 | if (phba->fcf.fcf_flag & FCF_ACVL_DISC) { |
fc2b989b | 16645 | spin_lock_irq(&phba->hbalock); |
0c9ab6f5 | 16646 | phba->fcf.fcf_flag &= ~FCF_ACVL_DISC; |
fc2b989b JS |
16647 | spin_unlock_irq(&phba->hbalock); |
16648 | /* | |
16649 | * CVL event triggered FCF rediscover request failed, | |
16650 | * last resort to re-try current registered FCF entry. | |
16651 | */ | |
16652 | lpfc_retry_pport_discovery(phba); | |
16653 | } else { | |
16654 | spin_lock_irq(&phba->hbalock); | |
0c9ab6f5 | 16655 | phba->fcf.fcf_flag &= ~FCF_DEAD_DISC; |
fc2b989b JS |
16656 | spin_unlock_irq(&phba->hbalock); |
16657 | /* | |
16658 | * DEAD FCF event triggered FCF rediscover request | |
16659 | * failed, last resort to fail over as a link down | |
16660 | * to FCF registration. | |
16661 | */ | |
16662 | lpfc_sli4_fcf_dead_failthrough(phba); | |
16663 | } | |
0c9ab6f5 JS |
16664 | } else { |
16665 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, | |
a93ff37a | 16666 | "2775 Start FCF rediscover quiescent timer\n"); |
ecfd03c6 JS |
16667 | /* |
16668 | * Start FCF rediscovery wait timer for pending FCF | |
16669 | * before rescan FCF record table. | |
16670 | */ | |
16671 | lpfc_fcf_redisc_wait_start_timer(phba); | |
0c9ab6f5 | 16672 | } |
ecfd03c6 JS |
16673 | |
16674 | mempool_free(mbox, phba->mbox_mem_pool); | |
16675 | } | |
16676 | ||
16677 | /** | |
3804dc84 | 16678 | * lpfc_sli4_redisc_fcf_table - Request to rediscover entire FCF table by port. |
ecfd03c6 JS |
16679 | * @phba: pointer to lpfc hba data structure. |
16680 | * | |
16681 | * This routine is invoked to request for rediscovery of the entire FCF table | |
16682 | * by the port. | |
16683 | **/ | |
16684 | int | |
16685 | lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba) | |
16686 | { | |
16687 | LPFC_MBOXQ_t *mbox; | |
16688 | struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf; | |
16689 | int rc, length; | |
16690 | ||
0c9ab6f5 JS |
16691 | /* Cancel retry delay timers to all vports before FCF rediscover */ |
16692 | lpfc_cancel_all_vport_retry_delay_timer(phba); | |
16693 | ||
ecfd03c6 JS |
16694 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
16695 | if (!mbox) { | |
16696 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
16697 | "2745 Failed to allocate mbox for " | |
16698 | "requesting FCF rediscover.\n"); | |
16699 | return -ENOMEM; | |
16700 | } | |
16701 | ||
16702 | length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) - | |
16703 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
16704 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
16705 | LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF, | |
16706 | length, LPFC_SLI4_MBX_EMBED); | |
16707 | ||
16708 | redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl; | |
16709 | /* Set count to 0 for invalidating the entire FCF database */ | |
16710 | bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0); | |
16711 | ||
16712 | /* Issue the mailbox command asynchronously */ | |
16713 | mbox->vport = phba->pport; | |
16714 | mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table; | |
16715 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); | |
16716 | ||
16717 | if (rc == MBX_NOT_FINISHED) { | |
16718 | mempool_free(mbox, phba->mbox_mem_pool); | |
16719 | return -EIO; | |
16720 | } | |
16721 | return 0; | |
16722 | } | |
16723 | ||
fc2b989b JS |
16724 | /** |
16725 | * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event | |
16726 | * @phba: pointer to lpfc hba data structure. | |
16727 | * | |
16728 | * This function is the failover routine as a last resort to the FCF DEAD | |
16729 | * event when driver failed to perform fast FCF failover. | |
16730 | **/ | |
16731 | void | |
16732 | lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba) | |
16733 | { | |
16734 | uint32_t link_state; | |
16735 | ||
16736 | /* | |
16737 | * Last resort as FCF DEAD event failover will treat this as | |
16738 | * a link down, but save the link state because we don't want | |
16739 | * it to be changed to Link Down unless it is already down. | |
16740 | */ | |
16741 | link_state = phba->link_state; | |
16742 | lpfc_linkdown(phba); | |
16743 | phba->link_state = link_state; | |
16744 | ||
16745 | /* Unregister FCF if no devices connected to it */ | |
16746 | lpfc_unregister_unused_fcf(phba); | |
16747 | } | |
16748 | ||
a0c87cbd | 16749 | /** |
026abb87 | 16750 | * lpfc_sli_get_config_region23 - Get sli3 port region 23 data. |
a0c87cbd | 16751 | * @phba: pointer to lpfc hba data structure. |
026abb87 | 16752 | * @rgn23_data: pointer to configure region 23 data. |
a0c87cbd | 16753 | * |
026abb87 JS |
16754 | * This function gets SLI3 port configure region 23 data through memory dump |
16755 | * mailbox command. When it successfully retrieves data, the size of the data | |
16756 | * will be returned, otherwise, 0 will be returned. | |
a0c87cbd | 16757 | **/ |
026abb87 JS |
16758 | static uint32_t |
16759 | lpfc_sli_get_config_region23(struct lpfc_hba *phba, char *rgn23_data) | |
a0c87cbd JS |
16760 | { |
16761 | LPFC_MBOXQ_t *pmb = NULL; | |
16762 | MAILBOX_t *mb; | |
026abb87 | 16763 | uint32_t offset = 0; |
a0c87cbd JS |
16764 | int rc; |
16765 | ||
026abb87 JS |
16766 | if (!rgn23_data) |
16767 | return 0; | |
16768 | ||
a0c87cbd JS |
16769 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
16770 | if (!pmb) { | |
16771 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
026abb87 JS |
16772 | "2600 failed to allocate mailbox memory\n"); |
16773 | return 0; | |
a0c87cbd JS |
16774 | } |
16775 | mb = &pmb->u.mb; | |
16776 | ||
a0c87cbd JS |
16777 | do { |
16778 | lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23); | |
16779 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); | |
16780 | ||
16781 | if (rc != MBX_SUCCESS) { | |
16782 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
026abb87 JS |
16783 | "2601 failed to read config " |
16784 | "region 23, rc 0x%x Status 0x%x\n", | |
16785 | rc, mb->mbxStatus); | |
a0c87cbd JS |
16786 | mb->un.varDmp.word_cnt = 0; |
16787 | } | |
16788 | /* | |
16789 | * dump mem may return a zero when finished or we got a | |
16790 | * mailbox error, either way we are done. | |
16791 | */ | |
16792 | if (mb->un.varDmp.word_cnt == 0) | |
16793 | break; | |
16794 | if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset) | |
16795 | mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset; | |
16796 | ||
16797 | lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET, | |
026abb87 JS |
16798 | rgn23_data + offset, |
16799 | mb->un.varDmp.word_cnt); | |
a0c87cbd JS |
16800 | offset += mb->un.varDmp.word_cnt; |
16801 | } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE); | |
16802 | ||
026abb87 JS |
16803 | mempool_free(pmb, phba->mbox_mem_pool); |
16804 | return offset; | |
16805 | } | |
16806 | ||
16807 | /** | |
16808 | * lpfc_sli4_get_config_region23 - Get sli4 port region 23 data. | |
16809 | * @phba: pointer to lpfc hba data structure. | |
16810 | * @rgn23_data: pointer to configure region 23 data. | |
16811 | * | |
16812 | * This function gets SLI4 port configure region 23 data through memory dump | |
16813 | * mailbox command. When it successfully retrieves data, the size of the data | |
16814 | * will be returned, otherwise, 0 will be returned. | |
16815 | **/ | |
16816 | static uint32_t | |
16817 | lpfc_sli4_get_config_region23(struct lpfc_hba *phba, char *rgn23_data) | |
16818 | { | |
16819 | LPFC_MBOXQ_t *mboxq = NULL; | |
16820 | struct lpfc_dmabuf *mp = NULL; | |
16821 | struct lpfc_mqe *mqe; | |
16822 | uint32_t data_length = 0; | |
16823 | int rc; | |
16824 | ||
16825 | if (!rgn23_data) | |
16826 | return 0; | |
16827 | ||
16828 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
16829 | if (!mboxq) { | |
16830 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
16831 | "3105 failed to allocate mailbox memory\n"); | |
16832 | return 0; | |
16833 | } | |
16834 | ||
16835 | if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) | |
16836 | goto out; | |
16837 | mqe = &mboxq->u.mqe; | |
16838 | mp = (struct lpfc_dmabuf *) mboxq->context1; | |
16839 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
16840 | if (rc) | |
16841 | goto out; | |
16842 | data_length = mqe->un.mb_words[5]; | |
16843 | if (data_length == 0) | |
16844 | goto out; | |
16845 | if (data_length > DMP_RGN23_SIZE) { | |
16846 | data_length = 0; | |
16847 | goto out; | |
16848 | } | |
16849 | lpfc_sli_pcimem_bcopy((char *)mp->virt, rgn23_data, data_length); | |
16850 | out: | |
16851 | mempool_free(mboxq, phba->mbox_mem_pool); | |
16852 | if (mp) { | |
16853 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
16854 | kfree(mp); | |
16855 | } | |
16856 | return data_length; | |
16857 | } | |
16858 | ||
16859 | /** | |
16860 | * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled. | |
16861 | * @phba: pointer to lpfc hba data structure. | |
16862 | * | |
16863 | * This function read region 23 and parse TLV for port status to | |
16864 | * decide if the user disaled the port. If the TLV indicates the | |
16865 | * port is disabled, the hba_flag is set accordingly. | |
16866 | **/ | |
16867 | void | |
16868 | lpfc_sli_read_link_ste(struct lpfc_hba *phba) | |
16869 | { | |
16870 | uint8_t *rgn23_data = NULL; | |
16871 | uint32_t if_type, data_size, sub_tlv_len, tlv_offset; | |
16872 | uint32_t offset = 0; | |
16873 | ||
16874 | /* Get adapter Region 23 data */ | |
16875 | rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL); | |
16876 | if (!rgn23_data) | |
16877 | goto out; | |
16878 | ||
16879 | if (phba->sli_rev < LPFC_SLI_REV4) | |
16880 | data_size = lpfc_sli_get_config_region23(phba, rgn23_data); | |
16881 | else { | |
16882 | if_type = bf_get(lpfc_sli_intf_if_type, | |
16883 | &phba->sli4_hba.sli_intf); | |
16884 | if (if_type == LPFC_SLI_INTF_IF_TYPE_0) | |
16885 | goto out; | |
16886 | data_size = lpfc_sli4_get_config_region23(phba, rgn23_data); | |
16887 | } | |
a0c87cbd JS |
16888 | |
16889 | if (!data_size) | |
16890 | goto out; | |
16891 | ||
16892 | /* Check the region signature first */ | |
16893 | if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) { | |
16894 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
16895 | "2619 Config region 23 has bad signature\n"); | |
16896 | goto out; | |
16897 | } | |
16898 | offset += 4; | |
16899 | ||
16900 | /* Check the data structure version */ | |
16901 | if (rgn23_data[offset] != LPFC_REGION23_VERSION) { | |
16902 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
16903 | "2620 Config region 23 has bad version\n"); | |
16904 | goto out; | |
16905 | } | |
16906 | offset += 4; | |
16907 | ||
16908 | /* Parse TLV entries in the region */ | |
16909 | while (offset < data_size) { | |
16910 | if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) | |
16911 | break; | |
16912 | /* | |
16913 | * If the TLV is not driver specific TLV or driver id is | |
16914 | * not linux driver id, skip the record. | |
16915 | */ | |
16916 | if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) || | |
16917 | (rgn23_data[offset + 2] != LINUX_DRIVER_ID) || | |
16918 | (rgn23_data[offset + 3] != 0)) { | |
16919 | offset += rgn23_data[offset + 1] * 4 + 4; | |
16920 | continue; | |
16921 | } | |
16922 | ||
16923 | /* Driver found a driver specific TLV in the config region */ | |
16924 | sub_tlv_len = rgn23_data[offset + 1] * 4; | |
16925 | offset += 4; | |
16926 | tlv_offset = 0; | |
16927 | ||
16928 | /* | |
16929 | * Search for configured port state sub-TLV. | |
16930 | */ | |
16931 | while ((offset < data_size) && | |
16932 | (tlv_offset < sub_tlv_len)) { | |
16933 | if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) { | |
16934 | offset += 4; | |
16935 | tlv_offset += 4; | |
16936 | break; | |
16937 | } | |
16938 | if (rgn23_data[offset] != PORT_STE_TYPE) { | |
16939 | offset += rgn23_data[offset + 1] * 4 + 4; | |
16940 | tlv_offset += rgn23_data[offset + 1] * 4 + 4; | |
16941 | continue; | |
16942 | } | |
16943 | ||
16944 | /* This HBA contains PORT_STE configured */ | |
16945 | if (!rgn23_data[offset + 2]) | |
16946 | phba->hba_flag |= LINK_DISABLED; | |
16947 | ||
16948 | goto out; | |
16949 | } | |
16950 | } | |
026abb87 | 16951 | |
a0c87cbd | 16952 | out: |
a0c87cbd JS |
16953 | kfree(rgn23_data); |
16954 | return; | |
16955 | } | |
695a814e | 16956 | |
52d52440 JS |
16957 | /** |
16958 | * lpfc_wr_object - write an object to the firmware | |
16959 | * @phba: HBA structure that indicates port to create a queue on. | |
16960 | * @dmabuf_list: list of dmabufs to write to the port. | |
16961 | * @size: the total byte value of the objects to write to the port. | |
16962 | * @offset: the current offset to be used to start the transfer. | |
16963 | * | |
16964 | * This routine will create a wr_object mailbox command to send to the port. | |
16965 | * the mailbox command will be constructed using the dma buffers described in | |
16966 | * @dmabuf_list to create a list of BDEs. This routine will fill in as many | |
16967 | * BDEs that the imbedded mailbox can support. The @offset variable will be | |
16968 | * used to indicate the starting offset of the transfer and will also return | |
16969 | * the offset after the write object mailbox has completed. @size is used to | |
16970 | * determine the end of the object and whether the eof bit should be set. | |
16971 | * | |
16972 | * Return 0 is successful and offset will contain the the new offset to use | |
16973 | * for the next write. | |
16974 | * Return negative value for error cases. | |
16975 | **/ | |
16976 | int | |
16977 | lpfc_wr_object(struct lpfc_hba *phba, struct list_head *dmabuf_list, | |
16978 | uint32_t size, uint32_t *offset) | |
16979 | { | |
16980 | struct lpfc_mbx_wr_object *wr_object; | |
16981 | LPFC_MBOXQ_t *mbox; | |
16982 | int rc = 0, i = 0; | |
16983 | uint32_t shdr_status, shdr_add_status; | |
16984 | uint32_t mbox_tmo; | |
16985 | union lpfc_sli4_cfg_shdr *shdr; | |
16986 | struct lpfc_dmabuf *dmabuf; | |
16987 | uint32_t written = 0; | |
16988 | ||
16989 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
16990 | if (!mbox) | |
16991 | return -ENOMEM; | |
16992 | ||
16993 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
16994 | LPFC_MBOX_OPCODE_WRITE_OBJECT, | |
16995 | sizeof(struct lpfc_mbx_wr_object) - | |
16996 | sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED); | |
16997 | ||
16998 | wr_object = (struct lpfc_mbx_wr_object *)&mbox->u.mqe.un.wr_object; | |
16999 | wr_object->u.request.write_offset = *offset; | |
17000 | sprintf((uint8_t *)wr_object->u.request.object_name, "/"); | |
17001 | wr_object->u.request.object_name[0] = | |
17002 | cpu_to_le32(wr_object->u.request.object_name[0]); | |
17003 | bf_set(lpfc_wr_object_eof, &wr_object->u.request, 0); | |
17004 | list_for_each_entry(dmabuf, dmabuf_list, list) { | |
17005 | if (i >= LPFC_MBX_WR_CONFIG_MAX_BDE || written >= size) | |
17006 | break; | |
17007 | wr_object->u.request.bde[i].addrLow = putPaddrLow(dmabuf->phys); | |
17008 | wr_object->u.request.bde[i].addrHigh = | |
17009 | putPaddrHigh(dmabuf->phys); | |
17010 | if (written + SLI4_PAGE_SIZE >= size) { | |
17011 | wr_object->u.request.bde[i].tus.f.bdeSize = | |
17012 | (size - written); | |
17013 | written += (size - written); | |
17014 | bf_set(lpfc_wr_object_eof, &wr_object->u.request, 1); | |
17015 | } else { | |
17016 | wr_object->u.request.bde[i].tus.f.bdeSize = | |
17017 | SLI4_PAGE_SIZE; | |
17018 | written += SLI4_PAGE_SIZE; | |
17019 | } | |
17020 | i++; | |
17021 | } | |
17022 | wr_object->u.request.bde_count = i; | |
17023 | bf_set(lpfc_wr_object_write_length, &wr_object->u.request, written); | |
17024 | if (!phba->sli4_hba.intr_enable) | |
17025 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
17026 | else { | |
a183a15f | 17027 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
52d52440 JS |
17028 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
17029 | } | |
17030 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
17031 | shdr = (union lpfc_sli4_cfg_shdr *) &wr_object->header.cfg_shdr; | |
17032 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
17033 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
17034 | if (rc != MBX_TIMEOUT) | |
17035 | mempool_free(mbox, phba->mbox_mem_pool); | |
17036 | if (shdr_status || shdr_add_status || rc) { | |
17037 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
17038 | "3025 Write Object mailbox failed with " | |
17039 | "status x%x add_status x%x, mbx status x%x\n", | |
17040 | shdr_status, shdr_add_status, rc); | |
17041 | rc = -ENXIO; | |
17042 | } else | |
17043 | *offset += wr_object->u.response.actual_write_length; | |
17044 | return rc; | |
17045 | } | |
17046 | ||
695a814e JS |
17047 | /** |
17048 | * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands. | |
17049 | * @vport: pointer to vport data structure. | |
17050 | * | |
17051 | * This function iterate through the mailboxq and clean up all REG_LOGIN | |
17052 | * and REG_VPI mailbox commands associated with the vport. This function | |
17053 | * is called when driver want to restart discovery of the vport due to | |
17054 | * a Clear Virtual Link event. | |
17055 | **/ | |
17056 | void | |
17057 | lpfc_cleanup_pending_mbox(struct lpfc_vport *vport) | |
17058 | { | |
17059 | struct lpfc_hba *phba = vport->phba; | |
17060 | LPFC_MBOXQ_t *mb, *nextmb; | |
17061 | struct lpfc_dmabuf *mp; | |
78730cfe | 17062 | struct lpfc_nodelist *ndlp; |
d439d286 | 17063 | struct lpfc_nodelist *act_mbx_ndlp = NULL; |
589a52d6 | 17064 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
d439d286 | 17065 | LIST_HEAD(mbox_cmd_list); |
63e801ce | 17066 | uint8_t restart_loop; |
695a814e | 17067 | |
d439d286 | 17068 | /* Clean up internally queued mailbox commands with the vport */ |
695a814e JS |
17069 | spin_lock_irq(&phba->hbalock); |
17070 | list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) { | |
17071 | if (mb->vport != vport) | |
17072 | continue; | |
17073 | ||
17074 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) && | |
17075 | (mb->u.mb.mbxCommand != MBX_REG_VPI)) | |
17076 | continue; | |
17077 | ||
d439d286 JS |
17078 | list_del(&mb->list); |
17079 | list_add_tail(&mb->list, &mbox_cmd_list); | |
17080 | } | |
17081 | /* Clean up active mailbox command with the vport */ | |
17082 | mb = phba->sli.mbox_active; | |
17083 | if (mb && (mb->vport == vport)) { | |
17084 | if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) || | |
17085 | (mb->u.mb.mbxCommand == MBX_REG_VPI)) | |
17086 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
17087 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { | |
17088 | act_mbx_ndlp = (struct lpfc_nodelist *)mb->context2; | |
17089 | /* Put reference count for delayed processing */ | |
17090 | act_mbx_ndlp = lpfc_nlp_get(act_mbx_ndlp); | |
17091 | /* Unregister the RPI when mailbox complete */ | |
17092 | mb->mbox_flag |= LPFC_MBX_IMED_UNREG; | |
17093 | } | |
17094 | } | |
63e801ce JS |
17095 | /* Cleanup any mailbox completions which are not yet processed */ |
17096 | do { | |
17097 | restart_loop = 0; | |
17098 | list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) { | |
17099 | /* | |
17100 | * If this mailox is already processed or it is | |
17101 | * for another vport ignore it. | |
17102 | */ | |
17103 | if ((mb->vport != vport) || | |
17104 | (mb->mbox_flag & LPFC_MBX_IMED_UNREG)) | |
17105 | continue; | |
17106 | ||
17107 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) && | |
17108 | (mb->u.mb.mbxCommand != MBX_REG_VPI)) | |
17109 | continue; | |
17110 | ||
17111 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
17112 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { | |
17113 | ndlp = (struct lpfc_nodelist *)mb->context2; | |
17114 | /* Unregister the RPI when mailbox complete */ | |
17115 | mb->mbox_flag |= LPFC_MBX_IMED_UNREG; | |
17116 | restart_loop = 1; | |
17117 | spin_unlock_irq(&phba->hbalock); | |
17118 | spin_lock(shost->host_lock); | |
17119 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; | |
17120 | spin_unlock(shost->host_lock); | |
17121 | spin_lock_irq(&phba->hbalock); | |
17122 | break; | |
17123 | } | |
17124 | } | |
17125 | } while (restart_loop); | |
17126 | ||
d439d286 JS |
17127 | spin_unlock_irq(&phba->hbalock); |
17128 | ||
17129 | /* Release the cleaned-up mailbox commands */ | |
17130 | while (!list_empty(&mbox_cmd_list)) { | |
17131 | list_remove_head(&mbox_cmd_list, mb, LPFC_MBOXQ_t, list); | |
695a814e JS |
17132 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
17133 | mp = (struct lpfc_dmabuf *) (mb->context1); | |
17134 | if (mp) { | |
17135 | __lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
17136 | kfree(mp); | |
17137 | } | |
78730cfe | 17138 | ndlp = (struct lpfc_nodelist *) mb->context2; |
d439d286 | 17139 | mb->context2 = NULL; |
78730cfe | 17140 | if (ndlp) { |
ec21b3b0 | 17141 | spin_lock(shost->host_lock); |
589a52d6 | 17142 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
ec21b3b0 | 17143 | spin_unlock(shost->host_lock); |
78730cfe | 17144 | lpfc_nlp_put(ndlp); |
78730cfe | 17145 | } |
695a814e | 17146 | } |
695a814e JS |
17147 | mempool_free(mb, phba->mbox_mem_pool); |
17148 | } | |
d439d286 JS |
17149 | |
17150 | /* Release the ndlp with the cleaned-up active mailbox command */ | |
17151 | if (act_mbx_ndlp) { | |
17152 | spin_lock(shost->host_lock); | |
17153 | act_mbx_ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; | |
17154 | spin_unlock(shost->host_lock); | |
17155 | lpfc_nlp_put(act_mbx_ndlp); | |
695a814e | 17156 | } |
695a814e JS |
17157 | } |
17158 | ||
2a9bf3d0 JS |
17159 | /** |
17160 | * lpfc_drain_txq - Drain the txq | |
17161 | * @phba: Pointer to HBA context object. | |
17162 | * | |
17163 | * This function attempt to submit IOCBs on the txq | |
17164 | * to the adapter. For SLI4 adapters, the txq contains | |
17165 | * ELS IOCBs that have been deferred because the there | |
17166 | * are no SGLs. This congestion can occur with large | |
17167 | * vport counts during node discovery. | |
17168 | **/ | |
17169 | ||
17170 | uint32_t | |
17171 | lpfc_drain_txq(struct lpfc_hba *phba) | |
17172 | { | |
17173 | LIST_HEAD(completions); | |
17174 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; | |
2e706377 | 17175 | struct lpfc_iocbq *piocbq = NULL; |
2a9bf3d0 JS |
17176 | unsigned long iflags = 0; |
17177 | char *fail_msg = NULL; | |
17178 | struct lpfc_sglq *sglq; | |
17179 | union lpfc_wqe wqe; | |
a2fc4aef | 17180 | uint32_t txq_cnt = 0; |
2a9bf3d0 | 17181 | |
398d81c9 | 17182 | spin_lock_irqsave(&pring->ring_lock, iflags); |
0e9bb8d7 JS |
17183 | list_for_each_entry(piocbq, &pring->txq, list) { |
17184 | txq_cnt++; | |
17185 | } | |
17186 | ||
17187 | if (txq_cnt > pring->txq_max) | |
17188 | pring->txq_max = txq_cnt; | |
2a9bf3d0 | 17189 | |
398d81c9 | 17190 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
2a9bf3d0 | 17191 | |
0e9bb8d7 | 17192 | while (!list_empty(&pring->txq)) { |
398d81c9 | 17193 | spin_lock_irqsave(&pring->ring_lock, iflags); |
2a9bf3d0 | 17194 | |
19ca7609 | 17195 | piocbq = lpfc_sli_ringtx_get(phba, pring); |
a629852a | 17196 | if (!piocbq) { |
398d81c9 | 17197 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
a629852a JS |
17198 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
17199 | "2823 txq empty and txq_cnt is %d\n ", | |
0e9bb8d7 | 17200 | txq_cnt); |
a629852a JS |
17201 | break; |
17202 | } | |
19ca7609 | 17203 | sglq = __lpfc_sli_get_sglq(phba, piocbq); |
2a9bf3d0 | 17204 | if (!sglq) { |
19ca7609 | 17205 | __lpfc_sli_ringtx_put(phba, pring, piocbq); |
398d81c9 | 17206 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
2a9bf3d0 | 17207 | break; |
2a9bf3d0 | 17208 | } |
0e9bb8d7 | 17209 | txq_cnt--; |
2a9bf3d0 JS |
17210 | |
17211 | /* The xri and iocb resources secured, | |
17212 | * attempt to issue request | |
17213 | */ | |
6d368e53 | 17214 | piocbq->sli4_lxritag = sglq->sli4_lxritag; |
2a9bf3d0 JS |
17215 | piocbq->sli4_xritag = sglq->sli4_xritag; |
17216 | if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocbq, sglq)) | |
17217 | fail_msg = "to convert bpl to sgl"; | |
17218 | else if (lpfc_sli4_iocb2wqe(phba, piocbq, &wqe)) | |
17219 | fail_msg = "to convert iocb to wqe"; | |
17220 | else if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe)) | |
17221 | fail_msg = " - Wq is full"; | |
17222 | else | |
17223 | lpfc_sli_ringtxcmpl_put(phba, pring, piocbq); | |
17224 | ||
17225 | if (fail_msg) { | |
17226 | /* Failed means we can't issue and need to cancel */ | |
17227 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
17228 | "2822 IOCB failed %s iotag 0x%x " | |
17229 | "xri 0x%x\n", | |
17230 | fail_msg, | |
17231 | piocbq->iotag, piocbq->sli4_xritag); | |
17232 | list_add_tail(&piocbq->list, &completions); | |
17233 | } | |
398d81c9 | 17234 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
2a9bf3d0 JS |
17235 | } |
17236 | ||
2a9bf3d0 JS |
17237 | /* Cancel all the IOCBs that cannot be issued */ |
17238 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, | |
17239 | IOERR_SLI_ABORTED); | |
17240 | ||
0e9bb8d7 | 17241 | return txq_cnt; |
2a9bf3d0 | 17242 | } |